📄 wd.c
字号:
outb_p(0x00, nic_addr + EN0_RCNTHI); outb(E8390_RREAD+E8390_START, nic_addr); /* Trigger it... */ mdelay(20); dev->irq = probe_irq_off(irq_mask); outb_p(0x00, nic_addr+EN0_IMR); /* Mask all intrs. again. */ if (ei_debug > 2) printk(" autoirq is %d", dev->irq); if (dev->irq < 2) dev->irq = word16 ? 10 : 5; } else dev->irq = irqmap[((reg4 >> 5) & 0x03) + (reg1 & 0x04)]; } else if (dev->irq == 2) /* Fixup bogosity: IRQ2 is really IRQ9 */ dev->irq = 9; /* Snarf the interrupt now. There's no point in waiting since we cannot share and the board will usually be enabled. */ i = request_irq(dev->irq, ei_interrupt, 0, DRV_NAME, dev); if (i) { printk (" unable to get IRQ %d.\n", dev->irq); return i; } /* OK, were are certain this is going to work. Setup the device. */ ei_status.name = model_name; ei_status.word16 = word16; ei_status.tx_start_page = WD_START_PG; ei_status.rx_start_page = WD_START_PG + TX_PAGES; /* Don't map in the shared memory until the board is actually opened. */ /* Some cards (eg WD8003EBT) can be jumpered for more (32k!) memory. */ if (dev->mem_end != 0) { ei_status.stop_page = (dev->mem_end - dev->mem_start)/256; ei_status.priv = dev->mem_end - dev->mem_start; } else { ei_status.stop_page = word16 ? WD13_STOP_PG : WD03_STOP_PG; dev->mem_end = dev->mem_start + (ei_status.stop_page - WD_START_PG)*256; ei_status.priv = (ei_status.stop_page - WD_START_PG)*256; } ei_status.mem = ioremap(dev->mem_start, ei_status.priv); if (!ei_status.mem) { free_irq(dev->irq, dev); return -ENOMEM; } printk(" %s, IRQ %d, shared memory at %#lx-%#lx.\n", model_name, dev->irq, dev->mem_start, dev->mem_end-1); ei_status.reset_8390 = &wd_reset_8390; ei_status.block_input = &wd_block_input; ei_status.block_output = &wd_block_output; ei_status.get_8390_hdr = &wd_get_8390_hdr; dev->open = &wd_open; dev->stop = &wd_close;#ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = ei_poll;#endif NS8390_init(dev, 0);#if 1 /* Enable interrupt generation on softconfig cards -- M.U */ /* .. but possibly potentially unsafe - Donald */ if (inb(ioaddr+14) & 0x20) outb(inb(ioaddr+4)|0x80, ioaddr+4);#endif err = register_netdev(dev); if (err) free_irq(dev->irq, dev); return err;}static intwd_open(struct net_device *dev){ int ioaddr = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */ /* Map in the shared memory. Always set register 0 last to remain compatible with very old boards. */ ei_status.reg0 = ((dev->mem_start>>13) & 0x3f) | WD_MEMENB; ei_status.reg5 = ((dev->mem_start>>19) & 0x1f) | NIC16; if (ei_status.word16) outb(ei_status.reg5, ioaddr+WD_CMDREG5); outb(ei_status.reg0, ioaddr); /* WD_CMDREG */ ei_open(dev); return 0;}static voidwd_reset_8390(struct net_device *dev){ int wd_cmd_port = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */ outb(WD_RESET, wd_cmd_port); if (ei_debug > 1) printk("resetting the WD80x3 t=%lu...", jiffies); ei_status.txing = 0; /* Set up the ASIC registers, just in case something changed them. */ outb((((dev->mem_start>>13) & 0x3f)|WD_MEMENB), wd_cmd_port); if (ei_status.word16) outb(NIC16 | ((dev->mem_start>>19) & 0x1f), wd_cmd_port+WD_CMDREG5); if (ei_debug > 1) printk("reset done\n"); return;}/* Grab the 8390 specific header. Similar to the block_input routine, but we don't need to be concerned with ring wrap as the header will be at the start of a page, so we optimize accordingly. */static voidwd_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page){ int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */ void __iomem *hdr_start = ei_status.mem + ((ring_page - WD_START_PG)<<8); /* We'll always get a 4 byte header read followed by a packet read, so we enable 16 bit mode before the header, and disable after the body. */ if (ei_status.word16) outb(ISA16 | ei_status.reg5, wd_cmdreg+WD_CMDREG5);#ifdef __BIG_ENDIAN /* Officially this is what we are doing, but the readl() is faster */ /* unfortunately it isn't endian aware of the struct */ memcpy_fromio(hdr, hdr_start, sizeof(struct e8390_pkt_hdr)); hdr->count = le16_to_cpu(hdr->count);#else ((unsigned int*)hdr)[0] = readl(hdr_start);#endif}/* Block input and output are easy on shared memory ethercards, and trivial on the Western digital card where there is no choice of how to do it. The only complications are that the ring buffer wraps, and need to map switch between 8- and 16-bit modes. */static voidwd_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset){ int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */ unsigned long offset = ring_offset - (WD_START_PG<<8); void __iomem *xfer_start = ei_status.mem + offset; if (offset + count > ei_status.priv) { /* We must wrap the input move. */ int semi_count = ei_status.priv - offset; memcpy_fromio(skb->data, xfer_start, semi_count); count -= semi_count; memcpy_fromio(skb->data + semi_count, ei_status.mem + TX_PAGES * 256, count); } else { /* Packet is in one chunk -- we can copy + cksum. */ memcpy_fromio(skb->data, xfer_start, count); } /* Turn off 16 bit access so that reboot works. ISA brain-damage */ if (ei_status.word16) outb(ei_status.reg5, wd_cmdreg+WD_CMDREG5);}static voidwd_block_output(struct net_device *dev, int count, const unsigned char *buf, int start_page){ int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */ void __iomem *shmem = ei_status.mem + ((start_page - WD_START_PG)<<8); if (ei_status.word16) { /* Turn on and off 16 bit access so that reboot works. */ outb(ISA16 | ei_status.reg5, wd_cmdreg+WD_CMDREG5); memcpy_toio(shmem, buf, count); outb(ei_status.reg5, wd_cmdreg+WD_CMDREG5); } else memcpy_toio(shmem, buf, count);}static intwd_close(struct net_device *dev){ int wd_cmdreg = dev->base_addr - WD_NIC_OFFSET; /* WD_CMDREG */ if (ei_debug > 1) printk("%s: Shutting down ethercard.\n", dev->name); ei_close(dev); /* Change from 16-bit to 8-bit shared memory so reboot works. */ if (ei_status.word16) outb(ei_status.reg5, wd_cmdreg + WD_CMDREG5 ); /* And disable the shared memory. */ outb(ei_status.reg0 & ~WD_MEMENB, wd_cmdreg); return 0;}#ifdef MODULE#define MAX_WD_CARDS 4 /* Max number of wd cards per module */static struct net_device *dev_wd[MAX_WD_CARDS];static int io[MAX_WD_CARDS];static int irq[MAX_WD_CARDS];static int mem[MAX_WD_CARDS];static int mem_end[MAX_WD_CARDS]; /* for non std. mem size */module_param_array(io, int, NULL, 0);module_param_array(irq, int, NULL, 0);module_param_array(mem, int, NULL, 0);module_param_array(mem_end, int, NULL, 0);MODULE_PARM_DESC(io, "I/O base address(es)");MODULE_PARM_DESC(irq, "IRQ number(s) (ignored for PureData boards)");MODULE_PARM_DESC(mem, "memory base address(es)(ignored for PureData boards)");MODULE_PARM_DESC(mem_end, "memory end address(es)");MODULE_DESCRIPTION("ISA Western Digital wd8003/wd8013 ; SMC Elite, Elite16 ethernet driver");MODULE_LICENSE("GPL");/* This is set up so that only a single autoprobe takes place per call.ISA device autoprobes on a running machine are not recommended. */int __init init_module(void){ struct net_device *dev; int this_dev, found = 0; for (this_dev = 0; this_dev < MAX_WD_CARDS; this_dev++) { if (io[this_dev] == 0) { if (this_dev != 0) break; /* only autoprobe 1st one */ printk(KERN_NOTICE "wd.c: Presently autoprobing (not recommended) for a single card.\n"); } dev = alloc_ei_netdev(); if (!dev) break; dev->irq = irq[this_dev]; dev->base_addr = io[this_dev]; dev->mem_start = mem[this_dev]; dev->mem_end = mem_end[this_dev]; if (do_wd_probe(dev) == 0) { dev_wd[found++] = dev; continue; } free_netdev(dev); printk(KERN_WARNING "wd.c: No wd80x3 card found (i/o = 0x%x).\n", io[this_dev]); break; } if (found) return 0; return -ENXIO;}static void cleanup_card(struct net_device *dev){ free_irq(dev->irq, dev); release_region(dev->base_addr - WD_NIC_OFFSET, WD_IO_EXTENT); iounmap(ei_status.mem);}void __exitcleanup_module(void){ int this_dev; for (this_dev = 0; this_dev < MAX_WD_CARDS; this_dev++) { struct net_device *dev = dev_wd[this_dev]; if (dev) { unregister_netdev(dev); cleanup_card(dev); free_netdev(dev); } }}#endif /* MODULE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -