rxe_verbs.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. /*
  2. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2015 System Fabric Works, 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
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/dma-mapping.h>
  34. #include <net/addrconf.h>
  35. #include "rxe.h"
  36. #include "rxe_loc.h"
  37. #include "rxe_queue.h"
  38. #include "rxe_hw_counters.h"
  39. static int rxe_query_device(struct ib_device *dev,
  40. struct ib_device_attr *attr,
  41. struct ib_udata *uhw)
  42. {
  43. struct rxe_dev *rxe = to_rdev(dev);
  44. if (uhw->inlen || uhw->outlen)
  45. return -EINVAL;
  46. *attr = rxe->attr;
  47. return 0;
  48. }
  49. static int rxe_query_port(struct ib_device *dev,
  50. u8 port_num, struct ib_port_attr *attr)
  51. {
  52. struct rxe_dev *rxe = to_rdev(dev);
  53. struct rxe_port *port;
  54. int rc = -EINVAL;
  55. if (unlikely(port_num != 1)) {
  56. pr_warn("invalid port_number %d\n", port_num);
  57. goto out;
  58. }
  59. port = &rxe->port;
  60. /* *attr being zeroed by the caller, avoid zeroing it here */
  61. *attr = port->attr;
  62. mutex_lock(&rxe->usdev_lock);
  63. rc = ib_get_eth_speed(dev, port_num, &attr->active_speed,
  64. &attr->active_width);
  65. mutex_unlock(&rxe->usdev_lock);
  66. out:
  67. return rc;
  68. }
  69. static struct net_device *rxe_get_netdev(struct ib_device *device,
  70. u8 port_num)
  71. {
  72. struct rxe_dev *rxe = to_rdev(device);
  73. if (rxe->ndev) {
  74. dev_hold(rxe->ndev);
  75. return rxe->ndev;
  76. }
  77. return NULL;
  78. }
  79. static int rxe_query_pkey(struct ib_device *device,
  80. u8 port_num, u16 index, u16 *pkey)
  81. {
  82. struct rxe_dev *rxe = to_rdev(device);
  83. struct rxe_port *port;
  84. if (unlikely(port_num != 1)) {
  85. dev_warn(device->dev.parent, "invalid port_num = %d\n",
  86. port_num);
  87. goto err1;
  88. }
  89. port = &rxe->port;
  90. if (unlikely(index >= port->attr.pkey_tbl_len)) {
  91. dev_warn(device->dev.parent, "invalid index = %d\n",
  92. index);
  93. goto err1;
  94. }
  95. *pkey = port->pkey_tbl[index];
  96. return 0;
  97. err1:
  98. return -EINVAL;
  99. }
  100. static int rxe_modify_device(struct ib_device *dev,
  101. int mask, struct ib_device_modify *attr)
  102. {
  103. struct rxe_dev *rxe = to_rdev(dev);
  104. if (mask & IB_DEVICE_MODIFY_SYS_IMAGE_GUID)
  105. rxe->attr.sys_image_guid = cpu_to_be64(attr->sys_image_guid);
  106. if (mask & IB_DEVICE_MODIFY_NODE_DESC) {
  107. memcpy(rxe->ib_dev.node_desc,
  108. attr->node_desc, sizeof(rxe->ib_dev.node_desc));
  109. }
  110. return 0;
  111. }
  112. static int rxe_modify_port(struct ib_device *dev,
  113. u8 port_num, int mask, struct ib_port_modify *attr)
  114. {
  115. struct rxe_dev *rxe = to_rdev(dev);
  116. struct rxe_port *port;
  117. if (unlikely(port_num != 1)) {
  118. pr_warn("invalid port_num = %d\n", port_num);
  119. goto err1;
  120. }
  121. port = &rxe->port;
  122. port->attr.port_cap_flags |= attr->set_port_cap_mask;
  123. port->attr.port_cap_flags &= ~attr->clr_port_cap_mask;
  124. if (mask & IB_PORT_RESET_QKEY_CNTR)
  125. port->attr.qkey_viol_cntr = 0;
  126. return 0;
  127. err1:
  128. return -EINVAL;
  129. }
  130. static enum rdma_link_layer rxe_get_link_layer(struct ib_device *dev,
  131. u8 port_num)
  132. {
  133. struct rxe_dev *rxe = to_rdev(dev);
  134. return rxe_link_layer(rxe, port_num);
  135. }
  136. static struct ib_ucontext *rxe_alloc_ucontext(struct ib_device *dev,
  137. struct ib_udata *udata)
  138. {
  139. struct rxe_dev *rxe = to_rdev(dev);
  140. struct rxe_ucontext *uc;
  141. uc = rxe_alloc(&rxe->uc_pool);
  142. return uc ? &uc->ibuc : ERR_PTR(-ENOMEM);
  143. }
  144. static int rxe_dealloc_ucontext(struct ib_ucontext *ibuc)
  145. {
  146. struct rxe_ucontext *uc = to_ruc(ibuc);
  147. rxe_drop_ref(uc);
  148. return 0;
  149. }
  150. static int rxe_port_immutable(struct ib_device *dev, u8 port_num,
  151. struct ib_port_immutable *immutable)
  152. {
  153. int err;
  154. struct ib_port_attr attr;
  155. immutable->core_cap_flags = RDMA_CORE_PORT_IBA_ROCE_UDP_ENCAP;
  156. err = ib_query_port(dev, port_num, &attr);
  157. if (err)
  158. return err;
  159. immutable->pkey_tbl_len = attr.pkey_tbl_len;
  160. immutable->gid_tbl_len = attr.gid_tbl_len;
  161. immutable->max_mad_size = IB_MGMT_MAD_SIZE;
  162. return 0;
  163. }
  164. static struct ib_pd *rxe_alloc_pd(struct ib_device *dev,
  165. struct ib_ucontext *context,
  166. struct ib_udata *udata)
  167. {
  168. struct rxe_dev *rxe = to_rdev(dev);
  169. struct rxe_pd *pd;
  170. pd = rxe_alloc(&rxe->pd_pool);
  171. return pd ? &pd->ibpd : ERR_PTR(-ENOMEM);
  172. }
  173. static int rxe_dealloc_pd(struct ib_pd *ibpd)
  174. {
  175. struct rxe_pd *pd = to_rpd(ibpd);
  176. rxe_drop_ref(pd);
  177. return 0;
  178. }
  179. static void rxe_init_av(struct rxe_dev *rxe, struct rdma_ah_attr *attr,
  180. struct rxe_av *av)
  181. {
  182. rxe_av_from_attr(rdma_ah_get_port_num(attr), av, attr);
  183. rxe_av_fill_ip_info(av, attr);
  184. }
  185. static struct ib_ah *rxe_create_ah(struct ib_pd *ibpd,
  186. struct rdma_ah_attr *attr,
  187. struct ib_udata *udata)
  188. {
  189. int err;
  190. struct rxe_dev *rxe = to_rdev(ibpd->device);
  191. struct rxe_pd *pd = to_rpd(ibpd);
  192. struct rxe_ah *ah;
  193. err = rxe_av_chk_attr(rxe, attr);
  194. if (err)
  195. return ERR_PTR(err);
  196. ah = rxe_alloc(&rxe->ah_pool);
  197. if (!ah)
  198. return ERR_PTR(-ENOMEM);
  199. rxe_add_ref(pd);
  200. ah->pd = pd;
  201. rxe_init_av(rxe, attr, &ah->av);
  202. return &ah->ibah;
  203. }
  204. static int rxe_modify_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr)
  205. {
  206. int err;
  207. struct rxe_dev *rxe = to_rdev(ibah->device);
  208. struct rxe_ah *ah = to_rah(ibah);
  209. err = rxe_av_chk_attr(rxe, attr);
  210. if (err)
  211. return err;
  212. rxe_init_av(rxe, attr, &ah->av);
  213. return 0;
  214. }
  215. static int rxe_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *attr)
  216. {
  217. struct rxe_ah *ah = to_rah(ibah);
  218. memset(attr, 0, sizeof(*attr));
  219. attr->type = ibah->type;
  220. rxe_av_to_attr(&ah->av, attr);
  221. return 0;
  222. }
  223. static int rxe_destroy_ah(struct ib_ah *ibah)
  224. {
  225. struct rxe_ah *ah = to_rah(ibah);
  226. rxe_drop_ref(ah->pd);
  227. rxe_drop_ref(ah);
  228. return 0;
  229. }
  230. static int post_one_recv(struct rxe_rq *rq, const struct ib_recv_wr *ibwr)
  231. {
  232. int err;
  233. int i;
  234. u32 length;
  235. struct rxe_recv_wqe *recv_wqe;
  236. int num_sge = ibwr->num_sge;
  237. if (unlikely(queue_full(rq->queue))) {
  238. err = -ENOMEM;
  239. goto err1;
  240. }
  241. if (unlikely(num_sge > rq->max_sge)) {
  242. err = -EINVAL;
  243. goto err1;
  244. }
  245. length = 0;
  246. for (i = 0; i < num_sge; i++)
  247. length += ibwr->sg_list[i].length;
  248. recv_wqe = producer_addr(rq->queue);
  249. recv_wqe->wr_id = ibwr->wr_id;
  250. recv_wqe->num_sge = num_sge;
  251. memcpy(recv_wqe->dma.sge, ibwr->sg_list,
  252. num_sge * sizeof(struct ib_sge));
  253. recv_wqe->dma.length = length;
  254. recv_wqe->dma.resid = length;
  255. recv_wqe->dma.num_sge = num_sge;
  256. recv_wqe->dma.cur_sge = 0;
  257. recv_wqe->dma.sge_offset = 0;
  258. /* make sure all changes to the work queue are written before we
  259. * update the producer pointer
  260. */
  261. smp_wmb();
  262. advance_producer(rq->queue);
  263. return 0;
  264. err1:
  265. return err;
  266. }
  267. static struct ib_srq *rxe_create_srq(struct ib_pd *ibpd,
  268. struct ib_srq_init_attr *init,
  269. struct ib_udata *udata)
  270. {
  271. int err;
  272. struct rxe_dev *rxe = to_rdev(ibpd->device);
  273. struct rxe_pd *pd = to_rpd(ibpd);
  274. struct rxe_srq *srq;
  275. struct ib_ucontext *context = udata ? ibpd->uobject->context : NULL;
  276. struct rxe_create_srq_resp __user *uresp = NULL;
  277. if (udata) {
  278. if (udata->outlen < sizeof(*uresp))
  279. return ERR_PTR(-EINVAL);
  280. uresp = udata->outbuf;
  281. }
  282. err = rxe_srq_chk_attr(rxe, NULL, &init->attr, IB_SRQ_INIT_MASK);
  283. if (err)
  284. goto err1;
  285. srq = rxe_alloc(&rxe->srq_pool);
  286. if (!srq) {
  287. err = -ENOMEM;
  288. goto err1;
  289. }
  290. rxe_add_index(srq);
  291. rxe_add_ref(pd);
  292. srq->pd = pd;
  293. err = rxe_srq_from_init(rxe, srq, init, context, uresp);
  294. if (err)
  295. goto err2;
  296. return &srq->ibsrq;
  297. err2:
  298. rxe_drop_ref(pd);
  299. rxe_drop_index(srq);
  300. rxe_drop_ref(srq);
  301. err1:
  302. return ERR_PTR(err);
  303. }
  304. static int rxe_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
  305. enum ib_srq_attr_mask mask,
  306. struct ib_udata *udata)
  307. {
  308. int err;
  309. struct rxe_srq *srq = to_rsrq(ibsrq);
  310. struct rxe_dev *rxe = to_rdev(ibsrq->device);
  311. struct rxe_modify_srq_cmd ucmd = {};
  312. if (udata) {
  313. if (udata->inlen < sizeof(ucmd))
  314. return -EINVAL;
  315. err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd));
  316. if (err)
  317. return err;
  318. }
  319. err = rxe_srq_chk_attr(rxe, srq, attr, mask);
  320. if (err)
  321. goto err1;
  322. err = rxe_srq_from_attr(rxe, srq, attr, mask, &ucmd);
  323. if (err)
  324. goto err1;
  325. return 0;
  326. err1:
  327. return err;
  328. }
  329. static int rxe_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr)
  330. {
  331. struct rxe_srq *srq = to_rsrq(ibsrq);
  332. if (srq->error)
  333. return -EINVAL;
  334. attr->max_wr = srq->rq.queue->buf->index_mask;
  335. attr->max_sge = srq->rq.max_sge;
  336. attr->srq_limit = srq->limit;
  337. return 0;
  338. }
  339. static int rxe_destroy_srq(struct ib_srq *ibsrq)
  340. {
  341. struct rxe_srq *srq = to_rsrq(ibsrq);
  342. if (srq->rq.queue)
  343. rxe_queue_cleanup(srq->rq.queue);
  344. rxe_drop_ref(srq->pd);
  345. rxe_drop_index(srq);
  346. rxe_drop_ref(srq);
  347. return 0;
  348. }
  349. static int rxe_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
  350. const struct ib_recv_wr **bad_wr)
  351. {
  352. int err = 0;
  353. unsigned long flags;
  354. struct rxe_srq *srq = to_rsrq(ibsrq);
  355. spin_lock_irqsave(&srq->rq.producer_lock, flags);
  356. while (wr) {
  357. err = post_one_recv(&srq->rq, wr);
  358. if (unlikely(err))
  359. break;
  360. wr = wr->next;
  361. }
  362. spin_unlock_irqrestore(&srq->rq.producer_lock, flags);
  363. if (err)
  364. *bad_wr = wr;
  365. return err;
  366. }
  367. static struct ib_qp *rxe_create_qp(struct ib_pd *ibpd,
  368. struct ib_qp_init_attr *init,
  369. struct ib_udata *udata)
  370. {
  371. int err;
  372. struct rxe_dev *rxe = to_rdev(ibpd->device);
  373. struct rxe_pd *pd = to_rpd(ibpd);
  374. struct rxe_qp *qp;
  375. struct rxe_create_qp_resp __user *uresp = NULL;
  376. if (udata) {
  377. if (udata->outlen < sizeof(*uresp))
  378. return ERR_PTR(-EINVAL);
  379. uresp = udata->outbuf;
  380. }
  381. err = rxe_qp_chk_init(rxe, init);
  382. if (err)
  383. goto err1;
  384. qp = rxe_alloc(&rxe->qp_pool);
  385. if (!qp) {
  386. err = -ENOMEM;
  387. goto err1;
  388. }
  389. if (udata) {
  390. if (udata->inlen) {
  391. err = -EINVAL;
  392. goto err2;
  393. }
  394. qp->is_user = 1;
  395. }
  396. rxe_add_index(qp);
  397. err = rxe_qp_from_init(rxe, qp, pd, init, uresp, ibpd);
  398. if (err)
  399. goto err3;
  400. return &qp->ibqp;
  401. err3:
  402. rxe_drop_index(qp);
  403. err2:
  404. rxe_drop_ref(qp);
  405. err1:
  406. return ERR_PTR(err);
  407. }
  408. static int rxe_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  409. int mask, struct ib_udata *udata)
  410. {
  411. int err;
  412. struct rxe_dev *rxe = to_rdev(ibqp->device);
  413. struct rxe_qp *qp = to_rqp(ibqp);
  414. err = rxe_qp_chk_attr(rxe, qp, attr, mask);
  415. if (err)
  416. goto err1;
  417. err = rxe_qp_from_attr(qp, attr, mask, udata);
  418. if (err)
  419. goto err1;
  420. return 0;
  421. err1:
  422. return err;
  423. }
  424. static int rxe_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
  425. int mask, struct ib_qp_init_attr *init)
  426. {
  427. struct rxe_qp *qp = to_rqp(ibqp);
  428. rxe_qp_to_init(qp, init);
  429. rxe_qp_to_attr(qp, attr, mask);
  430. return 0;
  431. }
  432. static int rxe_destroy_qp(struct ib_qp *ibqp)
  433. {
  434. struct rxe_qp *qp = to_rqp(ibqp);
  435. rxe_qp_destroy(qp);
  436. rxe_drop_index(qp);
  437. rxe_drop_ref(qp);
  438. return 0;
  439. }
  440. static int validate_send_wr(struct rxe_qp *qp, const struct ib_send_wr *ibwr,
  441. unsigned int mask, unsigned int length)
  442. {
  443. int num_sge = ibwr->num_sge;
  444. struct rxe_sq *sq = &qp->sq;
  445. if (unlikely(num_sge > sq->max_sge))
  446. goto err1;
  447. if (unlikely(mask & WR_ATOMIC_MASK)) {
  448. if (length < 8)
  449. goto err1;
  450. if (atomic_wr(ibwr)->remote_addr & 0x7)
  451. goto err1;
  452. }
  453. if (unlikely((ibwr->send_flags & IB_SEND_INLINE) &&
  454. (length > sq->max_inline)))
  455. goto err1;
  456. return 0;
  457. err1:
  458. return -EINVAL;
  459. }
  460. static void init_send_wr(struct rxe_qp *qp, struct rxe_send_wr *wr,
  461. const struct ib_send_wr *ibwr)
  462. {
  463. wr->wr_id = ibwr->wr_id;
  464. wr->num_sge = ibwr->num_sge;
  465. wr->opcode = ibwr->opcode;
  466. wr->send_flags = ibwr->send_flags;
  467. if (qp_type(qp) == IB_QPT_UD ||
  468. qp_type(qp) == IB_QPT_SMI ||
  469. qp_type(qp) == IB_QPT_GSI) {
  470. wr->wr.ud.remote_qpn = ud_wr(ibwr)->remote_qpn;
  471. wr->wr.ud.remote_qkey = ud_wr(ibwr)->remote_qkey;
  472. if (qp_type(qp) == IB_QPT_GSI)
  473. wr->wr.ud.pkey_index = ud_wr(ibwr)->pkey_index;
  474. if (wr->opcode == IB_WR_SEND_WITH_IMM)
  475. wr->ex.imm_data = ibwr->ex.imm_data;
  476. } else {
  477. switch (wr->opcode) {
  478. case IB_WR_RDMA_WRITE_WITH_IMM:
  479. wr->ex.imm_data = ibwr->ex.imm_data;
  480. /* fall through */
  481. case IB_WR_RDMA_READ:
  482. case IB_WR_RDMA_WRITE:
  483. wr->wr.rdma.remote_addr = rdma_wr(ibwr)->remote_addr;
  484. wr->wr.rdma.rkey = rdma_wr(ibwr)->rkey;
  485. break;
  486. case IB_WR_SEND_WITH_IMM:
  487. wr->ex.imm_data = ibwr->ex.imm_data;
  488. break;
  489. case IB_WR_SEND_WITH_INV:
  490. wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey;
  491. break;
  492. case IB_WR_ATOMIC_CMP_AND_SWP:
  493. case IB_WR_ATOMIC_FETCH_AND_ADD:
  494. wr->wr.atomic.remote_addr =
  495. atomic_wr(ibwr)->remote_addr;
  496. wr->wr.atomic.compare_add =
  497. atomic_wr(ibwr)->compare_add;
  498. wr->wr.atomic.swap = atomic_wr(ibwr)->swap;
  499. wr->wr.atomic.rkey = atomic_wr(ibwr)->rkey;
  500. break;
  501. case IB_WR_LOCAL_INV:
  502. wr->ex.invalidate_rkey = ibwr->ex.invalidate_rkey;
  503. break;
  504. case IB_WR_REG_MR:
  505. wr->wr.reg.mr = reg_wr(ibwr)->mr;
  506. wr->wr.reg.key = reg_wr(ibwr)->key;
  507. wr->wr.reg.access = reg_wr(ibwr)->access;
  508. break;
  509. default:
  510. break;
  511. }
  512. }
  513. }
  514. static int init_send_wqe(struct rxe_qp *qp, const struct ib_send_wr *ibwr,
  515. unsigned int mask, unsigned int length,
  516. struct rxe_send_wqe *wqe)
  517. {
  518. int num_sge = ibwr->num_sge;
  519. struct ib_sge *sge;
  520. int i;
  521. u8 *p;
  522. init_send_wr(qp, &wqe->wr, ibwr);
  523. if (qp_type(qp) == IB_QPT_UD ||
  524. qp_type(qp) == IB_QPT_SMI ||
  525. qp_type(qp) == IB_QPT_GSI)
  526. memcpy(&wqe->av, &to_rah(ud_wr(ibwr)->ah)->av, sizeof(wqe->av));
  527. if (unlikely(ibwr->send_flags & IB_SEND_INLINE)) {
  528. p = wqe->dma.inline_data;
  529. sge = ibwr->sg_list;
  530. for (i = 0; i < num_sge; i++, sge++) {
  531. memcpy(p, (void *)(uintptr_t)sge->addr,
  532. sge->length);
  533. p += sge->length;
  534. }
  535. } else if (mask & WR_REG_MASK) {
  536. wqe->mask = mask;
  537. wqe->state = wqe_state_posted;
  538. return 0;
  539. } else
  540. memcpy(wqe->dma.sge, ibwr->sg_list,
  541. num_sge * sizeof(struct ib_sge));
  542. wqe->iova = mask & WR_ATOMIC_MASK ? atomic_wr(ibwr)->remote_addr :
  543. mask & WR_READ_OR_WRITE_MASK ? rdma_wr(ibwr)->remote_addr : 0;
  544. wqe->mask = mask;
  545. wqe->dma.length = length;
  546. wqe->dma.resid = length;
  547. wqe->dma.num_sge = num_sge;
  548. wqe->dma.cur_sge = 0;
  549. wqe->dma.sge_offset = 0;
  550. wqe->state = wqe_state_posted;
  551. wqe->ssn = atomic_add_return(1, &qp->ssn);
  552. return 0;
  553. }
  554. static int post_one_send(struct rxe_qp *qp, const struct ib_send_wr *ibwr,
  555. unsigned int mask, u32 length)
  556. {
  557. int err;
  558. struct rxe_sq *sq = &qp->sq;
  559. struct rxe_send_wqe *send_wqe;
  560. unsigned long flags;
  561. err = validate_send_wr(qp, ibwr, mask, length);
  562. if (err)
  563. return err;
  564. spin_lock_irqsave(&qp->sq.sq_lock, flags);
  565. if (unlikely(queue_full(sq->queue))) {
  566. err = -ENOMEM;
  567. goto err1;
  568. }
  569. send_wqe = producer_addr(sq->queue);
  570. err = init_send_wqe(qp, ibwr, mask, length, send_wqe);
  571. if (unlikely(err))
  572. goto err1;
  573. /*
  574. * make sure all changes to the work queue are
  575. * written before we update the producer pointer
  576. */
  577. smp_wmb();
  578. advance_producer(sq->queue);
  579. spin_unlock_irqrestore(&qp->sq.sq_lock, flags);
  580. return 0;
  581. err1:
  582. spin_unlock_irqrestore(&qp->sq.sq_lock, flags);
  583. return err;
  584. }
  585. static int rxe_post_send_kernel(struct rxe_qp *qp, const struct ib_send_wr *wr,
  586. const struct ib_send_wr **bad_wr)
  587. {
  588. int err = 0;
  589. unsigned int mask;
  590. unsigned int length = 0;
  591. int i;
  592. struct ib_send_wr *next;
  593. while (wr) {
  594. mask = wr_opcode_mask(wr->opcode, qp);
  595. if (unlikely(!mask)) {
  596. err = -EINVAL;
  597. *bad_wr = wr;
  598. break;
  599. }
  600. if (unlikely((wr->send_flags & IB_SEND_INLINE) &&
  601. !(mask & WR_INLINE_MASK))) {
  602. err = -EINVAL;
  603. *bad_wr = wr;
  604. break;
  605. }
  606. next = wr->next;
  607. length = 0;
  608. for (i = 0; i < wr->num_sge; i++)
  609. length += wr->sg_list[i].length;
  610. err = post_one_send(qp, wr, mask, length);
  611. if (err) {
  612. *bad_wr = wr;
  613. break;
  614. }
  615. wr = next;
  616. }
  617. rxe_run_task(&qp->req.task, 1);
  618. if (unlikely(qp->req.state == QP_STATE_ERROR))
  619. rxe_run_task(&qp->comp.task, 1);
  620. return err;
  621. }
  622. static int rxe_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
  623. const struct ib_send_wr **bad_wr)
  624. {
  625. struct rxe_qp *qp = to_rqp(ibqp);
  626. if (unlikely(!qp->valid)) {
  627. *bad_wr = wr;
  628. return -EINVAL;
  629. }
  630. if (unlikely(qp->req.state < QP_STATE_READY)) {
  631. *bad_wr = wr;
  632. return -EINVAL;
  633. }
  634. if (qp->is_user) {
  635. /* Utilize process context to do protocol processing */
  636. rxe_run_task(&qp->req.task, 0);
  637. return 0;
  638. } else
  639. return rxe_post_send_kernel(qp, wr, bad_wr);
  640. }
  641. static int rxe_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
  642. const struct ib_recv_wr **bad_wr)
  643. {
  644. int err = 0;
  645. struct rxe_qp *qp = to_rqp(ibqp);
  646. struct rxe_rq *rq = &qp->rq;
  647. unsigned long flags;
  648. if (unlikely((qp_state(qp) < IB_QPS_INIT) || !qp->valid)) {
  649. *bad_wr = wr;
  650. err = -EINVAL;
  651. goto err1;
  652. }
  653. if (unlikely(qp->srq)) {
  654. *bad_wr = wr;
  655. err = -EINVAL;
  656. goto err1;
  657. }
  658. spin_lock_irqsave(&rq->producer_lock, flags);
  659. while (wr) {
  660. err = post_one_recv(rq, wr);
  661. if (unlikely(err)) {
  662. *bad_wr = wr;
  663. break;
  664. }
  665. wr = wr->next;
  666. }
  667. spin_unlock_irqrestore(&rq->producer_lock, flags);
  668. if (qp->resp.state == QP_STATE_ERROR)
  669. rxe_run_task(&qp->resp.task, 1);
  670. err1:
  671. return err;
  672. }
  673. static struct ib_cq *rxe_create_cq(struct ib_device *dev,
  674. const struct ib_cq_init_attr *attr,
  675. struct ib_ucontext *context,
  676. struct ib_udata *udata)
  677. {
  678. int err;
  679. struct rxe_dev *rxe = to_rdev(dev);
  680. struct rxe_cq *cq;
  681. struct rxe_create_cq_resp __user *uresp = NULL;
  682. if (udata) {
  683. if (udata->outlen < sizeof(*uresp))
  684. return ERR_PTR(-EINVAL);
  685. uresp = udata->outbuf;
  686. }
  687. if (attr->flags)
  688. return ERR_PTR(-EINVAL);
  689. err = rxe_cq_chk_attr(rxe, NULL, attr->cqe, attr->comp_vector);
  690. if (err)
  691. goto err1;
  692. cq = rxe_alloc(&rxe->cq_pool);
  693. if (!cq) {
  694. err = -ENOMEM;
  695. goto err1;
  696. }
  697. err = rxe_cq_from_init(rxe, cq, attr->cqe, attr->comp_vector,
  698. context, uresp);
  699. if (err)
  700. goto err2;
  701. return &cq->ibcq;
  702. err2:
  703. rxe_drop_ref(cq);
  704. err1:
  705. return ERR_PTR(err);
  706. }
  707. static int rxe_destroy_cq(struct ib_cq *ibcq)
  708. {
  709. struct rxe_cq *cq = to_rcq(ibcq);
  710. rxe_cq_disable(cq);
  711. rxe_drop_ref(cq);
  712. return 0;
  713. }
  714. static int rxe_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata)
  715. {
  716. int err;
  717. struct rxe_cq *cq = to_rcq(ibcq);
  718. struct rxe_dev *rxe = to_rdev(ibcq->device);
  719. struct rxe_resize_cq_resp __user *uresp = NULL;
  720. if (udata) {
  721. if (udata->outlen < sizeof(*uresp))
  722. return -EINVAL;
  723. uresp = udata->outbuf;
  724. }
  725. err = rxe_cq_chk_attr(rxe, cq, cqe, 0);
  726. if (err)
  727. goto err1;
  728. err = rxe_cq_resize_queue(cq, cqe, uresp);
  729. if (err)
  730. goto err1;
  731. return 0;
  732. err1:
  733. return err;
  734. }
  735. static int rxe_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
  736. {
  737. int i;
  738. struct rxe_cq *cq = to_rcq(ibcq);
  739. struct rxe_cqe *cqe;
  740. unsigned long flags;
  741. spin_lock_irqsave(&cq->cq_lock, flags);
  742. for (i = 0; i < num_entries; i++) {
  743. cqe = queue_head(cq->queue);
  744. if (!cqe)
  745. break;
  746. memcpy(wc++, &cqe->ibwc, sizeof(*wc));
  747. advance_consumer(cq->queue);
  748. }
  749. spin_unlock_irqrestore(&cq->cq_lock, flags);
  750. return i;
  751. }
  752. static int rxe_peek_cq(struct ib_cq *ibcq, int wc_cnt)
  753. {
  754. struct rxe_cq *cq = to_rcq(ibcq);
  755. int count = queue_count(cq->queue);
  756. return (count > wc_cnt) ? wc_cnt : count;
  757. }
  758. static int rxe_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
  759. {
  760. struct rxe_cq *cq = to_rcq(ibcq);
  761. unsigned long irq_flags;
  762. int ret = 0;
  763. spin_lock_irqsave(&cq->cq_lock, irq_flags);
  764. if (cq->notify != IB_CQ_NEXT_COMP)
  765. cq->notify = flags & IB_CQ_SOLICITED_MASK;
  766. if ((flags & IB_CQ_REPORT_MISSED_EVENTS) && !queue_empty(cq->queue))
  767. ret = 1;
  768. spin_unlock_irqrestore(&cq->cq_lock, irq_flags);
  769. return ret;
  770. }
  771. static struct ib_mr *rxe_get_dma_mr(struct ib_pd *ibpd, int access)
  772. {
  773. struct rxe_dev *rxe = to_rdev(ibpd->device);
  774. struct rxe_pd *pd = to_rpd(ibpd);
  775. struct rxe_mem *mr;
  776. int err;
  777. mr = rxe_alloc(&rxe->mr_pool);
  778. if (!mr) {
  779. err = -ENOMEM;
  780. goto err1;
  781. }
  782. rxe_add_index(mr);
  783. rxe_add_ref(pd);
  784. err = rxe_mem_init_dma(pd, access, mr);
  785. if (err)
  786. goto err2;
  787. return &mr->ibmr;
  788. err2:
  789. rxe_drop_ref(pd);
  790. rxe_drop_index(mr);
  791. rxe_drop_ref(mr);
  792. err1:
  793. return ERR_PTR(err);
  794. }
  795. static struct ib_mr *rxe_reg_user_mr(struct ib_pd *ibpd,
  796. u64 start,
  797. u64 length,
  798. u64 iova,
  799. int access, struct ib_udata *udata)
  800. {
  801. int err;
  802. struct rxe_dev *rxe = to_rdev(ibpd->device);
  803. struct rxe_pd *pd = to_rpd(ibpd);
  804. struct rxe_mem *mr;
  805. mr = rxe_alloc(&rxe->mr_pool);
  806. if (!mr) {
  807. err = -ENOMEM;
  808. goto err2;
  809. }
  810. rxe_add_index(mr);
  811. rxe_add_ref(pd);
  812. err = rxe_mem_init_user(pd, start, length, iova,
  813. access, udata, mr);
  814. if (err)
  815. goto err3;
  816. return &mr->ibmr;
  817. err3:
  818. rxe_drop_ref(pd);
  819. rxe_drop_index(mr);
  820. rxe_drop_ref(mr);
  821. err2:
  822. return ERR_PTR(err);
  823. }
  824. static int rxe_dereg_mr(struct ib_mr *ibmr)
  825. {
  826. struct rxe_mem *mr = to_rmr(ibmr);
  827. mr->state = RXE_MEM_STATE_ZOMBIE;
  828. rxe_drop_ref(mr->pd);
  829. rxe_drop_index(mr);
  830. rxe_drop_ref(mr);
  831. return 0;
  832. }
  833. static struct ib_mr *rxe_alloc_mr(struct ib_pd *ibpd,
  834. enum ib_mr_type mr_type,
  835. u32 max_num_sg)
  836. {
  837. struct rxe_dev *rxe = to_rdev(ibpd->device);
  838. struct rxe_pd *pd = to_rpd(ibpd);
  839. struct rxe_mem *mr;
  840. int err;
  841. if (mr_type != IB_MR_TYPE_MEM_REG)
  842. return ERR_PTR(-EINVAL);
  843. mr = rxe_alloc(&rxe->mr_pool);
  844. if (!mr) {
  845. err = -ENOMEM;
  846. goto err1;
  847. }
  848. rxe_add_index(mr);
  849. rxe_add_ref(pd);
  850. err = rxe_mem_init_fast(pd, max_num_sg, mr);
  851. if (err)
  852. goto err2;
  853. return &mr->ibmr;
  854. err2:
  855. rxe_drop_ref(pd);
  856. rxe_drop_index(mr);
  857. rxe_drop_ref(mr);
  858. err1:
  859. return ERR_PTR(err);
  860. }
  861. static int rxe_set_page(struct ib_mr *ibmr, u64 addr)
  862. {
  863. struct rxe_mem *mr = to_rmr(ibmr);
  864. struct rxe_map *map;
  865. struct rxe_phys_buf *buf;
  866. if (unlikely(mr->nbuf == mr->num_buf))
  867. return -ENOMEM;
  868. map = mr->map[mr->nbuf / RXE_BUF_PER_MAP];
  869. buf = &map->buf[mr->nbuf % RXE_BUF_PER_MAP];
  870. buf->addr = addr;
  871. buf->size = ibmr->page_size;
  872. mr->nbuf++;
  873. return 0;
  874. }
  875. static int rxe_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg,
  876. int sg_nents, unsigned int *sg_offset)
  877. {
  878. struct rxe_mem *mr = to_rmr(ibmr);
  879. int n;
  880. mr->nbuf = 0;
  881. n = ib_sg_to_pages(ibmr, sg, sg_nents, sg_offset, rxe_set_page);
  882. mr->va = ibmr->iova;
  883. mr->iova = ibmr->iova;
  884. mr->length = ibmr->length;
  885. mr->page_shift = ilog2(ibmr->page_size);
  886. mr->page_mask = ibmr->page_size - 1;
  887. mr->offset = mr->iova & mr->page_mask;
  888. return n;
  889. }
  890. static int rxe_attach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
  891. {
  892. int err;
  893. struct rxe_dev *rxe = to_rdev(ibqp->device);
  894. struct rxe_qp *qp = to_rqp(ibqp);
  895. struct rxe_mc_grp *grp;
  896. /* takes a ref on grp if successful */
  897. err = rxe_mcast_get_grp(rxe, mgid, &grp);
  898. if (err)
  899. return err;
  900. err = rxe_mcast_add_grp_elem(rxe, qp, grp);
  901. rxe_drop_ref(grp);
  902. return err;
  903. }
  904. static int rxe_detach_mcast(struct ib_qp *ibqp, union ib_gid *mgid, u16 mlid)
  905. {
  906. struct rxe_dev *rxe = to_rdev(ibqp->device);
  907. struct rxe_qp *qp = to_rqp(ibqp);
  908. return rxe_mcast_drop_grp_elem(rxe, qp, mgid);
  909. }
  910. static ssize_t parent_show(struct device *device,
  911. struct device_attribute *attr, char *buf)
  912. {
  913. struct rxe_dev *rxe = container_of(device, struct rxe_dev,
  914. ib_dev.dev);
  915. return scnprintf(buf, PAGE_SIZE, "%s\n", rxe_parent_name(rxe, 1));
  916. }
  917. static DEVICE_ATTR_RO(parent);
  918. static struct device_attribute *rxe_dev_attributes[] = {
  919. &dev_attr_parent,
  920. };
  921. int rxe_register_device(struct rxe_dev *rxe)
  922. {
  923. int err;
  924. int i;
  925. struct ib_device *dev = &rxe->ib_dev;
  926. struct crypto_shash *tfm;
  927. strlcpy(dev->name, "rxe%d", IB_DEVICE_NAME_MAX);
  928. strlcpy(dev->node_desc, "rxe", sizeof(dev->node_desc));
  929. dev->owner = THIS_MODULE;
  930. dev->node_type = RDMA_NODE_IB_CA;
  931. dev->phys_port_cnt = 1;
  932. dev->num_comp_vectors = num_possible_cpus();
  933. dev->dev.parent = rxe_dma_device(rxe);
  934. dev->local_dma_lkey = 0;
  935. addrconf_addr_eui48((unsigned char *)&dev->node_guid,
  936. rxe->ndev->dev_addr);
  937. dev->dev.dma_ops = &dma_virt_ops;
  938. dma_coerce_mask_and_coherent(&dev->dev,
  939. dma_get_required_mask(&dev->dev));
  940. dev->uverbs_abi_ver = RXE_UVERBS_ABI_VERSION;
  941. dev->uverbs_cmd_mask = BIT_ULL(IB_USER_VERBS_CMD_GET_CONTEXT)
  942. | BIT_ULL(IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)
  943. | BIT_ULL(IB_USER_VERBS_CMD_QUERY_DEVICE)
  944. | BIT_ULL(IB_USER_VERBS_CMD_QUERY_PORT)
  945. | BIT_ULL(IB_USER_VERBS_CMD_ALLOC_PD)
  946. | BIT_ULL(IB_USER_VERBS_CMD_DEALLOC_PD)
  947. | BIT_ULL(IB_USER_VERBS_CMD_CREATE_SRQ)
  948. | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_SRQ)
  949. | BIT_ULL(IB_USER_VERBS_CMD_QUERY_SRQ)
  950. | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_SRQ)
  951. | BIT_ULL(IB_USER_VERBS_CMD_POST_SRQ_RECV)
  952. | BIT_ULL(IB_USER_VERBS_CMD_CREATE_QP)
  953. | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_QP)
  954. | BIT_ULL(IB_USER_VERBS_CMD_QUERY_QP)
  955. | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_QP)
  956. | BIT_ULL(IB_USER_VERBS_CMD_POST_SEND)
  957. | BIT_ULL(IB_USER_VERBS_CMD_POST_RECV)
  958. | BIT_ULL(IB_USER_VERBS_CMD_CREATE_CQ)
  959. | BIT_ULL(IB_USER_VERBS_CMD_RESIZE_CQ)
  960. | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_CQ)
  961. | BIT_ULL(IB_USER_VERBS_CMD_POLL_CQ)
  962. | BIT_ULL(IB_USER_VERBS_CMD_PEEK_CQ)
  963. | BIT_ULL(IB_USER_VERBS_CMD_REQ_NOTIFY_CQ)
  964. | BIT_ULL(IB_USER_VERBS_CMD_REG_MR)
  965. | BIT_ULL(IB_USER_VERBS_CMD_DEREG_MR)
  966. | BIT_ULL(IB_USER_VERBS_CMD_CREATE_AH)
  967. | BIT_ULL(IB_USER_VERBS_CMD_MODIFY_AH)
  968. | BIT_ULL(IB_USER_VERBS_CMD_QUERY_AH)
  969. | BIT_ULL(IB_USER_VERBS_CMD_DESTROY_AH)
  970. | BIT_ULL(IB_USER_VERBS_CMD_ATTACH_MCAST)
  971. | BIT_ULL(IB_USER_VERBS_CMD_DETACH_MCAST)
  972. ;
  973. dev->query_device = rxe_query_device;
  974. dev->modify_device = rxe_modify_device;
  975. dev->query_port = rxe_query_port;
  976. dev->modify_port = rxe_modify_port;
  977. dev->get_link_layer = rxe_get_link_layer;
  978. dev->get_netdev = rxe_get_netdev;
  979. dev->query_pkey = rxe_query_pkey;
  980. dev->alloc_ucontext = rxe_alloc_ucontext;
  981. dev->dealloc_ucontext = rxe_dealloc_ucontext;
  982. dev->mmap = rxe_mmap;
  983. dev->get_port_immutable = rxe_port_immutable;
  984. dev->alloc_pd = rxe_alloc_pd;
  985. dev->dealloc_pd = rxe_dealloc_pd;
  986. dev->create_ah = rxe_create_ah;
  987. dev->modify_ah = rxe_modify_ah;
  988. dev->query_ah = rxe_query_ah;
  989. dev->destroy_ah = rxe_destroy_ah;
  990. dev->create_srq = rxe_create_srq;
  991. dev->modify_srq = rxe_modify_srq;
  992. dev->query_srq = rxe_query_srq;
  993. dev->destroy_srq = rxe_destroy_srq;
  994. dev->post_srq_recv = rxe_post_srq_recv;
  995. dev->create_qp = rxe_create_qp;
  996. dev->modify_qp = rxe_modify_qp;
  997. dev->query_qp = rxe_query_qp;
  998. dev->destroy_qp = rxe_destroy_qp;
  999. dev->post_send = rxe_post_send;
  1000. dev->post_recv = rxe_post_recv;
  1001. dev->create_cq = rxe_create_cq;
  1002. dev->destroy_cq = rxe_destroy_cq;
  1003. dev->resize_cq = rxe_resize_cq;
  1004. dev->poll_cq = rxe_poll_cq;
  1005. dev->peek_cq = rxe_peek_cq;
  1006. dev->req_notify_cq = rxe_req_notify_cq;
  1007. dev->get_dma_mr = rxe_get_dma_mr;
  1008. dev->reg_user_mr = rxe_reg_user_mr;
  1009. dev->dereg_mr = rxe_dereg_mr;
  1010. dev->alloc_mr = rxe_alloc_mr;
  1011. dev->map_mr_sg = rxe_map_mr_sg;
  1012. dev->attach_mcast = rxe_attach_mcast;
  1013. dev->detach_mcast = rxe_detach_mcast;
  1014. dev->get_hw_stats = rxe_ib_get_hw_stats;
  1015. dev->alloc_hw_stats = rxe_ib_alloc_hw_stats;
  1016. tfm = crypto_alloc_shash("crc32", 0, 0);
  1017. if (IS_ERR(tfm)) {
  1018. pr_err("failed to allocate crc algorithm err:%ld\n",
  1019. PTR_ERR(tfm));
  1020. return PTR_ERR(tfm);
  1021. }
  1022. rxe->tfm = tfm;
  1023. dev->driver_id = RDMA_DRIVER_RXE;
  1024. err = ib_register_device(dev, NULL);
  1025. if (err) {
  1026. pr_warn("%s failed with error %d\n", __func__, err);
  1027. goto err1;
  1028. }
  1029. for (i = 0; i < ARRAY_SIZE(rxe_dev_attributes); ++i) {
  1030. err = device_create_file(&dev->dev, rxe_dev_attributes[i]);
  1031. if (err) {
  1032. pr_warn("%s failed with error %d for attr number %d\n",
  1033. __func__, err, i);
  1034. goto err2;
  1035. }
  1036. }
  1037. return 0;
  1038. err2:
  1039. ib_unregister_device(dev);
  1040. err1:
  1041. crypto_free_shash(rxe->tfm);
  1042. return err;
  1043. }
  1044. int rxe_unregister_device(struct rxe_dev *rxe)
  1045. {
  1046. int i;
  1047. struct ib_device *dev = &rxe->ib_dev;
  1048. for (i = 0; i < ARRAY_SIZE(rxe_dev_attributes); ++i)
  1049. device_remove_file(&dev->dev, rxe_dev_attributes[i]);
  1050. ib_unregister_device(dev);
  1051. return 0;
  1052. }