mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/5] net: virtio-net: allow to set current MAC address
Date: Mon, 10 Jun 2024 09:51:01 +0200	[thread overview]
Message-ID: <20240610075105.812496-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240610075105.812496-1-s.hauer@pengutronix.de>

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@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




  reply	other threads:[~2024-06-10  7:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-10  7:51 [PATCH 0/5] net: preparations for integrating a network stack Sascha Hauer
2024-06-10  7:51 ` Sascha Hauer [this message]
2024-06-10  7:51 ` [PATCH 2/5] net: ifup: use accessor to set network device ip/netmask Sascha Hauer
2024-06-10  7:51 ` [PATCH 3/5] net: add edev argument to net_set_gateway() Sascha Hauer
2024-06-10  7:51 ` [PATCH 4/5] net: establish single code path for setting edev parameters Sascha Hauer
2024-06-10  7:51 ` [PATCH 5/5] net: host command: move to commands/ Sascha Hauer
2024-06-13  6:41 ` [PATCH 0/5] net: preparations for integrating a network stack Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240610075105.812496-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox