public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Russell King <rmk+kernel@armlinux•org.uk>
To: Andrew Lunn <andrew@lunn•ch>, Florian Fainelli <f.fainelli@gmail•com>
Cc: netdev@vger•kernel.org
Subject: [PATCH 4/6] net: phy: split out 10G genphy support
Date: Mon, 05 Jun 2017 12:23:05 +0100	[thread overview]
Message-ID: <E1dHq6D-0005X7-Ri@rmk-PC.armlinux.org.uk> (raw)
In-Reply-To: <20170605112203.GA10680@n2100.armlinux.org.uk>

Move the old 10G genphy support to sit beside the new clause 45 library
functions, so all the 10G phy code is together.

Reviewed-by: Andrew Lunn <andrew@lunn•ch>
Reviewed-by: Florian Fainelli <f.fainelli@gmail•com>
Signed-off-by: Russell King <rmk+kernel@armlinux•org.uk>
---
 drivers/net/phy/phy-c45.c    |  64 ++++++++++++++++++++++++++
 drivers/net/phy/phy_device.c | 105 ++++++++-----------------------------------
 2 files changed, 83 insertions(+), 86 deletions(-)

diff --git a/drivers/net/phy/phy-c45.c b/drivers/net/phy/phy-c45.c
index d311d6e6141c..dada819c6b78 100644
--- a/drivers/net/phy/phy-c45.c
+++ b/drivers/net/phy/phy-c45.c
@@ -232,3 +232,67 @@ int genphy_c45_read_pma(struct phy_device *phydev)
 	return 0;
 }
 EXPORT_SYMBOL_GPL(genphy_c45_read_pma);
+
+/* The gen10g_* functions are the old Clause 45 stub */
+
+static int gen10g_config_aneg(struct phy_device *phydev)
+{
+	return 0;
+}
+
+static int gen10g_read_status(struct phy_device *phydev)
+{
+	u32 mmd_mask = phydev->c45_ids.devices_in_package;
+	int ret;
+
+	/* For now just lie and say it's 10G all the time */
+	phydev->speed = SPEED_10000;
+	phydev->duplex = DUPLEX_FULL;
+
+	/* Avoid reading the vendor MMDs */
+	mmd_mask &= ~(BIT(MDIO_MMD_VEND1) | BIT(MDIO_MMD_VEND2));
+
+	ret = genphy_c45_read_link(phydev, mmd_mask);
+
+	phydev->link = ret > 0 ? 1 : 0;
+
+	return 0;
+}
+
+static int gen10g_soft_reset(struct phy_device *phydev)
+{
+	/* Do nothing for now */
+	return 0;
+}
+
+static int gen10g_config_init(struct phy_device *phydev)
+{
+	/* Temporarily just say we support everything */
+	phydev->supported = SUPPORTED_10000baseT_Full;
+	phydev->advertising = SUPPORTED_10000baseT_Full;
+
+	return 0;
+}
+
+static int gen10g_suspend(struct phy_device *phydev)
+{
+	return 0;
+}
+
+static int gen10g_resume(struct phy_device *phydev)
+{
+	return 0;
+}
+
+struct phy_driver genphy_10g_driver = {
+	.phy_id         = 0xffffffff,
+	.phy_id_mask    = 0xffffffff,
+	.name           = "Generic 10G PHY",
+	.soft_reset	= gen10g_soft_reset,
+	.config_init    = gen10g_config_init,
+	.features       = 0,
+	.config_aneg    = gen10g_config_aneg,
+	.read_status    = gen10g_read_status,
+	.suspend        = gen10g_suspend,
+	.resume         = gen10g_resume,
+};
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 6a79e24fa312..acf00f071c9a 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -69,13 +69,8 @@ static void phy_mdio_device_remove(struct mdio_device *mdiodev)
 	phy_device_remove(phydev);
 }
 
