📄 tulip_core.c
字号:
if (!force_csr0 && (tp->flags & HAS_PCI_MWI)) tulip_mwi_config (pdev, dev);#else /* MWI is broken for DC21143 rev 65... */ if (chip_idx == DC21143 && chip_rev == 65) tp->csr0 &= ~MWI;#endif /* Stop the chip's Tx and Rx processes. */ tulip_stop_rxtx(tp); pci_set_master(pdev);#ifdef CONFIG_GSC if (pdev->subsystem_vendor == PCI_VENDOR_ID_HP) { switch (pdev->subsystem_device) { default: break; case 0x1061: case 0x1062: case 0x1063: case 0x1098: case 0x1099: case 0x10EE: tp->flags |= HAS_SWAPPED_SEEPROM | NEEDS_FAKE_MEDIA_TABLE; chip_name = "GSC DS21140 Tulip"; } }#endif /* Clear the missed-packet counter. */ ioread32(ioaddr + CSR8); /* The station address ROM is read byte serially. The register must be polled, waiting for the value to be read bit serially from the EEPROM. */ ee_data = tp->eeprom; sum = 0; if (chip_idx == LC82C168) { for (i = 0; i < 3; i++) { int value, boguscnt = 100000; iowrite32(0x600 | i, ioaddr + 0x98); do value = ioread32(ioaddr + CSR9); while (value < 0 && --boguscnt > 0); put_unaligned(le16_to_cpu(value), ((u16*)dev->dev_addr) + i); sum += value & 0xffff; } } else if (chip_idx == COMET) { /* No need to read the EEPROM. */ put_unaligned(cpu_to_le32(ioread32(ioaddr + 0xA4)), (u32 *)dev->dev_addr); put_unaligned(cpu_to_le16(ioread32(ioaddr + 0xA8)), (u16 *)(dev->dev_addr + 4)); for (i = 0; i < 6; i ++) sum += dev->dev_addr[i]; } else { /* A serial EEPROM interface, we read now and sort it out later. */ int sa_offset = 0; int ee_addr_size = tulip_read_eeprom(dev, 0xff, 8) & 0x40000 ? 8 : 6; for (i = 0; i < sizeof(tp->eeprom); i+=2) { u16 data = tulip_read_eeprom(dev, i/2, ee_addr_size); ee_data[i] = data & 0xff; ee_data[i + 1] = data >> 8; } /* DEC now has a specification (see Notes) but early board makers just put the address in the first EEPROM locations. */ /* This does memcmp(ee_data, ee_data+16, 8) */ for (i = 0; i < 8; i ++) if (ee_data[i] != ee_data[16+i]) sa_offset = 20; if (chip_idx == CONEXANT) { /* Check that the tuple type and length is correct. */ if (ee_data[0x198] == 0x04 && ee_data[0x199] == 6) sa_offset = 0x19A; } else if (ee_data[0] == 0xff && ee_data[1] == 0xff && ee_data[2] == 0) { sa_offset = 2; /* Grrr, damn Matrox boards. */ multiport_cnt = 4; }#ifdef CONFIG_DDB5476 if ((pdev->bus->number == 0) && (PCI_SLOT(pdev->devfn) == 6)) { /* DDB5476 MAC address in first EEPROM locations. */ sa_offset = 0; /* No media table either */ tp->flags &= ~HAS_MEDIA_TABLE; }#endif#ifdef CONFIG_DDB5477 if ((pdev->bus->number == 0) && (PCI_SLOT(pdev->devfn) == 4)) { /* DDB5477 MAC address in first EEPROM locations. */ sa_offset = 0; /* No media table either */ tp->flags &= ~HAS_MEDIA_TABLE; }#endif#ifdef CONFIG_MIPS_COBALT if ((pdev->bus->number == 0) && ((PCI_SLOT(pdev->devfn) == 7) || (PCI_SLOT(pdev->devfn) == 12))) { /* Cobalt MAC address in first EEPROM locations. */ sa_offset = 0; /* Ensure our media table fixup get's applied */ memcpy(ee_data + 16, ee_data, 8); }#endif#ifdef CONFIG_GSC /* Check to see if we have a broken srom */ if (ee_data[0] == 0x61 && ee_data[1] == 0x10) { /* pci_vendor_id and subsystem_id are swapped */ ee_data[0] = ee_data[2]; ee_data[1] = ee_data[3]; ee_data[2] = 0x61; ee_data[3] = 0x10; /* HSC-PCI boards need to be byte-swaped and shifted * up 1 word. This shift needs to happen at the end * of the MAC first because of the 2 byte overlap. */ for (i = 4; i >= 0; i -= 2) { ee_data[17 + i + 3] = ee_data[17 + i]; ee_data[16 + i + 5] = ee_data[16 + i]; } }#endif for (i = 0; i < 6; i ++) { dev->dev_addr[i] = ee_data[i + sa_offset]; sum += ee_data[i + sa_offset]; } } /* Lite-On boards have the address byte-swapped. */ if ((dev->dev_addr[0] == 0xA0 || dev->dev_addr[0] == 0xC0 || dev->dev_addr[0] == 0x02) && dev->dev_addr[1] == 0x00) for (i = 0; i < 6; i+=2) { char tmp = dev->dev_addr[i]; dev->dev_addr[i] = dev->dev_addr[i+1]; dev->dev_addr[i+1] = tmp; } /* On the Zynx 315 Etherarray and other multiport boards only the first Tulip has an EEPROM. On Sparc systems the mac address is held in the OBP property "local-mac-address". The addresses of the subsequent ports are derived from the first. Many PCI BIOSes also incorrectly report the IRQ line, so we correct that here as well. */ if (sum == 0 || sum == 6*0xff) {#if defined(__sparc__) struct pcidev_cookie *pcp = pdev->sysdata;#endif eeprom_missing = 1; for (i = 0; i < 5; i++) dev->dev_addr[i] = last_phys_addr[i]; dev->dev_addr[i] = last_phys_addr[i] + 1;#if defined(__sparc__) if ((pcp != NULL) && prom_getproplen(pcp->prom_node, "local-mac-address") == 6) { prom_getproperty(pcp->prom_node, "local-mac-address", dev->dev_addr, 6); }#endif#if defined(__i386__) /* Patch up x86 BIOS bug. */ if (last_irq) irq = last_irq;#endif } for (i = 0; i < 6; i++) last_phys_addr[i] = dev->dev_addr[i]; last_irq = irq; dev->irq = irq; /* The lower four bits are the media type. */ if (board_idx >= 0 && board_idx < MAX_UNITS) { if (options[board_idx] & MEDIA_MASK) tp->default_port = options[board_idx] & MEDIA_MASK; if ((options[board_idx] & FullDuplex) || full_duplex[board_idx] > 0) tp->full_duplex = 1; if (mtu[board_idx] > 0) dev->mtu = mtu[board_idx]; } if (dev->mem_start & MEDIA_MASK) tp->default_port = dev->mem_start & MEDIA_MASK; if (tp->default_port) { printk(KERN_INFO "tulip%d: Transceiver selection forced to %s.\n", board_idx, medianame[tp->default_port & MEDIA_MASK]); tp->medialock = 1; if (tulip_media_cap[tp->default_port] & MediaAlwaysFD) tp->full_duplex = 1; } if (tp->full_duplex) tp->full_duplex_lock = 1; if (tulip_media_cap[tp->default_port] & MediaIsMII) { u16 media2advert[] = { 0x20, 0x40, 0x03e0, 0x60, 0x80, 0x100, 0x200 }; tp->mii_advertise = media2advert[tp->default_port - 9]; tp->mii_advertise |= (tp->flags & HAS_8023X); /* Matching bits! */ } if (tp->flags & HAS_MEDIA_TABLE) { sprintf(dev->name, "tulip%d", board_idx); /* hack */ tulip_parse_eeprom(dev); strcpy(dev->name, "eth%d"); /* un-hack */ } if ((tp->flags & ALWAYS_CHECK_MII) || (tp->mtable && tp->mtable->has_mii) || ( ! tp->mtable && (tp->flags & HAS_MII))) { if (tp->mtable && tp->mtable->has_mii) { for (i = 0; i < tp->mtable->leafcount; i++) if (tp->mtable->mleaf[i].media == 11) { tp->cur_index = i; tp->saved_if_port = dev->if_port; tulip_select_media(dev, 2); dev->if_port = tp->saved_if_port; break; } } /* Find the connected MII xcvrs. Doing this in open() would allow detecting external xcvrs later, but takes much time. */ tulip_find_mii (dev, board_idx); } /* The Tulip-specific entries in the device structure. */ dev->open = tulip_open; dev->hard_start_xmit = tulip_start_xmit; dev->tx_timeout = tulip_tx_timeout; dev->watchdog_timeo = TX_TIMEOUT;#ifdef CONFIG_TULIP_NAPI dev->poll = tulip_poll; dev->weight = 16;#endif dev->stop = tulip_close; dev->get_stats = tulip_get_stats; dev->do_ioctl = private_ioctl; dev->set_multicast_list = set_rx_mode;#ifdef CONFIG_NET_POLL_CONTROLLER dev->poll_controller = &poll_tulip;#endif SET_ETHTOOL_OPS(dev, &ops); if (register_netdev(dev)) goto err_out_free_ring; printk(KERN_INFO "%s: %s rev %d at %p,", dev->name, chip_name, chip_rev, ioaddr); pci_set_drvdata(pdev, dev); if (eeprom_missing) printk(" EEPROM not present,"); for (i = 0; i < 6; i++) printk("%c%2.2X", i ? ':' : ' ', dev->dev_addr[i]); printk(", IRQ %d.\n", irq); if (tp->chip_id == PNIC2) tp->link_change = pnic2_lnk_change; else if (tp->flags & HAS_NWAY) tp->link_change = t21142_lnk_change; else if (tp->flags & HAS_PNICNWAY) tp->link_change = pnic_lnk_change; /* Reset the xcvr interface and turn on heartbeat. */ switch (chip_idx) { case DC21140: case DM910X: default: if (tp->mtable) iowrite32(tp->mtable->csr12dir | 0x100, ioaddr + CSR12); break; case DC21142: if (tp->mii_cnt || tulip_media_cap[dev->if_port] & MediaIsMII) { iowrite32(csr6_mask_defstate, ioaddr + CSR6); iowrite32(0x0000, ioaddr + CSR13); iowrite32(0x0000, ioaddr + CSR14); iowrite32(csr6_mask_hdcap, ioaddr + CSR6); } else t21142_start_nway(dev); break; case PNIC2: /* just do a reset for sanity sake */ iowrite32(0x0000, ioaddr + CSR13); iowrite32(0x0000, ioaddr + CSR14); break; case LC82C168: if ( ! tp->mii_cnt) { tp->nway = 1; tp->nwayset = 0; iowrite32(csr6_ttm | csr6_ca, ioaddr + CSR6); iowrite32(0x30, ioaddr + CSR12); iowrite32(0x0001F078, ioaddr + CSR6); iowrite32(0x0201F078, ioaddr + CSR6); /* Turn on autonegotiation. */ } break; case MX98713: case COMPEX9881: iowrite32(0x00000000, ioaddr + CSR6); iowrite32(0x000711C0, ioaddr + CSR14); /* Turn on NWay. */ iowrite32(0x00000001, ioaddr + CSR13); break; case MX98715: case MX98725: iowrite32(0x01a80000, ioaddr + CSR6); iowrite32(0xFFFFFFFF, ioaddr + CSR14); iowrite32(0x00001000, ioaddr + CSR12); break; case COMET: /* No initialization necessary. */ break; } /* put the chip in snooze mode until opened */ tulip_set_power_state (tp, 0, 1); return 0;err_out_free_ring: pci_free_consistent (pdev, sizeof (struct tulip_rx_desc) * RX_RING_SIZE + sizeof (struct tulip_tx_desc) * TX_RING_SIZE, tp->rx_ring, tp->rx_ring_dma);err_out_mtable: kfree (tp->mtable); pci_iounmap(pdev, ioaddr);err_out_free_res: pci_release_regions (pdev);err_out_free_netdev: free_netdev (dev); return -ENODEV;}#ifdef CONFIG_PMstatic int tulip_suspend (struct pci_dev *pdev, pm_message_t state){ struct net_device *dev = pci_get_drvdata(pdev); if (!dev) return -EINVAL; if (netif_running(dev)) tulip_down(dev); netif_device_detach(dev); free_irq(dev->irq, dev); pci_save_state(pdev); pci_disable_device(pdev); pci_set_power_state(pdev, pci_choose_state(pdev, state)); return 0;}static int tulip_resume(struct pci_dev *pdev){ struct net_device *dev = pci_get_drvdata(pdev); int retval; if (!dev) return -EINVAL; pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); pci_enable_device(pdev); if ((retval = request_irq(dev->irq, &tulip_interrupt, SA_SHIRQ, dev->name, dev))) { printk (KERN_ERR "tulip: request_irq failed in resume\n"); return retval; } netif_device_attach(dev); if (netif_running(dev)) tulip_up(dev); return 0;}#endif /* CONFIG_PM */static void __devexit tulip_remove_one (struct pci_dev *pdev){ struct net_device *dev = pci_get_drvdata (pdev); struct tulip_private *tp; if (!dev) return; tp = netdev_priv(dev); unregister_netdev(dev); pci_free_consistent (pdev, sizeof (struct tulip_rx_desc) * RX_RING_SIZE + sizeof (struct tulip_tx_desc) * TX_RING_SIZE, tp->rx_ring, tp->rx_ring_dma); kfree (tp->mtable); pci_iounmap(pdev, tp->base_addr); free_netdev (dev); pci_release_regions (pdev); pci_set_drvdata (pdev, NULL); /* pci_power_off (pdev, -1); */}#ifdef CONFIG_NET_POLL_CONTROLLER/* * Polling 'interrupt' - used by things like netconsole to send skbs * without having to re-enable interrupts. It's not called while * the interrupt routine is executing. */static void poll_tulip (struct net_device *dev){ /* disable_irq here is not very nice, but with the lockless interrupt handler we have no other choice. */ disable_irq(dev->irq); tulip_interrupt (dev->irq, dev, NULL); enable_irq(dev->irq);}#endifstatic struct pci_driver tulip_driver = { .name = DRV_NAME, .id_table = tulip_pci_tbl, .probe = tulip_init_one, .remove = __devexit_p(tulip_remove_one),#ifdef CONFIG_PM .suspend = tulip_suspend, .resume = tulip_resume,#endif /* CONFIG_PM */};static int __init tulip_init (void){#ifdef MODULE printk (KERN_INFO "%s", version);#endif /* copy module parms into globals */ tulip_rx_copybreak = rx_copybreak; tulip_max_interrupt_work = max_interrupt_work; /* probe for and init boards */ return pci_module_init (&tulip_driver);}static void __exit tulip_cleanup (void){ pci_unregister_driver (&tulip_driver);}module_init(tulip_init);module_exit(tulip_cleanup);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -