This repository was archived by the owner on Oct 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhdr.h
More file actions
162 lines (135 loc) · 3.02 KB
/
hdr.h
File metadata and controls
162 lines (135 loc) · 3.02 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Author: Abby Cin
* Mail: abbytsing@gmail.com
* Create Time: 2023-09-03 16:20:59
*/
#pragma once
#include <infiniband/verbs.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#define SGL_PER_IO 16U
#define WR_DEPTH 16U
#define MAX_FILE 32U
#define _nou __attribute__((unused))
struct xfer_sgl {
uint32_t rkey;
uint32_t length;
uint64_t addr;
uint64_t offset;
};
struct req_hdr {
uint32_t req_id;
uint16_t nr_sgl;
uint16_t fid;
struct xfer_sgl sgl[SGL_PER_IO];
};
struct rsp_hdr {
uint32_t req_id;
uint32_t pad;
};
#define container_of(ptr, type, member) \
({ \
typeof(((type *)0)->member) *__mptr = (ptr); \
(type *)((char *)__mptr - offsetof(type, member)); \
})
#define min(x, y) \
({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
_x > _y ? _y : _x; \
})
#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
for ((var) = TAILQ_FIRST((head)); \
(var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
(var) = (tvar))
enum wr_type {
OP_RDMA_READ = 3,
OP_RDMA_SEND = 5,
OP_RDMA_RECV = 7,
};
struct pp_wr {
enum wr_type type;
};
typedef struct {
struct pp_wr pp_wr;
uint64_t addr;
uint64_t offset;
struct ibv_send_wr wr;
void *context;
} send_wr_t;
typedef struct {
struct pp_wr pp_wr;
struct ibv_recv_wr wr;
} recv_wr_t;
typedef struct {
struct ibv_send_wr *head;
struct ibv_send_wr *tail;
} sendq_t;
typedef struct {
struct ibv_recv_wr *head;
struct ibv_recv_wr *tail;
} recvq_t;
static inline bool txq_empty(sendq_t *q)
{
return q->head == NULL;
}
static inline struct ibv_send_wr *txq_head(sendq_t *q)
{
return q->head;
}
static inline void txq_push(sendq_t *q, struct ibv_send_wr *w)
{
w->next = NULL;
if (q->head == NULL) {
q->head = w;
q->tail = w;
} else {
q->tail->next = w;
q->tail = w;
}
}
static inline void txq_pop(sendq_t *q)
{
struct ibv_send_wr *r = q->head;
if (r) {
q->head = r->next;
r->next = NULL;
}
}
static inline bool rxq_empty(recvq_t *q)
{
return q->head == NULL;
}
static inline struct ibv_recv_wr *rxq_head(recvq_t *q)
{
return q->head;
}
static inline void rxq_push(recvq_t *q, struct ibv_recv_wr *w)
{
w->next = NULL;
if (q->head == NULL) {
q->head = w;
q->tail = w;
} else {
q->tail->next = w;
q->tail = w;
}
}
static inline void rxq_pop(recvq_t *q)
{
struct ibv_recv_wr *r = q->head;
if (r) {
q->head = r->next;
r->next = NULL;
}
}
static inline uint32_t decode_req_id(uint32_t id)
{
return id >> 16;
}
static inline uint32_t build_req_id(uint32_t task_id, uint16_t seq)
{
return (task_id << 16) | seq;
}