provider.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/device.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/etherdevice.h>
  37. #include <linux/delay.h>
  38. #include <linux/errno.h>
  39. #include <linux/list.h>
  40. #include <linux/spinlock.h>
  41. #include <linux/ethtool.h>
  42. #include <linux/rtnetlink.h>
  43. #include <linux/inetdevice.h>
  44. #include <linux/io.h>
  45. #include <asm/irq.h>
  46. #include <asm/byteorder.h>
  47. #include <rdma/iw_cm.h>
  48. #include <rdma/ib_verbs.h>
  49. #include <rdma/ib_smi.h>
  50. #include <rdma/ib_umem.h>
  51. #include <rdma/ib_user_verbs.h>
  52. #include "iw_cxgb4.h"
  53. static int fastreg_support = 1;
  54. module_param(fastreg_support, int, 0644);
  55. MODULE_PARM_DESC(fastreg_support, "Advertise fastreg support (default=1)");
  56. static struct ib_ah *c4iw_ah_create(struct ib_pd *pd,
  57. struct ib_ah_attr *ah_attr)
  58. {
  59. return ERR_PTR(-ENOSYS);
  60. }
  61. static int c4iw_ah_destroy(struct ib_ah *ah)
  62. {
  63. return -ENOSYS;
  64. }
  65. static int c4iw_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
  66. {
  67. return -ENOSYS;
  68. }
  69. static int c4iw_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
  70. {
  71. return -ENOSYS;
  72. }
  73. static int c4iw_process_mad(struct ib_device *ibdev, int mad_flags,
  74. u8 port_num, struct ib_wc *in_wc,
  75. struct ib_grh *in_grh, struct ib_mad *in_mad,
  76. struct ib_mad *out_mad)
  77. {
  78. return -ENOSYS;
  79. }
  80. static int c4iw_dealloc_ucontext(struct ib_ucontext *context)
  81. {
  82. struct c4iw_dev *rhp = to_c4iw_dev(context->device);
  83. struct c4iw_ucontext *ucontext = to_c4iw_ucontext(context);
  84. struct c4iw_mm_entry *mm, *tmp;
  85. PDBG("%s context %p\n", __func__, context);
  86. list_for_each_entry_safe(mm, tmp, &ucontext->mmaps, entry)
  87. kfree(mm);
  88. c4iw_release_dev_ucontext(&rhp->rdev, &ucontext->uctx);
  89. kfree(ucontext);
  90. return 0;
  91. }
  92. static struct ib_ucontext *c4iw_alloc_ucontext(struct ib_device *ibdev,
  93. struct ib_udata *udata)
  94. {
  95. struct c4iw_ucontext *context;
  96. struct c4iw_dev *rhp = to_c4iw_dev(ibdev);
  97. static int warned;
  98. struct c4iw_alloc_ucontext_resp uresp;
  99. int ret = 0;
  100. struct c4iw_mm_entry *mm = NULL;
  101. PDBG("%s ibdev %p\n", __func__, ibdev);
  102. context = kzalloc(sizeof(*context), GFP_KERNEL);
  103. if (!context) {
  104. ret = -ENOMEM;
  105. goto err;
  106. }
  107. c4iw_init_dev_ucontext(&rhp->rdev, &context->uctx);
  108. INIT_LIST_HEAD(&context->mmaps);
  109. spin_lock_init(&context->mmap_lock);
  110. if (udata->outlen < sizeof(uresp) - sizeof(uresp.reserved)) {
  111. if (!warned++)
  112. pr_err(MOD "Warning - downlevel libcxgb4 (non-fatal), device status page disabled.");
  113. rhp->rdev.flags |= T4_STATUS_PAGE_DISABLED;
  114. } else {
  115. mm = kmalloc(sizeof(*mm), GFP_KERNEL);
  116. if (!mm) {
  117. ret = -ENOMEM;
  118. goto err_free;
  119. }
  120. uresp.status_page_size = PAGE_SIZE;
  121. spin_lock(&context->mmap_lock);
  122. uresp.status_page_key = context->key;
  123. context->key += PAGE_SIZE;
  124. spin_unlock(&context->mmap_lock);
  125. ret = ib_copy_to_udata(udata, &uresp,
  126. sizeof(uresp) - sizeof(uresp.reserved));
  127. if (ret)
  128. goto err_mm;
  129. mm->key = uresp.status_page_key;
  130. mm->addr = virt_to_phys(rhp->rdev.status_page);
  131. mm->len = PAGE_SIZE;
  132. insert_mmap(context, mm);
  133. }
  134. return &context->ibucontext;
  135. err_mm:
  136. kfree(mm);
  137. err_free:
  138. kfree(context);
  139. err:
  140. return ERR_PTR(ret);
  141. }
  142. static int c4iw_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
  143. {
  144. int len = vma->vm_end - vma->vm_start;
  145. u32 key = vma->vm_pgoff << PAGE_SHIFT;
  146. struct c4iw_rdev *rdev;
  147. int ret = 0;
  148. struct c4iw_mm_entry *mm;
  149. struct c4iw_ucontext *ucontext;
  150. u64 addr;
  151. PDBG("%s pgoff 0x%lx key 0x%x len %d\n", __func__, vma->vm_pgoff,
  152. key, len);
  153. if (vma->vm_start & (PAGE_SIZE-1))
  154. return -EINVAL;
  155. rdev = &(to_c4iw_dev(context->device)->rdev);
  156. ucontext = to_c4iw_ucontext(context);
  157. mm = remove_mmap(ucontext, key, len);
  158. if (!mm)
  159. return -EINVAL;
  160. addr = mm->addr;
  161. kfree(mm);
  162. if ((addr >= pci_resource_start(rdev->lldi.pdev, 0)) &&
  163. (addr < (pci_resource_start(rdev->lldi.pdev, 0) +
  164. pci_resource_len(rdev->lldi.pdev, 0)))) {
  165. /*
  166. * MA_SYNC register...
  167. */
  168. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  169. ret = io_remap_pfn_range(vma, vma->vm_start,
  170. addr >> PAGE_SHIFT,
  171. len, vma->vm_page_prot);
  172. } else if ((addr >= pci_resource_start(rdev->lldi.pdev, 2)) &&
  173. (addr < (pci_resource_start(rdev->lldi.pdev, 2) +
  174. pci_resource_len(rdev->lldi.pdev, 2)))) {
  175. /*
  176. * Map user DB or OCQP memory...
  177. */
  178. if (addr >= rdev->oc_mw_pa)
  179. vma->vm_page_prot = t4_pgprot_wc(vma->vm_page_prot);
  180. else {
  181. if (is_t5(rdev->lldi.adapter_type))
  182. vma->vm_page_prot =
  183. t4_pgprot_wc(vma->vm_page_prot);
  184. else
  185. vma->vm_page_prot =
  186. pgprot_noncached(vma->vm_page_prot);
  187. }
  188. ret = io_remap_pfn_range(vma, vma->vm_start,
  189. addr >> PAGE_SHIFT,
  190. len, vma->vm_page_prot);
  191. } else {
  192. /*
  193. * Map WQ or CQ contig dma memory...
  194. */
  195. ret = remap_pfn_range(vma, vma->vm_start,
  196. addr >> PAGE_SHIFT,
  197. len, vma->vm_page_prot);
  198. }
  199. return ret;
  200. }
  201. static int c4iw_deallocate_pd(struct ib_pd *pd)
  202. {
  203. struct c4iw_dev *rhp;
  204. struct c4iw_pd *php;
  205. php = to_c4iw_pd(pd);
  206. rhp = php->rhp;
  207. PDBG("%s ibpd %p pdid 0x%x\n", __func__, pd, php->pdid);
  208. c4iw_put_resource(&rhp->rdev.resource.pdid_table, php->pdid);
  209. mutex_lock(&rhp->rdev.stats.lock);
  210. rhp->rdev.stats.pd.cur--;
  211. mutex_unlock(&rhp->rdev.stats.lock);
  212. kfree(php);
  213. return 0;
  214. }
  215. static struct ib_pd *c4iw_allocate_pd(struct ib_device *ibdev,
  216. struct ib_ucontext *context,
  217. struct ib_udata *udata)
  218. {
  219. struct c4iw_pd *php;
  220. u32 pdid;
  221. struct c4iw_dev *rhp;
  222. PDBG("%s ibdev %p\n", __func__, ibdev);
  223. rhp = (struct c4iw_dev *) ibdev;
  224. pdid = c4iw_get_resource(&rhp->rdev.resource.pdid_table);
  225. if (!pdid)
  226. return ERR_PTR(-EINVAL);
  227. php = kzalloc(sizeof(*php), GFP_KERNEL);
  228. if (!php) {
  229. c4iw_put_resource(&rhp->rdev.resource.pdid_table, pdid);
  230. return ERR_PTR(-ENOMEM);
  231. }
  232. php->pdid = pdid;
  233. php->rhp = rhp;
  234. if (context) {
  235. if (ib_copy_to_udata(udata, &php->pdid, sizeof(u32))) {
  236. c4iw_deallocate_pd(&php->ibpd);
  237. return ERR_PTR(-EFAULT);
  238. }
  239. }
  240. mutex_lock(&rhp->rdev.stats.lock);
  241. rhp->rdev.stats.pd.cur++;
  242. if (rhp->rdev.stats.pd.cur > rhp->rdev.stats.pd.max)
  243. rhp->rdev.stats.pd.max = rhp->rdev.stats.pd.cur;
  244. mutex_unlock(&rhp->rdev.stats.lock);
  245. PDBG("%s pdid 0x%0x ptr 0x%p\n", __func__, pdid, php);
  246. return &php->ibpd;
  247. }
  248. static int c4iw_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  249. u16 *pkey)
  250. {
  251. PDBG("%s ibdev %p\n", __func__, ibdev);
  252. *pkey = 0;
  253. return 0;
  254. }
  255. static int c4iw_query_gid(struct ib_device *ibdev, u8 port, int index,
  256. union ib_gid *gid)
  257. {
  258. struct c4iw_dev *dev;
  259. PDBG("%s ibdev %p, port %d, index %d, gid %p\n",
  260. __func__, ibdev, port, index, gid);
  261. dev = to_c4iw_dev(ibdev);
  262. BUG_ON(port == 0);
  263. memset(&(gid->raw[0]), 0, sizeof(gid->raw));
  264. memcpy(&(gid->raw[0]), dev->rdev.lldi.ports[port-1]->dev_addr, 6);
  265. return 0;
  266. }
  267. static int c4iw_query_device(struct ib_device *ibdev,
  268. struct ib_device_attr *props)
  269. {
  270. struct c4iw_dev *dev;
  271. PDBG("%s ibdev %p\n", __func__, ibdev);
  272. dev = to_c4iw_dev(ibdev);
  273. memset(props, 0, sizeof *props);
  274. memcpy(&props->sys_image_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
  275. props->hw_ver = CHELSIO_CHIP_RELEASE(dev->rdev.lldi.adapter_type);
  276. props->fw_ver = dev->rdev.lldi.fw_vers;
  277. props->device_cap_flags = dev->device_cap_flags;
  278. props->page_size_cap = T4_PAGESIZE_MASK;
  279. props->vendor_id = (u32)dev->rdev.lldi.pdev->vendor;
  280. props->vendor_part_id = (u32)dev->rdev.lldi.pdev->device;
  281. props->max_mr_size = T4_MAX_MR_SIZE;
  282. props->max_qp = T4_MAX_NUM_QP;
  283. props->max_qp_wr = T4_MAX_QP_DEPTH;
  284. props->max_sge = T4_MAX_RECV_SGE;
  285. props->max_sge_rd = 1;
  286. props->max_qp_rd_atom = c4iw_max_read_depth;
  287. props->max_qp_init_rd_atom = c4iw_max_read_depth;
  288. props->max_cq = T4_MAX_NUM_CQ;
  289. props->max_cqe = T4_MAX_CQ_DEPTH;
  290. props->max_mr = c4iw_num_stags(&dev->rdev);
  291. props->max_pd = T4_MAX_NUM_PD;
  292. props->local_ca_ack_delay = 0;
  293. props->max_fast_reg_page_list_len = t4_max_fr_depth(use_dsgl);
  294. return 0;
  295. }
  296. static int c4iw_query_port(struct ib_device *ibdev, u8 port,
  297. struct ib_port_attr *props)
  298. {
  299. struct c4iw_dev *dev;
  300. struct net_device *netdev;
  301. struct in_device *inetdev;
  302. PDBG("%s ibdev %p\n", __func__, ibdev);
  303. dev = to_c4iw_dev(ibdev);
  304. netdev = dev->rdev.lldi.ports[port-1];
  305. memset(props, 0, sizeof(struct ib_port_attr));
  306. props->max_mtu = IB_MTU_4096;
  307. if (netdev->mtu >= 4096)
  308. props->active_mtu = IB_MTU_4096;
  309. else if (netdev->mtu >= 2048)
  310. props->active_mtu = IB_MTU_2048;
  311. else if (netdev->mtu >= 1024)
  312. props->active_mtu = IB_MTU_1024;
  313. else if (netdev->mtu >= 512)
  314. props->active_mtu = IB_MTU_512;
  315. else
  316. props->active_mtu = IB_MTU_256;
  317. if (!netif_carrier_ok(netdev))
  318. props->state = IB_PORT_DOWN;
  319. else {
  320. inetdev = in_dev_get(netdev);
  321. if (inetdev) {
  322. if (inetdev->ifa_list)
  323. props->state = IB_PORT_ACTIVE;
  324. else
  325. props->state = IB_PORT_INIT;
  326. in_dev_put(inetdev);
  327. } else
  328. props->state = IB_PORT_INIT;
  329. }
  330. props->port_cap_flags =
  331. IB_PORT_CM_SUP |
  332. IB_PORT_SNMP_TUNNEL_SUP |
  333. IB_PORT_REINIT_SUP |
  334. IB_PORT_DEVICE_MGMT_SUP |
  335. IB_PORT_VENDOR_CLASS_SUP | IB_PORT_BOOT_MGMT_SUP;
  336. props->gid_tbl_len = 1;
  337. props->pkey_tbl_len = 1;
  338. props->active_width = 2;
  339. props->active_speed = IB_SPEED_DDR;
  340. props->max_msg_sz = -1;
  341. return 0;
  342. }
  343. static ssize_t show_rev(struct device *dev, struct device_attribute *attr,
  344. char *buf)
  345. {
  346. struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
  347. ibdev.dev);
  348. PDBG("%s dev 0x%p\n", __func__, dev);
  349. return sprintf(buf, "%d\n",
  350. CHELSIO_CHIP_RELEASE(c4iw_dev->rdev.lldi.adapter_type));
  351. }
  352. static ssize_t show_fw_ver(struct device *dev, struct device_attribute *attr,
  353. char *buf)
  354. {
  355. struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
  356. ibdev.dev);
  357. PDBG("%s dev 0x%p\n", __func__, dev);
  358. return sprintf(buf, "%u.%u.%u.%u\n",
  359. FW_HDR_FW_VER_MAJOR_GET(c4iw_dev->rdev.lldi.fw_vers),
  360. FW_HDR_FW_VER_MINOR_GET(c4iw_dev->rdev.lldi.fw_vers),
  361. FW_HDR_FW_VER_MICRO_GET(c4iw_dev->rdev.lldi.fw_vers),
  362. FW_HDR_FW_VER_BUILD_GET(c4iw_dev->rdev.lldi.fw_vers));
  363. }
  364. static ssize_t show_hca(struct device *dev, struct device_attribute *attr,
  365. char *buf)
  366. {
  367. struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
  368. ibdev.dev);
  369. struct ethtool_drvinfo info;
  370. struct net_device *lldev = c4iw_dev->rdev.lldi.ports[0];
  371. PDBG("%s dev 0x%p\n", __func__, dev);
  372. lldev->ethtool_ops->get_drvinfo(lldev, &info);
  373. return sprintf(buf, "%s\n", info.driver);
  374. }
  375. static ssize_t show_board(struct device *dev, struct device_attribute *attr,
  376. char *buf)
  377. {
  378. struct c4iw_dev *c4iw_dev = container_of(dev, struct c4iw_dev,
  379. ibdev.dev);
  380. PDBG("%s dev 0x%p\n", __func__, dev);
  381. return sprintf(buf, "%x.%x\n", c4iw_dev->rdev.lldi.pdev->vendor,
  382. c4iw_dev->rdev.lldi.pdev->device);
  383. }
  384. static int c4iw_get_mib(struct ib_device *ibdev,
  385. union rdma_protocol_stats *stats)
  386. {
  387. struct tp_tcp_stats v4, v6;
  388. struct c4iw_dev *c4iw_dev = to_c4iw_dev(ibdev);
  389. cxgb4_get_tcp_stats(c4iw_dev->rdev.lldi.pdev, &v4, &v6);
  390. memset(stats, 0, sizeof *stats);
  391. stats->iw.tcpInSegs = v4.tcpInSegs + v6.tcpInSegs;
  392. stats->iw.tcpOutSegs = v4.tcpOutSegs + v6.tcpOutSegs;
  393. stats->iw.tcpRetransSegs = v4.tcpRetransSegs + v6.tcpRetransSegs;
  394. stats->iw.tcpOutRsts = v4.tcpOutRsts + v6.tcpOutSegs;
  395. return 0;
  396. }
  397. static DEVICE_ATTR(hw_rev, S_IRUGO, show_rev, NULL);
  398. static DEVICE_ATTR(fw_ver, S_IRUGO, show_fw_ver, NULL);
  399. static DEVICE_ATTR(hca_type, S_IRUGO, show_hca, NULL);
  400. static DEVICE_ATTR(board_id, S_IRUGO, show_board, NULL);
  401. static struct device_attribute *c4iw_class_attributes[] = {
  402. &dev_attr_hw_rev,
  403. &dev_attr_fw_ver,
  404. &dev_attr_hca_type,
  405. &dev_attr_board_id,
  406. };
  407. int c4iw_register_device(struct c4iw_dev *dev)
  408. {
  409. int ret;
  410. int i;
  411. PDBG("%s c4iw_dev %p\n", __func__, dev);
  412. BUG_ON(!dev->rdev.lldi.ports[0]);
  413. strlcpy(dev->ibdev.name, "cxgb4_%d", IB_DEVICE_NAME_MAX);
  414. memset(&dev->ibdev.node_guid, 0, sizeof(dev->ibdev.node_guid));
  415. memcpy(&dev->ibdev.node_guid, dev->rdev.lldi.ports[0]->dev_addr, 6);
  416. dev->ibdev.owner = THIS_MODULE;
  417. dev->device_cap_flags = IB_DEVICE_LOCAL_DMA_LKEY | IB_DEVICE_MEM_WINDOW;
  418. if (fastreg_support)
  419. dev->device_cap_flags |= IB_DEVICE_MEM_MGT_EXTENSIONS;
  420. dev->ibdev.local_dma_lkey = 0;
  421. dev->ibdev.uverbs_cmd_mask =
  422. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  423. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  424. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  425. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  426. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  427. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  428. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  429. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  430. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  431. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  432. (1ull << IB_USER_VERBS_CMD_REQ_NOTIFY_CQ) |
  433. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  434. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  435. (1ull << IB_USER_VERBS_CMD_QUERY_QP) |
  436. (1ull << IB_USER_VERBS_CMD_POLL_CQ) |
  437. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  438. (1ull << IB_USER_VERBS_CMD_POST_SEND) |
  439. (1ull << IB_USER_VERBS_CMD_POST_RECV);
  440. dev->ibdev.node_type = RDMA_NODE_RNIC;
  441. memcpy(dev->ibdev.node_desc, C4IW_NODE_DESC, sizeof(C4IW_NODE_DESC));
  442. dev->ibdev.phys_port_cnt = dev->rdev.lldi.nports;
  443. dev->ibdev.num_comp_vectors = dev->rdev.lldi.nciq;
  444. dev->ibdev.dma_device = &(dev->rdev.lldi.pdev->dev);
  445. dev->ibdev.query_device = c4iw_query_device;
  446. dev->ibdev.query_port = c4iw_query_port;
  447. dev->ibdev.query_pkey = c4iw_query_pkey;
  448. dev->ibdev.query_gid = c4iw_query_gid;
  449. dev->ibdev.alloc_ucontext = c4iw_alloc_ucontext;
  450. dev->ibdev.dealloc_ucontext = c4iw_dealloc_ucontext;
  451. dev->ibdev.mmap = c4iw_mmap;
  452. dev->ibdev.alloc_pd = c4iw_allocate_pd;
  453. dev->ibdev.dealloc_pd = c4iw_deallocate_pd;
  454. dev->ibdev.create_ah = c4iw_ah_create;
  455. dev->ibdev.destroy_ah = c4iw_ah_destroy;
  456. dev->ibdev.create_qp = c4iw_create_qp;
  457. dev->ibdev.modify_qp = c4iw_ib_modify_qp;
  458. dev->ibdev.query_qp = c4iw_ib_query_qp;
  459. dev->ibdev.destroy_qp = c4iw_destroy_qp;
  460. dev->ibdev.create_cq = c4iw_create_cq;
  461. dev->ibdev.destroy_cq = c4iw_destroy_cq;
  462. dev->ibdev.resize_cq = c4iw_resize_cq;
  463. dev->ibdev.poll_cq = c4iw_poll_cq;
  464. dev->ibdev.get_dma_mr = c4iw_get_dma_mr;
  465. dev->ibdev.reg_phys_mr = c4iw_register_phys_mem;
  466. dev->ibdev.rereg_phys_mr = c4iw_reregister_phys_mem;
  467. dev->ibdev.reg_user_mr = c4iw_reg_user_mr;
  468. dev->ibdev.dereg_mr = c4iw_dereg_mr;
  469. dev->ibdev.alloc_mw = c4iw_alloc_mw;
  470. dev->ibdev.bind_mw = c4iw_bind_mw;
  471. dev->ibdev.dealloc_mw = c4iw_dealloc_mw;
  472. dev->ibdev.alloc_fast_reg_mr = c4iw_alloc_fast_reg_mr;
  473. dev->ibdev.alloc_fast_reg_page_list = c4iw_alloc_fastreg_pbl;
  474. dev->ibdev.free_fast_reg_page_list = c4iw_free_fastreg_pbl;
  475. dev->ibdev.attach_mcast = c4iw_multicast_attach;
  476. dev->ibdev.detach_mcast = c4iw_multicast_detach;
  477. dev->ibdev.process_mad = c4iw_process_mad;
  478. dev->ibdev.req_notify_cq = c4iw_arm_cq;
  479. dev->ibdev.post_send = c4iw_post_send;
  480. dev->ibdev.post_recv = c4iw_post_receive;
  481. dev->ibdev.get_protocol_stats = c4iw_get_mib;
  482. dev->ibdev.uverbs_abi_ver = C4IW_UVERBS_ABI_VERSION;
  483. dev->ibdev.iwcm = kmalloc(sizeof(struct iw_cm_verbs), GFP_KERNEL);
  484. if (!dev->ibdev.iwcm)
  485. return -ENOMEM;
  486. dev->ibdev.iwcm->connect = c4iw_connect;
  487. dev->ibdev.iwcm->accept = c4iw_accept_cr;
  488. dev->ibdev.iwcm->reject = c4iw_reject_cr;
  489. dev->ibdev.iwcm->create_listen = c4iw_create_listen;
  490. dev->ibdev.iwcm->destroy_listen = c4iw_destroy_listen;
  491. dev->ibdev.iwcm->add_ref = c4iw_qp_add_ref;
  492. dev->ibdev.iwcm->rem_ref = c4iw_qp_rem_ref;
  493. dev->ibdev.iwcm->get_qp = c4iw_get_qp;
  494. ret = ib_register_device(&dev->ibdev, NULL);
  495. if (ret)
  496. goto bail1;
  497. for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i) {
  498. ret = device_create_file(&dev->ibdev.dev,
  499. c4iw_class_attributes[i]);
  500. if (ret)
  501. goto bail2;
  502. }
  503. return 0;
  504. bail2:
  505. ib_unregister_device(&dev->ibdev);
  506. bail1:
  507. kfree(dev->ibdev.iwcm);
  508. return ret;
  509. }
  510. void c4iw_unregister_device(struct c4iw_dev *dev)
  511. {
  512. int i;
  513. PDBG("%s c4iw_dev %p\n", __func__, dev);
  514. for (i = 0; i < ARRAY_SIZE(c4iw_class_attributes); ++i)
  515. device_remove_file(&dev->ibdev.dev,
  516. c4iw_class_attributes[i]);
  517. ib_unregister_device(&dev->ibdev);
  518. kfree(dev->ibdev.iwcm);
  519. return;
  520. }