43 #include <linux/sunrpc/debug.h>
46 #include <linux/sched.h>
47 #include <linux/slab.h>
53 #include <linux/export.h>
56 #define RPCDBG_FACILITY RPCDBG_SVCXPRT
63 static void svc_rdma_release_rqst(
struct svc_rqst *);
64 static void dto_tasklet_func(
unsigned long data);
65 static void svc_rdma_detach(
struct svc_xprt *xprt);
66 static void svc_rdma_free(
struct svc_xprt *xprt);
67 static int svc_rdma_has_wspace(
struct svc_xprt *xprt);
76 .xpo_create = svc_rdma_create,
79 .xpo_release_rqst = svc_rdma_release_rqst,
80 .xpo_detach = svc_rdma_detach,
81 .xpo_free = svc_rdma_free,
83 .xpo_has_wspace = svc_rdma_has_wspace,
84 .xpo_accept = svc_rdma_accept,
90 .xcl_ops = &svc_rdma_ops,
105 INIT_LIST_HEAD(&ctxt->
dto_q);
116 for (i = 0; i < ctxt->
count && ctxt->
sge[
i].length; i++) {
125 ib_dma_unmap_page(xprt->
sc_cm_id->device,
141 for (i = 0; i < ctxt->
count; i++)
176 dprintk(
"svcrdma: received CQ event id=%d, context=%p\n",
177 event->
event, context);
186 switch (event->
event) {
192 dprintk(
"svcrdma: QP event %d received for QP=%p\n",
202 dprintk(
"svcrdma: QP ERROR event %d received for QP=%p, "
203 "closing transport\n",
219 static void dto_tasklet_func(
unsigned long data)
225 while (!list_empty(&dto_xprt_q)) {
229 spin_unlock_irqrestore(&dto_lock, flags);
237 spin_unlock_irqrestore(&dto_lock, flags);
271 spin_unlock_irqrestore(&dto_lock, flags);
274 tasklet_schedule(&dto_tasklet);
297 while ((ret = ib_poll_cq(xprt->
sc_rq_cq, 1, &
wc)) > 0) {
304 dprintk(
"svcrdma: transport closing putting ctxt %p\n", ctxt);
337 switch (ctxt->
wr_op) {
390 while ((ret = ib_poll_cq(cq, 1, &
wc)) > 0) {
410 static void sq_comp_handler(
struct ib_cq *cq,
void *cq_context)
435 spin_unlock_irqrestore(&dto_lock, flags);
438 tasklet_schedule(&dto_tasklet);
450 INIT_LIST_HEAD(&cma_xprt->
sc_dto_q);
504 pa = ib_dma_map_page(xprt->
sc_cm_id->device,
507 if (ib_dma_mapping_error(xprt->
sc_cm_id->device, pa))
510 ctxt->
sge[sge_no].addr = pa;
513 ctxt->
count = sge_no + 1;
519 recv_wr.
wr_id = (
u64)(
unsigned long)ctxt;
522 ret = ib_post_recv(xprt->
sc_qp, &recv_wr, &bad_recv_wr);
547 static void handle_connect_req(
struct rdma_cm_id *new_cma_id,
size_t client_ird)
554 newxprt = rdma_create_xprt(listen_xprt->
sc_xprt.xpt_server, 0);
556 dprintk(
"svcrdma: failed to create new transport\n");
561 dprintk(
"svcrdma: Creating newxprt=%p, cm_id=%p, listenxprt=%p\n",
562 newxprt, newxprt->
sc_cm_id, listen_xprt);
565 newxprt->
sc_ord = client_ird;
569 svc_xprt_set_remote(&newxprt->
sc_xprt, sa, svc_addr_len(sa));
571 svc_xprt_set_local(&newxprt->
sc_xprt, sa, svc_addr_len(sa));
577 spin_lock_bh(&listen_xprt->
sc_lock);
579 spin_unlock_bh(&listen_xprt->
sc_lock);
589 static int rdma_listen_handler(
struct rdma_cm_id *cma_id,
595 switch (event->
event) {
597 dprintk(
"svcrdma: Connect request on cma_id=%p, xprt = %p, "
599 handle_connect_req(cma_id,
605 dprintk(
"svcrdma: Connection completed on LISTEN xprt=%p, "
606 "cm_id=%p\n", xprt, cma_id);
610 dprintk(
"svcrdma: Device removal xprt=%p, cm_id=%p\n",
617 dprintk(
"svcrdma: Unexpected event on listening endpoint %p, "
618 "event=%d\n", cma_id, event->
event);
625 static int rdma_cma_handler(
struct rdma_cm_id *cma_id,
631 switch (event->
event) {
635 dprintk(
"svcrdma: Connection completed on DTO xprt=%p, "
636 "cm_id=%p\n", xprt, cma_id);
641 dprintk(
"svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
650 dprintk(
"svcrdma: Device removal cma_id=%p, xprt = %p, "
651 "event=%d\n", cma_id, xprt, event->
event);
658 dprintk(
"svcrdma: Unexpected event on DTO endpoint %p, "
659 "event=%d\n", cma_id, event->
event);
678 dprintk(
"svcrdma: Creating RDMA socket\n");
683 cma_xprt = rdma_create_xprt(serv, 1);
690 if (IS_ERR(listen_id)) {
691 ret = PTR_ERR(listen_id);
692 dprintk(
"svcrdma: rdma_create_id failed = %d\n", ret);
698 dprintk(
"svcrdma: rdma_bind_addr failed = %d\n", ret);
705 dprintk(
"svcrdma: rdma_listen failed = %d\n", ret);
714 svc_xprt_set_local(&cma_xprt->
sc_xprt, sa, salen);
757 static void rdma_dealloc_frmr_q(
struct svcxprt_rdma *xprt)
787 return rdma_alloc_frmr(rdma);
794 for (page_no = 0; page_no < frmr->
page_list_len; page_no++) {
796 if (ib_dma_mapping_error(frmr->
mr->device, addr))
799 ib_dma_unmap_page(frmr->
mr->device, addr,
PAGE_SIZE,
808 frmr_unmap_dma(rdma, frmr);
842 spin_lock_bh(&listen_rdma->
sc_lock);
850 spin_unlock_bh(&listen_rdma->
sc_lock);
854 dprintk(
"svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
859 dprintk(
"svcrdma: could not query device attributes on "
860 "device %p, rc=%d\n", newxprt->
sc_cm_id->device, ret);
880 if (IS_ERR(newxprt->
sc_pd)) {
881 dprintk(
"svcrdma: error creating PD for connect request\n");
891 dprintk(
"svcrdma: error creating SQ CQ for connect request\n");
901 dprintk(
"svcrdma: error creating RQ CQ for connect request\n");
905 memset(&qp_attr, 0,
sizeof qp_attr);
906 qp_attr.event_handler = qp_event_handler;
907 qp_attr.qp_context = &newxprt->
sc_xprt;
910 qp_attr.cap.max_send_sge = newxprt->
sc_max_sge;
911 qp_attr.cap.max_recv_sge = newxprt->
sc_max_sge;
914 qp_attr.send_cq = newxprt->
sc_sq_cq;
915 qp_attr.recv_cq = newxprt->
sc_rq_cq;
916 dprintk(
"svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n"
917 " cm_id->device=%p, sc_pd->device=%p\n"
918 " cap.max_send_wr = %d\n"
919 " cap.max_recv_wr = %d\n"
920 " cap.max_send_sge = %d\n"
921 " cap.max_recv_sge = %d\n",
924 qp_attr.cap.max_send_wr,
925 qp_attr.cap.max_recv_wr,
926 qp_attr.cap.max_send_sge,
927 qp_attr.cap.max_recv_sge);
936 qp_attr.cap.max_send_sge -= 2;
937 qp_attr.cap.max_recv_sge -= 2;
941 dprintk(
"svcrdma: failed to create QP, ret=%d\n", ret);
944 newxprt->
sc_max_sge = qp_attr.cap.max_send_sge;
945 newxprt->
sc_max_sge = qp_attr.cap.max_recv_sge;
975 devattr.max_fast_reg_page_list_len;
1013 dprintk(
"svcrdma: Failed to create DMA MR ret=%d\n",
1020 newxprt->
sc_cm_id->device->local_dma_lkey;
1026 dprintk(
"svcrdma: failure posting receive buffers\n");
1032 newxprt->
sc_cm_id->event_handler = rdma_cma_handler;
1043 memset(&conn_param, 0,
sizeof conn_param);
1044 conn_param.responder_resources = 0;
1045 conn_param.initiator_depth = newxprt->
sc_ord;
1048 dprintk(
"svcrdma: failed to accept new connection, ret=%d\n",
1053 dprintk(
"svcrdma: new connection %p accepted with the following "
1055 " local_ip : %pI4\n"
1056 " local_port : %d\n"
1057 " remote_ip : %pI4\n"
1058 " remote_port : %d\n"
1061 " max_requests : %d\n"
1065 route.addr.src_addr)->sin_addr.s_addr,
1067 route.addr.src_addr)->sin_port),
1069 route.addr.dst_addr)->sin_addr.s_addr,
1071 route.addr.dst_addr)->sin_port),
1080 dprintk(
"svcrdma: failure accepting new connection rc=%d.\n", ret);
1082 svc_xprt_get(&newxprt->
sc_xprt);
1083 if (newxprt->
sc_qp && !IS_ERR(newxprt->
sc_qp))
1091 static void svc_rdma_release_rqst(
struct svc_rqst *rqstp)
1107 static void svc_rdma_detach(
struct svc_xprt *xprt)
1111 dprintk(
"svc: svc_rdma_detach(%p)\n", xprt);
1121 dprintk(
"svcrdma: svc_rdma_free(%p)\n", rdma);
1137 list_del_init(&ctxt->
dto_q);
1147 list_del_init(&ctxt->
dto_q);
1156 rdma_dealloc_frmr_q(rdma);
1180 static void svc_rdma_free(
struct svc_xprt *xprt)
1188 static int svc_rdma_has_wspace(
struct svc_xprt *xprt)
1228 key = (
u8)(frmr->
mr->lkey & 0x000000FF);
1229 ib_update_fast_reg_key(frmr->
mr, ++key);
1232 memset(&fastreg_wr, 0,
sizeof fastreg_wr);
1257 for (n_wr = wr->
next; n_wr; n_wr = n_wr->
next)
1264 spin_unlock_bh(&xprt->
sc_lock);
1284 ret = ib_post_send(xprt->
sc_qp, wr, &bad_wr);
1290 dprintk(
"svcrdma: failed to post SQ WR rc=%d, "
1291 "sc_sq_count=%d, sc_sq_depth=%d\n",
1295 spin_unlock_bh(&xprt->
sc_lock);
1325 ctxt->
sge[0].addr = ib_dma_map_page(xprt->
sc_cm_id->device,
1327 if (ib_dma_mapping_error(xprt->
sc_cm_id->device, ctxt->
sge[0].addr)) {
1337 memset(&err_wr, 0,
sizeof err_wr);
1348 dprintk(
"svcrdma: Error %d posting send for protocol error\n",