📄 3c509.c
字号:
if (dev->base_addr) { if (dev->mem_end == 0x3c509 /* Magic key */ && dev->base_addr >= 0x200 && dev->base_addr <= 0x3e0) ioaddr = dev->base_addr & 0x3f0; else if (dev->base_addr != ioaddr) goto out; } if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509")) { err = -EBUSY; goto out; } /* Set the adaptor tag so that the next card can be found. */ outb(0xd0 + ++current_tag, id_port); /* Activate the adaptor at the EEPROM location. */ outb((ioaddr >> 4) | 0xe0, id_port); EL3WINDOW(0); if (inw(ioaddr) != 0x6d50) goto out1; /* Free the interrupt so that some other card can use it. */ outw(0x0f00, ioaddr + WN0_IRQ);#if defined(__ISAPNP__) found: /* PNP jumps here... */#endif /* __ISAPNP__ */ memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr)); dev->base_addr = ioaddr; dev->irq = irq; dev->if_port = if_port; lp = netdev_priv(dev);#if defined(__ISAPNP__) lp->dev = &idev->dev; if (pnp_found) lp->type = EL3_PNP;#endif err = el3_common_init(dev); if (err) goto out1; el3_cards++; lp->next_dev = el3_root_dev; el3_root_dev = dev; return 0;out1:#if defined(__ISAPNP__) if (idev) pnp_device_detach(idev);#endifout: free_netdev(dev); return err;}#ifdef CONFIG_MCAstatic int __init el3_mca_probe(struct device *device){ /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, * heavily modified by Chris Beauregard * (cpbeaure@csclub.uwaterloo.ca) to support standard MCA * probing. * * redone for multi-card detection by ZP Gu (zpg@castle.net) * now works as a module */ struct el3_private *lp; short i; int ioaddr, irq, if_port; u16 phys_addr[3]; struct net_device *dev = NULL; u_char pos4, pos5; struct mca_device *mdev = to_mca_device(device); int slot = mdev->slot; int err; pos4 = mca_device_read_stored_pos(mdev, 4); pos5 = mca_device_read_stored_pos(mdev, 5); ioaddr = ((short)((pos4&0xfc)|0x02)) << 8; irq = pos5 & 0x0f; printk("3c529: found %s at slot %d\n", el3_mca_adapter_names[mdev->index], slot + 1); /* claim the slot */ strncpy(mdev->name, el3_mca_adapter_names[mdev->index], sizeof(mdev->name)); mca_device_set_claim(mdev, 1); if_port = pos4 & 0x03; irq = mca_device_transform_irq(mdev, irq); ioaddr = mca_device_transform_ioport(mdev, ioaddr); if (el3_debug > 2) { printk("3c529: irq %d ioaddr 0x%x ifport %d\n", irq, ioaddr, if_port); } EL3WINDOW(0); for (i = 0; i < 3; i++) { phys_addr[i] = htons(read_eeprom(ioaddr, i)); } dev = alloc_etherdev(sizeof (struct el3_private)); if (dev == NULL) { release_region(ioaddr, EL3_IO_EXTENT); return -ENOMEM; } netdev_boot_setup_check(dev); memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr)); dev->base_addr = ioaddr; dev->irq = irq; dev->if_port = if_port; lp = netdev_priv(dev); lp->dev = device; lp->type = EL3_MCA; device->driver_data = dev; err = el3_common_init(dev); if (err) { device->driver_data = NULL; free_netdev(dev); return -ENOMEM; } el3_cards++; return 0;}#endif /* CONFIG_MCA */#ifdef CONFIG_EISAstatic int __init el3_eisa_probe (struct device *device){ struct el3_private *lp; short i; int ioaddr, irq, if_port; u16 phys_addr[3]; struct net_device *dev = NULL; struct eisa_device *edev; int err; /* Yeepee, The driver framework is calling us ! */ edev = to_eisa_device (device); ioaddr = edev->base_addr; if (!request_region(ioaddr, EL3_IO_EXTENT, "3c509")) return -EBUSY; /* Change the register set to the configuration window 0. */ outw(SelectWindow | 0, ioaddr + 0xC80 + EL3_CMD); irq = inw(ioaddr + WN0_IRQ) >> 12; if_port = inw(ioaddr + 6)>>14; for (i = 0; i < 3; i++) phys_addr[i] = htons(read_eeprom(ioaddr, i)); /* Restore the "Product ID" to the EEPROM read register. */ read_eeprom(ioaddr, 3); dev = alloc_etherdev(sizeof (struct el3_private)); if (dev == NULL) { release_region(ioaddr, EL3_IO_EXTENT); return -ENOMEM; } netdev_boot_setup_check(dev); memcpy(dev->dev_addr, phys_addr, sizeof(phys_addr)); dev->base_addr = ioaddr; dev->irq = irq; dev->if_port = if_port; lp = netdev_priv(dev); lp->dev = device; lp->type = EL3_EISA; eisa_set_drvdata (edev, dev); err = el3_common_init(dev); if (err) { eisa_set_drvdata (edev, NULL); free_netdev(dev); return err; } el3_cards++; return 0;}#endif#if defined(CONFIG_EISA) || defined(CONFIG_MCA)/* This remove works for all device types. * * The net dev must be stored in the driver_data field */static int __devexit el3_device_remove (struct device *device){ struct net_device *dev; dev = device->driver_data; el3_common_remove (dev); return 0;}#endif/* Read a word from the EEPROM using the regular EEPROM access register. Assume that we are in register window zero. */static ushort read_eeprom(int ioaddr, int index){ outw(EEPROM_READ + index, ioaddr + 10); /* Pause for at least 162 us. for the read to take place. Some chips seem to require much longer */ mdelay(2); return inw(ioaddr + 12);}/* Read a word from the EEPROM when in the ISA ID probe state. */static ushort __init id_read_eeprom(int index){ int bit, word = 0; /* Issue read command, and pause for at least 162 us. for it to complete. Assume extra-fast 16Mhz bus. */ outb(EEPROM_READ + index, id_port); /* Pause for at least 162 us. for the read to take place. */ /* Some chips seem to require much longer */ mdelay(4); for (bit = 15; bit >= 0; bit--) word = (word << 1) + (inb(id_port) & 0x01); if (el3_debug > 3) printk(" 3c509 EEPROM word %d %#4.4x.\n", index, word); return word;}static intel3_open(struct net_device *dev){ int ioaddr = dev->base_addr; int i; outw(TxReset, ioaddr + EL3_CMD); outw(RxReset, ioaddr + EL3_CMD); outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD); i = request_irq(dev->irq, &el3_interrupt, 0, dev->name, dev); if (i) return i; EL3WINDOW(0); if (el3_debug > 3) printk("%s: Opening, IRQ %d status@%x %4.4x.\n", dev->name, dev->irq, ioaddr + EL3_STATUS, inw(ioaddr + EL3_STATUS)); el3_up(dev); if (el3_debug > 3) printk("%s: Opened 3c509 IRQ %d status %4.4x.\n", dev->name, dev->irq, inw(ioaddr + EL3_STATUS)); return 0;}static voidel3_tx_timeout (struct net_device *dev){ struct el3_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr; /* Transmitter timeout, serious problems. */ printk("%s: transmit timed out, Tx_status %2.2x status %4.4x " "Tx FIFO room %d.\n", dev->name, inb(ioaddr + TX_STATUS), inw(ioaddr + EL3_STATUS), inw(ioaddr + TX_FREE)); lp->stats.tx_errors++; dev->trans_start = jiffies; /* Issue TX_RESET and TX_START commands. */ outw(TxReset, ioaddr + EL3_CMD); outw(TxEnable, ioaddr + EL3_CMD); netif_wake_queue(dev);}static intel3_start_xmit(struct sk_buff *skb, struct net_device *dev){ struct el3_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr; unsigned long flags; netif_stop_queue (dev); lp->stats.tx_bytes += skb->len; if (el3_debug > 4) { printk("%s: el3_start_xmit(length = %u) called, status %4.4x.\n", dev->name, skb->len, inw(ioaddr + EL3_STATUS)); }#if 0#ifndef final_version { /* Error-checking code, delete someday. */ ushort status = inw(ioaddr + EL3_STATUS); if (status & 0x0001 /* IRQ line active, missed one. */ && inw(ioaddr + EL3_STATUS) & 1) { /* Make sure. */ printk("%s: Missed interrupt, status then %04x now %04x" " Tx %2.2x Rx %4.4x.\n", dev->name, status, inw(ioaddr + EL3_STATUS), inb(ioaddr + TX_STATUS), inw(ioaddr + RX_STATUS)); /* Fake interrupt trigger by masking, acknowledge interrupts. */ outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD); outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq, ioaddr + EL3_CMD); outw(SetStatusEnb | 0xff, ioaddr + EL3_CMD); } }#endif#endif /* * We lock the driver against other processors. Note * we don't need to lock versus the IRQ as we suspended * that. This means that we lose the ability to take * an RX during a TX upload. That sucks a bit with SMP * on an original 3c509 (2K buffer) * * Using disable_irq stops us crapping on other * time sensitive devices. */ spin_lock_irqsave(&lp->lock, flags); /* Put out the doubleword header... */ outw(skb->len, ioaddr + TX_FIFO); outw(0x00, ioaddr + TX_FIFO); /* ... and the packet rounded to a doubleword. */ outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2); dev->trans_start = jiffies; if (inw(ioaddr + TX_FREE) > 1536) netif_start_queue(dev); else /* Interrupt us when the FIFO has room for max-sized packet. */ outw(SetTxThreshold + 1536, ioaddr + EL3_CMD); spin_unlock_irqrestore(&lp->lock, flags); dev_kfree_skb (skb); /* Clear the Tx status stack. */ { short tx_status; int i = 4; while (--i > 0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) { if (tx_status & 0x38) lp->stats.tx_aborted_errors++; if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD); if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD); outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ } } return 0;}/* The EL3 interrupt handler. */static irqreturn_tel3_interrupt(int irq, void *dev_id){ struct net_device *dev = dev_id; struct el3_private *lp; int ioaddr, status; int i = max_interrupt_work; lp = netdev_priv(dev); spin_lock(&lp->lock); ioaddr = dev->base_addr; if (el3_debug > 4) { status = inw(ioaddr + EL3_STATUS); printk("%s: interrupt, status %4.4x.\n", dev->name, status); } while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete | StatsFull)) { if (status & RxComplete) el3_rx(dev); if (status & TxAvailable) { if (el3_debug > 5) printk(" TX room bit was handled.\n"); /* There's room in the FIFO for a full-sized packet. */ outw(AckIntr | TxAvailable, ioaddr + EL3_CMD); netif_wake_queue (dev); } if (status & (AdapterFailure | RxEarly | StatsFull | TxComplete)) { /* Handle all uncommon interrupts. */ if (status & StatsFull) /* Empty statistics. */ update_stats(dev); if (status & RxEarly) { /* Rx early is unused. */ el3_rx(dev); outw(AckIntr | RxEarly, ioaddr + EL3_CMD); } if (status & TxComplete) { /* Really Tx error. */ struct el3_private *lp = netdev_priv(dev); short tx_status; int i = 4; while (--i>0 && (tx_status = inb(ioaddr + TX_STATUS)) > 0) { if (tx_status & 0x38) lp->stats.tx_aborted_errors++; if (tx_status & 0x30) outw(TxReset, ioaddr + EL3_CMD); if (tx_status & 0x3C) outw(TxEnable, ioaddr + EL3_CMD); outb(0x00, ioaddr + TX_STATUS); /* Pop the status stack. */ } } if (status & AdapterFailure) { /* Adapter failure requires Rx reset and reinit. */ outw(RxReset, ioaddr + EL3_CMD); /* Set the Rx filter to the current state. */ outw(SetRxFilter | RxStation | RxBroadcast | (dev->flags & IFF_ALLMULTI ? RxMulticast : 0) | (dev->flags & IFF_PROMISC ? RxProm : 0), ioaddr + EL3_CMD); outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */ outw(AckIntr | AdapterFailure, ioaddr + EL3_CMD); } } if (--i < 0) { printk("%s: Infinite loop in interrupt, status %4.4x.\n", dev->name, status); /* Clear all interrupts. */ outw(AckIntr | 0xFF, ioaddr + EL3_CMD); break; } /* Acknowledge the IRQ. */ outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD); /* Ack IRQ */ } if (el3_debug > 4) { printk("%s: exiting interrupt, status %4.4x.\n", dev->name, inw(ioaddr + EL3_STATUS)); } spin_unlock(&lp->lock); return IRQ_HANDLED;}#ifdef CONFIG_NET_POLL_CONTROLLER/* * Polling receive - used by netconsole and other diagnostic tools * to allow network i/o with interrupts disabled. */static void el3_poll_controller(struct net_device *dev){ disable_irq(dev->irq); el3_interrupt(dev->irq, dev); enable_irq(dev->irq);}#endifstatic struct net_device_stats *el3_get_stats(struct net_device *dev){ struct el3_private *lp = netdev_priv(dev); unsigned long flags; /* * This is fast enough not to bother with disable IRQ * stuff. */ spin_lock_irqsave(&lp->lock, flags); update_stats(dev); spin_unlock_irqrestore(&lp->lock, flags); return &lp->stats;}/* Update statistics. We change to register window 6, so this should be run single-threaded if the device is active. This is expected to be a rare operation, and it's simpler for the rest of the driver to assume that window 1 is always valid rather than use a special window-state variable. */static void update_stats(struct net_device *dev){ struct el3_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr; if (el3_debug > 5) printk(" Updating the statistics.\n"); /* Turn off statistics updates while reading. */ outw(StatsDisable, ioaddr + EL3_CMD); /* Switch to the stats window, and read everything. */ EL3WINDOW(6); lp->stats.tx_carrier_errors += inb(ioaddr + 0); lp->stats.tx_heartbeat_errors += inb(ioaddr + 1); /* Multiple collisions. */ inb(ioaddr + 2); lp->stats.collisions += inb(ioaddr + 3); lp->stats.tx_window_errors += inb(ioaddr + 4); lp->stats.rx_fifo_errors += inb(ioaddr + 5); lp->stats.tx_packets += inb(ioaddr + 6); /* Rx packets */ inb(ioaddr + 7); /* Tx deferrals */ inb(ioaddr + 8); inw(ioaddr + 10); /* Total Rx and Tx octets. */ inw(ioaddr + 12); /* Back to window 1, and turn statistics back on. */ EL3WINDOW(1); outw(StatsEnable, ioaddr + EL3_CMD); return;}static intel3_rx(struct net_device *dev){ struct el3_private *lp = netdev_priv(dev); int ioaddr = dev->base_addr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -