All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Schmitz <schmitzmic@gmail.com>
To: netdev@vger.kernel.org
Cc: andrew@lunn.ch, fthain@telegraphics.com.au, geert@linux-m68k.org,
	f.fainelli@gmail.com, linux-m68k@vger.kernel.org,
	Michael.Karcher@fu-berlin.de,
	Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>,
	Michael Schmitz <schmitzmic@gmail.com>
Subject: [PATCH v4 3/9] net-next: ax88796: Attach MII bus only when open
Date: Thu, 19 Apr 2018 14:05:20 +1200	[thread overview]
Message-ID: <1524103526-12240-4-git-send-email-schmitzmic@gmail.com> (raw)
In-Reply-To: <1524025616-3722-1-git-send-email-schmitzmic@gmail.com>

From: Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>

Call ax_mii_init in ax_open(), and unregister/remove mdiobus resources
in ax_close().

This is needed to be able to unload the module, as the module is busy
while the MII bus is attached.

Signed-off-by: Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/ethernet/8390/ax88796.c |  183 ++++++++++++++++++-----------------
 1 files changed, 95 insertions(+), 88 deletions(-)

diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
index ae39375..ab020e6 100644
--- a/drivers/net/ethernet/8390/ax88796.c
+++ b/drivers/net/ethernet/8390/ax88796.c
@@ -387,6 +387,90 @@ static void ax_phy_switch(struct net_device *dev, int on)
 	ei_outb(reg_gpoc, ei_local->mem + EI_SHIFT(0x17));
 }
 
+static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+
+	if (level)
+		ax->reg_memr |= AX_MEMR_MDC;
+	else
+		ax->reg_memr &= ~AX_MEMR_MDC;
+
+	ei_outb(ax->reg_memr, ax->addr_memr);
+}
+
+static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+
+	if (output)
+		ax->reg_memr &= ~AX_MEMR_MDIR;
+	else
+		ax->reg_memr |= AX_MEMR_MDIR;
+
+	ei_outb(ax->reg_memr, ax->addr_memr);
+}
+
+static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+
+	if (value)
+		ax->reg_memr |= AX_MEMR_MDO;
+	else
+		ax->reg_memr &= ~AX_MEMR_MDO;
+
+	ei_outb(ax->reg_memr, ax->addr_memr);
+}
+
+static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
+{
+	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
+	int reg_memr = ei_inb(ax->addr_memr);
+
+	return reg_memr & AX_MEMR_MDI ? 1 : 0;
+}
+
+static const struct mdiobb_ops bb_ops = {
+	.owner = THIS_MODULE,
+	.set_mdc = ax_bb_mdc,
+	.set_mdio_dir = ax_bb_dir,
+	.set_mdio_data = ax_bb_set_data,
+	.get_mdio_data = ax_bb_get_data,
+};
+
+static int ax_mii_init(struct net_device *dev)
+{
+	struct platform_device *pdev = to_platform_device(dev->dev.parent);
+	struct ei_device *ei_local = netdev_priv(dev);
+	struct ax_device *ax = to_ax_dev(dev);
+	int err;
+
+	ax->bb_ctrl.ops = &bb_ops;
+	ax->addr_memr = ei_local->mem + AX_MEMR;
+	ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
+	if (!ax->mii_bus) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	ax->mii_bus->name = "ax88796_mii_bus";
+	ax->mii_bus->parent = dev->dev.parent;
+	snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
+		 pdev->name, pdev->id);
+
+	err = mdiobus_register(ax->mii_bus);
+	if (err)
+		goto out_free_mdio_bitbang;
+
+	return 0;
+
+ out_free_mdio_bitbang:
+	free_mdio_bitbang(ax->mii_bus);
+ out:
+	return err;
+}
+
 static int ax_open(struct net_device *dev)
 {
 	struct ax_device *ax = to_ax_dev(dev);
@@ -394,6 +478,10 @@ static int ax_open(struct net_device *dev)
 
 	netdev_dbg(dev, "open\n");
 
+	ret = ax_mii_init(dev);
+	if (ret)
+		goto failed_mii;
+
 	ret = request_irq(dev->irq, ax_ei_interrupt, ax->irqflags,
 			  dev->name, dev);
 	if (ret)
@@ -421,6 +509,10 @@ static int ax_open(struct net_device *dev)
 	ax_phy_switch(dev, 0);
 	free_irq(dev->irq, dev);
  failed_request_irq:
+	/* unregister mdiobus */
+	mdiobus_unregister(ax->mii_bus);
+	free_mdio_bitbang(ax->mii_bus);
+ failed_mii:
 	return ret;
 }
 
@@ -440,6 +532,9 @@ static int ax_close(struct net_device *dev)
 	phy_disconnect(dev->phydev);
 
 	free_irq(dev->irq, dev);
+
+	mdiobus_unregister(ax->mii_bus);
+	free_mdio_bitbang(ax->mii_bus);
 	return 0;
 }
 
@@ -539,92 +634,8 @@ static void ax_eeprom_register_write(struct eeprom_93cx6 *eeprom)
 #endif
 };
 
-static void ax_bb_mdc(struct mdiobb_ctrl *ctrl, int level)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-
-	if (level)
-		ax->reg_memr |= AX_MEMR_MDC;
-	else
-		ax->reg_memr &= ~AX_MEMR_MDC;
-
-	ei_outb(ax->reg_memr, ax->addr_memr);
-}
-
-static void ax_bb_dir(struct mdiobb_ctrl *ctrl, int output)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-
-	if (output)
-		ax->reg_memr &= ~AX_MEMR_MDIR;
-	else
-		ax->reg_memr |= AX_MEMR_MDIR;
-
-	ei_outb(ax->reg_memr, ax->addr_memr);
-}
-
-static void ax_bb_set_data(struct mdiobb_ctrl *ctrl, int value)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-
-	if (value)
-		ax->reg_memr |= AX_MEMR_MDO;
-	else
-		ax->reg_memr &= ~AX_MEMR_MDO;
-
-	ei_outb(ax->reg_memr, ax->addr_memr);
-}
-
-static int ax_bb_get_data(struct mdiobb_ctrl *ctrl)
-{
-	struct ax_device *ax = container_of(ctrl, struct ax_device, bb_ctrl);
-	int reg_memr = ei_inb(ax->addr_memr);
-
-	return reg_memr & AX_MEMR_MDI ? 1 : 0;
-}
-
-static const struct mdiobb_ops bb_ops = {
-	.owner = THIS_MODULE,
-	.set_mdc = ax_bb_mdc,
-	.set_mdio_dir = ax_bb_dir,
-	.set_mdio_data = ax_bb_set_data,
-	.get_mdio_data = ax_bb_get_data,
-};
-
 /* setup code */
 
-static int ax_mii_init(struct net_device *dev)
-{
-	struct platform_device *pdev = to_platform_device(dev->dev.parent);
-	struct ei_device *ei_local = netdev_priv(dev);
-	struct ax_device *ax = to_ax_dev(dev);
-	int err;
-
-	ax->bb_ctrl.ops = &bb_ops;
-	ax->addr_memr = ei_local->mem + AX_MEMR;
-	ax->mii_bus = alloc_mdio_bitbang(&ax->bb_ctrl);
-	if (!ax->mii_bus) {
-		err = -ENOMEM;
-		goto out;
-	}
-
-	ax->mii_bus->name = "ax88796_mii_bus";
-	ax->mii_bus->parent = dev->dev.parent;
-	snprintf(ax->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
-		pdev->name, pdev->id);
-
-	err = mdiobus_register(ax->mii_bus);
-	if (err)
-		goto out_free_mdio_bitbang;
-
-	return 0;
-
- out_free_mdio_bitbang:
-	free_mdio_bitbang(ax->mii_bus);
- out:
-	return err;
-}
-
 static void ax_initial_setup(struct net_device *dev, struct ei_device *ei_local)
 {
 	void __iomem *ioaddr = ei_local->mem;
@@ -755,10 +766,6 @@ static int ax_init_dev(struct net_device *dev)
 	dev->netdev_ops = &ax_netdev_ops;
 	dev->ethtool_ops = &ax_ethtool_ops;
 
-	ret = ax_mii_init(dev);
-	if (ret)
-		goto err_out;
-
 	ax_NS8390_init(dev, 0);
 
 	ret = register_netdev(dev);
-- 
1.7.0.4

  parent reply	other threads:[~2018-04-19  2:05 UTC|newest]

Thread overview: 110+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 22:04 [PATCH 00/10] New network driver for Amiga X-Surf 100 (m68k) Michael Schmitz
2018-04-16 22:04 ` [PATCH 01/10] net: ax88796: Fix MAC address reading Michael Schmitz
2018-04-16 22:04 ` [PATCH 02/10] net: ax88796: Attach MII bus only when open Michael Schmitz
2018-04-16 22:59   ` Andrew Lunn
2018-04-16 23:53     ` Michael Schmitz
2018-04-16 22:04 ` [PATCH 03/10] net: ax88796: Do not free IRQ in ax_remove() (already freed in ax_close()) Michael Schmitz
2018-04-17  9:15   ` Sergei Shtylyov
2018-04-16 22:04 ` [PATCH 04/10] net: ax88796: Add block_input/output hooks to ax_plat_data Michael Schmitz
2018-04-17 18:46   ` kbuild test robot
2018-04-17 18:46     ` kbuild test robot
2018-04-18  0:53     ` Michael Schmitz
2018-04-18  1:19       ` Andrew Lunn
2018-04-18  3:39         ` Michael Schmitz
2018-04-18  1:23       ` Finn Thain
2018-04-18  3:46         ` Michael Schmitz
2018-04-16 22:04 ` [PATCH 05/10] net: ax88796: add interrupt status callback to platform data Michael Schmitz
2018-04-16 22:04 ` [PATCH 06/10] net: ax88796: set IRQF_SHARED flag when IRQ resource is marked as shareable Michael Schmitz
2018-04-16 22:04 ` [PATCH 07/10] net: ax88796: unregister mdiobus on ax_mii_init() fail Michael Schmitz
2018-04-16 22:04 ` [PATCH 08/10] net: ax88796: Make reset more robust on AX88796B Michael Schmitz
2018-04-16 23:12   ` Andrew Lunn
2018-04-17  0:14     ` Michael Schmitz
2018-04-17  1:32       ` Andrew Lunn
2018-04-17  5:18         ` Michael Karcher
2018-04-17 13:01           ` Andrew Lunn
2018-04-17 18:08             ` Florian Fainelli
2018-04-17 19:25               ` Michael Schmitz
2018-04-16 22:04 ` [PATCH 09/10] net: ax88796: release platform device drvdata on probe error and module remove Michael Schmitz
2018-04-16 22:04 ` [PATCH 10/10] net: New ax88796 platform driver for Amiga X-Surf 100 Zorro board (m68k) Michael Schmitz
2018-04-17 13:53   ` Geert Uytterhoeven
2018-04-17 22:35     ` Michael Schmitz
2018-04-18  7:54       ` Geert Uytterhoeven
2018-04-18  4:32     ` Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 0/8] New network driver for Amiga X-Surf 100 (m68k) Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 00/10] " Michael Schmitz
2018-04-18  5:10     ` Michael Schmitz
2018-04-18  5:45       ` Finn Thain
2018-04-18 21:26         ` Michael Schmitz
2018-04-18 12:19       ` Andrew Lunn
2018-04-18 21:34         ` Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 " Michael Schmitz
2018-04-19  3:17       ` Michael Schmitz
2018-04-19 20:11       ` David Miller
2018-04-19 21:36         ` Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 1/9] net-next: phy: new Asix Electronics PHY driver Michael Schmitz
2018-04-19 12:21       ` Andrew Lunn
2018-04-19 16:15       ` Florian Fainelli
2019-01-18 10:22       ` [v4,1/9] " Thomas Gleixner
2019-01-20 17:43         ` Andrew Lunn
2019-01-20 22:44           ` Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 2/9] net-next: ax88796: Fix MAC address reading Michael Schmitz
2018-04-19  2:05     ` Michael Schmitz [this message]
2018-04-19  2:05     ` [PATCH v4 4/9] net-next: ax88796: Do not free IRQ in ax_remove() (already freed in ax_close()) Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 5/9] net-next: ax88796: Add block_input/output hooks to ax_plat_data Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 6/9] net-next: ax88796: add interrupt status callback to platform data Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 7/9] net-next: ax88796: set IRQF_SHARED flag when IRQ resource is marked as shareable Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 8/9] net-next: ax88796: release platform device drvdata on probe error and module remove Michael Schmitz
2018-04-19  2:05     ` [PATCH v4 9/9] net-next: New ax88796 platform driver for Amiga X-Surf 100 Zorro board (m68k) Michael Schmitz
2018-06-07 14:36       ` Geert Uytterhoeven
2018-06-08  7:31         ` Michael Schmitz
2018-06-08  9:28           ` Michael Karcher
2018-06-09  0:28             ` Michael Schmitz
2018-06-09  9:15               ` Michael Karcher
2018-06-09 20:09                 ` Michael Schmitz
2018-06-09  5:57         ` [RFC PATCH 0/2] net-next: cleanup use of lib8390.c code in xsurf100.c Michael Schmitz
2018-06-09  5:57         ` [RFC PATCH 1/2] net-next: ax88796: export ax_NS8390_init() hook Michael Schmitz
2018-06-09 14:31           ` Geert Uytterhoeven
2018-06-09  5:57         ` [RFC PATCH 2/2] net-next: xsurf100: drop include of lib8390.c Michael Schmitz
2018-06-09 14:33           ` Geert Uytterhoeven
2018-06-09 19:00             ` Michael Schmitz
2018-06-10  4:22             ` [PATCH 0/2] net-next: cleanup use of lib8390.c code in xsurf100.c Michael Schmitz
2018-06-10  4:22             ` [PATCH 1/2] net-next: ax88796: export ax_NS8390_init() hook Michael Schmitz
2018-06-10  9:34               ` Geert Uytterhoeven
2018-06-10  4:22             ` [PATCH 2/2] net-next: xsurf100: drop include of lib8390.c Michael Schmitz
2018-06-10  9:34               ` Geert Uytterhoeven
2021-05-16  9:52               ` Arnd Bergmann
2021-05-18  8:42                 ` Michael Schmitz
2021-05-18 13:56                   ` Arnd Bergmann
2021-05-18 20:33                     ` Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 1/9] net: phy: new Asix Electronics PHY driver Michael Schmitz
2018-04-18  7:04     ` John Paul Adrian Glaubitz
2018-04-18 12:13     ` Andrew Lunn
2018-04-18 22:26       ` Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 2/9] net: ax88796: Fix MAC address reading Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 3/9] net: ax88796: Attach MII bus only when open Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 4/9] net: ax88796: Do not free IRQ in ax_remove() (already freed in ax_close()) Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 5/9] net: ax88796: Add block_input/output hooks to ax_plat_data Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 6/9] net: ax88796: add interrupt status callback to platform data Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 7/9] net: ax88796: set IRQF_SHARED flag when IRQ resource is marked as shareable Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 8/9] net: ax88796: release platform device drvdata on probe error and module remove Michael Schmitz
2018-04-18  4:26   ` [PATCH v3 9/9] net: New ax88796 platform driver for Amiga X-Surf 100 Zorro board (m68k) Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 1/8] net: ax88796: Fix MAC address reading Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 2/8] net: ax88796: Attach MII bus only when open Michael Schmitz
2018-04-17 13:19   ` Andrew Lunn
2018-04-17  2:08 ` [PATCH v2 3/8] net: ax88796: Do not free IRQ in ax_remove() (already freed in ax_close()) Michael Schmitz
2018-04-17  8:20   ` Geert Uytterhoeven
2018-04-17 13:51     ` David Miller
2018-04-17 20:36       ` Michael Schmitz
2018-04-17 11:40   ` John Paul Adrian Glaubitz
2018-04-17 20:32     ` Michael Schmitz
2018-04-17 20:42       ` John Paul Adrian Glaubitz
2018-04-17 21:13       ` Andrew Lunn
2018-04-17 21:53         ` Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 4/8] net: ax88796: Add block_input/output hooks to ax_plat_data Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 5/8] net: ax88796: add interrupt status callback to platform data Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 6/8] net: ax88796: set IRQF_SHARED flag when IRQ resource is marked as shareable Michael Schmitz
2018-04-17 11:40   ` John Paul Adrian Glaubitz
2018-04-17  2:08 ` [PATCH v2 7/8] net: ax88796: release platform device drvdata on probe error and module remove Michael Schmitz
2018-04-17  2:08 ` [PATCH v2 8/8] net: New ax88796 platform driver for Amiga X-Surf 100 Zorro board (m68k) Michael Schmitz
2018-04-17 13:26   ` Andrew Lunn
2018-04-17 23:00     ` Michael Schmitz

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=1524103526-12240-4-git-send-email-schmitzmic@gmail.com \
    --to=schmitzmic@gmail.com \
    --cc=Michael.Karcher@fu-berlin.de \
    --cc=andrew@lunn.ch \
    --cc=f.fainelli@gmail.com \
    --cc=fthain@telegraphics.com.au \
    --cc=geert@linux-m68k.org \
    --cc=kernel@mkarcher.dialup.fu-berlin.de \
    --cc=linux-m68k@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.