From 7ffe0765259ee97aa3918f1bed56c450cda67d78 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Mon, 15 May 2023 16:04:18 +0200 Subject: [PATCH] axgbe: move phy_stop to axgbe_if_detach() Since the iflib interface needs axgbe_pci_init() and its phy starting capabilities, no data was passed in its absence. With the NULL check of the axgbe_miibus we also resort back to an MDIO read as a module might be capable of both clause 22 and clause 45 methods of communication. with the move of phy_stop() to if_detach() in https://github.com/opnsense/src/commit/d50d4e8cd499882d4ac77765797a81306e316795, it's better to prevent reconfiguring the phy should the pci_init() callout trigger more than once. --- sys/dev/axgbe/if_axgbe_pci.c | 4 +--- sys/dev/axgbe/xgbe-mdio.c | 6 +++++- sys/dev/axgbe/xgbe-phy-v2.c | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sys/dev/axgbe/if_axgbe_pci.c b/sys/dev/axgbe/if_axgbe_pci.c index 707680413b9..db21739dcd1 100644 --- a/sys/dev/axgbe/if_axgbe_pci.c +++ b/sys/dev/axgbe/if_axgbe_pci.c @@ -1577,6 +1577,7 @@ axgbe_if_detach(if_ctx_t ctx) mac_res[0] = pdata->xgmac_res; mac_res[1] = pdata->xpcs_res; + phy_if->phy_stop(pdata); phy_if->phy_exit(pdata); /* Free Interrupts */ @@ -1648,7 +1649,6 @@ axgbe_pci_stop(if_ctx_t ctx) { struct axgbe_if_softc *sc = iflib_get_softc(ctx); struct xgbe_prv_data *pdata = &sc->pdata; - struct xgbe_phy_if *phy_if = &pdata->phy_if; struct xgbe_hw_if *hw_if = &pdata->hw_if; int ret; @@ -1663,8 +1663,6 @@ axgbe_pci_stop(if_ctx_t ctx) hw_if->disable_tx(pdata); hw_if->disable_rx(pdata); - phy_if->phy_stop(pdata); - ret = hw_if->exit(pdata); if (ret) axgbe_error("%s: exit error %d\n", __func__, ret); diff --git a/sys/dev/axgbe/xgbe-mdio.c b/sys/dev/axgbe/xgbe-mdio.c index 592f08dec53..a5a9fdd016b 100644 --- a/sys/dev/axgbe/xgbe-mdio.c +++ b/sys/dev/axgbe/xgbe-mdio.c @@ -1439,7 +1439,10 @@ xgbe_phy_stop(struct xgbe_prv_data *pdata) static int xgbe_phy_start(struct xgbe_prv_data *pdata) { - int ret; + int ret = 0; + + if (pdata->phy_started) + return (ret); DBGPR("-->xgbe_phy_start\n"); @@ -1584,6 +1587,7 @@ xgbe_phy_init(struct xgbe_prv_data *pdata) pdata->phy.duplex = DUPLEX_FULL; } + pdata->phy_started = 0; pdata->phy.link = 0; pdata->phy.pause_autoneg = pdata->pause_autoneg; diff --git a/sys/dev/axgbe/xgbe-phy-v2.c b/sys/dev/axgbe/xgbe-phy-v2.c index 48c2e0bf095..5d21d6ef7f3 100644 --- a/sys/dev/axgbe/xgbe-phy-v2.c +++ b/sys/dev/axgbe/xgbe-phy-v2.c @@ -3178,6 +3178,11 @@ xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart) } if (phy_data->phydev || phy_data->port_mode != XGBE_PORT_MODE_SFP) { + if (pdata->axgbe_miibus == NULL) { + axgbe_printf(1, "%s: miibus not initialized", __func__); + goto mdio_read; + } + mii = device_get_softc(pdata->axgbe_miibus); mii_tick(mii); @@ -3202,6 +3207,8 @@ xgbe_phy_link_status(struct xgbe_prv_data *pdata, int *an_restart) xgbe_rrc(pdata); } +mdio_read: + /* Link status is latched low, so read once to clear * and then read again to get current state */