drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/xsk/setup.c
Extension
.c
Size
5796 bytes
Lines
204
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
/* Copyright (c) 2019 Mellanox Technologies. */

#include "setup.h"
#include "en/params.h"
#include "en/txrx.h"
#include "en/health.h"
#include <net/xdp_sock_drv.h>

static int mlx5e_legacy_rq_validate_xsk(struct mlx5_core_dev *mdev,
					struct mlx5e_params *params,
					struct mlx5e_rq_opt_param *rqo)
{
	if (!mlx5e_rx_is_linear_skb(mdev, params, rqo)) {
		mlx5_core_err(mdev, "Legacy RQ linear mode for XSK can't be activated with current params\n");
		return -EINVAL;
	}

	return 0;
}

/* The limitation of 2048 can be altered, but shouldn't go beyond the minimal
 * stride size of striding RQ.
 */
#define MLX5E_MIN_XSK_CHUNK_SIZE max(2048, XDP_UMEM_MIN_CHUNK_SIZE)

bool mlx5e_validate_xsk_param(struct mlx5e_params *params,
			      struct mlx5e_rq_opt_param *rqo,
			      struct mlx5_core_dev *mdev)
{
	struct mlx5e_xsk_param *xsk = mlx5e_rqo_xsk_param(rqo);

	if (WARN_ON(!xsk))
		return false;

	/* AF_XDP doesn't support frames larger than PAGE_SIZE,
	 * and xsk->chunk_size is limited to 65535 bytes.
	 */
	if ((size_t)xsk->chunk_size > PAGE_SIZE || xsk->chunk_size < MLX5E_MIN_XSK_CHUNK_SIZE) {
		mlx5_core_err(mdev, "XSK chunk size %u out of bounds [%u, %lu]\n", xsk->chunk_size,
			      MLX5E_MIN_XSK_CHUNK_SIZE, PAGE_SIZE);
		return false;
	}

	/* frag_sz is different for regular and XSK RQs, so ensure that linear
	 * SKB mode is possible.
	 */
	switch (params->rq_wq_type) {
	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
		return !mlx5e_mpwrq_validate_xsk(mdev, params, rqo);
	default: /* MLX5_WQ_TYPE_CYCLIC */
		return !mlx5e_legacy_rq_validate_xsk(mdev, params, rqo);
	}
}

static int mlx5e_init_xsk_rq(struct mlx5e_channel *c,
			     struct mlx5e_params *params,
			     struct xsk_buff_pool *pool,
			     struct mlx5e_xsk_param *xsk,
			     struct mlx5e_rq *rq)
{
	struct mlx5_core_dev *mdev = c->mdev;
	int rq_xdp_ix;
	int err;

	rq->wq_type      = params->rq_wq_type;
	rq->pdev         = c->pdev;
	rq->netdev       = c->netdev;
	rq->priv         = c->priv;
	rq->hwtstamp_config = &c->priv->hwtstamp_config;
	rq->clock        = mdev->clock;
	rq->icosq        = &c->icosq;
	rq->ix           = c->ix;
	rq->channel      = c;
	rq->mdev         = mdev;
	rq->hw_mtu       = MLX5E_SW2HW_MTU(params, params->sw_mtu);
	rq->xdpsq        = &c->rq_xdpsq;
	rq->xsk_pool     = pool;
	rq->stats        = &c->priv->channel_stats[c->ix]->xskrq;
	rq->ptp_cyc2time = mlx5_rq_ts_translator(mdev);
	rq_xdp_ix        = c->ix;
	err = mlx5e_rq_set_handlers(rq, params, xsk);
	if (err)
		return err;

	return xdp_rxq_info_reg(&rq->xdp_rxq, rq->netdev, rq_xdp_ix, c->napi.napi_id);
}

static int mlx5e_open_xsk_rq(struct mlx5e_channel *c,
			     struct mlx5e_params *params,

Annotation

Implementation Notes