svc_rdma_transport.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  1. /*
  2. * Copyright (c) 2014 Open Grid Computing, Inc. All rights reserved.
  3. * Copyright (c) 2005-2007 Network Appliance, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the BSD-type
  9. * license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. *
  15. * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. *
  18. * Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials provided
  21. * with the distribution.
  22. *
  23. * Neither the name of the Network Appliance, Inc. nor the names of
  24. * its contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written
  26. * permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * Author: Tom Tucker <tom@opengridcomputing.com>
  41. */
  42. #include <linux/sunrpc/svc_xprt.h>
  43. #include <linux/sunrpc/addr.h>
  44. #include <linux/sunrpc/debug.h>
  45. #include <linux/sunrpc/rpc_rdma.h>
  46. #include <linux/interrupt.h>
  47. #include <linux/sched.h>
  48. #include <linux/slab.h>
  49. #include <linux/spinlock.h>
  50. #include <linux/workqueue.h>
  51. #include <rdma/ib_verbs.h>
  52. #include <rdma/rdma_cm.h>
  53. #include <rdma/rw.h>
  54. #include <linux/sunrpc/svc_rdma.h>
  55. #include <linux/export.h>
  56. #include "xprt_rdma.h"
  57. #define RPCDBG_FACILITY RPCDBG_SVCXPRT
  58. static int svc_rdma_post_recv(struct svcxprt_rdma *xprt);
  59. static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *, int);
  60. static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
  61. struct net *net,
  62. struct sockaddr *sa, int salen,
  63. int flags);
  64. static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt);
  65. static void svc_rdma_release_rqst(struct svc_rqst *);
  66. static void svc_rdma_detach(struct svc_xprt *xprt);
  67. static void svc_rdma_free(struct svc_xprt *xprt);
  68. static int svc_rdma_has_wspace(struct svc_xprt *xprt);
  69. static int svc_rdma_secure_port(struct svc_rqst *);
  70. static void svc_rdma_kill_temp_xprt(struct svc_xprt *);
  71. static const struct svc_xprt_ops svc_rdma_ops = {
  72. .xpo_create = svc_rdma_create,
  73. .xpo_recvfrom = svc_rdma_recvfrom,
  74. .xpo_sendto = svc_rdma_sendto,
  75. .xpo_release_rqst = svc_rdma_release_rqst,
  76. .xpo_detach = svc_rdma_detach,
  77. .xpo_free = svc_rdma_free,
  78. .xpo_prep_reply_hdr = svc_rdma_prep_reply_hdr,
  79. .xpo_has_wspace = svc_rdma_has_wspace,
  80. .xpo_accept = svc_rdma_accept,
  81. .xpo_secure_port = svc_rdma_secure_port,
  82. .xpo_kill_temp_xprt = svc_rdma_kill_temp_xprt,
  83. };
  84. struct svc_xprt_class svc_rdma_class = {
  85. .xcl_name = "rdma",
  86. .xcl_owner = THIS_MODULE,
  87. .xcl_ops = &svc_rdma_ops,
  88. .xcl_max_payload = RPCSVC_MAXPAYLOAD_RDMA,
  89. .xcl_ident = XPRT_TRANSPORT_RDMA,
  90. };
  91. #if defined(CONFIG_SUNRPC_BACKCHANNEL)
  92. static struct svc_xprt *svc_rdma_bc_create(struct svc_serv *, struct net *,
  93. struct sockaddr *, int, int);
  94. static void svc_rdma_bc_detach(struct svc_xprt *);
  95. static void svc_rdma_bc_free(struct svc_xprt *);
  96. static const struct svc_xprt_ops svc_rdma_bc_ops = {
  97. .xpo_create = svc_rdma_bc_create,
  98. .xpo_detach = svc_rdma_bc_detach,
  99. .xpo_free = svc_rdma_bc_free,
  100. .xpo_prep_reply_hdr = svc_rdma_prep_reply_hdr,
  101. .xpo_secure_port = svc_rdma_secure_port,
  102. };
  103. struct svc_xprt_class svc_rdma_bc_class = {
  104. .xcl_name = "rdma-bc",
  105. .xcl_owner = THIS_MODULE,
  106. .xcl_ops = &svc_rdma_bc_ops,
  107. .xcl_max_payload = (1024 - RPCRDMA_HDRLEN_MIN)
  108. };
  109. static struct svc_xprt *svc_rdma_bc_create(struct svc_serv *serv,
  110. struct net *net,
  111. struct sockaddr *sa, int salen,
  112. int flags)
  113. {
  114. struct svcxprt_rdma *cma_xprt;
  115. struct svc_xprt *xprt;
  116. cma_xprt = rdma_create_xprt(serv, 0);
  117. if (!cma_xprt)
  118. return ERR_PTR(-ENOMEM);
  119. xprt = &cma_xprt->sc_xprt;
  120. svc_xprt_init(net, &svc_rdma_bc_class, xprt, serv);
  121. set_bit(XPT_CONG_CTRL, &xprt->xpt_flags);
  122. serv->sv_bc_xprt = xprt;
  123. dprintk("svcrdma: %s(%p)\n", __func__, xprt);
  124. return xprt;
  125. }
  126. static void svc_rdma_bc_detach(struct svc_xprt *xprt)
  127. {
  128. dprintk("svcrdma: %s(%p)\n", __func__, xprt);
  129. }
  130. static void svc_rdma_bc_free(struct svc_xprt *xprt)
  131. {
  132. struct svcxprt_rdma *rdma =
  133. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  134. dprintk("svcrdma: %s(%p)\n", __func__, xprt);
  135. if (xprt)
  136. kfree(rdma);
  137. }
  138. #endif /* CONFIG_SUNRPC_BACKCHANNEL */
  139. static struct svc_rdma_op_ctxt *alloc_ctxt(struct svcxprt_rdma *xprt,
  140. gfp_t flags)
  141. {
  142. struct svc_rdma_op_ctxt *ctxt;
  143. ctxt = kmalloc(sizeof(*ctxt), flags);
  144. if (ctxt) {
  145. ctxt->xprt = xprt;
  146. INIT_LIST_HEAD(&ctxt->list);
  147. }
  148. return ctxt;
  149. }
  150. static bool svc_rdma_prealloc_ctxts(struct svcxprt_rdma *xprt)
  151. {
  152. unsigned int i;
  153. /* Each RPC/RDMA credit can consume one Receive and
  154. * one Send WQE at the same time.
  155. */
  156. i = xprt->sc_sq_depth + xprt->sc_rq_depth;
  157. while (i--) {
  158. struct svc_rdma_op_ctxt *ctxt;
  159. ctxt = alloc_ctxt(xprt, GFP_KERNEL);
  160. if (!ctxt) {
  161. dprintk("svcrdma: No memory for RDMA ctxt\n");
  162. return false;
  163. }
  164. list_add(&ctxt->list, &xprt->sc_ctxts);
  165. }
  166. return true;
  167. }
  168. struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *xprt)
  169. {
  170. struct svc_rdma_op_ctxt *ctxt = NULL;
  171. spin_lock(&xprt->sc_ctxt_lock);
  172. xprt->sc_ctxt_used++;
  173. if (list_empty(&xprt->sc_ctxts))
  174. goto out_empty;
  175. ctxt = list_first_entry(&xprt->sc_ctxts,
  176. struct svc_rdma_op_ctxt, list);
  177. list_del(&ctxt->list);
  178. spin_unlock(&xprt->sc_ctxt_lock);
  179. out:
  180. ctxt->count = 0;
  181. ctxt->mapped_sges = 0;
  182. return ctxt;
  183. out_empty:
  184. /* Either pre-allocation missed the mark, or send
  185. * queue accounting is broken.
  186. */
  187. spin_unlock(&xprt->sc_ctxt_lock);
  188. ctxt = alloc_ctxt(xprt, GFP_NOIO);
  189. if (ctxt)
  190. goto out;
  191. spin_lock(&xprt->sc_ctxt_lock);
  192. xprt->sc_ctxt_used--;
  193. spin_unlock(&xprt->sc_ctxt_lock);
  194. WARN_ONCE(1, "svcrdma: empty RDMA ctxt list?\n");
  195. return NULL;
  196. }
  197. void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt)
  198. {
  199. struct svcxprt_rdma *xprt = ctxt->xprt;
  200. struct ib_device *device = xprt->sc_cm_id->device;
  201. unsigned int i;
  202. for (i = 0; i < ctxt->mapped_sges; i++)
  203. ib_dma_unmap_page(device,
  204. ctxt->sge[i].addr,
  205. ctxt->sge[i].length,
  206. ctxt->direction);
  207. ctxt->mapped_sges = 0;
  208. }
  209. void svc_rdma_put_context(struct svc_rdma_op_ctxt *ctxt, int free_pages)
  210. {
  211. struct svcxprt_rdma *xprt = ctxt->xprt;
  212. int i;
  213. if (free_pages)
  214. for (i = 0; i < ctxt->count; i++)
  215. put_page(ctxt->pages[i]);
  216. spin_lock(&xprt->sc_ctxt_lock);
  217. xprt->sc_ctxt_used--;
  218. list_add(&ctxt->list, &xprt->sc_ctxts);
  219. spin_unlock(&xprt->sc_ctxt_lock);
  220. }
  221. static void svc_rdma_destroy_ctxts(struct svcxprt_rdma *xprt)
  222. {
  223. while (!list_empty(&xprt->sc_ctxts)) {
  224. struct svc_rdma_op_ctxt *ctxt;
  225. ctxt = list_first_entry(&xprt->sc_ctxts,
  226. struct svc_rdma_op_ctxt, list);
  227. list_del(&ctxt->list);
  228. kfree(ctxt);
  229. }
  230. }
  231. /* QP event handler */
  232. static void qp_event_handler(struct ib_event *event, void *context)
  233. {
  234. struct svc_xprt *xprt = context;
  235. switch (event->event) {
  236. /* These are considered benign events */
  237. case IB_EVENT_PATH_MIG:
  238. case IB_EVENT_COMM_EST:
  239. case IB_EVENT_SQ_DRAINED:
  240. case IB_EVENT_QP_LAST_WQE_REACHED:
  241. dprintk("svcrdma: QP event %s (%d) received for QP=%p\n",
  242. ib_event_msg(event->event), event->event,
  243. event->element.qp);
  244. break;
  245. /* These are considered fatal events */
  246. case IB_EVENT_PATH_MIG_ERR:
  247. case IB_EVENT_QP_FATAL:
  248. case IB_EVENT_QP_REQ_ERR:
  249. case IB_EVENT_QP_ACCESS_ERR:
  250. case IB_EVENT_DEVICE_FATAL:
  251. default:
  252. dprintk("svcrdma: QP ERROR event %s (%d) received for QP=%p, "
  253. "closing transport\n",
  254. ib_event_msg(event->event), event->event,
  255. event->element.qp);
  256. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  257. svc_xprt_enqueue(xprt);
  258. break;
  259. }
  260. }
  261. /**
  262. * svc_rdma_wc_receive - Invoked by RDMA provider for each polled Receive WC
  263. * @cq: completion queue
  264. * @wc: completed WR
  265. *
  266. */
  267. static void svc_rdma_wc_receive(struct ib_cq *cq, struct ib_wc *wc)
  268. {
  269. struct svcxprt_rdma *xprt = cq->cq_context;
  270. struct ib_cqe *cqe = wc->wr_cqe;
  271. struct svc_rdma_op_ctxt *ctxt;
  272. /* WARNING: Only wc->wr_cqe and wc->status are reliable */
  273. ctxt = container_of(cqe, struct svc_rdma_op_ctxt, cqe);
  274. svc_rdma_unmap_dma(ctxt);
  275. if (wc->status != IB_WC_SUCCESS)
  276. goto flushed;
  277. /* All wc fields are now known to be valid */
  278. ctxt->byte_len = wc->byte_len;
  279. spin_lock(&xprt->sc_rq_dto_lock);
  280. list_add_tail(&ctxt->list, &xprt->sc_rq_dto_q);
  281. spin_unlock(&xprt->sc_rq_dto_lock);
  282. svc_rdma_post_recv(xprt);
  283. set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
  284. if (test_bit(RDMAXPRT_CONN_PENDING, &xprt->sc_flags))
  285. goto out;
  286. goto out_enqueue;
  287. flushed:
  288. if (wc->status != IB_WC_WR_FLUSH_ERR)
  289. pr_warn("svcrdma: receive: %s (%u/0x%x)\n",
  290. ib_wc_status_msg(wc->status),
  291. wc->status, wc->vendor_err);
  292. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  293. svc_rdma_put_context(ctxt, 1);
  294. out_enqueue:
  295. svc_xprt_enqueue(&xprt->sc_xprt);
  296. out:
  297. svc_xprt_put(&xprt->sc_xprt);
  298. }
  299. /**
  300. * svc_rdma_wc_send - Invoked by RDMA provider for each polled Send WC
  301. * @cq: completion queue
  302. * @wc: completed WR
  303. *
  304. */
  305. void svc_rdma_wc_send(struct ib_cq *cq, struct ib_wc *wc)
  306. {
  307. struct svcxprt_rdma *xprt = cq->cq_context;
  308. struct ib_cqe *cqe = wc->wr_cqe;
  309. struct svc_rdma_op_ctxt *ctxt;
  310. atomic_inc(&xprt->sc_sq_avail);
  311. wake_up(&xprt->sc_send_wait);
  312. ctxt = container_of(cqe, struct svc_rdma_op_ctxt, cqe);
  313. svc_rdma_unmap_dma(ctxt);
  314. svc_rdma_put_context(ctxt, 1);
  315. if (unlikely(wc->status != IB_WC_SUCCESS)) {
  316. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  317. svc_xprt_enqueue(&xprt->sc_xprt);
  318. if (wc->status != IB_WC_WR_FLUSH_ERR)
  319. pr_err("svcrdma: Send: %s (%u/0x%x)\n",
  320. ib_wc_status_msg(wc->status),
  321. wc->status, wc->vendor_err);
  322. }
  323. svc_xprt_put(&xprt->sc_xprt);
  324. }
  325. static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv,
  326. int listener)
  327. {
  328. struct svcxprt_rdma *cma_xprt = kzalloc(sizeof *cma_xprt, GFP_KERNEL);
  329. if (!cma_xprt)
  330. return NULL;
  331. svc_xprt_init(&init_net, &svc_rdma_class, &cma_xprt->sc_xprt, serv);
  332. INIT_LIST_HEAD(&cma_xprt->sc_accept_q);
  333. INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
  334. INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
  335. INIT_LIST_HEAD(&cma_xprt->sc_ctxts);
  336. INIT_LIST_HEAD(&cma_xprt->sc_rw_ctxts);
  337. init_waitqueue_head(&cma_xprt->sc_send_wait);
  338. spin_lock_init(&cma_xprt->sc_lock);
  339. spin_lock_init(&cma_xprt->sc_rq_dto_lock);
  340. spin_lock_init(&cma_xprt->sc_ctxt_lock);
  341. spin_lock_init(&cma_xprt->sc_rw_ctxt_lock);
  342. /*
  343. * Note that this implies that the underlying transport support
  344. * has some form of congestion control (see RFC 7530 section 3.1
  345. * paragraph 2). For now, we assume that all supported RDMA
  346. * transports are suitable here.
  347. */
  348. set_bit(XPT_CONG_CTRL, &cma_xprt->sc_xprt.xpt_flags);
  349. if (listener)
  350. set_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
  351. return cma_xprt;
  352. }
  353. static int
  354. svc_rdma_post_recv(struct svcxprt_rdma *xprt)
  355. {
  356. struct ib_recv_wr recv_wr, *bad_recv_wr;
  357. struct svc_rdma_op_ctxt *ctxt;
  358. struct page *page;
  359. dma_addr_t pa;
  360. int sge_no;
  361. int buflen;
  362. int ret;
  363. ctxt = svc_rdma_get_context(xprt);
  364. buflen = 0;
  365. ctxt->direction = DMA_FROM_DEVICE;
  366. ctxt->cqe.done = svc_rdma_wc_receive;
  367. for (sge_no = 0; buflen < xprt->sc_max_req_size; sge_no++) {
  368. if (sge_no >= xprt->sc_max_sge) {
  369. pr_err("svcrdma: Too many sges (%d)\n", sge_no);
  370. goto err_put_ctxt;
  371. }
  372. page = alloc_page(GFP_KERNEL);
  373. if (!page)
  374. goto err_put_ctxt;
  375. ctxt->pages[sge_no] = page;
  376. pa = ib_dma_map_page(xprt->sc_cm_id->device,
  377. page, 0, PAGE_SIZE,
  378. DMA_FROM_DEVICE);
  379. if (ib_dma_mapping_error(xprt->sc_cm_id->device, pa))
  380. goto err_put_ctxt;
  381. svc_rdma_count_mappings(xprt, ctxt);
  382. ctxt->sge[sge_no].addr = pa;
  383. ctxt->sge[sge_no].length = PAGE_SIZE;
  384. ctxt->sge[sge_no].lkey = xprt->sc_pd->local_dma_lkey;
  385. ctxt->count = sge_no + 1;
  386. buflen += PAGE_SIZE;
  387. }
  388. recv_wr.next = NULL;
  389. recv_wr.sg_list = &ctxt->sge[0];
  390. recv_wr.num_sge = ctxt->count;
  391. recv_wr.wr_cqe = &ctxt->cqe;
  392. svc_xprt_get(&xprt->sc_xprt);
  393. ret = ib_post_recv(xprt->sc_qp, &recv_wr, &bad_recv_wr);
  394. if (ret) {
  395. svc_rdma_unmap_dma(ctxt);
  396. svc_rdma_put_context(ctxt, 1);
  397. svc_xprt_put(&xprt->sc_xprt);
  398. }
  399. return ret;
  400. err_put_ctxt:
  401. svc_rdma_unmap_dma(ctxt);
  402. svc_rdma_put_context(ctxt, 1);
  403. return -ENOMEM;
  404. }
  405. static void
  406. svc_rdma_parse_connect_private(struct svcxprt_rdma *newxprt,
  407. struct rdma_conn_param *param)
  408. {
  409. const struct rpcrdma_connect_private *pmsg = param->private_data;
  410. if (pmsg &&
  411. pmsg->cp_magic == rpcrdma_cmp_magic &&
  412. pmsg->cp_version == RPCRDMA_CMP_VERSION) {
  413. newxprt->sc_snd_w_inv = pmsg->cp_flags &
  414. RPCRDMA_CMP_F_SND_W_INV_OK;
  415. dprintk("svcrdma: client send_size %u, recv_size %u "
  416. "remote inv %ssupported\n",
  417. rpcrdma_decode_buffer_size(pmsg->cp_send_size),
  418. rpcrdma_decode_buffer_size(pmsg->cp_recv_size),
  419. newxprt->sc_snd_w_inv ? "" : "un");
  420. }
  421. }
  422. /*
  423. * This function handles the CONNECT_REQUEST event on a listening
  424. * endpoint. It is passed the cma_id for the _new_ connection. The context in
  425. * this cma_id is inherited from the listening cma_id and is the svc_xprt
  426. * structure for the listening endpoint.
  427. *
  428. * This function creates a new xprt for the new connection and enqueues it on
  429. * the accept queue for the listent xprt. When the listen thread is kicked, it
  430. * will call the recvfrom method on the listen xprt which will accept the new
  431. * connection.
  432. */
  433. static void handle_connect_req(struct rdma_cm_id *new_cma_id,
  434. struct rdma_conn_param *param)
  435. {
  436. struct svcxprt_rdma *listen_xprt = new_cma_id->context;
  437. struct svcxprt_rdma *newxprt;
  438. struct sockaddr *sa;
  439. /* Create a new transport */
  440. newxprt = rdma_create_xprt(listen_xprt->sc_xprt.xpt_server, 0);
  441. if (!newxprt) {
  442. dprintk("svcrdma: failed to create new transport\n");
  443. return;
  444. }
  445. newxprt->sc_cm_id = new_cma_id;
  446. new_cma_id->context = newxprt;
  447. dprintk("svcrdma: Creating newxprt=%p, cm_id=%p, listenxprt=%p\n",
  448. newxprt, newxprt->sc_cm_id, listen_xprt);
  449. svc_rdma_parse_connect_private(newxprt, param);
  450. /* Save client advertised inbound read limit for use later in accept. */
  451. newxprt->sc_ord = param->initiator_depth;
  452. /* Set the local and remote addresses in the transport */
  453. sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
  454. svc_xprt_set_remote(&newxprt->sc_xprt, sa, svc_addr_len(sa));
  455. sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
  456. svc_xprt_set_local(&newxprt->sc_xprt, sa, svc_addr_len(sa));
  457. /*
  458. * Enqueue the new transport on the accept queue of the listening
  459. * transport
  460. */
  461. spin_lock_bh(&listen_xprt->sc_lock);
  462. list_add_tail(&newxprt->sc_accept_q, &listen_xprt->sc_accept_q);
  463. spin_unlock_bh(&listen_xprt->sc_lock);
  464. set_bit(XPT_CONN, &listen_xprt->sc_xprt.xpt_flags);
  465. svc_xprt_enqueue(&listen_xprt->sc_xprt);
  466. }
  467. /*
  468. * Handles events generated on the listening endpoint. These events will be
  469. * either be incoming connect requests or adapter removal events.
  470. */
  471. static int rdma_listen_handler(struct rdma_cm_id *cma_id,
  472. struct rdma_cm_event *event)
  473. {
  474. struct svcxprt_rdma *xprt = cma_id->context;
  475. int ret = 0;
  476. switch (event->event) {
  477. case RDMA_CM_EVENT_CONNECT_REQUEST:
  478. dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
  479. "event = %s (%d)\n", cma_id, cma_id->context,
  480. rdma_event_msg(event->event), event->event);
  481. handle_connect_req(cma_id, &event->param.conn);
  482. break;
  483. case RDMA_CM_EVENT_ESTABLISHED:
  484. /* Accept complete */
  485. dprintk("svcrdma: Connection completed on LISTEN xprt=%p, "
  486. "cm_id=%p\n", xprt, cma_id);
  487. break;
  488. case RDMA_CM_EVENT_DEVICE_REMOVAL:
  489. dprintk("svcrdma: Device removal xprt=%p, cm_id=%p\n",
  490. xprt, cma_id);
  491. if (xprt) {
  492. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  493. svc_xprt_enqueue(&xprt->sc_xprt);
  494. }
  495. break;
  496. default:
  497. dprintk("svcrdma: Unexpected event on listening endpoint %p, "
  498. "event = %s (%d)\n", cma_id,
  499. rdma_event_msg(event->event), event->event);
  500. break;
  501. }
  502. return ret;
  503. }
  504. static int rdma_cma_handler(struct rdma_cm_id *cma_id,
  505. struct rdma_cm_event *event)
  506. {
  507. struct svc_xprt *xprt = cma_id->context;
  508. struct svcxprt_rdma *rdma =
  509. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  510. switch (event->event) {
  511. case RDMA_CM_EVENT_ESTABLISHED:
  512. /* Accept complete */
  513. svc_xprt_get(xprt);
  514. dprintk("svcrdma: Connection completed on DTO xprt=%p, "
  515. "cm_id=%p\n", xprt, cma_id);
  516. clear_bit(RDMAXPRT_CONN_PENDING, &rdma->sc_flags);
  517. svc_xprt_enqueue(xprt);
  518. break;
  519. case RDMA_CM_EVENT_DISCONNECTED:
  520. dprintk("svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
  521. xprt, cma_id);
  522. if (xprt) {
  523. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  524. svc_xprt_enqueue(xprt);
  525. svc_xprt_put(xprt);
  526. }
  527. break;
  528. case RDMA_CM_EVENT_DEVICE_REMOVAL:
  529. dprintk("svcrdma: Device removal cma_id=%p, xprt = %p, "
  530. "event = %s (%d)\n", cma_id, xprt,
  531. rdma_event_msg(event->event), event->event);
  532. if (xprt) {
  533. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  534. svc_xprt_enqueue(xprt);
  535. svc_xprt_put(xprt);
  536. }
  537. break;
  538. default:
  539. dprintk("svcrdma: Unexpected event on DTO endpoint %p, "
  540. "event = %s (%d)\n", cma_id,
  541. rdma_event_msg(event->event), event->event);
  542. break;
  543. }
  544. return 0;
  545. }
  546. /*
  547. * Create a listening RDMA service endpoint.
  548. */
  549. static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
  550. struct net *net,
  551. struct sockaddr *sa, int salen,
  552. int flags)
  553. {
  554. struct rdma_cm_id *listen_id;
  555. struct svcxprt_rdma *cma_xprt;
  556. int ret;
  557. dprintk("svcrdma: Creating RDMA socket\n");
  558. if ((sa->sa_family != AF_INET) && (sa->sa_family != AF_INET6)) {
  559. dprintk("svcrdma: Address family %d is not supported.\n", sa->sa_family);
  560. return ERR_PTR(-EAFNOSUPPORT);
  561. }
  562. cma_xprt = rdma_create_xprt(serv, 1);
  563. if (!cma_xprt)
  564. return ERR_PTR(-ENOMEM);
  565. listen_id = rdma_create_id(&init_net, rdma_listen_handler, cma_xprt,
  566. RDMA_PS_TCP, IB_QPT_RC);
  567. if (IS_ERR(listen_id)) {
  568. ret = PTR_ERR(listen_id);
  569. dprintk("svcrdma: rdma_create_id failed = %d\n", ret);
  570. goto err0;
  571. }
  572. /* Allow both IPv4 and IPv6 sockets to bind a single port
  573. * at the same time.
  574. */
  575. #if IS_ENABLED(CONFIG_IPV6)
  576. ret = rdma_set_afonly(listen_id, 1);
  577. if (ret) {
  578. dprintk("svcrdma: rdma_set_afonly failed = %d\n", ret);
  579. goto err1;
  580. }
  581. #endif
  582. ret = rdma_bind_addr(listen_id, sa);
  583. if (ret) {
  584. dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret);
  585. goto err1;
  586. }
  587. cma_xprt->sc_cm_id = listen_id;
  588. ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
  589. if (ret) {
  590. dprintk("svcrdma: rdma_listen failed = %d\n", ret);
  591. goto err1;
  592. }
  593. /*
  594. * We need to use the address from the cm_id in case the
  595. * caller specified 0 for the port number.
  596. */
  597. sa = (struct sockaddr *)&cma_xprt->sc_cm_id->route.addr.src_addr;
  598. svc_xprt_set_local(&cma_xprt->sc_xprt, sa, salen);
  599. return &cma_xprt->sc_xprt;
  600. err1:
  601. rdma_destroy_id(listen_id);
  602. err0:
  603. kfree(cma_xprt);
  604. return ERR_PTR(ret);
  605. }
  606. /*
  607. * This is the xpo_recvfrom function for listening endpoints. Its
  608. * purpose is to accept incoming connections. The CMA callback handler
  609. * has already created a new transport and attached it to the new CMA
  610. * ID.
  611. *
  612. * There is a queue of pending connections hung on the listening
  613. * transport. This queue contains the new svc_xprt structure. This
  614. * function takes svc_xprt structures off the accept_q and completes
  615. * the connection.
  616. */
  617. static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
  618. {
  619. struct svcxprt_rdma *listen_rdma;
  620. struct svcxprt_rdma *newxprt = NULL;
  621. struct rdma_conn_param conn_param;
  622. struct rpcrdma_connect_private pmsg;
  623. struct ib_qp_init_attr qp_attr;
  624. struct ib_device *dev;
  625. struct sockaddr *sap;
  626. unsigned int i, ctxts;
  627. int ret = 0;
  628. listen_rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt);
  629. clear_bit(XPT_CONN, &xprt->xpt_flags);
  630. /* Get the next entry off the accept list */
  631. spin_lock_bh(&listen_rdma->sc_lock);
  632. if (!list_empty(&listen_rdma->sc_accept_q)) {
  633. newxprt = list_entry(listen_rdma->sc_accept_q.next,
  634. struct svcxprt_rdma, sc_accept_q);
  635. list_del_init(&newxprt->sc_accept_q);
  636. }
  637. if (!list_empty(&listen_rdma->sc_accept_q))
  638. set_bit(XPT_CONN, &listen_rdma->sc_xprt.xpt_flags);
  639. spin_unlock_bh(&listen_rdma->sc_lock);
  640. if (!newxprt)
  641. return NULL;
  642. dprintk("svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
  643. newxprt, newxprt->sc_cm_id);
  644. dev = newxprt->sc_cm_id->device;
  645. newxprt->sc_port_num = newxprt->sc_cm_id->port_num;
  646. /* Qualify the transport resource defaults with the
  647. * capabilities of this particular device */
  648. newxprt->sc_max_sge = min((size_t)dev->attrs.max_sge,
  649. (size_t)RPCSVC_MAXPAGES);
  650. newxprt->sc_max_req_size = svcrdma_max_req_size;
  651. newxprt->sc_max_requests = svcrdma_max_requests;
  652. newxprt->sc_max_bc_requests = svcrdma_max_bc_requests;
  653. newxprt->sc_rq_depth = newxprt->sc_max_requests +
  654. newxprt->sc_max_bc_requests;
  655. if (newxprt->sc_rq_depth > dev->attrs.max_qp_wr) {
  656. pr_warn("svcrdma: reducing receive depth to %d\n",
  657. dev->attrs.max_qp_wr);
  658. newxprt->sc_rq_depth = dev->attrs.max_qp_wr;
  659. newxprt->sc_max_requests = newxprt->sc_rq_depth - 2;
  660. newxprt->sc_max_bc_requests = 2;
  661. }
  662. newxprt->sc_fc_credits = cpu_to_be32(newxprt->sc_max_requests);
  663. ctxts = rdma_rw_mr_factor(dev, newxprt->sc_port_num, RPCSVC_MAXPAGES);
  664. ctxts *= newxprt->sc_max_requests;
  665. newxprt->sc_sq_depth = newxprt->sc_rq_depth + ctxts;
  666. if (newxprt->sc_sq_depth > dev->attrs.max_qp_wr) {
  667. pr_warn("svcrdma: reducing send depth to %d\n",
  668. dev->attrs.max_qp_wr);
  669. newxprt->sc_sq_depth = dev->attrs.max_qp_wr;
  670. }
  671. atomic_set(&newxprt->sc_sq_avail, newxprt->sc_sq_depth);
  672. if (!svc_rdma_prealloc_ctxts(newxprt))
  673. goto errout;
  674. /*
  675. * Limit ORD based on client limit, local device limit, and
  676. * configured svcrdma limit.
  677. */
  678. newxprt->sc_ord = min_t(size_t, dev->attrs.max_qp_rd_atom, newxprt->sc_ord);
  679. newxprt->sc_ord = min_t(size_t, svcrdma_ord, newxprt->sc_ord);
  680. newxprt->sc_pd = ib_alloc_pd(dev, 0);
  681. if (IS_ERR(newxprt->sc_pd)) {
  682. dprintk("svcrdma: error creating PD for connect request\n");
  683. goto errout;
  684. }
  685. newxprt->sc_sq_cq = ib_alloc_cq(dev, newxprt, newxprt->sc_sq_depth,
  686. 0, IB_POLL_WORKQUEUE);
  687. if (IS_ERR(newxprt->sc_sq_cq)) {
  688. dprintk("svcrdma: error creating SQ CQ for connect request\n");
  689. goto errout;
  690. }
  691. newxprt->sc_rq_cq = ib_alloc_cq(dev, newxprt, newxprt->sc_rq_depth,
  692. 0, IB_POLL_WORKQUEUE);
  693. if (IS_ERR(newxprt->sc_rq_cq)) {
  694. dprintk("svcrdma: error creating RQ CQ for connect request\n");
  695. goto errout;
  696. }
  697. memset(&qp_attr, 0, sizeof qp_attr);
  698. qp_attr.event_handler = qp_event_handler;
  699. qp_attr.qp_context = &newxprt->sc_xprt;
  700. qp_attr.port_num = newxprt->sc_port_num;
  701. qp_attr.cap.max_rdma_ctxs = ctxts;
  702. qp_attr.cap.max_send_wr = newxprt->sc_sq_depth - ctxts;
  703. qp_attr.cap.max_recv_wr = newxprt->sc_rq_depth;
  704. qp_attr.cap.max_send_sge = newxprt->sc_max_sge;
  705. qp_attr.cap.max_recv_sge = newxprt->sc_max_sge;
  706. qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
  707. qp_attr.qp_type = IB_QPT_RC;
  708. qp_attr.send_cq = newxprt->sc_sq_cq;
  709. qp_attr.recv_cq = newxprt->sc_rq_cq;
  710. dprintk("svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n",
  711. newxprt->sc_cm_id, newxprt->sc_pd);
  712. dprintk(" cap.max_send_wr = %d, cap.max_recv_wr = %d\n",
  713. qp_attr.cap.max_send_wr, qp_attr.cap.max_recv_wr);
  714. dprintk(" cap.max_send_sge = %d, cap.max_recv_sge = %d\n",
  715. qp_attr.cap.max_send_sge, qp_attr.cap.max_recv_sge);
  716. ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd, &qp_attr);
  717. if (ret) {
  718. dprintk("svcrdma: failed to create QP, ret=%d\n", ret);
  719. goto errout;
  720. }
  721. newxprt->sc_qp = newxprt->sc_cm_id->qp;
  722. if (!(dev->attrs.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS))
  723. newxprt->sc_snd_w_inv = false;
  724. if (!rdma_protocol_iwarp(dev, newxprt->sc_port_num) &&
  725. !rdma_ib_or_roce(dev, newxprt->sc_port_num))
  726. goto errout;
  727. /* Post receive buffers */
  728. for (i = 0; i < newxprt->sc_max_requests; i++) {
  729. ret = svc_rdma_post_recv(newxprt);
  730. if (ret) {
  731. dprintk("svcrdma: failure posting receive buffers\n");
  732. goto errout;
  733. }
  734. }
  735. /* Swap out the handler */
  736. newxprt->sc_cm_id->event_handler = rdma_cma_handler;
  737. /* Construct RDMA-CM private message */
  738. pmsg.cp_magic = rpcrdma_cmp_magic;
  739. pmsg.cp_version = RPCRDMA_CMP_VERSION;
  740. pmsg.cp_flags = 0;
  741. pmsg.cp_send_size = pmsg.cp_recv_size =
  742. rpcrdma_encode_buffer_size(newxprt->sc_max_req_size);
  743. /* Accept Connection */
  744. set_bit(RDMAXPRT_CONN_PENDING, &newxprt->sc_flags);
  745. memset(&conn_param, 0, sizeof conn_param);
  746. conn_param.responder_resources = 0;
  747. conn_param.initiator_depth = newxprt->sc_ord;
  748. conn_param.private_data = &pmsg;
  749. conn_param.private_data_len = sizeof(pmsg);
  750. ret = rdma_accept(newxprt->sc_cm_id, &conn_param);
  751. if (ret) {
  752. dprintk("svcrdma: failed to accept new connection, ret=%d\n",
  753. ret);
  754. goto errout;
  755. }
  756. dprintk("svcrdma: new connection %p accepted:\n", newxprt);
  757. sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
  758. dprintk(" local address : %pIS:%u\n", sap, rpc_get_port(sap));
  759. sap = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
  760. dprintk(" remote address : %pIS:%u\n", sap, rpc_get_port(sap));
  761. dprintk(" max_sge : %d\n", newxprt->sc_max_sge);
  762. dprintk(" sq_depth : %d\n", newxprt->sc_sq_depth);
  763. dprintk(" rdma_rw_ctxs : %d\n", ctxts);
  764. dprintk(" max_requests : %d\n", newxprt->sc_max_requests);
  765. dprintk(" ord : %d\n", newxprt->sc_ord);
  766. return &newxprt->sc_xprt;
  767. errout:
  768. dprintk("svcrdma: failure accepting new connection rc=%d.\n", ret);
  769. /* Take a reference in case the DTO handler runs */
  770. svc_xprt_get(&newxprt->sc_xprt);
  771. if (newxprt->sc_qp && !IS_ERR(newxprt->sc_qp))
  772. ib_destroy_qp(newxprt->sc_qp);
  773. rdma_destroy_id(newxprt->sc_cm_id);
  774. /* This call to put will destroy the transport */
  775. svc_xprt_put(&newxprt->sc_xprt);
  776. return NULL;
  777. }
  778. static void svc_rdma_release_rqst(struct svc_rqst *rqstp)
  779. {
  780. }
  781. /*
  782. * When connected, an svc_xprt has at least two references:
  783. *
  784. * - A reference held by the cm_id between the ESTABLISHED and
  785. * DISCONNECTED events. If the remote peer disconnected first, this
  786. * reference could be gone.
  787. *
  788. * - A reference held by the svc_recv code that called this function
  789. * as part of close processing.
  790. *
  791. * At a minimum one references should still be held.
  792. */
  793. static void svc_rdma_detach(struct svc_xprt *xprt)
  794. {
  795. struct svcxprt_rdma *rdma =
  796. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  797. dprintk("svc: svc_rdma_detach(%p)\n", xprt);
  798. /* Disconnect and flush posted WQE */
  799. rdma_disconnect(rdma->sc_cm_id);
  800. }
  801. static void __svc_rdma_free(struct work_struct *work)
  802. {
  803. struct svcxprt_rdma *rdma =
  804. container_of(work, struct svcxprt_rdma, sc_work);
  805. struct svc_xprt *xprt = &rdma->sc_xprt;
  806. dprintk("svcrdma: %s(%p)\n", __func__, rdma);
  807. if (rdma->sc_qp && !IS_ERR(rdma->sc_qp))
  808. ib_drain_qp(rdma->sc_qp);
  809. /* We should only be called from kref_put */
  810. if (kref_read(&xprt->xpt_ref) != 0)
  811. pr_err("svcrdma: sc_xprt still in use? (%d)\n",
  812. kref_read(&xprt->xpt_ref));
  813. while (!list_empty(&rdma->sc_read_complete_q)) {
  814. struct svc_rdma_op_ctxt *ctxt;
  815. ctxt = list_first_entry(&rdma->sc_read_complete_q,
  816. struct svc_rdma_op_ctxt, list);
  817. list_del(&ctxt->list);
  818. svc_rdma_put_context(ctxt, 1);
  819. }
  820. while (!list_empty(&rdma->sc_rq_dto_q)) {
  821. struct svc_rdma_op_ctxt *ctxt;
  822. ctxt = list_first_entry(&rdma->sc_rq_dto_q,
  823. struct svc_rdma_op_ctxt, list);
  824. list_del(&ctxt->list);
  825. svc_rdma_put_context(ctxt, 1);
  826. }
  827. /* Warn if we leaked a resource or under-referenced */
  828. if (rdma->sc_ctxt_used != 0)
  829. pr_err("svcrdma: ctxt still in use? (%d)\n",
  830. rdma->sc_ctxt_used);
  831. /* Final put of backchannel client transport */
  832. if (xprt->xpt_bc_xprt) {
  833. xprt_put(xprt->xpt_bc_xprt);
  834. xprt->xpt_bc_xprt = NULL;
  835. }
  836. svc_rdma_destroy_rw_ctxts(rdma);
  837. svc_rdma_destroy_ctxts(rdma);
  838. /* Destroy the QP if present (not a listener) */
  839. if (rdma->sc_qp && !IS_ERR(rdma->sc_qp))
  840. ib_destroy_qp(rdma->sc_qp);
  841. if (rdma->sc_sq_cq && !IS_ERR(rdma->sc_sq_cq))
  842. ib_free_cq(rdma->sc_sq_cq);
  843. if (rdma->sc_rq_cq && !IS_ERR(rdma->sc_rq_cq))
  844. ib_free_cq(rdma->sc_rq_cq);
  845. if (rdma->sc_pd && !IS_ERR(rdma->sc_pd))
  846. ib_dealloc_pd(rdma->sc_pd);
  847. /* Destroy the CM ID */
  848. rdma_destroy_id(rdma->sc_cm_id);
  849. kfree(rdma);
  850. }
  851. static void svc_rdma_free(struct svc_xprt *xprt)
  852. {
  853. struct svcxprt_rdma *rdma =
  854. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  855. INIT_WORK(&rdma->sc_work, __svc_rdma_free);
  856. queue_work(svc_rdma_wq, &rdma->sc_work);
  857. }
  858. static int svc_rdma_has_wspace(struct svc_xprt *xprt)
  859. {
  860. struct svcxprt_rdma *rdma =
  861. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  862. /*
  863. * If there are already waiters on the SQ,
  864. * return false.
  865. */
  866. if (waitqueue_active(&rdma->sc_send_wait))
  867. return 0;
  868. /* Otherwise return true. */
  869. return 1;
  870. }
  871. static int svc_rdma_secure_port(struct svc_rqst *rqstp)
  872. {
  873. return 1;
  874. }
  875. static void svc_rdma_kill_temp_xprt(struct svc_xprt *xprt)
  876. {
  877. }
  878. int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
  879. {
  880. struct ib_send_wr *bad_wr, *n_wr;
  881. int wr_count;
  882. int i;
  883. int ret;
  884. if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
  885. return -ENOTCONN;
  886. wr_count = 1;
  887. for (n_wr = wr->next; n_wr; n_wr = n_wr->next)
  888. wr_count++;
  889. /* If the SQ is full, wait until an SQ entry is available */
  890. while (1) {
  891. if ((atomic_sub_return(wr_count, &xprt->sc_sq_avail) < 0)) {
  892. atomic_inc(&rdma_stat_sq_starve);
  893. /* Wait until SQ WR available if SQ still full */
  894. atomic_add(wr_count, &xprt->sc_sq_avail);
  895. wait_event(xprt->sc_send_wait,
  896. atomic_read(&xprt->sc_sq_avail) > wr_count);
  897. if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
  898. return -ENOTCONN;
  899. continue;
  900. }
  901. /* Take a transport ref for each WR posted */
  902. for (i = 0; i < wr_count; i++)
  903. svc_xprt_get(&xprt->sc_xprt);
  904. /* Bump used SQ WR count and post */
  905. ret = ib_post_send(xprt->sc_qp, wr, &bad_wr);
  906. if (ret) {
  907. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  908. for (i = 0; i < wr_count; i ++)
  909. svc_xprt_put(&xprt->sc_xprt);
  910. dprintk("svcrdma: failed to post SQ WR rc=%d\n", ret);
  911. dprintk(" sc_sq_avail=%d, sc_sq_depth=%d\n",
  912. atomic_read(&xprt->sc_sq_avail),
  913. xprt->sc_sq_depth);
  914. wake_up(&xprt->sc_send_wait);
  915. }
  916. break;
  917. }
  918. return ret;
  919. }