From nobody Wed Dec 08 08:34:49 2021 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 2D82118DBDEE; Wed, 8 Dec 2021 08:34:50 +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 4J89T55jbkz4cXN; Wed, 8 Dec 2021 08:34:49 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 A024B7EDC; Wed, 8 Dec 2021 08:34:49 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1B88YnmH097250; Wed, 8 Dec 2021 08:34:49 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B88Ynvj097249; Wed, 8 Dec 2021 08:34:49 GMT (envelope-from git) Date: Wed, 8 Dec 2021 08:34:49 GMT Message-Id: <202112080834.1B88Ynvj097249@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: cbac9a3613d8 - main - enetc: Serialize MDIO transactions 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: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cbac9a3613d811f91fe857e7744b10d01e889f25 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638952489; 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=HmYa7gbcZSdsottgtpC3aVI0fQapD7d4p9OGDC/YT08=; b=SacOHH4cwltHiucXFKXc0PcueDD0Dw25NWmROFlFF03fugzwyFBW2HS8LgIx3HA9yJS4xu 3nleLSswNg2ulHwOetjYxfwMkFKW/lTE/bDBCoMy1yHCdoImz86D0PyL7iuyhc7BYOULKq uI6OQRlaiNbbvY7STMeYPFsHkU2WB4u/eTLwtvUoqRyHchm1b8S0/Ns7wSPHQoaD4IKUfj /BswL4eN7/NFy3rLI2+sSydE04xhM+2BDgUo8G/ptnOeBRPnaYHuNzfoQRVS4lD8DamLWS 5Pia7/vHKIFIfoCDyccisRSN49y6ibbFjKp6KJD0DeidSVl63uNZ1BMq8WdLhw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638952489; a=rsa-sha256; cv=none; b=egpaErVJLd9fn//jQtwtp2nwl5+a9OcR6gyHaQ5Yt6tXX49ik52Hmo+8L0oNCsWTnREttW nPKzf/+3jIeAfB8kPJ9+b6ZdU8disgU6TEY5ohkmaADIXIcEPYqnOrDre98kfQgMG443yg 86tieNpCGeSiWVyoekm1y5OyUCMxxhpLoNFM8FmLfHTFnfdH+GXIQLd5CMACNKvpvskAKi nIvTPrnI5kPtNEq6Z7yYuof7rUjk+teLY00+dgMU0xYGwfuz2acgld0Cz2m2qm9U8z/c9a LvGKunx0IKDjDgGyj9CnkZ3RFiO/pL0KD9CLwBLJ6l8mSu9+eTmRWCKnVRvrFw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=cbac9a3613d811f91fe857e7744b10d01e889f25 commit cbac9a3613d811f91fe857e7744b10d01e889f25 Author: Kornel Duleba AuthorDate: 2021-11-29 11:57:24 +0000 Commit: Wojciech Macek CommitDate: 2021-12-08 08:32:51 +0000 enetc: Serialize MDIO transactions In theory we can have multiple concurrent accesses to the MDIO bus, e.g. link status check tick and ifconfig request. In that case we need to make sure that all MDIO transaction are serialized. Obtained from: Semihalf Sponsored by: Alstom Group --- sys/dev/enetc/enetc.h | 2 ++ sys/dev/enetc/if_enetc.c | 24 ++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/sys/dev/enetc/enetc.h b/sys/dev/enetc/enetc.h index d3064a48df76..57edc2b26f2c 100644 --- a/sys/dev/enetc/enetc.h +++ b/sys/dev/enetc/enetc.h @@ -70,6 +70,8 @@ struct enetc_ctrl_queue { struct enetc_softc { device_t dev; + struct mtx mii_lock; + if_ctx_t ctx; if_softc_ctx_t shared; #define tx_num_queues shared->isc_ntxqsets diff --git a/sys/dev/enetc/if_enetc.c b/sys/dev/enetc/if_enetc.c index e05e551ff48f..182b4f98b92a 100644 --- a/sys/dev/enetc/if_enetc.c +++ b/sys/dev/enetc/if_enetc.c @@ -376,6 +376,8 @@ enetc_attach_pre(if_ctx_t ctx) sc->shared = scctx; ifp = iflib_get_ifp(ctx); + mtx_init(&sc->mii_lock, "enetc_mdio", NULL, MTX_DEF); + pci_save_state(sc->dev); pcie_flr(sc->dev, 1000, false); pci_restore_state(sc->dev); @@ -471,6 +473,8 @@ enetc_detach(if_ctx_t ctx) if (sc->ctrl_queue.dma.idi_size != 0) iflib_dma_free(&sc->ctrl_queue.dma); + mtx_destroy(&sc->mii_lock); + return (error); } @@ -1390,20 +1394,32 @@ static int enetc_miibus_readreg(device_t dev, int phy, int reg) { struct enetc_softc *sc; + int val; sc = iflib_get_softc(device_get_softc(dev)); - return (enetc_mdio_read(sc->regs, ENETC_PORT_BASE + ENETC_EMDIO_BASE, - phy, reg)); + + mtx_lock(&sc->mii_lock); + val = enetc_mdio_read(sc->regs, ENETC_PORT_BASE + ENETC_EMDIO_BASE, + phy, reg); + mtx_unlock(&sc->mii_lock); + + return (val); } static int enetc_miibus_writereg(device_t dev, int phy, int reg, int data) { struct enetc_softc *sc; + int ret; sc = iflib_get_softc(device_get_softc(dev)); - return (enetc_mdio_write(sc->regs, ENETC_PORT_BASE + ENETC_EMDIO_BASE, - phy, reg, data)); + + mtx_lock(&sc->mii_lock); + ret = enetc_mdio_write(sc->regs, ENETC_PORT_BASE + ENETC_EMDIO_BASE, + phy, reg, data); + mtx_unlock(&sc->mii_lock); + + return (ret); } static void