-enum genphy_driver {
-	GENPHY_DRV_1G,
-	GENPHY_DRV_10G,
-	GENPHY_DRV_MAX
-};
-
-static struct phy_driver genphy_driver[GENPHY_DRV_MAX];
+static struct phy_driver genphy_driver;
+extern struct phy_driver genphy_10g_driver;
 
 static LIST_HEAD(phy_fixup_list);
 static DEFINE_MUTEX(phy_fixup_lock);
@@ -928,11 +923,9 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
 	 */
 	if (!d->driver) {
 		if (phydev->is_c45)
-			d->driver =
-				&genphy_driver[GENPHY_DRV_10G].mdiodrv.driver;
+			d->driver = &genphy_10g_driver.mdiodrv.driver;
 		else
-			d->driver =
-				&genphy_driver[GENPHY_DRV_1G].mdiodrv.driver;
+			d->driver = &genphy_driver.mdiodrv.driver;
 
 		using_genphy = true;
 	}
@@ -1069,7 +1062,6 @@ void phy_detach(struct phy_device *phydev)
 	struct net_device *dev = phydev->attached_dev;
 	struct module *ndev_owner = dev->dev.parent->driver->owner;
 	struct mii_bus *bus;
-	int i;
 
 	if (phydev->sysfs_links) {
 		sysfs_remove_link(&dev->dev.kobj, "phydev");
@@ -1088,13 +1080,9 @@ void phy_detach(struct phy_device *phydev)
 	 * from the generic driver so that there's a chance a
 	 * real driver could be loaded
 	 */
-	for (i = 0; i < ARRAY_SIZE(genphy_driver); i++) {
-		if (phydev->mdio.dev.driver ==
-		    &genphy_driver[i].mdiodrv.driver) {
-			device_release_driver(&phydev->mdio.dev);
-			break;
-		}
-	}
+	if (phydev->mdio.dev.driver == &genphy_10g_driver.mdiodrv.driver ||
+	    phydev->mdio.dev.driver == &genphy_driver.mdiodrv.driver)
+		device_release_driver(&phydev->mdio.dev);
 
 	/*
 	 * The phydev might go away on the put_device() below, so avoid
@@ -1368,11 +1356,6 @@ int genphy_aneg_done(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_aneg_done);
 
-static int gen10g_config_aneg(struct phy_device *phydev)
-{
-	return 0;
-}
-
 /**
  * genphy_update_link - update link status in @phydev
  * @phydev: target phy_device struct
@@ -1506,25 +1489,6 @@ int genphy_read_status(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_read_status);
 
-static int gen10g_read_status(struct phy_device *phydev)
-{
-	u32 mmd_mask = phydev->c45_ids.devices_in_package;
-	int ret;
-
-	/* For now just lie and say it's 10G all the time */
-	phydev->speed = SPEED_10000;
-	phydev->duplex = DUPLEX_FULL;
-
-	/* Avoid reading the vendor MMDs */
-	mmd_mask &= ~(BIT(MDIO_MMD_VEND1) | BIT(MDIO_MMD_VEND2));
-
-	ret = genphy_c45_read_link(phydev, mmd_mask);
-
-	phydev->link = ret > 0 ? 1 : 0;
-
-	return 0;
-}
-
 /**
  * genphy_soft_reset - software reset the PHY via BMCR_RESET bit
  * @phydev: target phy_device struct
@@ -1590,21 +1554,6 @@ int genphy_config_init(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_config_init);
 
-static int gen10g_soft_reset(struct phy_device *phydev)
-{
-	/* Do nothing for now */
-	return 0;
-}
-
-static int gen10g_config_init(struct phy_device *phydev)
-{
-	/* Temporarily just say we support everything */
-	phydev->supported = SUPPORTED_10000baseT_Full;
-	phydev->advertising = SUPPORTED_10000baseT_Full;
-
-	return 0;
-}
-
 int genphy_suspend(struct phy_device *phydev)
 {
 	int value;
@@ -1620,11 +1569,6 @@ int genphy_suspend(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_suspend);
 
-static int gen10g_suspend(struct phy_device *phydev)
-{
-	return 0;
-}
-
 int genphy_resume(struct phy_device *phydev)
 {
 	int value;
@@ -1640,11 +1584,6 @@ int genphy_resume(struct phy_device *phydev)
 }
 EXPORT_SYMBOL(genphy_resume);
 
-static int gen10g_resume(struct phy_device *phydev)
-{
-	return 0;
-}
-
 static int __set_phy_supported(struct phy_device *phydev, u32 max_speed)
 {
 	/* The default values for phydev->supported are provided by the PHY
@@ -1876,8 +1815,7 @@ void phy_drivers_unregister(struct phy_driver *drv, int n)
 }
 EXPORT_SYMBOL(phy_drivers_unregister);
 
-static struct phy_driver genphy_driver[] = {
-{
+static struct phy_driver genphy_driver = {
 	.phy_id		= 0xffffffff,
 	.phy_id_mask	= 0xffffffff,
 	.name		= "Generic PHY",
@@ -1891,18 +1829,7 @@ static struct phy_driver genphy_driver[] = {
 	.read_status	= genphy_read_status,
 	.suspend	= genphy_suspend,
 	.resume		= genphy_resume,
-}, {
-	.phy_id         = 0xffffffff,
-	.phy_id_mask    = 0xffffffff,
-	.name           = "Generic 10G PHY",
-	.soft_reset	= gen10g_soft_reset,
-	.config_init    = gen10g_config_init,
-	.features       = 0,
-	.config_aneg    = gen10g_config_aneg,
-	.read_status    = gen10g_read_status,
-	.suspend        = gen10g_suspend,
-	.resume         = gen10g_resume,
-} };
+};
 
 static int __init phy_init(void)
 {
@@ -1912,18 +1839,24 @@ static int __init phy_init(void)
 	if (rc)
 		return rc;
 
-	rc = phy_drivers_register(genphy_driver,
-				  ARRAY_SIZE(genphy_driver), THIS_MODULE);
+	rc = phy_driver_register(&genphy_10g_driver, THIS_MODULE);
 	if (rc)
+		goto err_10g;
+
+	rc = phy_driver_register(&genphy_driver, THIS_MODULE);
+	if (rc) {
+		phy_driver_unregister(&genphy_10g_driver);
+err_10g:
 		mdio_bus_exit();
+	}
 
 	return rc;
 }
 
 static void __exit phy_exit(void)
 {
-	phy_drivers_unregister(genphy_driver,
-			       ARRAY_SIZE(genphy_driver));
+	phy_driver_unregister(&genphy_10g_driver);
+	phy_driver_unregister(&genphy_driver);
 	mdio_bus_exit();
 }
 
-- 
2.7.4

  parent reply	other threads:[~2017-06-05 11:23 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 10:23 [PATCH 0/5] Add phylib support for MV88X3310 10G phy Russell King - ARM Linux
2017-06-01 10:26 ` [PATCH 1/5] net: phy: add 802.3 clause 45 support to phylib Russell King
2017-06-01 12:28   ` Andrew Lunn
2017-06-01 17:15   ` Florian Fainelli
2017-06-02 12:39     ` Russell King - ARM Linux
2017-06-01 10:26 ` [PATCH 2/5] net: phy: hook up clause 45 autonegotiation restart Russell King
2017-06-01 12:23   ` Andrew Lunn
2017-06-01 12:51     ` Russell King - ARM Linux
2017-06-01 13:05       ` Andrew Lunn
2017-06-01 13:09         ` Russell King - ARM Linux
2017-06-01 13:19           ` Andrew Lunn
2017-06-01 15:47             ` Russell King - ARM Linux
2017-06-01 16:24               ` Russell King - ARM Linux
2017-06-01 17:16                 ` Florian Fainelli
2017-06-02 12:43                   ` Russell King - ARM Linux
2017-06-02 13:46                     ` Andrew Lunn
2017-06-02 14:04                       ` Russell King - ARM Linux
2017-06-01 10:26 ` [PATCH 3/5] net: phy: split out 10G genphy support Russell King
2017-06-01 12:29   ` Andrew Lunn
2017-06-01 17:17   ` Florian Fainelli
2017-06-01 10:26 ` [PATCH 4/5] net: phy: add XAUI and 10GBASE-KR PHY connection types Russell King
     [not found]   ` <E1dGNJX-00043v-3M-eh5Bv4kxaXIk46pC+1QYvQNdhmdF6hFW@public.gmane.org>
2017-06-01 12:30     ` Andrew Lunn
2017-06-01 16:56   ` Florian Fainelli
     [not found]     ` <fb1a81e0-b5b9-80e4-7852-cc65a574b9e9-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2017-06-01 17:32       ` Russell King - ARM Linux
2017-06-01 10:26 ` [PATCH 5/5] net: phy: add Marvell Alaska X 88X3310 10Gigabit PHY support Russell King
2017-06-01 12:51   ` Andrew Lunn
2017-06-01 13:06     ` Russell King - ARM Linux
2017-06-01 17:28   ` Florian Fainelli
2017-06-01 17:57     ` Russell King - ARM Linux
2017-06-01 16:07 ` [PATCH 0/5] Add phylib support for MV88X3310 10G phy David Miller
     [not found]   ` <20170601.120736.670167741447008364.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2017-06-01 16:54     ` Russell King - ARM Linux
     [not found] ` <20170601102327.GF27796-l+eeeJia6m9URfEZ8mYm6t73F7V6hmMc@public.gmane.org>
2017-06-05 11:22   ` [PATCH v2 0/6] " Russell King - ARM Linux
2017-06-05 11:22     ` [PATCH 1/6] net: phy: add 802.3 clause 45 support to phylib Russell King
2017-06-05 16:25       ` Florian Fainelli
2017-06-05 11:22     ` [PATCH 2/6] net: phy: avoid genphy_aneg_done() for PHYs without clause 22 support Russell King
2017-06-05 11:58       ` Andrew Lunn
2017-06-05 16:29       ` Florian Fainelli
2017-06-05 11:23     ` [PATCH 3/6] net: phy: hook up clause 45 autonegotiation restart Russell King
2017-06-05 11:59       ` Andrew Lunn
2017-06-05 16:30       ` Florian Fainelli
2017-06-05 11:23     ` Russell King [this message]
2017-06-05 11:23     ` [PATCH 5/6] net: phy: add XAUI and 10GBASE-KR PHY connection types Russell King
     [not found]       ` <E1dHq6I-0005XE-VR-eh5Bv4kxaXIk46pC+1QYvQNdhmdF6hFW@public.gmane.org>
2017-06-05 12:00         ` Andrew Lunn
2017-06-05 16:24       ` Florian Fainelli
2017-06-05 11:23     ` [PATCH 6/6] net: phy: add Marvell Alaska X 88X3310 10Gigabit PHY support Russell King
2017-06-05 18:20       ` Andrew Lunn
2017-06-05 18:21       ` Florian Fainelli
2017-06-05 18:21       ` Andrew Lunn
2017-06-05 22:10         ` Russell King - ARM Linux
     [not found]     ` <20170605112203.GA10680-l+eeeJia6m9URfEZ8mYm6t73F7V6hmMc@public.gmane.org>
2017-06-05 21:53       ` [PATCH v2 0/6] Add phylib support for MV88X3310 10G phy David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E1dHq6D-0005X7-Ri@rmk-PC.armlinux.org.uk \
    --to=rmk+kernel@armlinux$(echo .)org.uk \
    --cc=andrew@lunn$(echo .)ch \
    --cc=f.fainelli@gmail$(echo .)com \
    --cc=netdev@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox