drivers/infiniband/hw/mlx5/ib_virt.c

Source file repositories/reference/linux-study-clean/drivers/infiniband/hw/mlx5/ib_virt.c

File Facts

System
Linux kernel
Corpus path
drivers/infiniband/hw/mlx5/ib_virt.c
Extension
.c
Size
6309 bytes
Lines
225
Domain
Driver Families
Bucket
drivers/infiniband
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

#include <linux/mlx5/vport.h>
#include "mlx5_ib.h"

static inline u32 mlx_to_net_policy(enum port_state_policy mlx_policy)
{
	switch (mlx_policy) {
	case MLX5_POLICY_DOWN:
		return IFLA_VF_LINK_STATE_DISABLE;
	case MLX5_POLICY_UP:
		return IFLA_VF_LINK_STATE_ENABLE;
	case MLX5_POLICY_FOLLOW:
		return IFLA_VF_LINK_STATE_AUTO;
	default:
		return __IFLA_VF_LINK_STATE_MAX;
	}
}

int mlx5_ib_get_vf_config(struct ib_device *device, int vf, u32 port,
			  struct ifla_vf_info *info)
{
	struct mlx5_ib_dev *dev = to_mdev(device);
	struct mlx5_core_dev *mdev = dev->mdev;
	struct mlx5_hca_vport_context *rep;
	int err;

	rep = kzalloc_obj(*rep);
	if (!rep)
		return -ENOMEM;

	err = mlx5_query_hca_vport_context(mdev, 1, 1,  vf + 1, rep);
	if (err) {
		mlx5_ib_warn(dev, "failed to query port policy for vf %d (%d)\n",
			     vf, err);
		goto free;
	}
	memset(info, 0, sizeof(*info));
	info->linkstate = mlx_to_net_policy(rep->policy);
	if (info->linkstate == __IFLA_VF_LINK_STATE_MAX)
		err = -EINVAL;

free:
	kfree(rep);
	return err;
}

static inline enum port_state_policy net_to_mlx_policy(int policy)
{
	switch (policy) {
	case IFLA_VF_LINK_STATE_DISABLE:
		return MLX5_POLICY_DOWN;
	case IFLA_VF_LINK_STATE_ENABLE:
		return MLX5_POLICY_UP;
	case IFLA_VF_LINK_STATE_AUTO:
		return MLX5_POLICY_FOLLOW;
	default:
		return MLX5_POLICY_INVALID;
	}
}

int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
			      u32 port, int state)
{
	struct mlx5_ib_dev *dev = to_mdev(device);
	struct mlx5_core_dev *mdev = dev->mdev;
	struct mlx5_hca_vport_context *in;
	struct mlx5_vf_context *vfs_ctx = mdev->priv.sriov.vfs_ctx;
	int err;

	in = kzalloc_obj(*in);
	if (!in)
		return -ENOMEM;

	in->policy = net_to_mlx_policy(state);
	if (in->policy == MLX5_POLICY_INVALID) {
		err = -EINVAL;
		goto out;
	}
	in->field_select = MLX5_HCA_VPORT_SEL_STATE_POLICY;
	err = mlx5_core_modify_hca_vport_context(mdev, 1, 1, vf + 1, in);
	if (!err)
		vfs_ctx[vf].policy = in->policy;

out:
	kfree(in);
	return err;
}

int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
			 u32 port, struct ifla_vf_stats *stats)
{

Annotation

Implementation Notes