The branch main has been updated by adrian: URL: https://cgit.FreeBSD.org/src/commit/?id=7ddf19492cd930e8b3df970b2cab0909d227dc6a
commit 7ddf19492cd930e8b3df970b2cab0909d227dc6a Author: Adrian Chadd <adr...@freebsd.org> AuthorDate: 2024-12-14 19:37:15 +0000 Commit: Adrian Chadd <adr...@freebsd.org> CommitDate: 2024-12-31 19:11:07 +0000 rtwn: add support for register IO debugging Add support to read/write the MAC/PHY registers. Hide it behind RTWN_DEBUG. This doesn't cover the RF registers as they require a different IO path, but I haven't yet debugged the RF paths. Locally tested: * RTL8192CU, STA * RTL8188EU, STA * RTL8812AU / RTL8821AU, STA Differential Revision: https://reviews.freebsd.org/D48084 Reviewed by: bz --- sys/dev/rtwn/if_rtwn.c | 34 ++++++++++++++++++++++++++++++++++ sys/dev/rtwn/if_rtwnvar.h | 1 + 2 files changed, 35 insertions(+) diff --git a/sys/dev/rtwn/if_rtwn.c b/sys/dev/rtwn/if_rtwn.c index 46fa8e2de840..d7dd97a3fe18 100644 --- a/sys/dev/rtwn/if_rtwn.c +++ b/sys/dev/rtwn/if_rtwn.c @@ -321,12 +321,46 @@ rtwn_radiotap_attach(struct rtwn_softc *sc) &rxtap->wr_ihdr, sizeof(*rxtap), RTWN_RX_RADIOTAP_PRESENT); } +#ifdef RTWN_DEBUG +static int +rtwn_sysctl_reg_readwrite(SYSCTL_HANDLER_ARGS) +{ + struct rtwn_softc *sc = arg1; + int error; + uint32_t val; + + if (sc->sc_reg_addr > 0xffff) + return (EINVAL); + + RTWN_LOCK(sc); + val = rtwn_read_4(sc, sc->sc_reg_addr); + RTWN_UNLOCK(sc); + error = sysctl_handle_int(oidp, &val, 0, req); + if (error || !req->newptr) + return (error); + RTWN_LOCK(sc); + rtwn_write_4(sc, sc->sc_reg_addr, val); + RTWN_UNLOCK(sc); + return (0); +} +#endif /* RTWN_DEBUG */ + void rtwn_sysctlattach(struct rtwn_softc *sc) { struct sysctl_ctx_list *ctx = device_get_sysctl_ctx(sc->sc_dev); struct sysctl_oid *tree = device_get_sysctl_tree(sc->sc_dev); + sc->sc_reg_addr = 0; +#ifdef RTWN_DEBUG + SYSCTL_ADD_UINT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "reg_addr", CTLFLAG_RW, &sc->sc_reg_addr, + sc->sc_reg_addr, "debug register address"); + SYSCTL_ADD_PROC(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, + "reg_val", CTLTYPE_INT | CTLFLAG_RW, sc, 0, + rtwn_sysctl_reg_readwrite, "I", "debug register read/write"); +#endif /* RTWN_DEBUG */ + sc->sc_ht40 = 0; SYSCTL_ADD_INT(ctx, SYSCTL_CHILDREN(tree), OID_AUTO, "ht40", CTLFLAG_RDTUN, &sc->sc_ht40, diff --git a/sys/dev/rtwn/if_rtwnvar.h b/sys/dev/rtwn/if_rtwnvar.h index 8c52ad7ff482..570403747392 100644 --- a/sys/dev/rtwn/if_rtwnvar.h +++ b/sys/dev/rtwn/if_rtwnvar.h @@ -178,6 +178,7 @@ struct rtwn_softc { int sc_hwcrypto; int sc_ratectl_sysctl; int sc_ratectl; + uint32_t sc_reg_addr; uint8_t sc_detached; uint8_t sc_flags;