drivers/net/ethernet/mellanox/mlx4/en_rx.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx4/en_rx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/mellanox/mlx4/en_rx.c- Extension
.c- Size
- 36349 bytes
- Lines
- 1313
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bpf.hlinux/bpf_trace.hlinux/mlx4/cq.hlinux/slab.hlinux/mlx4/qp.hlinux/skbuff.hlinux/rculist.hlinux/if_ether.hlinux/if_vlan.hlinux/vmalloc.hlinux/irq.hlinux/skbuff_ref.hnet/ip.hnet/ip6_checksum.hnet/page_pool/helpers.hmlx4_en.h
Detected Declarations
struct mlx4_en_xdp_bufffunction Copyrightfunction mlx4_en_free_fragfunction mlx4_en_init_rx_descfunction mlx4_en_prepare_rx_descfunction mlx4_en_is_ring_emptyfunction mlx4_en_update_rx_prod_dbfunction mlx4_en_free_rx_descfunction mlx4_en_fill_rx_buffersfunction mlx4_en_free_rx_buffunction mlx4_en_set_num_rx_ringsfunction mlx4_foreach_portfunction mlx4_en_create_rx_ringfunction mlx4_en_activate_rx_ringsfunction functionfunction mlx4_en_destroy_rx_ringfunction mlx4_en_deactivate_rx_ringfunction mlx4_en_complete_rx_descfunction validate_loopbackfunction mlx4_en_refill_rx_buffersfunction get_fixed_vlan_csumfunction get_fixed_ipv4_csumfunction get_fixed_ipv6_csumfunction thefunction mlx4_en_xdp_rx_timestampfunction mlx4_en_xdp_rx_hashfunction mlx4_en_process_rx_cqfunction hlist_for_each_entry_rcu_bhfunction mlx4_en_rx_irqfunction mlx4_en_poll_rx_cqfunction mlx4_en_calc_rx_buffunction mlx4_en_config_rss_qpfunction mlx4_en_create_drop_qpfunction mlx4_en_destroy_drop_qpfunction mlx4_en_config_rss_steerfunction mlx4_en_release_rss_steer
Annotated Snippet
struct mlx4_en_xdp_buff {
struct xdp_buff xdp;
struct mlx4_cqe *cqe;
struct mlx4_en_dev *mdev;
struct mlx4_en_rx_ring *ring;
struct net_device *dev;
};
int mlx4_en_xdp_rx_timestamp(const struct xdp_md *ctx, u64 *timestamp)
{
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
if (unlikely(_ctx->ring->hwtstamp_rx_filter != HWTSTAMP_FILTER_ALL))
return -ENODATA;
*timestamp = mlx4_en_get_hwtstamp(_ctx->mdev,
mlx4_en_get_cqe_ts(_ctx->cqe));
return 0;
}
int mlx4_en_xdp_rx_hash(const struct xdp_md *ctx, u32 *hash,
enum xdp_rss_hash_type *rss_type)
{
struct mlx4_en_xdp_buff *_ctx = (void *)ctx;
struct mlx4_cqe *cqe = _ctx->cqe;
enum xdp_rss_hash_type xht = 0;
__be16 status;
if (unlikely(!(_ctx->dev->features & NETIF_F_RXHASH)))
return -ENODATA;
*hash = be32_to_cpu(cqe->immed_rss_invalid);
status = cqe->status;
if (status & cpu_to_be16(MLX4_CQE_STATUS_TCP))
xht = XDP_RSS_L4_TCP;
if (status & cpu_to_be16(MLX4_CQE_STATUS_UDP))
xht = XDP_RSS_L4_UDP;
if (status & cpu_to_be16(MLX4_CQE_STATUS_IPV4 | MLX4_CQE_STATUS_IPV4F))
xht |= XDP_RSS_L3_IPV4;
if (status & cpu_to_be16(MLX4_CQE_STATUS_IPV6)) {
xht |= XDP_RSS_L3_IPV6;
if (cqe->ipv6_ext_mask)
xht |= XDP_RSS_L3_DYNHDR;
}
*rss_type = xht;
return 0;
}
int mlx4_en_process_rx_cq(struct net_device *dev, struct mlx4_en_cq *cq, int budget)
{
struct mlx4_en_priv *priv = netdev_priv(dev);
struct mlx4_en_xdp_buff mxbuf = {};
int factor = priv->cqe_factor;
struct mlx4_en_rx_ring *ring;
struct bpf_prog *xdp_prog;
int cq_ring = cq->ring;
bool doorbell_pending;
bool xdp_redir_flush;
struct mlx4_cqe *cqe;
int polled = 0;
int index;
if (unlikely(!priv->port_up || budget <= 0))
return 0;
ring = priv->rx_ring[cq_ring];
xdp_prog = rcu_dereference_bh(ring->xdp_prog);
xdp_init_buff(&mxbuf.xdp, priv->frag_info[0].frag_stride, &ring->xdp_rxq);
doorbell_pending = false;
xdp_redir_flush = false;
/* We assume a 1:1 mapping between CQEs and Rx descriptors, so Rx
* descriptor offset can be deduced from the CQE index instead of
* reading 'cqe->index' */
index = cq->mcq.cons_index & ring->size_mask;
cqe = mlx4_en_get_cqe(cq->buf, index, priv->cqe_size) + factor;
/* Process all completed CQEs */
while (XNOR(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK,
cq->mcq.cons_index & cq->size)) {
struct mlx4_en_rx_alloc *frags;
enum pkt_hash_types hash_type;
struct sk_buff *skb;
unsigned int length;
int ip_summed;
void *va;
int nr;
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/bpf_trace.h`, `linux/mlx4/cq.h`, `linux/slab.h`, `linux/mlx4/qp.h`, `linux/skbuff.h`, `linux/rculist.h`, `linux/if_ether.h`.
- Detected declarations: `struct mlx4_en_xdp_buff`, `function Copyright`, `function mlx4_en_free_frag`, `function mlx4_en_init_rx_desc`, `function mlx4_en_prepare_rx_desc`, `function mlx4_en_is_ring_empty`, `function mlx4_en_update_rx_prod_db`, `function mlx4_en_free_rx_desc`, `function mlx4_en_fill_rx_buffers`, `function mlx4_en_free_rx_buf`.
- 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.