- Adjust PCI latency timer on all types of chips
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 14 Oct 2008 15:11:38 +0000 (15:11 +0000)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 14 Oct 2008 15:11:38 +0000 (15:11 +0000)
- Adjust PCI cache line size for 8110/8169 chips
- For certain revision of 8101E, reading MAC address from IDRx may not
  work; read from EEPROM instead
- Add comment that adjusting config1 and config5 may cause unrecoverible
  disaster

Obtained-from: RealTek Linux drivers

sys/dev/netif/re/if_re.c
sys/dev/netif/re/if_rereg.h
sys/dev/netif/re/if_revar.h

index 4552e5a..97af8ee 100644 (file)
@@ -33,7 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/re/if_re.c,v 1.25 2004/06/09 14:34:01 naddy Exp $
- * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.81 2008/10/14 10:42:35 sephe Exp $
+ * $DragonFly: src/sys/dev/netif/re/if_re.c,v 1.82 2008/10/14 15:11:38 sephe Exp $
  */
 
 /*
@@ -200,22 +200,22 @@ static const struct re_hwrev re_hwrevs[] = {
          RE_C_HWCSUM | RE_C_8139CP },
 
        { RE_HWREV_8169,        RE_MACVER_UNKN,
-         RE_C_HWCSUM | RE_C_JUMBO },
+         RE_C_HWCSUM | RE_C_JUMBO | RE_C_8169 },
 
        { RE_HWREV_8110S,       RE_MACVER_03,
-         RE_C_HWCSUM | RE_C_JUMBO },
+         RE_C_HWCSUM | RE_C_JUMBO | RE_C_8169 },
 
        { RE_HWREV_8169S,       RE_MACVER_03,
-         RE_C_HWCSUM | RE_C_JUMBO },
+         RE_C_HWCSUM | RE_C_JUMBO | RE_C_8169 },
 
        { RE_HWREV_8169SB,      RE_MACVER_04,
-         RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT },
+         RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT | RE_C_8169 },
 
        { RE_HWREV_8169SC1,     RE_MACVER_05,
-         RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT },
+         RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT | RE_C_8169 },
 
        { RE_HWREV_8169SC2,     RE_MACVER_06,
-         RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT },
+         RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT | RE_C_8169 },
 
        { RE_HWREV_8168B1,      RE_MACVER_21,
          RE_C_HWIM | RE_C_HWCSUM | RE_C_JUMBO | RE_C_PHYPMGT },
@@ -285,12 +285,11 @@ static void       re_watchdog(struct ifnet *);
 static int     re_ifmedia_upd(struct ifnet *);
 static void    re_ifmedia_sts(struct ifnet *, struct ifmediareq *);
 
-#ifdef RE_USE_EEPROM
 static void    re_eeprom_putbyte(struct re_softc *, int);
 static void    re_eeprom_getword(struct re_softc *, int, u_int16_t *);
 static void    re_read_eeprom(struct re_softc *, caddr_t, int, int);
 static void    re_get_eewidth(struct re_softc *);
-#endif
+
 static int     re_gmii_readreg(device_t, int, int);
 static int     re_gmii_writereg(device_t, int, int, int);
 
@@ -379,8 +378,6 @@ re_free_rxchain(struct re_softc *sc)
        }
 }
 
-#ifdef RE_USE_EEPROM
-
 /*
  * Send a read command and address to the EEPROM, check for ACK.
  */
@@ -466,12 +463,10 @@ re_get_eewidth(struct re_softc *sc)
 
        sc->re_eewidth = 6;
        re_read_eeprom(sc, (caddr_t)&re_did, 0, 1);
-       if (re_did != 0x8129) /* XXX will this ever happen */
-               sc->re_eewidth = 8;
+       if (re_did != 0x8129)
+               sc->re_eewidth = 8;
 }
 
-#endif /* RE_USE_EEPROM */
-
 static int
 re_gmii_readreg(device_t dev, int phy, int reg)
 {
@@ -1495,9 +1490,13 @@ re_attach(device_t dev)
                      "-E" : ((sc->re_caps & RE_C_PCI64) ? "64" : "32"),
                      sc->re_bus_speed);
 
