Lines Matching full:dev
199 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_crdump_snapshot_get() local
201 ctx->val.vbool = dev->persist->crdump.snapshot_enable; in mlx4_devlink_crdump_snapshot_get()
209 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_crdump_snapshot_set() local
211 dev->persist->crdump.snapshot_enable = ctx->val.vbool; in mlx4_devlink_crdump_snapshot_set()
293 static inline void mlx4_set_num_reserved_uars(struct mlx4_dev *dev, in mlx4_set_num_reserved_uars() argument
300 dev->caps.reserved_uars = in mlx4_set_num_reserved_uars()
302 mlx4_get_num_reserved_uar(dev), in mlx4_set_num_reserved_uars()
304 (1 << (PAGE_SHIFT - dev->uar_page_shift))); in mlx4_set_num_reserved_uars()
307 int mlx4_check_port_params(struct mlx4_dev *dev, in mlx4_check_port_params() argument
312 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) { in mlx4_check_port_params()
313 for (i = 0; i < dev->caps.num_ports - 1; i++) { in mlx4_check_port_params()
315 mlx4_err(dev, "Only same port types supported on this HCA, aborting\n"); in mlx4_check_port_params()
321 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_check_port_params()
322 if (!(port_type[i] & dev->caps.supported_type[i+1])) { in mlx4_check_port_params()
323 mlx4_err(dev, "Requested port type for port %d is not supported on this HCA\n", in mlx4_check_port_params()
331 static void mlx4_set_port_mask(struct mlx4_dev *dev) in mlx4_set_port_mask() argument
335 for (i = 1; i <= dev->caps.num_ports; ++i) in mlx4_set_port_mask()
336 dev->caps.port_mask[i] = dev->caps.port_type[i]; in mlx4_set_port_mask()
343 static int mlx4_query_func(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_query_func() argument
348 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS) { in mlx4_query_func()
349 err = mlx4_QUERY_FUNC(dev, &func, 0); in mlx4_query_func()
351 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_query_func()
362 static void mlx4_enable_cqe_eqe_stride(struct mlx4_dev *dev) in mlx4_enable_cqe_eqe_stride() argument
364 struct mlx4_caps *dev_cap = &dev->caps; in mlx4_enable_cqe_eqe_stride()
382 mlx4_dbg(dev, "Enabling CQE stride cacheLine supported\n"); in mlx4_enable_cqe_eqe_stride()
387 if (mlx4_is_master(dev)) in mlx4_enable_cqe_eqe_stride()
391 mlx4_dbg(dev, "Disabling CQE stride, cacheLine size unsupported\n"); in mlx4_enable_cqe_eqe_stride()
397 static int _mlx4_dev_port(struct mlx4_dev *dev, int port, in _mlx4_dev_port() argument
400 dev->caps.vl_cap[port] = port_cap->max_vl; in _mlx4_dev_port()
401 dev->caps.ib_mtu_cap[port] = port_cap->ib_mtu; in _mlx4_dev_port()
402 dev->phys_caps.gid_phys_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
403 dev->phys_caps.pkey_phys_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
407 dev->caps.gid_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
408 dev->caps.pkey_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
409 dev->caps.port_width_cap[port] = port_cap->max_port_width; in _mlx4_dev_port()
410 dev->caps.eth_mtu_cap[port] = port_cap->eth_mtu; in _mlx4_dev_port()
411 dev->caps.max_tc_eth = port_cap->max_tc_eth; in _mlx4_dev_port()
412 dev->caps.def_mac[port] = port_cap->def_mac; in _mlx4_dev_port()
413 dev->caps.supported_type[port] = port_cap->supported_port_types; in _mlx4_dev_port()
414 dev->caps.suggested_type[port] = port_cap->suggested_type; in _mlx4_dev_port()
415 dev->caps.default_sense[port] = port_cap->default_sense; in _mlx4_dev_port()
416 dev->caps.trans_type[port] = port_cap->trans_type; in _mlx4_dev_port()
417 dev->caps.vendor_oui[port] = port_cap->vendor_oui; in _mlx4_dev_port()
418 dev->caps.wavelength[port] = port_cap->wavelength; in _mlx4_dev_port()
419 dev->caps.trans_code[port] = port_cap->trans_code; in _mlx4_dev_port()
424 static int mlx4_dev_port(struct mlx4_dev *dev, int port, in mlx4_dev_port() argument
429 err = mlx4_QUERY_PORT(dev, port, port_cap); in mlx4_dev_port()
432 mlx4_err(dev, "QUERY_PORT command failed.\n"); in mlx4_dev_port()
437 static inline void mlx4_enable_ignore_fcs(struct mlx4_dev *dev) in mlx4_enable_ignore_fcs() argument
439 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_IGNORE_FCS)) in mlx4_enable_ignore_fcs()
442 if (mlx4_is_mfunc(dev)) { in mlx4_enable_ignore_fcs()
443 mlx4_dbg(dev, "SRIOV mode - Disabling Ignore FCS"); in mlx4_enable_ignore_fcs()
444 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
448 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP)) { in mlx4_enable_ignore_fcs()
449 mlx4_dbg(dev, in mlx4_enable_ignore_fcs()
451 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
457 static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_dev_cap() argument
462 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_dev_cap()
464 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_dev_cap()
467 mlx4_dev_cap_dump(dev, dev_cap); in mlx4_dev_cap()
470 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_dev_cap()
475 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_dev_cap()
480 if (dev_cap->uar_size > pci_resource_len(dev->persist->pdev, 2)) { in mlx4_dev_cap()
481 …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()
484 pci_resource_len(dev->persist->pdev, 2)); in mlx4_dev_cap()
488 dev->caps.num_ports = dev_cap->num_ports; in mlx4_dev_cap()
489 dev->caps.num_sys_eqs = dev_cap->num_sys_eqs; in mlx4_dev_cap()
490 dev->phys_caps.num_phys_eqs = dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS ? in mlx4_dev_cap()
491 dev->caps.num_sys_eqs : in mlx4_dev_cap()
493 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
494 err = _mlx4_dev_port(dev, i, dev_cap->port_cap + i); in mlx4_dev_cap()
496 mlx4_err(dev, "QUERY_PORT command failed, aborting\n"); in mlx4_dev_cap()
501 dev->caps.map_clock_to_user = dev_cap->map_clock_to_user; in mlx4_dev_cap()
502 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_dev_cap()
503 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE; in mlx4_dev_cap()
504 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay; in mlx4_dev_cap()
505 dev->caps.bf_reg_size = dev_cap->bf_reg_size; in mlx4_dev_cap()
506 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page; in mlx4_dev_cap()
507 dev->caps.max_sq_sg = dev_cap->max_sq_sg; in mlx4_dev_cap()
508 dev->caps.max_rq_sg = dev_cap->max_rq_sg; in mlx4_dev_cap()
509 dev->caps.max_wqes = dev_cap->max_qp_sz; in mlx4_dev_cap()
510 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp; in mlx4_dev_cap()
511 dev->caps.max_srq_wqes = dev_cap->max_srq_sz; in mlx4_dev_cap()
512 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1; in mlx4_dev_cap()
513 dev->caps.reserved_srqs = dev_cap->reserved_srqs; in mlx4_dev_cap()
514 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz; in mlx4_dev_cap()
515 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz; in mlx4_dev_cap()
520 dev->caps.max_cqes = dev_cap->max_cq_sz - 1; in mlx4_dev_cap()
521 dev->caps.reserved_cqs = dev_cap->reserved_cqs; in mlx4_dev_cap()
522 dev->caps.reserved_eqs = dev_cap->reserved_eqs; in mlx4_dev_cap()
523 dev->caps.reserved_mtts = dev_cap->reserved_mtts; in mlx4_dev_cap()
524 dev->caps.reserved_mrws = dev_cap->reserved_mrws; in mlx4_dev_cap()
526 dev->caps.reserved_pds = dev_cap->reserved_pds; in mlx4_dev_cap()
527 dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
529 dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
531 dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz; in mlx4_dev_cap()
533 dev->caps.max_msg_sz = dev_cap->max_msg_sz; in mlx4_dev_cap()
534 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1); in mlx4_dev_cap()
535 dev->caps.flags = dev_cap->flags; in mlx4_dev_cap()
536 dev->caps.flags2 = dev_cap->flags2; in mlx4_dev_cap()
537 dev->caps.bmme_flags = dev_cap->bmme_flags; in mlx4_dev_cap()
538 dev->caps.reserved_lkey = dev_cap->reserved_lkey; in mlx4_dev_cap()
539 dev->caps.stat_rate_support = dev_cap->stat_rate_support; in mlx4_dev_cap()
540 dev->caps.max_gso_sz = dev_cap->max_gso_sz; in mlx4_dev_cap()
541 dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz; in mlx4_dev_cap()
542 dev->caps.wol_port[1] = dev_cap->wol_port[1]; in mlx4_dev_cap()
543 dev->caps.wol_port[2] = dev_cap->wol_port[2]; in mlx4_dev_cap()
544 dev->caps.health_buffer_addrs = dev_cap->health_buffer_addrs; in mlx4_dev_cap()
547 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
551 if (enable_4k_uar || !dev->persist->num_vfs) in mlx4_dev_cap()
552 dev->uar_page_shift = DEFAULT_UAR_PAGE_SHIFT; in mlx4_dev_cap()
554 dev->uar_page_shift = PAGE_SHIFT; in mlx4_dev_cap()
556 mlx4_set_num_reserved_uars(dev, dev_cap); in mlx4_dev_cap()
559 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PHV_EN) { in mlx4_dev_cap()
563 err = mlx4_QUERY_HCA(dev, &hca_param); in mlx4_dev_cap()
571 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_PHV_EN; in mlx4_dev_cap()
575 if (mlx4_priv(dev)->pci_dev_data & MLX4_PCI_DEV_FORCE_SENSE_PORT) in mlx4_dev_cap()
576 dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
578 if (mlx4_is_mfunc(dev)) in mlx4_dev_cap()
579 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
582 dev->caps.log_num_macs = MLX4_MIN_LOG_NUM_MAC; in mlx4_dev_cap()
583 dev->caps.log_num_vlans = MLX4_MIN_LOG_NUM_VLANS; in mlx4_dev_cap()
585 dev->caps.log_num_macs = log_num_mac; in mlx4_dev_cap()
586 dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS; in mlx4_dev_cap()
589 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
590 dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE; in mlx4_dev_cap()
591 if (dev->caps.supported_type[i]) { in mlx4_dev_cap()
593 if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_dev_cap()
594 dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH; in mlx4_dev_cap()
596 else if (dev->caps.supported_type[i] == in mlx4_dev_cap()
598 dev->caps.port_type[i] = MLX4_PORT_TYPE_IB; in mlx4_dev_cap()
604 dev->caps.port_type[i] = dev->caps.suggested_type[i] ? in mlx4_dev_cap()
607 dev->caps.port_type[i] = port_type_array[i - 1]; in mlx4_dev_cap()
616 mlx4_priv(dev)->sense.sense_allowed[i] = in mlx4_dev_cap()
617 ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) && in mlx4_dev_cap()
618 (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) && in mlx4_dev_cap()
619 (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)); in mlx4_dev_cap()
626 if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) { in mlx4_dev_cap()
628 dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO; in mlx4_dev_cap()
629 mlx4_SENSE_PORT(dev, i, &sensed_port); in mlx4_dev_cap()
631 dev->caps.port_type[i] = sensed_port; in mlx4_dev_cap()
633 dev->caps.possible_type[i] = dev->caps.port_type[i]; in mlx4_dev_cap()
636 if (dev->caps.log_num_macs > dev_cap->port_cap[i].log_max_macs) { in mlx4_dev_cap()
637 dev->caps.log_num_macs = dev_cap->port_cap[i].log_max_macs; in mlx4_dev_cap()
638 mlx4_warn(dev, "Requested number of MACs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
639 i, 1 << dev->caps.log_num_macs); in mlx4_dev_cap()
641 if (dev->caps.log_num_vlans > dev_cap->port_cap[i].log_max_vlans) { in mlx4_dev_cap()
642 dev->caps.log_num_vlans = dev_cap->port_cap[i].log_max_vlans; in mlx4_dev_cap()
643 mlx4_warn(dev, "Requested number of VLANs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
644 i, 1 << dev->caps.log_num_vlans); in mlx4_dev_cap()
648 if (mlx4_is_master(dev) && (dev->caps.num_ports == 2) && in mlx4_dev_cap()
651 mlx4_warn(dev, in mlx4_dev_cap()
653 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_QOS_VPP; in mlx4_dev_cap()
656 dev->caps.max_counters = dev_cap->max_counters; in mlx4_dev_cap()
658 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps; in mlx4_dev_cap()
659 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] = in mlx4_dev_cap()
660 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] = in mlx4_dev_cap()
661 (1 << dev->caps.log_num_macs) * in mlx4_dev_cap()
662 (1 << dev->caps.log_num_vlans) * in mlx4_dev_cap()
663 dev->caps.num_ports; in mlx4_dev_cap()
664 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH; in mlx4_dev_cap()
667 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) in mlx4_dev_cap()
668 dev->caps.dmfs_high_rate_qpn_base = dev_cap->dmfs_high_rate_qpn_base; in mlx4_dev_cap()
670 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
671 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
674 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) { in mlx4_dev_cap()
675 dev->caps.dmfs_high_rate_qpn_range = dev_cap->dmfs_high_rate_qpn_range; in mlx4_dev_cap()
676 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DEFAULT; in mlx4_dev_cap()
677 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_FS_A0; in mlx4_dev_cap()
679 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_NOT_SUPPORTED; in mlx4_dev_cap()
680 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
681 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
682 dev->caps.dmfs_high_rate_qpn_range = MLX4_A0_STEERING_TABLE_SIZE; in mlx4_dev_cap()
685 dev->caps.rl_caps = dev_cap->rl_caps; in mlx4_dev_cap()
687 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_RSS_RAW_ETH] = in mlx4_dev_cap()
688 dev->caps.dmfs_high_rate_qpn_range; in mlx4_dev_cap()
690 dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] + in mlx4_dev_cap()
691 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] + in mlx4_dev_cap()
692 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] + in mlx4_dev_cap()
693 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH]; in mlx4_dev_cap()
695 dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0; in mlx4_dev_cap()
697 if (!enable_64b_cqe_eqe && !mlx4_is_slave(dev)) { in mlx4_dev_cap()
700 mlx4_warn(dev, "64B EQEs/CQEs supported by the device but not enabled\n"); in mlx4_dev_cap()
701 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_CQE; in mlx4_dev_cap()
702 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_EQE; in mlx4_dev_cap()
708 mlx4_warn(dev, "Disabling EQE/CQE stride per user request\n"); in mlx4_dev_cap()
714 if ((dev->caps.flags & in mlx4_dev_cap()
716 mlx4_is_master(dev)) in mlx4_dev_cap()
717 dev->caps.function_caps |= MLX4_FUNC_CAP_64B_EQE_CQE; in mlx4_dev_cap()
719 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
720 mlx4_enable_cqe_eqe_stride(dev); in mlx4_dev_cap()
721 dev->caps.alloc_res_qp_mask = in mlx4_dev_cap()
722 (dev->caps.bf_reg_size ? MLX4_RESERVE_ETH_BF_QP : 0) | in mlx4_dev_cap()
725 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) && in mlx4_dev_cap()
726 dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) { in mlx4_dev_cap()
727 mlx4_warn(dev, "Old device ETS support detected\n"); in mlx4_dev_cap()
728 mlx4_warn(dev, "Consider upgrading device FW.\n"); in mlx4_dev_cap()
729 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_ETS_CFG; in mlx4_dev_cap()
733 dev->caps.alloc_res_qp_mask = 0; in mlx4_dev_cap()
736 mlx4_enable_ignore_fcs(dev); in mlx4_dev_cap()
742 static int mlx4_how_many_lives_vf(struct mlx4_dev *dev) in mlx4_how_many_lives_vf() argument
744 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_how_many_lives_vf()
749 for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) { in mlx4_how_many_lives_vf()
753 mlx4_warn(dev, "%s: slave: %d is still active\n", in mlx4_how_many_lives_vf()
761 int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey) in mlx4_get_parav_qkey() argument
765 if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX || in mlx4_get_parav_qkey()
766 qpn < dev->phys_caps.base_proxy_sqpn) in mlx4_get_parav_qkey()
769 if (qpn >= dev->phys_caps.base_tunnel_sqpn) in mlx4_get_parav_qkey()
771 qk += qpn - dev->phys_caps.base_tunnel_sqpn; in mlx4_get_parav_qkey()
773 qk += qpn - dev->phys_caps.base_proxy_sqpn; in mlx4_get_parav_qkey()
779 void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port, int i, int val) in mlx4_sync_pkey_table() argument
781 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_sync_pkey_table()
783 if (!mlx4_is_master(dev)) in mlx4_sync_pkey_table()
790 void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid) in mlx4_put_slave_node_guid() argument
792 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_put_slave_node_guid()
794 if (!mlx4_is_master(dev)) in mlx4_put_slave_node_guid()
801 __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave) in mlx4_get_slave_node_guid() argument
803 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_get_slave_node_guid()
805 if (!mlx4_is_master(dev)) in mlx4_get_slave_node_guid()
812 int mlx4_is_slave_active(struct mlx4_dev *dev, int slave) in mlx4_is_slave_active() argument
814 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_is_slave_active()
817 if (!mlx4_is_master(dev)) in mlx4_is_slave_active()
842 static void slave_adjust_steering_mode(struct mlx4_dev *dev, in slave_adjust_steering_mode() argument
846 dev->caps.steering_mode = hca_param->steering_mode; in slave_adjust_steering_mode()
847 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) { in slave_adjust_steering_mode()
848 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in slave_adjust_steering_mode()
849 dev->caps.fs_log_max_ucast_qp_range_size = in slave_adjust_steering_mode()
852 dev->caps.num_qp_per_mgm = in slave_adjust_steering_mode()
855 mlx4_dbg(dev, "Steering mode is: %s\n", in slave_adjust_steering_mode()
856 mlx4_steering_mode_str(dev->caps.steering_mode)); in slave_adjust_steering_mode()
859 static void mlx4_slave_destroy_special_qp_cap(struct mlx4_dev *dev) in mlx4_slave_destroy_special_qp_cap() argument
861 kfree(dev->caps.spec_qps); in mlx4_slave_destroy_special_qp_cap()
862 dev->caps.spec_qps = NULL; in mlx4_slave_destroy_special_qp_cap()
865 static int mlx4_slave_special_qp_cap(struct mlx4_dev *dev) in mlx4_slave_special_qp_cap() argument
868 struct mlx4_caps *caps = &dev->caps; in mlx4_slave_special_qp_cap()
875 mlx4_err(dev, "Failed to allocate memory for special qps cap\n"); in mlx4_slave_special_qp_cap()
881 err = mlx4_QUERY_FUNC_CAP(dev, i, func_cap); in mlx4_slave_special_qp_cap()
883 mlx4_err(dev, "QUERY_FUNC_CAP port command failed for port %d, aborting (%d)\n", in mlx4_slave_special_qp_cap()
890 err = mlx4_get_slave_pkey_gid_tbl_len(dev, i, in mlx4_slave_special_qp_cap()
894 mlx4_err(dev, "QUERY_PORT command failed for port %d, aborting (%d)\n", in mlx4_slave_special_qp_cap()
902 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_slave_special_qp_cap()
907 static int mlx4_slave_cap(struct mlx4_dev *dev) in mlx4_slave_cap() argument
919 mlx4_err(dev, "Failed to allocate memory for slave_cap\n"); in mlx4_slave_cap()
924 err = mlx4_QUERY_HCA(dev, hca_param); in mlx4_slave_cap()
926 mlx4_err(dev, "QUERY_HCA command failed, aborting\n"); in mlx4_slave_cap()
934 mlx4_err(dev, "Unknown hca global capabilities\n"); in mlx4_slave_cap()
939 dev->caps.hca_core_clock = hca_param->hca_core_clock; in mlx4_slave_cap()
941 dev->caps.max_qp_dest_rdma = 1 << hca_param->log_rd_per_qp; in mlx4_slave_cap()
942 err = mlx4_dev_cap(dev, dev_cap); in mlx4_slave_cap()
944 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_slave_cap()
948 err = mlx4_QUERY_FW(dev); in mlx4_slave_cap()
950 mlx4_err(dev, "QUERY_FW command failed: could not get FW version\n"); in mlx4_slave_cap()
952 page_size = ~dev->caps.page_size_cap + 1; in mlx4_slave_cap()
953 mlx4_warn(dev, "HCA minimum page size:%d\n", page_size); in mlx4_slave_cap()
955 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_slave_cap()
962 dev->uar_page_shift = hca_param->uar_page_sz + 12; in mlx4_slave_cap()
965 if (dev->uar_page_shift > PAGE_SHIFT) { in mlx4_slave_cap()
966 mlx4_err(dev, in mlx4_slave_cap()
973 mlx4_set_num_reserved_uars(dev, dev_cap); in mlx4_slave_cap()
979 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_slave_cap()
981 err = mlx4_QUERY_FUNC_CAP(dev, 0, func_cap); in mlx4_slave_cap()
983 mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d)\n", in mlx4_slave_cap()
990 mlx4_err(dev, "Unknown pf context behaviour %x known flags %x\n", in mlx4_slave_cap()
997 dev->caps.num_ports = func_cap->num_ports; in mlx4_slave_cap()
998 dev->quotas.qp = func_cap->qp_quota; in mlx4_slave_cap()
999 dev->quotas.srq = func_cap->srq_quota; in mlx4_slave_cap()
1000 dev->quotas.cq = func_cap->cq_quota; in mlx4_slave_cap()
1001 dev->quotas.mpt = func_cap->mpt_quota; in mlx4_slave_cap()
1002 dev->quotas.mtt = func_cap->mtt_quota; in mlx4_slave_cap()
1003 dev->caps.num_qps = 1 << hca_param->log_num_qps; in mlx4_slave_cap()
1004 dev->caps.num_srqs = 1 << hca_param->log_num_srqs; in mlx4_slave_cap()
1005 dev->caps.num_cqs = 1 << hca_param->log_num_cqs; in mlx4_slave_cap()
1006 dev->caps.num_mpts = 1 << hca_param->log_mpt_sz; in mlx4_slave_cap()
1007 dev->caps.num_eqs = func_cap->max_eq; in mlx4_slave_cap()
1008 dev->caps.reserved_eqs = func_cap->reserved_eq; in mlx4_slave_cap()
1009 dev->caps.reserved_lkey = func_cap->reserved_lkey; in mlx4_slave_cap()
1010 dev->caps.num_pds = MLX4_NUM_PDS; in mlx4_slave_cap()
1011 dev->caps.num_mgms = 0; in mlx4_slave_cap()
1012 dev->caps.num_amgms = 0; in mlx4_slave_cap()
1014 if (dev->caps.num_ports > MLX4_MAX_PORTS) { in mlx4_slave_cap()
1015 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_slave_cap()
1016 dev->caps.num_ports, MLX4_MAX_PORTS); in mlx4_slave_cap()
1021 mlx4_replace_zero_macs(dev); in mlx4_slave_cap()
1023 err = mlx4_slave_special_qp_cap(dev); in mlx4_slave_cap()
1025 mlx4_err(dev, "Set special QP caps failed. aborting\n"); in mlx4_slave_cap()
1029 if (dev->caps.uar_page_size * (dev->caps.num_uars - in mlx4_slave_cap()
1030 dev->caps.reserved_uars) > in mlx4_slave_cap()
1031 pci_resource_len(dev->persist->pdev, in mlx4_slave_cap()
1033 …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()
1034 dev->caps.uar_page_size * dev->caps.num_uars, in mlx4_slave_cap()
1036 pci_resource_len(dev->persist->pdev, 2)); in mlx4_slave_cap()
1042 dev->caps.eqe_size = 64; in mlx4_slave_cap()
1043 dev->caps.eqe_factor = 1; in mlx4_slave_cap()
1045 dev->caps.eqe_size = 32; in mlx4_slave_cap()
1046 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
1050 dev->caps.cqe_size = 64; in mlx4_slave_cap()
1051 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
1053 dev->caps.cqe_size = 32; in mlx4_slave_cap()
1057 dev->caps.eqe_size = hca_param->eqe_size; in mlx4_slave_cap()
1058 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
1062 dev->caps.cqe_size = hca_param->cqe_size; in mlx4_slave_cap()
1064 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
1067 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_slave_cap()
1068 mlx4_warn(dev, "Timestamping is not supported in slave mode\n"); in mlx4_slave_cap()
1070 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_USER_MAC_EN; in mlx4_slave_cap()
1071 mlx4_dbg(dev, "User MAC FW update is not supported in slave mode\n"); in mlx4_slave_cap()
1073 slave_adjust_steering_mode(dev, dev_cap, hca_param); in mlx4_slave_cap()
1074 mlx4_dbg(dev, "RSS support for IP fragments is %s\n", in mlx4_slave_cap()
1078 dev->caps.bf_reg_size) in mlx4_slave_cap()
1079 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_ETH_BF_QP; in mlx4_slave_cap()
1082 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_A0_QP; in mlx4_slave_cap()
1086 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_slave_cap()
1094 static void mlx4_request_modules(struct mlx4_dev *dev) in mlx4_request_modules() argument
1102 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_request_modules()
1103 if (dev->caps.port_type[port] == MLX4_PORT_TYPE_IB) in mlx4_request_modules()
1105 else if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) in mlx4_request_modules()
1111 if (has_ib_port || (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE)) in mlx4_request_modules()
1119 int mlx4_change_port_types(struct mlx4_dev *dev, in mlx4_change_port_types() argument
1126 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_change_port_types()
1129 if (port_types[port] != dev->caps.port_type[port + 1]) in mlx4_change_port_types()
1133 mlx4_unregister_device(dev); in mlx4_change_port_types()
1134 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_change_port_types()
1135 mlx4_CLOSE_PORT(dev, port); in mlx4_change_port_types()
1136 dev->caps.port_type[port] = port_types[port - 1]; in mlx4_change_port_types()
1137 err = mlx4_SET_PORT(dev, port, -1); in mlx4_change_port_types()
1139 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_change_port_types()
1144 mlx4_set_port_mask(dev); in mlx4_change_port_types()
1145 err = mlx4_register_device(dev); in mlx4_change_port_types()
1147 mlx4_err(dev, "Failed to register device\n"); in mlx4_change_port_types()
1150 mlx4_request_modules(dev); in mlx4_change_port_types()
1157 static ssize_t show_port_type(struct device *dev, in show_port_type() argument
1163 struct mlx4_dev *mdev = info->dev; in show_port_type()
1180 struct mlx4_dev *mdev = info->dev; in __set_port_type()
1243 static ssize_t set_port_type(struct device *dev, in set_port_type() argument
1249 struct mlx4_dev *mdev = info->dev; in set_port_type()
1308 static ssize_t show_port_ib_mtu(struct device *dev, in show_port_ib_mtu() argument
1314 struct mlx4_dev *mdev = info->dev; in show_port_ib_mtu()
1324 static ssize_t set_port_ib_mtu(struct device *dev, in set_port_ib_mtu() argument
1330 struct mlx4_dev *mdev = info->dev; in set_port_ib_mtu()
1371 static int mlx4_mf_bond(struct mlx4_dev *dev) in mlx4_mf_bond() argument
1379 slaves_port1 = mlx4_phys_to_slaves_pport(dev, 1); in mlx4_mf_bond()
1380 slaves_port2 = mlx4_phys_to_slaves_pport(dev, 2); in mlx4_mf_bond()
1383 dev->persist->num_vfs + 1); in mlx4_mf_bond()
1386 if (bitmap_weight(slaves_port_1_2, dev->persist->num_vfs + 1) > 1) { in mlx4_mf_bond()
1387 mlx4_warn(dev, "HA mode unsupported for dual ported VFs\n"); in mlx4_mf_bond()
1394 nvfs = bitmap_weight(slaves_port1.slaves, dev->persist->num_vfs + 1) + in mlx4_mf_bond()
1395 bitmap_weight(slaves_port2.slaves, dev->persist->num_vfs + 1) - 2; in mlx4_mf_bond()
1399 mlx4_warn(dev, "HA mode is not supported for %d VFs (max %d are allowed)\n", in mlx4_mf_bond()
1404 if (dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) { in mlx4_mf_bond()
1405 mlx4_warn(dev, "HA mode unsupported for NON DMFS steering\n"); in mlx4_mf_bond()
1409 err = mlx4_bond_mac_table(dev); in mlx4_mf_bond()
1412 err = mlx4_bond_vlan_table(dev); in mlx4_mf_bond()
1415 err = mlx4_bond_fs_rules(dev); in mlx4_mf_bond()
1421 (void)mlx4_unbond_vlan_table(dev); in mlx4_mf_bond()
1423 (void)mlx4_unbond_mac_table(dev); in mlx4_mf_bond()
1427 static int mlx4_mf_unbond(struct mlx4_dev *dev) in mlx4_mf_unbond() argument
1431 ret = mlx4_unbond_fs_rules(dev); in mlx4_mf_unbond()
1433 mlx4_warn(dev, "multifunction unbond for flow rules failed (%d)\n", ret); in mlx4_mf_unbond()
1434 ret1 = mlx4_unbond_mac_table(dev); in mlx4_mf_unbond()
1436 mlx4_warn(dev, "multifunction unbond for MAC table failed (%d)\n", ret1); in mlx4_mf_unbond()
1439 ret1 = mlx4_unbond_vlan_table(dev); in mlx4_mf_unbond()
1441 mlx4_warn(dev, "multifunction unbond for VLAN table failed (%d)\n", ret1); in mlx4_mf_unbond()
1447 int mlx4_bond(struct mlx4_dev *dev) in mlx4_bond() argument
1450 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_bond()
1454 if (!mlx4_is_bonded(dev)) { in mlx4_bond()
1455 ret = mlx4_do_bond(dev, true); in mlx4_bond()
1457 mlx4_err(dev, "Failed to bond device: %d\n", ret); in mlx4_bond()
1458 if (!ret && mlx4_is_master(dev)) { in mlx4_bond()
1459 ret = mlx4_mf_bond(dev); in mlx4_bond()
1461 mlx4_err(dev, "bond for multifunction failed\n"); in mlx4_bond()
1462 mlx4_do_bond(dev, false); in mlx4_bond()
1469 mlx4_dbg(dev, "Device is bonded\n"); in mlx4_bond()
1475 int mlx4_unbond(struct mlx4_dev *dev) in mlx4_unbond() argument
1478 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unbond()
1482 if (mlx4_is_bonded(dev)) { in mlx4_unbond()
1485 ret = mlx4_do_bond(dev, false); in mlx4_unbond()
1487 mlx4_err(dev, "Failed to unbond device: %d\n", ret); in mlx4_unbond()
1488 if (mlx4_is_master(dev)) in mlx4_unbond()
1489 ret2 = mlx4_mf_unbond(dev); in mlx4_unbond()
1491 mlx4_warn(dev, "Failed to unbond device for multifunction (%d)\n", ret2); in mlx4_unbond()
1498 mlx4_dbg(dev, "Device is unbonded\n"); in mlx4_unbond()
1505 int mlx4_port_map_set(struct mlx4_dev *dev, struct mlx4_port_map *v2p) in mlx4_port_map_set() argument
1509 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_port_map_set()
1512 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_REMAP)) in mlx4_port_map_set()
1533 err = mlx4_virt2phy_port_map(dev, port1, port2); in mlx4_port_map_set()
1535 mlx4_dbg(dev, "port map changed: [%d][%d]\n", in mlx4_port_map_set()
1540 mlx4_err(dev, "Failed to change port mape: %d\n", err); in mlx4_port_map_set()
1549 static int mlx4_load_fw(struct mlx4_dev *dev) in mlx4_load_fw() argument
1551 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_load_fw()
1554 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages, in mlx4_load_fw()
1557 mlx4_err(dev, "Couldn't allocate FW area, aborting\n"); in mlx4_load_fw()
1561 err = mlx4_MAP_FA(dev, priv->fw.fw_icm); in mlx4_load_fw()
1563 mlx4_err(dev, "MAP_FA command failed, aborting\n"); in mlx4_load_fw()
1567 err = mlx4_RUN_FW(dev); in mlx4_load_fw()
1569 mlx4_err(dev, "RUN_FW command failed, aborting\n"); in mlx4_load_fw()
1576 mlx4_UNMAP_FA(dev); in mlx4_load_fw()
1579 mlx4_free_icm(dev, priv->fw.fw_icm, 0); in mlx4_load_fw()
1583 static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base, in mlx4_init_cmpt_table() argument
1586 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_cmpt_table()
1590 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table, in mlx4_init_cmpt_table()
1594 cmpt_entry_sz, dev->caps.num_qps, in mlx4_init_cmpt_table()
1595 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_cmpt_table()
1600 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table, in mlx4_init_cmpt_table()
1604 cmpt_entry_sz, dev->caps.num_srqs, in mlx4_init_cmpt_table()
1605 dev->caps.reserved_srqs, 0, 0); in mlx4_init_cmpt_table()
1609 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table, in mlx4_init_cmpt_table()
1613 cmpt_entry_sz, dev->caps.num_cqs, in mlx4_init_cmpt_table()
1614 dev->caps.reserved_cqs, 0, 0); in mlx4_init_cmpt_table()
1618 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_cmpt_table()
1619 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table, in mlx4_init_cmpt_table()
1630 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_cmpt_table()
1633 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_cmpt_table()
1636 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_cmpt_table()
1642 static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_init_icm() argument
1645 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_icm()
1650 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages); in mlx4_init_icm()
1652 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting\n"); in mlx4_init_icm()
1656 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory\n", in mlx4_init_icm()
1660 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages, in mlx4_init_icm()
1663 mlx4_err(dev, "Couldn't allocate aux memory, aborting\n"); in mlx4_init_icm()
1667 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm); in mlx4_init_icm()
1669 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting\n"); in mlx4_init_icm()
1673 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz); in mlx4_init_icm()
1675 mlx4_err(dev, "Failed to map cMPT context memory, aborting\n"); in mlx4_init_icm()
1680 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_icm()
1681 err = mlx4_init_icm_table(dev, &priv->eq_table.table, in mlx4_init_icm()
1685 mlx4_err(dev, "Failed to map EQ context memory, aborting\n"); in mlx4_init_icm()
1693 * dev->caps.mtt_entry_sz below is really the MTT segment in mlx4_init_icm()
1696 dev->caps.reserved_mtts = in mlx4_init_icm()
1697 ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz, in mlx4_init_icm()
1698 dma_get_cache_alignment()) / dev->caps.mtt_entry_sz; in mlx4_init_icm()
1700 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table, in mlx4_init_icm()
1702 dev->caps.mtt_entry_sz, in mlx4_init_icm()
1703 dev->caps.num_mtts, in mlx4_init_icm()
1704 dev->caps.reserved_mtts, 1, 0); in mlx4_init_icm()
1706 mlx4_err(dev, "Failed to map MTT context memory, aborting\n"); in mlx4_init_icm()
1710 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table, in mlx4_init_icm()
1713 dev->caps.num_mpts, in mlx4_init_icm()
1714 dev->caps.reserved_mrws, 1, 1); in mlx4_init_icm()
1716 mlx4_err(dev, "Failed to map dMPT context memory, aborting\n"); in mlx4_init_icm()
1720 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table, in mlx4_init_icm()
1723 dev->caps.num_qps, in mlx4_init_icm()
1724 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1727 mlx4_err(dev, "Failed to map QP context memory, aborting\n"); in mlx4_init_icm()
1731 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table, in mlx4_init_icm()
1734 dev->caps.num_qps, in mlx4_init_icm()
1735 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1738 mlx4_err(dev, "Failed to map AUXC context memory, aborting\n"); in mlx4_init_icm()
1742 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table, in mlx4_init_icm()
1745 dev->caps.num_qps, in mlx4_init_icm()
1746 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1749 mlx4_err(dev, "Failed to map ALTC context memory, aborting\n"); in mlx4_init_icm()
1753 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table, in mlx4_init_icm()
1756 dev->caps.num_qps, in mlx4_init_icm()
1757 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1760 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n"); in mlx4_init_icm()
1764 err = mlx4_init_icm_table(dev, &priv->cq_table.table, in mlx4_init_icm()
1767 dev->caps.num_cqs, in mlx4_init_icm()
1768 dev->caps.reserved_cqs, 0, 0); in mlx4_init_icm()
1770 mlx4_err(dev, "Failed to map CQ context memory, aborting\n"); in mlx4_init_icm()
1774 err = mlx4_init_icm_table(dev, &priv->srq_table.table, in mlx4_init_icm()
1777 dev->caps.num_srqs, in mlx4_init_icm()
1778 dev->caps.reserved_srqs, 0, 0); in mlx4_init_icm()
1780 mlx4_err(dev, "Failed to map SRQ context memory, aborting\n"); in mlx4_init_icm()
1791 err = mlx4_init_icm_table(dev, &priv->mcg_table.table, in mlx4_init_icm()
1793 mlx4_get_mgm_entry_size(dev), in mlx4_init_icm()
1794 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1795 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1798 mlx4_err(dev, "Failed to map MCG context memory, aborting\n"); in mlx4_init_icm()
1805 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_init_icm()
1808 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_init_icm()
1811 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_init_icm()
1814 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_init_icm()
1817 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_init_icm()
1820 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_init_icm()
1823 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_init_icm()
1826 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_init_icm()
1829 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_init_icm()
1832 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_init_icm()
1833 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_icm()
1834 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_icm()
1835 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_icm()
1838 mlx4_UNMAP_ICM_AUX(dev); in mlx4_init_icm()
1841 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_init_icm()
1846 static void mlx4_free_icms(struct mlx4_dev *dev) in mlx4_free_icms() argument
1848 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_free_icms()
1850 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table); in mlx4_free_icms()
1851 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_free_icms()
1852 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_free_icms()
1853 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_free_icms()
1854 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_free_icms()
1855 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_free_icms()
1856 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_free_icms()
1857 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_free_icms()
1858 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_free_icms()
1859 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_free_icms()
1860 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_free_icms()
1861 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_free_icms()
1862 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_free_icms()
1863 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_free_icms()
1865 mlx4_UNMAP_ICM_AUX(dev); in mlx4_free_icms()
1866 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_free_icms()
1869 static void mlx4_slave_exit(struct mlx4_dev *dev) in mlx4_slave_exit() argument
1871 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_slave_exit()
1874 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, in mlx4_slave_exit()
1876 mlx4_warn(dev, "Failed to close slave function\n"); in mlx4_slave_exit()
1880 static int map_bf_area(struct mlx4_dev *dev) in map_bf_area() argument
1882 struct mlx4_priv *priv = mlx4_priv(dev); in map_bf_area()
1887 if (!dev->caps.bf_reg_size) in map_bf_area()
1890 bf_start = pci_resource_start(dev->persist->pdev, 2) + in map_bf_area()
1891 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1892 bf_len = pci_resource_len(dev->persist->pdev, 2) - in map_bf_area()
1893 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1901 static void unmap_bf_area(struct mlx4_dev *dev) in unmap_bf_area() argument
1903 if (mlx4_priv(dev)->bf_mapping) in unmap_bf_area()
1904 io_mapping_free(mlx4_priv(dev)->bf_mapping); in unmap_bf_area()
1907 u64 mlx4_read_clock(struct mlx4_dev *dev) in mlx4_read_clock() argument
1912 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_read_clock()
1929 static int map_internal_clock(struct mlx4_dev *dev) in map_internal_clock() argument
1931 struct mlx4_priv *priv = mlx4_priv(dev); in map_internal_clock()
1934 ioremap(pci_resource_start(dev->persist->pdev, in map_internal_clock()
1944 int mlx4_get_internal_clock_params(struct mlx4_dev *dev, in mlx4_get_internal_clock_params() argument
1947 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_internal_clock_params()
1949 if (mlx4_is_slave(dev)) in mlx4_get_internal_clock_params()
1952 if (!dev->caps.map_clock_to_user) { in mlx4_get_internal_clock_params()
1953 mlx4_dbg(dev, "Map clock to user is not supported.\n"); in mlx4_get_internal_clock_params()
1968 static void unmap_internal_clock(struct mlx4_dev *dev) in unmap_internal_clock() argument
1970 struct mlx4_priv *priv = mlx4_priv(dev); in unmap_internal_clock()
1976 static void mlx4_close_hca(struct mlx4_dev *dev) in mlx4_close_hca() argument
1978 unmap_internal_clock(dev); in mlx4_close_hca()
1979 unmap_bf_area(dev); in mlx4_close_hca()
1980 if (mlx4_is_slave(dev)) in mlx4_close_hca()
1981 mlx4_slave_exit(dev); in mlx4_close_hca()
1983 mlx4_CLOSE_HCA(dev, 0); in mlx4_close_hca()
1984 mlx4_free_icms(dev); in mlx4_close_hca()
1988 static void mlx4_close_fw(struct mlx4_dev *dev) in mlx4_close_fw() argument
1990 if (!mlx4_is_slave(dev)) { in mlx4_close_fw()
1991 mlx4_UNMAP_FA(dev); in mlx4_close_fw()
1992 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0); in mlx4_close_fw()
1996 static int mlx4_comm_check_offline(struct mlx4_dev *dev) in mlx4_comm_check_offline() argument
2003 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_comm_check_offline()
2017 if (dev->persist->interface_state & in mlx4_comm_check_offline()
2028 mlx4_err(dev, "Communication channel is offline.\n"); in mlx4_comm_check_offline()
2032 static void mlx4_reset_vf_support(struct mlx4_dev *dev) in mlx4_reset_vf_support() argument
2036 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_reset_vf_support()
2045 dev->caps.vf_caps |= MLX4_VF_CAP_FLAG_RESET; in mlx4_reset_vf_support()
2048 static int mlx4_init_slave(struct mlx4_dev *dev) in mlx4_init_slave() argument
2050 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_slave()
2057 mlx4_warn(dev, "PF is not ready - Deferring probe\n"); in mlx4_init_slave()
2063 if (mlx4_comm_check_offline(dev)) { in mlx4_init_slave()
2064 mlx4_err(dev, "PF is not responsive, skipping initialization\n"); in mlx4_init_slave()
2068 mlx4_reset_vf_support(dev); in mlx4_init_slave()
2069 mlx4_warn(dev, "Sending reset\n"); in mlx4_init_slave()
2070 ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, in mlx4_init_slave()
2076 mlx4_warn(dev, "slave is currently in the middle of FLR - Deferring probe\n"); in mlx4_init_slave()
2090 mlx4_err(dev, "slave driver version is not supported by the master\n"); in mlx4_init_slave()
2094 mlx4_warn(dev, "Sending vhcr0\n"); in mlx4_init_slave()
2095 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48, in mlx4_init_slave()
2098 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32, in mlx4_init_slave()
2101 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16, in mlx4_init_slave()
2104 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, in mlx4_init_slave()
2112 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, 0); in mlx4_init_slave()
2118 static void mlx4_parav_master_pf_caps(struct mlx4_dev *dev) in mlx4_parav_master_pf_caps() argument
2122 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_parav_master_pf_caps()
2123 if (dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_parav_master_pf_caps()
2124 dev->caps.gid_table_len[i] = in mlx4_parav_master_pf_caps()
2125 mlx4_get_slave_num_gids(dev, 0, i); in mlx4_parav_master_pf_caps()
2127 dev->caps.gid_table_len[i] = 1; in mlx4_parav_master_pf_caps()
2128 dev->caps.pkey_table_len[i] = in mlx4_parav_master_pf_caps()
2129 dev->phys_caps.pkey_phys_table_len[i] - 1; in mlx4_parav_master_pf_caps()
2171 static void choose_steering_mode(struct mlx4_dev *dev, in choose_steering_mode() argument
2176 if (dev->caps.dmfs_high_steer_mode == in choose_steering_mode()
2178 mlx4_err(dev, "DMFS high rate mode not supported\n"); in choose_steering_mode()
2180 dev->caps.dmfs_high_steer_mode = in choose_steering_mode()
2187 (!mlx4_is_mfunc(dev) || in choose_steering_mode()
2189 (dev->persist->num_vfs + 1))) && in choose_steering_mode()
2192 dev->oper_log_mgm_entry_size = in choose_steering_mode()
2194 dev->caps.steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED; in choose_steering_mode()
2195 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in choose_steering_mode()
2196 dev->caps.fs_log_max_ucast_qp_range_size = in choose_steering_mode()
2199 if (dev->caps.dmfs_high_steer_mode != in choose_steering_mode()
2201 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DISABLE; in choose_steering_mode()
2202 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER && in choose_steering_mode()
2203 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
2204 dev->caps.steering_mode = MLX4_STEERING_MODE_B0; in choose_steering_mode()
2206 dev->caps.steering_mode = MLX4_STEERING_MODE_A0; in choose_steering_mode()
2208 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER || in choose_steering_mode()
2209 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
2210 …mlx4_warn(dev, "Must have both UC_STEER and MC_STEER flags set to use B0 steering - falling back t… in choose_steering_mode()
2212 dev->oper_log_mgm_entry_size = in choose_steering_mode()
2216 dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev); in choose_steering_mode()
2218 …mlx4_dbg(dev, "Steering mode is: %s, oper_log_mgm_entry_size = %d, modparam log_num_mgm_entry_size… in choose_steering_mode()
2219 mlx4_steering_mode_str(dev->caps.steering_mode), in choose_steering_mode()
2220 dev->oper_log_mgm_entry_size, in choose_steering_mode()
2224 static void choose_tunnel_offload_mode(struct mlx4_dev *dev, in choose_tunnel_offload_mode() argument
2227 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED && in choose_tunnel_offload_mode()
2229 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_VXLAN; in choose_tunnel_offload_mode()
2231 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_NONE; in choose_tunnel_offload_mode()
2233 mlx4_dbg(dev, "Tunneling offload mode is: %s\n", (dev->caps.tunnel_offload_mode in choose_tunnel_offload_mode()
2237 static int mlx4_validate_optimized_steering(struct mlx4_dev *dev) in mlx4_validate_optimized_steering() argument
2242 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_NOT_SUPPORTED) in mlx4_validate_optimized_steering()
2245 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_validate_optimized_steering()
2246 if (mlx4_dev_port(dev, i, &port_cap)) { in mlx4_validate_optimized_steering()
2247 mlx4_err(dev, in mlx4_validate_optimized_steering()
2249 } else if ((dev->caps.dmfs_high_steer_mode != in mlx4_validate_optimized_steering()
2252 !!(dev->caps.dmfs_high_steer_mode == in mlx4_validate_optimized_steering()
2254 mlx4_err(dev, in mlx4_validate_optimized_steering()
2257 dev->caps.dmfs_high_steer_mode), in mlx4_validate_optimized_steering()
2266 static int mlx4_init_fw(struct mlx4_dev *dev) in mlx4_init_fw() argument
2271 if (!mlx4_is_slave(dev)) { in mlx4_init_fw()
2272 err = mlx4_QUERY_FW(dev); in mlx4_init_fw()
2275 mlx4_info(dev, "non-primary physical function, skipping\n"); in mlx4_init_fw()
2277 mlx4_err(dev, "QUERY_FW command failed, aborting\n"); in mlx4_init_fw()
2281 err = mlx4_load_fw(dev); in mlx4_init_fw()
2283 mlx4_err(dev, "Failed to start FW, aborting\n"); in mlx4_init_fw()
2289 err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg); in mlx4_init_fw()
2291 mlx4_warn(dev, "Failed to override log_pg_sz parameter\n"); in mlx4_init_fw()
2297 static int mlx4_init_hca(struct mlx4_dev *dev) in mlx4_init_hca() argument
2299 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_hca()
2308 if (!mlx4_is_slave(dev)) { in mlx4_init_hca()
2317 err = mlx4_dev_cap(dev, dev_cap); in mlx4_init_hca()
2319 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_init_hca()
2323 choose_steering_mode(dev, dev_cap); in mlx4_init_hca()
2324 choose_tunnel_offload_mode(dev, dev_cap); in mlx4_init_hca()
2326 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC && in mlx4_init_hca()
2327 mlx4_is_master(dev)) in mlx4_init_hca()
2328 dev->caps.function_caps |= MLX4_FUNC_CAP_DMFS_A0_STATIC; in mlx4_init_hca()
2330 err = mlx4_get_phys_port_id(dev); in mlx4_init_hca()
2332 mlx4_err(dev, "Fail to get physical port id\n"); in mlx4_init_hca()
2334 if (mlx4_is_master(dev)) in mlx4_init_hca()
2335 mlx4_parav_master_pf_caps(dev); in mlx4_init_hca()
2338 mlx4_info(dev, "Running from within kdump kernel. Using low memory profile\n"); in mlx4_init_hca()
2343 if (dev->caps.steering_mode == in mlx4_init_hca()
2347 icm_size = mlx4_make_profile(dev, &profile, dev_cap, in mlx4_init_hca()
2354 if (enable_4k_uar || !dev->persist->num_vfs) { in mlx4_init_hca()
2355 init_hca->log_uar_sz = ilog2(dev->caps.num_uars) + in mlx4_init_hca()
2359 init_hca->log_uar_sz = ilog2(dev->caps.num_uars); in mlx4_init_hca()
2364 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW || in mlx4_init_hca()
2365 dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) in mlx4_init_hca()
2368 err = mlx4_init_icm(dev, dev_cap, init_hca, icm_size); in mlx4_init_hca()
2372 err = mlx4_INIT_HCA(dev, init_hca); in mlx4_init_hca()
2374 mlx4_err(dev, "INIT_HCA command failed, aborting\n"); in mlx4_init_hca()
2379 err = mlx4_query_func(dev, dev_cap); in mlx4_init_hca()
2381 mlx4_err(dev, "QUERY_FUNC command failed, aborting.\n"); in mlx4_init_hca()
2384 dev->caps.num_eqs = dev_cap->max_eqs; in mlx4_init_hca()
2385 dev->caps.reserved_eqs = dev_cap->reserved_eqs; in mlx4_init_hca()
2386 dev->caps.reserved_uars = dev_cap->reserved_uars; in mlx4_init_hca()
2394 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) { in mlx4_init_hca()
2395 err = mlx4_QUERY_HCA(dev, init_hca); in mlx4_init_hca()
2397 mlx4_err(dev, "QUERY_HCA command failed, disable timestamp\n"); in mlx4_init_hca()
2398 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2400 dev->caps.hca_core_clock = in mlx4_init_hca()
2407 if (!dev->caps.hca_core_clock) { in mlx4_init_hca()
2408 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2409 mlx4_err(dev, in mlx4_init_hca()
2411 } else if (map_internal_clock(dev)) { in mlx4_init_hca()
2416 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2417 mlx4_err(dev, "Failed to map internal clock. Timestamping is not supported\n"); in mlx4_init_hca()
2421 if (dev->caps.dmfs_high_steer_mode != in mlx4_init_hca()
2423 if (mlx4_validate_optimized_steering(dev)) in mlx4_init_hca()
2424 mlx4_warn(dev, "Optimized steering validation failed\n"); in mlx4_init_hca()
2426 if (dev->caps.dmfs_high_steer_mode == in mlx4_init_hca()
2428 dev->caps.dmfs_high_rate_qpn_base = in mlx4_init_hca()
2429 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_init_hca()
2430 dev->caps.dmfs_high_rate_qpn_range = in mlx4_init_hca()
2434 mlx4_info(dev, "DMFS high rate steer mode is: %s\n", in mlx4_init_hca()
2436 dev->caps.dmfs_high_steer_mode)); in mlx4_init_hca()
2439 err = mlx4_init_slave(dev); in mlx4_init_hca()
2442 mlx4_err(dev, "Failed to initialize slave\n"); in mlx4_init_hca()
2446 err = mlx4_slave_cap(dev); in mlx4_init_hca()
2448 mlx4_err(dev, "Failed to obtain slave caps\n"); in mlx4_init_hca()
2453 if (map_bf_area(dev)) in mlx4_init_hca()
2454 mlx4_dbg(dev, "Failed to map blue flame area\n"); in mlx4_init_hca()
2457 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2458 mlx4_set_port_mask(dev); in mlx4_init_hca()
2460 err = mlx4_QUERY_ADAPTER(dev, &adapter); in mlx4_init_hca()
2462 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting\n"); in mlx4_init_hca()
2467 err = mlx4_config_dev_retrieval(dev, ¶ms); in mlx4_init_hca()
2469 mlx4_err(dev, "Failed to query CONFIG_DEV parameters\n"); in mlx4_init_hca()
2471 dev->caps.rx_checksum_flags_port[1] = params.rx_csum_flags_port_1; in mlx4_init_hca()
2472 dev->caps.rx_checksum_flags_port[2] = params.rx_csum_flags_port_2; in mlx4_init_hca()
2475 memcpy(dev->board_id, adapter.board_id, sizeof(dev->board_id)); in mlx4_init_hca()
2481 unmap_internal_clock(dev); in mlx4_init_hca()
2482 unmap_bf_area(dev); in mlx4_init_hca()
2484 if (mlx4_is_slave(dev)) in mlx4_init_hca()
2485 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_init_hca()
2488 if (mlx4_is_slave(dev)) in mlx4_init_hca()
2489 mlx4_slave_exit(dev); in mlx4_init_hca()
2491 mlx4_CLOSE_HCA(dev, 0); in mlx4_init_hca()
2494 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2495 mlx4_free_icms(dev); in mlx4_init_hca()
2504 static int mlx4_init_counters_table(struct mlx4_dev *dev) in mlx4_init_counters_table() argument
2506 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_counters_table()
2509 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_init_counters_table()
2512 if (!dev->caps.max_counters) in mlx4_init_counters_table()
2515 nent_pow2 = roundup_pow_of_two(dev->caps.max_counters); in mlx4_init_counters_table()
2519 nent_pow2 - dev->caps.max_counters + 1); in mlx4_init_counters_table()
2522 static void mlx4_cleanup_counters_table(struct mlx4_dev *dev) in mlx4_cleanup_counters_table() argument
2524 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_cleanup_counters_table()
2527 if (!dev->caps.max_counters) in mlx4_cleanup_counters_table()
2530 mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap); in mlx4_cleanup_counters_table()
2533 static void mlx4_cleanup_default_counters(struct mlx4_dev *dev) in mlx4_cleanup_default_counters() argument
2535 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_cleanup_default_counters()
2538 for (port = 0; port < dev->caps.num_ports; port++) in mlx4_cleanup_default_counters()
2540 mlx4_counter_free(dev, priv->def_counter[port]); in mlx4_cleanup_default_counters()
2543 static int mlx4_allocate_default_counters(struct mlx4_dev *dev) in mlx4_allocate_default_counters() argument
2545 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_allocate_default_counters()
2549 for (port = 0; port < dev->caps.num_ports; port++) in mlx4_allocate_default_counters()
2552 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_allocate_default_counters()
2553 err = mlx4_counter_alloc(dev, &idx, MLX4_RES_USAGE_DRIVER); in mlx4_allocate_default_counters()
2561 } else if (mlx4_is_slave(dev) && err == -EINVAL) { in mlx4_allocate_default_counters()
2562 priv->def_counter[port] = MLX4_SINK_COUNTER_INDEX(dev); in mlx4_allocate_default_counters()
2563 mlx4_warn(dev, "can't allocate counter from old PF driver, using index %d\n", in mlx4_allocate_default_counters()
2564 MLX4_SINK_COUNTER_INDEX(dev)); in mlx4_allocate_default_counters()
2567 mlx4_err(dev, "%s: failed to allocate default counter port %d err %d\n", in mlx4_allocate_default_counters()
2569 mlx4_cleanup_default_counters(dev); in mlx4_allocate_default_counters()
2573 mlx4_dbg(dev, "%s: default counter index %d for port %d\n", in mlx4_allocate_default_counters()
2580 int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) in __mlx4_counter_alloc() argument
2582 struct mlx4_priv *priv = mlx4_priv(dev); in __mlx4_counter_alloc()
2584 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_alloc()
2589 *idx = MLX4_SINK_COUNTER_INDEX(dev); in __mlx4_counter_alloc()
2596 int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx, u8 usage) in mlx4_counter_alloc() argument
2602 if (mlx4_is_mfunc(dev)) { in mlx4_counter_alloc()
2603 err = mlx4_cmd_imm(dev, 0, &out_param, in_modifier, in mlx4_counter_alloc()
2612 return __mlx4_counter_alloc(dev, idx); in mlx4_counter_alloc()
2616 static int __mlx4_clear_if_stat(struct mlx4_dev *dev, in __mlx4_clear_if_stat() argument
2623 if_stat_mailbox = mlx4_alloc_cmd_mailbox(dev); in __mlx4_clear_if_stat()
2627 err = mlx4_cmd_box(dev, 0, if_stat_mailbox->dma, if_stat_in_mod, 0, in __mlx4_clear_if_stat()
2631 mlx4_free_cmd_mailbox(dev, if_stat_mailbox); in __mlx4_clear_if_stat()
2635 void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in __mlx4_counter_free() argument
2637 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_free()
2640 if (idx == MLX4_SINK_COUNTER_INDEX(dev)) in __mlx4_counter_free()
2643 __mlx4_clear_if_stat(dev, idx); in __mlx4_counter_free()
2645 mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx, MLX4_USE_RR); in __mlx4_counter_free()
2649 void mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in mlx4_counter_free() argument
2653 if (mlx4_is_mfunc(dev)) { in mlx4_counter_free()
2655 mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE, in mlx4_counter_free()
2660 __mlx4_counter_free(dev, idx); in mlx4_counter_free()
2664 int mlx4_get_default_counter_index(struct mlx4_dev *dev, int port) in mlx4_get_default_counter_index() argument
2666 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_default_counter_index()
2672 void mlx4_set_admin_guid(struct mlx4_dev *dev, __be64 guid, int entry, int port) in mlx4_set_admin_guid() argument
2674 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_admin_guid()
2680 __be64 mlx4_get_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_get_admin_guid() argument
2682 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_admin_guid()
2688 void mlx4_set_random_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_set_random_admin_guid() argument
2690 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_random_admin_guid()
2703 static int mlx4_setup_hca(struct mlx4_dev *dev) in mlx4_setup_hca() argument
2705 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_setup_hca()
2710 err = mlx4_init_uar_table(dev); in mlx4_setup_hca()
2712 mlx4_err(dev, "Failed to initialize user access region table, aborting\n"); in mlx4_setup_hca()
2716 err = mlx4_uar_alloc(dev, &priv->driver_uar); in mlx4_setup_hca()
2718 mlx4_err(dev, "Failed to allocate driver access region, aborting\n"); in mlx4_setup_hca()
2724 mlx4_err(dev, "Couldn't map kernel access region, aborting\n"); in mlx4_setup_hca()
2729 err = mlx4_init_pd_table(dev); in mlx4_setup_hca()
2731 mlx4_err(dev, "Failed to initialize protection domain table, aborting\n"); in mlx4_setup_hca()
2735 err = mlx4_init_xrcd_table(dev); in mlx4_setup_hca()
2737 mlx4_err(dev, "Failed to initialize reliable connection domain table, aborting\n"); in mlx4_setup_hca()
2741 err = mlx4_init_mr_table(dev); in mlx4_setup_hca()
2743 mlx4_err(dev, "Failed to initialize memory region table, aborting\n"); in mlx4_setup_hca()
2747 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2748 err = mlx4_init_mcg_table(dev); in mlx4_setup_hca()
2750 mlx4_err(dev, "Failed to initialize multicast group table, aborting\n"); in mlx4_setup_hca()
2753 err = mlx4_config_mad_demux(dev); in mlx4_setup_hca()
2755 mlx4_err(dev, "Failed in config_mad_demux, aborting\n"); in mlx4_setup_hca()
2760 err = mlx4_init_eq_table(dev); in mlx4_setup_hca()
2762 mlx4_err(dev, "Failed to initialize event queue table, aborting\n"); in mlx4_setup_hca()
2766 err = mlx4_cmd_use_events(dev); in mlx4_setup_hca()
2768 mlx4_err(dev, "Failed to switch to event-driven firmware commands, aborting\n"); in mlx4_setup_hca()
2772 err = mlx4_NOP(dev); in mlx4_setup_hca()
2774 if (dev->flags & MLX4_FLAG_MSI_X) { in mlx4_setup_hca()
2775 mlx4_warn(dev, "NOP command failed to generate MSI-X interrupt IRQ %d)\n", in mlx4_setup_hca()
2777 mlx4_warn(dev, "Trying again without MSI-X\n"); in mlx4_setup_hca()
2779 mlx4_err(dev, "NOP command failed to generate interrupt (IRQ %d), aborting\n", in mlx4_setup_hca()
2781 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n"); in mlx4_setup_hca()
2787 mlx4_dbg(dev, "NOP command IRQ test passed\n"); in mlx4_setup_hca()
2789 err = mlx4_init_cq_table(dev); in mlx4_setup_hca()
2791 mlx4_err(dev, "Failed to initialize completion queue table, aborting\n"); in mlx4_setup_hca()
2795 err = mlx4_init_srq_table(dev); in mlx4_setup_hca()
2797 mlx4_err(dev, "Failed to initialize shared receive queue table, aborting\n"); in mlx4_setup_hca()
2801 err = mlx4_init_qp_table(dev); in mlx4_setup_hca()
2803 mlx4_err(dev, "Failed to initialize queue pair table, aborting\n"); in mlx4_setup_hca()
2807 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2808 err = mlx4_init_counters_table(dev); in mlx4_setup_hca()
2810 mlx4_err(dev, "Failed to initialize counters table, aborting\n"); in mlx4_setup_hca()
2815 err = mlx4_allocate_default_counters(dev); in mlx4_setup_hca()
2817 mlx4_err(dev, "Failed to allocate default counters, aborting\n"); in mlx4_setup_hca()
2821 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2822 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_setup_hca()
2824 err = mlx4_get_port_ib_caps(dev, port, in mlx4_setup_hca()
2827 mlx4_warn(dev, "failed to get port %d default ib capabilities (%d). Continuing with caps = 0\n", in mlx4_setup_hca()
2829 dev->caps.ib_port_def_cap[port] = ib_port_default_caps; in mlx4_setup_hca()
2832 if (mlx4_is_master(dev)) { in mlx4_setup_hca()
2834 for (i = 0; i < dev->num_slaves; i++) { in mlx4_setup_hca()
2835 if (i == mlx4_master_func_num(dev)) in mlx4_setup_hca()
2842 if (mlx4_is_mfunc(dev)) in mlx4_setup_hca()
2843 dev->caps.port_ib_mtu[port] = IB_MTU_2048; in mlx4_setup_hca()
2845 dev->caps.port_ib_mtu[port] = IB_MTU_4096; in mlx4_setup_hca()
2847 err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ? in mlx4_setup_hca()
2848 dev->caps.pkey_table_len[port] : -1); in mlx4_setup_hca()
2850 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_setup_hca()
2860 mlx4_cleanup_default_counters(dev); in mlx4_setup_hca()
2863 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2864 mlx4_cleanup_counters_table(dev); in mlx4_setup_hca()
2867 mlx4_cleanup_qp_table(dev); in mlx4_setup_hca()
2870 mlx4_cleanup_srq_table(dev); in mlx4_setup_hca()
2873 mlx4_cleanup_cq_table(dev); in mlx4_setup_hca()
2876 mlx4_cmd_use_polling(dev); in mlx4_setup_hca()
2879 mlx4_cleanup_eq_table(dev); in mlx4_setup_hca()
2882 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2883 mlx4_cleanup_mcg_table(dev); in mlx4_setup_hca()
2886 mlx4_cleanup_mr_table(dev); in mlx4_setup_hca()
2889 mlx4_cleanup_xrcd_table(dev); in mlx4_setup_hca()
2892 mlx4_cleanup_pd_table(dev); in mlx4_setup_hca()
2898 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_setup_hca()
2901 mlx4_cleanup_uar_table(dev); in mlx4_setup_hca()
2905 static int mlx4_init_affinity_hint(struct mlx4_dev *dev, int port, int eqn) in mlx4_init_affinity_hint() argument
2908 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_affinity_hint()
2913 if (eqn > dev->caps.num_comp_vectors) in mlx4_init_affinity_hint()
2917 off += mlx4_get_eqs_per_port(dev, i); in mlx4_init_affinity_hint()
2935 static void mlx4_enable_msi_x(struct mlx4_dev *dev) in mlx4_enable_msi_x() argument
2937 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_enable_msi_x()
2943 int nreq = min3(dev->caps.num_ports * in mlx4_enable_msi_x()
2945 dev->caps.num_eqs - dev->caps.reserved_eqs, in mlx4_enable_msi_x()
2958 nreq = pci_enable_msix_range(dev->persist->pdev, entries, 2, in mlx4_enable_msi_x()
2966 dev->caps.num_comp_vectors = nreq - 1; in mlx4_enable_msi_x()
2970 dev->caps.num_ports); in mlx4_enable_msi_x()
2972 for (i = 0; i < dev->caps.num_comp_vectors + 1; i++) { in mlx4_enable_msi_x()
2979 if (MLX4_IS_LEGACY_EQ_MODE(dev->caps)) { in mlx4_enable_msi_x()
2981 dev->caps.num_ports); in mlx4_enable_msi_x()
2988 if (mlx4_init_affinity_hint(dev, port + 1, i)) in mlx4_enable_msi_x()
2989 mlx4_warn(dev, "Couldn't init hint cpumask for EQ %d\n", in mlx4_enable_msi_x()
2993 * (dev->caps.num_comp_vectors / dev->caps.num_ports) in mlx4_enable_msi_x()
3001 if ((dev->caps.num_comp_vectors > dev->caps.num_ports) && in mlx4_enable_msi_x()
3003 (dev->caps.num_comp_vectors / dev->caps.num_ports)) == in mlx4_enable_msi_x()
3005 /* If dev->caps.num_comp_vectors < dev->caps.num_ports, in mlx4_enable_msi_x()
3011 dev->flags |= MLX4_FLAG_MSI_X; in mlx4_enable_msi_x()
3018 dev->caps.num_comp_vectors = 1; in mlx4_enable_msi_x()
3022 priv->eq_table.eq[i].irq = dev->persist->pdev->irq; in mlx4_enable_msi_x()
3025 dev->caps.num_ports); in mlx4_enable_msi_x()
3030 static int mlx4_init_port_info(struct mlx4_dev *dev, int port) in mlx4_init_port_info() argument
3032 struct devlink *devlink = priv_to_devlink(mlx4_priv(dev)); in mlx4_init_port_info()
3033 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; in mlx4_init_port_info()
3045 dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) in mlx4_init_port_info()
3048 dev->caps.port_type[port] == MLX4_PORT_TYPE_IB) in mlx4_init_port_info()
3051 info->dev = dev; in mlx4_init_port_info()
3053 if (!mlx4_is_slave(dev)) { in mlx4_init_port_info()
3054 mlx4_init_mac_table(dev, &info->mac_table); in mlx4_init_port_info()
3055 mlx4_init_vlan_table(dev, &info->vlan_table); in mlx4_init_port_info()
3056 mlx4_init_roce_gid_table(dev, &info->gid_table); in mlx4_init_port_info()
3057 info->base_qpn = mlx4_get_base_qpn(dev, port); in mlx4_init_port_info()
3062 if (mlx4_is_mfunc(dev)) { in mlx4_init_port_info()
3071 err = device_create_file(&dev->persist->pdev->dev, &info->port_attr); in mlx4_init_port_info()
3073 mlx4_err(dev, "Failed to create file for port %d\n", port); in mlx4_init_port_info()
3081 if (mlx4_is_mfunc(dev)) { in mlx4_init_port_info()
3090 err = device_create_file(&dev->persist->pdev->dev, in mlx4_init_port_info()
3093 mlx4_err(dev, "Failed to create mtu file for port %d\n", port); in mlx4_init_port_info()
3094 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_init_port_info()
3109 device_remove_file(&info->dev->persist->pdev->dev, &info->port_attr); in mlx4_cleanup_port_info()
3110 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_cleanup_port_info()
3120 static int mlx4_init_steering(struct mlx4_dev *dev) in mlx4_init_steering() argument
3122 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_steering()
3123 int num_entries = dev->caps.num_ports; in mlx4_init_steering()
3139 static void mlx4_clear_steering(struct mlx4_dev *dev) in mlx4_clear_steering() argument
3141 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clear_steering()
3144 int num_entries = dev->caps.num_ports; in mlx4_clear_steering()
3180 static int mlx4_get_ownership(struct mlx4_dev *dev) in mlx4_get_ownership() argument
3185 if (pci_channel_offline(dev->persist->pdev)) in mlx4_get_ownership()
3188 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_get_ownership()
3192 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_get_ownership()
3201 static void mlx4_free_ownership(struct mlx4_dev *dev) in mlx4_free_ownership() argument
3205 if (pci_channel_offline(dev->persist->pdev)) in mlx4_free_ownership()
3208 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_free_ownership()
3212 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_free_ownership()
3223 static u64 mlx4_enable_sriov(struct mlx4_dev *dev, struct pci_dev *pdev, in mlx4_enable_sriov() argument
3226 u64 dev_flags = dev->flags; in mlx4_enable_sriov()
3232 dev->dev_vfs = kcalloc(total_vfs, sizeof(*dev->dev_vfs), in mlx4_enable_sriov()
3234 if (!dev->dev_vfs) in mlx4_enable_sriov()
3240 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_enable_sriov()
3242 … mlx4_err(dev, "SR-IOV was already enabled, but with num_vfs (%d) different than requested (%d)\n", in mlx4_enable_sriov()
3248 dev->dev_vfs = kcalloc(total_vfs, sizeof(*dev->dev_vfs), GFP_KERNEL); in mlx4_enable_sriov()
3249 if (NULL == dev->dev_vfs) { in mlx4_enable_sriov()
3250 mlx4_err(dev, "Failed to allocate memory for VFs\n"); in mlx4_enable_sriov()
3254 if (!(dev->flags & MLX4_FLAG_SRIOV)) { in mlx4_enable_sriov()
3256 mlx4_err(dev, "requested vfs (%d) > available vfs (%d). Continuing without SR_IOV\n", in mlx4_enable_sriov()
3261 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", total_vfs); in mlx4_enable_sriov()
3265 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d)\n", in mlx4_enable_sriov()
3269 mlx4_warn(dev, "Running in master mode\n"); in mlx4_enable_sriov()
3273 dev->persist->num_vfs = total_vfs; in mlx4_enable_sriov()
3280 dev->persist->num_vfs = 0; in mlx4_enable_sriov()
3281 kfree(dev->dev_vfs); in mlx4_enable_sriov()
3282 dev->dev_vfs = NULL; in mlx4_enable_sriov()
3290 static int mlx4_check_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_check_dev_cap() argument
3297 mlx4_err(dev, "Requested %d VFs, but FW does not support more than 64\n", in mlx4_check_dev_cap()
3304 static int mlx4_pci_enable_device(struct mlx4_dev *dev) in mlx4_pci_enable_device() argument
3306 struct pci_dev *pdev = dev->persist->pdev; in mlx4_pci_enable_device()
3309 mutex_lock(&dev->persist->pci_status_mutex); in mlx4_pci_enable_device()
3310 if (dev->persist->pci_status == MLX4_PCI_STATUS_DISABLED) { in mlx4_pci_enable_device()
3313 dev->persist->pci_status = MLX4_PCI_STATUS_ENABLED; in mlx4_pci_enable_device()
3315 mutex_unlock(&dev->persist->pci_status_mutex); in mlx4_pci_enable_device()
3320 static void mlx4_pci_disable_device(struct mlx4_dev *dev) in mlx4_pci_disable_device() argument
3322 struct pci_dev *pdev = dev->persist->pdev; in mlx4_pci_disable_device()
3324 mutex_lock(&dev->persist->pci_status_mutex); in mlx4_pci_disable_device()
3325 if (dev->persist->pci_status == MLX4_PCI_STATUS_ENABLED) { in mlx4_pci_disable_device()
3327 dev->persist->pci_status = MLX4_PCI_STATUS_DISABLED; in mlx4_pci_disable_device()
3329 mutex_unlock(&dev->persist->pci_status_mutex); in mlx4_pci_disable_device()
3336 struct mlx4_dev *dev; in mlx4_load_one() local
3344 dev = &priv->dev; in mlx4_load_one()
3359 dev->rev_id = pdev->revision; in mlx4_load_one()
3360 dev->numa_node = dev_to_node(&pdev->dev); in mlx4_load_one()
3364 mlx4_warn(dev, "Detected virtual function - running in slave mode\n"); in mlx4_load_one()
3365 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
3370 err = mlx4_get_ownership(dev); in mlx4_load_one()
3375 mlx4_warn(dev, "Multiple PFs not yet supported - Skipping PF\n"); in mlx4_load_one()
3388 err = mlx4_reset(dev); in mlx4_load_one()
3390 mlx4_err(dev, "Failed to reset HCA, aborting\n"); in mlx4_load_one()
3395 dev->flags = MLX4_FLAG_MASTER; in mlx4_load_one()
3398 dev->flags |= MLX4_FLAG_SRIOV; in mlx4_load_one()
3399 dev->persist->num_vfs = total_vfs; in mlx4_load_one()
3406 dev->persist->state = MLX4_DEVICE_STATE_UP; in mlx4_load_one()
3409 err = mlx4_cmd_init(dev); in mlx4_load_one()
3411 mlx4_err(dev, "Failed to init command interface, aborting\n"); in mlx4_load_one()
3418 if (mlx4_is_mfunc(dev)) { in mlx4_load_one()
3419 if (mlx4_is_master(dev)) { in mlx4_load_one()
3420 dev->num_slaves = MLX4_MAX_NUM_SLAVES; in mlx4_load_one()
3423 dev->num_slaves = 0; in mlx4_load_one()
3424 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3426 mlx4_err(dev, "Failed to init slave mfunc interface, aborting\n"); in mlx4_load_one()
3432 err = mlx4_init_fw(dev); in mlx4_load_one()
3434 mlx4_err(dev, "Failed to init fw, aborting.\n"); in mlx4_load_one()
3438 if (mlx4_is_master(dev)) { in mlx4_load_one()
3448 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
3450 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
3454 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
3458 u64 dev_flags = mlx4_enable_sriov(dev, pdev, in mlx4_load_one()
3463 mlx4_close_fw(dev); in mlx4_load_one()
3464 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3465 dev->flags = dev_flags; in mlx4_load_one()
3466 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
3467 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
3470 err = mlx4_reset(dev); in mlx4_load_one()
3472 mlx4_err(dev, "Failed to reset HCA, aborting.\n"); in mlx4_load_one()
3483 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
3485 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
3489 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
3494 err = mlx4_init_hca(dev); in mlx4_load_one()
3499 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3501 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_load_one()
3504 if (mlx4_is_master(dev) && !reset_flow) in mlx4_load_one()
3506 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3508 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3509 mlx4_free_ownership(dev); in mlx4_load_one()
3510 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
3511 dev->flags &= ~MLX4_FLAG_MASTER; in mlx4_load_one()
3517 if (mlx4_is_master(dev) && (dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) { in mlx4_load_one()
3518 u64 dev_flags = mlx4_enable_sriov(dev, pdev, total_vfs, in mlx4_load_one()
3521 if ((dev->flags ^ dev_flags) & (MLX4_FLAG_MASTER | MLX4_FLAG_SLAVE)) { in mlx4_load_one()
3522 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_VHCR); in mlx4_load_one()
3523 dev->flags = dev_flags; in mlx4_load_one()
3524 err = mlx4_cmd_init(dev); in mlx4_load_one()
3529 mlx4_err(dev, "Failed to init VHCR command interface, aborting\n"); in mlx4_load_one()
3533 dev->flags = dev_flags; in mlx4_load_one()
3536 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
3537 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
3547 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3548 pcie_print_link_status(dev->persist->pdev); in mlx4_load_one()
3552 if (mlx4_is_master(dev)) { in mlx4_load_one()
3553 if (dev->caps.num_ports < 2 && in mlx4_load_one()
3556 mlx4_err(dev, in mlx4_load_one()
3558 dev->caps.num_ports); in mlx4_load_one()
3561 memcpy(dev->persist->nvfs, nvfs, sizeof(dev->persist->nvfs)); in mlx4_load_one()
3564 i < sizeof(dev->persist->nvfs)/ in mlx4_load_one()
3565 sizeof(dev->persist->nvfs[0]); i++) { in mlx4_load_one()
3568 for (j = 0; j < dev->persist->nvfs[i]; ++sum, ++j) { in mlx4_load_one()
3569 dev->dev_vfs[sum].min_port = i < 2 ? i + 1 : 1; in mlx4_load_one()
3570 dev->dev_vfs[sum].n_ports = i < 2 ? 1 : in mlx4_load_one()
3571 dev->caps.num_ports; in mlx4_load_one()
3578 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3580 mlx4_err(dev, "Failed to init master mfunc interface, aborting.\n"); in mlx4_load_one()
3585 err = mlx4_alloc_eq_table(dev); in mlx4_load_one()
3592 mlx4_enable_msi_x(dev); in mlx4_load_one()
3593 if ((mlx4_is_mfunc(dev)) && in mlx4_load_one()
3594 !(dev->flags & MLX4_FLAG_MSI_X)) { in mlx4_load_one()
3596 mlx4_err(dev, "INTx is not supported in multi-function mode, aborting\n"); in mlx4_load_one()
3600 if (!mlx4_is_slave(dev)) { in mlx4_load_one()
3601 err = mlx4_init_steering(dev); in mlx4_load_one()
3606 mlx4_init_quotas(dev); in mlx4_load_one()
3608 err = mlx4_setup_hca(dev); in mlx4_load_one()
3609 if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) && in mlx4_load_one()
3610 !mlx4_is_mfunc(dev)) { in mlx4_load_one()
3611 dev->flags &= ~MLX4_FLAG_MSI_X; in mlx4_load_one()
3612 dev->caps.num_comp_vectors = 1; in mlx4_load_one()
3614 err = mlx4_setup_hca(dev); in mlx4_load_one()
3623 if (mlx4_is_master(dev)) { in mlx4_load_one()
3624 err = mlx4_ARM_COMM_CHANNEL(dev); in mlx4_load_one()
3626 mlx4_err(dev, " Failed to arm comm channel eq: %x\n", in mlx4_load_one()
3632 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_load_one()
3633 err = mlx4_init_port_info(dev, port); in mlx4_load_one()
3641 err = mlx4_register_device(dev); in mlx4_load_one()
3645 mlx4_request_modules(dev); in mlx4_load_one()
3647 mlx4_sense_init(dev); in mlx4_load_one()
3648 mlx4_start_sense(dev); in mlx4_load_one()
3652 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3662 mlx4_cleanup_default_counters(dev); in mlx4_load_one()
3663 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3664 mlx4_cleanup_counters_table(dev); in mlx4_load_one()
3665 mlx4_cleanup_qp_table(dev); in mlx4_load_one()
3666 mlx4_cleanup_srq_table(dev); in mlx4_load_one()
3667 mlx4_cleanup_cq_table(dev); in mlx4_load_one()
3668 mlx4_cmd_use_polling(dev); in mlx4_load_one()
3669 mlx4_cleanup_eq_table(dev); in mlx4_load_one()
3670 mlx4_cleanup_mcg_table(dev); in mlx4_load_one()
3671 mlx4_cleanup_mr_table(dev); in mlx4_load_one()
3672 mlx4_cleanup_xrcd_table(dev); in mlx4_load_one()
3673 mlx4_cleanup_pd_table(dev); in mlx4_load_one()
3674 mlx4_cleanup_uar_table(dev); in mlx4_load_one()
3677 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3678 mlx4_clear_steering(dev); in mlx4_load_one()
3681 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_load_one()
3685 mlx4_free_eq_table(dev); in mlx4_load_one()
3688 if (mlx4_is_master(dev)) { in mlx4_load_one()
3689 mlx4_free_resource_tracker(dev, RES_TR_FREE_STRUCTS_ONLY); in mlx4_load_one()
3690 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3693 if (mlx4_is_slave(dev)) in mlx4_load_one()
3694 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_load_one()
3697 mlx4_close_hca(dev); in mlx4_load_one()
3700 mlx4_close_fw(dev); in mlx4_load_one()
3703 if (mlx4_is_slave(dev)) in mlx4_load_one()
3704 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3707 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3710 if (dev->flags & MLX4_FLAG_SRIOV && !existing_vfs) { in mlx4_load_one()
3712 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3715 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3718 kfree(priv->dev.dev_vfs); in mlx4_load_one()
3720 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3721 mlx4_free_ownership(dev); in mlx4_load_one()
3740 err = mlx4_pci_enable_device(&priv->dev); in __mlx4_init_one()
3742 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); in __mlx4_init_one()
3754 dev_err(&pdev->dev, "num_vfs module parameter cannot be negative\n"); in __mlx4_init_one()
3763 dev_err(&pdev->dev, "probe_vf module parameter cannot be negative or greater than num_vfs\n"); in __mlx4_init_one()
3769 dev_err(&pdev->dev, in __mlx4_init_one()
3778 dev_err(&pdev->dev, in __mlx4_init_one()
3790 …dev_err(&pdev->dev, "Missing DCS, aborting (driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\… in __mlx4_init_one()
3796 dev_err(&pdev->dev, "Missing UAR, aborting\n"); in __mlx4_init_one()
3803 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n"); in __mlx4_init_one()
3811 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); in __mlx4_init_one()
3814 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); in __mlx4_init_one()
3820 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit consistent PCI DMA mask\n"); in __mlx4_init_one()
3823 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, aborting\n"); in __mlx4_init_one()
3829 dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024); in __mlx4_init_one()
3848 dev_warn(&pdev->dev, "Skipping virtual function:%d\n", in __mlx4_init_one()
3856 err = mlx4_crdump_init(&priv->dev); in __mlx4_init_one()
3860 err = mlx4_catas_init(&priv->dev); in __mlx4_init_one()
3871 mlx4_catas_end(&priv->dev); in __mlx4_init_one()
3874 mlx4_crdump_end(&priv->dev); in __mlx4_init_one()
3880 mlx4_pci_disable_device(&priv->dev); in __mlx4_init_one()
3912 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_param_load_driverinit_values() local
3913 struct mlx4_fw_crdump *crdump = &dev->persist->crdump; in mlx4_devlink_param_load_driverinit_values()
3961 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_reload_down() local
3962 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_devlink_reload_down()
3969 …mlx4_warn(persist->dev, "Reload performed on PF, will cause reset on operating Virtual Functions\n… in mlx4_devlink_reload_down()
3979 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_reload_up() local
3980 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_devlink_reload_up()
3986 mlx4_err(persist->dev, "mlx4_restart_one_up failed, ret=%d\n", in mlx4_devlink_reload_up()
4003 struct mlx4_dev *dev; in mlx4_init_one() local
4013 dev = &priv->dev; in mlx4_init_one()
4014 dev->persist = kzalloc(sizeof(*dev->persist), GFP_KERNEL); in mlx4_init_one()
4015 if (!dev->persist) { in mlx4_init_one()
4019 dev->persist->pdev = pdev; in mlx4_init_one()
4020 dev->persist->dev = dev; in mlx4_init_one()
4021 pci_set_drvdata(pdev, dev->persist); in mlx4_init_one()
4023 mutex_init(&dev->persist->device_state_mutex); in mlx4_init_one()
4024 mutex_init(&dev->persist->interface_state_mutex); in mlx4_init_one()
4025 mutex_init(&dev->persist->pci_status_mutex); in mlx4_init_one()
4027 ret = devlink_register(devlink, &pdev->dev); in mlx4_init_one()
4050 kfree(dev->persist); in mlx4_init_one()
4056 static void mlx4_clean_dev(struct mlx4_dev *dev) in mlx4_clean_dev() argument
4058 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_clean_dev()
4059 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clean_dev()
4060 unsigned long flags = (dev->flags & RESET_PERSIST_MASK_FLAGS); in mlx4_clean_dev()
4063 priv->dev.persist = persist; in mlx4_clean_dev()
4064 priv->dev.flags = flags; in mlx4_clean_dev()
4070 struct mlx4_dev *dev = persist->dev; in mlx4_unload_one() local
4071 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unload_one()
4079 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_unload_one()
4080 dev->persist->curr_port_type[i] = dev->caps.port_type[i + 1]; in mlx4_unload_one()
4081 dev->persist->curr_port_poss_type[i] = dev->caps. in mlx4_unload_one()
4087 mlx4_stop_sense(dev); in mlx4_unload_one()
4088 mlx4_unregister_device(dev); in mlx4_unload_one()
4090 for (p = 1; p <= dev->caps.num_ports; p++) { in mlx4_unload_one()
4092 mlx4_CLOSE_PORT(dev, p); in mlx4_unload_one()
4095 if (mlx4_is_master(dev)) in mlx4_unload_one()
4096 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
4099 mlx4_cleanup_default_counters(dev); in mlx4_unload_one()
4100 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
4101 mlx4_cleanup_counters_table(dev); in mlx4_unload_one()
4102 mlx4_cleanup_qp_table(dev); in mlx4_unload_one()
4103 mlx4_cleanup_srq_table(dev); in mlx4_unload_one()
4104 mlx4_cleanup_cq_table(dev); in mlx4_unload_one()
4105 mlx4_cmd_use_polling(dev); in mlx4_unload_one()
4106 mlx4_cleanup_eq_table(dev); in mlx4_unload_one()
4107 mlx4_cleanup_mcg_table(dev); in mlx4_unload_one()
4108 mlx4_cleanup_mr_table(dev); in mlx4_unload_one()
4109 mlx4_cleanup_xrcd_table(dev); in mlx4_unload_one()
4110 mlx4_cleanup_pd_table(dev); in mlx4_unload_one()
4112 if (mlx4_is_master(dev)) in mlx4_unload_one()
4113 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
4117 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_unload_one()
4118 mlx4_cleanup_uar_table(dev); in mlx4_unload_one()
4119 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
4120 mlx4_clear_steering(dev); in mlx4_unload_one()
4121 mlx4_free_eq_table(dev); in mlx4_unload_one()
4122 if (mlx4_is_master(dev)) in mlx4_unload_one()
4123 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
4124 mlx4_close_hca(dev); in mlx4_unload_one()
4125 mlx4_close_fw(dev); in mlx4_unload_one()
4126 if (mlx4_is_slave(dev)) in mlx4_unload_one()
4127 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
4128 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_unload_one()
4130 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_unload_one()
4133 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
4134 mlx4_free_ownership(dev); in mlx4_unload_one()
4136 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_unload_one()
4137 kfree(dev->dev_vfs); in mlx4_unload_one()
4139 mlx4_clean_dev(dev); in mlx4_unload_one()
4147 struct mlx4_dev *dev = persist->dev; in mlx4_remove_one() local
4148 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_remove_one()
4154 if (mlx4_is_slave(dev)) in mlx4_remove_one()
4162 if (mlx4_is_master(dev) && dev->flags & MLX4_FLAG_SRIOV) { in mlx4_remove_one()
4163 active_vfs = mlx4_how_many_lives_vf(dev); in mlx4_remove_one()
4176 mlx4_info(dev, "%s: interface is down\n", __func__); in mlx4_remove_one()
4177 mlx4_catas_end(dev); in mlx4_remove_one()
4178 mlx4_crdump_end(dev); in mlx4_remove_one()
4179 if (dev->flags & MLX4_FLAG_SRIOV && !active_vfs) { in mlx4_remove_one()
4180 mlx4_warn(dev, "Disabling SR-IOV\n"); in mlx4_remove_one()
4185 mlx4_pci_disable_device(dev); in mlx4_remove_one()
4189 kfree(dev->persist); in mlx4_remove_one()
4193 static int restore_current_port_types(struct mlx4_dev *dev, in restore_current_port_types() argument
4197 struct mlx4_priv *priv = mlx4_priv(dev); in restore_current_port_types()
4200 mlx4_stop_sense(dev); in restore_current_port_types()
4203 for (i = 0; i < dev->caps.num_ports; i++) in restore_current_port_types()
4204 dev->caps.possible_type[i + 1] = poss_types[i]; in restore_current_port_types()
4205 err = mlx4_change_port_types(dev, types); in restore_current_port_types()
4206 mlx4_start_sense(dev); in restore_current_port_types()
4221 struct mlx4_dev *dev = persist->dev; in mlx4_restart_one_up() local
4222 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_restart_one_up()
4227 total_vfs = dev->persist->num_vfs; in mlx4_restart_one_up()
4228 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_restart_one_up()
4234 mlx4_err(dev, "%s: ERROR: mlx4_load_one failed, pci_name=%s, err=%d\n", in mlx4_restart_one_up()
4239 err = restore_current_port_types(dev, dev->persist->curr_port_type, in mlx4_restart_one_up()
4240 dev->persist->curr_port_poss_type); in mlx4_restart_one_up()
4242 mlx4_err(dev, "could not restore original port types (%d)\n", in mlx4_restart_one_up()
4311 mlx4_err(persist->dev, "mlx4_pci_err_detected was called\n"); in mlx4_pci_err_detected()
4322 mlx4_pci_disable_device(persist->dev); in mlx4_pci_err_detected()
4329 struct mlx4_dev *dev = persist->dev; in mlx4_pci_slot_reset() local
4332 mlx4_err(dev, "mlx4_pci_slot_reset was called\n"); in mlx4_pci_slot_reset()
4333 err = mlx4_pci_enable_device(dev); in mlx4_pci_slot_reset()
4335 mlx4_err(dev, "Can not re-enable device, err=%d\n", err); in mlx4_pci_slot_reset()
4348 struct mlx4_dev *dev = persist->dev; in mlx4_pci_resume() local
4349 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_pci_resume()
4354 mlx4_err(dev, "%s was called\n", __func__); in mlx4_pci_resume()
4355 total_vfs = dev->persist->num_vfs; in mlx4_pci_resume()
4356 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_pci_resume()
4363 mlx4_err(dev, "%s: mlx4_load_one failed, err=%d\n", in mlx4_pci_resume()
4368 err = restore_current_port_types(dev, dev->persist-> in mlx4_pci_resume()
4369 curr_port_type, dev->persist-> in mlx4_pci_resume()
4372 mlx4_err(dev, "could not restore original port types (%d)\n", err); in mlx4_pci_resume()
4382 struct mlx4_dev *dev = persist->dev; in mlx4_shutdown() local
4384 mlx4_info(persist->dev, "mlx4_shutdown was called\n"); in mlx4_shutdown()
4389 mlx4_pci_disable_device(dev); in mlx4_shutdown()
4402 struct mlx4_dev *dev = persist->dev; in mlx4_suspend() local
4404 mlx4_err(dev, "suspend was called\n"); in mlx4_suspend()
4417 struct mlx4_dev *dev = persist->dev; in mlx4_resume() local
4418 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_resume()
4423 mlx4_err(dev, "resume was called\n"); in mlx4_resume()
4424 total_vfs = dev->persist->num_vfs; in mlx4_resume()
4425 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_resume()
4432 ret = restore_current_port_types(dev, in mlx4_resume()
4433 dev->persist->curr_port_type, in mlx4_resume()
4434 dev->persist->curr_port_poss_type); in mlx4_resume()
4436 mlx4_err(dev, "resume: could not restore original port types (%d)\n", ret); in mlx4_resume()