]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - sys/ofed/include/linux/list.h
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.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_first_entry(ptr, type, member) \
115         list_entry((ptr)->next, type, member)
116
117 #define list_for_each(p, head)                                          \
118         for (p = (head)->next; p != (head); p = p->next)
119
120 #define list_for_each_safe(p, n, head)                                  \
121         for (p = (head)->next, n = p->next; p != (head); p = n, n = p->next)
122
123 #define list_for_each_entry(p, h, field)                                \
124         for (p = list_entry((h)->next, typeof(*p), field); &p->field != (h); \
125             p = list_entry(p->field.next, typeof(*p), field))
126
127 #define list_for_each_entry_safe(p, n, h, field)                        \
128         for (p = list_entry((h)->next, typeof(*p), field),              \
129             n = list_entry(p->field.next, typeof(*p), field); &p->field != (h);\
130             p = n, n = list_entry(n->field.next, typeof(*n), field))
131
132 #define list_for_each_entry_reverse(p, h, field)                        \
133         for (p = list_entry((h)->prev, typeof(*p), field); &p->field != (h); \
134             p = list_entry(p->field.prev, typeof(*p), field))
135
136 #define list_for_each_prev(p, h) for (p = (h)->prev; p != (h); p = p->prev)
137
138 static inline void
139 list_add(struct list_head *new, struct list_head *head)
140 {
141
142         _list_add(new, head, head->next);
143 }
144
145 static inline void
146 list_add_tail(struct list_head *new, struct list_head *head)
147 {
148
149         _list_add(new, head->prev, head);
150 }
151
152 static inline void
153 list_move(struct list_head *list, struct list_head *head)
154 {
155
156         list_del(list);
157         list_add(list, head);
158 }
159
160 static inline void
161 list_move_tail(struct list_head *entry, struct list_head *head)
162 {
163
164         list_del(entry);
165         list_add_tail(entry, head);
166 }
167
168 static inline void
169 _list_splice(const struct list_head *list, struct list_head *prev,  
170     struct list_head *next)
171 {
172         struct list_head *first;
173         struct list_head *last;
174
175         if (list_empty(list))
176                 return;
177         first = list->next;
178         last = list->prev;
179         first->prev = prev;
180         prev->next = first;
181         last->next = next;
182         next->prev = last;
183 }
184
185 static inline void
186 list_splice(const struct list_head *list, struct list_head *head)
187 {
188
189         _list_splice(list, head, head->next);
190
191
192 static inline void
193 list_splice_tail(struct list_head *list, struct list_head *head)
194 {
195
196         _list_splice(list, head->prev, head);
197 }
198  
199 static inline void
200 list_splice_init(struct list_head *list, struct list_head *head)
201 {
202
203         _list_splice(list, head, head->next);
204         INIT_LIST_HEAD(list);   
205 }
206  
207 static inline void
208 list_splice_tail_init(struct list_head *list, struct list_head *head)
209 {
210
211         _list_splice(list, head->prev, head);
212         INIT_LIST_HEAD(list);
213 }
214
215 #undef LIST_HEAD
216 #define LIST_HEAD(name) struct list_head name = { &(name), &(name) }
217
218
219 struct hlist_head {
220         struct hlist_node *first;
221 };
222
223 struct hlist_node {
224         struct hlist_node *next, **pprev;
225 };
226
227 #define HLIST_HEAD_INIT { }
228 #define HLIST_HEAD(name) struct hlist_head name = HLIST_HEAD_INIT
229 #define INIT_HLIST_HEAD(head) (head)->first = NULL
230 #define INIT_HLIST_NODE(node)                                           \
231 do {                                                                    \
232         (node)->next = NULL;                                            \
233         (node)->pprev = NULL;                                           \
234 } while (0)
235
236 static inline int
237 hlist_unhashed(const struct hlist_node *h)
238 {
239
240         return !h->pprev;
241 }
242
243 static inline int
244 hlist_empty(const struct hlist_head *h)
245 {
246
247         return !h->first;
248 }
249
250 static inline void
251 hlist_del(struct hlist_node *n)
252 {
253
254         if (n->next)
255                 n->next->pprev = n->pprev;
256         *n->pprev = n->next;
257 }
258
259 static inline void
260 hlist_del_init(struct hlist_node *n)
261 {
262
263         if (hlist_unhashed(n))
264                 return;
265         hlist_del(n);
266         INIT_HLIST_NODE(n);
267 }
268
269 static inline void
270 hlist_add_head(struct hlist_node *n, struct hlist_head *h)
271 {
272
273         n->next = h->first;
274         if (h->first)
275                 h->first->pprev = &n->next;
276         h->first = n;
277         n->pprev = &h->first;
278 }
279
280 static inline void
281 hlist_add_before(struct hlist_node *n, struct hlist_node *next)
282 {
283
284         n->pprev = next->pprev;
285         n->next = next;
286         next->pprev = &n->next;
287         *(n->pprev) = n;
288 }
289  
290 static inline void
291 hlist_add_after(struct hlist_node *n, struct hlist_node *next)
292 {
293
294         next->next = n->next;
295         n->next = next;
296         next->pprev = &n->next;
297         if (next->next)
298                 next->next->pprev = &next->next;
299 }
300  
301 static inline void
302 hlist_move_list(struct hlist_head *old, struct hlist_head *new)
303 {
304
305         new->first = old->first;
306         if (new->first)
307                 new->first->pprev = &new->first;
308         old->first = NULL;
309 }
310  
311 #define hlist_entry(ptr, type, field)   container_of(ptr, type, field)
312
313 #define hlist_for_each(p, head)                                         \
314         for (p = (head)->first; p; p = p->next)
315
316 #define hlist_for_each_safe(p, n, head)                                 \
317         for (p = (head)->first; p && ({ n = p->next; 1; }); p = n)
318
319 #define hlist_for_each_entry(tp, p, head, field)                        \
320         for (p = (head)->first;                                         \
321             p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
322  
323 #define hlist_for_each_entry_continue(tp, p, field)                     \
324         for (p = (p)->next;                                             \
325             p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
326
327 #define hlist_for_each_entry_from(tp, p, field)                         \
328         for (; p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next)
329
330 #define hlist_for_each_entry_safe(tp, p, n, head, field)                \
331         for (p = (head)->first; p ?                                     \
332             (n = p->next) | (tp = hlist_entry(p, typeof(*tp), field)) : \
333             NULL; p = n)
334
335 #endif /* _LINUX_LIST_H_ */