Skip to content

Commit 7886130

Browse files
Pull up following revision(s) (requested by jmcneill in ticket NetBSD#69):
sys/dev/ic/bwi.c: revision 1.45 sys/dev/ic/bwireg.h: revision 1.6 sys/dev/ic/bwivar.h: revision 1.12 bwi: AMRR fix, PCI/cardbus interrupt fix, and other enhancements. - Fix AMRR by passing the correct "retry count" to _bwi_txeof() from bwi_txeof(). While here, cleanup parsing of BWI_TXSTATUS_0 fields to make the code more readable. - IPL_SOFTNET is enough for PIO locks and workqueues, no need for IPL_NET - Extend the SDIO bus intr_mask fix to all busses, I'd be amazed if PCI or Cardbus devices worked at all with the old code. - Since we only load firmware from disk once, only log the firmware revision once. Previously it was being printed every time bwi_init was called.
1 parent 6077deb commit 7886130

File tree

3 files changed

+33
-23
lines changed

3 files changed

+33
-23
lines changed

sys/dev/ic/bwi.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: bwi.c,v 1.43.2.1 2025/10/20 13:57:46 martin Exp $ */
1+
/* $NetBSD: bwi.c,v 1.43.2.2 2025/10/26 12:30:39 martin Exp $ */
22
/* $OpenBSD: bwi.c,v 1.74 2008/02/25 21:13:30 mglocker Exp $ */
33

44
/*
@@ -48,7 +48,7 @@
4848

4949

5050
#include <sys/cdefs.h>
51-
__KERNEL_RCSID(0, "$NetBSD: bwi.c,v 1.43.2.1 2025/10/20 13:57:46 martin Exp $");
51+
__KERNEL_RCSID(0, "$NetBSD: bwi.c,v 1.43.2.2 2025/10/26 12:30:39 martin Exp $");
5252

5353
#include <sys/param.h>
5454
#include <sys/callout.h>
@@ -719,7 +719,8 @@ bwi_softintr(void *arg)
719719
struct bwi_softc *sc = arg;
720720
struct bwi_mac *mac;
721721
struct ifnet *ifp = &sc->sc_if;
722-
uint32_t intr_status, intr_mask;
722+
const uint32_t intr_mask = BWI_INIT_INTRS;
723+
uint32_t intr_status;
723724
uint32_t txrx_intr_status[BWI_TXRX_NRING];
724725
int i, s, txrx_error, tx = 0, rx_data = -1;
725726

@@ -735,12 +736,6 @@ bwi_softintr(void *arg)
735736
if (intr_status == 0xffffffff) /* Not for us */
736737
goto out;
737738

738-
if (BWI_IS_SDIO(sc)) {
739-
intr_mask = 0xffffffff;
740-
} else {
741-
/* XXX FIXME */
742-
intr_mask = CSR_READ_4(sc, BWI_MAC_INTR_MASK);
743-
}
744739
DPRINTF(sc, BWI_DBG_INTR,
745740
"intr status 0x%08x mask 0x%08x -> 0x%08x\n",
746741
intr_status, intr_mask, intr_status & intr_mask);
@@ -894,14 +889,14 @@ bwi_attach(struct bwi_softc *sc)
894889
if (BWI_IS_SDIO(sc)) {
895890
error = workqueue_create(&sc->sc_taskq,
896891
device_xname(sc->sc_dev), bwi_task, sc, PRI_NONE,
897-
IPL_NET, 0);
892+
IPL_SOFTNET, 0);
898893
if (error != 0) {
899894
device_printf(sc->sc_dev,
900895
"failed to create workqueue\n");
901896
goto fail;
902897
}
903898
sc->sc_freetask = pool_cache_init(sizeof(struct bwi_task),
904-
0, 0, 0, "bwitask", NULL, IPL_NET, NULL, NULL, NULL);
899+
0, 0, 0, "bwitask", NULL, IPL_SOFTNET, NULL, NULL, NULL);
905900
pool_cache_prime(sc->sc_freetask, BWI_TASK_COUNT);
906901
} else {
907902
sc->sc_soft_ih = softint_establish(SOFTINT_NET, bwi_softintr,
@@ -2142,9 +2137,12 @@ bwi_mac_fw_load(struct bwi_mac *mac)
21422137
return (ENODEV);
21432138
}
21442139

2145-
aprint_normal_dev(sc->sc_dev, "firmware rev 0x%04x,"
2146-
" patch level 0x%04x\n", fw_rev,
2147-
MOBJ_READ_2(mac, BWI_COMM_MOBJ, BWI_COMM_MOBJ_FWPATCHLV));
2140+
if (fw_rev != sc->sc_fw_rev) {
2141+
aprint_normal_dev(sc->sc_dev, "firmware rev 0x%04x,"
2142+
" patch level 0x%04x\n", fw_rev,
2143+
MOBJ_READ_2(mac, BWI_COMM_MOBJ, BWI_COMM_MOBJ_FWPATCHLV));
2144+
sc->sc_fw_rev = fw_rev;
2145+
}
21482146

21492147
return (0);
21502148
}
@@ -7596,7 +7594,8 @@ bwi_start(struct ifnet *ifp)
75967594
tbd->tbd_used++;
75977595
idx = (idx + 1) % BWI_TX_NDESC;
75987596

