51 #include <linux/pci.h>
52 #include <linux/slab.h>
61 # define RPCDBG_FACILITY RPCDBG_TRANS
78 rpcrdma_run_tasklet(
unsigned long data)
86 while (!list_empty(&rpcrdma_tasklets_g)) {
92 spin_unlock_irqrestore(&rpcrdma_tk_lock_g, flags);
101 spin_unlock_irqrestore(&rpcrdma_tk_lock_g, flags);
113 spin_unlock_irqrestore(&rpcrdma_tk_lock_g, flags);
114 tasklet_schedule(&rpcrdma_tasklet_g);
122 dprintk(
"RPC: %s: QP error %X on device %s ep %p\n",
123 __func__, event->
event, event->
device->name, context);
132 rpcrdma_cq_async_error_upcall(
struct ib_event *event,
void *context)
136 dprintk(
"RPC: %s: CQ error %X on device %s ep %p\n",
137 __func__, event->
event, event->
device->name, context);
146 void rpcrdma_event_process(
struct ib_wc *
wc)
148 struct rpcrdma_mw *frmr;
152 dprintk(
"RPC: %s: event rep %p status %X opcode %X length %u\n",
159 dprintk(
"RPC: %s: WC opcode %d status %X, connection lost\n",
163 rpcrdma_schedule_tasklet(rep);
169 frmr = (
struct rpcrdma_mw *)(
unsigned long)wc->
wr_id;
170 frmr->r.frmr.state = FRMR_IS_VALID;
173 frmr = (
struct rpcrdma_mw *)(
unsigned long)wc->
wr_id;
174 frmr->r.frmr.state = FRMR_IS_INVALID;
178 ib_dma_sync_single_for_cpu(
188 " dropped credits to 0!\n", __func__);
191 }
else if (credits > rep->
rr_buffer->rb_max_requests) {
193 " over-crediting: %d (%d)\n",
196 credits = rep->
rr_buffer->rb_max_requests;
202 rpcrdma_schedule_tasklet(rep);
205 dprintk(
"RPC: %s: unexpected WC event %X\n",
212 rpcrdma_cq_poll(
struct ib_cq *cq)
218 rc = ib_poll_cq(cq, 1, &wc);
220 dprintk(
"RPC: %s: ib_poll_cq failed %i\n",
227 rpcrdma_event_process(&wc);
249 rpcrdma_cq_event_upcall(
struct ib_cq *cq,
void *context)
253 rc = rpcrdma_cq_poll(cq);
259 dprintk(
"RPC: %s: ib_req_notify_cq failed %i\n",
268 static const char *
const conn[] = {
297 switch (event->
event) {
305 dprintk(
"RPC: %s: CM address resolution error, ep 0x%p\n",
311 dprintk(
"RPC: %s: CM route resolution error, ep 0x%p\n",
320 dprintk(
"RPC: %s: %d responder resources"
322 __func__,
attr.max_dest_rd_atomic,
attr.max_rd_atomic);
339 dprintk(
"RPC: %s: %s: %pI4:%u (ep 0x%p event 0x%x)\n",
342 "unknown connection error",
347 dprintk(
"RPC: %s: %sconnected\n",
348 __func__, connstate > 0 ?
"" :
"dis");
354 dprintk(
"RPC: %s: unexpected CM event %d\n",
355 __func__, event->
event);
360 if (connstate == 1) {
361 int ird =
attr.max_dest_rd_atomic;
364 "on %s, memreg %d slots %d ird %d%s\n",
367 ia->
ri_id->device->name,
369 xprt->
rx_buf.rb_max_requests,
370 ird, ird < 4 && ird < tird / 2 ?
" (low!)" :
"");
371 }
else if (connstate < 0) {
394 dprintk(
"RPC: %s: rdma_create_id() failed %i\n",
402 dprintk(
"RPC: %s: rdma_resolve_addr() failed %i\n",
415 dprintk(
"RPC: %s: rdma_resolve_route() failed %i\n",
436 rpcrdma_clean_cq(
struct ib_cq *cq)
441 while (1 == ib_poll_cq(cq, 1, &wc))
445 dprintk(
"RPC: %s: flushed %d events (last 0x%x)\n",
446 __func__, count, wc.
opcode);
465 ia->
ri_id = rpcrdma_create_id(xprt, ia, addr);
466 if (IS_ERR(ia->
ri_id)) {
467 rc = PTR_ERR(ia->
ri_id);
472 if (IS_ERR(ia->
ri_pd)) {
473 rc = PTR_ERR(ia->
ri_pd);
474 dprintk(
"RPC: %s: ib_alloc_pd() failed %i\n",
486 dprintk(
"RPC: %s: ib_query_device failed %d\n",
500 dprintk(
"RPC: %s: MEMWINDOWS registration "
501 "specified but not supported by adapter, "
502 "using slower RPCRDMA_REGISTER\n",
508 if (!ia->
ri_id->device->alloc_fmr) {
509 #if RPCRDMA_PERSISTENT_REGISTRATION
510 dprintk(
"RPC: %s: MTHCAFMR registration "
511 "specified but not supported by adapter, "
512 "using riskier RPCRDMA_ALLPHYSICAL\n",
516 dprintk(
"RPC: %s: MTHCAFMR registration "
517 "specified but not supported by adapter, "
518 "using slower RPCRDMA_REGISTER\n",
529 #if RPCRDMA_PERSISTENT_REGISTRATION
530 dprintk(
"RPC: %s: FRMR registration "
531 "specified but not supported by adapter, "
532 "using riskier RPCRDMA_ALLPHYSICAL\n",
536 dprintk(
"RPC: %s: FRMR registration "
537 "specified but not supported by adapter, "
538 "using slower RPCRDMA_REGISTER\n",
559 #if RPCRDMA_PERSISTENT_REGISTRATION
579 "phys register failed with %lX\n\t"
580 "Will continue with degraded performance\n",
592 dprintk(
"RPC: %s: memory registration strategy is %d\n",
616 dprintk(
"RPC: %s: entering\n", __func__);
619 dprintk(
"RPC: %s: ib_dereg_mr returned %i\n",
630 dprintk(
"RPC: %s: ib_dealloc_pd returned %i\n",
647 dprintk(
"RPC: %s: ib_query_device failed %d\n",
656 ep->
rep_attr.event_handler = rpcrdma_qp_async_error_upcall;
694 ep->
rep_attr.cap.max_inline_data = 0;
699 dprintk(
"RPC: %s: requested max: dtos: send %d recv %d; "
700 "iovs: send %d recv %d\n",
729 rpcrdma_cq_async_error_upcall,
NULL,
731 ep->
rep_attr.cap.max_send_wr + 1, 0);
734 dprintk(
"RPC: %s: ib_create_cq failed: %i\n",
741 dprintk(
"RPC: %s: ib_req_notify_cq failed: %i\n",
773 dprintk(
"RPC: %s: ib_destroy_cq returned %i\n",
794 dprintk(
"RPC: %s: entering, connected is %d\n",
800 dprintk(
"RPC: %s: rpcrdma_ep_disconnect"
801 " returned %i\n", __func__, rc);
812 rpcrdma_clean_cq(ep->
rep_cq);
815 dprintk(
"RPC: %s: ib_destroy_cq returned %i\n",
836 dprintk(
"RPC: %s: rpcrdma_ep_disconnect"
837 " status %i\n", __func__, rc);
838 rpcrdma_clean_cq(ep->
rep_cq);
841 id = rpcrdma_create_id(xprt, ia,
855 printk(
"RPC: %s: can't reconnect on "
856 "different device!\n", __func__);
869 dprintk(
"RPC: %s: rdma_create_qp failed %i\n",
875 if (
strnicmp(ia->
ri_id->device->dma_device->bus->name,
"pci", 3) == 0) {
891 dprintk(
"RPC: %s: rdma_connect() failed with %i\n",
906 dprintk(
"RPC: %s: non-peer_reject, retry\n", __func__);
924 dprintk(
"RPC: %s: connected\n", __func__);
947 rpcrdma_clean_cq(ep->
rep_cq);
953 dprintk(
"RPC: %s: after wait, %sconnected\n", __func__,
956 dprintk(
"RPC: %s: rdma_disconnect %i\n", __func__, rc);
972 struct rpcrdma_mw *
r;
993 sizeof(
struct rpcrdma_mw);
998 sizeof(
struct rpcrdma_mw);
1003 sizeof(
struct rpcrdma_mw);
1012 dprintk(
"RPC: %s: req_t/rep_t/pad kzalloc(%zd) failed\n",
1040 INIT_LIST_HEAD(&buf->
rb_mws);
1041 r = (
struct rpcrdma_mw *)p;
1047 if (IS_ERR(r->r.frmr.fr_mr)) {
1048 rc = PTR_ERR(r->r.frmr.fr_mr);
1049 dprintk(
"RPC: %s: ib_alloc_fast_reg_mr"
1050 " failed %i\n", __func__, rc);
1056 if (IS_ERR(r->r.frmr.fr_pgl)) {
1057 rc = PTR_ERR(r->r.frmr.fr_pgl);
1059 "ib_alloc_fast_reg_page_list "
1060 "failed %i\n", __func__, rc);
1063 list_add(&r->mw_list, &buf->
rb_mws);
1075 if (IS_ERR(r->r.fmr)) {
1076 rc = PTR_ERR(r->r.fmr);
1077 dprintk(
"RPC: %s: ib_alloc_fmr"
1078 " failed %i\n", __func__, rc);
1081 list_add(&r->mw_list, &buf->
rb_mws);
1090 if (IS_ERR(r->r.mw)) {
1091 rc = PTR_ERR(r->r.mw);
1092 dprintk(
"RPC: %s: ib_alloc_mw"
1093 " failed %i\n", __func__, rc);
1096 list_add(&r->mw_list, &buf->
rb_mws);
1119 dprintk(
"RPC: %s: request buffer %d alloc"
1120 " failed\n", __func__, i);
1140 dprintk(
"RPC: %s: reply buffer %d alloc failed\n",
1158 dprintk(
"RPC: %s: max_requests %d\n",
1178 struct rpcrdma_mw *
r;
1187 dprintk(
"RPC: %s: entering\n", __func__);
1197 while (!list_empty(&buf->
rb_mws)) {
1199 struct rpcrdma_mw, mw_list);
1255 unsigned long flags;
1257 struct rpcrdma_mw *
r;
1261 spin_unlock_irqrestore(&buffers->
rb_lock, flags);
1262 dprintk(
"RPC: %s: out of request buffers\n", __func__);
1268 dprintk(
"RPC: %s: %d extra receives outstanding (ok)\n",
1277 if (!list_empty(&buffers->
rb_mws)) {
1281 struct rpcrdma_mw, mw_list);
1286 spin_unlock_irqrestore(&buffers->
rb_lock, flags);
1300 unsigned long flags;
1323 struct rpcrdma_mw **mw;
1335 spin_unlock_irqrestore(&buffers->
rb_lock, flags);
1347 unsigned long flags;
1349 if (req->
rl_iov.length == 0)
1350 buffers = ((
struct rpcrdma_req *) buffers)->rl_buffer;
1356 spin_unlock_irqrestore(&buffers->
rb_lock, flags);
1368 unsigned long flags;
1373 spin_unlock_irqrestore(&buffers->
rb_lock, flags);
1391 iov->
addr = ib_dma_map_single(ia->
ri_id->device,
1410 dprintk(
"RPC: %s: phys convert: 0x%llx "
1411 "registered 0x%llx length %d\n",
1412 __func__, (
unsigned long long)ipb.
addr,
1413 (
unsigned long long)iov->
addr, len);
1418 dprintk(
"RPC: %s: failed with %i\n", __func__, rc);
1434 ib_dma_unmap_single(ia->
ri_id->device,
1442 dprintk(
"RPC: %s: ib_dereg_mr failed %i\n", __func__, rc);
1460 seg->
mr_dma = ib_dma_map_single(ia->
ri_id->device,
1463 if (ib_dma_mapping_error(ia->
ri_id->device, seg->
mr_dma)) {
1464 dprintk(
"RPC: %s: mr_dma %llx mr_offset %p mr_dma_len %zu\n",
1466 (
unsigned long long)seg->
mr_dma,
1475 ib_dma_unmap_page(ia->
ri_id->device,
1478 ib_dma_unmap_single(ia->
ri_id->device,
1484 int *nsegs,
int writing,
struct rpcrdma_ia *ia,
1488 struct ib_send_wr invalidate_wr, frmr_wr, *bad_wr, *post_wr;
1503 for (page_no = i = 0; i < *nsegs;) {
1504 rpcrdma_map_one(ia, seg, writing);
1519 dprintk(
"RPC: %s: Using frmr %p to map %d segments\n",
1523 dprintk(
"RPC: %s: frmr %x left valid, posting invalidate.\n",
1527 memset(&invalidate_wr, 0,
sizeof invalidate_wr);
1529 invalidate_wr.next = &frmr_wr;
1532 invalidate_wr.ex.invalidate_rkey =
1535 post_wr = &invalidate_wr;
1541 ib_update_fast_reg_key(seg1->
mr_chunk.
rl_mw->r.frmr.fr_mr, ++key);
1544 memset(&frmr_wr, 0,
sizeof frmr_wr);
1548 frmr_wr.wr.fast_reg.iova_start = seg1->
mr_dma;
1549 frmr_wr.wr.fast_reg.page_list = seg1->
mr_chunk.
rl_mw->r.frmr.fr_pgl;
1550 frmr_wr.wr.fast_reg.page_list_len = page_no;
1552 frmr_wr.wr.fast_reg.length = page_no <<
PAGE_SHIFT;
1553 BUG_ON(frmr_wr.wr.fast_reg.length < len);
1554 frmr_wr.wr.fast_reg.access_flags = (writing ?
1557 frmr_wr.wr.fast_reg.rkey = seg1->
mr_chunk.
rl_mw->r.frmr.fr_mr->rkey;
1560 rc = ib_post_send(ia->
ri_id->qp, post_wr, &bad_wr);
1563 dprintk(
"RPC: %s: failed ib_post_send for register,"
1564 " status %i\n", __func__, rc);
1566 rpcrdma_unmap_one(ia, --seg);
1586 rpcrdma_unmap_one(ia, seg++);
1588 memset(&invalidate_wr, 0,
sizeof invalidate_wr);
1592 invalidate_wr.ex.invalidate_rkey = seg1->
mr_chunk.
rl_mw->r.frmr.fr_mr->rkey;
1595 rc = ib_post_send(ia->
ri_id->qp, &invalidate_wr, &bad_wr);
1597 dprintk(
"RPC: %s: failed ib_post_send for invalidate,"
1598 " status %i\n", __func__, rc);
1604 int *nsegs,
int writing,
struct rpcrdma_ia *ia)
1608 int len, pageoff,
i,
rc;
1616 for (i = 0; i < *nsegs;) {
1617 rpcrdma_map_one(ia, seg, writing);
1628 physaddrs, i, seg1->
mr_dma);
1630 dprintk(
"RPC: %s: failed ib_map_phys_fmr "
1631 "%u@0x%llx+%i (%d)... status %i\n", __func__,
1632 len, (
unsigned long long)seg1->
mr_dma,
1635 rpcrdma_unmap_one(ia, --seg);
1657 rpcrdma_unmap_one(ia, seg++);
1659 dprintk(
"RPC: %s: failed ib_unmap_fmr,"
1660 " status %i\n", __func__, rc);
1666 int *nsegs,
int writing,
struct rpcrdma_ia *ia,
1675 rpcrdma_map_one(ia, seg, writing);
1680 param.send_flags = 0;
1681 param.mw_access_flags = mem_priv;
1686 dprintk(
"RPC: %s: failed ib_bind_mw "
1687 "%u@0x%llx status %i\n",
1689 (
unsigned long long)seg->
mr_dma, rc);
1690 rpcrdma_unmap_one(ia, seg);
1712 param.mw_access_flags = 0;
1719 param.send_flags = 0;
1723 rpcrdma_unmap_one(ia, seg);
1725 dprintk(
"RPC: %s: failed ib_(un)bind_mw,"
1726 " status %i\n", __func__, rc);
1734 int *nsegs,
int writing,
struct rpcrdma_ia *ia)
1744 for (len = 0, i = 0; i < *nsegs;) {
1745 rpcrdma_map_one(ia, seg, writing);
1761 dprintk(
"RPC: %s: failed ib_reg_phys_mr "
1762 "%u@0x%llx (%d)... status %i\n",
1764 (
unsigned long long)seg1->
mr_dma, i, rc);
1766 rpcrdma_unmap_one(ia, --seg);
1786 rpcrdma_unmap_one(ia, seg++);
1788 dprintk(
"RPC: %s: failed ib_dereg_mr,"
1789 " status %i\n", __func__, rc);
1802 #if RPCRDMA_PERSISTENT_REGISTRATION
1804 rpcrdma_map_one(ia, seg, writing);
1814 rc = rpcrdma_register_frmr_external(seg, &nsegs, writing, ia, r_xprt);
1819 rc = rpcrdma_register_fmr_external(seg, &nsegs, writing, ia);
1825 rc = rpcrdma_register_memwin_external(seg, &nsegs, writing, ia, r_xprt);
1830 rc = rpcrdma_register_default_external(seg, &nsegs, writing, ia);
1848 #if RPCRDMA_PERSISTENT_REGISTRATION
1851 rpcrdma_unmap_one(ia, seg);
1857 rc = rpcrdma_deregister_frmr_external(seg, ia, r_xprt);
1861 rc = rpcrdma_deregister_fmr_external(seg, ia);
1866 rc = rpcrdma_deregister_memwin_external(seg, ia, r_xprt, &r);
1870 rc = rpcrdma_deregister_default_external(seg, ia);
1904 send_wr.
wr_id = 0ULL;
1909 ib_dma_sync_single_for_device(ia->
ri_id->device,
1912 ib_dma_sync_single_for_device(ia->
ri_id->device,
1915 ib_dma_sync_single_for_device(ia->
ri_id->device,
1926 rc = ib_post_send(ia->
ri_id->qp, &send_wr, &send_wr_fail);
1928 dprintk(
"RPC: %s: ib_post_send returned %i\n", __func__,
1950 ib_dma_sync_single_for_cpu(ia->
ri_id->device,
1954 rc = ib_post_recv(ia->
ri_id->qp, &recv_wr, &recv_wr_fail);
1957 dprintk(
"RPC: %s: ib_post_recv returned %i\n", __func__,