Skip to content

Commit f84b66b

Browse files
yishaihjgunthorpe
authored andcommitted
net/mlx5: Fix DCT creation bad flow
In case the DCT creation command has succeeded a DRAIN must be issued before calling DESTROY. In addition, the original code used the wrong parameter for the DESTROY command, 'in' instead of 'din', which caused another creation try instead of destroying. Cc: <stable@vger.kernel.org> # 4.15 Fixes: 57cda16 ("net/mlx5: Add DCT command interface") Signed-off-by: Yishai Hadas <yishaih@mellanox.com> Reviewed-by: Artemy Kovalyov <artemyko@mellanox.com> Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: Jason Gunthorpe <jgg@mellanox.com>
1 parent 587443e commit f84b66b

File tree

1 file changed

+36
-30
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+36
-30
lines changed

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

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
#include "mlx5_core.h"
4141
#include "lib/eq.h"
4242

43+
static int mlx5_core_drain_dct(struct mlx5_core_dev *dev,
44+
struct mlx5_core_dct *dct);
45+
4346
static struct mlx5_core_rsc_common *
4447
mlx5_get_rsc(struct mlx5_qp_table *table, u32 rsn)
4548
{
@@ -227,13 +230,42 @@ static void destroy_resource_common(struct mlx5_core_dev *dev,
227230
wait_for_completion(&qp->common.free);
228231
}
229232

233+
static int _mlx5_core_destroy_dct(struct mlx5_core_dev *dev,
234+
struct mlx5_core_dct *dct, bool need_cleanup)
235+
{
236+
u32 out[MLX5_ST_SZ_DW(destroy_dct_out)] = {0};
237+
u32 in[MLX5_ST_SZ_DW(destroy_dct_in)] = {0};
238+
struct mlx5_core_qp *qp = &dct->mqp;
239+
int err;
240+
241+
err = mlx5_core_drain_dct(dev, dct);
242+
if (err) {
243+
if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) {
244+
goto destroy;
245+
} else {
246+
mlx5_core_warn(
247+
dev, "failed drain DCT 0x%x with error 0x%x\n",
248+
qp->qpn, err);
249+
return err;
250+
}
251+
}
252+
wait_for_completion(&dct->drained);
253+
destroy:
254+
if (need_cleanup)
255+
destroy_resource_common(dev, &dct->mqp);
256+
MLX5_SET(destroy_dct_in, in, opcode, MLX5_CMD_OP_DESTROY_DCT);
257+
MLX5_SET(destroy_dct_in, in, dctn, qp->qpn);
258+
MLX5_SET(destroy_dct_in, in, uid, qp->uid);
259+
err = mlx5_cmd_exec(dev, (void *)&in, sizeof(in),
260+
(void *)&out, sizeof(out));
261+
return err;
262+
}
263+
230264
int mlx5_core_create_dct(struct mlx5_core_dev *dev,
231265
struct mlx5_core_dct *dct,
232266
u32 *in, int inlen)
233267
{
234268
u32 out[MLX5_ST_SZ_DW(create_dct_out)] = {0};
235-
u32 din[MLX5_ST_SZ_DW(destroy_dct_in)] = {0};
236-
u32 dout[MLX5_ST_SZ_DW(destroy_dct_out)] = {0};
237269
struct mlx5_core_qp *qp = &dct->mqp;
238270
int err;
239271

@@ -254,11 +286,7 @@ int mlx5_core_create_dct(struct mlx5_core_dev *dev,
254286

255287
return 0;
256288
err_cmd:
257-
MLX5_SET(destroy_dct_in, din, opcode, MLX5_CMD_OP_DESTROY_DCT);
258-
MLX5_SET(destroy_dct_in, din, dctn, qp->qpn);
259-
MLX5_SET(destroy_dct_in, din, uid, qp->uid);
260-
mlx5_cmd_exec(dev, (void *)&in, sizeof(din),
261-
(void *)&out, sizeof(dout));
289+
_mlx5_core_destroy_dct(dev, dct, false);
262290
return err;
263291
}
264292
EXPORT_SYMBOL_GPL(mlx5_core_create_dct);
@@ -323,29 +351,7 @@ static int mlx5_core_drain_dct(struct mlx5_core_dev *dev,
323351
int mlx5_core_destroy_dct(struct mlx5_core_dev *dev,
324352
struct mlx5_core_dct *dct)
325353
{
326-
u32 out[MLX5_ST_SZ_DW(destroy_dct_out)] = {0};
327-
u32 in[MLX5_ST_SZ_DW(destroy_dct_in)] = {0};
328-
struct mlx5_core_qp *qp = &dct->mqp;
329-
int err;
330-
331-
err = mlx5_core_drain_dct(dev, dct);
332-
if (err) {
333-
if (dev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) {
334-
goto destroy;
335-
} else {
336-
mlx5_core_warn(dev, "failed drain DCT 0x%x with error 0x%x\n", qp->qpn, err);
337-
return err;
338-
}
339-
}
340-
wait_for_completion(&dct->drained);
341-
destroy:
342-
destroy_resource_common(dev, &dct->mqp);
343-
MLX5_SET(destroy_dct_in, in, opcode, MLX5_CMD_OP_DESTROY_DCT);
344-
MLX5_SET(destroy_dct_in, in, dctn, qp->qpn);
345-
MLX5_SET(destroy_dct_in, in, uid, qp->uid);
346-
err = mlx5_cmd_exec(dev, (void *)&in, sizeof(in),
347-
(void *)&out, sizeof(out));
348-
return err;
354+
return _mlx5_core_destroy_dct(dev, dct, true);
349355
}
350356
EXPORT_SYMBOL_GPL(mlx5_core_destroy_dct);
351357

0 commit comments

Comments
 (0)