Skip to content

Commit 06cd555

Browse files
shayshyiSaeed Mahameed
authored andcommitted
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: Shay Drory <[email protected]> Reviewed-by: Moshe Shemesh <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 0714ec9 commit 06cd555

File tree

3 files changed

+82
-56
lines changed

3 files changed

+82
-56
lines changed

drivers/net/ethernet/mellanox/mlx5/core/cmd.c

Lines changed: 68 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,6 @@ static void clean_debug_files(struct mlx5_core_dev *dev)
15481548
if (!mlx5_debugfs_root)
15491549
return;
15501550

1551-
mlx5_cmdif_debugfs_cleanup(dev);
15521551
debugfs_remove_recursive(dbg->dbg_root);
15531552
}
15541553

@@ -1563,8 +1562,6 @@ static void create_debugfs_files(struct mlx5_core_dev *dev)
15631562
debugfs_create_file("out_len", 0600, dbg->dbg_root, dev, &olfops);
15641563
debugfs_create_u8("status", 0600, dbg->dbg_root, &dbg->status);
15651564
debugfs_create_file("run", 0200, dbg->dbg_root, dev, &fops);
1566-
1567-
mlx5_cmdif_debugfs_init(dev);
15681565
}
15691566

15701567
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)
21902187
int size = sizeof(struct mlx5_cmd_prot_block);
21912188
int align = roundup_pow_of_two(size);
21922189
struct mlx5_cmd *cmd = &dev->cmd;
2193-
u32 cmd_h, cmd_l;
2190+
u32 cmd_l;
21942191
int err;
21952192
int i;
21962193

2197-
memset(cmd, 0, sizeof(*cmd));
2198-
cmd->vars.cmdif_rev = cmdif_rev(dev);
2199-
if (cmd->vars.cmdif_rev != CMD_IF_REV) {
2200-
mlx5_core_err(dev,
2201-
"Driver cmdif rev(%d) differs from firmware's(%d)\n",
2202-
CMD_IF_REV, cmd->vars.cmdif_rev);
2203-
return -EINVAL;
2204-
}
2205-
22062194
cmd->pool = dma_pool_create("mlx5_cmd", mlx5_core_dma_dev(dev), size, align, 0);
22072195
if (!cmd->pool)
22082196
return -ENOMEM;
@@ -2211,43 +2199,93 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
22112199
if (err)
22122200
goto err_free_pool;
22132201

