Enable user to set the mac address and mtu so that each vdpa device can have its own user specified mac address and mtu. This is done by implementing the management device's configuration layout fields setting callback routine. Now that user is enabled to set the mac address, remove the module parameter for same. And example of setting mac addr and mtu: $ vdpa mgmtdev show $ vdpa dev add name bar mgmtdev vdpasim_net $ vdpa dev config set bar mac 00:11:22:33:44:55 mtu 9000 View the config after setting: $ vdpa dev config show bar: mac 00:11:22:33:44:55 link up link_announce false mtu 9000 speed 0 duplex 0 Signed-off-by: Parav Pandit <parav@xxxxxxxxxx> Reviewed-by: Eli Cohen <elic@xxxxxxxxxx> --- changelog: v1->v2: - using updated interface and callbacks for get/set config --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 26 +++++++++++++++++++ drivers/vdpa/vdpa_sim/vdpa_sim.h | 4 +++ drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 39 +++++++++++++++++----------- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 5b6b2f87d40c..5d59e06ab224 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -467,6 +467,28 @@ static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset, vdpasim->dev_attr.set_config(vdpasim, vdpasim->config); } +static void vdpasim_get_ce_config(struct vdpa_device *vdpa, + struct vdpa_dev_config *config) +{ + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + + if (!vdpasim->dev_attr.get_ce_config) + return; + + vdpasim->dev_attr.get_ce_config(vdpasim, config); +} + +static int vdpasim_set_ce_config(struct vdpa_device *vdpa, + const struct vdpa_dev_set_config *config) +{ + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + + if (!vdpasim->dev_attr.set_ce_config) + return -EOPNOTSUPP; + + return vdpasim->dev_attr.set_ce_config(vdpasim, config); +} + static u32 vdpasim_get_generation(struct vdpa_device *vdpa) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); @@ -568,6 +590,8 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .set_status = vdpasim_set_status, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, + .get_ce_config = vdpasim_get_ce_config, + .set_ce_config = vdpasim_set_ce_config, .get_generation = vdpasim_get_generation, .get_iova_range = vdpasim_get_iova_range, .dma_map = vdpasim_dma_map, @@ -595,6 +619,8 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .set_status = vdpasim_set_status, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, + .get_ce_config = vdpasim_get_ce_config, + .set_ce_config = vdpasim_set_ce_config, .get_generation = vdpasim_get_generation, .get_iova_range = vdpasim_get_iova_range, .set_map = vdpasim_set_map, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index 6d75444f9948..62a21a4567cf 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -44,6 +44,10 @@ struct vdpasim_dev_attr { work_func_t work_fn; void (*get_config)(struct vdpasim *vdpasim, void *config); void (*set_config)(struct vdpasim *vdpasim, const void *config); + void (*get_ce_config)(struct vdpasim *vdpasim, + struct vdpa_dev_config *config); + int (*set_ce_config)(struct vdpasim *vdpasim, + const struct vdpa_dev_set_config *config); }; /* State of each vdpasim device */ diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index a1ab6163f7d1..bdc70e9bf3a2 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -29,12 +29,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); @@ -114,7 +108,28 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *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_get_ce_config(struct vdpasim *vdpasim, + struct vdpa_dev_config *config) +{ + struct virtio_net_config *vio_config = vdpasim->config; + + memcpy(config->net.mac, vio_config->mac, ETH_ALEN); + config->net.mtu = vdpasim16_to_cpu(vdpasim, vio_config->mtu); + config->net.status = VIRTIO_NET_S_LINK_UP; +} + +static int vdpasim_net_set_ce_config(struct vdpasim *vdpasim, + const struct vdpa_dev_set_config *config) +{ + struct virtio_net_config *vio_config = vdpasim->config; + + if (config->net_mask.mac_valid) + memcpy(vio_config->mac, config->net.mac, ETH_ALEN); + if (config->net_mask.mtu_valid) + vio_config->mtu = cpu_to_vdpasim16(vdpasim, config->net.mtu); + return 0; } static void vdpasim_net_mgmtdev_release(struct device *dev) @@ -139,6 +154,8 @@ static int vdpasim_net_dev_add(struct vdpa_mgmt_dev *mdev, const char *name) dev_attr.nvqs = VDPASIM_NET_VQ_NUM; dev_attr.config_size = sizeof(struct virtio_net_config); dev_attr.get_config = vdpasim_net_get_config; + dev_attr.get_ce_config = vdpasim_net_get_ce_config; + dev_attr.set_ce_config = vdpasim_net_set_ce_config; dev_attr.work_fn = vdpasim_net_work; dev_attr.buffer_size = PAGE_SIZE; @@ -185,14 +202,6 @@ 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(&vdpasim_net_mgmtdev); if (ret) return ret; -- 2.26.2 _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization