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.
This commit is contained in:
dyoung 2004-12-25 06:58:37 +00:00
parent 3954031773
commit d2b4873c41
5 changed files with 416 additions and 211 deletions

View File

@ -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 @@ rtw_cardbus_attach(parent, self, aux)
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 @@ rtw_cardbus_attach(parent, self, aux)
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 @@ rtw_cardbus_attach(parent, self, aux)
} 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 @@ rtw_cardbus_power(sc, why)
{
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) {
/*

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtwphy.c,v 1.2 2004/12/12 06:37:59 dyoung Exp $ */
/* $NetBSD: rtwphy.c,v 1.3 2004/12/25 06:58:37 dyoung Exp $ */
/*-
* Copyright (c) 2004, 2005 David Young. All rights reserved.
*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtwphy.c,v 1.2 2004/12/12 06:37:59 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtwphy.c,v 1.3 2004/12/25 06:58:37 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -597,9 +597,10 @@ rtw_phy_init(struct rtw_regs *regs, struct rtw_rf *rf, u_int8_t opaque_txpower,
enum rtw_pwrstate power)
{
int rc;
RTW_DPRINTF(("%s: txpower %u csthresh %u freq %u antdiv %u dflantb %u "
"pwrstate %s\n", __func__, opaque_txpower, cs_threshold,
freq, antdiv, dflantb, rtw_pwrstate_string(power)));
RTW_DPRINTF(RTW_DEBUG_PHY,
("%s: txpower %u csthresh %u freq %u antdiv %u dflantb %u "
"pwrstate %s\n", __func__, opaque_txpower, cs_threshold, freq,
antdiv, dflantb, rtw_pwrstate_string(power)));
/* XXX is this really necessary? */
if ((rc = rtw_rf_txpower(rf, opaque_txpower)) != 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtwphyio.c,v 1.3 2004/12/20 23:05:41 dyoung Exp $ */
/* $NetBSD: rtwphyio.c,v 1.4 2004/12/25 06:58:37 dyoung Exp $ */
/*-
* Copyright (c) 2004, 2005 David Young. All rights reserved.
*
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rtwphyio.c,v 1.3 2004/12/20 23:05:41 dyoung Exp $");
__KERNEL_RCSID(0, "$NetBSD: rtwphyio.c,v 1.4 2004/12/25 06:58:37 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -80,7 +80,8 @@ rtw_bbp_write(struct rtw_regs *regs, u_int addr, u_int val)
int i;
uint32_t wrbbp, rdbbp;
RTW_DPRINTF(("%s: bbp[%u] <- %u\n", __func__, addr, val));
RTW_DPRINTF(RTW_DEBUG_PHYIO,
("%s: bbp[%u] <- %u\n", __func__, addr, val));
KASSERT((addr & ~PRESHIFT(RTW_BB_ADDR_MASK)) == 0);
KASSERT((val & ~PRESHIFT(RTW_BB_WR_MASK)) == 0);
@ -91,8 +92,8 @@ rtw_bbp_write(struct rtw_regs *regs, u_int addr, u_int val)
rdbbp = LSHIFT(addr, RTW_BB_ADDR_MASK) |
RTW_BB_WR_MASK | RTW_BB_RD_MASK;
RTW_DPRINTF2(("%s: rdbbp = %#08x, wrbbp = %#08x\n", __func__,
rdbbp, wrbbp));
RTW_DPRINTF(RTW_DEBUG_PHYIO,
("%s: rdbbp = %#08x, wrbbp = %#08x\n", __func__, rdbbp, wrbbp));
for (i = BBP_WRITE_ITERS; --i >= 0; ) {
RTW_RBW(regs, RTW_BB, RTW_BB);
@ -103,7 +104,8 @@ rtw_bbp_write(struct rtw_regs *regs, u_int addr, u_int val)
delay(BBP_WRITE_DELAY); /* 1 microsecond */
if (MASK_AND_RSHIFT(RTW_READ(regs, RTW_BB),
RTW_BB_RD_MASK) == val) {
RTW_DPRINTF2(("%s: finished in %dus\n", __func__,
RTW_DPRINTF(RTW_DEBUG_PHYIO,
("%s: finished in %dus\n", __func__,
BBP_WRITE_DELAY * (BBP_WRITE_ITERS - i)));
return 0;
}
@ -123,7 +125,8 @@ rtw_rf_hostbangbits(struct rtw_regs *regs, u_int32_t bits, int lo_to_hi,
KASSERT(nbits <= 32);
RTW_DPRINTF(("%s: %u bits, %#08x, %s\n", __func__, nbits, bits,
RTW_DPRINTF(RTW_DEBUG_PHYIO,
("%s: %u bits, %#08x, %s\n", __func__, nbits, bits,
(lo_to_hi) ? "lo to hi" : "hi to lo"));
reg = RTW_PHYCFG_HST;
@ -136,7 +139,8 @@ rtw_rf_hostbangbits(struct rtw_regs *regs, u_int32_t bits, int lo_to_hi,
mask = 1 << (nbits - 1);
for (i = 0; i < nbits; i++) {
RTW_DPRINTF3(("%s: bits %#08x mask %#08x -> bit %#08x\n",
RTW_DPRINTF(RTW_DEBUG_PHYBITIO,
("%s: bits %#08x mask %#08x -> bit %#08x\n",
__func__, bits, mask, bits & mask));
if ((bits & mask) != 0)
@ -174,7 +178,7 @@ rtw_rf_macbangbits(struct rtw_regs *regs, u_int32_t reg)
{
int i;
RTW_DPRINTF(("%s: %#08x\n", __func__, reg));
RTW_DPRINTF(RTW_DEBUG_PHY, ("%s: %#08x\n", __func__, reg));
RTW_WRITE(regs, RTW_PHYCFG, RTW_PHYCFG_MAC_POLL | reg);
@ -188,7 +192,8 @@ rtw_rf_macbangbits(struct rtw_regs *regs, u_int32_t reg)
for (i = rtw_macbangbits_timeout; --i >= 0; delay(1)) {
if ((RTW_READ(regs, RTW_PHYCFG) & RTW_PHYCFG_MAC_POLL) == 0) {
RTW_DPRINTF2(("%s: finished in %dus\n", __func__,
RTW_DPRINTF(RTW_DEBUG_PHY,
("%s: finished in %dus\n", __func__,
rtw_macbangbits_timeout - i));
return 0;
}
@ -255,7 +260,7 @@ rtw_rf_hostwrite(struct rtw_regs *regs, enum rtw_rfchipid rfchipid,
int lo_to_hi;
u_int32_t bits;
RTW_DPRINTF(("%s: %s[%u] <- %#08x\n", __func__,
RTW_DPRINTF(RTW_DEBUG_PHYIO, ("%s: %s[%u] <- %#08x\n", __func__,
rtw_rfchipid_string(rfchipid), addr, val));
switch (rfchipid) {
@ -317,7 +322,7 @@ rtw_rf_macwrite(struct rtw_regs *regs, enum rtw_rfchipid rfchipid,
{
uint32_t reg;
RTW_DPRINTF(("%s: %s[%u] <- %#08x\n", __func__,
RTW_DPRINTF(RTW_DEBUG_PHYIO, ("%s: %s[%u] <- %#08x\n", __func__,
rtw_rfchipid_string(rfchipid), addr, val));
switch (rfchipid) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtwvar.h,v 1.7 2004/12/23 08:27:38 dyoung Exp $ */
/* $NetBSD: rtwvar.h,v 1.8 2004/12/25 06:58:37 dyoung Exp $ */
/*-
* Copyright (c) 2004, 2005 David Young. All rights reserved.
*
@ -37,20 +37,38 @@
#include <sys/callout.h>
#ifdef RTW_DEBUG
#define RTW_DEBUG_TUNE 0x00001
#define RTW_DEBUG_PKTFILT 0x00002
#define RTW_DEBUG_XMIT 0x00004
#define RTW_DEBUG_XMIT_DESC 0x00008
#define RTW_DEBUG_NODE 0x00010
#define RTW_DEBUG_PWR 0x00020
#define RTW_DEBUG_ATTACH 0x00040
#define RTW_DEBUG_REGDUMP 0x00080
#define RTW_DEBUG_ACCESS 0x00100
#define RTW_DEBUG_RESET 0x00200
#define RTW_DEBUG_INIT 0x00400
#define RTW_DEBUG_IOSTATE 0x00800
#define RTW_DEBUG_RECV 0x01000
#define RTW_DEBUG_RECV_DESC 0x02000
#define RTW_DEBUG_IO_KICK 0x04000
#define RTW_DEBUG_INTR 0x08000
#define RTW_DEBUG_PHY 0x10000
#define RTW_DEBUG_PHYIO 0x20000
#define RTW_DEBUG_PHYBITIO 0x40000
#define RTW_DEBUG_TIMEOUT 0x80000
#define RTW_DEBUG_MAX 0x7ffff
extern int rtw_debug;
#define RTW_DPRINTF(x) if (rtw_debug > 0) printf x
#define RTW_DPRINTF2(x) if (rtw_debug > 1) printf x
#define RTW_DPRINTF3(x) if (rtw_debug > 2) printf x
#define DPRINTF(sc, x) if ((sc)->sc_ic.ic_if.if_flags & IFF_DEBUG) printf x
#define DPRINTF2(sc, x) if ((sc)->sc_ic.ic_if.if_flags & IFF_DEBUG) RTW_DPRINTF2(x)
#define DPRINTF3(sc, x) if ((sc)->sc_ic.ic_if.if_flags & IFF_DEBUG) RTW_DPRINTF3(x)
#define RTW_DPRINTF(__flags, __x) \
if ((rtw_debug & (__flags)) != 0) printf __x
#define DPRINTF(__sc, __flags, __x) \
if (((__sc)->sc_ic.ic_if.if_flags & IFF_DEBUG) != 0) \
RTW_DPRINTF(__flags, __x)
#else /* RTW_DEBUG */
#define RTW_DPRINTF(x)
#define RTW_DPRINTF2(x)
#define RTW_DPRINTF3(x)
#define DPRINTF(sc, x)
#define DPRINTF2(sc, x)
#define DPRINTF3(sc, x)
#define RTW_DPRINTF(__x)
#define DPRINTF(__sc, __x)
#endif /* RTW_DEBUG */
#if 0
@ -127,37 +145,28 @@ struct rtw_txctl {
#define RTW_TXPRIHI 2
#define RTW_TXPRIBCN 3 /* beacon priority */
#define RTW_MAXPKTSEGS 32 /* max 32 segments per Tx packet */
#define RTW_MAXPKTSEGS 64 /* Max 64 segments per Tx packet */
#define CASSERT(cond, complaint) complaint[(cond) ? 0 : -1] = complaint[(cond) ? 0 : -1]
#define RTW_NTXDESC_ROUNDUP(n) \
roundup(n, RTW_DESC_ALIGNMENT / sizeof(struct rtw_txdesc))
#define RTW_TXQLEN_ROUNDUP(n) \
(RTW_NTXDESC_ROUNDUP(n * RTW_MAXPKTSEGS) / RTW_MAXPKTSEGS)
#define RTW_RXQLEN_ROUNDUP(n) \
roundup(n, RTW_DESC_ALIGNMENT / sizeof(struct rtw_rxdesc))
/* The descriptor rings must begin on RTW_DESC_ALIGNMENT boundaries.
* I allocate them consecutively from one buffer, so just round up.
/* Note well: the descriptor rings must begin on RTW_DESC_ALIGNMENT
* boundaries. I allocate them consecutively from one buffer, so
* just round up.
*/
#define RTW_TXQLENLO RTW_TXQLEN_ROUNDUP(64) /* low-priority queue length */
#define RTW_TXQLENMD RTW_TXQLEN_ROUNDUP(32) /* medium-priority */
#define RTW_TXQLENHI RTW_TXQLEN_ROUNDUP(16) /* high-priority */
#define RTW_TXQLENBCN 1 /* beacon */
#define RTW_TXQLENLO 64 /* low-priority queue length */
#define RTW_TXQLENMD 64 /* medium-priority */
#define RTW_TXQLENHI 64 /* high-priority */
#define RTW_TXQLENBCN 1 /* beacon */
#define RTW_NTXDESCLO (RTW_TXQLENLO * RTW_MAXPKTSEGS)
#define RTW_NTXDESCMD (RTW_TXQLENMD * RTW_MAXPKTSEGS)
#define RTW_NTXDESCHI (RTW_TXQLENHI * RTW_MAXPKTSEGS)
#define RTW_NTXDESCBCN (RTW_TXQLENBCN * RTW_MAXPKTSEGS)
#define RTW_NTXDESCLO RTW_TXQLENLO
#define RTW_NTXDESCMD RTW_TXQLENMD
#define RTW_NTXDESCHI RTW_TXQLENHI
#define RTW_NTXDESCBCN RTW_TXQLENBCN
#define RTW_NTXDESCTOTAL (RTW_NTXDESCLO + RTW_NTXDESCMD + \
RTW_NTXDESCHI + RTW_NTXDESCBCN)
#define RTW_RXQLEN RTW_RXQLEN_ROUNDUP(32)
#define RTW_NRXDESC RTW_RXQLEN
#define RTW_RXQLEN 64
struct rtw_txdesc_blk {
u_int htc_ndesc;
@ -189,7 +198,7 @@ struct rtw_descs {
struct rtw_txdesc hd_txlo[RTW_NTXDESCLO];
struct rtw_txdesc hd_txmd[RTW_NTXDESCMD];
struct rtw_txdesc hd_txhi[RTW_NTXDESCMD];
struct rtw_rxdesc hd_rx[RTW_NRXDESC];
struct rtw_rxdesc hd_rx[RTW_RXQLEN];
struct rtw_txdesc hd_bcn[RTW_NTXDESCBCN];
};
#define RTW_DESC_OFFSET(ring, i) offsetof(struct rtw_descs, ring[i])