7599-
if (tbd->tbd_used + BWI_TX_NSPRDESC >= BWI_TX_NDESC) {
7597+
if (tbd->tbd_used + BWI_TX_NSPRDESC >=
7598+
(BWI_IS_SDIO(sc) ? 32 : BWI_TX_NDESC)) {
76007599
ifp->if_flags |= IFF_OACTIVE;
76017600
break;
76027601
}
@@ -8057,7 +8056,7 @@ bwi_pio_alloc(struct bwi_softc *sc)
80578056
sc->sc_txeof_status = bwi_txeof_status_pio;
80588057
}
80598058

8060-
mutex_init(&sc->sc_pio_txlock, MUTEX_DEFAULT, IPL_NET);
8059+
mutex_init(&sc->sc_pio_txlock, MUTEX_DEFAULT, IPL_SOFTNET);
80618060
STAILQ_INIT(&sc->sc_pio_txpend);
80628061

80638062
sc->sc_pio_fifolen = 2000 - 80;
@@ -10017,22 +10016,28 @@ bwi_txeof(struct bwi_softc *sc)
1001710016

1001810017
for (;;) {
1001910018
uint32_t tx_status0;
10020-
uint16_t tx_id, tx_info;
10019+
uint16_t tx_id;
10020+
uint8_t tx_cnt;
1002110021

1002210022
tx_status0 = CSR_READ_4(sc, BWI_TXSTATUS_0);
1002310023
if ((tx_status0 & BWI_TXSTATUS_0_MORE) == 0)
1002410024
break;
1002510025
(void)CSR_READ_4(sc, BWI_TXSTATUS_1);
1002610026

1002710027
tx_id = __SHIFTOUT(tx_status0, BWI_TXSTATUS_0_TXID_MASK);
10028-
tx_info = BWI_TXSTATUS_0_INFO(tx_status0);
10028+
tx_cnt = __SHIFTOUT(tx_status0, BWI_TXSTATUS_0_DATA_TXCNT_MASK);
1002910029

10030-
if (tx_info & 0x30) /* XXX */
10030+
if ((tx_status0 &
10031+
(BWI_TXSTATUS_0_PENDING | BWI_TXSTATUS_0_AMPDU)) != 0) {
1003110032
continue;
10033+
}
1003210034

10033-
_bwi_txeof(sc, tx_id, (tx_info >> 8) & 0xf);
10035+
_bwi_txeof(sc, tx_id, tx_cnt != 1);
1003410036

1003510037
if_statinc(ifp, if_opackets);
10038+
if (tx_cnt == 0) {
10039+
if_statinc(ifp, if_oerrors);
10040+
}
1003610041
}
1003710042

1003810043
if ((ifp->if_flags & IFF_OACTIVE) == 0)

sys/dev/ic/bwireg.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: bwireg.h,v 1.5 2025/01/19 00:29:28 jmcneill Exp $ */
1+
/* $NetBSD: bwireg.h,v 1.5.2.1 2025/10/26 12:30:39 martin Exp $ */
22
/* $OpenBSD: bwireg.h,v 1.7 2007/11/17 16:50:02 mglocker Exp $ */
33

44
/*
@@ -251,7 +251,9 @@
251251
#define BWI_TXSTATUS_0 0x00000170
252252
#define BWI_TXSTATUS_0_MORE (1 << 0)
253253
#define BWI_TXSTATUS_0_TXID_MASK 0xffff0000
254-
#define BWI_TXSTATUS_0_INFO(st) (((st) & 0xfff0) | (((st) & 0xf) >> 1))
254+
#define BWI_TXSTATUS_0_DATA_TXCNT_MASK 0x0000f000
255+
#define BWI_TXSTATUS_0_PENDING 0x00000040
256+
#define BWI_TXSTATUS_0_AMPDU 0x00000020
255257
#define BWI_TXSTATUS_1 0x00000174
256258

257259
#define BWI_TXRX_CTRL_BASE 0x200

sys/dev/ic/bwivar.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: bwivar.h,v 1.11 2025/01/19 00:29:28 jmcneill Exp $ */
1+
/* $NetBSD: bwivar.h,v 1.11.2.1 2025/10/26 12:30:39 martin Exp $ */
22
/* $OpenBSD: bwivar.h,v 1.23 2008/02/25 20:36:54 mglocker Exp $ */
33

44
/*
@@ -690,6 +690,9 @@ struct bwi_softc {
690690
int sc_txpwr_calib;
691691
int sc_debug; /* BWI_DBG_ */
692692

693+
/* Firmware info */
694+
uint16_t sc_fw_rev; /* Last firmware revision */
695+
693696
struct bpf_if *sc_drvbpf;
694697

695698
union {

0 commit comments

Comments
 (0)