From patchwork Tue Dec 12 12:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 177315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp7691978vqy; Tue, 12 Dec 2023 04:38:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGmCS1Pqpxo03So8/YxYr6pBAh9ruBYOSzyYWvdOJl60fEdvPhm492Yq66Yo3NI8ONSEQ9C X-Received: by 2002:a17:902:7004:b0:1d0:6ffd:ae23 with SMTP id y4-20020a170902700400b001d06ffdae23mr2276458plk.138.1702384702379; Tue, 12 Dec 2023 04:38:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702384702; cv=none; d=google.com; s=arc-20160816; b=wFVAmTQXuYPY6ENQ7YGVNrytxTlXCgNEl/ECj/cHJU7I/OBL6VE9ead7kroHx8yNvD I4QwBpu7wDCt4qubVC/9ZFwTTBz0e0zK9RTzg6k2i5sijOuQqMjfDPPkv333uBuZ3SYR iInYf9rkmVkwriPkPuW85vcGTHD8TROYUamUmu9aVN1qaO2EW3ETSOklU6N1x6+j8OiL McNrhus6/Yc9N1H54Qe/PlLPcZ5wfNcid3a6wINPoFZoJjYt2e6qSXct3vGCsqRxQdvm 27o1o0rGPTVvhKLTZBcWiJvltCxync7hvnZx0WyUFYcVxEz783GKlVJdULcwTLwam4RF vtIg== 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=nc30ahckg68b/PDFQmmNDlUC9NcuXkQtpDFpHwacUN8=; b=bWqhkymOL2oav3UrGk00nbT15pQMn7Ay6oPpSzUKDQgqw6pYKQc8TpiASo9Z5mJQ7G FgLWyOa7mNbJriIRbezVq0ewSA1c/5eNKLOp6hVES/tFGFvD4/4EbkRV+vl0xIsCut7M id4EzyHa9nZCvI9eYKMQuwg6lbCnatR0YHWzGXxgT2MPs8w6kD/J0BEXwCIiUuLQUM7w dPEvgcCCkLiob2AR3aRhbKMP3j6MmRZX0jkyX3yFQSgYKzfaZAYBc+/mNme49nNgZGD4 pilSk7Ycmhrt6PDsbqk1QRwDprV6AwevoVI0VgNmuQQx3U15oksQ6uC8kyJnXo2kvUWD o+mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Yr1IkOEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id e5-20020a17090301c500b001b894687ec9si7327319plh.462.2023.12.12.04.38.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:38:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Yr1IkOEI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id F1F998021718; Tue, 12 Dec 2023 04:38:19 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346588AbjLLMh6 (ORCPT + 99 others); Tue, 12 Dec 2023 07:37:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346590AbjLLMhw (ORCPT ); Tue, 12 Dec 2023 07:37:52 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0A4E9; Tue, 12 Dec 2023 04:37:58 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-40c1e3ea2f2so57284845e9.2; Tue, 12 Dec 2023 04:37:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702384675; x=1702989475; 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=Yr1IkOEIgWR+zOTmWsWeJULtQ04k1yj2w/v6FzqZfDRFb4Y7oiMjgbImoiBz59zJlm rvMOG9E5FK51WNGquHKftkhRvnr3C0DaguwkqaO0devLD4bJyt7UsAjpBHoP2Ba/mUGi O3YatIyvrwQ1eJ7EKs2FS0QkM5KcrBEPHJWgC0tXTqvUka5x924VwZycSSlU/GejFJ2R R/mELJuyHAZ26Rr2tebXFNoOVSq5DVaN4pUXZ1bKt/Q3jJnPBHS53SCk0y/SubRPTVJc pq4EbDElfcqC4xwsc9y283GXjWYQsi4nQEp6XHZVk3OXpiutH0upOyx5nPpP//fRGVMP Ix+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702384675; x=1702989475; 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=JnIFimfmcnr2+Y3Rr4MQGI5clebLyKjtvgBEo1jbxq/bxZXhzZar3QuBKdsViVU/+a auhx+sTA1SjdWI1SL84vxxAXrlpVjo24TnqqYY1rbjp500nSHRGLWm+JmmbzgSja7hsH yT/OLGb4AN3W7AexkVmTL+/20SMiJYXHKmmn1hRtgKgk6ogPfhyP/Wq2O3/5T2vGh8C9 jEKMSMol4AM1skJBkokBP9Wzj8aevNrRx++In8FL+2YcXvL2stIEPkWQSOxcVYrvMRxE zfVyS4BcWn+pnFDLSss9RV2mC0OH/NnK9e/oWfFOze5uNxORHR0KKy2ch/2qaxUIH4Qh 2vvA== X-Gm-Message-State: AOJu0YzXqgXhKOPMBBnPW7m4RP0mJiv5JaQr99cWsQEE1XvGY4v4QHaO n1NpuBMKDgo0oj7TdsdSRpw4BqqIMTg= X-Received: by 2002:a7b:cb95:0:b0:40c:1946:be03 with SMTP id m21-20020a7bcb95000000b0040c1946be03mr3420933wmi.111.1702384674284; Tue, 12 Dec 2023 04:37:54 -0800 (PST) Received: from localhost.localdomain (93-34-89-13.ip49.fastwebnet.it. [93.34.89.13]) by smtp.googlemail.com with ESMTPSA id o12-20020a05600c4fcc00b0040c552a1338sm214890wmq.1.2023.12.12.04.37.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 04:37:53 -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 , Christian Marangi , "Russell King (Oracle)" , Harini Katakam , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [net-next PATCH v5 2/3] net: phy: restructure __phy_write/read_mmd to helper and phydev user Date: Tue, 12 Dec 2023 13:37:42 +0100 Message-Id: <20231212123743.29829-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231212123743.29829-1-ansuelsmth@gmail.com> References: <20231212123743.29829-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 morse.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 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 04:38:20 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785079741739998911 X-GMAIL-MSGID: 1785079741739998911 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 --- 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);