Skip to content

Commit d5c0715

Browse files
author
Saeed Mahameed
committed
net/mlx5: EQ add/del CQ API
Add API to add/del CQ to/from EQs CQ table to be used in cq.c upon CQ creation/destruction, as CQ table is now private to eq.c. Signed-off-by: Saeed Mahameed <saeedm@mellanox.com> Reviewed-by: Gal Pressman <galp@mellanox.com>
1 parent d2ff4fa commit d5c0715

3 files changed

Lines changed: 53 additions & 45 deletions

File tree

‎drivers/net/ethernet/mellanox/mlx5/core/cq.c‎

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,17 @@ void mlx5_cq_event(struct mlx5_eq *eq, u32 cqn, int event_type)
137137
int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
138138
u32 *in, int inlen)
139139
{
140+
int eqn = MLX5_GET(cqc, MLX5_ADDR_OF(create_cq_in, in, cq_context), c_eqn);
141+
u32 dout[MLX5_ST_SZ_DW(destroy_cq_out)];
140142
u32 out[MLX5_ST_SZ_DW(create_cq_out)];
141143
u32 din[MLX5_ST_SZ_DW(destroy_cq_in)];
142-
u32 dout[MLX5_ST_SZ_DW(destroy_cq_out)];
143-
int eqn = MLX5_GET(cqc, MLX5_ADDR_OF(create_cq_in, in, cq_context),
144-
c_eqn);
145-
struct mlx5_eq *eq, *async_eq;
146-
struct mlx5_cq_table *table;
144+
struct mlx5_eq *eq;
147145
int err;
148146

149-
async_eq = &dev->priv.eq_table.async_eq;
150147
eq = mlx5_eqn2eq(dev, eqn);
151148
if (IS_ERR(eq))
152149
return PTR_ERR(eq);
153150

154-
table = &eq->cq_table;
155-
156151
memset(out, 0, sizeof(out));
157152
MLX5_SET(create_cq_in, in, opcode, MLX5_CMD_OP_CREATE_CQ);
158153
err = mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
@@ -172,18 +167,14 @@ int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
172167
INIT_LIST_HEAD(&cq->tasklet_ctx.list);
173168

174169
/* Add to comp EQ CQ tree to recv comp events */
175-
spin_lock_irq(&table->lock);
176-
err = radix_tree_insert(&table->tree, cq->cqn, cq);
177-
spin_unlock_irq(&table->lock);
170+
err = mlx5_eq_add_cq(eq, cq);
178171
if (err)
179172
goto err_cmd;
180173

181-
/* Add to async EQ CQ tree to recv Async events */
182-
spin_lock_irq(&async_eq->cq_table.lock);
183-
err = radix_tree_insert(&async_eq->cq_table.tree, cq->cqn, cq);
184-
spin_unlock_irq(&async_eq->cq_table.lock);
174+
/* Add to async EQ CQ tree to recv async events */
175+
err = mlx5_eq_add_cq(&dev->priv.eq_table.async_eq, cq);
185176
if (err)
186-
goto err_cq_table;
177+
goto err_cq_add;
187178

188179
cq->pid = current->pid;
189180
err = mlx5_debug_cq_add(dev, cq);
@@ -195,10 +186,8 @@ int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
195186

196187
return 0;
197188

198-
err_cq_table:
199-
spin_lock_irq(&table->lock);
200-
radix_tree_delete(&table->tree, cq->cqn);
201-
spin_unlock_irq(&table->lock);
189+
err_cq_add:
190+
mlx5_eq_del_cq(eq, cq);
202191
err_cmd:
203192
memset(din, 0, sizeof(din));
204193
memset(dout, 0, sizeof(dout));
@@ -211,36 +200,17 @@ EXPORT_SYMBOL(mlx5_core_create_cq);
211200

212201
int mlx5_core_destroy_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq)
213202
{
214-
struct mlx5_cq_table *asyn_eq_cq_table = &dev->priv.eq_table.async_eq.cq_table;
215-
struct mlx5_cq_table *table = &cq->eq->cq_table;
216203
u32 out[MLX5_ST_SZ_DW(destroy_cq_out)] = {0};
217204
u32 in[MLX5_ST_SZ_DW(destroy_cq_in)] = {0};
218-
struct mlx5_core_cq *tmp;
219205
int err;
220206

221-
spin_lock_irq(&asyn_eq_cq_table->lock);
222-
tmp = radix_tree_delete(&asyn_eq_cq_table->tree, cq->cqn);
223-
spin_unlock_irq(&asyn_eq_cq_table->lock);
224-
if (!tmp) {
225-
mlx5_core_warn(dev, "cq 0x%x not found in async eq cq tree\n", cq->cqn);
226-
return -EINVAL;
227-
}
228-
if (tmp != cq) {
229-
mlx5_core_warn(dev, "corruption on cqn 0x%x in async eq cq tree\n", cq->cqn);
230-
return -EINVAL;
231-
}
207+
err = mlx5_eq_del_cq(&dev->priv.eq_table.async_eq, cq);
208+
if (err)
209+
return err;
232210

233-
spin_lock_irq(&table->lock);
234-
tmp = radix_tree_delete(&table->tree, cq->cqn);
235-
spin_unlock_irq(&table->lock);
236-
if (!tmp) {
237-
mlx5_core_warn(dev, "cq 0x%x not found in comp eq cq tree\n", cq->cqn);
238-
return -EINVAL;
239-
}
240-
if (tmp != cq) {
241-
mlx5_core_warn(dev, "corruption on cqn 0x%x in comp eq cq tree\n", cq->cqn);
242-
return -EINVAL;
243-
}
211+
err = mlx5_eq_del_cq(cq->eq, cq);
212+
if (err)
213+
return err;
244214

245215
MLX5_SET(destroy_cq_in, in, opcode, MLX5_CMD_OP_DESTROY_CQ);
246216
MLX5_SET(destroy_cq_in, in, cqn, cq->cqn);

‎drivers/net/ethernet/mellanox/mlx5/core/eq.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,40 @@ int mlx5_destroy_unmap_eq(struct mlx5_core_dev *dev, struct mlx5_eq *eq)
704704
}
705705
EXPORT_SYMBOL_GPL(mlx5_destroy_unmap_eq);
706706

