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