Module Name:    src
Committed By:   msaitoh
Date:           Fri Oct 24 17:50:50 UTC 2014

Modified Files:
        src/sys/dev/pci: if_wm.c if_wmreg.h

Log Message:
 Fix a bug that the offset of alt MAC address is wrongly calculated to 0
when alt MAC address function is really used. This bug does not appear
as real bug if the same MAC address is written in the default location
and alt MAC address's location.


To generate a diff of this commit:
cvs rdiff -u -r1.305 -r1.306 src/sys/dev/pci/if_wm.c
cvs rdiff -u -r1.63 -r1.64 src/sys/dev/pci/if_wmreg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/if_wm.c
diff -u src/sys/dev/pci/if_wm.c:1.305 src/sys/dev/pci/if_wm.c:1.306
--- src/sys/dev/pci/if_wm.c:1.305	Fri Oct 17 17:48:53 2014
+++ src/sys/dev/pci/if_wm.c	Fri Oct 24 17:50:50 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wm.c,v 1.305 2014/10/17 17:48:53 snj Exp $	*/
+/*	$NetBSD: if_wm.c,v 1.306 2014/10/24 17:50:50 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc.
@@ -81,7 +81,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.305 2014/10/17 17:48:53 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.306 2014/10/24 17:50:50 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -546,7 +546,7 @@ static void	wm_tick(void *);
 static int	wm_ifflags_cb(struct ethercom *);
 static int	wm_ioctl(struct ifnet *, u_long, void *);
 /* MAC address related */
-static int	wm_check_alt_mac_addr(struct wm_softc *);
+static uint16_t	wm_check_alt_mac_addr(struct wm_softc *);
 static int	wm_read_mac_addr(struct wm_softc *, uint8_t *);
 static void	wm_set_ral(struct wm_softc *, const uint8_t *, int);
 static uint32_t	wm_mchash(struct wm_softc *, const uint8_t *);
@@ -2759,7 +2759,11 @@ wm_ioctl(struct ifnet *ifp, u_long cmd, 
 
 /* MAC address related */
 
-static int
+/*
+ * Get the offset of MAC address and return it.
+ * If error occured, use offset 0.
+ */
+static uint16_t
 wm_check_alt_mac_addr(struct wm_softc *sc)
 {
 	uint16_t myea[ETHER_ADDR_LEN / 2];
@@ -2767,12 +2771,13 @@ wm_check_alt_mac_addr(struct wm_softc *s
 
 	/* Try to read alternative MAC address pointer */
 	if (wm_nvm_read(sc, NVM_OFF_ALT_MAC_ADDR_PTR, 1, &offset) != 0)
-		return -1;
+		return 0;
 
-	/* Check pointer */
-	if (offset == 0xffff)
-		return -1;
+	/* Check pointer if it's valid or not. */
+	if ((offset == 0x0000) || (offset == 0xffff))
+		return 0;
 
+	offset += NVM_OFF_MACADDR_82571(sc->sc_funcid);
 	/*
 	 * Check whether alternative MAC address is valid or not.
 	 * Some cards have non 0xffff pointer but those don't use
@@ -2782,10 +2787,10 @@ wm_check_alt_mac_addr(struct wm_softc *s
 	 */
 	if (wm_nvm_read(sc, offset, 1, myea) == 0)
 		if (((myea[0] & 0xff) & 0x01) == 0)
-			return 0; /* found! */
+			return offset; /* Found */
 
-	/* not found */
-	return -1;
+	/* Not found */
+	return 0;
 }
 
 static int
@@ -2824,34 +2829,10 @@ wm_read_mac_addr(struct wm_softc *sc, ui
 	case WM_T_80003:
 	case WM_T_I210:
 	case WM_T_I211:
-		if (wm_check_alt_mac_addr(sc) != 0) {
-			/* reset the offset to LAN0 */
-			offset = NVM_OFF_MACADDR;
+		offset = wm_check_alt_mac_addr(sc);
+		if (offset == 0)
 			if ((sc->sc_funcid & 0x01) == 1)
 				do_invert = 1;
-			goto do_read;
-		}
-		switch (sc->sc_funcid) {
-		case 0:
-			/*
-			 * The offset is the value in NVM_OFF_ALT_MAC_ADDR_PTR
-			 * itself.
-			 */
-			break;
-		case 1:
-			offset += NVM_OFF_MACADDR_LAN1;
-			break;
-		case 2:
-			offset += NVM_OFF_MACADDR_LAN2;
-			break;
-		case 3:
-			offset += NVM_OFF_MACADDR_LAN3;
-			break;
-		default:
-			goto bad;
-			/* NOTREACHED */
-			break;
-		}
 		break;
 	default:
 		if ((sc->sc_funcid & 0x01) == 1)
@@ -2859,11 +2840,9 @@ wm_read_mac_addr(struct wm_softc *sc, ui
 		break;
 	}
 
- do_read:
 	if (wm_nvm_read(sc, offset, sizeof(myea) / sizeof(myea[0]),
-		myea) != 0) {
+		myea) != 0)
 		goto bad;
-	}
 
 	enaddr[0] = myea[0] & 0xff;
 	enaddr[1] = myea[0] >> 8;

Index: src/sys/dev/pci/if_wmreg.h
diff -u src/sys/dev/pci/if_wmreg.h:1.63 src/sys/dev/pci/if_wmreg.h:1.64
--- src/sys/dev/pci/if_wmreg.h:1.63	Wed Sep  3 14:30:04 2014
+++ src/sys/dev/pci/if_wmreg.h	Fri Oct 24 17:50:50 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_wmreg.h,v 1.63 2014/09/03 14:30:04 msaitoh Exp $	*/
+/*	$NetBSD: if_wmreg.h,v 1.64 2014/10/24 17:50:50 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -966,9 +966,7 @@ struct livengood_tcpip_ctxdesc {
 
 #define NVM_CFG3_APME		(1U << 10)	
 
-#define	NVM_OFF_MACADDR_LAN1	3	/* macaddr offset from PTR (port 1) */
-#define	NVM_OFF_MACADDR_LAN2	6	/* macaddr offset from PTR (port 2) */
-#define	NVM_OFF_MACADDR_LAN3	9	/* macaddr offset from PTR (port 3) */
+#define	NVM_OFF_MACADDR_82571(x)	(3 * (x))
 
 /*
  * EEPROM Partitioning. See Table 6-1, "EEPROM Top Level Partitioning"

Reply via email to