drivers/net/ethernet/mellanox/mlx5/core/en/trap.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/trap.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/trap.c- Extension
.c- Size
- 7985 bytes
- Lines
- 336
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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
en/txrx.hen/params.hen/trap.h
Detected Declarations
function mlx5e_trap_napi_pollfunction mlx5e_init_trap_rqfunction mlx5e_open_trap_rqfunction mlx5e_close_trap_rqfunction mlx5e_create_trap_direct_rq_tirfunction mlx5e_build_trap_paramsfunction mlx5e_close_trapfunction mlx5e_activate_trapfunction mlx5e_deactivate_trapfunction mlx5e_del_trap_queuefunction mlx5e_trap_get_tirnfunction mlx5e_handle_action_trapfunction mlx5e_handle_action_dropfunction mlx5e_handle_trap_eventfunction mlx5e_apply_trapfunction mlx5e_apply_traps
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2020 Mellanox Technologies */
#include "en/txrx.h"
#include "en/params.h"
#include "en/trap.h"
static int mlx5e_trap_napi_poll(struct napi_struct *napi, int budget)
{
struct mlx5e_trap *trap_ctx = container_of(napi, struct mlx5e_trap, napi);
struct mlx5e_ch_stats *ch_stats = trap_ctx->stats;
struct mlx5e_rq *rq = &trap_ctx->rq;
bool busy = false;
int work_done = 0;
rcu_read_lock();
ch_stats->poll++;
work_done = mlx5e_poll_rx_cq(&rq->cq, budget);
busy |= work_done == budget;
busy |= rq->post_wqes(rq);
if (busy) {
work_done = budget;
goto out;
}
if (unlikely(!napi_complete_done(napi, work_done)))
goto out;
mlx5e_cq_arm(&rq->cq);
out:
rcu_read_unlock();
return work_done;
}
static void mlx5e_init_trap_rq(struct mlx5e_trap *t, struct mlx5e_params *params,
struct mlx5e_rq *rq)
{
struct mlx5_core_dev *mdev = t->mdev;
struct mlx5e_priv *priv = t->priv;
rq->wq_type = params->rq_wq_type;
rq->pdev = t->pdev;
rq->netdev = priv->netdev;
rq->priv = priv;
rq->clock = mdev->clock;
rq->hwtstamp_config = &priv->hwtstamp_config;
rq->mdev = mdev;
rq->hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
rq->stats = &priv->trap_stats.rq;
rq->ptp_cyc2time = mlx5_rq_ts_translator(mdev);
xdp_rxq_info_unused(&rq->xdp_rxq);
mlx5e_rq_set_trap_handlers(rq, params);
}
static int mlx5e_open_trap_rq(struct mlx5e_priv *priv, struct mlx5e_trap *t)
{
struct mlx5e_rq_param *rq_param = &t->rq_param;
struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_create_cq_param ccp = {};
struct dim_cq_moder trap_moder = {};
struct mlx5e_rq *rq = &t->rq;
u16 q_counter;
int node;
int err;
node = dev_to_node(mdev->device);
q_counter = priv->q_counter[0];
ccp.netdev = priv->netdev;
ccp.wq = priv->wq;
ccp.node = node;
ccp.ch_stats = t->stats;
ccp.napi = &t->napi;
ccp.ix = 0;
ccp.uar = mdev->priv.bfreg.up;
err = mlx5e_open_cq(priv->mdev, trap_moder, &rq_param->cqp, &ccp, &rq->cq);
if (err)
return err;
mlx5e_init_trap_rq(t, &t->params, rq);
err = mlx5e_open_rq(&t->params, rq_param, NULL, node, q_counter, rq);
if (err)
goto err_destroy_cq;
return 0;
Annotation
- Immediate include surface: `en/txrx.h`, `en/params.h`, `en/trap.h`.
- Detected declarations: `function mlx5e_trap_napi_poll`, `function mlx5e_init_trap_rq`, `function mlx5e_open_trap_rq`, `function mlx5e_close_trap_rq`, `function mlx5e_create_trap_direct_rq_tir`, `function mlx5e_build_trap_params`, `function mlx5e_close_trap`, `function mlx5e_activate_trap`, `function mlx5e_deactivate_trap`, `function mlx5e_del_trap_queue`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source 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.