Module Name: src Committed By: martin Date: Sat Nov 20 15:11:32 UTC 2021
Modified Files: src/sys/dev/mii [netbsd-8]: ihphy.c src/sys/dev/pci [netbsd-8]: if_wm.c if_wmreg.h Log Message: Pull up the following, requested by msaitoh in ticket #1707: sys/dev/pci/if_wm.c 1.716-1.718 via patch sys/dev/pci/if_wmreg.h 1.121 sys/dev/mii/ihphy.c 1.20 - Fix a bug that device timeout still happens when the link is down on ICH/PCH. Fixes PR kern/56478. - Add some sysctl info for debugging. - ihphy(4): Don't power down the PHY when the interface goes down. - Use macro. Fix comment. To generate a diff of this commit: cvs rdiff -u -r1.10.8.2 -r1.10.8.3 src/sys/dev/mii/ihphy.c cvs rdiff -u -r1.508.4.43 -r1.508.4.44 src/sys/dev/pci/if_wm.c cvs rdiff -u -r1.98.6.12 -r1.98.6.13 src/sys/dev/pci/if_wmreg.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/mii/ihphy.c diff -u src/sys/dev/mii/ihphy.c:1.10.8.2 src/sys/dev/mii/ihphy.c:1.10.8.3 --- src/sys/dev/mii/ihphy.c:1.10.8.2 Fri Jan 24 18:40:45 2020 +++ src/sys/dev/mii/ihphy.c Sat Nov 20 15:11:32 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: ihphy.c,v 1.10.8.2 2020/01/24 18:40:45 martin Exp $ */ +/* $NetBSD: ihphy.c,v 1.10.8.3 2021/11/20 15:11:32 martin Exp $ */ /*- * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ihphy.c,v 1.10.8.2 2020/01/24 18:40:45 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ihphy.c,v 1.10.8.3 2021/11/20 15:11:32 martin Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -216,7 +216,6 @@ ihphy_service(struct mii_softc *sc, stru case MII_DOWN: mii_phy_down(sc); - PHY_WRITE(sc, MII_BMCR, BMCR_PDOWN); return 0; } Index: src/sys/dev/pci/if_wm.c diff -u src/sys/dev/pci/if_wm.c:1.508.4.43 src/sys/dev/pci/if_wm.c:1.508.4.44 --- src/sys/dev/pci/if_wm.c:1.508.4.43 Sat Oct 23 11:49:22 2021 +++ src/sys/dev/pci/if_wm.c Sat Nov 20 15:11:31 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wm.c,v 1.508.4.43 2021/10/23 11:49:22 martin Exp $ */ +/* $NetBSD: if_wm.c,v 1.508.4.44 2021/11/20 15:11:31 martin Exp $ */ /* * Copyright (c) 2001, 2002, 2003, 2004 Wasabi Systems, Inc. @@ -82,7 +82,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.43 2021/10/23 11:49:22 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_wm.c,v 1.508.4.44 2021/11/20 15:11:31 martin Exp $"); #ifdef _KERNEL_OPT #include "opt_net_mpsafe.h" @@ -1042,6 +1042,8 @@ static bool wm_phy_need_linkdown_discard static void wm_set_linkdown_discard(struct wm_softc *); static void wm_clear_linkdown_discard(struct wm_softc *); +static int wm_sysctl_tdh_handler(SYSCTLFN_PROTO); +static int wm_sysctl_tdt_handler(SYSCTLFN_PROTO); #ifdef WM_DEBUG static int wm_sysctl_debug(SYSCTLFN_PROTO); #endif @@ -3114,8 +3116,12 @@ alloc_retry: sc->sc_txrx_use_workqueue = false; - if (wm_phy_need_linkdown_discard(sc)) + if (wm_phy_need_linkdown_discard(sc)) { + DPRINTF(sc, WM_DEBUG_LINK, + ("%s: %s: Set linkdown discard flag\n", + device_xname(sc->sc_dev), __func__)); wm_set_linkdown_discard(sc); + } wm_init_sysctls(sc); @@ -3566,10 +3572,12 @@ wm_ioctl(struct ifnet *ifp, u_long cmd, splx(s); #endif if (error == 0 && wm_phy_need_linkdown_discard(sc)) { - if (IFM_SUBTYPE(ifr->ifr_media) == IFM_NONE) + if (IFM_SUBTYPE(ifr->ifr_media) == IFM_NONE) { + DPRINTF(sc, WM_DEBUG_LINK, + ("%s: %s: Set linkdown discard flag\n", + device_xname(sc->sc_dev), __func__)); wm_set_linkdown_discard(sc); - else - wm_clear_linkdown_discard(sc); + } } break; case SIOCINITIFADDR: @@ -3585,14 +3593,14 @@ wm_ioctl(struct ifnet *ifp, u_long cmd, break; } WM_CORE_UNLOCK(sc); - if (((ifp->if_flags & IFF_UP) == 0) && wm_phy_need_linkdown_discard(sc)) - wm_clear_linkdown_discard(sc); /*FALLTHROUGH*/ default: if (cmd == SIOCSIFFLAGS && wm_phy_need_linkdown_discard(sc)) { - if (((ifp->if_flags & IFF_UP) == 0) && ((ifr->ifr_flags & IFF_UP) != 0)) { - wm_clear_linkdown_discard(sc); - } else if (((ifp->if_flags & IFF_UP) != 0) && ((ifr->ifr_flags & IFF_UP) == 0)) { + if (((ifp->if_flags & IFF_UP) != 0) && + ((ifr->ifr_flags & IFF_UP) == 0)) { + DPRINTF(sc, WM_DEBUG_LINK, + ("%s: %s: Set linkdown discard flag\n", + device_xname(sc->sc_dev), __func__)); wm_set_linkdown_discard(sc); } } @@ -5903,6 +5911,7 @@ wm_init_sysctls(struct wm_softc *sc) sc->sc_queue[i].sysctlname, SYSCTL_DESCR("Queue Name"), NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL) != 0) break; + if (sysctl_createv(log, 0, &qnode, &cnode, CTLFLAG_READONLY, CTLTYPE_INT, "txq_free", SYSCTL_DESCR("TX queue free"), @@ -5911,10 +5920,58 @@ wm_init_sysctls(struct wm_softc *sc) break; if (sysctl_createv(log, 0, &qnode, &cnode, CTLFLAG_READONLY, CTLTYPE_INT, + "txd_head", SYSCTL_DESCR("TX descriptor head"), + wm_sysctl_tdh_handler, 0, (void *)txq, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_INT, + "txd_tail", SYSCTL_DESCR("TX descriptor tail"), + wm_sysctl_tdt_handler, 0, (void *)txq, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_INT, "txq_next", SYSCTL_DESCR("TX queue next"), NULL, 0, &txq->txq_next, 0, CTL_CREATE, CTL_EOL) != 0) break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_INT, + "txq_sfree", SYSCTL_DESCR("TX queue sfree"), + NULL, 0, &txq->txq_sfree, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_INT, + "txq_snext", SYSCTL_DESCR("TX queue snext"), + NULL, 0, &txq->txq_snext, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_INT, + "txq_sdirty", SYSCTL_DESCR("TX queue sdirty"), + NULL, 0, &txq->txq_sdirty, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_INT, + "txq_flags", SYSCTL_DESCR("TX queue flags"), + NULL, 0, &txq->txq_flags, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_BOOL, + "txq_stopping", SYSCTL_DESCR("TX queue stopping"), + NULL, 0, &txq->txq_stopping, + 0, CTL_CREATE, CTL_EOL) != 0) + break; + if (sysctl_createv(log, 0, &qnode, &cnode, + CTLFLAG_READONLY, CTLTYPE_BOOL, + "txq_sending", SYSCTL_DESCR("TX queue sending"), + NULL, 0, &txq->txq_sending, + 0, CTL_CREATE, CTL_EOL) != 0) + break; if (sysctl_createv(log, 0, &qnode, &cnode, CTLFLAG_READONLY, CTLTYPE_INT, @@ -7335,7 +7392,9 @@ wm_init_tx_queue(struct wm_softc *sc, st wm_init_tx_regs(sc, wmq, txq); wm_init_tx_buffer(sc, txq); - txq->txq_flags = 0; /* Clear WM_TXQ_NO_SPACE */ + /* Clear other than WM_TXQ_LINKDOWN_DISCARD */ + txq->txq_flags &= WM_TXQ_LINKDOWN_DISCARD; + txq->txq_sending = false; } @@ -9357,13 +9416,21 @@ wm_linkintr_gmii(struct wm_softc *sc, ui DPRINTF(sc, WM_DEBUG_LINK, ("%s: LINK: LSC -> up %s\n", device_xname(sc->sc_dev), (status & STATUS_FD) ? "FDX" : "HDX")); - if (wm_phy_need_linkdown_discard(sc)) + if (wm_phy_need_linkdown_discard(sc)) { + DPRINTF(sc, WM_DEBUG_LINK, + ("%s: linkintr: Clear linkdown discard flag\n", + device_xname(dev))); wm_clear_linkdown_discard(sc); + } } else { - if (wm_phy_need_linkdown_discard(sc)) - wm_set_linkdown_discard(sc); DPRINTF(sc, WM_DEBUG_LINK, ("%s: LINK: LSC -> down\n", device_xname(sc->sc_dev))); + if (wm_phy_need_linkdown_discard(sc)) { + DPRINTF(sc, WM_DEBUG_LINK, + ("%s: linkintr: Set linkdown discard flag\n", + device_xname(dev))); + wm_set_linkdown_discard(sc); + } } if ((sc->sc_type == WM_T_ICH8) && (link == false)) wm_gig_downshift_workaround_ich8lan(sc); @@ -10268,9 +10335,9 @@ wm_gmii_setup_phytype(struct wm_softc *s } else { /* It's not the first call. Use PHY OUI and model */ switch (phy_oui) { - case MII_OUI_ATTANSIC: /* XXX ??? */ + case MII_OUI_ATTANSIC: /* atphy(4) */ switch (phy_model) { - case 0x0004: /* XXX */ + case MII_MODEL_ATTANSIC_AR8021: new_phytype = WMPHY_82578; break; default: @@ -16372,7 +16439,35 @@ wm_legacy_irq_quirk_spt(struct wm_softc CSR_WRITE(sc, WMREG_FEXTNVM9, reg); } -/* Sysctl function */ +/* Sysctl functions */ +static int +wm_sysctl_tdh_handler(SYSCTLFN_ARGS) +{ + struct sysctlnode node = *rnode; + struct wm_txqueue *txq = (struct wm_txqueue *)node.sysctl_data; + struct wm_queue *wmq = container_of(txq, struct wm_queue, wmq_txq); + struct wm_softc *sc = txq->txq_sc; + uint32_t reg; + + reg = CSR_READ(sc, WMREG_TDH(wmq->wmq_id)); + node.sysctl_data = ® + return sysctl_lookup(SYSCTLFN_CALL(&node)); +} + +static int +wm_sysctl_tdt_handler(SYSCTLFN_ARGS) +{ + struct sysctlnode node = *rnode; + struct wm_txqueue *txq = (struct wm_txqueue *)node.sysctl_data; + struct wm_queue *wmq = container_of(txq, struct wm_queue, wmq_txq); + struct wm_softc *sc = txq->txq_sc; + uint32_t reg; + + reg = CSR_READ(sc, WMREG_TDT(wmq->wmq_id)); + node.sysctl_data = ® + return sysctl_lookup(SYSCTLFN_CALL(&node)); +} + #ifdef WM_DEBUG static int wm_sysctl_debug(SYSCTLFN_ARGS) @@ -16390,6 +16485,8 @@ wm_sysctl_debug(SYSCTLFN_ARGS) return error; sc->sc_debug = dflags; + device_printf(sc->sc_dev, "TARC0: %08x\n", CSR_READ(sc, WMREG_TARC0)); + device_printf(sc->sc_dev, "TDT0: %08x\n", CSR_READ(sc, WMREG_TDT(0))); return 0; } Index: src/sys/dev/pci/if_wmreg.h diff -u src/sys/dev/pci/if_wmreg.h:1.98.6.12 src/sys/dev/pci/if_wmreg.h:1.98.6.13 --- src/sys/dev/pci/if_wmreg.h:1.98.6.12 Wed Aug 5 17:22:46 2020 +++ src/sys/dev/pci/if_wmreg.h Sat Nov 20 15:11:32 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: if_wmreg.h,v 1.98.6.12 2020/08/05 17:22:46 martin Exp $ */ +/* $NetBSD: if_wmreg.h,v 1.98.6.13 2021/11/20 15:11:32 martin Exp $ */ /* * Copyright (c) 2001 Wasabi Systems, Inc. @@ -973,8 +973,8 @@ struct livengood_tcpip_ctxdesc { #define WMREG_PHPM 0x0e14 /* PHY Power Management */ #define PHPM_SPD_EN __BIT(0) /* Smart Power Down */ #define PHPM_D0A_LPLU __BIT(1) /* D0 Low Power Link Up */ -#define PHPM_NOND0A_LPLU __BIT(2) /* D0 Low Power Link Up */ -#define PHPM_NOND0A_GBE_DIS __BIT(3) /* D0 Low Power Link Up */ +#define PHPM_NOND0A_LPLU __BIT(2) /* Non-D0a LPLU */ +#define PHPM_NOND0A_GBE_DIS __BIT(3) /* Disable 1G in non-D0a */ #define PHPM_GO_LINK_D __BIT(5) /* Go Link Disconnect */ #define WMREG_EEER 0x0e30 /* Energy Efficiency Ethernet "EEE" */