To support creating multiple vdpa devices and to allow user to manage them, add a knob to disable a default vdpa net device. Signed-off-by: Parav Pandit <parav@xxxxxxxxxx> --- Changelog: v1->v2: - new patch --- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 41 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index f0482427186b..34155831538c 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -33,6 +33,10 @@ static char *macaddr; module_param(macaddr, charp, 0); MODULE_PARM_DESC(macaddr, "Ethernet MAC address"); +static bool default_device = true; +module_param(default_device, bool, 0); +MODULE_PARM_DESC(default_device, "Support single default VDPA device"); + static u8 macaddr_buf[ETH_ALEN]; static struct vdpasim *vdpasim_net_dev; @@ -120,21 +124,11 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config) memcpy(net_config->mac, macaddr_buf, ETH_ALEN); } -static int __init vdpasim_net_init(void) +static int vdpasim_net_default_dev_register(void) { struct vdpasim_dev_attr dev_attr = {}; int ret; - if (macaddr) { - mac_pton(macaddr, macaddr_buf); - if (!is_valid_ether_addr(macaddr_buf)) { - ret = -EADDRNOTAVAIL; - goto out; - } - } else { - eth_random_addr(macaddr_buf); - } - dev_attr.id = VIRTIO_ID_NET; dev_attr.supported_features = VDPASIM_NET_FEATURES; dev_attr.nvqs = VDPASIM_NET_VQ_NUM; @@ -161,13 +155,36 @@ static int __init vdpasim_net_init(void) return ret; } -static void __exit vdpasim_net_exit(void) +static void vdpasim_net_default_dev_unregister(void) { struct vdpa_device *vdpa = &vdpasim_net_dev->vdpa; vdpa_unregister_device(vdpa); } +static int __init vdpasim_net_init(void) +{ + int ret = 0; + + if (macaddr) { + mac_pton(macaddr, macaddr_buf); + if (!is_valid_ether_addr(macaddr_buf)) + return -EADDRNOTAVAIL; + } else { + eth_random_addr(macaddr_buf); + } + + if (default_device) + ret = vdpasim_net_default_dev_register(); + return ret; +} + +static void __exit vdpasim_net_exit(void) +{ + if (default_device) + vdpasim_net_default_dev_unregister(); +} + module_init(vdpasim_net_init); module_exit(vdpasim_net_exit); -- 2.26.2 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization