[PATCH net v3 03/12] net/mac8390: Convert to nubus_driver

From: Finn Thain
Date: Sat Nov 11 2017 - 01:24:11 EST


Tested-by: Stan Johnson <userm57@xxxxxxxxx>
Signed-off-by: Finn Thain <fthain@xxxxxxxxxxxxxxxxxxx>
---
drivers/net/Space.c | 3 --
drivers/net/ethernet/8390/mac8390.c | 105 ++++++++++++++++++------------------
include/net/Space.h | 1 -
3 files changed, 53 insertions(+), 56 deletions(-)

diff --git a/drivers/net/Space.c b/drivers/net/Space.c
index fe123808c6b8..3afda6561434 100644
--- a/drivers/net/Space.c
+++ b/drivers/net/Space.c
@@ -114,9 +114,6 @@ static struct devprobe2 m68k_probes[] __initdata = {
#ifdef CONFIG_MVME147_NET /* MVME147 internal Ethernet */
{mvme147lance_probe, 0},
#endif
-#ifdef CONFIG_MAC8390 /* NuBus NS8390-based cards */
- {mac8390_probe, 0},
-#endif
{NULL, 0},
};

diff --git a/drivers/net/ethernet/8390/mac8390.c b/drivers/net/ethernet/8390/mac8390.c
index 0367c9ada7c6..80bbaa3c7241 100644
--- a/drivers/net/ethernet/8390/mac8390.c
+++ b/drivers/net/ethernet/8390/mac8390.c
@@ -123,8 +123,7 @@ enum mac8390_access {
};

