On Mon, 2024-07-08 at 14:55 +0800, Cindy Lu wrote:
> Add the function to support setting the MAC address.
> For vdpa/mlx5, the function will use mlx5_mpfs_add_mac
> to set the mac address
> 
> Tested in ConnectX-6 Dx device
> 
> Signed-off-by: Cindy Lu <l...@redhat.com>
> ---
>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c 
> b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 26ba7da6b410..f78701386690 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -3616,10 +3616,33 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev 
> *v_mdev, struct vdpa_device *
>       destroy_workqueue(wq);
>       mgtdev->ndev = NULL;
>  }
> +static int mlx5_vdpa_set_attr_mac(struct vdpa_mgmt_dev *v_mdev,
> +                               struct vdpa_device *dev,
> +                               const struct vdpa_dev_set_config *add_config)
> +{
> +     struct mlx5_vdpa_dev *mvdev = to_mvdev(dev);
> +     struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
> +     struct mlx5_core_dev *mdev = mvdev->mdev;
> +     struct virtio_net_config *config = &ndev->config;
> +     int err;
> +     struct mlx5_core_dev *pfmdev;
> +
You need to take the ndev->reslock.

> +     if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> +             if (!is_zero_ether_addr(add_config->net.mac)) {
> +                     memcpy(config->mac, add_config->net.mac, ETH_ALEN);
I would do the memcpy after mlx5_mpfs_add_mac() was called successfully. This
way the config gets changed only on success.

> +                     pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
> +                     err = mlx5_mpfs_add_mac(pfmdev, config->mac);
> +                     if (err)
> +                             return -1;
> +             }
> +     }
> +     return 0;
> +}
>  
>  static const struct vdpa_mgmtdev_ops mdev_ops = {
>       .dev_add = mlx5_vdpa_dev_add,
>       .dev_del = mlx5_vdpa_dev_del,
> +     .dev_set_attr = mlx5_vdpa_set_attr_mac,
>  };
>  
>  static struct virtio_device_id id_table[] = {

Thanks,
Dragos

Reply via email to