Commit 2b5ca00d authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[NET]: Convert YAM driver to dynamic net_device.

parent 9c09e405
...@@ -120,7 +120,7 @@ struct yam_port { ...@@ -120,7 +120,7 @@ struct yam_port {
int irq; int irq;
int dupmode; int dupmode;
struct net_device dev; struct net_device *dev;
/* Stats section */ /* Stats section */
...@@ -161,7 +161,7 @@ struct yam_mcs { ...@@ -161,7 +161,7 @@ struct yam_mcs {
struct yam_mcs *next; struct yam_mcs *next;
}; };
static struct yam_port yam_ports[NR_PORTS]; static struct net_device *yam_devs[NR_PORTS];
static struct yam_mcs *yam_data; static struct yam_mcs *yam_data;
...@@ -628,8 +628,8 @@ static void yam_dotimer(unsigned long dummy) ...@@ -628,8 +628,8 @@ static void yam_dotimer(unsigned long dummy)
int i; int i;
for (i = 0; i < NR_PORTS; i++) { for (i = 0; i < NR_PORTS; i++) {
struct net_device *dev = &yam_ports[i].dev; struct net_device *dev = yam_devs[i];
if (netif_running(dev)) if (dev && netif_running(dev))
yam_arbitrate(dev); yam_arbitrate(dev);
} }
yam_timer.expires = jiffies + HZ / 100; yam_timer.expires = jiffies + HZ / 100;
...@@ -724,8 +724,8 @@ static irqreturn_t yam_interrupt(int irq, void *dev_id, struct pt_regs *regs) ...@@ -724,8 +724,8 @@ static irqreturn_t yam_interrupt(int irq, void *dev_id, struct pt_regs *regs)
int handled = 0; int handled = 0;
for (i = 0; i < NR_PORTS; i++) { for (i = 0; i < NR_PORTS; i++) {
yp = &yam_ports[i]; dev = yam_devs[i];
dev = &yp->dev; yp = dev->priv;
if (!netif_running(dev)) if (!netif_running(dev))
continue; continue;
...@@ -882,8 +882,10 @@ static int yam_open(struct net_device *dev) ...@@ -882,8 +882,10 @@ static int yam_open(struct net_device *dev)
/* Reset overruns for all ports - FPGA programming makes overruns */ /* Reset overruns for all ports - FPGA programming makes overruns */
for (i = 0; i < NR_PORTS; i++) { for (i = 0; i < NR_PORTS; i++) {
inb(LSR(yam_ports[i].dev.base_addr)); struct net_device *dev = yam_devs[i];
yam_ports[i].stats.rx_fifo_errors = 0; struct yam_port *yp = dev->priv;
inb(LSR(dev->base_addr));
yp->stats.rx_fifo_errors = 0;
} }
printk(KERN_INFO "%s at iobase 0x%lx irq %u uart %s\n", dev->name, dev->base_addr, dev->irq, printk(KERN_INFO "%s at iobase 0x%lx irq %u uart %s\n", dev->name, dev->base_addr, dev->irq,
...@@ -1070,14 +1072,26 @@ static int yam_set_mac_address(struct net_device *dev, void *addr) ...@@ -1070,14 +1072,26 @@ static int yam_set_mac_address(struct net_device *dev, void *addr)
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int yam_probe(struct net_device *dev) static void yam_setup(struct net_device *dev)
{ {
struct yam_port *yp; struct yam_port *yp = dev->priv;
if (!dev)
return -ENXIO;
yp = (struct yam_port *) dev->priv; yp->magic = YAM_MAGIC;
yp->bitrate = DEFAULT_BITRATE;
yp->baudrate = DEFAULT_BITRATE * 2;
yp->iobase = 0;
yp->irq = 0;
yp->dupmode = 0;
yp->holdd = DEFAULT_HOLDD;
yp->txd = DEFAULT_TXD;
yp->txtail = DEFAULT_TXTAIL;
yp->slot = DEFAULT_SLOT;
yp->pers = DEFAULT_PERS;
yp->dev = dev;
dev->base_addr = yp->iobase;
dev->irq = yp->irq;
SET_MODULE_OWNER(dev);
dev->open = yam_open; dev->open = yam_open;
dev->stop = yam_close; dev->stop = yam_close;
...@@ -1104,50 +1118,35 @@ static int yam_probe(struct net_device *dev) ...@@ -1104,50 +1118,35 @@ static int yam_probe(struct net_device *dev)
memcpy(dev->broadcast, ax25_bcast, 7); memcpy(dev->broadcast, ax25_bcast, 7);
memcpy(dev->dev_addr, ax25_test, 7); memcpy(dev->dev_addr, ax25_test, 7);
/* New style flags */
dev->flags = 0;
return 0;
} }
/* --------------------------------------------------------------------- */
static int __init yam_init_driver(void) static int __init yam_init_driver(void)
{ {
struct net_device *dev; struct net_device *dev;
int i; int i, err;
char name[IFNAMSIZ];
printk(yam_drvinfo); printk(yam_drvinfo);
for (i = 0; i < NR_PORTS; i++) { for (i = 0; i < NR_PORTS; i++) {
sprintf(yam_ports[i].dev.name, "yam%d", i); sprintf(name, "yam%d", i);
yam_ports[i].magic = YAM_MAGIC;
yam_ports[i].bitrate = DEFAULT_BITRATE; dev = alloc_netdev(sizeof(struct yam_port), name,
yam_ports[i].baudrate = DEFAULT_BITRATE * 2; yam_setup);
yam_ports[i].iobase = 0; if (!dev) {
yam_ports[i].irq = 0; printk(KERN_ERR "yam: cannot allocate net device %s\n",
yam_ports[i].dupmode = 0; dev->name);
yam_ports[i].holdd = DEFAULT_HOLDD; err = -ENOMEM;
yam_ports[i].txd = DEFAULT_TXD; goto error;
yam_ports[i].txtail = DEFAULT_TXTAIL; }
yam_ports[i].slot = DEFAULT_SLOT;
yam_ports[i].pers = DEFAULT_PERS; err = register_netdev(dev);
if (err) {
dev = &yam_ports[i].dev;
dev->priv = &yam_ports[i];
dev->base_addr = yam_ports[i].iobase;
dev->irq = yam_ports[i].irq;
dev->init = yam_probe;
dev->if_port = 0;
if (register_netdev(dev)) {
printk(KERN_WARNING "yam: cannot register net device %s\n", dev->name); printk(KERN_WARNING "yam: cannot register net device %s\n", dev->name);
dev->priv = NULL; goto error;
return -ENXIO;
} }
yam_devs[i] = dev;
SET_MODULE_OWNER(dev);
} }
yam_timer.function = yam_dotimer; yam_timer.function = yam_dotimer;
...@@ -1156,6 +1155,12 @@ static int __init yam_init_driver(void) ...@@ -1156,6 +1155,12 @@ static int __init yam_init_driver(void)
proc_net_create("yam", 0, yam_net_get_info); proc_net_create("yam", 0, yam_net_get_info);
return 0; return 0;
error:
while (--i >= 0) {
unregister_netdev(yam_devs[i]);
kfree(yam_devs[i]);
}
return err;
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
...@@ -1167,12 +1172,11 @@ static void __exit yam_cleanup_driver(void) ...@@ -1167,12 +1172,11 @@ static void __exit yam_cleanup_driver(void)
del_timer(&yam_timer); del_timer(&yam_timer);
for (i = 0; i < NR_PORTS; i++) { for (i = 0; i < NR_PORTS; i++) {
struct net_device *dev = &yam_ports[i].dev; struct net_device *dev = yam_devs[i];
if (!dev->priv) if (dev) {
continue; unregister_netdev(dev);
if (netif_running(dev)) kfree(dev);
yam_close(dev); }
unregister_netdev(dev);
} }
while (yam_data) { while (yam_data) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment