Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] net: sunplus: also fix the byte order of 1c:50:1e MAC addresses
@ 2026-11-12 12:37 Andrew Gaylard
  2026-11-17 12:28 ` Daniel Machon
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Gaylard @ 2026-11-12 12:37 UTC (permalink / raw)
  To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: netdev

The driver reverses a MAC address from the OTP when it finds the
Sunplus OUI fc:4b:bc at the wrong end. Newer SP7021 chips have
a different Sunplus OUI (1c:50:1e), possibly stored in the same
reversed order, which the driver does not recognise. If the reversed
address has the multicast bit set, the driver rejects it and uses a
random address; otherwise it uses the reversed address as it is.

Handle both these OUIs. An address that already starts with either OUI
is left as is.  On chips that used the reversed address, the interface
now gets the correct address, so configuration tied to the old address
(DHCP reservations, udev or networkd rules) will need updating.

Tested on chips that needed each of these OUIs to be reversed.

Signed-off-by: Andrew Gaylard <ag@ffroot.co.za>
---
 drivers/net/ethernet/sunplus/spl2sw_driver.c | 36 +++++++++++++++-----
 1 file changed, 28 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
index 5e0e4c9ecbb0..ab0318bc6f6c 100644
--- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
+++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
@@ -203,18 +203,38 @@ static const struct net_device_ops netdev_ops = {
 	.ndo_tx_timeout = spl2sw_ethernet_tx_timeout,
 };
 
+static const u8 spl2sw_sunplus_ouis[][3] = {
+	{ 0xfc, 0x4b, 0xbc },
+	{ 0x1c, 0x50, 0x1e },
+};
+
 static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
 {
-	/* Byte order of MAC address of some samples are reversed.
-	 * Check vendor id and convert byte order if it is wrong.
-	 * OUI of Sunplus: fc:4b:bc
+	unsigned int i;
+
+	/* Some chips have the byte order of the MAC address reversed.
+	 * Check for Sunplus OUIs and fix the byte order if it is.
 	 */
-	if (mac_addr[5] == 0xfc && mac_addr[4] == 0x4b && mac_addr[3] == 0xbc &&
-	    (mac_addr[0] != 0xfc || mac_addr[1] != 0x4b || mac_addr[2] != 0xbc)) {
+	for (i = 0; i < ARRAY_SIZE(spl2sw_sunplus_ouis); i++) {
+		const u8 *oui = spl2sw_sunplus_ouis[i];
 
-		swap(mac_addr[0], mac_addr[5]);
-		swap(mac_addr[1], mac_addr[4]);
-		swap(mac_addr[2], mac_addr[3]);
+		if (mac_addr[0] == oui[0] &&
+		    mac_addr[1] == oui[1] &&
+		    mac_addr[2] == oui[2])
+			return;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(spl2sw_sunplus_ouis); i++) {
+		const u8 *oui = spl2sw_sunplus_ouis[i];
+
+		if (mac_addr[5] == oui[0] &&
+		    mac_addr[4] == oui[1] &&
+		    mac_addr[3] == oui[2]) {
+			swap(mac_addr[0], mac_addr[5]);
+			swap(mac_addr[1], mac_addr[4]);
+			swap(mac_addr[2], mac_addr[3]);
+			return;
+		}
 	}
 }
 

base-commit: 676f3aace662fbbc180b3898b190a372fa2a516b
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: sunplus: also fix the byte order of 1c:50:1e MAC addresses
  2026-11-12 12:37 [PATCH net-next] net: sunplus: also fix the byte order of 1c:50:1e MAC addresses Andrew Gaylard
@ 2026-11-17 12:28 ` Daniel Machon
  2026-11-17 13:32   ` Andrew Gaylard
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Machon @ 2026-11-17 12:28 UTC (permalink / raw)
  To: Andrew Gaylard
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev

Hi Andrew,

> The driver reverses a MAC address from the OTP when it finds the
> Sunplus OUI fc:4b:bc at the wrong end. Newer SP7021 chips have
> a different Sunplus OUI (1c:50:1e), possibly stored in the same
> reversed order, which the driver does not recognise. If the reversed
> address has the multicast bit set, the driver rejects it and uses a
> random address; otherwise it uses the reversed address as it is.
> 
> Handle both these OUIs. An address that already starts with either OUI
> is left as is.  On chips that used the reversed address, the interface
> now gets the correct address, so configuration tied to the old address
> (DHCP reservations, udev or networkd rules) will need updating.
> 
> Tested on chips that needed each of these OUIs to be reversed.
> 
> Signed-off-by: Andrew Gaylard <ag@ffroot.co.za>
> ---
>  drivers/net/ethernet/sunplus/spl2sw_driver.c | 36 +++++++++++++++-----
>  1 file changed, 28 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/net/ethernet/sunplus/spl2sw_driver.c b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> index 5e0e4c9ecbb0..ab0318bc6f6c 100644
> --- a/drivers/net/ethernet/sunplus/spl2sw_driver.c
> +++ b/drivers/net/ethernet/sunplus/spl2sw_driver.c
> @@ -203,18 +203,38 @@ static const struct net_device_ops netdev_ops = {
>  	.ndo_tx_timeout = spl2sw_ethernet_tx_timeout,
>  };
>  
> +static const u8 spl2sw_sunplus_ouis[][3] = {
> +	{ 0xfc, 0x4b, 0xbc },
> +	{ 0x1c, 0x50, 0x1e },
> +};
> +
>  static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
>  {
> -	/* Byte order of MAC address of some samples are reversed.
> -	 * Check vendor id and convert byte order if it is wrong.
> -	 * OUI of Sunplus: fc:4b:bc
> +	unsigned int i;
> +
> +	/* Some chips have the byte order of the MAC address reversed.
> +	 * Check for Sunplus OUIs and fix the byte order if it is.
>  	 */
> -	if (mac_addr[5] == 0xfc && mac_addr[4] == 0x4b && mac_addr[3] == 0xbc &&
> -	    (mac_addr[0] != 0xfc || mac_addr[1] != 0x4b || mac_addr[2] != 0xbc)) {
> +	for (i = 0; i < ARRAY_SIZE(spl2sw_sunplus_ouis); i++) {
> +		const u8 *oui = spl2sw_sunplus_ouis[i];
>  
> -		swap(mac_addr[0], mac_addr[5]);
> -		swap(mac_addr[1], mac_addr[4]);
> -		swap(mac_addr[2], mac_addr[3]);
> +		if (mac_addr[0] == oui[0] &&
> +		    mac_addr[1] == oui[1] &&
> +		    mac_addr[2] == oui[2])
> +			return;
> +	}
> +
> +	for (i = 0; i < ARRAY_SIZE(spl2sw_sunplus_ouis); i++) {
> +		const u8 *oui = spl2sw_sunplus_ouis[i];
> +
> +		if (mac_addr[5] == oui[0] &&
> +		    mac_addr[4] == oui[1] &&
> +		    mac_addr[3] == oui[2]) {
> +			swap(mac_addr[0], mac_addr[5]);
> +			swap(mac_addr[1], mac_addr[4]);
> +			swap(mac_addr[2], mac_addr[3]);
> +			return;
> +		}
>  	}
>  }
>  
> 
> base-commit: 676f3aace662fbbc180b3898b190a372fa2a516b
> -- 
> 2.53.0
>

The fix looks correct to me, but I personally dislike that double-loop. I think
it could be smaller and more readable with something like:

+static bool spl2sw_is_sunplus_oui(u8 b0, u8 b1, u8 b2)
+{
+	return (b0 == 0xfc && b1 == 0x4b && b2 == 0xbc) ||
+	       (b0 == 0x1c && b1 == 0x50 && b2 == 0x1e);
+}
+
 static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
 {
 	/* Byte order of MAC address of some samples are reversed.
 	 * Check vendor id and convert byte order if it is wrong.
-	 * OUI of Sunplus: fc:4b:bc
+	 * OUIs of Sunplus: fc:4b:bc, 1c:50:1e
 	 */
-	if (mac_addr[5] == 0xfc && mac_addr[4] == 0x4b && mac_addr[3] == 0xbc &&
-	    (mac_addr[0] != 0xfc || mac_addr[1] != 0x4b || mac_addr[2] != 0xbc)) {
-
+	if (spl2sw_is_sunplus_oui(mac_addr[5], mac_addr[4], mac_addr[3]) &&
+	    !spl2sw_is_sunplus_oui(mac_addr[0], mac_addr[1], mac_addr[2])) {
 		swap(mac_addr[0], mac_addr[5]);
 		swap(mac_addr[1], mac_addr[4]);
 		swap(mac_addr[2], mac_addr[3]);

This should behave the same as your two loops, and adding a new entry is still
easy.  Only a suggestion though, dont respin if you disagree.

Reviewed-by: Daniel Machon <daniel.machon@microchip.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next] net: sunplus: also fix the byte order of 1c:50:1e MAC addresses
  2026-11-17 12:28 ` Daniel Machon
