c2_rnic.c 16 KB

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