From patchwork Wed Dec 13 10:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 177866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7688682dys; Wed, 13 Dec 2023 02:58:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IFpLd3HJzxNoQJbSKRx0J1TRduwJFUDxmVdH1Bhjal2N7t8+/3YO/dI4KRqOtsfWlbV+pR3 X-Received: by 2002:a05:6e02:1baf:b0:35d:59a2:6901 with SMTP id n15-20020a056e021baf00b0035d59a26901mr10294458ili.46.1702465119240; Wed, 13 Dec 2023 02:58:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702465119; cv=none; d=google.com; s=arc-20160816; b=L5631D0G9MSTnN4EtII+M0jMTQ0WEK4ledJwg0hY4worRFqvFTjOdwSnCZbG0QkeIC wiusoEzSJu0+tHXdEfy/c2ulfx7UkNvWyIWydx0KdevWjN8unAMt5+pvRLXcg+lulzA9 gfqPpF4e/9qaXiq/n6Okok8PGmCuQrm4sfMIB3UlZ1DjAMGgAW7R8sIYduLGg8ThIEee 4MmgOjZAVnWkDrd5qEWd8mLe8sJvtFv1YEK7uaP9OKk7aEwml/KrZCXRJtPOAbavjQkQ NQiPCqiXKfMlYImUsyqHKIcEeCbcWQayqh12ocDZBnNcrCzrl+yNN6PWADipp4hqOWdt Iv0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=3PtocJM18WUz/9bnwDNM1XbvsGaiWt5uOf7PvLbW1SQ=; fh=e4NTAZpYxJjO9KGOmyKA8buDcaE3F5PQ5hdNGG6SGOA=; b=yduIEQWi/+KPqb+XcFH8tLmkvD1Nc9D5rF7CZN+aMLQiO6g39z+TF3+XzTg20uSdDn VDa1M+tkLSxu/gHWTIRJvv157dtUnmpcym53R9nnr7EvEXkBiMKbOZRG0HgcIwQh0abe pPEMyMYkl+YQa+O2tN1MQFcf7iS6MBonNkLHr+9Mw6feR3Celwy9gyjQu7xrC3xbtpH/ VD9sRKJF5zIw2uGmbsB4PeiC01sTH/s0eUtpA9/kYE92kvFDRnc63IMtMiI243dYvmOe z0Xpwm2o5M9BGqTrf+JBQ+Lu3kGsqlXaiCjZlcQkGWM0AOQ5Jwj8qt0VcssqDZ4s3+bB mfQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c6qAI960; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bv129-20020a632e87000000b0056a36ac322fsi9010203pgb.514.2023.12.13.02.58.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c6qAI960; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 3C9B38220131; Wed, 13 Dec 2023 02:58:29 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378325AbjLMK6S (ORCPT + 99 others); Wed, 13 Dec 2023 05:58:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235389AbjLMK6K (ORCPT ); Wed, 13 Dec 2023 05:58:10 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B427F110; Wed, 13 Dec 2023 02:58:07 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id 5b1f17b1804b1-40c1e3ea2f2so66996335e9.2; Wed, 13 Dec 2023 02:58:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702465086; x=1703069886; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=3PtocJM18WUz/9bnwDNM1XbvsGaiWt5uOf7PvLbW1SQ=; b=c6qAI960XOriwdyW/CqBexgivKhbvfULx6wpp5jy9r7jBW755QkxkBGBO2X8SzSarA YGwkbCR6Tlg5TX7+fypTATv0LZChUW+KHp6q3T/xSbBBiEdaSBXlZ2CmrxENWXCxArdf R4X6kFss1CiCOWmost9TW/zU33JUG5+J4DbVtvGHb7dzfOcY0dRiHI5HmfnPaayJ3Agv S1kP6iGkIe3lOexZ8tLp1l8I+VV38oBfijkYHpt5EPfFyzgJuWrt9qf7BQ8SPoFJGOjd 8eRAIMDWLH3LLo1A32IBnZKrsOgFsihSn28NEJtAGZmDl3uakq/WlG6RdqL5kUlG1yvZ 44/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702465086; x=1703069886; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3PtocJM18WUz/9bnwDNM1XbvsGaiWt5uOf7PvLbW1SQ=; b=QteZzSWBujUVxDsMOjPehX1BOVmdsNkzgIU7l2an6JobOE9k5HM6H/jx210GWMDHFt Ly5LoJX/OqZ9unyjZUa2TxPMKcBSgzwyeDMqjzEYQzYHpB5uOu8fSiSLRNOUSyueTnYX QlM/LSdc4sU66tnUeLMd/D/43M6rSDj7yb9pE7S5i80m3GGiduISGdrkGCrxeHuF+tJ8 PXKqQq00DfCebAy5mjymq8BW5xGbHe8hRQt9foOJ+RnJmGYIHMzPrqYabE5ZNs1JZlwR bum7GWXqVv30r8Cg3UruvvWVS+5+fhvy4HJoltB7OCBldp6ou7Xekib+kMVr8N9188Qp jtUg== X-Gm-Message-State: AOJu0YwVj6GUCWh/MD5//3N1w7eOSud+dXg6O8xha6LgpxTB2LrDY8NL BsQ/YKzbksnG6QBJdt8ZDuI= X-Received: by 2002:a7b:c419:0:b0:40b:5e1b:54a9 with SMTP id k25-20020a7bc419000000b0040b5e1b54a9mr4834446wmi.53.1702465085289; Wed, 13 Dec 2023 02:58:05 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id a11-20020a05600c348b00b0040b400711f5sm22432385wmq.7.2023.12.13.02.58.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 02:58:04 -0800 (PST) From: Christian Marangi To: Florian Fainelli , Broadcom internal kernel review list , Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Vladimir Oltean , David Epping , Harini Katakam , Christian Marangi , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v6 2/3] net: phy: restructure __phy_write/read_mmd to helper and phydev user Date: Wed, 13 Dec 2023 11:57:29 +0100 Message-Id: <20231213105730.1731-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231213105730.1731-1-ansuelsmth@gmail.com> References: <20231213105730.1731-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 13 Dec 2023 02:58:29 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785164064503724117 X-GMAIL-MSGID: 1785164064503724117 Restructure phy_write_mmd and phy_read_mmd to implement generic helper for direct mdiobus access for mmd and use these helper for phydev user. This is needed in preparation of PHY package API that requires generic access to the mdiobus and are deatched from phydev struct but instead access them based on PHY package base_addr and offsets. Signed-off-by: Christian Marangi Reviewed-by: Russell King (Oracle) --- Changes v3: - Move to phy-core.c instead of inline in phy.h Changes v2: - Introduce this patch drivers/net/phy/phy-core.c | 64 ++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 34 deletions(-) diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c index 966c93cbe616..b729ac8b2640 100644 --- a/drivers/net/phy/phy-core.c +++ b/drivers/net/phy/phy-core.c @@ -540,6 +540,28 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, devad | MII_MMD_CTRL_NOINCR); } +static int mmd_phy_read(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum) +{ + if (is_c45) + return __mdiobus_c45_read(bus, phy_addr, devad, regnum); + + mmd_phy_indirect(bus, phy_addr, devad, regnum); + /* Read the content of the MMD's selected register */ + return __mdiobus_read(bus, phy_addr, MII_MMD_DATA); +} + +static int mmd_phy_write(struct mii_bus *bus, int phy_addr, bool is_c45, + int devad, u32 regnum, u16 val) +{ + if (is_c45) + return __mdiobus_c45_write(bus, phy_addr, devad, regnum, val); + + mmd_phy_indirect(bus, phy_addr, devad, regnum); + /* Write the data into MMD's selected register */ + return __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); +} + /** * __phy_read_mmd - Convenience function for reading a register * from an MMD on a given PHY. @@ -551,26 +573,14 @@ static void mmd_phy_indirect(struct mii_bus *bus, int phy_addr, int devad, */ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum) { - int val; - if (regnum > (u16)~0 || devad > 32) return -EINVAL; - if (phydev->drv && phydev->drv->read_mmd) { - val = phydev->drv->read_mmd(phydev, devad, regnum); - } else if (phydev->is_c45) { - val = __mdiobus_c45_read(phydev->mdio.bus, phydev->mdio.addr, - devad, regnum); - } else { - struct mii_bus *bus = phydev->mdio.bus; - int phy_addr = phydev->mdio.addr; + if (phydev->drv && phydev->drv->read_mmd) + return phydev->drv->read_mmd(phydev, devad, regnum); - mmd_phy_indirect(bus, phy_addr, devad, regnum); - - /* Read the content of the MMD's selected register */ - val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA); - } - return val; + return mmd_phy_read(phydev->mdio.bus, phydev->mdio.addr, + phydev->is_c45, devad, regnum); } EXPORT_SYMBOL(__phy_read_mmd); @@ -607,28 +617,14 @@ EXPORT_SYMBOL(phy_read_mmd); */ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val) { - int ret; - if (regnum > (u16)~0 || devad > 32) return -EINVAL; - if (phydev->drv && phydev->drv->write_mmd) { - ret = phydev->drv->write_mmd(phydev, devad, regnum, val); - } else if (phydev->is_c45) { - ret = __mdiobus_c45_write(phydev->mdio.bus, phydev->mdio.addr, - devad, regnum, val); - } else { - struct mii_bus *bus = phydev->mdio.bus; - int phy_addr = phydev->mdio.addr; + if (phydev->drv && phydev->drv->write_mmd) + return phydev->drv->write_mmd(phydev, devad, regnum, val); - mmd_phy_indirect(bus, phy_addr, devad, regnum); - - /* Write the data into MMD's selected register */ - __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val); - - ret = 0; - } - return ret; + return mmd_phy_write(phydev->mdio.bus, phydev->mdio.addr, + phydev->is_c45, devad, regnum, val); } EXPORT_SYMBOL(__phy_write_mmd);