2202+
cmd_l = (u32)(cmd->dma);
2203+
if (cmd_l & 0xfff) {
2204+
mlx5_core_err(dev, "invalid command queue address\n");
2205+
err = -ENOMEM;
2206+
goto err_cmd_page;
2207+
}
2208+
cmd->checksum_disabled = 1;
2209+
2210+
spin_lock_init(&cmd->alloc_lock);
2211+
spin_lock_init(&cmd->token_lock);
2212+
for (i = 0; i < MLX5_CMD_OP_MAX; i++)
2213+
spin_lock_init(&cmd->stats[i].lock);
2214+
2215+
create_msg_cache(dev);
2216+
2217+
set_wqname(dev);
2218+
cmd->wq = create_singlethread_workqueue(cmd->wq_name);
2219+
if (!cmd->wq) {
2220+
mlx5_core_err(dev, "failed to create command workqueue\n");
2221+
err = -ENOMEM;
2222+
goto err_cache;
2223+
}
2224+
2225+
mlx5_cmdif_debugfs_init(dev);
2226+
2227+
return 0;
2228+
2229+
err_cache:
2230+
destroy_msg_cache(dev);
2231+
err_cmd_page:
2232+
free_cmd_page(dev, cmd);
2233+
err_free_pool:
2234+
dma_pool_destroy(cmd->pool);
2235+
return err;
2236+
}
2237+
2238+
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev)
2239+
{
2240+
struct mlx5_cmd *cmd = &dev->cmd;
2241+
2242+
mlx5_cmdif_debugfs_cleanup(dev);
2243+
destroy_workqueue(cmd->wq);
2244+
destroy_msg_cache(dev);
2245+
free_cmd_page(dev, cmd);
2246+
dma_pool_destroy(cmd->pool);
2247+
}
2248+
2249+
int mlx5_cmd_enable(struct mlx5_core_dev *dev)
2250+
{
2251+
struct mlx5_cmd *cmd = &dev->cmd;
2252+
u32 cmd_h, cmd_l;
2253+
2254+
memset(&cmd->vars, 0, sizeof(cmd->vars));
2255+
cmd->vars.cmdif_rev = cmdif_rev(dev);
2256+
if (cmd->vars.cmdif_rev != CMD_IF_REV) {
2257+
mlx5_core_err(dev,
2258+
"Driver cmdif rev(%d) differs from firmware's(%d)\n",
2259+
CMD_IF_REV, cmd->vars.cmdif_rev);
2260+
return -EINVAL;
2261+
}
2262+
22142263
cmd_l = ioread32be(&dev->iseg->cmdq_addr_l_sz) & 0xff;
22152264
cmd->vars.log_sz = cmd_l >> 4 & 0xf;
22162265
cmd->vars.log_stride = cmd_l & 0xf;
22172266
if (1 << cmd->vars.log_sz > MLX5_MAX_COMMANDS) {
22182267
mlx5_core_err(dev, "firmware reports too many outstanding commands %d\n",
22192268
1 << cmd->vars.log_sz);
2220-
err = -EINVAL;
2221-
goto err_free_page;
2269+
return -EINVAL;
22222270
}
22232271

22242272
if (cmd->vars.log_sz + cmd->vars.log_stride > MLX5_ADAPTER_PAGE_SHIFT) {
22252273
mlx5_core_err(dev, "command queue size overflow\n");
2226-
err = -EINVAL;
2227-
goto err_free_page;
2274+
return -EINVAL;
22282275
}
22292276

22302277
cmd->state = MLX5_CMDIF_STATE_DOWN;
2231-
cmd->checksum_disabled = 1;
22322278
cmd->vars.max_reg_cmds = (1 << cmd->vars.log_sz) - 1;
22332279
cmd->vars.bitmask = (1UL << cmd->vars.max_reg_cmds) - 1;
22342280

2235-
spin_lock_init(&cmd->alloc_lock);
2236-
spin_lock_init(&cmd->token_lock);
2237-
for (i = 0; i < MLX5_CMD_OP_MAX; i++)
2238-
spin_lock_init(&cmd->stats[i].lock);
2239-
22402281
sema_init(&cmd->vars.sem, cmd->vars.max_reg_cmds);
22412282
sema_init(&cmd->vars.pages_sem, 1);
22422283
sema_init(&cmd->vars.throttle_sem, DIV_ROUND_UP(cmd->vars.max_reg_cmds, 2));
22432284

22442285
cmd_h = (u32)((u64)(cmd->dma) >> 32);
22452286
cmd_l = (u32)(cmd->dma);
2246-
if (cmd_l & 0xfff) {
2247-
mlx5_core_err(dev, "invalid command queue address\n");
2248-
err = -ENOMEM;
2249-
goto err_free_page;
2250-
}
2287+
if (WARN_ON(cmd_l & 0xfff))
2288+
return -EINVAL;
22512289

22522290
iowrite32be(cmd_h, &dev->iseg->cmdq_addr_h);
22532291
iowrite32be(cmd_l, &dev->iseg->cmdq_addr_l_sz);
@@ -2260,40 +2298,17 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
22602298
cmd->mode = CMD_MODE_POLLING;
22612299
cmd->allowed_opcode = CMD_ALLOWED_OPCODE_ALL;
22622300

2263-
create_msg_cache(dev);
2264-
2265-
set_wqname(dev);
2266-
cmd->wq = create_singlethread_workqueue(cmd->wq_name);
2267-
if (!cmd->wq) {
2268-
mlx5_core_err(dev, "failed to create command workqueue\n");
2269-
err = -ENOMEM;
2270-
goto err_cache;
2271-
}
2272-
22732301
create_debugfs_files(dev);
22742302

22752303
return 0;
2276-
2277-
err_cache:
2278-
destroy_msg_cache(dev);
2279-
2280-
err_free_page:
2281-
free_cmd_page(dev, cmd);
2282-
2283-
err_free_pool:
2284-
dma_pool_destroy(cmd->pool);
2285-
return err;
22862304
}
22872305

