Commit e161105e authored by Saeed Mahameed's avatar Saeed Mahameed

net/mlx5: Function setup/teardown procedures

Function setup and teardown procedures are the basic procedure that
each mlx5 pci function should perform to boot up a mlx5 device function
and initialize basic communication with FW, before allocating any higher
level software/firmware resources.

This provides a better logical separation of mlx5 core device
initialization flow and will help to seamlessly support creating different
mlx5 device types such as PF, VF and SF mlx5 sub-function virtual device.

This patch does not change any functionality.
Signed-off-by: default avatarVu Pham <vuhuong@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 52c368dc
...@@ -913,44 +913,24 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev) ...@@ -913,44 +913,24 @@ static void mlx5_cleanup_once(struct mlx5_core_dev *dev)
mlx5_devcom_unregister_device(dev->priv.devcom); mlx5_devcom_unregister_device(dev->priv.devcom);
} }
static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot) static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot)
{ {
struct pci_dev *pdev = dev->pdev; struct pci_dev *pdev = dev->pdev;
int err; int err;
dev->caps.embedded_cpu = mlx5_read_embedded_cpu(dev);
mutex_lock(&dev->intf_state_mutex);
if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) {
dev_warn(&dev->pdev->dev, "%s: interface is up, NOP\n",
__func__);
goto out;
}
dev_info(&pdev->dev, "firmware version: %d.%d.%d\n", fw_rev_maj(dev),
fw_rev_min(dev), fw_rev_sub(dev));
/* Only PFs hold the relevant PCIe information for this query */
if (mlx5_core_is_pf(dev))
pcie_print_link_status(dev->pdev);
/* on load removing any previous indication of internal error, device is
* up
*/
dev->state = MLX5_DEVICE_STATE_UP;
/* wait for firmware to accept initialization segments configurations /* wait for firmware to accept initialization segments configurations
*/ */
err = wait_fw_init(dev, FW_PRE_INIT_TIMEOUT_MILI); err = wait_fw_init(dev, FW_PRE_INIT_TIMEOUT_MILI);
if (err) { if (err) {
dev_err(&dev->pdev->dev, "Firmware over %d MS in pre-initializing state, aborting\n", dev_err(&dev->pdev->dev, "Firmware over %d MS in pre-initializing state, aborting\n",
FW_PRE_INIT_TIMEOUT_MILI); FW_PRE_INIT_TIMEOUT_MILI);
goto out_err; return err;
} }
err = mlx5_cmd_init(dev); err = mlx5_cmd_init(dev);
if (err) { if (err) {
dev_err(&pdev->dev, "Failed initializing command interface, aborting\n"); dev_err(&pdev->dev, "Failed initializing command interface, aborting\n");
goto out_err; return err;
} }
err = wait_fw_init(dev, FW_INIT_TIMEOUT_MILI); err = wait_fw_init(dev, FW_INIT_TIMEOUT_MILI);
...@@ -1009,14 +989,74 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot) ...@@ -1009,14 +989,74 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot)
err = mlx5_query_hca_caps(dev); err = mlx5_query_hca_caps(dev);
if (err) { if (err) {
dev_err(&pdev->dev, "query hca failed\n"); dev_err(&pdev->dev, "query hca failed\n");
goto err_stop_poll; goto stop_health;
}
return 0;
stop_health:
mlx5_stop_health_poll(dev, boot);
reclaim_boot_pages:
mlx5_reclaim_startup_pages(dev);
err_disable_hca:
mlx5_core_disable_hca(dev, 0);
err_cmd_cleanup:
mlx5_cmd_cleanup(dev);
return err;
}
static int mlx5_function_teardown(struct mlx5_core_dev *dev, bool boot)
{
int err;
mlx5_stop_health_poll(dev, boot);
err = mlx5_cmd_teardown_hca(dev);
if (err) {
dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n");
return err;
}
mlx5_reclaim_startup_pages(dev);
mlx5_core_disable_hca(dev, 0);
mlx5_cmd_cleanup(dev);
return 0;
}
static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot)
{
struct pci_dev *pdev = dev->pdev;
int err;
dev->caps.embedded_cpu = mlx5_read_embedded_cpu(dev);
mutex_lock(&dev->intf_state_mutex);
if (test_bit(MLX5_INTERFACE_STATE_UP, &dev->intf_state)) {
dev_warn(&dev->pdev->dev, "%s: interface is up, NOP\n",
__func__);
goto out;
} }
dev_info(&pdev->dev, "firmware version: %d.%d.%d\n", fw_rev_maj(dev),
fw_rev_min(dev), fw_rev_sub(dev));
/* Only PFs hold the relevant PCIe information for this query */
if (mlx5_core_is_pf(dev))
pcie_print_link_status(dev->pdev);
/* on load removing any previous indication of internal error, device is
* up
*/
dev->state = MLX5_DEVICE_STATE_UP;
err = mlx5_function_setup(dev, boot);
if (err)
goto out;
if (boot) { if (boot) {
err = mlx5_init_once(dev); err = mlx5_init_once(dev);
if (err) { if (err) {
dev_err(&pdev->dev, "sw objs init failed\n"); dev_err(&pdev->dev, "sw objs init failed\n");
goto err_stop_poll; goto function_teardown;
} }
} }
...@@ -1133,23 +1173,8 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot) ...@@ -1133,23 +1173,8 @@ static int mlx5_load_one(struct mlx5_core_dev *dev, bool boot)
if (boot) if (boot)
mlx5_cleanup_once(dev); mlx5_cleanup_once(dev);
err_stop_poll: function_teardown:
mlx5_stop_health_poll(dev, boot); mlx5_function_teardown(dev, boot);
if (mlx5_cmd_teardown_hca(dev)) {
dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n");
goto out_err;
}
reclaim_boot_pages:
mlx5_reclaim_startup_pages(dev);
err_disable_hca:
mlx5_core_disable_hca(dev, 0);
err_cmd_cleanup:
mlx5_cmd_cleanup(dev);
out_err:
dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR; dev->state = MLX5_DEVICE_STATE_INTERNAL_ERROR;
mutex_unlock(&dev->intf_state_mutex); mutex_unlock(&dev->intf_state_mutex);
...@@ -1190,17 +1215,8 @@ static int mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup) ...@@ -1190,17 +1215,8 @@ static int mlx5_unload_one(struct mlx5_core_dev *dev, bool cleanup)
mlx5_put_uars_page(dev, dev->priv.uar); mlx5_put_uars_page(dev, dev->priv.uar);
if (cleanup) if (cleanup)
mlx5_cleanup_once(dev); mlx5_cleanup_once(dev);
mlx5_stop_health_poll(dev, cleanup);
err = mlx5_cmd_teardown_hca(dev);
if (err) {
dev_err(&dev->pdev->dev, "tear_down_hca failed, skip cleanup\n");
goto out;
}
mlx5_reclaim_startup_pages(dev);
mlx5_core_disable_hca(dev, 0);
mlx5_cmd_cleanup(dev);
mlx5_function_teardown(dev, cleanup);
out: out:
mutex_unlock(&dev->intf_state_mutex); mutex_unlock(&dev->intf_state_mutex);
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment