main.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. /*
  2. * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
  3. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  4. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  5. * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
  6. *
  7. * This software is available to you under a choice of one of two
  8. * licenses. You may choose to be licensed under the terms of the GNU
  9. * General Public License (GPL) Version 2, available from the file
  10. * COPYING in the main directory of this source tree, or the
  11. * OpenIB.org BSD license below:
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above
  18. * copyright notice, this list of conditions and the following
  19. * disclaimer.
  20. *
  21. * - Redistributions in binary form must reproduce the above
  22. * copyright notice, this list of conditions and the following
  23. * disclaimer in the documentation and/or other materials
  24. * provided with the distribution.
  25. *
  26. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  27. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  29. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  30. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  31. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  32. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  33. * SOFTWARE.
  34. */
  35. #include <linux/module.h>
  36. #include <linux/init.h>
  37. #include <linux/errno.h>
  38. #include <linux/pci.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/mlx4/device.h>
  41. #include <linux/mlx4/doorbell.h>
  42. #include "mlx4.h"
  43. #include "fw.h"
  44. #include "icm.h"
  45. MODULE_AUTHOR("Roland Dreier");
  46. MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
  47. MODULE_LICENSE("Dual BSD/GPL");
  48. MODULE_VERSION(DRV_VERSION);
  49. #ifdef CONFIG_MLX4_DEBUG
  50. int mlx4_debug_level = 0;
  51. module_param_named(debug_level, mlx4_debug_level, int, 0644);
  52. MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
  53. #endif /* CONFIG_MLX4_DEBUG */
  54. #ifdef CONFIG_PCI_MSI
  55. static int msi_x = 1;
  56. module_param(msi_x, int, 0444);
  57. MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
  58. #else /* CONFIG_PCI_MSI */
  59. #define msi_x (0)
  60. #endif /* CONFIG_PCI_MSI */
  61. static char mlx4_version[] __devinitdata =
  62. DRV_NAME ": Mellanox ConnectX core driver v"
  63. DRV_VERSION " (" DRV_RELDATE ")\n";
  64. static struct mlx4_profile default_profile = {
  65. .num_qp = 1 << 17,
  66. .num_srq = 1 << 16,
  67. .rdmarc_per_qp = 1 << 4,
  68. .num_cq = 1 << 16,
  69. .num_mcg = 1 << 13,
  70. .num_mpt = 1 << 17,
  71. .num_mtt = 1 << 20,
  72. };
  73. static int log_num_mac = 2;
  74. module_param_named(log_num_mac, log_num_mac, int, 0444);
  75. MODULE_PARM_DESC(log_num_mac, "Log2 max number of MACs per ETH port (1-7)");
  76. static int log_num_vlan;
  77. module_param_named(log_num_vlan, log_num_vlan, int, 0444);
  78. MODULE_PARM_DESC(log_num_vlan, "Log2 max number of VLANs per ETH port (0-7)");
  79. static int use_prio;
  80. module_param_named(use_prio, use_prio, bool, 0444);
  81. MODULE_PARM_DESC(use_prio, "Enable steering by VLAN priority on ETH ports "
  82. "(0/1, default 0)");
  83. static int mlx4_check_port_params(struct mlx4_dev *dev,
  84. enum mlx4_port_type *port_type)
  85. {
  86. int i;
  87. for (i = 0; i < dev->caps.num_ports - 1; i++) {
  88. if (port_type[i] != port_type[i+1] &&
  89. !(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) {
  90. mlx4_err(dev, "Only same port types supported "
  91. "on this HCA, aborting.\n");
  92. return -EINVAL;
  93. }
  94. }
  95. if ((port_type[0] == MLX4_PORT_TYPE_ETH) &&
  96. (port_type[1] == MLX4_PORT_TYPE_IB)) {
  97. mlx4_err(dev, "eth-ib configuration is not supported.\n");
  98. return -EINVAL;
  99. }
  100. for (i = 0; i < dev->caps.num_ports; i++) {
  101. if (!(port_type[i] & dev->caps.supported_type[i+1])) {
  102. mlx4_err(dev, "Requested port type for port %d is not "
  103. "supported on this HCA\n", i + 1);
  104. return -EINVAL;
  105. }
  106. }
  107. return 0;
  108. }
  109. static void mlx4_set_port_mask(struct mlx4_dev *dev)
  110. {
  111. int i;
  112. dev->caps.port_mask = 0;
  113. for (i = 1; i <= dev->caps.num_ports; ++i)
  114. if (dev->caps.port_type[i] == MLX4_PORT_TYPE_IB)
  115. dev->caps.port_mask |= 1 << (i - 1);
  116. }
  117. static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
  118. {
  119. int err;
  120. int i;
  121. err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
  122. if (err) {
  123. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  124. return err;
  125. }
  126. if (dev_cap->min_page_sz > PAGE_SIZE) {
  127. mlx4_err(dev, "HCA minimum page size of %d bigger than "
  128. "kernel PAGE_SIZE of %ld, aborting.\n",
  129. dev_cap->min_page_sz, PAGE_SIZE);
  130. return -ENODEV;
  131. }
  132. if (dev_cap->num_ports > MLX4_MAX_PORTS) {
  133. mlx4_err(dev, "HCA has %d ports, but we only support %d, "
  134. "aborting.\n",
  135. dev_cap->num_ports, MLX4_MAX_PORTS);
  136. return -ENODEV;
  137. }
  138. if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) {
  139. mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than "
  140. "PCI resource 2 size of 0x%llx, aborting.\n",
  141. dev_cap->uar_size,
  142. (unsigned long long) pci_resource_len(dev->pdev, 2));
  143. return -ENODEV;
  144. }
  145. dev->caps.num_ports = dev_cap->num_ports;
  146. for (i = 1; i <= dev->caps.num_ports; ++i) {
  147. dev->caps.vl_cap[i] = dev_cap->max_vl[i];
  148. dev->caps.ib_mtu_cap[i] = dev_cap->ib_mtu[i];
  149. dev->caps.gid_table_len[i] = dev_cap->max_gids[i];
  150. dev->caps.pkey_table_len[i] = dev_cap->max_pkeys[i];
  151. dev->caps.port_width_cap[i] = dev_cap->max_port_width[i];
  152. dev->caps.eth_mtu_cap[i] = dev_cap->eth_mtu[i];
  153. dev->caps.def_mac[i] = dev_cap->def_mac[i];
  154. dev->caps.supported_type[i] = dev_cap->supported_port_types[i];
  155. }
  156. dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
  157. dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
  158. dev->caps.bf_reg_size = dev_cap->bf_reg_size;
  159. dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
  160. dev->caps.max_sq_sg = dev_cap->max_sq_sg;
  161. dev->caps.max_rq_sg = dev_cap->max_rq_sg;
  162. dev->caps.max_wqes = dev_cap->max_qp_sz;
  163. dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
  164. dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
  165. dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
  166. dev->caps.reserved_srqs = dev_cap->reserved_srqs;
  167. dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
  168. dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
  169. dev->caps.num_qp_per_mgm = MLX4_QP_PER_MGM;
  170. /*
  171. * Subtract 1 from the limit because we need to allocate a
  172. * spare CQE so the HCA HW can tell the difference between an
  173. * empty CQ and a full CQ.
  174. */
  175. dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
  176. dev->caps.reserved_cqs = dev_cap->reserved_cqs;
  177. dev->caps.reserved_eqs = dev_cap->reserved_eqs;
  178. dev->caps.reserved_mtts = DIV_ROUND_UP(dev_cap->reserved_mtts,
  179. MLX4_MTT_ENTRY_PER_SEG);
  180. dev->caps.reserved_mrws = dev_cap->reserved_mrws;
  181. dev->caps.reserved_uars = dev_cap->reserved_uars;
  182. dev->caps.reserved_pds = dev_cap->reserved_pds;
  183. dev->caps.mtt_entry_sz = MLX4_MTT_ENTRY_PER_SEG * dev_cap->mtt_entry_sz;
  184. dev->caps.max_msg_sz = dev_cap->max_msg_sz;
  185. dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
  186. dev->caps.flags = dev_cap->flags;
  187. dev->caps.bmme_flags = dev_cap->bmme_flags;
  188. dev->caps.reserved_lkey = dev_cap->reserved_lkey;
  189. dev->caps.stat_rate_support = dev_cap->stat_rate_support;
  190. dev->caps.max_gso_sz = dev_cap->max_gso_sz;
  191. dev->caps.log_num_macs = log_num_mac;
  192. dev->caps.log_num_vlans = log_num_vlan;
  193. dev->caps.log_num_prios = use_prio ? 3 : 0;
  194. for (i = 1; i <= dev->caps.num_ports; ++i) {
  195. if (dev->caps.supported_type[i] != MLX4_PORT_TYPE_ETH)
  196. dev->caps.port_type[i] = MLX4_PORT_TYPE_IB;
  197. else
  198. dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH;
  199. if (dev->caps.log_num_macs > dev_cap->log_max_macs[i]) {
  200. dev->caps.log_num_macs = dev_cap->log_max_macs[i];
  201. mlx4_warn(dev, "Requested number of MACs is too much "
  202. "for port %d, reducing to %d.\n",
  203. i, 1 << dev->caps.log_num_macs);
  204. }
  205. if (dev->caps.log_num_vlans > dev_cap->log_max_vlans[i]) {
  206. dev->caps.log_num_vlans = dev_cap->log_max_vlans[i];
  207. mlx4_warn(dev, "Requested number of VLANs is too much "
  208. "for port %d, reducing to %d.\n",
  209. i, 1 << dev->caps.log_num_vlans);
  210. }
  211. }
  212. mlx4_set_port_mask(dev);
  213. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps;
  214. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] =
  215. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] =
  216. (1 << dev->caps.log_num_macs) *
  217. (1 << dev->caps.log_num_vlans) *
  218. (1 << dev->caps.log_num_prios) *
  219. dev->caps.num_ports;
  220. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH;
  221. dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] +
  222. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] +
  223. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] +
  224. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH];
  225. return 0;
  226. }
  227. /*
  228. * Change the port configuration of the device.
  229. * Every user of this function must hold the port mutex.
  230. */
  231. static int mlx4_change_port_types(struct mlx4_dev *dev,
  232. enum mlx4_port_type *port_types)
  233. {
  234. int err = 0;
  235. int change = 0;
  236. int port;
  237. for (port = 0; port < dev->caps.num_ports; port++) {
  238. if (port_types[port] != dev->caps.port_type[port + 1]) {
  239. change = 1;
  240. dev->caps.port_type[port + 1] = port_types[port];
  241. }
  242. }
  243. if (change) {
  244. mlx4_unregister_device(dev);
  245. for (port = 1; port <= dev->caps.num_ports; port++) {
  246. mlx4_CLOSE_PORT(dev, port);
  247. err = mlx4_SET_PORT(dev, port);
  248. if (err) {
  249. mlx4_err(dev, "Failed to set port %d, "
  250. "aborting\n", port);
  251. goto out;
  252. }
  253. }
  254. mlx4_set_port_mask(dev);
  255. err = mlx4_register_device(dev);
  256. }
  257. out:
  258. return err;
  259. }
  260. static ssize_t show_port_type(struct device *dev,
  261. struct device_attribute *attr,
  262. char *buf)
  263. {
  264. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  265. port_attr);
  266. struct mlx4_dev *mdev = info->dev;
  267. return sprintf(buf, "%s\n",
  268. mdev->caps.port_type[info->port] == MLX4_PORT_TYPE_IB ?
  269. "ib" : "eth");
  270. }
  271. static ssize_t set_port_type(struct device *dev,
  272. struct device_attribute *attr,
  273. const char *buf, size_t count)
  274. {
  275. struct mlx4_port_info *info = container_of(attr, struct mlx4_port_info,
  276. port_attr);
  277. struct mlx4_dev *mdev = info->dev;
  278. struct mlx4_priv *priv = mlx4_priv(mdev);
  279. enum mlx4_port_type types[MLX4_MAX_PORTS];
  280. int i;
  281. int err = 0;
  282. if (!strcmp(buf, "ib\n"))
  283. info->tmp_type = MLX4_PORT_TYPE_IB;
  284. else if (!strcmp(buf, "eth\n"))
  285. info->tmp_type = MLX4_PORT_TYPE_ETH;
  286. else {
  287. mlx4_err(mdev, "%s is not supported port type\n", buf);
  288. return -EINVAL;
  289. }
  290. mutex_lock(&priv->port_mutex);
  291. for (i = 0; i < mdev->caps.num_ports; i++)
  292. types[i] = priv->port[i+1].tmp_type ? priv->port[i+1].tmp_type :
  293. mdev->caps.port_type[i+1];
  294. err = mlx4_check_port_params(mdev, types);
  295. if (err)
  296. goto out;
  297. for (i = 1; i <= mdev->caps.num_ports; i++)
  298. priv->port[i].tmp_type = 0;
  299. err = mlx4_change_port_types(mdev, types);
  300. out:
  301. mutex_unlock(&priv->port_mutex);
  302. return err ? err : count;
  303. }
  304. static int mlx4_load_fw(struct mlx4_dev *dev)
  305. {
  306. struct mlx4_priv *priv = mlx4_priv(dev);
  307. int err;
  308. priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
  309. GFP_HIGHUSER | __GFP_NOWARN, 0);
  310. if (!priv->fw.fw_icm) {
  311. mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
  312. return -ENOMEM;
  313. }
  314. err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
  315. if (err) {
  316. mlx4_err(dev, "MAP_FA command failed, aborting.\n");
  317. goto err_free;
  318. }
  319. err = mlx4_RUN_FW(dev);
  320. if (err) {
  321. mlx4_err(dev, "RUN_FW command failed, aborting.\n");
  322. goto err_unmap_fa;
  323. }
  324. return 0;
  325. err_unmap_fa:
  326. mlx4_UNMAP_FA(dev);
  327. err_free:
  328. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  329. return err;
  330. }
  331. static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
  332. int cmpt_entry_sz)
  333. {
  334. struct mlx4_priv *priv = mlx4_priv(dev);
  335. int err;
  336. err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
  337. cmpt_base +
  338. ((u64) (MLX4_CMPT_TYPE_QP *
  339. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  340. cmpt_entry_sz, dev->caps.num_qps,
  341. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  342. 0, 0);
  343. if (err)
  344. goto err;
  345. err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
  346. cmpt_base +
  347. ((u64) (MLX4_CMPT_TYPE_SRQ *
  348. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  349. cmpt_entry_sz, dev->caps.num_srqs,
  350. dev->caps.reserved_srqs, 0, 0);
  351. if (err)
  352. goto err_qp;
  353. err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
  354. cmpt_base +
  355. ((u64) (MLX4_CMPT_TYPE_CQ *
  356. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  357. cmpt_entry_sz, dev->caps.num_cqs,
  358. dev->caps.reserved_cqs, 0, 0);
  359. if (err)
  360. goto err_srq;
  361. err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
  362. cmpt_base +
  363. ((u64) (MLX4_CMPT_TYPE_EQ *
  364. cmpt_entry_sz) << MLX4_CMPT_SHIFT),
  365. cmpt_entry_sz,
  366. dev->caps.num_eqs, dev->caps.num_eqs, 0, 0);
  367. if (err)
  368. goto err_cq;
  369. return 0;
  370. err_cq:
  371. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  372. err_srq:
  373. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  374. err_qp:
  375. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  376. err:
  377. return err;
  378. }
  379. static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
  380. struct mlx4_init_hca_param *init_hca, u64 icm_size)
  381. {
  382. struct mlx4_priv *priv = mlx4_priv(dev);
  383. u64 aux_pages;
  384. int err;
  385. err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
  386. if (err) {
  387. mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
  388. return err;
  389. }
  390. mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
  391. (unsigned long long) icm_size >> 10,
  392. (unsigned long long) aux_pages << 2);
  393. priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
  394. GFP_HIGHUSER | __GFP_NOWARN, 0);
  395. if (!priv->fw.aux_icm) {
  396. mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
  397. return -ENOMEM;
  398. }
  399. err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
  400. if (err) {
  401. mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
  402. goto err_free_aux;
  403. }
  404. err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
  405. if (err) {
  406. mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
  407. goto err_unmap_aux;
  408. }
  409. err = mlx4_map_eq_icm(dev, init_hca->eqc_base);
  410. if (err) {
  411. mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
  412. goto err_unmap_cmpt;
  413. }
  414. /*
  415. * Reserved MTT entries must be aligned up to a cacheline
  416. * boundary, since the FW will write to them, while the driver
  417. * writes to all other MTT entries. (The variable
  418. * dev->caps.mtt_entry_sz below is really the MTT segment
  419. * size, not the raw entry size)
  420. */
  421. dev->caps.reserved_mtts =
  422. ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz,
  423. dma_get_cache_alignment()) / dev->caps.mtt_entry_sz;
  424. err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
  425. init_hca->mtt_base,
  426. dev->caps.mtt_entry_sz,
  427. dev->caps.num_mtt_segs,
  428. dev->caps.reserved_mtts, 1, 0);
  429. if (err) {
  430. mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
  431. goto err_unmap_eq;
  432. }
  433. err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
  434. init_hca->dmpt_base,
  435. dev_cap->dmpt_entry_sz,
  436. dev->caps.num_mpts,
  437. dev->caps.reserved_mrws, 1, 1);
  438. if (err) {
  439. mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
  440. goto err_unmap_mtt;
  441. }
  442. err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
  443. init_hca->qpc_base,
  444. dev_cap->qpc_entry_sz,
  445. dev->caps.num_qps,
  446. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  447. 0, 0);
  448. if (err) {
  449. mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
  450. goto err_unmap_dmpt;
  451. }
  452. err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
  453. init_hca->auxc_base,
  454. dev_cap->aux_entry_sz,
  455. dev->caps.num_qps,
  456. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  457. 0, 0);
  458. if (err) {
  459. mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
  460. goto err_unmap_qp;
  461. }
  462. err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
  463. init_hca->altc_base,
  464. dev_cap->altc_entry_sz,
  465. dev->caps.num_qps,
  466. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  467. 0, 0);
  468. if (err) {
  469. mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
  470. goto err_unmap_auxc;
  471. }
  472. err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
  473. init_hca->rdmarc_base,
  474. dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
  475. dev->caps.num_qps,
  476. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  477. 0, 0);
  478. if (err) {
  479. mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
  480. goto err_unmap_altc;
  481. }
  482. err = mlx4_init_icm_table(dev, &priv->cq_table.table,
  483. init_hca->cqc_base,
  484. dev_cap->cqc_entry_sz,
  485. dev->caps.num_cqs,
  486. dev->caps.reserved_cqs, 0, 0);
  487. if (err) {
  488. mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
  489. goto err_unmap_rdmarc;
  490. }
  491. err = mlx4_init_icm_table(dev, &priv->srq_table.table,
  492. init_hca->srqc_base,
  493. dev_cap->srq_entry_sz,
  494. dev->caps.num_srqs,
  495. dev->caps.reserved_srqs, 0, 0);
  496. if (err) {
  497. mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
  498. goto err_unmap_cq;
  499. }
  500. /*
  501. * It's not strictly required, but for simplicity just map the
  502. * whole multicast group table now. The table isn't very big
  503. * and it's a lot easier than trying to track ref counts.
  504. */
  505. err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
  506. init_hca->mc_base, MLX4_MGM_ENTRY_SIZE,
  507. dev->caps.num_mgms + dev->caps.num_amgms,
  508. dev->caps.num_mgms + dev->caps.num_amgms,
  509. 0, 0);
  510. if (err) {
  511. mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
  512. goto err_unmap_srq;
  513. }
  514. return 0;
  515. err_unmap_srq:
  516. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  517. err_unmap_cq:
  518. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  519. err_unmap_rdmarc:
  520. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  521. err_unmap_altc:
  522. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  523. err_unmap_auxc:
  524. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  525. err_unmap_qp:
  526. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  527. err_unmap_dmpt:
  528. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  529. err_unmap_mtt:
  530. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  531. err_unmap_eq:
  532. mlx4_unmap_eq_icm(dev);
  533. err_unmap_cmpt:
  534. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  535. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  536. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  537. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  538. err_unmap_aux:
  539. mlx4_UNMAP_ICM_AUX(dev);
  540. err_free_aux:
  541. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  542. return err;
  543. }
  544. static void mlx4_free_icms(struct mlx4_dev *dev)
  545. {
  546. struct mlx4_priv *priv = mlx4_priv(dev);
  547. mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
  548. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  549. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  550. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  551. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  552. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  553. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  554. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  555. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  556. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  557. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  558. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  559. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  560. mlx4_unmap_eq_icm(dev);
  561. mlx4_UNMAP_ICM_AUX(dev);
  562. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  563. }
  564. static void mlx4_close_hca(struct mlx4_dev *dev)
  565. {
  566. mlx4_CLOSE_HCA(dev, 0);
  567. mlx4_free_icms(dev);
  568. mlx4_UNMAP_FA(dev);
  569. mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0);
  570. }
  571. static int mlx4_init_hca(struct mlx4_dev *dev)
  572. {
  573. struct mlx4_priv *priv = mlx4_priv(dev);
  574. struct mlx4_adapter adapter;
  575. struct mlx4_dev_cap dev_cap;
  576. struct mlx4_mod_stat_cfg mlx4_cfg;
  577. struct mlx4_profile profile;
  578. struct mlx4_init_hca_param init_hca;
  579. u64 icm_size;
  580. int err;
  581. err = mlx4_QUERY_FW(dev);
  582. if (err) {
  583. mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
  584. return err;
  585. }
  586. err = mlx4_load_fw(dev);
  587. if (err) {
  588. mlx4_err(dev, "Failed to start FW, aborting.\n");
  589. return err;
  590. }
  591. mlx4_cfg.log_pg_sz_m = 1;
  592. mlx4_cfg.log_pg_sz = 0;
  593. err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg);
  594. if (err)
  595. mlx4_warn(dev, "Failed to override log_pg_sz parameter\n");
  596. err = mlx4_dev_cap(dev, &dev_cap);
  597. if (err) {
  598. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  599. goto err_stop_fw;
  600. }
  601. profile = default_profile;
  602. icm_size = mlx4_make_profile(dev, &profile, &dev_cap, &init_hca);
  603. if ((long long) icm_size < 0) {
  604. err = icm_size;
  605. goto err_stop_fw;
  606. }
  607. init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
  608. err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
  609. if (err)
  610. goto err_stop_fw;
  611. err = mlx4_INIT_HCA(dev, &init_hca);
  612. if (err) {
  613. mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
  614. goto err_free_icm;
  615. }
  616. err = mlx4_QUERY_ADAPTER(dev, &adapter);
  617. if (err) {
  618. mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
  619. goto err_close;
  620. }
  621. priv->eq_table.inta_pin = adapter.inta_pin;
  622. memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
  623. return 0;
  624. err_close:
  625. mlx4_close_hca(dev);
  626. err_free_icm:
  627. mlx4_free_icms(dev);
  628. err_stop_fw:
  629. mlx4_UNMAP_FA(dev);
  630. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  631. return err;
  632. }
  633. static int mlx4_setup_hca(struct mlx4_dev *dev)
  634. {
  635. struct mlx4_priv *priv = mlx4_priv(dev);
  636. int err;
  637. int port;
  638. __be32 ib_port_default_caps;
  639. err = mlx4_init_uar_table(dev);
  640. if (err) {
  641. mlx4_err(dev, "Failed to initialize "
  642. "user access region table, aborting.\n");
  643. return err;
  644. }
  645. err = mlx4_uar_alloc(dev, &priv->driver_uar);
  646. if (err) {
  647. mlx4_err(dev, "Failed to allocate driver access region, "
  648. "aborting.\n");
  649. goto err_uar_table_free;
  650. }
  651. priv->kar = ioremap(priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
  652. if (!priv->kar) {
  653. mlx4_err(dev, "Couldn't map kernel access region, "
  654. "aborting.\n");
  655. err = -ENOMEM;
  656. goto err_uar_free;
  657. }
  658. err = mlx4_init_pd_table(dev);
  659. if (err) {
  660. mlx4_err(dev, "Failed to initialize "
  661. "protection domain table, aborting.\n");
  662. goto err_kar_unmap;
  663. }
  664. err = mlx4_init_mr_table(dev);
  665. if (err) {
  666. mlx4_err(dev, "Failed to initialize "
  667. "memory region table, aborting.\n");
  668. goto err_pd_table_free;
  669. }
  670. err = mlx4_init_eq_table(dev);
  671. if (err) {
  672. mlx4_err(dev, "Failed to initialize "
  673. "event queue table, aborting.\n");
  674. goto err_mr_table_free;
  675. }
  676. err = mlx4_cmd_use_events(dev);
  677. if (err) {
  678. mlx4_err(dev, "Failed to switch to event-driven "
  679. "firmware commands, aborting.\n");
  680. goto err_eq_table_free;
  681. }
  682. err = mlx4_NOP(dev);
  683. if (err) {
  684. if (dev->flags & MLX4_FLAG_MSI_X) {
  685. mlx4_warn(dev, "NOP command failed to generate MSI-X "
  686. "interrupt IRQ %d).\n",
  687. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  688. mlx4_warn(dev, "Trying again without MSI-X.\n");
  689. } else {
  690. mlx4_err(dev, "NOP command failed to generate interrupt "
  691. "(IRQ %d), aborting.\n",
  692. priv->eq_table.eq[dev->caps.num_comp_vectors].irq);
  693. mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
  694. }
  695. goto err_cmd_poll;
  696. }
  697. mlx4_dbg(dev, "NOP command IRQ test passed\n");
  698. err = mlx4_init_cq_table(dev);
  699. if (err) {
  700. mlx4_err(dev, "Failed to initialize "
  701. "completion queue table, aborting.\n");
  702. goto err_cmd_poll;
  703. }
  704. err = mlx4_init_srq_table(dev);
  705. if (err) {
  706. mlx4_err(dev, "Failed to initialize "
  707. "shared receive queue table, aborting.\n");
  708. goto err_cq_table_free;
  709. }
  710. err = mlx4_init_qp_table(dev);
  711. if (err) {
  712. mlx4_err(dev, "Failed to initialize "
  713. "queue pair table, aborting.\n");
  714. goto err_srq_table_free;
  715. }
  716. err = mlx4_init_mcg_table(dev);
  717. if (err) {
  718. mlx4_err(dev, "Failed to initialize "
  719. "multicast group table, aborting.\n");
  720. goto err_qp_table_free;
  721. }
  722. for (port = 1; port <= dev->caps.num_ports; port++) {
  723. ib_port_default_caps = 0;
  724. err = mlx4_get_port_ib_caps(dev, port, &ib_port_default_caps);
  725. if (err)
  726. mlx4_warn(dev, "failed to get port %d default "
  727. "ib capabilities (%d). Continuing with "
  728. "caps = 0\n", port, err);
  729. dev->caps.ib_port_def_cap[port] = ib_port_default_caps;
  730. err = mlx4_SET_PORT(dev, port);
  731. if (err) {
  732. mlx4_err(dev, "Failed to set port %d, aborting\n",
  733. port);
  734. goto err_mcg_table_free;
  735. }
  736. }
  737. return 0;
  738. err_mcg_table_free:
  739. mlx4_cleanup_mcg_table(dev);
  740. err_qp_table_free:
  741. mlx4_cleanup_qp_table(dev);
  742. err_srq_table_free:
  743. mlx4_cleanup_srq_table(dev);
  744. err_cq_table_free:
  745. mlx4_cleanup_cq_table(dev);
  746. err_cmd_poll:
  747. mlx4_cmd_use_polling(dev);
  748. err_eq_table_free:
  749. mlx4_cleanup_eq_table(dev);
  750. err_mr_table_free:
  751. mlx4_cleanup_mr_table(dev);
  752. err_pd_table_free:
  753. mlx4_cleanup_pd_table(dev);
  754. err_kar_unmap:
  755. iounmap(priv->kar);
  756. err_uar_free:
  757. mlx4_uar_free(dev, &priv->driver_uar);
  758. err_uar_table_free:
  759. mlx4_cleanup_uar_table(dev);
  760. return err;
  761. }
  762. static void mlx4_enable_msi_x(struct mlx4_dev *dev)
  763. {
  764. struct mlx4_priv *priv = mlx4_priv(dev);
  765. struct msix_entry *entries;
  766. int nreq;
  767. int err;
  768. int i;
  769. if (msi_x) {
  770. nreq = min(dev->caps.num_eqs - dev->caps.reserved_eqs,
  771. num_possible_cpus() + 1);
  772. entries = kcalloc(nreq, sizeof *entries, GFP_KERNEL);
  773. if (!entries)
  774. goto no_msi;
  775. for (i = 0; i < nreq; ++i)
  776. entries[i].entry = i;
  777. retry:
  778. err = pci_enable_msix(dev->pdev, entries, nreq);
  779. if (err) {
  780. /* Try again if at least 2 vectors are available */
  781. if (err > 1) {
  782. mlx4_info(dev, "Requested %d vectors, "
  783. "but only %d MSI-X vectors available, "
  784. "trying again\n", nreq, err);
  785. nreq = err;
  786. goto retry;
  787. }
  788. goto no_msi;
  789. }
  790. dev->caps.num_comp_vectors = nreq - 1;
  791. for (i = 0; i < nreq; ++i)
  792. priv->eq_table.eq[i].irq = entries[i].vector;
  793. dev->flags |= MLX4_FLAG_MSI_X;
  794. kfree(entries);
  795. return;
  796. }
  797. no_msi:
  798. dev->caps.num_comp_vectors = 1;
  799. for (i = 0; i < 2; ++i)
  800. priv->eq_table.eq[i].irq = dev->pdev->irq;
  801. }
  802. static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  803. {
  804. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  805. int err = 0;
  806. info->dev = dev;
  807. info->port = port;
  808. mlx4_init_mac_table(dev, &info->mac_table);
  809. mlx4_init_vlan_table(dev, &info->vlan_table);
  810. sprintf(info->dev_name, "mlx4_port%d", port);
  811. info->port_attr.attr.name = info->dev_name;
  812. info->port_attr.attr.mode = S_IRUGO | S_IWUSR;
  813. info->port_attr.show = show_port_type;
  814. info->port_attr.store = set_port_type;
  815. err = device_create_file(&dev->pdev->dev, &info->port_attr);
  816. if (err) {
  817. mlx4_err(dev, "Failed to create file for port %d\n", port);
  818. info->port = -1;
  819. }
  820. return err;
  821. }
  822. static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
  823. {
  824. if (info->port < 0)
  825. return;
  826. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  827. }
  828. static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  829. {
  830. struct mlx4_priv *priv;
  831. struct mlx4_dev *dev;
  832. int err;
  833. int port;
  834. printk(KERN_INFO PFX "Initializing %s\n",
  835. pci_name(pdev));
  836. err = pci_enable_device(pdev);
  837. if (err) {
  838. dev_err(&pdev->dev, "Cannot enable PCI device, "
  839. "aborting.\n");
  840. return err;
  841. }
  842. /*
  843. * Check for BARs. We expect 0: 1MB
  844. */
  845. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
  846. pci_resource_len(pdev, 0) != 1 << 20) {
  847. dev_err(&pdev->dev, "Missing DCS, aborting.\n");
  848. err = -ENODEV;
  849. goto err_disable_pdev;
  850. }
  851. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  852. dev_err(&pdev->dev, "Missing UAR, aborting.\n");
  853. err = -ENODEV;
  854. goto err_disable_pdev;
  855. }
  856. err = pci_request_region(pdev, 0, DRV_NAME);
  857. if (err) {
  858. dev_err(&pdev->dev, "Cannot request control region, aborting.\n");
  859. goto err_disable_pdev;
  860. }
  861. err = pci_request_region(pdev, 2, DRV_NAME);
  862. if (err) {
  863. dev_err(&pdev->dev, "Cannot request UAR region, aborting.\n");
  864. goto err_release_bar0;
  865. }
  866. pci_set_master(pdev);
  867. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  868. if (err) {
  869. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
  870. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  871. if (err) {
  872. dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
  873. goto err_release_bar2;
  874. }
  875. }
  876. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  877. if (err) {
  878. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
  879. "consistent PCI DMA mask.\n");
  880. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  881. if (err) {
  882. dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
  883. "aborting.\n");
  884. goto err_release_bar2;
  885. }
  886. }
  887. priv = kzalloc(sizeof *priv, GFP_KERNEL);
  888. if (!priv) {
  889. dev_err(&pdev->dev, "Device struct alloc failed, "
  890. "aborting.\n");
  891. err = -ENOMEM;
  892. goto err_release_bar2;
  893. }
  894. dev = &priv->dev;
  895. dev->pdev = pdev;
  896. INIT_LIST_HEAD(&priv->ctx_list);
  897. spin_lock_init(&priv->ctx_lock);
  898. mutex_init(&priv->port_mutex);
  899. INIT_LIST_HEAD(&priv->pgdir_list);
  900. mutex_init(&priv->pgdir_mutex);
  901. /*
  902. * Now reset the HCA before we touch the PCI capabilities or
  903. * attempt a firmware command, since a boot ROM may have left
  904. * the HCA in an undefined state.
  905. */
  906. err = mlx4_reset(dev);
  907. if (err) {
  908. mlx4_err(dev, "Failed to reset HCA, aborting.\n");
  909. goto err_free_dev;
  910. }
  911. if (mlx4_cmd_init(dev)) {
  912. mlx4_err(dev, "Failed to init command interface, aborting.\n");
  913. goto err_free_dev;
  914. }
  915. err = mlx4_init_hca(dev);
  916. if (err)
  917. goto err_cmd;
  918. err = mlx4_alloc_eq_table(dev);
  919. if (err)
  920. goto err_close;
  921. mlx4_enable_msi_x(dev);
  922. err = mlx4_setup_hca(dev);
  923. if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X)) {
  924. dev->flags &= ~MLX4_FLAG_MSI_X;
  925. pci_disable_msix(pdev);
  926. err = mlx4_setup_hca(dev);
  927. }
  928. if (err)
  929. goto err_free_eq;
  930. for (port = 1; port <= dev->caps.num_ports; port++) {
  931. err = mlx4_init_port_info(dev, port);
  932. if (err)
  933. goto err_port;
  934. }
  935. err = mlx4_register_device(dev);
  936. if (err)
  937. goto err_port;
  938. pci_set_drvdata(pdev, dev);
  939. return 0;
  940. err_port:
  941. for (port = 1; port <= dev->caps.num_ports; port++)
  942. mlx4_cleanup_port_info(&priv->port[port]);
  943. mlx4_cleanup_mcg_table(dev);
  944. mlx4_cleanup_qp_table(dev);
  945. mlx4_cleanup_srq_table(dev);
  946. mlx4_cleanup_cq_table(dev);
  947. mlx4_cmd_use_polling(dev);
  948. mlx4_cleanup_eq_table(dev);
  949. mlx4_cleanup_mr_table(dev);
  950. mlx4_cleanup_pd_table(dev);
  951. mlx4_cleanup_uar_table(dev);
  952. err_free_eq:
  953. mlx4_free_eq_table(dev);
  954. err_close:
  955. if (dev->flags & MLX4_FLAG_MSI_X)
  956. pci_disable_msix(pdev);
  957. mlx4_close_hca(dev);
  958. err_cmd:
  959. mlx4_cmd_cleanup(dev);
  960. err_free_dev:
  961. kfree(priv);
  962. err_release_bar2:
  963. pci_release_region(pdev, 2);
  964. err_release_bar0:
  965. pci_release_region(pdev, 0);
  966. err_disable_pdev:
  967. pci_disable_device(pdev);
  968. pci_set_drvdata(pdev, NULL);
  969. return err;
  970. }
  971. static int __devinit mlx4_init_one(struct pci_dev *pdev,
  972. const struct pci_device_id *id)
  973. {
  974. static int mlx4_version_printed;
  975. if (!mlx4_version_printed) {
  976. printk(KERN_INFO "%s", mlx4_version);
  977. ++mlx4_version_printed;
  978. }
  979. return __mlx4_init_one(pdev, id);
  980. }
  981. static void mlx4_remove_one(struct pci_dev *pdev)
  982. {
  983. struct mlx4_dev *dev = pci_get_drvdata(pdev);
  984. struct mlx4_priv *priv = mlx4_priv(dev);
  985. int p;
  986. if (dev) {
  987. mlx4_unregister_device(dev);
  988. for (p = 1; p <= dev->caps.num_ports; p++) {
  989. mlx4_cleanup_port_info(&priv->port[p]);
  990. mlx4_CLOSE_PORT(dev, p);
  991. }
  992. mlx4_cleanup_mcg_table(dev);
  993. mlx4_cleanup_qp_table(dev);
  994. mlx4_cleanup_srq_table(dev);
  995. mlx4_cleanup_cq_table(dev);
  996. mlx4_cmd_use_polling(dev);
  997. mlx4_cleanup_eq_table(dev);
  998. mlx4_cleanup_mr_table(dev);
  999. mlx4_cleanup_pd_table(dev);
  1000. iounmap(priv->kar);
  1001. mlx4_uar_free(dev, &priv->driver_uar);
  1002. mlx4_cleanup_uar_table(dev);
  1003. mlx4_free_eq_table(dev);
  1004. mlx4_close_hca(dev);
  1005. mlx4_cmd_cleanup(dev);
  1006. if (dev->flags & MLX4_FLAG_MSI_X)
  1007. pci_disable_msix(pdev);
  1008. kfree(priv);
  1009. pci_release_region(pdev, 2);
  1010. pci_release_region(pdev, 0);
  1011. pci_disable_device(pdev);
  1012. pci_set_drvdata(pdev, NULL);
  1013. }
  1014. }
  1015. int mlx4_restart_one(struct pci_dev *pdev)
  1016. {
  1017. mlx4_remove_one(pdev);
  1018. return __mlx4_init_one(pdev, NULL);
  1019. }
  1020. static struct pci_device_id mlx4_pci_table[] = {
  1021. { PCI_VDEVICE(MELLANOX, 0x6340) }, /* MT25408 "Hermon" SDR */
  1022. { PCI_VDEVICE(MELLANOX, 0x634a) }, /* MT25408 "Hermon" DDR */
  1023. { PCI_VDEVICE(MELLANOX, 0x6354) }, /* MT25408 "Hermon" QDR */
  1024. { PCI_VDEVICE(MELLANOX, 0x6732) }, /* MT25408 "Hermon" DDR PCIe gen2 */
  1025. { PCI_VDEVICE(MELLANOX, 0x673c) }, /* MT25408 "Hermon" QDR PCIe gen2 */
  1026. { PCI_VDEVICE(MELLANOX, 0x6368) }, /* MT25408 "Hermon" EN 10GigE */
  1027. { PCI_VDEVICE(MELLANOX, 0x6750) }, /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
  1028. { 0, }
  1029. };
  1030. MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
  1031. static struct pci_driver mlx4_driver = {
  1032. .name = DRV_NAME,
  1033. .id_table = mlx4_pci_table,
  1034. .probe = mlx4_init_one,
  1035. .remove = __devexit_p(mlx4_remove_one)
  1036. };
  1037. static int __init mlx4_verify_params(void)
  1038. {
  1039. if ((log_num_mac < 0) || (log_num_mac > 7)) {
  1040. printk(KERN_WARNING "mlx4_core: bad num_mac: %d\n", log_num_mac);
  1041. return -1;
  1042. }
  1043. if ((log_num_vlan < 0) || (log_num_vlan > 7)) {
  1044. printk(KERN_WARNING "mlx4_core: bad num_vlan: %d\n", log_num_vlan);
  1045. return -1;
  1046. }
  1047. return 0;
  1048. }
  1049. static int __init mlx4_init(void)
  1050. {
  1051. int ret;
  1052. if (mlx4_verify_params())
  1053. return -EINVAL;
  1054. ret = mlx4_catas_init();
  1055. if (ret)
  1056. return ret;
  1057. ret = pci_register_driver(&mlx4_driver);
  1058. return ret < 0 ? ret : 0;
  1059. }
  1060. static void __exit mlx4_cleanup(void)
  1061. {
  1062. pci_unregister_driver(&mlx4_driver);
  1063. mlx4_catas_cleanup();
  1064. }
  1065. module_init(mlx4_init);
  1066. module_exit(mlx4_cleanup);