Skip to content

Commit 218bb7e

Browse files
lulu-github-namemstsirkin
authored andcommitted
vdpa_sim_net: Add the support of set mac address
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 <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 2f87e9c commit 218bb7e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

drivers/vdpa/vdpa_sim/vdpa_sim_net.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,24 @@ static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config)
414414
net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
415415
}
416416

417+
static int vdpasim_net_set_attr(struct vdpa_mgmt_dev *mdev, struct vdpa_device *dev,
418+
const struct vdpa_dev_set_config *config)
419+
{
420+
struct vdpasim *vdpasim = container_of(dev, struct vdpasim, vdpa);
421+
struct virtio_net_config *vio_config = vdpasim->config;
422+
423+
mutex_lock(&vdpasim->mutex);
424+
425+
if (config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
426+
ether_addr_copy(vio_config->mac, config->net.mac);
427+
mutex_unlock(&vdpasim->mutex);
428+
return 0;
429+
}
430+
431+
mutex_unlock(&vdpasim->mutex);
432+
return -EOPNOTSUPP;
433+
}
434+
417435
static void vdpasim_net_setup_config(struct vdpasim *vdpasim,
418436
const struct vdpa_dev_set_config *config)
419437
{
@@ -510,7 +528,8 @@ static void vdpasim_net_dev_del(struct vdpa_mgmt_dev *mdev,
510528

511529
static const struct vdpa_mgmtdev_ops vdpasim_net_mgmtdev_ops = {
512530
.dev_add = vdpasim_net_dev_add,
513-
.dev_del = vdpasim_net_dev_del
531+
.dev_del = vdpasim_net_dev_del,
532+
.dev_set_attr = vdpasim_net_set_attr
514533
};
515534

516535
static struct virtio_device_id id_table[] = {

0 commit comments

Comments
 (0)