Message ID | 20240729052146.621924-3-lulu@redhat.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | vdpa: support set mac address from vdpa tool | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
> +static int vdpasim_net_set_attr(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev, > + const struct vdpa_dev_set_config *config) > +{ > + struct vdpasim *vdpasim = container_of(dev, struct vdpasim, vdpa); > + struct virtio_net_config *vio_config = vdpasim->config; > + > + mutex_lock(&vdpasim->mutex); > + > + if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { > + ether_addr_copy(vio_config->mac, config->net.mac); > + mutex_unlock(&vdpasim->mutex); > + return 0; > + } > + > + mutex_unlock(&vdpasim->mutex); > + return -EINVAL; EOPNOTSUPP would be more appropriate. Andrew
On Tue, 30 Jul 2024 at 03:15, Andrew Lunn <andrew@lunn.ch> wrote: > > > +static int vdpasim_net_set_attr(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev, > > + const struct vdpa_dev_set_config *config) > > +{ > > + struct vdpasim *vdpasim = container_of(dev, struct vdpasim, vdpa); > > + struct virtio_net_config *vio_config = vdpasim->config; > > + > > + mutex_lock(&vdpasim->mutex); > > + > > + if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { > > + ether_addr_copy(vio_config->mac, config->net.mac); > > + mutex_unlock(&vdpasim->mutex); > > + return 0; > > + } > > + > > + mutex_unlock(&vdpasim->mutex); > > + return -EINVAL; > > EOPNOTSUPP would be more appropriate. > > Andrew > will change this Thanks cindy
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c index cfe962911804..5baf934e685b 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim_net.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim_net.c @@ -414,6 +414,24 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config) net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP); } +static int vdpasim_net_set_attr(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev, + const struct vdpa_dev_set_config *config) +{ + struct vdpasim *vdpasim = container_of(dev, struct vdpasim, vdpa); + struct virtio_net_config *vio_config = vdpasim->config; + + mutex_lock(&vdpasim->mutex); + + if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) { + ether_addr_copy(vio_config->mac, config->net.mac); + mutex_unlock(&vdpasim->mutex); + return 0; + } + + mutex_unlock(&vdpasim->mutex); + return -EINVAL; +} + static void vdpasim_net_setup_config(struct vdpasim *vdpasim, const struct vdpa_dev_set_config *config) { @@ -510,7 +528,8 @@ static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev, static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = { .dev_add = vdpasim_net_dev_add, - .dev_del = vdpasim_net_dev_del + .dev_del = vdpasim_net_dev_del, + .dev_set_attr = vdpasim_net_set_attr }; static struct virtio_device_id id_table[] = {
Add the function to support setting the MAC address. For vdpa_sim_net, the driver will write the MAC address to the config space, and other devices can implement their own functions to support this. Signed-off-by: Cindy Lu <lulu@redhat.com> --- drivers/vdpa/vdpa_sim/vdpa_sim_net.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)