ip2main.c
来自「LINUX 2.6.17.4的源码」· C语言 代码 · 共 1,945 行 · 第 1/5 页
C
1,945 行
i2ServiceBoard( pB ); if( pB->i2eUsingIrq ) {// Re-enable his interrupts iiEnableMailIrq(pB); } }}/******************************************************************************//* Function: ip2_interrupt(int irq, void *dev_id, struct pt_regs * regs) *//* Parameters: irq - interrupt number *//* pointer to optional device ID structure *//* pointer to register structure *//* Returns: Nothing *//* *//* Description: *//* *//* Our task here is simply to identify each board which needs servicing. *//* If we are queuing then, queue it to be serviced, and disable its irq *//* mask otherwise process the board directly. *//* *//* We could queue by IRQ but that just complicates things on both ends *//* with very little gain in performance (how many instructions does *//* it take to iterate on the immediate queue). *//* *//* *//******************************************************************************/static irqreturn_tip2_interrupt(int irq, void *dev_id, struct pt_regs * regs){ int i; i2eBordStrPtr pB; int handled = 0; ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq ); /* Service just the boards on the list using this irq */ for( i = 0; i < i2nBoards; ++i ) { pB = i2BoardPtrTable[i];// Only process those boards which match our IRQ.// IRQ = 0 for polled boards, we won't poll "IRQ" boards if ( pB && (pB->i2eUsingIrq == irq) ) { handled = 1;#ifdef USE_IQI if (NO_MAIL_HERE != ( pB->i2eStartMail = iiGetMail(pB))) {// Disable his interrupt (will be enabled when serviced)// This is mostly to protect from reentrancy. iiDisableMailIrq(pB);// Park the board on the immediate queue for processing. schedule_work(&pB->tqueue_interrupt);// Make sure the immediate queue is flagged to fire. }#else// We are using immediate servicing here. This sucks and can// cause all sorts of havoc with ppp and others. The failsafe// check on iiSendPendingMail could also throw a hairball. i2ServiceBoard( pB );#endif /* USE_IQI */ } } ++irq_counter; ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 ); return IRQ_RETVAL(handled);}/******************************************************************************//* Function: ip2_poll(unsigned long arg) *//* Parameters: ? *//* Returns: Nothing *//* *//* Description: *//* This function calls the library routine i2ServiceBoard for each board in *//* the board table. This is used instead of the interrupt routine when polled *//* mode is specified. *//******************************************************************************/static voidip2_poll(unsigned long arg){ ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 ); TimerOn = 0; // it's the truth but not checked in service // Just polled boards, IRQ = 0 will hit all non-interrupt boards. // It will NOT poll boards handled by hard interrupts. // The issue of queued BH interrups is handled in ip2_interrupt(). ip2_interrupt(0, NULL, NULL); PollTimer.expires = POLL_TIMEOUT; add_timer( &PollTimer ); TimerOn = 1; ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );}static void do_input(void *p){ i2ChanStrPtr pCh = p; unsigned long flags; ip2trace(CHANN, ITRC_INPUT, 21, 0 ); // Data input if ( pCh->pTTY != NULL ) { READ_LOCK_IRQSAVE(&pCh->Ibuf_spinlock,flags) if (!pCh->throttled && (pCh->Ibuf_stuff != pCh->Ibuf_strip)) { READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags) i2Input( pCh ); } else READ_UNLOCK_IRQRESTORE(&pCh->Ibuf_spinlock,flags) } else { ip2trace(CHANN, ITRC_INPUT, 22, 0 ); i2InputFlush( pCh ); }}// code duplicated from n_tty (ldisc)static inline void isig(int sig, struct tty_struct *tty, int flush){ if (tty->pgrp > 0) kill_pg(tty->pgrp, sig, 1); if (flush || !L_NOFLSH(tty)) { if ( tty->ldisc.flush_buffer ) tty->ldisc.flush_buffer(tty); i2InputFlush( tty->driver_data ); }}static void do_status(void *p){ i2ChanStrPtr pCh = p; int status; status = i2GetStatus( pCh, (I2_BRK|I2_PAR|I2_FRA|I2_OVR) ); ip2trace (CHANN, ITRC_STATUS, 21, 1, status ); if (pCh->pTTY && (status & (I2_BRK|I2_PAR|I2_FRA|I2_OVR)) ) { if ( (status & I2_BRK) ) { // code duplicated from n_tty (ldisc) if (I_IGNBRK(pCh->pTTY)) goto skip_this; if (I_BRKINT(pCh->pTTY)) { isig(SIGINT, pCh->pTTY, 1); goto skip_this; } wake_up_interruptible(&pCh->pTTY->read_wait); }#ifdef NEVER_HAPPENS_AS_SETUP_XXX // and can't work because we don't know the_char // as the_char is reported on a separate path // The intelligent board does this stuff as setup { char brkf = TTY_NORMAL; unsigned char brkc = '\0'; unsigned char tmp; if ( (status & I2_BRK) ) { brkf = TTY_BREAK; brkc = '\0'; } else if (status & I2_PAR) { brkf = TTY_PARITY; brkc = the_char; } else if (status & I2_FRA) { brkf = TTY_FRAME; brkc = the_char; } else if (status & I2_OVR) { brkf = TTY_OVERRUN; brkc = the_char; } tmp = pCh->pTTY->real_raw; pCh->pTTY->real_raw = 0; pCh->pTTY->ldisc.receive_buf( pCh->pTTY, &brkc, &brkf, 1 ); pCh->pTTY->real_raw = tmp; }#endif /* NEVER_HAPPENS_AS_SETUP_XXX */ }skip_this: if ( status & (I2_DDCD | I2_DDSR | I2_DCTS | I2_DRI) ) { wake_up_interruptible(&pCh->delta_msr_wait); if ( (pCh->flags & ASYNC_CHECK_CD) && (status & I2_DDCD) ) { if ( status & I2_DCD ) { if ( pCh->wopen ) { wake_up_interruptible ( &pCh->open_wait ); } } else { if (pCh->pTTY && (!(pCh->pTTY->termios->c_cflag & CLOCAL)) ) { tty_hangup( pCh->pTTY ); } } } } ip2trace (CHANN, ITRC_STATUS, 26, 0 );}/******************************************************************************//* Device Open/Close/Ioctl Entry Point Section *//******************************************************************************//******************************************************************************//* Function: open_sanity_check() *//* Parameters: Pointer to tty structure *//* Pointer to file structure *//* Returns: Success or failure *//* *//* Description: *//* Verifies the structure magic numbers and cross links. *//******************************************************************************/#ifdef IP2DEBUG_OPENstatic void open_sanity_check( i2ChanStrPtr pCh, i2eBordStrPtr pBrd ){ if ( pBrd->i2eValid != I2E_MAGIC ) { printk(KERN_ERR "IP2: invalid board structure\n" ); } else if ( pBrd != pCh->pMyBord ) { printk(KERN_ERR "IP2: board structure pointer mismatch (%p)\n", pCh->pMyBord ); } else if ( pBrd->i2eChannelCnt < pCh->port_index ) { printk(KERN_ERR "IP2: bad device index (%d)\n", pCh->port_index ); } else if (&((i2ChanStrPtr)pBrd->i2eChannelPtr)[pCh->port_index] != pCh) { } else { printk(KERN_INFO "IP2: all pointers check out!\n" ); }}#endif/******************************************************************************//* Function: ip2_open() *//* Parameters: Pointer to tty structure *//* Pointer to file structure *//* Returns: Success or failure *//* *//* Description: (MANDATORY) *//* A successful device open has to run a gauntlet of checks before it *//* completes. After some sanity checking and pointer setup, the function *//* blocks until all conditions are satisfied. It then initialises the port to *//* the default characteristics and returns. *//******************************************************************************/static intip2_open( PTTY tty, struct file *pFile ){ wait_queue_t wait; int rc = 0; int do_clocal = 0; i2ChanStrPtr pCh = DevTable[tty->index]; ip2trace (tty->index, ITRC_OPEN, ITRC_ENTER, 0 ); if ( pCh == NULL ) { return -ENODEV; } /* Setup pointer links in device and tty structures */ pCh->pTTY = tty; tty->driver_data = pCh;#ifdef IP2DEBUG_OPEN printk(KERN_DEBUG \ "IP2:open(tty=%p,pFile=%p):dev=%s,ch=%d,idx=%d\n", tty, pFile, tty->name, pCh->infl.hd.i2sChannel, pCh->port_index); open_sanity_check ( pCh, pCh->pMyBord );#endif i2QueueCommands(PTYPE_INLINE, pCh, 100, 3, CMD_DTRUP,CMD_RTSUP,CMD_DCD_REP); pCh->dataSetOut |= (I2_DTR | I2_RTS); serviceOutgoingFifo( pCh->pMyBord ); /* Block here until the port is ready (per serial and istallion) */ /* * 1. If the port is in the middle of closing wait for the completion * and then return the appropriate error. */ init_waitqueue_entry(&wait, current); add_wait_queue(&pCh->close_wait, &wait); set_current_state( TASK_INTERRUPTIBLE ); if ( tty_hung_up_p(pFile) || ( pCh->flags & ASYNC_CLOSING )) { if ( pCh->flags & ASYNC_CLOSING ) { schedule(); } if ( tty_hung_up_p(pFile) ) { set_current_state( TASK_RUNNING ); remove_wait_queue(&pCh->close_wait, &wait); return( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS; } } set_current_state( TASK_RUNNING ); remove_wait_queue(&pCh->close_wait, &wait); /* * 3. Handle a non-blocking open of a normal port. */ if ( (pFile->f_flags & O_NONBLOCK) || (tty->flags & (1<<TTY_IO_ERROR) )) { pCh->flags |= ASYNC_NORMAL_ACTIVE; goto noblock; } /* * 4. Now loop waiting for the port to be free and carrier present * (if required). */ if ( tty->termios->c_cflag & CLOCAL ) do_clocal = 1;#ifdef IP2DEBUG_OPEN printk(KERN_DEBUG "OpenBlock: do_clocal = %d\n", do_clocal);#endif ++pCh->wopen; init_waitqueue_entry(&wait, current); add_wait_queue(&pCh->open_wait, &wait); for(;;) { i2QueueCommands(PTYPE_INLINE, pCh, 100, 2, CMD_DTRUP, CMD_RTSUP); pCh->dataSetOut |= (I2_DTR | I2_RTS); set_current_state( TASK_INTERRUPTIBLE ); serviceOutgoingFifo( pCh->pMyBord ); if ( tty_hung_up_p(pFile) ) { set_current_state( TASK_RUNNING ); remove_wait_queue(&pCh->open_wait, &wait); return ( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EBUSY : -ERESTARTSYS; } if (!(pCh->flags & ASYNC_CLOSING) && (do_clocal || (pCh->dataSetIn & I2_DCD) )) { rc = 0; break; }#ifdef IP2DEBUG_OPEN printk(KERN_DEBUG "ASYNC_CLOSING = %s\n", (pCh->flags & ASYNC_CLOSING)?"True":"False"); printk(KERN_DEBUG "OpenBlock: waiting for CD or signal\n");#endif ip2trace (CHANN, ITRC_OPEN, 3, 2, 0, (pCh->flags & ASYNC_CLOSING) ); /* check for signal */ if (signal_pending(current)) { rc = (( pCh->flags & ASYNC_HUP_NOTIFY ) ? -EAGAIN : -ERESTARTSYS); break; } schedule(); } set_current_state( TASK_RUNNING ); remove_wait_queue(&pCh->open_wait, &wait); --pCh->wopen; //why count? ip2trace (CHANN, ITRC_OPEN, 4, 0 ); if (rc != 0 ) { return rc; } pCh->flags |= ASYNC_NORMAL_ACTIVE;noblock: /* first open - Assign termios structure to port */ if ( tty->count == 1 ) { i2QueueCommands(PTYPE_INLINE, pCh, 0, 2, CMD_CTSFL_DSAB, CMD_RTSFL_DSAB); /* Now we must send the termios settings to the loadware */ set_params( pCh, NULL ); } /* * Now set any i2lib options. These may go away if the i2lib code ends * up rolled into the mainline. */ pCh->channelOptions |= CO_NBLOCK_WRITE;#ifdef IP2DEBUG_OPEN printk (KERN_DEBUG "IP2: open completed\n" );#endif serviceOutgoingFifo( pCh->pMyBord ); ip2trace (CHANN, ITRC_OPEN, ITRC_RETURN, 0 ); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?