c2_rnic.c 16 KB

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