707+
int mlx5_eq_add_cq(struct mlx5_eq *eq, struct mlx5_core_cq *cq)
708+
{
709+
struct mlx5_cq_table *table = &eq->cq_table;
710+
int err;
711+
712+
spin_lock_irq(&table->lock);
713+
err = radix_tree_insert(&table->tree, cq->cqn, cq);
714+
spin_unlock_irq(&table->lock);
715+
716+
return err;
717+
}
718+
719+
int mlx5_eq_del_cq(struct mlx5_eq *eq, struct mlx5_core_cq *cq)
720+
{
721+
struct mlx5_cq_table *table = &eq->cq_table;
722+
struct mlx5_core_cq *tmp;
723+
724+
spin_lock_irq(&table->lock);
725+
tmp = radix_tree_delete(&table->tree, cq->cqn);
726+
spin_unlock_irq(&table->lock);
727+
728+
if (!tmp) {
729+
mlx5_core_warn(eq->dev, "cq 0x%x not found in eq 0x%x tree\n", eq->eqn, cq->cqn);
730+
return -ENOENT;
731+
}
732+
733+
if (tmp != cq) {
734+
mlx5_core_warn(eq->dev, "corruption on cqn 0x%x in eq 0x%x\n", eq->eqn, cq->cqn);
735+
return -EINVAL;
736+
}
737+
738+
return 0;
739+
}
740+
707741
int mlx5_eq_init(struct mlx5_core_dev *dev)
708742
{
709743
int err;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <linux/sched.h>
3939
#include <linux/if_link.h>
4040
#include <linux/firmware.h>
41+
#include <linux/mlx5/cq.h>
4142

4243
#define DRIVER_NAME "mlx5_core"
4344
#define DRIVER_VERSION "5.0-0"
@@ -115,6 +116,9 @@ int mlx5_destroy_scheduling_element_cmd(struct mlx5_core_dev *dev, u8 hierarchy,
115116
u32 element_id);
116117
int mlx5_wait_for_vf_pages(struct mlx5_core_dev *dev);
117118
u64 mlx5_read_internal_timer(struct mlx5_core_dev *dev);
119+
120+
int mlx5_eq_add_cq(struct mlx5_eq *eq, struct mlx5_core_cq *cq);
121+
int mlx5_eq_del_cq(struct mlx5_eq *eq, struct mlx5_core_cq *cq);
118122
struct mlx5_eq *mlx5_eqn2eq(struct mlx5_core_dev *dev, int eqn);
119123
u32 mlx5_eq_poll_irq_disabled(struct mlx5_eq *eq);
120124
void mlx5_cq_tasklet_cb(unsigned long data);

0 commit comments

Comments
 (0)