@ 2026-11-17 13:32   ` Andrew Gaylard
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Gaylard @ 2026-11-17 13:32 UTC (permalink / raw)
  To: Daniel Machon
  Cc: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev

Hi Daniel,

Daniel Machon <daniel.machon@microchip.com> writes:
> The fix looks correct to me, but I personally dislike that double-loop. I think
> it could be smaller and more readable with something like:
>
> +static bool spl2sw_is_sunplus_oui(u8 b0, u8 b1, u8 b2)
> +{
> +	return (b0 == 0xfc && b1 == 0x4b && b2 == 0xbc) ||
> +	       (b0 == 0x1c && b1 == 0x50 && b2 == 0x1e);
> +}
> +
>  static void spl2sw_check_mac_vendor_id_and_convert(u8 *mac_addr)
>  {
>  	/* Byte order of MAC address of some samples are reversed.
>  	 * Check vendor id and convert byte order if it is wrong.
> -	 * OUI of Sunplus: fc:4b:bc
> +	 * OUIs of Sunplus: fc:4b:bc, 1c:50:1e
>  	 */
> -	if (mac_addr[5] == 0xfc && mac_addr[4] == 0x4b && mac_addr[3] == 0xbc &&
> -	    (mac_addr[0] != 0xfc || mac_addr[1] != 0x4b || mac_addr[2] != 0xbc)) {
> -
> +	if (spl2sw_is_sunplus_oui(mac_addr[5], mac_addr[4], mac_addr[3]) &&
> +	    !spl2sw_is_sunplus_oui(mac_addr[0], mac_addr[1], mac_addr[2])) {
>  		swap(mac_addr[0], mac_addr[5]);
>  		swap(mac_addr[1], mac_addr[4]);
>  		swap(mac_addr[2], mac_addr[3]);
>
> This should behave the same as your two loops, and adding a new entry is still
> easy.  Only a suggestion though, dont respin if you disagree.
>
> Reviewed-by: Daniel Machon <daniel.machon@microchip.com>

Thanks for the review.  I prefer your approach: definitely more
readable.  I'll respin and send a v2.

-- 
Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-17 13:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-12 12:37 [PATCH net-next] net: sunplus: also fix the byte order of 1c:50:1e MAC addresses Andrew Gaylard
2026-11-17 12:28 ` Daniel Machon
2026-11-17 13:32   ` Andrew Gaylard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox