smc_ib.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Shared Memory Communications over RDMA (SMC-R) and RoCE
  4. *
  5. * IB infrastructure:
  6. * Establish SMC-R as an Infiniband Client to be notified about added and
  7. * removed IB devices of type RDMA.
  8. * Determine device and port characteristics for these IB devices.
  9. *
  10. * Copyright IBM Corp. 2016
  11. *
  12. * Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
  13. */
  14. #include <linux/random.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/scatterlist.h>
  17. #include <rdma/ib_verbs.h>
  18. #include <rdma/ib_cache.h>
  19. #include "smc_pnet.h"
  20. #include "smc_ib.h"
  21. #include "smc_core.h"
  22. #include "smc_wr.h"
  23. #include "smc.h"
  24. #define SMC_MAX_CQE 32766 /* max. # of completion queue elements */
  25. #define SMC_QP_MIN_RNR_TIMER 5
  26. #define SMC_QP_TIMEOUT 15 /* 4096 * 2 ** timeout usec */
  27. #define SMC_QP_RETRY_CNT 7 /* 7: infinite */
  28. #define SMC_QP_RNR_RETRY 7 /* 7: infinite */
  29. struct smc_ib_devices smc_ib_devices = { /* smc-registered ib devices */
  30. .lock = __SPIN_LOCK_UNLOCKED(smc_ib_devices.lock),
  31. .list = LIST_HEAD_INIT(smc_ib_devices.list),
  32. };
  33. #define SMC_LOCAL_SYSTEMID_RESET "%%%%%%%"
  34. u8 local_systemid[SMC_SYSTEMID_LEN] = SMC_LOCAL_SYSTEMID_RESET; /* unique system
  35. * identifier
  36. */
  37. static int smc_ib_modify_qp_init(struct smc_link *lnk)
  38. {
  39. struct ib_qp_attr qp_attr;
  40. memset(&qp_attr, 0, sizeof(qp_attr));
  41. qp_attr.qp_state = IB_QPS_INIT;
  42. qp_attr.pkey_index = 0;
  43. qp_attr.port_num = lnk->ibport;
  44. qp_attr.qp_access_flags = IB_ACCESS_LOCAL_WRITE
  45. | IB_ACCESS_REMOTE_WRITE;
  46. return ib_modify_qp(lnk->roce_qp, &qp_attr,
  47. IB_QP_STATE | IB_QP_PKEY_INDEX |
  48. IB_QP_ACCESS_FLAGS | IB_QP_PORT);
  49. }
  50. static int smc_ib_modify_qp_rtr(struct smc_link *lnk)
  51. {
  52. enum ib_qp_attr_mask qp_attr_mask =
  53. IB_QP_STATE | IB_QP_AV | IB_QP_PATH_MTU | IB_QP_DEST_QPN |
  54. IB_QP_RQ_PSN | IB_QP_MAX_DEST_RD_ATOMIC | IB_QP_MIN_RNR_TIMER;
  55. struct ib_qp_attr qp_attr;
  56. memset(&qp_attr, 0, sizeof(qp_attr));
  57. qp_attr.qp_state = IB_QPS_RTR;
  58. qp_attr.path_mtu = min(lnk->path_mtu, lnk->peer_mtu);
  59. qp_attr.ah_attr.type = RDMA_AH_ATTR_TYPE_ROCE;
  60. rdma_ah_set_port_num(&qp_attr.ah_attr, lnk->ibport);
  61. rdma_ah_set_grh(&qp_attr.ah_attr, NULL, 0, lnk->sgid_index, 1, 0);
  62. rdma_ah_set_dgid_raw(&qp_attr.ah_attr, lnk->peer_gid);
  63. memcpy(&qp_attr.ah_attr.roce.dmac, lnk->peer_mac,
  64. sizeof(lnk->peer_mac));
  65. qp_attr.dest_qp_num = lnk->peer_qpn;
  66. qp_attr.rq_psn = lnk->peer_psn; /* starting receive packet seq # */
  67. qp_attr.max_dest_rd_atomic = 1; /* max # of resources for incoming
  68. * requests
  69. */
  70. qp_attr.min_rnr_timer = SMC_QP_MIN_RNR_TIMER;
  71. return ib_modify_qp(lnk->roce_qp, &qp_attr, qp_attr_mask);
  72. }
  73. int smc_ib_modify_qp_rts(struct smc_link *lnk)
  74. {
  75. struct ib_qp_attr qp_attr;
  76. memset(&qp_attr, 0, sizeof(qp_attr));
  77. qp_attr.qp_state = IB_QPS_RTS;
  78. qp_attr.timeout = SMC_QP_TIMEOUT; /* local ack timeout */
  79. qp_attr.retry_cnt = SMC_QP_RETRY_CNT; /* retry count */
  80. qp_attr.rnr_retry = SMC_QP_RNR_RETRY; /* RNR retries, 7=infinite */
  81. qp_attr.sq_psn = lnk->psn_initial; /* starting send packet seq # */
  82. qp_attr.max_rd_atomic = 1; /* # of outstanding RDMA reads and
  83. * atomic ops allowed
  84. */
  85. return ib_modify_qp(lnk->roce_qp, &qp_attr,
  86. IB_QP_STATE | IB_QP_TIMEOUT | IB_QP_RETRY_CNT |
  87. IB_QP_SQ_PSN | IB_QP_RNR_RETRY |
  88. IB_QP_MAX_QP_RD_ATOMIC);
  89. }
  90. int smc_ib_modify_qp_reset(struct smc_link *lnk)
  91. {
  92. struct ib_qp_attr qp_attr;
  93. memset(&qp_attr, 0, sizeof(qp_attr));
  94. qp_attr.qp_state = IB_QPS_RESET;
  95. return ib_modify_qp(lnk->roce_qp, &qp_attr, IB_QP_STATE);
  96. }
  97. int smc_ib_ready_link(struct smc_link *lnk)
  98. {
  99. struct smc_link_group *lgr = smc_get_lgr(lnk);
  100. int rc = 0;
  101. rc = smc_ib_modify_qp_init(lnk);
  102. if (rc)
  103. goto out;
  104. rc = smc_ib_modify_qp_rtr(lnk);
  105. if (rc)
  106. goto out;
  107. smc_wr_remember_qp_attr(lnk);
  108. rc = ib_req_notify_cq(lnk->smcibdev->roce_cq_recv,
  109. IB_CQ_SOLICITED_MASK);
  110. if (rc)
  111. goto out;
  112. rc = smc_wr_rx_post_init(lnk);
  113. if (rc)
  114. goto out;
  115. smc_wr_remember_qp_attr(lnk);
  116. if (lgr->role == SMC_SERV) {
  117. rc = smc_ib_modify_qp_rts(lnk);
  118. if (rc)
  119. goto out;
  120. smc_wr_remember_qp_attr(lnk);
  121. }
  122. out:
  123. return rc;
  124. }
  125. static int smc_ib_fill_mac(struct smc_ib_device *smcibdev, u8 ibport)
  126. {
  127. const struct ib_gid_attr *attr;
  128. int rc = 0;
  129. attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, 0);
  130. if (IS_ERR(attr))
  131. return -ENODEV;
  132. if (attr->ndev)
  133. memcpy(smcibdev->mac[ibport - 1], attr->ndev->dev_addr,
  134. ETH_ALEN);
  135. else
  136. rc = -ENODEV;
  137. rdma_put_gid_attr(attr);
  138. return rc;
  139. }
  140. /* Create an identifier unique for this instance of SMC-R.
  141. * The MAC-address of the first active registered IB device
  142. * plus a random 2-byte number is used to create this identifier.
  143. * This name is delivered to the peer during connection initialization.
  144. */
  145. static inline void smc_ib_define_local_systemid(struct smc_ib_device *smcibdev,
  146. u8 ibport)
  147. {
  148. memcpy(&local_systemid[2], &smcibdev->mac[ibport - 1],
  149. sizeof(smcibdev->mac[ibport - 1]));
  150. get_random_bytes(&local_systemid[0], 2);
  151. }
  152. bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport)
  153. {
  154. return smcibdev->pattr[ibport - 1].state == IB_PORT_ACTIVE;
  155. }
  156. /* determine the gid for an ib-device port and vlan id */
  157. int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
  158. unsigned short vlan_id, u8 gid[], u8 *sgid_index)
  159. {
  160. const struct ib_gid_attr *attr;
  161. int i;
  162. for (i = 0; i < smcibdev->pattr[ibport - 1].gid_tbl_len; i++) {
  163. attr = rdma_get_gid_attr(smcibdev->ibdev, ibport, i);
  164. if (IS_ERR(attr))
  165. continue;
  166. if (attr->ndev &&
  167. ((!vlan_id && !is_vlan_dev(attr->ndev)) ||
  168. (vlan_id && is_vlan_dev(attr->ndev) &&
  169. vlan_dev_vlan_id(attr->ndev) == vlan_id)) &&
  170. attr->gid_type == IB_GID_TYPE_ROCE) {
  171. if (gid)
  172. memcpy(gid, &attr->gid, SMC_GID_SIZE);
  173. if (sgid_index)
  174. *sgid_index = attr->index;
  175. rdma_put_gid_attr(attr);
  176. return 0;
  177. }
  178. rdma_put_gid_attr(attr);
  179. }
  180. return -ENODEV;
  181. }
  182. static int smc_ib_remember_port_attr(struct smc_ib_device *smcibdev, u8 ibport)
  183. {
  184. int rc;
  185. memset(&smcibdev->pattr[ibport - 1], 0,
  186. sizeof(smcibdev->pattr[ibport - 1]));
  187. rc = ib_query_port(smcibdev->ibdev, ibport,
  188. &smcibdev->pattr[ibport - 1]);
  189. if (rc)
  190. goto out;
  191. /* the SMC protocol requires specification of the RoCE MAC address */
  192. rc = smc_ib_fill_mac(smcibdev, ibport);
  193. if (rc)
  194. goto out;
  195. if (!strncmp(local_systemid, SMC_LOCAL_SYSTEMID_RESET,
  196. sizeof(local_systemid)) &&
  197. smc_ib_port_active(smcibdev, ibport))
  198. /* create unique system identifier */
  199. smc_ib_define_local_systemid(smcibdev, ibport);
  200. out:
  201. return rc;
  202. }
  203. /* process context wrapper for might_sleep smc_ib_remember_port_attr */
  204. static void smc_ib_port_event_work(struct work_struct *work)
  205. {
  206. struct smc_ib_device *smcibdev = container_of(
  207. work, struct smc_ib_device, port_event_work);
  208. u8 port_idx;
  209. for_each_set_bit(port_idx, &smcibdev->port_event_mask, SMC_MAX_PORTS) {
  210. smc_ib_remember_port_attr(smcibdev, port_idx + 1);
  211. clear_bit(port_idx, &smcibdev->port_event_mask);
  212. if (!smc_ib_port_active(smcibdev, port_idx + 1))
  213. smc_port_terminate(smcibdev, port_idx + 1);
  214. }
  215. }
  216. /* can be called in IRQ context */
  217. static void smc_ib_global_event_handler(struct ib_event_handler *handler,
  218. struct ib_event *ibevent)
  219. {
  220. struct smc_ib_device *smcibdev;
  221. u8 port_idx;
  222. smcibdev = container_of(handler, struct smc_ib_device, event_handler);
  223. switch (ibevent->event) {
  224. case IB_EVENT_PORT_ERR:
  225. case IB_EVENT_DEVICE_FATAL:
  226. case IB_EVENT_PORT_ACTIVE:
  227. port_idx = ibevent->element.port_num - 1;
  228. set_bit(port_idx, &smcibdev->port_event_mask);
  229. schedule_work(&smcibdev->port_event_work);
  230. break;
  231. default:
  232. break;
  233. }
  234. }
  235. void smc_ib_dealloc_protection_domain(struct smc_link *lnk)
  236. {
  237. if (lnk->roce_pd)
  238. ib_dealloc_pd(lnk->roce_pd);
  239. lnk->roce_pd = NULL;
  240. }
  241. int smc_ib_create_protection_domain(struct smc_link *lnk)
  242. {
  243. int rc;
  244. lnk->roce_pd = ib_alloc_pd(lnk->smcibdev->ibdev, 0);
  245. rc = PTR_ERR_OR_ZERO(lnk->roce_pd);
  246. if (IS_ERR(lnk->roce_pd))
  247. lnk->roce_pd = NULL;
  248. return rc;
  249. }
  250. static void smc_ib_qp_event_handler(struct ib_event *ibevent, void *priv)
  251. {
  252. struct smc_ib_device *smcibdev =
  253. (struct smc_ib_device *)ibevent->device;
  254. u8 port_idx;
  255. switch (ibevent->event) {
  256. case IB_EVENT_DEVICE_FATAL:
  257. case IB_EVENT_GID_CHANGE:
  258. case IB_EVENT_PORT_ERR:
  259. case IB_EVENT_QP_ACCESS_ERR:
  260. port_idx = ibevent->element.port_num - 1;
  261. set_bit(port_idx, &smcibdev->port_event_mask);
  262. schedule_work(&smcibdev->port_event_work);
  263. break;
  264. default:
  265. break;
  266. }
  267. }
  268. void smc_ib_destroy_queue_pair(struct smc_link *lnk)
  269. {
  270. if (lnk->roce_qp)
  271. ib_destroy_qp(lnk->roce_qp);
  272. lnk->roce_qp = NULL;
  273. }
  274. /* create a queue pair within the protection domain for a link */
  275. int smc_ib_create_queue_pair(struct smc_link *lnk)
  276. {
  277. struct ib_qp_init_attr qp_attr = {
  278. .event_handler = smc_ib_qp_event_handler,
  279. .qp_context = lnk,
  280. .send_cq = lnk->smcibdev->roce_cq_send,
  281. .recv_cq = lnk->smcibdev->roce_cq_recv,
  282. .srq = NULL,
  283. .cap = {
  284. /* include unsolicited rdma_writes as well,
  285. * there are max. 2 RDMA_WRITE per 1 WR_SEND
  286. */
  287. .max_send_wr = SMC_WR_BUF_CNT * 3,
  288. .max_recv_wr = SMC_WR_BUF_CNT * 3,
  289. .max_send_sge = SMC_IB_MAX_SEND_SGE,
  290. .max_recv_sge = 1,
  291. },
  292. .sq_sig_type = IB_SIGNAL_REQ_WR,
  293. .qp_type = IB_QPT_RC,
  294. };
  295. int rc;
  296. lnk->roce_qp = ib_create_qp(lnk->roce_pd, &qp_attr);
  297. rc = PTR_ERR_OR_ZERO(lnk->roce_qp);
  298. if (IS_ERR(lnk->roce_qp))
  299. lnk->roce_qp = NULL;
  300. else
  301. smc_wr_remember_qp_attr(lnk);
  302. return rc;
  303. }
  304. void smc_ib_put_memory_region(struct ib_mr *mr)
  305. {
  306. ib_dereg_mr(mr);
  307. }
  308. static int smc_ib_map_mr_sg(struct smc_buf_desc *buf_slot)
  309. {
  310. unsigned int offset = 0;
  311. int sg_num;
  312. /* map the largest prefix of a dma mapped SG list */
  313. sg_num = ib_map_mr_sg(buf_slot->mr_rx[SMC_SINGLE_LINK],
  314. buf_slot->sgt[SMC_SINGLE_LINK].sgl,
  315. buf_slot->sgt[SMC_SINGLE_LINK].orig_nents,
  316. &offset, PAGE_SIZE);
  317. return sg_num;
  318. }
  319. /* Allocate a memory region and map the dma mapped SG list of buf_slot */
  320. int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
  321. struct smc_buf_desc *buf_slot)
  322. {
  323. if (buf_slot->mr_rx[SMC_SINGLE_LINK])
  324. return 0; /* already done */
  325. buf_slot->mr_rx[SMC_SINGLE_LINK] =
  326. ib_alloc_mr(pd, IB_MR_TYPE_MEM_REG, 1 << buf_slot->order);
  327. if (IS_ERR(buf_slot->mr_rx[SMC_SINGLE_LINK])) {
  328. int rc;
  329. rc = PTR_ERR(buf_slot->mr_rx[SMC_SINGLE_LINK]);
  330. buf_slot->mr_rx[SMC_SINGLE_LINK] = NULL;
  331. return rc;
  332. }
  333. if (smc_ib_map_mr_sg(buf_slot) != 1)
  334. return -EINVAL;
  335. return 0;
  336. }
  337. /* synchronize buffer usage for cpu access */
  338. void smc_ib_sync_sg_for_cpu(struct smc_ib_device *smcibdev,
  339. struct smc_buf_desc *buf_slot,
  340. enum dma_data_direction data_direction)
  341. {
  342. struct scatterlist *sg;
  343. unsigned int i;
  344. /* for now there is just one DMA address */
  345. for_each_sg(buf_slot->sgt[SMC_SINGLE_LINK].sgl, sg,
  346. buf_slot->sgt[SMC_SINGLE_LINK].nents, i) {
  347. if (!sg_dma_len(sg))
  348. break;
  349. ib_dma_sync_single_for_cpu(smcibdev->ibdev,
  350. sg_dma_address(sg),
  351. sg_dma_len(sg),
  352. data_direction);
  353. }
  354. }
  355. /* synchronize buffer usage for device access */
  356. void smc_ib_sync_sg_for_device(struct smc_ib_device *smcibdev,
  357. struct smc_buf_desc *buf_slot,
  358. enum dma_data_direction data_direction)
  359. {
  360. struct scatterlist *sg;
  361. unsigned int i;
  362. /* for now there is just one DMA address */
  363. for_each_sg(buf_slot->sgt[SMC_SINGLE_LINK].sgl, sg,
  364. buf_slot->sgt[SMC_SINGLE_LINK].nents, i) {
  365. if (!sg_dma_len(sg))
  366. break;
  367. ib_dma_sync_single_for_device(smcibdev->ibdev,
  368. sg_dma_address(sg),
  369. sg_dma_len(sg),
  370. data_direction);
  371. }
  372. }
  373. /* Map a new TX or RX buffer SG-table to DMA */
  374. int smc_ib_buf_map_sg(struct smc_ib_device *smcibdev,
  375. struct smc_buf_desc *buf_slot,
  376. enum dma_data_direction data_direction)
  377. {
  378. int mapped_nents;
  379. mapped_nents = ib_dma_map_sg(smcibdev->ibdev,
  380. buf_slot->sgt[SMC_SINGLE_LINK].sgl,
  381. buf_slot->sgt[SMC_SINGLE_LINK].orig_nents,
  382. data_direction);
  383. if (!mapped_nents)
  384. return -ENOMEM;
  385. return mapped_nents;
  386. }
  387. void smc_ib_buf_unmap_sg(struct smc_ib_device *smcibdev,
  388. struct smc_buf_desc *buf_slot,
  389. enum dma_data_direction data_direction)
  390. {
  391. if (!buf_slot->sgt[SMC_SINGLE_LINK].sgl->dma_address)
  392. return; /* already unmapped */
  393. ib_dma_unmap_sg(smcibdev->ibdev,
  394. buf_slot->sgt[SMC_SINGLE_LINK].sgl,
  395. buf_slot->sgt[SMC_SINGLE_LINK].orig_nents,
  396. data_direction);
  397. buf_slot->sgt[SMC_SINGLE_LINK].sgl->dma_address = 0;
  398. }
  399. long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev)
  400. {
  401. struct ib_cq_init_attr cqattr = {
  402. .cqe = SMC_MAX_CQE, .comp_vector = 0 };
  403. int cqe_size_order, smc_order;
  404. long rc;
  405. /* the calculated number of cq entries fits to mlx5 cq allocation */
  406. cqe_size_order = cache_line_size() == 128 ? 7 : 6;
  407. smc_order = MAX_ORDER - cqe_size_order - 1;
  408. if (SMC_MAX_CQE + 2 > (0x00000001 << smc_order) * PAGE_SIZE)
  409. cqattr.cqe = (0x00000001 << smc_order) * PAGE_SIZE - 2;
  410. smcibdev->roce_cq_send = ib_create_cq(smcibdev->ibdev,
  411. smc_wr_tx_cq_handler, NULL,
  412. smcibdev, &cqattr);
  413. rc = PTR_ERR_OR_ZERO(smcibdev->roce_cq_send);
  414. if (IS_ERR(smcibdev->roce_cq_send)) {
  415. smcibdev->roce_cq_send = NULL;
  416. return rc;
  417. }
  418. smcibdev->roce_cq_recv = ib_create_cq(smcibdev->ibdev,
  419. smc_wr_rx_cq_handler, NULL,
  420. smcibdev, &cqattr);
  421. rc = PTR_ERR_OR_ZERO(smcibdev->roce_cq_recv);
  422. if (IS_ERR(smcibdev->roce_cq_recv)) {
  423. smcibdev->roce_cq_recv = NULL;
  424. goto err;
  425. }
  426. smc_wr_add_dev(smcibdev);
  427. smcibdev->initialized = 1;
  428. return rc;
  429. err:
  430. ib_destroy_cq(smcibdev->roce_cq_send);
  431. return rc;
  432. }
  433. static void smc_ib_cleanup_per_ibdev(struct smc_ib_device *smcibdev)
  434. {
  435. if (!smcibdev->initialized)
  436. return;
  437. smcibdev->initialized = 0;
  438. smc_wr_remove_dev(smcibdev);
  439. ib_destroy_cq(smcibdev->roce_cq_recv);
  440. ib_destroy_cq(smcibdev->roce_cq_send);
  441. }
  442. static struct ib_client smc_ib_client;
  443. /* callback function for ib_register_client() */
  444. static void smc_ib_add_dev(struct ib_device *ibdev)
  445. {
  446. struct smc_ib_device *smcibdev;
  447. u8 port_cnt;
  448. int i;
  449. if (ibdev->node_type != RDMA_NODE_IB_CA)
  450. return;
  451. smcibdev = kzalloc(sizeof(*smcibdev), GFP_KERNEL);
  452. if (!smcibdev)
  453. return;
  454. smcibdev->ibdev = ibdev;
  455. INIT_WORK(&smcibdev->port_event_work, smc_ib_port_event_work);
  456. spin_lock(&smc_ib_devices.lock);
  457. list_add_tail(&smcibdev->list, &smc_ib_devices.list);
  458. spin_unlock(&smc_ib_devices.lock);
  459. ib_set_client_data(ibdev, &smc_ib_client, smcibdev);
  460. INIT_IB_EVENT_HANDLER(&smcibdev->event_handler, smcibdev->ibdev,
  461. smc_ib_global_event_handler);
  462. ib_register_event_handler(&smcibdev->event_handler);
  463. /* trigger reading of the port attributes */
  464. port_cnt = smcibdev->ibdev->phys_port_cnt;
  465. for (i = 0;
  466. i < min_t(size_t, port_cnt, SMC_MAX_PORTS);
  467. i++) {
  468. set_bit(i, &smcibdev->port_event_mask);
  469. /* determine pnetids of the port */
  470. smc_pnetid_by_dev_port(ibdev->dev.parent, i,
  471. smcibdev->pnetid[i]);
  472. }
  473. schedule_work(&smcibdev->port_event_work);
  474. }
  475. /* callback function for ib_register_client() */
  476. static void smc_ib_remove_dev(struct ib_device *ibdev, void *client_data)
  477. {
  478. struct smc_ib_device *smcibdev;
  479. smcibdev = ib_get_client_data(ibdev, &smc_ib_client);
  480. if (!smcibdev || smcibdev->ibdev != ibdev)
  481. return;
  482. ib_set_client_data(ibdev, &smc_ib_client, NULL);
  483. spin_lock(&smc_ib_devices.lock);
  484. list_del_init(&smcibdev->list); /* remove from smc_ib_devices */
  485. spin_unlock(&smc_ib_devices.lock);
  486. smc_pnet_remove_by_ibdev(smcibdev);
  487. smc_ib_cleanup_per_ibdev(smcibdev);
  488. ib_unregister_event_handler(&smcibdev->event_handler);
  489. cancel_work_sync(&smcibdev->port_event_work);
  490. kfree(smcibdev);
  491. }
  492. static struct ib_client smc_ib_client = {
  493. .name = "smc_ib",
  494. .add = smc_ib_add_dev,
  495. .remove = smc_ib_remove_dev,
  496. };
  497. int __init smc_ib_register_client(void)
  498. {
  499. return ib_register_client(&smc_ib_client);
  500. }
  501. void smc_ib_unregister_client(void)
  502. {
  503. ib_unregister_client(&smc_ib_client);
  504. }