Skip to content

Commit a46c30f

Browse files
author
David S. Miller
committed
[NET] myri_sbus: Convert to new SBUS device layer.
Signed-off-by: David S. Miller <[email protected]>
1 parent ecba38a commit a46c30f

File tree

1 file changed

+61
-55
lines changed

1 file changed

+61
-55
lines changed

drivers/net/myri_sbus.c

Lines changed: 61 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/* myri_sbus.h: MyriCOM MyriNET SBUS card driver.
1+
/* myri_sbus.c: MyriCOM MyriNET SBUS card driver.
22
*
3-
* Copyright (C) 1996, 1999 David S. Miller (davem@redhat.com)
3+
* Copyright (C) 1996, 1999, 2006 David S. Miller (davem@davemloft.net)
44
*/
55

66
static char version[] =
7-
"myri_sbus.c:v1.9 12/Sep/99 David S. Miller (davem@redhat.com)\n";
7+
"myri_sbus.c:v2.0 June 23, 2006 David S. Miller (davem@davemloft.net)\n";
88

99
#include <linux/module.h>
1010
#include <linux/config.h>
@@ -81,10 +81,6 @@ static char version[] =
8181
#define DHDR(x)
8282
#endif
8383

84-
#ifdef MODULE
85-
static struct myri_eth *root_myri_dev;
86-
#endif
87-
8884
static void myri_reset_off(void __iomem *lp, void __iomem *cregs)
8985
{
9086
/* Clear IRQ mask. */
@@ -896,8 +892,9 @@ static void dump_eeprom(struct myri_eth *mp)
896892
}
897893
#endif
898894

899-
static int __init myri_ether_init(struct sbus_dev *sdev, int num)
895+
static int __init myri_ether_init(struct sbus_dev *sdev)
900896
{
897+
static int num;
901898
static unsigned version_printed;
902899
struct net_device *dev;
903900
struct myri_eth *mp;
@@ -913,6 +910,9 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
913910
if (version_printed++ == 0)
914911
printk(version);
915912

913+
SET_MODULE_OWNER(dev);
914+
SET_NETDEV_DEV(dev, &sdev->ofdev.dev);
915+
916916
mp = (struct myri_eth *) dev->priv;
917917
spin_lock_init(&mp->irq_lock);
918918
mp->myri_sdev = sdev;
@@ -1092,10 +1092,9 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
10921092
goto err_free_irq;
10931093
}
10941094

1095-
#ifdef MODULE
1096-
mp->next_module = root_myri_dev;
1097-
root_myri_dev = mp;
1098-
#endif
1095+
dev_set_drvdata(&sdev->ofdev.dev, mp);
1096+
1097+
num++;
10991098

11001099
printk("%s: MyriCOM MyriNET Ethernet ", dev->name);
11011100

@@ -1114,61 +1113,68 @@ static int __init myri_ether_init(struct sbus_dev *sdev, int num)
11141113
return -ENODEV;
11151114
}
11161115

1117-
static int __init myri_sbus_match(struct sbus_dev *sdev)
1118-
{
1119-
char *name = sdev->prom_name;
11201116

1121-
if (!strcmp(name, "MYRICOM,mlanai") ||
1122-
!strcmp(name, "myri"))
1123-
return 1;
1117+
static int __devinit myri_sbus_probe(struct of_device *dev, const struct of_device_id *match)
1118+
{
1119+
struct sbus_dev *sdev = to_sbus_device(&dev->dev);
11241120

1125-
return 0;
1121+
return myri_ether_init(sdev);
11261122
}
11271123

1128-
static int __init myri_sbus_probe(void)
1124+
static int __devexit myri_sbus_remove(struct of_device *dev)
11291125
{
1130-
struct sbus_bus *bus;
1131-
struct sbus_dev *sdev = NULL;
1132-
static int called;
1133-
int cards = 0, v;
1126+
struct myri_eth *mp = dev_get_drvdata(&dev->dev);
1127+
struct net_device *net_dev = mp->dev;
11341128

1135-
#ifdef MODULE
1136-
root_myri_dev = NULL;
1137-
#endif
1129+
unregister_netdevice(net_dev);
11381130

1139-
if (called)
1140-
return -ENODEV;
1141-
called++;
1142-
1143-
for_each_sbus(bus) {
1144-
for_each_sbusdev(sdev, bus) {
1145-
if (myri_sbus_match(sdev)) {
1146-
cards++;
1147-
DET(("Found myricom myrinet as %s\n", sdev->prom_name));
1148-
if ((v = myri_ether_init(sdev, (cards - 1))))
1149-
return v;
1150-
}
1151-
}
1131+
free_irq(net_dev->irq, net_dev);
1132+
1133+
if (mp->eeprom.cpuvers < CPUVERS_4_0) {
1134+
sbus_iounmap(mp->regs, mp->reg_size);
1135+
} else {
1136+
sbus_iounmap(mp->cregs, PAGE_SIZE);
1137+
sbus_iounmap(mp->lregs, (256 * 1024));
1138+
sbus_iounmap(mp->lanai, (512 * 1024));
11521139
}
1153-
if (!cards)
1154-
return -ENODEV;
1140+
1141+
free_netdev(net_dev);
1142+
1143+
dev_set_drvdata(&dev->dev, NULL);
1144+
11551145
return 0;
11561146
}
11571147

1158-
static void __exit myri_sbus_cleanup(void)
1148+
static struct of_device_id myri_sbus_match[] = {
1149+
{
1150+
.name = "MYRICOM,mlanai",
1151+
},
1152+
{
1153+
.name = "myri",
1154+
},
1155+
{},
1156+
};
1157+
1158+
MODULE_DEVICE_TABLE(of, myri_sbus_match);
1159+
1160+
static struct of_platform_driver myri_sbus_driver = {
1161+
.name = "myri",
1162+
.match_table = myri_sbus_match,
1163+
.probe = myri_sbus_probe,
1164+
.remove = __devexit_p(myri_sbus_remove),
1165+
};
1166+
1167+
static int __init myri_sbus_init(void)
1168+
{
1169+
return of_register_driver(&myri_sbus_driver, &sbus_bus_type);
1170+
}
1171+
1172+
static void __exit myri_sbus_exit(void)
11591173
{
1160-
#ifdef MODULE
1161-
while (root_myri_dev) {
1162-
struct myri_eth *next = root_myri_dev->next_module;
1163-
1164-
unregister_netdev(root_myri_dev->dev);
1165-
/* this will also free the co-allocated 'root_myri_dev' */
1166-
free_netdev(root_myri_dev->dev);
1167-
root_myri_dev = next;
1168-
}
1169-
#endif /* MODULE */
1174+
of_unregister_driver(&myri_sbus_driver);
11701175
}
11711176

1172-
module_init(myri_sbus_probe);
1173-
module_exit(myri_sbus_cleanup);
1177+
module_init(myri_sbus_init);
1178+
module_exit(myri_sbus_exit);
1179+
11741180
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)