RDS: IB: ack more receive completions to improve performance
[deliverable/linux.git] / net / rds / ib.h
1 #ifndef _RDS_IB_H
2 #define _RDS_IB_H
3
4 #include <rdma/ib_verbs.h>
5 #include <rdma/rdma_cm.h>
6 #include <linux/interrupt.h>
7 #include <linux/pci.h>
8 #include <linux/slab.h>
9 #include "rds.h"
10 #include "rdma_transport.h"
11
12 #define RDS_FMR_SIZE 256
13 #define RDS_FMR_POOL_SIZE 8192
14
15 #define RDS_IB_MAX_SGE 8
16 #define RDS_IB_RECV_SGE 2
17
18 #define RDS_IB_DEFAULT_RECV_WR 1024
19 #define RDS_IB_DEFAULT_SEND_WR 256
20
21 #define RDS_IB_DEFAULT_RETRY_COUNT 2
22
23 #define RDS_IB_SUPPORTED_PROTOCOLS 0x00000003 /* minor versions supported */
24
25 #define RDS_IB_RECYCLE_BATCH_COUNT 32
26
27 #define RDS_IB_WC_MAX 32
28
29 extern struct rw_semaphore rds_ib_devices_lock;
30 extern struct list_head rds_ib_devices;
31
32 /*
33 * IB posts RDS_FRAG_SIZE fragments of pages to the receive queues to
34 * try and minimize the amount of memory tied up both the device and
35 * socket receive queues.
36 */
37 struct rds_page_frag {
38 struct list_head f_item;
39 struct list_head f_cache_entry;
40 struct scatterlist f_sg;
41 };
42
43 struct rds_ib_incoming {
44 struct list_head ii_frags;
45 struct list_head ii_cache_entry;
46 struct rds_incoming ii_inc;
47 };
48
49 struct rds_ib_cache_head {
50 struct list_head *first;
51 unsigned long count;
52 };
53
54 struct rds_ib_refill_cache {
55 struct rds_ib_cache_head __percpu *percpu;
56 struct list_head *xfer;
57 struct list_head *ready;
58 };
59
60 struct rds_ib_connect_private {
61 /* Add new fields at the end, and don't permute existing fields. */
62 __be32 dp_saddr;
63 __be32 dp_daddr;
64 u8 dp_protocol_major;
65 u8 dp_protocol_minor;
66 __be16 dp_protocol_minor_mask; /* bitmask */
67 __be32 dp_reserved1;
68 __be64 dp_ack_seq;
69 __be32 dp_credit; /* non-zero enables flow ctl */
70 };
71
72 struct rds_ib_send_work {
73 void *s_op;
74 struct ib_send_wr s_wr;
75 struct ib_sge s_sge[RDS_IB_MAX_SGE];
76 unsigned long s_queued;
77 };
78
79 struct rds_ib_recv_work {
80 struct rds_ib_incoming *r_ibinc;
81 struct rds_page_frag *r_frag;
82 struct ib_recv_wr r_wr;
83 struct ib_sge r_sge[2];
84 };
85
86 struct rds_ib_work_ring {
87 u32 w_nr;
88 u32 w_alloc_ptr;
89 u32 w_alloc_ctr;
90 u32 w_free_ptr;
91 atomic_t w_free_ctr;
92 };
93
94 /* Rings are posted with all the allocations they'll need to queue the
95 * incoming message to the receiving socket so this can't fail.
96 * All fragments start with a header, so we can make sure we're not receiving
97 * garbage, and we can tell a small 8 byte fragment from an ACK frame.
98 */
99 struct rds_ib_ack_state {
100 u64 ack_next;
101 u64 ack_recv;
102 unsigned int ack_required:1;
103 unsigned int ack_next_valid:1;
104 unsigned int ack_recv_valid:1;
105 };
106
107
108 struct rds_ib_device;
109
110 struct rds_ib_connection {
111
112 struct list_head ib_node;
113 struct rds_ib_device *rds_ibdev;
114 struct rds_connection *conn;
115
116 /* alphabet soup, IBTA style */
117 struct rdma_cm_id *i_cm_id;
118 struct ib_pd *i_pd;
119 struct ib_cq *i_send_cq;
120 struct ib_cq *i_recv_cq;
121 struct ib_wc i_recv_wc[RDS_IB_WC_MAX];
122
123 /* interrupt handling */
124 struct tasklet_struct i_recv_tasklet;
125
126 /* tx */
127 struct rds_ib_work_ring i_send_ring;
128 struct rm_data_op *i_data_op;
129 struct rds_header *i_send_hdrs;
130 u64 i_send_hdrs_dma;
131 struct rds_ib_send_work *i_sends;
132 atomic_t i_signaled_sends;
133
134 /* rx */
135 struct mutex i_recv_mutex;
136 struct rds_ib_work_ring i_recv_ring;
137 struct rds_ib_incoming *i_ibinc;
138 u32 i_recv_data_rem;
139 struct rds_header *i_recv_hdrs;
140 u64 i_recv_hdrs_dma;
141 struct rds_ib_recv_work *i_recvs;
142 u64 i_ack_recv; /* last ACK received */
143 struct rds_ib_refill_cache i_cache_incs;
144 struct rds_ib_refill_cache i_cache_frags;
145
146 /* sending acks */
147 unsigned long i_ack_flags;
148 #ifdef KERNEL_HAS_ATOMIC64
149 atomic64_t i_ack_next; /* next ACK to send */
150 #else
151 spinlock_t i_ack_lock; /* protect i_ack_next */
152 u64 i_ack_next; /* next ACK to send */
153 #endif
154 struct rds_header *i_ack;
155 struct ib_send_wr i_ack_wr;
156 struct ib_sge i_ack_sge;
157 u64 i_ack_dma;
158 unsigned long i_ack_queued;
159
160 /* Flow control related information
161 *
162 * Our algorithm uses a pair variables that we need to access
163 * atomically - one for the send credits, and one posted
164 * recv credits we need to transfer to remote.
165 * Rather than protect them using a slow spinlock, we put both into
166 * a single atomic_t and update it using cmpxchg
167 */
168 atomic_t i_credits;
169
170 /* Protocol version specific information */
171 unsigned int i_flowctl:1; /* enable/disable flow ctl */
172
173 /* Batched completions */
174 unsigned int i_unsignaled_wrs;
175 };
176
177 /* This assumes that atomic_t is at least 32 bits */
178 #define IB_GET_SEND_CREDITS(v) ((v) & 0xffff)
179 #define IB_GET_POST_CREDITS(v) ((v) >> 16)
180 #define IB_SET_SEND_CREDITS(v) ((v) & 0xffff)
181 #define IB_SET_POST_CREDITS(v) ((v) << 16)
182
183 struct rds_ib_ipaddr {
184 struct list_head list;
185 __be32 ipaddr;
186 struct rcu_head rcu;
187 };
188
189 struct rds_ib_device {
190 struct list_head list;
191 struct list_head ipaddr_list;
192 struct list_head conn_list;
193 struct ib_device *dev;
194 struct ib_pd *pd;
195 struct rds_ib_mr_pool *mr_pool;
196 unsigned int fmr_max_remaps;
197 unsigned int max_fmrs;
198 int max_sge;
199 unsigned int max_wrs;
200 unsigned int max_initiator_depth;
201 unsigned int max_responder_resources;
202 spinlock_t spinlock; /* protect the above */
203 atomic_t refcount;
204 struct work_struct free_work;
205 };
206
207 #define ibdev_to_node(ibdev) dev_to_node(ibdev->dma_device)
208 #define rdsibdev_to_node(rdsibdev) ibdev_to_node(rdsibdev->dev)
209
210 /* bits for i_ack_flags */
211 #define IB_ACK_IN_FLIGHT 0
212 #define IB_ACK_REQUESTED 1
213
214 /* Magic WR_ID for ACKs */
215 #define RDS_IB_ACK_WR_ID (~(u64) 0)
216
217 struct rds_ib_statistics {
218 uint64_t s_ib_connect_raced;
219 uint64_t s_ib_listen_closed_stale;
220 uint64_t s_ib_tx_cq_call;
221 uint64_t s_ib_evt_handler_call;
222 uint64_t s_ib_tasklet_call;
223 uint64_t s_ib_tx_cq_event;
224 uint64_t s_ib_tx_ring_full;
225 uint64_t s_ib_tx_throttle;
226 uint64_t s_ib_tx_sg_mapping_failure;
227 uint64_t s_ib_tx_stalled;
228 uint64_t s_ib_tx_credit_updates;
229 uint64_t s_ib_rx_cq_event;
230 uint64_t s_ib_rx_ring_empty;
231 uint64_t s_ib_rx_refill_from_cq;
232 uint64_t s_ib_rx_refill_from_thread;
233 uint64_t s_ib_rx_alloc_limit;
234 uint64_t s_ib_rx_credit_updates;
235 uint64_t s_ib_ack_sent;
236 uint64_t s_ib_ack_send_failure;
237 uint64_t s_ib_ack_send_delayed;
238 uint64_t s_ib_ack_send_piggybacked;
239 uint64_t s_ib_ack_received;
240 uint64_t s_ib_rdma_mr_alloc;
241 uint64_t s_ib_rdma_mr_free;
242 uint64_t s_ib_rdma_mr_used;
243 uint64_t s_ib_rdma_mr_pool_flush;
244 uint64_t s_ib_rdma_mr_pool_wait;
245 uint64_t s_ib_rdma_mr_pool_depleted;
246 uint64_t s_ib_atomic_cswp;
247 uint64_t s_ib_atomic_fadd;
248 };
249
250 extern struct workqueue_struct *rds_ib_wq;
251
252 /*
253 * Fake ib_dma_sync_sg_for_{cpu,device} as long as ib_verbs.h
254 * doesn't define it.
255 */
256 static inline void rds_ib_dma_sync_sg_for_cpu(struct ib_device *dev,
257 struct scatterlist *sglist,
258 unsigned int sg_dma_len,
259 int direction)
260 {
261 struct scatterlist *sg;
262 unsigned int i;
263
264 for_each_sg(sglist, sg, sg_dma_len, i) {
265 ib_dma_sync_single_for_cpu(dev,
266 ib_sg_dma_address(dev, sg),
267 ib_sg_dma_len(dev, sg),
268 direction);
269 }
270 }
271 #define ib_dma_sync_sg_for_cpu rds_ib_dma_sync_sg_for_cpu
272
273 static inline void rds_ib_dma_sync_sg_for_device(struct ib_device *dev,
274 struct scatterlist *sglist,
275 unsigned int sg_dma_len,
276 int direction)
277 {
278 struct scatterlist *sg;
279 unsigned int i;
280
281 for_each_sg(sglist, sg, sg_dma_len, i) {
282 ib_dma_sync_single_for_device(dev,
283 ib_sg_dma_address(dev, sg),
284 ib_sg_dma_len(dev, sg),
285 direction);
286 }
287 }
288 #define ib_dma_sync_sg_for_device rds_ib_dma_sync_sg_for_device
289
290
291 /* ib.c */
292 extern struct rds_transport rds_ib_transport;
293 struct rds_ib_device *rds_ib_get_client_data(struct ib_device *device);
294 void rds_ib_dev_put(struct rds_ib_device *rds_ibdev);
295 extern struct ib_client rds_ib_client;
296
297 extern unsigned int fmr_message_size;
298 extern unsigned int rds_ib_retry_count;
299
300 extern spinlock_t ib_nodev_conns_lock;
301 extern struct list_head ib_nodev_conns;
302
303 /* ib_cm.c */
304 int rds_ib_conn_alloc(struct rds_connection *conn, gfp_t gfp);
305 void rds_ib_conn_free(void *arg);
306 int rds_ib_conn_connect(struct rds_connection *conn);
307 void rds_ib_conn_shutdown(struct rds_connection *conn);
308 void rds_ib_state_change(struct sock *sk);
309 int rds_ib_listen_init(void);
310 void rds_ib_listen_stop(void);
311 void __rds_ib_conn_error(struct rds_connection *conn, const char *, ...);
312 int rds_ib_cm_handle_connect(struct rdma_cm_id *cm_id,
313 struct rdma_cm_event *event);
314 int rds_ib_cm_initiate_connect(struct rdma_cm_id *cm_id);
315 void rds_ib_cm_connect_complete(struct rds_connection *conn,
316 struct rdma_cm_event *event);
317
318
319 #define rds_ib_conn_error(conn, fmt...) \
320 __rds_ib_conn_error(conn, KERN_WARNING "RDS/IB: " fmt)
321
322 /* ib_rdma.c */
323 int rds_ib_update_ipaddr(struct rds_ib_device *rds_ibdev, __be32 ipaddr);
324 void rds_ib_add_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn);
325 void rds_ib_remove_conn(struct rds_ib_device *rds_ibdev, struct rds_connection *conn);
326 void rds_ib_destroy_nodev_conns(void);
327 struct rds_ib_mr_pool *rds_ib_create_mr_pool(struct rds_ib_device *);
328 void rds_ib_get_mr_info(struct rds_ib_device *rds_ibdev, struct rds_info_rdma_connection *iinfo);
329 void rds_ib_destroy_mr_pool(struct rds_ib_mr_pool *);
330 void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
331 struct rds_sock *rs, u32 *key_ret);
332 void rds_ib_sync_mr(void *trans_private, int dir);
333 void rds_ib_free_mr(void *trans_private, int invalidate);
334 void rds_ib_flush_mrs(void);
335 int rds_ib_fmr_init(void);
336 void rds_ib_fmr_exit(void);
337
338 /* ib_recv.c */
339 int rds_ib_recv_init(void);
340 void rds_ib_recv_exit(void);
341 int rds_ib_recv(struct rds_connection *conn);
342 int rds_ib_recv_alloc_caches(struct rds_ib_connection *ic);
343 void rds_ib_recv_free_caches(struct rds_ib_connection *ic);
344 void rds_ib_recv_refill(struct rds_connection *conn, int prefill, gfp_t gfp);
345 void rds_ib_inc_free(struct rds_incoming *inc);
346 int rds_ib_inc_copy_to_user(struct rds_incoming *inc, struct iov_iter *to);
347 void rds_ib_recv_cqe_handler(struct rds_ib_connection *ic, struct ib_wc *wc,
348 struct rds_ib_ack_state *state);
349 void rds_ib_recv_tasklet_fn(unsigned long data);
350 void rds_ib_recv_init_ring(struct rds_ib_connection *ic);
351 void rds_ib_recv_clear_ring(struct rds_ib_connection *ic);
352 void rds_ib_recv_init_ack(struct rds_ib_connection *ic);
353 void rds_ib_attempt_ack(struct rds_ib_connection *ic);
354 void rds_ib_ack_send_complete(struct rds_ib_connection *ic);
355 u64 rds_ib_piggyb_ack(struct rds_ib_connection *ic);
356 void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq, int ack_required);
357
358 /* ib_ring.c */
359 void rds_ib_ring_init(struct rds_ib_work_ring *ring, u32 nr);
360 void rds_ib_ring_resize(struct rds_ib_work_ring *ring, u32 nr);
361 u32 rds_ib_ring_alloc(struct rds_ib_work_ring *ring, u32 val, u32 *pos);
362 void rds_ib_ring_free(struct rds_ib_work_ring *ring, u32 val);
363 void rds_ib_ring_unalloc(struct rds_ib_work_ring *ring, u32 val);
364 int rds_ib_ring_empty(struct rds_ib_work_ring *ring);
365 int rds_ib_ring_low(struct rds_ib_work_ring *ring);
366 u32 rds_ib_ring_oldest(struct rds_ib_work_ring *ring);
367 u32 rds_ib_ring_completed(struct rds_ib_work_ring *ring, u32 wr_id, u32 oldest);
368 extern wait_queue_head_t rds_ib_ring_empty_wait;
369
370 /* ib_send.c */
371 void rds_ib_xmit_complete(struct rds_connection *conn);
372 int rds_ib_xmit(struct rds_connection *conn, struct rds_message *rm,
373 unsigned int hdr_off, unsigned int sg, unsigned int off);
374 void rds_ib_send_cq_comp_handler(struct ib_cq *cq, void *context);
375 void rds_ib_send_init_ring(struct rds_ib_connection *ic);
376 void rds_ib_send_clear_ring(struct rds_ib_connection *ic);
377 int rds_ib_xmit_rdma(struct rds_connection *conn, struct rm_rdma_op *op);
378 void rds_ib_send_add_credits(struct rds_connection *conn, unsigned int credits);
379 void rds_ib_advertise_credits(struct rds_connection *conn, unsigned int posted);
380 int rds_ib_send_grab_credits(struct rds_ib_connection *ic, u32 wanted,
381 u32 *adv_credits, int need_posted, int max_posted);
382 int rds_ib_xmit_atomic(struct rds_connection *conn, struct rm_atomic_op *op);
383
384 /* ib_stats.c */
385 DECLARE_PER_CPU(struct rds_ib_statistics, rds_ib_stats);
386 #define rds_ib_stats_inc(member) rds_stats_inc_which(rds_ib_stats, member)
387 unsigned int rds_ib_stats_info_copy(struct rds_info_iterator *iter,
388 unsigned int avail);
389
390 /* ib_sysctl.c */
391 int rds_ib_sysctl_init(void);
392 void rds_ib_sysctl_exit(void);
393 extern unsigned long rds_ib_sysctl_max_send_wr;
394 extern unsigned long rds_ib_sysctl_max_recv_wr;
395 extern unsigned long rds_ib_sysctl_max_unsig_wrs;
396 extern unsigned long rds_ib_sysctl_max_unsig_bytes;
397 extern unsigned long rds_ib_sysctl_max_recv_allocation;
398 extern unsigned int rds_ib_sysctl_flow_control;
399
400 #endif
This page took 0.045641 seconds and 6 git commands to generate.