?? ne2k-pci.c
字號:
printk (KERN_ERR "ne2kpci(%s): unable to get memory for dev->priv.\n", pdev->slot_name); goto err_out_free_netdev; } ei_status.name = pci_clone_list[chip_idx].name; ei_status.tx_start_page = start_page; ei_status.stop_page = stop_page; ei_status.word16 = 1; ei_status.ne2k_flags = flags; if (fnd_cnt < MAX_UNITS) { if (full_duplex[fnd_cnt] > 0 || (options[fnd_cnt] & FORCE_FDX)) ei_status.ne2k_flags |= FORCE_FDX; } ei_status.rx_start_page = start_page + TX_PAGES;#ifdef PACKETBUF_MEMSIZE /* Allow the packet buffer size to be overridden by know-it-alls. */ ei_status.stop_page = ei_status.tx_start_page + PACKETBUF_MEMSIZE;#endif ei_status.reset_8390 = &ne2k_pci_reset_8390; ei_status.block_input = &ne2k_pci_block_input; ei_status.block_output = &ne2k_pci_block_output; ei_status.get_8390_hdr = &ne2k_pci_get_8390_hdr; ei_status.priv = (unsigned long) pdev; dev->open = &ne2k_pci_open; dev->stop = &ne2k_pci_close; dev->do_ioctl = &netdev_ioctl; NS8390_init(dev, 0); i = register_netdev(dev); if (i) goto err_out_free_8390; printk("%s: %s found at %#lx, IRQ %d, ", dev->name, pci_clone_list[chip_idx].name, ioaddr, dev->irq); for(i = 0; i < 6; i++) { printk("%2.2X%s", SA_prom[i], i == 5 ? ".\n": ":"); dev->dev_addr[i] = SA_prom[i]; } return 0;err_out_free_8390: kfree(dev->priv);err_out_free_netdev: kfree (dev);err_out_free_res: release_region (ioaddr, NE_IO_EXTENT); pci_set_drvdata (pdev, NULL); return -ENODEV;}static int ne2k_pci_open(struct net_device *dev){ int ret = request_irq(dev->irq, ei_interrupt, SA_SHIRQ, dev->name, dev); if (ret) return ret; /* Set full duplex for the chips that we know about. */ if (ei_status.ne2k_flags & FORCE_FDX) { long ioaddr = dev->base_addr; if (ei_status.ne2k_flags & REALTEK_FDX) { outb(0xC0 + E8390_NODMA, ioaddr + NE_CMD); /* Page 3 */ outb(inb(ioaddr + 0x20) | 0x80, ioaddr + 0x20); } else if (ei_status.ne2k_flags & HOLTEK_FDX) outb(inb(ioaddr + 0x20) | 0x80, ioaddr + 0x20); } ei_open(dev); return 0;}static int ne2k_pci_close(struct net_device *dev){ ei_close(dev); free_irq(dev->irq, dev); return 0;}/* Hard reset the card. This used to pause for the same period that a 8390 reset command required, but that shouldn't be necessary. */static void ne2k_pci_reset_8390(struct net_device *dev){ unsigned long reset_start_time = jiffies; if (debug > 1) printk("%s: Resetting the 8390 t=%ld...", dev->name, jiffies); outb(inb(NE_BASE + NE_RESET), NE_BASE + NE_RESET); ei_status.txing = 0; ei_status.dmaing = 0; /* This check _should_not_ be necessary, omit eventually. */ while ((inb(NE_BASE+EN0_ISR) & ENISR_RESET) == 0) if (jiffies - reset_start_time > 2) { printk("%s: ne2k_pci_reset_8390() did not complete.\n", dev->name); break; } outb(ENISR_RESET, NE_BASE + EN0_ISR); /* Ack intr. */}/* 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 void ne2k_pci_get_8390_hdr(struct net_device *dev, struct e8390_pkt_hdr *hdr, int ring_page){ long nic_base = dev->base_addr; /* This *shouldn't* happen. If it does, it's the last thing you'll see */ if (ei_status.dmaing) { printk("%s: DMAing conflict in ne2k_pci_get_8390_hdr " "[DMAstat:%d][irqlock:%d].\n", dev->name, ei_status.dmaing, ei_status.irqlock); return; } ei_status.dmaing |= 0x01; outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); outb(sizeof(struct e8390_pkt_hdr), nic_base + EN0_RCNTLO); outb(0, nic_base + EN0_RCNTHI); outb(0, nic_base + EN0_RSARLO); /* On page boundary */ outb(ring_page, nic_base + EN0_RSARHI); outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); if (ei_status.ne2k_flags & ONLY_16BIT_IO) { insw(NE_BASE + NE_DATAPORT, hdr, sizeof(struct e8390_pkt_hdr)>>1); } else { *(u32*)hdr = le32_to_cpu(inl(NE_BASE + NE_DATAPORT)); le16_to_cpus(&hdr->count); } outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ ei_status.dmaing &= ~0x01;}/* Block input and output, similar to the Crynwr packet driver. If you are porting to a new ethercard, look at the packet driver source for hints. The NEx000 doesn't share the on-board packet memory -- you have to put the packet out through the "remote DMA" dataport using outb. */static void ne2k_pci_block_input(struct net_device *dev, int count, struct sk_buff *skb, int ring_offset){ long nic_base = dev->base_addr; char *buf = skb->data; /* This *shouldn't* happen. If it does, it's the last thing you'll see */ if (ei_status.dmaing) { printk("%s: DMAing conflict in ne2k_pci_block_input " "[DMAstat:%d][irqlock:%d].\n", dev->name, ei_status.dmaing, ei_status.irqlock); return; } ei_status.dmaing |= 0x01; if (ei_status.ne2k_flags & ONLY_32BIT_IO) count = (count + 3) & 0xFFFC; outb(E8390_NODMA+E8390_PAGE0+E8390_START, nic_base+ NE_CMD); outb(count & 0xff, nic_base + EN0_RCNTLO); outb(count >> 8, nic_base + EN0_RCNTHI); outb(ring_offset & 0xff, nic_base + EN0_RSARLO); outb(ring_offset >> 8, nic_base + EN0_RSARHI); outb(E8390_RREAD+E8390_START, nic_base + NE_CMD); if (ei_status.ne2k_flags & ONLY_16BIT_IO) { insw(NE_BASE + NE_DATAPORT,buf,count>>1); if (count & 0x01) { buf[count-1] = inb(NE_BASE + NE_DATAPORT); } } else { insl(NE_BASE + NE_DATAPORT, buf, count>>2); if (count & 3) { buf += count & ~3; if (count & 2) *((u16*)buf)++ = le16_to_cpu(inw(NE_BASE + NE_DATAPORT)); if (count & 1) *buf = inb(NE_BASE + NE_DATAPORT); } } outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ ei_status.dmaing &= ~0x01;}static void ne2k_pci_block_output(struct net_device *dev, int count, const unsigned char *buf, const int start_page){ long nic_base = NE_BASE; unsigned long dma_start; /* On little-endian it's always safe to round the count up for word writes. */ if (ei_status.ne2k_flags & ONLY_32BIT_IO) count = (count + 3) & 0xFFFC; else if (count & 0x01) count++; /* This *shouldn't* happen. If it does, it's the last thing you'll see */ if (ei_status.dmaing) { printk("%s: DMAing conflict in ne2k_pci_block_output." "[DMAstat:%d][irqlock:%d]\n", dev->name, ei_status.dmaing, ei_status.irqlock); return; } ei_status.dmaing |= 0x01; /* We should already be in page 0, but to be safe... */ outb(E8390_PAGE0+E8390_START+E8390_NODMA, nic_base + NE_CMD);#ifdef NE8390_RW_BUGFIX /* Handle the read-before-write bug the same way as the Crynwr packet driver -- the NatSemi method doesn't work. Actually this doesn't always work either, but if you have problems with your NEx000 this is better than nothing! */ outb(0x42, nic_base + EN0_RCNTLO); outb(0x00, nic_base + EN0_RCNTHI); outb(0x42, nic_base + EN0_RSARLO); outb(0x00, nic_base + EN0_RSARHI); outb(E8390_RREAD+E8390_START, nic_base + NE_CMD);#endif outb(ENISR_RDC, nic_base + EN0_ISR); /* Now the normal output. */ outb(count & 0xff, nic_base + EN0_RCNTLO); outb(count >> 8, nic_base + EN0_RCNTHI); outb(0x00, nic_base + EN0_RSARLO); outb(start_page, nic_base + EN0_RSARHI); outb(E8390_RWRITE+E8390_START, nic_base + NE_CMD); if (ei_status.ne2k_flags & ONLY_16BIT_IO) { outsw(NE_BASE + NE_DATAPORT, buf, count>>1); } else { outsl(NE_BASE + NE_DATAPORT, buf, count>>2); if (count & 3) { buf += count & ~3; if (count & 2) outw(cpu_to_le16(*((u16*)buf)++), NE_BASE + NE_DATAPORT); } } dma_start = jiffies; while ((inb(nic_base + EN0_ISR) & ENISR_RDC) == 0) if (jiffies - dma_start > 2) { /* Avoid clock roll-over. */ printk(KERN_WARNING "%s: timeout waiting for Tx RDC.\n", dev->name); ne2k_pci_reset_8390(dev); NS8390_init(dev,1); break; } outb(ENISR_RDC, nic_base + EN0_ISR); /* Ack intr. */ ei_status.dmaing &= ~0x01; return;}static int netdev_ethtool_ioctl(struct net_device *dev, void *useraddr){ struct ei_device *ei = dev->priv; struct pci_dev *pci_dev = (struct pci_dev *) ei->priv; u32 ethcmd; if (copy_from_user(ðcmd, useraddr, sizeof(ethcmd))) return -EFAULT; switch (ethcmd) { case ETHTOOL_GDRVINFO: { struct ethtool_drvinfo info = {ETHTOOL_GDRVINFO}; strcpy(info.driver, DRV_NAME); strcpy(info.version, DRV_VERSION); strcpy(info.bus_info, pci_dev->slot_name); if (copy_to_user(useraddr, &info, sizeof(info))) return -EFAULT; return 0; } } return -EOPNOTSUPP;}static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd){ switch(cmd) { case SIOCETHTOOL: return netdev_ethtool_ioctl(dev, (void *) rq->ifr_data); default: return -EOPNOTSUPP; }}static void __devexit ne2k_pci_remove_one (struct pci_dev *pdev){ struct net_device *dev = pci_get_drvdata(pdev); if (!dev) BUG(); unregister_netdev(dev); release_region(dev->base_addr, NE_IO_EXTENT); kfree(dev); pci_set_drvdata(pdev, NULL);}static struct pci_driver ne2k_driver = { name: DRV_NAME, probe: ne2k_pci_init_one, remove: __devexit_p(ne2k_pci_remove_one), id_table: ne2k_pci_tbl,};static int __init ne2k_pci_init(void){/* when a module, this is printed whether or not devices are found in probe */#ifdef MODULE printk(version);#endif return pci_module_init (&ne2k_driver);}static void __exit ne2k_pci_cleanup(void){ pci_unregister_driver (&ne2k_driver);}module_init(ne2k_pci_init);module_exit(ne2k_pci_cleanup);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -