Source-Changes-HG archive

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

[src/trunk]: src/sys/dev Change rtw_debug from a debug level to a debug mask....



details:   https://anonhg.NetBSD.org/src/rev/888482afe9d9
branches:  trunk
changeset: 572213:888482afe9d9
user:      dyoung <dyoung%NetBSD.org@localhost>
date:      Sat Dec 25 06:58:37 2004 +0000

description:
Change rtw_debug from a debug level to a debug mask.  Add a lot of
debug flags.

>From Linux: handle an RTL8180 bug.  Sometimes the NIC skips from
the middle of the ring to the 0th rx descriptor.  Now the driver
resynchronizes.

Handle a receive descriptor underrun or Rx FIFO overflow condition
in the way that the Linux driver does.  This kind of seems like
overkill, but whatever.

Protect rtw_ioctl with splnet().

Do not load a tx descriptor with a buffer shorter than 4 bytes.

Handle a transmit timeout less disruptively.

diffstat:

 sys/dev/cardbus/if_rtw_cardbus.c |   24 +-
 sys/dev/ic/rtw.c                 |  498 ++++++++++++++++++++++++++------------
 sys/dev/ic/rtwphy.c              |   11 +-
 sys/dev/ic/rtwphyio.c            |   29 +-
 sys/dev/ic/rtwvar.h              |   83 +++--
 5 files changed, 425 insertions(+), 220 deletions(-)

diffs (truncated from 1464 to 300 lines):

diff -r f8ebedecd0de -r 888482afe9d9 sys/dev/cardbus/if_rtw_cardbus.c
--- a/sys/dev/cardbus/if_rtw_cardbus.c  Sat Dec 25 06:35:30 2004 +0000
+++ b/sys/dev/cardbus/if_rtw_cardbus.c  Sat Dec 25 06:58:37 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_rtw_cardbus.c,v 1.4 2004/12/20 21:05:34 dyoung Exp $ */
+/* $NetBSD: if_rtw_cardbus.c,v 1.5 2004/12/25 06:58:37 dyoung Exp $ */
 
 /*-
  * Copyright (c) 2004, 2005 David Young.  All rights reserved.
@@ -74,7 +74,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_rtw_cardbus.c,v 1.4 2004/12/20 21:05:34 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_rtw_cardbus.c,v 1.5 2004/12/25 06:58:37 dyoung Exp $");
 
 #include "opt_inet.h"
 #include "opt_ns.h"
@@ -271,9 +271,10 @@
 
        printf(": %s\n", rcp->rcp_product_name);
 
-       RTW_DPRINTF(("%s: pass %d.%d signature %08x\n", sc->sc_dev.dv_xname,
-           (rev >> 4) & 0xf, rev & 0xf,
-           cardbus_conf_read(ct->ct_cc, ct->ct_cf, csc->sc_tag, 0x80)));
+       RTW_DPRINTF(RTW_DEBUG_ATTACH,
+           ("%s: pass %d.%d signature %08x\n", sc->sc_dev.dv_xname,
+            (rev >> 4) & 0xf, rev & 0xf,
+            cardbus_conf_read(ct->ct_cc, ct->ct_cf, csc->sc_tag, 0x80)));
 
        /*
         * Map the device.
@@ -282,8 +283,9 @@
        if (Cardbus_mapreg_map(ct, RTW_PCI_MMBA,
            CARDBUS_MAPREG_TYPE_MEM, 0, &regs->r_bt, &regs->r_bh, &adr,
            &csc->sc_mapsize) == 0) {
-               RTW_DPRINTF(("%s: %s mapped %lu bytes mem space\n",
-                   sc->sc_dev.dv_xname, __func__, (long)csc->sc_mapsize));
+               RTW_DPRINTF(RTW_DEBUG_ATTACH,
+                   ("%s: %s mapped %lu bytes mem space\n",
+                    sc->sc_dev.dv_xname, __func__, (long)csc->sc_mapsize));
 #if rbus
 #else
                (*ct->ct_cf->cardbus_mem_open)(cc, 0, adr, adr+csc->sc_mapsize);
@@ -295,8 +297,9 @@
        } else if (Cardbus_mapreg_map(ct, RTW_PCI_IOBA,
            CARDBUS_MAPREG_TYPE_IO, 0, &regs->r_bt, &regs->r_bh, &adr,
            &csc->sc_mapsize) == 0) {
-               RTW_DPRINTF(("%s: %s mapped %lu bytes I/O space\n",
-                   sc->sc_dev.dv_xname, __func__, (long)csc->sc_mapsize));
+               RTW_DPRINTF(RTW_DEBUG_ATTACH,
+                   ("%s: %s mapped %lu bytes I/O space\n",
+                    sc->sc_dev.dv_xname, __func__, (long)csc->sc_mapsize));
 #if rbus
 #else
                (*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr+csc->sc_mapsize);
@@ -444,7 +447,8 @@
 {
        struct rtw_cardbus_softc *csc = (void *) sc;
 
-       RTW_DPRINTF(("%s: rtw_cardbus_power\n", sc->sc_dev.dv_xname));
+       RTW_DPRINTF(RTW_DEBUG_ATTACH,
+           ("%s: rtw_cardbus_power\n", sc->sc_dev.dv_xname));
 
        if (why == PWR_RESUME) {
                /*
diff -r f8ebedecd0de -r 888482afe9d9 sys/dev/ic/rtw.c
--- a/sys/dev/ic/rtw.c  Sat Dec 25 06:35:30 2004 +0000
+++ b/sys/dev/ic/rtw.c  Sat Dec 25 06:58:37 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rtw.c,v 1.20 2004/12/23 06:12:43 dyoung Exp $ */
+/* $NetBSD: rtw.c,v 1.21 2004/12/25 06:58:37 dyoung Exp $ */
 /*-
  * Copyright (c) 2004, 2005 David Young.  All rights reserved.
  *
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtw.c,v 1.20 2004/12/23 06:12:43 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtw.c,v 1.21 2004/12/25 06:58:37 dyoung Exp $");
 
 #include "bpfilter.h"
 
@@ -91,12 +91,13 @@
 int rtw_rfio_delay = 0;
 
 #ifdef RTW_DEBUG
-int rtw_debug = 2;
+int rtw_debug = 0;
 #endif /* RTW_DEBUG */
 
