[PATCH 1/5] net: virtio-net: allow to set current MAC address
Sascha Hauer
s.hauer at pengutronix.de
Mon Jun 10 00:51:01 PDT 2024
We currently can't change the current MAC address when VIRTIO_F_VERSION_1
is set, which is always the case. The barebox ethernet code calls set_ethaddr
with this exact MAC address it has just read from the hardware. Just
return successfully when the core wants to set the MAC address we
already have.
Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
drivers/net/virtio.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/drivers/net/virtio.c b/drivers/net/virtio.c
index 8605f67ae2..1bc5e0cd90 100644
--- a/drivers/net/virtio.c
+++ b/drivers/net/virtio.c
@@ -135,29 +135,39 @@ static void virtio_net_stop(struct eth_device *dev)
*/
}
+static int virtio_net_read_rom_hwaddr(struct eth_device *edev, unsigned char *adr)
+{
+ struct virtio_net_priv *priv = to_priv(edev);
+
+ virtio_cread_bytes(priv->vdev, offsetof(struct virtio_net_config, mac), adr, 6);
+
+ return 0;
+}
+
static int virtio_net_write_hwaddr(struct eth_device *edev, const unsigned char *adr)
{
struct virtio_net_priv *priv = to_priv(edev);
- int i;
+ int i, ret;
/*
* v1.0 compliant device's MAC address is set through control channel,
* which we don't support for now.
*/
- if (virtio_has_feature(priv->vdev, VIRTIO_F_VERSION_1))
- return -ENOSYS;
-
- for (i = 0; i < 6; i++)
- virtio_cwrite8(priv->vdev, offsetof(struct virtio_net_config, mac) + i, adr[i]);
+ if (virtio_has_feature(priv->vdev, VIRTIO_F_VERSION_1)) {
+ char mac[6];
- return 0;
-}
+ ret = virtio_net_read_rom_hwaddr(edev, mac);
+ if (ret)
+ return ret;
-static int virtio_net_read_rom_hwaddr(struct eth_device *edev, unsigned char *adr)
-{
- struct virtio_net_priv *priv = to_priv(edev);
+ if (!memcmp(mac, adr, 5))
+ return 0;
+ else
+ return -ENOSYS;
+ }
- virtio_cread_bytes(priv->vdev, offsetof(struct virtio_net_config, mac), adr, 6);
+ for (i = 0; i < 6; i++)
+ virtio_cwrite8(priv->vdev, offsetof(struct virtio_net_config, mac) + i, adr[i]);
return 0;
}
--
2.39.2
More information about the barebox
mailing list