drivers/net/ethernet/mellanox/mlx5/core/lib/hv_vhca.c

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

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/mellanox/mlx5/core/lib/hv_vhca.c
Extension
.c
Size
8534 bytes
Lines
372
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 mlx5_hv_vhca {
	struct mlx5_core_dev       *dev;
	struct workqueue_struct    *work_queue;
	struct mlx5_hv_vhca_agent  *agents[MLX5_HV_VHCA_AGENT_MAX];
	struct mutex                agents_lock; /* Protect agents array */
};

struct mlx5_hv_vhca_work {
	struct work_struct     invalidate_work;
	struct mlx5_hv_vhca   *hv_vhca;
	u64                    block_mask;
};

struct mlx5_hv_vhca_data_block {
	u16     sequence;
	u16     offset;
	u8      reserved[4];
	u64     data[15];
};

struct mlx5_hv_vhca_agent {
	enum mlx5_hv_vhca_agent_type	 type;
	struct mlx5_hv_vhca		*hv_vhca;
	void				*priv;
	u16                              seq;
	void (*control)(struct mlx5_hv_vhca_agent *agent,
			struct mlx5_hv_vhca_control_block *block);
	void (*invalidate)(struct mlx5_hv_vhca_agent *agent,
			   u64 block_mask);
	void (*cleanup)(struct mlx5_hv_vhca_agent *agent);
};

struct mlx5_hv_vhca *mlx5_hv_vhca_create(struct mlx5_core_dev *dev)
{
	struct mlx5_hv_vhca *hv_vhca;

	hv_vhca = kzalloc_obj(*hv_vhca);
	if (!hv_vhca)
		return ERR_PTR(-ENOMEM);

	hv_vhca->work_queue = create_singlethread_workqueue("mlx5_hv_vhca");
	if (!hv_vhca->work_queue) {
		kfree(hv_vhca);
		return ERR_PTR(-ENOMEM);
	}

	hv_vhca->dev = dev;
	mutex_init(&hv_vhca->agents_lock);

	return hv_vhca;
}

void mlx5_hv_vhca_destroy(struct mlx5_hv_vhca *hv_vhca)
{
	if (IS_ERR_OR_NULL(hv_vhca))
		return;

	destroy_workqueue(hv_vhca->work_queue);
	kfree(hv_vhca);
}

static void mlx5_hv_vhca_invalidate_work(struct work_struct *work)
{
	struct mlx5_hv_vhca_work *hwork;
	struct mlx5_hv_vhca *hv_vhca;
	int i;

	hwork = container_of(work, struct mlx5_hv_vhca_work, invalidate_work);
	hv_vhca = hwork->hv_vhca;

	mutex_lock(&hv_vhca->agents_lock);
	for (i = 0; i < MLX5_HV_VHCA_AGENT_MAX; i++) {
		struct mlx5_hv_vhca_agent *agent = hv_vhca->agents[i];

		if (!agent || !agent->invalidate)
			continue;

		if (!(BIT(agent->type) & hwork->block_mask))
			continue;

		agent->invalidate(agent, hwork->block_mask);
	}
	mutex_unlock(&hv_vhca->agents_lock);

	kfree(hwork);
}

void mlx5_hv_vhca_invalidate(void *context, u64 block_mask)
{
	struct mlx5_hv_vhca *hv_vhca = (struct mlx5_hv_vhca *)context;

Annotation

Implementation Notes