NetBSD-Bugs archive

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

kern/48343: patch for re(4) to change link address of 8111E_VL



>Number:         48343
>Category:       kern
>Synopsis:       patch for re(4) to change link address of 8111E_VL
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 25 17:35:01 +0000 2013
>Originator:     Takahiro HAYASHI
>Release:        NetBSD 6.99.24
>Organization:
>Environment:
System: NetBSD halt 6.99.24 NetBSD 6.99.24 (UNION) #0: Tue Oct 15 22:54:01 JST 
2013 root@halt:/usr/build2/obj.amd64/sys/arch/amd64/compile/UNION amd64
Architecture: x86_64
Machine: amd64
>Description:
        This patch allows re(4) driver to change adapter's link
        address of particular revision 8111E_VL(0x2c800000).
        It needs to set MAC address into special regs too.

        code taken from Linux drivers/net/ethernet/realtek/r8169.c.

>How-To-Repeat:

>Fix:
        Please apply this patch and define RE_USE_EECMD in your
        kernel config file.

Index: src/sys/dev/ic/rtl8169.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl8169.c,v
retrieving revision 1.139
diff -u -p -r1.139 rtl8169.c
--- src/sys/dev/ic/rtl8169.c    10 May 2013 14:55:08 -0000      1.139
+++ src/sys/dev/ic/rtl8169.c    15 Oct 2013 09:06:51 -0000
@@ -607,6 +609,8 @@ re_attach(struct rtk_softc *sc)
                            RTKQ_NOJUMBO;
                        break;
                case RTK_HWREV_8168E_VL:
+                       sc->sc_quirk |= RTKQ_SET_EXGMAC;
+                       /* FALLTHROUGH */
                case RTK_HWREV_8168F:
                        sc->sc_quirk |= RTKQ_DESCV2 | RTKQ_NOEECMD |
                            RTKQ_MACSTAT | RTKQ_CMDSTOP | RTKQ_NOJUMBO;
@@ -1744,6 +1748,62 @@ re_start(struct ifnet *ifp)
        }
 }
 
