From nobody Thu Jul 07 16:44:54 2022 X-Original-To: dev-commits-src-main@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 3A8CD12DA649; Thu, 7 Jul 2022 16:44:55 +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 4Lf2MC1BD4z3XhB; Thu, 7 Jul 2022 16:44:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657212295; 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=3fL9N1vCya2j2a1Wb9+B9v+Fbhy8IA8XYBiPpDRLCkQ=; b=JjwTWGI6JmbtwYTvMxuJTdpG/A5QAt2P1S0/mECCgVrJUAgivHDgPIKqw5TvBjy9P0+lUY f6iyYMDuidJjYyPp6UCcl+zoOhjI7pRwx9CvsOAjdIRPLsBESz69CxCe4EvPUnMmxzwFlS c9ZNGetrZMDWcFzgz9a9xwaabnF/6dBPEHmnMdnCVnsxTsEaYzN48j0hshGy6vaXk/bw4l Pxdto9MtgBW3ZFt3DVl+0+wkO1GZhFLbDxOpSjIaIenDuCk1f4vHJ01E5vWQwayljfQgU0 ZzRPDoMiUJ0P3FG6YiRS62A1ayD6hZvPLm82Pjk1Nkx6xIWsn2B+BOv+6d/OAw== 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 4Lf2MC076wzpwY; Thu, 7 Jul 2022 16:44:55 +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 267GisAE015626; Thu, 7 Jul 2022 16:44:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 267Gis3c015625; Thu, 7 Jul 2022 16:44:54 GMT (envelope-from git) Date: Thu, 7 Jul 2022 16:44:54 GMT Message-Id: <202207071644.267Gis3c015625@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Marcin Wojtas Subject: git: 469290648005 - main - e6000sw: add readphy and writephy wrappers List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mw X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 469290648005e13b819a19353032ca53dda4378f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657212295; 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=3fL9N1vCya2j2a1Wb9+B9v+Fbhy8IA8XYBiPpDRLCkQ=; b=ZU5EPRck/C5YJ0Md8sSdctEdcoKoPbhlIW4Sh35Ce3+oeYF92UvbGZTtIrzhjlq7R0hzWD o4hBg6bsBE418Rtu28EVX3SOUlA/jEvdNfREGoFeqBNxywL1Y6SgdKFYgybTJFeigxzycU Ns5zy5pix1gMNIQFm56PNdw2VaBwG5rzvbRPomM/zIyBBXR/QoGmAZUjONNDH4ogudDCqt 6cMw7yeZXf/CxMaDc/eK2NLQmRSgEZu0LsaBqWg1gR+A2C2rtbWh+h5PT6yK9tn2IVOLxZ nle+l94qvIBUjsDJHaWeyPktqGCL9HHbG6xptr3J2ZHhWSS3JpqfC1NfribNGA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657212295; a=rsa-sha256; cv=none; b=UZ1DN1F6UgJ6N11DkYTQKqq3YT0k3ojTTtk6wqIj43hYVd826m8gUXODKRZ30G8X/3Djes Tjf6w2SaWgh3Wku6RzhCrfsl2SqtY+b9uJG18gpF61HyZ2IacGXKJ4HKxW2wHGmkCAJSqE xFh0VardBnPzGxlCrN9SIvS0YhRZ4OUh9hm+jrB9tBHj05QojgIOZMu6pDrvlQjsuM0OG7 RT+rvn7Qtcc3D2l9qmhFFnVAOpfhGn+ULoM7FpQj8x5ZSUXBsr60FE9Fxsn7Uc6IruadYH +xPy08GQXxGZytTif8th/P5HhPHRLbAq3CmZbGzFBX6ZVhSyJ6utJDVytWUl/w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mw: URL: https://cgit.FreeBSD.org/src/commit/?id=469290648005e13b819a19353032ca53dda4378f commit 469290648005e13b819a19353032ca53dda4378f Author: Albert Jakiela AuthorDate: 2022-07-06 14:40:20 +0000 Commit: Marcin Wojtas CommitDate: 2022-07-07 16:25:00 +0000 e6000sw: add readphy and writephy wrappers New functions take lock and give lock after operation. Removed locking and unlocking within other methods, to prevent from recursive locking on non recursive lock. Tested on EspressoBin. Reviewed by: mw Obtained from: Semihalf Differential Revision: https://reviews.freebsd.org/D35656 --- sys/dev/etherswitch/e6000sw/e6000sw.c | 53 ++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/sys/dev/etherswitch/e6000sw/e6000sw.c b/sys/dev/etherswitch/e6000sw/e6000sw.c index 7374fe2d74e5..d096c31b349a 100644 --- a/sys/dev/etherswitch/e6000sw/e6000sw.c +++ b/sys/dev/etherswitch/e6000sw/e6000sw.c @@ -112,6 +112,8 @@ static int e6000sw_read_xmdio(device_t, int, int, int); static int e6000sw_write_xmdio(device_t, int, int, int, int); static int e6000sw_readphy(device_t, int, int); static int e6000sw_writephy(device_t, int, int, int); +static int e6000sw_readphy_locked(device_t, int, int); +static int e6000sw_writephy_locked(device_t, int, int, int); static etherswitch_info_t* e6000sw_getinfo(device_t); static int e6000sw_getconf(device_t, etherswitch_conf_t *); static int e6000sw_setconf(device_t, etherswitch_conf_t *); @@ -159,8 +161,8 @@ static device_method_t e6000sw_methods[] = { DEVMETHOD(bus_add_child, device_add_child_ordered), /* mii interface */ - DEVMETHOD(miibus_readreg, e6000sw_readphy), - DEVMETHOD(miibus_writereg, e6000sw_writephy), + DEVMETHOD(miibus_readreg, e6000sw_readphy_locked), + DEVMETHOD(miibus_writereg, e6000sw_writephy_locked), /* etherswitch interface */ DEVMETHOD(etherswitch_getinfo, e6000sw_getinfo), @@ -654,29 +656,41 @@ e6000sw_write_xmdio(device_t dev, int phy, int devaddr, int devreg, int val) return (0); } +static int e6000sw_readphy(device_t dev, int phy, int reg) +{ + e6000sw_softc_t *sc; + int ret; + + sc = device_get_softc(dev); + E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); + + E6000SW_LOCK(sc); + ret = e6000sw_readphy_locked(dev, phy, reg); + E6000SW_UNLOCK(sc); + + return (ret); +} + /* * PHY registers are paged. Put page index in reg 22 (accessible from every * page), then access specific register. */ static int -e6000sw_readphy(device_t dev, int phy, int reg) +e6000sw_readphy_locked(device_t dev, int phy, int reg) { e6000sw_softc_t *sc; uint32_t val; sc = device_get_softc(dev); - E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); + E6000SW_LOCK_ASSERT(sc, SA_XLOCKED); if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) { device_printf(dev, "Wrong register address.\n"); return (EINVAL); } - E6000SW_LOCK(sc); - if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) { device_printf(dev, "Timeout while waiting for switch\n"); - E6000SW_UNLOCK(sc); return (ETIMEDOUT); } @@ -685,35 +699,44 @@ e6000sw_readphy(device_t dev, int phy, int reg) ((phy << SMI_CMD_DEV_ADDR) & SMI_CMD_DEV_ADDR_MASK)); if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) { device_printf(dev, "Timeout while waiting for switch\n"); - E6000SW_UNLOCK(sc); return (ETIMEDOUT); } val = e6000sw_readreg(sc, REG_GLOBAL2, SMI_PHY_DATA_REG); + return (val & PHY_DATA_MASK); +} + +static int e6000sw_writephy(device_t dev, int phy, int reg, int data) +{ + e6000sw_softc_t *sc; + int ret; + + sc = device_get_softc(dev); + E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); + + E6000SW_LOCK(sc); + ret = e6000sw_writephy_locked(dev, phy, reg, data); E6000SW_UNLOCK(sc); - return (val & PHY_DATA_MASK); + return (ret); } static int -e6000sw_writephy(device_t dev, int phy, int reg, int data) +e6000sw_writephy_locked(device_t dev, int phy, int reg, int data) { e6000sw_softc_t *sc; sc = device_get_softc(dev); - E6000SW_LOCK_ASSERT(sc, SA_UNLOCKED); + E6000SW_LOCK_ASSERT(sc, SA_XLOCKED); if (!e6000sw_is_phyport(sc, phy) || reg >= E6000SW_NUM_PHY_REGS) { device_printf(dev, "Wrong register address.\n"); return (EINVAL); } - E6000SW_LOCK(sc); - if (E6000SW_WAITREADY2(sc, SMI_PHY_CMD_REG, SMI_CMD_BUSY)) { device_printf(dev, "Timeout while waiting for switch\n"); - E6000SW_UNLOCK(sc); return (ETIMEDOUT); } @@ -723,8 +746,6 @@ e6000sw_writephy(device_t dev, int phy, int reg, int data) SMI_CMD_OP_C22_WRITE | (reg & SMI_CMD_REG_ADDR_MASK) | ((phy << SMI_CMD_DEV_ADDR) & SMI_CMD_DEV_ADDR_MASK)); - E6000SW_UNLOCK(sc); - return (0); }