Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/pci Fix a bug that the offset of alt MAC address is ...



details:   https://anonhg.NetBSD.org/src/rev/3b6cccc77dac
branches:  trunk
changeset: 333232:3b6cccc77dac
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Fri Oct 24 17:50:50 2014 +0000

description:
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.

diffstat:

 sys/dev/pci/if_wm.c    |  65 ++++++++++++++++---------------------------------
 sys/dev/pci/if_wmreg.h |   6 +---
 2 files changed, 24 insertions(+), 47 deletions(-)

diffs (145 lines):

diff -r d23f8d9fb35b -r 3b6cccc77dac sys/dev/pci/if_wm.c
--- a/sys/dev/pci/if_wm.c       Fri Oct 24 15:51:16 2014 +0000
+++ b/sys/dev/pci/if_wm.c       Fri Oct 24 17:50:50 2014 +0000
@@ -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 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 @@
 
 /* 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 @@
 
        /* Try to read alternative MAC address pointer */
        if (wm_nvm_read(sc, NVM_OFF_ALT_MAC_ADDR_PTR, 1, &offset) != 0)
-               return -1;
-
-       /* Check pointer */
-       if (offset == 0xffff)
-               return -1;
-
+               return 0;
+
+       /* 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 @@
         */
        if (wm_nvm_read(sc, offset, 1, myea) == 0)
                if (((myea[0] & 0xff) & 0x01) == 0)
-                       return 0; /* found! */
-
-       /* not found */
-       return -1;
+                       return offset; /* Found */
+
+       /* Not found */
+       return 0;
 }
 
 static int
@@ -2824,34 +2829,10 @@
        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 @@
                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;
diff -r d23f8d9fb35b -r 3b6cccc77dac sys/dev/pci/if_wmreg.h
--- a/sys/dev/pci/if_wmreg.h    Fri Oct 24 15:51:16 2014 +0000
+++ b/sys/dev/pci/if_wmreg.h    Fri Oct 24 17:50:50 2014 +0000
@@ -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 @@
 
 #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"



Home | Main Index | Thread Index | Old Index