trans_rdma.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * linux/fs/9p/trans_rdma.c
  3. *
  4. * RDMA transport layer based on the trans_fd.c implementation.
  5. *
  6. * Copyright (C) 2008 by Tom Tucker <tom@opengridcomputing.com>
  7. * Copyright (C) 2006 by Russ Cox <rsc@swtch.com>
  8. * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net>
  9. * Copyright (C) 2004-2008 by Eric Van Hensbergen <ericvh@gmail.com>
  10. * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to:
  23. * Free Software Foundation
  24. * 51 Franklin Street, Fifth Floor
  25. * Boston, MA 02111-1301 USA
  26. *
  27. */
  28. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  29. #include <linux/in.h>
  30. #include <linux/module.h>
  31. #include <linux/net.h>
  32. #include <linux/ipv6.h>
  33. #include <linux/kthread.h>
  34. #include <linux/errno.h>
  35. #include <linux/kernel.h>
  36. #include <linux/un.h>
  37. #include <linux/uaccess.h>
  38. #include <linux/inet.h>
  39. #include <linux/idr.h>
  40. #include <linux/file.h>
  41. #include <linux/parser.h>
  42. #include <linux/semaphore.h>
  43. #include <linux/slab.h>
  44. #include <net/9p/9p.h>
  45. #include <net/9p/client.h>
  46. #include <net/9p/transport.h>
  47. #include <rdma/ib_verbs.h>
  48. #include <rdma/rdma_cm.h>
  49. #define P9_PORT 5640
  50. #define P9_RDMA_SQ_DEPTH 32
  51. #define P9_RDMA_RQ_DEPTH 32
  52. #define P9_RDMA_SEND_SGE 4
  53. #define P9_RDMA_RECV_SGE 4
  54. #define P9_RDMA_IRD 0
  55. #define P9_RDMA_ORD 0
  56. #define P9_RDMA_TIMEOUT 30000 /* 30 seconds */
  57. #define P9_RDMA_MAXSIZE (1024*1024) /* 1MB */
  58. /**
  59. * struct p9_trans_rdma - RDMA transport instance
  60. *
  61. * @state: tracks the transport state machine for connection setup and tear down
  62. * @cm_id: The RDMA CM ID
  63. * @pd: Protection Domain pointer
  64. * @qp: Queue Pair pointer
  65. * @cq: Completion Queue pointer
  66. * @dm_mr: DMA Memory Region pointer
  67. * @lkey: The local access only memory region key
  68. * @timeout: Number of uSecs to wait for connection management events
  69. * @sq_depth: The depth of the Send Queue
  70. * @sq_sem: Semaphore for the SQ
  71. * @rq_depth: The depth of the Receive Queue.
  72. * @rq_sem: Semaphore for the RQ
  73. * @addr: The remote peer's address
  74. * @req_lock: Protects the active request list
  75. * @cm_done: Completion event for connection management tracking
  76. */
  77. struct p9_trans_rdma {
  78. enum {
  79. P9_RDMA_INIT,
  80. P9_RDMA_ADDR_RESOLVED,
  81. P9_RDMA_ROUTE_RESOLVED,
  82. P9_RDMA_CONNECTED,
  83. P9_RDMA_FLUSHING,
  84. P9_RDMA_CLOSING,
  85. P9_RDMA_CLOSED,
  86. } state;
  87. struct rdma_cm_id *cm_id;
  88. struct ib_pd *pd;
  89. struct ib_qp *qp;
  90. struct ib_cq *cq;
  91. struct ib_mr *dma_mr;
  92. u32 lkey;
  93. long timeout;
  94. int sq_depth;
  95. struct semaphore sq_sem;
  96. int rq_depth;
  97. struct semaphore rq_sem;
  98. struct sockaddr_in addr;
  99. spinlock_t req_lock;
  100. struct completion cm_done;
  101. };
  102. /**
  103. * p9_rdma_context - Keeps track of in-process WR
  104. *
  105. * @wc_op: The original WR op for when the CQE completes in error.
  106. * @busa: Bus address to unmap when the WR completes
  107. * @req: Keeps track of requests (send)
  108. * @rc: Keepts track of replies (receive)
  109. */
  110. struct p9_rdma_req;
  111. struct p9_rdma_context {
  112. enum ib_wc_opcode wc_op;
  113. dma_addr_t busa;
  114. union {
  115. struct p9_req_t *req;
  116. struct p9_fcall *rc;
  117. };
  118. };
  119. /**
  120. * p9_rdma_opts - Collection of mount options
  121. * @port: port of connection
  122. * @sq_depth: The requested depth of the SQ. This really doesn't need
  123. * to be any deeper than the number of threads used in the client
  124. * @rq_depth: The depth of the RQ. Should be greater than or equal to SQ depth
  125. * @timeout: Time to wait in msecs for CM events
  126. */
  127. struct p9_rdma_opts {
  128. short port;
  129. int sq_depth;
  130. int rq_depth;
  131. long timeout;
  132. };
  133. /*
  134. * Option Parsing (code inspired by NFS code)
  135. */
  136. enum {
  137. /* Options that take integer arguments */
  138. Opt_port, Opt_rq_depth, Opt_sq_depth, Opt_timeout, Opt_err,
  139. };
  140. static match_table_t tokens = {
  141. {Opt_port, "port=%u"},
  142. {Opt_sq_depth, "sq=%u"},
  143. {Opt_rq_depth, "rq=%u"},
  144. {Opt_timeout, "timeout=%u"},
  145. {Opt_err, NULL},
  146. };
  147. /**
  148. * parse_opts - parse mount options into rdma options structure
  149. * @params: options string passed from mount
  150. * @opts: rdma transport-specific structure to parse options into
  151. *
  152. * Returns 0 upon success, -ERRNO upon failure
  153. */
  154. static int parse_opts(char *params, struct p9_rdma_opts *opts)
  155. {
  156. char *p;
  157. substring_t args[MAX_OPT_ARGS];
  158. int option;
  159. char *options, *tmp_options;
  160. opts->port = P9_PORT;
  161. opts->sq_depth = P9_RDMA_SQ_DEPTH;
  162. opts->rq_depth = P9_RDMA_RQ_DEPTH;
  163. opts->timeout = P9_RDMA_TIMEOUT;
  164. if (!params)
  165. return 0;
  166. tmp_options = kstrdup(params, GFP_KERNEL);
  167. if (!tmp_options) {
  168. p9_debug(P9_DEBUG_ERROR,
  169. "failed to allocate copy of option string\n");
  170. return -ENOMEM;
  171. }
  172. options = tmp_options;
  173. while ((p = strsep(&options, ",")) != NULL) {
  174. int token;
  175. int r;
  176. if (!*p)
  177. continue;
  178. token = match_token(p, tokens, args);
  179. r = match_int(&args[0], &option);
  180. if (r < 0) {
  181. p9_debug(P9_DEBUG_ERROR,
  182. "integer field, but no integer?\n");
  183. continue;
  184. }
  185. switch (token) {
  186. case Opt_port:
  187. opts->port = option;
  188. break;
  189. case Opt_sq_depth:
  190. opts->sq_depth = option;
  191. break;
  192. case Opt_rq_depth:
  193. opts->rq_depth = option;
  194. break;
  195. case Opt_timeout:
  196. opts->timeout = option;
  197. break;
  198. default:
  199. continue;
  200. }
  201. }
  202. /* RQ must be at least as large as the SQ */
  203. opts->rq_depth = max(opts->rq_depth, opts->sq_depth);
  204. kfree(tmp_options);
  205. return 0;
  206. }
  207. static int
  208. p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event)
  209. {
  210. struct p9_client *c = id->context;
  211. struct p9_trans_rdma *rdma = c->trans;
  212. switch (event->event) {
  213. case RDMA_CM_EVENT_ADDR_RESOLVED:
  214. BUG_ON(rdma->state != P9_RDMA_INIT);
  215. rdma->state = P9_RDMA_ADDR_RESOLVED;
  216. break;
  217. case RDMA_CM_EVENT_ROUTE_RESOLVED:
  218. BUG_ON(rdma->state != P9_RDMA_ADDR_RESOLVED);
  219. rdma->state = P9_RDMA_ROUTE_RESOLVED;
  220. break;
  221. case RDMA_CM_EVENT_ESTABLISHED:
  222. BUG_ON(rdma->state != P9_RDMA_ROUTE_RESOLVED);
  223. rdma->state = P9_RDMA_CONNECTED;
  224. break;
  225. case RDMA_CM_EVENT_DISCONNECTED:
  226. if (rdma)
  227. rdma->state = P9_RDMA_CLOSED;
  228. if (c)
  229. c->status = Disconnected;
  230. break;
  231. case RDMA_CM_EVENT_TIMEWAIT_EXIT:
  232. break;
  233. case RDMA_CM_EVENT_ADDR_CHANGE:
  234. case RDMA_CM_EVENT_ROUTE_ERROR:
  235. case RDMA_CM_EVENT_DEVICE_REMOVAL:
  236. case RDMA_CM_EVENT_MULTICAST_JOIN:
  237. case RDMA_CM_EVENT_MULTICAST_ERROR:
  238. case RDMA_CM_EVENT_REJECTED:
  239. case RDMA_CM_EVENT_CONNECT_REQUEST:
  240. case RDMA_CM_EVENT_CONNECT_RESPONSE:
  241. case RDMA_CM_EVENT_CONNECT_ERROR:
  242. case RDMA_CM_EVENT_ADDR_ERROR:
  243. case RDMA_CM_EVENT_UNREACHABLE:
  244. c->status = Disconnected;
  245. rdma_disconnect(rdma->cm_id);
  246. break;
  247. default:
  248. BUG();
  249. }
  250. complete(&rdma->cm_done);
  251. return 0;
  252. }
  253. static void
  254. handle_recv(struct p9_client *client, struct p9_trans_rdma *rdma,
  255. struct p9_rdma_context *c, enum ib_wc_status status, u32 byte_len)
  256. {
  257. struct p9_req_t *req;
  258. int err = 0;
  259. int16_t tag;
  260. req = NULL;
  261. ib_dma_unmap_single(rdma->cm_id->device, c->busa, client->msize,
  262. DMA_FROM_DEVICE);
  263. if (status != IB_WC_SUCCESS)
  264. goto err_out;
  265. err = p9_parse_header(c->rc, NULL, NULL, &tag, 1);
  266. if (err)
  267. goto err_out;
  268. req = p9_tag_lookup(client, tag);
  269. if (!req)
  270. goto err_out;
  271. /* Check that we have not yet received a reply for this request.
  272. */
  273. if (unlikely(req->rc)) {
  274. pr_err("Duplicate reply for request %d", tag);
  275. goto err_out;
  276. }
  277. req->rc = c->rc;
  278. req->status = REQ_STATUS_RCVD;
  279. p9_client_cb(client, req);
  280. return;
  281. err_out:
  282. p9_debug(P9_DEBUG_ERROR, "req %p err %d status %d\n", req, err, status);
  283. rdma->state = P9_RDMA_FLUSHING;
  284. client->status = Disconnected;
  285. }
  286. static void
  287. handle_send(struct p9_client *client, struct p9_trans_rdma *rdma,
  288. struct p9_rdma_context *c, enum ib_wc_status status, u32 byte_len)
  289. {
  290. ib_dma_unmap_single(rdma->cm_id->device,
  291. c->busa, c->req->tc->size,
  292. DMA_TO_DEVICE);
  293. }
  294. static void qp_event_handler(struct ib_event *event, void *context)
  295. {
  296. p9_debug(P9_DEBUG_ERROR, "QP event %d context %p\n",
  297. event->event, context);
  298. }
  299. static void cq_comp_handler(struct ib_cq *cq, void *cq_context)
  300. {
  301. struct p9_client *client = cq_context;
  302. struct p9_trans_rdma *rdma = client->trans;
  303. int ret;
  304. struct ib_wc wc;
  305. ib_req_notify_cq(rdma->cq, IB_CQ_NEXT_COMP);
  306. while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
  307. struct p9_rdma_context *c = (void *) (unsigned long) wc.wr_id;
  308. switch (c->wc_op) {
  309. case IB_WC_RECV:
  310. handle_recv(client, rdma, c, wc.status, wc.byte_len);
  311. up(&rdma->rq_sem);
  312. break;
  313. case IB_WC_SEND:
  314. handle_send(client, rdma, c, wc.status, wc.byte_len);
  315. up(&rdma->sq_sem);
  316. break;
  317. default:
  318. pr_err("unexpected completion type, c->wc_op=%d, wc.opcode=%d, status=%d\n",
  319. c->wc_op, wc.opcode, wc.status);
  320. break;
  321. }
  322. kfree(c);
  323. }
  324. }
  325. static void cq_event_handler(struct ib_event *e, void *v)
  326. {
  327. p9_debug(P9_DEBUG_ERROR, "CQ event %d context %p\n", e->event, v);
  328. }
  329. static void rdma_destroy_trans(struct p9_trans_rdma *rdma)
  330. {
  331. if (!rdma)
  332. return;
  333. if (rdma->dma_mr && !IS_ERR(rdma->dma_mr))
  334. ib_dereg_mr(rdma->dma_mr);
  335. if (rdma->qp && !IS_ERR(rdma->qp))
  336. ib_destroy_qp(rdma->qp);
  337. if (rdma->pd && !IS_ERR(rdma->pd))
  338. ib_dealloc_pd(rdma->pd);
  339. if (rdma->cq && !IS_ERR(rdma->cq))
  340. ib_destroy_cq(rdma->cq);
  341. if (rdma->cm_id && !IS_ERR(rdma->cm_id))
  342. rdma_destroy_id(rdma->cm_id);
  343. kfree(rdma);
  344. }
  345. static int
  346. post_recv(struct p9_client *client, struct p9_rdma_context *c)
  347. {
  348. struct p9_trans_rdma *rdma = client->trans;
  349. struct ib_recv_wr wr, *bad_wr;
  350. struct ib_sge sge;
  351. c->busa = ib_dma_map_single(rdma->cm_id->device,
  352. c->rc->sdata, client->msize,
  353. DMA_FROM_DEVICE);
  354. if (ib_dma_mapping_error(rdma->cm_id->device, c->busa))
  355. goto error;
  356. sge.addr = c->busa;
  357. sge.length = client->msize;
  358. sge.lkey = rdma->lkey;
  359. wr.next = NULL;
  360. c->wc_op = IB_WC_RECV;
  361. wr.wr_id = (unsigned long) c;
  362. wr.sg_list = &sge;
  363. wr.num_sge = 1;
  364. return ib_post_recv(rdma->qp, &wr, &bad_wr);
  365. error:
  366. p9_debug(P9_DEBUG_ERROR, "EIO\n");
  367. return -EIO;
  368. }
  369. static int rdma_request(struct p9_client *client, struct p9_req_t *req)
  370. {
  371. struct p9_trans_rdma *rdma = client->trans;
  372. struct ib_send_wr wr, *bad_wr;
  373. struct ib_sge sge;
  374. int err = 0;
  375. unsigned long flags;
  376. struct p9_rdma_context *c = NULL;
  377. struct p9_rdma_context *rpl_context = NULL;
  378. /* Allocate an fcall for the reply */
  379. rpl_context = kmalloc(sizeof *rpl_context, GFP_NOFS);
  380. if (!rpl_context) {
  381. err = -ENOMEM;
  382. goto err_close;
  383. }
  384. rpl_context->rc = req->rc;
  385. /*
  386. * Post a receive buffer for this request. We need to ensure
  387. * there is a reply buffer available for every outstanding
  388. * request. A flushed request can result in no reply for an
  389. * outstanding request, so we must keep a count to avoid
  390. * overflowing the RQ.
  391. */
  392. if (down_interruptible(&rdma->rq_sem))
  393. goto error; /* FIXME : -EINTR instead */
  394. err = post_recv(client, rpl_context);
  395. if (err) {
  396. p9_debug(P9_DEBUG_FCALL, "POST RECV failed\n");
  397. goto err_free;
  398. }
  399. /* remove posted receive buffer from request structure */
  400. req->rc = NULL;
  401. /* Post the request */
  402. c = kmalloc(sizeof *c, GFP_NOFS);
  403. if (!c) {
  404. err = -ENOMEM;
  405. goto err_free;
  406. }
  407. c->req = req;
  408. c->busa = ib_dma_map_single(rdma->cm_id->device,
  409. c->req->tc->sdata, c->req->tc->size,
  410. DMA_TO_DEVICE);
  411. if (ib_dma_mapping_error(rdma->cm_id->device, c->busa))
  412. goto error;
  413. sge.addr = c->busa;
  414. sge.length = c->req->tc->size;
  415. sge.lkey = rdma->lkey;
  416. wr.next = NULL;
  417. c->wc_op = IB_WC_SEND;
  418. wr.wr_id = (unsigned long) c;
  419. wr.opcode = IB_WR_SEND;
  420. wr.send_flags = IB_SEND_SIGNALED;
  421. wr.sg_list = &sge;
  422. wr.num_sge = 1;
  423. if (down_interruptible(&rdma->sq_sem))
  424. goto error;
  425. return ib_post_send(rdma->qp, &wr, &bad_wr);
  426. error:
  427. kfree(c);
  428. kfree(rpl_context);
  429. p9_debug(P9_DEBUG_ERROR, "EIO\n");
  430. return -EIO;
  431. err_free:
  432. kfree(rpl_context);
  433. err_close:
  434. spin_lock_irqsave(&rdma->req_lock, flags);
  435. if (rdma->state < P9_RDMA_CLOSING) {
  436. rdma->state = P9_RDMA_CLOSING;
  437. spin_unlock_irqrestore(&rdma->req_lock, flags);
  438. rdma_disconnect(rdma->cm_id);
  439. } else
  440. spin_unlock_irqrestore(&rdma->req_lock, flags);
  441. return err;
  442. }
  443. static void rdma_close(struct p9_client *client)
  444. {
  445. struct p9_trans_rdma *rdma;
  446. if (!client)
  447. return;
  448. rdma = client->trans;
  449. if (!rdma)
  450. return;
  451. client->status = Disconnected;
  452. rdma_disconnect(rdma->cm_id);
  453. rdma_destroy_trans(rdma);
  454. }
  455. /**
  456. * alloc_rdma - Allocate and initialize the rdma transport structure
  457. * @opts: Mount options structure
  458. */
  459. static struct p9_trans_rdma *alloc_rdma(struct p9_rdma_opts *opts)
  460. {
  461. struct p9_trans_rdma *rdma;
  462. rdma = kzalloc(sizeof(struct p9_trans_rdma), GFP_KERNEL);
  463. if (!rdma)
  464. return NULL;
  465. rdma->sq_depth = opts->sq_depth;
  466. rdma->rq_depth = opts->rq_depth;
  467. rdma->timeout = opts->timeout;
  468. spin_lock_init(&rdma->req_lock);
  469. init_completion(&rdma->cm_done);
  470. sema_init(&rdma->sq_sem, rdma->sq_depth);
  471. sema_init(&rdma->rq_sem, rdma->rq_depth);
  472. return rdma;
  473. }
  474. /* its not clear to me we can do anything after send has been posted */
  475. static int rdma_cancel(struct p9_client *client, struct p9_req_t *req)
  476. {
  477. return 1;
  478. }
  479. /**
  480. * trans_create_rdma - Transport method for creating atransport instance
  481. * @client: client instance
  482. * @addr: IP address string
  483. * @args: Mount options string
  484. */
  485. static int
  486. rdma_create_trans(struct p9_client *client, const char *addr, char *args)
  487. {
  488. int err;
  489. struct p9_rdma_opts opts;
  490. struct p9_trans_rdma *rdma;
  491. struct rdma_conn_param conn_param;
  492. struct ib_qp_init_attr qp_attr;
  493. struct ib_device_attr devattr;
  494. /* Parse the transport specific mount options */
  495. err = parse_opts(args, &opts);
  496. if (err < 0)
  497. return err;
  498. /* Create and initialize the RDMA transport structure */
  499. rdma = alloc_rdma(&opts);
  500. if (!rdma)
  501. return -ENOMEM;
  502. /* Create the RDMA CM ID */
  503. rdma->cm_id = rdma_create_id(p9_cm_event_handler, client, RDMA_PS_TCP,
  504. IB_QPT_RC);
  505. if (IS_ERR(rdma->cm_id))
  506. goto error;
  507. /* Associate the client with the transport */
  508. client->trans = rdma;
  509. /* Resolve the server's address */
  510. rdma->addr.sin_family = AF_INET;
  511. rdma->addr.sin_addr.s_addr = in_aton(addr);
  512. rdma->addr.sin_port = htons(opts.port);
  513. err = rdma_resolve_addr(rdma->cm_id, NULL,
  514. (struct sockaddr *)&rdma->addr,
  515. rdma->timeout);
  516. if (err)
  517. goto error;
  518. err = wait_for_completion_interruptible(&rdma->cm_done);
  519. if (err || (rdma->state != P9_RDMA_ADDR_RESOLVED))
  520. goto error;
  521. /* Resolve the route to the server */
  522. err = rdma_resolve_route(rdma->cm_id, rdma->timeout);
  523. if (err)
  524. goto error;
  525. err = wait_for_completion_interruptible(&rdma->cm_done);
  526. if (err || (rdma->state != P9_RDMA_ROUTE_RESOLVED))
  527. goto error;
  528. /* Query the device attributes */
  529. err = ib_query_device(rdma->cm_id->device, &devattr);
  530. if (err)
  531. goto error;
  532. /* Create the Completion Queue */
  533. rdma->cq = ib_create_cq(rdma->cm_id->device, cq_comp_handler,
  534. cq_event_handler, client,
  535. opts.sq_depth + opts.rq_depth + 1, 0);
  536. if (IS_ERR(rdma->cq))
  537. goto error;
  538. ib_req_notify_cq(rdma->cq, IB_CQ_NEXT_COMP);
  539. /* Create the Protection Domain */
  540. rdma->pd = ib_alloc_pd(rdma->cm_id->device);
  541. if (IS_ERR(rdma->pd))
  542. goto error;
  543. /* Cache the DMA lkey in the transport */
  544. rdma->dma_mr = NULL;
  545. if (devattr.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)
  546. rdma->lkey = rdma->cm_id->device->local_dma_lkey;
  547. else {
  548. rdma->dma_mr = ib_get_dma_mr(rdma->pd, IB_ACCESS_LOCAL_WRITE);
  549. if (IS_ERR(rdma->dma_mr))
  550. goto error;
  551. rdma->lkey = rdma->dma_mr->lkey;
  552. }
  553. /* Create the Queue Pair */
  554. memset(&qp_attr, 0, sizeof qp_attr);
  555. qp_attr.event_handler = qp_event_handler;
  556. qp_attr.qp_context = client;
  557. qp_attr.cap.max_send_wr = opts.sq_depth;
  558. qp_attr.cap.max_recv_wr = opts.rq_depth;
  559. qp_attr.cap.max_send_sge = P9_RDMA_SEND_SGE;
  560. qp_attr.cap.max_recv_sge = P9_RDMA_RECV_SGE;
  561. qp_attr.sq_sig_type = IB_SIGNAL_REQ_WR;
  562. qp_attr.qp_type = IB_QPT_RC;
  563. qp_attr.send_cq = rdma->cq;
  564. qp_attr.recv_cq = rdma->cq;
  565. err = rdma_create_qp(rdma->cm_id, rdma->pd, &qp_attr);
  566. if (err)
  567. goto error;
  568. rdma->qp = rdma->cm_id->qp;
  569. /* Request a connection */
  570. memset(&conn_param, 0, sizeof(conn_param));
  571. conn_param.private_data = NULL;
  572. conn_param.private_data_len = 0;
  573. conn_param.responder_resources = P9_RDMA_IRD;
  574. conn_param.initiator_depth = P9_RDMA_ORD;
  575. err = rdma_connect(rdma->cm_id, &conn_param);
  576. if (err)
  577. goto error;
  578. err = wait_for_completion_interruptible(&rdma->cm_done);
  579. if (err || (rdma->state != P9_RDMA_CONNECTED))
  580. goto error;
  581. client->status = Connected;
  582. return 0;
  583. error:
  584. rdma_destroy_trans(rdma);
  585. return -ENOTCONN;
  586. }
  587. static struct p9_trans_module p9_rdma_trans = {
  588. .name = "rdma",
  589. .maxsize = P9_RDMA_MAXSIZE,
  590. .def = 0,
  591. .owner = THIS_MODULE,
  592. .create = rdma_create_trans,
  593. .close = rdma_close,
  594. .request = rdma_request,
  595. .cancel = rdma_cancel,
  596. };
  597. /**
  598. * p9_trans_rdma_init - Register the 9P RDMA transport driver
  599. */
  600. static int __init p9_trans_rdma_init(void)
  601. {
  602. v9fs_register_trans(&p9_rdma_trans);
  603. return 0;
  604. }
  605. static void __exit p9_trans_rdma_exit(void)
  606. {
  607. v9fs_unregister_trans(&p9_rdma_trans);
  608. }
  609. module_init(p9_trans_rdma_init);
  610. module_exit(p9_trans_rdma_exit);
  611. MODULE_AUTHOR("Tom Tucker <tom@opengridcomputing.com>");
  612. MODULE_DESCRIPTION("RDMA Transport for 9P");
  613. MODULE_LICENSE("Dual BSD/GPL");