[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200622093744.13685-8-brgl@bgdev.pl>
Date: Mon, 22 Jun 2020 11:37:36 +0200
From: Bartosz Golaszewski <brgl@...ev.pl>
To: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Heiner Kallweit <hkallweit1@...il.com>,
Russell King <linux@...linux.org.uk>,
"David S . Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Rob Herring <robh+dt@...nel.org>,
Matthias Brugger <matthias.bgg@...il.com>,
Microchip Linux Driver Support <UNGLinuxDriver@...rochip.com>,
Vladimir Oltean <vladimir.oltean@....com>,
Claudiu Manoil <claudiu.manoil@....com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Vivien Didelot <vivien.didelot@...il.com>,
Tom Lendacky <thomas.lendacky@....com>,
Yisen Zhuang <yisen.zhuang@...wei.com>,
Salil Mehta <salil.mehta@...wei.com>,
Jassi Brar <jaswinder.singh@...aro.org>,
Ilias Apalodimas <ilias.apalodimas@...aro.org>,
Iyappan Subramanian <iyappan@...amperecomputing.com>,
Keyur Chudgar <keyur@...amperecomputing.com>,
Quan Nguyen <quan@...amperecomputing.com>,
Frank Rowand <frowand.list@...il.com>,
Philipp Zabel <p.zabel@...gutronix.de>,
Liam Girdwood <lgirdwood@...il.com>,
Mark Brown <broonie@...nel.org>
Cc: netdev@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org,
Fabien Parent <fparent@...libre.com>,
Stephane Le Provost <stephane.leprovost@...iatek.com>,
Pedro Tsai <pedro.tsai@...iatek.com>,
Andrew Perepech <andrew.perepech@...iatek.com>,
Bartosz Golaszewski <bgolaszewski@...libre.com>
Subject: [PATCH 07/15] net: phy: split out the PHY driver request out of phy_device_create()
From: Bartosz Golaszewski <bgolaszewski@...libre.com>
Move the code requesting the PHY driver module out of phy_device_create()
into a separate helper. This will be later reused when we delay the
module loading.
Signed-off-by: Bartosz Golaszewski <bgolaszewski@...libre.com>
---
drivers/net/phy/phy_device.c | 71 ++++++++++++++++++++----------------
1 file changed, 39 insertions(+), 32 deletions(-)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index f6985db08340..8037a9663a85 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -558,7 +558,7 @@ static const struct device_type mdio_bus_phy_type = {
.pm = MDIO_BUS_PHY_PM_OPS,
};
-static int phy_request_driver_module(struct phy_device *dev, u32 phy_id)
+static int phy_do_request_driver_module(struct phy_device *dev, u32 phy_id)
{
int ret;
@@ -578,6 +578,40 @@ static int phy_request_driver_module(struct phy_device *dev, u32 phy_id)
return 0;
}
+static int phy_request_driver_module(struct phy_device *phydev)
+{
+ int ret;
+
+ /* Request the appropriate module unconditionally; don't
+ * bother trying to do so only if it isn't already loaded,
+ * because that gets complicated. A hotplug event would have
+ * done an unconditional modprobe anyway.
+ * We don't do normal hotplug because it won't work for MDIO
+ * -- because it relies on the device staying around for long
+ * enough for the driver to get loaded. With MDIO, the NIC
+ * driver will get bored and give up as soon as it finds that
+ * there's no driver _already_ loaded.
+ */
+ if (phydev->is_c45) {
+ const int num_ids = ARRAY_SIZE(phydev->c45_ids.device_ids);
+ int i;
+
+ for (i = 1; i < num_ids; i++) {
+ if (phydev->c45_ids.device_ids[i] == 0xffffffff)
+ continue;
+
+ ret = phy_do_request_driver_module(phydev,
+ phydev->c45_ids.device_ids[i]);
+ if (ret)
+ break;
+ }
+ } else {
+ ret = phy_do_request_driver_module(phydev, phydev->phy_id);
+ }
+
+ return ret;
+}
+
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)
@@ -622,38 +656,11 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, u32 phy_id,
mutex_init(&dev->lock);
INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine);
+ device_initialize(&mdiodev->dev);
- /* Request the appropriate module unconditionally; don't
- * bother trying to do so only if it isn't already loaded,
- * because that gets complicated. A hotplug event would have
- * done an unconditional modprobe anyway.
- * We don't do normal hotplug because it won't work for MDIO
- * -- because it relies on the device staying around for long
- * enough for the driver to get loaded. With MDIO, the NIC
- * driver will get bored and give up as soon as it finds that
- * there's no driver _already_ loaded.
- */
- if (is_c45 && c45_ids) {
- const int num_ids = ARRAY_SIZE(c45_ids->device_ids);
- int i;
-
- for (i = 1; i < num_ids; i++) {
- if (c45_ids->device_ids[i] == 0xffffffff)
- continue;
-
- ret = phy_request_driver_module(dev,
- c45_ids->device_ids[i]);
- if (ret)
- break;
- }
- } else {
- ret = phy_request_driver_module(dev, phy_id);
- }
-
- if (!ret) {
- device_initialize(&mdiodev->dev);
- } else {
- kfree(dev);
+ ret = phy_request_driver_module(dev);
+ if (ret) {
+ phy_device_free(dev);
dev = ERR_PTR(ret);
}
--
2.26.1
Powered by blists - more mailing lists