-#ifdef RE_USE_EEPROM
-       re_get_eewidth(sc);
-#endif
+       /*
+        * NOTE:
+        * DO NOT try to adjust config1 and config5 which was spotted in
+        * Realtek's Linux drivers.  It will _permanently_ damage certain
+        * cards EEPROM, e.g. one of my 8168B (0x38000000) card ...
+        */
+
        re_get_eaddr(sc, eaddr);
 
        if (!RE_IS_8139CP(sc)) {
@@ -1518,8 +1517,9 @@ re_attach(device_t dev)
        /*
         * Apply some magic PCI settings from Realtek ...
         */
-       if (sc->re_macver == RE_MACVER_03)
-               pci_write_config(dev, RE_PCI_LATENCY_TIMER, 0x40, 1);
+       if (sc->re_caps & RE_C_8169)
+               pci_write_config(dev, PCIR_CACHELNSZ, 0x8, 1);
+       pci_write_config(dev, PCIR_LATTIMER, 0x40, 1);
 
        if (sc->re_caps & RE_C_MAC2) {
                /*
@@ -3217,18 +3217,28 @@ re_get_eaddr(struct re_softc *sc, uint8_t *eaddr)
 {
        int i;
 
-#ifdef RE_USE_EEPROM
-       uint16_t as[ETHER_ADDR_LEN / 2];
+       if (sc->re_macver == RE_MACVER_11 || sc->re_macver == RE_MACVER_12) {
+               uint16_t re_did;
+
+               re_get_eewidth(sc);
+               re_read_eeprom(sc, (caddr_t)&re_did, 0, 1);
+               if (re_did == 0x8128) {
+                       uint16_t as[ETHER_ADDR_LEN / 2];
+
+                       /*
+                        * Get station address from the EEPROM.
+                        */
+                       re_read_eeprom(sc, (caddr_t)as, RE_EE_EADDR, 3);
+                       for (i = 0; i < ETHER_ADDR_LEN / 2; i++)
+                               as[i] = le16toh(as[i]);
+                       bcopy(as, eaddr, sizeof(eaddr));
+                       return;
+               }
+       }
 
        /*
-        * Get station address from the EEPROM.
+        * Get station address from IDRx.
         */
-       re_read_eeprom(sc, (caddr_t)as, RE_EE_EADDR, 3);
-       for (i = 0; i < ETHER_ADDR_LEN / 2; i++)
-               as[i] = le16toh(as[i]);
-       bcopy(as, eaddr, sizeof(eaddr));
-#else
        for (i = 0; i < ETHER_ADDR_LEN; ++i)
                eaddr[i] = CSR_READ_1(sc, RE_IDR0 + i);
-#endif
 }
index 1719cf8..9fd571b 100644 (file)
@@ -33,7 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/pci/if_rlreg.h,v 1.42 2004/05/24 19:39:23 jhb Exp $
- * $DragonFly: src/sys/dev/netif/re/if_rereg.h,v 1.21 2008/10/14 10:42:35 sephe Exp $
+ * $DragonFly: src/sys/dev/netif/re/if_rereg.h,v 1.22 2008/10/14 15:11:38 sephe Exp $
  */
 
 /*
@@ -580,7 +580,6 @@ struct re_stats {
  * other PCI registers.
  */
 
-#define RE_PCI_LATENCY_TIMER   0x0D
 #define RE_PCI_LOMEM           0x14
 #define RE_PCI_LOIO            0x10
 
index d54ea6f..ac87afb 100644 (file)
@@ -33,7 +33,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/pci/if_rlreg.h,v 1.42 2004/05/24 19:39:23 jhb Exp $
- * $DragonFly: src/sys/dev/netif/re/if_revar.h,v 1.23 2008/10/13 14:10:42 sephe Exp $
+ * $DragonFly: src/sys/dev/netif/re/if_revar.h,v 1.24 2008/10/14 15:11:38 sephe Exp $
  */
 
 #define RE_RX_DESC_CNT_DEF     256
@@ -179,14 +179,15 @@ struct re_softc {
        uint8_t                 saved_lattimer;
 };
 
-#define RE_C_PCIE              0x1
-#define RE_C_PCI64             0x2
+#define RE_C_PCIE              0x1     /* PCI-E */
+#define RE_C_PCI64             0x2     /* PCI-X */
 #define RE_C_HWIM              0x4     /* hardware interrupt moderation */
-#define RE_C_HWCSUM            0x8
-#define RE_C_JUMBO             0x10
+#define RE_C_HWCSUM            0x8     /* hardware csum offload */
+#define RE_C_JUMBO             0x10    /* jumbo frame */
 #define RE_C_8139CP            0x20    /* is 8139C+ */
-#define RE_C_MAC2              0x40    /* MAC style 2? */
+#define RE_C_MAC2              0x40    /* MAC style 2 */
 #define RE_C_PHYPMGT           0x80    /* PHY supports power mgmt */
+#define RE_C_8169              0x100   /* is 8110/8169 */
 
 #define RE_IS_8139CP(sc)       ((sc)->re_caps & RE_C_8139CP)