Re: [PATCH linux-next v2 10/14] vdpa/mlx5: Support configuration of MAC

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




在 2021/4/7 上午1:04, Parav Pandit 写道:
From: Eli Cohen <elic@xxxxxxxxxx>

Add code to accept MAC configuration through vdpa tool. The MAC is
written into the config struct and later can be retrieved through
get_config().

Examples:
1. Configure MAC:
$ vdpa dev config set vdpa0 mac 00:11:22:33:44:55

2. Show configured params:
$ vdpa dev config show
vdpa0: mac 00:11:22:33:44:55 link down link_announce false mtu 0 speed 0 duplex 0

Signed-off-by: Eli Cohen <elic@xxxxxxxxxx>
Reviewed-by: Parav Pandit <parav@xxxxxxxxxx>
---
changelog:
v1->v2:
  - following new api for config get/set for mgmt tool
---
  drivers/vdpa/mlx5/net/mlx5_vnet.c | 45 ++++++++++++++++++++++++++++++-
  1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index aaf7f9394af0..949084aac102 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -1493,7 +1493,8 @@ static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev)
  	ndev->mvdev.mlx_features = mlx_to_vritio_features(dev_features);
  	if (MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, virtio_version_1_0))
  		ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_VERSION_1);
-	ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM);
+	ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM) |
+				     BIT_ULL(VIRTIO_NET_F_MAC);
  	print_features(mvdev, ndev->mvdev.mlx_features, false);
  	return ndev->mvdev.mlx_features;
  }
@@ -1562,6 +1563,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
  	return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
  }
+static inline u16 mlx5vdpa16_to_cpu(struct mlx5_vdpa_dev *mvdev, __virtio16 val)
+{
+	return __virtio16_to_cpu(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
  static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features)
  {
  	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -1880,6 +1886,41 @@ static int mlx5_get_vq_irq(struct vdpa_device *vdv, u16 idx)
  	return -EOPNOTSUPP;
  }
+static int mlx5_vdpa_set_ce_config(struct vdpa_device *vdev,
+				   const struct vdpa_dev_set_config *config)
+{
+	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
+	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
+	int err = 0;
+
+	mutex_lock(&ndev->reslock);
+	if (ndev->setup)
+		err = -EBUSY;
+	mutex_unlock(&ndev->reslock);
+
+	if (err)
+		return err;
+
+	if (config->net_mask.mtu_valid)
+		return -EOPNOTSUPP;
+
+	if (config->net_mask.mac_valid)
+		memcpy(ndev->config.mac, config->net.mac, ETH_ALEN);


So it looks to me this assumes that the mac can not be changed by guest because the filter is only re-programmed during setting status.

Any chance to trigger the filter programmming here to aovid future changes when VIRTIO_NET_F_CTRL_MAC is implemented?

Thanks


+
+	return 0;
+}
+
+static void mlx5_vdpa_get_ce_config(struct vdpa_device *vdev,
+				    struct vdpa_dev_config *config)
+{
+	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
+	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
+
+	memcpy(config->net.mac, ndev->config.mac, ETH_ALEN);
+	config->net.mtu = mlx5vdpa16_to_cpu(mvdev, ndev->config.mtu);
+	config->net.status = VIRTIO_NET_S_LINK_UP;
+}
+
  static const struct vdpa_config_ops mlx5_vdpa_ops = {
  	.set_vq_address = mlx5_vdpa_set_vq_address,
  	.set_vq_num = mlx5_vdpa_set_vq_num,
@@ -1902,6 +1943,8 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
  	.set_status = mlx5_vdpa_set_status,
  	.get_config = mlx5_vdpa_get_config,
  	.set_config = mlx5_vdpa_set_config,
+	.get_ce_config = mlx5_vdpa_get_ce_config,
+	.set_ce_config = mlx5_vdpa_set_ce_config,
  	.get_generation = mlx5_vdpa_get_generation,
  	.set_map = mlx5_vdpa_set_map,
  	.free = mlx5_vdpa_free,

_______________________________________________
Virtualization mailing list
Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx
https://lists.linuxfoundation.org/mailman/listinfo/virtualization




[Index of Archives]     [KVM Development]     [Libvirt Development]     [Libvirt Users]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux