Skip to content

Commit 0c86d77

Browse files
viviermstsirkin
authored andcommitted
vdpasim: allow to assign a MAC address
Add macaddr parameter to the module to set the MAC address to use Signed-off-by: Laurent Vivier <lvivier@redhat.com> Link: https://lore.kernel.org/r/20201029122050.776445-3-lvivier@redhat.com Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Jason Wang <jasowang@redhat.com>
1 parent 4a6a42d commit 0c86d77

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

drivers/vdpa/vdpa_sim/vdpa_sim.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ static int batch_mapping = 1;
3838
module_param(batch_mapping, int, 0444);
3939
MODULE_PARM_DESC(batch_mapping, "Batched mapping 1 -Enable; 0 - Disable");
4040

41+
static char *macaddr;
42+
module_param(macaddr, charp, 0);
43+
MODULE_PARM_DESC(macaddr, "Ethernet MAC address");
44+
4145
struct vdpasim_virtqueue {
4246
struct vringh vring;
4347
struct vringh_kiov iov;
@@ -375,7 +379,15 @@ static struct vdpasim *vdpasim_create(void)
375379
if (!vdpasim->buffer)
376380
goto err_iommu;
377381

378-
eth_random_addr(vdpasim->config.mac);
382+
if (macaddr) {
383+
mac_pton(macaddr, vdpasim->config.mac);
384+
if (!is_valid_ether_addr(vdpasim->config.mac)) {
385+
ret = -EADDRNOTAVAIL;
386+
goto err_iommu;
387+
}
388+
} else {
389+
eth_random_addr(vdpasim->config.mac);
390+
}
379391

380392
vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
381393
vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);

0 commit comments

Comments
 (0)