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#ifndef SVC_RDMA_H
43#define SVC_RDMA_H
44#include <linux/sunrpc/xdr.h>
45#include <linux/sunrpc/svcsock.h>
46#include <linux/sunrpc/rpc_rdma.h>
47#include <rdma/ib_verbs.h>
48#include <rdma/rdma_cm.h>
49#define SVCRDMA_DEBUG
50
51
52enum {
53 RPCRDMA_DEF_INLINE_THRESH = 4096,
54 RPCRDMA_MAX_INLINE_THRESH = 65536
55};
56
57
58extern unsigned int svcrdma_ord;
59extern unsigned int svcrdma_max_requests;
60extern unsigned int svcrdma_max_bc_requests;
61extern unsigned int svcrdma_max_req_size;
62
63extern atomic_t rdma_stat_recv;
64extern atomic_t rdma_stat_read;
65extern atomic_t rdma_stat_write;
66extern atomic_t rdma_stat_sq_starve;
67extern atomic_t rdma_stat_rq_starve;
68extern atomic_t rdma_stat_rq_poll;
69extern atomic_t rdma_stat_rq_prod;
70extern atomic_t rdma_stat_sq_poll;
71extern atomic_t rdma_stat_sq_prod;
72
73
74
75
76
77
78struct svc_rdma_op_ctxt {
79 struct list_head list;
80 struct xdr_buf arg;
81 struct ib_cqe cqe;
82 u32 byte_len;
83 struct svcxprt_rdma *xprt;
84 enum dma_data_direction direction;
85 int count;
86 unsigned int mapped_sges;
87 int hdr_count;
88 struct ib_send_wr send_wr;
89 struct ib_sge sge[1 + RPCRDMA_MAX_INLINE_THRESH / PAGE_SIZE];
90 struct page *pages[RPCSVC_MAXPAGES];
91};
92
93struct svcxprt_rdma {
94 struct svc_xprt sc_xprt;
95 struct rdma_cm_id *sc_cm_id;
96 struct list_head sc_accept_q;
97 int sc_ord;
98 int sc_max_sge;
99 bool sc_snd_w_inv;
100
101 atomic_t sc_sq_avail;
102 unsigned int sc_sq_depth;
103 unsigned int sc_rq_depth;
104 __be32 sc_fc_credits;
105 u32 sc_max_requests;
106 u32 sc_max_bc_requests;
107 int sc_max_req_size;
108 u8 sc_port_num;
109
110 struct ib_pd *sc_pd;
111
112 spinlock_t sc_ctxt_lock;
113 struct list_head sc_ctxts;
114 int sc_ctxt_used;
115 spinlock_t sc_rw_ctxt_lock;
116 struct list_head sc_rw_ctxts;
117
118 struct list_head sc_rq_dto_q;
119 spinlock_t sc_rq_dto_lock;
120 struct ib_qp *sc_qp;
121 struct ib_cq *sc_rq_cq;
122 struct ib_cq *sc_sq_cq;
123
124 spinlock_t sc_lock;
125
126 wait_queue_head_t sc_send_wait;
127 unsigned long sc_flags;
128 struct list_head sc_read_complete_q;
129 struct work_struct sc_work;
130};
131
132#define RDMAXPRT_CONN_PENDING 3
133
134#define RPCRDMA_LISTEN_BACKLOG 10
135
136
137#define RPCRDMA_ORD (64/4)
138#define RPCRDMA_MAX_REQUESTS 32
139
140
141
142
143#define RPCRDMA_MAX_BC_REQUESTS 2
144
145#define RPCSVC_MAXPAYLOAD_RDMA RPCSVC_MAXPAYLOAD
146
147
148static inline void svc_rdma_count_mappings(struct svcxprt_rdma *rdma,
149 struct svc_rdma_op_ctxt *ctxt)
150{
151 ctxt->mapped_sges++;
152}
153
154
155extern int svc_rdma_handle_bc_reply(struct rpc_xprt *xprt,
156 __be32 *rdma_resp,
157 struct xdr_buf *rcvbuf);
158
159
160extern int svc_rdma_recvfrom(struct svc_rqst *);
161
162
163extern void svc_rdma_destroy_rw_ctxts(struct svcxprt_rdma *rdma);
164extern int svc_rdma_recv_read_chunk(struct svcxprt_rdma *rdma,
165 struct svc_rqst *rqstp,
166 struct svc_rdma_op_ctxt *head, __be32 *p);
167extern int svc_rdma_send_write_chunk(struct svcxprt_rdma *rdma,
168 __be32 *wr_ch, struct xdr_buf *xdr);
169extern int svc_rdma_send_reply_chunk(struct svcxprt_rdma *rdma,
170 __be32 *rp_ch, bool writelist,
171 struct xdr_buf *xdr);
172
173
174extern int svc_rdma_map_reply_hdr(struct svcxprt_rdma *rdma,
175 struct svc_rdma_op_ctxt *ctxt,
176 __be32 *rdma_resp, unsigned int len);
177extern int svc_rdma_post_send_wr(struct svcxprt_rdma *rdma,
178 struct svc_rdma_op_ctxt *ctxt,
179 int num_sge, u32 inv_rkey);
180extern int svc_rdma_sendto(struct svc_rqst *);
181
182
183extern void svc_rdma_wc_send(struct ib_cq *, struct ib_wc *);
184extern void svc_rdma_wc_reg(struct ib_cq *, struct ib_wc *);
185extern void svc_rdma_wc_read(struct ib_cq *, struct ib_wc *);
186extern void svc_rdma_wc_inv(struct ib_cq *, struct ib_wc *);
187extern int svc_rdma_send(struct svcxprt_rdma *, struct ib_send_wr *);
188extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *);
189extern struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *);
190extern void svc_rdma_put_context(struct svc_rdma_op_ctxt *, int);
191extern void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt);
192extern void svc_sq_reap(struct svcxprt_rdma *);
193extern void svc_rq_reap(struct svcxprt_rdma *);
194extern void svc_rdma_prep_reply_hdr(struct svc_rqst *);
195
196extern struct svc_xprt_class svc_rdma_class;
197#ifdef CONFIG_SUNRPC_BACKCHANNEL
198extern struct svc_xprt_class svc_rdma_bc_class;
199#endif
200
201
202extern struct workqueue_struct *svc_rdma_wq;
203extern int svc_rdma_init(void);
204extern void svc_rdma_cleanup(void);
205
206#endif
207