From nobody Thu Nov 30 00:38:06 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Sgcjq1cw0z52Tyb; Thu, 30 Nov 2023 00:38:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Sgcjq0Z3nz3M5M; Thu, 30 Nov 2023 00:38:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701304687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bqUZA8g8uBL6S5dl7nyds1PhPJtxJzGcoo5v3fvBN3U=; b=pNpABGh6VeRMXH+GAK+4N5bT3p1NejPgnAWPUhTSEzmfCiBEk9hBx7pRLoxJZq3+hJ0Nb3 bHYJJZQv2mzTfLkLhzJSv7KYLV+XIGt4822C1GyNXMt7iN6mmmwqAZyLQUv4yQs2zmXmkN lLkGZN/OqyRwcSrwR7WLMlEODVlnoZ2bOhILtl22Wc8Q/2N/sMLxtRXMU7WHITcTCHM9Om Ex6rnCEMatcjvHAd0lM1ObNoEJxGvJcQod1P/YK1K7TwppHO5sNbuh9i+iZ0tz6lQu0FYK uEFLzbozPa7PsaQ9XQW0FlAs9MNHSZFhFrGVUdTLOgExiRdMND9yZGXDz28tpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1701304687; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=bqUZA8g8uBL6S5dl7nyds1PhPJtxJzGcoo5v3fvBN3U=; b=hg5pm+ZWpM/M3J/ychb7qKyemlRsHMJr9K2SeEwAT0sp96EZgfkQRssR7M/w+ffw8kTprh /UgsV4BZeniTVigcG8sf7GwCmcfMHCA2I1EJsVGw1YJErX3xemKr537nKDf2fw6vsj9uBQ 6p22z1QKkR7/y6j0y8gpwWRmZ5r1naH3fcHFvGD8z80bwMqd4L/FFJWkihvU3sOhkExWO/ sFD7piQrQljTNWUGzIcf/PTkQRUuXOsBanKE/bQujTCH1JU85wx8+I08TdUfIUvhOGDuuj towgINTrPNNNWTFv4JDhzkubjfNWJ34wcffyukF70PbKd2rPL3cO3KaANUS9qQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1701304687; a=rsa-sha256; cv=none; b=L4CZchdP5rqM32o+lNXZzR9HYqsCM5xcRwIB4wPvLZWdMH+WULT2Ui1/waoCw/kkktgmDg P1+N9QJb5qtPftS2K6w027eDMwok70SlBQGjpJskavCID8jbN+S9GD9qGNmugpQKUsxIpF mRsHDbjt/u0dLeN9KuuD5uYVDZW+1fafhlUXhoPXXV24Co21o3IxNjBlZCN+CCk4WO/pL2 gr7xwQuxmB8REmILeyRMSysi7WzG7X6qzY8a8r959JLLSHtFVlcVdSFshF5+NZbXM4m5Ec m7PoXiLlQdaewtABaPBRR9eV2zhlhuUjcDD8NGBgd1qCUUc34Ev2tUC7t/ZF4A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Sgcjp6TFtzDCN; Thu, 30 Nov 2023 00:38:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3AU0c6QE051546; Thu, 30 Nov 2023 00:38:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AU0c63H051543; Thu, 30 Nov 2023 00:38:06 GMT (envelope-from git) Date: Thu, 30 Nov 2023 00:38:06 GMT Message-Id: <202311300038.3AU0c63H051543@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 91987a959730 - stable/14 - dpaa2: defer link_state updates until we are up List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 91987a959730e051086b6d1ba55b0fa76c2695ef Auto-Submitted: auto-generated The branch stable/14 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=91987a959730e051086b6d1ba55b0fa76c2695ef commit 91987a959730e051086b6d1ba55b0fa76c2695ef Author: Bjoern A. Zeeb AuthorDate: 2023-11-17 00:47:11 +0000 Commit: Bjoern A. Zeeb CommitDate: 2023-11-30 00:36:56 +0000 dpaa2: defer link_state updates until we are up dpaa2_ni_media_change() was called in early setup stages, before we were fully setup. That lead to internal driver state being all synched and fine but hardware state was lost/never setup corrently. Introduce dpaa2_ni_media_change_locked() so we can avoid reccursive locking and call "dpaa2_ni_media_change()" instead of mii_mediachg() as the latter does not setup our state there either. In order for this all to work, call if_setdrvflagbits() just before rather than after the above. Also remove an unecessary direct call to dpaa2_ni_miibus_statchg() which mii_mediachg() will trigger anyway. This all fixes a problem [1] that one had to lose the link (either unplugging/replugging the cable or using ifconfig media none; ifconfig media auto) to re-trigger the all updates and get the full state programmed when hardware expected. GH-Issue: https://github.com/mcusim/freebsd-src/issues/21 [1] Reviewed by: dsl, dch Differential Revision: https://reviews.freebsd.org/D42643 (cherry picked from commit 964b3408fa872178aacf58f2d84dc43564ec0aa7) --- sys/dev/dpaa2/dpaa2_ni.c | 46 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/sys/dev/dpaa2/dpaa2_ni.c b/sys/dev/dpaa2/dpaa2_ni.c index 7cb472f45ee4..c1543ec20881 100644 --- a/sys/dev/dpaa2/dpaa2_ni.c +++ b/sys/dev/dpaa2/dpaa2_ni.c @@ -116,6 +116,9 @@ mtx_assert(&(__sc)->lock, MA_OWNED); \ mtx_unlock(&(__sc)->lock); \ } while (0) +#define DPNI_LOCK_ASSERT(__sc) do { \ + mtx_assert(&(__sc)->lock, MA_OWNED); \ +} while (0) #define DPAA2_TX_RING(sc, chan, tc) \ (&(sc)->channels[(chan)]->txc_queue.tx_rings[(tc)]) @@ -2269,6 +2272,16 @@ dpaa2_ni_miibus_statchg(device_t dev) if (sc->fixed_link || sc->mii == NULL) { return; } + if ((if_getdrvflags(sc->ifp) & IFF_DRV_RUNNING) == 0) { + /* + * We will receive calls and adjust the changes but + * not have setup everything (called before dpaa2_ni_init() + * really). This will then setup the link and internal + * sc->link_state and not trigger the update once needed, + * so basically dpmac never knows about it. + */ + return; + } /* * Note: ifp link state will only be changed AFTER we are called so we @@ -2344,23 +2357,33 @@ err_exit: * @brief Callback function to process media change request. */ static int -dpaa2_ni_media_change(if_t ifp) +dpaa2_ni_media_change_locked(struct dpaa2_ni_softc *sc) { - struct dpaa2_ni_softc *sc = if_getsoftc(ifp); - DPNI_LOCK(sc); + DPNI_LOCK_ASSERT(sc); if (sc->mii) { mii_mediachg(sc->mii); sc->media_status = sc->mii->mii_media.ifm_media; } else if (sc->fixed_link) { - if_printf(ifp, "%s: can't change media in fixed mode\n", + if_printf(sc->ifp, "%s: can't change media in fixed mode\n", __func__); } - DPNI_UNLOCK(sc); return (0); } +static int +dpaa2_ni_media_change(if_t ifp) +{ + struct dpaa2_ni_softc *sc = if_getsoftc(ifp); + int error; + + DPNI_LOCK(sc); + error = dpaa2_ni_media_change_locked(sc); + DPNI_UNLOCK(sc); + return (error); +} + /** * @brief Callback function to process media status request. */ @@ -2443,17 +2466,20 @@ dpaa2_ni_init(void *arg) } DPNI_LOCK(sc); + /* Announce we are up and running and can queue packets. */ + if_setdrvflagbits(ifp, IFF_DRV_RUNNING, IFF_DRV_OACTIVE); + if (sc->mii) { - mii_mediachg(sc->mii); + /* + * mii_mediachg() will trigger a call into + * dpaa2_ni_miibus_statchg() to setup link state. + */ + dpaa2_ni_media_change_locked(sc); } callout_reset(&sc->mii_callout, hz, dpaa2_ni_media_tick, sc); - if_setdrvflagbits(ifp, IFF_DRV_RUNNING, IFF_DRV_OACTIVE); DPNI_UNLOCK(sc); - /* Force link-state update to initilize things. */ - dpaa2_ni_miibus_statchg(dev); - (void)DPAA2_CMD_NI_CLOSE(dev, child, DPAA2_CMD_TK(&cmd, ni_token)); (void)DPAA2_CMD_RC_CLOSE(dev, child, DPAA2_CMD_TK(&cmd, rc_token)); return;