diff mbox series

[SRU,B,1/2] s390/qeth: improve fallback to random MAC address

Message ID 20200528123520.627320-2-frank.heimes@canonical.com
State New
Headers show
Series qeth: utilize virtual MAC for Layer2 OSD devices (LP: 1880834) | expand

Commit Message

Frank Heimes May 28, 2020, 12:35 p.m. UTC
From: Julian Wiedmann <jwi@linux.vnet.ibm.com>

BugLink: https://bugs.launchpad.net/bugs/1880834

If READ MAC fails to fetch a valid MAC address, allow some more device
types (IQD and z/VM OSD) to fall back to a random address.
Also use eth_hw_addr_random(), for indicating to userspace that the
address type is NET_ADDR_RANDOM.

Note that while z/VM has various protection schemes to prohibit
custom addresses on its NICs, they are all optional. So we should at
least give it a try.

Signed-off-by: Julian Wiedmann <jwi@linux.vnet.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
(backported from commit 21b1702af12eb62bb40d994c9c1546ecacfc8456)
[ jwi: backport to Ubuntu 4.15. Don't use eth_hw_addr_random(),
      it can trigger races on this old code level. ]
Signed-off-by: Julian Wiedmann <jwi@linux.ibm.com>
Signed-off-by: Frank Heimes <frank.heimes@canonical.com>
---
 drivers/s390/net/qeth_l2_main.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/drivers/s390/net/qeth_l2_main.c b/drivers/s390/net/qeth_l2_main.c
index 077d1dd359f1..3606ed0c9fe6 100644
--- a/drivers/s390/net/qeth_l2_main.c
+++ b/drivers/s390/net/qeth_l2_main.c
@@ -503,16 +503,21 @@  static int qeth_l2_request_initial_mac(struct qeth_card *card)
 	    card->info.type == QETH_CARD_TYPE_OSX ||
 	    card->info.guestlan) {
 		rc = qeth_setadpparms_change_macaddr(card);
-		if (rc) {
-			QETH_DBF_MESSAGE(2, "couldn't get MAC address on "
-				"device %x: %#x\n", CARD_DEVID(card), rc);
-			QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
-			return rc;
-		}
-	} else {
-		eth_random_addr(card->dev->dev_addr);
-		memcpy(card->dev->dev_addr, vendor_pre, 3);
+		if (!rc)
+			goto out;
+		QETH_DBF_MESSAGE(2, "READ_MAC Assist failed on device %x: %#x\n",
+				 CARD_DEVID(card), rc);
+		QETH_DBF_TEXT_(SETUP, 2, "1err%04x", rc);
+		/* fall back once more: */
 	}
+
+	/* some devices don't support a custom MAC address: */
+	if (card->info.type == QETH_CARD_TYPE_OSM ||
+	    card->info.type == QETH_CARD_TYPE_OSX)
+		return (rc) ? rc : -EADDRNOTAVAIL;
+	eth_random_addr(card->dev->dev_addr);
+	memcpy(card->dev->dev_addr, vendor_pre, 3);
+
 out:
 	QETH_DBF_HEX(SETUP, 2, card->dev->dev_addr, card->dev->addr_len);
 	return 0;