From 08f56582a4696d4b9379f739848a01e091ffa9d1 Mon Sep 17 00:00:00 2001 From: stsp Date: Mon, 22 Nov 2021 10:54:36 +0000 Subject: [PATCH] Let iwx(4) use per-Tx-queue interface timers to ensure that the interface watchdog will trigger a device timeout if a particular Tx queue gets stuck while other Tx queues keep working. The Linux driver is using a similar workaround for "stuck queues". Tested by myself and jmc@ --- sys/dev/pci/if_iwx.c | 49 +++++++++++++++++++++++++---------------- sys/dev/pci/if_iwxvar.h | 4 ++-- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/sys/dev/pci/if_iwx.c b/sys/dev/pci/if_iwx.c index 9d396feb6fe..b7072c166ed 100644 --- a/sys/dev/pci/if_iwx.c +++ b/sys/dev/pci/if_iwx.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_iwx.c,v 1.122 2021/11/22 10:47:55 stsp Exp $ */ +/* $OpenBSD: if_iwx.c,v 1.123 2021/11/22 10:54:36 stsp Exp $ */ /* * Copyright (c) 2014, 2016 genua gmbh @@ -4552,8 +4552,6 @@ iwx_rx_tx_cmd(struct iwx_softc *sc, struct iwx_rx_packet *pkt, bus_dmamap_sync(sc->sc_dmat, data->map, 0, IWX_RBUF_SIZE, BUS_DMASYNC_POSTREAD); - sc->sc_tx_timer = 0; - /* Sanity checks. */ if (sizeof(*tx_resp) > len) return; @@ -4563,6 +4561,8 @@ iwx_rx_tx_cmd(struct iwx_softc *sc, struct iwx_rx_packet *pkt, tx_resp->frame_count * sizeof(tx_resp->status) > len) return; + sc->sc_tx_timer[qid] = 0; + if (tx_resp->frame_count > 1) /* A-MPDU */ return; @@ -4658,7 +4658,7 @@ iwx_rx_compressed_ba(struct iwx_softc *sc, struct iwx_rx_packet *pkt, idx = le16toh(ba_tfd->tfd_index); if (idx >= IWX_TX_RING_COUNT) continue; - sc->sc_tx_timer = 0; + sc->sc_tx_timer[qid] = 0; iwx_txq_advance(sc, ring, idx); iwx_clear_oactive(sc, ring); } @@ -5433,6 +5433,9 @@ iwx_tx(struct iwx_softc *sc, struct mbuf *m, struct ieee80211_node *ni) sc->qfullmsk |= 1 << ring->qid; } + if (ic->ic_if.if_flags & IFF_UP) + sc->sc_tx_timer[ring->qid] = 15; + return 0; } @@ -7973,10 +7976,8 @@ iwx_start(struct ifnet *ifp) continue; } - if (ifp->if_flags & IFF_UP) { - sc->sc_tx_timer = 15; + if (ifp->if_flags & IFF_UP) ifp->if_timer = 1; - } } return; @@ -8046,7 +8047,8 @@ iwx_stop(struct ifnet *ifp) struct iwx_rxba_data *rxba = &sc->sc_rxba_data[i]; iwx_clear_reorder_buffer(sc, rxba); } - ifp->if_timer = sc->sc_tx_timer = 0; + memset(sc->sc_tx_timer, 0, sizeof(sc->sc_tx_timer)); + ifp->if_timer = 0; splx(s); } @@ -8055,21 +8057,30 @@ void iwx_watchdog(struct ifnet *ifp) { struct iwx_softc *sc = ifp->if_softc; + int i; ifp->if_timer = 0; - if (sc->sc_tx_timer > 0) { - if (--sc->sc_tx_timer == 0) { - printf("%s: device timeout\n", DEVNAME(sc)); - if (ifp->if_flags & IFF_DEBUG) { - iwx_nic_error(sc); - iwx_dump_driver_status(sc); + + /* + * We maintain a separate timer for each Tx queue because + * Tx aggregation queues can get "stuck" while other queues + * keep working. The Linux driver uses a similar workaround. + */ + for (i = 0; i < nitems(sc->sc_tx_timer); i++) { + if (sc->sc_tx_timer[i] > 0) { + if (--sc->sc_tx_timer[i] == 0) { + printf("%s: device timeout\n", DEVNAME(sc)); + if (ifp->if_flags & IFF_DEBUG) { + iwx_nic_error(sc); + iwx_dump_driver_status(sc); + } + if ((sc->sc_flags & IWX_FLAG_SHUTDOWN) == 0) + task_add(systq, &sc->init_task); + ifp->if_oerrors++; + return; } - if ((sc->sc_flags & IWX_FLAG_SHUTDOWN) == 0) - task_add(systq, &sc->init_task); - ifp->if_oerrors++; - return; + ifp->if_timer = 1; } - ifp->if_timer = 1; } ieee80211_watchdog(ifp); diff --git a/sys/dev/pci/if_iwxvar.h b/sys/dev/pci/if_iwxvar.h index 69eebcb3b19..02bdd3aa1ff 100644 --- a/sys/dev/pci/if_iwxvar.h +++ b/sys/dev/pci/if_iwxvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_iwxvar.h,v 1.26 2021/11/22 10:31:58 stsp Exp $ */ +/* $OpenBSD: if_iwxvar.h,v 1.27 2021/11/22 10:54:36 stsp Exp $ */ /* * Copyright (c) 2014 genua mbh @@ -563,7 +563,7 @@ struct iwx_softc { struct iwx_nvm_data sc_nvm; struct iwx_bf_data sc_bf; - int sc_tx_timer; + int sc_tx_timer[IWX_NUM_TX_QUEUES]; int sc_rx_ba_sessions; int sc_scan_last_antenna; -- 2.20.1