From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44247C53210 for ; Tue, 27 Dec 2022 23:08:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232540AbiL0XIS (ORCPT ); Tue, 27 Dec 2022 18:08:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232176AbiL0XHo (ORCPT ); Tue, 27 Dec 2022 18:07:44 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A229E03D; Tue, 27 Dec 2022 15:07:27 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 9E35F168F; Wed, 28 Dec 2022 00:07:25 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZcKmEvWBu/sPAlrpc3OKARVAht4Rj3HvMDK82/MupfY=; b=IKeJ0RNYWS3nnlxaCQbNCpq8E7bei/+8AyyFZvxPM/kv5e3ry1VssNYvSczFmBKViNXhgs EUN2pUf74WXpz2tgfU3RB/YK4zQOgmIMK5UWgrQdpWy+8savYKWTxvi6nPjlGi8VTH5dWw y3p4jEGzEgzUCKvfS6iZQ0iEYJ+4wn4lcVQag1Q6Af3ax24+ZhFkJzqqZ8Jt50crFtZtoY 5U6ygbDXidm5nNHB0mGtl4VWmg9G6D0DSdjKgf9lEjicKzy8Fyhc28K7ypyuAJEppdeZUg clvl4Cnxb//ZoWOFGnKFArCxEg/fRi93StFYsjq0Casfn+A/DvuglEcgwbEOdQ== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:17 +0100 Subject: [PATCH RFC net-next v2 01/12] net: mdio: Add dedicated C45 API to MDIO bus drivers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-1-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn Currently C22 and C45 transactions are mixed over a combined API calls which make use of a special bit in the reg address to indicate if a C45 transaction should be performed. This makes it impossible to know if the bus driver actually supports C45. Additionally, many C22 only drivers don't return -EOPNOTSUPP when asked to perform a C45 transaction, they mistaking perform a C22 transaction. This is the first step to cleanly separate C22 from C45. To maintain backwards compatibility until all drivers which are capable of performing C45 are converted to this new API, the helper functions will fall back to the older API if the new API is not supported. Eventually this fallback will be removed. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- drivers/net/phy/mdio_bus.c | 189 +++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/mdio.h | 39 +++++----- include/linux/phy.h | 5 ++ 3 files changed, 214 insertions(+), 19 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 1cd604cd1fa1..bde195864c17 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -826,6 +826,100 @@ int __mdiobus_modify_changed(struct mii_bus *bus, int= addr, u32 regnum, } EXPORT_SYMBOL_GPL(__mdiobus_modify_changed); =20 +/** + * __mdiobus_c45_read - Unlocked version of the mdiobus_c45_read function + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to read + * + * Read a MDIO bus register. Caller must hold the mdio bus lock. + * + * NOTE: MUST NOT be called from interrupt context. + */ +int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnu= m) +{ + int retval; + + lockdep_assert_held_once(&bus->mdio_lock); + + if (bus->read_c45) + retval =3D bus->read_c45(bus, addr, devad, regnum); + else + retval =3D bus->read(bus, addr, mdiobus_c45_addr(devad, regnum)); + + trace_mdio_access(bus, 1, addr, regnum, retval, retval); + mdiobus_stats_acct(&bus->stats[addr], true, retval); + + return retval; +} +EXPORT_SYMBOL(__mdiobus_c45_read); + +/** + * __mdiobus_c45_write - Unlocked version of the mdiobus_write function + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to write + * @val: value to write to @regnum + * + * Write a MDIO bus register. Caller must hold the mdio bus lock. + * + * NOTE: MUST NOT be called from interrupt context. + */ +int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regn= um, + u16 val) +{ + int err; + + lockdep_assert_held_once(&bus->mdio_lock); + + if (bus->write_c45) + err =3D bus->write_c45(bus, addr, devad, regnum, val); + else + err =3D bus->write(bus, addr, mdiobus_c45_addr(devad, regnum), + val); + + trace_mdio_access(bus, 0, addr, regnum, val, err); + mdiobus_stats_acct(&bus->stats[addr], false, err); + + return err; +} +EXPORT_SYMBOL(__mdiobus_c45_write); + +/** + * __mdiobus_c45_modify_changed - Unlocked version of the mdiobus_modify f= unction + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to modify + * @mask: bit mask of bits to clear + * @set: bit mask of bits to set + * + * Read, modify, and if any change, write the register value back to the + * device. Any error returns a negative number. + * + * NOTE: MUST NOT be called from interrupt context. + */ +static int __mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, + int devad, u32 regnum, u16 mask, + u16 set) +{ + int new, ret; + + ret =3D __mdiobus_c45_read(bus, addr, devad, regnum); + if (ret < 0) + return ret; + + new =3D (ret & ~mask) | set; + if (new =3D=3D ret) + return 0; + + ret =3D __mdiobus_c45_write(bus, addr, devad, regnum, new); + + return ret < 0 ? ret : 1; +} + /** * mdiobus_read_nested - Nested version of the mdiobus_read function * @bus: the mii_bus struct @@ -873,6 +967,29 @@ int mdiobus_read(struct mii_bus *bus, int addr, u32 re= gnum) } EXPORT_SYMBOL(mdiobus_read); =20 +/** + * mdiobus_c45_read - Convenience function for reading a given MII mgmt re= gister + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to read + * + * NOTE: MUST NOT be called from interrupt context, + * because the bus read/write functions may wait for an interrupt + * to conclude the operation. + */ +int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum) +{ + int retval; + + mutex_lock(&bus->mdio_lock); + retval =3D __mdiobus_c45_read(bus, addr, devad, regnum); + mutex_unlock(&bus->mdio_lock); + + return retval; +} +EXPORT_SYMBOL(mdiobus_c45_read); + /** * mdiobus_write_nested - Nested version of the mdiobus_write function * @bus: the mii_bus struct @@ -922,6 +1039,31 @@ int mdiobus_write(struct mii_bus *bus, int addr, u32 = regnum, u16 val) } EXPORT_SYMBOL(mdiobus_write); =20 +/** + * mdiobus_c45_write - Convenience function for writing a given MII mgmt r= egister + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to write + * @val: value to write to @regnum + * + * NOTE: MUST NOT be called from interrupt context, + * because the bus read/write functions may wait for an interrupt + * to conclude the operation. + */ +int mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnum, + u16 val) +{ + int err; + + mutex_lock(&bus->mdio_lock); + err =3D __mdiobus_c45_write(bus, addr, devad, regnum, val); + mutex_unlock(&bus->mdio_lock); + + return err; +} +EXPORT_SYMBOL(mdiobus_c45_write); + /** * mdiobus_modify - Convenience function for modifying a given mdio device * register @@ -943,6 +1085,30 @@ int mdiobus_modify(struct mii_bus *bus, int addr, u32= regnum, u16 mask, u16 set) } EXPORT_SYMBOL_GPL(mdiobus_modify); =20 +/** + * mdiobus_c45_modify - Convenience function for modifying a given mdio de= vice + * register + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to write + * @mask: bit mask of bits to clear + * @set: bit mask of bits to set + */ +int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnu= m, + u16 mask, u16 set) +{ + int err; + + mutex_lock(&bus->mdio_lock); + err =3D __mdiobus_c45_modify_changed(bus, addr, devad, regnum, + mask, set); + mutex_unlock(&bus->mdio_lock); + + return err < 0 ? err : 0; +} +EXPORT_SYMBOL_GPL(mdiobus_c45_modify); + /** * mdiobus_modify_changed - Convenience function for modifying a given mdio * device register and returning if it changed @@ -965,6 +1131,29 @@ int mdiobus_modify_changed(struct mii_bus *bus, int a= ddr, u32 regnum, } EXPORT_SYMBOL_GPL(mdiobus_modify_changed); =20 +/** + * mdiobus_c45_modify_changed - Convenience function for modifying a given= mdio + * device register and returning if it changed + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to write + * @mask: bit mask of bits to clear + * @set: bit mask of bits to set + */ +int mdiobus_c45_modify_changed(struct mii_bus *bus, int devad, int addr, + u32 regnum, u16 mask, u16 set) +{ + int err; + + mutex_lock(&bus->mdio_lock); + err =3D __mdiobus_c45_modify_changed(bus, addr, devad, regnum, mask, set); + mutex_unlock(&bus->mdio_lock); + + return err; +} +EXPORT_SYMBOL_GPL(mdiobus_c45_modify_changed); + /** * mdio_bus_match - determine if given MDIO driver supports the given * MDIO device diff --git a/include/linux/mdio.h b/include/linux/mdio.h index f7fbbf3069e7..1e78c8410b21 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -423,6 +423,17 @@ int mdiobus_modify(struct mii_bus *bus, int addr, u32 = regnum, u16 mask, u16 set); int mdiobus_modify_changed(struct mii_bus *bus, int addr, u32 regnum, u16 mask, u16 set); +int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnu= m); +int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum); +int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 reg= num, + u16 val); +int mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnu= m, + u16 val); +int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnu= m, + u16 mask, u16 set); + +int mdiobus_c45_modify_changed(struct mii_bus *bus, int addr, int devad, + u32 regnum, u16 mask, u16 set); =20 static inline int mdiodev_read(struct mdio_device *mdiodev, u32 regnum) { @@ -463,29 +474,19 @@ static inline u16 mdiobus_c45_devad(u32 regnum) return FIELD_GET(MII_DEVADDR_C45_MASK, regnum); } =20 -static inline int __mdiobus_c45_read(struct mii_bus *bus, int prtad, int d= evad, - u16 regnum) +static inline int mdiodev_c45_modify(struct mdio_device *mdiodev, int deva= d, + u32 regnum, u16 mask, u16 set) { - return __mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum)); + return mdiobus_c45_modify(mdiodev->bus, mdiodev->addr, devad, regnum, + mask, set); } =20 -static inline int __mdiobus_c45_write(struct mii_bus *bus, int prtad, int = devad, - u16 regnum, u16 val) +static inline int mdiodev_c45_modify_changed(struct mdio_device *mdiodev, + int devad, u32 regnum, u16 mask, + u16 set) { - return __mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum), - val); -} - -static inline int mdiobus_c45_read(struct mii_bus *bus, int prtad, int dev= ad, - u16 regnum) -{ - return mdiobus_read(bus, prtad, mdiobus_c45_addr(devad, regnum)); -} - -static inline int mdiobus_c45_write(struct mii_bus *bus, int prtad, int de= vad, - u16 regnum, u16 val) -{ - return mdiobus_write(bus, prtad, mdiobus_c45_addr(devad, regnum), val); + return mdiobus_c45_modify_changed(mdiodev->bus, mdiodev->addr, devad, + regnum, mask, set); } =20 static inline int mdiodev_c45_read(struct mdio_device *mdiodev, int devad, diff --git a/include/linux/phy.h b/include/linux/phy.h index 71eeb4e3b1fd..c33ad3255e3a 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -364,6 +364,11 @@ struct mii_bus { int (*read)(struct mii_bus *bus, int addr, int regnum); /** @write: Perform a write transfer on the bus */ int (*write)(struct mii_bus *bus, int addr, int regnum, u16 val); + /** @read: Perform a C45 read transfer on the bus */ + int (*read_c45)(struct mii_bus *bus, int addr, int devnum, int regnum); + /** @write: Perform a C45 write transfer on the bus */ + int (*write_c45)(struct mii_bus *bus, int addr, int devnum, + int regnum, u16 val); /** @reset: Perform a reset of the bus */ int (*reset)(struct mii_bus *bus); =20 --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AA3A8C4708D for ; Tue, 27 Dec 2022 23:08:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232026AbiL0XIH (ORCPT ); Tue, 27 Dec 2022 18:08:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232165AbiL0XHn (ORCPT ); Tue, 27 Dec 2022 18:07:43 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C22F8FC1; Tue, 27 Dec 2022 15:07:28 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 0BF7A1691; Wed, 28 Dec 2022 00:07:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2bhgExHn/ar4TfzsxVA1DWmb/VXmvJMEz1zy1qxzkSM=; b=0BRwE3+CnQZBCkueooc1hgIlxrIo0V225AOr2XwrlQzWPJ8ugeR1BDPDeamA7dPiMF3K0L /X/SEQZVotNLcfcLXxD1873LIdC8taHCSWHIMC9YVTfIX5Au7z9DL3sBb1cDeTF2Thcc8M B3SV0iGKSP1k6BI8a6CExi7RIQd1FG5nCKzmcuFPl4PPV7ByXGS+uxrwK5bDgV4RjZNHuT 7RTutdIP9lS65jHnOHgKOLG+AXCjTl33MypfVk5RqDVfFPu2kPRF88yPMC197dzrpcyuUY F/JvMQfaw1Yr77z2UPiPI6otSBkWBFJujTj7u/s3/ZDIwLsZ+yJa/CSAO26xxw== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:18 +0100 Subject: [PATCH RFC net-next v2 02/12] net: pcs: pcs-xpcs: Use C45 MDIO API MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-2-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn Convert the PCS-XPCS driver to make use of the C45 MDIO bus API for modify_change(). Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle Reviewed-by: Vladimir Oltean --- v2: - [al] new patch --- drivers/net/pcs/pcs-xpcs.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index f6a038a1d51e..bc428a816719 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -199,9 +199,7 @@ int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, = u16 val) static int xpcs_modify_changed(struct dw_xpcs *xpcs, int dev, u32 reg, u16 mask, u16 set) { - u32 reg_addr =3D mdiobus_c45_addr(dev, reg); - - return mdiodev_modify_changed(xpcs->mdiodev, reg_addr, mask, set); + return mdiodev_c45_modify_changed(xpcs->mdiodev, dev, reg, mask, set); } =20 static int xpcs_read_vendor(struct dw_xpcs *xpcs, int dev, u32 reg) --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F106AC4332F for ; Tue, 27 Dec 2022 23:08:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232373AbiL0XIW (ORCPT ); Tue, 27 Dec 2022 18:08:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbiL0XHo (ORCPT ); Tue, 27 Dec 2022 18:07:44 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C1CD62E5; Tue, 27 Dec 2022 15:07:28 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 696AF169D; Wed, 28 Dec 2022 00:07:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182446; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PEAs1cY2KUGfDWF8DZJhmKi3UDdwVzcJA87E/SYrVOE=; b=mtu1oTBaxSngOLJAMfQndS7QsiKJFcYMtxVy/Vf3h9ET6EQmvAN9NTeV9uvL5debjMGv8c LcP9XcxB/6EcWrvVwEhOs9ijS22CCQyFKGLbEKSgik0owwnYgfVXqpgTUA4HZdtpVBb7H7 v5nMCDpoHXlCUPKZMpempFS4ykEFxhFYFjmWHHfx+B9dRgwXBFJ+P0LejAaVmG2heL4liv fr8HpYAfgXekauNSI26OaansaGepJ1NLKTntcG+CMYfhX/NO6+O1wJSB3YAStScb1omZul AroLnuQwESfFBDCwasVEMZ1ti4zIFGEkGXYR6zxfC5emKzgU47zvhRYYyJJ+mQ== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:19 +0100 Subject: [PATCH RFC net-next v2 03/12] net: mdio: mdiobus_register: update validation test MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-3-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn Now that C45 uses its own read/write methods, the validation performed when a bus is registers needs updating. All combinations of C22 and C45 are supported, but both read and write methods must be provided, read only busses are not supported etc. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- v2: - [al] be consistent with other checks - [mw] make the test a bit easier to read --- drivers/net/phy/mdio_bus.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index bde195864c17..d14d7704e895 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -526,8 +526,18 @@ int __mdiobus_register(struct mii_bus *bus, struct mod= ule *owner) int i, err; struct gpio_desc *gpiod; =20 - if (NULL =3D=3D bus || NULL =3D=3D bus->name || - NULL =3D=3D bus->read || NULL =3D=3D bus->write) + if (!bus || !bus->name) + return -EINVAL; + + /* An access method always needs both read and write operations */ + if ((bus->read && !bus->write) || + (!bus->read && bus->write) || + (bus->read_c45 && !bus->write_c45) || + (!bus->read_c45 && bus->write_c45)) + return -EINVAL; + + /* At least one method is mandatory */ + if (!bus->read && !bus->read_c45) return -EINVAL; =20 if (bus->parent && bus->parent->of_node) --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CBB5C46467 for ; Tue, 27 Dec 2022 23:08:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229488AbiL0XI2 (ORCPT ); Tue, 27 Dec 2022 18:08:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232183AbiL0XHp (ORCPT ); Tue, 27 Dec 2022 18:07:45 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0F3063E7; Tue, 27 Dec 2022 15:07:28 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 0AD3516DC; Wed, 28 Dec 2022 00:07:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q+FQH7xKg3mu7py/TKhsNiqXLlNql6R3XEpSBYuofsU=; b=K9x/Tqb5P1nRpEongrUKmS2tFJkrt6WI0YbaSK1bz3NUJ4GNh7M1ZUAbjLrvZ7n187EBM+ xCtBIsPzLPn/fn/9WpgcwKEE/L9sqzy2+1Y7AmCU+R1j3AINHElvHam2GtAW9ewKWWgl1s 10r06HbkFOGtjubpeTsptw03a2i7f1n7UMmIluykbzQC6pag2sOznEsJva9QQv3Dr72z8f FJQF+bbcqkApXokAI61LjbxTBOCbjKwsP4wQiA7bm5YPb1nNfEf6ru7UjjI172Ie/H0tmF Kax7544yq9brnJLLt5ASPsgCptbMLbcpKK2gAW3a989X27X3CTSe/+BGMlk0Pg== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:20 +0100 Subject: [PATCH RFC net-next v2 04/12] net: mdio: C22 is now optional, EOPNOTSUPP if not provided MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-4-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn When performing a C22 operation, check that the bus driver actually provides the methods, and return -EOPNOTSUPP if not. C45 only busses do exist, and in future their C22 methods will be NULL. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- drivers/net/phy/mdio_bus.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index d14d7704e895..20ba38a346fe 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -769,7 +769,10 @@ int __mdiobus_read(struct mii_bus *bus, int addr, u32 = regnum) =20 lockdep_assert_held_once(&bus->mdio_lock); =20 - retval =3D bus->read(bus, addr, regnum); + if (bus->read) + retval =3D bus->read(bus, addr, regnum); + else + retval =3D -EOPNOTSUPP; =20 trace_mdio_access(bus, 1, addr, regnum, retval, retval); mdiobus_stats_acct(&bus->stats[addr], true, retval); @@ -795,7 +798,10 @@ int __mdiobus_write(struct mii_bus *bus, int addr, u32= regnum, u16 val) =20 lockdep_assert_held_once(&bus->mdio_lock); =20 - err =3D bus->write(bus, addr, regnum, val); + if (bus->write) + err =3D bus->write(bus, addr, regnum, val); + else + err =3D -EOPNOTSUPP; =20 trace_mdio_access(bus, 0, addr, regnum, val, err); mdiobus_stats_acct(&bus->stats[addr], false, err); --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E40DCC4332F for ; Tue, 27 Dec 2022 23:08:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232601AbiL0XIc (ORCPT ); Tue, 27 Dec 2022 18:08:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232208AbiL0XHp (ORCPT ); Tue, 27 Dec 2022 18:07:45 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A856455; Tue, 27 Dec 2022 15:07:30 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 6A0FF16DE; Wed, 28 Dec 2022 00:07:27 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RO0MXmSJzEk+1zx4vJ29wns0CosdyJgZJOJENWjajGc=; b=cYkMqjBQ7dPYmAfVqvYhpwUUd8PAVCQxNAv44EyS5NneWMCaFP2/jQxflBX576GAeO4jN3 oJ8kQsj589dVFjReDTPEFUy3sTTiOw1rfwUtVWMCX2+Qvk7jVh+iO9WIAW/51LTE08QL7s hww9jRl3aRrSVrylqfVG0jYZsZNcNaEV/udoM3iGXcnZJ6NdAP1/RzvmOybXEl4Se6MlVG pugns2OvZhW2L2IpeYqDRMuNEU8iw4LqTDn8c3eqA7Pk38UsuUPFb9+M/UJq97k4lGnpT2 KzwEYzMbJkQI8KW0EtoaLqHKJJKJSE2hhIf/SOjnC33OFAr98y5ofps8kuav5Q== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:21 +0100 Subject: [PATCH RFC net-next v2 05/12] net: mdio: Move mdiobus_c45_addr() next to users MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-5-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn Now that mdiobus_c45_addr() is only used within the MDIO code during fallback, move the function next to its only users. This function should not be used any more in drivers, the c45 helpers should be used in its place, so hiding it away will prevent any new users from being added. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- drivers/net/phy/mdio_bus.c | 5 +++++ include/linux/mdio.h | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 20ba38a346fe..0b04ce3766c8 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -842,6 +842,11 @@ int __mdiobus_modify_changed(struct mii_bus *bus, int = addr, u32 regnum, } EXPORT_SYMBOL_GPL(__mdiobus_modify_changed); =20 +static u32 mdiobus_c45_addr(int devad, u16 regnum) +{ + return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum; +} + /** * __mdiobus_c45_read - Unlocked version of the mdiobus_c45_read function * @bus: the mii_bus struct diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 1e78c8410b21..97b49765e8b5 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -459,11 +459,6 @@ static inline int mdiodev_modify_changed(struct mdio_d= evice *mdiodev, mask, set); } =20 -static inline u32 mdiobus_c45_addr(int devad, u16 regnum) -{ - return MII_ADDR_C45 | devad << MII_DEVADDR_C45_SHIFT | regnum; -} - static inline u16 mdiobus_c45_regad(u32 regnum) { return FIELD_GET(MII_REGADDR_C45_MASK, regnum); --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A8E4C4332F for ; Tue, 27 Dec 2022 23:08:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232657AbiL0XIk (ORCPT ); Tue, 27 Dec 2022 18:08:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232210AbiL0XHp (ORCPT ); Tue, 27 Dec 2022 18:07:45 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B8F766E; Tue, 27 Dec 2022 15:07:30 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 0A70416E2; Wed, 28 Dec 2022 00:07:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HenFeMJJHR8jOxjl7oLQQnysEHe4M2/BX8/WSa6lrOA=; b=DlENZoXaTXR+4O5KCi8ja8pPuN6LAX0jrjx4eXQ8np0YGdJTAdomcUVXYvjJJtnTE9d2Ck lTWUh4x+GFmWDLMwv8kjp4hTtV8UBZXZjtJ3qrbXAQfU/ytp0xKhiWa8V9qR2crFswImW0 6nHjUiKNfZr51h01XVNFdVxis4cNyVvbzdNP6eWKUpQ0yjtk9Ew4fHpHoxiD3UlVPy2P0A +dS3RO3dwUR2KzRjqYOEmFDmqi5VjPseZdAIMxPAxsNkGnr6udgZhd3keSAks3CmqHhzLz MjcNIXbDL+uxU6HAFYQvcenoVKBPi0MXlU1OdQOf8D4WQwGhB1StdM06jXZyAQ== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:22 +0100 Subject: [PATCH RFC net-next v2 06/12] net: mdio: mdio-bitbang: Separate C22 and C45 transactions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-6-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn The bitbbanging bus driver can perform both C22 and C45 transfers. Create separate functions for each and register the C45 versions using the new driver API calls. The SH Ethernet driver places wrappers around these functions. In order to not break boards which might be using C45, add similar wrappers for C45 operations. Reviewed-by: Geert Uytterhoeven Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- drivers/net/ethernet/renesas/sh_eth.c | 37 ++++++++++++++--- drivers/net/mdio/mdio-bitbang.c | 77 +++++++++++++++++++++++--------= ---- include/linux/mdio-bitbang.h | 6 ++- 3 files changed, 87 insertions(+), 33 deletions(-) diff --git a/drivers/net/ethernet/renesas/sh_eth.c b/drivers/net/ethernet/r= enesas/sh_eth.c index 71a499113308..ed17163d7811 100644 --- a/drivers/net/ethernet/renesas/sh_eth.c +++ b/drivers/net/ethernet/renesas/sh_eth.c @@ -3044,23 +3044,46 @@ static int sh_mdio_release(struct sh_eth_private *m= dp) return 0; } =20 -static int sh_mdiobb_read(struct mii_bus *bus, int phy, int reg) +static int sh_mdiobb_read_c22(struct mii_bus *bus, int phy, int reg) { int res; =20 pm_runtime_get_sync(bus->parent); - res =3D mdiobb_read(bus, phy, reg); + res =3D mdiobb_read_c22(bus, phy, reg); pm_runtime_put(bus->parent); =20 return res; } =20 -static int sh_mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val) +static int sh_mdiobb_write_c22(struct mii_bus *bus, int phy, int reg, u16 = val) { int res; =20 pm_runtime_get_sync(bus->parent); - res =3D mdiobb_write(bus, phy, reg, val); + res =3D mdiobb_write_c22(bus, phy, reg, val); + pm_runtime_put(bus->parent); + + return res; +} + +static int sh_mdiobb_read_c45(struct mii_bus *bus, int phy, int devad, int= reg) +{ + int res; + + pm_runtime_get_sync(bus->parent); + res =3D mdiobb_read_c45(bus, phy, devad, reg); + pm_runtime_put(bus->parent); + + return res; +} + +static int sh_mdiobb_write_c45(struct mii_bus *bus, int phy, int devad, + int reg, u16 val) +{ + int res; + + pm_runtime_get_sync(bus->parent); + res =3D mdiobb_write_c45(bus, phy, devad, reg, val); pm_runtime_put(bus->parent); =20 return res; @@ -3091,8 +3114,10 @@ static int sh_mdio_init(struct sh_eth_private *mdp, return -ENOMEM; =20 /* Wrap accessors with Runtime PM-aware ops */ - mdp->mii_bus->read =3D sh_mdiobb_read; - mdp->mii_bus->write =3D sh_mdiobb_write; + mdp->mii_bus->read =3D sh_mdiobb_read_c22; + mdp->mii_bus->write =3D sh_mdiobb_write_c22; + mdp->mii_bus->read_c45 =3D sh_mdiobb_read_c45; + mdp->mii_bus->write_c45 =3D sh_mdiobb_write_c45; =20 /* Hook up MII support for ethtool */ mdp->mii_bus->name =3D "sh_mii"; diff --git a/drivers/net/mdio/mdio-bitbang.c b/drivers/net/mdio/mdio-bitban= g.c index 07609114a26b..b83932562be2 100644 --- a/drivers/net/mdio/mdio-bitbang.c +++ b/drivers/net/mdio/mdio-bitbang.c @@ -127,14 +127,12 @@ static void mdiobb_cmd(struct mdiobb_ctrl *ctrl, int = op, u8 phy, u8 reg) =20 /* In clause 45 mode all commands are prefixed by MDIO_ADDR to specify the lower 16 bits of the 21 bit address. This transfer is done identically = to a - MDIO_WRITE except for a different code. To enable clause 45 mode or - MII_ADDR_C45 into the address. Theoretically clause 45 and normal devic= es - can exist on the same bus. Normal devices should ignore the MDIO_ADDR + MDIO_WRITE except for a different code. Theoretically clause 45 and nor= mal + devices can exist on the same bus. Normal devices should ignore the MDI= O_ADDR phase. */ -static int mdiobb_cmd_addr(struct mdiobb_ctrl *ctrl, int phy, u32 addr) +static void mdiobb_cmd_addr(struct mdiobb_ctrl *ctrl, int phy, int dev_add= r, + int reg) { - unsigned int dev_addr =3D (addr >> 16) & 0x1F; - unsigned int reg =3D addr & 0xFFFF; mdiobb_cmd(ctrl, MDIO_C45_ADDR, phy, dev_addr); =20 /* send the turnaround (10) */ @@ -145,21 +143,13 @@ static int mdiobb_cmd_addr(struct mdiobb_ctrl *ctrl, = int phy, u32 addr) =20 ctrl->ops->set_mdio_dir(ctrl, 0); mdiobb_get_bit(ctrl); - - return dev_addr; } =20 -int mdiobb_read(struct mii_bus *bus, int phy, int reg) +static int mdiobb_read_common(struct mii_bus *bus, int phy) { struct mdiobb_ctrl *ctrl =3D bus->priv; int ret, i; =20 - if (reg & MII_ADDR_C45) { - reg =3D mdiobb_cmd_addr(ctrl, phy, reg); - mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg); - } else - mdiobb_cmd(ctrl, ctrl->op_c22_read, phy, reg); - ctrl->ops->set_mdio_dir(ctrl, 0); =20 /* check the turnaround bit: the PHY should be driving it to zero, if this @@ -180,17 +170,31 @@ int mdiobb_read(struct mii_bus *bus, int phy, int reg) mdiobb_get_bit(ctrl); return ret; } -EXPORT_SYMBOL(mdiobb_read); =20 -int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val) +int mdiobb_read_c22(struct mii_bus *bus, int phy, int reg) { struct mdiobb_ctrl *ctrl =3D bus->priv; =20 - if (reg & MII_ADDR_C45) { - reg =3D mdiobb_cmd_addr(ctrl, phy, reg); - mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg); - } else - mdiobb_cmd(ctrl, ctrl->op_c22_write, phy, reg); + mdiobb_cmd(ctrl, ctrl->op_c22_read, phy, reg); + + return mdiobb_read_common(bus, phy); +} +EXPORT_SYMBOL(mdiobb_read_c22); + +int mdiobb_read_c45(struct mii_bus *bus, int phy, int devad, int reg) +{ + struct mdiobb_ctrl *ctrl =3D bus->priv; + + mdiobb_cmd_addr(ctrl, phy, devad, reg); + mdiobb_cmd(ctrl, MDIO_C45_READ, phy, reg); + + return mdiobb_read_common(bus, phy); +} +EXPORT_SYMBOL(mdiobb_read_c45); + +static int mdiobb_write_common(struct mii_bus *bus, u16 val) +{ + struct mdiobb_ctrl *ctrl =3D bus->priv; =20 /* send the turnaround (10) */ mdiobb_send_bit(ctrl, 1); @@ -202,7 +206,27 @@ int mdiobb_write(struct mii_bus *bus, int phy, int reg= , u16 val) mdiobb_get_bit(ctrl); return 0; } -EXPORT_SYMBOL(mdiobb_write); + +int mdiobb_write_c22(struct mii_bus *bus, int phy, int reg, u16 val) +{ + struct mdiobb_ctrl *ctrl =3D bus->priv; + + mdiobb_cmd(ctrl, ctrl->op_c22_write, phy, reg); + + return mdiobb_write_common(bus, val); +} +EXPORT_SYMBOL(mdiobb_write_c22); + +int mdiobb_write_c45(struct mii_bus *bus, int phy, int devad, int reg, u16= val) +{ + struct mdiobb_ctrl *ctrl =3D bus->priv; + + mdiobb_cmd_addr(ctrl, phy, devad, reg); + mdiobb_cmd(ctrl, MDIO_C45_WRITE, phy, reg); + + return mdiobb_write_common(bus, val); +} +EXPORT_SYMBOL(mdiobb_write_c45); =20 struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl) { @@ -214,8 +238,11 @@ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl = *ctrl) =20 __module_get(ctrl->ops->owner); =20 - bus->read =3D mdiobb_read; - bus->write =3D mdiobb_write; + bus->read =3D mdiobb_read_c22; + bus->write =3D mdiobb_write_c22; + bus->read_c45 =3D mdiobb_read_c45; + bus->write_c45 =3D mdiobb_write_c45; + bus->priv =3D ctrl; if (!ctrl->override_op_c22) { ctrl->op_c22_read =3D MDIO_READ; diff --git a/include/linux/mdio-bitbang.h b/include/linux/mdio-bitbang.h index 373630fe5c28..cffabdbce075 100644 --- a/include/linux/mdio-bitbang.h +++ b/include/linux/mdio-bitbang.h @@ -38,8 +38,10 @@ struct mdiobb_ctrl { u8 op_c22_write; }; =20 -int mdiobb_read(struct mii_bus *bus, int phy, int reg); -int mdiobb_write(struct mii_bus *bus, int phy, int reg, u16 val); +int mdiobb_read_c22(struct mii_bus *bus, int phy, int reg); +int mdiobb_write_c22(struct mii_bus *bus, int phy, int reg, u16 val); +int mdiobb_read_c45(struct mii_bus *bus, int devad, int phy, int reg); +int mdiobb_write_c45(struct mii_bus *bus, int devad, int phy, int reg, u16= val); =20 /* The returned bus is not yet registered with the phy layer. */ struct mii_bus *alloc_mdio_bitbang(struct mdiobb_ctrl *ctrl); --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11AB1C4332F for ; Tue, 27 Dec 2022 23:08:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232664AbiL0XIn (ORCPT ); Tue, 27 Dec 2022 18:08:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232225AbiL0XHq (ORCPT ); Tue, 27 Dec 2022 18:07:46 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3067B4A3; Tue, 27 Dec 2022 15:07:30 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id A15E416E4; Wed, 28 Dec 2022 00:07:28 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Lgn0fUyj9IFSMk8AaMRWHgs4+wjSuyxk0Wk78bhVnA0=; b=IG0HA2I8gt7HTMttS+b2tDKuI+ZaK9lzIPDjQBgMcPDv+Sb+AQ04m0EIUHjw0vVjK3qAfP Jjc1a6hxYB7nXWgWzd4Mp/YFFEZj4pdgYbpDeRlP4y4pCCOkaHptZjaR5GoQfgoBvkPhen uKC7DNiXTYMiJAJcMqpyIR2wpNjzJUvp6j7XXnTcleUDN+1nE6gepIOPcco06qgQU102HZ 3HyGptcDoFFK6PgavhIw+fZma1kC85QGmPShdRozl5NtLesMgWQCUwM/pMZ5NZiKwu1OHy Hz2taTVz9lmvUkfLkI3tCAViCdGPkzBqusQnp0EOv8Y6i/BbkVIboWqtISCwMw== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:23 +0100 Subject: [PATCH RFC net-next v2 07/12] net: mdio: mvmdio: Convert XSMI bus to new API MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-7-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn The marvell MDIO driver supports two different hardware blocks. The XSMI block is C45 only. Convert this block to the new API, and only populate the c45 calls in the bus structure. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- drivers/net/ethernet/marvell/mvmdio.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/drivers/net/ethernet/marvell/mvmdio.c b/drivers/net/ethernet/m= arvell/mvmdio.c index ef878973b859..2d654a40af13 100644 --- a/drivers/net/ethernet/marvell/mvmdio.c +++ b/drivers/net/ethernet/marvell/mvmdio.c @@ -204,21 +204,17 @@ static const struct orion_mdio_ops orion_mdio_xsmi_op= s =3D { .poll_interval_max =3D MVMDIO_XSMI_POLL_INTERVAL_MAX, }; =20 -static int orion_mdio_xsmi_read(struct mii_bus *bus, int mii_id, - int regnum) +static int orion_mdio_xsmi_read_c45(struct mii_bus *bus, int mii_id, + int dev_addr, int regnum) { struct orion_mdio_dev *dev =3D bus->priv; - u16 dev_addr =3D (regnum >> 16) & GENMASK(4, 0); int ret; =20 - if (!(regnum & MII_ADDR_C45)) - return -EOPNOTSUPP; - ret =3D orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus); if (ret < 0) return ret; =20 - writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG); + writel(regnum, dev->regs + MVMDIO_XSMI_ADDR_REG); writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) | (dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) | MVMDIO_XSMI_READ_OPERATION, @@ -237,21 +233,17 @@ static int orion_mdio_xsmi_read(struct mii_bus *bus, = int mii_id, return readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & GENMASK(15, 0); } =20 -static int orion_mdio_xsmi_write(struct mii_bus *bus, int mii_id, - int regnum, u16 value) +static int orion_mdio_xsmi_write_c45(struct mii_bus *bus, int mii_id, + int dev_addr, int regnum, u16 value) { struct orion_mdio_dev *dev =3D bus->priv; - u16 dev_addr =3D (regnum >> 16) & GENMASK(4, 0); int ret; =20 - if (!(regnum & MII_ADDR_C45)) - return -EOPNOTSUPP; - ret =3D orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus); if (ret < 0) return ret; =20 - writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG); + writel(regnum, dev->regs + MVMDIO_XSMI_ADDR_REG); writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) | (dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) | MVMDIO_XSMI_WRITE_OPERATION | value, @@ -302,8 +294,8 @@ static int orion_mdio_probe(struct platform_device *pde= v) bus->write =3D orion_mdio_smi_write; break; case BUS_TYPE_XSMI: - bus->read =3D orion_mdio_xsmi_read; - bus->write =3D orion_mdio_xsmi_write; + bus->read_c45 =3D orion_mdio_xsmi_read_c45; + bus->write_c45 =3D orion_mdio_xsmi_write_c45; break; } =20 --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0A78C4332F for ; Tue, 27 Dec 2022 23:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232701AbiL0XJI (ORCPT ); Tue, 27 Dec 2022 18:09:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44540 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231409AbiL0XHq (ORCPT ); Tue, 27 Dec 2022 18:07:46 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B0BB49C; Tue, 27 Dec 2022 15:07:30 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 0DB9016E6; Wed, 28 Dec 2022 00:07:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sMbUUXMbhp+M/zQYqTYPRcq5z/ESj3+QbHed23y5ENo=; b=YZrfu27TR2nT3nrR3XlDqTwRUVeyzcBHo246w6Ii1DHDEGKubzkXkxfQWIATAkgqCVBmiy 3M/SAQu+LzScxavvYFYHu9n122fLs5ecpE3vEI/pEEmnWk97W9coqauai7ZWpu2rnldEYT Em0b7H46SeO7KW/i8Ens3VdozEWDaj6rGUQwTf9GUJLziPjnEhcwiJ31qQP9+ZMN65UI5q X499JQS2oXuJdxt4Agha1C78JFA+my64aSFuWt7/I9bDkIX9gBWT8KmGLblubVefBZU6Yf tSsi30ar1lAt/HS2JRSUyGSldltR5hAHq/An73H/Nu1FRwdxxGN22noc00ZBDA== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:24 +0100 Subject: [PATCH RFC net-next v2 08/12] net: ethernet: freescale: xgmac: Separate C22 and C45 transactions for xgmac MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-8-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn The xgmac MDIO bus driver can perform both C22 and C45 transfers. Create separate functions for each and register the C45 versions using the new API calls where appropriate. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle Tested-by: Vladimir Oltean --- v2: - [al] Move the masking of regnum into the variable declarations - [al] Remove a couple of blank lines --- drivers/net/ethernet/freescale/xgmac_mdio.c | 150 +++++++++++++++++++++---= ---- 1 file changed, 113 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/freescale/xgmac_mdio.c b/drivers/net/ethe= rnet/freescale/xgmac_mdio.c index d7d39a58cd80..1861cf14f4d7 100644 --- a/drivers/net/ethernet/freescale/xgmac_mdio.c +++ b/drivers/net/ethernet/freescale/xgmac_mdio.c @@ -128,30 +128,57 @@ static int xgmac_wait_until_done(struct device *dev, return 0; } =20 -/* - * Write value to the PHY for this device to the register at regnum,waiting +/* Write value to the PHY for this device to the register at regnum,waiting * until the write is done before it returns. All PHY configuration has t= o be * done through the TSEC1 MIIM regs. */ -static int xgmac_mdio_write(struct mii_bus *bus, int phy_id, int regnum, u= 16 value) +static int xgmac_mdio_write_c22(struct mii_bus *bus, int phy_id, int regnu= m, + u16 value) { struct mdio_fsl_priv *priv =3D (struct mdio_fsl_priv *)bus->priv; struct tgec_mdio_controller __iomem *regs =3D priv->mdio_base; - uint16_t dev_addr; + bool endian =3D priv->is_little_endian; + u16 dev_addr =3D regnum & 0x1f; u32 mdio_ctl, mdio_stat; int ret; + + mdio_stat =3D xgmac_read32(®s->mdio_stat, endian); + mdio_stat &=3D ~MDIO_STAT_ENC; + xgmac_write32(mdio_stat, ®s->mdio_stat, endian); + + ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); + if (ret) + return ret; + + /* Set the port and dev addr */ + mdio_ctl =3D MDIO_CTL_PORT_ADDR(phy_id) | MDIO_CTL_DEV_ADDR(dev_addr); + xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian); + + /* Write the value to the register */ + xgmac_write32(MDIO_DATA(value), ®s->mdio_data, endian); + + ret =3D xgmac_wait_until_done(&bus->dev, regs, endian); + if (ret) + return ret; + + return 0; +} + +/* Write value to the PHY for this device to the register at regnum,waiting + * until the write is done before it returns. All PHY configuration has t= o be + * done through the TSEC1 MIIM regs. + */ +static int xgmac_mdio_write_c45(struct mii_bus *bus, int phy_id, int dev_a= ddr, + int regnum, u16 value) +{ + struct mdio_fsl_priv *priv =3D (struct mdio_fsl_priv *)bus->priv; + struct tgec_mdio_controller __iomem *regs =3D priv->mdio_base; bool endian =3D priv->is_little_endian; + u32 mdio_ctl, mdio_stat; + int ret; =20 mdio_stat =3D xgmac_read32(®s->mdio_stat, endian); - if (regnum & MII_ADDR_C45) { - /* Clause 45 (ie 10G) */ - dev_addr =3D (regnum >> 16) & 0x1f; - mdio_stat |=3D MDIO_STAT_ENC; - } else { - /* Clause 22 (ie 1G) */ - dev_addr =3D regnum & 0x1f; - mdio_stat &=3D ~MDIO_STAT_ENC; - } + mdio_stat |=3D MDIO_STAT_ENC; =20 xgmac_write32(mdio_stat, ®s->mdio_stat, endian); =20 @@ -164,13 +191,11 @@ static int xgmac_mdio_write(struct mii_bus *bus, int = phy_id, int regnum, u16 val xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian); =20 /* Set the register address */ - if (regnum & MII_ADDR_C45) { - xgmac_write32(regnum & 0xffff, ®s->mdio_addr, endian); + xgmac_write32(regnum & 0xffff, ®s->mdio_addr, endian); =20 - ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); - if (ret) - return ret; - } + ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); + if (ret) + return ret; =20 /* Write the value to the register */ xgmac_write32(MDIO_DATA(value), ®s->mdio_data, endian); @@ -182,31 +207,82 @@ static int xgmac_mdio_write(struct mii_bus *bus, int = phy_id, int regnum, u16 val return 0; } =20 -/* - * Reads from register regnum in the PHY for device dev, returning the val= ue. +/* Reads from register regnum in the PHY for device dev, returning the val= ue. * Clears miimcom first. All PHY configuration has to be done through the * TSEC1 MIIM regs. */ -static int xgmac_mdio_read(struct mii_bus *bus, int phy_id, int regnum) +static int xgmac_mdio_read_c22(struct mii_bus *bus, int phy_id, int regnum) { struct mdio_fsl_priv *priv =3D (struct mdio_fsl_priv *)bus->priv; struct tgec_mdio_controller __iomem *regs =3D priv->mdio_base; + bool endian =3D priv->is_little_endian; + u16 dev_addr =3D regnum & 0x1f; unsigned long flags; - uint16_t dev_addr; uint32_t mdio_stat; uint32_t mdio_ctl; int ret; - bool endian =3D priv->is_little_endian; =20 mdio_stat =3D xgmac_read32(®s->mdio_stat, endian); - if (regnum & MII_ADDR_C45) { - dev_addr =3D (regnum >> 16) & 0x1f; - mdio_stat |=3D MDIO_STAT_ENC; + mdio_stat &=3D ~MDIO_STAT_ENC; + xgmac_write32(mdio_stat, ®s->mdio_stat, endian); + + ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); + if (ret) + return ret; + + /* Set the Port and Device Addrs */ + mdio_ctl =3D MDIO_CTL_PORT_ADDR(phy_id) | MDIO_CTL_DEV_ADDR(dev_addr); + xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian); + + if (priv->has_a009885) + /* Once the operation completes, i.e. MDIO_STAT_BSY clears, we + * must read back the data register within 16 MDC cycles. + */ + local_irq_save(flags); + + /* Initiate the read */ + xgmac_write32(mdio_ctl | MDIO_CTL_READ, ®s->mdio_ctl, endian); + + ret =3D xgmac_wait_until_done(&bus->dev, regs, endian); + if (ret) + goto irq_restore; + + /* Return all Fs if nothing was there */ + if ((xgmac_read32(®s->mdio_stat, endian) & MDIO_STAT_RD_ER) && + !priv->has_a011043) { + dev_dbg(&bus->dev, + "Error while reading PHY%d reg at %d.%d\n", + phy_id, dev_addr, regnum); + ret =3D 0xffff; } else { - dev_addr =3D regnum & 0x1f; - mdio_stat &=3D ~MDIO_STAT_ENC; + ret =3D xgmac_read32(®s->mdio_data, endian) & 0xffff; + dev_dbg(&bus->dev, "read %04x\n", ret); } =20 +irq_restore: + if (priv->has_a009885) + local_irq_restore(flags); + + return ret; +} + +/* Reads from register regnum in the PHY for device dev, returning the val= ue. + * Clears miimcom first. All PHY configuration has to be done through the + * TSEC1 MIIM regs. + */ +static int xgmac_mdio_read_c45(struct mii_bus *bus, int phy_id, int dev_ad= dr, + int regnum) +{ + struct mdio_fsl_priv *priv =3D (struct mdio_fsl_priv *)bus->priv; + struct tgec_mdio_controller __iomem *regs =3D priv->mdio_base; + bool endian =3D priv->is_little_endian; + u32 mdio_stat, mdio_ctl; + unsigned long flags; + int ret; + + mdio_stat =3D xgmac_read32(®s->mdio_stat, endian); + mdio_stat |=3D MDIO_STAT_ENC; + xgmac_write32(mdio_stat, ®s->mdio_stat, endian); =20 ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); @@ -218,13 +294,11 @@ static int xgmac_mdio_read(struct mii_bus *bus, int p= hy_id, int regnum) xgmac_write32(mdio_ctl, ®s->mdio_ctl, endian); =20 /* Set the register address */ - if (regnum & MII_ADDR_C45) { - xgmac_write32(regnum & 0xffff, ®s->mdio_addr, endian); + xgmac_write32(regnum & 0xffff, ®s->mdio_addr, endian); =20 - ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); - if (ret) - return ret; - } + ret =3D xgmac_wait_until_free(&bus->dev, regs, endian); + if (ret) + return ret; =20 if (priv->has_a009885) /* Once the operation completes, i.e. MDIO_STAT_BSY clears, we @@ -326,8 +400,10 @@ static int xgmac_mdio_probe(struct platform_device *pd= ev) return -ENOMEM; =20 bus->name =3D "Freescale XGMAC MDIO Bus"; - bus->read =3D xgmac_mdio_read; - bus->write =3D xgmac_mdio_write; + bus->read =3D xgmac_mdio_read_c22; + bus->write =3D xgmac_mdio_write_c22; + bus->read_c45 =3D xgmac_mdio_read_c45; + bus->write_c45 =3D xgmac_mdio_write_c45; bus->parent =3D &pdev->dev; bus->probe_capabilities =3D MDIOBUS_C22_C45; snprintf(bus->id, MII_BUS_ID_SIZE, "%pa", &res->start); --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A559CC4332F for ; Tue, 27 Dec 2022 23:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232673AbiL0XIs (ORCPT ); Tue, 27 Dec 2022 18:08:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231835AbiL0XHq (ORCPT ); Tue, 27 Dec 2022 18:07:46 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23833B4A4; Tue, 27 Dec 2022 15:07:31 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 72ABA16E8; Wed, 28 Dec 2022 00:07:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EtKt42zATBVdhhVN4u6oBH/TSlZiEUvG2BWKEVPzk14=; b=M1YZBVs+yYhVfmD6UjKZ3McECNIVJ3SEJVo6ydAZ32tQCQ0kDa+hGXdGCA4dAfWqcARxEp iX8bcz+n5JLsKvT+2Q8nVcDNThws6ry+orAe+sxuI+FPO74hEqxB9jADPdUTU0zllGtX2P S2Ye89/BMwzc8RRfohTn1QI8i9cjlCYIkTfmXRpYiey4CNEdJFEJlYBF40CC7D/eHFsxK/ 6dsGWInxYFW08fOjEEv1OjLhJGIV2c1uGCeFwaIlh3jnzyKiel9O6EjNdM+r/2/JGer+K0 jOJF1FQREQC8C3edQNM3CeViZD/HOWDjGkDrUdXXP2cXux1i7vebt91+lrCH3g== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:25 +0100 Subject: [PATCH RFC net-next v2 09/12] net: ethernet: freescale: fec: Separate C22 and C45 transactions for xgmac MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-9-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn The fec MDIO bus driver can perform both C22 and C45 transfers. Create separate functions for each and register the C45 versions using the new API calls where appropriate. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle Reviewed-by: Wei Fang --- v2: - [al] Fixup some indentation --- drivers/net/ethernet/freescale/fec_main.c | 153 ++++++++++++++++++++------= ---- 1 file changed, 103 insertions(+), 50 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethern= et/freescale/fec_main.c index 644f3c963730..e6238e53940d 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1987,47 +1987,74 @@ static int fec_enet_mdio_wait(struct fec_enet_priva= te *fep) return ret; } =20 -static int fec_enet_mdio_read(struct mii_bus *bus, int mii_id, int regnum) +static int fec_enet_mdio_read_c22(struct mii_bus *bus, int mii_id, int reg= num) { struct fec_enet_private *fep =3D bus->priv; struct device *dev =3D &fep->pdev->dev; int ret =3D 0, frame_start, frame_addr, frame_op; - bool is_c45 =3D !!(regnum & MII_ADDR_C45); =20 ret =3D pm_runtime_resume_and_get(dev); if (ret < 0) return ret; =20 - if (is_c45) { - frame_start =3D FEC_MMFR_ST_C45; + /* C22 read */ + frame_op =3D FEC_MMFR_OP_READ; + frame_start =3D FEC_MMFR_ST; + frame_addr =3D regnum; =20 - /* write address */ - frame_addr =3D (regnum >> 16); - writel(frame_start | FEC_MMFR_OP_ADDR_WRITE | - FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(frame_addr) | - FEC_MMFR_TA | (regnum & 0xFFFF), - fep->hwp + FEC_MII_DATA); + /* start a read op */ + writel(frame_start | frame_op | + FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(frame_addr) | + FEC_MMFR_TA, fep->hwp + FEC_MII_DATA); =20 - /* wait for end of transfer */ - ret =3D fec_enet_mdio_wait(fep); - if (ret) { - netdev_err(fep->netdev, "MDIO address write timeout\n"); - goto out; - } + /* wait for end of transfer */ + ret =3D fec_enet_mdio_wait(fep); + if (ret) { + netdev_err(fep->netdev, "MDIO read timeout\n"); + goto out; + } =20 - frame_op =3D FEC_MMFR_OP_READ_C45; + ret =3D FEC_MMFR_DATA(readl(fep->hwp + FEC_MII_DATA)); =20 - } else { - /* C22 read */ - frame_op =3D FEC_MMFR_OP_READ; - frame_start =3D FEC_MMFR_ST; - frame_addr =3D regnum; +out: + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; +} + +static int fec_enet_mdio_read_c45(struct mii_bus *bus, int mii_id, + int devad, int regnum) +{ + struct fec_enet_private *fep =3D bus->priv; + struct device *dev =3D &fep->pdev->dev; + int ret =3D 0, frame_start, frame_op; + + ret =3D pm_runtime_resume_and_get(dev); + if (ret < 0) + return ret; + + frame_start =3D FEC_MMFR_ST_C45; + + /* write address */ + writel(frame_start | FEC_MMFR_OP_ADDR_WRITE | + FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(devad) | + FEC_MMFR_TA | (regnum & 0xFFFF), + fep->hwp + FEC_MII_DATA); + + /* wait for end of transfer */ + ret =3D fec_enet_mdio_wait(fep); + if (ret) { + netdev_err(fep->netdev, "MDIO address write timeout\n"); + goto out; } =20 + frame_op =3D FEC_MMFR_OP_READ_C45; + /* start a read op */ writel(frame_start | frame_op | - FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(frame_addr) | - FEC_MMFR_TA, fep->hwp + FEC_MII_DATA); + FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(devad) | + FEC_MMFR_TA, fep->hwp + FEC_MII_DATA); =20 /* wait for end of transfer */ ret =3D fec_enet_mdio_wait(fep); @@ -2045,45 +2072,69 @@ static int fec_enet_mdio_read(struct mii_bus *bus, = int mii_id, int regnum) return ret; } =20 -static int fec_enet_mdio_write(struct mii_bus *bus, int mii_id, int regnum, - u16 value) +static int fec_enet_mdio_write_c22(struct mii_bus *bus, int mii_id, int re= gnum, + u16 value) { struct fec_enet_private *fep =3D bus->priv; struct device *dev =3D &fep->pdev->dev; int ret, frame_start, frame_addr; - bool is_c45 =3D !!(regnum & MII_ADDR_C45); =20 ret =3D pm_runtime_resume_and_get(dev); if (ret < 0) return ret; =20 - if (is_c45) { - frame_start =3D FEC_MMFR_ST_C45; + /* C22 write */ + frame_start =3D FEC_MMFR_ST; + frame_addr =3D regnum; =20 - /* write address */ - frame_addr =3D (regnum >> 16); - writel(frame_start | FEC_MMFR_OP_ADDR_WRITE | - FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(frame_addr) | - FEC_MMFR_TA | (regnum & 0xFFFF), - fep->hwp + FEC_MII_DATA); + /* start a write op */ + writel(frame_start | FEC_MMFR_OP_WRITE | + FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(frame_addr) | + FEC_MMFR_TA | FEC_MMFR_DATA(value), + fep->hwp + FEC_MII_DATA); =20 - /* wait for end of transfer */ - ret =3D fec_enet_mdio_wait(fep); - if (ret) { - netdev_err(fep->netdev, "MDIO address write timeout\n"); - goto out; - } - } else { - /* C22 write */ - frame_start =3D FEC_MMFR_ST; - frame_addr =3D regnum; + /* wait for end of transfer */ + ret =3D fec_enet_mdio_wait(fep); + if (ret) + netdev_err(fep->netdev, "MDIO write timeout\n"); + + pm_runtime_mark_last_busy(dev); + pm_runtime_put_autosuspend(dev); + + return ret; +} + +static int fec_enet_mdio_write_c45(struct mii_bus *bus, int mii_id, + int devad, int regnum, u16 value) +{ + struct fec_enet_private *fep =3D bus->priv; + struct device *dev =3D &fep->pdev->dev; + int ret, frame_start; + + ret =3D pm_runtime_resume_and_get(dev); + if (ret < 0) + return ret; + + frame_start =3D FEC_MMFR_ST_C45; + + /* write address */ + writel(frame_start | FEC_MMFR_OP_ADDR_WRITE | + FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(devad) | + FEC_MMFR_TA | (regnum & 0xFFFF), + fep->hwp + FEC_MII_DATA); + + /* wait for end of transfer */ + ret =3D fec_enet_mdio_wait(fep); + if (ret) { + netdev_err(fep->netdev, "MDIO address write timeout\n"); + goto out; } =20 /* start a write op */ writel(frame_start | FEC_MMFR_OP_WRITE | - FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(frame_addr) | - FEC_MMFR_TA | FEC_MMFR_DATA(value), - fep->hwp + FEC_MII_DATA); + FEC_MMFR_PA(mii_id) | FEC_MMFR_RA(devad) | + FEC_MMFR_TA | FEC_MMFR_DATA(value), + fep->hwp + FEC_MII_DATA); =20 /* wait for end of transfer */ ret =3D fec_enet_mdio_wait(fep); @@ -2381,8 +2432,10 @@ static int fec_enet_mii_init(struct platform_device = *pdev) } =20 fep->mii_bus->name =3D "fec_enet_mii_bus"; - fep->mii_bus->read =3D fec_enet_mdio_read; - fep->mii_bus->write =3D fec_enet_mdio_write; + fep->mii_bus->read =3D fec_enet_mdio_read_c22; + fep->mii_bus->write =3D fec_enet_mdio_write_c22; + fep->mii_bus->read_c45 =3D fec_enet_mdio_read_c45; + fep->mii_bus->write_c45 =3D fec_enet_mdio_write_c45; snprintf(fep->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", pdev->name, fep->dev_id + 1); fep->mii_bus->priv =3D fep; --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD896C4332F for ; Tue, 27 Dec 2022 23:08:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232517AbiL0XIw (ORCPT ); Tue, 27 Dec 2022 18:08:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232151AbiL0XHq (ORCPT ); Tue, 27 Dec 2022 18:07:46 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90847B4A5; Tue, 27 Dec 2022 15:07:31 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id BD82D16EA; Wed, 28 Dec 2022 00:07:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hfJorQnKMERmz+LiqP1dBLwXqwSIibWbImpZkqwPLDw=; b=IidzJcgxLAGi5gJlWjd90IjWinbkMgOZwpbubUi/VSuvXFVFjARyi0ZrAHJQA1HFwHs4RU SNfggwd9pRguuIP1RE71gz8cQIe+Mg0PtUkDctemXSF+OyHaQ8vhNeJb4RiPf9zoXm2uik lHA4RJkDGy9oOK42rpNQqgk/eBhwsnXfBtePO/vBY2CKZVq8kjtyfu6KSkqhVXztDYjYrq gSp70TmhKgf8MBdImYt1wB83ysnUxMIA5tLZl1GhxQva6MZQ0c5Mx34WDlvyV3sfmcRRej kAjzsoPX0XBaNj09csgFcdn2LYOPrnyhs6mcIuRobQrk91o4FpqR78qa5Jmi4g== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:26 +0100 Subject: [PATCH RFC net-next v2 10/12] net: mdio: add mdiobus_c45_read/write_nested helpers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-10-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn Some DSA devices pass through PHY access to the MDIO bus the switch is on. Add C45 versions of the current C22 helpers for nested accesses to MDIO busses, so that C22 and C45 can be separated in these DSA drivers. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- v2: - [al] new patch --- drivers/net/phy/mdio_bus.c | 55 ++++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/mdio.h | 4 ++++ 2 files changed, 59 insertions(+) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 0b04ce3766c8..7f6b12b65f0d 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -1011,6 +1011,33 @@ int mdiobus_c45_read(struct mii_bus *bus, int addr, = int devad, u32 regnum) } EXPORT_SYMBOL(mdiobus_c45_read); =20 +/** + * mdiobus_c45_read_nested - Nested version of the mdiobus_c45_read functi= on + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to read + * + * In case of nested MDIO bus access avoid lockdep false positives by + * using mutex_lock_nested(). + * + * NOTE: MUST NOT be called from interrupt context, + * because the bus read/write functions may wait for an interrupt + * to conclude the operation. + */ +int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad, + u32 regnum) +{ + int retval; + + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + retval =3D __mdiobus_c45_read(bus, addr, devad, regnum); + mutex_unlock(&bus->mdio_lock); + + return retval; +} +EXPORT_SYMBOL(mdiobus_c45_read_nested); + /** * mdiobus_write_nested - Nested version of the mdiobus_write function * @bus: the mii_bus struct @@ -1085,6 +1112,34 @@ int mdiobus_c45_write(struct mii_bus *bus, int addr,= int devad, u32 regnum, } EXPORT_SYMBOL(mdiobus_c45_write); =20 +/** + * mdiobus_c45_write_nested - Nested version of the mdiobus_c45_write func= tion + * @bus: the mii_bus struct + * @addr: the phy address + * @devad: device address to read + * @regnum: register number to write + * @val: value to write to @regnum + * + * In case of nested MDIO bus access avoid lockdep false positives by + * using mutex_lock_nested(). + * + * NOTE: MUST NOT be called from interrupt context, + * because the bus read/write functions may wait for an interrupt + * to conclude the operation. + */ +int mdiobus_c45_write_nested(struct mii_bus *bus, int addr, int devad, + u32 regnum, u16 val) +{ + int err; + + mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED); + err =3D __mdiobus_c45_write(bus, addr, devad, regnum, val); + mutex_unlock(&bus->mdio_lock); + + return err; +} +EXPORT_SYMBOL(mdiobus_c45_write_nested); + /** * mdiobus_modify - Convenience function for modifying a given mdio device * register diff --git a/include/linux/mdio.h b/include/linux/mdio.h index 97b49765e8b5..220f3ca8702d 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -425,10 +425,14 @@ int mdiobus_modify_changed(struct mii_bus *bus, int a= ddr, u32 regnum, u16 mask, u16 set); int __mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnu= m); int mdiobus_c45_read(struct mii_bus *bus, int addr, int devad, u32 regnum); +int mdiobus_c45_read_nested(struct mii_bus *bus, int addr, int devad, + u32 regnum); int __mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 reg= num, u16 val); int mdiobus_c45_write(struct mii_bus *bus, int addr, int devad, u32 regnu= m, u16 val); +int mdiobus_c45_write_nested(struct mii_bus *bus, int addr, int devad, + u32 regnum, u16 val); int mdiobus_c45_modify(struct mii_bus *bus, int addr, int devad, u32 regnu= m, u16 mask, u16 set); =20 --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34D3EC4332F for ; Tue, 27 Dec 2022 23:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232537AbiL0XI6 (ORCPT ); Tue, 27 Dec 2022 18:08:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232161AbiL0XHq (ORCPT ); Tue, 27 Dec 2022 18:07:46 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F076DB4A7; Tue, 27 Dec 2022 15:07:31 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 29B3416EC; Wed, 28 Dec 2022 00:07:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=zvah4gb6JfTRtcNM4GdmgGrH5+DJzSKUpsj4la1NmEU=; b=ezK3oi5PsWw9mo7Kayb5ARon1mvRK8YVrerHWdZdYutNd0UzVf7kBsxHzv7y3X/9azeFhk fg1UMFh8s5lBnWUpNtIXozB2f5qriHnKa1etKEnY1H6Na5wA1I2eZiRINewxrIQMxZ238o 2xFnUTYEq09X4sbX+z497DmSJKg2uDbTQfiKeFOAY7rXoth3JyMeZ0sOYwjSUr20/b34W0 j5wEFNvdy2+UJAC3GL1+69cT1D1dKZ7TSpQUFUs0Ef3PaHc6gaea6EZr/QOgxWjy7kbp/C Llg7dVNcgrycHoUrEZCVqBc8pKcar3HhoaxF3cRkf2xrRfmhDtGonux+5JQsiQ== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:27 +0100 Subject: [PATCH RFC net-next v2 11/12] net: dsa: Separate C22 and C45 MDIO bus transaction methods MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-11-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn By adding _c45 function pointers to the dsa_switch_op structure, the dsa core can register an MDIO bus with C45 accessors. The dsa-loop driver could in theory provide such accessors, since it just passed requests to the MDIO bus it is on, but it seems unlikely to be useful at the moment. It can however be added later. mt7530 does support C45, but its uses a mix of registering its MDIO bus and using the DSA core provided bus. This makes the change a bit more complex. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle --- v2: - [al] Remove conditional c45, since all switches support c45 - [al] Remove dsa core changes, they are not needed - [al] Add comment that DSA provided MDIO bus is C22 only. --- drivers/net/dsa/mt7530.c | 87 ++++++++++++++++++++++++--------------------= ---- drivers/net/dsa/mt7530.h | 15 ++++++--- include/net/dsa.h | 2 +- 3 files changed, 56 insertions(+), 48 deletions(-) diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 908fa89444c9..616b21c90d05 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -608,17 +608,29 @@ mt7530_mib_reset(struct dsa_switch *ds) mt7530_write(priv, MT7530_MIB_CCR, CCR_MIB_ACTIVATE); } =20 -static int mt7530_phy_read(struct mt7530_priv *priv, int port, int regnum) +static int mt7530_phy_read_c22(struct mt7530_priv *priv, int port, int reg= num) { return mdiobus_read_nested(priv->bus, port, regnum); } =20 -static int mt7530_phy_write(struct mt7530_priv *priv, int port, int regnum, - u16 val) +static int mt7530_phy_write_c22(struct mt7530_priv *priv, int port, int re= gnum, + u16 val) { return mdiobus_write_nested(priv->bus, port, regnum, val); } =20 +static int mt7530_phy_read_c45(struct mt7530_priv *priv, int port, + int devad, int regnum) +{ + return mdiobus_c45_read_nested(priv->bus, port, devad, regnum); +} + +static int mt7530_phy_write_c45(struct mt7530_priv *priv, int port, int de= vad, + int regnum, u16 val) +{ + return mdiobus_c45_write_nested(priv->bus, port, devad, regnum, val); +} + static int mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int port, int devad, int regnum) @@ -670,7 +682,7 @@ mt7531_ind_c45_phy_read(struct mt7530_priv *priv, int p= ort, int devad, =20 static int mt7531_ind_c45_phy_write(struct mt7530_priv *priv, int port, int devad, - int regnum, u32 data) + int regnum, u16 data) { struct mii_bus *bus =3D priv->bus; struct mt7530_dummy_poll p; @@ -793,55 +805,36 @@ mt7531_ind_c22_phy_write(struct mt7530_priv *priv, in= t port, int regnum, } =20 static int -mt7531_ind_phy_read(struct mt7530_priv *priv, int port, int regnum) +mt753x_phy_read_c22(struct mii_bus *bus, int port, int regnum) { - int devad; - int ret; - - if (regnum & MII_ADDR_C45) { - devad =3D (regnum >> MII_DEVADDR_C45_SHIFT) & 0x1f; - ret =3D mt7531_ind_c45_phy_read(priv, port, devad, - regnum & MII_REGADDR_C45_MASK); - } else { - ret =3D mt7531_ind_c22_phy_read(priv, port, regnum); - } + struct mt7530_priv *priv =3D bus->priv; =20 - return ret; + return priv->info->phy_read_c22(priv, port, regnum); } =20 static int -mt7531_ind_phy_write(struct mt7530_priv *priv, int port, int regnum, - u16 data) +mt753x_phy_read_c45(struct mii_bus *bus, int port, int devad, int regnum) { - int devad; - int ret; - - if (regnum & MII_ADDR_C45) { - devad =3D (regnum >> MII_DEVADDR_C45_SHIFT) & 0x1f; - ret =3D mt7531_ind_c45_phy_write(priv, port, devad, - regnum & MII_REGADDR_C45_MASK, - data); - } else { - ret =3D mt7531_ind_c22_phy_write(priv, port, regnum, data); - } + struct mt7530_priv *priv =3D bus->priv; =20 - return ret; + return priv->info->phy_read_c45(priv, port, devad, regnum); } =20 static int -mt753x_phy_read(struct mii_bus *bus, int port, int regnum) +mt753x_phy_write_c22(struct mii_bus *bus, int port, int regnum, u16 val) { struct mt7530_priv *priv =3D bus->priv; =20 - return priv->info->phy_read(priv, port, regnum); + return priv->info->phy_write_c22(priv, port, regnum, val); } =20 static int -mt753x_phy_write(struct mii_bus *bus, int port, int regnum, u16 val) +mt753x_phy_write_c45(struct mii_bus *bus, int port, int devad, int regnum, + u16 val) { struct mt7530_priv *priv =3D bus->priv; =20 - return priv->info->phy_write(priv, port, regnum, val); + return priv->info->phy_write_c45(priv, port, devad, regnum, val); } =20 static void @@ -2086,8 +2079,10 @@ mt7530_setup_mdio(struct mt7530_priv *priv) bus->priv =3D priv; bus->name =3D KBUILD_MODNAME "-mii"; snprintf(bus->id, MII_BUS_ID_SIZE, KBUILD_MODNAME "-%d", idx++); - bus->read =3D mt753x_phy_read; - bus->write =3D mt753x_phy_write; + bus->read =3D mt753x_phy_read_c22; + bus->write =3D mt753x_phy_write_c22; + bus->read_c45 =3D mt753x_phy_read_c45; + bus->write_c45 =3D mt753x_phy_write_c45; bus->parent =3D dev; bus->phy_mask =3D ~ds->phys_mii_mask; =20 @@ -3182,8 +3177,10 @@ static const struct mt753x_info mt753x_table[] =3D { .id =3D ID_MT7621, .pcs_ops =3D &mt7530_pcs_ops, .sw_setup =3D mt7530_setup, - .phy_read =3D mt7530_phy_read, - .phy_write =3D mt7530_phy_write, + .phy_read_c22 =3D mt7530_phy_read_c22, + .phy_write_c22 =3D mt7530_phy_write_c22, + .phy_read_c45 =3D mt7530_phy_read_c45, + .phy_write_c45 =3D mt7530_phy_write_c45, .pad_setup =3D mt7530_pad_clk_setup, .mac_port_get_caps =3D mt7530_mac_port_get_caps, .mac_port_config =3D mt7530_mac_config, @@ -3192,8 +3189,10 @@ static const struct mt753x_info mt753x_table[] =3D { .id =3D ID_MT7530, .pcs_ops =3D &mt7530_pcs_ops, .sw_setup =3D mt7530_setup, - .phy_read =3D mt7530_phy_read, - .phy_write =3D mt7530_phy_write, + .phy_read_c22 =3D mt7530_phy_read_c22, + .phy_write_c22 =3D mt7530_phy_write_c22, + .phy_read_c45 =3D mt7530_phy_read_c45, + .phy_write_c45 =3D mt7530_phy_write_c45, .pad_setup =3D mt7530_pad_clk_setup, .mac_port_get_caps =3D mt7530_mac_port_get_caps, .mac_port_config =3D mt7530_mac_config, @@ -3202,8 +3201,10 @@ static const struct mt753x_info mt753x_table[] =3D { .id =3D ID_MT7531, .pcs_ops =3D &mt7531_pcs_ops, .sw_setup =3D mt7531_setup, - .phy_read =3D mt7531_ind_phy_read, - .phy_write =3D mt7531_ind_phy_write, + .phy_read_c22 =3D mt7531_ind_c22_phy_read, + .phy_write_c22 =3D mt7531_ind_c22_phy_write, + .phy_read_c45 =3D mt7531_ind_c45_phy_read, + .phy_write_c45 =3D mt7531_ind_c45_phy_write, .pad_setup =3D mt7531_pad_setup, .cpu_port_config =3D mt7531_cpu_port_config, .mac_port_get_caps =3D mt7531_mac_port_get_caps, @@ -3263,7 +3264,7 @@ mt7530_probe(struct mdio_device *mdiodev) * properly. */ if (!priv->info->sw_setup || !priv->info->pad_setup || - !priv->info->phy_read || !priv->info->phy_write || + !priv->info->phy_read_c22 || !priv->info->phy_write_c22 || !priv->info->mac_port_get_caps || !priv->info->mac_port_config) return -EINVAL; diff --git a/drivers/net/dsa/mt7530.h b/drivers/net/dsa/mt7530.h index e8d966435350..6b2fc6290ea8 100644 --- a/drivers/net/dsa/mt7530.h +++ b/drivers/net/dsa/mt7530.h @@ -750,8 +750,10 @@ struct mt753x_pcs { /* struct mt753x_info - This is the main data structure for holding the sp= ecific * part for each supported device * @sw_setup: Holding the handler to a device initialization - * @phy_read: Holding the way reading PHY port - * @phy_write: Holding the way writing PHY port + * @phy_read_c22: Holding the way reading PHY port using C22 + * @phy_write_c22: Holding the way writing PHY port using C22 + * @phy_read_c45: Holding the way reading PHY port using C45 + * @phy_write_c45: Holding the way writing PHY port using C45 * @pad_setup: Holding the way setting up the bus pad for a certain * MAC port * @phy_mode_supported: Check if the PHY type is being supported on a cert= ain @@ -767,8 +769,13 @@ struct mt753x_info { const struct phylink_pcs_ops *pcs_ops; =20 int (*sw_setup)(struct dsa_switch *ds); - int (*phy_read)(struct mt7530_priv *priv, int port, int regnum); - int (*phy_write)(struct mt7530_priv *priv, int port, int regnum, u16 val); + int (*phy_read_c22)(struct mt7530_priv *priv, int port, int regnum); + int (*phy_write_c22)(struct mt7530_priv *priv, int port, int regnum, + u16 val); + int (*phy_read_c45)(struct mt7530_priv *priv, int port, int devad, + int regnum); + int (*phy_write_c45)(struct mt7530_priv *priv, int port, int devad, + int regnum, u16 val); int (*pad_setup)(struct dsa_switch *ds, phy_interface_t interface); int (*cpu_port_config)(struct dsa_switch *ds, int port); void (*mac_port_get_caps)(struct dsa_switch *ds, int port, diff --git a/include/net/dsa.h b/include/net/dsa.h index 96086289aa9b..732c7bc261a9 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -858,7 +858,7 @@ struct dsa_switch_ops { u32 (*get_phy_flags)(struct dsa_switch *ds, int port); =20 /* - * Access to the switch's PHY registers. + * Access to the switch's PHY registers. C22 only. */ int (*phy_read)(struct dsa_switch *ds, int port, int regnum); int (*phy_write)(struct dsa_switch *ds, int port, --=20 2.30.2 From nobody Thu Nov 14 07:37:56 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE635C4332F for ; Tue, 27 Dec 2022 23:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232695AbiL0XJE (ORCPT ); Tue, 27 Dec 2022 18:09:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232250AbiL0XHr (ORCPT ); Tue, 27 Dec 2022 18:07:47 -0500 Received: from mail.3ffe.de (0001.3ffe.de [IPv6:2a01:4f8:c0c:9d57::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CED1B4B8; Tue, 27 Dec 2022 15:07:32 -0800 (PST) Received: from mwalle01.sab.local (unknown [213.135.10.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.3ffe.de (Postfix) with ESMTPSA id 83AB016EE; Wed, 28 Dec 2022 00:07:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1672182450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EKyU70LpottYUIYJrXadpCxsUCc0JAs8eFsNy5YFyrM=; b=rG7WQRkFiXNO5ztABj5DEwwG5fDj3KX3yaGW1I3Twpbw482vUKEQCWfyyNvq4OGZpaVCcB dqodZKDAwtqKxRC+vbJBkH89ppIRsVHOpxA8VxX3J/h/ejVm4lkenFkyLYkIaOE9aJVh5f sYbTJ2+pSm+UCrluJEqoN5i1jrrP86PGVFOSFgPuInN0oHv9XegnoS+O63xhedzHDNjh4d YEnde4eTGX+pGQsnMqKjEYHwO5O1YubvfW1RwKIIyYBRCKg8qdSLc4Wm9MwlyM+3M3Kxdh Xf83KhAZoN7qLpplF6jwzxGMaX47BsRVk3cjbIxbChSU7i7khP6lw6ka5Qi4WQ== From: Michael Walle Date: Wed, 28 Dec 2022 00:07:28 +0100 Subject: [PATCH RFC net-next v2 12/12] net: dsa: mv88e6xxx: Separate C22 and C45 transactions MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20221227-v6-2-rc1-c45-seperation-v2-12-ddb37710e5a7@walle.cc> References: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> In-Reply-To: <20221227-v6-2-rc1-c45-seperation-v2-0-ddb37710e5a7@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jose Abreu , Sergey Shtylyov , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Sean Wang , Landen Chao , DENG Qingfang , Florian Fainelli , Vladimir Oltean , Matthias Brugger Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Andrew Lunn , Geert Uytterhoeven , Michael Walle X-Mailer: b4 0.11.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Lunn The global2 SMI MDIO bus driver can perform both C22 and C45 transfers. Create separate functions for each and register the C45 versions using the new API calls where appropriate. Update the SERDES code to make use of these new accessors. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle Reviewed-by: Vladimir Oltean --- drivers/net/dsa/mv88e6xxx/chip.c | 175 ++++++++++++++++++++++++++------= ---- drivers/net/dsa/mv88e6xxx/chip.h | 7 ++ drivers/net/dsa/mv88e6xxx/global2.c | 66 ++++++++------ drivers/net/dsa/mv88e6xxx/global2.h | 18 ++-- drivers/net/dsa/mv88e6xxx/phy.c | 32 +++++++ drivers/net/dsa/mv88e6xxx/phy.h | 4 + drivers/net/dsa/mv88e6xxx/serdes.c | 8 +- 7 files changed, 225 insertions(+), 85 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/c= hip.c index 242b8b325504..0ff9cd0be217 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -3884,6 +3884,24 @@ static int mv88e6xxx_mdio_read(struct mii_bus *bus, = int phy, int reg) return err ? err : val; } =20 +static int mv88e6xxx_mdio_read_c45(struct mii_bus *bus, int phy, int devad, + int reg) +{ + struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; + struct mv88e6xxx_chip *chip =3D mdio_bus->chip; + u16 val; + int err; + + if (!chip->info->ops->phy_read_c45) + return -EOPNOTSUPP; + + mv88e6xxx_reg_lock(chip); + err =3D chip->info->ops->phy_read_c45(chip, bus, phy, devad, reg, &val); + mv88e6xxx_reg_unlock(chip); + + return err ? err : val; +} + static int mv88e6xxx_mdio_write(struct mii_bus *bus, int phy, int reg, u16= val) { struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; @@ -3900,6 +3918,23 @@ static int mv88e6xxx_mdio_write(struct mii_bus *bus,= int phy, int reg, u16 val) return err; } =20 +static int mv88e6xxx_mdio_write_c45(struct mii_bus *bus, int phy, int deva= d, + int reg, u16 val) +{ + struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; + struct mv88e6xxx_chip *chip =3D mdio_bus->chip; + int err; + + if (!chip->info->ops->phy_write_c45) + return -EOPNOTSUPP; + + mv88e6xxx_reg_lock(chip); + err =3D chip->info->ops->phy_write_c45(chip, bus, phy, devad, reg, val); + mv88e6xxx_reg_unlock(chip); + + return err; +} + static int mv88e6xxx_mdio_register(struct mv88e6xxx_chip *chip, struct device_node *np, bool external) @@ -3938,6 +3973,8 @@ static int mv88e6xxx_mdio_register(struct mv88e6xxx_c= hip *chip, =20 bus->read =3D mv88e6xxx_mdio_read; bus->write =3D mv88e6xxx_mdio_write; + bus->read_c45 =3D mv88e6xxx_mdio_read_c45; + bus->write_c45 =3D mv88e6xxx_mdio_write_c45; bus->parent =3D chip->dev; =20 if (!external) { @@ -4149,8 +4186,10 @@ static const struct mv88e6xxx_ops mv88e6097_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6185_port_sync_link, .port_set_speed_duplex =3D mv88e6185_port_set_speed_duplex, @@ -4198,8 +4237,10 @@ static const struct mv88e6xxx_ops mv88e6123_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_speed_duplex =3D mv88e6185_port_set_speed_duplex, @@ -4279,8 +4320,10 @@ static const struct mv88e6xxx_ops mv88e6141_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -4343,8 +4386,10 @@ static const struct mv88e6xxx_ops mv88e6161_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_speed_duplex =3D mv88e6185_port_set_speed_duplex, @@ -4426,8 +4471,10 @@ static const struct mv88e6xxx_ops mv88e6171_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -4472,8 +4519,10 @@ static const struct mv88e6xxx_ops mv88e6172_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -4527,8 +4576,10 @@ static const struct mv88e6xxx_ops mv88e6175_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -4573,8 +4624,10 @@ static const struct mv88e6xxx_ops mv88e6176_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -4673,8 +4726,10 @@ static const struct mv88e6xxx_ops mv88e6190_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -4736,8 +4791,10 @@ static const struct mv88e6xxx_ops mv88e6190x_ops =3D= { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -4799,8 +4856,10 @@ static const struct mv88e6xxx_ops mv88e6191_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -4862,8 +4921,10 @@ static const struct mv88e6xxx_ops mv88e6240_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -4925,8 +4986,10 @@ static const struct mv88e6xxx_ops mv88e6250_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -4964,8 +5027,10 @@ static const struct mv88e6xxx_ops mv88e6290_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -5029,8 +5094,10 @@ static const struct mv88e6xxx_ops mv88e6320_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6320_port_set_rgmii_delay, @@ -5074,8 +5141,10 @@ static const struct mv88e6xxx_ops mv88e6321_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6320_port_set_rgmii_delay, @@ -5117,8 +5186,10 @@ static const struct mv88e6xxx_ops mv88e6341_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -5183,8 +5254,10 @@ static const struct mv88e6xxx_ops mv88e6350_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -5227,8 +5300,10 @@ static const struct mv88e6xxx_ops mv88e6351_ops =3D { .ip_pri_map =3D mv88e6085_g1_ip_pri_map, .irl_init_all =3D mv88e6352_g2_irl_init_all, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -5275,8 +5350,10 @@ static const struct mv88e6xxx_ops mv88e6352_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom16, .set_eeprom =3D mv88e6xxx_g2_set_eeprom16, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6352_port_set_rgmii_delay, @@ -5340,8 +5417,10 @@ static const struct mv88e6xxx_ops mv88e6390_ops =3D { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -5407,8 +5486,10 @@ static const struct mv88e6xxx_ops mv88e6390x_ops =3D= { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, @@ -5473,8 +5554,10 @@ static const struct mv88e6xxx_ops mv88e6393x_ops =3D= { .get_eeprom =3D mv88e6xxx_g2_get_eeprom8, .set_eeprom =3D mv88e6xxx_g2_set_eeprom8, .set_switch_mac =3D mv88e6xxx_g2_set_switch_mac, - .phy_read =3D mv88e6xxx_g2_smi_phy_read, - .phy_write =3D mv88e6xxx_g2_smi_phy_write, + .phy_read =3D mv88e6xxx_g2_smi_phy_read_c22, + .phy_write =3D mv88e6xxx_g2_smi_phy_write_c22, + .phy_read_c45 =3D mv88e6xxx_g2_smi_phy_read_c45, + .phy_write_c45 =3D mv88e6xxx_g2_smi_phy_write_c45, .port_set_link =3D mv88e6xxx_port_set_link, .port_sync_link =3D mv88e6xxx_port_sync_link, .port_set_rgmii_delay =3D mv88e6390_port_set_rgmii_delay, diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/c= hip.h index e693154cf803..751bede49942 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.h +++ b/drivers/net/dsa/mv88e6xxx/chip.h @@ -451,6 +451,13 @@ struct mv88e6xxx_ops { struct mii_bus *bus, int addr, int reg, u16 val); =20 + int (*phy_read_c45)(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int devad, int reg, u16 *val); + int (*phy_write_c45)(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int devad, int reg, u16 val); + /* Priority Override Table operations */ int (*pot_clear)(struct mv88e6xxx_chip *chip); =20 diff --git a/drivers/net/dsa/mv88e6xxx/global2.c b/drivers/net/dsa/mv88e6xx= x/global2.c index fa65ecd9cb85..ed3b2f88e783 100644 --- a/drivers/net/dsa/mv88e6xxx/global2.c +++ b/drivers/net/dsa/mv88e6xxx/global2.c @@ -739,20 +739,18 @@ static int mv88e6xxx_g2_smi_phy_read_data_c45(struct = mv88e6xxx_chip *chip, return mv88e6xxx_g2_read(chip, MV88E6XXX_G2_SMI_PHY_DATA, data); } =20 -static int mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip *chip, - bool external, int port, int reg, - u16 *data) +static int _mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip *chip, + bool external, int port, int devad, + int reg, u16 *data) { - int dev =3D (reg >> 16) & 0x1f; - int addr =3D reg & 0xffff; int err; =20 - err =3D mv88e6xxx_g2_smi_phy_write_addr_c45(chip, external, port, dev, - addr); + err =3D mv88e6xxx_g2_smi_phy_write_addr_c45(chip, external, port, devad, + reg); if (err) return err; =20 - return mv88e6xxx_g2_smi_phy_read_data_c45(chip, external, port, dev, + return mv88e6xxx_g2_smi_phy_read_data_c45(chip, external, port, devad, data); } =20 @@ -771,51 +769,65 @@ static int mv88e6xxx_g2_smi_phy_write_data_c45(struct= mv88e6xxx_chip *chip, return mv88e6xxx_g2_smi_phy_access_c45(chip, external, op, port, dev); } =20 -static int mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip *chip, - bool external, int port, int reg, - u16 data) +static int _mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip *chip, + bool external, int port, int devad, + int reg, u16 data) { - int dev =3D (reg >> 16) & 0x1f; - int addr =3D reg & 0xffff; int err; =20 - err =3D mv88e6xxx_g2_smi_phy_write_addr_c45(chip, external, port, dev, - addr); + err =3D mv88e6xxx_g2_smi_phy_write_addr_c45(chip, external, port, devad, + reg); if (err) return err; =20 - return mv88e6xxx_g2_smi_phy_write_data_c45(chip, external, port, dev, + return mv88e6xxx_g2_smi_phy_write_data_c45(chip, external, port, devad, data); } =20 -int mv88e6xxx_g2_smi_phy_read(struct mv88e6xxx_chip *chip, struct mii_bus = *bus, - int addr, int reg, u16 *val) +int mv88e6xxx_g2_smi_phy_read_c22(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int reg, u16 *val) { struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; bool external =3D mdio_bus->external; =20 - if (reg & MII_ADDR_C45) - return mv88e6xxx_g2_smi_phy_read_c45(chip, external, addr, reg, - val); - return mv88e6xxx_g2_smi_phy_read_data_c22(chip, external, addr, reg, val); } =20 -int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, struct mii_bus= *bus, - int addr, int reg, u16 val) +int mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, int addr, int devad, + int reg, u16 *val) { struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; bool external =3D mdio_bus->external; =20 - if (reg & MII_ADDR_C45) - return mv88e6xxx_g2_smi_phy_write_c45(chip, external, addr, reg, - val); + return _mv88e6xxx_g2_smi_phy_read_c45(chip, external, addr, devad, reg, + val); +} + +int mv88e6xxx_g2_smi_phy_write_c22(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, int addr, int reg, + u16 val) +{ + struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; + bool external =3D mdio_bus->external; =20 return mv88e6xxx_g2_smi_phy_write_data_c22(chip, external, addr, reg, val); } =20 +int mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, int addr, int devad, + int reg, u16 val) +{ + struct mv88e6xxx_mdio_bus *mdio_bus =3D bus->priv; + bool external =3D mdio_bus->external; + + return _mv88e6xxx_g2_smi_phy_write_c45(chip, external, addr, devad, reg, + val); +} + /* Offset 0x1B: Watchdog Control */ static int mv88e6097_watchdog_action(struct mv88e6xxx_chip *chip, int irq) { diff --git a/drivers/net/dsa/mv88e6xxx/global2.h b/drivers/net/dsa/mv88e6xx= x/global2.h index 7536b8b0ad01..e973114d6890 100644 --- a/drivers/net/dsa/mv88e6xxx/global2.h +++ b/drivers/net/dsa/mv88e6xxx/global2.h @@ -314,12 +314,18 @@ int mv88e6xxx_g2_wait_bit(struct mv88e6xxx_chip *chip= , int reg, int mv88e6352_g2_irl_init_all(struct mv88e6xxx_chip *chip, int port); int mv88e6390_g2_irl_init_all(struct mv88e6xxx_chip *chip, int port); =20 -int mv88e6xxx_g2_smi_phy_read(struct mv88e6xxx_chip *chip, - struct mii_bus *bus, - int addr, int reg, u16 *val); -int mv88e6xxx_g2_smi_phy_write(struct mv88e6xxx_chip *chip, - struct mii_bus *bus, - int addr, int reg, u16 val); +int mv88e6xxx_g2_smi_phy_read_c22(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int reg, u16 *val); +int mv88e6xxx_g2_smi_phy_write_c22(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int reg, u16 val); +int mv88e6xxx_g2_smi_phy_read_c45(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int devad, int reg, u16 *val); +int mv88e6xxx_g2_smi_phy_write_c45(struct mv88e6xxx_chip *chip, + struct mii_bus *bus, + int addr, int devad, int reg, u16 val); int mv88e6xxx_g2_set_switch_mac(struct mv88e6xxx_chip *chip, u8 *addr); =20 int mv88e6xxx_g2_get_eeprom8(struct mv88e6xxx_chip *chip, diff --git a/drivers/net/dsa/mv88e6xxx/phy.c b/drivers/net/dsa/mv88e6xxx/ph= y.c index 252b5b3a3efe..8bb88b3d900d 100644 --- a/drivers/net/dsa/mv88e6xxx/phy.c +++ b/drivers/net/dsa/mv88e6xxx/phy.c @@ -55,6 +55,38 @@ int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int= phy, int reg, u16 val) return chip->info->ops->phy_write(chip, bus, addr, reg, val); } =20 +int mv88e6xxx_phy_read_c45(struct mv88e6xxx_chip *chip, int phy, int devad, + int reg, u16 *val) +{ + int addr =3D phy; /* PHY devices addresses start at 0x0 */ + struct mii_bus *bus; + + bus =3D mv88e6xxx_default_mdio_bus(chip); + if (!bus) + return -EOPNOTSUPP; + + if (!chip->info->ops->phy_read_c45) + return -EOPNOTSUPP; + + return chip->info->ops->phy_read_c45(chip, bus, addr, devad, reg, val); +} + +int mv88e6xxx_phy_write_c45(struct mv88e6xxx_chip *chip, int phy, int deva= d, + int reg, u16 val) +{ + int addr =3D phy; /* PHY devices addresses start at 0x0 */ + struct mii_bus *bus; + + bus =3D mv88e6xxx_default_mdio_bus(chip); + if (!bus) + return -EOPNOTSUPP; + + if (!chip->info->ops->phy_write_c45) + return -EOPNOTSUPP; + + return chip->info->ops->phy_write_c45(chip, bus, addr, devad, reg, val); +} + static int mv88e6xxx_phy_page_get(struct mv88e6xxx_chip *chip, int phy, u8= page) { return mv88e6xxx_phy_write(chip, phy, MV88E6XXX_PHY_PAGE, page); diff --git a/drivers/net/dsa/mv88e6xxx/phy.h b/drivers/net/dsa/mv88e6xxx/ph= y.h index 05ea0d546969..5f47722364cc 100644 --- a/drivers/net/dsa/mv88e6xxx/phy.h +++ b/drivers/net/dsa/mv88e6xxx/phy.h @@ -28,6 +28,10 @@ int mv88e6xxx_phy_read(struct mv88e6xxx_chip *chip, int = phy, int reg, u16 *val); int mv88e6xxx_phy_write(struct mv88e6xxx_chip *chip, int phy, int reg, u16 val); +int mv88e6xxx_phy_read_c45(struct mv88e6xxx_chip *chip, int phy, int devad, + int reg, u16 *val); +int mv88e6xxx_phy_write_c45(struct mv88e6xxx_chip *chip, int phy, int deva= d, + int reg, u16 val); int mv88e6xxx_phy_page_read(struct mv88e6xxx_chip *chip, int phy, u8 page, int reg, u16 *val); int mv88e6xxx_phy_page_write(struct mv88e6xxx_chip *chip, int phy, diff --git a/drivers/net/dsa/mv88e6xxx/serdes.c b/drivers/net/dsa/mv88e6xxx= /serdes.c index d94150d8f3f4..72faec8f44dc 100644 --- a/drivers/net/dsa/mv88e6xxx/serdes.c +++ b/drivers/net/dsa/mv88e6xxx/serdes.c @@ -36,17 +36,13 @@ static int mv88e6352_serdes_write(struct mv88e6xxx_chip= *chip, int reg, static int mv88e6390_serdes_read(struct mv88e6xxx_chip *chip, int lane, int device, int reg, u16 *val) { - int reg_c45 =3D MII_ADDR_C45 | device << 16 | reg; - - return mv88e6xxx_phy_read(chip, lane, reg_c45, val); + return mv88e6xxx_phy_read_c45(chip, lane, device, reg, val); } =20 static int mv88e6390_serdes_write(struct mv88e6xxx_chip *chip, int lane, int device, int reg, u16 val) { - int reg_c45 =3D MII_ADDR_C45 | device << 16 | reg; - - return mv88e6xxx_phy_write(chip, lane, reg_c45, val); + return mv88e6xxx_phy_write_c45(chip, lane, device, reg, val); } =20 static int mv88e6xxx_serdes_pcs_get_state(struct mv88e6xxx_chip *chip, --=20 2.30.2