📄 de4x5.c
字号:
static struct device *insert_device(struct device *dev, u_long iobase, int (*init)(struct device *));static int count_adapters(void);static int loading_module = 1;MODULE_PARM(de4x5_debug, "i");MODULE_PARM(dec_only, "i");MODULE_PARM(args, "s");# elsestatic int loading_module = 0;#endif /* MODULE */static char name[DE4X5_NAME_LENGTH + 1];#if !defined(__sparc_v9__) && !defined(__powerpc__) && !defined(__alpha__)static u_char de4x5_irq[] = EISA_ALLOWED_IRQ_LIST;static int lastEISA = 0;#elsestatic int lastEISA = MAX_EISA_SLOTS; /* Only PCI probes */#endifstatic int num_de4x5s = 0;static int cfrv = 0, useSROM = 0;static int lastPCI = -1;static struct device *lastModule = NULL;static struct pci_dev *pdev = NULL;/*** List the SROM infoleaf functions and chipsets*/struct InfoLeaf { int chipset; int (*fn)(struct device *);};static struct InfoLeaf infoleaf_array[] = { {DC21041, dc21041_infoleaf}, {DC21140, dc21140_infoleaf}, {DC21142, dc21142_infoleaf}, {DC21143, dc21143_infoleaf}};#define INFOLEAF_SIZE (sizeof(infoleaf_array)/(sizeof(int)+sizeof(int *)))/*** List the SROM info block functions*/static int (*dc_infoblock[])(struct device *dev, u_char, u_char *) = { type0_infoblock, type1_infoblock, type2_infoblock, type3_infoblock, type4_infoblock, type5_infoblock, compact_infoblock};#define COMPACT (sizeof(dc_infoblock)/sizeof(int *) - 1)/*** Miscellaneous defines...*/#define RESET_DE4X5 {\ int i;\ i=inl(DE4X5_BMR);\ de4x5_ms_delay(1);\ outl(i | BMR_SWR, DE4X5_BMR);\ de4x5_ms_delay(1);\ outl(i, DE4X5_BMR);\ de4x5_ms_delay(1);\ for (i=0;i<5;i++) {inl(DE4X5_BMR); de4x5_ms_delay(1);}\ de4x5_ms_delay(1);\}#define PHY_HARD_RESET {\ outl(GEP_HRST, DE4X5_GEP); /* Hard RESET the PHY dev. */\ mdelay(1); /* Assert for 1ms */\ outl(0x00, DE4X5_GEP);\ mdelay(2); /* Wait for 2ms */\}/*** Autoprobing in modules is allowed here. See the top of the file for** more info.*/__initfunc(intde4x5_probe(struct device *dev)){ u_long iobase = dev->base_addr;#if !defined(__sparc_v9__) && !defined(__powerpc__) && !defined(__alpha__) eisa_probe(dev, iobase);#endif if (lastEISA == MAX_EISA_SLOTS) { pci_probe(dev, iobase); } return (dev->priv ? 0 : -ENODEV);}__initfunc(static intde4x5_hw_init(struct device *dev, u_long iobase)){ struct bus_type *lp = &bus; int i, status=0; char *tmp; /* Ensure we're not sleeping */ if (lp->bus == EISA) { outb(WAKEUP, PCI_CFPM); } else { pcibios_write_config_byte(lp->bus_num, lp->device << 3, PCI_CFDA_PSM, WAKEUP); } de4x5_ms_delay(10); RESET_DE4X5; if ((inl(DE4X5_STS) & (STS_TS | STS_RS)) != 0) { return -ENXIO; /* Hardware could not reset */ } /* ** Now find out what kind of DC21040/DC21041/DC21140 board we have. */ useSROM = FALSE; if (lp->bus == PCI) { PCI_signature(name, lp); } else { EISA_signature(name, EISA_ID0); } if (*name == '\0') { /* Not found a board signature */ return -ENXIO; } dev->base_addr = iobase; if (lp->bus == EISA) { printk("%s: %s at 0x%04lx (EISA slot %ld)", dev->name, name, iobase, ((iobase>>12)&0x0f)); } else { /* PCI port address */ printk("%s: %s at 0x%04lx (PCI bus %d, device %d)", dev->name, name, iobase, lp->bus_num, lp->device); } printk(", h/w address "); status = get_hw_addr(dev); for (i = 0; i < ETH_ALEN - 1; i++) { /* get the ethernet addr. */ printk("%2.2x:", dev->dev_addr[i]); } printk("%2.2x,\n", dev->dev_addr[i]); if (status != 0) { printk(" which has an Ethernet PROM CRC error.\n"); return -ENXIO; } else { struct de4x5_private *lp; /* ** Reserve a section of kernel memory for the adapter ** private area and the TX/RX descriptor rings. */ dev->priv = (void *) kmalloc(sizeof(struct de4x5_private) + ALIGN, GFP_KERNEL); if (dev->priv == NULL) { return -ENOMEM; } /* ** Align to a longword boundary */ tmp = dev->priv; dev->priv = (void *)(((u_long)dev->priv + ALIGN) & ~ALIGN); lp = (struct de4x5_private *)dev->priv; memset(dev->priv, 0, sizeof(struct de4x5_private)); lp->bus = bus.bus; lp->bus_num = bus.bus_num; lp->device = bus.device; lp->chipset = bus.chipset; lp->cache.priv = tmp; lp->cache.gepc = GEP_INIT; lp->asBit = GEP_SLNK; lp->asPolarity = GEP_SLNK; lp->asBitValid = TRUE; lp->timeout = -1; lp->useSROM = useSROM; memcpy((char *)&lp->srom,(char *)&bus.srom,sizeof(struct de4x5_srom)); lp->lock = (spinlock_t) SPIN_LOCK_UNLOCKED; de4x5_parse_params(dev); /* ** Choose correct autosensing in case someone messed up */ lp->autosense = lp->params.autosense; if (lp->chipset != DC21140) { if ((lp->chipset==DC21040) && (lp->params.autosense&TP_NW)) { lp->params.autosense = TP; } if ((lp->chipset==DC21041) && (lp->params.autosense&BNC_AUI)) { lp->params.autosense = BNC; } } lp->fdx = lp->params.fdx; sprintf(lp->adapter_name,"%s (%s)", name, dev->name); /* ** Set up the RX descriptor ring (Intels) ** Allocate contiguous receive buffers, long word aligned (Alphas) */#if !defined(__alpha__) && !defined(__powerpc__) && !defined(__sparc_v9__) && !defined(DE4X5_DO_MEMCPY) for (i=0; i<NUM_RX_DESC; i++) { lp->rx_ring[i].status = 0; lp->rx_ring[i].des1 = RX_BUFF_SZ; lp->rx_ring[i].buf = 0; lp->rx_ring[i].next = 0; lp->rx_skb[i] = (struct sk_buff *) 1; /* Dummy entry */ }#else if ((tmp = (void *)kmalloc(RX_BUFF_SZ * NUM_RX_DESC + ALIGN, GFP_KERNEL)) == NULL) { kfree(lp->cache.priv); return -ENOMEM; } lp->cache.buf = tmp; tmp = (char *)(((u_long) tmp + ALIGN) & ~ALIGN); for (i=0; i<NUM_RX_DESC; i++) { lp->rx_ring[i].status = 0; lp->rx_ring[i].des1 = cpu_to_le32(RX_BUFF_SZ); lp->rx_ring[i].buf = cpu_to_le32(virt_to_bus(tmp+i*RX_BUFF_SZ)); lp->rx_ring[i].next = 0; lp->rx_skb[i] = (struct sk_buff *) 1; /* Dummy entry */ }#endif barrier(); request_region(iobase, (lp->bus == PCI ? DE4X5_PCI_TOTAL_SIZE : DE4X5_EISA_TOTAL_SIZE), lp->adapter_name); lp->rxRingSize = NUM_RX_DESC; lp->txRingSize = NUM_TX_DESC; /* Write the end of list marker to the descriptor lists */ lp->rx_ring[lp->rxRingSize - 1].des1 |= cpu_to_le32(RD_RER); lp->tx_ring[lp->txRingSize - 1].des1 |= cpu_to_le32(TD_TER); /* Tell the adapter where the TX/RX rings are located. */ outl(virt_to_bus(lp->rx_ring), DE4X5_RRBA); outl(virt_to_bus(lp->tx_ring), DE4X5_TRBA); /* Initialise the IRQ mask and Enable/Disable */ lp->irq_mask = IMR_RIM | IMR_TIM | IMR_TUM | IMR_UNM; lp->irq_en = IMR_NIM | IMR_AIM; /* Create a loopback packet frame for later media probing */ create_packet(dev, lp->frame, sizeof(lp->frame)); /* Check if the RX overflow bug needs testing for */ i = cfrv & 0x000000fe; if ((lp->chipset == DC21140) && (i == 0x20)) { lp->rx_ovf = 1; } /* Initialise the SROM pointers if possible */ if (lp->useSROM) { lp->state = INITIALISED; if (srom_infoleaf_info(dev)) { return -ENXIO; } srom_init(dev); } lp->state = CLOSED; /* ** Check for an MII interface */ if ((lp->chipset != DC21040) && (lp->chipset != DC21041)) { mii_get_phy(dev); } #ifndef __sparc_v9__ printk(" and requires IRQ%d (provided by %s).\n", dev->irq,#else printk(" and requires IRQ%x (provided by %s).\n", dev->irq,#endif ((lp->bus == PCI) ? "PCI BIOS" : "EISA CNFG")); } if (de4x5_debug & DEBUG_VERSION) { printk(version); } /* The DE4X5-specific entries in the device structure. */ dev->open = &de4x5_open; dev->hard_start_xmit = &de4x5_queue_pkt; dev->stop = &de4x5_close; dev->get_stats = &de4x5_get_stats; dev->set_multicast_list = &set_multicast_list; dev->do_ioctl = &de4x5_ioctl; dev->mem_start = 0; /* Fill in the generic fields of the device structure. */ ether_setup(dev); /* Let the adapter sleep to save power */ yawn(dev, SLEEP); return status;}static intde4x5_open(struct device *dev){ struct de4x5_private *lp = (struct de4x5_private *)dev->priv; u_long iobase = dev->base_addr; int i, status = 0; s32 omr; /* Allocate the RX buffers */ for (i=0; i<lp->rxRingSize; i++) { if (de4x5_alloc_rx_buff(dev, i, 0) == NULL) { de4x5_free_rx_buffs(dev); return -EAGAIN; } } /* ** Wake up the adapter */ yawn(dev, WAKEUP); /* ** Re-initialize the DE4X5... */ status = de4x5_init(dev); lp->lock = (spinlock_t) SPIN_LOCK_UNLOCKED;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -