Re: [PATCH linux-next v6 5/8] vdpa_sim_net: Enable user to set mac address and mtu

2021-10-26 Thread Stefano Garzarella

On Tue, Oct 26, 2021 at 07:02:40AM +0300, Parav Pandit via Virtualization wrote:

Enable user to set the mac address and mtu so that each vdpa device
can have its own user specified mac address and mtu.

Now that user is enabled to set the mac address, remove the module
parameter for same.

And example of setting mac addr and mtu and view the configuration:
$ vdpa mgmtdev show
vdpasim_net:
 supported_classes net

$ vdpa dev add name bar mgmtdev vdpasim_net mac 00:11:22:33:44:55 mtu 9000

$ vdpa dev config show
bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000

Signed-off-by: Parav Pandit 
Reviewed-by: Eli Cohen 
---
changelog:
v4->v5:
- updated commit log example for add command
---
drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 35 +++-
1 file changed, 19 insertions(+), 16 deletions(-)


Reviewed-by: Stefano Garzarella 

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization


Re: [PATCH linux-next v6 5/8] vdpa_sim_net: Enable user to set mac address and mtu

2021-10-25 Thread Jason Wang
On Tue, Oct 26, 2021 at 12:03 PM Parav Pandit  wrote:
>
> Enable user to set the mac address and mtu so that each vdpa device
> can have its own user specified mac address and mtu.
>
> Now that user is enabled to set the mac address, remove the module
> parameter for same.
>
> And example of setting mac addr and mtu and view the configuration:
> $ vdpa mgmtdev show
> vdpasim_net:
>   supported_classes net
>
> $ vdpa dev add name bar mgmtdev vdpasim_net mac 00:11:22:33:44:55 mtu 9000
>
> $ vdpa dev config show
> bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000
>
> Signed-off-by: Parav Pandit 
> Reviewed-by: Eli Cohen 

Acked-by: Jason Wang 

> ---
> changelog:
> v4->v5:
>  - updated commit log example for add command
> ---
>  drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 35 +++-
>  1 file changed, 19 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c 
> b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
> index d681e423e64f..76dd24abc791 100644
> --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c
> @@ -16,6 +16,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>
>  #include "vdpa_sim.h"
>
> @@ -29,12 +30,6 @@
>
>  #define VDPASIM_NET_VQ_NUM 2
>
> -static char *macaddr;
> -module_param(macaddr, charp, 0);
> -MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
> -
> -static u8 macaddr_buf[ETH_ALEN];
> -
>  static void vdpasim_net_work(struct work_struct *work)
>  {
> struct vdpasim *vdpasim = container_of(work, struct vdpasim, work);
> @@ -112,9 +107,21 @@ static void vdpasim_net_get_config(struct vdpasim 
> *vdpasim, void *config)
>  {
> struct virtio_net_config *net_config = config;
>
> -   net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
> net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
> -   memcpy(net_config->mac, macaddr_buf, ETH_ALEN);
> +}
> +
> +static void vdpasim_net_setup_config(struct vdpasim *vdpasim,
> +const struct vdpa_dev_set_config *config)
> +{
> +   struct virtio_net_config *vio_config = vdpasim->config;
> +
> +   if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR))
> +   memcpy(vio_config->mac, config->net.mac, ETH_ALEN);
> +   if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MTU))
> +   vio_config->mtu = cpu_to_vdpasim16(vdpasim, config->net.mtu);
> +   else
> +   /* Setup default MTU to be 1500 */
> +   vio_config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
>  }
>
>  static void vdpasim_net_mgmtdev_release(struct device *dev)
> @@ -147,6 +154,8 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev 
> *mdev, const char *name,
> if (IS_ERR(simdev))
> return PTR_ERR(simdev);
>
> +   vdpasim_net_setup_config(simdev, config);
> +
> ret = _vdpa_register_device(>vdpa, VDPASIM_NET_VQ_NUM);
> if (ret)
> goto reg_err;
> @@ -180,20 +189,14 @@ static struct vdpa_mgmt_dev mgmt_dev = {
> .device = _net_mgmtdev,
> .id_table = id_table,
> .ops = _net_mgmtdev_ops,
> +   .config_attr_mask = (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR |
> +1 << VDPA_ATTR_DEV_NET_CFG_MTU),
>  };
>
>  static int __init vdpasim_net_init(void)
>  {
> int ret;
>
> -   if (macaddr) {
> -   mac_pton(macaddr, macaddr_buf);
> -   if (!is_valid_ether_addr(macaddr_buf))
> -   return -EADDRNOTAVAIL;
> -   } else {
> -   eth_random_addr(macaddr_buf);
> -   }
> -
> ret = device_register(_net_mgmtdev);
> if (ret)
> return ret;
> --
> 2.25.4
>

___
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization