From patchwork Sun Jun 5 00:44:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ramon Fried X-Patchwork-Id: 1638962 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=JfAr21dm; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4LFyZ512mrz9s0w for ; Sun, 5 Jun 2022 10:44:43 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4CE3383E80; Sun, 5 Jun 2022 02:44:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="JfAr21dm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 80B1983E80; Sun, 5 Jun 2022 02:44:32 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 28BE183093 for ; Sun, 5 Jun 2022 02:44:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=rfried.dev@gmail.com Received: by mail-wr1-x436.google.com with SMTP id k19so15075088wrd.8 for ; Sat, 04 Jun 2022 17:44:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qW21X+s54Z1tEWBCzhA7aHgXdyLjooMDynZ99c+ysH8=; b=JfAr21dmy4bdpL5eKnJxjtXBaX/rNM7KMlJPkaV6290oztOQwP2A5TpGlII3cCfS+v DBpQF7lh+CCuqNglZMCwIdzs23MkyXcgC54FF8czWU6H3c9+xbGa6JbDJjvjhjLqjmP/ dSwnD5QcpHclEMQPHmp8lqIiWwurGQeMpmwIjVtI3Nho7+AmCd/r2XmcSSgwlwGtVU3F 38h/zqDa1wx9r4svnwSqsMFmVVZQ1gditwM6QgP/uZg5y/1Q4GQWlIg1FDLppClEK1TJ MsuAkb9uraDHBDHhYKWA0NSkAxcElRqGzXEo5VB1OnUqZBTHUyPVJzWpbXN8rPKiAZPr Gvkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qW21X+s54Z1tEWBCzhA7aHgXdyLjooMDynZ99c+ysH8=; b=3d8mRtgoBg3SXVf02fzwjB1lwrK8oNeCJ0z1EsR0kLW4dLGjIveAz7fZ88OGB3PPY+ 5dqtyOgtdK5Q7vEzmt5yTYJa0EZOBzlZRoXSMQIQoIG8YmOAV2Vfzs0fokKk7RMvjavz tMSzVxRatUPZspJ566kdFf7M3ZUfbJxKG03y/r4XGfVvDh23J9jLJpLh1NFd/BvYIgY6 FzYiuLcKz+GXzlbmZESF5GvcN58p81r7nGrTE7AEG5hs7uEnA2lmtaPWhKb0vksMDr7J 0Zi2YgXVLQJrtdzJJrGmfSGv9ZSSmJStvuDQYxes4erQmRE9Kjrf91G/ePSjRxresLhh qB8g== X-Gm-Message-State: AOAM5336y/hTpJzwPrcmvUGw7DRvh4RrAJ6mpaj7ie5bkUsJMFv7ydz+ vIxcSogWoyWDX0V6UqI2g/I= X-Google-Smtp-Source: ABdhPJyRy6A/0tnstSTrrmbChaIT0YcdknYojAG80kN34TLTAFG1iUuEFqWwy4kIjm7R3Fiqn4N5Hw== X-Received: by 2002:a5d:4344:0:b0:20c:9156:8ec with SMTP id u4-20020a5d4344000000b0020c915608ecmr15105703wrr.71.1654389866458; Sat, 04 Jun 2022 17:44:26 -0700 (PDT) Received: from mclaren.neureality.corp (82.166.25.98.fix.netvision.net.il. [82.166.25.98]) by smtp.gmail.com with ESMTPSA id o14-20020a05600c378e00b003974d0d981dsm15914202wmr.35.2022.06.04.17.44.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 17:44:25 -0700 (PDT) From: Ramon Fried To: marek.behun@nic.cz, vladimir.oltean@nxp.com, t.karthik.reddy@xilinx.com, michal.simek@amd.com, ariel.dalessandro@collabora.com, michael@amarulasolutions.com, wd@denx.de, nate.d@variscite.com, radu-nicolae.pirea@oss.nxp.com, u-boot@lists.denx.de, rasmus.villemoes@prevas.dk Cc: Ramon Fried Subject: [PATCH] net: phy: Remove inline definitions from convinience functions Date: Sun, 5 Jun 2022 03:44:15 +0300 Message-Id: <20220605004415.2933536-1-rfried.dev@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean The convinience functions are not that small and they caused bloated text segments because of their usage. There was no need to inline them in the first place, as they're not part of a fastpath. Signed-off-by: Ramon Fried Reviewed-by: Michael Trimarchi Reviewed-by: Marek BehĂșn Reviewed-by: Vladimir Oltean --- drivers/net/phy/phy.c | 174 ++++++++++++++++++++++++++++++++++++++ include/phy.h | 189 ++---------------------------------------- 2 files changed, 183 insertions(+), 180 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 1121b99abf..e6e1755518 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1101,3 +1101,177 @@ int phy_modify(struct phy_device *phydev, int devad, int regnum, u16 mask, return phy_write(phydev, devad, regnum, (ret & ~mask) | set); } + +/** + * phy_read - Convenience function for reading a given PHY register + * @phydev: the phy_device struct + * @devad: The MMD to read from + * @regnum: register number to read + * @return: value for success or negative errno for failure + */ +int phy_read(struct phy_device *phydev, int devad, int regnum) +{ + struct mii_dev *bus = phydev->bus; + + if (!bus || !bus->read) { + debug("%s: No bus configured\n", __func__); + return -1; + } + + return bus->read(bus, phydev->addr, devad, regnum); +} + +/** + * phy_write - Convenience function for writing a given PHY register + * @phydev: the phy_device struct + * @devad: The MMD to read from + * @regnum: register number to write + * @val: value to write to @regnum + * @return: 0 for success or negative errno for failure + */ +int phy_write(struct phy_device *phydev, int devad, int regnum, u16 val) +{ + struct mii_dev *bus = phydev->bus; + + if (!bus || !bus->write) { + debug("%s: No bus configured\n", __func__); + return -1; + } + + return bus->write(bus, phydev->addr, devad, regnum, val); +} + +/** + * phy_mmd_start_indirect - Convenience function for writing MMD registers + * @phydev: the phy_device struct + * @devad: The MMD to read from + * @regnum: register number to write + * @return: None + */ +void phy_mmd_start_indirect(struct phy_device *phydev, int devad, int regnum) +{ + /* Write the desired MMD Devad */ + phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, devad); + + /* Write the desired MMD register address */ + phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, regnum); + + /* Select the Function : DATA with no post increment */ + phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, + (devad | MII_MMD_CTRL_NOINCR)); +} + +/** + * phy_read_mmd - Convenience function for reading a register + * from an MMD on a given PHY. + * @phydev: The phy_device struct + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * @return: Value for success or negative errno for failure + */ +int phy_read_mmd(struct phy_device *phydev, int devad, int regnum) +{ + struct phy_driver *drv = phydev->drv; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + /* driver-specific access */ + if (drv->read_mmd) + return drv->read_mmd(phydev, devad, regnum); + + /* direct C45 / C22 access */ + if ((drv->features & PHY_10G_FEATURES) == PHY_10G_FEATURES || + devad == MDIO_DEVAD_NONE || !devad) + return phy_read(phydev, devad, regnum); + + /* indirect C22 access */ + phy_mmd_start_indirect(phydev, devad, regnum); + + /* Read the content of the MMD's selected register */ + return phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA); +} + +/** + * phy_write_mmd - Convenience function for writing a register + * on an MMD on a given PHY. + * @phydev: The phy_device struct + * @devad: The MMD to read from + * @regnum: The register on the MMD to read + * @val: value to write to @regnum + * @return: 0 for success or negative errno for failure + */ +int phy_write_mmd(struct phy_device *phydev, int devad, int regnum, u16 val) +{ + struct phy_driver *drv = phydev->drv; + + if (regnum > (u16)~0 || devad > 32) + return -EINVAL; + + /* driver-specific access */ + if (drv->write_mmd) + return drv->write_mmd(phydev, devad, regnum, val); + + /* direct C45 / C22 access */ + if ((drv->features & PHY_10G_FEATURES) == PHY_10G_FEATURES || + devad == MDIO_DEVAD_NONE || !devad) + return phy_write(phydev, devad, regnum, val); + + /* indirect C22 access */ + phy_mmd_start_indirect(phydev, devad, regnum); + + /* Write the data into MMD's selected register */ + return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val); +} + +/** + * phy_set_bits_mmd - Convenience function for setting bits in a register + * on MMD + * @phydev: the phy_device struct + * @devad: the MMD containing register to modify + * @regnum: register number to modify + * @val: bits to set + * @return: 0 for success or negative errno for failure + */ +int phy_set_bits_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) +{ + int value, ret; + + value = phy_read_mmd(phydev, devad, regnum); + if (value < 0) + return value; + + value |= val; + + ret = phy_write_mmd(phydev, devad, regnum, value); + if (ret < 0) + return ret; + + return 0; +} + +/** + * phy_clear_bits_mmd - Convenience function for clearing bits in a register + * on MMD + * @phydev: the phy_device struct + * @devad: the MMD containing register to modify + * @regnum: register number to modify + * @val: bits to clear + * @return: 0 for success or negative errno for failure + */ +int phy_clear_bits_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) +{ + int value, ret; + + value = phy_read_mmd(phydev, devad, regnum); + if (value < 0) + return value; + + value &= ~val; + + ret = phy_write_mmd(phydev, devad, regnum, value); + if (ret < 0) + return ret; + + return 0; +} diff --git a/include/phy.h b/include/phy.h index b329595710..ad2096ca84 100644 --- a/include/phy.h +++ b/include/phy.h @@ -177,186 +177,6 @@ struct fixed_link { int asym_pause; }; -/** - * phy_read - Convenience function for reading a given PHY register - * @phydev: the phy_device struct - * @devad: The MMD to read from - * @regnum: register number to read - * @return: value for success or negative errno for failure - */ -static inline int phy_read(struct phy_device *phydev, int devad, int regnum) -{ - struct mii_dev *bus = phydev->bus; - - if (!bus || !bus->read) { - debug("%s: No bus configured\n", __func__); - return -1; - } - - return bus->read(bus, phydev->addr, devad, regnum); -} - -/** - * phy_write - Convenience function for writing a given PHY register - * @phydev: the phy_device struct - * @devad: The MMD to read from - * @regnum: register number to write - * @val: value to write to @regnum - * @return: 0 for success or negative errno for failure - */ -static inline int phy_write(struct phy_device *phydev, int devad, int regnum, - u16 val) -{ - struct mii_dev *bus = phydev->bus; - - if (!bus || !bus->write) { - debug("%s: No bus configured\n", __func__); - return -1; - } - - return bus->write(bus, phydev->addr, devad, regnum, val); -} - -/** - * phy_mmd_start_indirect - Convenience function for writing MMD registers - * @phydev: the phy_device struct - * @devad: The MMD to read from - * @regnum: register number to write - * @return: None - */ -static inline void phy_mmd_start_indirect(struct phy_device *phydev, int devad, - int regnum) -{ - /* Write the desired MMD Devad */ - phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, devad); - - /* Write the desired MMD register address */ - phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, regnum); - - /* Select the Function : DATA with no post increment */ - phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_CTRL, - (devad | MII_MMD_CTRL_NOINCR)); -} - -/** - * phy_read_mmd - Convenience function for reading a register - * from an MMD on a given PHY. - * @phydev: The phy_device struct - * @devad: The MMD to read from - * @regnum: The register on the MMD to read - * @return: Value for success or negative errno for failure - */ -static inline int phy_read_mmd(struct phy_device *phydev, int devad, - int regnum) -{ - struct phy_driver *drv = phydev->drv; - - if (regnum > (u16)~0 || devad > 32) - return -EINVAL; - - /* driver-specific access */ - if (drv->read_mmd) - return drv->read_mmd(phydev, devad, regnum); - - /* direct C45 / C22 access */ - if ((drv->features & PHY_10G_FEATURES) == PHY_10G_FEATURES || - devad == MDIO_DEVAD_NONE || !devad) - return phy_read(phydev, devad, regnum); - - /* indirect C22 access */ - phy_mmd_start_indirect(phydev, devad, regnum); - - /* Read the content of the MMD's selected register */ - return phy_read(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA); -} - -/** - * phy_write_mmd - Convenience function for writing a register - * on an MMD on a given PHY. - * @phydev: The phy_device struct - * @devad: The MMD to read from - * @regnum: The register on the MMD to read - * @val: value to write to @regnum - * @return: 0 for success or negative errno for failure - */ -static inline int phy_write_mmd(struct phy_device *phydev, int devad, - int regnum, u16 val) -{ - struct phy_driver *drv = phydev->drv; - - if (regnum > (u16)~0 || devad > 32) - return -EINVAL; - - /* driver-specific access */ - if (drv->write_mmd) - return drv->write_mmd(phydev, devad, regnum, val); - - /* direct C45 / C22 access */ - if ((drv->features & PHY_10G_FEATURES) == PHY_10G_FEATURES || - devad == MDIO_DEVAD_NONE || !devad) - return phy_write(phydev, devad, regnum, val); - - /* indirect C22 access */ - phy_mmd_start_indirect(phydev, devad, regnum); - - /* Write the data into MMD's selected register */ - return phy_write(phydev, MDIO_DEVAD_NONE, MII_MMD_DATA, val); -} - -/** - * phy_set_bits_mmd - Convenience function for setting bits in a register - * on MMD - * @phydev: the phy_device struct - * @devad: the MMD containing register to modify - * @regnum: register number to modify - * @val: bits to set - * @return: 0 for success or negative errno for failure - */ -static inline int phy_set_bits_mmd(struct phy_device *phydev, int devad, - u32 regnum, u16 val) -{ - int value, ret; - - value = phy_read_mmd(phydev, devad, regnum); - if (value < 0) - return value; - - value |= val; - - ret = phy_write_mmd(phydev, devad, regnum, value); - if (ret < 0) - return ret; - - return 0; -} - -/** - * phy_clear_bits_mmd - Convenience function for clearing bits in a register - * on MMD - * @phydev: the phy_device struct - * @devad: the MMD containing register to modify - * @regnum: register number to modify - * @val: bits to clear - * @return: 0 for success or negative errno for failure - */ -static inline int phy_clear_bits_mmd(struct phy_device *phydev, int devad, - u32 regnum, u16 val) -{ - int value, ret; - - value = phy_read_mmd(phydev, devad, regnum); - if (value < 0) - return value; - - value &= ~val; - - ret = phy_write_mmd(phydev, devad, regnum, value); - if (ret < 0) - return ret; - - return 0; -} - #ifdef CONFIG_PHYLIB_10G extern struct phy_driver gen10g_driver; #endif @@ -508,6 +328,15 @@ static inline ofnode phy_get_ofnode(struct phy_device *phydev) return ofnode_null(); } #endif + +int phy_read(struct phy_device *phydev, int devad, int regnum); +int phy_write(struct phy_device *phydev, int devad, int regnum, u16 val); +void phy_mmd_start_indirect(struct phy_device *phydev, int devad, int regnum); +int phy_read_mmd(struct phy_device *phydev, int devad, int regnum); +int phy_write_mmd(struct phy_device *phydev, int devad, int regnum, u16 val); +int phy_set_bits_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val); +int phy_clear_bits_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val); + int phy_startup(struct phy_device *phydev); int phy_config(struct phy_device *phydev); int phy_shutdown(struct phy_device *phydev);