2288-
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev)
2306+
void mlx5_cmd_disable(struct mlx5_core_dev *dev)
22892307
{
22902308
struct mlx5_cmd *cmd = &dev->cmd;
22912309

22922310
clean_debug_files(dev);
2293-
destroy_workqueue(cmd->wq);
2294-
destroy_msg_cache(dev);
2295-
free_cmd_page(dev, cmd);
2296-
dma_pool_destroy(cmd->pool);
2311+
flush_workqueue(cmd->wq);
22972312
}
22982313

22992314
void mlx5_cmd_set_state(struct mlx5_core_dev *dev,

drivers/net/ethernet/mellanox/mlx5/core/main.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeou
11421142
return err;
11431143
}
11441144

1145-
err = mlx5_cmd_init(dev);
1145+
err = mlx5_cmd_enable(dev);
11461146
if (err) {
11471147
mlx5_core_err(dev, "Failed initializing command interface, aborting\n");
11481148
return err;
@@ -1196,7 +1196,7 @@ static int mlx5_function_enable(struct mlx5_core_dev *dev, bool boot, u64 timeou
11961196
mlx5_stop_health_poll(dev, boot);
11971197
err_cmd_cleanup:
11981198
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
1199-
mlx5_cmd_cleanup(dev);
1199+
mlx5_cmd_disable(dev);
12001200

12011201
return err;
12021202
}
@@ -1207,7 +1207,7 @@ static void mlx5_function_disable(struct mlx5_core_dev *dev, bool boot)
12071207
mlx5_core_disable_hca(dev, 0);
12081208
mlx5_stop_health_poll(dev, boot);
12091209
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
1210-
mlx5_cmd_cleanup(dev);
1210+
mlx5_cmd_disable(dev);
12111211
}
12121212

12131213
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)
17961796
debugfs_create_file("vhca_id", 0400, priv->dbg.dbg_root, dev, &vhca_id_fops);
17971797
INIT_LIST_HEAD(&priv->traps);
17981798

1799+
err = mlx5_cmd_init(dev);
1800+
if (err) {
1801+
mlx5_core_err(dev, "Failed initializing cmdif SW structs, aborting\n");
1802+
goto err_cmd_init;
1803+
}
1804+
17991805
err = mlx5_tout_init(dev);
18001806
if (err) {
18011807
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)
18411847
err_health_init:
18421848
mlx5_tout_cleanup(dev);
18431849
err_timeout_init:
1850+
mlx5_cmd_cleanup(dev);
1851+
err_cmd_init:
18441852
debugfs_remove(dev->priv.dbg.dbg_root);
18451853
mutex_destroy(&priv->pgdir_mutex);
18461854
mutex_destroy(&priv->alloc_mutex);
@@ -1863,6 +1871,7 @@ void mlx5_mdev_uninit(struct mlx5_core_dev *dev)
18631871
mlx5_pagealloc_cleanup(dev);
18641872
mlx5_health_cleanup(dev);
18651873
mlx5_tout_cleanup(dev);
1874+
mlx5_cmd_cleanup(dev);
18661875
debugfs_remove_recursive(dev->priv.dbg.dbg_root);
18671876
mutex_destroy(&priv->pgdir_mutex);
18681877
mutex_destroy(&priv->alloc_mutex);

drivers/net/ethernet/mellanox/mlx5/core/mlx5_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev);
178178
int mlx5_query_board_id(struct mlx5_core_dev *dev);
179179
int mlx5_cmd_init(struct mlx5_core_dev *dev);
180180
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
181+
int mlx5_cmd_enable(struct mlx5_core_dev *dev);
182+
void mlx5_cmd_disable(struct mlx5_core_dev *dev);
181183
void mlx5_cmd_set_state(struct mlx5_core_dev *dev,
182184
enum mlx5_cmdif_state cmdif_state);
183185
int mlx5_cmd_init_hca(struct mlx5_core_dev *dev, uint32_t *sw_owner_id);

0 commit comments

Comments
 (0)