+#ifdef RE_USE_EECMD
+static bool
+re_eri_loop_wait(struct rtk_softc *sc, unsigned int d, int n)
+{
+       int i;
+
+       for (i = 0; i < n; i++) {
+               DELAY(d);
+               if ((CSR_READ_4(sc, RTK_ERIAR) & RTK_ERIAR_FLAG) == false)
+                       return true;
+       }
+       aprint_error_dev(sc->sc_dev, "loop: %d, delay: %u\n", n, d);
+       return false;
+}
+
+static void
+re_eri_write(struct rtk_softc *sc, int addr, uint32_t mask,
+                         uint32_t val, int type)
+{
+       KASSERT((addr & 3) || (mask == 0));
+       CSR_WRITE_4(sc, RTK_ERIDR, val);
+       CSR_WRITE_4(sc, RTK_ERIAR, RTK_ERIAR_WRITE_CMD | type | mask | addr);
+
+       re_eri_loop_wait(sc, 100, 100);
+}
+
+struct exgmac_reg {
+       uint16_t addr;
+       uint16_t mask;
+       uint32_t val;
+};
+
+static void
+re_set_exgmac(struct rtk_softc *sc, const uint8_t *enaddr)
+{
+       const uint16_t w[] = {
+               enaddr[0] | (enaddr[1] << 8),
+               enaddr[2] | (enaddr[3] << 8),
+               enaddr[4] | (enaddr[5] << 8)
+       };
+       /* XXX replace magic */
+       const struct exgmac_reg e[] = {
+               { .addr = 0xe0, RTK_ERIAR_MASK_1111, .val = w[0]|(w[1] << 16) },
+               { .addr = 0xe4, RTK_ERIAR_MASK_1111, .val = w[2] },
+               { .addr = 0xf0, RTK_ERIAR_MASK_1111, .val = w[0] << 16 },
+               { .addr = 0xf4, RTK_ERIAR_MASK_1111, .val = w[1]|(w[2] << 16) }
+       };
+       int i;
+
+       for (i = 0; i < __arraycount(e); i++) {
+               re_eri_write(sc,
+                   e[i].addr, e[i].mask, e[i].val, RTK_ERIAR_EXGMAC);
+       }
+}
+#endif /* RE_USE_CMD */
+
 static int
 re_init(struct ifnet *ifp)
 {
@@ -1812,6 +1872,14 @@ re_init(struct ifnet *ifp)
        CSR_WRITE_4(sc, RTK_IDR0, reg);
        reg = enaddr[4] | (enaddr[5] << 8);
        CSR_WRITE_4(sc, RTK_IDR4, reg);
+
+       /*
+        * 8111E_VL needs to set MAC address into special regs too.
+        * from Linux drivers/net/ethernet/realtek/r8169.c
+        */
+       if ((sc->sc_quirk & RTKQ_SET_EXGMAC) != 0) {
+               re_set_exgmac(sc, enaddr);
+       }
        CSR_WRITE_1(sc, RTK_EECMD, RTK_EEMODE_OFF);
 #endif
 
Index: src/sys/dev/ic/rtl81x9reg.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9reg.h,v
retrieving revision 1.44
diff -u -p -r1.44 rtl81x9reg.h
--- src/sys/dev/ic/rtl81x9reg.h 6 Apr 2013 01:53:14 -0000       1.44
+++ src/sys/dev/ic/rtl81x9reg.h 15 Oct 2013 09:06:51 -0000
@@ -131,6 +131,21 @@
 #define RTK_TBI_LPAR           0x006A
 #define RTK_GMEDIASTAT         0x006C  /* 8 bits */
 #define RTK_PMCH               0x006F  /* 8 bits */
+#define RTK_ERIDR              0x0070
+#define RTK_ERIAR              0x0074
+#define RTK_ERIAR_FLAG         0x80000000
+#define RTK_ERIAR_WRITE_CMD    0x80000000
+#define RTK_ERIAR_READ_CMD     0x00000000
+#define RTK_ERIAR_ADDR_BYTE_ALIGN 4
+#define RTK_ERIAR_TYPE_SHIFT   16
+#define RTK_ERIAR_EXGMAC       (0x00 << RTK_ERIAR_TYPE_SHIFT)
+#define RTK_ERIAR_MSIX         (0x01 << RTK_ERIAR_TYPE_SHIFT)
+#define RTK_ERIAR_ASF          (0x02 << RTK_ERIAR_TYPE_SHIFT)
+#define RTK_ERIAR_MASK_SHIFT   12
+#define RTK_ERIAR_MASK_0001    (0x1 << RTK_ERIAR_MASK_SHIFT)
+#define RTK_ERIAR_MASK_0011    (0x3 << RTK_ERIAR_MASK_SHIFT)
+#define RTK_ERIAR_MASK_0101    (0x5 << RTK_ERIAR_MASK_SHIFT)
+#define RTK_ERIAR_MASK_1111    (0xf << RTK_ERIAR_MASK_SHIFT)
 #define RTK_EPHYAR             0x0080
 #define RTK_LDPS               0x0082  /* Link Down Power Saving */
 #define RTK_DBG_REG            0x00D1
Index: src/sys/dev/ic/rtl81x9var.h
===================================================================
RCS file: /cvsroot/src/sys/dev/ic/rtl81x9var.h,v
retrieving revision 1.53
diff -u -p -r1.53 rtl81x9var.h
--- src/sys/dev/ic/rtl81x9var.h 2 Feb 2012 19:43:03 -0000       1.53
+++ src/sys/dev/ic/rtl81x9var.h 15 Oct 2013 09:06:51 -0000
@@ -192,6 +192,7 @@ struct rtk_softc {
 #define RTKQ_MACSTAT           0x00000100      /* set MACSTAT_DIS on init */
 #define RTKQ_CMDSTOP           0x00000200      /* set STOPREQ on stop */
 #define RTKQ_PHYWAKE_PM                0x00000400      /* wake PHY from power 
down */
+#define RTKQ_SET_EXGMAC                0x00000800      /* write MAC addr to 
GigaMAC */
 
        bus_dma_tag_t           sc_dmat;
 
--
t-hash



Home | Main Index | Thread Index | Old Index