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