Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp415280rwl; Wed, 5 Apr 2023 02:32:49 -0700 (PDT) X-Google-Smtp-Source: AKy350ZkltkAmnTvGqi3ses1zUD+BCJI3XgwARth2h4Vy9dKbhJVf3ndVfPiMyguoU8aLo2e4OUz X-Received: by 2002:a17:90a:2ac2:b0:230:ac12:a5ca with SMTP id i2-20020a17090a2ac200b00230ac12a5camr1949841pjg.3.1680687168916; Wed, 05 Apr 2023 02:32:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680687168; cv=none; d=google.com; s=arc-20160816; b=OImSKv9aZhEcB55oLAuzEysqiSwbE5cbu1XVwfosnXHsnTrBx3qyFH7hepBkR1ffZ8 Pc2dop9O7W6rd3nqWYvCf9WvA0cem36DPk1hluT2wEPuljY01oJZqpxwKsOS+iaVCial lJ23SYDy6/P6otUvB25BhSmAmPi4fMOh7bvkMEozTg3qwUOBDV9Yvdi5KFqrdmnWKNQO NhbULqMEiNPpXccoqw65mcnAVXFfTfPCcQdJK8zGtGFDy+SNJylfkb52ZOUX592Leo9O X4WV9iEybrGvE4xnbIoiETOiMxS/nSTTzr1TXzGYg/NNDgXeiPz+URAn7vdqwxzieCeu zb9Q== 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; bh=q2I1B8NEMKN/oUJpHm61WMqODeH0Vgv9ehGUz+Y4w+8=; b=dE9oW1BzuaZYkPdUA6suxXqDxPk8H0l1uorWB6fRBghGn/HxXUCEuAIsuYJ7GL+NvH GWGj9+8chCliX2s5hnUpEltzr5JMezvmOqhjb/lQBq7kZ4aSmMzoiGPc1WH9/zsO3RIF EkBWJU9fBDdIexQCitnkZzgUvax9yVrVce0HjHbDL15mWpTptcpviLxQ9vTagShkyCoo CjvFT5m0T3RGVfFFBvCAgnNMYVhCeXgDSnboWGXl75aqVv1a8N6e3VWmVT/pez66eF75 jN8OkHlzJ25AL3DmeF18AcSx0qFBSNnZGvqn6H6U1NMsK4lBQSoca60zCsRrteGUUwPM yoJw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170902d4c900b001893c960ac9si12619781plg.533.2023.04.05.02.32.30; Wed, 05 Apr 2023 02:32:48 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237765AbjDEJax (ORCPT + 99 others); Wed, 5 Apr 2023 05:30:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237736AbjDEJaT (ORCPT ); Wed, 5 Apr 2023 05:30:19 -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 57B0F59D1 for ; Wed, 5 Apr 2023 02:29:47 -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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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-kernel@vger.kernel.org X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 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); } -- 2.39.2