Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp2609840ybt; Mon, 22 Jun 2020 02:45:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwR8x8VvBv2voy7dVBVBejjnads2PVmJQWCM9e9Cwi7ReDW/S9fhG1ovk0kWLofnsdw8BIu X-Received: by 2002:a05:6402:3044:: with SMTP id bu4mr16117372edb.69.1592819150626; Mon, 22 Jun 2020 02:45:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592819150; cv=none; d=google.com; s=arc-20160816; b=oa7IooP0GOr6eFtuA9np83ScGn+/PLIc0TAhViVO8RODVl3CGVAAhZ6AC2k0DFvP3V YFABXxWIqM6zF/OzKSkZsdy/zMuZ7haie3FIOyFN9w9xiTRXX5HTfIF934l9QbNu0j/N +65G0s4uHCYx6rnnkkxBhDem4BKlIhFoof3h8sVQ7n+P/dFSy067Pcz5j2LrrWTu67Dw PjBpoRjBEOYk4w0FtFvK9b5iJhjxkJkAXYYgfIWFbY22NYvLF2C1LMvdzjRf4RLIResY lc45PH3M9I6re2WTfrW5hPSH0vjkXRBbhWDas9FZAdJk2LmYrvXIJXlhETxMaF8f95ox 443w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=GfxRtzTQEG/5B2vcAI0+WR3x7R55kmvGCSrvKLTEK2Q=; b=loeppEyDNzPh4gvXcFyHDK0eoe1+OCgD+MkrvRv5nh3C3PxZX6fDKfetqz6H6uVHFY znICZfgPtVgezDhJxd9wuTcjdipwiStH32Z9bxyfZcrLV/MrMd6NVQ4/6W7RdKgfQHxS MqSNyHklyp64jylIro5ItD0u5xNc5Xf1kdO5nnyON6hnAqULCn/MeGiG7G2+GtglTh8A SIfVa6jD3lw9+R3ZR6agTYiUXnPdC8Vek1HtJBBla3gRKYOpNQxaSyH4QSb5jUCj+TfB kLOcyUmFCIcpps5kIri7zPA6D6+nbguwAY8COxqEg1Nj3DwNnLoIxoUh+WDAgtikODjo TDwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=A0YsIPLN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p26si3685288eji.592.2020.06.22.02.45.28; Mon, 22 Jun 2020 02:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=A0YsIPLN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727959AbgFVJmx (ORCPT + 99 others); Mon, 22 Jun 2020 05:42:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727098AbgFVJlh (ORCPT ); Mon, 22 Jun 2020 05:41:37 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6BCCC061797 for ; Mon, 22 Jun 2020 02:41:35 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id b6so15932740wrs.11 for ; Mon, 22 Jun 2020 02:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GfxRtzTQEG/5B2vcAI0+WR3x7R55kmvGCSrvKLTEK2Q=; b=A0YsIPLNyYjq0ssEvXKicqSfckLBHv0GVryALC9d+AV98+m0KCKKpxY0AwyeTaC/SV 4ewNSwSYjUQsP4yxHm8UWF9gryWmZ5NreLHL6eNRWjMmIjJRCWiNutTjs4Dj5nQbR/al xKYExJnhmZzF3ijNBmLN0+9cPyr9XfVrG4iIqj5hbRDxQ5onbhon50y62e0SSGhWhkuw rmocxlBQDpuSpCL4KghX633TaDScTSjnEqyd5R5g43WJlC81zN4EIN3Bn8mQId8I8MeF 8+2wsc96b1npN8idQoXobDeawhU/GfrNBYEANPkdYosOat1y3XLGX18/UsW4P4z0HqDS YNGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GfxRtzTQEG/5B2vcAI0+WR3x7R55kmvGCSrvKLTEK2Q=; b=dHcZtCdtR2ppS7xruof1XHxfF1v8us7hZM3cG4mbLDqMHwzrhiuy9gSBVPvEwa69Zv 00PwXnHznTz2GVXKhdmvlMMnWVAlXjOE+JnhVCikwdNAAFnHVge3bsecbmY98/rdDXP9 1KA3dCav1RpDQv6Y62a6PiEtm5xVUZPyV6p0zQwBMKUWruoxzpGq+SRLpnzjBhs3dp5t nbkcAQ2YJa9l5s91ntC5poNMtzxWv7Vri1Ah0QQlSGo4Ffj94Zs6cCyZXninmAAO0xVu Sv0aC/hl1GUXsTA4odew7WcDZgSCZbWrfJ6kgHiaCrXyO2CfgerYFfxYCUcURsUo08Tj qs7w== X-Gm-Message-State: AOAM530LnJFKmJMXPQmwUp9xKWXobFCfO0PQ9Ptmd2IGuhSim3P9m8s8 45SW3ggPzdvPcu22U9F4/l6n9A== X-Received: by 2002:a5d:4bd2:: with SMTP id l18mr400661wrt.119.1592818894547; Mon, 22 Jun 2020 02:41:34 -0700 (PDT) Received: from localhost.localdomain (lfbn-nic-1-65-232.w2-15.abo.wanadoo.fr. [2.15.156.232]) by smtp.gmail.com with ESMTPSA id j24sm14392652wrd.43.2020.06.22.02.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 02:41:34 -0700 (PDT) From: Bartosz Golaszewski To: Andrew Lunn , Florian Fainelli , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Rob Herring , Matthias Brugger , Microchip Linux Driver Support , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , Vivien Didelot , Tom Lendacky , Yisen Zhuang , Salil Mehta , Jassi Brar , Ilias Apalodimas , Iyappan Subramanian , Keyur Chudgar , Quan Nguyen , Frank Rowand , Philipp Zabel , Liam Girdwood , Mark Brown Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Fabien Parent , Stephane Le Provost , Pedro Tsai , Andrew Perepech , Bartosz Golaszewski Subject: [PATCH 07/15] net: phy: split out the PHY driver request out of phy_device_create() Date: Mon, 22 Jun 2020 11:37:36 +0200 Message-Id: <20200622093744.13685-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200622093744.13685-1-brgl@bgdev.pl> References: <20200622093744.13685-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski 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 --- 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