⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 de4x5.c

📁 Linux内核源代码 为压缩文件 是<<Linux内核>>一书中的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
static int     test_bad_enet(struct net_device *dev, int status);static int     an_exception(struct bus_type *lp);#if !defined(__sparc_v9__) && !defined(__powerpc__) && !defined(__alpha__)static void    eisa_probe(struct net_device *dev, u_long iobase);#endifstatic void    pci_probe(struct net_device *dev, u_long iobase);static void    srom_search(struct pci_dev *pdev);static char    *build_setup_frame(struct net_device *dev, int mode);static void    disable_ast(struct net_device *dev);static void    enable_ast(struct net_device *dev, u32 time_out);static long    de4x5_switch_mac_port(struct net_device *dev);static int     gep_rd(struct net_device *dev);static void    gep_wr(s32 data, struct net_device *dev);static void    timeout(struct net_device *dev, void (*fn)(u_long data), u_long data, u_long msec);static void    yawn(struct net_device *dev, int state);static void    link_modules(struct net_device *dev, struct net_device *tmp);static void    de4x5_parse_params(struct net_device *dev);static void    de4x5_dbg_open(struct net_device *dev);static void    de4x5_dbg_mii(struct net_device *dev, int k);static void    de4x5_dbg_media(struct net_device *dev);static void    de4x5_dbg_srom(struct de4x5_srom *p);static void    de4x5_dbg_rx(struct sk_buff *skb, int len);static int     de4x5_strncmp(char *a, char *b, int n);static int     dc21041_infoleaf(struct net_device *dev);static int     dc21140_infoleaf(struct net_device *dev);static int     dc21142_infoleaf(struct net_device *dev);static int     dc21143_infoleaf(struct net_device *dev);static int     type0_infoblock(struct net_device *dev, u_char count, u_char *p);static int     type1_infoblock(struct net_device *dev, u_char count, u_char *p);static int     type2_infoblock(struct net_device *dev, u_char count, u_char *p);static int     type3_infoblock(struct net_device *dev, u_char count, u_char *p);static int     type4_infoblock(struct net_device *dev, u_char count, u_char *p);static int     type5_infoblock(struct net_device *dev, u_char count, u_char *p);static int     compact_infoblock(struct net_device *dev, u_char count, u_char *p);#ifdef MODULEint  init_module(void);void cleanup_module(void);static struct net_device *unlink_modules(struct net_device *p);static struct net_device *insert_device(struct net_device *dev, u_long iobase,				     int (*init)(struct net_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;#  ifdef DE4X5_FORCE_EISA                 /* Force an EISA bus probe or not */static int forceEISA = 1;#  elsestatic int forceEISA = 0;#  endif#endifstatic int num_de4x5s = 0;static int cfrv = 0, useSROM = 0;static int lastPCI = -1;static struct net_device *lastModule = NULL;static struct pci_dev *pdev = NULL;/*** List the SROM infoleaf functions and chipsets*/struct InfoLeaf {    int chipset;    int (*fn)(struct net_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 net_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.*/int __init de4x5_probe(struct net_device *dev){    u_long iobase = dev->base_addr;    pci_probe(dev, iobase);#if !defined(__sparc_v9__) && !defined(__powerpc__) && !defined(__alpha__)    if ((lastPCI == NO_MORE_PCI) && ((num_de4x5s == 0) || forceEISA)) {        eisa_probe(dev, iobase);    }#endif        return (dev->priv ? 0 : -ENODEV);}static int __init de4x5_hw_init(struct net_device *dev, u_long iobase, struct pci_dev *pdev){    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;	lp->pdev = pdev;	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);	lp->dma_size = (NUM_RX_DESC + NUM_TX_DESC) * sizeof(struct de4x5_desc);#if defined(__alpha__) || defined(__powerpc__) || defined(__sparc_v9__) || defined(DE4X5_DO_MEMCPY)	lp->dma_size += RX_BUFF_SZ * NUM_RX_DESC + ALIGN;#endif	lp->rx_ring = pci_alloc_consistent(pdev, lp->dma_size, &lp->dma_rings);	if (lp->rx_ring == NULL) {	    kfree(lp->cache.priv);	    lp->cache.priv = NULL;	    return -ENOMEM;	}	lp->tx_ring = lp->rx_ring + NUM_RX_DESC;	    	/*	** 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 = cpu_to_le32(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	{		dma_addr_t dma_rx_bufs;		dma_rx_bufs = lp->dma_rings + (NUM_RX_DESC + NUM_TX_DESC)		      	* sizeof(struct de4x5_desc);		dma_rx_bufs = (dma_rx_bufs + ALIGN) & ~ALIGN;		lp->rx_bufs = (char *)(((long)(lp->rx_ring + NUM_RX_DESC		      	+ NUM_TX_DESC) + 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(dma_rx_bufs+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(lp->dma_rings, DE4X5_RRBA);	outl(lp->dma_rings + NUM_RX_DESC * sizeof(struct de4x5_desc),	     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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -