hp100.c

来自「Linux Kernel 2.6.9 for OMAP1710」· C语言 代码 · 共 2,162 行 · 第 1/5 页

C
2,162
字号
	u_int memory_size = 0, virt_memory_size = 0;	u_short local_mode, lsw;	short mem_mapped;	unsigned long mem_ptr_phys;	void **mem_ptr_virt;	struct hp100_private *lp;#ifdef HP100_DEBUG_B	hp100_outw(0x4201, TRACE);	printk("hp100: %s: probe1\n", dev->name);#endif	/* memory region for programmed i/o */	if (!request_region(ioaddr, HP100_REGION_SIZE, "hp100"))		goto out1;	if (hp100_inw(HW_ID) != HP100_HW_ID_CASCADE) 		goto out2;	chip = hp100_inw(PAGING) & HP100_CHIPID_MASK;#ifdef HP100_DEBUG	if (chip == HP100_CHIPID_SHASTA)		printk("hp100: %s: Shasta Chip detected. (This is a pre 802.12 chip)\n", dev->name);	else if (chip == HP100_CHIPID_RAINIER)		printk("hp100: %s: Rainier Chip detected. (This is a pre 802.12 chip)\n", dev->name);	else if (chip == HP100_CHIPID_LASSEN)		printk("hp100: %s: Lassen Chip detected.\n", dev->name);	else		printk("hp100: %s: Warning: Unknown CASCADE chip (id=0x%.4x).\n", dev->name, chip);#endif	dev->base_addr = ioaddr;	eid = hp100_read_id(ioaddr);	if (eid == NULL) {	/* bad checksum? */		printk(KERN_WARNING "hp100_probe: bad ID checksum at base port 0x%x\n", ioaddr);		goto out2;	}	hp100_page(ID_MAC_ADDR);	for (i = uc = 0; i < 7; i++)		uc += hp100_inb(LAN_ADDR + i);	if (uc != 0xff) {		printk(KERN_WARNING "hp100_probe: bad lan address checksum at port 0x%x)\n", ioaddr);		err = -EIO;		goto out2;	}	/* Make sure, that all registers are correctly updated... */	hp100_load_eeprom(dev, ioaddr);	wait();	/*	 * Determine driver operation mode	 *	 * Use the variable "hp100_mode" upon insmod or as kernel parameter to	 * force driver modes:	 * hp100_mode=1 -> default, use busmaster mode if configured.	 * hp100_mode=2 -> enable shared memory mode 	 * hp100_mode=3 -> force use of i/o mapped mode.	 * hp100_mode=4 -> same as 1, but re-set the enable bit on the card.	 */	/*	 * LSW values:	 *   0x2278 -> J2585B, PnP shared memory mode	 *   0x2270 -> J2585B, shared memory mode, 0xdc000	 *   0xa23c -> J2585B, I/O mapped mode	 *   0x2240 -> EISA COMPEX, BusMaster (Shasta Chip)	 *   0x2220 -> EISA HP, I/O (Shasta Chip)	 *   0x2260 -> EISA HP, BusMaster (Shasta Chip)	 */#if 0	local_mode = 0x2270;	hp100_outw(0xfefe, OPTION_LSW);	hp100_outw(local_mode | HP100_SET_LB | HP100_SET_HB, OPTION_LSW);#endif	/* hp100_mode value maybe used in future by another card */	local_mode = hp100_mode;	if (local_mode < 1 || local_mode > 4)		local_mode = 1;	/* default */#ifdef HP100_DEBUG	printk("hp100: %s: original LSW = 0x%x\n", dev->name,	       hp100_inw(OPTION_LSW));#endif	if (local_mode == 3) {		hp100_outw(HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);		hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);		hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);		printk("hp100: IO mapped mode forced.\n");	} else if (local_mode == 2) {		hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);		hp100_outw(HP100_IO_EN | HP100_SET_LB, OPTION_LSW);		hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_RESET_HB, OPTION_LSW);		printk("hp100: Shared memory mode requested.\n");	} else if (local_mode == 4) {		if (chip == HP100_CHIPID_LASSEN) {			hp100_outw(HP100_BM_WRITE | HP100_BM_READ | HP100_SET_HB, OPTION_LSW);			hp100_outw(HP100_IO_EN | HP100_MEM_EN | HP100_RESET_LB, OPTION_LSW);			printk("hp100: Busmaster mode requested.\n");		}		local_mode = 1;	}	if (local_mode == 1) {	/* default behaviour */		lsw = hp100_inw(OPTION_LSW);		if ((lsw & HP100_IO_EN) && (~lsw & HP100_MEM_EN) &&		    (~lsw & (HP100_BM_WRITE | HP100_BM_READ))) {#ifdef HP100_DEBUG			printk("hp100: %s: IO_EN bit is set on card.\n", dev->name);#endif			local_mode = 3;		} else if (chip == HP100_CHIPID_LASSEN &&			   (lsw & (HP100_BM_WRITE | HP100_BM_READ)) == (HP100_BM_WRITE | HP100_BM_READ)) {			/* Conversion to new PCI API :			 * I don't have the doc, but I assume that the card			 * can map the full 32bit address space.			 * Also, we can have EISA Busmaster cards (not tested),			 * so beware !!! - Jean II */			if((bus == HP100_BUS_PCI) &&			   (pci_set_dma_mask(pci_dev, 0xffffffff))) {				/* Gracefully fallback to shared memory */				goto busmasterfail;			}			printk("hp100: Busmaster mode enabled.\n");			hp100_outw(HP100_MEM_EN | HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);		} else {		busmasterfail:#ifdef HP100_DEBUG			printk("hp100: %s: Card not configured for BM or BM not supported with this card.\n", dev->name);			printk("hp100: %s: Trying shared memory mode.\n", dev->name);#endif			/* In this case, try shared memory mode */			local_mode = 2;			hp100_outw(HP100_MEM_EN | HP100_SET_LB, OPTION_LSW);			/* hp100_outw(HP100_IO_EN|HP100_RESET_LB, OPTION_LSW); */		}	}#ifdef HP100_DEBUG	printk("hp100: %s: new LSW = 0x%x\n", dev->name, hp100_inw(OPTION_LSW));#endif	/* Check for shared memory on the card, eventually remap it */	hp100_page(HW_MAP);	mem_mapped = ((hp100_inw(OPTION_LSW) & (HP100_MEM_EN)) != 0);	mem_ptr_phys = 0UL;	mem_ptr_virt = NULL;	memory_size = (8192 << ((hp100_inb(SRAM) >> 5) & 0x07));	virt_memory_size = 0;	/* For memory mapped or busmaster mode, we want the memory address */	if (mem_mapped || (local_mode == 1)) {		mem_ptr_phys = (hp100_inw(MEM_MAP_LSW) | (hp100_inw(MEM_MAP_MSW) << 16));		mem_ptr_phys &= ~0x1fff;	/* 8k alignment */		if (bus == HP100_BUS_ISA && (mem_ptr_phys & ~0xfffff) != 0) {			printk("hp100: Can only use programmed i/o mode.\n");			mem_ptr_phys = 0;			mem_mapped = 0;			local_mode = 3;	/* Use programmed i/o */		}		/* We do not need access to shared memory in busmaster mode */		/* However in slave mode we need to remap high (>1GB) card memory  */		if (local_mode != 1) {	/* = not busmaster */			/* We try with smaller memory sizes, if ioremap fails */			for (virt_memory_size = memory_size; virt_memory_size > 16383; virt_memory_size >>= 1) {				if ((mem_ptr_virt = ioremap((u_long) mem_ptr_phys, virt_memory_size)) == NULL) {#ifdef HP100_DEBUG					printk("hp100: %s: ioremap for 0x%x bytes high PCI memory at 0x%lx failed\n", dev->name, virt_memory_size, mem_ptr_phys);#endif				} else {#ifdef HP100_DEBUG					printk("hp100: %s: remapped 0x%x bytes high PCI memory at 0x%lx to %p.\n", dev->name, virt_memory_size, mem_ptr_phys, mem_ptr_virt);#endif					break;				}			}			if (mem_ptr_virt == NULL) {	/* all ioremap tries failed */				printk("hp100: Failed to ioremap the PCI card memory. Will have to use i/o mapped mode.\n");				local_mode = 3;				virt_memory_size = 0;			}		}	}	if (local_mode == 3) {	/* io mapped forced */		mem_mapped = 0;		mem_ptr_phys = 0;		mem_ptr_virt = NULL;		printk("hp100: Using (slow) programmed i/o mode.\n");	}	/* Initialise the "private" data structure for this card. */	lp = (struct hp100_private *) dev->priv;	spin_lock_init(&lp->lock);	strlcpy(lp->id, eid, HP100_SIG_LEN);	lp->chip = chip;	lp->mode = local_mode;	lp->bus = bus;	lp->pci_dev = pci_dev;	lp->priority_tx = hp100_priority_tx;	lp->rx_ratio = hp100_rx_ratio;	lp->mem_ptr_phys = mem_ptr_phys;	lp->mem_ptr_virt = mem_ptr_virt;	hp100_page(ID_MAC_ADDR);	lp->soft_model = hp100_inb(SOFT_MODEL);	lp->mac1_mode = HP100_MAC1MODE3;	lp->mac2_mode = HP100_MAC2MODE3;	memset(&lp->hash_bytes, 0x00, 8);	dev->base_addr = ioaddr;	lp->memory_size = memory_size;	lp->virt_memory_size = virt_memory_size;	lp->rx_ratio = hp100_rx_ratio;	/* can be conf'd with insmod */	dev->open = hp100_open;	dev->stop = hp100_close;	if (lp->mode == 1)	/* busmaster */		dev->hard_start_xmit = hp100_start_xmit_bm;	else		dev->hard_start_xmit = hp100_start_xmit;	dev->get_stats = hp100_get_stats;	dev->set_multicast_list = &hp100_set_multicast_list;	/* Ask the card for which IRQ line it is configured */	if (bus == HP100_BUS_PCI) {		dev->irq = pci_dev->irq;	} else {		hp100_page(HW_MAP);		dev->irq = hp100_inb(IRQ_CHANNEL) & HP100_IRQMASK;		if (dev->irq == 2)			dev->irq = 9;	}	if (lp->mode == 1)	/* busmaster */		dev->dma = 4;	/* Ask the card for its MAC address and store it for later use. */	hp100_page(ID_MAC_ADDR);	for (i = uc = 0; i < 6; i++)		dev->dev_addr[i] = hp100_inb(LAN_ADDR + i);	/* Reset statistics (counters) */	hp100_clear_stats(lp, ioaddr);	/* If busmaster mode is wanted, a dma-capable memory area is needed for	 * the rx and tx PDLs 	 * PCI cards can access the whole PC memory. Therefore GFP_DMA is not	 * needed for the allocation of the memory area. 	 */	/* TODO: We do not need this with old cards, where PDLs are stored	 * in the cards shared memory area. But currently, busmaster has been	 * implemented/tested only with the lassen chip anyway... */	if (lp->mode == 1) {	/* busmaster */		dma_addr_t page_baddr;		/* Get physically continous memory for TX & RX PDLs    */		/* Conversion to new PCI API :		 * Pages are always aligned and zeroed, no need to it ourself.		 * Doc says should be OK for EISA bus as well - Jean II */		if ((lp->page_vaddr_algn = pci_alloc_consistent(lp->pci_dev, MAX_RINGSIZE, &page_baddr)) == NULL) {			err = -ENOMEM;			goto out2;		}		lp->whatever_offset = ((u_long) page_baddr) - ((u_long) lp->page_vaddr_algn);#ifdef HP100_DEBUG_BM		printk("hp100: %s: Reserved DMA memory from 0x%x to 0x%x\n", dev->name, (u_int) lp->page_vaddr_algn, (u_int) lp->page_vaddr_algn + MAX_RINGSIZE);#endif		lp->rxrcommit = lp->txrcommit = 0;		lp->rxrhead = lp->rxrtail = &(lp->rxring[0]);		lp->txrhead = lp->txrtail = &(lp->txring[0]);	}	/* Initialise the card. */	/* (I'm not really sure if it's a good idea to do this during probing, but 	 * like this it's assured that the lan connection type can be sensed	 * correctly)	 */	hp100_hwinit(dev);	/* Try to find out which kind of LAN the card is connected to. */	lp->lan_type = hp100_sense_lan(dev);	/* Print out a message what about what we think we have probed. */	printk("hp100: at 0x%x, IRQ %d, ", ioaddr, dev->irq);	switch (bus) {	case HP100_BUS_EISA:		printk("EISA");		break;	case HP100_BUS_PCI:		printk("PCI");		break;	default:		printk("ISA");		break;	}	printk(" bus, %dk SRAM (rx/tx %d%%).\n", lp->memory_size >> 10, lp->rx_ratio);	if (lp->mode == 2) {	/* memory mapped */		printk("hp100: Memory area at 0x%lx-0x%lx", mem_ptr_phys,				(mem_ptr_phys + (mem_ptr_phys > 0x100000 ? (u_long) lp->memory_size : 16 * 1024)) - 1);		if (mem_ptr_virt)			printk(" (virtual base %p)", mem_ptr_virt);		printk(".\n");		/* Set for info when doing ifconfig */		dev->mem_start = mem_ptr_phys;		dev->mem_end = mem_ptr_phys + lp->memory_size;	}	printk("hp100: ");	if (lp->lan_type != HP100_LAN_ERR)		printk("Adapter is attached to ");	switch (lp->lan_type) {	case HP100_LAN_100:		printk("100Mb/s Voice Grade AnyLAN network.\n");		break;	case HP100_LAN_10:		printk("10Mb/s network (10baseT).\n");		break;	case HP100_LAN_COAX:		printk("10Mb/s network (coax).\n");		break;	default:		printk("Warning! Link down.\n");	}	return 0;out2:	release_region(ioaddr, HP100_REGION_SIZE);out1:	return -ENODEV;}/* This procedure puts the card into a stable init state */static void hp100_hwinit(struct net_device *dev){	int ioaddr = dev->base_addr;	struct hp100_private *lp = (struct hp100_private *) dev->priv;#ifdef HP100_DEBUG_B	hp100_outw(0x4202, TRACE);	printk("hp100: %s: hwinit\n", dev->name);#endif	/* Initialise the card. -------------------------------------------- */	/* Clear all pending Ints and disable Ints */	hp100_page(PERFORMANCE);	hp100_outw(0xfefe, IRQ_MASK);	/* mask off all ints */	hp100_outw(0xffff, IRQ_STATUS);	/* clear all pending ints */	hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);	hp100_outw(HP100_TRI_INT | HP100_SET_HB, OPTION_LSW);	if (lp->mode == 1) {		hp100_BM_shutdown(dev);	/* disables BM, puts cascade in reset */		wait();	} else {		hp100_outw(HP100_INT_EN | HP100_RESET_LB, OPTION_LSW);		hp100_cascade_reset(dev, 1);		hp100_page(MAC_CTRL);		hp100_andb(~(HP100_RX_EN | HP100_TX_EN), MAC_CFG_1);	}	/* Initiate EEPROM reload */	hp100_load_eeprom(dev, 0);	wait();	/* Go into reset again. */	hp100_cascade_reset(dev, 1);	/* Set Option Registers to a safe state  */	hp100_outw(HP100_DEBUG_EN |		   HP100_RX_HDR |		   HP100_EE_EN |		   HP100_BM_WRITE |		   HP100_BM_READ | HP100_RESET_HB |		   HP100_FAKE_INT |		   HP100_INT_EN |		   HP100_MEM_EN |		   HP100_IO_EN | HP100_RESET_LB, OPTION_LSW);	hp100_outw(HP100_TRI_INT |		   HP100_MMAP_DIS | HP100_SET_HB, OPTION_LSW);	hp100_outb(HP100_PRIORITY_TX |		   HP100_ADV_NXT_PKT |		   HP100_TX_CMD | HP100_RESET_LB, OPTION_MSW);	/* TODO: Configure MMU for Ram Test. */	/* TODO: Ram Test. */	/* Re-check if adapter is still at same i/o location      */	/* (If the base i/o in eeprom has been changed but the    */	/* registers had not been changed, a reload of the eeprom */	/* would move the adapter to the address stored in eeprom */	/* TODO: Code to implement. */	/* Until here it was code from HWdiscover procedure. */	/* Next comes code from mmuinit procedure of SCO BM driver which is	 * called from HWconfigure in the SCO driver.  */	/* Initialise MMU, eventually switch on Busmaster Mode, initialise 	 * multicast filter...	 */	hp100_mmuinit(dev);	/* We don't turn the interrupts on here - this is done by start_interface. */	wait();			/* TODO: Do we really need this? */	/* Enable Hardware (e.g. unreset) */	hp100_cascade_reset(dev, 0);	/* ------- initialisation complete ----------- */	/* Finally try to log in the Hub if there may be a VG connection. */	if ((lp->lan_type == HP100_LAN_100) || (lp->lan_type == HP100_LAN_ERR))		hp100_login_to_vg_hub(dev, 0);	/* relogin */

⌨️ 快捷键说明

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