From patchwork Wed Apr 5 09:26:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 671067 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 8AD49C7619A for ; Wed, 5 Apr 2023 09:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237762AbjDEJac (ORCPT ); Wed, 5 Apr 2023 05:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237680AbjDEJaF (ORCPT ); Wed, 5 Apr 2023 05:30:05 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 312D25BB0 for ; Wed, 5 Apr 2023 02:29:34 -0700 (PDT) Received: from dude02.red.stw.pengutronix.de ([2a0a:edc0:0:1101:1d::28]) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1pjzPy-0004pA-Rh; Wed, 05 Apr 2023 11:27:02 +0200 From: Marco Felsch Date: Wed, 05 Apr 2023 11:26:52 +0200 Subject: [PATCH 01/12] net: phy: refactor phy_device_create function MIME-Version: 1.0 Message-Id: <20230405-net-next-topic-net-phy-reset-v1-1-7e5329f08002@pengutronix.de> References: <20230405-net-next-topic-net-phy-reset-v1-0-7e5329f08002@pengutronix.de> In-Reply-To: <20230405-net-next-topic-net-phy-reset-v1-0-7e5329f08002@pengutronix.de> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Broadcom internal kernel review list , Richard Cochran , Radu Pirea , Shyam Sundar S K , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , "Rafael J. Wysocki" , Len Brown , Rob Herring , Frank Rowand Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, devicetree@vger.kernel.org, kernel@pengutronix.de X-Mailer: b4 0.12.1 X-SA-Exim-Connect-IP: 2a0a:edc0:0:1101:1d::28 X-SA-Exim-Mail-From: m.felsch@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-acpi@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Split phy_device_create() into local helper functions. This commit is in preparation of fixing the phy reset handling. No functional changes for the public API users. Signed-off-by: Marco Felsch --- drivers/net/phy/phy_device.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c index 917ba84105fc..dd0aaa866d17 100644 --- a/drivers/net/phy/phy_device.c +++ b/drivers/net/phy/phy_device.c @@ -629,13 +629,10 @@ static int phy_request_driver_module(struct phy_device *dev, u32 phy_id) return 0; } -struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, - bool is_c45, - struct phy_c45_device_ids *c45_ids) +static struct phy_device *phy_device_alloc(struct mii_bus *bus, int addr) { struct phy_device *dev; struct mdio_device *mdiodev; - int ret = 0; /* We allocate the device, and initialize the default values */ dev = kzalloc(sizeof(*dev), GFP_KERNEL); @@ -653,6 +650,15 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, mdiodev->device_free = phy_mdio_device_free; mdiodev->device_remove = phy_mdio_device_remove; + dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); + device_initialize(&mdiodev->dev); + + return dev; +} + +static int phy_device_init(struct phy_device *dev, u32 phy_id, bool is_c45, + struct phy_c45_device_ids *c45_ids) +{ dev->speed = SPEED_UNKNOWN; dev->duplex = DUPLEX_UNKNOWN; dev->pause = 0; @@ -670,9 +676,6 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, dev->c45_ids = *c45_ids; dev->irq = bus->irq[addr]; - dev_set_name(&mdiodev->dev, PHY_ID_FMT, bus->id, addr); - device_initialize(&mdiodev->dev); - dev->state = PHY_DOWN; mutex_init(&dev->lock); @@ -690,7 +693,7 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, */ if (is_c45 && c45_ids) { const int num_ids = ARRAY_SIZE(c45_ids->device_ids); - int i; + int ret, i; for (i = 1; i < num_ids; i++) { if (c45_ids->device_ids[i] == 0xffffffff) @@ -699,14 +702,29 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, ret = phy_request_driver_module(dev, c45_ids->device_ids[i]); if (ret) - break; + return ret; } - } else { - ret = phy_request_driver_module(dev, phy_id); + + return 0; } + return phy_request_driver_module(dev, phy_id); +} + +struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id, + bool is_c45, + struct phy_c45_device_ids *c45_ids) +{ + struct phy_device *dev; + int ret; + + dev = phy_device_alloc(bus, addr); + if (IS_ERR(dev)) + return dev; + + ret = phy_device_init(dev, phy_id, is_c45, c45_ids); if (ret) { - put_device(&mdiodev->dev); + put_device(&dev->mdio.dev); dev = ERR_PTR(ret); }