extern int mac8390_memtest(struct net_device *dev);
-static int mac8390_initdev(struct net_device *dev,
- struct nubus_functional_resource *ndev,
+static int mac8390_initdev(struct net_device *dev, struct nubus_board *board,
enum mac8390_type type);

static int mac8390_open(struct net_device *dev);
@@ -170,7 +169,7 @@ static void word_memcpy_tocard(unsigned long tp, const void *fp, int count);
static void word_memcpy_fromcard(void *tp, unsigned long fp, int count);
static u32 mac8390_msg_enable;

-static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource *dev)
+static enum mac8390_type mac8390_ident(struct nubus_functional_resource *dev)
{
switch (dev->dr_sw) {
case NUBUS_DRSW_3COM:
@@ -236,7 +235,7 @@ static enum mac8390_type __init mac8390_ident(struct nubus_functional_resource *
return MAC8390_NONE;
}

-static enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
+static enum mac8390_access mac8390_testio(unsigned long membase)
{
unsigned long outdata = 0xA5A0B5B0;
unsigned long indata = 0x00000000;
@@ -254,7 +253,7 @@ static enum mac8390_access __init mac8390_testio(volatile unsigned long membase)
return ACCESS_UNKNOWN;
}

-static int __init mac8390_memsize(unsigned long membase)
+static int mac8390_memsize(unsigned long membase)
{
unsigned long flags;
int i, j;
@@ -290,9 +289,9 @@ static int __init mac8390_memsize(unsigned long membase)
return i * 0x1000;
}

-static bool __init mac8390_init(struct net_device *dev,
- struct nubus_functional_resource *ndev,
- enum mac8390_type cardtype)
+static bool mac8390_rsrc_init(struct net_device *dev,
+ struct nubus_functional_resource *ndev,
+ enum mac8390_type cardtype)
{
struct nubus_dir dir;
struct nubus_dirent ent;
@@ -393,49 +392,40 @@ static bool __init mac8390_init(struct net_device *dev,
return true;
}

-struct net_device * __init mac8390_probe(int unit)
+static int mac8390_device_probe(struct nubus_board *board)
{
struct net_device *dev;
- struct nubus_functional_resource *ndev = NULL;
int err = -ENODEV;
struct ei_device *ei_local;
-
- static unsigned int slots;
-
- enum mac8390_type cardtype;
-
- /* probably should check for Nubus instead */
+ struct nubus_functional_resource *fres;
+ enum mac8390_type cardtype = MAC8390_NONE;

if (!MACH_IS_MAC)
- return ERR_PTR(-ENODEV);
+ return -ENODEV;

dev = ____alloc_ei_netdev(0);
if (!dev)
- return ERR_PTR(-ENOMEM);
+ return -ENOMEM;

- if (unit >= 0)
- sprintf(dev->name, "eth%d", unit);
+ SET_NETDEV_DEV(dev, &board->dev);

- while ((ndev = nubus_find_type(NUBUS_CAT_NETWORK, NUBUS_TYPE_ETHERNET,
- ndev))) {
- /* Have we seen it already? */
- if (slots & (1 << ndev->board->slot))
+ for_each_board_func_rsrc(board, fres) {
+ if (fres->category != NUBUS_CAT_NETWORK ||
+ fres->type != NUBUS_TYPE_ETHERNET)
continue;
- slots |= 1 << ndev->board->slot;

- cardtype = mac8390_ident(ndev);
+ cardtype = mac8390_ident(fres);
if (cardtype == MAC8390_NONE)
continue;

- if (!mac8390_init(dev, ndev, cardtype))
- continue;
-
- /* Do the nasty 8390 stuff */
- if (!mac8390_initdev(dev, ndev, cardtype))
+ if (mac8390_rsrc_init(dev, fres, cardtype))
break;
}
+ if (!fres)
+ goto out;

- if (!ndev)
+ err = mac8390_initdev(dev, board, cardtype);
+ if (err)
goto out;

ei_local = netdev_priv(dev);
@@ -444,37 +434,48 @@ struct net_device * __init mac8390_probe(int unit)
err = register_netdev(dev);
if (err)
goto out;
- return dev;
+
+ nubus_set_drvdata(board, dev);
+ return 0;

out:
free_netdev(dev);
- return ERR_PTR(err);
+ return err;
}

-#ifdef MODULE
MODULE_AUTHOR("David Huggins-Daines <dhd@xxxxxxxxxx> and others");
MODULE_DESCRIPTION("Macintosh NS8390-based Nubus Ethernet driver");
MODULE_LICENSE("GPL");

-static struct net_device *dev_mac8390;
-
-int __init init_module(void)
+static int mac8390_device_remove(struct nubus_board *board)
{
- dev_mac8390 = mac8390_probe(-1);
- if (IS_ERR(dev_mac8390)) {
- pr_warn("mac8390: No card found\n");
- return PTR_ERR(dev_mac8390);
- }
+ struct net_device *dev = nubus_get_drvdata(board);
+
+ unregister_netdev(dev);
+ free_netdev(dev);
return 0;
}

-void __exit cleanup_module(void)
+static struct nubus_driver mac8390_driver = {
+ .probe = mac8390_device_probe,
+ .remove = mac8390_device_remove,
+ .driver = {
+ .name = KBUILD_MODNAME,
+ .owner = THIS_MODULE,
+ }
+};
+
+static int __init mac8390_init(void)
{
- unregister_netdev(dev_mac8390);
- free_netdev(dev_mac8390);
+ return nubus_driver_register(&mac8390_driver);
}
+module_init(mac8390_init);

-#endif /* MODULE */
+static void __exit mac8390_exit(void)
+{
+ nubus_driver_unregister(&mac8390_driver);
+}
+module_exit(mac8390_exit);

static const struct net_device_ops mac8390_netdev_ops = {
.ndo_open = mac8390_open,
@@ -490,9 +491,9 @@ static const struct net_device_ops mac8390_netdev_ops = {
#endif
};

-static int __init mac8390_initdev(struct net_device *dev,
- struct nubus_functional_resource *ndev,
- enum mac8390_type type)
+static int mac8390_initdev(struct net_device *dev,
+ struct nubus_board *board,
+ enum mac8390_type type)
{
static u32 fwrd4_offsets[16] = {
0, 4, 8, 12,
@@ -610,7 +611,7 @@ static int __init mac8390_initdev(struct net_device *dev,

default:
pr_err("Card type %s is unsupported, sorry\n",
- ndev->board->name);
+ board->name);
return -ENODEV;
}

@@ -618,7 +619,7 @@ static int __init mac8390_initdev(struct net_device *dev,

/* Good, done, now spit out some messages */
pr_info("%s: %s in slot %X (type %s)\n",
- dev->name, ndev->board->name, ndev->board->slot,
+ dev->name, board->name, board->slot,
cardname[type]);
pr_info("MAC %pM IRQ %d, %d KB shared memory at %#lx, %d-bit access.\n",
dev->dev_addr, dev->irq,
diff --git a/include/net/Space.h b/include/net/Space.h
index a41b447e4a2c..62997cf96630 100644
--- a/include/net/Space.h
+++ b/include/net/Space.h
@@ -19,7 +19,6 @@ struct net_device *cs89x0_probe(int unit);
struct net_device *mvme147lance_probe(int unit);
struct net_device *tc515_probe(int unit);
struct net_device *lance_probe(int unit);
-struct net_device *mac8390_probe(int unit);
struct net_device *cops_probe(int unit);
struct net_device *ltpc_probe(void);

--
2.13.6