Lines Matching refs:dev

198 	struct mlx4_dev *dev = &priv->dev;  in mlx4_devlink_crdump_snapshot_get()  local
200 ctx->val.vbool = dev->persist->crdump.snapshot_enable; in mlx4_devlink_crdump_snapshot_get()
208 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_crdump_snapshot_set() local
210 dev->persist->crdump.snapshot_enable = ctx->val.vbool; in mlx4_devlink_crdump_snapshot_set()
292 static inline void mlx4_set_num_reserved_uars(struct mlx4_dev *dev, in mlx4_set_num_reserved_uars() argument
299 dev->caps.reserved_uars = in mlx4_set_num_reserved_uars()
301 mlx4_get_num_reserved_uar(dev), in mlx4_set_num_reserved_uars()
303 (1 << (PAGE_SHIFT - dev->uar_page_shift))); in mlx4_set_num_reserved_uars()
306 int mlx4_check_port_params(struct mlx4_dev *dev, in mlx4_check_port_params() argument
311 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) { in mlx4_check_port_params()
312 for (i = 0; i < dev->caps.num_ports - 1; i++) { in mlx4_check_port_params()
314 mlx4_err(dev, "Only same port types supported on this HCA, aborting\n"); in mlx4_check_port_params()
320 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_check_port_params()
321 if (!(port_type[i] & dev->caps.supported_type[i+1])) { in mlx4_check_port_params()
322 mlx4_err(dev, "Requested port type for port %d is not supported on this HCA\n", in mlx4_check_port_params()
330 static void mlx4_set_port_mask(struct mlx4_dev *dev) in mlx4_set_port_mask() argument
334 for (i = 1; i <= dev->caps.num_ports; ++i) in mlx4_set_port_mask()
335 dev->caps.port_mask[i] = dev->caps.port_type[i]; in mlx4_set_port_mask()
342 static int mlx4_query_func(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_query_func() argument
347 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS) { in mlx4_query_func()
348 err = mlx4_QUERY_FUNC(dev, &func, 0); in mlx4_query_func()
350 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_query_func()
361 static void mlx4_enable_cqe_eqe_stride(struct mlx4_dev *dev) in mlx4_enable_cqe_eqe_stride() argument
363 struct mlx4_caps *dev_cap = &dev->caps; in mlx4_enable_cqe_eqe_stride()
381 mlx4_dbg(dev, "Enabling CQE stride cacheLine supported\n"); in mlx4_enable_cqe_eqe_stride()
386 if (mlx4_is_master(dev)) in mlx4_enable_cqe_eqe_stride()
390 mlx4_dbg(dev, "Disabling CQE stride, cacheLine size unsupported\n"); in mlx4_enable_cqe_eqe_stride()
396 static int _mlx4_dev_port(struct mlx4_dev *dev, int port, in _mlx4_dev_port() argument
399 dev->caps.vl_cap[port] = port_cap->max_vl; in _mlx4_dev_port()
400 dev->caps.ib_mtu_cap[port] = port_cap->ib_mtu; in _mlx4_dev_port()
401 dev->phys_caps.gid_phys_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
402 dev->phys_caps.pkey_phys_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
406 dev->caps.gid_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
407 dev->caps.pkey_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
408 dev->caps.port_width_cap[port] = port_cap->max_port_width; in _mlx4_dev_port()
409 dev->caps.eth_mtu_cap[port] = port_cap->eth_mtu; in _mlx4_dev_port()
410 dev->caps.max_tc_eth = port_cap->max_tc_eth; in _mlx4_dev_port()
411 dev->caps.def_mac[port] = port_cap->def_mac; in _mlx4_dev_port()
412 dev->caps.supported_type[port] = port_cap->supported_port_types; in _mlx4_dev_port()
413 dev->caps.suggested_type[port] = port_cap->suggested_type; in _mlx4_dev_port()
414 dev->caps.default_sense[port] = port_cap->default_sense; in _mlx4_dev_port()
415 dev->caps.trans_type[port] = port_cap->trans_type; in _mlx4_dev_port()
416 dev->caps.vendor_oui[port] = port_cap->vendor_oui; in _mlx4_dev_port()
417 dev->caps.wavelength[port] = port_cap->wavelength; in _mlx4_dev_port()
418 dev->caps.trans_code[port] = port_cap->trans_code; in _mlx4_dev_port()
423 static int mlx4_dev_port(struct mlx4_dev *dev, int port, in mlx4_dev_port() argument
428 err = mlx4_QUERY_PORT(dev, port, port_cap); in mlx4_dev_port()
431 mlx4_err(dev, "QUERY_PORT command failed.\n"); in mlx4_dev_port()
436 static inline void mlx4_enable_ignore_fcs(struct mlx4_dev *dev) in mlx4_enable_ignore_fcs() argument
438 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_IGNORE_FCS)) in mlx4_enable_ignore_fcs()
441 if (mlx4_is_mfunc(dev)) { in mlx4_enable_ignore_fcs()
442 mlx4_dbg(dev, "SRIOV mode - Disabling Ignore FCS"); in mlx4_enable_ignore_fcs()
443 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
447 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP)) { in mlx4_enable_ignore_fcs()
448 mlx4_dbg(dev, in mlx4_enable_ignore_fcs()
450 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
456 static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_dev_cap() argument
461 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_dev_cap()
463 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_dev_cap()
466 mlx4_dev_cap_dump(dev, dev_cap); in mlx4_dev_cap()
469 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_dev_cap()
474 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_dev_cap()
479 if (dev_cap->uar_size > pci_resource_len(dev->persist->pdev, 2)) { in mlx4_dev_cap()
480 …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()
483 pci_resource_len(dev->persist->pdev, 2)); in mlx4_dev_cap()
487 dev->caps.num_ports = dev_cap->num_ports; in mlx4_dev_cap()
488 dev->caps.num_sys_eqs = dev_cap->num_sys_eqs; in mlx4_dev_cap()
489 dev->phys_caps.num_phys_eqs = dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS ? in mlx4_dev_cap()
490 dev->caps.num_sys_eqs : in mlx4_dev_cap()
492 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
493 err = _mlx4_dev_port(dev, i, dev_cap->port_cap + i); in mlx4_dev_cap()
495 mlx4_err(dev, "QUERY_PORT command failed, aborting\n"); in mlx4_dev_cap()
500 dev->caps.map_clock_to_user = dev_cap->map_clock_to_user; in mlx4_dev_cap()
501 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_dev_cap()
502 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE; in mlx4_dev_cap()
503 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay; in mlx4_dev_cap()
504 dev->caps.bf_reg_size = dev_cap->bf_reg_size; in mlx4_dev_cap()
505 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page; in mlx4_dev_cap()
506 dev->caps.max_sq_sg = dev_cap->max_sq_sg; in mlx4_dev_cap()
507 dev->caps.max_rq_sg = dev_cap->max_rq_sg; in mlx4_dev_cap()
508 dev->caps.max_wqes = dev_cap->max_qp_sz; in mlx4_dev_cap()
509 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp; in mlx4_dev_cap()
510 dev->caps.max_srq_wqes = dev_cap->max_srq_sz; in mlx4_dev_cap()
511 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1; in mlx4_dev_cap()
512 dev->caps.reserved_srqs = dev_cap->reserved_srqs; in mlx4_dev_cap()
513 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz; in mlx4_dev_cap()
514 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz; in mlx4_dev_cap()
519 dev->caps.max_cqes = dev_cap->max_cq_sz - 1; in mlx4_dev_cap()
520 dev->caps.reserved_cqs = dev_cap->reserved_cqs; in mlx4_dev_cap()
521 dev->caps.reserved_eqs = dev_cap->reserved_eqs; in mlx4_dev_cap()
522 dev->caps.reserved_mtts = dev_cap->reserved_mtts; in mlx4_dev_cap()
523 dev->caps.reserved_mrws = dev_cap->reserved_mrws; in mlx4_dev_cap()
525 dev->caps.reserved_pds = dev_cap->reserved_pds; in mlx4_dev_cap()
526 dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
528 dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
530 dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz; in mlx4_dev_cap()
532 dev->caps.max_msg_sz = dev_cap->max_msg_sz; in mlx4_dev_cap()
533 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1); in mlx4_dev_cap()
534 dev->caps.flags = dev_cap->flags; in mlx4_dev_cap()
535 dev->caps.flags2 = dev_cap->flags2; in mlx4_dev_cap()
536 dev->caps.bmme_flags = dev_cap->bmme_flags; in mlx4_dev_cap()
537 dev->caps.reserved_lkey = dev_cap->reserved_lkey; in mlx4_dev_cap()
538 dev->caps.stat_rate_support = dev_cap->stat_rate_support; in mlx4_dev_cap()
539 dev->caps.max_gso_sz = dev_cap->max_gso_sz; in mlx4_dev_cap()
540 dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz; in mlx4_dev_cap()
541 dev->caps.wol_port[1] = dev_cap->wol_port[1]; in mlx4_dev_cap()
542 dev->caps.wol_port[2] = dev_cap->wol_port[2]; in mlx4_dev_cap()
543 dev->caps.health_buffer_addrs = dev_cap->health_buffer_addrs; in mlx4_dev_cap()
546 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
550 if (enable_4k_uar || !dev->persist->num_vfs) in mlx4_dev_cap()
551 dev->uar_page_shift = DEFAULT_UAR_PAGE_SHIFT; in mlx4_dev_cap()
553 dev->uar_page_shift = PAGE_SHIFT; in mlx4_dev_cap()
555 mlx4_set_num_reserved_uars(dev, dev_cap); in mlx4_dev_cap()
558 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PHV_EN) { in mlx4_dev_cap()
562 err = mlx4_QUERY_HCA(dev, &hca_param); in mlx4_dev_cap()
570 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_PHV_EN; in mlx4_dev_cap()
574 if (mlx4_priv(dev)->pci_dev_data & MLX4_PCI_DEV_FORCE_SENSE_PORT) in mlx4_dev_cap()
575 dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
577 if (mlx4_is_mfunc(dev)) in mlx4_dev_cap()
578 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
581 dev->caps.log_num_macs = MLX4_MIN_LOG_NUM_MAC; in mlx4_dev_cap()
582 dev->caps.log_num_vlans = MLX4_MIN_LOG_NUM_VLANS; in mlx4_dev_cap()
584 dev->caps.log_num_macs = log_num_mac; in mlx4_dev_cap()
585 dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS; in mlx4_dev_cap()
588 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
589 dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE; in mlx4_dev_cap()
590 if (dev->caps.supported_type[i]) { in mlx4_dev_cap()
592 if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_dev_cap()
593 dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH; in mlx4_dev_cap()
595 else if (dev->caps.supported_type[i] == in mlx4_dev_cap()
597 dev->caps.port_type[i] = MLX4_PORT_TYPE_IB; in mlx4_dev_cap()
603 dev->caps.port_type[i] = dev->caps.suggested_type[i] ? in mlx4_dev_cap()
606 dev->caps.port_type[i] = port_type_array[i - 1]; in mlx4_dev_cap()
615 mlx4_priv(dev)->sense.sense_allowed[i] = in mlx4_dev_cap()
616 ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) && in mlx4_dev_cap()
617 (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) && in mlx4_dev_cap()
618 (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)); in mlx4_dev_cap()
625 if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) { in mlx4_dev_cap()
627 dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO; in mlx4_dev_cap()
628 mlx4_SENSE_PORT(dev, i, &sensed_port); in mlx4_dev_cap()
630 dev->caps.port_type[i] = sensed_port; in mlx4_dev_cap()
632 dev->caps.possible_type[i] = dev->caps.port_type[i]; in mlx4_dev_cap()
635 if (dev->caps.log_num_macs > dev_cap->port_cap[i].log_max_macs) { in mlx4_dev_cap()
636 dev->caps.log_num_macs = dev_cap->port_cap[i].log_max_macs; in mlx4_dev_cap()
637 mlx4_warn(dev, "Requested number of MACs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
638 i, 1 << dev->caps.log_num_macs); in mlx4_dev_cap()
640 if (dev->caps.log_num_vlans > dev_cap->port_cap[i].log_max_vlans) { in mlx4_dev_cap()
641 dev->caps.log_num_vlans = dev_cap->port_cap[i].log_max_vlans; in mlx4_dev_cap()
642 mlx4_warn(dev, "Requested number of VLANs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
643 i, 1 << dev->caps.log_num_vlans); in mlx4_dev_cap()
647 if (mlx4_is_master(dev) && (dev->caps.num_ports == 2) && in mlx4_dev_cap()
650 mlx4_warn(dev, in mlx4_dev_cap()
652 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_QOS_VPP; in mlx4_dev_cap()
655 dev->caps.max_counters = dev_cap->max_counters; in mlx4_dev_cap()
657 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps; in mlx4_dev_cap()
658 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] = in mlx4_dev_cap()
659 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] = in mlx4_dev_cap()
660 (1 << dev->caps.log_num_macs) * in mlx4_dev_cap()
661 (1 << dev->caps.log_num_vlans) * in mlx4_dev_cap()
662 dev->caps.num_ports; in mlx4_dev_cap()
663 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH; in mlx4_dev_cap()
666 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) in mlx4_dev_cap()
667 dev->caps.dmfs_high_rate_qpn_base = dev_cap->dmfs_high_rate_qpn_base; in mlx4_dev_cap()
669 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
670 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
673 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) { in mlx4_dev_cap()
674 dev->caps.dmfs_high_rate_qpn_range = dev_cap->dmfs_high_rate_qpn_range; in mlx4_dev_cap()
675 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DEFAULT; in mlx4_dev_cap()
676 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_FS_A0; in mlx4_dev_cap()
678 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_NOT_SUPPORTED; in mlx4_dev_cap()
679 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
680 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
681 dev->caps.dmfs_high_rate_qpn_range = MLX4_A0_STEERING_TABLE_SIZE; in mlx4_dev_cap()
684 dev->caps.rl_caps = dev_cap->rl_caps; in mlx4_dev_cap()
686 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_RSS_RAW_ETH] = in mlx4_dev_cap()
687 dev->caps.dmfs_high_rate_qpn_range; in mlx4_dev_cap()
689 dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] + in mlx4_dev_cap()
690 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] + in mlx4_dev_cap()
691 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] + in mlx4_dev_cap()
692 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH]; in mlx4_dev_cap()
694 dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0; in mlx4_dev_cap()
696 if (!enable_64b_cqe_eqe && !mlx4_is_slave(dev)) { in mlx4_dev_cap()
699 mlx4_warn(dev, "64B EQEs/CQEs supported by the device but not enabled\n"); in mlx4_dev_cap()
700 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_CQE; in mlx4_dev_cap()
701 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_EQE; in mlx4_dev_cap()
707 mlx4_warn(dev, "Disabling EQE/CQE stride per user request\n"); in mlx4_dev_cap()
713 if ((dev->caps.flags & in mlx4_dev_cap()
715 mlx4_is_master(dev)) in mlx4_dev_cap()
716 dev->caps.function_caps |= MLX4_FUNC_CAP_64B_EQE_CQE; in mlx4_dev_cap()
718 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
719 mlx4_enable_cqe_eqe_stride(dev); in mlx4_dev_cap()
720 dev->caps.alloc_res_qp_mask = in mlx4_dev_cap()
721 (dev->caps.bf_reg_size ? MLX4_RESERVE_ETH_BF_QP : 0) | in mlx4_dev_cap()
724 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) && in mlx4_dev_cap()
725 dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) { in mlx4_dev_cap()
726 mlx4_warn(dev, "Old device ETS support detected\n"); in mlx4_dev_cap()
727 mlx4_warn(dev, "Consider upgrading device FW.\n"); in mlx4_dev_cap()
728 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_ETS_CFG; in mlx4_dev_cap()
732 dev->caps.alloc_res_qp_mask = 0; in mlx4_dev_cap()
735 mlx4_enable_ignore_fcs(dev); in mlx4_dev_cap()
741 static int mlx4_how_many_lives_vf(struct mlx4_dev *dev) in mlx4_how_many_lives_vf() argument
743 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_how_many_lives_vf()
748 for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) { in mlx4_how_many_lives_vf()
752 mlx4_warn(dev, "%s: slave: %d is still active\n", in mlx4_how_many_lives_vf()
760 int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey) in mlx4_get_parav_qkey() argument
764 if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX || in mlx4_get_parav_qkey()
765 qpn < dev->phys_caps.base_proxy_sqpn) in mlx4_get_parav_qkey()
768 if (qpn >= dev->phys_caps.base_tunnel_sqpn) in mlx4_get_parav_qkey()
770 qk += qpn - dev->phys_caps.base_tunnel_sqpn; in mlx4_get_parav_qkey()
772 qk += qpn - dev->phys_caps.base_proxy_sqpn; in mlx4_get_parav_qkey()
778 void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port, int i, int val) in mlx4_sync_pkey_table() argument
780 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_sync_pkey_table()
782 if (!mlx4_is_master(dev)) in mlx4_sync_pkey_table()
789 void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid) in mlx4_put_slave_node_guid() argument
791 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_put_slave_node_guid()
793 if (!mlx4_is_master(dev)) in mlx4_put_slave_node_guid()
800 __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave) in mlx4_get_slave_node_guid() argument
802 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_get_slave_node_guid()
804 if (!mlx4_is_master(dev)) in mlx4_get_slave_node_guid()
811 int mlx4_is_slave_active(struct mlx4_dev *dev, int slave) in mlx4_is_slave_active() argument
813 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_is_slave_active()
816 if (!mlx4_is_master(dev)) in mlx4_is_slave_active()
841 static void slave_adjust_steering_mode(struct mlx4_dev *dev, in slave_adjust_steering_mode() argument
845 dev->caps.steering_mode = hca_param->steering_mode; in slave_adjust_steering_mode()
846 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) { in slave_adjust_steering_mode()
847 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in slave_adjust_steering_mode()
848 dev->caps.fs_log_max_ucast_qp_range_size = in slave_adjust_steering_mode()
851 dev->caps.num_qp_per_mgm = in slave_adjust_steering_mode()
854 mlx4_dbg(dev, "Steering mode is: %s\n", in slave_adjust_steering_mode()
855 mlx4_steering_mode_str(dev->caps.steering_mode)); in slave_adjust_steering_mode()
858 static void mlx4_slave_destroy_special_qp_cap(struct mlx4_dev *dev) in mlx4_slave_destroy_special_qp_cap() argument
860 kfree(dev->caps.spec_qps); in mlx4_slave_destroy_special_qp_cap()
861 dev->caps.spec_qps = NULL; in mlx4_slave_destroy_special_qp_cap()
864 static int mlx4_slave_special_qp_cap(struct mlx4_dev *dev) in mlx4_slave_special_qp_cap() argument
867 struct mlx4_caps *caps = &dev->caps; in mlx4_slave_special_qp_cap()
874 mlx4_err(dev, "Failed to allocate memory for special qps cap\n"); in mlx4_slave_special_qp_cap()
880 err = mlx4_QUERY_FUNC_CAP(dev, i, func_cap); in mlx4_slave_special_qp_cap()
882 mlx4_err(dev, "QUERY_FUNC_CAP port command failed for port %d, aborting (%d)\n", in mlx4_slave_special_qp_cap()
889 err = mlx4_get_slave_pkey_gid_tbl_len(dev, i, in mlx4_slave_special_qp_cap()
893 mlx4_err(dev, "QUERY_PORT command failed for port %d, aborting (%d)\n", in mlx4_slave_special_qp_cap()
901 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_slave_special_qp_cap()
906 static int mlx4_slave_cap(struct mlx4_dev *dev) in mlx4_slave_cap() argument
918 mlx4_err(dev, "Failed to allocate memory for slave_cap\n"); in mlx4_slave_cap()
923 err = mlx4_QUERY_HCA(dev, hca_param); in mlx4_slave_cap()
925 mlx4_err(dev, "QUERY_HCA command failed, aborting\n"); in mlx4_slave_cap()
933 mlx4_err(dev, "Unknown hca global capabilities\n"); in mlx4_slave_cap()
938 dev->caps.hca_core_clock = hca_param->hca_core_clock; in mlx4_slave_cap()
940 dev->caps.max_qp_dest_rdma = 1 << hca_param->log_rd_per_qp; in mlx4_slave_cap()
941 err = mlx4_dev_cap(dev, dev_cap); in mlx4_slave_cap()
943 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_slave_cap()
947 err = mlx4_QUERY_FW(dev); in mlx4_slave_cap()
949 mlx4_err(dev, "QUERY_FW command failed: could not get FW version\n"); in mlx4_slave_cap()
951 page_size = ~dev->caps.page_size_cap + 1; in mlx4_slave_cap()
952 mlx4_warn(dev, "HCA minimum page size:%d\n", page_size); in mlx4_slave_cap()
954 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_slave_cap()
961 dev->uar_page_shift = hca_param->uar_page_sz + 12; in mlx4_slave_cap()
964 if (dev->uar_page_shift > PAGE_SHIFT) { in mlx4_slave_cap()
965 mlx4_err(dev, in mlx4_slave_cap()
972 mlx4_set_num_reserved_uars(dev, dev_cap); in mlx4_slave_cap()
978 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_slave_cap()
980 err = mlx4_QUERY_FUNC_CAP(dev, 0, func_cap); in mlx4_slave_cap()
982 mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d)\n", in mlx4_slave_cap()
989 mlx4_err(dev, "Unknown pf context behaviour %x known flags %x\n", in mlx4_slave_cap()
996 dev->caps.num_ports = func_cap->num_ports; in mlx4_slave_cap()
997 dev->quotas.qp = func_cap->qp_quota; in mlx4_slave_cap()
998 dev->quotas.srq = func_cap->srq_quota; in mlx4_slave_cap()
999 dev->quotas.cq = func_cap->cq_quota; in mlx4_slave_cap()
1000 dev->quotas.mpt = func_cap->mpt_quota; in mlx4_slave_cap()
1001 dev->quotas.mtt = func_cap->mtt_quota; in mlx4_slave_cap()
1002 dev->caps.num_qps = 1 << hca_param->log_num_qps; in mlx4_slave_cap()
1003 dev->caps.num_srqs = 1 << hca_param->log_num_srqs; in mlx4_slave_cap()
1004 dev->caps.num_cqs = 1 << hca_param->log_num_cqs; in mlx4_slave_cap()
1005 dev->caps.num_mpts = 1 << hca_param->log_mpt_sz; in mlx4_slave_cap()
1006 dev->caps.num_eqs = func_cap->max_eq; in mlx4_slave_cap()
1007 dev->caps.reserved_eqs = func_cap->reserved_eq; in mlx4_slave_cap()
1008 dev->caps.reserved_lkey = func_cap->reserved_lkey; in mlx4_slave_cap()
1009 dev->caps.num_pds = MLX4_NUM_PDS; in mlx4_slave_cap()
1010 dev->caps.num_mgms = 0; in mlx4_slave_cap()
1011 dev->caps.num_amgms = 0; in mlx4_slave_cap()
1013 if (dev->caps.num_ports > MLX4_MAX_PORTS) { in mlx4_slave_cap()
1014 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_slave_cap()
1015 dev->caps.num_ports, MLX4_MAX_PORTS); in mlx4_slave_cap()
1020 mlx4_replace_zero_macs(dev); in mlx4_slave_cap()
1022 err = mlx4_slave_special_qp_cap(dev); in mlx4_slave_cap()
1024 mlx4_err(dev, "Set special QP caps failed. aborting\n"); in mlx4_slave_cap()
1028 if (dev->caps.uar_page_size * (dev->caps.num_uars - in mlx4_slave_cap()
1029 dev->caps.reserved_uars) > in mlx4_slave_cap()
1030 pci_resource_len(dev->persist->pdev, in mlx4_slave_cap()
1032 …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()
1033 dev->caps.uar_page_size * dev->caps.num_uars, in mlx4_slave_cap()
1035 pci_resource_len(dev->persist->pdev, 2)); in mlx4_slave_cap()
1041 dev->caps.eqe_size = 64; in mlx4_slave_cap()
1042 dev->caps.eqe_factor = 1; in mlx4_slave_cap()
1044 dev->caps.eqe_size = 32; in mlx4_slave_cap()
1045 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
1049 dev->caps.cqe_size = 64; in mlx4_slave_cap()
1050 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
1052 dev->caps.cqe_size = 32; in mlx4_slave_cap()
1056 dev->caps.eqe_size = hca_param->eqe_size; in mlx4_slave_cap()
1057 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
1061 dev->caps.cqe_size = hca_param->cqe_size; in mlx4_slave_cap()
1063 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
1066 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_slave_cap()
1067 mlx4_warn(dev, "Timestamping is not supported in slave mode\n"); in mlx4_slave_cap()
1069 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_USER_MAC_EN; in mlx4_slave_cap()
1070 mlx4_dbg(dev, "User MAC FW update is not supported in slave mode\n"); in mlx4_slave_cap()
1072 slave_adjust_steering_mode(dev, dev_cap, hca_param); in mlx4_slave_cap()
1073 mlx4_dbg(dev, "RSS support for IP fragments is %s\n", in mlx4_slave_cap()
1077 dev->caps.bf_reg_size) in mlx4_slave_cap()
1078 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_ETH_BF_QP; in mlx4_slave_cap()
1081 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_A0_QP; in mlx4_slave_cap()
1085 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_slave_cap()
1097 int mlx4_change_port_types(struct mlx4_dev *dev, in mlx4_change_port_types() argument
1104 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_change_port_types()
1107 if (port_types[port] != dev->caps.port_type[port + 1]) in mlx4_change_port_types()
1111 mlx4_unregister_device(dev); in mlx4_change_port_types()
1112 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_change_port_types()
1113 mlx4_CLOSE_PORT(dev, port); in mlx4_change_port_types()
1114 dev->caps.port_type[port] = port_types[port - 1]; in mlx4_change_port_types()
1115 err = mlx4_SET_PORT(dev, port, -1); in mlx4_change_port_types()
1117 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_change_port_types()
1122 mlx4_set_port_mask(dev); in mlx4_change_port_types()
1123 err = mlx4_register_device(dev); in mlx4_change_port_types()
1125 mlx4_err(dev, "Failed to register device\n"); in mlx4_change_port_types()
1134 static ssize_t show_port_type(struct device *dev, in show_port_type() argument
1140 struct mlx4_dev *mdev = info->dev; in show_port_type()
1157 struct mlx4_dev *mdev = info->dev; in __set_port_type()
1220 static ssize_t set_port_type(struct device *dev, in set_port_type() argument
1226 struct mlx4_dev *mdev = info->dev; in set_port_type()
1285 static ssize_t show_port_ib_mtu(struct device *dev, in show_port_ib_mtu() argument
1291 struct mlx4_dev *mdev = info->dev; in show_port_ib_mtu()
1301 static ssize_t set_port_ib_mtu(struct device *dev, in set_port_ib_mtu() argument
1307 struct mlx4_dev *mdev = info->dev; in set_port_ib_mtu()
1348 static int mlx4_mf_bond(struct mlx4_dev *dev) in mlx4_mf_bond() argument
1355 slaves_port1 = mlx4_phys_to_slaves_pport(dev, 1); in mlx4_mf_bond()
1356 slaves_port2 = mlx4_phys_to_slaves_pport(dev, 2); in mlx4_mf_bond()
1360 dev->persist->num_vfs + 1) > 1) { in mlx4_mf_bond()
1361 mlx4_warn(dev, "HA mode unsupported for dual ported VFs\n"); in mlx4_mf_bond()
1368 nvfs = bitmap_weight(slaves_port1.slaves, dev->persist->num_vfs + 1) + in mlx4_mf_bond()
1369 bitmap_weight(slaves_port2.slaves, dev->persist->num_vfs + 1) - 2; in mlx4_mf_bond()
1373 mlx4_warn(dev, "HA mode is not supported for %d VFs (max %d are allowed)\n", in mlx4_mf_bond()
1378 if (dev->caps.steering_mode != MLX4_STEERING_MODE_DEVICE_MANAGED) { in mlx4_mf_bond()
1379 mlx4_warn(dev, "HA mode unsupported for NON DMFS steering\n"); in mlx4_mf_bond()
1383 err = mlx4_bond_mac_table(dev); in mlx4_mf_bond()
1386 err = mlx4_bond_vlan_table(dev); in mlx4_mf_bond()
1389 err = mlx4_bond_fs_rules(dev); in mlx4_mf_bond()
1395 (void)mlx4_unbond_vlan_table(dev); in mlx4_mf_bond()
1397 (void)mlx4_unbond_mac_table(dev); in mlx4_mf_bond()
1401 static int mlx4_mf_unbond(struct mlx4_dev *dev) in mlx4_mf_unbond() argument
1405 ret = mlx4_unbond_fs_rules(dev); in mlx4_mf_unbond()
1407 mlx4_warn(dev, "multifunction unbond for flow rules failed (%d)\n", ret); in mlx4_mf_unbond()
1408 ret1 = mlx4_unbond_mac_table(dev); in mlx4_mf_unbond()
1410 mlx4_warn(dev, "multifunction unbond for MAC table failed (%d)\n", ret1); in mlx4_mf_unbond()
1413 ret1 = mlx4_unbond_vlan_table(dev); in mlx4_mf_unbond()
1415 mlx4_warn(dev, "multifunction unbond for VLAN table failed (%d)\n", ret1); in mlx4_mf_unbond()
1421 static int mlx4_bond(struct mlx4_dev *dev) in mlx4_bond() argument
1424 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_bond()
1428 if (!mlx4_is_bonded(dev)) { in mlx4_bond()
1429 ret = mlx4_do_bond(dev, true); in mlx4_bond()
1431 mlx4_err(dev, "Failed to bond device: %d\n", ret); in mlx4_bond()
1432 if (!ret && mlx4_is_master(dev)) { in mlx4_bond()
1433 ret = mlx4_mf_bond(dev); in mlx4_bond()
1435 mlx4_err(dev, "bond for multifunction failed\n"); in mlx4_bond()
1436 mlx4_do_bond(dev, false); in mlx4_bond()
1443 mlx4_dbg(dev, "Device is bonded\n"); in mlx4_bond()
1448 static int mlx4_unbond(struct mlx4_dev *dev) in mlx4_unbond() argument
1451 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unbond()
1455 if (mlx4_is_bonded(dev)) { in mlx4_unbond()
1458 ret = mlx4_do_bond(dev, false); in mlx4_unbond()
1460 mlx4_err(dev, "Failed to unbond device: %d\n", ret); in mlx4_unbond()
1461 if (mlx4_is_master(dev)) in mlx4_unbond()
1462 ret2 = mlx4_mf_unbond(dev); in mlx4_unbond()
1464 mlx4_warn(dev, "Failed to unbond device for multifunction (%d)\n", ret2); in mlx4_unbond()
1471 mlx4_dbg(dev, "Device is unbonded\n"); in mlx4_unbond()
1476 static int mlx4_port_map_set(struct mlx4_dev *dev, struct mlx4_port_map *v2p) in mlx4_port_map_set() argument
1480 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_port_map_set()
1483 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_REMAP)) in mlx4_port_map_set()
1504 err = mlx4_virt2phy_port_map(dev, port1, port2); in mlx4_port_map_set()
1506 mlx4_dbg(dev, "port map changed: [%d][%d]\n", in mlx4_port_map_set()
1511 mlx4_err(dev, "Failed to change port mape: %d\n", err); in mlx4_port_map_set()
1521 struct mlx4_dev *dev; member
1532 if (!mlx4_is_bonded(bond->dev)) { in mlx4_bond_work()
1533 err = mlx4_bond(bond->dev); in mlx4_bond_work()
1535 mlx4_err(bond->dev, "Fail to bond device\n"); in mlx4_bond_work()
1538 err = mlx4_port_map_set(bond->dev, &bond->port_map); in mlx4_bond_work()
1540 mlx4_err(bond->dev, in mlx4_bond_work()
1545 } else if (mlx4_is_bonded(bond->dev)) { in mlx4_bond_work()
1546 err = mlx4_unbond(bond->dev); in mlx4_bond_work()
1548 mlx4_err(bond->dev, "Fail to unbond device\n"); in mlx4_bond_work()
1550 put_device(&bond->dev->persist->pdev->dev); in mlx4_bond_work()
1554 int mlx4_queue_bond_work(struct mlx4_dev *dev, int is_bonded, u8 v2p_p1, in mlx4_queue_bond_work() argument
1564 get_device(&dev->persist->pdev->dev); in mlx4_queue_bond_work()
1565 bond->dev = dev; in mlx4_queue_bond_work()
1574 static int mlx4_load_fw(struct mlx4_dev *dev) in mlx4_load_fw() argument
1576 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_load_fw()
1579 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages, in mlx4_load_fw()
1582 mlx4_err(dev, "Couldn't allocate FW area, aborting\n"); in mlx4_load_fw()
1586 err = mlx4_MAP_FA(dev, priv->fw.fw_icm); in mlx4_load_fw()
1588 mlx4_err(dev, "MAP_FA command failed, aborting\n"); in mlx4_load_fw()
1592 err = mlx4_RUN_FW(dev); in mlx4_load_fw()
1594 mlx4_err(dev, "RUN_FW command failed, aborting\n"); in mlx4_load_fw()
1601 mlx4_UNMAP_FA(dev); in mlx4_load_fw()
1604 mlx4_free_icm(dev, priv->fw.fw_icm, 0); in mlx4_load_fw()
1608 static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base, in mlx4_init_cmpt_table() argument
1611 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_cmpt_table()
1615 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table, in mlx4_init_cmpt_table()
1619 cmpt_entry_sz, dev->caps.num_qps, in mlx4_init_cmpt_table()
1620 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_cmpt_table()
1625 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table, in mlx4_init_cmpt_table()
1629 cmpt_entry_sz, dev->caps.num_srqs, in mlx4_init_cmpt_table()
1630 dev->caps.reserved_srqs, 0, 0); in mlx4_init_cmpt_table()
1634 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table, in mlx4_init_cmpt_table()
1638 cmpt_entry_sz, dev->caps.num_cqs, in mlx4_init_cmpt_table()
1639 dev->caps.reserved_cqs, 0, 0); in mlx4_init_cmpt_table()
1643 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_cmpt_table()
1644 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table, in mlx4_init_cmpt_table()
1655 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_cmpt_table()
1658 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_cmpt_table()
1661 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_cmpt_table()
1667 static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_init_icm() argument
1670 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_icm()
1675 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages); in mlx4_init_icm()
1677 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting\n"); in mlx4_init_icm()
1681 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory\n", in mlx4_init_icm()
1685 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages, in mlx4_init_icm()
1688 mlx4_err(dev, "Couldn't allocate aux memory, aborting\n"); in mlx4_init_icm()
1692 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm); in mlx4_init_icm()
1694 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting\n"); in mlx4_init_icm()
1698 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz); in mlx4_init_icm()
1700 mlx4_err(dev, "Failed to map cMPT context memory, aborting\n"); in mlx4_init_icm()
1705 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_icm()
1706 err = mlx4_init_icm_table(dev, &priv->eq_table.table, in mlx4_init_icm()
1710 mlx4_err(dev, "Failed to map EQ context memory, aborting\n"); in mlx4_init_icm()
1721 dev->caps.reserved_mtts = in mlx4_init_icm()
1722 ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz, in mlx4_init_icm()
1723 dma_get_cache_alignment()) / dev->caps.mtt_entry_sz; in mlx4_init_icm()
1725 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table, in mlx4_init_icm()
1727 dev->caps.mtt_entry_sz, in mlx4_init_icm()
1728 dev->caps.num_mtts, in mlx4_init_icm()
1729 dev->caps.reserved_mtts, 1, 0); in mlx4_init_icm()
1731 mlx4_err(dev, "Failed to map MTT context memory, aborting\n"); in mlx4_init_icm()
1735 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table, in mlx4_init_icm()
1738 dev->caps.num_mpts, in mlx4_init_icm()
1739 dev->caps.reserved_mrws, 1, 1); in mlx4_init_icm()
1741 mlx4_err(dev, "Failed to map dMPT context memory, aborting\n"); in mlx4_init_icm()
1745 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table, in mlx4_init_icm()
1748 dev->caps.num_qps, in mlx4_init_icm()
1749 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1752 mlx4_err(dev, "Failed to map QP context memory, aborting\n"); in mlx4_init_icm()
1756 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table, in mlx4_init_icm()
1759 dev->caps.num_qps, in mlx4_init_icm()
1760 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1763 mlx4_err(dev, "Failed to map AUXC context memory, aborting\n"); in mlx4_init_icm()
1767 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table, in mlx4_init_icm()
1770 dev->caps.num_qps, in mlx4_init_icm()
1771 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1774 mlx4_err(dev, "Failed to map ALTC context memory, aborting\n"); in mlx4_init_icm()
1778 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table, in mlx4_init_icm()
1781 dev->caps.num_qps, in mlx4_init_icm()
1782 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1785 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n"); in mlx4_init_icm()
1789 err = mlx4_init_icm_table(dev, &priv->cq_table.table, in mlx4_init_icm()
1792 dev->caps.num_cqs, in mlx4_init_icm()
1793 dev->caps.reserved_cqs, 0, 0); in mlx4_init_icm()
1795 mlx4_err(dev, "Failed to map CQ context memory, aborting\n"); in mlx4_init_icm()
1799 err = mlx4_init_icm_table(dev, &priv->srq_table.table, in mlx4_init_icm()
1802 dev->caps.num_srqs, in mlx4_init_icm()
1803 dev->caps.reserved_srqs, 0, 0); in mlx4_init_icm()
1805 mlx4_err(dev, "Failed to map SRQ context memory, aborting\n"); in mlx4_init_icm()
1816 err = mlx4_init_icm_table(dev, &priv->mcg_table.table, in mlx4_init_icm()
1818 mlx4_get_mgm_entry_size(dev), in mlx4_init_icm()
1819 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1820 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1823 mlx4_err(dev, "Failed to map MCG context memory, aborting\n"); in mlx4_init_icm()
1830 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_init_icm()
1833 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_init_icm()
1836 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_init_icm()
1839 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_init_icm()
1842 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_init_icm()
1845 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_init_icm()
1848 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_init_icm()
1851 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_init_icm()
1854 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_init_icm()
1857 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_init_icm()
1858 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_icm()
1859 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_icm()
1860 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_icm()
1863 mlx4_UNMAP_ICM_AUX(dev); in mlx4_init_icm()
1866 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_init_icm()
1871 static void mlx4_free_icms(struct mlx4_dev *dev) in mlx4_free_icms() argument
1873 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_free_icms()
1875 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table); in mlx4_free_icms()
1876 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_free_icms()
1877 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_free_icms()
1878 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_free_icms()
1879 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_free_icms()
1880 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_free_icms()
1881 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_free_icms()
1882 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_free_icms()
1883 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_free_icms()
1884 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_free_icms()
1885 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_free_icms()
1886 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_free_icms()
1887 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_free_icms()
1888 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_free_icms()
1890 mlx4_UNMAP_ICM_AUX(dev); in mlx4_free_icms()
1891 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_free_icms()
1894 static void mlx4_slave_exit(struct mlx4_dev *dev) in mlx4_slave_exit() argument
1896 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_slave_exit()
1899 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, in mlx4_slave_exit()
1901 mlx4_warn(dev, "Failed to close slave function\n"); in mlx4_slave_exit()
1905 static int map_bf_area(struct mlx4_dev *dev) in map_bf_area() argument
1907 struct mlx4_priv *priv = mlx4_priv(dev); in map_bf_area()
1912 if (!dev->caps.bf_reg_size) in map_bf_area()
1915 bf_start = pci_resource_start(dev->persist->pdev, 2) + in map_bf_area()
1916 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1917 bf_len = pci_resource_len(dev->persist->pdev, 2) - in map_bf_area()
1918 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1926 static void unmap_bf_area(struct mlx4_dev *dev) in unmap_bf_area() argument
1928 if (mlx4_priv(dev)->bf_mapping) in unmap_bf_area()
1929 io_mapping_free(mlx4_priv(dev)->bf_mapping); in unmap_bf_area()
1932 u64 mlx4_read_clock(struct mlx4_dev *dev) in mlx4_read_clock() argument
1937 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_read_clock()
1954 static int map_internal_clock(struct mlx4_dev *dev) in map_internal_clock() argument
1956 struct mlx4_priv *priv = mlx4_priv(dev); in map_internal_clock()
1959 ioremap(pci_resource_start(dev->persist->pdev, in map_internal_clock()
1969 int mlx4_get_internal_clock_params(struct mlx4_dev *dev, in mlx4_get_internal_clock_params() argument
1972 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_internal_clock_params()
1974 if (mlx4_is_slave(dev)) in mlx4_get_internal_clock_params()
1977 if (!dev->caps.map_clock_to_user) { in mlx4_get_internal_clock_params()
1978 mlx4_dbg(dev, "Map clock to user is not supported.\n"); in mlx4_get_internal_clock_params()
1993 static void unmap_internal_clock(struct mlx4_dev *dev) in unmap_internal_clock() argument
1995 struct mlx4_priv *priv = mlx4_priv(dev); in unmap_internal_clock()
2001 static void mlx4_close_hca(struct mlx4_dev *dev) in mlx4_close_hca() argument
2003 unmap_internal_clock(dev); in mlx4_close_hca()
2004 unmap_bf_area(dev); in mlx4_close_hca()
2005 if (mlx4_is_slave(dev)) in mlx4_close_hca()
2006 mlx4_slave_exit(dev); in mlx4_close_hca()
2008 mlx4_CLOSE_HCA(dev, 0); in mlx4_close_hca()
2009 mlx4_free_icms(dev); in mlx4_close_hca()
2013 static void mlx4_close_fw(struct mlx4_dev *dev) in mlx4_close_fw() argument
2015 if (!mlx4_is_slave(dev)) { in mlx4_close_fw()
2016 mlx4_UNMAP_FA(dev); in mlx4_close_fw()
2017 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0); in mlx4_close_fw()
2021 static int mlx4_comm_check_offline(struct mlx4_dev *dev) in mlx4_comm_check_offline() argument
2028 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_comm_check_offline()
2042 if (dev->persist->interface_state & in mlx4_comm_check_offline()
2053 mlx4_err(dev, "Communication channel is offline.\n"); in mlx4_comm_check_offline()
2057 static void mlx4_reset_vf_support(struct mlx4_dev *dev) in mlx4_reset_vf_support() argument
2061 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_reset_vf_support()
2070 dev->caps.vf_caps |= MLX4_VF_CAP_FLAG_RESET; in mlx4_reset_vf_support()
2073 static int mlx4_init_slave(struct mlx4_dev *dev) in mlx4_init_slave() argument
2075 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_slave()
2082 mlx4_warn(dev, "PF is not ready - Deferring probe\n"); in mlx4_init_slave()
2088 if (mlx4_comm_check_offline(dev)) { in mlx4_init_slave()
2089 mlx4_err(dev, "PF is not responsive, skipping initialization\n"); in mlx4_init_slave()
2093 mlx4_reset_vf_support(dev); in mlx4_init_slave()
2094 mlx4_warn(dev, "Sending reset\n"); in mlx4_init_slave()
2095 ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, in mlx4_init_slave()
2101 mlx4_warn(dev, "slave is currently in the middle of FLR - Deferring probe\n"); in mlx4_init_slave()
2115 mlx4_err(dev, "slave driver version is not supported by the master\n"); in mlx4_init_slave()
2119 mlx4_warn(dev, "Sending vhcr0\n"); in mlx4_init_slave()
2120 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48, in mlx4_init_slave()
2123 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32, in mlx4_init_slave()
2126 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16, in mlx4_init_slave()
2129 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, in mlx4_init_slave()
2137 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, 0); in mlx4_init_slave()
2143 static void mlx4_parav_master_pf_caps(struct mlx4_dev *dev) in mlx4_parav_master_pf_caps() argument
2147 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_parav_master_pf_caps()
2148 if (dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_parav_master_pf_caps()
2149 dev->caps.gid_table_len[i] = in mlx4_parav_master_pf_caps()
2150 mlx4_get_slave_num_gids(dev, 0, i); in mlx4_parav_master_pf_caps()
2152 dev->caps.gid_table_len[i] = 1; in mlx4_parav_master_pf_caps()
2153 dev->caps.pkey_table_len[i] = in mlx4_parav_master_pf_caps()
2154 dev->phys_caps.pkey_phys_table_len[i] - 1; in mlx4_parav_master_pf_caps()
2196 static void choose_steering_mode(struct mlx4_dev *dev, in choose_steering_mode() argument
2201 if (dev->caps.dmfs_high_steer_mode == in choose_steering_mode()
2203 mlx4_err(dev, "DMFS high rate mode not supported\n"); in choose_steering_mode()
2205 dev->caps.dmfs_high_steer_mode = in choose_steering_mode()
2212 (!mlx4_is_mfunc(dev) || in choose_steering_mode()
2214 (dev->persist->num_vfs + 1))) && in choose_steering_mode()
2217 dev->oper_log_mgm_entry_size = in choose_steering_mode()
2219 dev->caps.steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED; in choose_steering_mode()
2220 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in choose_steering_mode()
2221 dev->caps.fs_log_max_ucast_qp_range_size = in choose_steering_mode()
2224 if (dev->caps.dmfs_high_steer_mode != in choose_steering_mode()
2226 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DISABLE; in choose_steering_mode()
2227 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER && in choose_steering_mode()
2228 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
2229 dev->caps.steering_mode = MLX4_STEERING_MODE_B0; in choose_steering_mode()
2231 dev->caps.steering_mode = MLX4_STEERING_MODE_A0; in choose_steering_mode()
2233 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER || in choose_steering_mode()
2234 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
2235 …mlx4_warn(dev, "Must have both UC_STEER and MC_STEER flags set to use B0 steering - falling back t… in choose_steering_mode()
2237 dev->oper_log_mgm_entry_size = in choose_steering_mode()
2241 dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev); in choose_steering_mode()
2243 …mlx4_dbg(dev, "Steering mode is: %s, oper_log_mgm_entry_size = %d, modparam log_num_mgm_entry_size… in choose_steering_mode()
2244 mlx4_steering_mode_str(dev->caps.steering_mode), in choose_steering_mode()
2245 dev->oper_log_mgm_entry_size, in choose_steering_mode()
2249 static void choose_tunnel_offload_mode(struct mlx4_dev *dev, in choose_tunnel_offload_mode() argument
2252 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED && in choose_tunnel_offload_mode()
2254 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_VXLAN; in choose_tunnel_offload_mode()
2256 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_NONE; in choose_tunnel_offload_mode()
2258 mlx4_dbg(dev, "Tunneling offload mode is: %s\n", (dev->caps.tunnel_offload_mode in choose_tunnel_offload_mode()
2262 static int mlx4_validate_optimized_steering(struct mlx4_dev *dev) in mlx4_validate_optimized_steering() argument
2267 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_NOT_SUPPORTED) in mlx4_validate_optimized_steering()
2270 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_validate_optimized_steering()
2271 if (mlx4_dev_port(dev, i, &port_cap)) { in mlx4_validate_optimized_steering()
2272 mlx4_err(dev, in mlx4_validate_optimized_steering()
2274 } else if ((dev->caps.dmfs_high_steer_mode != in mlx4_validate_optimized_steering()
2277 !!(dev->caps.dmfs_high_steer_mode == in mlx4_validate_optimized_steering()
2279 mlx4_err(dev, in mlx4_validate_optimized_steering()
2282 dev->caps.dmfs_high_steer_mode), in mlx4_validate_optimized_steering()
2291 static int mlx4_init_fw(struct mlx4_dev *dev) in mlx4_init_fw() argument
2296 if (!mlx4_is_slave(dev)) { in mlx4_init_fw()
2297 err = mlx4_QUERY_FW(dev); in mlx4_init_fw()
2300 mlx4_info(dev, "non-primary physical function, skipping\n"); in mlx4_init_fw()
2302 mlx4_err(dev, "QUERY_FW command failed, aborting\n"); in mlx4_init_fw()
2306 err = mlx4_load_fw(dev); in mlx4_init_fw()
2308 mlx4_err(dev, "Failed to start FW, aborting\n"); in mlx4_init_fw()
2314 err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg); in mlx4_init_fw()
2316 mlx4_warn(dev, "Failed to override log_pg_sz parameter\n"); in mlx4_init_fw()
2322 static int mlx4_init_hca(struct mlx4_dev *dev) in mlx4_init_hca() argument
2324 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_hca()
2333 if (!mlx4_is_slave(dev)) { in mlx4_init_hca()
2342 err = mlx4_dev_cap(dev, dev_cap); in mlx4_init_hca()
2344 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_init_hca()
2348 choose_steering_mode(dev, dev_cap); in mlx4_init_hca()
2349 choose_tunnel_offload_mode(dev, dev_cap); in mlx4_init_hca()
2351 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC && in mlx4_init_hca()
2352 mlx4_is_master(dev)) in mlx4_init_hca()
2353 dev->caps.function_caps |= MLX4_FUNC_CAP_DMFS_A0_STATIC; in mlx4_init_hca()
2355 err = mlx4_get_phys_port_id(dev); in mlx4_init_hca()
2357 mlx4_err(dev, "Fail to get physical port id\n"); in mlx4_init_hca()
2359 if (mlx4_is_master(dev)) in mlx4_init_hca()
2360 mlx4_parav_master_pf_caps(dev); in mlx4_init_hca()
2363 mlx4_info(dev, "Running from within kdump kernel. Using low memory profile\n"); in mlx4_init_hca()
2368 if (dev->caps.steering_mode == in mlx4_init_hca()
2372 icm_size = mlx4_make_profile(dev, &profile, dev_cap, in mlx4_init_hca()
2379 if (enable_4k_uar || !dev->persist->num_vfs) { in mlx4_init_hca()
2380 init_hca->log_uar_sz = ilog2(dev->caps.num_uars) + in mlx4_init_hca()
2384 init_hca->log_uar_sz = ilog2(dev->caps.num_uars); in mlx4_init_hca()
2389 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW || in mlx4_init_hca()
2390 dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) in mlx4_init_hca()
2393 err = mlx4_init_icm(dev, dev_cap, init_hca, icm_size); in mlx4_init_hca()
2397 err = mlx4_INIT_HCA(dev, init_hca); in mlx4_init_hca()
2399 mlx4_err(dev, "INIT_HCA command failed, aborting\n"); in mlx4_init_hca()
2404 err = mlx4_query_func(dev, dev_cap); in mlx4_init_hca()
2406 mlx4_err(dev, "QUERY_FUNC command failed, aborting.\n"); in mlx4_init_hca()
2409 dev->caps.num_eqs = dev_cap->max_eqs; in mlx4_init_hca()
2410 dev->caps.reserved_eqs = dev_cap->reserved_eqs; in mlx4_init_hca()
2411 dev->caps.reserved_uars = dev_cap->reserved_uars; in mlx4_init_hca()
2419 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) { in mlx4_init_hca()
2420 err = mlx4_QUERY_HCA(dev, init_hca); in mlx4_init_hca()
2422 mlx4_err(dev, "QUERY_HCA command failed, disable timestamp\n"); in mlx4_init_hca()
2423 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2425 dev->caps.hca_core_clock = in mlx4_init_hca()
2432 if (!dev->caps.hca_core_clock) { in mlx4_init_hca()
2433 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2434 mlx4_err(dev, in mlx4_init_hca()
2436 } else if (map_internal_clock(dev)) { in mlx4_init_hca()
2441 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2442 mlx4_err(dev, "Failed to map internal clock. Timestamping is not supported\n"); in mlx4_init_hca()
2446 if (dev->caps.dmfs_high_steer_mode != in mlx4_init_hca()
2448 if (mlx4_validate_optimized_steering(dev)) in mlx4_init_hca()
2449 mlx4_warn(dev, "Optimized steering validation failed\n"); in mlx4_init_hca()
2451 if (dev->caps.dmfs_high_steer_mode == in mlx4_init_hca()
2453 dev->caps.dmfs_high_rate_qpn_base = in mlx4_init_hca()
2454 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_init_hca()
2455 dev->caps.dmfs_high_rate_qpn_range = in mlx4_init_hca()
2459 mlx4_info(dev, "DMFS high rate steer mode is: %s\n", in mlx4_init_hca()
2461 dev->caps.dmfs_high_steer_mode)); in mlx4_init_hca()
2464 err = mlx4_init_slave(dev); in mlx4_init_hca()
2467 mlx4_err(dev, "Failed to initialize slave\n"); in mlx4_init_hca()
2471 err = mlx4_slave_cap(dev); in mlx4_init_hca()
2473 mlx4_err(dev, "Failed to obtain slave caps\n"); in mlx4_init_hca()
2478 if (map_bf_area(dev)) in mlx4_init_hca()
2479 mlx4_dbg(dev, "Failed to map blue flame area\n"); in mlx4_init_hca()
2482 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2483 mlx4_set_port_mask(dev); in mlx4_init_hca()
2485 err = mlx4_QUERY_ADAPTER(dev, &adapter); in mlx4_init_hca()
2487 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting\n"); in mlx4_init_hca()
2492 err = mlx4_config_dev_retrieval(dev, &params); in mlx4_init_hca()
2494 mlx4_err(dev, "Failed to query CONFIG_DEV parameters\n"); in mlx4_init_hca()
2496 dev->caps.rx_checksum_flags_port[1] = params.rx_csum_flags_port_1; in mlx4_init_hca()
2497 dev->caps.rx_checksum_flags_port[2] = params.rx_csum_flags_port_2; in mlx4_init_hca()
2500 memcpy(dev->board_id, adapter.board_id, sizeof(dev->board_id)); in mlx4_init_hca()
2506 unmap_internal_clock(dev); in mlx4_init_hca()
2507 unmap_bf_area(dev); in mlx4_init_hca()
2509 if (mlx4_is_slave(dev)) in mlx4_init_hca()
2510 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_init_hca()
2513 if (mlx4_is_slave(dev)) in mlx4_init_hca()
2514 mlx4_slave_exit(dev); in mlx4_init_hca()
2516 mlx4_CLOSE_HCA(dev, 0); in mlx4_init_hca()
2519 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2520 mlx4_free_icms(dev); in mlx4_init_hca()
2529 static int mlx4_init_counters_table(struct mlx4_dev *dev) in mlx4_init_counters_table() argument
2531 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_counters_table()
2534 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_init_counters_table()
2537 if (!dev->caps.max_counters) in mlx4_init_counters_table()
2540 nent_pow2 = roundup_pow_of_two(dev->caps.max_counters); in mlx4_init_counters_table()
2544 nent_pow2 - dev->caps.max_counters + 1); in mlx4_init_counters_table()
2547 static void mlx4_cleanup_counters_table(struct mlx4_dev *dev) in mlx4_cleanup_counters_table() argument
2549 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_cleanup_counters_table()
2552 if (!dev->caps.max_counters) in mlx4_cleanup_counters_table()
2555 mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap); in mlx4_cleanup_counters_table()
2558 static void mlx4_cleanup_default_counters(struct mlx4_dev *dev) in mlx4_cleanup_default_counters() argument
2560 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_cleanup_default_counters()
2563 for (port = 0; port < dev->caps.num_ports; port++) in mlx4_cleanup_default_counters()
2565 mlx4_counter_free(dev, priv->def_counter[port]); in mlx4_cleanup_default_counters()
2568 static int mlx4_allocate_default_counters(struct mlx4_dev *dev) in mlx4_allocate_default_counters() argument
2570 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_allocate_default_counters()
2574 for (port = 0; port < dev->caps.num_ports; port++) in mlx4_allocate_default_counters()
2577 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_allocate_default_counters()
2578 err = mlx4_counter_alloc(dev, &idx, MLX4_RES_USAGE_DRIVER); in mlx4_allocate_default_counters()
2586 } else if (mlx4_is_slave(dev) && err == -EINVAL) { in mlx4_allocate_default_counters()
2587 priv->def_counter[port] = MLX4_SINK_COUNTER_INDEX(dev); in mlx4_allocate_default_counters()
2588 mlx4_warn(dev, "can't allocate counter from old PF driver, using index %d\n", in mlx4_allocate_default_counters()
2589 MLX4_SINK_COUNTER_INDEX(dev)); in mlx4_allocate_default_counters()
2592 mlx4_err(dev, "%s: failed to allocate default counter port %d err %d\n", in mlx4_allocate_default_counters()
2594 mlx4_cleanup_default_counters(dev); in mlx4_allocate_default_counters()
2598 mlx4_dbg(dev, "%s: default counter index %d for port %d\n", in mlx4_allocate_default_counters()
2605 int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) in __mlx4_counter_alloc() argument
2607 struct mlx4_priv *priv = mlx4_priv(dev); in __mlx4_counter_alloc()
2609 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_alloc()
2614 *idx = MLX4_SINK_COUNTER_INDEX(dev); in __mlx4_counter_alloc()
2621 int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx, u8 usage) in mlx4_counter_alloc() argument
2627 if (mlx4_is_mfunc(dev)) { in mlx4_counter_alloc()
2628 err = mlx4_cmd_imm(dev, 0, &out_param, in_modifier, in mlx4_counter_alloc()
2637 return __mlx4_counter_alloc(dev, idx); in mlx4_counter_alloc()
2641 static int __mlx4_clear_if_stat(struct mlx4_dev *dev, in __mlx4_clear_if_stat() argument
2648 if_stat_mailbox = mlx4_alloc_cmd_mailbox(dev); in __mlx4_clear_if_stat()
2652 err = mlx4_cmd_box(dev, 0, if_stat_mailbox->dma, if_stat_in_mod, 0, in __mlx4_clear_if_stat()
2656 mlx4_free_cmd_mailbox(dev, if_stat_mailbox); in __mlx4_clear_if_stat()
2660 void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in __mlx4_counter_free() argument
2662 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_free()
2665 if (idx == MLX4_SINK_COUNTER_INDEX(dev)) in __mlx4_counter_free()
2668 __mlx4_clear_if_stat(dev, idx); in __mlx4_counter_free()
2670 mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx, MLX4_USE_RR); in __mlx4_counter_free()
2674 void mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in mlx4_counter_free() argument
2678 if (mlx4_is_mfunc(dev)) { in mlx4_counter_free()
2680 mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE, in mlx4_counter_free()
2685 __mlx4_counter_free(dev, idx); in mlx4_counter_free()
2689 int mlx4_get_default_counter_index(struct mlx4_dev *dev, int port) in mlx4_get_default_counter_index() argument
2691 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_default_counter_index()
2697 void mlx4_set_admin_guid(struct mlx4_dev *dev, __be64 guid, int entry, int port) in mlx4_set_admin_guid() argument
2699 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_admin_guid()
2705 __be64 mlx4_get_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_get_admin_guid() argument
2707 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_admin_guid()
2713 void mlx4_set_random_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_set_random_admin_guid() argument
2715 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_random_admin_guid()
2728 static int mlx4_setup_hca(struct mlx4_dev *dev) in mlx4_setup_hca() argument
2730 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_setup_hca()
2735 err = mlx4_init_uar_table(dev); in mlx4_setup_hca()
2737 mlx4_err(dev, "Failed to initialize user access region table, aborting\n"); in mlx4_setup_hca()
2741 err = mlx4_uar_alloc(dev, &priv->driver_uar); in mlx4_setup_hca()
2743 mlx4_err(dev, "Failed to allocate driver access region, aborting\n"); in mlx4_setup_hca()
2749 mlx4_err(dev, "Couldn't map kernel access region, aborting\n"); in mlx4_setup_hca()
2754 err = mlx4_init_pd_table(dev); in mlx4_setup_hca()
2756 mlx4_err(dev, "Failed to initialize protection domain table, aborting\n"); in mlx4_setup_hca()
2760 err = mlx4_init_xrcd_table(dev); in mlx4_setup_hca()
2762 mlx4_err(dev, "Failed to initialize reliable connection domain table, aborting\n"); in mlx4_setup_hca()
2766 err = mlx4_init_mr_table(dev); in mlx4_setup_hca()
2768 mlx4_err(dev, "Failed to initialize memory region table, aborting\n"); in mlx4_setup_hca()
2772 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2773 err = mlx4_init_mcg_table(dev); in mlx4_setup_hca()
2775 mlx4_err(dev, "Failed to initialize multicast group table, aborting\n"); in mlx4_setup_hca()
2778 err = mlx4_config_mad_demux(dev); in mlx4_setup_hca()
2780 mlx4_err(dev, "Failed in config_mad_demux, aborting\n"); in mlx4_setup_hca()
2785 err = mlx4_init_eq_table(dev); in mlx4_setup_hca()
2787 mlx4_err(dev, "Failed to initialize event queue table, aborting\n"); in mlx4_setup_hca()
2791 err = mlx4_cmd_use_events(dev); in mlx4_setup_hca()
2793 mlx4_err(dev, "Failed to switch to event-driven firmware commands, aborting\n"); in mlx4_setup_hca()
2797 err = mlx4_NOP(dev); in mlx4_setup_hca()
2799 if (dev->flags & MLX4_FLAG_MSI_X) { in mlx4_setup_hca()
2800 mlx4_warn(dev, "NOP command failed to generate MSI-X interrupt IRQ %d)\n", in mlx4_setup_hca()
2802 mlx4_warn(dev, "Trying again without MSI-X\n"); in mlx4_setup_hca()
2804 mlx4_err(dev, "NOP command failed to generate interrupt (IRQ %d), aborting\n", in mlx4_setup_hca()
2806 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n"); in mlx4_setup_hca()
2812 mlx4_dbg(dev, "NOP command IRQ test passed\n"); in mlx4_setup_hca()
2814 err = mlx4_init_cq_table(dev); in mlx4_setup_hca()
2816 mlx4_err(dev, "Failed to initialize completion queue table, aborting\n"); in mlx4_setup_hca()
2820 err = mlx4_init_srq_table(dev); in mlx4_setup_hca()
2822 mlx4_err(dev, "Failed to initialize shared receive queue table, aborting\n"); in mlx4_setup_hca()
2826 err = mlx4_init_qp_table(dev); in mlx4_setup_hca()
2828 mlx4_err(dev, "Failed to initialize queue pair table, aborting\n"); in mlx4_setup_hca()
2832 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2833 err = mlx4_init_counters_table(dev); in mlx4_setup_hca()
2835 mlx4_err(dev, "Failed to initialize counters table, aborting\n"); in mlx4_setup_hca()
2840 err = mlx4_allocate_default_counters(dev); in mlx4_setup_hca()
2842 mlx4_err(dev, "Failed to allocate default counters, aborting\n"); in mlx4_setup_hca()
2846 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2847 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_setup_hca()
2849 err = mlx4_get_port_ib_caps(dev, port, in mlx4_setup_hca()
2852 mlx4_warn(dev, "failed to get port %d default ib capabilities (%d). Continuing with caps = 0\n", in mlx4_setup_hca()
2854 dev->caps.ib_port_def_cap[port] = ib_port_default_caps; in mlx4_setup_hca()
2857 if (mlx4_is_master(dev)) { in mlx4_setup_hca()
2859 for (i = 0; i < dev->num_slaves; i++) { in mlx4_setup_hca()
2860 if (i == mlx4_master_func_num(dev)) in mlx4_setup_hca()
2867 if (mlx4_is_mfunc(dev)) in mlx4_setup_hca()
2868 dev->caps.port_ib_mtu[port] = IB_MTU_2048; in mlx4_setup_hca()
2870 dev->caps.port_ib_mtu[port] = IB_MTU_4096; in mlx4_setup_hca()
2872 err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ? in mlx4_setup_hca()
2873 dev->caps.pkey_table_len[port] : -1); in mlx4_setup_hca()
2875 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_setup_hca()
2885 mlx4_cleanup_default_counters(dev); in mlx4_setup_hca()
2888 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2889 mlx4_cleanup_counters_table(dev); in mlx4_setup_hca()
2892 mlx4_cleanup_qp_table(dev); in mlx4_setup_hca()
2895 mlx4_cleanup_srq_table(dev); in mlx4_setup_hca()
2898 mlx4_cleanup_cq_table(dev); in mlx4_setup_hca()
2901 mlx4_cmd_use_polling(dev); in mlx4_setup_hca()
2904 mlx4_cleanup_eq_table(dev); in mlx4_setup_hca()
2907 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2908 mlx4_cleanup_mcg_table(dev); in mlx4_setup_hca()
2911 mlx4_cleanup_mr_table(dev); in mlx4_setup_hca()
2914 mlx4_cleanup_xrcd_table(dev); in mlx4_setup_hca()
2917 mlx4_cleanup_pd_table(dev); in mlx4_setup_hca()
2923 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_setup_hca()
2926 mlx4_cleanup_uar_table(dev); in mlx4_setup_hca()
2930 static int mlx4_init_affinity_hint(struct mlx4_dev *dev, int port, int eqn) in mlx4_init_affinity_hint() argument
2933 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_affinity_hint()
2938 if (eqn > dev->caps.num_comp_vectors) in mlx4_init_affinity_hint()
2942 off += mlx4_get_eqs_per_port(dev, i); in mlx4_init_affinity_hint()
2960 static void mlx4_enable_msi_x(struct mlx4_dev *dev) in mlx4_enable_msi_x() argument
2962 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_enable_msi_x()
2968 int nreq = min3(dev->caps.num_ports * in mlx4_enable_msi_x()
2970 dev->caps.num_eqs - dev->caps.reserved_eqs, in mlx4_enable_msi_x()
2983 nreq = pci_enable_msix_range(dev->persist->pdev, entries, 2, in mlx4_enable_msi_x()
2991 dev->caps.num_comp_vectors = nreq - 1; in mlx4_enable_msi_x()
2995 dev->caps.num_ports); in mlx4_enable_msi_x()
2997 for (i = 0; i < dev->caps.num_comp_vectors + 1; i++) { in mlx4_enable_msi_x()
3004 if (MLX4_IS_LEGACY_EQ_MODE(dev->caps)) { in mlx4_enable_msi_x()
3006 dev->caps.num_ports); in mlx4_enable_msi_x()
3013 if (mlx4_init_affinity_hint(dev, port + 1, i)) in mlx4_enable_msi_x()
3014 mlx4_warn(dev, "Couldn't init hint cpumask for EQ %d\n", in mlx4_enable_msi_x()
3026 if ((dev->caps.num_comp_vectors > dev->caps.num_ports) && in mlx4_enable_msi_x()
3028 (dev->caps.num_comp_vectors / dev->caps.num_ports)) == in mlx4_enable_msi_x()
3036 dev->flags |= MLX4_FLAG_MSI_X; in mlx4_enable_msi_x()
3043 dev->caps.num_comp_vectors = 1; in mlx4_enable_msi_x()
3047 priv->eq_table.eq[i].irq = dev->persist->pdev->irq; in mlx4_enable_msi_x()
3050 dev->caps.num_ports); in mlx4_enable_msi_x()
3084 static int mlx4_init_port_info(struct mlx4_dev *dev, int port) in mlx4_init_port_info() argument
3086 struct devlink *devlink = priv_to_devlink(mlx4_priv(dev)); in mlx4_init_port_info()
3087 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; in mlx4_init_port_info()
3100 dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) in mlx4_init_port_info()
3103 dev->caps.port_type[port] == MLX4_PORT_TYPE_IB) in mlx4_init_port_info()
3106 info->dev = dev; in mlx4_init_port_info()
3108 if (!mlx4_is_slave(dev)) { in mlx4_init_port_info()
3109 mlx4_init_mac_table(dev, &info->mac_table); in mlx4_init_port_info()
3110 mlx4_init_vlan_table(dev, &info->vlan_table); in mlx4_init_port_info()
3111 mlx4_init_roce_gid_table(dev, &info->gid_table); in mlx4_init_port_info()
3112 info->base_qpn = mlx4_get_base_qpn(dev, port); in mlx4_init_port_info()
3117 if (mlx4_is_mfunc(dev)) { in mlx4_init_port_info()
3126 err = device_create_file(&dev->persist->pdev->dev, &info->port_attr); in mlx4_init_port_info()
3128 mlx4_err(dev, "Failed to create file for port %d\n", port); in mlx4_init_port_info()
3137 if (mlx4_is_mfunc(dev)) { in mlx4_init_port_info()
3146 err = device_create_file(&dev->persist->pdev->dev, in mlx4_init_port_info()
3149 mlx4_err(dev, "Failed to create mtu file for port %d\n", port); in mlx4_init_port_info()
3150 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_init_port_info()
3166 device_remove_file(&info->dev->persist->pdev->dev, &info->port_attr); in mlx4_cleanup_port_info()
3167 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_cleanup_port_info()
3178 static int mlx4_init_steering(struct mlx4_dev *dev) in mlx4_init_steering() argument
3180 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_steering()
3181 int num_entries = dev->caps.num_ports; in mlx4_init_steering()
3197 static void mlx4_clear_steering(struct mlx4_dev *dev) in mlx4_clear_steering() argument
3199 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clear_steering()
3202 int num_entries = dev->caps.num_ports; in mlx4_clear_steering()
3238 static int mlx4_get_ownership(struct mlx4_dev *dev) in mlx4_get_ownership() argument
3243 if (pci_channel_offline(dev->persist->pdev)) in mlx4_get_ownership()
3246 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_get_ownership()
3250 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_get_ownership()
3259 static void mlx4_free_ownership(struct mlx4_dev *dev) in mlx4_free_ownership() argument
3263 if (pci_channel_offline(dev->persist->pdev)) in mlx4_free_ownership()
3266 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_free_ownership()
3270 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_free_ownership()
3281 static u64 mlx4_enable_sriov(struct mlx4_dev *dev, struct pci_dev *pdev, in mlx4_enable_sriov() argument
3284 u64 dev_flags = dev->flags; in mlx4_enable_sriov()
3290 dev->dev_vfs = kcalloc(total_vfs, sizeof(*dev->dev_vfs), in mlx4_enable_sriov()
3292 if (!dev->dev_vfs) in mlx4_enable_sriov()
3298 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_enable_sriov()
3300 … mlx4_err(dev, "SR-IOV was already enabled, but with num_vfs (%d) different than requested (%d)\n", in mlx4_enable_sriov()
3306 dev->dev_vfs = kcalloc(total_vfs, sizeof(*dev->dev_vfs), GFP_KERNEL); in mlx4_enable_sriov()
3307 if (NULL == dev->dev_vfs) { in mlx4_enable_sriov()
3308 mlx4_err(dev, "Failed to allocate memory for VFs\n"); in mlx4_enable_sriov()
3312 if (!(dev->flags & MLX4_FLAG_SRIOV)) { in mlx4_enable_sriov()
3314 mlx4_err(dev, "requested vfs (%d) > available vfs (%d). Continuing without SR_IOV\n", in mlx4_enable_sriov()
3319 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", total_vfs); in mlx4_enable_sriov()
3323 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d)\n", in mlx4_enable_sriov()
3327 mlx4_warn(dev, "Running in master mode\n"); in mlx4_enable_sriov()
3331 dev->persist->num_vfs = total_vfs; in mlx4_enable_sriov()
3338 dev->persist->num_vfs = 0; in mlx4_enable_sriov()
3339 kfree(dev->dev_vfs); in mlx4_enable_sriov()
3340 dev->dev_vfs = NULL; in mlx4_enable_sriov()
3348 static int mlx4_check_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_check_dev_cap() argument
3355 mlx4_err(dev, "Requested %d VFs, but FW does not support more than 64\n", in mlx4_check_dev_cap()
3362 static int mlx4_pci_enable_device(struct mlx4_dev *dev) in mlx4_pci_enable_device() argument
3364 struct pci_dev *pdev = dev->persist->pdev; in mlx4_pci_enable_device()
3367 mutex_lock(&dev->persist->pci_status_mutex); in mlx4_pci_enable_device()
3368 if (dev->persist->pci_status == MLX4_PCI_STATUS_DISABLED) { in mlx4_pci_enable_device()
3371 dev->persist->pci_status = MLX4_PCI_STATUS_ENABLED; in mlx4_pci_enable_device()
3373 mutex_unlock(&dev->persist->pci_status_mutex); in mlx4_pci_enable_device()
3378 static void mlx4_pci_disable_device(struct mlx4_dev *dev) in mlx4_pci_disable_device() argument
3380 struct pci_dev *pdev = dev->persist->pdev; in mlx4_pci_disable_device()
3382 mutex_lock(&dev->persist->pci_status_mutex); in mlx4_pci_disable_device()
3383 if (dev->persist->pci_status == MLX4_PCI_STATUS_ENABLED) { in mlx4_pci_disable_device()
3385 dev->persist->pci_status = MLX4_PCI_STATUS_DISABLED; in mlx4_pci_disable_device()
3387 mutex_unlock(&dev->persist->pci_status_mutex); in mlx4_pci_disable_device()
3395 struct mlx4_dev *dev; in mlx4_load_one() local
3404 dev = &priv->dev; in mlx4_load_one()
3406 err = mlx4_adev_init(dev); in mlx4_load_one()
3422 dev->rev_id = pdev->revision; in mlx4_load_one()
3423 dev->numa_node = dev_to_node(&pdev->dev); in mlx4_load_one()
3427 mlx4_warn(dev, "Detected virtual function - running in slave mode\n"); in mlx4_load_one()
3428 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
3433 err = mlx4_get_ownership(dev); in mlx4_load_one()
3438 mlx4_warn(dev, "Multiple PFs not yet supported - Skipping PF\n"); in mlx4_load_one()
3452 err = mlx4_reset(dev); in mlx4_load_one()
3454 mlx4_err(dev, "Failed to reset HCA, aborting\n"); in mlx4_load_one()
3459 dev->flags = MLX4_FLAG_MASTER; in mlx4_load_one()
3462 dev->flags |= MLX4_FLAG_SRIOV; in mlx4_load_one()
3463 dev->persist->num_vfs = total_vfs; in mlx4_load_one()
3470 dev->persist->state = MLX4_DEVICE_STATE_UP; in mlx4_load_one()
3473 err = mlx4_cmd_init(dev); in mlx4_load_one()
3475 mlx4_err(dev, "Failed to init command interface, aborting\n"); in mlx4_load_one()
3482 if (mlx4_is_mfunc(dev)) { in mlx4_load_one()
3483 if (mlx4_is_master(dev)) { in mlx4_load_one()
3484 dev->num_slaves = MLX4_MAX_NUM_SLAVES; in mlx4_load_one()
3487 dev->num_slaves = 0; in mlx4_load_one()
3488 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3490 mlx4_err(dev, "Failed to init slave mfunc interface, aborting\n"); in mlx4_load_one()
3496 err = mlx4_init_fw(dev); in mlx4_load_one()
3498 mlx4_err(dev, "Failed to init fw, aborting.\n"); in mlx4_load_one()
3502 if (mlx4_is_master(dev)) { in mlx4_load_one()
3512 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
3514 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
3518 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
3522 u64 dev_flags = mlx4_enable_sriov(dev, pdev, in mlx4_load_one()
3527 mlx4_close_fw(dev); in mlx4_load_one()
3528 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3529 dev->flags = dev_flags; in mlx4_load_one()
3530 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
3531 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
3534 err = mlx4_reset(dev); in mlx4_load_one()
3536 mlx4_err(dev, "Failed to reset HCA, aborting.\n"); in mlx4_load_one()
3547 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
3549 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
3553 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
3558 err = mlx4_init_hca(dev); in mlx4_load_one()
3563 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3565 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_load_one()
3568 if (mlx4_is_master(dev) && !reset_flow) in mlx4_load_one()
3570 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3572 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3573 mlx4_free_ownership(dev); in mlx4_load_one()
3574 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
3575 dev->flags &= ~MLX4_FLAG_MASTER; in mlx4_load_one()
3581 if (mlx4_is_master(dev) && (dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) { in mlx4_load_one()
3582 u64 dev_flags = mlx4_enable_sriov(dev, pdev, total_vfs, in mlx4_load_one()
3585 if ((dev->flags ^ dev_flags) & (MLX4_FLAG_MASTER | MLX4_FLAG_SLAVE)) { in mlx4_load_one()
3586 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_VHCR); in mlx4_load_one()
3587 dev->flags = dev_flags; in mlx4_load_one()
3588 err = mlx4_cmd_init(dev); in mlx4_load_one()
3593 mlx4_err(dev, "Failed to init VHCR command interface, aborting\n"); in mlx4_load_one()
3597 dev->flags = dev_flags; in mlx4_load_one()
3600 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
3601 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
3611 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3612 pcie_print_link_status(dev->persist->pdev); in mlx4_load_one()
3616 if (mlx4_is_master(dev)) { in mlx4_load_one()
3617 if (dev->caps.num_ports < 2 && in mlx4_load_one()
3620 mlx4_err(dev, in mlx4_load_one()
3622 dev->caps.num_ports); in mlx4_load_one()
3625 memcpy(dev->persist->nvfs, nvfs, sizeof(dev->persist->nvfs)); in mlx4_load_one()
3628 i < sizeof(dev->persist->nvfs)/ in mlx4_load_one()
3629 sizeof(dev->persist->nvfs[0]); i++) { in mlx4_load_one()
3632 for (j = 0; j < dev->persist->nvfs[i]; ++sum, ++j) { in mlx4_load_one()
3633 dev->dev_vfs[sum].min_port = i < 2 ? i + 1 : 1; in mlx4_load_one()
3634 dev->dev_vfs[sum].n_ports = i < 2 ? 1 : in mlx4_load_one()
3635 dev->caps.num_ports; in mlx4_load_one()
3642 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3644 mlx4_err(dev, "Failed to init master mfunc interface, aborting.\n"); in mlx4_load_one()
3649 err = mlx4_alloc_eq_table(dev); in mlx4_load_one()
3656 mlx4_enable_msi_x(dev); in mlx4_load_one()
3657 if ((mlx4_is_mfunc(dev)) && in mlx4_load_one()
3658 !(dev->flags & MLX4_FLAG_MSI_X)) { in mlx4_load_one()
3660 mlx4_err(dev, "INTx is not supported in multi-function mode, aborting\n"); in mlx4_load_one()
3664 if (!mlx4_is_slave(dev)) { in mlx4_load_one()
3665 err = mlx4_init_steering(dev); in mlx4_load_one()
3670 mlx4_init_quotas(dev); in mlx4_load_one()
3672 err = mlx4_setup_hca(dev); in mlx4_load_one()
3673 if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) && in mlx4_load_one()
3674 !mlx4_is_mfunc(dev)) { in mlx4_load_one()
3675 dev->flags &= ~MLX4_FLAG_MSI_X; in mlx4_load_one()
3676 dev->caps.num_comp_vectors = 1; in mlx4_load_one()
3678 err = mlx4_setup_hca(dev); in mlx4_load_one()
3687 if (mlx4_is_master(dev)) { in mlx4_load_one()
3688 err = mlx4_ARM_COMM_CHANNEL(dev); in mlx4_load_one()
3690 mlx4_err(dev, " Failed to arm comm channel eq: %x\n", in mlx4_load_one()
3696 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_load_one()
3697 err = mlx4_init_port_info(dev, port); in mlx4_load_one()
3705 err = mlx4_register_device(dev); in mlx4_load_one()
3709 mlx4_sense_init(dev); in mlx4_load_one()
3710 mlx4_start_sense(dev); in mlx4_load_one()
3714 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3724 mlx4_cleanup_default_counters(dev); in mlx4_load_one()
3725 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3726 mlx4_cleanup_counters_table(dev); in mlx4_load_one()
3727 mlx4_cleanup_qp_table(dev); in mlx4_load_one()
3728 mlx4_cleanup_srq_table(dev); in mlx4_load_one()
3729 mlx4_cleanup_cq_table(dev); in mlx4_load_one()
3730 mlx4_cmd_use_polling(dev); in mlx4_load_one()
3731 mlx4_cleanup_eq_table(dev); in mlx4_load_one()
3732 mlx4_cleanup_mcg_table(dev); in mlx4_load_one()
3733 mlx4_cleanup_mr_table(dev); in mlx4_load_one()
3734 mlx4_cleanup_xrcd_table(dev); in mlx4_load_one()
3735 mlx4_cleanup_pd_table(dev); in mlx4_load_one()
3736 mlx4_cleanup_uar_table(dev); in mlx4_load_one()
3739 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3740 mlx4_clear_steering(dev); in mlx4_load_one()
3743 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_load_one()
3747 mlx4_free_eq_table(dev); in mlx4_load_one()
3750 if (mlx4_is_master(dev)) { in mlx4_load_one()
3751 mlx4_free_resource_tracker(dev, RES_TR_FREE_STRUCTS_ONLY); in mlx4_load_one()
3752 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3755 if (mlx4_is_slave(dev)) in mlx4_load_one()
3756 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_load_one()
3759 mlx4_close_hca(dev); in mlx4_load_one()
3762 mlx4_close_fw(dev); in mlx4_load_one()
3765 if (mlx4_is_slave(dev)) in mlx4_load_one()
3766 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3769 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3772 if (dev->flags & MLX4_FLAG_SRIOV && !existing_vfs) { in mlx4_load_one()
3774 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3777 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3780 kfree(priv->dev.dev_vfs); in mlx4_load_one()
3782 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3783 mlx4_free_ownership(dev); in mlx4_load_one()
3788 mlx4_adev_cleanup(dev); in mlx4_load_one()
3805 err = mlx4_pci_enable_device(&priv->dev); in __mlx4_init_one()
3807 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); in __mlx4_init_one()
3819 dev_err(&pdev->dev, "num_vfs module parameter cannot be negative\n"); in __mlx4_init_one()
3828 dev_err(&pdev->dev, "probe_vf module parameter cannot be negative or greater than num_vfs\n"); in __mlx4_init_one()
3834 dev_err(&pdev->dev, in __mlx4_init_one()
3843 dev_err(&pdev->dev, in __mlx4_init_one()
3855 …dev_err(&pdev->dev, "Missing DCS, aborting (driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\… in __mlx4_init_one()
3861 dev_err(&pdev->dev, "Missing UAR, aborting\n"); in __mlx4_init_one()
3868 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n"); in __mlx4_init_one()
3874 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in __mlx4_init_one()
3876 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); in __mlx4_init_one()
3877 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); in __mlx4_init_one()
3879 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); in __mlx4_init_one()
3885 dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024); in __mlx4_init_one()
3904 dev_warn(&pdev->dev, "Skipping virtual function:%d\n", in __mlx4_init_one()
3912 err = mlx4_crdump_init(&priv->dev); in __mlx4_init_one()
3916 err = mlx4_catas_init(&priv->dev); in __mlx4_init_one()
3927 mlx4_catas_end(&priv->dev); in __mlx4_init_one()
3930 mlx4_crdump_end(&priv->dev); in __mlx4_init_one()
3936 mlx4_pci_disable_device(&priv->dev); in __mlx4_init_one()
3943 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_param_load_driverinit_values() local
3944 struct mlx4_fw_crdump *crdump = &dev->persist->crdump; in mlx4_devlink_param_load_driverinit_values()
3992 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_reload_down() local
3993 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_devlink_reload_down()
4000 …mlx4_warn(persist->dev, "Reload performed on PF, will cause reset on operating Virtual Functions\n… in mlx4_devlink_reload_down()
4010 struct mlx4_dev *dev = &priv->dev; in mlx4_devlink_reload_up() local
4011 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_devlink_reload_up()
4017 mlx4_err(persist->dev, "mlx4_restart_one_up failed, ret=%d\n", in mlx4_devlink_reload_up()
4033 struct mlx4_dev *dev; in mlx4_init_one() local
4038 devlink = devlink_alloc(&mlx4_devlink_ops, sizeof(*priv), &pdev->dev); in mlx4_init_one()
4044 dev = &priv->dev; in mlx4_init_one()
4045 dev->persist = kzalloc(sizeof(*dev->persist), GFP_KERNEL); in mlx4_init_one()
4046 if (!dev->persist) { in mlx4_init_one()
4050 dev->persist->pdev = pdev; in mlx4_init_one()
4051 dev->persist->dev = dev; in mlx4_init_one()
4052 pci_set_drvdata(pdev, dev->persist); in mlx4_init_one()
4054 mutex_init(&dev->persist->device_state_mutex); in mlx4_init_one()
4055 mutex_init(&dev->persist->interface_state_mutex); in mlx4_init_one()
4056 mutex_init(&dev->persist->pci_status_mutex); in mlx4_init_one()
4076 kfree(dev->persist); in mlx4_init_one()
4083 static void mlx4_clean_dev(struct mlx4_dev *dev) in mlx4_clean_dev() argument
4085 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_clean_dev()
4086 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clean_dev()
4087 unsigned long flags = (dev->flags & RESET_PERSIST_MASK_FLAGS); in mlx4_clean_dev()
4090 priv->dev.persist = persist; in mlx4_clean_dev()
4091 priv->dev.flags = flags; in mlx4_clean_dev()
4097 struct mlx4_dev *dev = persist->dev; in mlx4_unload_one() local
4098 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unload_one()
4109 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_unload_one()
4110 dev->persist->curr_port_type[i] = dev->caps.port_type[i + 1]; in mlx4_unload_one()
4111 dev->persist->curr_port_poss_type[i] = dev->caps. in mlx4_unload_one()
4117 mlx4_stop_sense(dev); in mlx4_unload_one()
4118 mlx4_unregister_device(dev); in mlx4_unload_one()
4120 for (p = 1; p <= dev->caps.num_ports; p++) { in mlx4_unload_one()
4122 mlx4_CLOSE_PORT(dev, p); in mlx4_unload_one()
4125 if (mlx4_is_master(dev)) in mlx4_unload_one()
4126 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
4129 mlx4_cleanup_default_counters(dev); in mlx4_unload_one()
4130 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
4131 mlx4_cleanup_counters_table(dev); in mlx4_unload_one()
4132 mlx4_cleanup_qp_table(dev); in mlx4_unload_one()
4133 mlx4_cleanup_srq_table(dev); in mlx4_unload_one()
4134 mlx4_cleanup_cq_table(dev); in mlx4_unload_one()
4135 mlx4_cmd_use_polling(dev); in mlx4_unload_one()
4136 mlx4_cleanup_eq_table(dev); in mlx4_unload_one()
4137 mlx4_cleanup_mcg_table(dev); in mlx4_unload_one()
4138 mlx4_cleanup_mr_table(dev); in mlx4_unload_one()
4139 mlx4_cleanup_xrcd_table(dev); in mlx4_unload_one()
4140 mlx4_cleanup_pd_table(dev); in mlx4_unload_one()
4142 if (mlx4_is_master(dev)) in mlx4_unload_one()
4143 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
4147 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_unload_one()
4148 mlx4_cleanup_uar_table(dev); in mlx4_unload_one()
4149 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
4150 mlx4_clear_steering(dev); in mlx4_unload_one()
4151 mlx4_free_eq_table(dev); in mlx4_unload_one()
4152 if (mlx4_is_master(dev)) in mlx4_unload_one()
4153 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
4154 mlx4_close_hca(dev); in mlx4_unload_one()
4155 mlx4_close_fw(dev); in mlx4_unload_one()
4156 if (mlx4_is_slave(dev)) in mlx4_unload_one()
4157 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
4158 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_unload_one()
4160 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_unload_one()
4163 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
4164 mlx4_free_ownership(dev); in mlx4_unload_one()
4166 mlx4_slave_destroy_special_qp_cap(dev); in mlx4_unload_one()
4167 kfree(dev->dev_vfs); in mlx4_unload_one()
4169 mlx4_adev_cleanup(dev); in mlx4_unload_one()
4171 mlx4_clean_dev(dev); in mlx4_unload_one()
4179 struct mlx4_dev *dev = persist->dev; in mlx4_remove_one() local
4180 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_remove_one()
4187 if (mlx4_is_slave(dev)) in mlx4_remove_one()
4195 if (mlx4_is_master(dev) && dev->flags & MLX4_FLAG_SRIOV) { in mlx4_remove_one()
4196 active_vfs = mlx4_how_many_lives_vf(dev); in mlx4_remove_one()
4209 mlx4_info(dev, "%s: interface is down\n", __func__); in mlx4_remove_one()
4210 mlx4_catas_end(dev); in mlx4_remove_one()
4211 mlx4_crdump_end(dev); in mlx4_remove_one()
4212 if (dev->flags & MLX4_FLAG_SRIOV && !active_vfs) { in mlx4_remove_one()
4213 mlx4_warn(dev, "Disabling SR-IOV\n"); in mlx4_remove_one()
4218 mlx4_pci_disable_device(dev); in mlx4_remove_one()
4221 kfree(dev->persist); in mlx4_remove_one()
4226 static int restore_current_port_types(struct mlx4_dev *dev, in restore_current_port_types() argument
4230 struct mlx4_priv *priv = mlx4_priv(dev); in restore_current_port_types()
4233 mlx4_stop_sense(dev); in restore_current_port_types()
4236 for (i = 0; i < dev->caps.num_ports; i++) in restore_current_port_types()
4237 dev->caps.possible_type[i + 1] = poss_types[i]; in restore_current_port_types()
4238 err = mlx4_change_port_types(dev, types); in restore_current_port_types()
4239 mlx4_start_sense(dev); in restore_current_port_types()
4254 struct mlx4_dev *dev = persist->dev; in mlx4_restart_one_up() local
4255 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_restart_one_up()
4260 total_vfs = dev->persist->num_vfs; in mlx4_restart_one_up()
4261 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_restart_one_up()
4267 mlx4_err(dev, "%s: ERROR: mlx4_load_one failed, pci_name=%s, err=%d\n", in mlx4_restart_one_up()
4272 err = restore_current_port_types(dev, dev->persist->curr_port_type, in mlx4_restart_one_up()
4273 dev->persist->curr_port_poss_type); in mlx4_restart_one_up()
4275 mlx4_err(dev, "could not restore original port types (%d)\n", in mlx4_restart_one_up()
4343 struct mlx4_dev *dev = persist->dev; in mlx4_pci_err_detected() local
4346 mlx4_err(persist->dev, "mlx4_pci_err_detected was called\n"); in mlx4_pci_err_detected()
4349 devlink = priv_to_devlink(mlx4_priv(dev)); in mlx4_pci_err_detected()
4360 mlx4_pci_disable_device(persist->dev); in mlx4_pci_err_detected()
4367 struct mlx4_dev *dev = persist->dev; in mlx4_pci_slot_reset() local
4370 mlx4_err(dev, "mlx4_pci_slot_reset was called\n"); in mlx4_pci_slot_reset()
4371 err = mlx4_pci_enable_device(dev); in mlx4_pci_slot_reset()
4373 mlx4_err(dev, "Can not re-enable device, err=%d\n", err); in mlx4_pci_slot_reset()
4386 struct mlx4_dev *dev = persist->dev; in mlx4_pci_resume() local
4387 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_pci_resume()
4393 mlx4_err(dev, "%s was called\n", __func__); in mlx4_pci_resume()
4394 total_vfs = dev->persist->num_vfs; in mlx4_pci_resume()
4395 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_pci_resume()
4404 mlx4_err(dev, "%s: mlx4_load_one failed, err=%d\n", in mlx4_pci_resume()
4409 err = restore_current_port_types(dev, dev->persist-> in mlx4_pci_resume()
4410 curr_port_type, dev->persist-> in mlx4_pci_resume()
4413 mlx4_err(dev, "could not restore original port types (%d)\n", err); in mlx4_pci_resume()
4423 struct mlx4_dev *dev = persist->dev; in mlx4_shutdown() local
4426 mlx4_info(persist->dev, "mlx4_shutdown was called\n"); in mlx4_shutdown()
4427 devlink = priv_to_devlink(mlx4_priv(dev)); in mlx4_shutdown()
4434 mlx4_pci_disable_device(dev); in mlx4_shutdown()
4447 struct mlx4_dev *dev = persist->dev; in mlx4_suspend() local
4450 mlx4_err(dev, "suspend was called\n"); in mlx4_suspend()
4451 devlink = priv_to_devlink(mlx4_priv(dev)); in mlx4_suspend()
4466 struct mlx4_dev *dev = persist->dev; in mlx4_resume() local
4467 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_resume()
4473 mlx4_err(dev, "resume was called\n"); in mlx4_resume()
4474 total_vfs = dev->persist->num_vfs; in mlx4_resume()
4475 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_resume()
4484 ret = restore_current_port_types(dev, in mlx4_resume()
4485 dev->persist->curr_port_type, in mlx4_resume()
4486 dev->persist->curr_port_poss_type); in mlx4_resume()
4488 mlx4_err(dev, "resume: could not restore original port types (%d)\n", ret); in mlx4_resume()