main.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249
  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. roundup_pow_of_two(MLX4_NUM_EQ +
  367. dev->caps.reserved_eqs),
  368. MLX4_NUM_EQ + dev->caps.reserved_eqs, 0, 0);
  369. if (err)
  370. goto err_cq;
  371. return 0;
  372. err_cq:
  373. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  374. err_srq:
  375. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  376. err_qp:
  377. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  378. err:
  379. return err;
  380. }
  381. static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap,
  382. struct mlx4_init_hca_param *init_hca, u64 icm_size)
  383. {
  384. struct mlx4_priv *priv = mlx4_priv(dev);
  385. u64 aux_pages;
  386. int err;
  387. err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
  388. if (err) {
  389. mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
  390. return err;
  391. }
  392. mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
  393. (unsigned long long) icm_size >> 10,
  394. (unsigned long long) aux_pages << 2);
  395. priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
  396. GFP_HIGHUSER | __GFP_NOWARN, 0);
  397. if (!priv->fw.aux_icm) {
  398. mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
  399. return -ENOMEM;
  400. }
  401. err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
  402. if (err) {
  403. mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
  404. goto err_free_aux;
  405. }
  406. err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
  407. if (err) {
  408. mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
  409. goto err_unmap_aux;
  410. }
  411. err = mlx4_map_eq_icm(dev, init_hca->eqc_base);
  412. if (err) {
  413. mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
  414. goto err_unmap_cmpt;
  415. }
  416. /*
  417. * Reserved MTT entries must be aligned up to a cacheline
  418. * boundary, since the FW will write to them, while the driver
  419. * writes to all other MTT entries. (The variable
  420. * dev->caps.mtt_entry_sz below is really the MTT segment
  421. * size, not the raw entry size)
  422. */
  423. dev->caps.reserved_mtts =
  424. ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz,
  425. dma_get_cache_alignment()) / dev->caps.mtt_entry_sz;
  426. err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
  427. init_hca->mtt_base,
  428. dev->caps.mtt_entry_sz,
  429. dev->caps.num_mtt_segs,
  430. dev->caps.reserved_mtts, 1, 0);
  431. if (err) {
  432. mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
  433. goto err_unmap_eq;
  434. }
  435. err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
  436. init_hca->dmpt_base,
  437. dev_cap->dmpt_entry_sz,
  438. dev->caps.num_mpts,
  439. dev->caps.reserved_mrws, 1, 1);
  440. if (err) {
  441. mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
  442. goto err_unmap_mtt;
  443. }
  444. err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
  445. init_hca->qpc_base,
  446. dev_cap->qpc_entry_sz,
  447. dev->caps.num_qps,
  448. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  449. 0, 0);
  450. if (err) {
  451. mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
  452. goto err_unmap_dmpt;
  453. }
  454. err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
  455. init_hca->auxc_base,
  456. dev_cap->aux_entry_sz,
  457. dev->caps.num_qps,
  458. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  459. 0, 0);
  460. if (err) {
  461. mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
  462. goto err_unmap_qp;
  463. }
  464. err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
  465. init_hca->altc_base,
  466. dev_cap->altc_entry_sz,
  467. dev->caps.num_qps,
  468. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  469. 0, 0);
  470. if (err) {
  471. mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
  472. goto err_unmap_auxc;
  473. }
  474. err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
  475. init_hca->rdmarc_base,
  476. dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
  477. dev->caps.num_qps,
  478. dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW],
  479. 0, 0);
  480. if (err) {
  481. mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
  482. goto err_unmap_altc;
  483. }
  484. err = mlx4_init_icm_table(dev, &priv->cq_table.table,
  485. init_hca->cqc_base,
  486. dev_cap->cqc_entry_sz,
  487. dev->caps.num_cqs,
  488. dev->caps.reserved_cqs, 0, 0);
  489. if (err) {
  490. mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
  491. goto err_unmap_rdmarc;
  492. }
  493. err = mlx4_init_icm_table(dev, &priv->srq_table.table,
  494. init_hca->srqc_base,
  495. dev_cap->srq_entry_sz,
  496. dev->caps.num_srqs,
  497. dev->caps.reserved_srqs, 0, 0);
  498. if (err) {
  499. mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
  500. goto err_unmap_cq;
  501. }
  502. /*
  503. * It's not strictly required, but for simplicity just map the
  504. * whole multicast group table now. The table isn't very big
  505. * and it's a lot easier than trying to track ref counts.
  506. */
  507. err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
  508. init_hca->mc_base, MLX4_MGM_ENTRY_SIZE,
  509. dev->caps.num_mgms + dev->caps.num_amgms,
  510. dev->caps.num_mgms + dev->caps.num_amgms,
  511. 0, 0);
  512. if (err) {
  513. mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
  514. goto err_unmap_srq;
  515. }
  516. return 0;
  517. err_unmap_srq:
  518. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  519. err_unmap_cq:
  520. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  521. err_unmap_rdmarc:
  522. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  523. err_unmap_altc:
  524. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  525. err_unmap_auxc:
  526. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  527. err_unmap_qp:
  528. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  529. err_unmap_dmpt:
  530. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  531. err_unmap_mtt:
  532. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  533. err_unmap_eq:
  534. mlx4_unmap_eq_icm(dev);
  535. err_unmap_cmpt:
  536. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  537. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  538. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  539. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  540. err_unmap_aux:
  541. mlx4_UNMAP_ICM_AUX(dev);
  542. err_free_aux:
  543. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  544. return err;
  545. }
  546. static void mlx4_free_icms(struct mlx4_dev *dev)
  547. {
  548. struct mlx4_priv *priv = mlx4_priv(dev);
  549. mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
  550. mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
  551. mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
  552. mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
  553. mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
  554. mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
  555. mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
  556. mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
  557. mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
  558. mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
  559. mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
  560. mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
  561. mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
  562. mlx4_unmap_eq_icm(dev);
  563. mlx4_UNMAP_ICM_AUX(dev);
  564. mlx4_free_icm(dev, priv->fw.aux_icm, 0);
  565. }
  566. static void mlx4_close_hca(struct mlx4_dev *dev)
  567. {
  568. mlx4_CLOSE_HCA(dev, 0);
  569. mlx4_free_icms(dev);
  570. mlx4_UNMAP_FA(dev);
  571. mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0);
  572. }
  573. static int mlx4_init_hca(struct mlx4_dev *dev)
  574. {
  575. struct mlx4_priv *priv = mlx4_priv(dev);
  576. struct mlx4_adapter adapter;
  577. struct mlx4_dev_cap dev_cap;
  578. struct mlx4_mod_stat_cfg mlx4_cfg;
  579. struct mlx4_profile profile;
  580. struct mlx4_init_hca_param init_hca;
  581. u64 icm_size;
  582. int err;
  583. err = mlx4_QUERY_FW(dev);
  584. if (err) {
  585. mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
  586. return err;
  587. }
  588. err = mlx4_load_fw(dev);
  589. if (err) {
  590. mlx4_err(dev, "Failed to start FW, aborting.\n");
  591. return err;
  592. }
  593. mlx4_cfg.log_pg_sz_m = 1;
  594. mlx4_cfg.log_pg_sz = 0;
  595. err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg);
  596. if (err)
  597. mlx4_warn(dev, "Failed to override log_pg_sz parameter\n");
  598. err = mlx4_dev_cap(dev, &dev_cap);
  599. if (err) {
  600. mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
  601. goto err_stop_fw;
  602. }
  603. profile = default_profile;
  604. icm_size = mlx4_make_profile(dev, &profile, &dev_cap, &init_hca);
  605. if ((long long) icm_size < 0) {
  606. err = icm_size;
  607. goto err_stop_fw;
  608. }
  609. init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
  610. err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
  611. if (err)
  612. goto err_stop_fw;
  613. err = mlx4_INIT_HCA(dev, &init_hca);
  614. if (err) {
  615. mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
  616. goto err_free_icm;
  617. }
  618. err = mlx4_QUERY_ADAPTER(dev, &adapter);
  619. if (err) {
  620. mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
  621. goto err_close;
  622. }
  623. priv->eq_table.inta_pin = adapter.inta_pin;
  624. memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id);
  625. return 0;
  626. err_close:
  627. mlx4_close_hca(dev);
  628. err_free_icm:
  629. mlx4_free_icms(dev);
  630. err_stop_fw:
  631. mlx4_UNMAP_FA(dev);
  632. mlx4_free_icm(dev, priv->fw.fw_icm, 0);
  633. return err;
  634. }
  635. static int mlx4_setup_hca(struct mlx4_dev *dev)
  636. {
  637. struct mlx4_priv *priv = mlx4_priv(dev);
  638. int err;
  639. int port;
  640. err = mlx4_init_uar_table(dev);
  641. if (err) {
  642. mlx4_err(dev, "Failed to initialize "
  643. "user access region table, aborting.\n");
  644. return err;
  645. }
  646. err = mlx4_uar_alloc(dev, &priv->driver_uar);
  647. if (err) {
  648. mlx4_err(dev, "Failed to allocate driver access region, "
  649. "aborting.\n");
  650. goto err_uar_table_free;
  651. }
  652. priv->kar = ioremap(priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
  653. if (!priv->kar) {
  654. mlx4_err(dev, "Couldn't map kernel access region, "
  655. "aborting.\n");
  656. err = -ENOMEM;
  657. goto err_uar_free;
  658. }
  659. err = mlx4_init_pd_table(dev);
  660. if (err) {
  661. mlx4_err(dev, "Failed to initialize "
  662. "protection domain table, aborting.\n");
  663. goto err_kar_unmap;
  664. }
  665. err = mlx4_init_mr_table(dev);
  666. if (err) {
  667. mlx4_err(dev, "Failed to initialize "
  668. "memory region table, aborting.\n");
  669. goto err_pd_table_free;
  670. }
  671. err = mlx4_init_eq_table(dev);
  672. if (err) {
  673. mlx4_err(dev, "Failed to initialize "
  674. "event queue table, aborting.\n");
  675. goto err_mr_table_free;
  676. }
  677. err = mlx4_cmd_use_events(dev);
  678. if (err) {
  679. mlx4_err(dev, "Failed to switch to event-driven "
  680. "firmware commands, aborting.\n");
  681. goto err_eq_table_free;
  682. }
  683. err = mlx4_NOP(dev);
  684. if (err) {
  685. if (dev->flags & MLX4_FLAG_MSI_X) {
  686. mlx4_warn(dev, "NOP command failed to generate MSI-X "
  687. "interrupt IRQ %d).\n",
  688. priv->eq_table.eq[MLX4_EQ_ASYNC].irq);
  689. mlx4_warn(dev, "Trying again without MSI-X.\n");
  690. } else {
  691. mlx4_err(dev, "NOP command failed to generate interrupt "
  692. "(IRQ %d), aborting.\n",
  693. priv->eq_table.eq[MLX4_EQ_ASYNC].irq);
  694. mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
  695. }
  696. goto err_cmd_poll;
  697. }
  698. mlx4_dbg(dev, "NOP command IRQ test passed\n");
  699. err = mlx4_init_cq_table(dev);
  700. if (err) {
  701. mlx4_err(dev, "Failed to initialize "
  702. "completion queue table, aborting.\n");
  703. goto err_cmd_poll;
  704. }
  705. err = mlx4_init_srq_table(dev);
  706. if (err) {
  707. mlx4_err(dev, "Failed to initialize "
  708. "shared receive queue table, aborting.\n");
  709. goto err_cq_table_free;
  710. }
  711. err = mlx4_init_qp_table(dev);
  712. if (err) {
  713. mlx4_err(dev, "Failed to initialize "
  714. "queue pair table, aborting.\n");
  715. goto err_srq_table_free;
  716. }
  717. err = mlx4_init_mcg_table(dev);
  718. if (err) {
  719. mlx4_err(dev, "Failed to initialize "
  720. "multicast group table, aborting.\n");
  721. goto err_qp_table_free;
  722. }
  723. for (port = 1; port <= dev->caps.num_ports; port++) {
  724. err = mlx4_SET_PORT(dev, port);
  725. if (err) {
  726. mlx4_err(dev, "Failed to set port %d, aborting\n",
  727. port);
  728. goto err_mcg_table_free;
  729. }
  730. }
  731. return 0;
  732. err_mcg_table_free:
  733. mlx4_cleanup_mcg_table(dev);
  734. err_qp_table_free:
  735. mlx4_cleanup_qp_table(dev);
  736. err_srq_table_free:
  737. mlx4_cleanup_srq_table(dev);
  738. err_cq_table_free:
  739. mlx4_cleanup_cq_table(dev);
  740. err_cmd_poll:
  741. mlx4_cmd_use_polling(dev);
  742. err_eq_table_free:
  743. mlx4_cleanup_eq_table(dev);
  744. err_mr_table_free:
  745. mlx4_cleanup_mr_table(dev);
  746. err_pd_table_free:
  747. mlx4_cleanup_pd_table(dev);
  748. err_kar_unmap:
  749. iounmap(priv->kar);
  750. err_uar_free:
  751. mlx4_uar_free(dev, &priv->driver_uar);
  752. err_uar_table_free:
  753. mlx4_cleanup_uar_table(dev);
  754. return err;
  755. }
  756. static void mlx4_enable_msi_x(struct mlx4_dev *dev)
  757. {
  758. struct mlx4_priv *priv = mlx4_priv(dev);
  759. struct msix_entry entries[MLX4_NUM_EQ];
  760. int err;
  761. int i;
  762. if (msi_x) {
  763. for (i = 0; i < MLX4_NUM_EQ; ++i)
  764. entries[i].entry = i;
  765. err = pci_enable_msix(dev->pdev, entries, ARRAY_SIZE(entries));
  766. if (err) {
  767. if (err > 0)
  768. mlx4_info(dev, "Only %d MSI-X vectors available, "
  769. "not using MSI-X\n", err);
  770. goto no_msi;
  771. }
  772. for (i = 0; i < MLX4_NUM_EQ; ++i)
  773. priv->eq_table.eq[i].irq = entries[i].vector;
  774. dev->flags |= MLX4_FLAG_MSI_X;
  775. return;
  776. }
  777. no_msi:
  778. for (i = 0; i < MLX4_NUM_EQ; ++i)
  779. priv->eq_table.eq[i].irq = dev->pdev->irq;
  780. }
  781. static int mlx4_init_port_info(struct mlx4_dev *dev, int port)
  782. {
  783. struct mlx4_port_info *info = &mlx4_priv(dev)->port[port];
  784. int err = 0;
  785. info->dev = dev;
  786. info->port = port;
  787. mlx4_init_mac_table(dev, &info->mac_table);
  788. mlx4_init_vlan_table(dev, &info->vlan_table);
  789. sprintf(info->dev_name, "mlx4_port%d", port);
  790. info->port_attr.attr.name = info->dev_name;
  791. info->port_attr.attr.mode = S_IRUGO | S_IWUSR;
  792. info->port_attr.show = show_port_type;
  793. info->port_attr.store = set_port_type;
  794. err = device_create_file(&dev->pdev->dev, &info->port_attr);
  795. if (err) {
  796. mlx4_err(dev, "Failed to create file for port %d\n", port);
  797. info->port = -1;
  798. }
  799. return err;
  800. }
  801. static void mlx4_cleanup_port_info(struct mlx4_port_info *info)
  802. {
  803. if (info->port < 0)
  804. return;
  805. device_remove_file(&info->dev->pdev->dev, &info->port_attr);
  806. }
  807. static int __mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
  808. {
  809. struct mlx4_priv *priv;
  810. struct mlx4_dev *dev;
  811. int err;
  812. int port;
  813. printk(KERN_INFO PFX "Initializing %s\n",
  814. pci_name(pdev));
  815. err = pci_enable_device(pdev);
  816. if (err) {
  817. dev_err(&pdev->dev, "Cannot enable PCI device, "
  818. "aborting.\n");
  819. return err;
  820. }
  821. /*
  822. * Check for BARs. We expect 0: 1MB
  823. */
  824. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
  825. pci_resource_len(pdev, 0) != 1 << 20) {
  826. dev_err(&pdev->dev, "Missing DCS, aborting.\n");
  827. err = -ENODEV;
  828. goto err_disable_pdev;
  829. }
  830. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  831. dev_err(&pdev->dev, "Missing UAR, aborting.\n");
  832. err = -ENODEV;
  833. goto err_disable_pdev;
  834. }
  835. err = pci_request_region(pdev, 0, DRV_NAME);
  836. if (err) {
  837. dev_err(&pdev->dev, "Cannot request control region, aborting.\n");
  838. goto err_disable_pdev;
  839. }
  840. err = pci_request_region(pdev, 2, DRV_NAME);
  841. if (err) {
  842. dev_err(&pdev->dev, "Cannot request UAR region, aborting.\n");
  843. goto err_release_bar0;
  844. }
  845. pci_set_master(pdev);
  846. err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
  847. if (err) {
  848. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
  849. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  850. if (err) {
  851. dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
  852. goto err_release_bar2;
  853. }
  854. }
  855. err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
  856. if (err) {
  857. dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
  858. "consistent PCI DMA mask.\n");
  859. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  860. if (err) {
  861. dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
  862. "aborting.\n");
  863. goto err_release_bar2;
  864. }
  865. }
  866. priv = kzalloc(sizeof *priv, GFP_KERNEL);
  867. if (!priv) {
  868. dev_err(&pdev->dev, "Device struct alloc failed, "
  869. "aborting.\n");
  870. err = -ENOMEM;
  871. goto err_release_bar2;
  872. }
  873. dev = &priv->dev;
  874. dev->pdev = pdev;
  875. INIT_LIST_HEAD(&priv->ctx_list);
  876. spin_lock_init(&priv->ctx_lock);
  877. mutex_init(&priv->port_mutex);
  878. INIT_LIST_HEAD(&priv->pgdir_list);
  879. mutex_init(&priv->pgdir_mutex);
  880. /*
  881. * Now reset the HCA before we touch the PCI capabilities or
  882. * attempt a firmware command, since a boot ROM may have left
  883. * the HCA in an undefined state.
  884. */
  885. err = mlx4_reset(dev);
  886. if (err) {
  887. mlx4_err(dev, "Failed to reset HCA, aborting.\n");
  888. goto err_free_dev;
  889. }
  890. if (mlx4_cmd_init(dev)) {
  891. mlx4_err(dev, "Failed to init command interface, aborting.\n");
  892. goto err_free_dev;
  893. }
  894. err = mlx4_init_hca(dev);
  895. if (err)
  896. goto err_cmd;
  897. mlx4_enable_msi_x(dev);
  898. err = mlx4_setup_hca(dev);
  899. if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X)) {
  900. dev->flags &= ~MLX4_FLAG_MSI_X;
  901. pci_disable_msix(pdev);
  902. err = mlx4_setup_hca(dev);
  903. }
  904. if (err)
  905. goto err_close;
  906. for (port = 1; port <= dev->caps.num_ports; port++) {
  907. err = mlx4_init_port_info(dev, port);
  908. if (err)
  909. goto err_port;
  910. }
  911. err = mlx4_register_device(dev);
  912. if (err)
  913. goto err_port;
  914. pci_set_drvdata(pdev, dev);
  915. return 0;
  916. err_port:
  917. for (port = 1; port <= dev->caps.num_ports; port++)
  918. mlx4_cleanup_port_info(&priv->port[port]);
  919. mlx4_cleanup_mcg_table(dev);
  920. mlx4_cleanup_qp_table(dev);
  921. mlx4_cleanup_srq_table(dev);
  922. mlx4_cleanup_cq_table(dev);
  923. mlx4_cmd_use_polling(dev);
  924. mlx4_cleanup_eq_table(dev);
  925. mlx4_cleanup_mr_table(dev);
  926. mlx4_cleanup_pd_table(dev);
  927. mlx4_cleanup_uar_table(dev);
  928. err_close:
  929. if (dev->flags & MLX4_FLAG_MSI_X)
  930. pci_disable_msix(pdev);
  931. mlx4_close_hca(dev);
  932. err_cmd:
  933. mlx4_cmd_cleanup(dev);
  934. err_free_dev:
  935. kfree(priv);
  936. err_release_bar2:
  937. pci_release_region(pdev, 2);
  938. err_release_bar0:
  939. pci_release_region(pdev, 0);
  940. err_disable_pdev:
  941. pci_disable_device(pdev);
  942. pci_set_drvdata(pdev, NULL);
  943. return err;
  944. }
  945. static int __devinit mlx4_init_one(struct pci_dev *pdev,
  946. const struct pci_device_id *id)
  947. {
  948. static int mlx4_version_printed;
  949. if (!mlx4_version_printed) {
  950. printk(KERN_INFO "%s", mlx4_version);
  951. ++mlx4_version_printed;
  952. }
  953. return __mlx4_init_one(pdev, id);
  954. }
  955. static void mlx4_remove_one(struct pci_dev *pdev)
  956. {
  957. struct mlx4_dev *dev = pci_get_drvdata(pdev);
  958. struct mlx4_priv *priv = mlx4_priv(dev);
  959. int p;
  960. if (dev) {
  961. mlx4_unregister_device(dev);
  962. for (p = 1; p <= dev->caps.num_ports; p++) {
  963. mlx4_cleanup_port_info(&priv->port[p]);
  964. mlx4_CLOSE_PORT(dev, p);
  965. }
  966. mlx4_cleanup_mcg_table(dev);
  967. mlx4_cleanup_qp_table(dev);
  968. mlx4_cleanup_srq_table(dev);
  969. mlx4_cleanup_cq_table(dev);
  970. mlx4_cmd_use_polling(dev);
  971. mlx4_cleanup_eq_table(dev);
  972. mlx4_cleanup_mr_table(dev);
  973. mlx4_cleanup_pd_table(dev);
  974. iounmap(priv->kar);
  975. mlx4_uar_free(dev, &priv->driver_uar);
  976. mlx4_cleanup_uar_table(dev);
  977. mlx4_close_hca(dev);
  978. mlx4_cmd_cleanup(dev);
  979. if (dev->flags & MLX4_FLAG_MSI_X)
  980. pci_disable_msix(pdev);
  981. kfree(priv);
  982. pci_release_region(pdev, 2);
  983. pci_release_region(pdev, 0);
  984. pci_disable_device(pdev);
  985. pci_set_drvdata(pdev, NULL);
  986. }
  987. }
  988. int mlx4_restart_one(struct pci_dev *pdev)
  989. {
  990. mlx4_remove_one(pdev);
  991. return __mlx4_init_one(pdev, NULL);
  992. }
  993. static struct pci_device_id mlx4_pci_table[] = {
  994. { PCI_VDEVICE(MELLANOX, 0x6340) }, /* MT25408 "Hermon" SDR */
  995. { PCI_VDEVICE(MELLANOX, 0x634a) }, /* MT25408 "Hermon" DDR */
  996. { PCI_VDEVICE(MELLANOX, 0x6354) }, /* MT25408 "Hermon" QDR */
  997. { PCI_VDEVICE(MELLANOX, 0x6732) }, /* MT25408 "Hermon" DDR PCIe gen2 */
  998. { PCI_VDEVICE(MELLANOX, 0x673c) }, /* MT25408 "Hermon" QDR PCIe gen2 */
  999. { PCI_VDEVICE(MELLANOX, 0x6368) }, /* MT25408 "Hermon" EN 10GigE */
  1000. { PCI_VDEVICE(MELLANOX, 0x6750) }, /* MT25408 "Hermon" EN 10GigE PCIe gen2 */
  1001. { 0, }
  1002. };
  1003. MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
  1004. static struct pci_driver mlx4_driver = {
  1005. .name = DRV_NAME,
  1006. .id_table = mlx4_pci_table,
  1007. .probe = mlx4_init_one,
  1008. .remove = __devexit_p(mlx4_remove_one)
  1009. };
  1010. static int __init mlx4_verify_params(void)
  1011. {
  1012. if ((log_num_mac < 0) || (log_num_mac > 7)) {
  1013. printk(KERN_WARNING "mlx4_core: bad num_mac: %d\n", log_num_mac);
  1014. return -1;
  1015. }
  1016. if ((log_num_vlan < 0) || (log_num_vlan > 7)) {
  1017. printk(KERN_WARNING "mlx4_core: bad num_vlan: %d\n", log_num_vlan);
  1018. return -1;
  1019. }
  1020. return 0;
  1021. }
  1022. static int __init mlx4_init(void)
  1023. {
  1024. int ret;
  1025. if (mlx4_verify_params())
  1026. return -EINVAL;
  1027. ret = mlx4_catas_init();
  1028. if (ret)
  1029. return ret;
  1030. ret = pci_register_driver(&mlx4_driver);
  1031. return ret < 0 ? ret : 0;
  1032. }
  1033. static void __exit mlx4_cleanup(void)
  1034. {
  1035. pci_unregister_driver(&mlx4_driver);
  1036. mlx4_catas_cleanup();
  1037. }
  1038. module_init(mlx4_init);
  1039. module_exit(mlx4_cleanup);