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 mbuf *rx_ctl_q; 407 struct mbuf *rx_ctl_tail; 408 409 int qp_active; /* XXX Flag. */ 410 int max_sge; 411 struct work_struct rx_comp_work; 412 #define rcv_nxt(ssk) atomic_read(&(ssk->rcv_nxt)) 413 atomic_t rcv_nxt; 414 415 /* SDP specific */ 416 atomic_t mseq_ack; 417 #define mseq_ack(ssk) (atomic_read(&ssk->mseq_ack)) 418 unsigned max_bufs; /* Initial buffers offered by other side */ 419 unsigned min_bufs; /* Low water mark to wake senders */ 420 421 unsigned long nagle_last_unacked; /* mseq of lastest unacked packet */ 422 423 atomic_t remote_credits; 424 #define remote_credits(ssk) (atomic_read(&ssk->remote_credits)) 425 int poll_cq; 426 427 /* SDP slow start */ 428 int recv_request_head; /* mark the rx_head when the resize request 429 was received */ 430 int recv_request; /* XXX flag if request to resize was received */ 431 432 unsigned long tx_packets; 433 unsigned long rx_packets; 434 unsigned long tx_bytes; 435 unsigned long rx_bytes; 436 struct sdp_moderation auto_mod; 437 struct task shutdown_task; 438 #ifdef SDP_ZCOPY 439 struct tx_srcavail_state *tx_sa; 440 struct rx_srcavail_state *rx_sa; 441 spinlock_t tx_sa_lock; 442 struct delayed_work srcavail_cancel_work; 443 int srcavail_cancel_mseq; 444 /* ZCOPY data: -1:use global; 0:disable zcopy; >0: zcopy threshold */ 445 int zcopy_thresh; 446 #endif 447 }; 448 449 #define sdp_sk(so) ((struct sdp_sock *)(so->so_pcb)) 450 451 #define SDP_RLOCK(ssk) rw_rlock(&(ssk)->lock) 452 #define SDP_WLOCK(ssk) rw_wlock(&(ssk)->lock) 453 #define SDP_RUNLOCK(ssk) rw_runlock(&(ssk)->lock) 454 #define SDP_WUNLOCK(ssk) rw_wunlock(&(ssk)->lock) 455 #define SDP_WLOCK_ASSERT(ssk) rw_assert(&(ssk)->lock, RA_WLOCKED) 456 #define SDP_RLOCK_ASSERT(ssk) rw_assert(&(ssk)->lock, RA_RLOCKED) 457 #define SDP_LOCK_ASSERT(ssk) rw_assert(&(ssk)->lock, RA_LOCKED) 458 459 static inline void tx_sa_reset(struct tx_srcavail_state *tx_sa) 460 { 461 memset((void *)&tx_sa->busy, 0, 462 sizeof(*tx_sa) - offsetof(typeof(*tx_sa), busy)); 463 } 464 465 static inline void rx_ring_unlock(struct sdp_rx_ring *rx_ring) 466 { 467 rw_runlock(&rx_ring->destroyed_lock); 468 } 469 470 static inline int rx_ring_trylock(struct sdp_rx_ring *rx_ring) 471 { 472 rw_rlock(&rx_ring->destroyed_lock); 473 if (rx_ring->destroyed) { 474 rx_ring_unlock(rx_ring); 475 return 0; 476 } 477 return 1; 478 } 479 480 static inline void rx_ring_destroy_lock(struct sdp_rx_ring *rx_ring) 481 { 482 rw_wlock(&rx_ring->destroyed_lock); 483 rx_ring->destroyed = 1; 484 rw_wunlock(&rx_ring->destroyed_lock); 485 } 486 487 static inline void sdp_arm_rx_cq(struct sdp_sock *ssk) 488 { 489 sdp_prf(ssk->socket, NULL, "Arming RX cq"); 490 sdp_dbg_data(ssk->socket, "Arming RX cq\n"); 491 492 ib_req_notify_cq(ssk->rx_ring.cq, IB_CQ_NEXT_COMP); 493 } 494 495 static inline void sdp_arm_tx_cq(struct sdp_sock *ssk) 496 { 497 sdp_prf(ssk->socket, NULL, "Arming TX cq"); 498 sdp_dbg_data(ssk->socket, "Arming TX cq. credits: %d, posted: %d\n", 499 tx_credits(ssk), tx_ring_posted(ssk)); 500 501 ib_req_notify_cq(ssk->tx_ring.cq, IB_CQ_NEXT_COMP); 502 } 503 504 /* return the min of: 505 * - tx credits 506 * - free slots in tx_ring (not including SDP_MIN_TX_CREDITS 507 */ 508 static inline int tx_slots_free(struct sdp_sock *ssk) 509 { 510 int min_free; 511 512 min_free = MIN(tx_credits(ssk), 513 SDP_TX_SIZE - tx_ring_posted(ssk)); 514 if (min_free < SDP_MIN_TX_CREDITS) 515 return 0; 516 517 return min_free - SDP_MIN_TX_CREDITS; 518 }; 519 520 /* utilities */ 521 static inline char *mid2str(int mid) 522 { 523 #define ENUM2STR(e) [e] = #e 524 static char *mid2str[] = { 525 ENUM2STR(SDP_MID_HELLO), 526 ENUM2STR(SDP_MID_HELLO_ACK), 527 ENUM2STR(SDP_MID_ABORT), 528 ENUM2STR(SDP_MID_DISCONN), 529 ENUM2STR(SDP_MID_SENDSM), 530 ENUM2STR(SDP_MID_RDMARDCOMPL), 531 ENUM2STR(SDP_MID_SRCAVAIL_CANCEL), 532 ENUM2STR(SDP_MID_CHRCVBUF), 533 ENUM2STR(SDP_MID_CHRCVBUF_ACK), 534 ENUM2STR(SDP_MID_DATA), 535 ENUM2STR(SDP_MID_SRCAVAIL), 536 ENUM2STR(SDP_MID_SINKAVAIL), 537 }; 538 539 if (mid >= ARRAY_SIZE(mid2str)) 540 return NULL; 541 542 return mid2str[mid]; 543 } 544 545 static inline struct mbuf * 546 sdp_alloc_mb(struct socket *sk, u8 mid, int size, int wait) 547 { 548 struct sdp_bsdh *h; 549 struct mbuf *mb; 550 551 MGETHDR(mb, wait, MT_DATA); 552 if (mb == NULL) 553 return (NULL); 554 mb->m_pkthdr.len = mb->m_len = sizeof(struct sdp_bsdh); 555 h = mtod(mb, struct sdp_bsdh *); 556 h->mid = mid; 557 558 return mb; 559 } 560 static inline struct mbuf * 561 sdp_alloc_mb_data(struct socket *sk, int wait) 562 { 563 return sdp_alloc_mb(sk, SDP_MID_DATA, 0, wait); 564 } 565 566 static inline struct mbuf * 567 sdp_alloc_mb_disconnect(struct socket *sk, int wait) 568 { 569 return sdp_alloc_mb(sk, SDP_MID_DISCONN, 0, wait); 570 } 571 572 static inline void * 573 mb_put(struct mbuf *mb, int len) 574 { 575 uint8_t *data; 576 577 data = mb->m_data; 578 data += mb->m_len; 579 mb->m_len += len; 580 return (void *)data; 581 } 582 583 static inline struct mbuf * 584 sdp_alloc_mb_chrcvbuf_ack(struct socket *sk, int size, int wait) 585 { 586 struct mbuf *mb; 587 struct sdp_chrecvbuf *resp_size; 588 589 mb = sdp_alloc_mb(sk, SDP_MID_CHRCVBUF_ACK, sizeof(*resp_size), wait); 590 if (mb == NULL) 591 return (NULL); 592 resp_size = (struct sdp_chrecvbuf *)mb_put(mb, sizeof *resp_size); 593 resp_size->size = htonl(size); 594 595 return mb; 596 } 597 598 static inline struct mbuf * 599 sdp_alloc_mb_srcavail(struct socket *sk, u32 len, u32 rkey, u64 vaddr, int wait) 600 { 601 struct mbuf *mb; 602 struct sdp_srcah *srcah; 603 604 mb = sdp_alloc_mb(sk, SDP_MID_SRCAVAIL, sizeof(*srcah), wait); 605 if (mb == NULL) 606 return (NULL); 607 srcah = (struct sdp_srcah *)mb_put(mb, sizeof(*srcah)); 608 srcah->len = htonl(len); 609 srcah->rkey = htonl(rkey); 610 srcah->vaddr = cpu_to_be64(vaddr); 611 612 return mb; 613 } 614 615 static inline struct mbuf * 616 sdp_alloc_mb_srcavail_cancel(struct socket *sk, int wait) 617 { 618 return sdp_alloc_mb(sk, SDP_MID_SRCAVAIL_CANCEL, 0, wait); 619 } 620 621 static inline struct mbuf * 622 sdp_alloc_mb_rdmardcompl(struct socket *sk, u32 len, int wait) 623 { 624 struct mbuf *mb; 625 struct sdp_rrch *rrch; 626 627 mb = sdp_alloc_mb(sk, SDP_MID_RDMARDCOMPL, sizeof(*rrch), wait); 628 if (mb == NULL) 629 return (NULL); 630 rrch = (struct sdp_rrch *)mb_put(mb, sizeof(*rrch)); 631 rrch->len = htonl(len); 632 633 return mb; 634 } 635 636 static inline struct mbuf * 637 sdp_alloc_mb_sendsm(struct socket *sk, int wait) 638 { 639 return sdp_alloc_mb(sk, SDP_MID_SENDSM, 0, wait); 640 } 641 static inline int sdp_tx_ring_slots_left(struct sdp_sock *ssk) 642 { 643 return SDP_TX_SIZE - tx_ring_posted(ssk); 644 } 645 646 static inline int credit_update_needed(struct sdp_sock *ssk) 647 { 648 int c; 649 650 c = remote_credits(ssk); 651 if (likely(c > SDP_MIN_TX_CREDITS)) 652 c += c/2; 653 return unlikely(c < rx_ring_posted(ssk)) && 654 likely(tx_credits(ssk) > 0) && 655 likely(sdp_tx_ring_slots_left(ssk)); 656 } 657 658 659 #define SDPSTATS_COUNTER_INC(stat) 660 #define SDPSTATS_COUNTER_ADD(stat, val) 661 #define SDPSTATS_COUNTER_MID_INC(stat, mid) 662 #define SDPSTATS_HIST_LINEAR(stat, size) 663 #define SDPSTATS_HIST(stat, size) 664 665 static inline void 666 sdp_cleanup_sdp_buf(struct sdp_sock *ssk, struct sdp_buf *sbuf, 667 enum dma_data_direction dir) 668 { 669 struct ib_device *dev; 670 struct mbuf *mb; 671 int i; 672 673 dev = ssk->ib_device; 674 for (i = 0, mb = sbuf->mb; mb != NULL; mb = mb->m_next, i++) 675 ib_dma_unmap_single(dev, sbuf->mapping[i], mb->m_len, dir); 676 } 677 678 /* sdp_main.c */ 679 void sdp_set_default_moderation(struct sdp_sock *ssk); 680 void sdp_start_keepalive_timer(struct socket *sk); 681 void sdp_urg(struct sdp_sock *ssk, struct mbuf *mb); 682 void sdp_cancel_dreq_wait_timeout(struct sdp_sock *ssk); 683 void sdp_abort(struct socket *sk); 684 struct sdp_sock *sdp_notify(struct sdp_sock *ssk, int error); 685 686 687 /* sdp_cma.c */ 688 int sdp_cma_handler(struct rdma_cm_id *, struct rdma_cm_event *); 689 690 /* sdp_tx.c */ 691 int sdp_tx_ring_create(struct sdp_sock *ssk, struct ib_device *device); 692 void sdp_tx_ring_destroy(struct sdp_sock *ssk); 693 int sdp_xmit_poll(struct sdp_sock *ssk, int force); 694 void sdp_post_send(struct sdp_sock *ssk, struct mbuf *mb); 695 void sdp_post_sends(struct sdp_sock *ssk, int wait); 696 void sdp_post_keepalive(struct sdp_sock *ssk); 697 698 /* sdp_rx.c */ 699 void sdp_rx_ring_init(struct sdp_sock *ssk); 700 int sdp_rx_ring_create(struct sdp_sock *ssk, struct ib_device *device); 701 void sdp_rx_ring_destroy(struct sdp_sock *ssk); 702 int sdp_resize_buffers(struct sdp_sock *ssk, u32 new_size); 703 int sdp_init_buffers(struct sdp_sock *ssk, u32 new_size); 704 void sdp_do_posts(struct sdp_sock *ssk); 705 void sdp_rx_comp_full(struct sdp_sock *ssk); 706 707 /* sdp_zcopy.c */ 708 struct kiocb; 709 int sdp_sendmsg_zcopy(struct kiocb *iocb, struct socket *sk, struct iovec *iov); 710 int sdp_handle_srcavail(struct sdp_sock *ssk, struct sdp_srcah *srcah); 711 void sdp_handle_sendsm(struct sdp_sock *ssk, u32 mseq_ack); 712 void sdp_handle_rdma_read_compl(struct sdp_sock *ssk, u32 mseq_ack, 713 u32 bytes_completed); 714 int sdp_handle_rdma_read_cqe(struct sdp_sock *ssk); 715 int sdp_rdma_to_iovec(struct socket *sk, struct iovec *iov, struct mbuf *mb, 716 unsigned long *used); 717 int sdp_post_rdma_rd_compl(struct sdp_sock *ssk, 718 struct rx_srcavail_state *rx_sa); 719 int sdp_post_sendsm(struct socket *sk); 720 void srcavail_cancel_timeout(struct work_struct *work); 721 void sdp_abort_srcavail(struct socket *sk); 722 void sdp_abort_rdma_read(struct socket *sk); 723 int sdp_process_rx(struct sdp_sock *ssk); 724 725 #endif 726