From 566e78fc447a35f0193442d7bc274c9595f27a3d Mon Sep 17 00:00:00 2001 From: dlg Date: Sat, 22 Apr 2023 05:01:44 +0000 Subject: [PATCH] use if_baudrate and if_link_state for mac config, not mii media values the phy code sets if_baudrate and if_link_state, so the information needed to config the mac on the chip is there anyway. it also has the benefit that the driver doesnt have to understand every type of media (eg, 1000baseTX vs 1000baseSX) because they're both the same speed and that's what matters when configuring the chip and the clocks etc. this is a step toward being able to use a fixed-link node in the device tree instead of a phy, as is found on the banana pi bpi-r2 pro on the gmac connected to a switch chip. --- sys/dev/fdt/if_dwqe_fdt.c | 20 +++++++++++--------- sys/dev/ic/dwqe.c | 16 +++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/sys/dev/fdt/if_dwqe_fdt.c b/sys/dev/fdt/if_dwqe_fdt.c index 5d441600db3..0da10556b7d 100644 --- a/sys/dev/fdt/if_dwqe_fdt.c +++ b/sys/dev/fdt/if_dwqe_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_dwqe_fdt.c,v 1.9 2023/04/07 22:55:26 dlg Exp $ */ +/* $OpenBSD: if_dwqe_fdt.c,v 1.10 2023/04/22 05:01:44 dlg Exp $ */ /* * Copyright (c) 2008, 2019 Mark Kettenis * Copyright (c) 2017, 2022 Patrick Wildt @@ -349,17 +349,18 @@ void dwqe_mii_statchg_rk3568_task(void *arg) { struct dwqe_softc *sc = arg; + struct ifnet *ifp = &sc->sc_ac.ac_if; dwqe_mii_statchg(&sc->sc_dev); - switch (IFM_SUBTYPE(sc->sc_mii.mii_media_active)) { - case IFM_10_T: + switch (ifp->if_baudrate) { + case IF_Mbps(10): clock_set_frequency(sc->sc_node, "clk_mac_speed", 2500000); break; - case IFM_100_TX: + case IF_Mbps(100): clock_set_frequency(sc->sc_node, "clk_mac_speed", 25000000); break; - case IFM_1000_T: + case IF_Mbps(1000): clock_set_frequency(sc->sc_node, "clk_mac_speed", 125000000); break; } @@ -377,6 +378,7 @@ void dwqe_mii_statchg_rk3588(struct device *self) { struct dwqe_softc *sc = (void *)self; + struct ifnet *ifp = &sc->sc_ac.ac_if; struct regmap *rm; uint32_t grf; uint32_t gmac_clk_sel = 0; @@ -388,14 +390,14 @@ dwqe_mii_statchg_rk3588(struct device *self) if (rm == NULL) return; - switch (IFM_SUBTYPE(sc->sc_mii.mii_media_active)) { - case IFM_10_T: + switch (ifp->if_baudrate) { + case IF_Mbps(10): gmac_clk_sel = sc->sc_clk_sel_2_5; break; - case IFM_100_TX: + case IF_Mbps(100): gmac_clk_sel = sc->sc_clk_sel_25; break; - case IFM_1000_T: + case IF_Mbps(1000): gmac_clk_sel = sc->sc_clk_sel_125; break; } diff --git a/sys/dev/ic/dwqe.c b/sys/dev/ic/dwqe.c index bcc8b191194..9c9653344d1 100644 --- a/sys/dev/ic/dwqe.c +++ b/sys/dev/ic/dwqe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwqe.c,v 1.4 2023/04/07 08:53:03 kettenis Exp $ */ +/* $OpenBSD: dwqe.c,v 1.5 2023/04/22 05:01:44 dlg Exp $ */ /* * Copyright (c) 2008, 2019 Mark Kettenis * Copyright (c) 2017, 2022 Patrick Wildt @@ -476,23 +476,21 @@ void dwqe_mii_statchg(struct device *self) { struct dwqe_softc *sc = (void *)self; + struct ifnet *ifp = &sc->sc_ac.ac_if; uint32_t conf; conf = dwqe_read(sc, GMAC_MAC_CONF); conf &= ~(GMAC_MAC_CONF_PS | GMAC_MAC_CONF_FES); - switch (IFM_SUBTYPE(sc->sc_mii.mii_media_active)) { - case IFM_1000_SX: - case IFM_1000_LX: - case IFM_1000_CX: - case IFM_1000_T: + switch (ifp->if_baudrate) { + case IF_Mbps(1000): sc->sc_link = 1; break; - case IFM_100_TX: + case IF_Mbps(100): conf |= GMAC_MAC_CONF_PS | GMAC_MAC_CONF_FES; sc->sc_link = 1; break; - case IFM_10_T: + case IF_Mbps(10): conf |= GMAC_MAC_CONF_PS; sc->sc_link = 1; break; @@ -505,7 +503,7 @@ dwqe_mii_statchg(struct device *self) return; conf &= ~GMAC_MAC_CONF_DM; - if ((sc->sc_mii.mii_media_active & IFM_GMASK) == IFM_FDX) + if (ifp->if_link_state == LINK_STATE_FULL_DUPLEX) conf |= GMAC_MAC_CONF_DM; dwqe_write(sc, GMAC_MAC_CONF, conf); -- 2.20.1