drivers/net/ethernet/mellanox/mlx5/core/cq.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/cq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/cq.c- Extension
.c- Size
- 8027 bytes
- Lines
- 256
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/hardirq.hlinux/mlx5/driver.hrdma/ib_verbs.hlinux/mlx5/cq.hmlx5_core.hlib/eq.h
Detected Declarations
function Copyrightfunction list_for_each_entry_safefunction mlx5_add_cq_to_taskletfunction mlx5_core_cq_dummy_cbfunction mlx5_create_cqfunction mlx5_core_create_cqfunction mlx5_core_destroy_cqfunction mlx5_core_query_cqfunction mlx5_core_modify_cqfunction mlx5_core_modify_cq_moderationexport mlx5_add_cq_to_taskletexport mlx5_create_cqexport mlx5_core_create_cqexport mlx5_core_destroy_cqexport mlx5_core_query_cqexport mlx5_core_modify_cqexport mlx5_core_modify_cq_moderation
Annotated Snippet
#include <linux/kernel.h>
#include <linux/hardirq.h>
#include <linux/mlx5/driver.h>
#include <rdma/ib_verbs.h>
#include <linux/mlx5/cq.h>
#include "mlx5_core.h"
#include "lib/eq.h"
#define TASKLET_MAX_TIME 2
#define TASKLET_MAX_TIME_JIFFIES msecs_to_jiffies(TASKLET_MAX_TIME)
void mlx5_cq_tasklet_cb(struct tasklet_struct *t)
{
unsigned long flags;
unsigned long end = jiffies + TASKLET_MAX_TIME_JIFFIES;
struct mlx5_eq_tasklet *ctx = from_tasklet(ctx, t, task);
struct mlx5_core_cq *mcq;
struct mlx5_core_cq *temp;
spin_lock_irqsave(&ctx->lock, flags);
list_splice_tail_init(&ctx->list, &ctx->process_list);
spin_unlock_irqrestore(&ctx->lock, flags);
list_for_each_entry_safe(mcq, temp, &ctx->process_list,
tasklet_ctx.list) {
list_del_init(&mcq->tasklet_ctx.list);
mcq->tasklet_ctx.comp(mcq, NULL);
mlx5_cq_put(mcq);
if (time_after(jiffies, end))
break;
}
if (!list_empty(&ctx->process_list))
tasklet_schedule(&ctx->task);
}
void mlx5_add_cq_to_tasklet(struct mlx5_core_cq *cq,
struct mlx5_eqe *eqe)
{
unsigned long flags;
struct mlx5_eq_tasklet *tasklet_ctx = cq->tasklet_ctx.priv;
bool schedule_tasklet = false;
spin_lock_irqsave(&tasklet_ctx->lock, flags);
/* When migrating CQs between EQs will be implemented, please note
* that you need to sync this point. It is possible that
* while migrating a CQ, completions on the old EQs could
* still arrive.
*/
if (list_empty_careful(&cq->tasklet_ctx.list)) {
mlx5_cq_hold(cq);
/* If the tasklet CQ work list isn't empty, mlx5_cq_tasklet_cb()
* is scheduled/running and hasn't processed the list yet, so it
* will see this added CQ when it runs. If the list is empty,
* the tasklet needs to be scheduled to pick up the CQ. The
* spinlock avoids any race with the tasklet accessing the list.
*/
schedule_tasklet = list_empty(&tasklet_ctx->list);
list_add_tail(&cq->tasklet_ctx.list, &tasklet_ctx->list);
}
spin_unlock_irqrestore(&tasklet_ctx->lock, flags);
if (schedule_tasklet)
tasklet_schedule(&tasklet_ctx->task);
}
EXPORT_SYMBOL(mlx5_add_cq_to_tasklet);
static void mlx5_core_cq_dummy_cb(struct mlx5_core_cq *cq, struct mlx5_eqe *eqe)
{
mlx5_core_err(cq->eq->core.dev,
"CQ default completion callback, CQ #%u\n", cq->cqn);
}
#define MLX5_CQ_INIT_CMD_SN cpu_to_be32(2 << 28)
/* Callers must verify outbox status in case of err */
int mlx5_create_cq(struct mlx5_core_dev *dev, struct mlx5_core_cq *cq,
u32 *in, int inlen, u32 *out, int outlen)
{
int eqn = MLX5_GET(cqc, MLX5_ADDR_OF(create_cq_in, in, cq_context),
c_eqn_or_apu_element);
u32 din[MLX5_ST_SZ_DW(destroy_cq_in)] = {};
struct mlx5_eq_comp *eq;
int err;
eq = mlx5_eqn2comp_eq(dev, eqn);
if (IS_ERR(eq))
return PTR_ERR(eq);
memset(out, 0, outlen);
MLX5_SET(create_cq_in, in, opcode, MLX5_CMD_OP_CREATE_CQ);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/hardirq.h`, `linux/mlx5/driver.h`, `rdma/ib_verbs.h`, `linux/mlx5/cq.h`, `mlx5_core.h`, `lib/eq.h`.
- Detected declarations: `function Copyright`, `function list_for_each_entry_safe`, `function mlx5_add_cq_to_tasklet`, `function mlx5_core_cq_dummy_cb`, `function mlx5_create_cq`, `function mlx5_core_create_cq`, `function mlx5_core_destroy_cq`, `function mlx5_core_query_cq`, `function mlx5_core_modify_cq`, `function mlx5_core_modify_cq_moderation`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.