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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#ifndef _IB_H
#define _IB_H
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ib.h, rpcib plugin interface.
*/
#include <sys/types.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/conf.h>
#include <sys/stat.h>
#include <rpc/rpc.h>
#include <rpc/rpc_rdma.h>
#include <sys/ib/ibtl/ibti.h>
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_BUFS 256 /* max no. of buffers per pool */
#define DEF_CQ_SIZE 4096 - 1 /* default CQ size */
/*
* Tavor returns the next higher power of 2
* CQ entries than the requested size.
* For instance, if you request (2^12 - 1)
* CQ entries, Tavor returns 2^12 entries.
* 4K CQ entries suffice. Hence, 4096 - 1.
*/
#define DEF_SQ_SIZE 128 /* default SendQ size */
#define DEF_RQ_SIZE 256 /* default RecvQ size */
#define DSEG_MAX 2
#define RQ_DSEG_MAX 1 /* default RQ data seg */
#define IBSRM_HB 0x8000 /* high order bit of pkey */
#define NFS_SEC_KEY0 0x6878 /* randomly selected NFS security key */
#define NFS_SEC_KEY1 0x8679
/* max no. of refresh attempts on IBT_CM_CONN_STALE error */
#define REFRESH_ATTEMPTS 3
typedef struct rib_hca_s rib_hca_t;
typedef struct rib_qp_s rib_qp_t;
typedef struct rib_cq_s rib_cq_t;
/*
* Notification for RDMA_DONE is based on xid
*/
struct rdma_done_list {
uint32_t xid; /* XID waiting for RDMA_DONE */
kcondvar_t rdma_done_cv; /* cv for RDMA_DONE */
struct rdma_done_list *next;
struct rdma_done_list *prev;
};
/*
* State of the plugin.
* ACCEPT = accepting new connections and requests
* NO_ACCEPT = not accepting new connection and requests
*/
#define ACCEPT 1
#define NO_ACCEPT 2
/*
* Send Wait states
*/
#define SEND_WAIT -1
/*
* Reply states
*/
#define REPLY_WAIT -1
typedef void * rib_pvoid;
typedef rib_pvoid RIB_SYNCMEM_HANDLE;
/*
* IB buffer pool management structure
*/
/*
* Buffer pool info
*/
typedef struct {
kmutex_t buflock; /* lock for this structure */
caddr_t buf; /* pool address */
uint32_t bufhandle; /* rkey for this pool */
ulong_t bufsize; /* size of pool */
int rsize; /* size of each element */
int numelems; /* no. of elements allocated */
int buffree; /* no. of free elements */
void *buflist[1]; /* free elements in pool */
} bufpool_t;
typedef struct {
bufpool_t *bpool;
ibt_mr_hdl_t *mr_hdl;
ibt_mr_desc_t *mr_desc; /* vaddr, lkey, rkey */
} rib_bufpool_t;
/*
* ATS relsted defines and structures.
*/
#define ATS_AR_DATA_LEN 16
#define IBD_NAME "ibd"
#define N_IBD_INSTANCES 4
typedef struct rpcib_ats_s {
int ras_inst;
ib_pkey_t ras_pkey;
ib_gid_t ras_port_gid;
sa_family_t ras_inet_type;
union {
struct sockaddr_in ras_sockaddr;
struct sockaddr_in6 ras_sockaddr6;
} ra_sin;
#define ras_sin ra_sin.ras_sockaddr
#define ras_sin6 ra_sin.ras_sockaddr6
} rpcib_ats_t;
typedef struct rpcib_ibd_insts_s {
int rib_ibd_alloc;
int rib_ibd_cnt;
rpcib_ats_t *rib_ats;
} rpcib_ibd_insts_t;
/*
* Service types supported by RPCIB
* For now only NFS is supported.
*/
#define NFS 1
#define NLM 2
/*
* Tracks consumer state (client or server).
*/
typedef enum {
RIB_SERVER,
RIB_CLIENT
} rib_mode_t;
/*
* CQ structure
*/
struct rib_cq_s {
rib_hca_t *rib_hca;
ibt_cq_hdl_t rib_cq_hdl;
};
/*
* RPCIB plugin state
*/
typedef struct rpcib_state {
ibt_clnt_hdl_t ibt_clnt_hdl;
uint32_t hca_count;
uint32_t nhca_inited;
ib_guid_t *hca_guids;
rib_hca_t *hcas;
int refcount;
kmutex_t open_hca_lock;
rib_hca_t *hca; /* the hca being used */
queue_t *q; /* up queue for a serv_type */
uint32_t service_type; /* NFS, NLM, etc */
void *private;
} rpcib_state_t;
/*
* Each registered service's data structure.
* Each HCA has a list of these structures, which are the registered
* services on this HCA.
*/
typedef struct rib_service rib_service_t;
struct rib_service {
uint32_t srv_type; /* i.e, NFS, NLM, v4CBD */
/*
* service name, i.e, <IP>::NFS or <IP>::NLM. Since
* each type of service can be registered with many
* IP addrs(srv_name) and is running on all ports
* for all HCAs.
*/
char *srv_name;
uint32_t srv_port; /* port on which registered */
ib_svc_id_t srv_id; /* from ibt_register call */
ibt_srv_hdl_t srv_hdl; /* from ibt_register call */
ibt_sbind_hdl_t *srv_sbind_hdl; /* from ibt_bind call */
ibt_ar_t srv_ar;
/*
* pointer to the next service registered on this
* particular HCA
*/
rib_service_t *srv_next;
};
/*
* Connection lists
*/
typedef struct {
krwlock_t conn_lock; /* list lock */
CONN *conn_hd; /* list head */
} rib_conn_list_t;
enum hca_state {
HCA_INITED, /* hca in up and running state */
HCA_DETACHED /* hca in detached state */
};
/*
* RPCIB per HCA structure
*/
struct rib_hca_s {
ibt_clnt_hdl_t ibt_clnt_hdl;
/*
* per HCA.
*/
ibt_hca_hdl_t hca_hdl; /* HCA handle */
ibt_hca_attr_t hca_attrs; /* HCA attributes */
ibt_pd_hdl_t pd_hdl;
ib_guid_t hca_guid;
uint32_t hca_nports;
ibt_hca_portinfo_t *hca_ports;
size_t hca_pinfosz;
enum hca_state state; /* state of HCA */
krwlock_t state_lock; /* protects state field */
bool_t inuse; /* indicates HCA usage */
kmutex_t inuse_lock; /* protects inuse field */
/*
* List of services registered on all ports available
* on this HCA. Only one consumer of KRPC can register
* its services at one time or tear them down at one
* time.
*/
rib_service_t *service_list;
krwlock_t service_list_lock;
rib_service_t *ats_list; /* Service list for ATS */
rib_conn_list_t cl_conn_list; /* client conn list */
rib_conn_list_t srv_conn_list; /* server conn list */
rib_cq_t *clnt_scq;
rib_cq_t *clnt_rcq;
rib_cq_t *svc_scq;
rib_cq_t *svc_rcq;
kmutex_t cb_lock;
kcondvar_t cb_cv;
rib_bufpool_t *recv_pool; /* recv buf pool */
rib_bufpool_t *send_pool; /* send buf pool */
void *iblock; /* interrupt cookie */
};
/*
* Structure on wait state of a post send
*/
struct send_wid {
uint32_t xid;
int cv_sig;
kmutex_t sendwait_lock;
kcondvar_t wait_cv;
uint_t status;
rib_qp_t *qp;
int nsbufs; /* # of send buffers posted */
uint64_t sbufaddr[DSEG_MAX]; /* posted send buffers */
};
/*
* Structure on reply descriptor for recv queue.
* Different from the above posting of a descriptor.
*/
struct reply {
uint32_t xid;
uint_t status;
uint64_t vaddr_cq; /* buf addr from CQ */
uint_t bytes_xfer;
kcondvar_t wait_cv;
struct reply *next;
struct reply *prev;
};
struct svc_recv {
rib_qp_t *qp;
uint64_t vaddr;
uint_t bytes_xfer;
};
struct recv_wid {
uint32_t xid;
rib_qp_t *qp;
uint64_t addr; /* posted buf addr */
};
/*
* Per QP data structure
*/
struct rib_qp_s {
rib_hca_t *hca;
rib_mode_t mode; /* RIB_SERVER or RIB_CLIENT */
CONN rdmaconn;
ibt_channel_hdl_t qp_hdl;
uint_t port_num;
ib_qpn_t qpn;
int chan_flags;
clock_t timeout;
ibt_rc_chan_query_attr_t qp_q_attrs;
rib_cq_t *send_cq; /* send CQ */
rib_cq_t *recv_cq; /* recv CQ */
/*
* Number of pre-posted rbufs
*/
uint_t n_posted_rbufs;
kcondvar_t posted_rbufs_cv;
kmutex_t posted_rbufs_lock;
/*
* RPC reply
*/
uint_t rep_list_size;
struct reply *replylist;
kmutex_t replylist_lock;
/*
* server only, RDMA_DONE
*/
struct rdma_done_list *rdlist;
kmutex_t rdlist_lock;
kmutex_t cb_lock;
kcondvar_t cb_conn_cv;
caddr_t q; /* upstream queue */
};
#define ctoqp(conn) ((rib_qp_t *)((conn)->c_private))
#define qptoc(rqp) ((CONN *)&((rqp)->rdmaconn))
/*
* Timeout for various calls
*/
#define CONN_WAIT_TIME 40
#define SEND_WAIT_TIME 40 /* time for send completion */
#define REPLY_WAIT_TIME 40 /* time to get reply from remote QP */
#ifdef __cplusplus
}
#endif
#endif /* !_IB_H */
|