From patchwork Wed Jan 18 10:01:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Walle X-Patchwork-Id: 45163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2267264wrn; Wed, 18 Jan 2023 02:56:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFqnMKp8JwTstVoAaXLf3JPslvTcy8Q6wxXZ75NzzgQFaR78A/lI2/C3+xpGTaA649OdZH X-Received: by 2002:a17:907:7e9c:b0:86e:2c11:9bca with SMTP id qb28-20020a1709077e9c00b0086e2c119bcamr8242242ejc.30.1674039392979; Wed, 18 Jan 2023 02:56:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674039392; cv=none; d=google.com; s=arc-20160816; b=n3pldEuI++E4zWiuLXN1z4srujJgc4BnNfmii9gxEizHhtLmQ0Di39ySnGZScVy5qD fRtsbShTDDRIr2WHjb8qj87u+6zxgQpnKPh97IhjGbCK3Tj1ZPLaw3Y0TnfnyPajn5Wh TUQQzPl8ttrJr4TTa1WICaUVlVIyT5Et/f1klogzDBD6tZz55vICLkvcnF+nG1OGVUNx WLB89Fp17Mq185/U8aKpm0/H89O9k0ztE87Gdg5K3iWsAX7iawsF8lfasifixyJoZZD2 /adyb41zeZlabZi1yv5CxBWM5ajsHcxt9kz9ww16CNJYQ2cSA1XXzea6zt5BJ6cxSTmY maSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:in-reply-to:references:message-id :content-transfer-encoding:mime-version:subject:date:from :dkim-signature; bh=Bi1ar46rbvnQqsoEQKKLvDAlQMVa/GezJoHRqvFBwes=; b=aToKziBh4hWOAEiPw6F3m47O9Fr5Hmz1lMw2Gwpd2NKr/zIOyWXGydNvfLTloQ+L3/ jixkTsCysfdLbSZBpPykF9+9um5sLksanGeERMu9MPymw+Tnv6N35UYT9GN13HQOuWSJ bFzUC8/Z46Ur/KEQvLy5aNIgr5vXi8bjWqRE0I/GDyjcH1efy0yHIZG43qzZDBPhWVzD R6B5SK/ja5a1vLwXwjsuOG5mYanPF+yepCFPdRw831QANb6vp+k8JLT+mKY9yrmz+1tA soTvoa5K/Ilxtk1E7aI2UXbPdutBR6HTPYu9ISwzKqpQVNIi3NvomOcm3WOHbN0dF3FB yGpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=eunLPQUh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga8-20020a1709070c0800b00870558f5f0fsi12182089ejc.256.2023.01.18.02.56.09; Wed, 18 Jan 2023 02:56:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2022082101 header.b=eunLPQUh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=walle.cc Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbjARKzj (ORCPT + 99 others); Wed, 18 Jan 2023 05:55:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbjARKxB (ORCPT ); Wed, 18 Jan 2023 05:53:01 -0500 Received: from mail.3ffe.de (0001.3ffe.de [159.69.201.130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38F9682D75; Wed, 18 Jan 2023 02:01:46 -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 85C6E166A; Wed, 18 Jan 2023 11:01:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2022082101; t=1674036104; 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=Bi1ar46rbvnQqsoEQKKLvDAlQMVa/GezJoHRqvFBwes=; b=eunLPQUhQUsgOOtPbRzh/TpQxbKy0JOosphj29cyRTBxnl6WE7bNZULm9T+Srkk9rU8D9H K3k3teRsI1UZVX5yYZorFutpISPpQtaZ5A4DPUsP98OOkkg7G91YWjAARV3h2/74N9PqaE z3fGgZdORDa9knPUzYEnC9Z8YWtv+9pHYVB/qoQLfD9KgeLJ74bqFDsxVooJTSjPo+lI46 Supkfn+7YEmUW/9PZDkuDikNcJVWMo7NEAADbm5kIZpdA/E/0soeHhzmqncD0pTQlri6R6 160v7ljE5BjiWNEAvL6r8xe3GoH3Ypl069kmSIzMT9zldCNYJzZJxTPhfpLwSw== From: Michael Walle Date: Wed, 18 Jan 2023 11:01:35 +0100 Subject: [PATCH net-next v2 1/6] net: mdio: Move mdiobus_scan() within file MIME-Version: 1.0 Message-Id: <20230116-net-next-remove-probe-capabilities-v2-1-15513b05e1f4@walle.cc> References: <20230116-net-next-remove-probe-capabilities-v2-0-15513b05e1f4@walle.cc> In-Reply-To: <20230116-net-next-remove-probe-capabilities-v2-0-15513b05e1f4@walle.cc> To: Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , Bryan Whitehead , UNGLinuxDriver@microchip.com, Giuseppe Cavallaro , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Joel Stanley , Andrew Jeffery Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-aspeed@lists.ozlabs.org, Andrew Lunn , Michael Walle , Jesse Brandeburg X-Mailer: b4 0.11.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755357530327503475?= X-GMAIL-MSGID: =?utf-8?q?1755357530327503475?= From: Andrew Lunn No functional change, just place it earlier in preparation for some refactoring. While at it, correct the comment format and one typo. Signed-off-by: Andrew Lunn Signed-off-by: Michael Walle Reviewed-by: Jesse Brandeburg --- drivers/net/phy/mdio_bus.c | 101 ++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 902e1c88ef58..61c33c6098a1 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -506,6 +506,56 @@ static int mdiobus_create_device(struct mii_bus *bus, return ret; } +/** + * mdiobus_scan - scan a bus for MDIO devices. + * @bus: mii_bus to scan + * @addr: address on bus to scan + * + * This function scans the MDIO bus, looking for devices which can be + * identified using a vendor/product ID in registers 2 and 3. Not all + * MDIO devices have such registers, but PHY devices typically + * do. Hence this function assumes anything found is a PHY, or can be + * treated as a PHY. Other MDIO devices, such as switches, will + * probably not be found during the scan. + */ +struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) +{ + struct phy_device *phydev = ERR_PTR(-ENODEV); + int err; + + switch (bus->probe_capabilities) { + case MDIOBUS_NO_CAP: + case MDIOBUS_C22: + phydev = get_phy_device(bus, addr, false); + break; + case MDIOBUS_C45: + phydev = get_phy_device(bus, addr, true); + break; + case MDIOBUS_C22_C45: + phydev = get_phy_device(bus, addr, false); + if (IS_ERR(phydev)) + phydev = get_phy_device(bus, addr, true); + break; + } + + if (IS_ERR(phydev)) + return phydev; + + /* For DT, see if the auto-probed phy has a corresponding child + * in the bus node, and set the of_node pointer in this case. + */ + of_mdiobus_link_mdiodev(bus, &phydev->mdio); + + err = phy_device_register(phydev); + if (err) { + phy_device_free(phydev); + return ERR_PTR(-ENODEV); + } + + return phydev; +} +EXPORT_SYMBOL(mdiobus_scan); + /** * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus * @bus: target mii_bus @@ -679,57 +729,6 @@ void mdiobus_free(struct mii_bus *bus) } EXPORT_SYMBOL(mdiobus_free); -/** - * mdiobus_scan - scan a bus for MDIO devices. - * @bus: mii_bus to scan - * @addr: address on bus to scan - * - * This function scans the MDIO bus, looking for devices which can be - * identified using a vendor/product ID in registers 2 and 3. Not all - * MDIO devices have such registers, but PHY devices typically - * do. Hence this function assumes anything found is a PHY, or can be - * treated as a PHY. Other MDIO devices, such as switches, will - * probably not be found during the scan. - */ -struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr) -{ - struct phy_device *phydev = ERR_PTR(-ENODEV); - int err; - - switch (bus->probe_capabilities) { - case MDIOBUS_NO_CAP: - case MDIOBUS_C22: - phydev = get_phy_device(bus, addr, false); - break; - case MDIOBUS_C45: - phydev = get_phy_device(bus, addr, true); - break; - case MDIOBUS_C22_C45: - phydev = get_phy_device(bus, addr, false); - if (IS_ERR(phydev)) - phydev = get_phy_device(bus, addr, true); - break; - } - - if (IS_ERR(phydev)) - return phydev; - - /* - * For DT, see if the auto-probed phy has a correspoding child - * in the bus node, and set the of_node pointer in this case. - */ - of_mdiobus_link_mdiodev(bus, &phydev->mdio); - - err = phy_device_register(phydev); - if (err) { - phy_device_free(phydev); - return ERR_PTR(-ENODEV); - } - - return phydev; -} -EXPORT_SYMBOL(mdiobus_scan); - static void mdiobus_stats_acct(struct mdio_bus_stats *stats, bool op, int ret) { preempt_disable();