c2_rnic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /*
  2. * Copyright (c) 2005 Ammasso, Inc. All rights reserved.
  3. * Copyright (c) 2005 Open Grid Computing, 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. */
  34. #include <linux/module.h>
  35. #include <linux/moduleparam.h>
  36. #include <linux/pci.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/delay.h>
  40. #include <linux/ethtool.h>
  41. #include <linux/mii.h>
  42. #include <linux/if_vlan.h>
  43. #include <linux/crc32.h>
  44. #include <linux/in.h>
  45. #include <linux/ip.h>
  46. #include <linux/tcp.h>
  47. #include <linux/init.h>
  48. #include <linux/dma-mapping.h>
  49. #include <linux/mm.h>
  50. #include <linux/inet.h>
  51. #include <linux/vmalloc.h>
  52. #include <linux/route.h>
  53. #include <asm/io.h>
  54. #include <asm/irq.h>
  55. #include <asm/byteorder.h>
  56. #include <rdma/ib_smi.h>
  57. #include "c2.h"
  58. #include "c2_vq.h"
  59. /* Device capabilities */
  60. #define C2_MIN_PAGESIZE 1024
  61. #define C2_MAX_MRS 32768
  62. #define C2_MAX_QPS 16000
  63. #define C2_MAX_WQE_SZ 256
  64. #define C2_MAX_QP_WR ((128*1024)/C2_MAX_WQE_SZ)
  65. #define C2_MAX_SGES 4
  66. #define C2_MAX_SGE_RD 1
  67. #define C2_MAX_CQS 32768
  68. #define C2_MAX_CQES 4096
  69. #define C2_MAX_PDS 16384
  70. /*
  71. * Send the adapter INIT message to the amso1100
  72. */
  73. static int c2_adapter_init(struct c2_dev *c2dev)
  74. {
  75. struct c2wr_init_req wr;
  76. int err;
  77. memset(&wr, 0, sizeof(wr));
  78. c2_wr_set_id(&wr, CCWR_INIT);
  79. wr.hdr.context = 0;
  80. wr.hint_count = cpu_to_be64(c2dev->hint_count_dma);
  81. wr.q0_host_shared = cpu_to_be64(c2dev->req_vq.shared_dma);
  82. wr.q1_host_shared = cpu_to_be64(c2dev->rep_vq.shared_dma);
  83. wr.q1_host_msg_pool = cpu_to_be64(c2dev->rep_vq.host_dma);
  84. wr.q2_host_shared = cpu_to_be64(c2dev->aeq.shared_dma);
  85. wr.q2_host_msg_pool = cpu_to_be64(c2dev->aeq.host_dma);
  86. /* Post the init message */
  87. err = vq_send_wr(c2dev, (union c2wr *) & wr);
  88. return err;
  89. }
  90. /*
  91. * Send the adapter TERM message to the amso1100
  92. */
  93. static void c2_adapter_term(struct c2_dev *c2dev)
  94. {
  95. struct c2wr_init_req wr;
  96. memset(&wr, 0, sizeof(wr));
  97. c2_wr_set_id(&wr, CCWR_TERM);
  98. wr.hdr.context = 0;
  99. /* Post the init message */
  100. vq_send_wr(c2dev, (union c2wr *) & wr);
  101. c2dev->init = 0;
  102. return;
  103. }
  104. /*
  105. * Query the adapter
  106. */
  107. static int c2_rnic_query(struct c2_dev *c2dev, struct ib_device_attr *props)
  108. {
  109. struct c2_vq_req *vq_req;
  110. struct c2wr_rnic_query_req wr;
  111. struct c2wr_rnic_query_rep *reply;
  112. int err;
  113. vq_req = vq_req_alloc(c2dev);
  114. if (!vq_req)
  115. return -ENOMEM;
  116. c2_wr_set_id(&wr, CCWR_RNIC_QUERY);
  117. wr.hdr.context = (unsigned long) vq_req;
  118. wr.rnic_handle = c2dev->adapter_handle;
  119. vq_req_get(c2dev, vq_req);
  120. err = vq_send_wr(c2dev, (union c2wr *) &wr);
  121. if (err) {
  122. vq_req_put(c2dev, vq_req);
  123. goto bail1;
  124. }
  125. err = vq_wait_for_reply(c2dev, vq_req);
  126. if (err)
  127. goto bail1;
  128. reply =
  129. (struct c2wr_rnic_query_rep *) (unsigned long) (vq_req->reply_msg);
  130. if (!reply)
  131. err = -ENOMEM;
  132. err = c2_errno(reply);
  133. if (err)
  134. goto bail2;
  135. props->fw_ver =
  136. ((u64)be32_to_cpu(reply->fw_ver_major) << 32) |
  137. ((be32_to_cpu(reply->fw_ver_minor) && 0xFFFF) << 16) |
  138. (be32_to_cpu(reply->fw_ver_patch) && 0xFFFF);
  139. memcpy(&props->sys_image_guid, c2dev->netdev->dev_addr, 6);
  140. props->max_mr_size = 0xFFFFFFFF;
  141. props->page_size_cap = ~(C2_MIN_PAGESIZE-1);
  142. props->vendor_id = be32_to_cpu(reply->vendor_id);
  143. props->vendor_part_id = be32_to_cpu(reply->part_number);
  144. props->hw_ver = be32_to_cpu(reply->hw_version);
  145. props->max_qp = be32_to_cpu(reply->max_qps);
  146. props->max_qp_wr = be32_to_cpu(reply->max_qp_depth);
  147. props->device_cap_flags = c2dev->device_cap_flags;
  148. props->max_sge = C2_MAX_SGES;
  149. props->max_sge_rd = C2_MAX_SGE_RD;
  150. props->max_cq = be32_to_cpu(reply->max_cqs);
  151. props->max_cqe = be32_to_cpu(reply->max_cq_depth);
  152. props->max_mr = be32_to_cpu(reply->max_mrs);
  153. props->max_pd = be32_to_cpu(reply->max_pds);
  154. props->max_qp_rd_atom = be32_to_cpu(reply->max_qp_ird);
  155. props->max_ee_rd_atom = 0;
  156. props->max_res_rd_atom = be32_to_cpu(reply->max_global_ird);
  157. props->max_qp_init_rd_atom = be32_to_cpu(reply->max_qp_ord);
  158. props->max_ee_init_rd_atom = 0;
  159. props->atomic_cap = IB_ATOMIC_NONE;
  160. props->max_ee = 0;
  161. props->max_rdd = 0;
  162. props->max_mw = be32_to_cpu(reply->max_mws);
  163. props->max_raw_ipv6_qp = 0;
  164. props->max_raw_ethy_qp = 0;
  165. props->max_mcast_grp = 0;
  166. props->max_mcast_qp_attach = 0;
  167. props->max_total_mcast_qp_attach = 0;
  168. props->max_ah = 0;
  169. props->max_fmr = 0;
  170. props->max_map_per_fmr = 0;
  171. props->max_srq = 0;
  172. props->max_srq_wr = 0;
  173. props->max_srq_sge = 0;
  174. props->max_pkeys = 0;
  175. props->local_ca_ack_delay = 0;
  176. bail2:
  177. vq_repbuf_free(c2dev, reply);
  178. bail1:
  179. vq_req_free(c2dev, vq_req);
  180. return err;
  181. }
  182. /*
  183. * Add an IP address to the RNIC interface
  184. */
  185. int c2_add_addr(struct c2_dev *c2dev, u32 inaddr, u32 inmask)
  186. {
  187. struct c2_vq_req *vq_req;
  188. struct c2wr_rnic_setconfig_req *wr;
  189. struct c2wr_rnic_setconfig_rep *reply;
  190. struct c2_netaddr netaddr;
  191. int err, len;
  192. vq_req = vq_req_alloc(c2dev);
  193. if (!vq_req)
  194. return -ENOMEM;
  195. len = sizeof(struct c2_netaddr);
  196. wr = kmalloc(c2dev->req_vq.msg_size, GFP_KERNEL);
  197. if (!wr) {
  198. err = -ENOMEM;
  199. goto bail0;
  200. }
  201. c2_wr_set_id(wr, CCWR_RNIC_SETCONFIG);
  202. wr->hdr.context = (unsigned long) vq_req;
  203. wr->rnic_handle = c2dev->adapter_handle;
  204. wr->option = cpu_to_be32(C2_CFG_ADD_ADDR);
  205. netaddr.ip_addr = inaddr;
  206. netaddr.netmask = inmask;
  207. netaddr.mtu = 0;
  208. memcpy(wr->data, &netaddr, len);
  209. vq_req_get(c2dev, vq_req);
  210. err = vq_send_wr(c2dev, (union c2wr *) wr);
  211. if (err) {
  212. vq_req_put(c2dev, vq_req);
  213. goto bail1;
  214. }
  215. err = vq_wait_for_reply(c2dev, vq_req);
  216. if (err)
  217. goto bail1;
  218. reply =
  219. (struct c2wr_rnic_setconfig_rep *) (unsigned long) (vq_req->reply_msg);
  220. if (!reply) {
  221. err = -ENOMEM;
  222. goto bail1;
  223. }
  224. err = c2_errno(reply);
  225. vq_repbuf_free(c2dev, reply);
  226. bail1:
  227. kfree(wr);
  228. bail0:
  229. vq_req_free(c2dev, vq_req);
  230. return err;
  231. }
  232. /*
  233. * Delete an IP address from the RNIC interface
  234. */
  235. int c2_del_addr(struct c2_dev *c2dev, u32 inaddr, u32 inmask)
  236. {
  237. struct c2_vq_req *vq_req;
  238. struct c2wr_rnic_setconfig_req *wr;
  239. struct c2wr_rnic_setconfig_rep *reply;
  240. struct c2_netaddr netaddr;
  241. int err, len;
  242. vq_req = vq_req_alloc(c2dev);
  243. if (!vq_req)
  244. return -ENOMEM;
  245. len = sizeof(struct c2_netaddr);
  246. wr = kmalloc(c2dev->req_vq.msg_size, GFP_KERNEL);
  247. if (!wr) {
  248. err = -ENOMEM;
  249. goto bail0;
  250. }
  251. c2_wr_set_id(wr, CCWR_RNIC_SETCONFIG);
  252. wr->hdr.context = (unsigned long) vq_req;
  253. wr->rnic_handle = c2dev->adapter_handle;
  254. wr->option = cpu_to_be32(C2_CFG_DEL_ADDR);
  255. netaddr.ip_addr = inaddr;
  256. netaddr.netmask = inmask;
  257. netaddr.mtu = 0;
  258. memcpy(wr->data, &netaddr, len);
  259. vq_req_get(c2dev, vq_req);
  260. err = vq_send_wr(c2dev, (union c2wr *) wr);
  261. if (err) {
  262. vq_req_put(c2dev, vq_req);
  263. goto bail1;
  264. }
  265. err = vq_wait_for_reply(c2dev, vq_req);
  266. if (err)
  267. goto bail1;
  268. reply =
  269. (struct c2wr_rnic_setconfig_rep *) (unsigned long) (vq_req->reply_msg);
  270. if (!reply) {
  271. err = -ENOMEM;
  272. goto bail1;
  273. }
  274. err = c2_errno(reply);
  275. vq_repbuf_free(c2dev, reply);
  276. bail1:
  277. kfree(wr);
  278. bail0:
  279. vq_req_free(c2dev, vq_req);
  280. return err;
  281. }
  282. /*
  283. * Open a single RNIC instance to use with all
  284. * low level openib calls
  285. */
  286. static int c2_rnic_open(struct c2_dev *c2dev)
  287. {
  288. struct c2_vq_req *vq_req;
  289. union c2wr wr;
  290. struct c2wr_rnic_open_rep *reply;
  291. int err;
  292. vq_req = vq_req_alloc(c2dev);
  293. if (vq_req == NULL) {
  294. return -ENOMEM;
  295. }
  296. memset(&wr, 0, sizeof(wr));
  297. c2_wr_set_id(&wr, CCWR_RNIC_OPEN);
  298. wr.rnic_open.req.hdr.context = (unsigned long) (vq_req);
  299. wr.rnic_open.req.flags = cpu_to_be16(RNIC_PRIV_MODE);
  300. wr.rnic_open.req.port_num = cpu_to_be16(0);
  301. wr.rnic_open.req.user_context = (unsigned long) c2dev;
  302. vq_req_get(c2dev, vq_req);
  303. err = vq_send_wr(c2dev, &wr);
  304. if (err) {
  305. vq_req_put(c2dev, vq_req);
  306. goto bail0;
  307. }
  308. err = vq_wait_for_reply(c2dev, vq_req);
  309. if (err) {
  310. goto bail0;
  311. }
  312. reply = (struct c2wr_rnic_open_rep *) (unsigned long) (vq_req->reply_msg);
  313. if (!reply) {
  314. err = -ENOMEM;
  315. goto bail0;
  316. }
  317. if ((err = c2_errno(reply)) != 0) {
  318. goto bail1;
  319. }
  320. c2dev->adapter_handle = reply->rnic_handle;
  321. bail1:
  322. vq_repbuf_free(c2dev, reply);
  323. bail0:
  324. vq_req_free(c2dev, vq_req);
  325. return err;
  326. }
  327. /*
  328. * Close the RNIC instance
  329. */
  330. static int c2_rnic_close(struct c2_dev *c2dev)
  331. {
  332. struct c2_vq_req *vq_req;
  333. union c2wr wr;
  334. struct c2wr_rnic_close_rep *reply;
  335. int err;
  336. vq_req = vq_req_alloc(c2dev);
  337. if (vq_req == NULL) {
  338. return -ENOMEM;
  339. }
  340. memset(&wr, 0, sizeof(wr));
  341. c2_wr_set_id(&wr, CCWR_RNIC_CLOSE);
  342. wr.rnic_close.req.hdr.context = (unsigned long) vq_req;
  343. wr.rnic_close.req.rnic_handle = c2dev->adapter_handle;
  344. vq_req_get(c2dev, vq_req);
  345. err = vq_send_wr(c2dev, &wr);
  346. if (err) {
  347. vq_req_put(c2dev, vq_req);
  348. goto bail0;
  349. }
  350. err = vq_wait_for_reply(c2dev, vq_req);
  351. if (err) {
  352. goto bail0;
  353. }
  354. reply = (struct c2wr_rnic_close_rep *) (unsigned long) (vq_req->reply_msg);
  355. if (!reply) {
  356. err = -ENOMEM;
  357. goto bail0;
  358. }
  359. if ((err = c2_errno(reply)) != 0) {
  360. goto bail1;
  361. }
  362. c2dev->adapter_handle = 0;
  363. bail1:
  364. vq_repbuf_free(c2dev, reply);
  365. bail0:
  366. vq_req_free(c2dev, vq_req);
  367. return err;
  368. }
  369. /*
  370. * Called by c2_probe to initialize the RNIC. This principally
  371. * involves initalizing the various limits and resouce pools that
  372. * comprise the RNIC instance.
  373. */
  374. int c2_rnic_init(struct c2_dev *c2dev)
  375. {
  376. int err;
  377. u32 qsize, msgsize;
  378. void *q1_pages;
  379. void *q2_pages;
  380. void __iomem *mmio_regs;
  381. /* Device capabilities */
  382. c2dev->device_cap_flags =
  383. (IB_DEVICE_RESIZE_MAX_WR |
  384. IB_DEVICE_CURR_QP_STATE_MOD |
  385. IB_DEVICE_SYS_IMAGE_GUID |
  386. IB_DEVICE_ZERO_STAG |
  387. IB_DEVICE_SEND_W_INV | IB_DEVICE_MEM_WINDOW);
  388. /* Allocate the qptr_array */
  389. c2dev->qptr_array = vmalloc(C2_MAX_CQS * sizeof(void *));
  390. if (!c2dev->qptr_array) {
  391. return -ENOMEM;
  392. }
  393. /* Inialize the qptr_array */
  394. memset(c2dev->qptr_array, 0, C2_MAX_CQS * sizeof(void *));
  395. c2dev->qptr_array[0] = (void *) &c2dev->req_vq;
  396. c2dev->qptr_array[1] = (void *) &c2dev->rep_vq;
  397. c2dev->qptr_array[2] = (void *) &c2dev->aeq;
  398. /* Initialize data structures */
  399. init_waitqueue_head(&c2dev->req_vq_wo);
  400. spin_lock_init(&c2dev->vqlock);
  401. spin_lock_init(&c2dev->lock);
  402. /* Allocate MQ shared pointer pool for kernel clients. User
  403. * mode client pools are hung off the user context
  404. */
  405. err = c2_init_mqsp_pool(c2dev, GFP_KERNEL, &c2dev->kern_mqsp_pool);
  406. if (err) {
  407. goto bail0;
  408. }
  409. /* Allocate shared pointers for Q0, Q1, and Q2 from
  410. * the shared pointer pool.
  411. */
  412. c2dev->hint_count = c2_alloc_mqsp(c2dev, c2dev->kern_mqsp_pool,
  413. &c2dev->hint_count_dma,
  414. GFP_KERNEL);
  415. c2dev->req_vq.shared = c2_alloc_mqsp(c2dev, c2dev->kern_mqsp_pool,
  416. &c2dev->req_vq.shared_dma,
  417. GFP_KERNEL);
  418. c2dev->rep_vq.shared = c2_alloc_mqsp(c2dev, c2dev->kern_mqsp_pool,
  419. &c2dev->rep_vq.shared_dma,
  420. GFP_KERNEL);
  421. c2dev->aeq.shared = c2_alloc_mqsp(c2dev, c2dev->kern_mqsp_pool,
  422. &c2dev->aeq.shared_dma, GFP_KERNEL);
  423. if (!c2dev->hint_count || !c2dev->req_vq.shared ||
  424. !c2dev->rep_vq.shared || !c2dev->aeq.shared) {
  425. err = -ENOMEM;
  426. goto bail1;
  427. }
  428. mmio_regs = c2dev->kva;
  429. /* Initialize the Verbs Request Queue */
  430. c2_mq_req_init(&c2dev->req_vq, 0,
  431. be32_to_cpu(readl(mmio_regs + C2_REGS_Q0_QSIZE)),
  432. be32_to_cpu(readl(mmio_regs + C2_REGS_Q0_MSGSIZE)),
  433. mmio_regs +
  434. be32_to_cpu(readl(mmio_regs + C2_REGS_Q0_POOLSTART)),
  435. mmio_regs +
  436. be32_to_cpu(readl(mmio_regs + C2_REGS_Q0_SHARED)),
  437. C2_MQ_ADAPTER_TARGET);
  438. /* Initialize the Verbs Reply Queue */
  439. qsize = be32_to_cpu(readl(mmio_regs + C2_REGS_Q1_QSIZE));
  440. msgsize = be32_to_cpu(readl(mmio_regs + C2_REGS_Q1_MSGSIZE));
  441. q1_pages = kmalloc(qsize * msgsize, GFP_KERNEL);
  442. if (!q1_pages) {
  443. err = -ENOMEM;
  444. goto bail1;
  445. }
  446. c2dev->rep_vq.host_dma = dma_map_single(c2dev->ibdev.dma_device,
  447. (void *)q1_pages, qsize * msgsize,
  448. DMA_FROM_DEVICE);
  449. pci_unmap_addr_set(&c2dev->rep_vq, mapping, c2dev->rep_vq.host_dma);
  450. pr_debug("%s rep_vq va %p dma %llx\n", __FUNCTION__, q1_pages,
  451. (unsigned long long) c2dev->rep_vq.host_dma);
  452. c2_mq_rep_init(&c2dev->rep_vq,
  453. 1,
  454. qsize,
  455. msgsize,
  456. q1_pages,
  457. mmio_regs +
  458. be32_to_cpu(readl(mmio_regs + C2_REGS_Q1_SHARED)),
  459. C2_MQ_HOST_TARGET);
  460. /* Initialize the Asynchronus Event Queue */
  461. qsize = be32_to_cpu(readl(mmio_regs + C2_REGS_Q2_QSIZE));
  462. msgsize = be32_to_cpu(readl(mmio_regs + C2_REGS_Q2_MSGSIZE));
  463. q2_pages = kmalloc(qsize * msgsize, GFP_KERNEL);
  464. if (!q2_pages) {
  465. err = -ENOMEM;
  466. goto bail2;
  467. }
  468. c2dev->aeq.host_dma = dma_map_single(c2dev->ibdev.dma_device,
  469. (void *)q2_pages, qsize * msgsize,
  470. DMA_FROM_DEVICE);
  471. pci_unmap_addr_set(&c2dev->aeq, mapping, c2dev->aeq.host_dma);
  472. pr_debug("%s aeq va %p dma %llx\n", __FUNCTION__, q1_pages,
  473. (unsigned long long) c2dev->rep_vq.host_dma);
  474. c2_mq_rep_init(&c2dev->aeq,
  475. 2,
  476. qsize,
  477. msgsize,
  478. q2_pages,
  479. mmio_regs +
  480. be32_to_cpu(readl(mmio_regs + C2_REGS_Q2_SHARED)),
  481. C2_MQ_HOST_TARGET);
  482. /* Initialize the verbs request allocator */
  483. err = vq_init(c2dev);
  484. if (err)
  485. goto bail3;
  486. /* Enable interrupts on the adapter */
  487. writel(0, c2dev->regs + C2_IDIS);
  488. /* create the WR init message */
  489. err = c2_adapter_init(c2dev);
  490. if (err)
  491. goto bail4;
  492. c2dev->init++;
  493. /* open an adapter instance */
  494. err = c2_rnic_open(c2dev);
  495. if (err)
  496. goto bail4;
  497. /* Initialize cached the adapter limits */
  498. if (c2_rnic_query(c2dev, &c2dev->props))
  499. goto bail5;
  500. /* Initialize the PD pool */
  501. err = c2_init_pd_table(c2dev);
  502. if (err)
  503. goto bail5;
  504. /* Initialize the QP pool */
  505. c2_init_qp_table(c2dev);
  506. return 0;
  507. bail5:
  508. c2_rnic_close(c2dev);
  509. bail4:
  510. vq_term(c2dev);
  511. bail3:
  512. dma_unmap_single(c2dev->ibdev.dma_device,
  513. pci_unmap_addr(&c2dev->aeq, mapping),
  514. c2dev->aeq.q_size * c2dev->aeq.msg_size,
  515. DMA_FROM_DEVICE);
  516. kfree(q2_pages);
  517. bail2:
  518. dma_unmap_single(c2dev->ibdev.dma_device,
  519. pci_unmap_addr(&c2dev->rep_vq, mapping),
  520. c2dev->rep_vq.q_size * c2dev->rep_vq.msg_size,
  521. DMA_FROM_DEVICE);
  522. kfree(q1_pages);
  523. bail1:
  524. c2_free_mqsp_pool(c2dev, c2dev->kern_mqsp_pool);
  525. bail0:
  526. vfree(c2dev->qptr_array);
  527. return err;
  528. }
  529. /*
  530. * Called by c2_remove to cleanup the RNIC resources.
  531. */
  532. void c2_rnic_term(struct c2_dev *c2dev)
  533. {
  534. /* Close the open adapter instance */
  535. c2_rnic_close(c2dev);
  536. /* Send the TERM message to the adapter */
  537. c2_adapter_term(c2dev);
  538. /* Disable interrupts on the adapter */
  539. writel(1, c2dev->regs + C2_IDIS);
  540. /* Free the QP pool */
  541. c2_cleanup_qp_table(c2dev);
  542. /* Free the PD pool */
  543. c2_cleanup_pd_table(c2dev);
  544. /* Free the verbs request allocator */
  545. vq_term(c2dev);
  546. /* Unmap and free the asynchronus event queue */
  547. dma_unmap_single(c2dev->ibdev.dma_device,
  548. pci_unmap_addr(&c2dev->aeq, mapping),
  549. c2dev->aeq.q_size * c2dev->aeq.msg_size,
  550. DMA_FROM_DEVICE);
  551. kfree(c2dev->aeq.msg_pool.host);
  552. /* Unmap and free the verbs reply queue */
  553. dma_unmap_single(c2dev->ibdev.dma_device,
  554. pci_unmap_addr(&c2dev->rep_vq, mapping),
  555. c2dev->rep_vq.q_size * c2dev->rep_vq.msg_size,
  556. DMA_FROM_DEVICE);
  557. kfree(c2dev->rep_vq.msg_pool.host);
  558. /* Free the MQ shared pointer pool */
  559. c2_free_mqsp_pool(c2dev, c2dev->kern_mqsp_pool);
  560. /* Free the qptr_array */
  561. vfree(c2dev->qptr_array);
  562. return;
  563. }