Back to home page

OSCL-LXR

 
 

    


0001 /* smc-ultra.c: A SMC Ultra ethernet driver for linux. */
0002 /*
0003     This is a driver for the SMC Ultra and SMC EtherEZ ISA ethercards.
0004 
0005     Written 1993-1998 by Donald Becker.
0006 
0007     Copyright 1993 United States Government as represented by the
0008     Director, National Security Agency.
0009 
0010     This software may be used and distributed according to the terms
0011     of the GNU General Public License, incorporated herein by reference.
0012 
0013     The author may be reached as becker@scyld.com, or C/O
0014     Scyld Computing Corporation
0015     410 Severn Ave., Suite 210
0016     Annapolis MD 21403
0017 
0018     This driver uses the cards in the 8390-compatible mode.
0019     Most of the run-time complexity is handled by the generic code in
0020     8390.c.  The code in this file is responsible for
0021 
0022         ultra_probe()       Detecting and initializing the card.
0023         ultra_probe1()
0024         ultra_probe_isapnp()
0025 
0026         ultra_open()        The card-specific details of starting, stopping
0027         ultra_reset_8390()  and resetting the 8390 NIC core.
0028         ultra_close()
0029 
0030         ultra_block_input()     Routines for reading and writing blocks of
0031         ultra_block_output()    packet buffer memory.
0032         ultra_pio_input()
0033         ultra_pio_output()
0034 
0035     This driver enables the shared memory only when doing the actual data
0036     transfers to avoid a bug in early version of the card that corrupted
0037     data transferred by a AHA1542.
0038 
0039     This driver now supports the programmed-I/O (PIO) data transfer mode of
0040     the EtherEZ. It does not use the non-8390-compatible "Altego" mode.
0041     That support (if available) is in smc-ez.c.
0042 
0043     Changelog:
0044 
0045     Paul Gortmaker  : multiple card support for module users.
0046     Donald Becker   : 4/17/96 PIO support, minor potential problems avoided.
0047     Donald Becker   : 6/6/96 correctly set auto-wrap bit.
0048     Alexander Sotirov : 1/20/01 Added support for ISAPnP cards
0049 
0050     Note about the ISA PnP support:
0051 
0052     This driver can not autoprobe for more than one SMC EtherEZ PnP card.
0053     You have to configure the second card manually through the /proc/isapnp
0054     interface and then load the module with an explicit io=0x___ option.
0055 */
0056 
0057 static const char version[] =
0058     "smc-ultra.c:v2.02 2/3/98 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
0059 
0060 #include <linux/module.h>
0061 #include <linux/kernel.h>
0062 #include <linux/errno.h>
0063 #include <linux/string.h>
0064 #include <linux/init.h>
0065 #include <linux/interrupt.h>
0066 #include <linux/isapnp.h>
0067 #include <linux/netdevice.h>
0068 #include <linux/etherdevice.h>
0069 
0070 #include <asm/io.h>
0071 #include <asm/irq.h>
0072 
0073 #include "8390.h"
0074 
0075 #define DRV_NAME "smc-ultra"
0076 
0077 /* A zero-terminated list of I/O addresses to be probed. */
0078 static unsigned int ultra_portlist[] __initdata =
0079 {0x200, 0x220, 0x240, 0x280, 0x300, 0x340, 0x380, 0};
0080 
0081 static int ultra_probe1(struct net_device *dev, int ioaddr);
0082 
0083 #ifdef __ISAPNP__
0084 static int ultra_probe_isapnp(struct net_device *dev);
0085 #endif
0086 
0087 static int ultra_open(struct net_device *dev);
0088 static void ultra_reset_8390(struct net_device *dev);
0089 static void ultra_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
0090                         int ring_page);
0091 static void ultra_block_input(struct net_device *dev, int count,
0092                           struct sk_buff *skb, int ring_offset);
0093 static void ultra_block_output(struct net_device *dev, int count,
0094                             const unsigned char *buf, const int start_page);
0095 static void ultra_pio_get_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
0096                         int ring_page);
0097 static void ultra_pio_input(struct net_device *dev, int count,
0098                           struct sk_buff *skb, int ring_offset);
0099 static void ultra_pio_output(struct net_device *dev, int count,
0100                              const unsigned char *buf, const int start_page);
0101 static int ultra_close_card(struct net_device *dev);
0102 
0103 #ifdef __ISAPNP__
0104 static struct isapnp_device_id ultra_device_ids[] __initdata = {
0105         {       ISAPNP_VENDOR('S','M','C'), ISAPNP_FUNCTION(0x8416),
0106                 ISAPNP_VENDOR('S','M','C'), ISAPNP_FUNCTION(0x8416),
0107                 (long) "SMC EtherEZ (8416)" },
0108         { } /* terminate list */
0109 };
0110 
0111 MODULE_DEVICE_TABLE(isapnp, ultra_device_ids);
0112 #endif
0113 
0114 static u32 ultra_msg_enable;
0115 
0116 #define START_PG        0x00    /* First page of TX buffer */
0117 
0118 #define ULTRA_CMDREG    0       /* Offset to ASIC command register. */
0119 #define  ULTRA_RESET    0x80    /* Board reset, in ULTRA_CMDREG. */
0120 #define  ULTRA_MEMENB   0x40    /* Enable the shared memory. */
0121 #define IOPD    0x02            /* I/O Pipe Data (16 bits), PIO operation. */
0122 #define IOPA    0x07            /* I/O Pipe Address for PIO operation. */
0123 #define ULTRA_NIC_OFFSET  16    /* NIC register offset from the base_addr. */
0124 #define ULTRA_IO_EXTENT 32
0125 #define EN0_ERWCNT      0x08    /* Early receive warning count. */
0126 
0127 #ifdef CONFIG_NET_POLL_CONTROLLER
0128 static void ultra_poll(struct net_device *dev)
0129 {
0130     disable_irq(dev->irq);
0131     ei_interrupt(dev->irq, dev);
0132     enable_irq(dev->irq);
0133 }
0134 #endif
0135 /*  Probe for the Ultra.  This looks like a 8013 with the station
0136     address PROM at I/O ports <base>+8 to <base>+13, with a checksum
0137     following.
0138 */
0139 
0140 static int __init do_ultra_probe(struct net_device *dev)
0141 {
0142     int i;
0143     int base_addr = dev->base_addr;
0144     int irq = dev->irq;
0145 
0146     if (base_addr > 0x1ff)      /* Check a single specified location. */
0147         return ultra_probe1(dev, base_addr);
0148     else if (base_addr != 0)    /* Don't probe at all. */
0149         return -ENXIO;
0150 
0151 #ifdef __ISAPNP__
0152     /* Look for any installed ISAPnP cards */
0153     if (isapnp_present() && (ultra_probe_isapnp(dev) == 0))
0154         return 0;
0155 #endif
0156 
0157     for (i = 0; ultra_portlist[i]; i++) {
0158         dev->irq = irq;
0159         if (ultra_probe1(dev, ultra_portlist[i]) == 0)
0160             return 0;
0161     }
0162 
0163     return -ENODEV;
0164 }
0165 
0166 #ifndef MODULE
0167 struct net_device * __init ultra_probe(int unit)
0168 {
0169     struct net_device *dev = alloc_ei_netdev();
0170     int err;
0171 
0172     if (!dev)
0173         return ERR_PTR(-ENOMEM);
0174 
0175     sprintf(dev->name, "eth%d", unit);
0176     netdev_boot_setup_check(dev);
0177 
0178     err = do_ultra_probe(dev);
0179     if (err)
0180         goto out;
0181     return dev;
0182 out:
0183     free_netdev(dev);
0184     return ERR_PTR(err);
0185 }
0186 #endif
0187 
0188 static const struct net_device_ops ultra_netdev_ops = {
0189     .ndo_open       = ultra_open,
0190     .ndo_stop       = ultra_close_card,
0191 
0192     .ndo_start_xmit     = ei_start_xmit,
0193     .ndo_tx_timeout     = ei_tx_timeout,
0194     .ndo_get_stats      = ei_get_stats,
0195     .ndo_set_rx_mode    = ei_set_multicast_list,
0196     .ndo_validate_addr  = eth_validate_addr,
0197     .ndo_set_mac_address    = eth_mac_addr,
0198 #ifdef CONFIG_NET_POLL_CONTROLLER
0199     .ndo_poll_controller    = ultra_poll,
0200 #endif
0201 };
0202 
0203 static int __init ultra_probe1(struct net_device *dev, int ioaddr)
0204 {
0205     int i, retval;
0206     int checksum = 0;
0207     u8 macaddr[ETH_ALEN];
0208     const char *model_name;
0209     unsigned char eeprom_irq = 0;
0210     static unsigned version_printed;
0211     /* Values from various config regs. */
0212     unsigned char num_pages, irqreg, addr, piomode;
0213     unsigned char idreg = inb(ioaddr + 7);
0214     unsigned char reg4 = inb(ioaddr + 4) & 0x7f;
0215     struct ei_device *ei_local = netdev_priv(dev);
0216 
0217     if (!request_region(ioaddr, ULTRA_IO_EXTENT, DRV_NAME))
0218         return -EBUSY;
0219 
0220     /* Check the ID nibble. */
0221     if ((idreg & 0xF0) != 0x20          /* SMC Ultra */
0222         && (idreg & 0xF0) != 0x40) {        /* SMC EtherEZ */
0223         retval = -ENODEV;
0224         goto out;
0225     }
0226 
0227     /* Select the station address register set. */
0228     outb(reg4, ioaddr + 4);
0229 
0230     for (i = 0; i < 8; i++)
0231         checksum += inb(ioaddr + 8 + i);
0232     if ((checksum & 0xff) != 0xFF) {
0233         retval = -ENODEV;
0234         goto out;
0235     }
0236 
0237     if ((ultra_msg_enable & NETIF_MSG_DRV) && (version_printed++ == 0))
0238         netdev_info(dev, version);
0239 
0240     model_name = (idreg & 0xF0) == 0x20 ? "SMC Ultra" : "SMC EtherEZ";
0241 
0242     for (i = 0; i < 6; i++)
0243         macaddr[i] = inb(ioaddr + 8 + i);
0244     eth_hw_addr_set(dev, macaddr);
0245 
0246     netdev_info(dev, "%s at %#3x, %pM", model_name,
0247             ioaddr, dev->dev_addr);
0248 
0249     /* Switch from the station address to the alternate register set and
0250        read the useful registers there. */
0251     outb(0x80 | reg4, ioaddr + 4);
0252 
0253     /* Enabled FINE16 mode to avoid BIOS ROM width mismatches @ reboot. */
0254     outb(0x80 | inb(ioaddr + 0x0c), ioaddr + 0x0c);
0255     piomode = inb(ioaddr + 0x8);
0256     addr = inb(ioaddr + 0xb);
0257     irqreg = inb(ioaddr + 0xd);
0258 
0259     /* Switch back to the station address register set so that the MS-DOS driver
0260        can find the card after a warm boot. */
0261     outb(reg4, ioaddr + 4);
0262 
0263     if (dev->irq < 2) {
0264         unsigned char irqmap[] = {0, 9, 3, 5, 7, 10, 11, 15};
0265         int irq;
0266 
0267         /* The IRQ bits are split. */
0268         irq = irqmap[((irqreg & 0x40) >> 4) + ((irqreg & 0x0c) >> 2)];
0269 
0270         if (irq == 0) {
0271             pr_cont(", failed to detect IRQ line.\n");
0272             retval =  -EAGAIN;
0273             goto out;
0274         }
0275         dev->irq = irq;
0276         eeprom_irq = 1;
0277     }
0278 
0279     /* The 8390 isn't at the base address, so fake the offset */
0280     dev->base_addr = ioaddr+ULTRA_NIC_OFFSET;
0281 
0282     {
0283         static const int addr_tbl[4] = {
0284             0x0C0000, 0x0E0000, 0xFC0000, 0xFE0000
0285         };
0286         static const short num_pages_tbl[4] = {
0287             0x20, 0x40, 0x80, 0xff
0288         };
0289 
0290         dev->mem_start = ((addr & 0x0f) << 13) + addr_tbl[(addr >> 6) & 3] ;
0291         num_pages = num_pages_tbl[(addr >> 4) & 3];
0292     }
0293 
0294     ei_status.name = model_name;
0295     ei_status.word16 = 1;
0296     ei_status.tx_start_page = START_PG;
0297     ei_status.rx_start_page = START_PG + TX_PAGES;
0298     ei_status.stop_page = num_pages;
0299 
0300     ei_status.mem = ioremap(dev->mem_start, (ei_status.stop_page - START_PG)*256);
0301     if (!ei_status.mem) {
0302         pr_cont(", failed to ioremap.\n");
0303         retval =  -ENOMEM;
0304         goto out;
0305     }
0306 
0307     dev->mem_end = dev->mem_start + (ei_status.stop_page - START_PG)*256;
0308 
0309     if (piomode) {
0310         pr_cont(", %s IRQ %d programmed-I/O mode.\n",
0311             eeprom_irq ? "EEPROM" : "assigned ", dev->irq);
0312         ei_status.block_input = &ultra_pio_input;
0313         ei_status.block_output = &ultra_pio_output;
0314         ei_status.get_8390_hdr = &ultra_pio_get_hdr;
0315     } else {
0316         pr_cont(", %s IRQ %d memory %#lx-%#lx.\n",
0317             eeprom_irq ? "" : "assigned ", dev->irq, dev->mem_start,
0318             dev->mem_end-1);
0319         ei_status.block_input = &ultra_block_input;
0320         ei_status.block_output = &ultra_block_output;
0321         ei_status.get_8390_hdr = &ultra_get_8390_hdr;
0322     }
0323     ei_status.reset_8390 = &ultra_reset_8390;
0324 
0325     dev->netdev_ops = &ultra_netdev_ops;
0326     NS8390_init(dev, 0);
0327     ei_local->msg_enable = ultra_msg_enable;
0328 
0329     retval = register_netdev(dev);
0330     if (retval)
0331         goto out;
0332     return 0;
0333 out:
0334     release_region(ioaddr, ULTRA_IO_EXTENT);
0335     return retval;
0336 }
0337 
0338 #ifdef __ISAPNP__
0339 static int __init ultra_probe_isapnp(struct net_device *dev)
0340 {
0341         int i;
0342 
0343         for (i = 0; ultra_device_ids[i].vendor != 0; i++) {
0344         struct pnp_dev *idev = NULL;
0345 
0346                 while ((idev = pnp_find_dev(NULL,
0347                                             ultra_device_ids[i].vendor,
0348                                             ultra_device_ids[i].function,
0349                                             idev))) {
0350                         /* Avoid already found cards from previous calls */
0351                         if (pnp_device_attach(idev) < 0)
0352                 continue;
0353                         if (pnp_activate_dev(idev) < 0) {
0354                               __again:
0355                 pnp_device_detach(idev);
0356                 continue;
0357                         }
0358             /* if no io and irq, search for next */
0359             if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0))
0360                 goto __again;
0361                         /* found it */
0362             dev->base_addr = pnp_port_start(idev, 0);
0363             dev->irq = pnp_irq(idev, 0);
0364             netdev_info(dev,
0365                     "smc-ultra.c: ISAPnP reports %s at i/o %#lx, irq %d.\n",
0366                     (char *) ultra_device_ids[i].driver_data,
0367                     dev->base_addr, dev->irq);
0368                         if (ultra_probe1(dev, dev->base_addr) != 0) {      /* Shouldn't happen. */
0369                 netdev_err(dev,
0370                        "smc-ultra.c: Probe of ISAPnP card at %#lx failed.\n",
0371                        dev->base_addr);
0372                 pnp_device_detach(idev);
0373                 return -ENXIO;
0374                         }
0375                         ei_status.priv = (unsigned long)idev;
0376                         break;
0377                 }
0378                 if (!idev)
0379                         continue;
0380                 return 0;
0381         }
0382 
0383         return -ENODEV;
0384 }
0385 #endif
0386 
0387 static int
0388 ultra_open(struct net_device *dev)
0389 {
0390     int retval;
0391     int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
0392     unsigned char irq2reg[] = {0, 0, 0x04, 0x08, 0, 0x0C, 0, 0x40,
0393                    0, 0x04, 0x44, 0x48, 0, 0, 0, 0x4C, };
0394 
0395     retval = request_irq(dev->irq, ei_interrupt, 0, dev->name, dev);
0396     if (retval)
0397         return retval;
0398 
0399     outb(0x00, ioaddr); /* Disable shared memory for safety. */
0400     outb(0x80, ioaddr + 5);
0401     /* Set the IRQ line. */
0402     outb(inb(ioaddr + 4) | 0x80, ioaddr + 4);
0403     outb((inb(ioaddr + 13) & ~0x4C) | irq2reg[dev->irq], ioaddr + 13);
0404     outb(inb(ioaddr + 4) & 0x7f, ioaddr + 4);
0405 
0406     if (ei_status.block_input == &ultra_pio_input) {
0407         outb(0x11, ioaddr + 6);     /* Enable interrupts and PIO. */
0408         outb(0x01, ioaddr + 0x19);      /* Enable ring read auto-wrap. */
0409     } else
0410         outb(0x01, ioaddr + 6);     /* Enable interrupts and memory. */
0411     /* Set the early receive warning level in window 0 high enough not
0412        to receive ERW interrupts. */
0413     outb_p(E8390_NODMA+E8390_PAGE0, dev->base_addr);
0414     outb(0xff, dev->base_addr + EN0_ERWCNT);
0415     ei_open(dev);
0416     return 0;
0417 }
0418 
0419 static void
0420 ultra_reset_8390(struct net_device *dev)
0421 {
0422     int cmd_port = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC base addr */
0423     struct ei_device *ei_local = netdev_priv(dev);
0424 
0425     outb(ULTRA_RESET, cmd_port);
0426     netif_dbg(ei_local, hw, dev, "resetting Ultra, t=%ld...\n", jiffies);
0427     ei_status.txing = 0;
0428 
0429     outb(0x00, cmd_port);   /* Disable shared memory for safety. */
0430     outb(0x80, cmd_port + 5);
0431     if (ei_status.block_input == &ultra_pio_input)
0432         outb(0x11, cmd_port + 6);       /* Enable interrupts and PIO. */
0433     else
0434         outb(0x01, cmd_port + 6);       /* Enable interrupts and memory. */
0435 
0436     netif_dbg(ei_local, hw, dev, "reset done\n");
0437 }
0438 
0439 /* Grab the 8390 specific header. Similar to the block_input routine, but
0440    we don't need to be concerned with ring wrap as the header will be at
0441    the start of a page, so we optimize accordingly. */
0442 
0443 static void
0444 ultra_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page)
0445 {
0446     void __iomem *hdr_start = ei_status.mem + ((ring_page - START_PG)<<8);
0447 
0448     outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);  /* shmem on */
0449 #ifdef __BIG_ENDIAN
0450     /* Officially this is what we are doing, but the readl() is faster */
0451     /* unfortunately it isn't endian aware of the struct               */
0452     memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr));
0453     hdr->count = le16_to_cpu(hdr->count);
0454 #else
0455     ((unsigned int*)hdr)[0] = readl(hdr_start);
0456 #endif
0457     outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* shmem off */
0458 }
0459 
0460 /* Block input and output are easy on shared memory ethercards, the only
0461    complication is when the ring buffer wraps. */
0462 
0463 static void
0464 ultra_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset)
0465 {
0466     void __iomem *xfer_start = ei_status.mem + ring_offset - (START_PG<<8);
0467 
0468     /* Enable shared memory. */
0469     outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
0470 
0471     if (ring_offset + count > ei_status.stop_page*256) {
0472         /* We must wrap the input move. */
0473         int semi_count = ei_status.stop_page*256 - ring_offset;
0474         memcpy_fromio(skb->data, xfer_start, semi_count);
0475         count -= semi_count;
0476         memcpy_fromio(skb->data + semi_count, ei_status.mem + TX_PAGES * 256, count);
0477     } else {
0478         memcpy_fromio(skb->data, xfer_start, count);
0479     }
0480 
0481     outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET);  /* Disable memory. */
0482 }
0483 
0484 static void
0485 ultra_block_output(struct net_device *dev, int count, const unsigned char *buf,
0486                 int start_page)
0487 {
0488     void __iomem *shmem = ei_status.mem + ((start_page - START_PG)<<8);
0489 
0490     /* Enable shared memory. */
0491     outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
0492 
0493     memcpy_toio(shmem, buf, count);
0494 
0495     outb(0x00, dev->base_addr - ULTRA_NIC_OFFSET); /* Disable memory. */
0496 }
0497 
0498 /* The identical operations for programmed I/O cards.
0499    The PIO model is trivial to use: the 16 bit start address is written
0500    byte-sequentially to IOPA, with no intervening I/O operations, and the
0501    data is read or written to the IOPD data port.
0502    The only potential complication is that the address register is shared
0503    and must be always be rewritten between each read/write direction change.
0504    This is no problem for us, as the 8390 code ensures that we are single
0505    threaded. */
0506 static void ultra_pio_get_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr,
0507                         int ring_page)
0508 {
0509     int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
0510     outb(0x00, ioaddr + IOPA);  /* Set the address, LSB first. */
0511     outb(ring_page, ioaddr + IOPA);
0512     insw(ioaddr + IOPD, hdr, sizeof(struct e8390_pkt_hdr)>>1);
0513 }
0514 
0515 static void ultra_pio_input(struct net_device *dev, int count,
0516                           struct sk_buff *skb, int ring_offset)
0517 {
0518     int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
0519     char *buf = skb->data;
0520 
0521     /* For now set the address again, although it should already be correct. */
0522     outb(ring_offset, ioaddr + IOPA);   /* Set the address, LSB first. */
0523     outb(ring_offset >> 8, ioaddr + IOPA);
0524     /* We know skbuffs are padded to at least word alignment. */
0525     insw(ioaddr + IOPD, buf, (count+1)>>1);
0526 }
0527 static void ultra_pio_output(struct net_device *dev, int count,
0528                             const unsigned char *buf, const int start_page)
0529 {
0530     int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* ASIC addr */
0531     outb(0x00, ioaddr + IOPA);  /* Set the address, LSB first. */
0532     outb(start_page, ioaddr + IOPA);
0533     /* An extra odd byte is OK here as well. */
0534     outsw(ioaddr + IOPD, buf, (count+1)>>1);
0535 }
0536 
0537 static int
0538 ultra_close_card(struct net_device *dev)
0539 {
0540     int ioaddr = dev->base_addr - ULTRA_NIC_OFFSET; /* CMDREG */
0541     struct ei_device *ei_local = netdev_priv(dev);
0542 
0543     netif_stop_queue(dev);
0544 
0545     netif_dbg(ei_local, ifdown, dev, "Shutting down ethercard.\n");
0546 
0547     outb(0x00, ioaddr + 6);     /* Disable interrupts. */
0548     free_irq(dev->irq, dev);
0549 
0550     NS8390_init(dev, 0);
0551 
0552     /* We should someday disable shared memory and change to 8-bit mode
0553        "just in case"... */
0554 
0555     return 0;
0556 }
0557 
0558 
0559 #ifdef MODULE
0560 #define MAX_ULTRA_CARDS 4   /* Max number of Ultra cards per module */
0561 static struct net_device *dev_ultra[MAX_ULTRA_CARDS];
0562 static int io[MAX_ULTRA_CARDS];
0563 static int irq[MAX_ULTRA_CARDS];
0564 
0565 module_param_hw_array(io, int, ioport, NULL, 0);
0566 module_param_hw_array(irq, int, irq, NULL, 0);
0567 module_param_named(msg_enable, ultra_msg_enable, uint, 0444);
0568 MODULE_PARM_DESC(io, "I/O base address(es)");
0569 MODULE_PARM_DESC(irq, "IRQ number(s) (assigned)");
0570 MODULE_PARM_DESC(msg_enable, "Debug message level (see linux/netdevice.h for bitmap)");
0571 MODULE_DESCRIPTION("SMC Ultra/EtherEZ ISA/PnP Ethernet driver");
0572 MODULE_LICENSE("GPL");
0573 
0574 /* This is set up so that only a single autoprobe takes place per call.
0575 ISA device autoprobes on a running machine are not recommended. */
0576 static int __init ultra_init_module(void)
0577 {
0578     struct net_device *dev;
0579     int this_dev, found = 0;
0580 
0581     for (this_dev = 0; this_dev < MAX_ULTRA_CARDS; this_dev++) {
0582         if (io[this_dev] == 0)  {
0583             if (this_dev != 0) break; /* only autoprobe 1st one */
0584             printk(KERN_NOTICE "smc-ultra.c: Presently autoprobing (not recommended) for a single card.\n");
0585         }
0586         dev = alloc_ei_netdev();
0587         if (!dev)
0588             break;
0589         dev->irq = irq[this_dev];
0590         dev->base_addr = io[this_dev];
0591         if (do_ultra_probe(dev) == 0) {
0592             dev_ultra[found++] = dev;
0593             continue;
0594         }
0595         free_netdev(dev);
0596         printk(KERN_WARNING "smc-ultra.c: No SMC Ultra card found (i/o = 0x%x).\n", io[this_dev]);
0597         break;
0598     }
0599     if (found)
0600         return 0;
0601     return -ENXIO;
0602 }
0603 module_init(ultra_init_module);
0604 
0605 static void cleanup_card(struct net_device *dev)
0606 {
0607     /* NB: ultra_close_card() does free_irq */
0608 #ifdef __ISAPNP__
0609     struct pnp_dev *idev = (struct pnp_dev *)ei_status.priv;
0610     if (idev)
0611         pnp_device_detach(idev);
0612 #endif
0613     release_region(dev->base_addr - ULTRA_NIC_OFFSET, ULTRA_IO_EXTENT);
0614     iounmap(ei_status.mem);
0615 }
0616 
0617 static void __exit ultra_cleanup_module(void)
0618 {
0619     int this_dev;
0620 
0621     for (this_dev = 0; this_dev < MAX_ULTRA_CARDS; this_dev++) {
0622         struct net_device *dev = dev_ultra[this_dev];
0623         if (dev) {
0624             unregister_netdev(dev);
0625             cleanup_card(dev);
0626             free_netdev(dev);
0627         }
0628     }
0629 }
0630 module_exit(ultra_cleanup_module);
0631 #endif /* MODULE */