Lines Matching refs:dev

181 static inline void mlx4_set_num_reserved_uars(struct mlx4_dev *dev,  in mlx4_set_num_reserved_uars()  argument
188 dev->caps.reserved_uars = in mlx4_set_num_reserved_uars()
190 mlx4_get_num_reserved_uar(dev), in mlx4_set_num_reserved_uars()
192 (1 << (PAGE_SHIFT - dev->uar_page_shift))); in mlx4_set_num_reserved_uars()
195 int mlx4_check_port_params(struct mlx4_dev *dev, in mlx4_check_port_params() argument
200 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) { in mlx4_check_port_params()
201 for (i = 0; i < dev->caps.num_ports - 1; i++) { in mlx4_check_port_params()
203 mlx4_err(dev, "Only same port types supported on this HCA, aborting\n"); in mlx4_check_port_params()
209 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_check_port_params()
210 if (!(port_type[i] & dev->caps.supported_type[i+1])) { in mlx4_check_port_params()
211 mlx4_err(dev, "Requested port type for port %d is not supported on this HCA\n", in mlx4_check_port_params()
219 static void mlx4_set_port_mask(struct mlx4_dev *dev) in mlx4_set_port_mask() argument
223 for (i = 1; i <= dev->caps.num_ports; ++i) in mlx4_set_port_mask()
224 dev->caps.port_mask[i] = dev->caps.port_type[i]; in mlx4_set_port_mask()
231 static int mlx4_query_func(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_query_func() argument
236 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS) { in mlx4_query_func()
237 err = mlx4_QUERY_FUNC(dev, &func, 0); in mlx4_query_func()
239 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_query_func()
250 static void mlx4_enable_cqe_eqe_stride(struct mlx4_dev *dev) in mlx4_enable_cqe_eqe_stride() argument
252 struct mlx4_caps *dev_cap = &dev->caps; in mlx4_enable_cqe_eqe_stride()
270 mlx4_dbg(dev, "Enabling CQE stride cacheLine supported\n"); in mlx4_enable_cqe_eqe_stride()
275 if (mlx4_is_master(dev)) in mlx4_enable_cqe_eqe_stride()
279 mlx4_dbg(dev, "Disabling CQE stride, cacheLine size unsupported\n"); in mlx4_enable_cqe_eqe_stride()
285 static int _mlx4_dev_port(struct mlx4_dev *dev, int port, in _mlx4_dev_port() argument
288 dev->caps.vl_cap[port] = port_cap->max_vl; in _mlx4_dev_port()
289 dev->caps.ib_mtu_cap[port] = port_cap->ib_mtu; in _mlx4_dev_port()
290 dev->phys_caps.gid_phys_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
291 dev->phys_caps.pkey_phys_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
295 dev->caps.gid_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
296 dev->caps.pkey_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
297 dev->caps.port_width_cap[port] = port_cap->max_port_width; in _mlx4_dev_port()
298 dev->caps.eth_mtu_cap[port] = port_cap->eth_mtu; in _mlx4_dev_port()
299 dev->caps.max_tc_eth = port_cap->max_tc_eth; in _mlx4_dev_port()
300 dev->caps.def_mac[port] = port_cap->def_mac; in _mlx4_dev_port()
301 dev->caps.supported_type[port] = port_cap->supported_port_types; in _mlx4_dev_port()
302 dev->caps.suggested_type[port] = port_cap->suggested_type; in _mlx4_dev_port()
303 dev->caps.default_sense[port] = port_cap->default_sense; in _mlx4_dev_port()
304 dev->caps.trans_type[port] = port_cap->trans_type; in _mlx4_dev_port()
305 dev->caps.vendor_oui[port] = port_cap->vendor_oui; in _mlx4_dev_port()
306 dev->caps.wavelength[port] = port_cap->wavelength; in _mlx4_dev_port()
307 dev->caps.trans_code[port] = port_cap->trans_code; in _mlx4_dev_port()
312 static int mlx4_dev_port(struct mlx4_dev *dev, int port, in mlx4_dev_port() argument
317 err = mlx4_QUERY_PORT(dev, port, port_cap); in mlx4_dev_port()
320 mlx4_err(dev, "QUERY_PORT command failed.\n"); in mlx4_dev_port()
325 static inline void mlx4_enable_ignore_fcs(struct mlx4_dev *dev) in mlx4_enable_ignore_fcs() argument
327 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_IGNORE_FCS)) in mlx4_enable_ignore_fcs()
330 if (mlx4_is_mfunc(dev)) { in mlx4_enable_ignore_fcs()
331 mlx4_dbg(dev, "SRIOV mode - Disabling Ignore FCS"); in mlx4_enable_ignore_fcs()
332 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
336 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP)) { in mlx4_enable_ignore_fcs()
337 mlx4_dbg(dev, in mlx4_enable_ignore_fcs()
339 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
345 static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_dev_cap() argument
350 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_dev_cap()
352 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_dev_cap()
355 mlx4_dev_cap_dump(dev, dev_cap); in mlx4_dev_cap()
358 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_dev_cap()
363 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_dev_cap()
368 if (dev_cap->uar_size > pci_resource_len(dev->persist->pdev, 2)) { in mlx4_dev_cap()
369 …mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than PCI resource 2 size of 0x%llx, aborting\n… in mlx4_dev_cap()
372 pci_resource_len(dev->persist->pdev, 2)); in mlx4_dev_cap()
376 dev->caps.num_ports = dev_cap->num_ports; in mlx4_dev_cap()
377 dev->caps.num_sys_eqs = dev_cap->num_sys_eqs; in mlx4_dev_cap()
378 dev->phys_caps.num_phys_eqs = dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS ? in mlx4_dev_cap()
379 dev->caps.num_sys_eqs : in mlx4_dev_cap()
381 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
382 err = _mlx4_dev_port(dev, i, dev_cap->port_cap + i); in mlx4_dev_cap()
384 mlx4_err(dev, "QUERY_PORT command failed, aborting\n"); in mlx4_dev_cap()
389 dev->caps.map_clock_to_user = dev_cap->map_clock_to_user; in mlx4_dev_cap()
390 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_dev_cap()
391 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE; in mlx4_dev_cap()
392 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay; in mlx4_dev_cap()
393 dev->caps.bf_reg_size = dev_cap->bf_reg_size; in mlx4_dev_cap()
394 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page; in mlx4_dev_cap()
395 dev->caps.max_sq_sg = dev_cap->max_sq_sg; in mlx4_dev_cap()
396 dev->caps.max_rq_sg = dev_cap->max_rq_sg; in mlx4_dev_cap()
397 dev->caps.max_wqes = dev_cap->max_qp_sz; in mlx4_dev_cap()
398 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp; in mlx4_dev_cap()
399 dev->caps.max_srq_wqes = dev_cap->max_srq_sz; in mlx4_dev_cap()
400 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1; in mlx4_dev_cap()
401 dev->caps.reserved_srqs = dev_cap->reserved_srqs; in mlx4_dev_cap()
402 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz; in mlx4_dev_cap()
403 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz; in mlx4_dev_cap()
409 dev->caps.max_cqes = dev_cap->max_cq_sz - 1; in mlx4_dev_cap()
410 dev->caps.reserved_cqs = dev_cap->reserved_cqs; in mlx4_dev_cap()
411 dev->caps.reserved_eqs = dev_cap->reserved_eqs; in mlx4_dev_cap()
412 dev->caps.reserved_mtts = dev_cap->reserved_mtts; in mlx4_dev_cap()
413 dev->caps.reserved_mrws = dev_cap->reserved_mrws; in mlx4_dev_cap()
415 dev->caps.reserved_pds = dev_cap->reserved_pds; in mlx4_dev_cap()
416 dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
418 dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
420 dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz; in mlx4_dev_cap()
422 dev->caps.max_msg_sz = dev_cap->max_msg_sz; in mlx4_dev_cap()
423 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1); in mlx4_dev_cap()
424 dev->caps.flags = dev_cap->flags; in mlx4_dev_cap()
425 dev->caps.flags2 = dev_cap->flags2; in mlx4_dev_cap()
426 dev->caps.bmme_flags = dev_cap->bmme_flags; in mlx4_dev_cap()
427 dev->caps.reserved_lkey = dev_cap->reserved_lkey; in mlx4_dev_cap()
428 dev->caps.stat_rate_support = dev_cap->stat_rate_support; in mlx4_dev_cap()
429 dev->caps.max_gso_sz = dev_cap->max_gso_sz; in mlx4_dev_cap()
430 dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz; in mlx4_dev_cap()
433 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
438 dev->uar_page_shift = DEFAULT_UAR_PAGE_SHIFT; in mlx4_dev_cap()
440 dev->uar_page_shift = PAGE_SHIFT; in mlx4_dev_cap()
442 mlx4_set_num_reserved_uars(dev, dev_cap); in mlx4_dev_cap()
445 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PHV_EN) { in mlx4_dev_cap()
449 err = mlx4_QUERY_HCA(dev, &hca_param); in mlx4_dev_cap()
457 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_PHV_EN; in mlx4_dev_cap()
461 if (mlx4_priv(dev)->pci_dev_data & MLX4_PCI_DEV_FORCE_SENSE_PORT) in mlx4_dev_cap()
462 dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
464 if (mlx4_is_mfunc(dev)) in mlx4_dev_cap()
465 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
468 dev->caps.log_num_macs = MLX4_MIN_LOG_NUM_MAC; in mlx4_dev_cap()
469 dev->caps.log_num_vlans = MLX4_MIN_LOG_NUM_VLANS; in mlx4_dev_cap()
471 dev->caps.log_num_macs = log_num_mac; in mlx4_dev_cap()
472 dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS; in mlx4_dev_cap()
475 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
476 dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE; in mlx4_dev_cap()
477 if (dev->caps.supported_type[i]) { in mlx4_dev_cap()
479 if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_dev_cap()
480 dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH; in mlx4_dev_cap()
482 else if (dev->caps.supported_type[i] == in mlx4_dev_cap()
484 dev->caps.port_type[i] = MLX4_PORT_TYPE_IB; in mlx4_dev_cap()
490 dev->caps.port_type[i] = dev->caps.suggested_type[i] ? in mlx4_dev_cap()
493 dev->caps.port_type[i] = port_type_array[i - 1]; in mlx4_dev_cap()
502 mlx4_priv(dev)->sense.sense_allowed[i] = in mlx4_dev_cap()
503 ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) && in mlx4_dev_cap()
504 (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) && in mlx4_dev_cap()
505 (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)); in mlx4_dev_cap()
512 if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) { in mlx4_dev_cap()
514 dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO; in mlx4_dev_cap()
515 mlx4_SENSE_PORT(dev, i, &sensed_port); in mlx4_dev_cap()
517 dev->caps.port_type[i] = sensed_port; in mlx4_dev_cap()
519 dev->caps.possible_type[i] = dev->caps.port_type[i]; in mlx4_dev_cap()
522 if (dev->caps.log_num_macs > dev_cap->port_cap[i].log_max_macs) { in mlx4_dev_cap()
523 dev->caps.log_num_macs = dev_cap->port_cap[i].log_max_macs; in mlx4_dev_cap()
524 mlx4_warn(dev, "Requested number of MACs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
525 i, 1 << dev->caps.log_num_macs); in mlx4_dev_cap()
527 if (dev->caps.log_num_vlans > dev_cap->port_cap[i].log_max_vlans) { in mlx4_dev_cap()
528 dev->caps.log_num_vlans = dev_cap->port_cap[i].log_max_vlans; in mlx4_dev_cap()
529 mlx4_warn(dev, "Requested number of VLANs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
530 i, 1 << dev->caps.log_num_vlans); in mlx4_dev_cap()
534 if (mlx4_is_master(dev) && (dev->caps.num_ports == 2) && in mlx4_dev_cap()
537 mlx4_warn(dev, in mlx4_dev_cap()
539 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_QOS_VPP; in mlx4_dev_cap()
542 dev->caps.max_counters = dev_cap->max_counters; in mlx4_dev_cap()
544 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps; in mlx4_dev_cap()
545 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] = in mlx4_dev_cap()
546 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] = in mlx4_dev_cap()
547 (1 << dev->caps.log_num_macs) * in mlx4_dev_cap()
548 (1 << dev->caps.log_num_vlans) * in mlx4_dev_cap()
549 dev->caps.num_ports; in mlx4_dev_cap()
550 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH; in mlx4_dev_cap()
553 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) in mlx4_dev_cap()
554 dev->caps.dmfs_high_rate_qpn_base = dev_cap->dmfs_high_rate_qpn_base; in mlx4_dev_cap()
556 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
557 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
560 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) { in mlx4_dev_cap()
561 dev->caps.dmfs_high_rate_qpn_range = dev_cap->dmfs_high_rate_qpn_range; in mlx4_dev_cap()
562 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DEFAULT; in mlx4_dev_cap()
563 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_FS_A0; in mlx4_dev_cap()
565 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_NOT_SUPPORTED; in mlx4_dev_cap()
566 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
567 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
568 dev->caps.dmfs_high_rate_qpn_range = MLX4_A0_STEERING_TABLE_SIZE; in mlx4_dev_cap()
571 dev->caps.rl_caps = dev_cap->rl_caps; in mlx4_dev_cap()
573 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_RSS_RAW_ETH] = in mlx4_dev_cap()
574 dev->caps.dmfs_high_rate_qpn_range; in mlx4_dev_cap()
576 dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] + in mlx4_dev_cap()
577 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] + in mlx4_dev_cap()
578 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] + in mlx4_dev_cap()
579 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH]; in mlx4_dev_cap()
581 dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0; in mlx4_dev_cap()
583 if (!enable_64b_cqe_eqe && !mlx4_is_slave(dev)) { in mlx4_dev_cap()
586 mlx4_warn(dev, "64B EQEs/CQEs supported by the device but not enabled\n"); in mlx4_dev_cap()
587 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_CQE; in mlx4_dev_cap()
588 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_EQE; in mlx4_dev_cap()
594 mlx4_warn(dev, "Disabling EQE/CQE stride per user request\n"); in mlx4_dev_cap()
600 if ((dev->caps.flags & in mlx4_dev_cap()
602 mlx4_is_master(dev)) in mlx4_dev_cap()
603 dev->caps.function_caps |= MLX4_FUNC_CAP_64B_EQE_CQE; in mlx4_dev_cap()
605 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
606 mlx4_enable_cqe_eqe_stride(dev); in mlx4_dev_cap()
607 dev->caps.alloc_res_qp_mask = in mlx4_dev_cap()
608 (dev->caps.bf_reg_size ? MLX4_RESERVE_ETH_BF_QP : 0) | in mlx4_dev_cap()
611 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) && in mlx4_dev_cap()
612 dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) { in mlx4_dev_cap()
613 mlx4_warn(dev, "Old device ETS support detected\n"); in mlx4_dev_cap()
614 mlx4_warn(dev, "Consider upgrading device FW.\n"); in mlx4_dev_cap()
615 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_ETS_CFG; in mlx4_dev_cap()
619 dev->caps.alloc_res_qp_mask = 0; in mlx4_dev_cap()
622 mlx4_enable_ignore_fcs(dev); in mlx4_dev_cap()
627 static int mlx4_get_pcie_dev_link_caps(struct mlx4_dev *dev, in mlx4_get_pcie_dev_link_caps() argument
639 err1 = pcie_capability_read_dword(dev->persist->pdev, PCI_EXP_LNKCAP, in mlx4_get_pcie_dev_link_caps()
641 err2 = pcie_capability_read_dword(dev->persist->pdev, PCI_EXP_LNKCAP2, in mlx4_get_pcie_dev_link_caps()
668 static void mlx4_check_pcie_caps(struct mlx4_dev *dev) in mlx4_check_pcie_caps() argument
680 err = mlx4_get_pcie_dev_link_caps(dev, &speed_cap, &width_cap); in mlx4_check_pcie_caps()
682 mlx4_warn(dev, in mlx4_check_pcie_caps()
687 err = pcie_get_minimum_link(dev->persist->pdev, &speed, &width); in mlx4_check_pcie_caps()
690 mlx4_warn(dev, in mlx4_check_pcie_caps()
696 mlx4_warn(dev, in mlx4_check_pcie_caps()
699 mlx4_info(dev, "PCIe link speed is %s, device supports %s\n", in mlx4_check_pcie_caps()
701 mlx4_info(dev, "PCIe link width is x%d, device supports x%d\n", in mlx4_check_pcie_caps()
707 static int mlx4_how_many_lives_vf(struct mlx4_dev *dev) in mlx4_how_many_lives_vf() argument
709 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_how_many_lives_vf()
714 for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) { in mlx4_how_many_lives_vf()
718 mlx4_warn(dev, "%s: slave: %d is still active\n", in mlx4_how_many_lives_vf()
726 int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey) in mlx4_get_parav_qkey() argument
730 if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX || in mlx4_get_parav_qkey()
731 qpn < dev->phys_caps.base_proxy_sqpn) in mlx4_get_parav_qkey()
734 if (qpn >= dev->phys_caps.base_tunnel_sqpn) in mlx4_get_parav_qkey()
736 qk += qpn - dev->phys_caps.base_tunnel_sqpn; in mlx4_get_parav_qkey()
738 qk += qpn - dev->phys_caps.base_proxy_sqpn; in mlx4_get_parav_qkey()
744 void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port, int i, int val) in mlx4_sync_pkey_table() argument
746 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_sync_pkey_table()
748 if (!mlx4_is_master(dev)) in mlx4_sync_pkey_table()
755 void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid) in mlx4_put_slave_node_guid() argument
757 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_put_slave_node_guid()
759 if (!mlx4_is_master(dev)) in mlx4_put_slave_node_guid()
766 __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave) in mlx4_get_slave_node_guid() argument
768 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_get_slave_node_guid()
770 if (!mlx4_is_master(dev)) in mlx4_get_slave_node_guid()
777 int mlx4_is_slave_active(struct mlx4_dev *dev, int slave) in mlx4_is_slave_active() argument
779 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_is_slave_active()
782 if (!mlx4_is_master(dev)) in mlx4_is_slave_active()
790 static void slave_adjust_steering_mode(struct mlx4_dev *dev, in slave_adjust_steering_mode() argument
794 dev->caps.steering_mode = hca_param->steering_mode; in slave_adjust_steering_mode()
795 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) { in slave_adjust_steering_mode()
796 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in slave_adjust_steering_mode()
797 dev->caps.fs_log_max_ucast_qp_range_size = in slave_adjust_steering_mode()
800 dev->caps.num_qp_per_mgm = in slave_adjust_steering_mode()
803 mlx4_dbg(dev, "Steering mode is: %s\n", in slave_adjust_steering_mode()
804 mlx4_steering_mode_str(dev->caps.steering_mode)); in slave_adjust_steering_mode()
807 static int mlx4_slave_cap(struct mlx4_dev *dev) in mlx4_slave_cap() argument
817 err = mlx4_QUERY_HCA(dev, &hca_param); in mlx4_slave_cap()
819 mlx4_err(dev, "QUERY_HCA command failed, aborting\n"); in mlx4_slave_cap()
827 mlx4_err(dev, "Unknown hca global capabilities\n"); in mlx4_slave_cap()
833 dev->caps.hca_core_clock = hca_param.hca_core_clock; in mlx4_slave_cap()
836 dev->caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp; in mlx4_slave_cap()
837 err = mlx4_dev_cap(dev, &dev_cap); in mlx4_slave_cap()
839 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_slave_cap()
843 err = mlx4_QUERY_FW(dev); in mlx4_slave_cap()
845 mlx4_err(dev, "QUERY_FW command failed: could not get FW version\n"); in mlx4_slave_cap()
847 page_size = ~dev->caps.page_size_cap + 1; in mlx4_slave_cap()
848 mlx4_warn(dev, "HCA minimum page size:%d\n", page_size); in mlx4_slave_cap()
850 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_slave_cap()
856 dev->uar_page_shift = hca_param.uar_page_sz + 12; in mlx4_slave_cap()
859 if (dev->uar_page_shift > PAGE_SHIFT) { in mlx4_slave_cap()
860 mlx4_err(dev, in mlx4_slave_cap()
866 mlx4_set_num_reserved_uars(dev, &dev_cap); in mlx4_slave_cap()
872 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_slave_cap()
875 err = mlx4_QUERY_FUNC_CAP(dev, 0, &func_cap); in mlx4_slave_cap()
877 mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d)\n", in mlx4_slave_cap()
884 mlx4_err(dev, "Unknown pf context behaviour %x known flags %x\n", in mlx4_slave_cap()
889 dev->caps.num_ports = func_cap.num_ports; in mlx4_slave_cap()
890 dev->quotas.qp = func_cap.qp_quota; in mlx4_slave_cap()
891 dev->quotas.srq = func_cap.srq_quota; in mlx4_slave_cap()
892 dev->quotas.cq = func_cap.cq_quota; in mlx4_slave_cap()
893 dev->quotas.mpt = func_cap.mpt_quota; in mlx4_slave_cap()
894 dev->quotas.mtt = func_cap.mtt_quota; in mlx4_slave_cap()
895 dev->caps.num_qps = 1 << hca_param.log_num_qps; in mlx4_slave_cap()
896 dev->caps.num_srqs = 1 << hca_param.log_num_srqs; in mlx4_slave_cap()
897 dev->caps.num_cqs = 1 << hca_param.log_num_cqs; in mlx4_slave_cap()
898 dev->caps.num_mpts = 1 << hca_param.log_mpt_sz; in mlx4_slave_cap()
899 dev->caps.num_eqs = func_cap.max_eq; in mlx4_slave_cap()
900 dev->caps.reserved_eqs = func_cap.reserved_eq; in mlx4_slave_cap()
901 dev->caps.reserved_lkey = func_cap.reserved_lkey; in mlx4_slave_cap()
902 dev->caps.num_pds = MLX4_NUM_PDS; in mlx4_slave_cap()
903 dev->caps.num_mgms = 0; in mlx4_slave_cap()
904 dev->caps.num_amgms = 0; in mlx4_slave_cap()
906 if (dev->caps.num_ports > MLX4_MAX_PORTS) { in mlx4_slave_cap()
907 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_slave_cap()
908 dev->caps.num_ports, MLX4_MAX_PORTS); in mlx4_slave_cap()
912 mlx4_replace_zero_macs(dev); in mlx4_slave_cap()
914 dev->caps.qp0_qkey = kcalloc(dev->caps.num_ports, sizeof(u32), GFP_KERNEL); in mlx4_slave_cap()
915 dev->caps.qp0_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
916 dev->caps.qp0_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
917 dev->caps.qp1_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
918 dev->caps.qp1_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
920 if (!dev->caps.qp0_tunnel || !dev->caps.qp0_proxy || in mlx4_slave_cap()
921 !dev->caps.qp1_tunnel || !dev->caps.qp1_proxy || in mlx4_slave_cap()
922 !dev->caps.qp0_qkey) { in mlx4_slave_cap()
927 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_slave_cap()
928 err = mlx4_QUERY_FUNC_CAP(dev, i, &func_cap); in mlx4_slave_cap()
930 mlx4_err(dev, "QUERY_FUNC_CAP port command failed for port %d, aborting (%d)\n", in mlx4_slave_cap()
934 dev->caps.qp0_qkey[i - 1] = func_cap.qp0_qkey; in mlx4_slave_cap()
935 dev->caps.qp0_tunnel[i - 1] = func_cap.qp0_tunnel_qpn; in mlx4_slave_cap()
936 dev->caps.qp0_proxy[i - 1] = func_cap.qp0_proxy_qpn; in mlx4_slave_cap()
937 dev->caps.qp1_tunnel[i - 1] = func_cap.qp1_tunnel_qpn; in mlx4_slave_cap()
938 dev->caps.qp1_proxy[i - 1] = func_cap.qp1_proxy_qpn; in mlx4_slave_cap()
939 dev->caps.port_mask[i] = dev->caps.port_type[i]; in mlx4_slave_cap()
940 dev->caps.phys_port_id[i] = func_cap.phys_port_id; in mlx4_slave_cap()
941 err = mlx4_get_slave_pkey_gid_tbl_len(dev, i, in mlx4_slave_cap()
942 &dev->caps.gid_table_len[i], in mlx4_slave_cap()
943 &dev->caps.pkey_table_len[i]); in mlx4_slave_cap()
948 if (dev->caps.uar_page_size * (dev->caps.num_uars - in mlx4_slave_cap()
949 dev->caps.reserved_uars) > in mlx4_slave_cap()
950 pci_resource_len(dev->persist->pdev, in mlx4_slave_cap()
952 …mlx4_err(dev, "HCA reported UAR region size of 0x%x bigger than PCI resource 2 size of 0x%llx, abo… in mlx4_slave_cap()
953 dev->caps.uar_page_size * dev->caps.num_uars, in mlx4_slave_cap()
955 pci_resource_len(dev->persist->pdev, 2)); in mlx4_slave_cap()
961 dev->caps.eqe_size = 64; in mlx4_slave_cap()
962 dev->caps.eqe_factor = 1; in mlx4_slave_cap()
964 dev->caps.eqe_size = 32; in mlx4_slave_cap()
965 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
969 dev->caps.cqe_size = 64; in mlx4_slave_cap()
970 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
972 dev->caps.cqe_size = 32; in mlx4_slave_cap()
976 dev->caps.eqe_size = hca_param.eqe_size; in mlx4_slave_cap()
977 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
981 dev->caps.cqe_size = hca_param.cqe_size; in mlx4_slave_cap()
983 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
986 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_slave_cap()
987 mlx4_warn(dev, "Timestamping is not supported in slave mode\n"); in mlx4_slave_cap()
989 slave_adjust_steering_mode(dev, &dev_cap, &hca_param); in mlx4_slave_cap()
990 mlx4_dbg(dev, "RSS support for IP fragments is %s\n", in mlx4_slave_cap()
994 dev->caps.bf_reg_size) in mlx4_slave_cap()
995 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_ETH_BF_QP; in mlx4_slave_cap()
998 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_A0_QP; in mlx4_slave_cap()
1003 kfree(dev->caps.qp0_qkey); in mlx4_slave_cap()
1004 kfree(dev->caps.qp0_tunnel); in mlx4_slave_cap()
1005 kfree(dev->caps.qp0_proxy); in mlx4_slave_cap()
1006 kfree(dev->caps.qp1_tunnel); in mlx4_slave_cap()
1007 kfree(dev->caps.qp1_proxy); in mlx4_slave_cap()
1008 dev->caps.qp0_qkey = NULL; in mlx4_slave_cap()
1009 dev->caps.qp0_tunnel = NULL; in mlx4_slave_cap()
1010 dev->caps.qp0_proxy = NULL; in mlx4_slave_cap()
1011 dev->caps.qp1_tunnel = NULL; in mlx4_slave_cap()
1012 dev->caps.qp1_proxy = NULL; in mlx4_slave_cap()
1017 static void mlx4_request_modules(struct mlx4_dev *dev) in mlx4_request_modules() argument
1025 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_request_modules()
1026 if (dev->caps.port_type[port] == MLX4_PORT_TYPE_IB) in mlx4_request_modules()
1028 else if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) in mlx4_request_modules()
1034 if (has_ib_port || (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE)) in mlx4_request_modules()
1042 int mlx4_change_port_types(struct mlx4_dev *dev, in mlx4_change_port_types() argument
1049 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_change_port_types()
1052 if (port_types[port] != dev->caps.port_type[port + 1]) in mlx4_change_port_types()
1056 mlx4_unregister_device(dev); in mlx4_change_port_types()
1057 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_change_port_types()
1058 mlx4_CLOSE_PORT(dev, port); in mlx4_change_port_types()
1059 dev->caps.port_type[port] = port_types[port - 1]; in mlx4_change_port_types()
1060 err = mlx4_SET_PORT(dev, port, -1); in mlx4_change_port_types()
1062 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_change_port_types()
1067 mlx4_set_port_mask(dev); in mlx4_change_port_types()
1068 err = mlx4_register_device(dev); in mlx4_change_port_types()
1070 mlx4_err(dev, "Failed to register device\n"); in mlx4_change_port_types()
1073 mlx4_request_modules(dev); in mlx4_change_port_types()
1080 static ssize_t show_port_type(struct device *dev, in show_port_type() argument
1086 struct mlx4_dev *mdev = info->dev; in show_port_type()
1103 struct mlx4_dev *mdev = info->dev; in __set_port_type()
1167 static ssize_t set_port_type(struct device *dev, in set_port_type() argument
1173 struct mlx4_dev *mdev = info->dev; in set_port_type()
1232 static ssize_t show_port_ib_mtu(struct device *dev, in show_port_ib_mtu() argument
1238 struct mlx4_dev *mdev = info->dev; in show_port_ib_mtu()
1245 static ssize_t set_port_ib_mtu(struct device *dev, in set_port_ib_mtu() argument
1251 struct mlx4_dev *mdev = info->dev; in set_port_ib_mtu()
1292 static int mlx4_mf_bond(struct mlx4_dev *dev) in mlx4_mf_bond() argument
1300 slaves_port1 = mlx4_phys_to_slaves_pport(dev, 1); in mlx4_mf_bond()
1301 slaves_port2 = mlx4_phys_to_slaves_pport(dev, 2); in mlx4_mf_bond()
1304 dev->persist->num_vfs + 1); in mlx4_mf_bond()
1307 if (bitmap_weight(slaves_port_1_2, dev->persist->num_vfs + 1) > 1) { in mlx4_mf_bond()
1308 mlx4_warn(dev, "HA mode unsupported for dual ported VFs\n"); in mlx4_mf_bond()
1315 nvfs = bitmap_weight(slaves_port1.slaves, dev->persist->num_vfs + 1) + in mlx4_mf_bond()
1316 bitmap_weight(slaves_port2.slaves, dev->persist->num_vfs + 1) - 2; in mlx4_mf_bond()
1320 mlx4_warn(dev, "HA mode is not supported for %d VFs (max %d are allowed)\n", in mlx4_mf_bond()
1325 if (dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) { in mlx4_mf_bond()
1326 mlx4_warn(dev, "HA mode unsupported for NON DMFS steering\n"); in mlx4_mf_bond()
1330 err = mlx4_bond_mac_table(dev); in mlx4_mf_bond()
1333 err = mlx4_bond_vlan_table(dev); in mlx4_mf_bond()
1336 err = mlx4_bond_fs_rules(dev); in mlx4_mf_bond()
1342 (void)mlx4_unbond_vlan_table(dev); in mlx4_mf_bond()
1344 (void)mlx4_unbond_mac_table(dev); in mlx4_mf_bond()
1348 static int mlx4_mf_unbond(struct mlx4_dev *dev) in mlx4_mf_unbond() argument
1352 ret = mlx4_unbond_fs_rules(dev); in mlx4_mf_unbond()
1354 mlx4_warn(dev, "multifunction unbond for flow rules failedi (%d)\n", ret); in mlx4_mf_unbond()
1355 ret1 = mlx4_unbond_mac_table(dev); in mlx4_mf_unbond()
1357 mlx4_warn(dev, "multifunction unbond for MAC table failed (%d)\n", ret1); in mlx4_mf_unbond()
1360 ret1 = mlx4_unbond_vlan_table(dev); in mlx4_mf_unbond()
1362 mlx4_warn(dev, "multifunction unbond for VLAN table failed (%d)\n", ret1); in mlx4_mf_unbond()
1368 int mlx4_bond(struct mlx4_dev *dev) in mlx4_bond() argument
1371 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_bond()
1375 if (!mlx4_is_bonded(dev)) { in mlx4_bond()
1376 ret = mlx4_do_bond(dev, true); in mlx4_bond()
1378 mlx4_err(dev, "Failed to bond device: %d\n", ret); in mlx4_bond()
1379 if (!ret && mlx4_is_master(dev)) { in mlx4_bond()
1380 ret = mlx4_mf_bond(dev); in mlx4_bond()
1382 mlx4_err(dev, "bond for multifunction failed\n"); in mlx4_bond()
1383 mlx4_do_bond(dev, false); in mlx4_bond()
1390 mlx4_dbg(dev, "Device is bonded\n"); in mlx4_bond()
1396 int mlx4_unbond(struct mlx4_dev *dev) in mlx4_unbond() argument
1399 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unbond()
1403 if (mlx4_is_bonded(dev)) { in mlx4_unbond()
1406 ret = mlx4_do_bond(dev, false); in mlx4_unbond()
1408 mlx4_err(dev, "Failed to unbond device: %d\n", ret); in mlx4_unbond()
1409 if (mlx4_is_master(dev)) in mlx4_unbond()
1410 ret2 = mlx4_mf_unbond(dev); in mlx4_unbond()
1412 mlx4_warn(dev, "Failed to unbond device for multifunction (%d)\n", ret2); in mlx4_unbond()
1419 mlx4_dbg(dev, "Device is unbonded\n"); in mlx4_unbond()
1426 int mlx4_port_map_set(struct mlx4_dev *dev, struct mlx4_port_map *v2p) in mlx4_port_map_set() argument
1430 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_port_map_set()
1433 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_REMAP)) in mlx4_port_map_set()
1454 err = mlx4_virt2phy_port_map(dev, port1, port2); in mlx4_port_map_set()
1456 mlx4_dbg(dev, "port map changed: [%d][%d]\n", in mlx4_port_map_set()
1461 mlx4_err(dev, "Failed to change port mape: %d\n", err); in mlx4_port_map_set()
1470 static int mlx4_load_fw(struct mlx4_dev *dev) in mlx4_load_fw() argument
1472 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_load_fw()
1475 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages, in mlx4_load_fw()
1478 mlx4_err(dev, "Couldn't allocate FW area, aborting\n"); in mlx4_load_fw()
1482 err = mlx4_MAP_FA(dev, priv->fw.fw_icm); in mlx4_load_fw()
1484 mlx4_err(dev, "MAP_FA command failed, aborting\n"); in mlx4_load_fw()
1488 err = mlx4_RUN_FW(dev); in mlx4_load_fw()
1490 mlx4_err(dev, "RUN_FW command failed, aborting\n"); in mlx4_load_fw()
1497 mlx4_UNMAP_FA(dev); in mlx4_load_fw()
1500 mlx4_free_icm(dev, priv->fw.fw_icm, 0); in mlx4_load_fw()
1504 static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base, in mlx4_init_cmpt_table() argument
1507 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_cmpt_table()
1511 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table, in mlx4_init_cmpt_table()
1515 cmpt_entry_sz, dev->caps.num_qps, in mlx4_init_cmpt_table()
1516 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_cmpt_table()
1521 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table, in mlx4_init_cmpt_table()
1525 cmpt_entry_sz, dev->caps.num_srqs, in mlx4_init_cmpt_table()
1526 dev->caps.reserved_srqs, 0, 0); in mlx4_init_cmpt_table()
1530 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table, in mlx4_init_cmpt_table()
1534 cmpt_entry_sz, dev->caps.num_cqs, in mlx4_init_cmpt_table()
1535 dev->caps.reserved_cqs, 0, 0); in mlx4_init_cmpt_table()
1539 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_cmpt_table()
1540 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table, in mlx4_init_cmpt_table()
1551 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_cmpt_table()
1554 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_cmpt_table()
1557 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_cmpt_table()
1563 static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_init_icm() argument
1566 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_icm()
1571 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages); in mlx4_init_icm()
1573 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting\n"); in mlx4_init_icm()
1577 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory\n", in mlx4_init_icm()
1581 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages, in mlx4_init_icm()
1584 mlx4_err(dev, "Couldn't allocate aux memory, aborting\n"); in mlx4_init_icm()
1588 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm); in mlx4_init_icm()
1590 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting\n"); in mlx4_init_icm()
1594 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz); in mlx4_init_icm()
1596 mlx4_err(dev, "Failed to map cMPT context memory, aborting\n"); in mlx4_init_icm()
1601 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_icm()
1602 err = mlx4_init_icm_table(dev, &priv->eq_table.table, in mlx4_init_icm()
1606 mlx4_err(dev, "Failed to map EQ context memory, aborting\n"); in mlx4_init_icm()
1617 dev->caps.reserved_mtts = in mlx4_init_icm()
1618 ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz, in mlx4_init_icm()
1619 dma_get_cache_alignment()) / dev->caps.mtt_entry_sz; in mlx4_init_icm()
1621 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table, in mlx4_init_icm()
1623 dev->caps.mtt_entry_sz, in mlx4_init_icm()
1624 dev->caps.num_mtts, in mlx4_init_icm()
1625 dev->caps.reserved_mtts, 1, 0); in mlx4_init_icm()
1627 mlx4_err(dev, "Failed to map MTT context memory, aborting\n"); in mlx4_init_icm()
1631 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table, in mlx4_init_icm()
1634 dev->caps.num_mpts, in mlx4_init_icm()
1635 dev->caps.reserved_mrws, 1, 1); in mlx4_init_icm()
1637 mlx4_err(dev, "Failed to map dMPT context memory, aborting\n"); in mlx4_init_icm()
1641 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table, in mlx4_init_icm()
1644 dev->caps.num_qps, in mlx4_init_icm()
1645 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1648 mlx4_err(dev, "Failed to map QP context memory, aborting\n"); in mlx4_init_icm()
1652 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table, in mlx4_init_icm()
1655 dev->caps.num_qps, in mlx4_init_icm()
1656 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1659 mlx4_err(dev, "Failed to map AUXC context memory, aborting\n"); in mlx4_init_icm()
1663 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table, in mlx4_init_icm()
1666 dev->caps.num_qps, in mlx4_init_icm()
1667 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1670 mlx4_err(dev, "Failed to map ALTC context memory, aborting\n"); in mlx4_init_icm()
1674 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table, in mlx4_init_icm()
1677 dev->caps.num_qps, in mlx4_init_icm()
1678 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1681 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n"); in mlx4_init_icm()
1685 err = mlx4_init_icm_table(dev, &priv->cq_table.table, in mlx4_init_icm()
1688 dev->caps.num_cqs, in mlx4_init_icm()
1689 dev->caps.reserved_cqs, 0, 0); in mlx4_init_icm()
1691 mlx4_err(dev, "Failed to map CQ context memory, aborting\n"); in mlx4_init_icm()
1695 err = mlx4_init_icm_table(dev, &priv->srq_table.table, in mlx4_init_icm()
1698 dev->caps.num_srqs, in mlx4_init_icm()
1699 dev->caps.reserved_srqs, 0, 0); in mlx4_init_icm()
1701 mlx4_err(dev, "Failed to map SRQ context memory, aborting\n"); in mlx4_init_icm()
1712 err = mlx4_init_icm_table(dev, &priv->mcg_table.table, in mlx4_init_icm()
1714 mlx4_get_mgm_entry_size(dev), in mlx4_init_icm()
1715 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1716 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1719 mlx4_err(dev, "Failed to map MCG context memory, aborting\n"); in mlx4_init_icm()
1726 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_init_icm()
1729 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_init_icm()
1732 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_init_icm()
1735 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_init_icm()
1738 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_init_icm()
1741 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_init_icm()
1744 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_init_icm()
1747 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_init_icm()
1750 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_init_icm()
1753 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_init_icm()
1754 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_icm()
1755 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_icm()
1756 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_icm()
1759 mlx4_UNMAP_ICM_AUX(dev); in mlx4_init_icm()
1762 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_init_icm()
1767 static void mlx4_free_icms(struct mlx4_dev *dev) in mlx4_free_icms() argument
1769 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_free_icms()
1771 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table); in mlx4_free_icms()
1772 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_free_icms()
1773 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_free_icms()
1774 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_free_icms()
1775 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_free_icms()
1776 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_free_icms()
1777 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_free_icms()
1778 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_free_icms()
1779 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_free_icms()
1780 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_free_icms()
1781 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_free_icms()
1782 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_free_icms()
1783 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_free_icms()
1784 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_free_icms()
1786 mlx4_UNMAP_ICM_AUX(dev); in mlx4_free_icms()
1787 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_free_icms()
1790 static void mlx4_slave_exit(struct mlx4_dev *dev) in mlx4_slave_exit() argument
1792 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_slave_exit()
1795 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, in mlx4_slave_exit()
1797 mlx4_warn(dev, "Failed to close slave function\n"); in mlx4_slave_exit()
1801 static int map_bf_area(struct mlx4_dev *dev) in map_bf_area() argument
1803 struct mlx4_priv *priv = mlx4_priv(dev); in map_bf_area()
1808 if (!dev->caps.bf_reg_size) in map_bf_area()
1811 bf_start = pci_resource_start(dev->persist->pdev, 2) + in map_bf_area()
1812 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1813 bf_len = pci_resource_len(dev->persist->pdev, 2) - in map_bf_area()
1814 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1822 static void unmap_bf_area(struct mlx4_dev *dev) in unmap_bf_area() argument
1824 if (mlx4_priv(dev)->bf_mapping) in unmap_bf_area()
1825 io_mapping_free(mlx4_priv(dev)->bf_mapping); in unmap_bf_area()
1828 s64 mlx4_read_clock(struct mlx4_dev *dev) in mlx4_read_clock() argument
1833 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_read_clock()
1853 static int map_internal_clock(struct mlx4_dev *dev) in map_internal_clock() argument
1855 struct mlx4_priv *priv = mlx4_priv(dev); in map_internal_clock()
1858 ioremap(pci_resource_start(dev->persist->pdev, in map_internal_clock()
1868 int mlx4_get_internal_clock_params(struct mlx4_dev *dev, in mlx4_get_internal_clock_params() argument
1871 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_internal_clock_params()
1873 if (mlx4_is_slave(dev)) in mlx4_get_internal_clock_params()
1876 if (!dev->caps.map_clock_to_user) { in mlx4_get_internal_clock_params()
1877 mlx4_dbg(dev, "Map clock to user is not supported.\n"); in mlx4_get_internal_clock_params()
1892 static void unmap_internal_clock(struct mlx4_dev *dev) in unmap_internal_clock() argument
1894 struct mlx4_priv *priv = mlx4_priv(dev); in unmap_internal_clock()
1900 static void mlx4_close_hca(struct mlx4_dev *dev) in mlx4_close_hca() argument
1902 sysctl_ctx_free(&dev->hw_ctx); in mlx4_close_hca()
1903 unmap_internal_clock(dev); in mlx4_close_hca()
1904 unmap_bf_area(dev); in mlx4_close_hca()
1905 if (mlx4_is_slave(dev)) in mlx4_close_hca()
1906 mlx4_slave_exit(dev); in mlx4_close_hca()
1908 mlx4_CLOSE_HCA(dev, 0); in mlx4_close_hca()
1909 mlx4_free_icms(dev); in mlx4_close_hca()
1913 static void mlx4_close_fw(struct mlx4_dev *dev) in mlx4_close_fw() argument
1915 if (!mlx4_is_slave(dev)) { in mlx4_close_fw()
1916 mlx4_UNMAP_FA(dev); in mlx4_close_fw()
1917 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0); in mlx4_close_fw()
1921 static int mlx4_comm_check_offline(struct mlx4_dev *dev) in mlx4_comm_check_offline() argument
1928 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_comm_check_offline()
1945 mlx4_err(dev, "Communication channel is offline.\n"); in mlx4_comm_check_offline()
1949 static void mlx4_reset_vf_support(struct mlx4_dev *dev) in mlx4_reset_vf_support() argument
1953 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_reset_vf_support()
1962 dev->caps.vf_caps |= MLX4_VF_CAP_FLAG_RESET; in mlx4_reset_vf_support()
1965 static int mlx4_init_slave(struct mlx4_dev *dev) in mlx4_init_slave() argument
1967 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_slave()
1974 mlx4_warn(dev, "PF is not ready - Deferring probe\n"); in mlx4_init_slave()
1980 if (mlx4_comm_check_offline(dev)) { in mlx4_init_slave()
1981 mlx4_err(dev, "PF is not responsive, skipping initialization\n"); in mlx4_init_slave()
1985 mlx4_reset_vf_support(dev); in mlx4_init_slave()
1986 mlx4_warn(dev, "Sending reset\n"); in mlx4_init_slave()
1987 ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, in mlx4_init_slave()
1993 mlx4_warn(dev, "slave is currently in the middle of FLR - Deferring probe\n"); in mlx4_init_slave()
2007 mlx4_err(dev, "slave driver version is not supported by the master\n"); in mlx4_init_slave()
2011 mlx4_warn(dev, "Sending vhcr0\n"); in mlx4_init_slave()
2012 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48, in mlx4_init_slave()
2015 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32, in mlx4_init_slave()
2018 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16, in mlx4_init_slave()
2021 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, in mlx4_init_slave()
2029 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, 0); in mlx4_init_slave()
2035 static void mlx4_parav_master_pf_caps(struct mlx4_dev *dev) in mlx4_parav_master_pf_caps() argument
2039 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_parav_master_pf_caps()
2040 if (dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_parav_master_pf_caps()
2041 dev->caps.gid_table_len[i] = in mlx4_parav_master_pf_caps()
2042 mlx4_get_slave_num_gids(dev, 0, i); in mlx4_parav_master_pf_caps()
2044 dev->caps.gid_table_len[i] = 1; in mlx4_parav_master_pf_caps()
2045 dev->caps.pkey_table_len[i] = in mlx4_parav_master_pf_caps()
2046 dev->phys_caps.pkey_phys_table_len[i] - 1; in mlx4_parav_master_pf_caps()
2088 static void choose_steering_mode(struct mlx4_dev *dev, in choose_steering_mode() argument
2093 if (dev->caps.dmfs_high_steer_mode == in choose_steering_mode()
2095 mlx4_err(dev, "DMFS high rate mode not supported\n"); in choose_steering_mode()
2097 dev->caps.dmfs_high_steer_mode = in choose_steering_mode()
2104 (!mlx4_is_mfunc(dev) || in choose_steering_mode()
2106 (dev->persist->num_vfs + 1))) && in choose_steering_mode()
2109 dev->oper_log_mgm_entry_size = in choose_steering_mode()
2111 dev->caps.steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED; in choose_steering_mode()
2112 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in choose_steering_mode()
2113 dev->caps.fs_log_max_ucast_qp_range_size = in choose_steering_mode()
2116 if (dev->caps.dmfs_high_steer_mode != in choose_steering_mode()
2118 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DISABLE; in choose_steering_mode()
2119 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER && in choose_steering_mode()
2120 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
2121 dev->caps.steering_mode = MLX4_STEERING_MODE_B0; in choose_steering_mode()
2123 dev->caps.steering_mode = MLX4_STEERING_MODE_A0; in choose_steering_mode()
2125 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER || in choose_steering_mode()
2126 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
2127 …mlx4_warn(dev, "Must have both UC_STEER and MC_STEER flags set to use B0 steering - falling back t… in choose_steering_mode()
2129 dev->oper_log_mgm_entry_size = in choose_steering_mode()
2133 dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev); in choose_steering_mode()
2135 …mlx4_dbg(dev, "Steering mode is: %s, oper_log_mgm_entry_size = %d, modparam log_num_mgm_entry_size… in choose_steering_mode()
2136 mlx4_steering_mode_str(dev->caps.steering_mode), in choose_steering_mode()
2137 dev->oper_log_mgm_entry_size, in choose_steering_mode()
2141 static void choose_tunnel_offload_mode(struct mlx4_dev *dev, in choose_tunnel_offload_mode() argument
2144 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED && in choose_tunnel_offload_mode()
2146 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_VXLAN; in choose_tunnel_offload_mode()
2148 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_NONE; in choose_tunnel_offload_mode()
2150 mlx4_dbg(dev, "Tunneling offload mode is: %s\n", (dev->caps.tunnel_offload_mode in choose_tunnel_offload_mode()
2154 static int mlx4_validate_optimized_steering(struct mlx4_dev *dev) in mlx4_validate_optimized_steering() argument
2159 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_NOT_SUPPORTED) in mlx4_validate_optimized_steering()
2162 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_validate_optimized_steering()
2163 if (mlx4_dev_port(dev, i, &port_cap)) { in mlx4_validate_optimized_steering()
2164 mlx4_err(dev, in mlx4_validate_optimized_steering()
2166 } else if ((dev->caps.dmfs_high_steer_mode != in mlx4_validate_optimized_steering()
2169 !!(dev->caps.dmfs_high_steer_mode == in mlx4_validate_optimized_steering()
2171 mlx4_err(dev, in mlx4_validate_optimized_steering()
2174 dev->caps.dmfs_high_steer_mode), in mlx4_validate_optimized_steering()
2183 static int mlx4_init_fw(struct mlx4_dev *dev) in mlx4_init_fw() argument
2188 if (!mlx4_is_slave(dev)) { in mlx4_init_fw()
2189 err = mlx4_QUERY_FW(dev); in mlx4_init_fw()
2192 mlx4_info(dev, "non-primary physical function, skipping\n"); in mlx4_init_fw()
2194 mlx4_err(dev, "QUERY_FW command failed, aborting\n"); in mlx4_init_fw()
2198 err = mlx4_load_fw(dev); in mlx4_init_fw()
2200 mlx4_err(dev, "Failed to start FW, aborting\n"); in mlx4_init_fw()
2206 err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg); in mlx4_init_fw()
2208 mlx4_warn(dev, "Failed to override log_pg_sz parameter\n"); in mlx4_init_fw()
2214 static int mlx4_init_hca(struct mlx4_dev *dev) in mlx4_init_hca() argument
2216 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_hca()
2225 if (!mlx4_is_slave(dev)) { in mlx4_init_hca()
2226 err = mlx4_dev_cap(dev, &dev_cap); in mlx4_init_hca()
2228 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_init_hca()
2232 choose_steering_mode(dev, &dev_cap); in mlx4_init_hca()
2233 choose_tunnel_offload_mode(dev, &dev_cap); in mlx4_init_hca()
2235 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC && in mlx4_init_hca()
2236 mlx4_is_master(dev)) in mlx4_init_hca()
2237 dev->caps.function_caps |= MLX4_FUNC_CAP_DMFS_A0_STATIC; in mlx4_init_hca()
2239 err = mlx4_get_phys_port_id(dev); in mlx4_init_hca()
2241 mlx4_err(dev, "Fail to get physical port id\n"); in mlx4_init_hca()
2243 if (mlx4_is_master(dev)) in mlx4_init_hca()
2244 mlx4_parav_master_pf_caps(dev); in mlx4_init_hca()
2247 mlx4_info(dev, "Running from within kdump kernel. Using low memory profile\n"); in mlx4_init_hca()
2252 if (dev->caps.steering_mode == in mlx4_init_hca()
2256 icm_size = mlx4_make_profile(dev, &profile, &dev_cap, in mlx4_init_hca()
2263 dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1; in mlx4_init_hca()
2266 init_hca.log_uar_sz = ilog2(dev->caps.num_uars) + in mlx4_init_hca()
2270 init_hca.log_uar_sz = ilog2(dev->caps.num_uars); in mlx4_init_hca()
2275 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW || in mlx4_init_hca()
2276 dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) in mlx4_init_hca()
2279 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size); in mlx4_init_hca()
2283 err = mlx4_INIT_HCA(dev, &init_hca); in mlx4_init_hca()
2285 mlx4_err(dev, "INIT_HCA command failed, aborting\n"); in mlx4_init_hca()
2290 err = mlx4_query_func(dev, &dev_cap); in mlx4_init_hca()
2292 mlx4_err(dev, "QUERY_FUNC command failed, aborting.\n"); in mlx4_init_hca()
2295 dev->caps.num_eqs = dev_cap.max_eqs; in mlx4_init_hca()
2296 dev->caps.reserved_eqs = dev_cap.reserved_eqs; in mlx4_init_hca()
2297 dev->caps.reserved_uars = dev_cap.reserved_uars; in mlx4_init_hca()
2305 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) { in mlx4_init_hca()
2307 err = mlx4_QUERY_HCA(dev, &init_hca); in mlx4_init_hca()
2309 mlx4_err(dev, "QUERY_HCA command failed, disable timestamp\n"); in mlx4_init_hca()
2310 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2312 dev->caps.hca_core_clock = in mlx4_init_hca()
2319 if (!dev->caps.hca_core_clock) { in mlx4_init_hca()
2320 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2321 mlx4_err(dev, in mlx4_init_hca()
2323 } else if (map_internal_clock(dev)) { in mlx4_init_hca()
2328 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2329 mlx4_err(dev, "Failed to map internal clock. Timestamping is not supported\n"); in mlx4_init_hca()
2333 if (dev->caps.dmfs_high_steer_mode != in mlx4_init_hca()
2335 if (mlx4_validate_optimized_steering(dev)) in mlx4_init_hca()
2336 mlx4_warn(dev, "Optimized steering validation failed\n"); in mlx4_init_hca()
2338 if (dev->caps.dmfs_high_steer_mode == in mlx4_init_hca()
2340 dev->caps.dmfs_high_rate_qpn_base = in mlx4_init_hca()
2341 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_init_hca()
2342 dev->caps.dmfs_high_rate_qpn_range = in mlx4_init_hca()
2346 mlx4_dbg(dev, "DMFS high rate steer mode is: %s\n", in mlx4_init_hca()
2348 dev->caps.dmfs_high_steer_mode)); in mlx4_init_hca()
2351 err = mlx4_init_slave(dev); in mlx4_init_hca()
2354 mlx4_err(dev, "Failed to initialize slave\n"); in mlx4_init_hca()
2358 err = mlx4_slave_cap(dev); in mlx4_init_hca()
2360 mlx4_err(dev, "Failed to obtain slave caps\n"); in mlx4_init_hca()
2365 if (map_bf_area(dev)) in mlx4_init_hca()
2366 mlx4_dbg(dev, "Failed to map blue flame area\n"); in mlx4_init_hca()
2369 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2370 mlx4_set_port_mask(dev); in mlx4_init_hca()
2372 err = mlx4_QUERY_ADAPTER(dev, &adapter); in mlx4_init_hca()
2374 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting\n"); in mlx4_init_hca()
2379 err = mlx4_config_dev_retrieval(dev, &params); in mlx4_init_hca()
2381 mlx4_err(dev, "Failed to query CONFIG_DEV parameters\n"); in mlx4_init_hca()
2383 dev->caps.rx_checksum_flags_port[1] = params.rx_csum_flags_port_1; in mlx4_init_hca()
2384 dev->caps.rx_checksum_flags_port[2] = params.rx_csum_flags_port_2; in mlx4_init_hca()
2387 memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id); in mlx4_init_hca()
2392 unmap_internal_clock(dev); in mlx4_init_hca()
2393 unmap_bf_area(dev); in mlx4_init_hca()
2395 if (mlx4_is_slave(dev)) { in mlx4_init_hca()
2396 kfree(dev->caps.qp0_qkey); in mlx4_init_hca()
2397 kfree(dev->caps.qp0_tunnel); in mlx4_init_hca()
2398 kfree(dev->caps.qp0_proxy); in mlx4_init_hca()
2399 kfree(dev->caps.qp1_tunnel); in mlx4_init_hca()
2400 kfree(dev->caps.qp1_proxy); in mlx4_init_hca()
2404 if (mlx4_is_slave(dev)) in mlx4_init_hca()
2405 mlx4_slave_exit(dev); in mlx4_init_hca()
2407 mlx4_CLOSE_HCA(dev, 0); in mlx4_init_hca()
2410 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2411 mlx4_free_icms(dev); in mlx4_init_hca()
2416 static int mlx4_init_counters_table(struct mlx4_dev *dev) in mlx4_init_counters_table() argument
2418 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_counters_table()
2421 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_init_counters_table()
2424 if (!dev->caps.max_counters) in mlx4_init_counters_table()
2427 nent_pow2 = roundup_pow_of_two(dev->caps.max_counters); in mlx4_init_counters_table()
2431 nent_pow2 - dev->caps.max_counters + 1); in mlx4_init_counters_table()
2434 static void mlx4_cleanup_counters_table(struct mlx4_dev *dev) in mlx4_cleanup_counters_table() argument
2436 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_cleanup_counters_table()
2439 if (!dev->caps.max_counters) in mlx4_cleanup_counters_table()
2442 mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap); in mlx4_cleanup_counters_table()
2445 static void mlx4_cleanup_default_counters(struct mlx4_dev *dev) in mlx4_cleanup_default_counters() argument
2447 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_cleanup_default_counters()
2450 for (port = 0; port < dev->caps.num_ports; port++) in mlx4_cleanup_default_counters()
2452 mlx4_counter_free(dev, priv->def_counter[port]); in mlx4_cleanup_default_counters()
2455 static int mlx4_allocate_default_counters(struct mlx4_dev *dev) in mlx4_allocate_default_counters() argument
2457 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_allocate_default_counters()
2461 for (port = 0; port < dev->caps.num_ports; port++) in mlx4_allocate_default_counters()
2464 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_allocate_default_counters()
2465 err = mlx4_counter_alloc(dev, &idx); in mlx4_allocate_default_counters()
2472 } else if (mlx4_is_slave(dev) && err == -EINVAL) { in mlx4_allocate_default_counters()
2473 priv->def_counter[port] = MLX4_SINK_COUNTER_INDEX(dev); in mlx4_allocate_default_counters()
2474 mlx4_warn(dev, "can't allocate counter from old PF driver, using index %d\n", in mlx4_allocate_default_counters()
2475 MLX4_SINK_COUNTER_INDEX(dev)); in mlx4_allocate_default_counters()
2478 mlx4_err(dev, "%s: failed to allocate default counter port %d err %d\n", in mlx4_allocate_default_counters()
2480 mlx4_cleanup_default_counters(dev); in mlx4_allocate_default_counters()
2484 mlx4_dbg(dev, "%s: default counter index %d for port %d\n", in mlx4_allocate_default_counters()
2491 int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) in __mlx4_counter_alloc() argument
2493 struct mlx4_priv *priv = mlx4_priv(dev); in __mlx4_counter_alloc()
2495 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_alloc()
2500 *idx = MLX4_SINK_COUNTER_INDEX(dev); in __mlx4_counter_alloc()
2507 int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) in mlx4_counter_alloc() argument
2512 if (mlx4_is_mfunc(dev)) { in mlx4_counter_alloc()
2513 err = mlx4_cmd_imm(dev, 0, &out_param, RES_COUNTER, in mlx4_counter_alloc()
2521 return __mlx4_counter_alloc(dev, idx); in mlx4_counter_alloc()
2525 static int __mlx4_clear_if_stat(struct mlx4_dev *dev, in __mlx4_clear_if_stat() argument
2532 if_stat_mailbox = mlx4_alloc_cmd_mailbox(dev); in __mlx4_clear_if_stat()
2536 err = mlx4_cmd_box(dev, 0, if_stat_mailbox->dma, if_stat_in_mod, 0, in __mlx4_clear_if_stat()
2540 mlx4_free_cmd_mailbox(dev, if_stat_mailbox); in __mlx4_clear_if_stat()
2544 void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in __mlx4_counter_free() argument
2546 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_free()
2549 if (idx == MLX4_SINK_COUNTER_INDEX(dev)) in __mlx4_counter_free()
2552 __mlx4_clear_if_stat(dev, idx); in __mlx4_counter_free()
2554 mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx, MLX4_USE_RR); in __mlx4_counter_free()
2558 void mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in mlx4_counter_free() argument
2562 if (mlx4_is_mfunc(dev)) { in mlx4_counter_free()
2564 mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE, in mlx4_counter_free()
2569 __mlx4_counter_free(dev, idx); in mlx4_counter_free()
2573 int mlx4_get_default_counter_index(struct mlx4_dev *dev, int port) in mlx4_get_default_counter_index() argument
2575 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_default_counter_index()
2581 void mlx4_set_admin_guid(struct mlx4_dev *dev, __be64 guid, int entry, int port) in mlx4_set_admin_guid() argument
2583 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_admin_guid()
2589 __be64 mlx4_get_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_get_admin_guid() argument
2591 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_admin_guid()
2597 void mlx4_set_random_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_set_random_admin_guid() argument
2599 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_random_admin_guid()
2612 static int mlx4_setup_hca(struct mlx4_dev *dev) in mlx4_setup_hca() argument
2614 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_setup_hca()
2619 err = mlx4_init_uar_table(dev); in mlx4_setup_hca()
2621 mlx4_err(dev, "Failed to initialize user access region table, aborting\n"); in mlx4_setup_hca()
2625 err = mlx4_uar_alloc(dev, &priv->driver_uar); in mlx4_setup_hca()
2627 mlx4_err(dev, "Failed to allocate driver access region, aborting\n"); in mlx4_setup_hca()
2633 mlx4_err(dev, "Couldn't map kernel access region, aborting\n"); in mlx4_setup_hca()
2638 err = mlx4_init_pd_table(dev); in mlx4_setup_hca()
2640 mlx4_err(dev, "Failed to initialize protection domain table, aborting\n"); in mlx4_setup_hca()
2644 err = mlx4_init_xrcd_table(dev); in mlx4_setup_hca()
2646 mlx4_err(dev, "Failed to initialize reliable connection domain table, aborting\n"); in mlx4_setup_hca()
2650 err = mlx4_init_mr_table(dev); in mlx4_setup_hca()
2652 mlx4_err(dev, "Failed to initialize memory region table, aborting\n"); in mlx4_setup_hca()
2656 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2657 err = mlx4_init_mcg_table(dev); in mlx4_setup_hca()
2659 mlx4_err(dev, "Failed to initialize multicast group table, aborting\n"); in mlx4_setup_hca()
2662 err = mlx4_config_mad_demux(dev); in mlx4_setup_hca()
2664 mlx4_err(dev, "Failed in config_mad_demux, aborting\n"); in mlx4_setup_hca()
2669 err = mlx4_init_eq_table(dev); in mlx4_setup_hca()
2671 mlx4_err(dev, "Failed to initialize event queue table, aborting\n"); in mlx4_setup_hca()
2675 err = mlx4_cmd_use_events(dev); in mlx4_setup_hca()
2677 mlx4_err(dev, "Failed to switch to event-driven firmware commands, aborting\n"); in mlx4_setup_hca()
2681 err = mlx4_NOP(dev); in mlx4_setup_hca()
2683 if (dev->flags & MLX4_FLAG_MSI_X) { in mlx4_setup_hca()
2684 mlx4_warn(dev, "NOP command failed to generate MSI-X interrupt IRQ %d)\n", in mlx4_setup_hca()
2686 mlx4_warn(dev, "Trying again without MSI-X\n"); in mlx4_setup_hca()
2688 mlx4_err(dev, "NOP command failed to generate interrupt (IRQ %d), aborting\n", in mlx4_setup_hca()
2690 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n"); in mlx4_setup_hca()
2696 mlx4_dbg(dev, "NOP command IRQ test passed\n"); in mlx4_setup_hca()
2698 err = mlx4_init_cq_table(dev); in mlx4_setup_hca()
2700 mlx4_err(dev, "Failed to initialize completion queue table, aborting\n"); in mlx4_setup_hca()
2704 err = mlx4_init_srq_table(dev); in mlx4_setup_hca()
2706 mlx4_err(dev, "Failed to initialize shared receive queue table, aborting\n"); in mlx4_setup_hca()
2710 err = mlx4_init_qp_table(dev); in mlx4_setup_hca()
2712 mlx4_err(dev, "Failed to initialize queue pair table, aborting\n"); in mlx4_setup_hca()
2716 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2717 err = mlx4_init_counters_table(dev); in mlx4_setup_hca()
2719 mlx4_err(dev, "Failed to initialize counters table, aborting\n"); in mlx4_setup_hca()
2724 err = mlx4_allocate_default_counters(dev); in mlx4_setup_hca()
2726 mlx4_err(dev, "Failed to allocate default counters, aborting\n"); in mlx4_setup_hca()
2730 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2731 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_setup_hca()
2733 err = mlx4_get_port_ib_caps(dev, port, in mlx4_setup_hca()
2736 mlx4_warn(dev, "failed to get port %d default ib capabilities (%d). Continuing with caps = 0\n", in mlx4_setup_hca()
2738 dev->caps.ib_port_def_cap[port] = ib_port_default_caps; in mlx4_setup_hca()
2741 if (mlx4_is_master(dev)) { in mlx4_setup_hca()
2743 for (i = 0; i < dev->num_slaves; i++) { in mlx4_setup_hca()
2744 if (i == mlx4_master_func_num(dev)) in mlx4_setup_hca()
2751 if (mlx4_is_mfunc(dev)) in mlx4_setup_hca()
2752 dev->caps.port_ib_mtu[port] = IB_MTU_2048; in mlx4_setup_hca()
2754 dev->caps.port_ib_mtu[port] = IB_MTU_4096; in mlx4_setup_hca()
2756 err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ? in mlx4_setup_hca()
2757 dev->caps.pkey_table_len[port] : -1); in mlx4_setup_hca()
2759 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_setup_hca()
2769 mlx4_cleanup_default_counters(dev); in mlx4_setup_hca()
2772 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2773 mlx4_cleanup_counters_table(dev); in mlx4_setup_hca()
2776 mlx4_cleanup_qp_table(dev); in mlx4_setup_hca()
2779 mlx4_cleanup_srq_table(dev); in mlx4_setup_hca()
2782 mlx4_cleanup_cq_table(dev); in mlx4_setup_hca()
2785 mlx4_cmd_use_polling(dev); in mlx4_setup_hca()
2788 mlx4_cleanup_eq_table(dev); in mlx4_setup_hca()
2791 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2792 mlx4_cleanup_mcg_table(dev); in mlx4_setup_hca()
2795 mlx4_cleanup_mr_table(dev); in mlx4_setup_hca()
2798 mlx4_cleanup_xrcd_table(dev); in mlx4_setup_hca()
2801 mlx4_cleanup_pd_table(dev); in mlx4_setup_hca()
2807 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_setup_hca()
2810 mlx4_cleanup_uar_table(dev); in mlx4_setup_hca()
2814 static int mlx4_init_affinity_hint(struct mlx4_dev *dev, int port, int eqn) in mlx4_init_affinity_hint() argument
2817 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_affinity_hint()
2822 if (eqn > dev->caps.num_comp_vectors) in mlx4_init_affinity_hint()
2826 off += mlx4_get_eqs_per_port(dev, i); in mlx4_init_affinity_hint()
2841 static void mlx4_enable_msi_x(struct mlx4_dev *dev) in mlx4_enable_msi_x() argument
2843 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_enable_msi_x()
2849 int nreq = dev->caps.num_ports * num_online_cpus() + 1; in mlx4_enable_msi_x()
2851 nreq = min_t(int, dev->caps.num_eqs - dev->caps.reserved_eqs, in mlx4_enable_msi_x()
2863 nreq = pci_enable_msix_range(dev->persist->pdev, entries, 2, in mlx4_enable_msi_x()
2871 dev->caps.num_comp_vectors = nreq - 1; in mlx4_enable_msi_x()
2875 dev->caps.num_ports); in mlx4_enable_msi_x()
2877 for (i = 0; i < dev->caps.num_comp_vectors + 1; i++) { in mlx4_enable_msi_x()
2884 if (MLX4_IS_LEGACY_EQ_MODE(dev->caps)) { in mlx4_enable_msi_x()
2886 dev->caps.num_ports); in mlx4_enable_msi_x()
2893 if (mlx4_init_affinity_hint(dev, port + 1, i)) in mlx4_enable_msi_x()
2894 mlx4_warn(dev, "Couldn't init hint cpumask for EQ %d\n", in mlx4_enable_msi_x()
2906 if ((dev->caps.num_comp_vectors > dev->caps.num_ports) && in mlx4_enable_msi_x()
2908 (dev->caps.num_comp_vectors / dev->caps.num_ports)) == in mlx4_enable_msi_x()
2916 dev->flags |= MLX4_FLAG_MSI_X; in mlx4_enable_msi_x()
2923 dev->caps.num_comp_vectors = 1; in mlx4_enable_msi_x()
2927 priv->eq_table.eq[i].irq = dev->persist->pdev->irq; in mlx4_enable_msi_x()
2930 dev->caps.num_ports); in mlx4_enable_msi_x()
2935 static int mlx4_init_port_info(struct mlx4_dev *dev, int port) in mlx4_init_port_info() argument
2937 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; in mlx4_init_port_info()
2940 info->dev = dev; in mlx4_init_port_info()
2942 if (!mlx4_is_slave(dev)) { in mlx4_init_port_info()
2943 mlx4_init_mac_table(dev, &info->mac_table); in mlx4_init_port_info()
2944 mlx4_init_vlan_table(dev, &info->vlan_table); in mlx4_init_port_info()
2945 mlx4_init_roce_gid_table(dev, &info->gid_table); in mlx4_init_port_info()
2946 info->base_qpn = mlx4_get_base_qpn(dev, port); in mlx4_init_port_info()
2951 if (mlx4_is_mfunc(dev)) in mlx4_init_port_info()
2960 err = device_create_file(&dev->persist->pdev->dev, &info->port_attr); in mlx4_init_port_info()
2962 mlx4_err(dev, "Failed to create file for port %d\n", port); in mlx4_init_port_info()
2968 if (mlx4_is_mfunc(dev)) in mlx4_init_port_info()
2977 err = device_create_file(&dev->persist->pdev->dev, in mlx4_init_port_info()
2980 mlx4_err(dev, "Failed to create mtu file for port %d\n", port); in mlx4_init_port_info()
2981 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_init_port_info()
2994 device_remove_file(&info->dev->persist->pdev->dev, &info->port_attr); in mlx4_cleanup_port_info()
2995 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_cleanup_port_info()
3003 static int mlx4_init_steering(struct mlx4_dev *dev) in mlx4_init_steering() argument
3005 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_steering()
3006 int num_entries = dev->caps.num_ports; in mlx4_init_steering()
3021 static void mlx4_clear_steering(struct mlx4_dev *dev) in mlx4_clear_steering() argument
3023 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clear_steering()
3026 int num_entries = dev->caps.num_ports; in mlx4_clear_steering()
3062 static int mlx4_get_ownership(struct mlx4_dev *dev) in mlx4_get_ownership() argument
3067 if (pci_channel_offline(dev->persist->pdev)) in mlx4_get_ownership()
3070 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_get_ownership()
3074 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_get_ownership()
3083 static void mlx4_free_ownership(struct mlx4_dev *dev) in mlx4_free_ownership() argument
3087 if (pci_channel_offline(dev->persist->pdev)) in mlx4_free_ownership()
3090 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_free_ownership()
3094 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_free_ownership()
3105 static u64 mlx4_enable_sriov(struct mlx4_dev *dev, struct pci_dev *pdev, in mlx4_enable_sriov() argument
3108 u64 dev_flags = dev->flags; in mlx4_enable_sriov()
3112 dev->dev_vfs = kcalloc(total_vfs, sizeof(*dev->dev_vfs), in mlx4_enable_sriov()
3114 if (!dev->dev_vfs) in mlx4_enable_sriov()
3120 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_enable_sriov()
3122 … mlx4_err(dev, "SR-IOV was already enabled, but with num_vfs (%d) different than requested (%d)\n", in mlx4_enable_sriov()
3128 dev->dev_vfs = kzalloc(total_vfs * sizeof(*dev->dev_vfs), GFP_KERNEL); in mlx4_enable_sriov()
3129 if (NULL == dev->dev_vfs) { in mlx4_enable_sriov()
3130 mlx4_err(dev, "Failed to allocate memory for VFs\n"); in mlx4_enable_sriov()
3134 if (!(dev->flags & MLX4_FLAG_SRIOV)) { in mlx4_enable_sriov()
3135 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", total_vfs); in mlx4_enable_sriov()
3139 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d)\n", in mlx4_enable_sriov()
3143 mlx4_warn(dev, "Running in master mode\n"); in mlx4_enable_sriov()
3147 dev->persist->num_vfs = total_vfs; in mlx4_enable_sriov()
3154 dev->persist->num_vfs = 0; in mlx4_enable_sriov()
3155 kfree(dev->dev_vfs); in mlx4_enable_sriov()
3156 dev->dev_vfs = NULL; in mlx4_enable_sriov()
3164 static int mlx4_check_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_check_dev_cap() argument
3171 mlx4_err(dev, "Requested %d VFs, but FW does not support more than 64\n", in mlx4_check_dev_cap()
3178 static int mlx4_pci_enable_device(struct mlx4_dev *dev) in mlx4_pci_enable_device() argument
3180 struct pci_dev *pdev = dev->persist->pdev; in mlx4_pci_enable_device()
3183 mutex_lock(&dev->persist->pci_status_mutex); in mlx4_pci_enable_device()
3184 if (dev->persist->pci_status == MLX4_PCI_STATUS_DISABLED) { in mlx4_pci_enable_device()
3187 dev->persist->pci_status = MLX4_PCI_STATUS_ENABLED; in mlx4_pci_enable_device()
3189 mutex_unlock(&dev->persist->pci_status_mutex); in mlx4_pci_enable_device()
3194 static void mlx4_pci_disable_device(struct mlx4_dev *dev) in mlx4_pci_disable_device() argument
3196 struct pci_dev *pdev = dev->persist->pdev; in mlx4_pci_disable_device()
3198 mutex_lock(&dev->persist->pci_status_mutex); in mlx4_pci_disable_device()
3199 if (dev->persist->pci_status == MLX4_PCI_STATUS_ENABLED) { in mlx4_pci_disable_device()
3201 dev->persist->pci_status = MLX4_PCI_STATUS_DISABLED; in mlx4_pci_disable_device()
3203 mutex_unlock(&dev->persist->pci_status_mutex); in mlx4_pci_disable_device()
3210 struct mlx4_dev *dev; in mlx4_load_one() local
3218 dev = &priv->dev; in mlx4_load_one()
3233 dev->rev_id = pdev->revision; in mlx4_load_one()
3234 dev->numa_node = dev_to_node(&pdev->dev); in mlx4_load_one()
3238 mlx4_warn(dev, "Detected virtual function - running in slave mode\n"); in mlx4_load_one()
3239 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
3244 err = mlx4_get_ownership(dev); in mlx4_load_one()
3249 mlx4_warn(dev, "Multiple PFs not yet supported - Skipping PF\n"); in mlx4_load_one()
3262 err = mlx4_reset(dev); in mlx4_load_one()
3264 mlx4_err(dev, "Failed to reset HCA, aborting\n"); in mlx4_load_one()
3269 dev->flags = MLX4_FLAG_MASTER; in mlx4_load_one()
3272 dev->flags |= MLX4_FLAG_SRIOV; in mlx4_load_one()
3273 dev->persist->num_vfs = total_vfs; in mlx4_load_one()
3280 dev->persist->state = MLX4_DEVICE_STATE_UP; in mlx4_load_one()
3283 err = mlx4_cmd_init(dev); in mlx4_load_one()
3285 mlx4_err(dev, "Failed to init command interface, aborting\n"); in mlx4_load_one()
3292 if (mlx4_is_mfunc(dev)) { in mlx4_load_one()
3293 if (mlx4_is_master(dev)) { in mlx4_load_one()
3294 dev->num_slaves = MLX4_MAX_NUM_SLAVES; in mlx4_load_one()
3297 dev->num_slaves = 0; in mlx4_load_one()
3298 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3300 mlx4_err(dev, "Failed to init slave mfunc interface, aborting\n"); in mlx4_load_one()
3306 err = mlx4_init_fw(dev); in mlx4_load_one()
3308 mlx4_err(dev, "Failed to init fw, aborting.\n"); in mlx4_load_one()
3312 if (mlx4_is_master(dev)) { in mlx4_load_one()
3322 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
3324 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
3328 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
3332 u64 dev_flags = mlx4_enable_sriov(dev, pdev, in mlx4_load_one()
3337 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3338 dev->flags = dev_flags; in mlx4_load_one()
3339 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
3340 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
3343 err = mlx4_reset(dev); in mlx4_load_one()
3345 mlx4_err(dev, "Failed to reset HCA, aborting.\n"); in mlx4_load_one()
3356 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
3358 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
3362 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
3367 err = mlx4_init_hca(dev); in mlx4_load_one()
3372 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3374 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_load_one()
3377 if (mlx4_is_master(dev) && !reset_flow) in mlx4_load_one()
3379 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3381 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3382 mlx4_free_ownership(dev); in mlx4_load_one()
3383 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
3384 dev->flags &= ~MLX4_FLAG_MASTER; in mlx4_load_one()
3390 if (mlx4_is_master(dev) && (dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) { in mlx4_load_one()
3391 u64 dev_flags = mlx4_enable_sriov(dev, pdev, total_vfs, in mlx4_load_one()
3394 if ((dev->flags ^ dev_flags) & (MLX4_FLAG_MASTER | MLX4_FLAG_SLAVE)) { in mlx4_load_one()
3395 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_VHCR); in mlx4_load_one()
3396 dev->flags = dev_flags; in mlx4_load_one()
3397 err = mlx4_cmd_init(dev); in mlx4_load_one()
3402 mlx4_err(dev, "Failed to init VHCR command interface, aborting\n"); in mlx4_load_one()
3406 dev->flags = dev_flags; in mlx4_load_one()
3409 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
3410 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
3419 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3420 mlx4_check_pcie_caps(dev); in mlx4_load_one()
3424 if (mlx4_is_master(dev)) { in mlx4_load_one()
3425 if (dev->caps.num_ports < 2 && in mlx4_load_one()
3428 mlx4_err(dev, in mlx4_load_one()
3430 dev->caps.num_ports); in mlx4_load_one()
3433 memcpy(dev->persist->nvfs, nvfs, sizeof(dev->persist->nvfs)); in mlx4_load_one()
3436 i < sizeof(dev->persist->nvfs)/ in mlx4_load_one()
3437 sizeof(dev->persist->nvfs[0]); i++) { in mlx4_load_one()
3440 for (j = 0; j < dev->persist->nvfs[i]; ++sum, ++j) { in mlx4_load_one()
3441 dev->dev_vfs[sum].min_port = i < 2 ? i + 1 : 1; in mlx4_load_one()
3442 dev->dev_vfs[sum].n_ports = i < 2 ? 1 : in mlx4_load_one()
3443 dev->caps.num_ports; in mlx4_load_one()
3450 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3452 mlx4_err(dev, "Failed to init master mfunc interface, aborting.\n"); in mlx4_load_one()
3457 err = mlx4_alloc_eq_table(dev); in mlx4_load_one()
3464 mlx4_enable_msi_x(dev); in mlx4_load_one()
3465 if ((mlx4_is_mfunc(dev)) && in mlx4_load_one()
3466 !(dev->flags & MLX4_FLAG_MSI_X)) { in mlx4_load_one()
3468 mlx4_err(dev, "INTx is not supported in multi-function mode, aborting\n"); in mlx4_load_one()
3472 if (!mlx4_is_slave(dev)) { in mlx4_load_one()
3473 err = mlx4_init_steering(dev); in mlx4_load_one()
3478 mlx4_init_quotas(dev); in mlx4_load_one()
3480 err = mlx4_setup_hca(dev); in mlx4_load_one()
3481 if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) && in mlx4_load_one()
3482 !mlx4_is_mfunc(dev)) { in mlx4_load_one()
3483 dev->flags &= ~MLX4_FLAG_MSI_X; in mlx4_load_one()
3484 dev->caps.num_comp_vectors = 1; in mlx4_load_one()
3486 err = mlx4_setup_hca(dev); in mlx4_load_one()
3495 if (mlx4_is_master(dev)) { in mlx4_load_one()
3496 err = mlx4_ARM_COMM_CHANNEL(dev); in mlx4_load_one()
3498 mlx4_err(dev, " Failed to arm comm channel eq: %x\n", in mlx4_load_one()
3504 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_load_one()
3505 err = mlx4_init_port_info(dev, port); in mlx4_load_one()
3513 err = mlx4_register_device(dev); in mlx4_load_one()
3517 mlx4_request_modules(dev); in mlx4_load_one()
3519 mlx4_sense_init(dev); in mlx4_load_one()
3520 mlx4_start_sense(dev); in mlx4_load_one()
3524 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3534 mlx4_cleanup_counters_table(dev); in mlx4_load_one()
3535 mlx4_cleanup_qp_table(dev); in mlx4_load_one()
3536 mlx4_cleanup_srq_table(dev); in mlx4_load_one()
3537 mlx4_cleanup_cq_table(dev); in mlx4_load_one()
3538 mlx4_cmd_use_polling(dev); in mlx4_load_one()
3539 mlx4_cleanup_eq_table(dev); in mlx4_load_one()
3540 mlx4_cleanup_mcg_table(dev); in mlx4_load_one()
3541 mlx4_cleanup_mr_table(dev); in mlx4_load_one()
3542 mlx4_cleanup_xrcd_table(dev); in mlx4_load_one()
3543 mlx4_cleanup_pd_table(dev); in mlx4_load_one()
3544 mlx4_cleanup_uar_table(dev); in mlx4_load_one()
3547 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3548 mlx4_clear_steering(dev); in mlx4_load_one()
3551 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_load_one()
3555 mlx4_free_eq_table(dev); in mlx4_load_one()
3558 if (mlx4_is_master(dev)) { in mlx4_load_one()
3559 mlx4_free_resource_tracker(dev, RES_TR_FREE_STRUCTS_ONLY); in mlx4_load_one()
3560 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3563 if (mlx4_is_slave(dev)) { in mlx4_load_one()
3564 kfree(dev->caps.qp0_qkey); in mlx4_load_one()
3565 kfree(dev->caps.qp0_tunnel); in mlx4_load_one()
3566 kfree(dev->caps.qp0_proxy); in mlx4_load_one()
3567 kfree(dev->caps.qp1_tunnel); in mlx4_load_one()
3568 kfree(dev->caps.qp1_proxy); in mlx4_load_one()
3572 mlx4_close_hca(dev); in mlx4_load_one()
3575 mlx4_close_fw(dev); in mlx4_load_one()
3578 if (mlx4_is_slave(dev)) in mlx4_load_one()
3579 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3582 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3585 if (dev->flags & MLX4_FLAG_SRIOV && !existing_vfs) { in mlx4_load_one()
3587 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3590 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3593 kfree(priv->dev.dev_vfs); in mlx4_load_one()
3595 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3596 mlx4_free_ownership(dev); in mlx4_load_one()
3615 err = mlx4_pci_enable_device(&priv->dev); in __mlx4_init_one()
3617 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); in __mlx4_init_one()
3629 dev_err(&pdev->dev, "num_vfs module parameter cannot be negative\n"); in __mlx4_init_one()
3638 dev_err(&pdev->dev, "probe_vf module parameter cannot be negative or greater than num_vfs\n"); in __mlx4_init_one()
3644 dev_err(&pdev->dev, in __mlx4_init_one()
3653 dev_err(&pdev->dev, in __mlx4_init_one()
3665 …dev_err(&pdev->dev, "Missing DCS, aborting (driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\… in __mlx4_init_one()
3671 dev_err(&pdev->dev, "Missing UAR, aborting\n"); in __mlx4_init_one()
3678 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n"); in __mlx4_init_one()
3686 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); in __mlx4_init_one()
3689 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); in __mlx4_init_one()
3695 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit consistent PCI DMA mask\n"); in __mlx4_init_one()
3698 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, aborting\n"); in __mlx4_init_one()
3704 dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024); in __mlx4_init_one()
3723 dev_warn(&pdev->dev, "Skipping virtual function:%d\n", in __mlx4_init_one()
3731 err = mlx4_catas_init(&priv->dev); in __mlx4_init_one()
3742 mlx4_catas_end(&priv->dev); in __mlx4_init_one()
3748 mlx4_pci_disable_device(&priv->dev); in __mlx4_init_one()
3760 struct mlx4_dev *dev; in mlx4_init_one() local
3769 dev = &priv->dev; in mlx4_init_one()
3770 dev->persist = kzalloc(sizeof(*dev->persist), GFP_KERNEL); in mlx4_init_one()
3771 if (!dev->persist) { in mlx4_init_one()
3775 dev->persist->pdev = pdev; in mlx4_init_one()
3776 dev->persist->dev = dev; in mlx4_init_one()
3777 pci_set_drvdata(pdev, dev->persist); in mlx4_init_one()
3779 mutex_init(&dev->persist->device_state_mutex); in mlx4_init_one()
3780 mutex_init(&dev->persist->interface_state_mutex); in mlx4_init_one()
3781 mutex_init(&dev->persist->pci_status_mutex); in mlx4_init_one()
3785 kfree(dev->persist); in mlx4_init_one()
3789 device_set_desc(pdev->dev.bsddev, mlx4_description); in mlx4_init_one()
3793 snprintf(dev->fw_str, sizeof(dev->fw_str), "%d.%d.%d", in mlx4_init_one()
3794 (int) (dev->caps.fw_ver >> 32), in mlx4_init_one()
3795 (int) (dev->caps.fw_ver >> 16) & 0xffff, in mlx4_init_one()
3796 (int) (dev->caps.fw_ver & 0xffff)); in mlx4_init_one()
3798 ctx = &dev->hw_ctx; in mlx4_init_one()
3800 node = SYSCTL_ADD_NODE(ctx,SYSCTL_CHILDREN(pdev->dev.kobj.oidp), in mlx4_init_one()
3806 "fw_version", CTLFLAG_RD, dev->fw_str, 0, in mlx4_init_one()
3809 "board_id", CTLFLAG_RD, dev->board_id, 0, in mlx4_init_one()
3816 static void mlx4_clean_dev(struct mlx4_dev *dev) in mlx4_clean_dev() argument
3818 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_clean_dev()
3819 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clean_dev()
3820 unsigned long flags = (dev->flags & RESET_PERSIST_MASK_FLAGS); in mlx4_clean_dev()
3823 priv->dev.persist = persist; in mlx4_clean_dev()
3824 priv->dev.flags = flags; in mlx4_clean_dev()
3830 struct mlx4_dev *dev = persist->dev; in mlx4_unload_one() local
3831 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unload_one()
3839 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_unload_one()
3840 dev->persist->curr_port_type[i] = dev->caps.port_type[i + 1]; in mlx4_unload_one()
3841 dev->persist->curr_port_poss_type[i] = dev->caps. in mlx4_unload_one()
3847 mlx4_stop_sense(dev); in mlx4_unload_one()
3848 mlx4_unregister_device(dev); in mlx4_unload_one()
3850 for (p = 1; p <= dev->caps.num_ports; p++) { in mlx4_unload_one()
3852 mlx4_CLOSE_PORT(dev, p); in mlx4_unload_one()
3855 if (mlx4_is_master(dev)) in mlx4_unload_one()
3856 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
3859 mlx4_cleanup_default_counters(dev); in mlx4_unload_one()
3860 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
3861 mlx4_cleanup_counters_table(dev); in mlx4_unload_one()
3862 mlx4_cleanup_qp_table(dev); in mlx4_unload_one()
3863 mlx4_cleanup_srq_table(dev); in mlx4_unload_one()
3864 mlx4_cleanup_cq_table(dev); in mlx4_unload_one()
3865 mlx4_cmd_use_polling(dev); in mlx4_unload_one()
3866 mlx4_cleanup_eq_table(dev); in mlx4_unload_one()
3867 mlx4_cleanup_mcg_table(dev); in mlx4_unload_one()
3868 mlx4_cleanup_mr_table(dev); in mlx4_unload_one()
3869 mlx4_cleanup_xrcd_table(dev); in mlx4_unload_one()
3870 mlx4_cleanup_pd_table(dev); in mlx4_unload_one()
3872 if (mlx4_is_master(dev)) in mlx4_unload_one()
3873 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
3877 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_unload_one()
3878 mlx4_cleanup_uar_table(dev); in mlx4_unload_one()
3879 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
3880 mlx4_clear_steering(dev); in mlx4_unload_one()
3881 mlx4_free_eq_table(dev); in mlx4_unload_one()
3882 if (mlx4_is_master(dev)) in mlx4_unload_one()
3883 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
3884 mlx4_close_hca(dev); in mlx4_unload_one()
3885 mlx4_close_fw(dev); in mlx4_unload_one()
3886 if (mlx4_is_slave(dev)) in mlx4_unload_one()
3887 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
3888 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_unload_one()
3890 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_unload_one()
3893 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
3894 mlx4_free_ownership(dev); in mlx4_unload_one()
3896 kfree(dev->caps.qp0_qkey); in mlx4_unload_one()
3897 kfree(dev->caps.qp0_tunnel); in mlx4_unload_one()
3898 kfree(dev->caps.qp0_proxy); in mlx4_unload_one()
3899 kfree(dev->caps.qp1_tunnel); in mlx4_unload_one()
3900 kfree(dev->caps.qp1_proxy); in mlx4_unload_one()
3901 kfree(dev->dev_vfs); in mlx4_unload_one()
3903 mlx4_clean_dev(dev); in mlx4_unload_one()
3911 struct mlx4_dev *dev = persist->dev; in mlx4_remove_one() local
3912 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_remove_one()
3924 device_set_desc(pdev->dev.bsddev, NULL); in mlx4_remove_one()
3927 if (mlx4_is_master(dev) && dev->flags & MLX4_FLAG_SRIOV) { in mlx4_remove_one()
3928 active_vfs = mlx4_how_many_lives_vf(dev); in mlx4_remove_one()
3941 mlx4_info(dev, "%s: interface is down\n", __func__); in mlx4_remove_one()
3942 mlx4_catas_end(dev); in mlx4_remove_one()
3943 if (dev->flags & MLX4_FLAG_SRIOV && !active_vfs) { in mlx4_remove_one()
3944 mlx4_warn(dev, "Disabling SR-IOV\n"); in mlx4_remove_one()
3950 kfree(dev->persist); in mlx4_remove_one()
3955 static int restore_current_port_types(struct mlx4_dev *dev, in restore_current_port_types() argument
3959 struct mlx4_priv *priv = mlx4_priv(dev); in restore_current_port_types()
3962 mlx4_stop_sense(dev); in restore_current_port_types()
3965 for (i = 0; i < dev->caps.num_ports; i++) in restore_current_port_types()
3966 dev->caps.possible_type[i + 1] = poss_types[i]; in restore_current_port_types()
3967 err = mlx4_change_port_types(dev, types); in restore_current_port_types()
3970 mlx4_start_sense(dev); in restore_current_port_types()
3978 struct mlx4_dev *dev = persist->dev; in mlx4_restart_one() local
3979 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_restart_one()
3984 total_vfs = dev->persist->num_vfs; in mlx4_restart_one()
3985 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_restart_one()
3990 mlx4_err(dev, "%s: ERROR: mlx4_load_one failed, pci_name=%s, err=%d\n", in mlx4_restart_one()
3995 err = restore_current_port_types(dev, dev->persist->curr_port_type, in mlx4_restart_one()
3996 dev->persist->curr_port_poss_type); in mlx4_restart_one()
3998 mlx4_err(dev, "could not restore original port types (%d)\n", in mlx4_restart_one()
4071 mlx4_err(persist->dev, "mlx4_pci_err_detected was called\n"); in mlx4_pci_err_detected()
4082 mlx4_pci_disable_device(persist->dev); in mlx4_pci_err_detected()
4089 struct mlx4_dev *dev = persist->dev; in mlx4_pci_slot_reset() local
4092 mlx4_err(dev, "mlx4_pci_slot_reset was called\n"); in mlx4_pci_slot_reset()
4093 err = mlx4_pci_enable_device(dev); in mlx4_pci_slot_reset()
4095 mlx4_err(dev, "Can not re-enable device, err=%d\n", err); in mlx4_pci_slot_reset()
4106 struct mlx4_dev *dev = persist->dev; in mlx4_pci_resume() local
4107 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_pci_resume()
4112 mlx4_err(dev, "%s was called\n", __func__); in mlx4_pci_resume()
4113 total_vfs = dev->persist->num_vfs; in mlx4_pci_resume()
4114 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_pci_resume()
4121 mlx4_err(dev, "%s: mlx4_load_one failed, err=%d\n", in mlx4_pci_resume()
4126 err = restore_current_port_types(dev, dev->persist-> in mlx4_pci_resume()
4127 curr_port_type, dev->persist-> in mlx4_pci_resume()
4130 mlx4_err(dev, "could not restore original port types (%d)\n", err); in mlx4_pci_resume()
4141 mlx4_info(persist->dev, "mlx4_shutdown was called\n"); in mlx4_shutdown()