drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.c

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.c
Extension
.c
Size
16494 bytes
Lines
593
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

struct mlx5e_buffer_pool {
	u32 infi_size;
	u32 size;
	u32 buff_occupancy;
};

static int mlx5e_port_query_pool(struct mlx5_core_dev *mdev,
				 struct mlx5e_buffer_pool *buffer_pool,
				 u32 desc, u8 dir, u8 pool_idx)
{
	u32 out[MLX5_ST_SZ_DW(sbpr_reg)] = {};
	int err;

	err = mlx5e_port_query_sbpr(mdev, desc, dir, pool_idx, out,
				    sizeof(out));
	if (err)
		return err;

	buffer_pool->size = MLX5_GET(sbpr_reg, out, size);
	buffer_pool->infi_size = MLX5_GET(sbpr_reg, out, infi_size);
	buffer_pool->buff_occupancy = MLX5_GET(sbpr_reg, out, buff_occupancy);

	return err;
}

enum {
	MLX5_INGRESS_DIR = 0,
	MLX5_EGRESS_DIR = 1,
};

enum {
	MLX5_LOSSY_POOL = 0,
	MLX5_LOSSLESS_POOL = 1,
};

/* No limit on usage of shared buffer pool (max_buff=0) */
#define MLX5_SB_POOL_NO_THRESHOLD  0
/* Shared buffer pool usage threshold when calculated
 * dynamically in alpha units. alpha=13 is equivalent to
 * HW_alpha of  [(1/128) * 2 ^ (alpha-1)] = 32, where HW_alpha
 * equates to the following portion of the shared buffer pool:
 * [32 / (1 + n * 32)] While *n* is the number of buffers
 * that are using the shared buffer pool.
 */
#define MLX5_SB_POOL_THRESHOLD 13

/* Shared buffer class management parameters */
struct mlx5_sbcm_params {
	u8 pool_idx;
	u8 max_buff;
	u8 infi_size;
};

static const struct mlx5_sbcm_params sbcm_default = {
	.pool_idx = MLX5_LOSSY_POOL,
	.max_buff = MLX5_SB_POOL_NO_THRESHOLD,
	.infi_size = 0,
};

static const struct mlx5_sbcm_params sbcm_lossy = {
	.pool_idx = MLX5_LOSSY_POOL,
	.max_buff = MLX5_SB_POOL_NO_THRESHOLD,
	.infi_size = 1,
};

static const struct mlx5_sbcm_params sbcm_lossless = {
	.pool_idx = MLX5_LOSSLESS_POOL,
	.max_buff = MLX5_SB_POOL_THRESHOLD,
	.infi_size = 0,
};

static const struct mlx5_sbcm_params sbcm_lossless_no_threshold = {
	.pool_idx = MLX5_LOSSLESS_POOL,
	.max_buff = MLX5_SB_POOL_NO_THRESHOLD,
	.infi_size = 1,
};

/**
 * select_sbcm_params() - selects the shared buffer pool configuration
 *
 * @buffer: <input> port buffer to retrieve params of
 * @lossless_buff_count: <input> number of lossless buffers in total
 *
 * The selection is based on the following rules:
 * 1. If buffer size is 0, no shared buffer pool is used.
 * 2. If buffer is lossy, use lossy shared buffer pool.
 * 3. If there are more than 1 lossless buffers, use lossless shared buffer pool
 *    with threshold.
 * 4. If there is only 1 lossless buffer, use lossless shared buffer pool
 *    without threshold.

Annotation

Implementation Notes