Commit 06cd555f authored by Shay Drory's avatar Shay Drory Committed by Saeed Mahameed

net/mlx5: split mlx5_cmd_init() to probe and reload routines

There is no need to destroy and allocate cmd SW structs during reload,
this is time consuming for no reason.
Hence, split mlx5_cmd_init() to probe and reload routines.
Signed-off-by: default avatarShay Drory <shayd@nvidia.com>
Reviewed-by: default avatarMoshe Shemesh <moshe@nvidia.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@nvidia.com>
parent 0714ec9e
...@@ -1548,7 +1548,6 @@ static void clean_debug_files(struct mlx5_core_dev *dev) ...@@ -1548,7 +1548,6 @@ static void clean_debug_files(struct mlx5_core_dev *dev)
if (!mlx5_debugfs_root) if (!mlx5_debugfs_root)
return; return;
mlx5_cmdif_debugfs_cleanup(dev);
debugfs_remove_recursive(dbg->dbg_root); debugfs_remove_recursive(dbg->dbg_root);
} }
...@@ -1563,8 +1562,6 @@ static void create_debugfs_files(struct mlx5_core_dev *dev) ...@@ -1563,8 +1562,6 @@ static void create_debugfs_files(struct mlx5_core_dev *dev)
debugfs_create_file("out_len", 0600, dbg->dbg_root, dev, &olfops); debugfs_create_file("out_len", 0600, dbg->dbg_root, dev, &olfops);
debugfs_create_u8("status", 0600, dbg->dbg_root, &dbg->status); debugfs_create_u8("status", 0600, dbg->dbg_root, &dbg->status);
debugfs_create_file("run", 0200, dbg->dbg_root, dev, &fops); debugfs_create_file("run", 0200, dbg->dbg_root, dev, &fops);
mlx5_cmdif_debugfs_init(dev);
} }
void mlx5_cmd_allowed_opcode(struct mlx5_core_dev *dev, u16 opcode) void mlx5_cmd_allowed_opcode(struct mlx5_core_dev *dev, u16 opcode)
...@@ -2190,19 +2187,10 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev) ...@@ -2190,19 +2187,10 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
int size = sizeof(struct mlx5_cmd_prot_block); int size = sizeof(struct mlx5_cmd_prot_block);
int align = roundup_pow_of_two(size); int align = roundup_pow_of_two(size);
struct mlx5_cmd *cmd = &dev->cmd; struct mlx5_cmd *cmd = &dev->cmd;
u32 cmd_h, cmd_l; u32 cmd_l;
int err; int err;
int i; int i;
memset(cmd, 0, sizeof(*cmd));
cmd->vars.cmdif_rev = cmdif_rev(dev);
if (cmd->vars.cmdif_rev != CMD_IF_REV) {
mlx5_core_err(dev,
"Driver cmdif rev(%d) differs from firmware's(%d)\n",
CMD_IF_REV, cmd->vars.cmdif_rev);
return -EINVAL;
}
cmd->pool = dma_pool_create("mlx5_cmd", mlx5_core_dma_dev(dev), size, align, 0); cmd->pool = dma_pool_create("mlx5_cmd", mlx5_core_dma_dev(dev), size, align, 0);
if (!cmd->pool) if (!cmd->pool)
return -ENOMEM; return -ENOMEM;
...@@ -2211,43 +2199,93 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev) ...@@ -2211,43 +2199,93 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
if (err) if (err)
goto err_free_pool; goto err_free_pool;
cmd_l = (u32)(cmd->dma);
if (cmd_l & 0xfff) {
mlx5_core_err(dev, "invalid command queue address\n");
err = -ENOMEM;
goto err_cmd_page;
}
cmd->checksum_disabled = 1;
spin_lock_init(&cmd->alloc_lock);
spin_lock_init(&cmd->token_lock);
for (i = 0; i < MLX5_CMD_OP_MAX; i++)
spin_lock_init(&cmd->stats[i].lock);
create_msg_cache(dev);
set_wqname(dev);
cmd->wq = create_singlethread_workqueue(cmd->wq_name);
if (!cmd->wq) {
mlx5_core_err(dev, "failed to create command workqueue\n");
err = -ENOMEM;
goto err_cache;
}
mlx5_cmdif_debugfs_init(dev);
return 0;
err_cache:
destroy_msg_cache(dev);
err_cmd_page:
free_cmd_page(dev, cmd);
err_free_pool:
dma_pool_destroy(cmd->pool);
return err;
}
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev)
{
struct mlx5_cmd *cmd = &dev->cmd;
mlx5_cmdif_debugfs_cleanup(dev);
destroy_workqueue(cmd->wq);
destroy_msg_cache(dev);
free_cmd_page(dev, cmd);
dma_pool_destroy(cmd->pool);
}
int mlx5_cmd_enable(struct mlx5_core_dev *dev)
{
struct mlx5_cmd *cmd = &dev->cmd;
u32 cmd_h, cmd_l;
memset(&cmd->vars, 0, sizeof(cmd->vars));
cmd->vars.cmdif_rev = cmdif_rev(dev);
if (cmd->vars.cmdif_rev != CMD_IF_REV) {
mlx5_core_err(dev,
"Driver cmdif rev(%d) differs from firmware's(%d)\n",
CMD_IF_REV, cmd->vars.cmdif_rev);
return -EINVAL;
}
cmd_l = ioread32be(&dev->iseg->cmdq_addr_l_sz) & 0xff; cmd_l = ioread32be(&dev->iseg->cmdq_addr_l_sz) & 0xff;
cmd->vars.log_sz = cmd_l >> 4 & 0xf; cmd->vars.log_sz = cmd_l >> 4 & 0xf;
cmd->vars.log_stride = cmd_l & 0xf; cmd->vars.log_stride = cmd_l & 0xf;
if (1 << cmd->vars.log_sz > MLX5_MAX_COMMANDS) { if (1 << cmd->vars.log_sz > MLX5_MAX_COMMANDS) {
mlx5_core_err(dev, "firmware reports too many outstanding commands %d\n", mlx5_core_err(dev, "firmware reports too many outstanding commands %d\n",
1 << cmd->vars.log_sz); 1 << cmd->vars.log_sz);
err = -EINVAL; return -EINVAL;
goto err_free_page;
} }
if (cmd->vars.log_sz + cmd->vars.log_stride > MLX5_ADAPTER_PAGE_SHIFT) { if (cmd->vars.log_sz + cmd->vars.log_stride > MLX5_ADAPTER_PAGE_SHIFT) {
mlx5_core_err(dev, "command queue size overflow\n"); mlx5_core_err(dev, "command queue size overflow\n");
err = -EINVAL; return -EINVAL;
goto err_free_page;
} }
cmd->state = MLX5_CMDIF_STATE_DOWN; cmd->state = MLX5_CMDIF_STATE_DOWN;
cmd->checksum_disabled = 1;
cmd->vars.max_reg_cmds = (1 << cmd->vars.log_sz) - 1; cmd->vars.max_reg_cmds = (1 << cmd->vars.log_sz) - 1;
cmd->vars.bitmask = (1UL << cmd->vars.max_reg_cmds) - 1; cmd->vars.bitmask = (1UL << cmd->vars.max_reg_cmds) - 1;
spin_lock_init(&cmd->alloc_lock);
spin_lock_init(&cmd->token_lock);
for (i = 0; i < MLX5_CMD_OP_MAX; i++)
spin_lock_init(&cmd->stats[i].lock);
sema_init(&cmd->vars.sem, cmd->vars.max_reg_cmds); sema_init(&cmd->vars.sem, cmd->vars.max_reg_cmds);
sema_init(&cmd->vars.pages_sem, 1); sema_init(&cmd->vars.pages_sem, 1);
sema_init(&cmd->vars.throttle_sem, DIV_ROUND_UP(cmd->vars.max_reg_cmds, 2)); sema_init(&cmd->vars.throttle_sem, DIV_ROUND_UP(cmd->vars.max_reg_cmds, 2));
cmd_h = (u32)((u64)(cmd->dma) >> 32); cmd_h = (u32)((u64)(cmd->dma) >> 32);
cmd_l = (u32)(cmd->dma); cmd_l = (u32)(cmd->dma);
if (cmd_l & 0xfff) { if (WARN_ON(cmd_l & 0xfff))
mlx5_core_err(dev, "invalid command queue address\n"); return -EINVAL;
err = -ENOMEM;
goto err_free_page;
}
iowrite32be(cmd_h, &dev->iseg->cmdq_addr_h); iowrite32be(cmd_h, &dev->iseg->cmdq_addr_h);
iowrite32be(cmd_l, &dev->iseg->cmdq_addr_l_sz); iowrite32be(cmd_l, &dev->iseg->cmdq_addr_l_sz);
...@@ -2260,40 +2298,17 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev) ...@@ -2260,40 +2298,17 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
cmd->mode = CMD_MODE_POLLING; cmd->mode = CMD_MODE_POLLING;
cmd->allowed_opcode = CMD_ALLOWED_OPCODE_ALL; cmd->allowed_opcode = CMD_ALLOWED_OPCODE_ALL;
create_msg_cache(dev);
set_wqname(dev);
cmd->wq = create_singlethread_workqueue(cmd->wq_name);
if (!cmd->wq) {
mlx5_core_err(dev, "failed to create command workqueue\n");
err = -ENOMEM;
goto err_cache;
}
create_debugfs_files(dev); create_debugfs_files(dev);
return 0; return 0;
err_cache:
destroy_msg_cache(dev);
err_free_page:
free_cmd_page(dev, cmd);
err_free_pool:
dma_pool_destroy(cmd->pool);
return err;
} }
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev) void mlx5_cmd_disable(struct mlx5_core_dev *dev)
{ {
struct mlx5_cmd *cmd = &dev->cmd; struct mlx5_cmd *cmd = &dev->cmd;
clean_debug_files(dev); clean_debug_files(dev);
destroy_workqueue(cmd->wq); flush_workqueue(cmd->wq);
destroy_msg_cache(dev);
free_cmd_page(dev, cmd);
dma_pool_destroy(cmd->pool);
} }
void mlx5_cmd_set_state(struct mlx5_core_dev *dev, void mlx5_cmd_set_state(struct mlx5_core_dev *dev,
......
...@@ -1142,7 +1142,7 @@ static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeou ...@@ -1142,7 +1142,7 @@ static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeou
return err; return err;
} }
err = mlx5_cmd_init(dev); err = mlx5_cmd_enable(dev);
if (err) { if (err) {
mlx5_core_err(dev, "Failed initializing command interface, aborting\n"); mlx5_core_err(dev, "Failed initializing command interface, aborting\n");
return err; return err;
...@@ -1196,7 +1196,7 @@ static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeou ...@@ -1196,7 +1196,7 @@ static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeou
mlx5_stop_health_poll(dev, boot); mlx5_stop_health_poll(dev, boot);
err_cmd_cleanup: err_cmd_cleanup:
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN); mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
mlx5_cmd_cleanup(dev); mlx5_cmd_disable(dev);
return err; return err;
} }
...@@ -1207,7 +1207,7 @@ static void mlx5_function_disable(struct mlx5_core_dev *dev, bool boot) ...@@ -1207,7 +1207,7 @@ static void mlx5_function_disable(struct mlx5_core_dev *dev, bool boot)
mlx5_core_disable_hca(dev, 0); mlx5_core_disable_hca(dev, 0);
mlx5_stop_health_poll(dev, boot); mlx5_stop_health_poll(dev, boot);
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN); mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
mlx5_cmd_cleanup(dev); mlx5_cmd_disable(dev);
} }
static int mlx5_function_open(struct mlx5_core_dev *dev) static int mlx5_function_open(struct mlx5_core_dev *dev)
...@@ -1796,6 +1796,12 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx) ...@@ -1796,6 +1796,12 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
debugfs_create_file("vhca_id", 0400, priv->dbg.dbg_root, dev, &vhca_id_fops); debugfs_create_file("vhca_id", 0400, priv->dbg.dbg_root, dev, &vhca_id_fops);
INIT_LIST_HEAD(&priv->traps); INIT_LIST_HEAD(&priv->traps);
err = mlx5_cmd_init(dev);
if (err) {
mlx5_core_err(dev, "Failed initializing cmdif SW structs, aborting\n");
goto err_cmd_init;
}
err = mlx5_tout_init(dev); err = mlx5_tout_init(dev);
if (err) { if (err) {
mlx5_core_err(dev, "Failed initializing timeouts, aborting\n"); mlx5_core_err(dev, "Failed initializing timeouts, aborting\n");
...@@ -1841,6 +1847,8 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx) ...@@ -1841,6 +1847,8 @@ int mlx5_mdev_init(struct mlx5_core_dev *dev, int profile_idx)
err_health_init: err_health_init:
mlx5_tout_cleanup(dev); mlx5_tout_cleanup(dev);
err_timeout_init: err_timeout_init:
mlx5_cmd_cleanup(dev);
err_cmd_init:
debugfs_remove(dev->priv.dbg.dbg_root); debugfs_remove(dev->priv.dbg.dbg_root);
mutex_destroy(&priv->pgdir_mutex); mutex_destroy(&priv->pgdir_mutex);
mutex_destroy(&priv->alloc_mutex); mutex_destroy(&priv->alloc_mutex);
...@@ -1863,6 +1871,7 @@ void mlx5_mdev_uninit(struct mlx5_core_dev *dev) ...@@ -1863,6 +1871,7 @@ void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
mlx5_pagealloc_cleanup(dev); mlx5_pagealloc_cleanup(dev);
mlx5_health_cleanup(dev); mlx5_health_cleanup(dev);
mlx5_tout_cleanup(dev); mlx5_tout_cleanup(dev);
mlx5_cmd_cleanup(dev);
debugfs_remove_recursive(dev->priv.dbg.dbg_root); debugfs_remove_recursive(dev->priv.dbg.dbg_root);
mutex_destroy(&priv->pgdir_mutex); mutex_destroy(&priv->pgdir_mutex);
mutex_destroy(&priv->alloc_mutex); mutex_destroy(&priv->alloc_mutex);
......
...@@ -178,6 +178,8 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev); ...@@ -178,6 +178,8 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev);
int mlx5_query_board_id(struct mlx5_core_dev *dev); int mlx5_query_board_id(struct mlx5_core_dev *dev);
int mlx5_cmd_init(struct mlx5_core_dev *dev); int mlx5_cmd_init(struct mlx5_core_dev *dev);
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev); void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
int mlx5_cmd_enable(struct mlx5_core_dev *dev);
void mlx5_cmd_disable(struct mlx5_core_dev *dev);
void mlx5_cmd_set_state(struct mlx5_core_dev *dev, void mlx5_cmd_set_state(struct mlx5_core_dev *dev,
enum mlx5_cmdif_state cmdif_state); enum mlx5_cmdif_state cmdif_state);
int mlx5_cmd_init_hca(struct mlx5_core_dev *dev, uint32_t *sw_owner_id); int mlx5_cmd_init_hca(struct mlx5_core_dev *dev, uint32_t *sw_owner_id);
......
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