ip2main.c

来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 1,945 行 · 第 1/5 页

C
1,945
字号
					IP2_SA_FLAGS | (ip2config.type[i] == PCI ? SA_SHIRQ : 0),					pcName, (void *)&pcName);				if (rc) {					printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);					ip2config.irq[i] = CIR_POLL;					printk( KERN_INFO "IP2: Polling %ld/sec.\n",							(POLL_TIMEOUT - jiffies));					goto retry;				} 				mark_requested_irq(ip2config.irq[i]);				/* Initialise the interrupt handler bottom half (aka slih). */			}		}		for( i = 0; i < IP2_MAX_BOARDS; ++i ) {			if ( i2BoardPtrTable[i] ) {				set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */			}		}	}	ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 );	goto out;out_class:	class_destroy(ip2_class);out_chrdev:	unregister_chrdev(IP2_IPL_MAJOR, "ip2");out:	return err;}EXPORT_SYMBOL(ip2_loadmain);/******************************************************************************//* Function:   ip2_init_board()                                               *//* Parameters: Index of board in configuration structure                      *//* Returns:    Success (0)                                                    *//*                                                                            *//* Description:                                                               *//* This function initializes the specified board. The loadware is copied to   *//* the board, the channel structures are initialized, and the board details   *//* are reported on the console.                                               *//******************************************************************************/static void __initip2_init_board( int boardnum ){	int i;	int nports = 0, nboxes = 0;	i2ChanStrPtr pCh;	i2eBordStrPtr pB = i2BoardPtrTable[boardnum];	if ( !iiInitialize ( pB ) ) {		printk ( KERN_ERR "IP2: Failed to initialize board at 0x%x, error %d\n",			 pB->i2eBase, pB->i2eError );		goto err_initialize;	}	printk(KERN_INFO "IP2: Board %d: addr=0x%x irq=%d\n", boardnum + 1,	       ip2config.addr[boardnum], ip2config.irq[boardnum] );	if (!request_region( ip2config.addr[boardnum], 8, pcName )) {		printk(KERN_ERR "IP2: bad addr=0x%x\n", ip2config.addr[boardnum]);		goto err_initialize;	}	if ( iiDownloadAll ( pB, (loadHdrStrPtr)Fip_firmware, 1, Fip_firmware_size )	    != II_DOWN_GOOD ) {		printk ( KERN_ERR "IP2: failed to download loadware\n" );		goto err_release_region;	} else {		printk ( KERN_INFO "IP2: fv=%d.%d.%d lv=%d.%d.%d\n",			 pB->i2ePom.e.porVersion,			 pB->i2ePom.e.porRevision,			 pB->i2ePom.e.porSubRev, pB->i2eLVersion,			 pB->i2eLRevision, pB->i2eLSub );	}	switch ( pB->i2ePom.e.porID & ~POR_ID_RESERVED ) {	default:		printk( KERN_ERR "IP2: Unknown board type, ID = %x\n",				pB->i2ePom.e.porID );		nports = 0;		goto err_release_region;		break;	case POR_ID_II_4: /* IntelliPort-II, ISA-4 (4xRJ45) */		printk ( KERN_INFO "IP2: ISA-4\n" );		nports = 4;		break;	case POR_ID_II_8: /* IntelliPort-II, 8-port using standard brick. */		printk ( KERN_INFO "IP2: ISA-8 std\n" );		nports = 8;		break;	case POR_ID_II_8R: /* IntelliPort-II, 8-port using RJ11's (no CTS) */		printk ( KERN_INFO "IP2: ISA-8 RJ11\n" );		nports = 8;		break;	case POR_ID_FIIEX: /* IntelliPort IIEX */	{		int portnum = IP2_PORTS_PER_BOARD * boardnum;		int            box;		for( box = 0; box < ABS_MAX_BOXES; ++box ) {			if ( pB->i2eChannelMap[box] != 0 ) {				++nboxes;			}			for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {				if ( pB->i2eChannelMap[box] & 1<< i ) {					++nports;				}			}		}		DevTableMem[boardnum] = pCh =			kmalloc( sizeof(i2ChanStr) * nports, GFP_KERNEL );		if ( !pCh ) {			printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");			goto err_release_region;		}		if ( !i2InitChannels( pB, nports, pCh ) ) {			printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);			kfree ( pCh );			goto err_release_region;		}		pB->i2eChannelPtr = &DevTable[portnum];		pB->i2eChannelCnt = ABS_MOST_PORTS;		for( box = 0; box < ABS_MAX_BOXES; ++box, portnum += ABS_BIGGEST_BOX ) {			for( i = 0; i < ABS_BIGGEST_BOX; ++i ) {				if ( pB->i2eChannelMap[box] & (1 << i) ) {					DevTable[portnum + i] = pCh;					pCh->port_index = portnum + i;					pCh++;				}			}		}		printk(KERN_INFO "IP2: EX box=%d ports=%d %d bit\n",			nboxes, nports, pB->i2eDataWidth16 ? 16 : 8 );		}		goto ex_exit;	}	DevTableMem[boardnum] = pCh =		kmalloc ( sizeof (i2ChanStr) * nports, GFP_KERNEL );	if ( !pCh ) {		printk ( KERN_ERR "IP2: (i2_init_channel:) Out of memory.\n");		goto err_release_region;	}	pB->i2eChannelPtr = pCh;	pB->i2eChannelCnt = nports;	if ( !i2InitChannels( pB, nports, pCh ) ) {		printk(KERN_ERR "IP2: i2InitChannels failed: %d\n",pB->i2eError);		kfree ( pCh );		goto err_release_region;	}	pB->i2eChannelPtr = &DevTable[IP2_PORTS_PER_BOARD * boardnum];	for( i = 0; i < pB->i2eChannelCnt; ++i ) {		DevTable[IP2_PORTS_PER_BOARD * boardnum + i] = pCh;		pCh->port_index = (IP2_PORTS_PER_BOARD * boardnum) + i;		pCh++;	}ex_exit:	INIT_WORK(&pB->tqueue_interrupt, (void(*)(void*)) ip2_interrupt_bh, pB);	return;err_release_region:	release_region(ip2config.addr[boardnum], 8);err_initialize:	kfree ( pB );	i2BoardPtrTable[boardnum] = NULL;	return;}/******************************************************************************//* Function:   find_eisa_board ( int start_slot )                             *//* Parameters: First slot to check                                            *//* Returns:    Address of EISA IntelliPort II controller                      *//*                                                                            *//* Description:                                                               *//* This function searches for an EISA IntelliPort controller, starting        *//* from the specified slot number. If the motherboard is not identified as an *//* EISA motherboard, or no valid board ID is selected it returns 0. Otherwise *//* it returns the base address of the controller.                             *//******************************************************************************/static unsigned short __initfind_eisa_board( int start_slot ){	int i, j;	unsigned int idm = 0;	unsigned int idp = 0;	unsigned int base = 0;	unsigned int value;	int setup_address;	int setup_irq;	int ismine = 0;	/*	 * First a check for an EISA motherboard, which we do by comparing the	 * EISA ID registers for the system board and the first couple of slots.	 * No slot ID should match the system board ID, but on an ISA or PCI	 * machine the odds are that an empty bus will return similar values for	 * each slot.	 */	i = 0x0c80;	value = (inb(i) << 24) + (inb(i+1) << 16) + (inb(i+2) << 8) + inb(i+3);	for( i = 0x1c80; i <= 0x4c80; i += 0x1000 ) {		j = (inb(i)<<24)+(inb(i+1)<<16)+(inb(i+2)<<8)+inb(i+3);		if ( value == j )			return 0;	}	/*	 * OK, so we are inclined to believe that this is an EISA machine. Find	 * an IntelliPort controller.	 */	for( i = start_slot; i < 16; i++ ) {		base = i << 12;		idm = (inb(base + 0xc80) << 8) | (inb(base + 0xc81) & 0xff);		idp = (inb(base + 0xc82) << 8) | (inb(base + 0xc83) & 0xff);		ismine = 0;		if ( idm == 0x0e8e ) {			if ( idp == 0x0281 || idp == 0x0218 ) {				ismine = 1;			} else if ( idp == 0x0282 || idp == 0x0283 ) {				ismine = 3;	/* Can do edge-trigger */			}			if ( ismine ) {				Eisa_slot = i;				break;			}		}	}	if ( !ismine )		return 0;	/* It's some sort of EISA card, but at what address is it configured? */	setup_address = base + 0xc88;	value = inb(base + 0xc86);	setup_irq = (value & 8) ? Valid_Irqs[value & 7] : 0;	if ( (ismine & 2) && !(value & 0x10) ) {		ismine = 1;	/* Could be edging, but not */	}	if ( Eisa_irq == 0 ) {		Eisa_irq = setup_irq;	} else if ( Eisa_irq != setup_irq ) {		printk ( KERN_ERR "IP2: EISA irq mismatch between EISA controllers\n" );	}#ifdef IP2DEBUG_INITprintk(KERN_DEBUG "Computone EISA board in slot %d, I.D. 0x%x%x, Address 0x%x",	       base >> 12, idm, idp, setup_address);	if ( Eisa_irq ) {		printk(KERN_DEBUG ", Interrupt %d %s\n",		       setup_irq, (ismine & 2) ? "(edge)" : "(level)");	} else {		printk(KERN_DEBUG ", (polled)\n");	}#endif	return setup_address;}/******************************************************************************//* Function:   set_irq()                                                      *//* Parameters: index to board in board table                                  *//*             IRQ to use                                                     *//* Returns:    Success (0)                                                    *//*                                                                            *//* Description:                                                               *//******************************************************************************/static voidset_irq( int boardnum, int boardIrq ){	unsigned char tempCommand[16];	i2eBordStrPtr pB = i2BoardPtrTable[boardnum];	unsigned long flags;	/*	 * Notify the boards they may generate interrupts. This is done by	 * sending an in-line command to channel 0 on each board. This is why	 * the channels have to be defined already. For each board, if the	 * interrupt has never been defined, we must do so NOW, directly, since	 * board will not send flow control or even give an interrupt until this	 * is done.  If polling we must send 0 as the interrupt parameter.	 */	// We will get an interrupt here at the end of this function	iiDisableMailIrq(pB);	/* We build up the entire packet header. */	CHANNEL_OF(tempCommand) = 0;	PTYPE_OF(tempCommand) = PTYPE_INLINE;	CMD_COUNT_OF(tempCommand) = 2;	(CMD_OF(tempCommand))[0] = CMDVALUE_IRQ;	(CMD_OF(tempCommand))[1] = boardIrq;	/*	 * Write to FIFO; don't bother to adjust fifo capacity for this, since	 * board will respond almost immediately after SendMail hit.	 */	WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);	iiWriteBuf(pB, tempCommand, 4);	WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);	pB->i2eUsingIrq = boardIrq;	pB->i2eOutMailWaiting |= MB_OUT_STUFFED;	/* Need to update number of boards before you enable mailbox int */	++i2nBoards;	CHANNEL_OF(tempCommand) = 0;	PTYPE_OF(tempCommand) = PTYPE_BYPASS;	CMD_COUNT_OF(tempCommand) = 6;	(CMD_OF(tempCommand))[0] = 88;	// SILO	(CMD_OF(tempCommand))[1] = 64;	// chars	(CMD_OF(tempCommand))[2] = 32;	// ms	(CMD_OF(tempCommand))[3] = 28;	// MAX_BLOCK	(CMD_OF(tempCommand))[4] = 64;	// chars	(CMD_OF(tempCommand))[5] = 87;	// HW_TEST	WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);	iiWriteBuf(pB, tempCommand, 8);	WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);	CHANNEL_OF(tempCommand) = 0;	PTYPE_OF(tempCommand) = PTYPE_BYPASS;	CMD_COUNT_OF(tempCommand) = 1;	(CMD_OF(tempCommand))[0] = 84;	/* get BOX_IDS */	iiWriteBuf(pB, tempCommand, 3);#ifdef XXX	// enable heartbeat for test porpoises	CHANNEL_OF(tempCommand) = 0;	PTYPE_OF(tempCommand) = PTYPE_BYPASS;	CMD_COUNT_OF(tempCommand) = 2;	(CMD_OF(tempCommand))[0] = 44;	/* get ping */	(CMD_OF(tempCommand))[1] = 200;	/* 200 ms */	WRITE_LOCK_IRQSAVE(&pB->write_fifo_spinlock,flags);	iiWriteBuf(pB, tempCommand, 4);	WRITE_UNLOCK_IRQRESTORE(&pB->write_fifo_spinlock,flags);#endif	iiEnableMailIrq(pB);	iiSendPendingMail(pB);}/******************************************************************************//* Interrupt Handler Section                                                  *//******************************************************************************/static inline voidservice_all_boards(void){	int i;	i2eBordStrPtr  pB;	/* Service every board on the list */	for( i = 0; i < IP2_MAX_BOARDS; ++i ) {		pB = i2BoardPtrTable[i];		if ( pB ) {			i2ServiceBoard( pB );		}	}}/******************************************************************************//* Function:   ip2_interrupt_bh(pB)                                           *//* Parameters: pB - pointer to the board structure                            *//* Returns:    Nothing                                                        *//*                                                                            *//* Description:                                                               *//*	Service the board in a bottom half interrupt handler and then         *//*	reenable the board's interrupts if it has an IRQ number               *//*                                                                            *//******************************************************************************/static voidip2_interrupt_bh(i2eBordStrPtr pB){//	pB better well be set or we have a problem!  We can only get//	here from the IMMEDIATE queue.  Here, we process the boards.//	Checking pB doesn't cost much and it saves us from the sanity checkers.	bh_counter++; 	if ( pB ) {

⌨️ 快捷键说明

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