36 #include <linux/module.h>
38 #include <linux/errno.h>
39 #include <linux/pci.h>
41 #include <linux/slab.h>
44 #include <linux/netdevice.h>
60 #ifdef CONFIG_MLX4_DEBUG
86 MODULE_PARM_DESC(probe_vf,
"number of vfs to probe by pf driver (num_vfs > 0)");
91 MODULE_PARM_DESC(log_num_mgm_entry_size,
"log mgm size, that defines the num"
92 " of qp per mcg, for example:"
93 " 10 gives 248.range: 9<="
94 " log_num_mgm_entry_size <= 12."
95 " Not in use with device managed"
98 #define HCA_GLOBAL_CAP_MASK 0
99 #define PF_CONTEXT_BEHAVIOUR_MASK 0
102 DRV_NAME ": Mellanox ConnectX core driver v"
108 .rdmarc_per_qp = 1 << 4,
115 static int log_num_mac = 7;
117 MODULE_PARM_DESC(log_num_mac,
"Log2 max number of MACs per ETH port (1-7)");
119 static int log_num_vlan;
121 MODULE_PARM_DESC(log_num_vlan,
"Log2 max number of VLANs per ETH port (0-7)");
123 #define MLX4_LOG_NUM_VLANS 7
125 static bool use_prio;
132 MODULE_PARM_DESC(log_mtts_per_seg,
"Log2 number of MTT entries per segment (1-7)");
135 static int arr_argc = 2;
137 MODULE_PARM_DESC(port_type_array,
"Array of port types: HW_DEFAULT (0) is default "
138 "1 for IB, 2 for Ethernet");
151 for (i = 0; i < dev->
caps.num_ports - 1; i++) {
152 if (port_type[i] != port_type[i + 1]) {
154 mlx4_err(dev,
"Only same port types supported "
155 "on this HCA, aborting.\n");
161 for (i = 0; i < dev->
caps.num_ports; i++) {
162 if (!(port_type[i] & dev->
caps.supported_type[i+1])) {
163 mlx4_err(dev,
"Requested port type for port %d is not "
164 "supported on this HCA\n", i + 1);
171 static void mlx4_set_port_mask(
struct mlx4_dev *
dev)
175 for (i = 1; i <= dev->
caps.num_ports; ++
i)
176 dev->
caps.port_mask[i] = dev->
caps.port_type[i];
186 mlx4_err(dev,
"QUERY_DEV_CAP command failed, aborting.\n");
191 mlx4_err(dev,
"HCA minimum page size of %d bigger than "
192 "kernel PAGE_SIZE of %ld, aborting.\n",
197 mlx4_err(dev,
"HCA has %d ports, but we only support %d, "
204 mlx4_err(dev,
"HCA reported UAR size of 0x%x bigger than "
205 "PCI resource 2 size of 0x%llx, aborting.\n",
213 for (i = 1; i <= dev->
caps.num_ports; ++
i) {
281 dev->
caps.fs_log_max_ucast_qp_range_size =
292 mlx4_warn(dev,
"Must have UC_STEER and MC_STEER flags "
293 "set to use B0 steering. Falling back to A0 steering mode.\n");
297 mlx4_dbg(dev,
"Steering mode is: %s\n",
298 mlx4_steering_mode_str(dev->
caps.steering_mode));
304 if (mlx4_is_mfunc(dev))
307 dev->
caps.log_num_macs = log_num_mac;
309 dev->
caps.log_num_prios = use_prio ? 3 : 0;
311 for (i = 1; i <= dev->
caps.num_ports; ++
i) {
313 if (dev->
caps.supported_type[i]) {
318 else if (dev->
caps.supported_type[i] ==
326 dev->
caps.port_type[
i] = dev->
caps.suggested_type[
i] ?
329 dev->
caps.port_type[
i] = port_type_array[i - 1];
353 dev->
caps.port_type[
i] = sensed_port;
355 dev->
caps.possible_type[
i] = dev->
caps.port_type[
i];
360 mlx4_warn(dev,
"Requested number of MACs is too much "
361 "for port %d, reducing to %d.\n",
362 i, 1 << dev->
caps.log_num_macs);
366 mlx4_warn(dev,
"Requested number of VLANs is too much "
367 "for port %d, reducing to %d.\n",
368 i, 1 << dev->
caps.log_num_vlans);
377 (1 << dev->
caps.log_num_macs) *
378 (1 << dev->
caps.log_num_vlans) *
379 (1 << dev->
caps.log_num_prios) *
392 static int mlx4_how_many_lives_vf(
struct mlx4_dev *dev)
400 s_state = &priv->
mfunc.master.slave_state[
i];
403 mlx4_warn(dev,
"%s: slave: %d is still active\n",
416 qpn < dev->phys_caps.base_proxy_sqpn)
419 if (qpn >= dev->
phys_caps.base_tunnel_sqpn)
421 qk += qpn - dev->
phys_caps.base_tunnel_sqpn;
423 qk += qpn - dev->
phys_caps.base_proxy_sqpn;
433 if (!mlx4_is_master(dev))
444 if (!mlx4_is_master(dev))
455 if (!mlx4_is_master(dev))
467 if (!mlx4_is_master(dev))
470 s_slave = &priv->
mfunc.master.slave_state[slave];
475 static int mlx4_slave_cap(
struct mlx4_dev *dev)
484 memset(&hca_param, 0,
sizeof(hca_param));
487 mlx4_err(dev,
"QUERY_HCA command failed, aborting.\n");
494 mlx4_err(dev,
"Unknown hca global capabilities\n");
500 memset(&dev_cap, 0,
sizeof(dev_cap));
501 dev->
caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp;
504 mlx4_err(dev,
"QUERY_DEV_CAP command failed, aborting.\n");
510 mlx4_err(dev,
"QUERY_FW command failed: could not get FW version.\n");
512 page_size = ~dev->
caps.page_size_cap + 1;
513 mlx4_warn(dev,
"HCA minimum page size:%d\n", page_size);
515 mlx4_err(dev,
"HCA minimum page size of %d bigger than "
516 "kernel PAGE_SIZE of %ld, aborting.\n",
522 dev->
caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12);
526 mlx4_err(dev,
"UAR size:%d != kernel PAGE_SIZE of %ld\n",
531 memset(&func_cap, 0,
sizeof(func_cap));
534 mlx4_err(dev,
"QUERY_FUNC_CAP general command failed, aborting (%d).\n",
541 mlx4_err(dev,
"Unknown pf context behaviour\n");
545 dev->
caps.num_ports = func_cap.num_ports;
546 dev->
caps.num_qps = func_cap.qp_quota;
547 dev->
caps.num_srqs = func_cap.srq_quota;
548 dev->
caps.num_cqs = func_cap.cq_quota;
549 dev->
caps.num_eqs = func_cap.max_eq;
550 dev->
caps.reserved_eqs = func_cap.reserved_eq;
551 dev->
caps.num_mpts = func_cap.mpt_quota;
552 dev->
caps.num_mtts = func_cap.mtt_quota;
554 dev->
caps.num_mgms = 0;
555 dev->
caps.num_amgms = 0;
558 mlx4_err(dev,
"HCA has %d ports, but we only support %d, "
568 if (!dev->
caps.qp0_tunnel || !dev->
caps.qp0_proxy ||
569 !dev->
caps.qp1_tunnel || !dev->
caps.qp1_proxy) {
574 for (i = 1; i <= dev->
caps.num_ports; ++
i) {
577 mlx4_err(dev,
"QUERY_FUNC_CAP port command failed for"
578 " port %d, aborting (%d).\n", i, err);
581 dev->
caps.qp0_tunnel[i - 1] = func_cap.qp0_tunnel_qpn;
582 dev->
caps.qp0_proxy[i - 1] = func_cap.qp0_proxy_qpn;
583 dev->
caps.qp1_tunnel[i - 1] = func_cap.qp1_tunnel_qpn;
584 dev->
caps.qp1_proxy[i - 1] = func_cap.qp1_proxy_qpn;
585 dev->
caps.port_mask[
i] = dev->
caps.port_type[
i];
587 &dev->
caps.gid_table_len[i],
588 &dev->
caps.pkey_table_len[i]))
592 if (dev->
caps.uar_page_size * (dev->
caps.num_uars -
593 dev->
caps.reserved_uars) >
595 mlx4_err(dev,
"HCA reported UAR region size of 0x%x bigger than "
596 "PCI resource 2 size of 0x%llx, aborting.\n",
597 dev->
caps.uar_page_size * dev->
caps.num_uars,
609 dev->
caps.qp0_tunnel = dev->
caps.qp0_proxy =
626 for (port = 0; port < dev->
caps.num_ports; port++) {
629 if (port_types[port] != dev->
caps.port_type[port + 1])
634 for (port = 1; port <= dev->
caps.num_ports; port++) {
636 dev->
caps.port_type[
port] = port_types[port - 1];
639 mlx4_err(dev,
"Failed to set port %d, "
644 mlx4_set_port_mask(dev);
665 sprintf(buf,
"auto (%s)\n", type);
674 const char *buf,
size_t count)
687 else if (!
strcmp(buf,
"eth\n"))
689 else if (!
strcmp(buf,
"auto\n"))
692 mlx4_err(mdev,
"%s is not supported port type\n", buf);
701 for (i = 0; i < mdev->
caps.num_ports; i++) {
702 types[
i] = priv->
port[i+1].tmp_type ? priv->
port[i+1].tmp_type :
703 mdev->
caps.possible_type[i+1];
705 types[
i] = mdev->
caps.port_type[i+1];
710 for (i = 1; i <= mdev->
caps.num_ports; i++) {
712 mdev->
caps.possible_type[
i] = mdev->
caps.port_type[
i];
718 mlx4_err(mdev,
"Auto sensing is not supported on this HCA. "
719 "Set only 'eth' or 'ib' for both ports "
720 "(should be the same)\n");
733 for (i = 0; i < mdev->
caps.num_ports; i++)
734 priv->
port[i + 1].tmp_type = 0;
741 return err ? err :
count;
752 static inline int int_to_ibta_mtu(
int mtu)
764 static inline int ibta_mtu_to_int(
enum ibta_mtu mtu)
785 mlx4_warn(mdev,
"port level mtu is only used for IB ports\n");
788 ibta_mtu_to_int(mdev->
caps.port_ib_mtu[info->
port]));
794 const char *buf,
size_t count)
803 mlx4_warn(mdev,
"port level mtu is only used for IB ports\n");
807 err =
sscanf(buf,
"%d", &mtu);
809 ibta_mtu = int_to_ibta_mtu(mtu);
811 if (err <= 0 || ibta_mtu < 0) {
812 mlx4_err(mdev,
"%s is invalid IBTA mtu\n", buf);
821 for (port = 1; port <= mdev->
caps.num_ports; port++) {
825 mlx4_err(mdev,
"Failed to set port %d, "
834 return err ? err :
count;
837 static int mlx4_load_fw(
struct mlx4_dev *dev)
844 if (!priv->
fw.fw_icm) {
845 mlx4_err(dev,
"Couldn't allocate FW area, aborting.\n");
851 mlx4_err(dev,
"MAP_FA command failed, aborting.\n");
857 mlx4_err(dev,
"RUN_FW command failed, aborting.\n");
871 static int mlx4_init_cmpt_table(
struct mlx4_dev *dev,
u64 cmpt_base,
882 cmpt_entry_sz, dev->
caps.num_qps,
892 cmpt_entry_sz, dev->
caps.num_srqs,
893 dev->
caps.reserved_srqs, 0, 0);
901 cmpt_entry_sz, dev->
caps.num_cqs,
902 dev->
caps.reserved_cqs, 0, 0);
906 num_eqs = (mlx4_is_master(dev)) ? dev->
phys_caps.num_phys_eqs :
912 cmpt_entry_sz, num_eqs, num_eqs, 0, 0);
941 mlx4_err(dev,
"SET_ICM_SIZE command failed, aborting.\n");
945 mlx4_dbg(dev,
"%lld KB of HCA context requires %lld KB aux memory.\n",
946 (
unsigned long long) icm_size >> 10,
947 (
unsigned long long) aux_pages << 2);
951 if (!priv->
fw.aux_icm) {
952 mlx4_err(dev,
"Couldn't allocate aux memory, aborting.\n");
958 mlx4_err(dev,
"MAP_ICM_AUX command failed, aborting.\n");
964 mlx4_err(dev,
"Failed to map cMPT context memory, aborting.\n");
969 num_eqs = (mlx4_is_master(dev)) ? dev->
phys_caps.num_phys_eqs :
973 num_eqs, num_eqs, 0, 0);
975 mlx4_err(dev,
"Failed to map EQ context memory, aborting.\n");
986 dev->
caps.reserved_mtts =
992 dev->
caps.mtt_entry_sz,
994 dev->
caps.reserved_mtts, 1, 0);
996 mlx4_err(dev,
"Failed to map MTT context memory, aborting.\n");
1004 dev->
caps.reserved_mrws, 1, 1);
1006 mlx4_err(dev,
"Failed to map dMPT context memory, aborting.\n");
1017 mlx4_err(dev,
"Failed to map QP context memory, aborting.\n");
1018 goto err_unmap_dmpt;
1028 mlx4_err(dev,
"Failed to map AUXC context memory, aborting.\n");
1039 mlx4_err(dev,
"Failed to map ALTC context memory, aborting.\n");
1040 goto err_unmap_auxc;
1050 mlx4_err(dev,
"Failed to map RDMARC context memory, aborting\n");
1051 goto err_unmap_altc;
1058 dev->
caps.reserved_cqs, 0, 0);
1060 mlx4_err(dev,
"Failed to map CQ context memory, aborting.\n");
1061 goto err_unmap_rdmarc;
1068 dev->
caps.reserved_srqs, 0, 0);
1070 mlx4_err(dev,
"Failed to map SRQ context memory, aborting.\n");
1084 dev->
caps.num_mgms + dev->
caps.num_amgms,
1085 dev->
caps.num_mgms + dev->
caps.num_amgms,
1088 mlx4_err(dev,
"Failed to map MCG context memory, aborting.\n");
1136 static void mlx4_free_icms(
struct mlx4_dev *dev)
1159 static void mlx4_slave_exit(
struct mlx4_dev *dev)
1165 mlx4_warn(dev,
"Failed to close slave function.\n");
1169 static int map_bf_area(
struct mlx4_dev *dev)
1176 if (!dev->
caps.bf_reg_size)
1183 priv->
bf_mapping = io_mapping_create_wc(bf_start, bf_len);
1190 static void unmap_bf_area(
struct mlx4_dev *dev)
1196 static void mlx4_close_hca(
struct mlx4_dev *dev)
1199 if (mlx4_is_slave(dev))
1200 mlx4_slave_exit(dev);
1203 mlx4_free_icms(dev);
1209 static int mlx4_init_slave(
struct mlx4_dev *dev)
1214 int ret_from_reset = 0;
1216 u32 cmd_channel_ver;
1219 priv->
cmd.max_cmds = 1;
1225 if (ret_from_reset) {
1228 while (ret_from_reset && num_of_reset_retries) {
1229 mlx4_warn(dev,
"slave is currently in the"
1230 "middle of FLR. retrying..."
1233 num_of_reset_retries + 1));
1237 num_of_reset_retries = num_of_reset_retries - 1;
1250 mlx4_err(dev,
"slave driver version is not supported"
1251 " by the master\n");
1277 static void mlx4_parav_master_pf_caps(
struct mlx4_dev *dev)
1281 for (i = 1; i <= dev->
caps.num_ports; i++) {
1282 dev->
caps.gid_table_len[
i] = 1;
1283 dev->
caps.pkey_table_len[
i] =
1288 static int mlx4_init_hca(
struct mlx4_dev *dev)
1299 if (!mlx4_is_slave(dev)) {
1303 mlx4_info(dev,
"non-primary physical function, skipping.\n");
1305 mlx4_err(dev,
"QUERY_FW command failed, aborting.\n");
1309 err = mlx4_load_fw(dev);
1311 mlx4_err(dev,
"Failed to start FW, aborting.\n");
1315 mlx4_cfg.log_pg_sz_m = 1;
1316 mlx4_cfg.log_pg_sz = 0;
1319 mlx4_warn(dev,
"Failed to override log_pg_sz parameter\n");
1323 mlx4_err(dev,
"QUERY_DEV_CAP command failed, aborting.\n");
1327 if (mlx4_is_master(dev))
1328 mlx4_parav_master_pf_caps(dev);
1347 if (dev->
caps.steering_mode ==
1353 if ((
long long) icm_size < 0) {
1358 dev->
caps.max_fmr_maps = (1 << (32 -
ilog2(dev->
caps.num_mpts))) - 1;
1363 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
1369 mlx4_err(dev,
"INIT_HCA command failed, aborting.\n");
1373 err = mlx4_init_slave(dev);
1375 mlx4_err(dev,
"Failed to initialize slave\n");
1379 err = mlx4_slave_cap(dev);
1381 mlx4_err(dev,
"Failed to obtain slave caps\n");
1386 if (map_bf_area(dev))
1387 mlx4_dbg(dev,
"Failed to map blue flame area\n");
1390 if (!mlx4_is_slave(dev))
1391 mlx4_set_port_mask(dev);
1395 mlx4_err(dev,
"QUERY_ADAPTER command failed, aborting.\n");
1408 if (mlx4_is_slave(dev))
1409 mlx4_slave_exit(dev);
1414 if (!mlx4_is_slave(dev))
1415 mlx4_free_icms(dev);
1418 if (!mlx4_is_slave(dev)) {
1425 static int mlx4_init_counters_table(
struct mlx4_dev *dev)
1433 nent = dev->
caps.max_counters;
1437 static void mlx4_cleanup_counters_table(
struct mlx4_dev *dev)
1461 if (mlx4_is_mfunc(dev)) {
1462 err = mlx4_cmd_imm(dev, 0, &out_param,
RES_COUNTER,
1466 *idx = get_param_l(&out_param);
1484 if (mlx4_is_mfunc(dev)) {
1485 set_param_l(&in_param, idx);
1495 static int mlx4_setup_hca(
struct mlx4_dev *dev)
1500 __be32 ib_port_default_caps;
1504 mlx4_err(dev,
"Failed to initialize "
1505 "user access region table, aborting.\n");
1511 mlx4_err(dev,
"Failed to allocate driver access region, "
1513 goto err_uar_table_free;
1518 mlx4_err(dev,
"Couldn't map kernel access region, "
1526 mlx4_err(dev,
"Failed to initialize "
1527 "protection domain table, aborting.\n");
1533 mlx4_err(dev,
"Failed to initialize "
1534 "reliable connection domain table, aborting.\n");
1535 goto err_pd_table_free;
1540 mlx4_err(dev,
"Failed to initialize "
1541 "memory region table, aborting.\n");
1542 goto err_xrcd_table_free;
1547 mlx4_err(dev,
"Failed to initialize "
1548 "event queue table, aborting.\n");
1549 goto err_mr_table_free;
1554 mlx4_err(dev,
"Failed to switch to event-driven "
1555 "firmware commands, aborting.\n");
1556 goto err_eq_table_free;
1562 mlx4_warn(dev,
"NOP command failed to generate MSI-X "
1563 "interrupt IRQ %d).\n",
1565 mlx4_warn(dev,
"Trying again without MSI-X.\n");
1567 mlx4_err(dev,
"NOP command failed to generate interrupt "
1568 "(IRQ %d), aborting.\n",
1570 mlx4_err(dev,
"BIOS or ACPI interrupt routing problem?\n");
1576 mlx4_dbg(dev,
"NOP command IRQ test passed\n");
1580 mlx4_err(dev,
"Failed to initialize "
1581 "completion queue table, aborting.\n");
1587 mlx4_err(dev,
"Failed to initialize "
1588 "shared receive queue table, aborting.\n");
1589 goto err_cq_table_free;
1594 mlx4_err(dev,
"Failed to initialize "
1595 "queue pair table, aborting.\n");
1596 goto err_srq_table_free;
1599 if (!mlx4_is_slave(dev)) {
1602 mlx4_err(dev,
"Failed to initialize "
1603 "multicast group table, aborting.\n");
1604 goto err_qp_table_free;
1608 err = mlx4_init_counters_table(dev);
1609 if (err && err != -
ENOENT) {
1610 mlx4_err(dev,
"Failed to initialize counters table, aborting.\n");
1611 goto err_mcg_table_free;
1614 if (!mlx4_is_slave(dev)) {
1615 for (port = 1; port <= dev->
caps.num_ports; port++) {
1616 ib_port_default_caps = 0;
1618 &ib_port_default_caps);
1620 mlx4_warn(dev,
"failed to get port %d default "
1621 "ib capabilities (%d). Continuing "
1622 "with caps = 0\n", port, err);
1623 dev->
caps.ib_port_def_cap[
port] = ib_port_default_caps;
1626 if (mlx4_is_master(dev)) {
1629 if (i == mlx4_master_func_num(dev))
1631 priv->
mfunc.master.slave_state[
i].ib_cap_mask[
port] =
1632 ib_port_default_caps;
1636 if (mlx4_is_mfunc(dev))
1642 dev->
caps.pkey_table_len[port] : -1);
1644 mlx4_err(dev,
"Failed to set port %d, aborting\n",
1646 goto err_counters_table_free;
1653 err_counters_table_free:
1654 mlx4_cleanup_counters_table(dev);
1677 err_xrcd_table_free:
1694 static void mlx4_enable_msi_x(
struct mlx4_dev *dev)
1698 int nreq =
min_t(
int, dev->
caps.num_ports *
1708 if (mlx4_is_mfunc(dev)) {
1712 dev->
caps.reserved_eqs, nreq);
1715 entries = kcalloc(nreq,
sizeof *entries,
GFP_KERNEL);
1719 for (i = 0; i < nreq; ++
i)
1720 entries[i].
entry = i;
1728 "but only %d MSI-X vectors available, "
1729 "trying again\n", nreq, err);
1740 dev->
caps.comp_pool = 0;
1741 dev->
caps.num_comp_vectors = nreq - 1;
1744 dev->
caps.num_comp_vectors = MSIX_LEGACY_SZ - 1;
1746 for (i = 0; i < nreq; ++
i)
1747 priv->
eq_table.eq[i].irq = entries[i].vector;
1756 dev->
caps.num_comp_vectors = 1;
1757 dev->
caps.comp_pool = 0;
1759 for (i = 0; i < 2; ++
i)
1763 static int mlx4_init_port_info(
struct mlx4_dev *dev,
int port)
1770 if (!mlx4_is_slave(dev)) {
1776 (port - 1) * (1 << log_num_mac);
1781 if (mlx4_is_mfunc(dev))
1792 mlx4_err(dev,
"Failed to create file for port %d\n", port);
1798 if (mlx4_is_mfunc(dev))
1809 mlx4_err(dev,
"Failed to create mtu file for port %d\n", port);
1826 static int mlx4_init_steering(
struct mlx4_dev *dev)
1838 INIT_LIST_HEAD(&priv->
steer[i].promisc_qps[j]);
1839 INIT_LIST_HEAD(&priv->
steer[i].steer_entries[j]);
1844 static void mlx4_clear_steering(
struct mlx4_dev *dev)
1849 int num_entries = dev->
caps.num_ports;
1855 &priv->
steer[i].promisc_qps[j],
1861 &priv->
steer[i].steer_entries[j],
1877 static int extended_func_num(
struct pci_dev *pdev)
1882 #define MLX4_OWNER_BASE 0x8069c
1883 #define MLX4_OWNER_SIZE 4
1885 static int mlx4_get_ownership(
struct mlx4_dev *dev)
1890 if (pci_channel_offline(dev->
pdev))
1896 mlx4_err(dev,
"Failed to obtain ownership bit\n");
1905 static void mlx4_free_ownership(
struct mlx4_dev *dev)
1909 if (pci_channel_offline(dev->
pdev))
1915 mlx4_err(dev,
"Failed to obtain ownership bit\n");
1923 static int __mlx4_init_one(
struct pci_dev *pdev,
int pci_dev_data)
1934 dev_err(&pdev->
dev,
"Cannot enable PCI device, "
1949 "(driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\n",
1952 goto err_disable_pdev;
1955 dev_err(&pdev->
dev,
"Missing UAR, aborting.\n");
1957 goto err_disable_pdev;
1962 dev_err(&pdev->
dev,
"Couldn't get PCI resources, aborting\n");
1963 goto err_disable_pdev;
1970 dev_warn(&pdev->
dev,
"Warning: couldn't set 64-bit PCI DMA mask.\n");
1973 dev_err(&pdev->
dev,
"Can't set PCI DMA mask, aborting.\n");
1974 goto err_release_regions;
1977 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(64));
1979 dev_warn(&pdev->
dev,
"Warning: couldn't set 64-bit "
1980 "consistent PCI DMA mask.\n");
1981 err = pci_set_consistent_dma_mask(pdev,
DMA_BIT_MASK(32));
1983 dev_err(&pdev->
dev,
"Can't set consistent PCI DMA mask, "
1985 goto err_release_regions;
1990 dma_set_max_seg_size(&pdev->
dev, 1024 * 1024 * 1024);
1994 dev_err(&pdev->
dev,
"Device struct alloc failed, "
1997 goto err_release_regions;
2010 INIT_LIST_HEAD(&priv->
bf_list);
2015 if (pci_dev_data & MLX4_PCI_DEV_IS_VF) {
2018 if (
num_vfs && extended_func_num(pdev) > probe_vf) {
2019 mlx4_warn(dev,
"Skipping virtual function:%d\n",
2020 extended_func_num(pdev));
2024 mlx4_warn(dev,
"Detected virtual function - running in slave mode\n");
2030 err = mlx4_get_ownership(dev);
2035 mlx4_warn(dev,
"Multiple PFs not yet supported."
2046 mlx4_err(dev,
"Failed to enable SR-IOV, continuing without SR-IOV (err = %d).\n",
2050 mlx4_warn(dev,
"Running in master mode\n");
2064 mlx4_err(dev,
"Failed to reset HCA, aborting.\n");
2072 mlx4_err(dev,
"Failed to init command interface, aborting.\n");
2079 if (mlx4_is_mfunc(dev)) {
2080 if (mlx4_is_master(dev))
2085 mlx4_err(dev,
"Failed to init slave mfunc"
2086 " interface, aborting.\n");
2092 err = mlx4_init_hca(dev);
2107 if (mlx4_is_master(dev)) {
2109 mlx4_err(dev,
"Failed to init master mfunc"
2110 "interface, aborting.\n");
2117 goto err_master_mfunc;
2122 mlx4_enable_msi_x(dev);
2123 if ((mlx4_is_mfunc(dev)) &&
2125 mlx4_err(dev,
"INTx is not supported in multi-function mode."
2130 if (!mlx4_is_slave(dev)) {
2131 err = mlx4_init_steering(dev);
2136 err = mlx4_setup_hca(dev);
2138 !mlx4_is_mfunc(dev)) {
2140 dev->
caps.num_comp_vectors = 1;
2141 dev->
caps.comp_pool = 0;
2143 err = mlx4_setup_hca(dev);
2149 for (port = 1; port <= dev->
caps.num_ports; port++) {
2150 err = mlx4_init_port_info(dev, port);
2163 pci_set_drvdata(pdev, dev);
2168 for (--port; port >= 1; --
port)
2169 mlx4_cleanup_port_info(&priv->
port[port]);
2171 mlx4_cleanup_counters_table(dev);
2184 if (!mlx4_is_slave(dev))
2185 mlx4_clear_steering(dev);
2191 if (mlx4_is_master(dev))
2198 mlx4_close_hca(dev);
2201 if (mlx4_is_slave(dev))
2212 if (!mlx4_is_slave(dev))
2213 mlx4_free_ownership(dev);
2218 err_release_regions:
2223 pci_set_drvdata(pdev,
NULL);
2235 static void mlx4_remove_one(
struct pci_dev *pdev)
2237 struct mlx4_dev *dev = pci_get_drvdata(pdev);
2244 if (mlx4_is_master(dev)) {
2245 if (mlx4_how_many_lives_vf(dev))
2246 printk(
KERN_ERR "Removing PF when there are assigned VF's !!!\n");
2251 for (p = 1; p <= dev->
caps.num_ports; p++) {
2252 mlx4_cleanup_port_info(&priv->
port[p]);
2256 if (mlx4_is_master(dev))
2260 mlx4_cleanup_counters_table(dev);
2271 if (mlx4_is_master(dev))
2278 if (!mlx4_is_slave(dev))
2279 mlx4_clear_steering(dev);
2281 if (mlx4_is_master(dev))
2283 mlx4_close_hca(dev);
2284 if (mlx4_is_slave(dev))
2295 if (!mlx4_is_slave(dev))
2296 mlx4_free_ownership(dev);
2306 pci_set_drvdata(pdev,
NULL);
2312 struct mlx4_dev *dev = pci_get_drvdata(pdev);
2317 mlx4_remove_one(pdev);
2318 return __mlx4_init_one(pdev, pci_dev_data);
2323 {
PCI_VDEVICE(MELLANOX, 0x6340), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2325 {
PCI_VDEVICE(MELLANOX, 0x634a), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2327 {
PCI_VDEVICE(MELLANOX, 0x6354), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2329 {
PCI_VDEVICE(MELLANOX, 0x6732), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2331 {
PCI_VDEVICE(MELLANOX, 0x673c), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2333 {
PCI_VDEVICE(MELLANOX, 0x6368), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2335 {
PCI_VDEVICE(MELLANOX, 0x6750), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2337 {
PCI_VDEVICE(MELLANOX, 0x6372), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2339 {
PCI_VDEVICE(MELLANOX, 0x675a), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2341 {
PCI_VDEVICE(MELLANOX, 0x6764), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2343 {
PCI_VDEVICE(MELLANOX, 0x6746), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2345 {
PCI_VDEVICE(MELLANOX, 0x676e), MLX4_PCI_DEV_FORCE_SENSE_PORT },
2347 {
PCI_VDEVICE(MELLANOX, 0x1002), MLX4_PCI_DEV_IS_VF },
2351 {
PCI_VDEVICE(MELLANOX, 0x1004), MLX4_PCI_DEV_IS_VF },
2372 mlx4_remove_one(pdev);
2380 int ret = __mlx4_init_one(pdev, 0);
2386 .error_detected = mlx4_pci_err_detected,
2387 .slot_reset = mlx4_pci_slot_reset,
2392 .id_table = mlx4_pci_table,
2393 .probe = mlx4_init_one,
2395 .err_handler = &mlx4_err_handler,
2398 static int __init mlx4_verify_params(
void)
2400 if ((log_num_mac < 0) || (log_num_mac > 7)) {
2401 pr_warning(
"mlx4_core: bad num_mac: %d\n", log_num_mac);
2405 if (log_num_vlan != 0)
2406 pr_warning(
"mlx4_core: log_num_vlan - obsolete module param, using %d\n",
2409 if ((log_mtts_per_seg < 1) || (log_mtts_per_seg > 7)) {
2410 pr_warning(
"mlx4_core: bad log_mtts_per_seg: %d\n", log_mtts_per_seg);
2415 if (port_type_array[0] ==
false && port_type_array[1] ==
true) {
2416 printk(
KERN_WARNING "Module parameter configuration ETH/IB is not supported. Switching to default configuration IB/IB\n");
2417 port_type_array[0] =
true;
2423 static int __init mlx4_init(
void)
2427 if (mlx4_verify_params())
2436 ret = pci_register_driver(&mlx4_driver);
2437 return ret < 0 ? ret : 0;
2440 static void __exit mlx4_cleanup(
void)