main.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Copyright (c) 2006, 2007 Cisco Systems, 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/init.h>
  34. #include <linux/errno.h>
  35. #include <rdma/ib_smi.h>
  36. #include <rdma/ib_user_verbs.h>
  37. #include <linux/mlx4/driver.h>
  38. #include <linux/mlx4/cmd.h>
  39. #include "mlx4_ib.h"
  40. #include "user.h"
  41. #define DRV_NAME "mlx4_ib"
  42. #define DRV_VERSION "0.01"
  43. #define DRV_RELDATE "May 1, 2006"
  44. MODULE_AUTHOR("Roland Dreier");
  45. MODULE_DESCRIPTION("Mellanox ConnectX HCA InfiniBand driver");
  46. MODULE_LICENSE("Dual BSD/GPL");
  47. MODULE_VERSION(DRV_VERSION);
  48. static const char mlx4_ib_version[] __devinitdata =
  49. DRV_NAME ": Mellanox ConnectX InfiniBand driver v"
  50. DRV_VERSION " (" DRV_RELDATE ")\n";
  51. static void init_query_mad(struct ib_smp *mad)
  52. {
  53. mad->base_version = 1;
  54. mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
  55. mad->class_version = 1;
  56. mad->method = IB_MGMT_METHOD_GET;
  57. }
  58. static int mlx4_ib_query_device(struct ib_device *ibdev,
  59. struct ib_device_attr *props)
  60. {
  61. struct mlx4_ib_dev *dev = to_mdev(ibdev);
  62. struct ib_smp *in_mad = NULL;
  63. struct ib_smp *out_mad = NULL;
  64. int err = -ENOMEM;
  65. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  66. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  67. if (!in_mad || !out_mad)
  68. goto out;
  69. init_query_mad(in_mad);
  70. in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
  71. err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, 1, NULL, NULL, in_mad, out_mad);
  72. if (err)
  73. goto out;
  74. memset(props, 0, sizeof *props);
  75. props->fw_ver = dev->dev->caps.fw_ver;
  76. props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
  77. IB_DEVICE_PORT_ACTIVE_EVENT |
  78. IB_DEVICE_SYS_IMAGE_GUID |
  79. IB_DEVICE_RC_RNR_NAK_GEN;
  80. if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR)
  81. props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
  82. if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR)
  83. props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
  84. if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_APM)
  85. props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
  86. if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UD_AV_PORT)
  87. props->device_cap_flags |= IB_DEVICE_UD_AV_PORT_ENFORCE;
  88. props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) &
  89. 0xffffff;
  90. props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30));
  91. props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32));
  92. memcpy(&props->sys_image_guid, out_mad->data + 4, 8);
  93. props->max_mr_size = ~0ull;
  94. props->page_size_cap = dev->dev->caps.page_size_cap;
  95. props->max_qp = dev->dev->caps.num_qps - dev->dev->caps.reserved_qps;
  96. props->max_qp_wr = dev->dev->caps.max_wqes;
  97. props->max_sge = min(dev->dev->caps.max_sq_sg,
  98. dev->dev->caps.max_rq_sg);
  99. props->max_cq = dev->dev->caps.num_cqs - dev->dev->caps.reserved_cqs;
  100. props->max_cqe = dev->dev->caps.max_cqes;
  101. props->max_mr = dev->dev->caps.num_mpts - dev->dev->caps.reserved_mrws;
  102. props->max_pd = dev->dev->caps.num_pds - dev->dev->caps.reserved_pds;
  103. props->max_qp_rd_atom = dev->dev->caps.max_qp_dest_rdma;
  104. props->max_qp_init_rd_atom = dev->dev->caps.max_qp_init_rdma;
  105. props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
  106. props->max_srq = dev->dev->caps.num_srqs - dev->dev->caps.reserved_srqs;
  107. props->max_srq_wr = dev->dev->caps.max_srq_wqes;
  108. props->max_srq_sge = dev->dev->caps.max_srq_sge;
  109. props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay;
  110. props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ?
  111. IB_ATOMIC_HCA : IB_ATOMIC_NONE;
  112. props->max_pkeys = dev->dev->caps.pkey_table_len;
  113. props->max_mcast_grp = dev->dev->caps.num_mgms + dev->dev->caps.num_amgms;
  114. props->max_mcast_qp_attach = dev->dev->caps.num_qp_per_mgm;
  115. props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
  116. props->max_mcast_grp;
  117. props->max_map_per_fmr = (1 << (32 - ilog2(dev->dev->caps.num_mpts))) - 1;
  118. out:
  119. kfree(in_mad);
  120. kfree(out_mad);
  121. return err;
  122. }
  123. static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
  124. struct ib_port_attr *props)
  125. {
  126. struct ib_smp *in_mad = NULL;
  127. struct ib_smp *out_mad = NULL;
  128. int err = -ENOMEM;
  129. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  130. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  131. if (!in_mad || !out_mad)
  132. goto out;
  133. memset(props, 0, sizeof *props);
  134. init_query_mad(in_mad);
  135. in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
  136. in_mad->attr_mod = cpu_to_be32(port);
  137. err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
  138. if (err)
  139. goto out;
  140. props->lid = be16_to_cpup((__be16 *) (out_mad->data + 16));
  141. props->lmc = out_mad->data[34] & 0x7;
  142. props->sm_lid = be16_to_cpup((__be16 *) (out_mad->data + 18));
  143. props->sm_sl = out_mad->data[36] & 0xf;
  144. props->state = out_mad->data[32] & 0xf;
  145. props->phys_state = out_mad->data[33] >> 4;
  146. props->port_cap_flags = be32_to_cpup((__be32 *) (out_mad->data + 20));
  147. props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len;
  148. props->max_msg_sz = 0x80000000;
  149. props->pkey_tbl_len = to_mdev(ibdev)->dev->caps.pkey_table_len;
  150. props->bad_pkey_cntr = be16_to_cpup((__be16 *) (out_mad->data + 46));
  151. props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48));
  152. props->active_width = out_mad->data[31] & 0xf;
  153. props->active_speed = out_mad->data[35] >> 4;
  154. props->max_mtu = out_mad->data[41] & 0xf;
  155. props->active_mtu = out_mad->data[36] >> 4;
  156. props->subnet_timeout = out_mad->data[51] & 0x1f;
  157. props->max_vl_num = out_mad->data[37] >> 4;
  158. props->init_type_reply = out_mad->data[41] >> 4;
  159. out:
  160. kfree(in_mad);
  161. kfree(out_mad);
  162. return err;
  163. }
  164. static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
  165. union ib_gid *gid)
  166. {
  167. struct ib_smp *in_mad = NULL;
  168. struct ib_smp *out_mad = NULL;
  169. int err = -ENOMEM;
  170. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  171. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  172. if (!in_mad || !out_mad)
  173. goto out;
  174. init_query_mad(in_mad);
  175. in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
  176. in_mad->attr_mod = cpu_to_be32(port);
  177. err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
  178. if (err)
  179. goto out;
  180. memcpy(gid->raw, out_mad->data + 8, 8);
  181. init_query_mad(in_mad);
  182. in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
  183. in_mad->attr_mod = cpu_to_be32(index / 8);
  184. err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
  185. if (err)
  186. goto out;
  187. memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8);
  188. out:
  189. kfree(in_mad);
  190. kfree(out_mad);
  191. return err;
  192. }
  193. static int mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
  194. u16 *pkey)
  195. {
  196. struct ib_smp *in_mad = NULL;
  197. struct ib_smp *out_mad = NULL;
  198. int err = -ENOMEM;
  199. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  200. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  201. if (!in_mad || !out_mad)
  202. goto out;
  203. init_query_mad(in_mad);
  204. in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
  205. in_mad->attr_mod = cpu_to_be32(index / 32);
  206. err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
  207. if (err)
  208. goto out;
  209. *pkey = be16_to_cpu(((__be16 *) out_mad->data)[index % 32]);
  210. out:
  211. kfree(in_mad);
  212. kfree(out_mad);
  213. return err;
  214. }
  215. static int mlx4_ib_modify_device(struct ib_device *ibdev, int mask,
  216. struct ib_device_modify *props)
  217. {
  218. if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
  219. return -EOPNOTSUPP;
  220. if (mask & IB_DEVICE_MODIFY_NODE_DESC) {
  221. spin_lock(&to_mdev(ibdev)->sm_lock);
  222. memcpy(ibdev->node_desc, props->node_desc, 64);
  223. spin_unlock(&to_mdev(ibdev)->sm_lock);
  224. }
  225. return 0;
  226. }
  227. static int mlx4_SET_PORT(struct mlx4_ib_dev *dev, u8 port, int reset_qkey_viols,
  228. u32 cap_mask)
  229. {
  230. struct mlx4_cmd_mailbox *mailbox;
  231. int err;
  232. mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
  233. if (IS_ERR(mailbox))
  234. return PTR_ERR(mailbox);
  235. memset(mailbox->buf, 0, 256);
  236. *(u8 *) mailbox->buf = !!reset_qkey_viols << 6;
  237. ((__be32 *) mailbox->buf)[2] = cpu_to_be32(cap_mask);
  238. err = mlx4_cmd(dev->dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT,
  239. MLX4_CMD_TIME_CLASS_B);
  240. mlx4_free_cmd_mailbox(dev->dev, mailbox);
  241. return err;
  242. }
  243. static int mlx4_ib_modify_port(struct ib_device *ibdev, u8 port, int mask,
  244. struct ib_port_modify *props)
  245. {
  246. struct ib_port_attr attr;
  247. u32 cap_mask;
  248. int err;
  249. mutex_lock(&to_mdev(ibdev)->cap_mask_mutex);
  250. err = mlx4_ib_query_port(ibdev, port, &attr);
  251. if (err)
  252. goto out;
  253. cap_mask = (attr.port_cap_flags | props->set_port_cap_mask) &
  254. ~props->clr_port_cap_mask;
  255. err = mlx4_SET_PORT(to_mdev(ibdev), port,
  256. !!(mask & IB_PORT_RESET_QKEY_CNTR),
  257. cap_mask);
  258. out:
  259. mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex);
  260. return err;
  261. }
  262. static struct ib_ucontext *mlx4_ib_alloc_ucontext(struct ib_device *ibdev,
  263. struct ib_udata *udata)
  264. {
  265. struct mlx4_ib_dev *dev = to_mdev(ibdev);
  266. struct mlx4_ib_ucontext *context;
  267. struct mlx4_ib_alloc_ucontext_resp resp;
  268. int err;
  269. resp.qp_tab_size = dev->dev->caps.num_qps;
  270. resp.bf_reg_size = dev->dev->caps.bf_reg_size;
  271. resp.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
  272. context = kmalloc(sizeof *context, GFP_KERNEL);
  273. if (!context)
  274. return ERR_PTR(-ENOMEM);
  275. err = mlx4_uar_alloc(to_mdev(ibdev)->dev, &context->uar);
  276. if (err) {
  277. kfree(context);
  278. return ERR_PTR(err);
  279. }
  280. INIT_LIST_HEAD(&context->db_page_list);
  281. mutex_init(&context->db_page_mutex);
  282. err = ib_copy_to_udata(udata, &resp, sizeof resp);
  283. if (err) {
  284. mlx4_uar_free(to_mdev(ibdev)->dev, &context->uar);
  285. kfree(context);
  286. return ERR_PTR(-EFAULT);
  287. }
  288. return &context->ibucontext;
  289. }
  290. static int mlx4_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
  291. {
  292. struct mlx4_ib_ucontext *context = to_mucontext(ibcontext);
  293. mlx4_uar_free(to_mdev(ibcontext->device)->dev, &context->uar);
  294. kfree(context);
  295. return 0;
  296. }
  297. static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
  298. {
  299. struct mlx4_ib_dev *dev = to_mdev(context->device);
  300. if (vma->vm_end - vma->vm_start != PAGE_SIZE)
  301. return -EINVAL;
  302. if (vma->vm_pgoff == 0) {
  303. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  304. if (io_remap_pfn_range(vma, vma->vm_start,
  305. to_mucontext(context)->uar.pfn,
  306. PAGE_SIZE, vma->vm_page_prot))
  307. return -EAGAIN;
  308. } else if (vma->vm_pgoff == 1 && dev->dev->caps.bf_reg_size != 0) {
  309. /* FIXME want pgprot_writecombine() for BlueFlame pages */
  310. vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  311. if (io_remap_pfn_range(vma, vma->vm_start,
  312. to_mucontext(context)->uar.pfn +
  313. dev->dev->caps.num_uars,
  314. PAGE_SIZE, vma->vm_page_prot))
  315. return -EAGAIN;
  316. } else
  317. return -EINVAL;
  318. return 0;
  319. }
  320. static struct ib_pd *mlx4_ib_alloc_pd(struct ib_device *ibdev,
  321. struct ib_ucontext *context,
  322. struct ib_udata *udata)
  323. {
  324. struct mlx4_ib_pd *pd;
  325. int err;
  326. pd = kmalloc(sizeof *pd, GFP_KERNEL);
  327. if (!pd)
  328. return ERR_PTR(-ENOMEM);
  329. err = mlx4_pd_alloc(to_mdev(ibdev)->dev, &pd->pdn);
  330. if (err) {
  331. kfree(pd);
  332. return ERR_PTR(err);
  333. }
  334. if (context)
  335. if (ib_copy_to_udata(udata, &pd->pdn, sizeof (__u32))) {
  336. mlx4_pd_free(to_mdev(ibdev)->dev, pd->pdn);
  337. kfree(pd);
  338. return ERR_PTR(-EFAULT);
  339. }
  340. return &pd->ibpd;
  341. }
  342. static int mlx4_ib_dealloc_pd(struct ib_pd *pd)
  343. {
  344. mlx4_pd_free(to_mdev(pd->device)->dev, to_mpd(pd)->pdn);
  345. kfree(pd);
  346. return 0;
  347. }
  348. static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
  349. {
  350. return mlx4_multicast_attach(to_mdev(ibqp->device)->dev,
  351. &to_mqp(ibqp)->mqp, gid->raw);
  352. }
  353. static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
  354. {
  355. return mlx4_multicast_detach(to_mdev(ibqp->device)->dev,
  356. &to_mqp(ibqp)->mqp, gid->raw);
  357. }
  358. static int init_node_data(struct mlx4_ib_dev *dev)
  359. {
  360. struct ib_smp *in_mad = NULL;
  361. struct ib_smp *out_mad = NULL;
  362. int err = -ENOMEM;
  363. in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
  364. out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
  365. if (!in_mad || !out_mad)
  366. goto out;
  367. init_query_mad(in_mad);
  368. in_mad->attr_id = IB_SMP_ATTR_NODE_DESC;
  369. err = mlx4_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
  370. if (err)
  371. goto out;
  372. memcpy(dev->ib_dev.node_desc, out_mad->data, 64);
  373. in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
  374. err = mlx4_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
  375. if (err)
  376. goto out;
  377. memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
  378. out:
  379. kfree(in_mad);
  380. kfree(out_mad);
  381. return err;
  382. }
  383. static void *mlx4_ib_add(struct mlx4_dev *dev)
  384. {
  385. struct mlx4_ib_dev *ibdev;
  386. ibdev = (struct mlx4_ib_dev *) ib_alloc_device(sizeof *ibdev);
  387. if (!ibdev) {
  388. dev_err(&dev->pdev->dev, "Device struct alloc failed\n");
  389. return NULL;
  390. }
  391. if (mlx4_pd_alloc(dev, &ibdev->priv_pdn))
  392. goto err_dealloc;
  393. if (mlx4_uar_alloc(dev, &ibdev->priv_uar))
  394. goto err_pd;
  395. ibdev->uar_map = ioremap(ibdev->priv_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
  396. if (!ibdev->uar_map)
  397. goto err_uar;
  398. MLX4_INIT_DOORBELL_LOCK(&ibdev->uar_lock);
  399. INIT_LIST_HEAD(&ibdev->pgdir_list);
  400. mutex_init(&ibdev->pgdir_mutex);
  401. ibdev->dev = dev;
  402. strlcpy(ibdev->ib_dev.name, "mlx4_%d", IB_DEVICE_NAME_MAX);
  403. ibdev->ib_dev.owner = THIS_MODULE;
  404. ibdev->ib_dev.node_type = RDMA_NODE_IB_CA;
  405. ibdev->ib_dev.phys_port_cnt = dev->caps.num_ports;
  406. ibdev->ib_dev.num_comp_vectors = 1;
  407. ibdev->ib_dev.dma_device = &dev->pdev->dev;
  408. ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION;
  409. ibdev->ib_dev.uverbs_cmd_mask =
  410. (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
  411. (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
  412. (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
  413. (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
  414. (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
  415. (1ull << IB_USER_VERBS_CMD_REG_MR) |
  416. (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
  417. (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
  418. (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
  419. (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
  420. (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
  421. (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
  422. (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
  423. (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
  424. (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
  425. (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
  426. (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
  427. (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
  428. ibdev->ib_dev.query_device = mlx4_ib_query_device;
  429. ibdev->ib_dev.query_port = mlx4_ib_query_port;
  430. ibdev->ib_dev.query_gid = mlx4_ib_query_gid;
  431. ibdev->ib_dev.query_pkey = mlx4_ib_query_pkey;
  432. ibdev->ib_dev.modify_device = mlx4_ib_modify_device;
  433. ibdev->ib_dev.modify_port = mlx4_ib_modify_port;
  434. ibdev->ib_dev.alloc_ucontext = mlx4_ib_alloc_ucontext;
  435. ibdev->ib_dev.dealloc_ucontext = mlx4_ib_dealloc_ucontext;
  436. ibdev->ib_dev.mmap = mlx4_ib_mmap;
  437. ibdev->ib_dev.alloc_pd = mlx4_ib_alloc_pd;
  438. ibdev->ib_dev.dealloc_pd = mlx4_ib_dealloc_pd;
  439. ibdev->ib_dev.create_ah = mlx4_ib_create_ah;
  440. ibdev->ib_dev.query_ah = mlx4_ib_query_ah;
  441. ibdev->ib_dev.destroy_ah = mlx4_ib_destroy_ah;
  442. ibdev->ib_dev.create_srq = mlx4_ib_create_srq;
  443. ibdev->ib_dev.modify_srq = mlx4_ib_modify_srq;
  444. ibdev->ib_dev.destroy_srq = mlx4_ib_destroy_srq;
  445. ibdev->ib_dev.post_srq_recv = mlx4_ib_post_srq_recv;
  446. ibdev->ib_dev.create_qp = mlx4_ib_create_qp;
  447. ibdev->ib_dev.modify_qp = mlx4_ib_modify_qp;
  448. ibdev->ib_dev.destroy_qp = mlx4_ib_destroy_qp;
  449. ibdev->ib_dev.post_send = mlx4_ib_post_send;
  450. ibdev->ib_dev.post_recv = mlx4_ib_post_recv;
  451. ibdev->ib_dev.create_cq = mlx4_ib_create_cq;
  452. ibdev->ib_dev.destroy_cq = mlx4_ib_destroy_cq;
  453. ibdev->ib_dev.poll_cq = mlx4_ib_poll_cq;
  454. ibdev->ib_dev.req_notify_cq = mlx4_ib_arm_cq;
  455. ibdev->ib_dev.get_dma_mr = mlx4_ib_get_dma_mr;
  456. ibdev->ib_dev.reg_user_mr = mlx4_ib_reg_user_mr;
  457. ibdev->ib_dev.dereg_mr = mlx4_ib_dereg_mr;
  458. ibdev->ib_dev.attach_mcast = mlx4_ib_mcg_attach;
  459. ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach;
  460. ibdev->ib_dev.process_mad = mlx4_ib_process_mad;
  461. if (init_node_data(ibdev))
  462. goto err_map;
  463. spin_lock_init(&ibdev->sm_lock);
  464. mutex_init(&ibdev->cap_mask_mutex);
  465. if (ib_register_device(&ibdev->ib_dev))
  466. goto err_map;
  467. if (mlx4_ib_mad_init(ibdev))
  468. goto err_reg;
  469. return ibdev;
  470. err_reg:
  471. ib_unregister_device(&ibdev->ib_dev);
  472. err_map:
  473. iounmap(ibdev->uar_map);
  474. err_uar:
  475. mlx4_uar_free(dev, &ibdev->priv_uar);
  476. err_pd:
  477. mlx4_pd_free(dev, ibdev->priv_pdn);
  478. err_dealloc:
  479. ib_dealloc_device(&ibdev->ib_dev);
  480. return NULL;
  481. }
  482. static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
  483. {
  484. struct mlx4_ib_dev *ibdev = ibdev_ptr;
  485. int p;
  486. for (p = 1; p <= dev->caps.num_ports; ++p)
  487. mlx4_CLOSE_PORT(dev, p);
  488. mlx4_ib_mad_cleanup(ibdev);
  489. ib_unregister_device(&ibdev->ib_dev);
  490. iounmap(ibdev->uar_map);
  491. mlx4_uar_free(dev, &ibdev->priv_uar);
  492. mlx4_pd_free(dev, ibdev->priv_pdn);
  493. ib_dealloc_device(&ibdev->ib_dev);
  494. }
  495. static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
  496. enum mlx4_dev_event event, int subtype,
  497. int port)
  498. {
  499. struct ib_event ibev;
  500. switch (event) {
  501. case MLX4_EVENT_TYPE_PORT_CHANGE:
  502. ibev.event = subtype == MLX4_PORT_CHANGE_SUBTYPE_ACTIVE ?
  503. IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
  504. break;
  505. case MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR:
  506. ibev.event = IB_EVENT_DEVICE_FATAL;
  507. break;
  508. default:
  509. return;
  510. }
  511. ibev.device = ibdev_ptr;
  512. ibev.element.port_num = port;
  513. ib_dispatch_event(&ibev);
  514. }
  515. static struct mlx4_interface mlx4_ib_interface = {
  516. .add = mlx4_ib_add,
  517. .remove = mlx4_ib_remove,
  518. .event = mlx4_ib_event
  519. };
  520. static int __init mlx4_ib_init(void)
  521. {
  522. return mlx4_register_interface(&mlx4_ib_interface);
  523. }
  524. static void __exit mlx4_ib_cleanup(void)
  525. {
  526. mlx4_unregister_interface(&mlx4_ib_interface);
  527. }
  528. module_init(mlx4_ib_init);
  529. module_exit(mlx4_ib_cleanup);