Lines Matching refs:dev
171 int mlx4_check_port_params(struct mlx4_dev *dev, in mlx4_check_port_params() argument
176 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP)) { in mlx4_check_port_params()
177 for (i = 0; i < dev->caps.num_ports - 1; i++) { in mlx4_check_port_params()
179 mlx4_err(dev, "Only same port types supported on this HCA, aborting\n"); in mlx4_check_port_params()
185 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_check_port_params()
186 if (!(port_type[i] & dev->caps.supported_type[i+1])) { in mlx4_check_port_params()
187 mlx4_err(dev, "Requested port type for port %d is not supported on this HCA\n", in mlx4_check_port_params()
195 static void mlx4_set_port_mask(struct mlx4_dev *dev) in mlx4_set_port_mask() argument
199 for (i = 1; i <= dev->caps.num_ports; ++i) in mlx4_set_port_mask()
200 dev->caps.port_mask[i] = dev->caps.port_type[i]; in mlx4_set_port_mask()
207 static int mlx4_query_func(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_query_func() argument
212 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS) { in mlx4_query_func()
213 err = mlx4_QUERY_FUNC(dev, &func, 0); in mlx4_query_func()
215 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_query_func()
226 static void mlx4_enable_cqe_eqe_stride(struct mlx4_dev *dev) in mlx4_enable_cqe_eqe_stride() argument
228 struct mlx4_caps *dev_cap = &dev->caps; in mlx4_enable_cqe_eqe_stride()
246 mlx4_dbg(dev, "Enabling CQE stride cacheLine supported\n"); in mlx4_enable_cqe_eqe_stride()
251 if (mlx4_is_master(dev)) in mlx4_enable_cqe_eqe_stride()
255 mlx4_dbg(dev, "Disabling CQE stride, cacheLine size unsupported\n"); in mlx4_enable_cqe_eqe_stride()
261 static int _mlx4_dev_port(struct mlx4_dev *dev, int port, in _mlx4_dev_port() argument
264 dev->caps.vl_cap[port] = port_cap->max_vl; in _mlx4_dev_port()
265 dev->caps.ib_mtu_cap[port] = port_cap->ib_mtu; in _mlx4_dev_port()
266 dev->phys_caps.gid_phys_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
267 dev->phys_caps.pkey_phys_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
271 dev->caps.gid_table_len[port] = port_cap->max_gids; in _mlx4_dev_port()
272 dev->caps.pkey_table_len[port] = port_cap->max_pkeys; in _mlx4_dev_port()
273 dev->caps.port_width_cap[port] = port_cap->max_port_width; in _mlx4_dev_port()
274 dev->caps.eth_mtu_cap[port] = port_cap->eth_mtu; in _mlx4_dev_port()
275 dev->caps.def_mac[port] = port_cap->def_mac; in _mlx4_dev_port()
276 dev->caps.supported_type[port] = port_cap->supported_port_types; in _mlx4_dev_port()
277 dev->caps.suggested_type[port] = port_cap->suggested_type; in _mlx4_dev_port()
278 dev->caps.default_sense[port] = port_cap->default_sense; in _mlx4_dev_port()
279 dev->caps.trans_type[port] = port_cap->trans_type; in _mlx4_dev_port()
280 dev->caps.vendor_oui[port] = port_cap->vendor_oui; in _mlx4_dev_port()
281 dev->caps.wavelength[port] = port_cap->wavelength; in _mlx4_dev_port()
282 dev->caps.trans_code[port] = port_cap->trans_code; in _mlx4_dev_port()
287 static int mlx4_dev_port(struct mlx4_dev *dev, int port, in mlx4_dev_port() argument
292 err = mlx4_QUERY_PORT(dev, port, port_cap); in mlx4_dev_port()
295 mlx4_err(dev, "QUERY_PORT command failed.\n"); in mlx4_dev_port()
300 static inline void mlx4_enable_ignore_fcs(struct mlx4_dev *dev) in mlx4_enable_ignore_fcs() argument
302 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_IGNORE_FCS)) in mlx4_enable_ignore_fcs()
305 if (mlx4_is_mfunc(dev)) { in mlx4_enable_ignore_fcs()
306 mlx4_dbg(dev, "SRIOV mode - Disabling Ignore FCS"); in mlx4_enable_ignore_fcs()
307 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
311 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_FCS_KEEP)) { in mlx4_enable_ignore_fcs()
312 mlx4_dbg(dev, in mlx4_enable_ignore_fcs()
314 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_IGNORE_FCS; in mlx4_enable_ignore_fcs()
320 static int mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap) in mlx4_dev_cap() argument
325 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_dev_cap()
327 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_dev_cap()
330 mlx4_dev_cap_dump(dev, dev_cap); in mlx4_dev_cap()
333 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_dev_cap()
338 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_dev_cap()
343 if (dev_cap->uar_size > pci_resource_len(dev->persist->pdev, 2)) { in mlx4_dev_cap()
344 …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()
347 pci_resource_len(dev->persist->pdev, 2)); in mlx4_dev_cap()
351 dev->caps.num_ports = dev_cap->num_ports; in mlx4_dev_cap()
352 dev->caps.num_sys_eqs = dev_cap->num_sys_eqs; in mlx4_dev_cap()
353 dev->phys_caps.num_phys_eqs = dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS ? in mlx4_dev_cap()
354 dev->caps.num_sys_eqs : in mlx4_dev_cap()
356 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
357 err = _mlx4_dev_port(dev, i, dev_cap->port_cap + i); in mlx4_dev_cap()
359 mlx4_err(dev, "QUERY_PORT command failed, aborting\n"); in mlx4_dev_cap()
364 dev->caps.uar_page_size = PAGE_SIZE; in mlx4_dev_cap()
365 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE; in mlx4_dev_cap()
366 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay; in mlx4_dev_cap()
367 dev->caps.bf_reg_size = dev_cap->bf_reg_size; in mlx4_dev_cap()
368 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page; in mlx4_dev_cap()
369 dev->caps.max_sq_sg = dev_cap->max_sq_sg; in mlx4_dev_cap()
370 dev->caps.max_rq_sg = dev_cap->max_rq_sg; in mlx4_dev_cap()
371 dev->caps.max_wqes = dev_cap->max_qp_sz; in mlx4_dev_cap()
372 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp; in mlx4_dev_cap()
373 dev->caps.max_srq_wqes = dev_cap->max_srq_sz; in mlx4_dev_cap()
374 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1; in mlx4_dev_cap()
375 dev->caps.reserved_srqs = dev_cap->reserved_srqs; in mlx4_dev_cap()
376 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz; in mlx4_dev_cap()
377 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz; in mlx4_dev_cap()
383 dev->caps.max_cqes = dev_cap->max_cq_sz - 1; in mlx4_dev_cap()
384 dev->caps.reserved_cqs = dev_cap->reserved_cqs; in mlx4_dev_cap()
385 dev->caps.reserved_eqs = dev_cap->reserved_eqs; in mlx4_dev_cap()
386 dev->caps.reserved_mtts = dev_cap->reserved_mtts; in mlx4_dev_cap()
387 dev->caps.reserved_mrws = dev_cap->reserved_mrws; in mlx4_dev_cap()
390 dev->caps.reserved_uars = max_t(int, 128, dev_cap->reserved_uars); in mlx4_dev_cap()
391 dev->caps.reserved_pds = dev_cap->reserved_pds; in mlx4_dev_cap()
392 dev->caps.reserved_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
394 dev->caps.max_xrcds = (dev->caps.flags & MLX4_DEV_CAP_FLAG_XRC) ? in mlx4_dev_cap()
396 dev->caps.mtt_entry_sz = dev_cap->mtt_entry_sz; in mlx4_dev_cap()
398 dev->caps.max_msg_sz = dev_cap->max_msg_sz; in mlx4_dev_cap()
399 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1); in mlx4_dev_cap()
400 dev->caps.flags = dev_cap->flags; in mlx4_dev_cap()
401 dev->caps.flags2 = dev_cap->flags2; in mlx4_dev_cap()
402 dev->caps.bmme_flags = dev_cap->bmme_flags; in mlx4_dev_cap()
403 dev->caps.reserved_lkey = dev_cap->reserved_lkey; in mlx4_dev_cap()
404 dev->caps.stat_rate_support = dev_cap->stat_rate_support; in mlx4_dev_cap()
405 dev->caps.max_gso_sz = dev_cap->max_gso_sz; in mlx4_dev_cap()
406 dev->caps.max_rss_tbl_sz = dev_cap->max_rss_tbl_sz; in mlx4_dev_cap()
409 if (mlx4_priv(dev)->pci_dev_data & MLX4_PCI_DEV_FORCE_SENSE_PORT) in mlx4_dev_cap()
410 dev->caps.flags |= MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
412 if (mlx4_is_mfunc(dev)) in mlx4_dev_cap()
413 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_SENSE_SUPPORT; in mlx4_dev_cap()
416 dev->caps.log_num_macs = MLX4_MIN_LOG_NUM_MAC; in mlx4_dev_cap()
417 dev->caps.log_num_vlans = MLX4_MIN_LOG_NUM_VLANS; in mlx4_dev_cap()
419 dev->caps.log_num_macs = log_num_mac; in mlx4_dev_cap()
420 dev->caps.log_num_vlans = MLX4_LOG_NUM_VLANS; in mlx4_dev_cap()
423 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_dev_cap()
424 dev->caps.port_type[i] = MLX4_PORT_TYPE_NONE; in mlx4_dev_cap()
425 if (dev->caps.supported_type[i]) { in mlx4_dev_cap()
427 if (dev->caps.supported_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_dev_cap()
428 dev->caps.port_type[i] = MLX4_PORT_TYPE_ETH; in mlx4_dev_cap()
430 else if (dev->caps.supported_type[i] == in mlx4_dev_cap()
432 dev->caps.port_type[i] = MLX4_PORT_TYPE_IB; in mlx4_dev_cap()
438 dev->caps.port_type[i] = dev->caps.suggested_type[i] ? in mlx4_dev_cap()
441 dev->caps.port_type[i] = port_type_array[i - 1]; in mlx4_dev_cap()
450 mlx4_priv(dev)->sense.sense_allowed[i] = in mlx4_dev_cap()
451 ((dev->caps.supported_type[i] == MLX4_PORT_TYPE_AUTO) && in mlx4_dev_cap()
452 (dev->caps.flags & MLX4_DEV_CAP_FLAG_DPDP) && in mlx4_dev_cap()
453 (dev->caps.flags & MLX4_DEV_CAP_FLAG_SENSE_SUPPORT)); in mlx4_dev_cap()
460 if (mlx4_priv(dev)->sense.sense_allowed[i] && dev->caps.default_sense[i]) { in mlx4_dev_cap()
462 dev->caps.possible_type[i] = MLX4_PORT_TYPE_AUTO; in mlx4_dev_cap()
463 mlx4_SENSE_PORT(dev, i, &sensed_port); in mlx4_dev_cap()
465 dev->caps.port_type[i] = sensed_port; in mlx4_dev_cap()
467 dev->caps.possible_type[i] = dev->caps.port_type[i]; in mlx4_dev_cap()
470 if (dev->caps.log_num_macs > dev_cap->port_cap[i].log_max_macs) { in mlx4_dev_cap()
471 dev->caps.log_num_macs = dev_cap->port_cap[i].log_max_macs; in mlx4_dev_cap()
472 mlx4_warn(dev, "Requested number of MACs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
473 i, 1 << dev->caps.log_num_macs); in mlx4_dev_cap()
475 if (dev->caps.log_num_vlans > dev_cap->port_cap[i].log_max_vlans) { in mlx4_dev_cap()
476 dev->caps.log_num_vlans = dev_cap->port_cap[i].log_max_vlans; in mlx4_dev_cap()
477 mlx4_warn(dev, "Requested number of VLANs is too much for port %d, reducing to %d\n", in mlx4_dev_cap()
478 i, 1 << dev->caps.log_num_vlans); in mlx4_dev_cap()
482 dev->caps.max_counters = 1 << ilog2(dev_cap->max_counters); in mlx4_dev_cap()
484 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] = dev_cap->reserved_qps; in mlx4_dev_cap()
485 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] = in mlx4_dev_cap()
486 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] = in mlx4_dev_cap()
487 (1 << dev->caps.log_num_macs) * in mlx4_dev_cap()
488 (1 << dev->caps.log_num_vlans) * in mlx4_dev_cap()
489 dev->caps.num_ports; in mlx4_dev_cap()
490 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH] = MLX4_NUM_FEXCH; in mlx4_dev_cap()
493 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) in mlx4_dev_cap()
494 dev->caps.dmfs_high_rate_qpn_base = dev_cap->dmfs_high_rate_qpn_base; in mlx4_dev_cap()
496 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
497 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
500 dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_FS_EN) { in mlx4_dev_cap()
501 dev->caps.dmfs_high_rate_qpn_range = dev_cap->dmfs_high_rate_qpn_range; in mlx4_dev_cap()
502 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DEFAULT; in mlx4_dev_cap()
503 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_FS_A0; in mlx4_dev_cap()
505 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_NOT_SUPPORTED; in mlx4_dev_cap()
506 dev->caps.dmfs_high_rate_qpn_base = in mlx4_dev_cap()
507 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_dev_cap()
508 dev->caps.dmfs_high_rate_qpn_range = MLX4_A0_STEERING_TABLE_SIZE; in mlx4_dev_cap()
511 dev->caps.rl_caps = dev_cap->rl_caps; in mlx4_dev_cap()
513 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_RSS_RAW_ETH] = in mlx4_dev_cap()
514 dev->caps.dmfs_high_rate_qpn_range; in mlx4_dev_cap()
516 dev->caps.reserved_qps = dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW] + in mlx4_dev_cap()
517 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_ETH_ADDR] + in mlx4_dev_cap()
518 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_ADDR] + in mlx4_dev_cap()
519 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FC_EXCH]; in mlx4_dev_cap()
521 dev->caps.sqp_demux = (mlx4_is_master(dev)) ? MLX4_MAX_NUM_SLAVES : 0; in mlx4_dev_cap()
523 if (!enable_64b_cqe_eqe && !mlx4_is_slave(dev)) { in mlx4_dev_cap()
526 mlx4_warn(dev, "64B EQEs/CQEs supported by the device but not enabled\n"); in mlx4_dev_cap()
527 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_CQE; in mlx4_dev_cap()
528 dev->caps.flags &= ~MLX4_DEV_CAP_FLAG_64B_EQE; in mlx4_dev_cap()
534 mlx4_warn(dev, "Disabling EQE/CQE stride per user request\n"); in mlx4_dev_cap()
540 if ((dev->caps.flags & in mlx4_dev_cap()
542 mlx4_is_master(dev)) in mlx4_dev_cap()
543 dev->caps.function_caps |= MLX4_FUNC_CAP_64B_EQE_CQE; in mlx4_dev_cap()
545 if (!mlx4_is_slave(dev)) { in mlx4_dev_cap()
546 mlx4_enable_cqe_eqe_stride(dev); in mlx4_dev_cap()
547 dev->caps.alloc_res_qp_mask = in mlx4_dev_cap()
548 (dev->caps.bf_reg_size ? MLX4_RESERVE_ETH_BF_QP : 0) | in mlx4_dev_cap()
551 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_ETS_CFG) && in mlx4_dev_cap()
552 dev->caps.flags & MLX4_DEV_CAP_FLAG_SET_ETH_SCHED) { in mlx4_dev_cap()
553 mlx4_warn(dev, "Old device ETS support detected\n"); in mlx4_dev_cap()
554 mlx4_warn(dev, "Consider upgrading device FW.\n"); in mlx4_dev_cap()
555 dev->caps.flags2 |= MLX4_DEV_CAP_FLAG2_ETS_CFG; in mlx4_dev_cap()
559 dev->caps.alloc_res_qp_mask = 0; in mlx4_dev_cap()
562 mlx4_enable_ignore_fcs(dev); in mlx4_dev_cap()
567 static int mlx4_get_pcie_dev_link_caps(struct mlx4_dev *dev, in mlx4_get_pcie_dev_link_caps() argument
579 err1 = pcie_capability_read_dword(dev->persist->pdev, PCI_EXP_LNKCAP, in mlx4_get_pcie_dev_link_caps()
581 err2 = pcie_capability_read_dword(dev->persist->pdev, PCI_EXP_LNKCAP2, in mlx4_get_pcie_dev_link_caps()
608 static void mlx4_check_pcie_caps(struct mlx4_dev *dev) in mlx4_check_pcie_caps() argument
620 err = mlx4_get_pcie_dev_link_caps(dev, &speed_cap, &width_cap); in mlx4_check_pcie_caps()
622 mlx4_warn(dev, in mlx4_check_pcie_caps()
627 err = pcie_get_minimum_link(dev->persist->pdev, &speed, &width); in mlx4_check_pcie_caps()
630 mlx4_warn(dev, in mlx4_check_pcie_caps()
636 mlx4_warn(dev, in mlx4_check_pcie_caps()
639 mlx4_info(dev, "PCIe link speed is %s, device supports %s\n", in mlx4_check_pcie_caps()
641 mlx4_info(dev, "PCIe link width is x%d, device supports x%d\n", in mlx4_check_pcie_caps()
647 static int mlx4_how_many_lives_vf(struct mlx4_dev *dev) in mlx4_how_many_lives_vf() argument
649 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_how_many_lives_vf()
654 for (i = 1/*the ppf is 0*/; i < dev->num_slaves; ++i) { in mlx4_how_many_lives_vf()
658 mlx4_warn(dev, "%s: slave: %d is still active\n", in mlx4_how_many_lives_vf()
666 int mlx4_get_parav_qkey(struct mlx4_dev *dev, u32 qpn, u32 *qkey) in mlx4_get_parav_qkey() argument
670 if (qpn >= dev->phys_caps.base_tunnel_sqpn + 8 * MLX4_MFUNC_MAX || in mlx4_get_parav_qkey()
671 qpn < dev->phys_caps.base_proxy_sqpn) in mlx4_get_parav_qkey()
674 if (qpn >= dev->phys_caps.base_tunnel_sqpn) in mlx4_get_parav_qkey()
676 qk += qpn - dev->phys_caps.base_tunnel_sqpn; in mlx4_get_parav_qkey()
678 qk += qpn - dev->phys_caps.base_proxy_sqpn; in mlx4_get_parav_qkey()
684 void mlx4_sync_pkey_table(struct mlx4_dev *dev, int slave, int port, int i, int val) in mlx4_sync_pkey_table() argument
686 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_sync_pkey_table()
688 if (!mlx4_is_master(dev)) in mlx4_sync_pkey_table()
695 void mlx4_put_slave_node_guid(struct mlx4_dev *dev, int slave, __be64 guid) in mlx4_put_slave_node_guid() argument
697 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_put_slave_node_guid()
699 if (!mlx4_is_master(dev)) in mlx4_put_slave_node_guid()
706 __be64 mlx4_get_slave_node_guid(struct mlx4_dev *dev, int slave) in mlx4_get_slave_node_guid() argument
708 struct mlx4_priv *priv = container_of(dev, struct mlx4_priv, dev); in mlx4_get_slave_node_guid()
710 if (!mlx4_is_master(dev)) in mlx4_get_slave_node_guid()
717 int mlx4_is_slave_active(struct mlx4_dev *dev, int slave) in mlx4_is_slave_active() argument
719 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_is_slave_active()
722 if (!mlx4_is_master(dev)) in mlx4_is_slave_active()
730 static void slave_adjust_steering_mode(struct mlx4_dev *dev, in slave_adjust_steering_mode() argument
734 dev->caps.steering_mode = hca_param->steering_mode; in slave_adjust_steering_mode()
735 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED) { in slave_adjust_steering_mode()
736 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in slave_adjust_steering_mode()
737 dev->caps.fs_log_max_ucast_qp_range_size = in slave_adjust_steering_mode()
740 dev->caps.num_qp_per_mgm = in slave_adjust_steering_mode()
743 mlx4_dbg(dev, "Steering mode is: %s\n", in slave_adjust_steering_mode()
744 mlx4_steering_mode_str(dev->caps.steering_mode)); in slave_adjust_steering_mode()
747 static int mlx4_slave_cap(struct mlx4_dev *dev) in mlx4_slave_cap() argument
757 err = mlx4_QUERY_HCA(dev, &hca_param); in mlx4_slave_cap()
759 mlx4_err(dev, "QUERY_HCA command failed, aborting\n"); in mlx4_slave_cap()
767 mlx4_err(dev, "Unknown hca global capabilities\n"); in mlx4_slave_cap()
773 dev->caps.hca_core_clock = hca_param.hca_core_clock; in mlx4_slave_cap()
776 dev->caps.max_qp_dest_rdma = 1 << hca_param.log_rd_per_qp; in mlx4_slave_cap()
777 err = mlx4_dev_cap(dev, &dev_cap); in mlx4_slave_cap()
779 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_slave_cap()
783 err = mlx4_QUERY_FW(dev); in mlx4_slave_cap()
785 mlx4_err(dev, "QUERY_FW command failed: could not get FW version\n"); in mlx4_slave_cap()
787 page_size = ~dev->caps.page_size_cap + 1; in mlx4_slave_cap()
788 mlx4_warn(dev, "HCA minimum page size:%d\n", page_size); in mlx4_slave_cap()
790 mlx4_err(dev, "HCA minimum page size of %d bigger than kernel PAGE_SIZE of %ld, aborting\n", in mlx4_slave_cap()
796 dev->caps.uar_page_size = 1 << (hca_param.uar_page_sz + 12); in mlx4_slave_cap()
799 if (dev->caps.uar_page_size != PAGE_SIZE) { in mlx4_slave_cap()
800 mlx4_err(dev, "UAR size:%d != kernel PAGE_SIZE of %ld\n", in mlx4_slave_cap()
801 dev->caps.uar_page_size, PAGE_SIZE); in mlx4_slave_cap()
806 err = mlx4_QUERY_FUNC_CAP(dev, 0, &func_cap); in mlx4_slave_cap()
808 mlx4_err(dev, "QUERY_FUNC_CAP general command failed, aborting (%d)\n", in mlx4_slave_cap()
815 mlx4_err(dev, "Unknown pf context behaviour %x known flags %x\n", in mlx4_slave_cap()
820 dev->caps.num_ports = func_cap.num_ports; in mlx4_slave_cap()
821 dev->quotas.qp = func_cap.qp_quota; in mlx4_slave_cap()
822 dev->quotas.srq = func_cap.srq_quota; in mlx4_slave_cap()
823 dev->quotas.cq = func_cap.cq_quota; in mlx4_slave_cap()
824 dev->quotas.mpt = func_cap.mpt_quota; in mlx4_slave_cap()
825 dev->quotas.mtt = func_cap.mtt_quota; in mlx4_slave_cap()
826 dev->caps.num_qps = 1 << hca_param.log_num_qps; in mlx4_slave_cap()
827 dev->caps.num_srqs = 1 << hca_param.log_num_srqs; in mlx4_slave_cap()
828 dev->caps.num_cqs = 1 << hca_param.log_num_cqs; in mlx4_slave_cap()
829 dev->caps.num_mpts = 1 << hca_param.log_mpt_sz; in mlx4_slave_cap()
830 dev->caps.num_eqs = func_cap.max_eq; in mlx4_slave_cap()
831 dev->caps.reserved_eqs = func_cap.reserved_eq; in mlx4_slave_cap()
832 dev->caps.reserved_lkey = func_cap.reserved_lkey; in mlx4_slave_cap()
833 dev->caps.num_pds = MLX4_NUM_PDS; in mlx4_slave_cap()
834 dev->caps.num_mgms = 0; in mlx4_slave_cap()
835 dev->caps.num_amgms = 0; in mlx4_slave_cap()
837 if (dev->caps.num_ports > MLX4_MAX_PORTS) { in mlx4_slave_cap()
838 mlx4_err(dev, "HCA has %d ports, but we only support %d, aborting\n", in mlx4_slave_cap()
839 dev->caps.num_ports, MLX4_MAX_PORTS); in mlx4_slave_cap()
843 dev->caps.qp0_qkey = kcalloc(dev->caps.num_ports, sizeof(u32), GFP_KERNEL); in mlx4_slave_cap()
844 dev->caps.qp0_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
845 dev->caps.qp0_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
846 dev->caps.qp1_tunnel = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
847 dev->caps.qp1_proxy = kcalloc(dev->caps.num_ports, sizeof (u32), GFP_KERNEL); in mlx4_slave_cap()
849 if (!dev->caps.qp0_tunnel || !dev->caps.qp0_proxy || in mlx4_slave_cap()
850 !dev->caps.qp1_tunnel || !dev->caps.qp1_proxy || in mlx4_slave_cap()
851 !dev->caps.qp0_qkey) { in mlx4_slave_cap()
856 for (i = 1; i <= dev->caps.num_ports; ++i) { in mlx4_slave_cap()
857 err = mlx4_QUERY_FUNC_CAP(dev, i, &func_cap); in mlx4_slave_cap()
859 mlx4_err(dev, "QUERY_FUNC_CAP port command failed for port %d, aborting (%d)\n", in mlx4_slave_cap()
863 dev->caps.qp0_qkey[i - 1] = func_cap.qp0_qkey; in mlx4_slave_cap()
864 dev->caps.qp0_tunnel[i - 1] = func_cap.qp0_tunnel_qpn; in mlx4_slave_cap()
865 dev->caps.qp0_proxy[i - 1] = func_cap.qp0_proxy_qpn; in mlx4_slave_cap()
866 dev->caps.qp1_tunnel[i - 1] = func_cap.qp1_tunnel_qpn; in mlx4_slave_cap()
867 dev->caps.qp1_proxy[i - 1] = func_cap.qp1_proxy_qpn; in mlx4_slave_cap()
868 dev->caps.port_mask[i] = dev->caps.port_type[i]; in mlx4_slave_cap()
869 dev->caps.phys_port_id[i] = func_cap.phys_port_id; in mlx4_slave_cap()
870 if (mlx4_get_slave_pkey_gid_tbl_len(dev, i, in mlx4_slave_cap()
871 &dev->caps.gid_table_len[i], in mlx4_slave_cap()
872 &dev->caps.pkey_table_len[i])) in mlx4_slave_cap()
876 if (dev->caps.uar_page_size * (dev->caps.num_uars - in mlx4_slave_cap()
877 dev->caps.reserved_uars) > in mlx4_slave_cap()
878 pci_resource_len(dev->persist->pdev, in mlx4_slave_cap()
880 …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()
881 dev->caps.uar_page_size * dev->caps.num_uars, in mlx4_slave_cap()
883 pci_resource_len(dev->persist->pdev, 2)); in mlx4_slave_cap()
888 dev->caps.eqe_size = 64; in mlx4_slave_cap()
889 dev->caps.eqe_factor = 1; in mlx4_slave_cap()
891 dev->caps.eqe_size = 32; in mlx4_slave_cap()
892 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
896 dev->caps.cqe_size = 64; in mlx4_slave_cap()
897 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
899 dev->caps.cqe_size = 32; in mlx4_slave_cap()
903 dev->caps.eqe_size = hca_param.eqe_size; in mlx4_slave_cap()
904 dev->caps.eqe_factor = 0; in mlx4_slave_cap()
908 dev->caps.cqe_size = hca_param.cqe_size; in mlx4_slave_cap()
910 dev->caps.userspace_caps |= MLX4_USER_DEV_CAP_LARGE_CQE; in mlx4_slave_cap()
913 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_slave_cap()
914 mlx4_warn(dev, "Timestamping is not supported in slave mode\n"); in mlx4_slave_cap()
916 slave_adjust_steering_mode(dev, &dev_cap, &hca_param); in mlx4_slave_cap()
917 mlx4_dbg(dev, "RSS support for IP fragments is %s\n", in mlx4_slave_cap()
921 dev->caps.bf_reg_size) in mlx4_slave_cap()
922 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_ETH_BF_QP; in mlx4_slave_cap()
925 dev->caps.alloc_res_qp_mask |= MLX4_RESERVE_A0_QP; in mlx4_slave_cap()
930 kfree(dev->caps.qp0_qkey); in mlx4_slave_cap()
931 kfree(dev->caps.qp0_tunnel); in mlx4_slave_cap()
932 kfree(dev->caps.qp0_proxy); in mlx4_slave_cap()
933 kfree(dev->caps.qp1_tunnel); in mlx4_slave_cap()
934 kfree(dev->caps.qp1_proxy); in mlx4_slave_cap()
935 dev->caps.qp0_qkey = NULL; in mlx4_slave_cap()
936 dev->caps.qp0_tunnel = NULL; in mlx4_slave_cap()
937 dev->caps.qp0_proxy = NULL; in mlx4_slave_cap()
938 dev->caps.qp1_tunnel = NULL; in mlx4_slave_cap()
939 dev->caps.qp1_proxy = NULL; in mlx4_slave_cap()
944 static void mlx4_request_modules(struct mlx4_dev *dev) in mlx4_request_modules() argument
952 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_request_modules()
953 if (dev->caps.port_type[port] == MLX4_PORT_TYPE_IB) in mlx4_request_modules()
955 else if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) in mlx4_request_modules()
961 if (has_ib_port || (dev->caps.flags & MLX4_DEV_CAP_FLAG_IBOE)) in mlx4_request_modules()
969 int mlx4_change_port_types(struct mlx4_dev *dev, in mlx4_change_port_types() argument
976 for (port = 0; port < dev->caps.num_ports; port++) { in mlx4_change_port_types()
979 if (port_types[port] != dev->caps.port_type[port + 1]) in mlx4_change_port_types()
983 mlx4_unregister_device(dev); in mlx4_change_port_types()
984 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_change_port_types()
985 mlx4_CLOSE_PORT(dev, port); in mlx4_change_port_types()
986 dev->caps.port_type[port] = port_types[port - 1]; in mlx4_change_port_types()
987 err = mlx4_SET_PORT(dev, port, -1); in mlx4_change_port_types()
989 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_change_port_types()
994 mlx4_set_port_mask(dev); in mlx4_change_port_types()
995 err = mlx4_register_device(dev); in mlx4_change_port_types()
997 mlx4_err(dev, "Failed to register device\n"); in mlx4_change_port_types()
1000 mlx4_request_modules(dev); in mlx4_change_port_types()
1007 static ssize_t show_port_type(struct device *dev, in show_port_type() argument
1013 struct mlx4_dev *mdev = info->dev; in show_port_type()
1027 static ssize_t set_port_type(struct device *dev, in set_port_type() argument
1033 struct mlx4_dev *mdev = info->dev; in set_port_type()
1136 static ssize_t show_port_ib_mtu(struct device *dev, in show_port_ib_mtu() argument
1142 struct mlx4_dev *mdev = info->dev; in show_port_ib_mtu()
1152 static ssize_t set_port_ib_mtu(struct device *dev, in set_port_ib_mtu() argument
1158 struct mlx4_dev *mdev = info->dev; in set_port_ib_mtu()
1197 int mlx4_bond(struct mlx4_dev *dev) in mlx4_bond() argument
1200 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_bond()
1204 if (!mlx4_is_bonded(dev)) in mlx4_bond()
1205 ret = mlx4_do_bond(dev, true); in mlx4_bond()
1211 mlx4_err(dev, "Failed to bond device: %d\n", ret); in mlx4_bond()
1213 mlx4_dbg(dev, "Device is bonded\n"); in mlx4_bond()
1218 int mlx4_unbond(struct mlx4_dev *dev) in mlx4_unbond() argument
1221 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unbond()
1225 if (mlx4_is_bonded(dev)) in mlx4_unbond()
1226 ret = mlx4_do_bond(dev, false); in mlx4_unbond()
1230 mlx4_err(dev, "Failed to unbond device: %d\n", ret); in mlx4_unbond()
1232 mlx4_dbg(dev, "Device is unbonded\n"); in mlx4_unbond()
1238 int mlx4_port_map_set(struct mlx4_dev *dev, struct mlx4_port_map *v2p) in mlx4_port_map_set() argument
1242 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_port_map_set()
1245 if (!(dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_PORT_REMAP)) in mlx4_port_map_set()
1266 err = mlx4_virt2phy_port_map(dev, port1, port2); in mlx4_port_map_set()
1268 mlx4_dbg(dev, "port map changed: [%d][%d]\n", in mlx4_port_map_set()
1273 mlx4_err(dev, "Failed to change port mape: %d\n", err); in mlx4_port_map_set()
1282 static int mlx4_load_fw(struct mlx4_dev *dev) in mlx4_load_fw() argument
1284 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_load_fw()
1287 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages, in mlx4_load_fw()
1290 mlx4_err(dev, "Couldn't allocate FW area, aborting\n"); in mlx4_load_fw()
1294 err = mlx4_MAP_FA(dev, priv->fw.fw_icm); in mlx4_load_fw()
1296 mlx4_err(dev, "MAP_FA command failed, aborting\n"); in mlx4_load_fw()
1300 err = mlx4_RUN_FW(dev); in mlx4_load_fw()
1302 mlx4_err(dev, "RUN_FW command failed, aborting\n"); in mlx4_load_fw()
1309 mlx4_UNMAP_FA(dev); in mlx4_load_fw()
1312 mlx4_free_icm(dev, priv->fw.fw_icm, 0); in mlx4_load_fw()
1316 static int mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base, in mlx4_init_cmpt_table() argument
1319 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_cmpt_table()
1323 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table, in mlx4_init_cmpt_table()
1327 cmpt_entry_sz, dev->caps.num_qps, in mlx4_init_cmpt_table()
1328 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_cmpt_table()
1333 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table, in mlx4_init_cmpt_table()
1337 cmpt_entry_sz, dev->caps.num_srqs, in mlx4_init_cmpt_table()
1338 dev->caps.reserved_srqs, 0, 0); in mlx4_init_cmpt_table()
1342 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table, in mlx4_init_cmpt_table()
1346 cmpt_entry_sz, dev->caps.num_cqs, in mlx4_init_cmpt_table()
1347 dev->caps.reserved_cqs, 0, 0); in mlx4_init_cmpt_table()
1351 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_cmpt_table()
1352 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table, in mlx4_init_cmpt_table()
1363 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_cmpt_table()
1366 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_cmpt_table()
1369 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_cmpt_table()
1375 static int mlx4_init_icm(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_init_icm() argument
1378 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_icm()
1383 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages); in mlx4_init_icm()
1385 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting\n"); in mlx4_init_icm()
1389 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory\n", in mlx4_init_icm()
1393 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages, in mlx4_init_icm()
1396 mlx4_err(dev, "Couldn't allocate aux memory, aborting\n"); in mlx4_init_icm()
1400 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm); in mlx4_init_icm()
1402 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting\n"); in mlx4_init_icm()
1406 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz); in mlx4_init_icm()
1408 mlx4_err(dev, "Failed to map cMPT context memory, aborting\n"); in mlx4_init_icm()
1413 num_eqs = dev->phys_caps.num_phys_eqs; in mlx4_init_icm()
1414 err = mlx4_init_icm_table(dev, &priv->eq_table.table, in mlx4_init_icm()
1418 mlx4_err(dev, "Failed to map EQ context memory, aborting\n"); in mlx4_init_icm()
1429 dev->caps.reserved_mtts = in mlx4_init_icm()
1430 ALIGN(dev->caps.reserved_mtts * dev->caps.mtt_entry_sz, in mlx4_init_icm()
1431 dma_get_cache_alignment()) / dev->caps.mtt_entry_sz; in mlx4_init_icm()
1433 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table, in mlx4_init_icm()
1435 dev->caps.mtt_entry_sz, in mlx4_init_icm()
1436 dev->caps.num_mtts, in mlx4_init_icm()
1437 dev->caps.reserved_mtts, 1, 0); in mlx4_init_icm()
1439 mlx4_err(dev, "Failed to map MTT context memory, aborting\n"); in mlx4_init_icm()
1443 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table, in mlx4_init_icm()
1446 dev->caps.num_mpts, in mlx4_init_icm()
1447 dev->caps.reserved_mrws, 1, 1); in mlx4_init_icm()
1449 mlx4_err(dev, "Failed to map dMPT context memory, aborting\n"); in mlx4_init_icm()
1453 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table, in mlx4_init_icm()
1456 dev->caps.num_qps, in mlx4_init_icm()
1457 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1460 mlx4_err(dev, "Failed to map QP context memory, aborting\n"); in mlx4_init_icm()
1464 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table, in mlx4_init_icm()
1467 dev->caps.num_qps, in mlx4_init_icm()
1468 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1471 mlx4_err(dev, "Failed to map AUXC context memory, aborting\n"); in mlx4_init_icm()
1475 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table, in mlx4_init_icm()
1478 dev->caps.num_qps, in mlx4_init_icm()
1479 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1482 mlx4_err(dev, "Failed to map ALTC context memory, aborting\n"); in mlx4_init_icm()
1486 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table, in mlx4_init_icm()
1489 dev->caps.num_qps, in mlx4_init_icm()
1490 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW], in mlx4_init_icm()
1493 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n"); in mlx4_init_icm()
1497 err = mlx4_init_icm_table(dev, &priv->cq_table.table, in mlx4_init_icm()
1500 dev->caps.num_cqs, in mlx4_init_icm()
1501 dev->caps.reserved_cqs, 0, 0); in mlx4_init_icm()
1503 mlx4_err(dev, "Failed to map CQ context memory, aborting\n"); in mlx4_init_icm()
1507 err = mlx4_init_icm_table(dev, &priv->srq_table.table, in mlx4_init_icm()
1510 dev->caps.num_srqs, in mlx4_init_icm()
1511 dev->caps.reserved_srqs, 0, 0); in mlx4_init_icm()
1513 mlx4_err(dev, "Failed to map SRQ context memory, aborting\n"); in mlx4_init_icm()
1524 err = mlx4_init_icm_table(dev, &priv->mcg_table.table, in mlx4_init_icm()
1526 mlx4_get_mgm_entry_size(dev), in mlx4_init_icm()
1527 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1528 dev->caps.num_mgms + dev->caps.num_amgms, in mlx4_init_icm()
1531 mlx4_err(dev, "Failed to map MCG context memory, aborting\n"); in mlx4_init_icm()
1538 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_init_icm()
1541 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_init_icm()
1544 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_init_icm()
1547 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_init_icm()
1550 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_init_icm()
1553 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_init_icm()
1556 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_init_icm()
1559 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_init_icm()
1562 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_init_icm()
1565 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_init_icm()
1566 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_init_icm()
1567 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_init_icm()
1568 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_init_icm()
1571 mlx4_UNMAP_ICM_AUX(dev); in mlx4_init_icm()
1574 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_init_icm()
1579 static void mlx4_free_icms(struct mlx4_dev *dev) in mlx4_free_icms() argument
1581 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_free_icms()
1583 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table); in mlx4_free_icms()
1584 mlx4_cleanup_icm_table(dev, &priv->srq_table.table); in mlx4_free_icms()
1585 mlx4_cleanup_icm_table(dev, &priv->cq_table.table); in mlx4_free_icms()
1586 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table); in mlx4_free_icms()
1587 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table); in mlx4_free_icms()
1588 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table); in mlx4_free_icms()
1589 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table); in mlx4_free_icms()
1590 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table); in mlx4_free_icms()
1591 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table); in mlx4_free_icms()
1592 mlx4_cleanup_icm_table(dev, &priv->eq_table.table); in mlx4_free_icms()
1593 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table); in mlx4_free_icms()
1594 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table); in mlx4_free_icms()
1595 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table); in mlx4_free_icms()
1596 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table); in mlx4_free_icms()
1598 mlx4_UNMAP_ICM_AUX(dev); in mlx4_free_icms()
1599 mlx4_free_icm(dev, priv->fw.aux_icm, 0); in mlx4_free_icms()
1602 static void mlx4_slave_exit(struct mlx4_dev *dev) in mlx4_slave_exit() argument
1604 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_slave_exit()
1607 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, in mlx4_slave_exit()
1609 mlx4_warn(dev, "Failed to close slave function\n"); in mlx4_slave_exit()
1613 static int map_bf_area(struct mlx4_dev *dev) in map_bf_area() argument
1615 struct mlx4_priv *priv = mlx4_priv(dev); in map_bf_area()
1620 if (!dev->caps.bf_reg_size) in map_bf_area()
1623 bf_start = pci_resource_start(dev->persist->pdev, 2) + in map_bf_area()
1624 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1625 bf_len = pci_resource_len(dev->persist->pdev, 2) - in map_bf_area()
1626 (dev->caps.num_uars << PAGE_SHIFT); in map_bf_area()
1634 static void unmap_bf_area(struct mlx4_dev *dev) in unmap_bf_area() argument
1636 if (mlx4_priv(dev)->bf_mapping) in unmap_bf_area()
1637 io_mapping_free(mlx4_priv(dev)->bf_mapping); in unmap_bf_area()
1640 cycle_t mlx4_read_clock(struct mlx4_dev *dev) in mlx4_read_clock() argument
1645 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_read_clock()
1662 static int map_internal_clock(struct mlx4_dev *dev) in map_internal_clock() argument
1664 struct mlx4_priv *priv = mlx4_priv(dev); in map_internal_clock()
1667 ioremap(pci_resource_start(dev->persist->pdev, in map_internal_clock()
1677 static void unmap_internal_clock(struct mlx4_dev *dev) in unmap_internal_clock() argument
1679 struct mlx4_priv *priv = mlx4_priv(dev); in unmap_internal_clock()
1685 static void mlx4_close_hca(struct mlx4_dev *dev) in mlx4_close_hca() argument
1687 unmap_internal_clock(dev); in mlx4_close_hca()
1688 unmap_bf_area(dev); in mlx4_close_hca()
1689 if (mlx4_is_slave(dev)) in mlx4_close_hca()
1690 mlx4_slave_exit(dev); in mlx4_close_hca()
1692 mlx4_CLOSE_HCA(dev, 0); in mlx4_close_hca()
1693 mlx4_free_icms(dev); in mlx4_close_hca()
1697 static void mlx4_close_fw(struct mlx4_dev *dev) in mlx4_close_fw() argument
1699 if (!mlx4_is_slave(dev)) { in mlx4_close_fw()
1700 mlx4_UNMAP_FA(dev); in mlx4_close_fw()
1701 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm, 0); in mlx4_close_fw()
1705 static int mlx4_comm_check_offline(struct mlx4_dev *dev) in mlx4_comm_check_offline() argument
1712 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_comm_check_offline()
1729 mlx4_err(dev, "Communication channel is offline.\n"); in mlx4_comm_check_offline()
1733 static void mlx4_reset_vf_support(struct mlx4_dev *dev) in mlx4_reset_vf_support() argument
1737 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_reset_vf_support()
1746 dev->caps.vf_caps |= MLX4_VF_CAP_FLAG_RESET; in mlx4_reset_vf_support()
1749 static int mlx4_init_slave(struct mlx4_dev *dev) in mlx4_init_slave() argument
1751 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_slave()
1758 mlx4_warn(dev, "PF is not ready - Deferring probe\n"); in mlx4_init_slave()
1764 if (mlx4_comm_check_offline(dev)) { in mlx4_init_slave()
1765 mlx4_err(dev, "PF is not responsive, skipping initialization\n"); in mlx4_init_slave()
1769 mlx4_reset_vf_support(dev); in mlx4_init_slave()
1770 mlx4_warn(dev, "Sending reset\n"); in mlx4_init_slave()
1771 ret_from_reset = mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, in mlx4_init_slave()
1777 mlx4_warn(dev, "slave is currently in the middle of FLR - Deferring probe\n"); in mlx4_init_slave()
1791 mlx4_err(dev, "slave driver version is not supported by the master\n"); in mlx4_init_slave()
1795 mlx4_warn(dev, "Sending vhcr0\n"); in mlx4_init_slave()
1796 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR0, dma >> 48, in mlx4_init_slave()
1799 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR1, dma >> 32, in mlx4_init_slave()
1802 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR2, dma >> 16, in mlx4_init_slave()
1805 if (mlx4_comm_cmd(dev, MLX4_COMM_CMD_VHCR_EN, dma, in mlx4_init_slave()
1813 mlx4_comm_cmd(dev, MLX4_COMM_CMD_RESET, 0, MLX4_COMM_CMD_NA_OP, 0); in mlx4_init_slave()
1819 static void mlx4_parav_master_pf_caps(struct mlx4_dev *dev) in mlx4_parav_master_pf_caps() argument
1823 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_parav_master_pf_caps()
1824 if (dev->caps.port_type[i] == MLX4_PORT_TYPE_ETH) in mlx4_parav_master_pf_caps()
1825 dev->caps.gid_table_len[i] = in mlx4_parav_master_pf_caps()
1826 mlx4_get_slave_num_gids(dev, 0, i); in mlx4_parav_master_pf_caps()
1828 dev->caps.gid_table_len[i] = 1; in mlx4_parav_master_pf_caps()
1829 dev->caps.pkey_table_len[i] = in mlx4_parav_master_pf_caps()
1830 dev->phys_caps.pkey_phys_table_len[i] - 1; in mlx4_parav_master_pf_caps()
1872 static void choose_steering_mode(struct mlx4_dev *dev, in choose_steering_mode() argument
1877 if (dev->caps.dmfs_high_steer_mode == in choose_steering_mode()
1879 mlx4_err(dev, "DMFS high rate mode not supported\n"); in choose_steering_mode()
1881 dev->caps.dmfs_high_steer_mode = in choose_steering_mode()
1888 (!mlx4_is_mfunc(dev) || in choose_steering_mode()
1890 (dev->persist->num_vfs + 1))) && in choose_steering_mode()
1893 dev->oper_log_mgm_entry_size = in choose_steering_mode()
1895 dev->caps.steering_mode = MLX4_STEERING_MODE_DEVICE_MANAGED; in choose_steering_mode()
1896 dev->caps.num_qp_per_mgm = dev_cap->fs_max_num_qp_per_entry; in choose_steering_mode()
1897 dev->caps.fs_log_max_ucast_qp_range_size = in choose_steering_mode()
1900 if (dev->caps.dmfs_high_steer_mode != in choose_steering_mode()
1902 dev->caps.dmfs_high_steer_mode = MLX4_STEERING_DMFS_A0_DISABLE; in choose_steering_mode()
1903 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER && in choose_steering_mode()
1904 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
1905 dev->caps.steering_mode = MLX4_STEERING_MODE_B0; in choose_steering_mode()
1907 dev->caps.steering_mode = MLX4_STEERING_MODE_A0; in choose_steering_mode()
1909 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_UC_STEER || in choose_steering_mode()
1910 dev->caps.flags & MLX4_DEV_CAP_FLAG_VEP_MC_STEER) in choose_steering_mode()
1911 …mlx4_warn(dev, "Must have both UC_STEER and MC_STEER flags set to use B0 steering - falling back t… in choose_steering_mode()
1913 dev->oper_log_mgm_entry_size = in choose_steering_mode()
1917 dev->caps.num_qp_per_mgm = mlx4_get_qp_per_mgm(dev); in choose_steering_mode()
1919 …mlx4_dbg(dev, "Steering mode is: %s, oper_log_mgm_entry_size = %d, modparam log_num_mgm_entry_size… in choose_steering_mode()
1920 mlx4_steering_mode_str(dev->caps.steering_mode), in choose_steering_mode()
1921 dev->oper_log_mgm_entry_size, in choose_steering_mode()
1925 static void choose_tunnel_offload_mode(struct mlx4_dev *dev, in choose_tunnel_offload_mode() argument
1928 if (dev->caps.steering_mode == MLX4_STEERING_MODE_DEVICE_MANAGED && in choose_tunnel_offload_mode()
1930 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_VXLAN; in choose_tunnel_offload_mode()
1932 dev->caps.tunnel_offload_mode = MLX4_TUNNEL_OFFLOAD_MODE_NONE; in choose_tunnel_offload_mode()
1934 mlx4_dbg(dev, "Tunneling offload mode is: %s\n", (dev->caps.tunnel_offload_mode in choose_tunnel_offload_mode()
1938 static int mlx4_validate_optimized_steering(struct mlx4_dev *dev) in mlx4_validate_optimized_steering() argument
1943 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_NOT_SUPPORTED) in mlx4_validate_optimized_steering()
1946 for (i = 1; i <= dev->caps.num_ports; i++) { in mlx4_validate_optimized_steering()
1947 if (mlx4_dev_port(dev, i, &port_cap)) { in mlx4_validate_optimized_steering()
1948 mlx4_err(dev, in mlx4_validate_optimized_steering()
1950 } else if ((dev->caps.dmfs_high_steer_mode != in mlx4_validate_optimized_steering()
1953 !!(dev->caps.dmfs_high_steer_mode == in mlx4_validate_optimized_steering()
1955 mlx4_err(dev, in mlx4_validate_optimized_steering()
1958 dev->caps.dmfs_high_steer_mode), in mlx4_validate_optimized_steering()
1967 static int mlx4_init_fw(struct mlx4_dev *dev) in mlx4_init_fw() argument
1972 if (!mlx4_is_slave(dev)) { in mlx4_init_fw()
1973 err = mlx4_QUERY_FW(dev); in mlx4_init_fw()
1976 mlx4_info(dev, "non-primary physical function, skipping\n"); in mlx4_init_fw()
1978 mlx4_err(dev, "QUERY_FW command failed, aborting\n"); in mlx4_init_fw()
1982 err = mlx4_load_fw(dev); in mlx4_init_fw()
1984 mlx4_err(dev, "Failed to start FW, aborting\n"); in mlx4_init_fw()
1990 err = mlx4_MOD_STAT_CFG(dev, &mlx4_cfg); in mlx4_init_fw()
1992 mlx4_warn(dev, "Failed to override log_pg_sz parameter\n"); in mlx4_init_fw()
1998 static int mlx4_init_hca(struct mlx4_dev *dev) in mlx4_init_hca() argument
2000 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_hca()
2009 if (!mlx4_is_slave(dev)) { in mlx4_init_hca()
2010 err = mlx4_dev_cap(dev, &dev_cap); in mlx4_init_hca()
2012 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting\n"); in mlx4_init_hca()
2016 choose_steering_mode(dev, &dev_cap); in mlx4_init_hca()
2017 choose_tunnel_offload_mode(dev, &dev_cap); in mlx4_init_hca()
2019 if (dev->caps.dmfs_high_steer_mode == MLX4_STEERING_DMFS_A0_STATIC && in mlx4_init_hca()
2020 mlx4_is_master(dev)) in mlx4_init_hca()
2021 dev->caps.function_caps |= MLX4_FUNC_CAP_DMFS_A0_STATIC; in mlx4_init_hca()
2023 err = mlx4_get_phys_port_id(dev); in mlx4_init_hca()
2025 mlx4_err(dev, "Fail to get physical port id\n"); in mlx4_init_hca()
2027 if (mlx4_is_master(dev)) in mlx4_init_hca()
2028 mlx4_parav_master_pf_caps(dev); in mlx4_init_hca()
2031 mlx4_info(dev, "Running from within kdump kernel. Using low memory profile\n"); in mlx4_init_hca()
2036 if (dev->caps.steering_mode == in mlx4_init_hca()
2040 icm_size = mlx4_make_profile(dev, &profile, &dev_cap, in mlx4_init_hca()
2047 dev->caps.max_fmr_maps = (1 << (32 - ilog2(dev->caps.num_mpts))) - 1; in mlx4_init_hca()
2049 init_hca.log_uar_sz = ilog2(dev->caps.num_uars); in mlx4_init_hca()
2052 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_MEM_WINDOW || in mlx4_init_hca()
2053 dev->caps.bmme_flags & MLX4_BMME_FLAG_TYPE_2_WIN) in mlx4_init_hca()
2056 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size); in mlx4_init_hca()
2060 err = mlx4_INIT_HCA(dev, &init_hca); in mlx4_init_hca()
2062 mlx4_err(dev, "INIT_HCA command failed, aborting\n"); in mlx4_init_hca()
2067 err = mlx4_query_func(dev, &dev_cap); in mlx4_init_hca()
2069 mlx4_err(dev, "QUERY_FUNC command failed, aborting.\n"); in mlx4_init_hca()
2072 dev->caps.num_eqs = dev_cap.max_eqs; in mlx4_init_hca()
2073 dev->caps.reserved_eqs = dev_cap.reserved_eqs; in mlx4_init_hca()
2074 dev->caps.reserved_uars = dev_cap.reserved_uars; in mlx4_init_hca()
2082 if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_TS) { in mlx4_init_hca()
2084 err = mlx4_QUERY_HCA(dev, &init_hca); in mlx4_init_hca()
2086 mlx4_err(dev, "QUERY_HCA command failed, disable timestamp\n"); in mlx4_init_hca()
2087 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2089 dev->caps.hca_core_clock = in mlx4_init_hca()
2096 if (!dev->caps.hca_core_clock) { in mlx4_init_hca()
2097 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2098 mlx4_err(dev, in mlx4_init_hca()
2100 } else if (map_internal_clock(dev)) { in mlx4_init_hca()
2105 dev->caps.flags2 &= ~MLX4_DEV_CAP_FLAG2_TS; in mlx4_init_hca()
2106 mlx4_err(dev, "Failed to map internal clock. Timestamping is not supported\n"); in mlx4_init_hca()
2110 if (dev->caps.dmfs_high_steer_mode != in mlx4_init_hca()
2112 if (mlx4_validate_optimized_steering(dev)) in mlx4_init_hca()
2113 mlx4_warn(dev, "Optimized steering validation failed\n"); in mlx4_init_hca()
2115 if (dev->caps.dmfs_high_steer_mode == in mlx4_init_hca()
2117 dev->caps.dmfs_high_rate_qpn_base = in mlx4_init_hca()
2118 dev->caps.reserved_qps_cnt[MLX4_QP_REGION_FW]; in mlx4_init_hca()
2119 dev->caps.dmfs_high_rate_qpn_range = in mlx4_init_hca()
2123 mlx4_dbg(dev, "DMFS high rate steer mode is: %s\n", in mlx4_init_hca()
2125 dev->caps.dmfs_high_steer_mode)); in mlx4_init_hca()
2128 err = mlx4_init_slave(dev); in mlx4_init_hca()
2131 mlx4_err(dev, "Failed to initialize slave\n"); in mlx4_init_hca()
2135 err = mlx4_slave_cap(dev); in mlx4_init_hca()
2137 mlx4_err(dev, "Failed to obtain slave caps\n"); in mlx4_init_hca()
2142 if (map_bf_area(dev)) in mlx4_init_hca()
2143 mlx4_dbg(dev, "Failed to map blue flame area\n"); in mlx4_init_hca()
2146 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2147 mlx4_set_port_mask(dev); in mlx4_init_hca()
2149 err = mlx4_QUERY_ADAPTER(dev, &adapter); in mlx4_init_hca()
2151 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting\n"); in mlx4_init_hca()
2156 err = mlx4_config_dev_retrieval(dev, ¶ms); in mlx4_init_hca()
2158 mlx4_err(dev, "Failed to query CONFIG_DEV parameters\n"); in mlx4_init_hca()
2160 dev->caps.rx_checksum_flags_port[1] = params.rx_csum_flags_port_1; in mlx4_init_hca()
2161 dev->caps.rx_checksum_flags_port[2] = params.rx_csum_flags_port_2; in mlx4_init_hca()
2164 memcpy(dev->board_id, adapter.board_id, sizeof dev->board_id); in mlx4_init_hca()
2169 unmap_internal_clock(dev); in mlx4_init_hca()
2170 unmap_bf_area(dev); in mlx4_init_hca()
2172 if (mlx4_is_slave(dev)) { in mlx4_init_hca()
2173 kfree(dev->caps.qp0_qkey); in mlx4_init_hca()
2174 kfree(dev->caps.qp0_tunnel); in mlx4_init_hca()
2175 kfree(dev->caps.qp0_proxy); in mlx4_init_hca()
2176 kfree(dev->caps.qp1_tunnel); in mlx4_init_hca()
2177 kfree(dev->caps.qp1_proxy); in mlx4_init_hca()
2181 if (mlx4_is_slave(dev)) in mlx4_init_hca()
2182 mlx4_slave_exit(dev); in mlx4_init_hca()
2184 mlx4_CLOSE_HCA(dev, 0); in mlx4_init_hca()
2187 if (!mlx4_is_slave(dev)) in mlx4_init_hca()
2188 mlx4_free_icms(dev); in mlx4_init_hca()
2193 static int mlx4_init_counters_table(struct mlx4_dev *dev) in mlx4_init_counters_table() argument
2195 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_counters_table()
2198 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in mlx4_init_counters_table()
2201 nent = dev->caps.max_counters; in mlx4_init_counters_table()
2205 static void mlx4_cleanup_counters_table(struct mlx4_dev *dev) in mlx4_cleanup_counters_table() argument
2207 mlx4_bitmap_cleanup(&mlx4_priv(dev)->counters_bitmap); in mlx4_cleanup_counters_table()
2210 int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) in __mlx4_counter_alloc() argument
2212 struct mlx4_priv *priv = mlx4_priv(dev); in __mlx4_counter_alloc()
2214 if (!(dev->caps.flags & MLX4_DEV_CAP_FLAG_COUNTERS)) in __mlx4_counter_alloc()
2224 int mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx) in mlx4_counter_alloc() argument
2229 if (mlx4_is_mfunc(dev)) { in mlx4_counter_alloc()
2230 err = mlx4_cmd_imm(dev, 0, &out_param, RES_COUNTER, in mlx4_counter_alloc()
2238 return __mlx4_counter_alloc(dev, idx); in mlx4_counter_alloc()
2242 void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in __mlx4_counter_free() argument
2244 mlx4_bitmap_free(&mlx4_priv(dev)->counters_bitmap, idx, MLX4_USE_RR); in __mlx4_counter_free()
2248 void mlx4_counter_free(struct mlx4_dev *dev, u32 idx) in mlx4_counter_free() argument
2252 if (mlx4_is_mfunc(dev)) { in mlx4_counter_free()
2254 mlx4_cmd(dev, in_param, RES_COUNTER, RES_OP_RESERVE, in mlx4_counter_free()
2259 __mlx4_counter_free(dev, idx); in mlx4_counter_free()
2263 void mlx4_set_admin_guid(struct mlx4_dev *dev, __be64 guid, int entry, int port) in mlx4_set_admin_guid() argument
2265 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_admin_guid()
2271 __be64 mlx4_get_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_get_admin_guid() argument
2273 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_get_admin_guid()
2279 void mlx4_set_random_admin_guid(struct mlx4_dev *dev, int entry, int port) in mlx4_set_random_admin_guid() argument
2281 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_set_random_admin_guid()
2294 static int mlx4_setup_hca(struct mlx4_dev *dev) in mlx4_setup_hca() argument
2296 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_setup_hca()
2301 err = mlx4_init_uar_table(dev); in mlx4_setup_hca()
2303 mlx4_err(dev, "Failed to initialize user access region table, aborting\n"); in mlx4_setup_hca()
2307 err = mlx4_uar_alloc(dev, &priv->driver_uar); in mlx4_setup_hca()
2309 mlx4_err(dev, "Failed to allocate driver access region, aborting\n"); in mlx4_setup_hca()
2315 mlx4_err(dev, "Couldn't map kernel access region, aborting\n"); in mlx4_setup_hca()
2320 err = mlx4_init_pd_table(dev); in mlx4_setup_hca()
2322 mlx4_err(dev, "Failed to initialize protection domain table, aborting\n"); in mlx4_setup_hca()
2326 err = mlx4_init_xrcd_table(dev); in mlx4_setup_hca()
2328 mlx4_err(dev, "Failed to initialize reliable connection domain table, aborting\n"); in mlx4_setup_hca()
2332 err = mlx4_init_mr_table(dev); in mlx4_setup_hca()
2334 mlx4_err(dev, "Failed to initialize memory region table, aborting\n"); in mlx4_setup_hca()
2338 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2339 err = mlx4_init_mcg_table(dev); in mlx4_setup_hca()
2341 mlx4_err(dev, "Failed to initialize multicast group table, aborting\n"); in mlx4_setup_hca()
2344 err = mlx4_config_mad_demux(dev); in mlx4_setup_hca()
2346 mlx4_err(dev, "Failed in config_mad_demux, aborting\n"); in mlx4_setup_hca()
2351 err = mlx4_init_eq_table(dev); in mlx4_setup_hca()
2353 mlx4_err(dev, "Failed to initialize event queue table, aborting\n"); in mlx4_setup_hca()
2357 err = mlx4_cmd_use_events(dev); in mlx4_setup_hca()
2359 mlx4_err(dev, "Failed to switch to event-driven firmware commands, aborting\n"); in mlx4_setup_hca()
2363 err = mlx4_NOP(dev); in mlx4_setup_hca()
2365 if (dev->flags & MLX4_FLAG_MSI_X) { in mlx4_setup_hca()
2366 mlx4_warn(dev, "NOP command failed to generate MSI-X interrupt IRQ %d)\n", in mlx4_setup_hca()
2367 priv->eq_table.eq[dev->caps.num_comp_vectors].irq); in mlx4_setup_hca()
2368 mlx4_warn(dev, "Trying again without MSI-X\n"); in mlx4_setup_hca()
2370 mlx4_err(dev, "NOP command failed to generate interrupt (IRQ %d), aborting\n", in mlx4_setup_hca()
2371 priv->eq_table.eq[dev->caps.num_comp_vectors].irq); in mlx4_setup_hca()
2372 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n"); in mlx4_setup_hca()
2378 mlx4_dbg(dev, "NOP command IRQ test passed\n"); in mlx4_setup_hca()
2380 err = mlx4_init_cq_table(dev); in mlx4_setup_hca()
2382 mlx4_err(dev, "Failed to initialize completion queue table, aborting\n"); in mlx4_setup_hca()
2386 err = mlx4_init_srq_table(dev); in mlx4_setup_hca()
2388 mlx4_err(dev, "Failed to initialize shared receive queue table, aborting\n"); in mlx4_setup_hca()
2392 err = mlx4_init_qp_table(dev); in mlx4_setup_hca()
2394 mlx4_err(dev, "Failed to initialize queue pair table, aborting\n"); in mlx4_setup_hca()
2398 err = mlx4_init_counters_table(dev); in mlx4_setup_hca()
2400 mlx4_err(dev, "Failed to initialize counters table, aborting\n"); in mlx4_setup_hca()
2404 if (!mlx4_is_slave(dev)) { in mlx4_setup_hca()
2405 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_setup_hca()
2407 err = mlx4_get_port_ib_caps(dev, port, in mlx4_setup_hca()
2410 mlx4_warn(dev, "failed to get port %d default ib capabilities (%d). Continuing with caps = 0\n", in mlx4_setup_hca()
2412 dev->caps.ib_port_def_cap[port] = ib_port_default_caps; in mlx4_setup_hca()
2415 if (mlx4_is_master(dev)) { in mlx4_setup_hca()
2417 for (i = 0; i < dev->num_slaves; i++) { in mlx4_setup_hca()
2418 if (i == mlx4_master_func_num(dev)) in mlx4_setup_hca()
2425 if (mlx4_is_mfunc(dev)) in mlx4_setup_hca()
2426 dev->caps.port_ib_mtu[port] = IB_MTU_2048; in mlx4_setup_hca()
2428 dev->caps.port_ib_mtu[port] = IB_MTU_4096; in mlx4_setup_hca()
2430 err = mlx4_SET_PORT(dev, port, mlx4_is_master(dev) ? in mlx4_setup_hca()
2431 dev->caps.pkey_table_len[port] : -1); in mlx4_setup_hca()
2433 mlx4_err(dev, "Failed to set port %d, aborting\n", in mlx4_setup_hca()
2443 mlx4_cleanup_counters_table(dev); in mlx4_setup_hca()
2446 mlx4_cleanup_qp_table(dev); in mlx4_setup_hca()
2449 mlx4_cleanup_srq_table(dev); in mlx4_setup_hca()
2452 mlx4_cleanup_cq_table(dev); in mlx4_setup_hca()
2455 mlx4_cmd_use_polling(dev); in mlx4_setup_hca()
2458 mlx4_cleanup_eq_table(dev); in mlx4_setup_hca()
2461 if (!mlx4_is_slave(dev)) in mlx4_setup_hca()
2462 mlx4_cleanup_mcg_table(dev); in mlx4_setup_hca()
2465 mlx4_cleanup_mr_table(dev); in mlx4_setup_hca()
2468 mlx4_cleanup_xrcd_table(dev); in mlx4_setup_hca()
2471 mlx4_cleanup_pd_table(dev); in mlx4_setup_hca()
2477 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_setup_hca()
2480 mlx4_cleanup_uar_table(dev); in mlx4_setup_hca()
2484 static void mlx4_enable_msi_x(struct mlx4_dev *dev) in mlx4_enable_msi_x() argument
2486 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_enable_msi_x()
2491 int nreq = dev->caps.num_ports * num_online_cpus() + MSIX_LEGACY_SZ; in mlx4_enable_msi_x()
2493 nreq = min_t(int, dev->caps.num_eqs - dev->caps.reserved_eqs, in mlx4_enable_msi_x()
2503 nreq = pci_enable_msix_range(dev->persist->pdev, entries, 2, in mlx4_enable_msi_x()
2510 dev->caps.num_ports * MIN_MSIX_P_PORT) { in mlx4_enable_msi_x()
2512 dev->caps.comp_pool = 0; in mlx4_enable_msi_x()
2513 dev->caps.num_comp_vectors = nreq - 1; in mlx4_enable_msi_x()
2515 dev->caps.comp_pool = nreq - MSIX_LEGACY_SZ; in mlx4_enable_msi_x()
2516 dev->caps.num_comp_vectors = MSIX_LEGACY_SZ - 1; in mlx4_enable_msi_x()
2521 dev->flags |= MLX4_FLAG_MSI_X; in mlx4_enable_msi_x()
2528 dev->caps.num_comp_vectors = 1; in mlx4_enable_msi_x()
2529 dev->caps.comp_pool = 0; in mlx4_enable_msi_x()
2532 priv->eq_table.eq[i].irq = dev->persist->pdev->irq; in mlx4_enable_msi_x()
2535 static int mlx4_init_port_info(struct mlx4_dev *dev, int port) in mlx4_init_port_info() argument
2537 struct mlx4_port_info *info = &mlx4_priv(dev)->port[port]; in mlx4_init_port_info()
2540 info->dev = dev; in mlx4_init_port_info()
2542 if (!mlx4_is_slave(dev)) { in mlx4_init_port_info()
2543 mlx4_init_mac_table(dev, &info->mac_table); in mlx4_init_port_info()
2544 mlx4_init_vlan_table(dev, &info->vlan_table); in mlx4_init_port_info()
2545 mlx4_init_roce_gid_table(dev, &info->gid_table); in mlx4_init_port_info()
2546 info->base_qpn = mlx4_get_base_qpn(dev, port); in mlx4_init_port_info()
2551 if (mlx4_is_mfunc(dev)) in mlx4_init_port_info()
2560 err = device_create_file(&dev->persist->pdev->dev, &info->port_attr); in mlx4_init_port_info()
2562 mlx4_err(dev, "Failed to create file for port %d\n", port); in mlx4_init_port_info()
2568 if (mlx4_is_mfunc(dev)) in mlx4_init_port_info()
2577 err = device_create_file(&dev->persist->pdev->dev, in mlx4_init_port_info()
2580 mlx4_err(dev, "Failed to create mtu file for port %d\n", port); in mlx4_init_port_info()
2581 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_init_port_info()
2594 device_remove_file(&info->dev->persist->pdev->dev, &info->port_attr); in mlx4_cleanup_port_info()
2595 device_remove_file(&info->dev->persist->pdev->dev, in mlx4_cleanup_port_info()
2599 static int mlx4_init_steering(struct mlx4_dev *dev) in mlx4_init_steering() argument
2601 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_init_steering()
2602 int num_entries = dev->caps.num_ports; in mlx4_init_steering()
2617 static void mlx4_clear_steering(struct mlx4_dev *dev) in mlx4_clear_steering() argument
2619 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clear_steering()
2622 int num_entries = dev->caps.num_ports; in mlx4_clear_steering()
2658 static int mlx4_get_ownership(struct mlx4_dev *dev) in mlx4_get_ownership() argument
2663 if (pci_channel_offline(dev->persist->pdev)) in mlx4_get_ownership()
2666 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_get_ownership()
2670 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_get_ownership()
2679 static void mlx4_free_ownership(struct mlx4_dev *dev) in mlx4_free_ownership() argument
2683 if (pci_channel_offline(dev->persist->pdev)) in mlx4_free_ownership()
2686 owner = ioremap(pci_resource_start(dev->persist->pdev, 0) + in mlx4_free_ownership()
2690 mlx4_err(dev, "Failed to obtain ownership bit\n"); in mlx4_free_ownership()
2701 static u64 mlx4_enable_sriov(struct mlx4_dev *dev, struct pci_dev *pdev, in mlx4_enable_sriov() argument
2704 u64 dev_flags = dev->flags; in mlx4_enable_sriov()
2708 dev->dev_vfs = kcalloc(total_vfs, sizeof(*dev->dev_vfs), in mlx4_enable_sriov()
2710 if (!dev->dev_vfs) in mlx4_enable_sriov()
2716 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_enable_sriov()
2718 … mlx4_err(dev, "SR-IOV was already enabled, but with num_vfs (%d) different than requested (%d)\n", in mlx4_enable_sriov()
2724 dev->dev_vfs = kzalloc(total_vfs * sizeof(*dev->dev_vfs), GFP_KERNEL); in mlx4_enable_sriov()
2725 if (NULL == dev->dev_vfs) { in mlx4_enable_sriov()
2726 mlx4_err(dev, "Failed to allocate memory for VFs\n"); in mlx4_enable_sriov()
2730 if (!(dev->flags & MLX4_FLAG_SRIOV)) { in mlx4_enable_sriov()
2731 mlx4_warn(dev, "Enabling SR-IOV with %d VFs\n", total_vfs); in mlx4_enable_sriov()
2735 mlx4_err(dev, "Failed to enable SR-IOV, continuing without SR-IOV (err = %d)\n", in mlx4_enable_sriov()
2739 mlx4_warn(dev, "Running in master mode\n"); in mlx4_enable_sriov()
2743 dev->persist->num_vfs = total_vfs; in mlx4_enable_sriov()
2750 dev->persist->num_vfs = 0; in mlx4_enable_sriov()
2751 kfree(dev->dev_vfs); in mlx4_enable_sriov()
2759 static int mlx4_check_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap, in mlx4_check_dev_cap() argument
2766 mlx4_err(dev, "Requested %d VFs, but FW does not support more than 64\n", in mlx4_check_dev_cap()
2777 struct mlx4_dev *dev; in mlx4_load_one() local
2785 dev = &priv->dev; in mlx4_load_one()
2799 dev->rev_id = pdev->revision; in mlx4_load_one()
2800 dev->numa_node = dev_to_node(&pdev->dev); in mlx4_load_one()
2804 mlx4_warn(dev, "Detected virtual function - running in slave mode\n"); in mlx4_load_one()
2805 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
2810 err = mlx4_get_ownership(dev); in mlx4_load_one()
2815 mlx4_warn(dev, "Multiple PFs not yet supported - Skipping PF\n"); in mlx4_load_one()
2828 err = mlx4_reset(dev); in mlx4_load_one()
2830 mlx4_err(dev, "Failed to reset HCA, aborting\n"); in mlx4_load_one()
2835 dev->flags = MLX4_FLAG_MASTER; in mlx4_load_one()
2838 dev->flags |= MLX4_FLAG_SRIOV; in mlx4_load_one()
2839 dev->persist->num_vfs = total_vfs; in mlx4_load_one()
2846 dev->persist->state = MLX4_DEVICE_STATE_UP; in mlx4_load_one()
2849 err = mlx4_cmd_init(dev); in mlx4_load_one()
2851 mlx4_err(dev, "Failed to init command interface, aborting\n"); in mlx4_load_one()
2858 if (mlx4_is_mfunc(dev)) { in mlx4_load_one()
2859 if (mlx4_is_master(dev)) { in mlx4_load_one()
2860 dev->num_slaves = MLX4_MAX_NUM_SLAVES; in mlx4_load_one()
2863 dev->num_slaves = 0; in mlx4_load_one()
2864 err = mlx4_multi_func_init(dev); in mlx4_load_one()
2866 mlx4_err(dev, "Failed to init slave mfunc interface, aborting\n"); in mlx4_load_one()
2872 err = mlx4_init_fw(dev); in mlx4_load_one()
2874 mlx4_err(dev, "Failed to init fw, aborting.\n"); in mlx4_load_one()
2878 if (mlx4_is_master(dev)) { in mlx4_load_one()
2888 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
2890 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
2894 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
2898 u64 dev_flags = mlx4_enable_sriov(dev, pdev, in mlx4_load_one()
2903 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
2904 dev->flags = dev_flags; in mlx4_load_one()
2905 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
2906 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
2909 err = mlx4_reset(dev); in mlx4_load_one()
2911 mlx4_err(dev, "Failed to reset HCA, aborting.\n"); in mlx4_load_one()
2922 err = mlx4_QUERY_DEV_CAP(dev, dev_cap); in mlx4_load_one()
2924 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n"); in mlx4_load_one()
2928 if (mlx4_check_dev_cap(dev, dev_cap, nvfs)) in mlx4_load_one()
2933 err = mlx4_init_hca(dev); in mlx4_load_one()
2938 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
2940 if (dev->flags & MLX4_FLAG_SRIOV) { in mlx4_load_one()
2943 if (mlx4_is_master(dev) && !reset_flow) in mlx4_load_one()
2945 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
2947 if (!mlx4_is_slave(dev)) in mlx4_load_one()
2948 mlx4_free_ownership(dev); in mlx4_load_one()
2949 dev->flags |= MLX4_FLAG_SLAVE; in mlx4_load_one()
2950 dev->flags &= ~MLX4_FLAG_MASTER; in mlx4_load_one()
2956 if (mlx4_is_master(dev) && (dev_cap->flags2 & MLX4_DEV_CAP_FLAG2_SYS_EQS)) { in mlx4_load_one()
2957 u64 dev_flags = mlx4_enable_sriov(dev, pdev, total_vfs, in mlx4_load_one()
2960 if ((dev->flags ^ dev_flags) & (MLX4_FLAG_MASTER | MLX4_FLAG_SLAVE)) { in mlx4_load_one()
2961 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_VHCR); in mlx4_load_one()
2962 dev->flags = dev_flags; in mlx4_load_one()
2963 err = mlx4_cmd_init(dev); in mlx4_load_one()
2968 mlx4_err(dev, "Failed to init VHCR command interface, aborting\n"); in mlx4_load_one()
2972 dev->flags = dev_flags; in mlx4_load_one()
2975 if (!SRIOV_VALID_STATE(dev->flags)) { in mlx4_load_one()
2976 mlx4_err(dev, "Invalid SRIOV state\n"); in mlx4_load_one()
2985 if (!mlx4_is_slave(dev)) in mlx4_load_one()
2986 mlx4_check_pcie_caps(dev); in mlx4_load_one()
2990 if (mlx4_is_master(dev)) { in mlx4_load_one()
2993 mlx4_foreach_port(i, dev, MLX4_PORT_TYPE_IB) in mlx4_load_one()
2998 mlx4_err(dev, in mlx4_load_one()
3003 if (dev->caps.num_ports < 2 && in mlx4_load_one()
3006 mlx4_err(dev, in mlx4_load_one()
3008 dev->caps.num_ports); in mlx4_load_one()
3011 memcpy(dev->persist->nvfs, nvfs, sizeof(dev->persist->nvfs)); in mlx4_load_one()
3014 i < sizeof(dev->persist->nvfs)/ in mlx4_load_one()
3015 sizeof(dev->persist->nvfs[0]); i++) { in mlx4_load_one()
3018 for (j = 0; j < dev->persist->nvfs[i]; ++sum, ++j) { in mlx4_load_one()
3019 dev->dev_vfs[sum].min_port = i < 2 ? i + 1 : 1; in mlx4_load_one()
3020 dev->dev_vfs[sum].n_ports = i < 2 ? 1 : in mlx4_load_one()
3021 dev->caps.num_ports; in mlx4_load_one()
3028 err = mlx4_multi_func_init(dev); in mlx4_load_one()
3030 mlx4_err(dev, "Failed to init master mfunc interface, aborting.\n"); in mlx4_load_one()
3035 err = mlx4_alloc_eq_table(dev); in mlx4_load_one()
3042 mlx4_enable_msi_x(dev); in mlx4_load_one()
3043 if ((mlx4_is_mfunc(dev)) && in mlx4_load_one()
3044 !(dev->flags & MLX4_FLAG_MSI_X)) { in mlx4_load_one()
3046 mlx4_err(dev, "INTx is not supported in multi-function mode, aborting\n"); in mlx4_load_one()
3050 if (!mlx4_is_slave(dev)) { in mlx4_load_one()
3051 err = mlx4_init_steering(dev); in mlx4_load_one()
3056 err = mlx4_setup_hca(dev); in mlx4_load_one()
3057 if (err == -EBUSY && (dev->flags & MLX4_FLAG_MSI_X) && in mlx4_load_one()
3058 !mlx4_is_mfunc(dev)) { in mlx4_load_one()
3059 dev->flags &= ~MLX4_FLAG_MSI_X; in mlx4_load_one()
3060 dev->caps.num_comp_vectors = 1; in mlx4_load_one()
3061 dev->caps.comp_pool = 0; in mlx4_load_one()
3063 err = mlx4_setup_hca(dev); in mlx4_load_one()
3069 mlx4_init_quotas(dev); in mlx4_load_one()
3073 if (mlx4_is_master(dev)) { in mlx4_load_one()
3074 err = mlx4_ARM_COMM_CHANNEL(dev); in mlx4_load_one()
3076 mlx4_err(dev, " Failed to arm comm channel eq: %x\n", in mlx4_load_one()
3082 for (port = 1; port <= dev->caps.num_ports; port++) { in mlx4_load_one()
3083 err = mlx4_init_port_info(dev, port); in mlx4_load_one()
3091 err = mlx4_register_device(dev); in mlx4_load_one()
3095 mlx4_request_modules(dev); in mlx4_load_one()
3097 mlx4_sense_init(dev); in mlx4_load_one()
3098 mlx4_start_sense(dev); in mlx4_load_one()
3102 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3112 mlx4_cleanup_counters_table(dev); in mlx4_load_one()
3113 mlx4_cleanup_qp_table(dev); in mlx4_load_one()
3114 mlx4_cleanup_srq_table(dev); in mlx4_load_one()
3115 mlx4_cleanup_cq_table(dev); in mlx4_load_one()
3116 mlx4_cmd_use_polling(dev); in mlx4_load_one()
3117 mlx4_cleanup_eq_table(dev); in mlx4_load_one()
3118 mlx4_cleanup_mcg_table(dev); in mlx4_load_one()
3119 mlx4_cleanup_mr_table(dev); in mlx4_load_one()
3120 mlx4_cleanup_xrcd_table(dev); in mlx4_load_one()
3121 mlx4_cleanup_pd_table(dev); in mlx4_load_one()
3122 mlx4_cleanup_uar_table(dev); in mlx4_load_one()
3125 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3126 mlx4_clear_steering(dev); in mlx4_load_one()
3129 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_load_one()
3133 mlx4_free_eq_table(dev); in mlx4_load_one()
3136 if (mlx4_is_master(dev)) { in mlx4_load_one()
3137 mlx4_free_resource_tracker(dev, RES_TR_FREE_STRUCTS_ONLY); in mlx4_load_one()
3138 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3141 if (mlx4_is_slave(dev)) { in mlx4_load_one()
3142 kfree(dev->caps.qp0_qkey); in mlx4_load_one()
3143 kfree(dev->caps.qp0_tunnel); in mlx4_load_one()
3144 kfree(dev->caps.qp0_proxy); in mlx4_load_one()
3145 kfree(dev->caps.qp1_tunnel); in mlx4_load_one()
3146 kfree(dev->caps.qp1_proxy); in mlx4_load_one()
3150 mlx4_close_hca(dev); in mlx4_load_one()
3153 mlx4_close_fw(dev); in mlx4_load_one()
3156 if (mlx4_is_slave(dev)) in mlx4_load_one()
3157 mlx4_multi_func_cleanup(dev); in mlx4_load_one()
3160 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_load_one()
3163 if (dev->flags & MLX4_FLAG_SRIOV && !existing_vfs) { in mlx4_load_one()
3165 dev->flags &= ~MLX4_FLAG_SRIOV; in mlx4_load_one()
3168 if (mlx4_is_master(dev) && dev->persist->num_vfs && !reset_flow) in mlx4_load_one()
3171 kfree(priv->dev.dev_vfs); in mlx4_load_one()
3173 if (!mlx4_is_slave(dev)) in mlx4_load_one()
3174 mlx4_free_ownership(dev); in mlx4_load_one()
3195 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); in __mlx4_init_one()
3207 dev_err(&pdev->dev, "num_vfs module parameter cannot be negative\n"); in __mlx4_init_one()
3216 dev_err(&pdev->dev, "probe_vf module parameter cannot be negative or greater than num_vfs\n"); in __mlx4_init_one()
3222 dev_err(&pdev->dev, in __mlx4_init_one()
3231 dev_err(&pdev->dev, in __mlx4_init_one()
3243 …dev_err(&pdev->dev, "Missing DCS, aborting (driver_data: 0x%x, pci_resource_flags(pdev, 0):0x%lx)\… in __mlx4_init_one()
3249 dev_err(&pdev->dev, "Missing UAR, aborting\n"); in __mlx4_init_one()
3256 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n"); in __mlx4_init_one()
3264 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); in __mlx4_init_one()
3267 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); in __mlx4_init_one()
3273 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit consistent PCI DMA mask\n"); in __mlx4_init_one()
3276 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, aborting\n"); in __mlx4_init_one()
3282 dma_set_max_seg_size(&pdev->dev, 1024 * 1024 * 1024); in __mlx4_init_one()
3301 dev_warn(&pdev->dev, "Skipping virtual function:%d\n", in __mlx4_init_one()
3309 err = mlx4_catas_init(&priv->dev); in __mlx4_init_one()
3320 mlx4_catas_end(&priv->dev); in __mlx4_init_one()
3334 struct mlx4_dev *dev; in mlx4_init_one() local
3343 dev = &priv->dev; in mlx4_init_one()
3344 dev->persist = kzalloc(sizeof(*dev->persist), GFP_KERNEL); in mlx4_init_one()
3345 if (!dev->persist) { in mlx4_init_one()
3349 dev->persist->pdev = pdev; in mlx4_init_one()
3350 dev->persist->dev = dev; in mlx4_init_one()
3351 pci_set_drvdata(pdev, dev->persist); in mlx4_init_one()
3353 mutex_init(&dev->persist->device_state_mutex); in mlx4_init_one()
3354 mutex_init(&dev->persist->interface_state_mutex); in mlx4_init_one()
3358 kfree(dev->persist); in mlx4_init_one()
3367 static void mlx4_clean_dev(struct mlx4_dev *dev) in mlx4_clean_dev() argument
3369 struct mlx4_dev_persistent *persist = dev->persist; in mlx4_clean_dev()
3370 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_clean_dev()
3371 unsigned long flags = (dev->flags & RESET_PERSIST_MASK_FLAGS); in mlx4_clean_dev()
3374 priv->dev.persist = persist; in mlx4_clean_dev()
3375 priv->dev.flags = flags; in mlx4_clean_dev()
3381 struct mlx4_dev *dev = persist->dev; in mlx4_unload_one() local
3382 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_unload_one()
3390 for (i = 0; i < dev->caps.num_ports; i++) { in mlx4_unload_one()
3391 dev->persist->curr_port_type[i] = dev->caps.port_type[i + 1]; in mlx4_unload_one()
3392 dev->persist->curr_port_poss_type[i] = dev->caps. in mlx4_unload_one()
3398 mlx4_stop_sense(dev); in mlx4_unload_one()
3399 mlx4_unregister_device(dev); in mlx4_unload_one()
3401 for (p = 1; p <= dev->caps.num_ports; p++) { in mlx4_unload_one()
3403 mlx4_CLOSE_PORT(dev, p); in mlx4_unload_one()
3406 if (mlx4_is_master(dev)) in mlx4_unload_one()
3407 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
3410 mlx4_cleanup_counters_table(dev); in mlx4_unload_one()
3411 mlx4_cleanup_qp_table(dev); in mlx4_unload_one()
3412 mlx4_cleanup_srq_table(dev); in mlx4_unload_one()
3413 mlx4_cleanup_cq_table(dev); in mlx4_unload_one()
3414 mlx4_cmd_use_polling(dev); in mlx4_unload_one()
3415 mlx4_cleanup_eq_table(dev); in mlx4_unload_one()
3416 mlx4_cleanup_mcg_table(dev); in mlx4_unload_one()
3417 mlx4_cleanup_mr_table(dev); in mlx4_unload_one()
3418 mlx4_cleanup_xrcd_table(dev); in mlx4_unload_one()
3419 mlx4_cleanup_pd_table(dev); in mlx4_unload_one()
3421 if (mlx4_is_master(dev)) in mlx4_unload_one()
3422 mlx4_free_resource_tracker(dev, in mlx4_unload_one()
3426 mlx4_uar_free(dev, &priv->driver_uar); in mlx4_unload_one()
3427 mlx4_cleanup_uar_table(dev); in mlx4_unload_one()
3428 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
3429 mlx4_clear_steering(dev); in mlx4_unload_one()
3430 mlx4_free_eq_table(dev); in mlx4_unload_one()
3431 if (mlx4_is_master(dev)) in mlx4_unload_one()
3432 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
3433 mlx4_close_hca(dev); in mlx4_unload_one()
3434 mlx4_close_fw(dev); in mlx4_unload_one()
3435 if (mlx4_is_slave(dev)) in mlx4_unload_one()
3436 mlx4_multi_func_cleanup(dev); in mlx4_unload_one()
3437 mlx4_cmd_cleanup(dev, MLX4_CMD_CLEANUP_ALL); in mlx4_unload_one()
3439 if (dev->flags & MLX4_FLAG_MSI_X) in mlx4_unload_one()
3442 if (!mlx4_is_slave(dev)) in mlx4_unload_one()
3443 mlx4_free_ownership(dev); in mlx4_unload_one()
3445 kfree(dev->caps.qp0_qkey); in mlx4_unload_one()
3446 kfree(dev->caps.qp0_tunnel); in mlx4_unload_one()
3447 kfree(dev->caps.qp0_proxy); in mlx4_unload_one()
3448 kfree(dev->caps.qp1_tunnel); in mlx4_unload_one()
3449 kfree(dev->caps.qp1_proxy); in mlx4_unload_one()
3450 kfree(dev->dev_vfs); in mlx4_unload_one()
3452 mlx4_clean_dev(dev); in mlx4_unload_one()
3460 struct mlx4_dev *dev = persist->dev; in mlx4_remove_one() local
3461 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_remove_one()
3469 if (mlx4_is_master(dev) && dev->flags & MLX4_FLAG_SRIOV) { in mlx4_remove_one()
3470 active_vfs = mlx4_how_many_lives_vf(dev); in mlx4_remove_one()
3483 mlx4_info(dev, "%s: interface is down\n", __func__); in mlx4_remove_one()
3484 mlx4_catas_end(dev); in mlx4_remove_one()
3485 if (dev->flags & MLX4_FLAG_SRIOV && !active_vfs) { in mlx4_remove_one()
3486 mlx4_warn(dev, "Disabling SR-IOV\n"); in mlx4_remove_one()
3492 kfree(dev->persist); in mlx4_remove_one()
3497 static int restore_current_port_types(struct mlx4_dev *dev, in restore_current_port_types() argument
3501 struct mlx4_priv *priv = mlx4_priv(dev); in restore_current_port_types()
3504 mlx4_stop_sense(dev); in restore_current_port_types()
3507 for (i = 0; i < dev->caps.num_ports; i++) in restore_current_port_types()
3508 dev->caps.possible_type[i + 1] = poss_types[i]; in restore_current_port_types()
3509 err = mlx4_change_port_types(dev, types); in restore_current_port_types()
3510 mlx4_start_sense(dev); in restore_current_port_types()
3519 struct mlx4_dev *dev = persist->dev; in mlx4_restart_one() local
3520 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_restart_one()
3525 total_vfs = dev->persist->num_vfs; in mlx4_restart_one()
3526 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_restart_one()
3531 mlx4_err(dev, "%s: ERROR: mlx4_load_one failed, pci_name=%s, err=%d\n", in mlx4_restart_one()
3536 err = restore_current_port_types(dev, dev->persist->curr_port_type, in mlx4_restart_one()
3537 dev->persist->curr_port_poss_type); in mlx4_restart_one()
3539 mlx4_err(dev, "could not restore original port types (%d)\n", in mlx4_restart_one()
3598 mlx4_err(persist->dev, "mlx4_pci_err_detected was called\n"); in mlx4_pci_err_detected()
3616 struct mlx4_dev *dev = persist->dev; in mlx4_pci_slot_reset() local
3617 struct mlx4_priv *priv = mlx4_priv(dev); in mlx4_pci_slot_reset()
3622 mlx4_err(dev, "mlx4_pci_slot_reset was called\n"); in mlx4_pci_slot_reset()
3625 mlx4_err(dev, "Can not re-enable device, ret=%d\n", ret); in mlx4_pci_slot_reset()
3633 total_vfs = dev->persist->num_vfs; in mlx4_pci_slot_reset()
3634 memcpy(nvfs, dev->persist->nvfs, sizeof(dev->persist->nvfs)); in mlx4_pci_slot_reset()
3641 mlx4_err(dev, "%s: mlx4_load_one failed, ret=%d\n", in mlx4_pci_slot_reset()
3646 ret = restore_current_port_types(dev, dev->persist-> in mlx4_pci_slot_reset()
3647 curr_port_type, dev->persist-> in mlx4_pci_slot_reset()
3650 mlx4_err(dev, "could not restore original port types (%d)\n", ret); in mlx4_pci_slot_reset()
3662 mlx4_info(persist->dev, "mlx4_shutdown was called\n"); in mlx4_shutdown()