ne2k-pci.c
来自「linux 内核源代码」· C语言 代码 · 共 717 行 · 第 1/2 页
C
717 行
#ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = ei_poll;#endif NS8390_init(dev, 0); i = register_netdev(dev); if (i) goto err_out_free_netdev; for(i = 0; i < 6; i++) dev->dev_addr[i] = SA_prom[i]; printk("%s: %s found at %#lx, IRQ %d, %s.\n", dev->name, pci_clone_list[chip_idx].name, ioaddr, dev->irq, print_mac(mac, dev->dev_addr)); memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); return 0;err_out_free_netdev: free_netdev (dev);err_out_free_res: release_region (ioaddr, NE_IO_EXTENT); pci_set_drvdata (pdev, NULL); return -ENODEV;}/* * Magic incantation sequence for full duplex on the supported cards. */static inline int set_realtek_fdx(struct net_device *dev){ long ioaddr = dev->base_addr; outb(0xC0 + E8390_NODMA, ioaddr + NE_CMD); /* Page 3 */ outb(0xC0, ioaddr + 0x01); /* Enable writes to CONFIG3 */ outb(0x40, ioaddr + 0x06); /* Enable full duplex */ outb(0x00, ioaddr + 0x01); /* Disable writes to CONFIG3 */ outb(E8390_PAGE0 + E8390_NODMA, ioaddr + NE_CMD); /* Page 0 */ return 0;}static inline int set_holtek_fdx(struct net_device *dev){ long ioaddr = dev->base_addr; outb(inb(ioaddr + 0x20) | 0x80, ioaddr + 0x20); return 0;}static int ne2k_pci_set_fdx(struct net_device *dev){ if (ei_status.ne2k_flags & REALTEK_FDX) return set_realtek_fdx(dev); else if (ei_status.ne2k_flags & HOLTEK_FDX) return set_holtek_fdx(dev); return -EOPNOTSUPP;}static int ne2k_pci_open(struct net_device *dev){ int ret = request_irq(dev->irq, ei_interrupt, IRQF_SHARED, dev->name, dev); if (ret) return ret; if (ei_status.ne2k_flags & FORCE_FDX) ne2k_pci_set_fdx(dev); 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 *b = (u16 *)buf; *b++ = le16_to_cpu(inw(NE_BASE + NE_DATAPORT)); buf = (char *)b; } 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) { u16 *b = (u16 *)buf; outw(cpu_to_le16(*b++), NE_BASE + NE_DATAPORT); buf = (char *)b; } } } 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 void ne2k_pci_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info){ struct ei_device *ei = dev->priv; struct pci_dev *pci_dev = (struct pci_dev *) ei->priv; strcpy(info->driver, DRV_NAME); strcpy(info->version, DRV_VERSION); strcpy(info->bus_info, pci_name(pci_dev));}static const struct ethtool_ops ne2k_pci_ethtool_ops = { .get_drvinfo = ne2k_pci_get_drvinfo,};static void __devexit ne2k_pci_remove_one (struct pci_dev *pdev){ struct net_device *dev = pci_get_drvdata(pdev); BUG_ON(!dev); unregister_netdev(dev); release_region(dev->base_addr, NE_IO_EXTENT); free_netdev(dev); pci_disable_device(pdev); pci_set_drvdata(pdev, NULL);}#ifdef CONFIG_PMstatic int ne2k_pci_suspend (struct pci_dev *pdev, pm_message_t state){ struct net_device *dev = pci_get_drvdata (pdev); netif_device_detach(dev); pci_save_state(pdev); pci_disable_device(pdev); pci_set_power_state(pdev, pci_choose_state(pdev, state)); return 0;}static int ne2k_pci_resume (struct pci_dev *pdev){ struct net_device *dev = pci_get_drvdata (pdev); int rc; pci_set_power_state(pdev, 0); pci_restore_state(pdev); rc = pci_enable_device(pdev); if (rc) return rc; NS8390_init(dev, 1); netif_device_attach(dev); return 0;}#endif /* CONFIG_PM */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,#ifdef CONFIG_PM .suspend = ne2k_pci_suspend, .resume = ne2k_pci_resume,#endif /* CONFIG_PM */};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_register_driver(&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 + =
减小字号Ctrl + -
显示快捷键?