]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/ofed/include/linux/list.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / ofed / include / linux / list.h
1 /*-
2  * Copyright (c) 2010 Isilon Systems, Inc.
3  * Copyright (c) 2010 iX Systems, Inc.
4  * Copyright (c) 2010 Panasas, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice unmodified, this list of conditions, and the following
12  *    disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 #ifndef _LINUX_LIST_H_
29 #define _LINUX_LIST_H_
30
31 /*
32  * Since LIST_HEAD conflicts with the linux definition we must include any
33  * FreeBSD header which requires it here so it is resolved with the correct
34  * definition prior to the undef.
35  */
36 #include <linux/types.h>
37
38 #include <sys/param.h>
39 #include <sys/kernel.h>
40 #include <sys/queue.h>
41 #include <sys/cpuset.h>
42 #include <sys/lock.h>
43 #include <sys/mutex.h>
44 #include <sys/proc.h>
45 #include <sys/vnode.h>
46 #include <sys/conf.h>
47 #include <sys/socket.h>
48 #include <sys/mbuf.h>
49
50 #include <net/bpf.h>
51 #include <net/if.h>
52 #include <net/if_types.h>
53 #include <net/if_media.h>
54
55 #include <netinet/in.h>
56 #include <netinet/in_pcb.h>
57
58 #include <netinet6/in6_var.h>
59 #include <netinet6/nd6.h>
60
61 #include <vm/vm.h>
62 #include <vm/vm_object.h>
63
64 #define prefetch(x)
65
66 struct list_head {
67         struct list_head *next;
68         struct list_head *prev;
69 };
70
71 static inline void
72 INIT_LIST_HEAD(struct list_head *list)
73 {
74
75         list->next = list->prev = list;
76 }
77  
78 static inline int
79 list_empty(const struct list_head *head)
80 {
81
82         return (head->next == head);
83 }
84
85 static inline void
86 list_del(struct list_head *entry)
87 {
88
89         entry->next->prev = entry->prev;
90         entry->prev->next = entry->next;
91 }
92
93 static inline void
94 _list_add(struct list_head *new, struct list_head *prev,
95     struct list_head *next)
96 {
97
98         next->prev = new;
99         new->next = next;
100         new->prev = prev;
101         prev->next = new;
102 }
103
104 static inline void
105 list_del_init(struct list_head *entry)
106 {       
107
108         list_del(entry);
109         INIT_LIST_HEAD(entry);
110 }
111
112 #define list_entry(ptr, type, field)    container_of(ptr, type, field)
113
114 #define list_for_each(p, head)                                          \
115         for (p = (head)->next; p != (head); p = p->next)
116
117 #define list_for_each_safe(p, n, head)                                  \
118         for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
119
120 #define list_for_each_entry(p, h, field)                                \
121         for (p = list_entry((h)->next, typeof(*p), field); &p->field != (h); \
122             p = list_entry(p->field.next, typeof(*p), field))
123
124 #define list_for_each_entry_safe(p, n, h, field)                        \
125         for (p = list_entry((h)->next, typeof(*p), field),              \
126             n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\
127             p = n, n = list_entry(n->field.next, typeof(*n), field))
128
129 #define list_for_each_entry_reverse(p, h, field)                        \
130         for (p = list_entry((h)->prev, typeof(*p), field); &p->field != (h); \
131             p = list_entry(p->field.prev, typeof(*p), field))
132
133 #define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev)
134
135 static inline void
136 list_add(struct list_head *new, struct list_head *head)
137 {
138
139         _list_add(new, head, head->next);
140 }
141
142 static inline void
143 list_add_tail(struct list_head *new, struct list_head *head)
144 {
145
146         _list_add(new, head->prev, head);
147 }
148
149 static inline void
150 list_move(struct list_head *list, struct list_head *head)
151 {
152
153         list_del(list);
154         list_add(list, head);
155 }
156
157 static inline void
158 list_move_tail(struct list_head *entry, struct list_head *head)
159 {
160
161         list_del(entry);
162         list_add_tail(entry, head);
163 }
164
165 static inline void
166 _list_splice(const struct list_head *list, struct list_head *prev,  
167     struct list_head *next)
168 {
169         struct list_head *first;
170         struct list_head *last;
171
172         if (list_empty(list))
173                 return;
174         first = list->next;
175         last = list->prev;
176         first->prev = prev;
177         prev->next = first;
178         last->next = next;
179         next->prev = last;
180 }
181
182 static inline void
183 list_splice(const struct list_head *list, struct list_head *head)
184 {
185
186         _list_splice(list, head, head->next);
187
188
189 static inline void
190 list_splice_tail(struct list_head *list, struct list_head *head)
191 {
192
193         _list_splice(list, head->prev, head);
194 }
195  
196 static inline void
197 list_splice_init(struct list_head *list, struct list_head *head)
198 {
199
200         _list_splice(list, head, head->next);
201         INIT_LIST_HEAD(list);   
202 }
203  
204 static inline void
205 list_splice_tail_init(struct list_head *list, struct list_head *head)
206 {
207
208         _list_splice(list, head->prev, head);
209         INIT_LIST_HEAD(list);
210 }
211
212 #undef LIST_HEAD
213 #define LIST_HEAD(name) struct list_head name = { &(name), &(name) }
214
215
216 struct hlist_head {
217         struct hlist_node *first;
218 };
219
220 struct hlist_node {
221         struct hlist_node *next, **pprev;
222 };
223
224 #define HLIST_HEAD_INIT { }
225 #define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
226 #define INIT_HLIST_HEAD(head) (head)->first = NULL
227 #define INIT_HLIST_NODE(node)                                           \
228 do {                                                                    \
229         (node)->next = NULL;                                            \
230         (node)->pprev = NULL;                                           \
231 } while (0)
232
233 static inline int
234 hlist_unhashed(const struct hlist_node *h)
235 {
236
237         return !h->pprev;
238 }
239
240 static inline int
241 hlist_empty(const struct hlist_head *h)
242 {
243
244         return !h->first;
245 }
246
247 static inline void
248 hlist_del(struct hlist_node *n)
249 {
250
251         if (n->next)
252                 n->next->pprev = n->pprev;
253         *n->pprev = n->next;
254 }
255
256 static inline void
257 hlist_del_init(struct hlist_node *n)
258 {
259
260         if (hlist_unhashed(n))
261                 return;
262         hlist_del(n);
263         INIT_HLIST_NODE(n);
264 }
265
266 static inline void
267 hlist_add_head(struct hlist_node *n, struct hlist_head *h)
268 {
269
270         n->next = h->first;
271         if (h->first)
272                 h->first->pprev = &n->next;
273         h->first = n;
274         n->pprev = &h->first;
275 }
276
277 static inline void
278 hlist_add_before(struct hlist_node *n, struct hlist_node *next)
279 {
280
281         n->pprev = next->pprev;
282         n->next = next;
283         next->pprev = &n->next;
284         *(n->pprev) = n;
285 }
286  
287 static inline void
288 hlist_add_after(struct hlist_node *n, struct hlist_node *next)
289 {
290
291         next->next = n->next;
292         n->next = next;
293         next->pprev = &n->next;
294         if (next->next)
295                 next->next->pprev = &next->next;
296 }
297  
298 static inline void
299 hlist_move_list(struct hlist_head *old, struct hlist_head *new)
300 {
301
302         new->first = old->first;
303         if (new->first)
304                 new->first->pprev = &new->first;
305         old->first = NULL;
306 }
307  
308 #define hlist_entry(ptr, type, field)   container_of(ptr, type, field)
309
310 #define hlist_for_each(p, head)                                         \
311         for (p = (head)->first; p; p = p->next)
312
313 #define hlist_for_each_safe(p, n, head)                                 \
314         for (p = (head)->first; p && ({ n = p->next; 1; }); p = n)
315
316 #define hlist_for_each_entry(tp, p, head, field)                        \
317         for (p = (head)->first;                                         \
318             p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
319  
320 #define hlist_for_each_entry_continue(tp, p, field)                     \
321         for (p = (p)->next;                                             \
322             p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
323
324 #define hlist_for_each_entry_from(tp, p, field)                         \
325         for (; p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
326
327 #define hlist_for_each_entry_safe(tp, p, n, head, field)                \
328         for (p = (head)->first; p ?                                     \
329             (n = p->next) | (tp = hlist_entry(p, typeof(*tp), field)) : \
330             NULL; p = n)
331
332 #endif /* _LINUX_LIST_H_ */