ocrdma_main.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. /*******************************************************************
  2. * This file is part of the Emulex RoCE Device Driver for *
  3. * RoCE (RDMA over Converged Ethernet) adapters. *
  4. * Copyright (C) 2008-2012 Emulex. All rights reserved. *
  5. * EMULEX and SLI are trademarks of Emulex. *
  6. * www.emulex.com *
  7. * *
  8. * This program is free software; you can redistribute it and/or *
  9. * modify it under the terms of version 2 of the GNU General *
  10. * Public License as published by the Free Software Foundation. *
  11. * This program is distributed in the hope that it will be useful. *
  12. * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
  13. * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
  14. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
  15. * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
  16. * TO BE LEGALLY INVALID. See the GNU General Public License for *
  17. * more details, a copy of which can be found in the file COPYING *
  18. * included with this package. *
  19. *
  20. * Contact Information:
  21. * linux-drivers@emulex.com
  22. *
  23. * Emulex
  24. * 3333 Susan Street
  25. * Costa Mesa, CA 92626
  26. *******************************************************************/
  27. #include <linux/module.h>
  28. #include <linux/idr.h>
  29. #include <rdma/ib_verbs.h>
  30. #include <rdma/ib_user_verbs.h>
  31. #include <rdma/ib_addr.h>
  32. #include <linux/netdevice.h>
  33. #include <net/addrconf.h>
  34. #include "ocrdma.h"
  35. #include "ocrdma_verbs.h"
  36. #include "ocrdma_ah.h"
  37. #include "be_roce.h"
  38. #include "ocrdma_hw.h"
  39. #include "ocrdma_stats.h"
  40. #include "ocrdma_abi.h"
  41. MODULE_VERSION(OCRDMA_ROCE_DRV_VERSION);
  42. MODULE_DESCRIPTION(OCRDMA_ROCE_DRV_DESC " " OCRDMA_ROCE_DRV_VERSION);
  43. MODULE_AUTHOR("Emulex Corporation");
  44. MODULE_LICENSE("GPL");
  45. static LIST_HEAD(ocrdma_dev_list);
  46. static DEFINE_SPINLOCK(ocrdma_devlist_lock);
  47. static DEFINE_IDR(ocrdma_dev_id);
  48. static union ib_gid ocrdma_zero_sgid;
  49. void ocrdma_get_guid(struct ocrdma_dev *dev, u8 *guid)
  50. {
  51. u8 mac_addr[6];
  52. memcpy(&mac_addr[0], &dev->nic_info.mac_addr[0], ETH_ALEN);
  53. guid[0] = mac_addr[0] ^ 2;
  54. guid[1] = mac_addr[1];
  55. guid[2] = mac_addr[2];
  56. guid[3] = 0xff;
  57. guid[4] = 0xfe;
  58. guid[5] = mac_addr[3];
  59. guid[6] = mac_addr[4];
  60. guid[7] = mac_addr[5];
  61. }
  62. static bool ocrdma_add_sgid(struct ocrdma_dev *dev, union ib_gid *new_sgid)
  63. {
  64. int i;
  65. unsigned long flags;
  66. memset(&ocrdma_zero_sgid, 0, sizeof(union ib_gid));
  67. spin_lock_irqsave(&dev->sgid_lock, flags);
  68. for (i = 0; i < OCRDMA_MAX_SGID; i++) {
  69. if (!memcmp(&dev->sgid_tbl[i], &ocrdma_zero_sgid,
  70. sizeof(union ib_gid))) {
  71. /* found free entry */
  72. memcpy(&dev->sgid_tbl[i], new_sgid,
  73. sizeof(union ib_gid));
  74. spin_unlock_irqrestore(&dev->sgid_lock, flags);
  75. return true;
  76. } else if (!memcmp(&dev->sgid_tbl[i], new_sgid,
  77. sizeof(union ib_gid))) {
  78. /* entry already present, no addition is required. */
  79. spin_unlock_irqrestore(&dev->sgid_lock, flags);
  80. return false;
  81. }
  82. }
  83. spin_unlock_irqrestore(&dev->sgid_lock, flags);
  84. return false;
  85. }
  86. static bool ocrdma_del_sgid(struct ocrdma_dev *dev, union ib_gid *sgid)
  87. {
  88. int found = false;
  89. int i;
  90. unsigned long flags;
  91. spin_lock_irqsave(&dev->sgid_lock, flags);
  92. /* first is default sgid, which cannot be deleted. */
  93. for (i = 1; i < OCRDMA_MAX_SGID; i++) {
  94. if (!memcmp(&dev->sgid_tbl[i], sgid, sizeof(union ib_gid))) {
  95. /* found matching entry */
  96. memset(&dev->sgid_tbl[i], 0, sizeof(union ib_gid));
  97. found = true;
  98. break;
  99. }
  100. }
  101. spin_unlock_irqrestore(&dev->sgid_lock, flags);
  102. return found;
  103. }
  104. static int ocrdma_addr_event(unsigned long event, struct net_device *netdev,
  105. union ib_gid *gid)
  106. {
  107. struct ib_event gid_event;
  108. struct ocrdma_dev *dev;
  109. bool found = false;
  110. bool updated = false;
  111. bool is_vlan = false;
  112. is_vlan = netdev->priv_flags & IFF_802_1Q_VLAN;
  113. if (is_vlan)
  114. netdev = rdma_vlan_dev_real_dev(netdev);
  115. rcu_read_lock();
  116. list_for_each_entry_rcu(dev, &ocrdma_dev_list, entry) {
  117. if (dev->nic_info.netdev == netdev) {
  118. found = true;
  119. break;
  120. }
  121. }
  122. rcu_read_unlock();
  123. if (!found)
  124. return NOTIFY_DONE;
  125. mutex_lock(&dev->dev_lock);
  126. switch (event) {
  127. case NETDEV_UP:
  128. updated = ocrdma_add_sgid(dev, gid);
  129. break;
  130. case NETDEV_DOWN:
  131. updated = ocrdma_del_sgid(dev, gid);
  132. break;
  133. default:
  134. break;
  135. }
  136. if (updated) {
  137. /* GID table updated, notify the consumers about it */
  138. gid_event.device = &dev->ibdev;
  139. gid_event.element.port_num = 1;
  140. gid_event.event = IB_EVENT_GID_CHANGE;
  141. ib_dispatch_event(&gid_event);
  142. }
  143. mutex_unlock(&dev->dev_lock);
  144. return NOTIFY_OK;
  145. }
  146. static int ocrdma_inetaddr_event(struct notifier_block *notifier,
  147. unsigned long event, void *ptr)
  148. {
  149. struct in_ifaddr *ifa = ptr;
  150. union ib_gid gid;
  151. struct net_device *netdev = ifa->ifa_dev->dev;
  152. ipv6_addr_set_v4mapped(ifa->ifa_address, (struct in6_addr *)&gid);
  153. return ocrdma_addr_event(event, netdev, &gid);
  154. }
  155. static struct notifier_block ocrdma_inetaddr_notifier = {
  156. .notifier_call = ocrdma_inetaddr_event
  157. };
  158. #if IS_ENABLED(CONFIG_IPV6)
  159. static int ocrdma_inet6addr_event(struct notifier_block *notifier,
  160. unsigned long event, void *ptr)
  161. {
  162. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
  163. union ib_gid *gid = (union ib_gid *)&ifa->addr;
  164. struct net_device *netdev = ifa->idev->dev;
  165. return ocrdma_addr_event(event, netdev, gid);
  166. }
  167. static struct notifier_block ocrdma_inet6addr_notifier = {
  168. .notifier_call = ocrdma_inet6addr_event
  169. };
  170. #endif /* IPV6 and VLAN */
  171. static enum rdma_link_layer ocrdma_link_layer(struct ib_device *device,
  172. u8 port_num)
  173. {
  174. return IB_LINK_LAYER_ETHERNET;
  175. }
  176. static int ocrdma_register_device(struct ocrdma_dev *dev)
  177. {
  178. strlcpy(dev->ibdev.name, "ocrdma%d", IB_DEVICE_NAME_MAX);
  179. ocrdma_get_guid(dev, (u8 *)&dev->ibdev.node_guid);
  180. memcpy(dev->ibdev.node_desc, OCRDMA_NODE_DESC,
  181. sizeof(OCRDMA_NODE_DESC));
  182. dev->ibdev.owner = THIS_MODULE;
  183. dev->ibdev.uverbs_abi_ver = OCRDMA_ABI_VERSION;
  184. dev->ibdev.uverbs_cmd_mask =
  185. OCRDMA_UVERBS(GET_CONTEXT) |
  186. OCRDMA_UVERBS(QUERY_DEVICE) |
  187. OCRDMA_UVERBS(QUERY_PORT) |
  188. OCRDMA_UVERBS(ALLOC_PD) |
  189. OCRDMA_UVERBS(DEALLOC_PD) |
  190. OCRDMA_UVERBS(REG_MR) |
  191. OCRDMA_UVERBS(DEREG_MR) |
  192. OCRDMA_UVERBS(CREATE_COMP_CHANNEL) |
  193. OCRDMA_UVERBS(CREATE_CQ) |
  194. OCRDMA_UVERBS(RESIZE_CQ) |
  195. OCRDMA_UVERBS(DESTROY_CQ) |
  196. OCRDMA_UVERBS(REQ_NOTIFY_CQ) |
  197. OCRDMA_UVERBS(CREATE_QP) |
  198. OCRDMA_UVERBS(MODIFY_QP) |
  199. OCRDMA_UVERBS(QUERY_QP) |
  200. OCRDMA_UVERBS(DESTROY_QP) |
  201. OCRDMA_UVERBS(POLL_CQ) |
  202. OCRDMA_UVERBS(POST_SEND) |
  203. OCRDMA_UVERBS(POST_RECV);
  204. dev->ibdev.uverbs_cmd_mask |=
  205. OCRDMA_UVERBS(CREATE_AH) |
  206. OCRDMA_UVERBS(MODIFY_AH) |
  207. OCRDMA_UVERBS(QUERY_AH) |
  208. OCRDMA_UVERBS(DESTROY_AH);
  209. dev->ibdev.node_type = RDMA_NODE_IB_CA;
  210. dev->ibdev.phys_port_cnt = 1;
  211. dev->ibdev.num_comp_vectors = 1;
  212. /* mandatory verbs. */
  213. dev->ibdev.query_device = ocrdma_query_device;
  214. dev->ibdev.query_port = ocrdma_query_port;
  215. dev->ibdev.modify_port = ocrdma_modify_port;
  216. dev->ibdev.query_gid = ocrdma_query_gid;
  217. dev->ibdev.get_link_layer = ocrdma_link_layer;
  218. dev->ibdev.alloc_pd = ocrdma_alloc_pd;
  219. dev->ibdev.dealloc_pd = ocrdma_dealloc_pd;
  220. dev->ibdev.create_cq = ocrdma_create_cq;
  221. dev->ibdev.destroy_cq = ocrdma_destroy_cq;
  222. dev->ibdev.resize_cq = ocrdma_resize_cq;
  223. dev->ibdev.create_qp = ocrdma_create_qp;
  224. dev->ibdev.modify_qp = ocrdma_modify_qp;
  225. dev->ibdev.query_qp = ocrdma_query_qp;
  226. dev->ibdev.destroy_qp = ocrdma_destroy_qp;
  227. dev->ibdev.query_pkey = ocrdma_query_pkey;
  228. dev->ibdev.create_ah = ocrdma_create_ah;
  229. dev->ibdev.destroy_ah = ocrdma_destroy_ah;
  230. dev->ibdev.query_ah = ocrdma_query_ah;
  231. dev->ibdev.modify_ah = ocrdma_modify_ah;
  232. dev->ibdev.poll_cq = ocrdma_poll_cq;
  233. dev->ibdev.post_send = ocrdma_post_send;
  234. dev->ibdev.post_recv = ocrdma_post_recv;
  235. dev->ibdev.req_notify_cq = ocrdma_arm_cq;
  236. dev->ibdev.get_dma_mr = ocrdma_get_dma_mr;
  237. dev->ibdev.reg_phys_mr = ocrdma_reg_kernel_mr;
  238. dev->ibdev.dereg_mr = ocrdma_dereg_mr;
  239. dev->ibdev.reg_user_mr = ocrdma_reg_user_mr;
  240. dev->ibdev.alloc_fast_reg_mr = ocrdma_alloc_frmr;
  241. dev->ibdev.alloc_fast_reg_page_list = ocrdma_alloc_frmr_page_list;
  242. dev->ibdev.free_fast_reg_page_list = ocrdma_free_frmr_page_list;
  243. /* mandatory to support user space verbs consumer. */
  244. dev->ibdev.alloc_ucontext = ocrdma_alloc_ucontext;
  245. dev->ibdev.dealloc_ucontext = ocrdma_dealloc_ucontext;
  246. dev->ibdev.mmap = ocrdma_mmap;
  247. dev->ibdev.dma_device = &dev->nic_info.pdev->dev;
  248. dev->ibdev.process_mad = ocrdma_process_mad;
  249. if (ocrdma_get_asic_type(dev) == OCRDMA_ASIC_GEN_SKH_R) {
  250. dev->ibdev.uverbs_cmd_mask |=
  251. OCRDMA_UVERBS(CREATE_SRQ) |
  252. OCRDMA_UVERBS(MODIFY_SRQ) |
  253. OCRDMA_UVERBS(QUERY_SRQ) |
  254. OCRDMA_UVERBS(DESTROY_SRQ) |
  255. OCRDMA_UVERBS(POST_SRQ_RECV);
  256. dev->ibdev.create_srq = ocrdma_create_srq;
  257. dev->ibdev.modify_srq = ocrdma_modify_srq;
  258. dev->ibdev.query_srq = ocrdma_query_srq;
  259. dev->ibdev.destroy_srq = ocrdma_destroy_srq;
  260. dev->ibdev.post_srq_recv = ocrdma_post_srq_recv;
  261. }
  262. return ib_register_device(&dev->ibdev, NULL);
  263. }
  264. static int ocrdma_alloc_resources(struct ocrdma_dev *dev)
  265. {
  266. mutex_init(&dev->dev_lock);
  267. dev->sgid_tbl = kzalloc(sizeof(union ib_gid) *
  268. OCRDMA_MAX_SGID, GFP_KERNEL);
  269. if (!dev->sgid_tbl)
  270. goto alloc_err;
  271. spin_lock_init(&dev->sgid_lock);
  272. dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) *
  273. OCRDMA_MAX_CQ, GFP_KERNEL);
  274. if (!dev->cq_tbl)
  275. goto alloc_err;
  276. if (dev->attr.max_qp) {
  277. dev->qp_tbl = kzalloc(sizeof(struct ocrdma_qp *) *
  278. OCRDMA_MAX_QP, GFP_KERNEL);
  279. if (!dev->qp_tbl)
  280. goto alloc_err;
  281. }
  282. spin_lock_init(&dev->av_tbl.lock);
  283. spin_lock_init(&dev->flush_q_lock);
  284. return 0;
  285. alloc_err:
  286. pr_err("%s(%d) error.\n", __func__, dev->id);
  287. return -ENOMEM;
  288. }
  289. static void ocrdma_free_resources(struct ocrdma_dev *dev)
  290. {
  291. kfree(dev->qp_tbl);
  292. kfree(dev->cq_tbl);
  293. kfree(dev->sgid_tbl);
  294. }
  295. /* OCRDMA sysfs interface */
  296. static ssize_t show_rev(struct device *device, struct device_attribute *attr,
  297. char *buf)
  298. {
  299. struct ocrdma_dev *dev = dev_get_drvdata(device);
  300. return scnprintf(buf, PAGE_SIZE, "0x%x\n", dev->nic_info.pdev->vendor);
  301. }
  302. static ssize_t show_fw_ver(struct device *device, struct device_attribute *attr,
  303. char *buf)
  304. {
  305. struct ocrdma_dev *dev = dev_get_drvdata(device);
  306. return scnprintf(buf, PAGE_SIZE, "%s", &dev->attr.fw_ver[0]);
  307. }
  308. static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  309. static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
  310. static struct device_attribute *ocrdma_attributes[] = {
  311. &dev_attr_hw_rev,
  312. &dev_attr_fw_ver
  313. };
  314. static void ocrdma_remove_sysfiles(struct ocrdma_dev *dev)
  315. {
  316. int i;
  317. for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++)
  318. device_remove_file(&dev->ibdev.dev, ocrdma_attributes[i]);
  319. }
  320. static struct ocrdma_dev *ocrdma_add(struct be_dev_info *dev_info)
  321. {
  322. int status = 0, i;
  323. struct ocrdma_dev *dev;
  324. dev = (struct ocrdma_dev *)ib_alloc_device(sizeof(struct ocrdma_dev));
  325. if (!dev) {
  326. pr_err("Unable to allocate ib device\n");
  327. return NULL;
  328. }
  329. dev->mbx_cmd = kzalloc(sizeof(struct ocrdma_mqe_emb_cmd), GFP_KERNEL);
  330. if (!dev->mbx_cmd)
  331. goto idr_err;
  332. memcpy(&dev->nic_info, dev_info, sizeof(*dev_info));
  333. dev->id = idr_alloc(&ocrdma_dev_id, NULL, 0, 0, GFP_KERNEL);
  334. if (dev->id < 0)
  335. goto idr_err;
  336. status = ocrdma_init_hw(dev);
  337. if (status)
  338. goto init_err;
  339. status = ocrdma_alloc_resources(dev);
  340. if (status)
  341. goto alloc_err;
  342. status = ocrdma_register_device(dev);
  343. if (status)
  344. goto alloc_err;
  345. for (i = 0; i < ARRAY_SIZE(ocrdma_attributes); i++)
  346. if (device_create_file(&dev->ibdev.dev, ocrdma_attributes[i]))
  347. goto sysfs_err;
  348. spin_lock(&ocrdma_devlist_lock);
  349. list_add_tail_rcu(&dev->entry, &ocrdma_dev_list);
  350. spin_unlock(&ocrdma_devlist_lock);
  351. /* Init stats */
  352. ocrdma_add_port_stats(dev);
  353. pr_info("%s %s: %s \"%s\" port %d\n",
  354. dev_name(&dev->nic_info.pdev->dev), hca_name(dev),
  355. port_speed_string(dev), dev->model_number,
  356. dev->hba_port_num);
  357. pr_info("%s ocrdma%d driver loaded successfully\n",
  358. dev_name(&dev->nic_info.pdev->dev), dev->id);
  359. return dev;
  360. sysfs_err:
  361. ocrdma_remove_sysfiles(dev);
  362. alloc_err:
  363. ocrdma_free_resources(dev);
  364. ocrdma_cleanup_hw(dev);
  365. init_err:
  366. idr_remove(&ocrdma_dev_id, dev->id);
  367. idr_err:
  368. kfree(dev->mbx_cmd);
  369. ib_dealloc_device(&dev->ibdev);
  370. pr_err("%s() leaving. ret=%d\n", __func__, status);
  371. return NULL;
  372. }
  373. static void ocrdma_remove_free(struct rcu_head *rcu)
  374. {
  375. struct ocrdma_dev *dev = container_of(rcu, struct ocrdma_dev, rcu);
  376. idr_remove(&ocrdma_dev_id, dev->id);
  377. kfree(dev->mbx_cmd);
  378. ib_dealloc_device(&dev->ibdev);
  379. }
  380. static void ocrdma_remove(struct ocrdma_dev *dev)
  381. {
  382. /* first unregister with stack to stop all the active traffic
  383. * of the registered clients.
  384. */
  385. ocrdma_rem_port_stats(dev);
  386. ocrdma_remove_sysfiles(dev);
  387. ib_unregister_device(&dev->ibdev);
  388. spin_lock(&ocrdma_devlist_lock);
  389. list_del_rcu(&dev->entry);
  390. spin_unlock(&ocrdma_devlist_lock);
  391. ocrdma_free_resources(dev);
  392. ocrdma_cleanup_hw(dev);
  393. call_rcu(&dev->rcu, ocrdma_remove_free);
  394. }
  395. static int ocrdma_open(struct ocrdma_dev *dev)
  396. {
  397. struct ib_event port_event;
  398. port_event.event = IB_EVENT_PORT_ACTIVE;
  399. port_event.element.port_num = 1;
  400. port_event.device = &dev->ibdev;
  401. ib_dispatch_event(&port_event);
  402. return 0;
  403. }
  404. static int ocrdma_close(struct ocrdma_dev *dev)
  405. {
  406. int i;
  407. struct ocrdma_qp *qp, **cur_qp;
  408. struct ib_event err_event;
  409. struct ib_qp_attr attrs;
  410. int attr_mask = IB_QP_STATE;
  411. attrs.qp_state = IB_QPS_ERR;
  412. mutex_lock(&dev->dev_lock);
  413. if (dev->qp_tbl) {
  414. cur_qp = dev->qp_tbl;
  415. for (i = 0; i < OCRDMA_MAX_QP; i++) {
  416. qp = cur_qp[i];
  417. if (qp && qp->ibqp.qp_type != IB_QPT_GSI) {
  418. /* change the QP state to ERROR */
  419. _ocrdma_modify_qp(&qp->ibqp, &attrs, attr_mask);
  420. err_event.event = IB_EVENT_QP_FATAL;
  421. err_event.element.qp = &qp->ibqp;
  422. err_event.device = &dev->ibdev;
  423. ib_dispatch_event(&err_event);
  424. }
  425. }
  426. }
  427. mutex_unlock(&dev->dev_lock);
  428. err_event.event = IB_EVENT_PORT_ERR;
  429. err_event.element.port_num = 1;
  430. err_event.device = &dev->ibdev;
  431. ib_dispatch_event(&err_event);
  432. return 0;
  433. }
  434. /* event handling via NIC driver ensures that all the NIC specific
  435. * initialization done before RoCE driver notifies
  436. * event to stack.
  437. */
  438. static void ocrdma_event_handler(struct ocrdma_dev *dev, u32 event)
  439. {
  440. switch (event) {
  441. case BE_DEV_UP:
  442. ocrdma_open(dev);
  443. break;
  444. case BE_DEV_DOWN:
  445. ocrdma_close(dev);
  446. break;
  447. }
  448. }
  449. static struct ocrdma_driver ocrdma_drv = {
  450. .name = "ocrdma_driver",
  451. .add = ocrdma_add,
  452. .remove = ocrdma_remove,
  453. .state_change_handler = ocrdma_event_handler,
  454. .be_abi_version = OCRDMA_BE_ROCE_ABI_VERSION,
  455. };
  456. static void ocrdma_unregister_inet6addr_notifier(void)
  457. {
  458. #if IS_ENABLED(CONFIG_IPV6)
  459. unregister_inet6addr_notifier(&ocrdma_inet6addr_notifier);
  460. #endif
  461. }
  462. static void ocrdma_unregister_inetaddr_notifier(void)
  463. {
  464. unregister_inetaddr_notifier(&ocrdma_inetaddr_notifier);
  465. }
  466. static int __init ocrdma_init_module(void)
  467. {
  468. int status;
  469. ocrdma_init_debugfs();
  470. status = register_inetaddr_notifier(&ocrdma_inetaddr_notifier);
  471. if (status)
  472. return status;
  473. #if IS_ENABLED(CONFIG_IPV6)
  474. status = register_inet6addr_notifier(&ocrdma_inet6addr_notifier);
  475. if (status)
  476. goto err_notifier6;
  477. #endif
  478. status = be_roce_register_driver(&ocrdma_drv);
  479. if (status)
  480. goto err_be_reg;
  481. return 0;
  482. err_be_reg:
  483. ocrdma_unregister_inet6addr_notifier();
  484. err_notifier6:
  485. ocrdma_unregister_inetaddr_notifier();
  486. return status;
  487. }
  488. static void __exit ocrdma_exit_module(void)
  489. {
  490. be_roce_unregister_driver(&ocrdma_drv);
  491. ocrdma_unregister_inet6addr_notifier();
  492. ocrdma_unregister_inetaddr_notifier();
  493. ocrdma_rem_debugfs();
  494. }
  495. module_init(ocrdma_init_module);
  496. module_exit(ocrdma_exit_module);