use if_baudrate and if_link_state for mac config, not mii media values
authordlg <dlg@openbsd.org>
Sat, 22 Apr 2023 05:01:44 +0000 (05:01 +0000)
committerdlg <dlg@openbsd.org>
Sat, 22 Apr 2023 05:01:44 +0000 (05:01 +0000)
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
sys/dev/ic/dwqe.c

index 5d44160..0da1055 100644 (file)
@@ -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 <kettenis@openbsd.org>
  * Copyright (c) 2017, 2022 Patrick Wildt <patrick@blueri.se>
@@ -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;
        }
index bcc8b19..9c96533 100644 (file)
@@ -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 <kettenis@openbsd.org>
  * Copyright (c) 2017, 2022 Patrick Wildt <patrick@blueri.se>
@@ -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);