]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/contrib/rdma/types.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / contrib / rdma / types.h
1 /*
2  * $FreeBSD$
3  */
4 #ifndef __RDMA_TYPES_H_
5 #define __RDMA_TYPES_H_
6 #include <sys/types.h>
7 #include <sys/malloc.h>
8
9
10 typedef uint8_t         u8;
11 typedef uint16_t        u16;
12 typedef uint32_t        u32;
13 typedef uint64_t        u64;
14  
15 typedef uint8_t         __u8;
16 typedef uint16_t        __u16;
17 typedef uint32_t        __u32;
18 typedef uint64_t        __u64;
19 typedef uint8_t         __be8;
20 typedef uint16_t        __be16;
21 typedef uint32_t        __be32;
22 typedef uint64_t        __be64;
23
24 typedef int32_t         __s32;
25
26
27 #define LINUX_TYPES_DEFINED
28 #define ERR_PTR(err) ((void *)((long)(err)))
29 #define IS_ERR(ptr)  ((unsigned long)(ptr) > (unsigned long)(-1000))
30 #define PTR_ERR(ptr)    ((long)(ptr))
31
32 #define PANIC_IF(exp) do {                  \
33         if (exp)                            \
34                 panic("BUG func %s line %u: %s", __FUNCTION__, __LINE__, #exp);      \
35 } while (0)
36
37 #define container_of(p, stype, field) ((stype *)(((uint8_t *)(p)) - offsetof(stype, field)))
38
39 static __inline int
40 find_first_zero_bit(volatile void *p, int max)
41 {
42         int b;
43         volatile int *ptr = (volatile int *)p;
44
45         for (b = 0; b < max; b += 32) {
46                 if (ptr[b >> 5] != ~0) {
47                         for (;;) {
48                                 if ((ptr[b >> 5] & (1 << (b & 0x1f))) == 0)
49                                         return (b);
50                                 b++;
51                         }
52                 }
53         }
54
55         return (max);
56 }
57
58 struct kvl {
59         struct kvl *next;
60         unsigned int key;
61         void *value;
62 };
63
64 #define DEFINE_KVL(x) struct kvl x;
65
66 static __inline void *
67 kvl_lookup(struct kvl *x, uint32_t key)
68 {
69         struct kvl *i;
70         for (i=x->next;i;i=i->next) if (i->key==key) return(i->value);
71         return(0);
72 }
73
74 static __inline int
75 kvl_alloc_above(struct kvl *idp, void *ptr, int starting_id, int *id)
76 {
77         int newid = starting_id;
78         struct kvl *i;
79
80         for (i=idp->next;i;i=i->next) 
81                 if (i->key == newid)
82                         return -EEXIST;
83
84         i=malloc(sizeof(struct kvl),M_TEMP,M_NOWAIT);
85         i->key=newid;
86         i->value=ptr;
87         i->next=idp->next;
88         idp->next=i;
89         *id = newid;
90         return(0);
91 }
92
93 static __inline void
94 kvl_delete(struct kvl *idp, int id) 
95 {
96         /* leak */
97         struct kvl *i, *prev=NULL;
98         for (i=idp->next;i;prev=i,i=i->next) 
99                 if ((i)->key==id) {
100                         if (!prev)
101                                 idp->next = i->next;
102                         else
103                                 prev->next = i->next;
104                         free(i, M_TEMP);
105                         return;
106                 }
107 }
108
109 static __inline void
110 kvl_free(struct kvl *idp)
111 {
112         struct kvl *i, *tmp;
113         for (i=idp->next;i;i=tmp) {
114                 tmp=i->next;
115                 free(i, M_TEMP);
116         }
117         idp->next = NULL;
118 }
119
120
121 #endif