Skip to content

Commit f7936dd

Browse files
Eran Ben ElishaSaeed Mahameed
authored andcommitted
net/mlx5: Avoid processing commands before cmdif is ready
When driver is reloading during recovery flow, it can't get new commands till command interface is up again. Otherwise we may get to null pointer trying to access non initialized command structures. Add cmdif state to avoid processing commands while cmdif is not ready. Fixes: e126ba9 ("mlx5: Add driver for Mellanox Connect-IB adapters") Signed-off-by: Eran Ben Elisha <[email protected]> Signed-off-by: Moshe Shemesh <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent d43b700 commit f7936dd

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,7 @@ static void cmd_work_handler(struct work_struct *work)
923923
/* Skip sending command to fw if internal error */
924924
if (pci_channel_offline(dev->pdev) ||
925925
dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR ||
926+
cmd->state != MLX5_CMDIF_STATE_UP ||
926927
!opcode_allowed(&dev->cmd, ent->op)) {
927928
u8 status = 0;
928929
u32 drv_synd;
@@ -1712,6 +1713,7 @@ static int cmd_exec(struct mlx5_core_dev *dev, void *in, int in_size, void *out,
17121713
opcode = MLX5_GET(mbox_in, in, opcode);
17131714
if (pci_channel_offline(dev->pdev) ||
17141715
dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR ||
1716+
dev->cmd.state != MLX5_CMDIF_STATE_UP ||
17151717
!opcode_allowed(&dev->cmd, opcode)) {
17161718
err = mlx5_internal_err_ret_value(dev, opcode, &drv_synd, &status);
17171719
MLX5_SET(mbox_out, out, status, status);
@@ -1977,6 +1979,7 @@ int mlx5_cmd_init(struct mlx5_core_dev *dev)
19771979
goto err_free_page;
19781980
}
19791981

1982+
cmd->state = MLX5_CMDIF_STATE_DOWN;
19801983
cmd->checksum_disabled = 1;
19811984
cmd->max_reg_cmds = (1 << cmd->log_sz) - 1;
19821985
cmd->bitmask = (1UL << cmd->max_reg_cmds) - 1;
@@ -2054,3 +2057,10 @@ void mlx5_cmd_cleanup(struct mlx5_core_dev *dev)
20542057
dma_pool_destroy(cmd->pool);
20552058
}
20562059
EXPORT_SYMBOL(mlx5_cmd_cleanup);
2060+
2061+
void mlx5_cmd_set_state(struct mlx5_core_dev *dev,
2062+
enum mlx5_cmdif_state cmdif_state)
2063+
{
2064+
dev->cmd.state = cmdif_state;
2065+
}
2066+
EXPORT_SYMBOL(mlx5_cmd_set_state);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,8 @@ static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot)
965965
goto err_cmd_cleanup;
966966
}
967967

968+
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_UP);
969+
968970
err = mlx5_core_enable_hca(dev, 0);
969971
if (err) {
970972
mlx5_core_err(dev, "enable hca failed\n");
@@ -1026,6 +1028,7 @@ static int mlx5_function_setup(struct mlx5_core_dev *dev, bool boot)
10261028
err_disable_hca:
10271029
mlx5_core_disable_hca(dev, 0);
10281030
err_cmd_cleanup:
1031+
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
10291032
mlx5_cmd_cleanup(dev);
10301033

10311034
return err;
@@ -1043,6 +1046,7 @@ static int mlx5_function_teardown(struct mlx5_core_dev *dev, bool boot)
10431046
}
10441047
mlx5_reclaim_startup_pages(dev);
10451048
mlx5_core_disable_hca(dev, 0);
1049+
mlx5_cmd_set_state(dev, MLX5_CMDIF_STATE_DOWN);
10461050
mlx5_cmd_cleanup(dev);
10471051

10481052
return 0;

include/linux/mlx5/driver.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ enum mlx5_port_status {
213213
MLX5_PORT_DOWN = 2,
214214
};
215215

216+
enum mlx5_cmdif_state {
217+
MLX5_CMDIF_STATE_UNINITIALIZED,
218+
MLX5_CMDIF_STATE_UP,
219+
MLX5_CMDIF_STATE_DOWN,
220+
};
221+
216222
struct mlx5_cmd_first {
217223
__be32 data[4];
218224
};
@@ -258,6 +264,7 @@ struct mlx5_cmd_stats {
258264
struct mlx5_cmd {
259265
struct mlx5_nb nb;
260266

267+
enum mlx5_cmdif_state state;
261268
void *cmd_alloc_buf;
262269
dma_addr_t alloc_dma;
263270
int alloc_size;
@@ -882,6 +889,8 @@ enum {
882889

883890
int mlx5_cmd_init(struct mlx5_core_dev *dev);
884891
void mlx5_cmd_cleanup(struct mlx5_core_dev *dev);
892+
void mlx5_cmd_set_state(struct mlx5_core_dev *dev,
893+
enum mlx5_cmdif_state cmdif_state);
885894
void mlx5_cmd_use_events(struct mlx5_core_dev *dev);
886895
void mlx5_cmd_use_polling(struct mlx5_core_dev *dev);
887896
void mlx5_cmd_allowed_opcode(struct mlx5_core_dev *dev, u16 opcode);

0 commit comments

Comments
 (0)