2 * Copyright (c) 2003-2007 Network Appliance, Inc. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the BSD-type
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * Neither the name of the Network Appliance, Inc. nor the names of
23 * its contributors may be used to endorse or promote products
24 * derived from this software without specific prior written
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 * Encapsulates the major functions managing:
50 #include <linux/interrupt.h>
51 #include <linux/slab.h>
52 #include <linux/prefetch.h>
53 #include <linux/sunrpc/addr.h>
54 #include <asm/bitops.h>
56 #include "xprt_rdma.h"
62 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
63 # define RPCDBG_FACILITY RPCDBG_TRANS
71 * handle replies in tasklet context, using a single, global list
72 * rdma tasklet function -- just turn around and call the func
73 * for all replies on the list
76 static DEFINE_SPINLOCK(rpcrdma_tk_lock_g);
77 static LIST_HEAD(rpcrdma_tasklets_g);
80 rpcrdma_run_tasklet(unsigned long data)
82 struct rpcrdma_rep *rep;
83 void (*func)(struct rpcrdma_rep *);
87 spin_lock_irqsave(&rpcrdma_tk_lock_g, flags);
88 while (!list_empty(&rpcrdma_tasklets_g)) {
89 rep = list_entry(rpcrdma_tasklets_g.next,
90 struct rpcrdma_rep, rr_list);
91 list_del(&rep->rr_list);
94 spin_unlock_irqrestore(&rpcrdma_tk_lock_g, flags);
99 rpcrdma_recv_buffer_put(rep);
101 spin_lock_irqsave(&rpcrdma_tk_lock_g, flags);
103 spin_unlock_irqrestore(&rpcrdma_tk_lock_g, flags);
106 static DECLARE_TASKLET(rpcrdma_tasklet_g, rpcrdma_run_tasklet, 0UL);
109 rpcrdma_schedule_tasklet(struct list_head *sched_list)
113 spin_lock_irqsave(&rpcrdma_tk_lock_g, flags);
114 list_splice_tail(sched_list, &rpcrdma_tasklets_g);
115 spin_unlock_irqrestore(&rpcrdma_tk_lock_g, flags);
116 tasklet_schedule(&rpcrdma_tasklet_g);
120 rpcrdma_qp_async_error_upcall(struct ib_event *event, void *context)
122 struct rpcrdma_ep *ep = context;
124 pr_err("RPC: %s: %s on device %s ep %p\n",
125 __func__, ib_event_msg(event->event),
126 event->device->name, context);
127 if (ep->rep_connected == 1) {
128 ep->rep_connected = -EIO;
129 rpcrdma_conn_func(ep);
130 wake_up_all(&ep->rep_connect_wait);
135 rpcrdma_cq_async_error_upcall(struct ib_event *event, void *context)
137 struct rpcrdma_ep *ep = context;
139 pr_err("RPC: %s: %s on device %s ep %p\n",
140 __func__, ib_event_msg(event->event),
141 event->device->name, context);
142 if (ep->rep_connected == 1) {
143 ep->rep_connected = -EIO;
144 rpcrdma_conn_func(ep);
145 wake_up_all(&ep->rep_connect_wait);
150 rpcrdma_sendcq_process_wc(struct ib_wc *wc)
152 /* WARNING: Only wr_id and status are reliable at this point */
153 if (wc->wr_id == RPCRDMA_IGNORE_COMPLETION) {
154 if (wc->status != IB_WC_SUCCESS &&
155 wc->status != IB_WC_WR_FLUSH_ERR)
156 pr_err("RPC: %s: SEND: %s\n",
157 __func__, ib_wc_status_msg(wc->status));
159 struct rpcrdma_mw *r;
161 r = (struct rpcrdma_mw *)(unsigned long)wc->wr_id;
162 r->mw_sendcompletion(wc);
167 rpcrdma_sendcq_poll(struct ib_cq *cq, struct rpcrdma_ep *ep)
170 int budget, count, rc;
172 budget = RPCRDMA_WC_BUDGET / RPCRDMA_POLLSIZE;
174 wcs = ep->rep_send_wcs;
176 rc = ib_poll_cq(cq, RPCRDMA_POLLSIZE, wcs);
182 rpcrdma_sendcq_process_wc(wcs++);
183 } while (rc == RPCRDMA_POLLSIZE && --budget);
188 * Handle send, fast_reg_mr, and local_inv completions.
190 * Send events are typically suppressed and thus do not result
191 * in an upcall. Occasionally one is signaled, however. This
192 * prevents the provider's completion queue from wrapping and
193 * losing a completion.
196 rpcrdma_sendcq_upcall(struct ib_cq *cq, void *cq_context)
198 struct rpcrdma_ep *ep = (struct rpcrdma_ep *)cq_context;
201 rc = rpcrdma_sendcq_poll(cq, ep);
203 dprintk("RPC: %s: ib_poll_cq failed: %i\n",
208 rc = ib_req_notify_cq(cq,
209 IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS);
213 dprintk("RPC: %s: ib_req_notify_cq failed: %i\n",
218 rpcrdma_sendcq_poll(cq, ep);
222 rpcrdma_recvcq_process_wc(struct ib_wc *wc, struct list_head *sched_list)
224 struct rpcrdma_rep *rep =
225 (struct rpcrdma_rep *)(unsigned long)wc->wr_id;
227 /* WARNING: Only wr_id and status are reliable at this point */
228 if (wc->status != IB_WC_SUCCESS)
231 /* status == SUCCESS means all fields in wc are trustworthy */
232 if (wc->opcode != IB_WC_RECV)
235 dprintk("RPC: %s: rep %p opcode 'recv', length %u: success\n",
236 __func__, rep, wc->byte_len);
238 rep->rr_len = wc->byte_len;
239 ib_dma_sync_single_for_cpu(rdmab_to_ia(rep->rr_buffer)->ri_id->device,
240 rdmab_addr(rep->rr_rdmabuf),
241 rep->rr_len, DMA_FROM_DEVICE);
242 prefetch(rdmab_to_msg(rep->rr_rdmabuf));
245 list_add_tail(&rep->rr_list, sched_list);
248 if (wc->status != IB_WC_WR_FLUSH_ERR)
249 pr_err("RPC: %s: rep %p: %s\n",
250 __func__, rep, ib_wc_status_msg(wc->status));
256 rpcrdma_recvcq_poll(struct ib_cq *cq, struct rpcrdma_ep *ep)
258 struct list_head sched_list;
260 int budget, count, rc;
262 INIT_LIST_HEAD(&sched_list);
263 budget = RPCRDMA_WC_BUDGET / RPCRDMA_POLLSIZE;
265 wcs = ep->rep_recv_wcs;
267 rc = ib_poll_cq(cq, RPCRDMA_POLLSIZE, wcs);
273 rpcrdma_recvcq_process_wc(wcs++, &sched_list);
274 } while (rc == RPCRDMA_POLLSIZE && --budget);
278 rpcrdma_schedule_tasklet(&sched_list);
283 * Handle receive completions.
285 * It is reentrant but processes single events in order to maintain
286 * ordering of receives to keep server credits.
288 * It is the responsibility of the scheduled tasklet to return
289 * recv buffers to the pool. NOTE: this affects synchronization of
290 * connection shutdown. That is, the structures required for
291 * the completion of the reply handler must remain intact until
292 * all memory has been reclaimed.
295 rpcrdma_recvcq_upcall(struct ib_cq *cq, void *cq_context)
297 struct rpcrdma_ep *ep = (struct rpcrdma_ep *)cq_context;
300 rc = rpcrdma_recvcq_poll(cq, ep);
302 dprintk("RPC: %s: ib_poll_cq failed: %i\n",
307 rc = ib_req_notify_cq(cq,
308 IB_CQ_NEXT_COMP | IB_CQ_REPORT_MISSED_EVENTS);
312 dprintk("RPC: %s: ib_req_notify_cq failed: %i\n",
317 rpcrdma_recvcq_poll(cq, ep);
321 rpcrdma_flush_cqs(struct rpcrdma_ep *ep)
324 LIST_HEAD(sched_list);
326 while (ib_poll_cq(ep->rep_attr.recv_cq, 1, &wc) > 0)
327 rpcrdma_recvcq_process_wc(&wc, &sched_list);
328 if (!list_empty(&sched_list))
329 rpcrdma_schedule_tasklet(&sched_list);
330 while (ib_poll_cq(ep->rep_attr.send_cq, 1, &wc) > 0)
331 rpcrdma_sendcq_process_wc(&wc);
335 rpcrdma_conn_upcall(struct rdma_cm_id *id, struct rdma_cm_event *event)
337 struct rpcrdma_xprt *xprt = id->context;
338 struct rpcrdma_ia *ia = &xprt->rx_ia;
339 struct rpcrdma_ep *ep = &xprt->rx_ep;
340 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
341 struct sockaddr *sap = (struct sockaddr *)&ep->rep_remote_addr;
343 struct ib_qp_attr *attr = &ia->ri_qp_attr;
344 struct ib_qp_init_attr *iattr = &ia->ri_qp_init_attr;
347 switch (event->event) {
348 case RDMA_CM_EVENT_ADDR_RESOLVED:
349 case RDMA_CM_EVENT_ROUTE_RESOLVED:
351 complete(&ia->ri_done);
353 case RDMA_CM_EVENT_ADDR_ERROR:
354 ia->ri_async_rc = -EHOSTUNREACH;
355 dprintk("RPC: %s: CM address resolution error, ep 0x%p\n",
357 complete(&ia->ri_done);
359 case RDMA_CM_EVENT_ROUTE_ERROR:
360 ia->ri_async_rc = -ENETUNREACH;
361 dprintk("RPC: %s: CM route resolution error, ep 0x%p\n",
363 complete(&ia->ri_done);
365 case RDMA_CM_EVENT_ESTABLISHED:
367 ib_query_qp(ia->ri_id->qp, attr,
368 IB_QP_MAX_QP_RD_ATOMIC | IB_QP_MAX_DEST_RD_ATOMIC,
370 dprintk("RPC: %s: %d responder resources"
372 __func__, attr->max_dest_rd_atomic,
373 attr->max_rd_atomic);
375 case RDMA_CM_EVENT_CONNECT_ERROR:
376 connstate = -ENOTCONN;
378 case RDMA_CM_EVENT_UNREACHABLE:
379 connstate = -ENETDOWN;
381 case RDMA_CM_EVENT_REJECTED:
382 connstate = -ECONNREFUSED;
384 case RDMA_CM_EVENT_DISCONNECTED:
385 connstate = -ECONNABORTED;
387 case RDMA_CM_EVENT_DEVICE_REMOVAL:
390 dprintk("RPC: %s: %sconnected\n",
391 __func__, connstate > 0 ? "" : "dis");
392 ep->rep_connected = connstate;
393 rpcrdma_conn_func(ep);
394 wake_up_all(&ep->rep_connect_wait);
397 dprintk("RPC: %s: %pIS:%u (ep 0x%p): %s\n",
398 __func__, sap, rpc_get_port(sap), ep,
399 rdma_event_msg(event->event));
403 #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
404 if (connstate == 1) {
405 int ird = attr->max_dest_rd_atomic;
406 int tird = ep->rep_remote_cma.responder_resources;
408 pr_info("rpcrdma: connection to %pIS:%u on %s, memreg '%s', %d credits, %d responders%s\n",
409 sap, rpc_get_port(sap),
410 ia->ri_id->device->name,
411 ia->ri_ops->ro_displayname,
412 xprt->rx_buf.rb_max_requests,
413 ird, ird < 4 && ird < tird / 2 ? " (low!)" : "");
414 } else if (connstate < 0) {
415 pr_info("rpcrdma: connection to %pIS:%u closed (%d)\n",
416 sap, rpc_get_port(sap), connstate);
423 static struct rdma_cm_id *
424 rpcrdma_create_id(struct rpcrdma_xprt *xprt,
425 struct rpcrdma_ia *ia, struct sockaddr *addr)
427 struct rdma_cm_id *id;
430 init_completion(&ia->ri_done);
432 id = rdma_create_id(rpcrdma_conn_upcall, xprt, RDMA_PS_TCP, IB_QPT_RC);
435 dprintk("RPC: %s: rdma_create_id() failed %i\n",
440 ia->ri_async_rc = -ETIMEDOUT;
441 rc = rdma_resolve_addr(id, NULL, addr, RDMA_RESOLVE_TIMEOUT);
443 dprintk("RPC: %s: rdma_resolve_addr() failed %i\n",
447 wait_for_completion_interruptible_timeout(&ia->ri_done,
448 msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1);
449 rc = ia->ri_async_rc;
453 ia->ri_async_rc = -ETIMEDOUT;
454 rc = rdma_resolve_route(id, RDMA_RESOLVE_TIMEOUT);
456 dprintk("RPC: %s: rdma_resolve_route() failed %i\n",
460 wait_for_completion_interruptible_timeout(&ia->ri_done,
461 msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT) + 1);
462 rc = ia->ri_async_rc;
474 * Drain any cq, prior to teardown.
477 rpcrdma_clean_cq(struct ib_cq *cq)
482 while (1 == ib_poll_cq(cq, 1, &wc))
486 dprintk("RPC: %s: flushed %d events (last 0x%x)\n",
487 __func__, count, wc.opcode);
491 * Exported functions.
495 * Open and initialize an Interface Adapter.
496 * o initializes fields of struct rpcrdma_ia, including
497 * interface and provider attributes and protection zone.
500 rpcrdma_ia_open(struct rpcrdma_xprt *xprt, struct sockaddr *addr, int memreg)
503 struct rpcrdma_ia *ia = &xprt->rx_ia;
504 struct ib_device_attr *devattr = &ia->ri_devattr;
506 ia->ri_id = rpcrdma_create_id(xprt, ia, addr);
507 if (IS_ERR(ia->ri_id)) {
508 rc = PTR_ERR(ia->ri_id);
512 ia->ri_pd = ib_alloc_pd(ia->ri_id->device);
513 if (IS_ERR(ia->ri_pd)) {
514 rc = PTR_ERR(ia->ri_pd);
515 dprintk("RPC: %s: ib_alloc_pd() failed %i\n",
520 rc = ib_query_device(ia->ri_id->device, devattr);
522 dprintk("RPC: %s: ib_query_device failed %d\n",
527 if (devattr->device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY) {
528 ia->ri_have_dma_lkey = 1;
529 ia->ri_dma_lkey = ia->ri_id->device->local_dma_lkey;
532 if (memreg == RPCRDMA_FRMR) {
533 /* Requires both frmr reg and local dma lkey */
534 if (((devattr->device_cap_flags &
535 (IB_DEVICE_MEM_MGT_EXTENSIONS|IB_DEVICE_LOCAL_DMA_LKEY)) !=
536 (IB_DEVICE_MEM_MGT_EXTENSIONS|IB_DEVICE_LOCAL_DMA_LKEY)) ||
537 (devattr->max_fast_reg_page_list_len == 0)) {
538 dprintk("RPC: %s: FRMR registration "
539 "not supported by HCA\n", __func__);
540 memreg = RPCRDMA_MTHCAFMR;
543 if (memreg == RPCRDMA_MTHCAFMR) {
544 if (!ia->ri_id->device->alloc_fmr) {
545 dprintk("RPC: %s: MTHCAFMR registration "
546 "not supported by HCA\n", __func__);
547 memreg = RPCRDMA_ALLPHYSICAL;
552 * Optionally obtain an underlying physical identity mapping in
553 * order to do a memory window-based bind. This base registration
554 * is protected from remote access - that is enabled only by binding
555 * for the specific bytes targeted during each RPC operation, and
556 * revoked after the corresponding completion similar to a storage
561 ia->ri_ops = &rpcrdma_frwr_memreg_ops;
563 case RPCRDMA_ALLPHYSICAL:
564 ia->ri_ops = &rpcrdma_physical_memreg_ops;
565 mem_priv = IB_ACCESS_LOCAL_WRITE |
566 IB_ACCESS_REMOTE_WRITE |
567 IB_ACCESS_REMOTE_READ;
569 case RPCRDMA_MTHCAFMR:
570 ia->ri_ops = &rpcrdma_fmr_memreg_ops;
571 if (ia->ri_have_dma_lkey)
573 mem_priv = IB_ACCESS_LOCAL_WRITE;
575 ia->ri_bind_mem = ib_get_dma_mr(ia->ri_pd, mem_priv);
576 if (IS_ERR(ia->ri_bind_mem)) {
577 printk(KERN_ALERT "%s: ib_get_dma_mr for "
578 "phys register failed with %lX\n",
579 __func__, PTR_ERR(ia->ri_bind_mem));
585 printk(KERN_ERR "RPC: Unsupported memory "
586 "registration mode: %d\n", memreg);
590 dprintk("RPC: %s: memory registration strategy is '%s'\n",
591 __func__, ia->ri_ops->ro_displayname);
593 /* Else will do memory reg/dereg for each chunk */
594 ia->ri_memreg_strategy = memreg;
596 rwlock_init(&ia->ri_qplock);
600 ib_dealloc_pd(ia->ri_pd);
603 rdma_destroy_id(ia->ri_id);
610 * Clean up/close an IA.
611 * o if event handles and PD have been initialized, free them.
615 rpcrdma_ia_close(struct rpcrdma_ia *ia)
619 dprintk("RPC: %s: entering\n", __func__);
620 if (ia->ri_bind_mem != NULL) {
621 rc = ib_dereg_mr(ia->ri_bind_mem);
622 dprintk("RPC: %s: ib_dereg_mr returned %i\n",
625 if (ia->ri_id != NULL && !IS_ERR(ia->ri_id)) {
627 rdma_destroy_qp(ia->ri_id);
628 rdma_destroy_id(ia->ri_id);
631 if (ia->ri_pd != NULL && !IS_ERR(ia->ri_pd)) {
632 rc = ib_dealloc_pd(ia->ri_pd);
633 dprintk("RPC: %s: ib_dealloc_pd returned %i\n",
639 * Create unconnected endpoint.
642 rpcrdma_ep_create(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia,
643 struct rpcrdma_create_data_internal *cdata)
645 struct ib_device_attr *devattr = &ia->ri_devattr;
646 struct ib_cq *sendcq, *recvcq;
649 /* check provider's send/recv wr limits */
650 if (cdata->max_requests > devattr->max_qp_wr)
651 cdata->max_requests = devattr->max_qp_wr;
653 ep->rep_attr.event_handler = rpcrdma_qp_async_error_upcall;
654 ep->rep_attr.qp_context = ep;
655 ep->rep_attr.srq = NULL;
656 ep->rep_attr.cap.max_send_wr = cdata->max_requests;
657 rc = ia->ri_ops->ro_open(ia, ep, cdata);
660 ep->rep_attr.cap.max_recv_wr = cdata->max_requests;
661 ep->rep_attr.cap.max_send_sge = (cdata->padding ? 4 : 2);
662 ep->rep_attr.cap.max_recv_sge = 1;
663 ep->rep_attr.cap.max_inline_data = 0;
664 ep->rep_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
665 ep->rep_attr.qp_type = IB_QPT_RC;
666 ep->rep_attr.port_num = ~0;
668 if (cdata->padding) {
669 ep->rep_padbuf = rpcrdma_alloc_regbuf(ia, cdata->padding,
671 if (IS_ERR(ep->rep_padbuf))
672 return PTR_ERR(ep->rep_padbuf);
674 ep->rep_padbuf = NULL;
676 dprintk("RPC: %s: requested max: dtos: send %d recv %d; "
677 "iovs: send %d recv %d\n",
679 ep->rep_attr.cap.max_send_wr,
680 ep->rep_attr.cap.max_recv_wr,
681 ep->rep_attr.cap.max_send_sge,
682 ep->rep_attr.cap.max_recv_sge);
684 /* set trigger for requesting send completion */
685 ep->rep_cqinit = ep->rep_attr.cap.max_send_wr/2 - 1;
686 if (ep->rep_cqinit > RPCRDMA_MAX_UNSIGNALED_SENDS)
687 ep->rep_cqinit = RPCRDMA_MAX_UNSIGNALED_SENDS;
688 else if (ep->rep_cqinit <= 2)
691 init_waitqueue_head(&ep->rep_connect_wait);
692 INIT_DELAYED_WORK(&ep->rep_connect_worker, rpcrdma_connect_worker);
694 sendcq = ib_create_cq(ia->ri_id->device, rpcrdma_sendcq_upcall,
695 rpcrdma_cq_async_error_upcall, ep,
696 ep->rep_attr.cap.max_send_wr + 1, 0);
697 if (IS_ERR(sendcq)) {
698 rc = PTR_ERR(sendcq);
699 dprintk("RPC: %s: failed to create send CQ: %i\n",
704 rc = ib_req_notify_cq(sendcq, IB_CQ_NEXT_COMP);
706 dprintk("RPC: %s: ib_req_notify_cq failed: %i\n",
711 recvcq = ib_create_cq(ia->ri_id->device, rpcrdma_recvcq_upcall,
712 rpcrdma_cq_async_error_upcall, ep,
713 ep->rep_attr.cap.max_recv_wr + 1, 0);
714 if (IS_ERR(recvcq)) {
715 rc = PTR_ERR(recvcq);
716 dprintk("RPC: %s: failed to create recv CQ: %i\n",
721 rc = ib_req_notify_cq(recvcq, IB_CQ_NEXT_COMP);
723 dprintk("RPC: %s: ib_req_notify_cq failed: %i\n",
725 ib_destroy_cq(recvcq);
729 ep->rep_attr.send_cq = sendcq;
730 ep->rep_attr.recv_cq = recvcq;
732 /* Initialize cma parameters */
734 /* RPC/RDMA does not use private data */
735 ep->rep_remote_cma.private_data = NULL;
736 ep->rep_remote_cma.private_data_len = 0;
738 /* Client offers RDMA Read but does not initiate */
739 ep->rep_remote_cma.initiator_depth = 0;
740 if (devattr->max_qp_rd_atom > 32) /* arbitrary but <= 255 */
741 ep->rep_remote_cma.responder_resources = 32;
743 ep->rep_remote_cma.responder_resources =
744 devattr->max_qp_rd_atom;
746 ep->rep_remote_cma.retry_count = 7;
747 ep->rep_remote_cma.flow_control = 0;
748 ep->rep_remote_cma.rnr_retry_count = 0;
753 err = ib_destroy_cq(sendcq);
755 dprintk("RPC: %s: ib_destroy_cq returned %i\n",
758 rpcrdma_free_regbuf(ia, ep->rep_padbuf);
765 * Disconnect and destroy endpoint. After this, the only
766 * valid operations on the ep are to free it (if dynamically
767 * allocated) or re-create it.
770 rpcrdma_ep_destroy(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
774 dprintk("RPC: %s: entering, connected is %d\n",
775 __func__, ep->rep_connected);
777 cancel_delayed_work_sync(&ep->rep_connect_worker);
780 rpcrdma_ep_disconnect(ep, ia);
781 rdma_destroy_qp(ia->ri_id);
782 ia->ri_id->qp = NULL;
785 rpcrdma_free_regbuf(ia, ep->rep_padbuf);
787 rpcrdma_clean_cq(ep->rep_attr.recv_cq);
788 rc = ib_destroy_cq(ep->rep_attr.recv_cq);
790 dprintk("RPC: %s: ib_destroy_cq returned %i\n",
793 rpcrdma_clean_cq(ep->rep_attr.send_cq);
794 rc = ib_destroy_cq(ep->rep_attr.send_cq);
796 dprintk("RPC: %s: ib_destroy_cq returned %i\n",
801 * Connect unconnected endpoint.
804 rpcrdma_ep_connect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
806 struct rdma_cm_id *id, *old;
810 if (ep->rep_connected != 0) {
811 struct rpcrdma_xprt *xprt;
813 dprintk("RPC: %s: reconnecting...\n", __func__);
815 rpcrdma_ep_disconnect(ep, ia);
816 rpcrdma_flush_cqs(ep);
818 xprt = container_of(ia, struct rpcrdma_xprt, rx_ia);
819 ia->ri_ops->ro_reset(xprt);
821 id = rpcrdma_create_id(xprt, ia,
822 (struct sockaddr *)&xprt->rx_data.addr);
827 /* TEMP TEMP TEMP - fail if new device:
828 * Deregister/remarshal *all* requests!
829 * Close and recreate adapter, pd, etc!
830 * Re-determine all attributes still sane!
831 * More stuff I haven't thought of!
834 if (ia->ri_id->device != id->device) {
835 printk("RPC: %s: can't reconnect on "
836 "different device!\n", __func__);
842 rc = rdma_create_qp(id, ia->ri_pd, &ep->rep_attr);
844 dprintk("RPC: %s: rdma_create_qp failed %i\n",
851 write_lock(&ia->ri_qplock);
854 write_unlock(&ia->ri_qplock);
856 rdma_destroy_qp(old);
857 rdma_destroy_id(old);
859 dprintk("RPC: %s: connecting...\n", __func__);
860 rc = rdma_create_qp(ia->ri_id, ia->ri_pd, &ep->rep_attr);
862 dprintk("RPC: %s: rdma_create_qp failed %i\n",
864 /* do not update ep->rep_connected */
869 ep->rep_connected = 0;
871 rc = rdma_connect(ia->ri_id, &ep->rep_remote_cma);
873 dprintk("RPC: %s: rdma_connect() failed with %i\n",
878 wait_event_interruptible(ep->rep_connect_wait, ep->rep_connected != 0);
881 * Check state. A non-peer reject indicates no listener
882 * (ECONNREFUSED), which may be a transient state. All
883 * others indicate a transport condition which has already
884 * undergone a best-effort.
886 if (ep->rep_connected == -ECONNREFUSED &&
887 ++retry_count <= RDMA_CONNECT_RETRY_MAX) {
888 dprintk("RPC: %s: non-peer_reject, retry\n", __func__);
891 if (ep->rep_connected <= 0) {
892 /* Sometimes, the only way to reliably connect to remote
893 * CMs is to use same nonzero values for ORD and IRD. */
894 if (retry_count++ <= RDMA_CONNECT_RETRY_MAX + 1 &&
895 (ep->rep_remote_cma.responder_resources == 0 ||
896 ep->rep_remote_cma.initiator_depth !=
897 ep->rep_remote_cma.responder_resources)) {
898 if (ep->rep_remote_cma.responder_resources == 0)
899 ep->rep_remote_cma.responder_resources = 1;
900 ep->rep_remote_cma.initiator_depth =
901 ep->rep_remote_cma.responder_resources;
904 rc = ep->rep_connected;
906 dprintk("RPC: %s: connected\n", __func__);
911 ep->rep_connected = rc;
916 * rpcrdma_ep_disconnect
918 * This is separate from destroy to facilitate the ability
919 * to reconnect without recreating the endpoint.
921 * This call is not reentrant, and must not be made in parallel
922 * on the same endpoint.
925 rpcrdma_ep_disconnect(struct rpcrdma_ep *ep, struct rpcrdma_ia *ia)
929 rpcrdma_flush_cqs(ep);
930 rc = rdma_disconnect(ia->ri_id);
932 /* returns without wait if not connected */
933 wait_event_interruptible(ep->rep_connect_wait,
934 ep->rep_connected != 1);
935 dprintk("RPC: %s: after wait, %sconnected\n", __func__,
936 (ep->rep_connected == 1) ? "still " : "dis");
938 dprintk("RPC: %s: rdma_disconnect %i\n", __func__, rc);
939 ep->rep_connected = rc;
943 static struct rpcrdma_req *
944 rpcrdma_create_req(struct rpcrdma_xprt *r_xprt)
946 struct rpcrdma_req *req;
948 req = kzalloc(sizeof(*req), GFP_KERNEL);
950 return ERR_PTR(-ENOMEM);
952 req->rl_buffer = &r_xprt->rx_buf;
956 static struct rpcrdma_rep *
957 rpcrdma_create_rep(struct rpcrdma_xprt *r_xprt)
959 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
960 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
961 struct rpcrdma_rep *rep;
965 rep = kzalloc(sizeof(*rep), GFP_KERNEL);
969 rep->rr_rdmabuf = rpcrdma_alloc_regbuf(ia, cdata->inline_rsize,
971 if (IS_ERR(rep->rr_rdmabuf)) {
972 rc = PTR_ERR(rep->rr_rdmabuf);
976 rep->rr_buffer = &r_xprt->rx_buf;
986 rpcrdma_buffer_create(struct rpcrdma_xprt *r_xprt)
988 struct rpcrdma_buffer *buf = &r_xprt->rx_buf;
989 struct rpcrdma_ia *ia = &r_xprt->rx_ia;
990 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
995 buf->rb_max_requests = cdata->max_requests;
996 spin_lock_init(&buf->rb_lock);
999 * 1. arrays for send and recv pointers
1000 * 2. arrays of struct rpcrdma_req to fill in pointers
1001 * 3. array of struct rpcrdma_rep for replies
1002 * Send/recv buffers in req/rep need to be registered
1004 len = buf->rb_max_requests *
1005 (sizeof(struct rpcrdma_req *) + sizeof(struct rpcrdma_rep *));
1007 p = kzalloc(len, GFP_KERNEL);
1009 dprintk("RPC: %s: req_t/rep_t/pad kzalloc(%zd) failed\n",
1014 buf->rb_pool = p; /* for freeing it later */
1016 buf->rb_send_bufs = (struct rpcrdma_req **) p;
1017 p = (char *) &buf->rb_send_bufs[buf->rb_max_requests];
1018 buf->rb_recv_bufs = (struct rpcrdma_rep **) p;
1019 p = (char *) &buf->rb_recv_bufs[buf->rb_max_requests];
1021 rc = ia->ri_ops->ro_init(r_xprt);
1025 for (i = 0; i < buf->rb_max_requests; i++) {
1026 struct rpcrdma_req *req;
1027 struct rpcrdma_rep *rep;
1029 req = rpcrdma_create_req(r_xprt);
1031 dprintk("RPC: %s: request buffer %d alloc"
1032 " failed\n", __func__, i);
1036 buf->rb_send_bufs[i] = req;
1038 rep = rpcrdma_create_rep(r_xprt);
1040 dprintk("RPC: %s: reply buffer %d alloc failed\n",
1045 buf->rb_recv_bufs[i] = rep;
1050 rpcrdma_buffer_destroy(buf);
1055 rpcrdma_destroy_rep(struct rpcrdma_ia *ia, struct rpcrdma_rep *rep)
1060 rpcrdma_free_regbuf(ia, rep->rr_rdmabuf);
1065 rpcrdma_destroy_req(struct rpcrdma_ia *ia, struct rpcrdma_req *req)
1070 rpcrdma_free_regbuf(ia, req->rl_sendbuf);
1071 rpcrdma_free_regbuf(ia, req->rl_rdmabuf);
1076 rpcrdma_buffer_destroy(struct rpcrdma_buffer *buf)
1078 struct rpcrdma_ia *ia = rdmab_to_ia(buf);
1081 /* clean up in reverse order from create
1082 * 1. recv mr memory (mr free, then kfree)
1083 * 2. send mr memory (mr free, then kfree)
1086 dprintk("RPC: %s: entering\n", __func__);
1088 for (i = 0; i < buf->rb_max_requests; i++) {
1089 if (buf->rb_recv_bufs)
1090 rpcrdma_destroy_rep(ia, buf->rb_recv_bufs[i]);
1091 if (buf->rb_send_bufs)
1092 rpcrdma_destroy_req(ia, buf->rb_send_bufs[i]);
1095 ia->ri_ops->ro_destroy(buf);
1097 kfree(buf->rb_pool);
1100 /* "*mw" can be NULL when rpcrdma_buffer_get_mrs() fails, leaving
1101 * some req segments uninitialized.
1104 rpcrdma_buffer_put_mr(struct rpcrdma_mw **mw, struct rpcrdma_buffer *buf)
1107 list_add_tail(&(*mw)->mw_list, &buf->rb_mws);
1112 /* Cycle mw's back in reverse order, and "spin" them.
1113 * This delays and scrambles reuse as much as possible.
1116 rpcrdma_buffer_put_mrs(struct rpcrdma_req *req, struct rpcrdma_buffer *buf)
1118 struct rpcrdma_mr_seg *seg = req->rl_segments;
1119 struct rpcrdma_mr_seg *seg1 = seg;
1122 for (i = 1, seg++; i < RPCRDMA_MAX_SEGS; seg++, i++)
1123 rpcrdma_buffer_put_mr(&seg->rl_mw, buf);
1124 rpcrdma_buffer_put_mr(&seg1->rl_mw, buf);
1128 rpcrdma_buffer_put_sendbuf(struct rpcrdma_req *req, struct rpcrdma_buffer *buf)
1130 buf->rb_send_bufs[--buf->rb_send_index] = req;
1132 if (req->rl_reply) {
1133 buf->rb_recv_bufs[--buf->rb_recv_index] = req->rl_reply;
1134 req->rl_reply->rr_func = NULL;
1135 req->rl_reply = NULL;
1139 /* rpcrdma_unmap_one() was already done during deregistration.
1140 * Redo only the ib_post_send().
1143 rpcrdma_retry_local_inv(struct rpcrdma_mw *r, struct rpcrdma_ia *ia)
1145 struct rpcrdma_xprt *r_xprt =
1146 container_of(ia, struct rpcrdma_xprt, rx_ia);
1147 struct ib_send_wr invalidate_wr, *bad_wr;
1150 dprintk("RPC: %s: FRMR %p is stale\n", __func__, r);
1152 /* When this FRMR is re-inserted into rb_mws, it is no longer stale */
1153 r->r.frmr.fr_state = FRMR_IS_INVALID;
1155 memset(&invalidate_wr, 0, sizeof(invalidate_wr));
1156 invalidate_wr.wr_id = (unsigned long)(void *)r;
1157 invalidate_wr.opcode = IB_WR_LOCAL_INV;
1158 invalidate_wr.ex.invalidate_rkey = r->r.frmr.fr_mr->rkey;
1159 DECR_CQCOUNT(&r_xprt->rx_ep);
1161 dprintk("RPC: %s: frmr %p invalidating rkey %08x\n",
1162 __func__, r, r->r.frmr.fr_mr->rkey);
1164 read_lock(&ia->ri_qplock);
1165 rc = ib_post_send(ia->ri_id->qp, &invalidate_wr, &bad_wr);
1166 read_unlock(&ia->ri_qplock);
1168 /* Force rpcrdma_buffer_get() to retry */
1169 r->r.frmr.fr_state = FRMR_IS_STALE;
1170 dprintk("RPC: %s: ib_post_send failed, %i\n",
1176 rpcrdma_retry_flushed_linv(struct list_head *stale,
1177 struct rpcrdma_buffer *buf)
1179 struct rpcrdma_ia *ia = rdmab_to_ia(buf);
1180 struct list_head *pos;
1181 struct rpcrdma_mw *r;
1182 unsigned long flags;
1184 list_for_each(pos, stale) {
1185 r = list_entry(pos, struct rpcrdma_mw, mw_list);
1186 rpcrdma_retry_local_inv(r, ia);
1189 spin_lock_irqsave(&buf->rb_lock, flags);
1190 list_splice_tail(stale, &buf->rb_mws);
1191 spin_unlock_irqrestore(&buf->rb_lock, flags);
1194 static struct rpcrdma_req *
1195 rpcrdma_buffer_get_frmrs(struct rpcrdma_req *req, struct rpcrdma_buffer *buf,
1196 struct list_head *stale)
1198 struct rpcrdma_mw *r;
1201 i = RPCRDMA_MAX_SEGS - 1;
1202 while (!list_empty(&buf->rb_mws)) {
1203 r = list_entry(buf->rb_mws.next,
1204 struct rpcrdma_mw, mw_list);
1205 list_del(&r->mw_list);
1206 if (r->r.frmr.fr_state == FRMR_IS_STALE) {
1207 list_add(&r->mw_list, stale);
1210 req->rl_segments[i].rl_mw = r;
1211 if (unlikely(i-- == 0))
1212 return req; /* Success */
1215 /* Not enough entries on rb_mws for this req */
1216 rpcrdma_buffer_put_sendbuf(req, buf);
1217 rpcrdma_buffer_put_mrs(req, buf);
1221 static struct rpcrdma_req *
1222 rpcrdma_buffer_get_fmrs(struct rpcrdma_req *req, struct rpcrdma_buffer *buf)
1224 struct rpcrdma_mw *r;
1227 i = RPCRDMA_MAX_SEGS - 1;
1228 while (!list_empty(&buf->rb_mws)) {
1229 r = list_entry(buf->rb_mws.next,
1230 struct rpcrdma_mw, mw_list);
1231 list_del(&r->mw_list);
1232 req->rl_segments[i].rl_mw = r;
1233 if (unlikely(i-- == 0))
1234 return req; /* Success */
1237 /* Not enough entries on rb_mws for this req */
1238 rpcrdma_buffer_put_sendbuf(req, buf);
1239 rpcrdma_buffer_put_mrs(req, buf);
1244 * Get a set of request/reply buffers.
1246 * Reply buffer (if needed) is attached to send buffer upon return.
1248 * rb_send_index and rb_recv_index MUST always be pointing to the
1249 * *next* available buffer (non-NULL). They are incremented after
1250 * removing buffers, and decremented *before* returning them.
1252 struct rpcrdma_req *
1253 rpcrdma_buffer_get(struct rpcrdma_buffer *buffers)
1255 struct rpcrdma_ia *ia = rdmab_to_ia(buffers);
1256 struct list_head stale;
1257 struct rpcrdma_req *req;
1258 unsigned long flags;
1260 spin_lock_irqsave(&buffers->rb_lock, flags);
1261 if (buffers->rb_send_index == buffers->rb_max_requests) {
1262 spin_unlock_irqrestore(&buffers->rb_lock, flags);
1263 dprintk("RPC: %s: out of request buffers\n", __func__);
1264 return ((struct rpcrdma_req *)NULL);
1267 req = buffers->rb_send_bufs[buffers->rb_send_index];
1268 if (buffers->rb_send_index < buffers->rb_recv_index) {
1269 dprintk("RPC: %s: %d extra receives outstanding (ok)\n",
1271 buffers->rb_recv_index - buffers->rb_send_index);
1272 req->rl_reply = NULL;
1274 req->rl_reply = buffers->rb_recv_bufs[buffers->rb_recv_index];
1275 buffers->rb_recv_bufs[buffers->rb_recv_index++] = NULL;
1277 buffers->rb_send_bufs[buffers->rb_send_index++] = NULL;
1279 INIT_LIST_HEAD(&stale);
1280 switch (ia->ri_memreg_strategy) {
1282 req = rpcrdma_buffer_get_frmrs(req, buffers, &stale);
1284 case RPCRDMA_MTHCAFMR:
1285 req = rpcrdma_buffer_get_fmrs(req, buffers);
1290 spin_unlock_irqrestore(&buffers->rb_lock, flags);
1291 if (!list_empty(&stale))
1292 rpcrdma_retry_flushed_linv(&stale, buffers);
1297 * Put request/reply buffers back into pool.
1298 * Pre-decrement counter/array index.
1301 rpcrdma_buffer_put(struct rpcrdma_req *req)
1303 struct rpcrdma_buffer *buffers = req->rl_buffer;
1304 struct rpcrdma_ia *ia = rdmab_to_ia(buffers);
1305 unsigned long flags;
1307 spin_lock_irqsave(&buffers->rb_lock, flags);
1308 rpcrdma_buffer_put_sendbuf(req, buffers);
1309 switch (ia->ri_memreg_strategy) {
1311 case RPCRDMA_MTHCAFMR:
1312 rpcrdma_buffer_put_mrs(req, buffers);
1317 spin_unlock_irqrestore(&buffers->rb_lock, flags);
1321 * Recover reply buffers from pool.
1322 * This happens when recovering from error conditions.
1323 * Post-increment counter/array index.
1326 rpcrdma_recv_buffer_get(struct rpcrdma_req *req)
1328 struct rpcrdma_buffer *buffers = req->rl_buffer;
1329 unsigned long flags;
1331 spin_lock_irqsave(&buffers->rb_lock, flags);
1332 if (buffers->rb_recv_index < buffers->rb_max_requests) {
1333 req->rl_reply = buffers->rb_recv_bufs[buffers->rb_recv_index];
1334 buffers->rb_recv_bufs[buffers->rb_recv_index++] = NULL;
1336 spin_unlock_irqrestore(&buffers->rb_lock, flags);
1340 * Put reply buffers back into pool when not attached to
1341 * request. This happens in error conditions.
1344 rpcrdma_recv_buffer_put(struct rpcrdma_rep *rep)
1346 struct rpcrdma_buffer *buffers = rep->rr_buffer;
1347 unsigned long flags;
1349 rep->rr_func = NULL;
1350 spin_lock_irqsave(&buffers->rb_lock, flags);
1351 buffers->rb_recv_bufs[--buffers->rb_recv_index] = rep;
1352 spin_unlock_irqrestore(&buffers->rb_lock, flags);
1356 * Wrappers for internal-use kmalloc memory registration, used by buffer code.
1360 rpcrdma_mapping_error(struct rpcrdma_mr_seg *seg)
1362 dprintk("RPC: map_one: offset %p iova %llx len %zu\n",
1364 (unsigned long long)seg->mr_dma, seg->mr_dmalen);
1368 rpcrdma_register_internal(struct rpcrdma_ia *ia, void *va, int len,
1369 struct ib_mr **mrp, struct ib_sge *iov)
1371 struct ib_phys_buf ipb;
1376 * All memory passed here was kmalloc'ed, therefore phys-contiguous.
1378 iov->addr = ib_dma_map_single(ia->ri_id->device,
1379 va, len, DMA_BIDIRECTIONAL);
1380 if (ib_dma_mapping_error(ia->ri_id->device, iov->addr))
1385 if (ia->ri_have_dma_lkey) {
1387 iov->lkey = ia->ri_dma_lkey;
1389 } else if (ia->ri_bind_mem != NULL) {
1391 iov->lkey = ia->ri_bind_mem->lkey;
1395 ipb.addr = iov->addr;
1396 ipb.size = iov->length;
1397 mr = ib_reg_phys_mr(ia->ri_pd, &ipb, 1,
1398 IB_ACCESS_LOCAL_WRITE, &iov->addr);
1400 dprintk("RPC: %s: phys convert: 0x%llx "
1401 "registered 0x%llx length %d\n",
1402 __func__, (unsigned long long)ipb.addr,
1403 (unsigned long long)iov->addr, len);
1408 dprintk("RPC: %s: failed with %i\n", __func__, rc);
1411 iov->lkey = mr->lkey;
1419 rpcrdma_deregister_internal(struct rpcrdma_ia *ia,
1420 struct ib_mr *mr, struct ib_sge *iov)
1424 ib_dma_unmap_single(ia->ri_id->device,
1425 iov->addr, iov->length, DMA_BIDIRECTIONAL);
1430 rc = ib_dereg_mr(mr);
1432 dprintk("RPC: %s: ib_dereg_mr failed %i\n", __func__, rc);
1437 * rpcrdma_alloc_regbuf - kmalloc and register memory for SEND/RECV buffers
1438 * @ia: controlling rpcrdma_ia
1439 * @size: size of buffer to be allocated, in bytes
1442 * Returns pointer to private header of an area of internally
1443 * registered memory, or an ERR_PTR. The registered buffer follows
1444 * the end of the private header.
1446 * xprtrdma uses a regbuf for posting an outgoing RDMA SEND, or for
1447 * receiving the payload of RDMA RECV operations. regbufs are not
1448 * used for RDMA READ/WRITE operations, thus are registered only for
1451 struct rpcrdma_regbuf *
1452 rpcrdma_alloc_regbuf(struct rpcrdma_ia *ia, size_t size, gfp_t flags)
1454 struct rpcrdma_regbuf *rb;
1458 rb = kmalloc(sizeof(*rb) + size, flags);
1463 rb->rg_owner = NULL;
1464 rc = rpcrdma_register_internal(ia, rb->rg_base, size,
1465 &rb->rg_mr, &rb->rg_iov);
1478 * rpcrdma_free_regbuf - deregister and free registered buffer
1479 * @ia: controlling rpcrdma_ia
1480 * @rb: regbuf to be deregistered and freed
1483 rpcrdma_free_regbuf(struct rpcrdma_ia *ia, struct rpcrdma_regbuf *rb)
1486 rpcrdma_deregister_internal(ia, rb->rg_mr, &rb->rg_iov);
1492 * Prepost any receive buffer, then post send.
1494 * Receive buffer is donated to hardware, reclaimed upon recv completion.
1497 rpcrdma_ep_post(struct rpcrdma_ia *ia,
1498 struct rpcrdma_ep *ep,
1499 struct rpcrdma_req *req)
1501 struct ib_send_wr send_wr, *send_wr_fail;
1502 struct rpcrdma_rep *rep = req->rl_reply;
1506 rc = rpcrdma_ep_post_recv(ia, ep, rep);
1509 req->rl_reply = NULL;
1512 send_wr.next = NULL;
1513 send_wr.wr_id = RPCRDMA_IGNORE_COMPLETION;
1514 send_wr.sg_list = req->rl_send_iov;
1515 send_wr.num_sge = req->rl_niovs;
1516 send_wr.opcode = IB_WR_SEND;
1517 if (send_wr.num_sge == 4) /* no need to sync any pad (constant) */
1518 ib_dma_sync_single_for_device(ia->ri_id->device,
1519 req->rl_send_iov[3].addr, req->rl_send_iov[3].length,
1521 ib_dma_sync_single_for_device(ia->ri_id->device,
1522 req->rl_send_iov[1].addr, req->rl_send_iov[1].length,
1524 ib_dma_sync_single_for_device(ia->ri_id->device,
1525 req->rl_send_iov[0].addr, req->rl_send_iov[0].length,
1528 if (DECR_CQCOUNT(ep) > 0)
1529 send_wr.send_flags = 0;
1530 else { /* Provider must take a send completion every now and then */
1532 send_wr.send_flags = IB_SEND_SIGNALED;
1535 rc = ib_post_send(ia->ri_id->qp, &send_wr, &send_wr_fail);
1537 dprintk("RPC: %s: ib_post_send returned %i\n", __func__,
1544 * (Re)post a receive buffer.
1547 rpcrdma_ep_post_recv(struct rpcrdma_ia *ia,
1548 struct rpcrdma_ep *ep,
1549 struct rpcrdma_rep *rep)
1551 struct ib_recv_wr recv_wr, *recv_wr_fail;
1554 recv_wr.next = NULL;
1555 recv_wr.wr_id = (u64) (unsigned long) rep;
1556 recv_wr.sg_list = &rep->rr_rdmabuf->rg_iov;
1557 recv_wr.num_sge = 1;
1559 ib_dma_sync_single_for_cpu(ia->ri_id->device,
1560 rdmab_addr(rep->rr_rdmabuf),
1561 rdmab_length(rep->rr_rdmabuf),
1564 rc = ib_post_recv(ia->ri_id->qp, &recv_wr, &recv_wr_fail);
1567 dprintk("RPC: %s: ib_post_recv returned %i\n", __func__,
1572 /* How many chunk list items fit within our inline buffers?
1575 rpcrdma_max_segments(struct rpcrdma_xprt *r_xprt)
1577 struct rpcrdma_create_data_internal *cdata = &r_xprt->rx_data;
1578 int bytes, segments;
1580 bytes = min_t(unsigned int, cdata->inline_wsize, cdata->inline_rsize);
1581 bytes -= RPCRDMA_HDRLEN_MIN;
1582 if (bytes < sizeof(struct rpcrdma_segment) * 2) {
1583 pr_warn("RPC: %s: inline threshold too small\n",
1588 segments = 1 << (fls(bytes / sizeof(struct rpcrdma_segment)) - 1);
1589 dprintk("RPC: %s: max chunk list size = %d segments\n",
1590 __func__, segments);