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