diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2023-04-07 08:53:04 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2023-04-07 08:53:04 +0000 |
commit | bafaebc509894c84502c014673e75f452f6bdc19 (patch) | |
tree | c47540dd5312dd4f7ab56ec2df8f2d1964ed1383 | |
parent | d0eae993bf9722c3a769734bb6b5d8eb7f13bd07 (diff) |
Determine PHY mode and pass the appropriate flags down to the PHY when we
attach it.
ok dlg@
-rw-r--r-- | sys/dev/fdt/if_dwqe_fdt.c | 15 | ||||
-rw-r--r-- | sys/dev/ic/dwqe.c | 22 | ||||
-rw-r--r-- | sys/dev/ic/dwqevar.h | 11 |
3 files changed, 44 insertions, 4 deletions
diff --git a/sys/dev/fdt/if_dwqe_fdt.c b/sys/dev/fdt/if_dwqe_fdt.c index b4a66dead99..5bc5b321240 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.7 2023/04/07 06:33:49 dlg Exp $ */ +/* $OpenBSD: if_dwqe_fdt.c,v 1.8 2023/04/07 08:53:03 kettenis Exp $ */ /* * Copyright (c) 2008, 2019 Mark Kettenis <kettenis@openbsd.org> * Copyright (c) 2017, 2022 Patrick Wildt <patrick@blueri.se> @@ -86,6 +86,7 @@ dwqe_fdt_attach(struct device *parent, struct device *self, void *aux) { struct dwqe_softc *sc = (void *)self; struct fdt_attach_args *faa = aux; + char phy_mode[16] = { 0 }; uint32_t phy, phy_supply; uint32_t axi_config; struct ifnet *ifp; @@ -113,6 +114,18 @@ dwqe_fdt_attach(struct device *parent, struct device *self, void *aux) return; } + OF_getprop(faa->fa_node, "phy-mode", phy_mode, sizeof(phy_mode)); + if (strcmp(phy_mode, "rgmii") == 0) + sc->sc_phy_mode = DWQE_PHY_MODE_RGMII; + else if (strcmp(phy_mode, "rgmii-rxid") == 0) + sc->sc_phy_mode = DWQE_PHY_MODE_RGMII_RXID; + else if (strcmp(phy_mode, "rgmii-txid") == 0) + sc->sc_phy_mode = DWQE_PHY_MODE_RGMII_TXID; + else if (strcmp(phy_mode, "rgmii-id") == 0) + sc->sc_phy_mode = DWQE_PHY_MODE_RGMII_ID; + else + sc->sc_phy_mode = DWQE_PHY_MODE_UNKNOWN; + /* Lookup PHY. */ phy = OF_getpropint(faa->fa_node, "phy", 0); if (phy == 0) diff --git a/sys/dev/ic/dwqe.c b/sys/dev/ic/dwqe.c index 1f94791e465..bcc8b191194 100644 --- a/sys/dev/ic/dwqe.c +++ b/sys/dev/ic/dwqe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dwqe.c,v 1.3 2023/03/22 21:41:28 jsg Exp $ */ +/* $OpenBSD: dwqe.c,v 1.4 2023/04/07 08:53:03 kettenis Exp $ */ /* * Copyright (c) 2008, 2019 Mark Kettenis <kettenis@openbsd.org> * Copyright (c) 2017, 2022 Patrick Wildt <patrick@blueri.se> @@ -106,6 +106,7 @@ dwqe_attach(struct dwqe_softc *sc) { struct ifnet *ifp; uint32_t version, mode; + int mii_flags = 0; int i; version = dwqe_read(sc, GMAC_VERSION); @@ -212,8 +213,25 @@ dwqe_attach(struct dwqe_softc *sc) dwqe_write(sc, GMAC_SYS_BUS_MODE, mode); } + switch (sc->sc_phy_mode) { + case DWQE_PHY_MODE_RGMII: + mii_flags |= MIIF_SETDELAY; + break; + case DWQE_PHY_MODE_RGMII_ID: + mii_flags |= MIIF_SETDELAY | MIIF_RXID | MIIF_TXID; + break; + case DWQE_PHY_MODE_RGMII_RXID: + mii_flags |= MIIF_SETDELAY | MIIF_RXID; + break; + case DWQE_PHY_MODE_RGMII_TXID: + mii_flags |= MIIF_SETDELAY | MIIF_TXID; + break; + default: + break; + } + mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, sc->sc_phyloc, - (sc->sc_phyloc == MII_PHY_ANY) ? 0 : MII_OFFSET_ANY, 0); + (sc->sc_phyloc == MII_PHY_ANY) ? 0 : MII_OFFSET_ANY, mii_flags); if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) { printf("%s: no PHY found!\n", sc->sc_dev.dv_xname); ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL); diff --git a/sys/dev/ic/dwqevar.h b/sys/dev/ic/dwqevar.h index bb47dd688d6..060f61d2ac4 100644 --- a/sys/dev/ic/dwqevar.h +++ b/sys/dev/ic/dwqevar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dwqevar.h,v 1.2 2023/03/19 09:46:40 kettenis Exp $ */ +/* $OpenBSD: dwqevar.h,v 1.3 2023/04/07 08:53:03 kettenis Exp $ */ /* * Copyright (c) 2008, 2019 Mark Kettenis <kettenis@openbsd.org> * Copyright (c) 2017, 2022 Patrick Wildt <patrick@blueri.se> @@ -16,6 +16,14 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +enum dwqe_phy_mode { + DWQE_PHY_MODE_UNKNOWN, + DWQE_PHY_MODE_RGMII, + DWQE_PHY_MODE_RGMII_ID, + DWQE_PHY_MODE_RGMII_TXID, + DWQE_PHY_MODE_RGMII_RXID, +}; + struct dwqe_buf { bus_dmamap_t tb_map; struct mbuf *tb_m; @@ -51,6 +59,7 @@ struct dwqe_softc { #define sc_media sc_mii.mii_media int sc_link; int sc_phyloc; + enum dwqe_phy_mode sc_phy_mode; struct dwqe_dmamem *sc_txring; struct dwqe_buf *sc_txbuf; |