Commit f105b45b authored by Saeed Mahameed's avatar Saeed Mahameed

net/mlx5: CQ hold/put API

Now as the CQ table is per EQ, add an API to hold/put CQ to be used from
eq.c in downstream patch.
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
Reviewed-by: default avatarGal Pressman <galp@mellanox.com>
parent d5c07157
...@@ -58,8 +58,7 @@ void mlx5_cq_tasklet_cb(unsigned long data) ...@@ -58,8 +58,7 @@ void mlx5_cq_tasklet_cb(unsigned long data)
tasklet_ctx.list) { tasklet_ctx.list) {
list_del_init(&mcq->tasklet_ctx.list); list_del_init(&mcq->tasklet_ctx.list);
mcq->tasklet_ctx.comp(mcq); mcq->tasklet_ctx.comp(mcq);
if (refcount_dec_and_test(&mcq->refcount)) mlx5_cq_put(mcq);
complete(&mcq->free);
if (time_after(jiffies, end)) if (time_after(jiffies, end))
break; break;
} }
...@@ -80,23 +79,31 @@ static void mlx5_add_cq_to_tasklet(struct mlx5_core_cq *cq) ...@@ -80,23 +79,31 @@ static void mlx5_add_cq_to_tasklet(struct mlx5_core_cq *cq)
* still arrive. * still arrive.
*/ */
if (list_empty_careful(&cq->tasklet_ctx.list)) { if (list_empty_careful(&cq->tasklet_ctx.list)) {
refcount_inc(&cq->refcount); mlx5_cq_hold(cq);
list_add_tail(&cq->tasklet_ctx.list, &tasklet_ctx->list); list_add_tail(&cq->tasklet_ctx.list, &tasklet_ctx->list);
} }
spin_unlock_irqrestore(&tasklet_ctx->lock, flags); spin_unlock_irqrestore(&tasklet_ctx->lock, flags);
} }
void mlx5_cq_completion(struct mlx5_eq *eq, u32 cqn) /* caller must eventually call mlx5_cq_put on the returned cq */
static struct mlx5_core_cq *mlx5_eq_cq_get(struct mlx5_eq *eq, u32 cqn)
{ {
struct mlx5_cq_table *table = &eq->cq_table; struct mlx5_cq_table *table = &eq->cq_table;
struct mlx5_core_cq *cq; struct mlx5_core_cq *cq = NULL;
spin_lock(&table->lock); spin_lock(&table->lock);
cq = radix_tree_lookup(&table->tree, cqn); cq = radix_tree_lookup(&table->tree, cqn);
if (likely(cq)) if (likely(cq))
refcount_inc(&cq->refcount); mlx5_cq_hold(cq);
spin_unlock(&table->lock); spin_unlock(&table->lock);
return cq;
}
void mlx5_cq_completion(struct mlx5_eq *eq, u32 cqn)
{
struct mlx5_core_cq *cq = mlx5_eq_cq_get(eq, cqn);
if (unlikely(!cq)) { if (unlikely(!cq)) {
mlx5_core_warn(eq->dev, "Completion event for bogus CQ 0x%x\n", cqn); mlx5_core_warn(eq->dev, "Completion event for bogus CQ 0x%x\n", cqn);
return; return;
...@@ -106,22 +113,12 @@ void mlx5_cq_completion(struct mlx5_eq *eq, u32 cqn) ...@@ -106,22 +113,12 @@ void mlx5_cq_completion(struct mlx5_eq *eq, u32 cqn)
cq->comp(cq); cq->comp(cq);
if (refcount_dec_and_test(&cq->refcount)) mlx5_cq_put(cq);
complete(&cq->free);
} }
void mlx5_cq_event(struct mlx5_eq *eq, u32 cqn, int event_type) void mlx5_cq_event(struct mlx5_eq *eq, u32 cqn, int event_type)
{ {
struct mlx5_cq_table *table = &eq->cq_table; struct mlx5_core_cq *cq = mlx5_eq_cq_get(eq, cqn);
struct mlx5_core_cq *cq;
spin_lock(&table->lock);
cq = radix_tree_lookup(&table->tree, cqn);
if (likely(cq))
refcount_inc(&cq->refcount);
spin_unlock(&table->lock);
if (unlikely(!cq)) { if (unlikely(!cq)) {
mlx5_core_warn(eq->dev, "Async event for bogus CQ 0x%x\n", cqn); mlx5_core_warn(eq->dev, "Async event for bogus CQ 0x%x\n", cqn);
...@@ -130,8 +127,7 @@ void mlx5_cq_event(struct mlx5_eq *eq, u32 cqn, int event_type) ...@@ -130,8 +127,7 @@ void mlx5_cq_event(struct mlx5_eq *eq, u32 cqn, int event_type)
cq->event(cq, event_type); cq->event(cq, event_type);
if (refcount_dec_and_test(&cq->refcount)) mlx5_cq_put(cq);
complete(&cq->free);
} }
int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq, int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
...@@ -158,7 +154,8 @@ int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq, ...@@ -158,7 +154,8 @@ int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
cq->cons_index = 0; cq->cons_index = 0;
cq->arm_sn = 0; cq->arm_sn = 0;
cq->eq = eq; cq->eq = eq;
refcount_set(&cq->refcount, 1); refcount_set(&cq->refcount, 0);
mlx5_cq_hold(cq);
init_completion(&cq->free); init_completion(&cq->free);
if (!cq->comp) if (!cq->comp)
cq->comp = mlx5_add_cq_to_tasklet; cq->comp = mlx5_add_cq_to_tasklet;
...@@ -221,8 +218,7 @@ int mlx5_core_destroy_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq) ...@@ -221,8 +218,7 @@ int mlx5_core_destroy_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq)
synchronize_irq(cq->irqn); synchronize_irq(cq->irqn);
mlx5_debug_cq_remove(dev, cq); mlx5_debug_cq_remove(dev, cq);
if (refcount_dec_and_test(&cq->refcount)) mlx5_cq_put(cq);
complete(&cq->free);
wait_for_completion(&cq->free); wait_for_completion(&cq->free);
return 0; return 0;
......
...@@ -172,6 +172,17 @@ static inline void mlx5_cq_arm(struct mlx5_core_cq *cq, u32 cmd, ...@@ -172,6 +172,17 @@ static inline void mlx5_cq_arm(struct mlx5_core_cq *cq, u32 cmd,
mlx5_write64(doorbell, uar_page + MLX5_CQ_DOORBELL, NULL); mlx5_write64(doorbell, uar_page + MLX5_CQ_DOORBELL, NULL);
} }
static inline void mlx5_cq_hold(struct mlx5_core_cq *cq)
{
refcount_inc(&cq->refcount);
}
static inline void mlx5_cq_put(struct mlx5_core_cq *cq)
{
if (refcount_dec_and_test(&cq->refcount))
complete(&cq->free);
}
int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq, int mlx5_core_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
u32 *in, int inlen); u32 *in, int inlen);
int mlx5_core_destroy_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq); int mlx5_core_destroy_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq);
......
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