Fri Oct 20 09:51:49 2023 UTC ()
eqos(4): Fix a bug that the MAC address is swapped.

 Don't swap the MAC address in eqos_get_eaddr(). Other OSes except FreeBSD
(which was based on NetBSD's) don't swap it. With this change, my own
OnLogic Helix 330's MAC address becomes correct. The OUI is 84:8b:cd:4d.
It's owned by Logic Supply and they were acquired by OnLogic.
On Quartz64 with UEIF, the MAC address is wrongly set and the multicast
bit might be set. To do workaround, clear the bit if it's set.


(msaitoh)
diff -r1.17 -r1.18 src/sys/dev/ic/dwc_eqos.c

cvs diff -r1.17 -r1.18 src/sys/dev/ic/dwc_eqos.c (expand / switch to unified diff)

--- src/sys/dev/ic/dwc_eqos.c 2023/06/03 20:41:45 1.17
+++ src/sys/dev/ic/dwc_eqos.c 2023/10/20 09:51:49 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dwc_eqos.c,v 1.17 2023/06/03 20:41:45 andvar Exp $ */ 1/* $NetBSD: dwc_eqos.c,v 1.18 2023/10/20 09:51:49 msaitoh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2022 Jared McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2022 Jared McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * DesignWare Ethernet Quality-of-Service controller 30 * DesignWare Ethernet Quality-of-Service controller
31 */ 31 */
32 32
33#include "opt_net_mpsafe.h" 33#include "opt_net_mpsafe.h"
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: dwc_eqos.c,v 1.17 2023/06/03 20:41:45 andvar Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: dwc_eqos.c,v 1.18 2023/10/20 09:51:49 msaitoh Exp $");
37 37
38#include <sys/param.h> 38#include <sys/param.h>
39#include <sys/bus.h> 39#include <sys/bus.h>
40#include <sys/device.h> 40#include <sys/device.h>
41#include <sys/intr.h> 41#include <sys/intr.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/mutex.h> 44#include <sys/mutex.h>
45#include <sys/callout.h> 45#include <sys/callout.h>
46#include <sys/cprng.h> 46#include <sys/cprng.h>
47#include <sys/evcnt.h> 47#include <sys/evcnt.h>
48 48
49#include <sys/rndsource.h> 49#include <sys/rndsource.h>
@@ -1192,28 +1192,33 @@ eqos_get_eaddr(struct eqos_softc *sc, ui @@ -1192,28 +1192,33 @@ eqos_get_eaddr(struct eqos_softc *sc, ui
1192 prop_dictionary_t prop = device_properties(sc->sc_dev); 1192 prop_dictionary_t prop = device_properties(sc->sc_dev);
1193 uint32_t maclo, machi; 1193 uint32_t maclo, machi;
1194 prop_data_t eaprop; 1194 prop_data_t eaprop;
1195 1195
1196 eaprop = prop_dictionary_get(prop, "mac-address"); 1196 eaprop = prop_dictionary_get(prop, "mac-address");
1197 if (eaprop != NULL) { 1197 if (eaprop != NULL) {
1198 KASSERT(prop_object_type(eaprop) == PROP_TYPE_DATA); 1198 KASSERT(prop_object_type(eaprop) == PROP_TYPE_DATA);
1199 KASSERT(prop_data_size(eaprop) == ETHER_ADDR_LEN); 1199 KASSERT(prop_data_size(eaprop) == ETHER_ADDR_LEN);
1200 memcpy(eaddr, prop_data_value(eaprop), 1200 memcpy(eaddr, prop_data_value(eaprop),
1201 ETHER_ADDR_LEN); 1201 ETHER_ADDR_LEN);
1202 return; 1202 return;
1203 } 1203 }
1204 1204
1205 maclo = htobe32(RD4(sc, GMAC_MAC_ADDRESS0_LOW)); 1205 maclo = RD4(sc, GMAC_MAC_ADDRESS0_LOW);
1206 machi = htobe16(RD4(sc, GMAC_MAC_ADDRESS0_HIGH) & 0xFFFF); 1206 machi = RD4(sc, GMAC_MAC_ADDRESS0_HIGH) & 0xFFFF;
 1207 if ((maclo & 0x00000001) != 0) {
 1208 aprint_error_dev(sc->sc_dev,
 1209 "Wrong MAC address. Clear the multicast bit.\n");
 1210 maclo &= ~0x00000001;
 1211 }
1207 1212
1208 if (maclo == 0xFFFFFFFF && machi == 0xFFFF) { 1213 if (maclo == 0xFFFFFFFF && machi == 0xFFFF) {
1209 /* Create one */ 1214 /* Create one */
1210 maclo = 0x00f2 | (cprng_strong32() & 0xffff0000); 1215 maclo = 0x00f2 | (cprng_strong32() & 0xffff0000);
1211 machi = cprng_strong32() & 0xffff; 1216 machi = cprng_strong32() & 0xffff;
1212 } 1217 }
1213 1218
1214 eaddr[0] = maclo & 0xff; 1219 eaddr[0] = maclo & 0xff;
1215 eaddr[1] = (maclo >> 8) & 0xff; 1220 eaddr[1] = (maclo >> 8) & 0xff;
1216 eaddr[2] = (maclo >> 16) & 0xff; 1221 eaddr[2] = (maclo >> 16) & 0xff;
1217 eaddr[3] = (maclo >> 24) & 0xff; 1222 eaddr[3] = (maclo >> 24) & 0xff;
1218 eaddr[4] = machi & 0xff; 1223 eaddr[4] = machi & 0xff;
1219 eaddr[5] = (machi >> 8) & 0xff; 1224 eaddr[5] = (machi >> 8) & 0xff;