svc_rdma_transport.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. /*
  2. * Copyright (c) 2005-2007 Network Appliance, Inc. All rights reserved.
  3. *
  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
  8. * license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. *
  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.
  21. *
  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
  25. * permission.
  26. *
  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.
  38. *
  39. * Author: Tom Tucker <tom@opengridcomputing.com>
  40. */
  41. #include <linux/sunrpc/svc_xprt.h>
  42. #include <linux/sunrpc/debug.h>
  43. #include <linux/sunrpc/rpc_rdma.h>
  44. #include <linux/spinlock.h>
  45. #include <rdma/ib_verbs.h>
  46. #include <rdma/rdma_cm.h>
  47. #include <linux/sunrpc/svc_rdma.h>
  48. #define RPCDBG_FACILITY RPCDBG_SVCXPRT
  49. static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
  50. struct sockaddr *sa, int salen,
  51. int flags);
  52. static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt);
  53. static void svc_rdma_release_rqst(struct svc_rqst *);
  54. static void rdma_destroy_xprt(struct svcxprt_rdma *xprt);
  55. static void dto_tasklet_func(unsigned long data);
  56. static void svc_rdma_detach(struct svc_xprt *xprt);
  57. static void svc_rdma_free(struct svc_xprt *xprt);
  58. static int svc_rdma_has_wspace(struct svc_xprt *xprt);
  59. static void rq_cq_reap(struct svcxprt_rdma *xprt);
  60. static void sq_cq_reap(struct svcxprt_rdma *xprt);
  61. DECLARE_TASKLET(dto_tasklet, dto_tasklet_func, 0UL);
  62. static DEFINE_SPINLOCK(dto_lock);
  63. static LIST_HEAD(dto_xprt_q);
  64. static struct svc_xprt_ops svc_rdma_ops = {
  65. .xpo_create = svc_rdma_create,
  66. .xpo_recvfrom = svc_rdma_recvfrom,
  67. .xpo_sendto = svc_rdma_sendto,
  68. .xpo_release_rqst = svc_rdma_release_rqst,
  69. .xpo_detach = svc_rdma_detach,
  70. .xpo_free = svc_rdma_free,
  71. .xpo_prep_reply_hdr = svc_rdma_prep_reply_hdr,
  72. .xpo_has_wspace = svc_rdma_has_wspace,
  73. .xpo_accept = svc_rdma_accept,
  74. };
  75. struct svc_xprt_class svc_rdma_class = {
  76. .xcl_name = "rdma",
  77. .xcl_owner = THIS_MODULE,
  78. .xcl_ops = &svc_rdma_ops,
  79. .xcl_max_payload = RPCSVC_MAXPAYLOAD_TCP,
  80. };
  81. static int rdma_bump_context_cache(struct svcxprt_rdma *xprt)
  82. {
  83. int target;
  84. int at_least_one = 0;
  85. struct svc_rdma_op_ctxt *ctxt;
  86. target = min(xprt->sc_ctxt_cnt + xprt->sc_ctxt_bump,
  87. xprt->sc_ctxt_max);
  88. spin_lock_bh(&xprt->sc_ctxt_lock);
  89. while (xprt->sc_ctxt_cnt < target) {
  90. xprt->sc_ctxt_cnt++;
  91. spin_unlock_bh(&xprt->sc_ctxt_lock);
  92. ctxt = kmalloc(sizeof(*ctxt), GFP_KERNEL);
  93. spin_lock_bh(&xprt->sc_ctxt_lock);
  94. if (ctxt) {
  95. at_least_one = 1;
  96. ctxt->next = xprt->sc_ctxt_head;
  97. xprt->sc_ctxt_head = ctxt;
  98. } else {
  99. /* kmalloc failed...give up for now */
  100. xprt->sc_ctxt_cnt--;
  101. break;
  102. }
  103. }
  104. spin_unlock_bh(&xprt->sc_ctxt_lock);
  105. dprintk("svcrdma: sc_ctxt_max=%d, sc_ctxt_cnt=%d\n",
  106. xprt->sc_ctxt_max, xprt->sc_ctxt_cnt);
  107. return at_least_one;
  108. }
  109. struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *xprt)
  110. {
  111. struct svc_rdma_op_ctxt *ctxt;
  112. while (1) {
  113. spin_lock_bh(&xprt->sc_ctxt_lock);
  114. if (unlikely(xprt->sc_ctxt_head == NULL)) {
  115. /* Try to bump my cache. */
  116. spin_unlock_bh(&xprt->sc_ctxt_lock);
  117. if (rdma_bump_context_cache(xprt))
  118. continue;
  119. printk(KERN_INFO "svcrdma: sleeping waiting for "
  120. "context memory on xprt=%p\n",
  121. xprt);
  122. schedule_timeout_uninterruptible(msecs_to_jiffies(500));
  123. continue;
  124. }
  125. ctxt = xprt->sc_ctxt_head;
  126. xprt->sc_ctxt_head = ctxt->next;
  127. spin_unlock_bh(&xprt->sc_ctxt_lock);
  128. ctxt->xprt = xprt;
  129. INIT_LIST_HEAD(&ctxt->dto_q);
  130. ctxt->count = 0;
  131. break;
  132. }
  133. return ctxt;
  134. }
  135. void svc_rdma_put_context(struct svc_rdma_op_ctxt *ctxt, int free_pages)
  136. {
  137. struct svcxprt_rdma *xprt;
  138. int i;
  139. BUG_ON(!ctxt);
  140. xprt = ctxt->xprt;
  141. if (free_pages)
  142. for (i = 0; i < ctxt->count; i++)
  143. put_page(ctxt->pages[i]);
  144. for (i = 0; i < ctxt->count; i++)
  145. dma_unmap_single(xprt->sc_cm_id->device->dma_device,
  146. ctxt->sge[i].addr,
  147. ctxt->sge[i].length,
  148. ctxt->direction);
  149. spin_lock_bh(&xprt->sc_ctxt_lock);
  150. ctxt->next = xprt->sc_ctxt_head;
  151. xprt->sc_ctxt_head = ctxt;
  152. spin_unlock_bh(&xprt->sc_ctxt_lock);
  153. }
  154. /* ib_cq event handler */
  155. static void cq_event_handler(struct ib_event *event, void *context)
  156. {
  157. struct svc_xprt *xprt = context;
  158. dprintk("svcrdma: received CQ event id=%d, context=%p\n",
  159. event->event, context);
  160. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  161. }
  162. /* QP event handler */
  163. static void qp_event_handler(struct ib_event *event, void *context)
  164. {
  165. struct svc_xprt *xprt = context;
  166. switch (event->event) {
  167. /* These are considered benign events */
  168. case IB_EVENT_PATH_MIG:
  169. case IB_EVENT_COMM_EST:
  170. case IB_EVENT_SQ_DRAINED:
  171. case IB_EVENT_QP_LAST_WQE_REACHED:
  172. dprintk("svcrdma: QP event %d received for QP=%p\n",
  173. event->event, event->element.qp);
  174. break;
  175. /* These are considered fatal events */
  176. case IB_EVENT_PATH_MIG_ERR:
  177. case IB_EVENT_QP_FATAL:
  178. case IB_EVENT_QP_REQ_ERR:
  179. case IB_EVENT_QP_ACCESS_ERR:
  180. case IB_EVENT_DEVICE_FATAL:
  181. default:
  182. dprintk("svcrdma: QP ERROR event %d received for QP=%p, "
  183. "closing transport\n",
  184. event->event, event->element.qp);
  185. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  186. break;
  187. }
  188. }
  189. /*
  190. * Data Transfer Operation Tasklet
  191. *
  192. * Walks a list of transports with I/O pending, removing entries as
  193. * they are added to the server's I/O pending list. Two bits indicate
  194. * if SQ, RQ, or both have I/O pending. The dto_lock is an irqsave
  195. * spinlock that serializes access to the transport list with the RQ
  196. * and SQ interrupt handlers.
  197. */
  198. static void dto_tasklet_func(unsigned long data)
  199. {
  200. struct svcxprt_rdma *xprt;
  201. unsigned long flags;
  202. spin_lock_irqsave(&dto_lock, flags);
  203. while (!list_empty(&dto_xprt_q)) {
  204. xprt = list_entry(dto_xprt_q.next,
  205. struct svcxprt_rdma, sc_dto_q);
  206. list_del_init(&xprt->sc_dto_q);
  207. spin_unlock_irqrestore(&dto_lock, flags);
  208. if (test_and_clear_bit(RDMAXPRT_RQ_PENDING, &xprt->sc_flags)) {
  209. ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
  210. rq_cq_reap(xprt);
  211. set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
  212. /*
  213. * If data arrived before established event,
  214. * don't enqueue. This defers RPC I/O until the
  215. * RDMA connection is complete.
  216. */
  217. if (!test_bit(RDMAXPRT_CONN_PENDING, &xprt->sc_flags))
  218. svc_xprt_enqueue(&xprt->sc_xprt);
  219. }
  220. if (test_and_clear_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags)) {
  221. ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
  222. sq_cq_reap(xprt);
  223. }
  224. spin_lock_irqsave(&dto_lock, flags);
  225. }
  226. spin_unlock_irqrestore(&dto_lock, flags);
  227. }
  228. /*
  229. * Receive Queue Completion Handler
  230. *
  231. * Since an RQ completion handler is called on interrupt context, we
  232. * need to defer the handling of the I/O to a tasklet
  233. */
  234. static void rq_comp_handler(struct ib_cq *cq, void *cq_context)
  235. {
  236. struct svcxprt_rdma *xprt = cq_context;
  237. unsigned long flags;
  238. /*
  239. * Set the bit regardless of whether or not it's on the list
  240. * because it may be on the list already due to an SQ
  241. * completion.
  242. */
  243. set_bit(RDMAXPRT_RQ_PENDING, &xprt->sc_flags);
  244. /*
  245. * If this transport is not already on the DTO transport queue,
  246. * add it
  247. */
  248. spin_lock_irqsave(&dto_lock, flags);
  249. if (list_empty(&xprt->sc_dto_q))
  250. list_add_tail(&xprt->sc_dto_q, &dto_xprt_q);
  251. spin_unlock_irqrestore(&dto_lock, flags);
  252. /* Tasklet does all the work to avoid irqsave locks. */
  253. tasklet_schedule(&dto_tasklet);
  254. }
  255. /*
  256. * rq_cq_reap - Process the RQ CQ.
  257. *
  258. * Take all completing WC off the CQE and enqueue the associated DTO
  259. * context on the dto_q for the transport.
  260. */
  261. static void rq_cq_reap(struct svcxprt_rdma *xprt)
  262. {
  263. int ret;
  264. struct ib_wc wc;
  265. struct svc_rdma_op_ctxt *ctxt = NULL;
  266. atomic_inc(&rdma_stat_rq_poll);
  267. spin_lock_bh(&xprt->sc_rq_dto_lock);
  268. while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
  269. ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
  270. ctxt->wc_status = wc.status;
  271. ctxt->byte_len = wc.byte_len;
  272. if (wc.status != IB_WC_SUCCESS) {
  273. /* Close the transport */
  274. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  275. svc_rdma_put_context(ctxt, 1);
  276. continue;
  277. }
  278. list_add_tail(&ctxt->dto_q, &xprt->sc_rq_dto_q);
  279. }
  280. spin_unlock_bh(&xprt->sc_rq_dto_lock);
  281. if (ctxt)
  282. atomic_inc(&rdma_stat_rq_prod);
  283. }
  284. /*
  285. * Send Queue Completion Handler - potentially called on interrupt context.
  286. */
  287. static void sq_cq_reap(struct svcxprt_rdma *xprt)
  288. {
  289. struct svc_rdma_op_ctxt *ctxt = NULL;
  290. struct ib_wc wc;
  291. struct ib_cq *cq = xprt->sc_sq_cq;
  292. int ret;
  293. atomic_inc(&rdma_stat_sq_poll);
  294. while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
  295. ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
  296. xprt = ctxt->xprt;
  297. if (wc.status != IB_WC_SUCCESS)
  298. /* Close the transport */
  299. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  300. /* Decrement used SQ WR count */
  301. atomic_dec(&xprt->sc_sq_count);
  302. wake_up(&xprt->sc_send_wait);
  303. switch (ctxt->wr_op) {
  304. case IB_WR_SEND:
  305. case IB_WR_RDMA_WRITE:
  306. svc_rdma_put_context(ctxt, 1);
  307. break;
  308. case IB_WR_RDMA_READ:
  309. if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) {
  310. set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
  311. set_bit(RDMACTXT_F_READ_DONE, &ctxt->flags);
  312. spin_lock_bh(&xprt->sc_read_complete_lock);
  313. list_add_tail(&ctxt->dto_q,
  314. &xprt->sc_read_complete_q);
  315. spin_unlock_bh(&xprt->sc_read_complete_lock);
  316. svc_xprt_enqueue(&xprt->sc_xprt);
  317. }
  318. break;
  319. default:
  320. printk(KERN_ERR "svcrdma: unexpected completion type, "
  321. "opcode=%d, status=%d\n",
  322. wc.opcode, wc.status);
  323. break;
  324. }
  325. }
  326. if (ctxt)
  327. atomic_inc(&rdma_stat_sq_prod);
  328. }
  329. static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
  330. {
  331. struct svcxprt_rdma *xprt = cq_context;
  332. unsigned long flags;
  333. /*
  334. * Set the bit regardless of whether or not it's on the list
  335. * because it may be on the list already due to an RQ
  336. * completion.
  337. */
  338. set_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags);
  339. /*
  340. * If this transport is not already on the DTO transport queue,
  341. * add it
  342. */
  343. spin_lock_irqsave(&dto_lock, flags);
  344. if (list_empty(&xprt->sc_dto_q))
  345. list_add_tail(&xprt->sc_dto_q, &dto_xprt_q);
  346. spin_unlock_irqrestore(&dto_lock, flags);
  347. /* Tasklet does all the work to avoid irqsave locks. */
  348. tasklet_schedule(&dto_tasklet);
  349. }
  350. static void create_context_cache(struct svcxprt_rdma *xprt,
  351. int ctxt_count, int ctxt_bump, int ctxt_max)
  352. {
  353. struct svc_rdma_op_ctxt *ctxt;
  354. int i;
  355. xprt->sc_ctxt_max = ctxt_max;
  356. xprt->sc_ctxt_bump = ctxt_bump;
  357. xprt->sc_ctxt_cnt = 0;
  358. xprt->sc_ctxt_head = NULL;
  359. for (i = 0; i < ctxt_count; i++) {
  360. ctxt = kmalloc(sizeof(*ctxt), GFP_KERNEL);
  361. if (ctxt) {
  362. ctxt->next = xprt->sc_ctxt_head;
  363. xprt->sc_ctxt_head = ctxt;
  364. xprt->sc_ctxt_cnt++;
  365. }
  366. }
  367. }
  368. static void destroy_context_cache(struct svc_rdma_op_ctxt *ctxt)
  369. {
  370. struct svc_rdma_op_ctxt *next;
  371. if (!ctxt)
  372. return;
  373. do {
  374. next = ctxt->next;
  375. kfree(ctxt);
  376. ctxt = next;
  377. } while (next);
  378. }
  379. static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv,
  380. int listener)
  381. {
  382. struct svcxprt_rdma *cma_xprt = kzalloc(sizeof *cma_xprt, GFP_KERNEL);
  383. if (!cma_xprt)
  384. return NULL;
  385. svc_xprt_init(&svc_rdma_class, &cma_xprt->sc_xprt, serv);
  386. INIT_LIST_HEAD(&cma_xprt->sc_accept_q);
  387. INIT_LIST_HEAD(&cma_xprt->sc_dto_q);
  388. INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
  389. INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
  390. init_waitqueue_head(&cma_xprt->sc_send_wait);
  391. spin_lock_init(&cma_xprt->sc_lock);
  392. spin_lock_init(&cma_xprt->sc_read_complete_lock);
  393. spin_lock_init(&cma_xprt->sc_ctxt_lock);
  394. spin_lock_init(&cma_xprt->sc_rq_dto_lock);
  395. cma_xprt->sc_ord = svcrdma_ord;
  396. cma_xprt->sc_max_req_size = svcrdma_max_req_size;
  397. cma_xprt->sc_max_requests = svcrdma_max_requests;
  398. cma_xprt->sc_sq_depth = svcrdma_max_requests * RPCRDMA_SQ_DEPTH_MULT;
  399. atomic_set(&cma_xprt->sc_sq_count, 0);
  400. if (!listener) {
  401. int reqs = cma_xprt->sc_max_requests;
  402. create_context_cache(cma_xprt,
  403. reqs << 1, /* starting size */
  404. reqs, /* bump amount */
  405. reqs +
  406. cma_xprt->sc_sq_depth +
  407. RPCRDMA_MAX_THREADS + 1); /* max */
  408. if (!cma_xprt->sc_ctxt_head) {
  409. kfree(cma_xprt);
  410. return NULL;
  411. }
  412. clear_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
  413. } else
  414. set_bit(XPT_LISTENER, &cma_xprt->sc_xprt.xpt_flags);
  415. return cma_xprt;
  416. }
  417. struct page *svc_rdma_get_page(void)
  418. {
  419. struct page *page;
  420. while ((page = alloc_page(GFP_KERNEL)) == NULL) {
  421. /* If we can't get memory, wait a bit and try again */
  422. printk(KERN_INFO "svcrdma: out of memory...retrying in 1000 "
  423. "jiffies.\n");
  424. schedule_timeout_uninterruptible(msecs_to_jiffies(1000));
  425. }
  426. return page;
  427. }
  428. int svc_rdma_post_recv(struct svcxprt_rdma *xprt)
  429. {
  430. struct ib_recv_wr recv_wr, *bad_recv_wr;
  431. struct svc_rdma_op_ctxt *ctxt;
  432. struct page *page;
  433. unsigned long pa;
  434. int sge_no;
  435. int buflen;
  436. int ret;
  437. ctxt = svc_rdma_get_context(xprt);
  438. buflen = 0;
  439. ctxt->direction = DMA_FROM_DEVICE;
  440. for (sge_no = 0; buflen < xprt->sc_max_req_size; sge_no++) {
  441. BUG_ON(sge_no >= xprt->sc_max_sge);
  442. page = svc_rdma_get_page();
  443. ctxt->pages[sge_no] = page;
  444. pa = ib_dma_map_page(xprt->sc_cm_id->device,
  445. page, 0, PAGE_SIZE,
  446. DMA_FROM_DEVICE);
  447. ctxt->sge[sge_no].addr = pa;
  448. ctxt->sge[sge_no].length = PAGE_SIZE;
  449. ctxt->sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
  450. buflen += PAGE_SIZE;
  451. }
  452. ctxt->count = sge_no;
  453. recv_wr.next = NULL;
  454. recv_wr.sg_list = &ctxt->sge[0];
  455. recv_wr.num_sge = ctxt->count;
  456. recv_wr.wr_id = (u64)(unsigned long)ctxt;
  457. ret = ib_post_recv(xprt->sc_qp, &recv_wr, &bad_recv_wr);
  458. return ret;
  459. }
  460. /*
  461. * This function handles the CONNECT_REQUEST event on a listening
  462. * endpoint. It is passed the cma_id for the _new_ connection. The context in
  463. * this cma_id is inherited from the listening cma_id and is the svc_xprt
  464. * structure for the listening endpoint.
  465. *
  466. * This function creates a new xprt for the new connection and enqueues it on
  467. * the accept queue for the listent xprt. When the listen thread is kicked, it
  468. * will call the recvfrom method on the listen xprt which will accept the new
  469. * connection.
  470. */
  471. static void handle_connect_req(struct rdma_cm_id *new_cma_id)
  472. {
  473. struct svcxprt_rdma *listen_xprt = new_cma_id->context;
  474. struct svcxprt_rdma *newxprt;
  475. /* Create a new transport */
  476. newxprt = rdma_create_xprt(listen_xprt->sc_xprt.xpt_server, 0);
  477. if (!newxprt) {
  478. dprintk("svcrdma: failed to create new transport\n");
  479. return;
  480. }
  481. newxprt->sc_cm_id = new_cma_id;
  482. new_cma_id->context = newxprt;
  483. dprintk("svcrdma: Creating newxprt=%p, cm_id=%p, listenxprt=%p\n",
  484. newxprt, newxprt->sc_cm_id, listen_xprt);
  485. /*
  486. * Enqueue the new transport on the accept queue of the listening
  487. * transport
  488. */
  489. spin_lock_bh(&listen_xprt->sc_lock);
  490. list_add_tail(&newxprt->sc_accept_q, &listen_xprt->sc_accept_q);
  491. spin_unlock_bh(&listen_xprt->sc_lock);
  492. /*
  493. * Can't use svc_xprt_received here because we are not on a
  494. * rqstp thread
  495. */
  496. set_bit(XPT_CONN, &listen_xprt->sc_xprt.xpt_flags);
  497. svc_xprt_enqueue(&listen_xprt->sc_xprt);
  498. }
  499. /*
  500. * Handles events generated on the listening endpoint. These events will be
  501. * either be incoming connect requests or adapter removal events.
  502. */
  503. static int rdma_listen_handler(struct rdma_cm_id *cma_id,
  504. struct rdma_cm_event *event)
  505. {
  506. struct svcxprt_rdma *xprt = cma_id->context;
  507. int ret = 0;
  508. switch (event->event) {
  509. case RDMA_CM_EVENT_CONNECT_REQUEST:
  510. dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
  511. "event=%d\n", cma_id, cma_id->context, event->event);
  512. handle_connect_req(cma_id);
  513. break;
  514. case RDMA_CM_EVENT_ESTABLISHED:
  515. /* Accept complete */
  516. dprintk("svcrdma: Connection completed on LISTEN xprt=%p, "
  517. "cm_id=%p\n", xprt, cma_id);
  518. break;
  519. case RDMA_CM_EVENT_DEVICE_REMOVAL:
  520. dprintk("svcrdma: Device removal xprt=%p, cm_id=%p\n",
  521. xprt, cma_id);
  522. if (xprt)
  523. set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
  524. break;
  525. default:
  526. dprintk("svcrdma: Unexpected event on listening endpoint %p, "
  527. "event=%d\n", cma_id, event->event);
  528. break;
  529. }
  530. return ret;
  531. }
  532. static int rdma_cma_handler(struct rdma_cm_id *cma_id,
  533. struct rdma_cm_event *event)
  534. {
  535. struct svc_xprt *xprt = cma_id->context;
  536. struct svcxprt_rdma *rdma =
  537. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  538. switch (event->event) {
  539. case RDMA_CM_EVENT_ESTABLISHED:
  540. /* Accept complete */
  541. dprintk("svcrdma: Connection completed on DTO xprt=%p, "
  542. "cm_id=%p\n", xprt, cma_id);
  543. clear_bit(RDMAXPRT_CONN_PENDING, &rdma->sc_flags);
  544. svc_xprt_enqueue(xprt);
  545. break;
  546. case RDMA_CM_EVENT_DISCONNECTED:
  547. dprintk("svcrdma: Disconnect on DTO xprt=%p, cm_id=%p\n",
  548. xprt, cma_id);
  549. if (xprt) {
  550. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  551. svc_xprt_enqueue(xprt);
  552. }
  553. break;
  554. case RDMA_CM_EVENT_DEVICE_REMOVAL:
  555. dprintk("svcrdma: Device removal cma_id=%p, xprt = %p, "
  556. "event=%d\n", cma_id, xprt, event->event);
  557. if (xprt) {
  558. set_bit(XPT_CLOSE, &xprt->xpt_flags);
  559. svc_xprt_enqueue(xprt);
  560. }
  561. break;
  562. default:
  563. dprintk("svcrdma: Unexpected event on DTO endpoint %p, "
  564. "event=%d\n", cma_id, event->event);
  565. break;
  566. }
  567. return 0;
  568. }
  569. /*
  570. * Create a listening RDMA service endpoint.
  571. */
  572. static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
  573. struct sockaddr *sa, int salen,
  574. int flags)
  575. {
  576. struct rdma_cm_id *listen_id;
  577. struct svcxprt_rdma *cma_xprt;
  578. struct svc_xprt *xprt;
  579. int ret;
  580. dprintk("svcrdma: Creating RDMA socket\n");
  581. cma_xprt = rdma_create_xprt(serv, 1);
  582. if (!cma_xprt)
  583. return ERR_PTR(ENOMEM);
  584. xprt = &cma_xprt->sc_xprt;
  585. listen_id = rdma_create_id(rdma_listen_handler, cma_xprt, RDMA_PS_TCP);
  586. if (IS_ERR(listen_id)) {
  587. rdma_destroy_xprt(cma_xprt);
  588. dprintk("svcrdma: rdma_create_id failed = %ld\n",
  589. PTR_ERR(listen_id));
  590. return (void *)listen_id;
  591. }
  592. ret = rdma_bind_addr(listen_id, sa);
  593. if (ret) {
  594. rdma_destroy_xprt(cma_xprt);
  595. rdma_destroy_id(listen_id);
  596. dprintk("svcrdma: rdma_bind_addr failed = %d\n", ret);
  597. return ERR_PTR(ret);
  598. }
  599. cma_xprt->sc_cm_id = listen_id;
  600. ret = rdma_listen(listen_id, RPCRDMA_LISTEN_BACKLOG);
  601. if (ret) {
  602. rdma_destroy_id(listen_id);
  603. rdma_destroy_xprt(cma_xprt);
  604. dprintk("svcrdma: rdma_listen failed = %d\n", ret);
  605. }
  606. /*
  607. * We need to use the address from the cm_id in case the
  608. * caller specified 0 for the port number.
  609. */
  610. sa = (struct sockaddr *)&cma_xprt->sc_cm_id->route.addr.src_addr;
  611. svc_xprt_set_local(&cma_xprt->sc_xprt, sa, salen);
  612. return &cma_xprt->sc_xprt;
  613. }
  614. /*
  615. * This is the xpo_recvfrom function for listening endpoints. Its
  616. * purpose is to accept incoming connections. The CMA callback handler
  617. * has already created a new transport and attached it to the new CMA
  618. * ID.
  619. *
  620. * There is a queue of pending connections hung on the listening
  621. * transport. This queue contains the new svc_xprt structure. This
  622. * function takes svc_xprt structures off the accept_q and completes
  623. * the connection.
  624. */
  625. static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
  626. {
  627. struct svcxprt_rdma *listen_rdma;
  628. struct svcxprt_rdma *newxprt = NULL;
  629. struct rdma_conn_param conn_param;
  630. struct ib_qp_init_attr qp_attr;
  631. struct ib_device_attr devattr;
  632. struct sockaddr *sa;
  633. int ret;
  634. int i;
  635. listen_rdma = container_of(xprt, struct svcxprt_rdma, sc_xprt);
  636. clear_bit(XPT_CONN, &xprt->xpt_flags);
  637. /* Get the next entry off the accept list */
  638. spin_lock_bh(&listen_rdma->sc_lock);
  639. if (!list_empty(&listen_rdma->sc_accept_q)) {
  640. newxprt = list_entry(listen_rdma->sc_accept_q.next,
  641. struct svcxprt_rdma, sc_accept_q);
  642. list_del_init(&newxprt->sc_accept_q);
  643. }
  644. if (!list_empty(&listen_rdma->sc_accept_q))
  645. set_bit(XPT_CONN, &listen_rdma->sc_xprt.xpt_flags);
  646. spin_unlock_bh(&listen_rdma->sc_lock);
  647. if (!newxprt)
  648. return NULL;
  649. dprintk("svcrdma: newxprt from accept queue = %p, cm_id=%p\n",
  650. newxprt, newxprt->sc_cm_id);
  651. ret = ib_query_device(newxprt->sc_cm_id->device, &devattr);
  652. if (ret) {
  653. dprintk("svcrdma: could not query device attributes on "
  654. "device %p, rc=%d\n", newxprt->sc_cm_id->device, ret);
  655. goto errout;
  656. }
  657. /* Qualify the transport resource defaults with the
  658. * capabilities of this particular device */
  659. newxprt->sc_max_sge = min((size_t)devattr.max_sge,
  660. (size_t)RPCSVC_MAXPAGES);
  661. newxprt->sc_max_requests = min((size_t)devattr.max_qp_wr,
  662. (size_t)svcrdma_max_requests);
  663. newxprt->sc_sq_depth = RPCRDMA_SQ_DEPTH_MULT * newxprt->sc_max_requests;
  664. newxprt->sc_ord = min((size_t)devattr.max_qp_rd_atom,
  665. (size_t)svcrdma_ord);
  666. newxprt->sc_pd = ib_alloc_pd(newxprt->sc_cm_id->device);
  667. if (IS_ERR(newxprt->sc_pd)) {
  668. dprintk("svcrdma: error creating PD for connect request\n");
  669. goto errout;
  670. }
  671. newxprt->sc_sq_cq = ib_create_cq(newxprt->sc_cm_id->device,
  672. sq_comp_handler,
  673. cq_event_handler,
  674. newxprt,
  675. newxprt->sc_sq_depth,
  676. 0);
  677. if (IS_ERR(newxprt->sc_sq_cq)) {
  678. dprintk("svcrdma: error creating SQ CQ for connect request\n");
  679. goto errout;
  680. }
  681. newxprt->sc_rq_cq = ib_create_cq(newxprt->sc_cm_id->device,
  682. rq_comp_handler,
  683. cq_event_handler,
  684. newxprt,
  685. newxprt->sc_max_requests,
  686. 0);
  687. if (IS_ERR(newxprt->sc_rq_cq)) {
  688. dprintk("svcrdma: error creating RQ CQ for connect request\n");
  689. goto errout;
  690. }
  691. memset(&qp_attr, 0, sizeof qp_attr);
  692. qp_attr.event_handler = qp_event_handler;
  693. qp_attr.qp_context = &newxprt->sc_xprt;
  694. qp_attr.cap.max_send_wr = newxprt->sc_sq_depth;
  695. qp_attr.cap.max_recv_wr = newxprt->sc_max_requests;
  696. qp_attr.cap.max_send_sge = newxprt->sc_max_sge;
  697. qp_attr.cap.max_recv_sge = newxprt->sc_max_sge;
  698. qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
  699. qp_attr.qp_type = IB_QPT_RC;
  700. qp_attr.send_cq = newxprt->sc_sq_cq;
  701. qp_attr.recv_cq = newxprt->sc_rq_cq;
  702. dprintk("svcrdma: newxprt->sc_cm_id=%p, newxprt->sc_pd=%p\n"
  703. " cm_id->device=%p, sc_pd->device=%p\n"
  704. " cap.max_send_wr = %d\n"
  705. " cap.max_recv_wr = %d\n"
  706. " cap.max_send_sge = %d\n"
  707. " cap.max_recv_sge = %d\n",
  708. newxprt->sc_cm_id, newxprt->sc_pd,
  709. newxprt->sc_cm_id->device, newxprt->sc_pd->device,
  710. qp_attr.cap.max_send_wr,
  711. qp_attr.cap.max_recv_wr,
  712. qp_attr.cap.max_send_sge,
  713. qp_attr.cap.max_recv_sge);
  714. ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd, &qp_attr);
  715. if (ret) {
  716. /*
  717. * XXX: This is a hack. We need a xx_request_qp interface
  718. * that will adjust the qp_attr's with a best-effort
  719. * number
  720. */
  721. qp_attr.cap.max_send_sge -= 2;
  722. qp_attr.cap.max_recv_sge -= 2;
  723. ret = rdma_create_qp(newxprt->sc_cm_id, newxprt->sc_pd,
  724. &qp_attr);
  725. if (ret) {
  726. dprintk("svcrdma: failed to create QP, ret=%d\n", ret);
  727. goto errout;
  728. }
  729. newxprt->sc_max_sge = qp_attr.cap.max_send_sge;
  730. newxprt->sc_max_sge = qp_attr.cap.max_recv_sge;
  731. newxprt->sc_sq_depth = qp_attr.cap.max_send_wr;
  732. newxprt->sc_max_requests = qp_attr.cap.max_recv_wr;
  733. }
  734. newxprt->sc_qp = newxprt->sc_cm_id->qp;
  735. /* Register all of physical memory */
  736. newxprt->sc_phys_mr = ib_get_dma_mr(newxprt->sc_pd,
  737. IB_ACCESS_LOCAL_WRITE |
  738. IB_ACCESS_REMOTE_WRITE);
  739. if (IS_ERR(newxprt->sc_phys_mr)) {
  740. dprintk("svcrdma: Failed to create DMA MR ret=%d\n", ret);
  741. goto errout;
  742. }
  743. /* Post receive buffers */
  744. for (i = 0; i < newxprt->sc_max_requests; i++) {
  745. ret = svc_rdma_post_recv(newxprt);
  746. if (ret) {
  747. dprintk("svcrdma: failure posting receive buffers\n");
  748. goto errout;
  749. }
  750. }
  751. /* Swap out the handler */
  752. newxprt->sc_cm_id->event_handler = rdma_cma_handler;
  753. /* Accept Connection */
  754. set_bit(RDMAXPRT_CONN_PENDING, &newxprt->sc_flags);
  755. memset(&conn_param, 0, sizeof conn_param);
  756. conn_param.responder_resources = 0;
  757. conn_param.initiator_depth = newxprt->sc_ord;
  758. ret = rdma_accept(newxprt->sc_cm_id, &conn_param);
  759. if (ret) {
  760. dprintk("svcrdma: failed to accept new connection, ret=%d\n",
  761. ret);
  762. goto errout;
  763. }
  764. dprintk("svcrdma: new connection %p accepted with the following "
  765. "attributes:\n"
  766. " local_ip : %d.%d.%d.%d\n"
  767. " local_port : %d\n"
  768. " remote_ip : %d.%d.%d.%d\n"
  769. " remote_port : %d\n"
  770. " max_sge : %d\n"
  771. " sq_depth : %d\n"
  772. " max_requests : %d\n"
  773. " ord : %d\n",
  774. newxprt,
  775. NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id->
  776. route.addr.src_addr)->sin_addr.s_addr),
  777. ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
  778. route.addr.src_addr)->sin_port),
  779. NIPQUAD(((struct sockaddr_in *)&newxprt->sc_cm_id->
  780. route.addr.dst_addr)->sin_addr.s_addr),
  781. ntohs(((struct sockaddr_in *)&newxprt->sc_cm_id->
  782. route.addr.dst_addr)->sin_port),
  783. newxprt->sc_max_sge,
  784. newxprt->sc_sq_depth,
  785. newxprt->sc_max_requests,
  786. newxprt->sc_ord);
  787. /* Set the local and remote addresses in the transport */
  788. sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.dst_addr;
  789. svc_xprt_set_remote(&newxprt->sc_xprt, sa, svc_addr_len(sa));
  790. sa = (struct sockaddr *)&newxprt->sc_cm_id->route.addr.src_addr;
  791. svc_xprt_set_local(&newxprt->sc_xprt, sa, svc_addr_len(sa));
  792. ib_req_notify_cq(newxprt->sc_sq_cq, IB_CQ_NEXT_COMP);
  793. ib_req_notify_cq(newxprt->sc_rq_cq, IB_CQ_NEXT_COMP);
  794. return &newxprt->sc_xprt;
  795. errout:
  796. dprintk("svcrdma: failure accepting new connection rc=%d.\n", ret);
  797. rdma_destroy_id(newxprt->sc_cm_id);
  798. rdma_destroy_xprt(newxprt);
  799. return NULL;
  800. }
  801. /*
  802. * Post an RQ WQE to the RQ when the rqst is being released. This
  803. * effectively returns an RQ credit to the client. The rq_xprt_ctxt
  804. * will be null if the request is deferred due to an RDMA_READ or the
  805. * transport had no data ready (EAGAIN). Note that an RPC deferred in
  806. * svc_process will still return the credit, this is because the data
  807. * is copied and no longer consume a WQE/WC.
  808. */
  809. static void svc_rdma_release_rqst(struct svc_rqst *rqstp)
  810. {
  811. int err;
  812. struct svcxprt_rdma *rdma =
  813. container_of(rqstp->rq_xprt, struct svcxprt_rdma, sc_xprt);
  814. if (rqstp->rq_xprt_ctxt) {
  815. BUG_ON(rqstp->rq_xprt_ctxt != rdma);
  816. err = svc_rdma_post_recv(rdma);
  817. if (err)
  818. dprintk("svcrdma: failed to post an RQ WQE error=%d\n",
  819. err);
  820. }
  821. rqstp->rq_xprt_ctxt = NULL;
  822. }
  823. /* Disable data ready events for this connection */
  824. static void svc_rdma_detach(struct svc_xprt *xprt)
  825. {
  826. struct svcxprt_rdma *rdma =
  827. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  828. unsigned long flags;
  829. dprintk("svc: svc_rdma_detach(%p)\n", xprt);
  830. /*
  831. * Shutdown the connection. This will ensure we don't get any
  832. * more events from the provider.
  833. */
  834. rdma_disconnect(rdma->sc_cm_id);
  835. rdma_destroy_id(rdma->sc_cm_id);
  836. /* We may already be on the DTO list */
  837. spin_lock_irqsave(&dto_lock, flags);
  838. if (!list_empty(&rdma->sc_dto_q))
  839. list_del_init(&rdma->sc_dto_q);
  840. spin_unlock_irqrestore(&dto_lock, flags);
  841. }
  842. static void svc_rdma_free(struct svc_xprt *xprt)
  843. {
  844. struct svcxprt_rdma *rdma = (struct svcxprt_rdma *)xprt;
  845. dprintk("svcrdma: svc_rdma_free(%p)\n", rdma);
  846. rdma_destroy_xprt(rdma);
  847. kfree(rdma);
  848. }
  849. static void rdma_destroy_xprt(struct svcxprt_rdma *xprt)
  850. {
  851. if (xprt->sc_qp && !IS_ERR(xprt->sc_qp))
  852. ib_destroy_qp(xprt->sc_qp);
  853. if (xprt->sc_sq_cq && !IS_ERR(xprt->sc_sq_cq))
  854. ib_destroy_cq(xprt->sc_sq_cq);
  855. if (xprt->sc_rq_cq && !IS_ERR(xprt->sc_rq_cq))
  856. ib_destroy_cq(xprt->sc_rq_cq);
  857. if (xprt->sc_phys_mr && !IS_ERR(xprt->sc_phys_mr))
  858. ib_dereg_mr(xprt->sc_phys_mr);
  859. if (xprt->sc_pd && !IS_ERR(xprt->sc_pd))
  860. ib_dealloc_pd(xprt->sc_pd);
  861. destroy_context_cache(xprt->sc_ctxt_head);
  862. }
  863. static int svc_rdma_has_wspace(struct svc_xprt *xprt)
  864. {
  865. struct svcxprt_rdma *rdma =
  866. container_of(xprt, struct svcxprt_rdma, sc_xprt);
  867. /*
  868. * If there are fewer SQ WR available than required to send a
  869. * simple response, return false.
  870. */
  871. if ((rdma->sc_sq_depth - atomic_read(&rdma->sc_sq_count) < 3))
  872. return 0;
  873. /*
  874. * ...or there are already waiters on the SQ,
  875. * return false.
  876. */
  877. if (waitqueue_active(&rdma->sc_send_wait))
  878. return 0;
  879. /* Otherwise return true. */
  880. return 1;
  881. }
  882. int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
  883. {
  884. struct ib_send_wr *bad_wr;
  885. int ret;
  886. if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
  887. return 0;
  888. BUG_ON(wr->send_flags != IB_SEND_SIGNALED);
  889. BUG_ON(((struct svc_rdma_op_ctxt *)(unsigned long)wr->wr_id)->wr_op !=
  890. wr->opcode);
  891. /* If the SQ is full, wait until an SQ entry is available */
  892. while (1) {
  893. spin_lock_bh(&xprt->sc_lock);
  894. if (xprt->sc_sq_depth == atomic_read(&xprt->sc_sq_count)) {
  895. spin_unlock_bh(&xprt->sc_lock);
  896. atomic_inc(&rdma_stat_sq_starve);
  897. /* See if we can reap some SQ WR */
  898. sq_cq_reap(xprt);
  899. /* Wait until SQ WR available if SQ still full */
  900. wait_event(xprt->sc_send_wait,
  901. atomic_read(&xprt->sc_sq_count) <
  902. xprt->sc_sq_depth);
  903. continue;
  904. }
  905. /* Bumped used SQ WR count and post */
  906. ret = ib_post_send(xprt->sc_qp, wr, &bad_wr);
  907. if (!ret)
  908. atomic_inc(&xprt->sc_sq_count);
  909. else
  910. dprintk("svcrdma: failed to post SQ WR rc=%d, "
  911. "sc_sq_count=%d, sc_sq_depth=%d\n",
  912. ret, atomic_read(&xprt->sc_sq_count),
  913. xprt->sc_sq_depth);
  914. spin_unlock_bh(&xprt->sc_lock);
  915. break;
  916. }
  917. return ret;
  918. }
  919. int svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,
  920. enum rpcrdma_errcode err)
  921. {
  922. struct ib_send_wr err_wr;
  923. struct ib_sge sge;
  924. struct page *p;
  925. struct svc_rdma_op_ctxt *ctxt;
  926. u32 *va;
  927. int length;
  928. int ret;
  929. p = svc_rdma_get_page();
  930. va = page_address(p);
  931. /* XDR encode error */
  932. length = svc_rdma_xdr_encode_error(xprt, rmsgp, err, va);
  933. /* Prepare SGE for local address */
  934. sge.addr = ib_dma_map_page(xprt->sc_cm_id->device,
  935. p, 0, PAGE_SIZE, DMA_FROM_DEVICE);
  936. sge.lkey = xprt->sc_phys_mr->lkey;
  937. sge.length = length;
  938. ctxt = svc_rdma_get_context(xprt);
  939. ctxt->count = 1;
  940. ctxt->pages[0] = p;
  941. /* Prepare SEND WR */
  942. memset(&err_wr, 0, sizeof err_wr);
  943. ctxt->wr_op = IB_WR_SEND;
  944. err_wr.wr_id = (unsigned long)ctxt;
  945. err_wr.sg_list = &sge;
  946. err_wr.num_sge = 1;
  947. err_wr.opcode = IB_WR_SEND;
  948. err_wr.send_flags = IB_SEND_SIGNALED;
  949. /* Post It */
  950. ret = svc_rdma_send(xprt, &err_wr);
  951. if (ret) {
  952. dprintk("svcrdma: Error posting send = %d\n", ret);
  953. svc_rdma_put_context(ctxt, 1);
  954. }
  955. return ret;
  956. }