-#define NEXT_ATTACH_STATE(sc, state) do {                              \
-       DPRINTF(sc, ("%s: attach state %s\n", __func__, #state));       \
-       sc->sc_attach_state = state;                                    \
+#define NEXT_ATTACH_STATE(sc, state) do {                      \
+       DPRINTF(sc, RTW_DEBUG_ATTACH,                           \
+           ("%s: attach state %s\n", __func__, #state));       \
+       sc->sc_attach_state = state;                            \
 } while (0)
 
 int rtw_dwelltime = 1000;      /* milliseconds */
@@ -107,6 +108,8 @@
 static int rtw_sysctl_verify_rfio_delay(SYSCTLFN_PROTO);
 static int rtw_sysctl_verify_rfprog(SYSCTLFN_PROTO);
 #ifdef RTW_DEBUG
+static void rtw_print_txdesc(struct rtw_softc *, const char *,
+    struct rtw_txctl *, struct rtw_txdesc_blk *, int);
 static int rtw_sysctl_verify_debug(SYSCTLFN_PROTO);
 #endif /* RTW_DEBUG */
 
@@ -222,25 +225,28 @@
 static int
 rtw_sysctl_verify_debug(SYSCTLFN_ARGS)
 {
-       return rtw_sysctl_verify(SYSCTLFN_CALL(rnode), 0, 2);
+       return rtw_sysctl_verify(SYSCTLFN_CALL(rnode), 0, RTW_DEBUG_MAX);
 }
 
 static void
 rtw_print_regs(struct rtw_regs *regs, const char *dvname, const char *where)
 {
-#define PRINTREG32(sc, reg) \
-       RTW_DPRINTF2(("%s: reg[ " #reg " / %03x ] = %08x\n", \
+#define PRINTREG32(sc, reg)                            \
+       RTW_DPRINTF(RTW_DEBUG_REGDUMP,                  \
+           ("%s: reg[ " #reg " / %03x ] = %08x\n",     \
            dvname, reg, RTW_READ(regs, reg)))
 
-#define PRINTREG16(sc, reg) \
-       RTW_DPRINTF2(("%s: reg[ " #reg " / %03x ] = %04x\n", \
+#define PRINTREG16(sc, reg)                            \
+       RTW_DPRINTF(RTW_DEBUG_REGDUMP,                  \
+           ("%s: reg[ " #reg " / %03x ] = %04x\n",     \
            dvname, reg, RTW_READ16(regs, reg)))
 
-#define PRINTREG8(sc, reg) \
-       RTW_DPRINTF2(("%s: reg[ " #reg " / %03x ] = %02x\n", \
+#define PRINTREG8(sc, reg)                             \
+       RTW_DPRINTF(RTW_DEBUG_REGDUMP,                  \
+           ("%s: reg[ " #reg " / %03x ] = %02x\n",     \
            dvname, reg, RTW_READ8(regs, reg)))
 
-       RTW_DPRINTF2(("%s: %s\n", dvname, where));
+       RTW_DPRINTF(RTW_DEBUG_REGDUMP, ("%s: %s\n", dvname, where));
 
        PRINTREG32(regs, RTW_IDR0);
        PRINTREG32(regs, RTW_IDR1);
@@ -418,7 +424,8 @@
 rtw_set_access(struct rtw_softc *sc, enum rtw_access access)
 {
        rtw_set_access1(&sc->sc_regs, sc->sc_access, access);
-       RTW_DPRINTF(("%s: access %s -> %s\n", sc->sc_dev.dv_xname,
+       RTW_DPRINTF(RTW_DEBUG_ACCESS,
+           ("%s: access %s -> %s\n", sc->sc_dev.dv_xname,
            rtw_access_string(sc->sc_access),
            rtw_access_string(access)));
        sc->sc_access = access;
@@ -485,13 +492,14 @@
 
        RTW_WBR(regs, RTW_CR, RTW_CR);
 
-       for (i = 0; i < 10000; i++) {
+       for (i = 0; i < 1000; i++) {
                if ((cr = RTW_READ8(regs, RTW_CR) & RTW_CR_RST) == 0) {
-                       RTW_DPRINTF(("%s: reset in %dus\n", dvname, i));
+                       RTW_DPRINTF(RTW_DEBUG_RESET,
+                           ("%s: reset in %dus\n", dvname, i));
                        return 0;
                }
                RTW_RBR(regs, RTW_CR, RTW_CR);
-               DELAY(1); /* 1us */
+               DELAY(10); /* 10us */
        }
 
        printf("%s: reset failed\n", dvname);
@@ -530,8 +538,8 @@
        for (i = 0; i < 25; i++) {
                ecr = RTW_READ8(regs, RTW_9346CR);
                if ((ecr & RTW_9346CR_EEM_MASK) == RTW_9346CR_EEM_NORMAL) {
-                       RTW_DPRINTF(("%s: recall EEPROM in %dus\n", dvname,
-                           i * 100));
+                       RTW_DPRINTF(RTW_DEBUG_RESET,
+                           ("%s: recall EEPROM in %dus\n", dvname, i * 100));
                        return 0;
                }
                RTW_RBR(regs, RTW_9346CR, RTW_9346CR);
@@ -665,7 +673,8 @@
        for (i = 0; i < IEEE80211_ADDR_LEN; i++)
                mac[i] = RTW_SR_GET(sr, RTW_SR_MAC + i);
 
-       RTW_DPRINTF(("%s: EEPROM MAC %s\n", dvname, ether_sprintf(mac)));
+       RTW_DPRINTF(RTW_DEBUG_ATTACH,
+           ("%s: EEPROM MAC %s\n", dvname, ether_sprintf(mac)));
 
        *cs_threshold = RTW_SR_GET(sr, RTW_SR_ENERGYDETTHR);
 
@@ -750,11 +759,11 @@
        ecr = RTW_READ8(regs, RTW_9346CR);
 
        if ((flags & RTW_F_9356SROM) != 0) {
-               RTW_DPRINTF(("%s: 93c56 SROM\n", dvname));
+               RTW_DPRINTF(RTW_DEBUG_ATTACH, ("%s: 93c56 SROM\n", dvname));
                sr->sr_size = 256;
                sd.sd_chip = C56_66;
        } else {
-               RTW_DPRINTF(("%s: 93c46 SROM\n", dvname));
+               RTW_DPRINTF(RTW_DEBUG_ATTACH, ("%s: 93c46 SROM\n", dvname));
                sr->sr_size = 128;
                sd.sd_chip = C46;
        }
@@ -814,13 +823,15 @@
 #ifdef RTW_DEBUG
        {
                int i;
-               RTW_DPRINTF(("\n%s: serial ROM:\n\t", dvname));
+               RTW_DPRINTF(RTW_DEBUG_ATTACH,
+                   ("\n%s: serial ROM:\n\t", dvname));
                for (i = 0; i < sr->sr_size/2; i++) {
                        if (((i % 8) == 0) && (i != 0))
-                               RTW_DPRINTF(("\n\t"));
-                       RTW_DPRINTF((" %04x", sr->sr_content[i]));
+                               RTW_DPRINTF(RTW_DEBUG_ATTACH, ("\n\t"));
+                       RTW_DPRINTF(RTW_DEBUG_ATTACH,
+                           (" %04x", sr->sr_content[i]));
                }
-               RTW_DPRINTF(("\n"));
+               RTW_DPRINTF(RTW_DEBUG_ATTACH, ("\n"));
        }
 #endif /* RTW_DEBUG */
        return 0;
@@ -858,7 +869,8 @@
 
        RTW_WBR(regs, RTW_CONFIG4, RTW_CONFIG4);
 
-       RTW_DPRINTF(("%s: %s RF programming method, %#02x\n", dvname, method,
+       RTW_DPRINTF(RTW_DEBUG_INIT,
+           ("%s: %s RF programming method, %#02x\n", dvname, method,
            RTW_READ8(regs, RTW_CONFIG4)));
 }
 
@@ -1038,15 +1050,20 @@
 rtw_rxdescs_sync(bus_dma_tag_t dmat, bus_dmamap_t dmap, u_int desc0, u_int
     nsync, int ops)
 {
+       KASSERT(nsync <= RTW_RXQLEN);
        /* sync to end of ring */
-       if (desc0 + nsync > RTW_NRXDESC) {
+       if (desc0 + nsync > RTW_RXQLEN) {
                bus_dmamap_sync(dmat, dmap,
                    offsetof(struct rtw_descs, hd_rx[desc0]),
-                   sizeof(struct rtw_rxdesc) * (RTW_NRXDESC - desc0), ops);
-               nsync -= (RTW_NRXDESC - desc0);
+                   sizeof(struct rtw_rxdesc) * (RTW_RXQLEN - desc0), ops);
+               nsync -= (RTW_RXQLEN - desc0);
                desc0 = 0;
        }
 
+       KASSERT(desc0 < RTW_RXQLEN);
+       KASSERT(nsync <= RTW_RXQLEN);
+       KASSERT(desc0 + nsync <= RTW_RXQLEN);
+
        /* sync what remains */
        bus_dmamap_sync(dmat, dmap,
            offsetof(struct rtw_descs, hd_rx[desc0]),
@@ -1091,7 +1108,7 @@
        int i;
        struct rtw_rxctl *srx;
 
-       for (i = 0; i < RTW_NRXDESC; i++) {
+       for (i = 0; i < RTW_RXQLEN; i++) {
                srx = &desc[i];
                bus_dmamap_sync(dmat, srx->srx_dmamap, 0,
                    srx->srx_dmamap->dm_mapsize, BUS_DMASYNC_POSTREAD);
@@ -1140,7 +1157,7 @@
        int i, rc;
        struct rtw_rxctl *srx;
 
-       for (i = 0; i < RTW_NRXDESC; i++) {
+       for (i = 0; i < RTW_RXQLEN; i++) {
                srx = &desc[i];
                if ((rc = rtw_rxbuf_alloc(dmat, srx)) == 0)
                        continue;
@@ -1157,11 +1174,12 @@
 
 static __inline void
 rtw_rxdesc_init(bus_dma_tag_t dmat, bus_dmamap_t dmam,
-    struct rtw_rxdesc *hrx, struct rtw_rxctl *srx, int idx)
+    struct rtw_rxdesc *hrx, struct rtw_rxctl *srx, int idx, int flags)
 {
-       int is_last = (idx == RTW_NRXDESC - 1);
-       uint32_t ctl;
-
+       int is_last = (idx == RTW_RXQLEN - 1);
+       uint32_t ctl, octl, obuf;
+
+       obuf = hrx->hrx_buf;
        hrx->hrx_buf = htole32(srx->srx_dmamap->dm_segs[0].ds_addr);
 
        ctl = LSHIFT(srx->srx_mbuf->m_len, RTW_RXCTL_LENGTH_MASK) |



Home | Main Index | Thread Index | Old Index