0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
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
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 { }
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
0117
0118 #define ULTRA_CMDREG 0
0119 #define ULTRA_RESET 0x80
0120 #define ULTRA_MEMENB 0x40
0121 #define IOPD 0x02
0122 #define IOPA 0x07
0123 #define ULTRA_NIC_OFFSET 16
0124 #define ULTRA_IO_EXTENT 32
0125 #define EN0_ERWCNT 0x08
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
0136
0137
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)
0147 return ultra_probe1(dev, base_addr);
0148 else if (base_addr != 0)
0149 return -ENXIO;
0150
0151 #ifdef __ISAPNP__
0152
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
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
0221 if ((idreg & 0xF0) != 0x20
0222 && (idreg & 0xF0) != 0x40) {
0223 retval = -ENODEV;
0224 goto out;
0225 }
0226
0227
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
0250
0251 outb(0x80 | reg4, ioaddr + 4);
0252
0253
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
0260
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
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
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
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
0359 if (!pnp_port_valid(idev, 0) || !pnp_irq_valid(idev, 0))
0360 goto __again;
0361
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) {
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;
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);
0400 outb(0x80, ioaddr + 5);
0401
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);
0408 outb(0x01, ioaddr + 0x19);
0409 } else
0410 outb(0x01, ioaddr + 6);
0411
0412
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;
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);
0430 outb(0x80, cmd_port + 5);
0431 if (ei_status.block_input == &ultra_pio_input)
0432 outb(0x11, cmd_port + 6);
0433 else
0434 outb(0x01, cmd_port + 6);
0435
0436 netif_dbg(ei_local, hw, dev, "reset done\n");
0437 }
0438
0439
0440
0441
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);
0449 #ifdef __BIG_ENDIAN
0450
0451
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);
0458 }
0459
0460
0461
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
0469 outb(ULTRA_MEMENB, dev->base_addr - ULTRA_NIC_OFFSET);
0470
0471 if (ring_offset + count > ei_status.stop_page*256) {
0472
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);
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
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);
0496 }
0497
0498
0499
0500
0501
0502
0503
0504
0505
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;
0510 outb(0x00, ioaddr + IOPA);
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;
0519 char *buf = skb->data;
0520
0521
0522 outb(ring_offset, ioaddr + IOPA);
0523 outb(ring_offset >> 8, ioaddr + IOPA);
0524
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;
0531 outb(0x00, ioaddr + IOPA);
0532 outb(start_page, ioaddr + IOPA);
0533
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;
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);
0548 free_irq(dev->irq, dev);
0549
0550 NS8390_init(dev, 0);
0551
0552
0553
0554
0555 return 0;
0556 }
0557
0558
0559 #ifdef MODULE
0560 #define MAX_ULTRA_CARDS 4
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
0575
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;
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
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