]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/ofed/drivers/infiniband/ulp/sdp/sdp.h
Upgrade our copies of clang, llvm, lldb and compiler-rt to r311606 from
[FreeBSD/FreeBSD.git] / sys / ofed / drivers / infiniband / ulp / sdp / sdp.h
1 #ifndef _SDP_H_
2 #define _SDP_H_
3
4 #define LINUXKPI_PARAM_PREFIX ib_sdp_
5
6 #include "opt_ddb.h"
7 #include "opt_inet.h"
8 #include "opt_ofed.h"
9
10 #include <sys/param.h>
11 #include <sys/systm.h>
12 #include <sys/malloc.h>
13 #include <sys/kernel.h>
14 #include <sys/sysctl.h>
15 #include <sys/mbuf.h>
16 #include <sys/lock.h>
17 #include <sys/rwlock.h>
18 #include <sys/socket.h>
19 #include <sys/socketvar.h>
20 #include <sys/protosw.h>
21 #include <sys/proc.h>
22 #include <sys/jail.h>
23 #include <sys/domain.h>
24
25 #ifdef DDB
26 #include <ddb/ddb.h>
27 #endif
28
29 #include <net/if.h>
30 #include <net/if_var.h>
31 #include <net/route.h>
32 #include <net/vnet.h>
33
34 #include <netinet/in.h>
35 #include <netinet/in_systm.h>
36 #include <netinet/in_var.h>
37 #include <netinet/in_pcb.h>
38 #include <netinet/tcp.h>
39 #include <netinet/tcp_fsm.h>
40 #include <netinet/tcp_timer.h>
41 #include <netinet/tcp_var.h>
42
43 #include <linux/device.h>
44 #include <linux/err.h>
45 #include <linux/sched.h>
46 #include <linux/workqueue.h>
47 #include <linux/wait.h>
48 #include <linux/module.h>
49 #include <linux/moduleparam.h>
50 #include <linux/pci.h>
51
52 #include <rdma/ib_verbs.h>
53 #include <rdma/rdma_cm.h>
54 #include <rdma/ib_cm.h>
55 #include <rdma/sdp_socket.h>
56 #include <rdma/ib_fmr_pool.h>
57
58 #ifdef SDP_DEBUG
59 #define CONFIG_INFINIBAND_SDP_DEBUG
60 #endif
61
62 #include "sdp_dbg.h"
63
64 #undef LIST_HEAD
65 /* From sys/queue.h */
66 #define LIST_HEAD(name, type)                                           \
67 struct name {                                                           \
68         struct type *lh_first;  /* first element */                     \
69 }
70
71 /* Interval between successive polls in the Tx routine when polling is used
72    instead of interrupts (in per-core Tx rings) - should be power of 2 */
73 #define SDP_TX_POLL_MODER       16
74 #define SDP_TX_POLL_TIMEOUT     (HZ / 20)
75 #define SDP_NAGLE_TIMEOUT (HZ / 10)
76
77 #define SDP_SRCAVAIL_CANCEL_TIMEOUT (HZ * 5)
78 #define SDP_SRCAVAIL_ADV_TIMEOUT (1 * HZ)
79 #define SDP_SRCAVAIL_PAYLOAD_LEN 1
80
81 #define SDP_RESOLVE_TIMEOUT 1000
82 #define SDP_ROUTE_TIMEOUT 1000
83 #define SDP_RETRY_COUNT 5
84 #define SDP_KEEPALIVE_TIME (120 * 60 * HZ)
85 #define SDP_FIN_WAIT_TIMEOUT (60 * HZ) /* like TCP_FIN_TIMEOUT */
86
87 #define SDP_TX_SIZE 0x40
88 #define SDP_RX_SIZE 0x40
89
90 #define SDP_FMR_SIZE (MIN(0x1000, PAGE_SIZE) / sizeof(u64))
91 #define SDP_FMR_POOL_SIZE       1024
92 #define SDP_FMR_DIRTY_SIZE      ( SDP_FMR_POOL_SIZE / 4 )
93
94 #define SDP_MAX_RDMA_READ_LEN (PAGE_SIZE * (SDP_FMR_SIZE - 2))
95
96 /* mb inlined data len - rest will be rx'ed into frags */
97 #define SDP_HEAD_SIZE (sizeof(struct sdp_bsdh))
98
99 /* limit tx payload len, if the sink supports bigger buffers than the source
100  * can handle.
101  * or rx fragment size (limited by sge->length size) */
102 #define SDP_MAX_PACKET  (1 << 16)
103 #define SDP_MAX_PAYLOAD (SDP_MAX_PACKET - SDP_HEAD_SIZE)
104
105 #define SDP_MAX_RECV_SGES (SDP_MAX_PACKET / MCLBYTES)
106 #define SDP_MAX_SEND_SGES (SDP_MAX_PACKET / MCLBYTES) + 2
107
108 #define SDP_NUM_WC 4
109
110 #define SDP_DEF_ZCOPY_THRESH 64*1024
111 #define SDP_MIN_ZCOPY_THRESH PAGE_SIZE
112 #define SDP_MAX_ZCOPY_THRESH 1048576
113
114 #define SDP_OP_RECV 0x800000000LL
115 #define SDP_OP_SEND 0x400000000LL
116 #define SDP_OP_RDMA 0x200000000LL
117 #define SDP_OP_NOP  0x100000000LL
118
119 /* how long (in jiffies) to block sender till tx completion*/
120 #define SDP_BZCOPY_POLL_TIMEOUT (HZ / 10)
121
122 #define SDP_AUTO_CONF   0xffff
123 #define AUTO_MOD_DELAY (HZ / 4)
124
125 struct sdp_mb_cb {
126         __u32           seq;            /* Starting sequence number     */
127         struct bzcopy_state      *bz;
128         struct rx_srcavail_state *rx_sa;
129         struct tx_srcavail_state *tx_sa;
130 };
131
132 #define M_PUSH  M_PROTO1        /* Do a 'push'. */
133 #define M_URG   M_PROTO2        /* Mark as urgent (oob). */
134
135 #define SDP_SKB_CB(__mb)      ((struct sdp_mb_cb *)&((__mb)->cb[0]))
136 #define BZCOPY_STATE(mb)      (SDP_SKB_CB(mb)->bz)
137 #define RX_SRCAVAIL_STATE(mb) (SDP_SKB_CB(mb)->rx_sa)
138 #define TX_SRCAVAIL_STATE(mb) (SDP_SKB_CB(mb)->tx_sa)
139
140 #ifndef MIN
141 #define MIN(a, b) (a < b ? a : b)
142 #endif
143
144 #define ring_head(ring)   (atomic_read(&(ring).head))
145 #define ring_tail(ring)   (atomic_read(&(ring).tail))
146 #define ring_posted(ring) (ring_head(ring) - ring_tail(ring))
147
148 #define rx_ring_posted(ssk) ring_posted(ssk->rx_ring)
149 #ifdef SDP_ZCOPY
150 #define tx_ring_posted(ssk) (ring_posted(ssk->tx_ring) + \
151         (ssk->tx_ring.rdma_inflight ? ssk->tx_ring.rdma_inflight->busy : 0))
152 #else
153 #define tx_ring_posted(ssk) ring_posted(ssk->tx_ring)
154 #endif
155
156 extern int sdp_zcopy_thresh;
157 extern int rcvbuf_initial_size;
158 extern struct workqueue_struct *rx_comp_wq;
159 extern struct ib_client sdp_client;
160
161 enum sdp_mid {
162         SDP_MID_HELLO = 0x0,
163         SDP_MID_HELLO_ACK = 0x1,
164         SDP_MID_DISCONN = 0x2,
165         SDP_MID_ABORT = 0x3,
166         SDP_MID_SENDSM = 0x4,
167         SDP_MID_RDMARDCOMPL = 0x6,
168         SDP_MID_SRCAVAIL_CANCEL = 0x8,
169         SDP_MID_CHRCVBUF = 0xB,
170         SDP_MID_CHRCVBUF_ACK = 0xC,
171         SDP_MID_SINKAVAIL = 0xFD,
172         SDP_MID_SRCAVAIL = 0xFE,
173         SDP_MID_DATA = 0xFF,
174 };
175
176 enum sdp_flags {
177         SDP_OOB_PRES = 1 << 0,
178         SDP_OOB_PEND = 1 << 1,
179 };
180
181 enum {
182         SDP_MIN_TX_CREDITS = 2
183 };
184
185 enum {
186         SDP_ERR_ERROR   = -4,
187         SDP_ERR_FAULT   = -3,
188         SDP_NEW_SEG     = -2,
189         SDP_DO_WAIT_MEM = -1
190 };
191
192 struct sdp_bsdh {
193         u8 mid;
194         u8 flags;
195         __u16 bufs;
196         __u32 len;
197         __u32 mseq;
198         __u32 mseq_ack;
199 } __attribute__((__packed__));
200
201 union cma_ip_addr {
202         struct in6_addr ip6;
203         struct {
204                 __u32 pad[3];
205                 __u32 addr;
206         } ip4;
207 } __attribute__((__packed__));
208
209 /* TODO: too much? Can I avoid having the src/dst and port here? */
210 struct sdp_hh {
211         struct sdp_bsdh bsdh;
212         u8 majv_minv;
213         u8 ipv_cap;
214         u8 rsvd1;
215         u8 max_adverts;
216         __u32 desremrcvsz;
217         __u32 localrcvsz;
218         __u16 port;
219         __u16 rsvd2;
220         union cma_ip_addr src_addr;
221         union cma_ip_addr dst_addr;
222         u8 rsvd3[IB_CM_REQ_PRIVATE_DATA_SIZE - sizeof(struct sdp_bsdh) - 48];
223 } __attribute__((__packed__));
224
225 struct sdp_hah {
226         struct sdp_bsdh bsdh;
227         u8 majv_minv;
228         u8 ipv_cap;
229         u8 rsvd1;
230         u8 ext_max_adverts;
231         __u32 actrcvsz;
232         u8 rsvd2[IB_CM_REP_PRIVATE_DATA_SIZE - sizeof(struct sdp_bsdh) - 8];
233 } __attribute__((__packed__));
234
235 struct sdp_rrch {
236         __u32 len;
237 } __attribute__((__packed__));
238
239 struct sdp_srcah {
240         __u32 len;
241         __u32 rkey;
242         __u64 vaddr;
243 } __attribute__((__packed__));
244
245 struct sdp_buf {
246         struct mbuf *mb;
247         u64             mapping[SDP_MAX_SEND_SGES];
248 } __attribute__((__packed__));
249
250 struct sdp_chrecvbuf {
251         u32 size;
252 } __attribute__((__packed__));
253
254 /* Context used for synchronous zero copy bcopy (BZCOPY) */
255 struct bzcopy_state {
256         unsigned char __user  *u_base;
257         int                    u_len;
258         int                    left;
259         int                    page_cnt;
260         int                    cur_page;
261         int                    cur_offset;
262         int                    busy;
263         struct sdp_sock      *ssk;
264         struct page         **pages;
265 };
266
267 enum rx_sa_flag {
268         RX_SA_ABORTED    = 2,
269 };
270
271 enum tx_sa_flag {
272         TX_SA_SENDSM     = 0x01,
273         TX_SA_CROSS_SEND = 0x02,
274         TX_SA_INTRRUPTED = 0x04,
275         TX_SA_TIMEDOUT   = 0x08,
276         TX_SA_ERROR      = 0x10,
277 };
278
279 struct rx_srcavail_state {
280         /* Advertised buffer stuff */
281         u32 mseq;
282         u32 used;
283         u32 reported;
284         u32 len;
285         u32 rkey;
286         u64 vaddr;
287
288         /* Dest buff info */
289         struct ib_umem *umem;
290         struct ib_pool_fmr *fmr;
291
292         /* Utility */
293         u8  busy;
294         enum rx_sa_flag  flags;
295 };
296
297 struct tx_srcavail_state {
298         /* Data below 'busy' will be reset */
299         u8              busy;
300
301         struct ib_umem *umem;
302         struct ib_pool_fmr *fmr;
303
304         u32             bytes_sent;
305         u32             bytes_acked;
306
307         enum tx_sa_flag abort_flags;
308         u8              posted;
309
310         u32             mseq;
311 };
312
313 struct sdp_tx_ring {
314 #ifdef SDP_ZCOPY
315         struct rx_srcavail_state *rdma_inflight;
316 #endif
317         struct sdp_buf          *buffer;
318         atomic_t                head;
319         atomic_t                tail;
320         struct ib_cq            *cq;
321
322         atomic_t                credits;
323 #define tx_credits(ssk) (atomic_read(&ssk->tx_ring.credits))
324
325         struct callout          timer;
326         u16                     poll_cnt;
327 };
328
329 struct sdp_rx_ring {
330         struct sdp_buf   *buffer;
331         atomic_t          head;
332         atomic_t          tail;
333         struct ib_cq     *cq;
334
335         int              destroyed;
336         struct rwlock    destroyed_lock;
337 };
338
339 struct sdp_device {
340         struct ib_pd            *pd;
341         struct ib_mr            *mr;
342         struct ib_fmr_pool      *fmr_pool;
343 };
344
345 struct sdp_moderation {
346         unsigned long last_moder_packets;
347         unsigned long last_moder_tx_packets;
348         unsigned long last_moder_bytes;
349         unsigned long last_moder_jiffies;
350         int last_moder_time;
351         u16 rx_usecs;
352         u16 rx_frames;
353         u16 tx_usecs;
354         u32 pkt_rate_low;
355         u16 rx_usecs_low;
356         u32 pkt_rate_high;
357         u16 rx_usecs_high;
358         u16 sample_interval;
359         u16 adaptive_rx_coal;
360         u32 msg_enable;
361
362         int moder_cnt;
363         int moder_time;
364 };
365
366 /* These are flags fields. */
367 #define SDP_TIMEWAIT    0x0001          /* In ssk timewait state. */
368 #define SDP_DROPPED     0x0002          /* Socket has been dropped. */
369 #define SDP_SOCKREF     0x0004          /* Holding a sockref for close. */
370 #define SDP_NODELAY     0x0008          /* Disble nagle. */
371 #define SDP_NEEDFIN     0x0010          /* Send a fin on the next tx. */
372 #define SDP_DREQWAIT    0x0020          /* Waiting on DREQ. */
373 #define SDP_DESTROY     0x0040          /* Being destroyed. */
374 #define SDP_DISCON      0x0080          /* rdma_disconnect is owed. */
375
376 /* These are oobflags */
377 #define SDP_HADOOB      0x0001          /* Had OOB data. */
378 #define SDP_HAVEOOB     0x0002          /* Have OOB data. */
379
380 struct sdp_sock {
381         LIST_ENTRY(sdp_sock) list;
382         struct socket *socket;
383         struct rdma_cm_id *id;
384         struct ib_device *ib_device;
385         struct sdp_device *sdp_dev;
386         struct ib_qp *qp;
387         struct ucred *cred;
388         struct callout keep2msl;        /* 2msl and keepalive timer. */
389         struct callout nagle_timer;     /* timeout waiting for ack */
390         struct ib_ucontext context;
391         in_port_t lport;
392         in_addr_t laddr;
393         in_port_t fport;
394         in_addr_t faddr;
395         int flags;
396         int oobflags;           /* protected by rx lock. */
397         int state;
398         int softerror;
399         int recv_bytes;         /* Bytes per recv. buf including header */
400         int xmit_size_goal;
401         char iobc;
402
403         struct sdp_rx_ring rx_ring;
404         struct sdp_tx_ring tx_ring;
405         struct rwlock   lock;
406         struct mbufq    rxctlq;         /* received control packets */
407
408         int qp_active;  /* XXX Flag. */
409         int max_sge;
410         struct work_struct rx_comp_work;
411 #define rcv_nxt(ssk) atomic_read(&(ssk->rcv_nxt))
412         atomic_t rcv_nxt;
413
414         /* SDP specific */
415         atomic_t mseq_ack;
416 #define mseq_ack(ssk) (atomic_read(&ssk->mseq_ack))
417         unsigned max_bufs;      /* Initial buffers offered by other side */
418         unsigned min_bufs;      /* Low water mark to wake senders */
419
420         unsigned long nagle_last_unacked; /* mseq of lastest unacked packet */
421
422         atomic_t               remote_credits;
423 #define remote_credits(ssk) (atomic_read(&ssk->remote_credits))
424         int               poll_cq;
425
426         /* SDP slow start */
427         int recv_request_head;  /* mark the rx_head when the resize request
428                                    was received */
429         int recv_request;       /* XXX flag if request to resize was received */
430
431         unsigned long tx_packets;
432         unsigned long rx_packets;
433         unsigned long tx_bytes;
434         unsigned long rx_bytes;
435         struct sdp_moderation auto_mod;
436         struct task shutdown_task;
437 #ifdef SDP_ZCOPY
438         struct tx_srcavail_state *tx_sa;
439         struct rx_srcavail_state *rx_sa;
440         spinlock_t tx_sa_lock;
441         struct delayed_work srcavail_cancel_work;
442         int srcavail_cancel_mseq;
443         /* ZCOPY data: -1:use global; 0:disable zcopy; >0: zcopy threshold */
444         int zcopy_thresh;
445 #endif
446 };
447
448 #define sdp_sk(so)      ((struct sdp_sock *)(so->so_pcb))
449
450 #define SDP_RLOCK(ssk)          rw_rlock(&(ssk)->lock)
451 #define SDP_WLOCK(ssk)          rw_wlock(&(ssk)->lock)
452 #define SDP_RUNLOCK(ssk)        rw_runlock(&(ssk)->lock)
453 #define SDP_WUNLOCK(ssk)        rw_wunlock(&(ssk)->lock)
454 #define SDP_WLOCK_ASSERT(ssk)   rw_assert(&(ssk)->lock, RA_WLOCKED)
455 #define SDP_RLOCK_ASSERT(ssk)   rw_assert(&(ssk)->lock, RA_RLOCKED)
456 #define SDP_LOCK_ASSERT(ssk)    rw_assert(&(ssk)->lock, RA_LOCKED)
457
458 MALLOC_DECLARE(M_SDP);
459
460 static inline void tx_sa_reset(struct tx_srcavail_state *tx_sa)
461 {
462         memset((void *)&tx_sa->busy, 0,
463                         sizeof(*tx_sa) - offsetof(typeof(*tx_sa), busy));
464 }
465
466 static inline void rx_ring_unlock(struct sdp_rx_ring *rx_ring)
467 {
468         rw_runlock(&rx_ring->destroyed_lock);
469 }
470
471 static inline int rx_ring_trylock(struct sdp_rx_ring *rx_ring)
472 {
473         rw_rlock(&rx_ring->destroyed_lock);
474         if (rx_ring->destroyed) {
475                 rx_ring_unlock(rx_ring);
476                 return 0;
477         }
478         return 1;
479 }
480
481 static inline void rx_ring_destroy_lock(struct sdp_rx_ring *rx_ring)
482 {
483         rw_wlock(&rx_ring->destroyed_lock);
484         rx_ring->destroyed = 1;
485         rw_wunlock(&rx_ring->destroyed_lock);
486 }
487
488 static inline void sdp_arm_rx_cq(struct sdp_sock *ssk)
489 {
490         sdp_prf(ssk->socket, NULL, "Arming RX cq");
491         sdp_dbg_data(ssk->socket, "Arming RX cq\n");
492
493         ib_req_notify_cq(ssk->rx_ring.cq, IB_CQ_NEXT_COMP);
494 }
495
496 static inline void sdp_arm_tx_cq(struct sdp_sock *ssk)
497 {
498         sdp_prf(ssk->socket, NULL, "Arming TX cq");
499         sdp_dbg_data(ssk->socket, "Arming TX cq. credits: %d, posted: %d\n",
500                 tx_credits(ssk), tx_ring_posted(ssk));
501
502         ib_req_notify_cq(ssk->tx_ring.cq, IB_CQ_NEXT_COMP);
503 }
504
505 /* return the min of:
506  * - tx credits
507  * - free slots in tx_ring (not including SDP_MIN_TX_CREDITS
508  */
509 static inline int tx_slots_free(struct sdp_sock *ssk)
510 {
511         int min_free;
512
513         min_free = MIN(tx_credits(ssk),
514                         SDP_TX_SIZE - tx_ring_posted(ssk));
515         if (min_free < SDP_MIN_TX_CREDITS)
516                 return 0;
517
518         return min_free - SDP_MIN_TX_CREDITS;
519 };
520
521 /* utilities */
522 static inline char *mid2str(int mid)
523 {
524 #define ENUM2STR(e) [e] = #e
525         static char *mid2str[] = {
526                 ENUM2STR(SDP_MID_HELLO),
527                 ENUM2STR(SDP_MID_HELLO_ACK),
528                 ENUM2STR(SDP_MID_ABORT),
529                 ENUM2STR(SDP_MID_DISCONN),
530                 ENUM2STR(SDP_MID_SENDSM),
531                 ENUM2STR(SDP_MID_RDMARDCOMPL),
532                 ENUM2STR(SDP_MID_SRCAVAIL_CANCEL),
533                 ENUM2STR(SDP_MID_CHRCVBUF),
534                 ENUM2STR(SDP_MID_CHRCVBUF_ACK),
535                 ENUM2STR(SDP_MID_DATA),
536                 ENUM2STR(SDP_MID_SRCAVAIL),
537                 ENUM2STR(SDP_MID_SINKAVAIL),
538         };
539
540         if (mid >= ARRAY_SIZE(mid2str))
541                 return NULL;
542
543         return mid2str[mid];
544 }
545
546 static inline struct mbuf *
547 sdp_alloc_mb(struct socket *sk, u8 mid, int size, int wait)
548 {
549         struct sdp_bsdh *h;
550         struct mbuf *mb;
551
552         MGETHDR(mb, wait, MT_DATA);
553         if (mb == NULL)
554                 return (NULL);
555         mb->m_pkthdr.len = mb->m_len = sizeof(struct sdp_bsdh);
556         h = mtod(mb, struct sdp_bsdh *);
557         h->mid = mid;
558
559         return mb;
560 }
561 static inline struct mbuf *
562 sdp_alloc_mb_data(struct socket *sk, int wait)
563 {
564         return sdp_alloc_mb(sk, SDP_MID_DATA, 0, wait);
565 }
566
567 static inline struct mbuf *
568 sdp_alloc_mb_disconnect(struct socket *sk, int wait)
569 {
570         return sdp_alloc_mb(sk, SDP_MID_DISCONN, 0, wait);
571 }
572
573 static inline void *
574 mb_put(struct mbuf *mb, int len)
575 {
576         uint8_t *data;
577
578         data = mb->m_data;
579         data += mb->m_len;
580         mb->m_len += len;
581         return (void *)data;
582 }
583
584 static inline struct mbuf *
585 sdp_alloc_mb_chrcvbuf_ack(struct socket *sk, int size, int wait)
586 {
587         struct mbuf *mb;
588         struct sdp_chrecvbuf *resp_size;
589
590         mb = sdp_alloc_mb(sk, SDP_MID_CHRCVBUF_ACK, sizeof(*resp_size), wait);
591         if (mb == NULL)
592                 return (NULL);
593         resp_size = (struct sdp_chrecvbuf *)mb_put(mb, sizeof *resp_size);
594         resp_size->size = htonl(size);
595
596         return mb;
597 }
598
599 static inline struct mbuf *
600 sdp_alloc_mb_srcavail(struct socket *sk, u32 len, u32 rkey, u64 vaddr, int wait)
601 {
602         struct mbuf *mb;
603         struct sdp_srcah *srcah;
604
605         mb = sdp_alloc_mb(sk, SDP_MID_SRCAVAIL, sizeof(*srcah), wait);
606         if (mb == NULL)
607                 return (NULL);
608         srcah = (struct sdp_srcah *)mb_put(mb, sizeof(*srcah));
609         srcah->len = htonl(len);
610         srcah->rkey = htonl(rkey);
611         srcah->vaddr = cpu_to_be64(vaddr);
612
613         return mb;
614 }
615
616 static inline struct mbuf *
617 sdp_alloc_mb_srcavail_cancel(struct socket *sk, int wait)
618 {
619         return sdp_alloc_mb(sk, SDP_MID_SRCAVAIL_CANCEL, 0, wait);
620 }
621
622 static inline struct mbuf *
623 sdp_alloc_mb_rdmardcompl(struct socket *sk, u32 len, int wait)
624 {
625         struct mbuf *mb;
626         struct sdp_rrch *rrch;
627
628         mb = sdp_alloc_mb(sk, SDP_MID_RDMARDCOMPL, sizeof(*rrch), wait);
629         if (mb == NULL)
630                 return (NULL);
631         rrch = (struct sdp_rrch *)mb_put(mb, sizeof(*rrch));
632         rrch->len = htonl(len);
633
634         return mb;
635 }
636
637 static inline struct mbuf *
638 sdp_alloc_mb_sendsm(struct socket *sk, int wait)
639 {
640         return sdp_alloc_mb(sk, SDP_MID_SENDSM, 0, wait);
641 }
642 static inline int sdp_tx_ring_slots_left(struct sdp_sock *ssk)
643 {
644         return SDP_TX_SIZE - tx_ring_posted(ssk);
645 }
646
647 static inline int credit_update_needed(struct sdp_sock *ssk)
648 {
649         int c;
650
651         c = remote_credits(ssk);
652         if (likely(c > SDP_MIN_TX_CREDITS))
653                 c += c/2;
654         return unlikely(c < rx_ring_posted(ssk)) &&
655             likely(tx_credits(ssk) > 0) &&
656             likely(sdp_tx_ring_slots_left(ssk));
657 }
658
659
660 #define SDPSTATS_COUNTER_INC(stat)
661 #define SDPSTATS_COUNTER_ADD(stat, val)
662 #define SDPSTATS_COUNTER_MID_INC(stat, mid)
663 #define SDPSTATS_HIST_LINEAR(stat, size)
664 #define SDPSTATS_HIST(stat, size)
665
666 static inline void
667 sdp_cleanup_sdp_buf(struct sdp_sock *ssk, struct sdp_buf *sbuf,
668     enum dma_data_direction dir)
669 {
670         struct ib_device *dev;
671         struct mbuf *mb;
672         int i;
673
674         dev = ssk->ib_device;
675         for (i = 0, mb = sbuf->mb; mb != NULL; mb = mb->m_next, i++)
676                 ib_dma_unmap_single(dev, sbuf->mapping[i], mb->m_len, dir);
677 }
678
679 /* sdp_main.c */
680 void sdp_set_default_moderation(struct sdp_sock *ssk);
681 void sdp_start_keepalive_timer(struct socket *sk);
682 void sdp_urg(struct sdp_sock *ssk, struct mbuf *mb);
683 void sdp_cancel_dreq_wait_timeout(struct sdp_sock *ssk);
684 void sdp_abort(struct socket *sk);
685 struct sdp_sock *sdp_notify(struct sdp_sock *ssk, int error);
686
687
688 /* sdp_cma.c */
689 int sdp_cma_handler(struct rdma_cm_id *, struct rdma_cm_event *);
690
691 /* sdp_tx.c */
692 int sdp_tx_ring_create(struct sdp_sock *ssk, struct ib_device *device);
693 void sdp_tx_ring_destroy(struct sdp_sock *ssk);
694 int sdp_xmit_poll(struct sdp_sock *ssk, int force);
695 void sdp_post_send(struct sdp_sock *ssk, struct mbuf *mb);
696 void sdp_post_sends(struct sdp_sock *ssk, int wait);
697 void sdp_post_keepalive(struct sdp_sock *ssk);
698
699 /* sdp_rx.c */
700 void sdp_rx_ring_init(struct sdp_sock *ssk);
701 int sdp_rx_ring_create(struct sdp_sock *ssk, struct ib_device *device);
702 void sdp_rx_ring_destroy(struct sdp_sock *ssk);
703 int sdp_resize_buffers(struct sdp_sock *ssk, u32 new_size);
704 int sdp_init_buffers(struct sdp_sock *ssk, u32 new_size);
705 void sdp_do_posts(struct sdp_sock *ssk);
706 void sdp_rx_comp_full(struct sdp_sock *ssk);
707
708 /* sdp_zcopy.c */
709 struct kiocb;
710 int sdp_sendmsg_zcopy(struct kiocb *iocb, struct socket *sk, struct iovec *iov);
711 int sdp_handle_srcavail(struct sdp_sock *ssk, struct sdp_srcah *srcah);
712 void sdp_handle_sendsm(struct sdp_sock *ssk, u32 mseq_ack);
713 void sdp_handle_rdma_read_compl(struct sdp_sock *ssk, u32 mseq_ack,
714                 u32 bytes_completed);
715 int sdp_handle_rdma_read_cqe(struct sdp_sock *ssk);
716 int sdp_rdma_to_iovec(struct socket *sk, struct iovec *iov, struct mbuf *mb,
717                 unsigned long *used);
718 int sdp_post_rdma_rd_compl(struct sdp_sock *ssk,
719                 struct rx_srcavail_state *rx_sa);
720 int sdp_post_sendsm(struct socket *sk);
721 void srcavail_cancel_timeout(struct work_struct *work);
722 void sdp_abort_srcavail(struct socket *sk);
723 void sdp_abort_rdma_read(struct socket *sk);
724 int sdp_process_rx(struct sdp_sock *ssk);
725
726 #endif