Lines Matching refs:dev
188 static int wait_fw_init(struct mlx5_core_dev *dev, u32 max_wait_mili, in wait_fw_init() argument
197 fw_initializing = ioread32be(&dev->iseg->initializing); in wait_fw_init()
201 test_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state)) { in wait_fw_init()
206 mlx5_core_warn(dev, "Waiting for FW initialization, timeout abort in %ds (0x%x)\n", in wait_fw_init()
210 msleep(mlx5_tout_ms(dev, FW_PRE_INIT_WAIT)); in wait_fw_init()
216 static void mlx5_set_driver_version(struct mlx5_core_dev *dev) in mlx5_set_driver_version() argument
224 if (!MLX5_CAP_GEN(dev, driver_version)) in mlx5_set_driver_version()
250 mlx5_cmd_exec_in(dev, set_driver_version, in); in mlx5_set_driver_version()
257 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); in set_dma_caps()
259 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask\n"); in set_dma_caps()
260 err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)); in set_dma_caps()
262 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting\n"); in set_dma_caps()
267 dma_set_max_seg_size(&pdev->dev, 2u * 1024 * 1024 * 1024); in set_dma_caps()
271 static int mlx5_pci_enable_device(struct mlx5_core_dev *dev) in mlx5_pci_enable_device() argument
273 struct pci_dev *pdev = dev->pdev; in mlx5_pci_enable_device()
276 mutex_lock(&dev->pci_status_mutex); in mlx5_pci_enable_device()
277 if (dev->pci_status == MLX5_PCI_STATUS_DISABLED) { in mlx5_pci_enable_device()
280 dev->pci_status = MLX5_PCI_STATUS_ENABLED; in mlx5_pci_enable_device()
282 mutex_unlock(&dev->pci_status_mutex); in mlx5_pci_enable_device()
287 static void mlx5_pci_disable_device(struct mlx5_core_dev *dev) in mlx5_pci_disable_device() argument
289 struct pci_dev *pdev = dev->pdev; in mlx5_pci_disable_device()
291 mutex_lock(&dev->pci_status_mutex); in mlx5_pci_disable_device()
292 if (dev->pci_status == MLX5_PCI_STATUS_ENABLED) { in mlx5_pci_disable_device()
294 dev->pci_status = MLX5_PCI_STATUS_DISABLED; in mlx5_pci_disable_device()
296 mutex_unlock(&dev->pci_status_mutex); in mlx5_pci_disable_device()
304 dev_err(&pdev->dev, "Missing registers BAR, aborting\n"); in request_bar()
310 dev_err(&pdev->dev, "Couldn't get PCI resources, aborting\n"); in request_bar()
325 static u16 to_fw_pkey_sz(struct mlx5_core_dev *dev, u32 size) in to_fw_pkey_sz() argument
341 mlx5_core_warn(dev, "invalid pkey table size %d\n", size); in to_fw_pkey_sz()
346 void mlx5_core_uplink_netdev_set(struct mlx5_core_dev *dev, struct net_device *netdev) in mlx5_core_uplink_netdev_set() argument
348 mutex_lock(&dev->mlx5e_res.uplink_netdev_lock); in mlx5_core_uplink_netdev_set()
349 dev->mlx5e_res.uplink_netdev = netdev; in mlx5_core_uplink_netdev_set()
350 mlx5_blocking_notifier_call_chain(dev, MLX5_DRIVER_EVENT_UPLINK_NETDEV, in mlx5_core_uplink_netdev_set()
352 mutex_unlock(&dev->mlx5e_res.uplink_netdev_lock); in mlx5_core_uplink_netdev_set()
355 void mlx5_core_uplink_netdev_event_replay(struct mlx5_core_dev *dev) in mlx5_core_uplink_netdev_event_replay() argument
357 mutex_lock(&dev->mlx5e_res.uplink_netdev_lock); in mlx5_core_uplink_netdev_event_replay()
358 mlx5_blocking_notifier_call_chain(dev, MLX5_DRIVER_EVENT_UPLINK_NETDEV, in mlx5_core_uplink_netdev_event_replay()
359 dev->mlx5e_res.uplink_netdev); in mlx5_core_uplink_netdev_event_replay()
360 mutex_unlock(&dev->mlx5e_res.uplink_netdev_lock); in mlx5_core_uplink_netdev_event_replay()
364 void mlx5_core_mp_event_replay(struct mlx5_core_dev *dev, u32 event, void *data) in mlx5_core_mp_event_replay() argument
366 mlx5_blocking_notifier_call_chain(dev, event, data); in mlx5_core_mp_event_replay()
370 int mlx5_core_get_caps_mode(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type, in mlx5_core_get_caps_mode() argument
386 err = mlx5_cmd_exec_inout(dev, query_hca_cap, in, out); in mlx5_core_get_caps_mode()
388 mlx5_core_warn(dev, in mlx5_core_get_caps_mode()
398 memcpy(dev->caps.hca[cap_type]->max, hca_caps, in mlx5_core_get_caps_mode()
402 memcpy(dev->caps.hca[cap_type]->cur, hca_caps, in mlx5_core_get_caps_mode()
406 mlx5_core_warn(dev, in mlx5_core_get_caps_mode()
417 int mlx5_core_get_caps(struct mlx5_core_dev *dev, enum mlx5_cap_type cap_type) in mlx5_core_get_caps() argument
421 ret = mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_CUR); in mlx5_core_get_caps()
424 return mlx5_core_get_caps_mode(dev, cap_type, HCA_CAP_OPMOD_GET_MAX); in mlx5_core_get_caps()
427 static int set_caps(struct mlx5_core_dev *dev, void *in, int opmod) in set_caps() argument
431 return mlx5_cmd_exec_in(dev, set_hca_cap, in); in set_caps()
434 static int handle_hca_cap_atomic(struct mlx5_core_dev *dev, void *set_ctx) in handle_hca_cap_atomic() argument
440 if (!MLX5_CAP_GEN(dev, atomic)) in handle_hca_cap_atomic()
443 err = mlx5_core_get_caps(dev, MLX5_CAP_ATOMIC); in handle_hca_cap_atomic()
448 MLX5_CAP_ATOMIC(dev, in handle_hca_cap_atomic()
460 return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ATOMIC); in handle_hca_cap_atomic()
463 static int handle_hca_cap_odp(struct mlx5_core_dev *dev, void *set_ctx) in handle_hca_cap_odp() argument
470 !MLX5_CAP_GEN(dev, pg)) in handle_hca_cap_odp()
473 err = mlx5_core_get_caps(dev, MLX5_CAP_ODP); in handle_hca_cap_odp()
478 memcpy(set_hca_cap, dev->caps.hca[MLX5_CAP_ODP]->cur, in handle_hca_cap_odp()
481 #define ODP_CAP_SET_MAX(dev, field) \ in handle_hca_cap_odp() argument
483 u32 _res = MLX5_CAP_ODP_MAX(dev, field); \ in handle_hca_cap_odp()
490 ODP_CAP_SET_MAX(dev, ud_odp_caps.srq_receive); in handle_hca_cap_odp()
491 ODP_CAP_SET_MAX(dev, rc_odp_caps.srq_receive); in handle_hca_cap_odp()
492 ODP_CAP_SET_MAX(dev, xrc_odp_caps.srq_receive); in handle_hca_cap_odp()
493 ODP_CAP_SET_MAX(dev, xrc_odp_caps.send); in handle_hca_cap_odp()
494 ODP_CAP_SET_MAX(dev, xrc_odp_caps.receive); in handle_hca_cap_odp()
495 ODP_CAP_SET_MAX(dev, xrc_odp_caps.write); in handle_hca_cap_odp()
496 ODP_CAP_SET_MAX(dev, xrc_odp_caps.read); in handle_hca_cap_odp()
497 ODP_CAP_SET_MAX(dev, xrc_odp_caps.atomic); in handle_hca_cap_odp()
498 ODP_CAP_SET_MAX(dev, dc_odp_caps.srq_receive); in handle_hca_cap_odp()
499 ODP_CAP_SET_MAX(dev, dc_odp_caps.send); in handle_hca_cap_odp()
500 ODP_CAP_SET_MAX(dev, dc_odp_caps.receive); in handle_hca_cap_odp()
501 ODP_CAP_SET_MAX(dev, dc_odp_caps.write); in handle_hca_cap_odp()
502 ODP_CAP_SET_MAX(dev, dc_odp_caps.read); in handle_hca_cap_odp()
503 ODP_CAP_SET_MAX(dev, dc_odp_caps.atomic); in handle_hca_cap_odp()
508 return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ODP); in handle_hca_cap_odp()
511 static int max_uc_list_get_devlink_param(struct mlx5_core_dev *dev) in max_uc_list_get_devlink_param() argument
513 struct devlink *devlink = priv_to_devlink(dev); in max_uc_list_get_devlink_param()
522 mlx5_core_dbg(dev, "Failed to get param. err = %d\n", err); in max_uc_list_get_devlink_param()
526 bool mlx5_is_roce_on(struct mlx5_core_dev *dev) in mlx5_is_roce_on() argument
528 struct devlink *devlink = priv_to_devlink(dev); in mlx5_is_roce_on()
539 mlx5_core_dbg(dev, "Failed to get param. err = %d\n", err); in mlx5_is_roce_on()
540 return MLX5_CAP_GEN(dev, roce); in mlx5_is_roce_on()
544 static int handle_hca_cap_2(struct mlx5_core_dev *dev, void *set_ctx) in handle_hca_cap_2() argument
549 if (!MLX5_CAP_GEN_MAX(dev, hca_cap_2)) in handle_hca_cap_2()
552 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL_2); in handle_hca_cap_2()
556 if (!MLX5_CAP_GEN_2_MAX(dev, sw_vhca_id_valid) || in handle_hca_cap_2()
557 !(dev->priv.sw_vhca_id > 0)) in handle_hca_cap_2()
562 memcpy(set_hca_cap, dev->caps.hca[MLX5_CAP_GENERAL_2]->cur, in handle_hca_cap_2()
566 return set_caps(dev, set_ctx, MLX5_CAP_GENERAL_2); in handle_hca_cap_2()
569 static int handle_hca_cap(struct mlx5_core_dev *dev, void *set_ctx) in handle_hca_cap() argument
571 struct mlx5_profile *prof = &dev->profile; in handle_hca_cap()
576 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL); in handle_hca_cap()
582 memcpy(set_hca_cap, dev->caps.hca[MLX5_CAP_GENERAL]->cur, in handle_hca_cap()
585 mlx5_core_dbg(dev, "Current Pkey table size %d Setting new size %d\n", in handle_hca_cap()
586 mlx5_to_sw_pkey_sz(MLX5_CAP_GEN(dev, pkey_table_size)), in handle_hca_cap()
590 to_fw_pkey_sz(dev, 128)); in handle_hca_cap()
594 prof->log_max_qp = min_t(u8, 18, MLX5_CAP_GEN_MAX(dev, log_max_qp)); in handle_hca_cap()
595 } else if (MLX5_CAP_GEN_MAX(dev, log_max_qp) < prof->log_max_qp) { in handle_hca_cap()
596 …mlx5_core_warn(dev, "log_max_qp value in current profile is %d, changing it to HCA capability limi… in handle_hca_cap()
598 MLX5_CAP_GEN_MAX(dev, log_max_qp)); in handle_hca_cap()
599 prof->log_max_qp = MLX5_CAP_GEN_MAX(dev, log_max_qp); in handle_hca_cap()
611 if (MLX5_CAP_GEN_MAX(dev, uar_4k) && PAGE_SIZE > 4096) in handle_hca_cap()
616 if (MLX5_CAP_GEN_MAX(dev, cache_line_128byte)) in handle_hca_cap()
622 if (MLX5_CAP_GEN_MAX(dev, dct)) in handle_hca_cap()
625 if (MLX5_CAP_GEN_MAX(dev, pci_sync_for_fw_update_event)) in handle_hca_cap()
627 if (MLX5_CAP_GEN_MAX(dev, pci_sync_for_fw_update_with_driver_unload)) in handle_hca_cap()
631 if (MLX5_CAP_GEN_MAX(dev, num_vhca_ports)) in handle_hca_cap()
635 MLX5_CAP_GEN_MAX(dev, num_vhca_ports)); in handle_hca_cap()
637 if (MLX5_CAP_GEN_MAX(dev, release_all_pages)) in handle_hca_cap()
640 if (MLX5_CAP_GEN_MAX(dev, mkey_by_name)) in handle_hca_cap()
643 mlx5_vhca_state_cap_handle(dev, set_hca_cap); in handle_hca_cap()
645 if (MLX5_CAP_GEN_MAX(dev, num_total_dynamic_vf_msix)) in handle_hca_cap()
647 MLX5_CAP_GEN_MAX(dev, num_total_dynamic_vf_msix)); in handle_hca_cap()
649 if (MLX5_CAP_GEN(dev, roce_rw_supported) && MLX5_CAP_GEN_MAX(dev, roce)) in handle_hca_cap()
651 mlx5_is_roce_on(dev)); in handle_hca_cap()
653 max_uc_list = max_uc_list_get_devlink_param(dev); in handle_hca_cap()
658 return set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_GENERAL_DEVICE); in handle_hca_cap()
675 static bool is_roce_fw_disabled(struct mlx5_core_dev *dev) in is_roce_fw_disabled() argument
677 return (MLX5_CAP_GEN(dev, roce_rw_supported) && !mlx5_is_roce_on(dev)) || in is_roce_fw_disabled()
678 (!MLX5_CAP_GEN(dev, roce_rw_supported) && !MLX5_CAP_GEN(dev, roce)); in is_roce_fw_disabled()
681 static int handle_hca_cap_roce(struct mlx5_core_dev *dev, void *set_ctx) in handle_hca_cap_roce() argument
686 if (is_roce_fw_disabled(dev)) in handle_hca_cap_roce()
689 err = mlx5_core_get_caps(dev, MLX5_CAP_ROCE); in handle_hca_cap_roce()
693 if (MLX5_CAP_ROCE(dev, sw_r_roce_src_udp_port) || in handle_hca_cap_roce()
694 !MLX5_CAP_ROCE_MAX(dev, sw_r_roce_src_udp_port)) in handle_hca_cap_roce()
698 memcpy(set_hca_cap, dev->caps.hca[MLX5_CAP_ROCE]->cur, in handle_hca_cap_roce()
702 if (MLX5_CAP_ROCE_MAX(dev, qp_ooo_transmit_default)) in handle_hca_cap_roce()
705 err = set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_ROCE); in handle_hca_cap_roce()
709 static int handle_hca_cap_port_selection(struct mlx5_core_dev *dev, in handle_hca_cap_port_selection() argument
715 if (!MLX5_CAP_GEN(dev, port_selection_cap)) in handle_hca_cap_port_selection()
718 err = mlx5_core_get_caps(dev, MLX5_CAP_PORT_SELECTION); in handle_hca_cap_port_selection()
722 if (MLX5_CAP_PORT_SELECTION(dev, port_select_flow_table_bypass) || in handle_hca_cap_port_selection()
723 !MLX5_CAP_PORT_SELECTION_MAX(dev, port_select_flow_table_bypass)) in handle_hca_cap_port_selection()
727 memcpy(set_hca_cap, dev->caps.hca[MLX5_CAP_PORT_SELECTION]->cur, in handle_hca_cap_port_selection()
731 err = set_caps(dev, set_ctx, MLX5_SET_HCA_CAP_OP_MOD_PORT_SELECTION); in handle_hca_cap_port_selection()
736 static int set_hca_cap(struct mlx5_core_dev *dev) in set_hca_cap() argument
746 err = handle_hca_cap(dev, set_ctx); in set_hca_cap()
748 mlx5_core_err(dev, "handle_hca_cap failed\n"); in set_hca_cap()
753 err = handle_hca_cap_atomic(dev, set_ctx); in set_hca_cap()
755 mlx5_core_err(dev, "handle_hca_cap_atomic failed\n"); in set_hca_cap()
760 err = handle_hca_cap_odp(dev, set_ctx); in set_hca_cap()
762 mlx5_core_err(dev, "handle_hca_cap_odp failed\n"); in set_hca_cap()
767 err = handle_hca_cap_roce(dev, set_ctx); in set_hca_cap()
769 mlx5_core_err(dev, "handle_hca_cap_roce failed\n"); in set_hca_cap()
774 err = handle_hca_cap_2(dev, set_ctx); in set_hca_cap()
776 mlx5_core_err(dev, "handle_hca_cap_2 failed\n"); in set_hca_cap()
781 err = handle_hca_cap_port_selection(dev, set_ctx); in set_hca_cap()
783 mlx5_core_err(dev, "handle_hca_cap_port_selection failed\n"); in set_hca_cap()
792 static int set_hca_ctrl(struct mlx5_core_dev *dev) in set_hca_ctrl() argument
798 if (!mlx5_core_is_pf(dev)) in set_hca_ctrl()
803 err = mlx5_core_access_reg(dev, &he_in, sizeof(he_in), in set_hca_ctrl()
809 static int mlx5_core_set_hca_defaults(struct mlx5_core_dev *dev) in mlx5_core_set_hca_defaults() argument
814 if (MLX5_CAP_GEN(dev, port_type) == MLX5_CAP_PORT_TYPE_ETH) in mlx5_core_set_hca_defaults()
815 ret = mlx5_nic_vport_update_local_lb(dev, false); in mlx5_core_set_hca_defaults()
820 int mlx5_core_enable_hca(struct mlx5_core_dev *dev, u16 func_id) in mlx5_core_enable_hca() argument
827 dev->caps.embedded_cpu); in mlx5_core_enable_hca()
828 return mlx5_cmd_exec_in(dev, enable_hca, in); in mlx5_core_enable_hca()
831 int mlx5_core_disable_hca(struct mlx5_core_dev *dev, u16 func_id) in mlx5_core_disable_hca() argument
838 dev->caps.embedded_cpu); in mlx5_core_disable_hca()
839 return mlx5_cmd_exec_in(dev, disable_hca, in); in mlx5_core_disable_hca()
842 static int mlx5_core_set_issi(struct mlx5_core_dev *dev) in mlx5_core_set_issi() argument
850 err = mlx5_cmd_exec_inout(dev, query_issi, query_in, query_out); in mlx5_core_set_issi()
856 mlx5_core_err(dev, "Failed to query ISSI err(%d) status(%d) synd(%d)\n", in mlx5_core_set_issi()
861 mlx5_core_warn(dev, "Query ISSI is not supported by FW, ISSI is 0\n"); in mlx5_core_set_issi()
862 dev->issi = 0; in mlx5_core_set_issi()
873 err = mlx5_cmd_exec_in(dev, set_issi, set_in); in mlx5_core_set_issi()
875 mlx5_core_err(dev, "Failed to set ISSI to 1 err(%d)\n", in mlx5_core_set_issi()
880 dev->issi = 1; in mlx5_core_set_issi()
890 static int mlx5_pci_init(struct mlx5_core_dev *dev, struct pci_dev *pdev, in mlx5_pci_init() argument
895 mutex_init(&dev->pci_status_mutex); in mlx5_pci_init()
896 pci_set_drvdata(dev->pdev, dev); in mlx5_pci_init()
898 dev->bar_addr = pci_resource_start(pdev, 0); in mlx5_pci_init()
900 err = mlx5_pci_enable_device(dev); in mlx5_pci_init()
902 mlx5_core_err(dev, "Cannot enable PCI device, aborting\n"); in mlx5_pci_init()
908 mlx5_core_err(dev, "error requesting BARs, aborting\n"); in mlx5_pci_init()
916 mlx5_core_err(dev, "Failed setting DMA capabilities mask, aborting\n"); in mlx5_pci_init()
923 mlx5_core_dbg(dev, "Enabling pci atomics failed\n"); in mlx5_pci_init()
925 dev->iseg_base = dev->bar_addr; in mlx5_pci_init()
926 dev->iseg = ioremap(dev->iseg_base, sizeof(*dev->iseg)); in mlx5_pci_init()
927 if (!dev->iseg) { in mlx5_pci_init()
929 mlx5_core_err(dev, "Failed mapping initialization segment, aborting\n"); in mlx5_pci_init()
933 mlx5_pci_vsc_init(dev); in mlx5_pci_init()
937 release_bar(dev->pdev); in mlx5_pci_init()
939 mlx5_pci_disable_device(dev); in mlx5_pci_init()
943 static void mlx5_pci_close(struct mlx5_core_dev *dev) in mlx5_pci_close() argument
949 mlx5_drain_health_wq(dev); in mlx5_pci_close()
950 iounmap(dev->iseg); in mlx5_pci_close()
951 release_bar(dev->pdev); in mlx5_pci_close()
952 mlx5_pci_disable_device(dev); in mlx5_pci_close()
955 static int mlx5_init_once(struct mlx5_core_dev *dev) in mlx5_init_once() argument
959 dev->priv.devc = mlx5_devcom_register_device(dev); in mlx5_init_once()
960 if (IS_ERR(dev->priv.devc)) in mlx5_init_once()
961 mlx5_core_warn(dev, "failed to register devcom device %ld\n", in mlx5_init_once()
962 PTR_ERR(dev->priv.devc)); in mlx5_init_once()
964 err = mlx5_query_board_id(dev); in mlx5_init_once()
966 mlx5_core_err(dev, "query board id failed\n"); in mlx5_init_once()
970 err = mlx5_irq_table_init(dev); in mlx5_init_once()
972 mlx5_core_err(dev, "failed to initialize irq table\n"); in mlx5_init_once()
976 err = mlx5_eq_table_init(dev); in mlx5_init_once()
978 mlx5_core_err(dev, "failed to initialize eq\n"); in mlx5_init_once()
982 err = mlx5_events_init(dev); in mlx5_init_once()
984 mlx5_core_err(dev, "failed to initialize events\n"); in mlx5_init_once()
988 err = mlx5_fw_reset_init(dev); in mlx5_init_once()
990 mlx5_core_err(dev, "failed to initialize fw reset events\n"); in mlx5_init_once()
994 mlx5_cq_debugfs_init(dev); in mlx5_init_once()
996 mlx5_init_reserved_gids(dev); in mlx5_init_once()
998 mlx5_init_clock(dev); in mlx5_init_once()
1000 dev->vxlan = mlx5_vxlan_create(dev); in mlx5_init_once()
1001 dev->geneve = mlx5_geneve_create(dev); in mlx5_init_once()
1003 err = mlx5_init_rl_table(dev); in mlx5_init_once()
1005 mlx5_core_err(dev, "Failed to init rate limiting\n"); in mlx5_init_once()
1009 err = mlx5_mpfs_init(dev); in mlx5_init_once()
1011 mlx5_core_err(dev, "Failed to init l2 table %d\n", err); in mlx5_init_once()
1015 err = mlx5_sriov_init(dev); in mlx5_init_once()
1017 mlx5_core_err(dev, "Failed to init sriov %d\n", err); in mlx5_init_once()
1021 err = mlx5_eswitch_init(dev); in mlx5_init_once()
1023 mlx5_core_err(dev, "Failed to init eswitch %d\n", err); in mlx5_init_once()
1027 err = mlx5_fpga_init(dev); in mlx5_init_once()
1029 mlx5_core_err(dev, "Failed to init fpga device %d\n", err); in mlx5_init_once()
1033 err = mlx5_vhca_event_init(dev); in mlx5_init_once()
1035 mlx5_core_err(dev, "Failed to init vhca event notifier %d\n", err); in mlx5_init_once()
1039 err = mlx5_sf_hw_table_init(dev); in mlx5_init_once()
1041 mlx5_core_err(dev, "Failed to init SF HW table %d\n", err); in mlx5_init_once()
1045 err = mlx5_sf_table_init(dev); in mlx5_init_once()
1047 mlx5_core_err(dev, "Failed to init SF table %d\n", err); in mlx5_init_once()
1051 err = mlx5_fs_core_alloc(dev); in mlx5_init_once()
1053 mlx5_core_err(dev, "Failed to alloc flow steering\n"); in mlx5_init_once()
1057 dev->dm = mlx5_dm_create(dev); in mlx5_init_once()
1058 if (IS_ERR(dev->dm)) in mlx5_init_once()
1059 mlx5_core_warn(dev, "Failed to init device memory %ld\n", PTR_ERR(dev->dm)); in mlx5_init_once()
1061 dev->tracer = mlx5_fw_tracer_create(dev); in mlx5_init_once()
1062 dev->hv_vhca = mlx5_hv_vhca_create(dev); in mlx5_init_once()
1063 dev->rsc_dump = mlx5_rsc_dump_create(dev); in mlx5_init_once()
1068 mlx5_sf_table_cleanup(dev); in mlx5_init_once()
1070 mlx5_sf_hw_table_cleanup(dev); in mlx5_init_once()
1072 mlx5_vhca_event_cleanup(dev); in mlx5_init_once()
1074 mlx5_fpga_cleanup(dev); in mlx5_init_once()
1076 mlx5_eswitch_cleanup(dev->priv.eswitch); in mlx5_init_once()
1078 mlx5_sriov_cleanup(dev); in mlx5_init_once()
1080 mlx5_mpfs_cleanup(dev); in mlx5_init_once()
1082 mlx5_cleanup_rl_table(dev); in mlx5_init_once()
1084 mlx5_geneve_destroy(dev->geneve); in mlx5_init_once()
1085 mlx5_vxlan_destroy(dev->vxlan); in mlx5_init_once()
1086 mlx5_cleanup_clock(dev); in mlx5_init_once()
1087 mlx5_cleanup_reserved_gids(dev); in mlx5_init_once()
1088 mlx5_cq_debugfs_cleanup(dev); in mlx5_init_once()
1089 mlx5_fw_reset_cleanup(dev); in mlx5_init_once()
1091 mlx5_events_cleanup(dev); in mlx5_init_once()
1093 mlx5_eq_table_cleanup(dev); in mlx5_init_once()
1095 mlx5_irq_table_cleanup(dev); in mlx5_init_once()
1097 mlx5_devcom_unregister_device(dev->priv.devc); in mlx5_init_once()
1102 static void mlx5_cleanup_once(struct mlx5_core_dev *dev) in mlx5_cleanup_once() argument
1104 mlx5_rsc_dump_destroy(dev); in mlx5_cleanup_once()
1105 mlx5_hv_vhca_destroy(dev->hv_vhca); in mlx5_cleanup_once()
1106 mlx5_fw_tracer_destroy(dev->tracer); in mlx5_cleanup_once()
1107 mlx5_dm_cleanup(dev); in mlx5_cleanup_once()
1108 mlx5_fs_core_free(dev); in mlx5_cleanup_once()
1109 mlx5_sf_table_cleanup(dev); in mlx5_cleanup_once()
1110 mlx5_sf_hw_table_cleanup(dev); in mlx5_cleanup_once()
1111 mlx5_vhca_event_cleanup(dev); in mlx5_cleanup_once()
1112 mlx5_fpga_cleanup(dev); in mlx5_cleanup_once()
1113 mlx5_eswitch_cleanup(dev->priv.eswitch); in mlx5_cleanup_once()
1114 mlx5_sriov_cleanup(dev); in mlx5_cleanup_once()
1115 mlx5_mpfs_cleanup(dev); in mlx5_cleanup_once()
1116 mlx5_cleanup_rl_table(dev); in mlx5_cleanup_once()
1117 mlx5_geneve_destroy(dev->geneve); in mlx5_cleanup_once()
1118 mlx5_vxlan_destroy(dev->vxlan); in mlx5_cleanup_once()
1119 mlx5_cleanup_clock(dev); in mlx5_cleanup_once()
1120 mlx5_cleanup_reserved_gids(dev); in mlx5_cleanup_once()
1121 mlx5_cq_debugfs_cleanup(dev); in mlx5_cleanup_once()
1122 mlx5_fw_reset_cleanup(dev); in mlx5_cleanup_once()
1123 mlx5_events_cleanup(dev); in mlx5_cleanup_once()
1124 mlx5_eq_table_cleanup(dev); in mlx5_cleanup_once()
1125 mlx5_irq_table_cleanup(dev); in mlx5_cleanup_once()
1126 mlx5_devcom_unregister_device(dev->priv.devc); in mlx5_cleanup_once()
1129 static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeout) in mlx5_function_enable() argument
1133 mlx5_core_info(dev, "firmware version: %d.%d.%d\n", fw_rev_maj(dev), in mlx5_function_enable()
1134 fw_rev_min(dev), fw_rev_sub(dev)); in mlx5_function_enable()
1137 if (mlx5_core_is_pf(dev)) in mlx5_function_enable()
1138 pcie_print_link_status(dev->pdev); in mlx5_function_enable()
1142 err = wait_fw_init(dev, timeout, in mlx5_function_enable()
1143 mlx5_tout_ms(dev, FW_PRE_INIT_WARN_MESSAGE_INTERVAL)); in mlx5_function_enable()
1145 mlx5_core_err(dev, "Firmware over %llu MS in pre-initializing state, aborting\n", in mlx5_function_enable()
1150 err = mlx5_cmd_enable(dev); in mlx5_function_enable()
1152 mlx5_core_err(dev, "Failed initializing command interface, aborting\n"); in mlx5_function_enable()
1156 mlx5_tout_query_iseg(dev); in mlx5_function_enable()
1158 err = wait_fw_init(dev, mlx5_tout_ms(dev, FW_INIT), 0); in mlx5_function_enable()
1160 mlx5_core_err(dev, "Firmware over %llu MS in initializing state, aborting\n", in mlx5_function_enable()
1161 mlx5_tout_ms(dev, FW_INIT)); in mlx5_function_enable()
1165 dev->caps.embedded_cpu = mlx5_read_embedded_cpu(dev); in mlx5_function_enable()
1166 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_UP); in mlx5_function_enable()
1168 mlx5_start_health_poll(dev); in mlx5_function_enable()
1170 err = mlx5_core_enable_hca(dev, 0); in mlx5_function_enable()
1172 mlx5_core_err(dev, "enable hca failed\n"); in mlx5_function_enable()
1176 err = mlx5_core_set_issi(dev); in mlx5_function_enable()
1178 mlx5_core_err(dev, "failed to set issi\n"); in mlx5_function_enable()
1182 err = mlx5_satisfy_startup_pages(dev, 1); in mlx5_function_enable()
1184 mlx5_core_err(dev, "failed to allocate boot pages\n"); in mlx5_function_enable()
1188 err = mlx5_tout_query_dtor(dev); in mlx5_function_enable()
1190 mlx5_core_err(dev, "failed to read dtor\n"); in mlx5_function_enable()
1197 mlx5_reclaim_startup_pages(dev); in mlx5_function_enable()
1199 mlx5_core_disable_hca(dev, 0); in mlx5_function_enable()
1201 mlx5_stop_health_poll(dev, boot); in mlx5_function_enable()
1203 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN); in mlx5_function_enable()
1204 mlx5_cmd_disable(dev); in mlx5_function_enable()
1209 static void mlx5_function_disable(struct mlx5_core_dev *dev, bool boot) in mlx5_function_disable() argument
1211 mlx5_reclaim_startup_pages(dev); in mlx5_function_disable()
1212 mlx5_core_disable_hca(dev, 0); in mlx5_function_disable()
1213 mlx5_stop_health_poll(dev, boot); in mlx5_function_disable()
1214 mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN); in mlx5_function_disable()
1215 mlx5_cmd_disable(dev); in mlx5_function_disable()
1218 static int mlx5_function_open(struct mlx5_core_dev *dev) in mlx5_function_open() argument
1222 err = set_hca_ctrl(dev); in mlx5_function_open()
1224 mlx5_core_err(dev, "set_hca_ctrl failed\n"); in mlx5_function_open()
1228 err = set_hca_cap(dev); in mlx5_function_open()
1230 mlx5_core_err(dev, "set_hca_cap failed\n"); in mlx5_function_open()
1234 err = mlx5_satisfy_startup_pages(dev, 0); in mlx5_function_open()
1236 mlx5_core_err(dev, "failed to allocate init pages\n"); in mlx5_function_open()
1240 err = mlx5_cmd_init_hca(dev, sw_owner_id); in mlx5_function_open()
1242 mlx5_core_err(dev, "init hca failed\n"); in mlx5_function_open()
1246 mlx5_set_driver_version(dev); in mlx5_function_open()
1248 err = mlx5_query_hca_caps(dev); in mlx5_function_open()
1250 mlx5_core_err(dev, "query hca failed\n"); in mlx5_function_open()
1253 mlx5_start_health_fw_log_up(dev); in mlx5_function_open()
1257 static int mlx5_function_close(struct mlx5_core_dev *dev) in mlx5_function_close() argument
1261 err = mlx5_cmd_teardown_hca(dev); in mlx5_function_close()
1263 mlx5_core_err(dev, "tear_down_hca failed, skip cleanup\n"); in mlx5_function_close()
1270 static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot, u64 timeout) in mlx5_function_setup() argument
1274 err = mlx5_function_enable(dev, boot, timeout); in mlx5_function_setup()
1278 err = mlx5_function_open(dev); in mlx5_function_setup()
1280 mlx5_function_disable(dev, boot); in mlx5_function_setup()
1284 static int mlx5_function_teardown(struct mlx5_core_dev *dev, bool boot) in mlx5_function_teardown() argument
1286 int err = mlx5_function_close(dev); in mlx5_function_teardown()
1289 mlx5_function_disable(dev, boot); in mlx5_function_teardown()
1291 mlx5_stop_health_poll(dev, boot); in mlx5_function_teardown()
1296 static int mlx5_load(struct mlx5_core_dev *dev) in mlx5_load() argument
1300 dev->priv.uar = mlx5_get_uars_page(dev); in mlx5_load()
1301 if (IS_ERR(dev->priv.uar)) { in mlx5_load()
1302 mlx5_core_err(dev, "Failed allocating uar, aborting\n"); in mlx5_load()
1303 err = PTR_ERR(dev->priv.uar); in mlx5_load()
1307 mlx5_events_start(dev); in mlx5_load()
1308 mlx5_pagealloc_start(dev); in mlx5_load()
1310 err = mlx5_irq_table_create(dev); in mlx5_load()
1312 mlx5_core_err(dev, "Failed to alloc IRQs\n"); in mlx5_load()
1316 err = mlx5_eq_table_create(dev); in mlx5_load()
1318 mlx5_core_err(dev, "Failed to create EQs\n"); in mlx5_load()
1322 err = mlx5_fw_tracer_init(dev->tracer); in mlx5_load()
1324 mlx5_core_err(dev, "Failed to init FW tracer %d\n", err); in mlx5_load()
1325 mlx5_fw_tracer_destroy(dev->tracer); in mlx5_load()
1326 dev->tracer = NULL; in mlx5_load()
1329 mlx5_fw_reset_events_start(dev); in mlx5_load()
1330 mlx5_hv_vhca_init(dev->hv_vhca); in mlx5_load()
1332 err = mlx5_rsc_dump_init(dev); in mlx5_load()
1334 mlx5_core_err(dev, "Failed to init Resource dump %d\n", err); in mlx5_load()
1335 mlx5_rsc_dump_destroy(dev); in mlx5_load()
1336 dev->rsc_dump = NULL; in mlx5_load()
1339 err = mlx5_fpga_device_start(dev); in mlx5_load()
1341 mlx5_core_err(dev, "fpga device start failed %d\n", err); in mlx5_load()
1345 err = mlx5_fs_core_init(dev); in mlx5_load()
1347 mlx5_core_err(dev, "Failed to init flow steering\n"); in mlx5_load()
1351 err = mlx5_core_set_hca_defaults(dev); in mlx5_load()
1353 mlx5_core_err(dev, "Failed to set hca defaults\n"); in mlx5_load()
1357 mlx5_vhca_event_start(dev); in mlx5_load()
1359 err = mlx5_sf_hw_table_create(dev); in mlx5_load()
1361 mlx5_core_err(dev, "sf table create failed %d\n", err); in mlx5_load()
1365 err = mlx5_ec_init(dev); in mlx5_load()
1367 mlx5_core_err(dev, "Failed to init embedded CPU\n"); in mlx5_load()
1371 mlx5_lag_add_mdev(dev); in mlx5_load()
1372 err = mlx5_sriov_attach(dev); in mlx5_load()
1374 mlx5_core_err(dev, "sriov init failed %d\n", err); in mlx5_load()
1378 mlx5_sf_dev_table_create(dev); in mlx5_load()
1380 err = mlx5_devlink_traps_register(priv_to_devlink(dev)); in mlx5_load()
1387 mlx5_sf_dev_table_destroy(dev); in mlx5_load()
1388 mlx5_sriov_detach(dev); in mlx5_load()
1390 mlx5_lag_remove_mdev(dev); in mlx5_load()
1391 mlx5_ec_cleanup(dev); in mlx5_load()
1393 mlx5_sf_hw_table_destroy(dev); in mlx5_load()
1395 mlx5_vhca_event_stop(dev); in mlx5_load()
1397 mlx5_fs_core_cleanup(dev); in mlx5_load()
1399 mlx5_fpga_device_stop(dev); in mlx5_load()
1401 mlx5_rsc_dump_cleanup(dev); in mlx5_load()
1402 mlx5_hv_vhca_cleanup(dev->hv_vhca); in mlx5_load()
1403 mlx5_fw_reset_events_stop(dev); in mlx5_load()
1404 mlx5_fw_tracer_cleanup(dev->tracer); in mlx5_load()
1405 mlx5_eq_table_destroy(dev); in mlx5_load()
1407 mlx5_irq_table_destroy(dev); in mlx5_load()
1409 mlx5_pagealloc_stop(dev); in mlx5_load()
1410 mlx5_events_stop(dev); in mlx5_load()
1411 mlx5_put_uars_page(dev, dev->priv.uar); in mlx5_load()
1415 static void mlx5_unload(struct mlx5_core_dev *dev) in mlx5_unload() argument
1417 mlx5_devlink_traps_unregister(priv_to_devlink(dev)); in mlx5_unload()
1418 mlx5_sf_dev_table_destroy(dev); in mlx5_unload()
1419 mlx5_eswitch_disable(dev->priv.eswitch); in mlx5_unload()
1420 mlx5_sriov_detach(dev); in mlx5_unload()
1421 mlx5_lag_remove_mdev(dev); in mlx5_unload()
1422 mlx5_ec_cleanup(dev); in mlx5_unload()
1423 mlx5_sf_hw_table_destroy(dev); in mlx5_unload()
1424 mlx5_vhca_event_stop(dev); in mlx5_unload()
1425 mlx5_fs_core_cleanup(dev); in mlx5_unload()
1426 mlx5_fpga_device_stop(dev); in mlx5_unload()
1427 mlx5_rsc_dump_cleanup(dev); in mlx5_unload()
1428 mlx5_hv_vhca_cleanup(dev->hv_vhca); in mlx5_unload()
1429 mlx5_fw_reset_events_stop(dev); in mlx5_unload()
1430 mlx5_fw_tracer_cleanup(dev->tracer); in mlx5_unload()
1431 mlx5_eq_table_destroy(dev); in mlx5_unload()
1432 mlx5_irq_table_destroy(dev); in mlx5_unload()
1433 mlx5_pagealloc_stop(dev); in mlx5_unload()
1434 mlx5_events_stop(dev); in mlx5_unload()
1435 mlx5_put_uars_page(dev, dev->priv.uar); in mlx5_unload()
1438 int mlx5_init_one_devl_locked(struct mlx5_core_dev *dev) in mlx5_init_one_devl_locked() argument
1440 bool light_probe = mlx5_dev_is_lightweight(dev); in mlx5_init_one_devl_locked()
1443 mutex_lock(&dev->intf_state_mutex); in mlx5_init_one_devl_locked()
1444 dev->state = MLX5_DEVICE_STATE_UP; in mlx5_init_one_devl_locked()
1446 err = mlx5_function_setup(dev, true, mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT)); in mlx5_init_one_devl_locked()
1450 err = mlx5_init_once(dev); in mlx5_init_one_devl_locked()
1452 mlx5_core_err(dev, "sw objs init failed\n"); in mlx5_init_one_devl_locked()
1460 err = mlx5_devlink_params_register(priv_to_devlink(dev)); in mlx5_init_one_devl_locked()
1465 err = mlx5_load(dev); in mlx5_init_one_devl_locked()
1469 set_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state); in mlx5_init_one_devl_locked()
1471 err = mlx5_register_device(dev); in mlx5_init_one_devl_locked()
1475 err = mlx5_crdump_enable(dev); in mlx5_init_one_devl_locked()
1477 mlx5_core_err(dev, "mlx5_crdump_enable failed with error code %d\n", err); in mlx5_init_one_devl_locked()
1479 err = mlx5_hwmon_dev_register(dev); in mlx5_init_one_devl_locked()
1481 mlx5_core_err(dev, "mlx5_hwmon_dev_register failed with error code %d\n", err); in mlx5_init_one_devl_locked()
1483 mutex_unlock(&dev->intf_state_mutex); in mlx5_init_one_devl_locked()
1487 clear_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state); in mlx5_init_one_devl_locked()
1488 mlx5_unload(dev); in mlx5_init_one_devl_locked()
1491 mlx5_devlink_params_unregister(priv_to_devlink(dev)); in mlx5_init_one_devl_locked()
1493 mlx5_cleanup_once(dev); in mlx5_init_one_devl_locked()
1495 mlx5_function_teardown(dev, true); in mlx5_init_one_devl_locked()
1497 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; in mlx5_init_one_devl_locked()
1498 mutex_unlock(&dev->intf_state_mutex); in mlx5_init_one_devl_locked()
1502 int mlx5_init_one(struct mlx5_core_dev *dev) in mlx5_init_one() argument
1504 struct devlink *devlink = priv_to_devlink(dev); in mlx5_init_one()
1509 err = mlx5_init_one_devl_locked(dev); in mlx5_init_one()
1516 void mlx5_uninit_one(struct mlx5_core_dev *dev) in mlx5_uninit_one() argument
1518 struct devlink *devlink = priv_to_devlink(dev); in mlx5_uninit_one()
1521 mutex_lock(&dev->intf_state_mutex); in mlx5_uninit_one()
1523 mlx5_hwmon_dev_unregister(dev); in mlx5_uninit_one()
1524 mlx5_crdump_disable(dev); in mlx5_uninit_one()
1525 mlx5_unregister_device(dev); in mlx5_uninit_one()
1527 if (!test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) { in mlx5_uninit_one()
1528 mlx5_core_warn(dev, "%s: interface is down, NOP\n", in mlx5_uninit_one()
1530 mlx5_devlink_params_unregister(priv_to_devlink(dev)); in mlx5_uninit_one()
1531 mlx5_cleanup_once(dev); in mlx5_uninit_one()
1535 clear_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state); in mlx5_uninit_one()
1536 mlx5_unload(dev); in mlx5_uninit_one()
1537 mlx5_devlink_params_unregister(priv_to_devlink(dev)); in mlx5_uninit_one()
1538 mlx5_cleanup_once(dev); in mlx5_uninit_one()
1539 mlx5_function_teardown(dev, true); in mlx5_uninit_one()
1541 mutex_unlock(&dev->intf_state_mutex); in mlx5_uninit_one()
1546 int mlx5_load_one_devl_locked(struct mlx5_core_dev *dev, bool recovery) in mlx5_load_one_devl_locked() argument
1551 devl_assert_locked(priv_to_devlink(dev)); in mlx5_load_one_devl_locked()
1552 mutex_lock(&dev->intf_state_mutex); in mlx5_load_one_devl_locked()
1553 if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) { in mlx5_load_one_devl_locked()
1554 mlx5_core_warn(dev, "interface is up, NOP\n"); in mlx5_load_one_devl_locked()
1558 dev->state = MLX5_DEVICE_STATE_UP; in mlx5_load_one_devl_locked()
1561 timeout = mlx5_tout_ms(dev, FW_PRE_INIT_ON_RECOVERY_TIMEOUT); in mlx5_load_one_devl_locked()
1563 timeout = mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT); in mlx5_load_one_devl_locked()
1564 err = mlx5_function_setup(dev, false, timeout); in mlx5_load_one_devl_locked()
1568 err = mlx5_load(dev); in mlx5_load_one_devl_locked()
1572 set_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state); in mlx5_load_one_devl_locked()
1574 err = mlx5_attach_device(dev); in mlx5_load_one_devl_locked()
1578 mutex_unlock(&dev->intf_state_mutex); in mlx5_load_one_devl_locked()
1582 clear_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state); in mlx5_load_one_devl_locked()
1583 mlx5_unload(dev); in mlx5_load_one_devl_locked()
1585 mlx5_function_teardown(dev, false); in mlx5_load_one_devl_locked()
1587 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; in mlx5_load_one_devl_locked()
1589 mutex_unlock(&dev->intf_state_mutex); in mlx5_load_one_devl_locked()
1593 int mlx5_load_one(struct mlx5_core_dev *dev, bool recovery) in mlx5_load_one() argument
1595 struct devlink *devlink = priv_to_devlink(dev); in mlx5_load_one()
1599 ret = mlx5_load_one_devl_locked(dev, recovery); in mlx5_load_one()
1604 void mlx5_unload_one_devl_locked(struct mlx5_core_dev *dev, bool suspend) in mlx5_unload_one_devl_locked() argument
1606 devl_assert_locked(priv_to_devlink(dev)); in mlx5_unload_one_devl_locked()
1607 mutex_lock(&dev->intf_state_mutex); in mlx5_unload_one_devl_locked()
1609 mlx5_detach_device(dev, suspend); in mlx5_unload_one_devl_locked()
1611 if (!test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) { in mlx5_unload_one_devl_locked()
1612 mlx5_core_warn(dev, "%s: interface is down, NOP\n", in mlx5_unload_one_devl_locked()
1617 clear_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state); in mlx5_unload_one_devl_locked()
1618 mlx5_unload(dev); in mlx5_unload_one_devl_locked()
1619 mlx5_function_teardown(dev, false); in mlx5_unload_one_devl_locked()
1621 mutex_unlock(&dev->intf_state_mutex); in mlx5_unload_one_devl_locked()
1624 void mlx5_unload_one(struct mlx5_core_dev *dev, bool suspend) in mlx5_unload_one() argument
1626 struct devlink *devlink = priv_to_devlink(dev); in mlx5_unload_one()
1629 mlx5_unload_one_devl_locked(dev, suspend); in mlx5_unload_one()
1636 static int mlx5_query_hca_caps_light(struct mlx5_core_dev *dev) in mlx5_query_hca_caps_light() argument
1640 err = mlx5_core_get_caps(dev, MLX5_CAP_GENERAL); in mlx5_query_hca_caps_light()
1644 if (MLX5_CAP_GEN(dev, eth_net_offloads)) { in mlx5_query_hca_caps_light()
1645 err = mlx5_core_get_caps_mode(dev, MLX5_CAP_ETHERNET_OFFLOADS, in mlx5_query_hca_caps_light()
1651 if (MLX5_CAP_GEN(dev, nic_flow_table) || in mlx5_query_hca_caps_light()
1652 MLX5_CAP_GEN(dev, ipoib_enhanced_offloads)) { in mlx5_query_hca_caps_light()
1653 err = mlx5_core_get_caps_mode(dev, MLX5_CAP_FLOW_TABLE, in mlx5_query_hca_caps_light()
1659 if (MLX5_CAP_GEN_64(dev, general_obj_types) & in mlx5_query_hca_caps_light()
1661 err = mlx5_core_get_caps_mode(dev, MLX5_CAP_VDPA_EMULATION, in mlx5_query_hca_caps_light()
1670 int mlx5_init_one_light(struct mlx5_core_dev *dev) in mlx5_init_one_light() argument
1672 struct devlink *devlink = priv_to_devlink(dev); in mlx5_init_one_light()
1675 dev->state = MLX5_DEVICE_STATE_UP; in mlx5_init_one_light()
1676 err = mlx5_function_enable(dev, true, mlx5_tout_ms(dev, FW_PRE_INIT_TIMEOUT)); in mlx5_init_one_light()
1678 mlx5_core_warn(dev, "mlx5_function_enable err=%d\n", err); in mlx5_init_one_light()
1682 err = mlx5_query_hca_caps_light(dev); in mlx5_init_one_light()
1684 mlx5_core_warn(dev, "mlx5_query_hca_caps_light err=%d\n", err); in mlx5_init_one_light()
1691 err = mlx5_devlink_params_register(priv_to_devlink(dev)); in mlx5_init_one_light()
1693 mlx5_core_warn(dev, "mlx5_devlink_param_reg err = %d\n", err); in mlx5_init_one_light()
1703 mlx5_function_disable(dev, true); in mlx5_init_one_light()
1705 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; in mlx5_init_one_light()
1709 void mlx5_uninit_one_light(struct mlx5_core_dev *dev) in mlx5_uninit_one_light() argument
1711 struct devlink *devlink = priv_to_devlink(dev); in mlx5_uninit_one_light()
1714 mlx5_devlink_params_unregister(priv_to_devlink(dev)); in mlx5_uninit_one_light()
1717 if (dev->state != MLX5_DEVICE_STATE_UP) in mlx5_uninit_one_light()
1719 mlx5_function_disable(dev, true); in mlx5_uninit_one_light()
1727 void mlx5_unload_one_light(struct mlx5_core_dev *dev) in mlx5_unload_one_light() argument
1729 if (dev->state != MLX5_DEVICE_STATE_UP) in mlx5_unload_one_light()
1731 mlx5_function_disable(dev, false); in mlx5_unload_one_light()
1732 dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; in mlx5_unload_one_light()
1760 static void mlx5_hca_caps_free(struct mlx5_core_dev *dev) in mlx5_hca_caps_free() argument
1767 kfree(dev->caps.hca[type]); in mlx5_hca_caps_free()
1771 static int mlx5_hca_caps_alloc(struct mlx5_core_dev *dev) in mlx5_hca_caps_alloc() argument
1782 dev->caps.hca[type] = cap; in mlx5_hca_caps_alloc()
1788 mlx5_hca_caps_free(dev); in mlx5_hca_caps_alloc()
1794 struct mlx5_core_dev *dev = file->private; in vhca_id_show() local
1796 seq_printf(file, "0x%x\n", MLX5_CAP_GEN(dev, vhca_id)); in vhca_id_show()
1802 int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx) in mlx5_mdev_init() argument
1804 struct mlx5_priv *priv = &dev->priv; in mlx5_mdev_init()
1807 memcpy(&dev->profile, &profile[profile_idx], sizeof(dev->profile)); in mlx5_mdev_init()
1808 lockdep_register_key(&dev->lock_key); in mlx5_mdev_init()
1809 mutex_init(&dev->intf_state_mutex); in mlx5_mdev_init()
1810 lockdep_set_class(&dev->intf_state_mutex, &dev->lock_key); in mlx5_mdev_init()
1811 mutex_init(&dev->mlx5e_res.uplink_netdev_lock); in mlx5_mdev_init()
1822 priv->numa_node = dev_to_node(mlx5_core_dma_dev(dev)); in mlx5_mdev_init()
1823 priv->dbg.dbg_root = debugfs_create_dir(dev_name(dev->device), in mlx5_mdev_init()
1825 debugfs_create_file("vhca_id", 0400, priv->dbg.dbg_root, dev, &vhca_id_fops); in mlx5_mdev_init()
1828 err = mlx5_cmd_init(dev); in mlx5_mdev_init()
1830 mlx5_core_err(dev, "Failed initializing cmdif SW structs, aborting\n"); in mlx5_mdev_init()
1834 err = mlx5_tout_init(dev); in mlx5_mdev_init()
1836 mlx5_core_err(dev, "Failed initializing timeouts, aborting\n"); in mlx5_mdev_init()
1840 err = mlx5_health_init(dev); in mlx5_mdev_init()
1844 err = mlx5_pagealloc_init(dev); in mlx5_mdev_init()
1848 err = mlx5_adev_init(dev); in mlx5_mdev_init()
1852 err = mlx5_hca_caps_alloc(dev); in mlx5_mdev_init()
1861 dev->priv.sw_vhca_id = ida_alloc_range(&sw_vhca_ida, 1, in mlx5_mdev_init()
1864 if (dev->priv.sw_vhca_id < 0) in mlx5_mdev_init()
1865 mlx5_core_err(dev, "failed to allocate sw_vhca_id, err=%d\n", in mlx5_mdev_init()
1866 dev->priv.sw_vhca_id); in mlx5_mdev_init()
1871 mlx5_adev_cleanup(dev); in mlx5_mdev_init()
1873 mlx5_pagealloc_cleanup(dev); in mlx5_mdev_init()
1875 mlx5_health_cleanup(dev); in mlx5_mdev_init()
1877 mlx5_tout_cleanup(dev); in mlx5_mdev_init()
1879 mlx5_cmd_cleanup(dev); in mlx5_mdev_init()
1881 debugfs_remove(dev->priv.dbg.dbg_root); in mlx5_mdev_init()
1886 mutex_destroy(&dev->intf_state_mutex); in mlx5_mdev_init()
1887 lockdep_unregister_key(&dev->lock_key); in mlx5_mdev_init()
1891 void mlx5_mdev_uninit(struct mlx5_core_dev *dev) in mlx5_mdev_uninit() argument
1893 struct mlx5_priv *priv = &dev->priv; in mlx5_mdev_uninit()
1896 ida_free(&sw_vhca_ida, dev->priv.sw_vhca_id); in mlx5_mdev_uninit()
1898 mlx5_hca_caps_free(dev); in mlx5_mdev_uninit()
1899 mlx5_adev_cleanup(dev); in mlx5_mdev_uninit()
1900 mlx5_pagealloc_cleanup(dev); in mlx5_mdev_uninit()
1901 mlx5_health_cleanup(dev); in mlx5_mdev_uninit()
1902 mlx5_tout_cleanup(dev); in mlx5_mdev_uninit()
1903 mlx5_cmd_cleanup(dev); in mlx5_mdev_uninit()
1904 debugfs_remove_recursive(dev->priv.dbg.dbg_root); in mlx5_mdev_uninit()
1909 mutex_destroy(&dev->mlx5e_res.uplink_netdev_lock); in mlx5_mdev_uninit()
1910 mutex_destroy(&dev->intf_state_mutex); in mlx5_mdev_uninit()
1911 lockdep_unregister_key(&dev->lock_key); in mlx5_mdev_uninit()
1916 struct mlx5_core_dev *dev; in probe_one() local
1920 devlink = mlx5_devlink_alloc(&pdev->dev); in probe_one()
1922 dev_err(&pdev->dev, "devlink alloc failed\n"); in probe_one()
1926 dev = devlink_priv(devlink); in probe_one()
1927 dev->device = &pdev->dev; in probe_one()
1928 dev->pdev = pdev; in probe_one()
1930 dev->coredev_type = id->driver_data & MLX5_PCI_DEV_IS_VF ? in probe_one()
1933 dev->priv.adev_idx = mlx5_adev_idx_alloc(); in probe_one()
1934 if (dev->priv.adev_idx < 0) { in probe_one()
1935 err = dev->priv.adev_idx; in probe_one()
1939 err = mlx5_mdev_init(dev, prof_sel); in probe_one()
1943 err = mlx5_pci_init(dev, pdev, id); in probe_one()
1945 mlx5_core_err(dev, "mlx5_pci_init failed with error code %d\n", in probe_one()
1950 err = mlx5_init_one(dev); in probe_one()
1952 mlx5_core_err(dev, "mlx5_init_one failed with error code %d\n", in probe_one()
1961 mlx5_pci_close(dev); in probe_one()
1963 mlx5_mdev_uninit(dev); in probe_one()
1965 mlx5_adev_idx_free(dev->priv.adev_idx); in probe_one()
1974 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in remove_one() local
1975 struct devlink *devlink = priv_to_devlink(dev); in remove_one()
1977 set_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state); in remove_one()
1978 mlx5_drain_fw_reset(dev); in remove_one()
1979 mlx5_drain_health_wq(dev); in remove_one()
1981 mlx5_uninit_one(dev); in remove_one()
1982 mlx5_pci_close(dev); in remove_one()
1983 mlx5_mdev_uninit(dev); in remove_one()
1984 mlx5_adev_idx_free(dev->priv.adev_idx); in remove_one()
1988 #define mlx5_pci_trace(dev, fmt, ...) ({ \ argument
1989 struct mlx5_core_dev *__dev = (dev); \
2006 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in mlx5_pci_err_detected() local
2009 mlx5_pci_trace(dev, "Enter, pci channel state = %d\n", state); in mlx5_pci_err_detected()
2011 mlx5_enter_error_state(dev, false); in mlx5_pci_err_detected()
2012 mlx5_error_sw_reset(dev); in mlx5_pci_err_detected()
2013 mlx5_unload_one(dev, false); in mlx5_pci_err_detected()
2014 mlx5_drain_health_wq(dev); in mlx5_pci_err_detected()
2015 mlx5_pci_disable_device(dev); in mlx5_pci_err_detected()
2020 mlx5_core_info(dev, "%s Device state = %d pci_status: %d. Exit, result = %d, %s\n", in mlx5_pci_err_detected()
2021 __func__, dev->state, dev->pci_status, res, result2str(res)); in mlx5_pci_err_detected()
2030 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in wait_vital() local
2031 struct mlx5_core_health *health = &dev->priv.health; in wait_vital()
2041 mlx5_core_info(dev, in wait_vital()
2057 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in mlx5_pci_slot_reset() local
2060 mlx5_core_info(dev, "%s Device state = %d pci_status: %d. Enter\n", in mlx5_pci_slot_reset()
2061 __func__, dev->state, dev->pci_status); in mlx5_pci_slot_reset()
2063 err = mlx5_pci_enable_device(dev); in mlx5_pci_slot_reset()
2065 mlx5_core_err(dev, "%s: mlx5_pci_enable_device failed with error code: %d\n", in mlx5_pci_slot_reset()
2076 mlx5_core_err(dev, "%s: wait vital failed with error code: %d\n", in mlx5_pci_slot_reset()
2083 mlx5_core_info(dev, "%s Device state = %d pci_status: %d. Exit, err = %d, result = %d, %s\n", in mlx5_pci_slot_reset()
2084 __func__, dev->state, dev->pci_status, err, res, result2str(res)); in mlx5_pci_slot_reset()
2090 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in mlx5_pci_resume() local
2093 mlx5_pci_trace(dev, "Enter, loading driver..\n"); in mlx5_pci_resume()
2095 err = mlx5_load_one(dev, false); in mlx5_pci_resume()
2098 devlink_health_reporter_state_update(dev->priv.health.fw_fatal_reporter, in mlx5_pci_resume()
2101 mlx5_pci_trace(dev, "Done, err = %d, device %s\n", err, in mlx5_pci_resume()
2111 static int mlx5_try_fast_unload(struct mlx5_core_dev *dev) in mlx5_try_fast_unload() argument
2116 fast_teardown = MLX5_CAP_GEN(dev, fast_teardown); in mlx5_try_fast_unload()
2117 force_teardown = MLX5_CAP_GEN(dev, force_teardown); in mlx5_try_fast_unload()
2119 mlx5_core_dbg(dev, "force teardown firmware support=%d\n", force_teardown); in mlx5_try_fast_unload()
2120 mlx5_core_dbg(dev, "fast teardown firmware support=%d\n", fast_teardown); in mlx5_try_fast_unload()
2125 if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) { in mlx5_try_fast_unload()
2126 mlx5_core_dbg(dev, "Device in internal error state, giving up\n"); in mlx5_try_fast_unload()
2133 mlx5_stop_health_poll(dev, false); in mlx5_try_fast_unload()
2135 ret = mlx5_cmd_fast_teardown_hca(dev); in mlx5_try_fast_unload()
2139 ret = mlx5_cmd_force_teardown_hca(dev); in mlx5_try_fast_unload()
2143 mlx5_core_dbg(dev, "Firmware couldn't do fast unload error: %d\n", ret); in mlx5_try_fast_unload()
2144 mlx5_start_health_poll(dev); in mlx5_try_fast_unload()
2148 mlx5_enter_error_state(dev, true); in mlx5_try_fast_unload()
2155 mlx5_core_eq_free_irqs(dev); in mlx5_try_fast_unload()
2162 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in shutdown() local
2165 mlx5_core_info(dev, "Shutdown was called\n"); in shutdown()
2166 set_bit(MLX5_BREAK_FW_WAIT, &dev->intf_state); in shutdown()
2167 mlx5_drain_health_wq(dev); in shutdown()
2168 err = mlx5_try_fast_unload(dev); in shutdown()
2170 mlx5_unload_one(dev, false); in shutdown()
2171 mlx5_pci_disable_device(dev); in shutdown()
2176 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in mlx5_suspend() local
2178 mlx5_unload_one(dev, true); in mlx5_suspend()
2185 struct mlx5_core_dev *dev = pci_get_drvdata(pdev); in mlx5_resume() local
2187 return mlx5_load_one(dev, false); in mlx5_resume()
2218 void mlx5_disable_device(struct mlx5_core_dev *dev) in mlx5_disable_device() argument
2220 mlx5_error_sw_reset(dev); in mlx5_disable_device()
2221 mlx5_unload_one_devl_locked(dev, false); in mlx5_disable_device()
2224 int mlx5_recover_device(struct mlx5_core_dev *dev) in mlx5_recover_device() argument
2226 if (!mlx5_core_is_sf(dev)) { in mlx5_recover_device()
2227 mlx5_pci_disable_device(dev); in mlx5_recover_device()
2228 if (mlx5_pci_slot_reset(dev->pdev) != PCI_ERS_RESULT_RECOVERED) in mlx5_recover_device()
2232 return mlx5_load_one_devl_locked(dev, true); in mlx5_recover_device()