You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
171 lines
5.7 KiB
171 lines
5.7 KiB
From 87996301447ff46d4dbdc81cade0315957c3ffbb Mon Sep 17 00:00:00 2001
|
|
From: Igor Russkikh <irusskik@redhat.com>
|
|
Date: Fri, 6 Nov 2020 18:37:49 -0500
|
|
Subject: [PATCH 092/139] [netdrv] net: atlantic: unify MAC generation
|
|
|
|
Message-id: <1604687916-15087-93-git-send-email-irusskik@redhat.com>
|
|
Patchwork-id: 338515
|
|
Patchwork-instance: patchwork
|
|
O-Subject: [RHEL8.4 BZ 1857861 092/139] net: atlantic: unify MAC generation
|
|
Bugzilla: 1857861
|
|
RH-Acked-by: David Arcari <darcari@redhat.com>
|
|
RH-Acked-by: John Linville <linville@redhat.com>
|
|
RH-Acked-by: Tony Camuso <tcamuso@redhat.com>
|
|
|
|
Bugzilla: http://bugzilla.redhat.com/1857861
|
|
|
|
commit b4de6c49e569c7ca91bf0d4c25cdb6eeca9c9529
|
|
Author: Mark Starovoytov <mstarovoitov@marvell.com>
|
|
Date: Sat May 9 09:47:00 2020 +0300
|
|
|
|
net: atlantic: unify MAC generation
|
|
|
|
This patch unifies invalid MAC address handling with other drivers.
|
|
|
|
Basically we've switched to using standard APIs (is_valid_ether_addr /
|
|
eth_hw_addr_random) where possible.
|
|
It's worth noting that some of engineering Aquantia NICs might be
|
|
provisioned with a partially zeroed out MAC, which is still invalid,
|
|
but not caught by is_valid_ether_addr(), so we've added a special
|
|
handling for this case.
|
|
|
|
Also adding a warning in case of fallback to random MAC, because
|
|
this shouldn't be needed on production NICs, they should all be
|
|
provisioned with unique MAC.
|
|
|
|
NB! Default systemd/udevd configuration is 'MACAddressPolicy=persistent'.
|
|
This causes MAC address to be persisted across driver reloads and
|
|
reboots. We had to change it to 'none' for verification purposes.
|
|
|
|
Signed-off-by: Mark Starovoytov <mstarovoitov@marvell.com>
|
|
Signed-off-by: Igor Russkikh <irusskikh@marvell.com>
|
|
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
|
|
|
|
Signed-off-by: Igor Russkikh <irusskik@redhat.com>
|
|
|
|
Cc: David Arcari <darcari@redhat.com>
|
|
Cc: Igor Russkikh <irusskik@redhat.com>
|
|
Signed-off-by: Jan Stancek <jstancek@redhat.com>
|
|
---
|
|
drivers/net/ethernet/aquantia/atlantic/aq_nic.c | 14 +++++++++++++
|
|
.../aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c | 22 ---------------------
|
|
.../aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c | 23 +---------------------
|
|
3 files changed, 15 insertions(+), 44 deletions(-)
|
|
|
|
diff --git a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
|
|
index ee8218d43b31..4918c6867c2b 100644
|
|
--- a/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
|
|
+++ b/drivers/net/ethernet/aquantia/atlantic/aq_nic.c
|
|
@@ -264,6 +264,14 @@ static int aq_nic_hw_prepare(struct aq_nic_s *self)
|
|
return err;
|
|
}
|
|
|
|
+static bool aq_nic_is_valid_ether_addr(const u8 *addr)
|
|
+{
|
|
+ /* Some engineering samples of Aquantia NICs are provisioned with a
|
|
+ * partially populated MAC, which is still invalid.
|
|
+ */
|
|
+ return !(addr[0] == 0 && addr[1] == 0 && addr[2] == 0);
|
|
+}
|
|
+
|
|
int aq_nic_ndev_register(struct aq_nic_s *self)
|
|
{
|
|
int err = 0;
|
|
@@ -284,6 +292,12 @@ int aq_nic_ndev_register(struct aq_nic_s *self)
|
|
if (err)
|
|
goto err_exit;
|
|
|
|
+ if (!is_valid_ether_addr(self->ndev->dev_addr) ||
|
|
+ !aq_nic_is_valid_ether_addr(self->ndev->dev_addr)) {
|
|
+ netdev_warn(self->ndev, "MAC is invalid, will use random.");
|
|
+ eth_hw_addr_random(self->ndev);
|
|
+ }
|
|
+
|
|
#if defined(AQ_CFG_MAC_ADDR_PERMANENT)
|
|
{
|
|
static u8 mac_addr_permanent[] = AQ_CFG_MAC_ADDR_PERMANENT;
|
|
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
|
|
index 719fad921cb8..8296a1e63522 100644
|
|
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
|
|
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.c
|
|
@@ -280,8 +280,6 @@ static int aq_fw2x_get_mac_permanent(struct aq_hw_s *self, u8 *mac)
|
|
u32 efuse_addr = aq_hw_read_reg(self, HW_ATL_FW2X_MPI_EFUSE_ADDR);
|
|
u32 mac_addr[2] = { 0 };
|
|
int err = 0;
|
|
- u32 h = 0U;
|
|
- u32 l = 0U;
|
|
|
|
if (efuse_addr != 0) {
|
|
err = hw_atl_utils_fw_downld_dwords(self,
|
|
@@ -296,26 +294,6 @@ static int aq_fw2x_get_mac_permanent(struct aq_hw_s *self, u8 *mac)
|
|
|
|
ether_addr_copy(mac, (u8 *)mac_addr);
|
|
|
|
- if ((mac[0] & 0x01U) || ((mac[0] | mac[1] | mac[2]) == 0x00U)) {
|
|
- unsigned int rnd = 0;
|
|
-
|
|
- get_random_bytes(&rnd, sizeof(unsigned int));
|
|
-
|
|
- l = 0xE3000000U | (0xFFFFU & rnd) | (0x00 << 16);
|
|
- h = 0x8001300EU;
|
|
-
|
|
- mac[5] = (u8)(0xFFU & l);
|
|
- l >>= 8;
|
|
- mac[4] = (u8)(0xFFU & l);
|
|
- l >>= 8;
|
|
- mac[3] = (u8)(0xFFU & l);
|
|
- l >>= 8;
|
|
- mac[2] = (u8)(0xFFU & l);
|
|
- mac[1] = (u8)(0xFFU & h);
|
|
- h >>= 8;
|
|
- mac[0] = (u8)(0xFFU & h);
|
|
- }
|
|
-
|
|
return err;
|
|
}
|
|
|
|
diff --git a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c
|
|
index e8f4aad8c1e5..0ffc33bd67d0 100644
|
|
--- a/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c
|
|
+++ b/drivers/net/ethernet/aquantia/atlantic/hw_atl2/hw_atl2_utils_fw.c
|
|
@@ -6,6 +6,7 @@
|
|
#include <linux/iopoll.h>
|
|
|
|
#include "aq_hw.h"
|
|
+#include "aq_hw_utils.h"
|
|
#include "hw_atl/hw_atl_llh.h"
|
|
#include "hw_atl2_utils.h"
|
|
#include "hw_atl2_llh.h"
|
|
@@ -212,28 +213,6 @@ static int aq_a2_fw_get_mac_permanent(struct aq_hw_s *self, u8 *mac)
|
|
hw_atl2_shared_buffer_get(self, mac_address, mac_address);
|
|
ether_addr_copy(mac, (u8 *)mac_address.aligned.mac_address);
|
|
|
|
- if ((mac[0] & 0x01U) || ((mac[0] | mac[1] | mac[2]) == 0x00U)) {
|
|
- unsigned int rnd = 0;
|
|
- u32 h;
|
|
- u32 l;
|
|
-
|
|
- get_random_bytes(&rnd, sizeof(unsigned int));
|
|
-
|
|
- l = 0xE3000000U | (0xFFFFU & rnd) | (0x00 << 16);
|
|
- h = 0x8001300EU;
|
|
-
|
|
- mac[5] = (u8)(0xFFU & l);
|
|
- l >>= 8;
|
|
- mac[4] = (u8)(0xFFU & l);
|
|
- l >>= 8;
|
|
- mac[3] = (u8)(0xFFU & l);
|
|
- l >>= 8;
|
|
- mac[2] = (u8)(0xFFU & l);
|
|
- mac[1] = (u8)(0xFFU & h);
|
|
- h >>= 8;
|
|
- mac[0] = (u8)(0xFFU & h);
|
|
- }
|
|
-
|
|
return 0;
|
|
}
|
|
|
|
--
|
|
2.13.6
|
|
|