X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fchar%2Fspecialix.c;h=5343e9fc6ab7e721dc1a578e6a6e81e044549490;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=bf82f06d401135552c334743a44c513436437529;hpb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;p=linux-2.6.git diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c index bf82f06d4..5343e9fc6 100644 --- a/drivers/char/specialix.c +++ b/drivers/char/specialix.c @@ -38,19 +38,19 @@ * * Revision 1.0: April 1st 1997. * Initial release for alpha testing. - * Revision 1.1: April 14th 1997. - * Incorporated Richard Hudsons suggestions, + * Revision 1.1: April 14th 1997. + * Incorporated Richard Hudsons suggestions, * removed some debugging printk's. * Revision 1.2: April 15th 1997. * Ported to 2.1.x kernels. - * Revision 1.3: April 17th 1997 - * Backported to 2.0. (Compatibility macros). + * Revision 1.3: April 17th 1997 + * Backported to 2.0. (Compatibility macros). * Revision 1.4: April 18th 1997 - * Fixed DTR/RTS bug that caused the card to indicate - * "don't send data" to a modem after the password prompt. + * Fixed DTR/RTS bug that caused the card to indicate + * "don't send data" to a modem after the password prompt. * Fixed bug for premature (fake) interrupts. * Revision 1.5: April 19th 1997 - * fixed a minor typo in the header file, cleanup a little. + * fixed a minor typo in the header file, cleanup a little. * performance warnings are now MAXed at once per minute. * Revision 1.6: May 23 1997 * Changed the specialix=... format to include interrupt. @@ -60,13 +60,13 @@ * port to linux-2.1.43 kernel. * Revision 1.9: Oct 9 1998 * Added stuff for the IO8+/PCI version. - * Revision 1.10: Oct 22 1999 / Jan 21 2000. - * Added stuff for setserial. + * Revision 1.10: Oct 22 1999 / Jan 21 2000. + * Added stuff for setserial. * Nicolas Mailhot (Nicolas.Mailhot@email.enst.fr) - * + * */ -#define VERSION "1.10" +#define VERSION "1.11" /* @@ -85,12 +85,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -99,6 +99,44 @@ #include "cd1865.h" +/* + This driver can spew a whole lot of debugging output at you. If you + need maximum performance, you should disable the DEBUG define. To + aid in debugging in the field, I'm leaving the compile-time debug + features enabled, and disable them "runtime". That allows me to + instruct people with problems to enable debugging without requiring + them to recompile... +*/ +#define DEBUG + +static int sx_debug; +static int sx_rxfifo = SPECIALIX_RXFIFO; + +#ifdef DEBUG +#define dprintk(f, str...) if (sx_debug & f) printk (str) +#else +#define dprintk(f, str...) /* nothing */ +#endif + +#define SX_DEBUG_FLOW 0x0001 +#define SX_DEBUG_DATA 0x0002 +#define SX_DEBUG_PROBE 0x0004 +#define SX_DEBUG_CHAN 0x0008 +#define SX_DEBUG_INIT 0x0010 +#define SX_DEBUG_RX 0x0020 +#define SX_DEBUG_TX 0x0040 +#define SX_DEBUG_IRQ 0x0080 +#define SX_DEBUG_OPEN 0x0100 +#define SX_DEBUG_TERMIOS 0x0200 +#define SX_DEBUG_SIGNALS 0x0400 +#define SX_DEBUG_FIFO 0x0800 + + +#define func_enter() dprintk (SX_DEBUG_FLOW, "io8: enter %s\n",__FUNCTION__) +#define func_exit() dprintk (SX_DEBUG_FLOW, "io8: exit %s\n", __FUNCTION__) + +#define jiffies_from_ms(a) ((((a) * HZ)/1000)+1) + /* Configurable options: */ @@ -110,7 +148,13 @@ requiring attention, the timer doesn't help either. */ #undef SPECIALIX_TIMER -/* +#ifdef SPECIALIX_TIMER +static int sx_poll = HZ; +#endif + + + +/* * The following defines are mostly for testing purposes. But if you need * some nice reporting in your syslog, you can define them also. */ @@ -140,11 +184,10 @@ static struct tty_driver *specialix_driver; static unsigned char * tmp_buf; -static DECLARE_MUTEX(tmp_buf_sem); static unsigned long baud_table[] = { 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, - 9600, 19200, 38400, 57600, 115200, 0, + 9600, 19200, 38400, 57600, 115200, 0, }; static struct specialix_board sx_board[SX_NBOARD] = { @@ -172,7 +215,7 @@ static inline int sx_paranoia_check(struct specialix_port const * port, KERN_ERR "sx: Warning: bad specialix port magic number for device %s in %s\n"; static const char *badinfo = KERN_ERR "sx: Warning: null specialix port for device %s in %s\n"; - + if (!port) { printk(badinfo, name, routine); return 1; @@ -187,9 +230,9 @@ static inline int sx_paranoia_check(struct specialix_port const * port, /* - * + * * Service functions for specialix IO8+ driver. - * + * */ /* Get board number from pointer */ @@ -202,7 +245,7 @@ static inline int board_No (struct specialix_board * bp) /* Get port number from pointer */ static inline int port_No (struct specialix_port const * port) { - return SX_PORT(port - sx_port); + return SX_PORT(port - sx_port); } @@ -254,12 +297,18 @@ static inline void sx_out_off(struct specialix_board * bp, unsigned short reg, /* Wait for Channel Command Register ready */ static inline void sx_wait_CCR(struct specialix_board * bp) { - unsigned long delay; - - for (delay = SX_CCR_TIMEOUT; delay; delay--) - if (!sx_in(bp, CD186x_CCR)) + unsigned long delay, flags; + unsigned char ccr; + + for (delay = SX_CCR_TIMEOUT; delay; delay--) { + spin_lock_irqsave(&bp->lock, flags); + ccr = sx_in(bp, CD186x_CCR); + spin_unlock_irqrestore(&bp->lock, flags); + if (!ccr) return; - + udelay (1); + } + printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); } @@ -268,11 +317,18 @@ static inline void sx_wait_CCR(struct specialix_board * bp) static inline void sx_wait_CCR_off(struct specialix_board * bp) { unsigned long delay; + unsigned char crr; + unsigned long flags; - for (delay = SX_CCR_TIMEOUT; delay; delay--) - if (!sx_in_off(bp, CD186x_CCR)) + for (delay = SX_CCR_TIMEOUT; delay; delay--) { + spin_lock_irqsave(&bp->lock, flags); + crr = sx_in_off(bp, CD186x_CCR); + spin_unlock_irqrestore(&bp->lock, flags); + if (!crr) return; - + udelay (1); + } + printk(KERN_ERR "sx%d: Timeout waiting for CCR.\n", board_No(bp)); } @@ -281,46 +337,41 @@ static inline void sx_wait_CCR_off(struct specialix_board * bp) * specialix IO8+ IO range functions. */ -static inline int sx_check_io_range(struct specialix_board * bp) -{ - return check_region (bp->base, SX_IO_SPACE); -} - - -static inline void sx_request_io_range(struct specialix_board * bp) +static inline int sx_request_io_range(struct specialix_board * bp) { - request_region(bp->base, - bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE, - "specialix IO8+" ); + return request_region(bp->base, + bp->flags & SX_BOARD_IS_PCI ? SX_PCI_IO_SPACE : SX_IO_SPACE, + "specialix IO8+") == NULL; } static inline void sx_release_io_range(struct specialix_board * bp) { - release_region(bp->base, + release_region(bp->base, bp->flags&SX_BOARD_IS_PCI?SX_PCI_IO_SPACE:SX_IO_SPACE); } - + /* Must be called with enabled interrupts */ -/* Ugly. Very ugly. Don't use this for anything else than initialization +/* Ugly. Very ugly. Don't use this for anything else than initialization code */ static inline void sx_long_delay(unsigned long delay) { unsigned long i; - + for (i = jiffies + delay; time_after(i, jiffies); ) ; } /* Set the IRQ using the RTS lines that run to the PAL on the board.... */ -int sx_set_irq ( struct specialix_board *bp) +static int sx_set_irq ( struct specialix_board *bp) { int virq; int i; + unsigned long flags; - if (bp->flags & SX_BOARD_IS_PCI) + if (bp->flags & SX_BOARD_IS_PCI) return 1; switch (bp->irq) { /* In the same order as in the docs... */ @@ -331,11 +382,12 @@ int sx_set_irq ( struct specialix_board *bp) default: printk (KERN_ERR "Speclialix: cannot set irq to %d.\n", bp->irq); return 0; } - + spin_lock_irqsave(&bp->lock, flags); for (i=0;i<2;i++) { sx_out(bp, CD186x_CAR, i); sx_out(bp, CD186x_MSVRTS, ((virq >> i) & 0x1)? MSVR_RTS:0); } + spin_unlock_irqrestore(&bp->lock, flags); return 1; } @@ -346,14 +398,14 @@ static int sx_init_CD186x(struct specialix_board * bp) unsigned long flags; int scaler; int rv = 1; - - save_flags(flags); cli(); + func_enter(); sx_wait_CCR_off(bp); /* Wait for CCR ready */ + spin_lock_irqsave(&bp->lock, flags); sx_out_off(bp, CD186x_CCR, CCR_HARDRESET); /* Reset CD186x chip */ - sti(); + spin_unlock_irqrestore(&bp->lock, flags); sx_long_delay(HZ/20); /* Delay 0.05 sec */ - cli(); + spin_lock_irqsave(&bp->lock, flags); sx_out_off(bp, CD186x_GIVR, SX_ID); /* Set ID for this chip */ sx_out_off(bp, CD186x_GICR, 0); /* Clear all bits */ sx_out_off(bp, CD186x_PILR1, SX_ACK_MINT); /* Prio for modem intr */ @@ -361,12 +413,13 @@ static int sx_init_CD186x(struct specialix_board * bp) sx_out_off(bp, CD186x_PILR3, SX_ACK_RINT); /* Prio for receiver intr */ /* Set RegAckEn */ sx_out_off(bp, CD186x_SRCR, sx_in (bp, CD186x_SRCR) | SRCR_REGACKEN); - + /* Setting up prescaler. We need 4 ticks per 1 ms */ scaler = SX_OSCFREQ/SPECIALIX_TPS; sx_out_off(bp, CD186x_PPRH, scaler >> 8); sx_out_off(bp, CD186x_PPRL, scaler & 0xff); + spin_unlock_irqrestore(&bp->lock, flags); if (!sx_set_irq (bp)) { /* Figure out how to pass this along... */ @@ -374,21 +427,25 @@ static int sx_init_CD186x(struct specialix_board * bp) rv = 0; } - restore_flags(flags); + func_exit(); return rv; } -int read_cross_byte (struct specialix_board *bp, int reg, int bit) +static int read_cross_byte (struct specialix_board *bp, int reg, int bit) { int i; int t; + unsigned long flags; + spin_lock_irqsave(&bp->lock, flags); for (i=0, t=0;i<8;i++) { sx_out_off (bp, CD186x_CAR, i); - if (sx_in_off (bp, reg) & bit) + if (sx_in_off (bp, reg) & bit) t |= 1 << i; } + spin_unlock_irqrestore(&bp->lock, flags); + return t; } @@ -396,15 +453,22 @@ int read_cross_byte (struct specialix_board *bp, int reg, int bit) #ifdef SPECIALIX_TIMER void missed_irq (unsigned long data) { - if (sx_in ((struct specialix_board *)data, CD186x_SRSR) & + unsigned char irq; + unsigned long flags; + struct specialix_board *bp = (struct specialix_board *)data; + + spin_lock_irqsave(&bp->lock, flags); + irq = sx_in ((struct specialix_board *)data, CD186x_SRSR) & (SRSR_RREQint | SRSR_TREQint | - SRSR_MREQint)) { + SRSR_MREQint); + spin_unlock_irqrestore(&bp->lock, flags); + if (irq) { printk (KERN_INFO "Missed interrupt... Calling int from timer. \n"); - sx_interrupt (((struct specialix_board *)data)->irq, - NULL, NULL); + sx_interrupt (((struct specialix_board *)data)->irq, + (void*)data, NULL); } - missed_irq_timer.expires = jiffies + HZ; + missed_irq_timer.expires = jiffies + sx_poll; add_timer (&missed_irq_timer); } #endif @@ -422,8 +486,12 @@ static int sx_probe(struct specialix_board *bp) int rev; int chip; - if (sx_check_io_range(bp)) + func_enter(); + + if (sx_request_io_range(bp)) { + func_exit(); return 1; + } /* Are the I/O ports here ? */ sx_out_off(bp, CD186x_PPRL, 0x5a); @@ -434,21 +502,22 @@ static int sx_probe(struct specialix_board *bp) short_pause (); val2 = sx_in_off(bp, CD186x_PPRL); - + if ((val1 != 0x5a) || (val2 != 0xa5)) { printk(KERN_INFO "sx%d: specialix IO8+ Board at 0x%03x not found.\n", board_No(bp), bp->base); + sx_release_io_range(bp); + func_exit(); return 1; } - /* Check the DSR lines that Specialix uses as board + /* Check the DSR lines that Specialix uses as board identification */ val1 = read_cross_byte (bp, CD186x_MSVR, MSVR_DSR); val2 = read_cross_byte (bp, CD186x_MSVR, MSVR_RTS); -#ifdef SPECIALIX_DEBUG - printk (KERN_DEBUG "sx%d: DSR lines are: %02x, rts lines are: %02x\n", + dprintk (SX_DEBUG_INIT, "sx%d: DSR lines are: %02x, rts lines are: %02x\n", board_No(bp), val1, val2); -#endif + /* They managed to switch the bit order between the docs and the IO8+ card. The new PCI card now conforms to old docs. They changed the PCI docs to reflect the situation on the @@ -457,6 +526,8 @@ static int sx_probe(struct specialix_board *bp) if (val1 != val2) { printk(KERN_INFO "sx%d: specialix IO8+ ID %02x at 0x%03x not found (%02x).\n", board_No(bp), val2, bp->base, val1); + sx_release_io_range(bp); + func_exit(); return 1; } @@ -470,31 +541,31 @@ static int sx_probe(struct specialix_board *bp) sx_wait_CCR(bp); sx_out(bp, CD186x_CCR, CCR_TXEN); /* Enable transmitter */ sx_out(bp, CD186x_IER, IER_TXRDY); /* Enable tx empty intr */ - sx_long_delay(HZ/20); + sx_long_delay(HZ/20); irqs = probe_irq_off(irqs); -#if SPECIALIX_DEBUG > 2 - printk (KERN_DEBUG "SRSR = %02x, ", sx_in(bp, CD186x_SRSR)); - printk ( "TRAR = %02x, ", sx_in(bp, CD186x_TRAR)); - printk ( "GIVR = %02x, ", sx_in(bp, CD186x_GIVR)); - printk ( "GICR = %02x, ", sx_in(bp, CD186x_GICR)); - printk ( "\n"); -#endif + dprintk (SX_DEBUG_INIT, "SRSR = %02x, ", sx_in(bp, CD186x_SRSR)); + dprintk (SX_DEBUG_INIT, "TRAR = %02x, ", sx_in(bp, CD186x_TRAR)); + dprintk (SX_DEBUG_INIT, "GIVR = %02x, ", sx_in(bp, CD186x_GIVR)); + dprintk (SX_DEBUG_INIT, "GICR = %02x, ", sx_in(bp, CD186x_GICR)); + dprintk (SX_DEBUG_INIT, "\n"); + /* Reset CD186x again */ if (!sx_init_CD186x(bp)) { /* Hmmm. This is dead code anyway. */ } -#if SPECIALIX_DEBUG > 2 - printk (KERN_DEBUG "val1 = %02x, val2 = %02x, val3 = %02x.\n", - val1, val2, val3); -#endif - + + dprintk (SX_DEBUG_INIT "val1 = %02x, val2 = %02x, val3 = %02x.\n", + val1, val2, val3); + } - + #if 0 if (irqs <= 0) { printk(KERN_ERR "sx%d: Can't find IRQ for specialix IO8+ board at 0x%03x.\n", board_No(bp), bp->base); + sx_release_io_range(bp); + func_exit(); return 1; } #endif @@ -504,18 +575,20 @@ static int sx_probe(struct specialix_board *bp) #endif /* Reset CD186x again */ if (!sx_init_CD186x(bp)) { - return -EIO; + sx_release_io_range(bp); + func_exit(); + return 1; } sx_request_io_range(bp); bp->flags |= SX_BOARD_PRESENT; - + /* Chip revcode pkgtype GFRCR SRCR bit 7 CD180 rev B 0x81 0 CD180 rev C 0x82 0 CD1864 rev A 0x82 1 - CD1865 rev A 0x83 1 -- Do not use!!! Does not work. + CD1865 rev A 0x83 1 -- Do not use!!! Does not work. CD1865 rev B 0x84 1 -- Thanks to Gwen Wang, Cirrus Logic. */ @@ -528,15 +601,13 @@ static int sx_probe(struct specialix_board *bp) default:chip=-1;rev='x'; } -#if SPECIALIX_DEBUG > 2 - printk (KERN_DEBUG " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) ); -#endif + dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) ); #ifdef SPECIALIX_TIMER init_timer (&missed_irq_timer); missed_irq_timer.function = missed_irq; missed_irq_timer.data = (unsigned long) bp; - missed_irq_timer.expires = jiffies + HZ; + missed_irq_timer.expires = jiffies + sx_poll; add_timer (&missed_irq_timer); #endif @@ -545,18 +616,23 @@ static int sx_probe(struct specialix_board *bp) bp->base, bp->irq, chip, rev); + func_exit(); return 0; } -/* - * +/* + * * Interrupt processing routines. * */ static inline void sx_mark_event(struct specialix_port * port, int event) { + func_enter(); + set_bit(event, &port->event); schedule_work(&port->tqueue); + + func_exit(); } @@ -564,16 +640,21 @@ static inline struct specialix_port * sx_get_port(struct specialix_board * bp, unsigned char const * what) { unsigned char channel; - struct specialix_port * port; - + struct specialix_port * port = NULL; + channel = sx_in(bp, CD186x_GICR) >> GICR_CHAN_OFF; + dprintk (SX_DEBUG_CHAN, "channel: %d\n", channel); if (channel < CD186x_NCH) { port = &sx_port[board_No(bp) * SX_NPORT + channel]; + dprintk (SX_DEBUG_CHAN, "port: %d %p flags: 0x%x\n",board_No(bp) * SX_NPORT + channel, port, port->flags & ASYNC_INITIALIZED); + if (port->flags & ASYNC_INITIALIZED) { + dprintk (SX_DEBUG_CHAN, "port: %d %p\n", channel, port); + func_exit(); return port; } } - printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n", + printk(KERN_INFO "sx%d: %s interrupt from invalid port %d\n", board_No(bp), what, channel); return NULL; } @@ -584,64 +665,70 @@ static inline void sx_receive_exc(struct specialix_board * bp) struct specialix_port *port; struct tty_struct *tty; unsigned char status; - unsigned char ch; + unsigned char ch, flag; - if (!(port = sx_get_port(bp, "Receive"))) - return; + func_enter(); - tty = port->tty; - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n", - board_No(bp), port_No(port)); + port = sx_get_port(bp, "Receive"); + if (!port) { + dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); + func_exit(); return; } - -#ifdef SX_REPORT_OVERRUN + tty = port->tty; + status = sx_in(bp, CD186x_RCSR); + + dprintk (SX_DEBUG_RX, "status: 0x%x\n", status); if (status & RCSR_OE) { port->overrun++; -#if SPECIALIX_DEBUG - printk(KERN_DEBUG "sx%d: port %d: Overrun. Total %ld overruns.\n", + dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Overrun. Total %ld overruns.\n", board_No(bp), port_No(port), port->overrun); -#endif } status &= port->mark_mask; -#else - status = sx_in(bp, CD186x_RCSR) & port->mark_mask; -#endif + + /* This flip buffer check needs to be below the reading of the + status register to reset the chip's IRQ.... */ + if (tty_buffer_request_room(tty, 1) == 0) { + dprintk(SX_DEBUG_FIFO, "sx%d: port %d: Working around flip buffer overflow.\n", + board_No(bp), port_No(port)); + func_exit(); + return; + } + ch = sx_in(bp, CD186x_RDR); if (!status) { + func_exit(); return; } if (status & RCSR_TOUT) { - printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n", + printk(KERN_INFO "sx%d: port %d: Receiver timeout. Hardware problems ?\n", board_No(bp), port_No(port)); + func_exit(); return; - + } else if (status & RCSR_BREAK) { -#ifdef SPECIALIX_DEBUG - printk(KERN_DEBUG "sx%d: port %d: Handling break...\n", + dprintk(SX_DEBUG_RX, "sx%d: port %d: Handling break...\n", board_No(bp), port_No(port)); -#endif - *tty->flip.flag_buf_ptr++ = TTY_BREAK; + flag = TTY_BREAK; if (port->flags & ASYNC_SAK) do_SAK(tty); - - } else if (status & RCSR_PE) - *tty->flip.flag_buf_ptr++ = TTY_PARITY; - - else if (status & RCSR_FE) - *tty->flip.flag_buf_ptr++ = TTY_FRAME; - + + } else if (status & RCSR_PE) + flag = TTY_PARITY; + + else if (status & RCSR_FE) + flag = TTY_FRAME; + else if (status & RCSR_OE) - *tty->flip.flag_buf_ptr++ = TTY_OVERRUN; - + flag = TTY_OVERRUN; + else - *tty->flip.flag_buf_ptr++ = 0; - - *tty->flip.char_buf_ptr++ = ch; - tty->flip.count++; - schedule_delayed_work(&tty->flip.work, 1); + flag = TTY_NORMAL; + + if(tty_insert_flip_char(tty, ch, flag)) + tty_flip_buffer_push(tty); + func_exit(); } @@ -650,29 +737,26 @@ static inline void sx_receive(struct specialix_board * bp) struct specialix_port *port; struct tty_struct *tty; unsigned char count; - - if (!(port = sx_get_port(bp, "Receive"))) + + func_enter(); + + if (!(port = sx_get_port(bp, "Receive"))) { + dprintk (SX_DEBUG_RX, "Hmm, couldn't find port.\n"); + func_exit(); return; - + } tty = port->tty; - + count = sx_in(bp, CD186x_RDCR); - -#ifdef SX_REPORT_FIFO + dprintk (SX_DEBUG_RX, "port: %p: count: %d\n", port, count); port->hits[count > 8 ? 9 : count]++; -#endif - - while (count--) { - if (tty->flip.count >= TTY_FLIPBUF_SIZE) { - printk(KERN_INFO "sx%d: port %d: Working around flip buffer overflow.\n", - board_No(bp), port_No(port)); - break; - } - *tty->flip.char_buf_ptr++ = sx_in(bp, CD186x_RDR); - *tty->flip.flag_buf_ptr++ = 0; - tty->flip.count++; - } - schedule_delayed_work(&tty->flip.work, 1); + + tty_buffer_request_room(tty, count); + + while (count--) + tty_insert_flip_char(tty, sx_in(bp, CD186x_RDR), TTY_NORMAL); + tty_flip_buffer_push(tty); + func_exit(); } @@ -681,29 +765,33 @@ static inline void sx_transmit(struct specialix_board * bp) struct specialix_port *port; struct tty_struct *tty; unsigned char count; - - - if (!(port = sx_get_port(bp, "Transmit"))) + + func_enter(); + if (!(port = sx_get_port(bp, "Transmit"))) { + func_exit(); return; - + } + dprintk (SX_DEBUG_TX, "port: %p\n", port); tty = port->tty; - + if (port->IER & IER_TXEMPTY) { /* FIFO drained */ sx_out(bp, CD186x_CAR, port_No(port)); port->IER &= ~IER_TXEMPTY; sx_out(bp, CD186x_IER, port->IER); + func_exit(); return; } - + if ((port->xmit_cnt <= 0 && !port->break_length) || tty->stopped || tty->hw_stopped) { sx_out(bp, CD186x_CAR, port_No(port)); port->IER &= ~IER_TXRDY; sx_out(bp, CD186x_IER, port->IER); + func_exit(); return; } - + if (port->break_length) { if (port->break_length > 0) { if (port->COR2 & COR2_ETC) { @@ -725,9 +813,11 @@ static inline void sx_transmit(struct specialix_board * bp) sx_out(bp, CD186x_CCR, CCR_CORCHG2); port->break_length = 0; } + + func_exit(); return; } - + count = CD186x_NFIFO; do { sx_out(bp, CD186x_TDR, port->xmit_buf[port->xmit_tail++]); @@ -735,7 +825,7 @@ static inline void sx_transmit(struct specialix_board * bp) if (--port->xmit_cnt <= 0) break; } while (--count > 0); - + if (port->xmit_cnt <= 0) { sx_out(bp, CD186x_CAR, port_No(port)); port->IER &= ~IER_TXRDY; @@ -743,6 +833,8 @@ static inline void sx_transmit(struct specialix_board * bp) } if (port->xmit_cnt <= port->wakeup_chars) sx_mark_event(port, RS_EVENT_WRITE_WAKEUP); + + func_exit(); } @@ -751,35 +843,29 @@ static inline void sx_check_modem(struct specialix_board * bp) struct specialix_port *port; struct tty_struct *tty; unsigned char mcr; + int msvr_cd; -#ifdef SPECIALIX_DEBUG - printk (KERN_DEBUG "Modem intr. "); -#endif + dprintk (SX_DEBUG_SIGNALS, "Modem intr. "); if (!(port = sx_get_port(bp, "Modem"))) return; - + tty = port->tty; - + mcr = sx_in(bp, CD186x_MCR); printk ("mcr = %02x.\n", mcr); if ((mcr & MCR_CDCHG)) { -#ifdef SPECIALIX_DEBUG - printk (KERN_DEBUG "CD just changed... "); -#endif - if (sx_in(bp, CD186x_MSVR) & MSVR_CD) { -#ifdef SPECIALIX_DEBUG - printk ( "Waking up guys in open.\n"); -#endif + dprintk (SX_DEBUG_SIGNALS, "CD just changed... "); + msvr_cd = sx_in(bp, CD186x_MSVR) & MSVR_CD; + if (msvr_cd) { + dprintk (SX_DEBUG_SIGNALS, "Waking up guys in open.\n"); wake_up_interruptible(&port->open_wait); } else { -#ifdef SPECIALIX_DEBUG - printk ( "Sending HUP.\n"); -#endif + dprintk (SX_DEBUG_SIGNALS, "Sending HUP.\n"); schedule_work(&port->tqueue_hangup); } } - + #ifdef SPECIALIX_BRAIN_DAMAGED_CTS if (mcr & MCR_CTSCHG) { if (sx_in(bp, CD186x_MSVR) & MSVR_CTS) { @@ -806,7 +892,7 @@ static inline void sx_check_modem(struct specialix_board * bp) sx_out(bp, CD186x_IER, port->IER); } #endif /* SPECIALIX_BRAIN_DAMAGED_CTS */ - + /* Clear change bits */ sx_out(bp, CD186x_MCR, 0); } @@ -820,13 +906,18 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs) struct specialix_board *bp; unsigned long loop = 0; int saved_reg; + unsigned long flags; + + func_enter(); bp = dev_id; - + spin_lock_irqsave(&bp->lock, flags); + + dprintk (SX_DEBUG_FLOW, "enter %s port %d room: %ld\n", __FUNCTION__, port_No(sx_get_port(bp, "INT")), SERIAL_XMIT_SIZE - sx_get_port(bp, "ITN")->xmit_cnt - 1); if (!bp || !(bp->flags & SX_BOARD_ACTIVE)) { -#ifdef SPECIALIX_DEBUG - printk (KERN_DEBUG "sx: False interrupt. irq %d.\n", irq); -#endif + dprintk (SX_DEBUG_IRQ, "sx: False interrupt. irq %d.\n", irq); + spin_unlock_irqrestore(&bp->lock, flags); + func_exit(); return IRQ_NONE; } @@ -835,7 +926,7 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs) while ((++loop < 16) && (status = (sx_in(bp, CD186x_SRSR) & (SRSR_RREQint | SRSR_TREQint | - SRSR_MREQint)))) { + SRSR_MREQint)))) { if (status & SRSR_RREQint) { ack = sx_in(bp, CD186x_RRAR); @@ -844,32 +935,34 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs) else if (ack == (SX_ID | GIVR_IT_REXC)) sx_receive_exc(bp); else - printk(KERN_ERR "sx%d: Bad receive ack 0x%02x.\n", - board_No(bp), ack); - + printk(KERN_ERR "sx%d: status: 0x%x Bad receive ack 0x%02x.\n", + board_No(bp), status, ack); + } else if (status & SRSR_TREQint) { ack = sx_in(bp, CD186x_TRAR); if (ack == (SX_ID | GIVR_IT_TX)) sx_transmit(bp); else - printk(KERN_ERR "sx%d: Bad transmit ack 0x%02x.\n", - board_No(bp), ack); + printk(KERN_ERR "sx%d: status: 0x%x Bad transmit ack 0x%02x. port: %d\n", + board_No(bp), status, ack, port_No (sx_get_port (bp, "Int"))); } else if (status & SRSR_MREQint) { ack = sx_in(bp, CD186x_MRAR); - if (ack == (SX_ID | GIVR_IT_MODEM)) + if (ack == (SX_ID | GIVR_IT_MODEM)) sx_check_modem(bp); else - printk(KERN_ERR "sx%d: Bad modem ack 0x%02x.\n", - board_No(bp), ack); - - } + printk(KERN_ERR "sx%d: status: 0x%x Bad modem ack 0x%02x.\n", + board_No(bp), status, ack); + + } sx_out(bp, CD186x_EOIR, 0); /* Mark end of interrupt */ } bp->reg = saved_reg; outb (bp->reg, bp->base + SX_ADDR_REG); + spin_unlock_irqrestore(&bp->lock, flags); + func_exit(); return IRQ_HANDLED; } @@ -878,23 +971,39 @@ static irqreturn_t sx_interrupt(int irq, void *dev_id, struct pt_regs *regs) * Routines for open & close processing. */ -void turn_ints_off (struct specialix_board *bp) +static void turn_ints_off (struct specialix_board *bp) { + unsigned long flags; + + func_enter(); if (bp->flags & SX_BOARD_IS_PCI) { /* This was intended for enabeling the interrupt on the * PCI card. However it seems that it's already enabled * and as PCI interrupts can be shared, there is no real * reason to have to turn it off. */ } + + spin_lock_irqsave(&bp->lock, flags); (void) sx_in_off (bp, 0); /* Turn off interrupts. */ + spin_unlock_irqrestore(&bp->lock, flags); + + func_exit(); } -void turn_ints_on (struct specialix_board *bp) +static void turn_ints_on (struct specialix_board *bp) { + unsigned long flags; + + func_enter(); + if (bp->flags & SX_BOARD_IS_PCI) { /* play with the PCI chip. See comment above. */ } + spin_lock_irqsave(&bp->lock, flags); (void) sx_in (bp, 0); /* Turn ON interrupts. */ + spin_unlock_irqrestore(&bp->lock, flags); + + func_exit(); } @@ -903,7 +1012,7 @@ static inline int sx_setup_board(struct specialix_board * bp) { int error; - if (bp->flags & SX_BOARD_ACTIVE) + if (bp->flags & SX_BOARD_ACTIVE) return 0; if (bp->flags & SX_BOARD_IS_PCI) @@ -911,7 +1020,7 @@ static inline int sx_setup_board(struct specialix_board * bp) else error = request_irq(bp->irq, sx_interrupt, SA_INTERRUPT, "specialix IO8+", bp); - if (error) + if (error) return error; turn_ints_on (bp); @@ -924,23 +1033,28 @@ static inline int sx_setup_board(struct specialix_board * bp) /* Called with disabled interrupts */ static inline void sx_shutdown_board(struct specialix_board *bp) { - if (!(bp->flags & SX_BOARD_ACTIVE)) + func_enter(); + + if (!(bp->flags & SX_BOARD_ACTIVE)) { + func_exit(); return; - + } + bp->flags &= ~SX_BOARD_ACTIVE; - -#if SPECIALIX_DEBUG > 2 - printk ("Freeing IRQ%d for board %d.\n", bp->irq, board_No (bp)); -#endif + + dprintk (SX_DEBUG_IRQ, "Freeing IRQ%d for board %d.\n", + bp->irq, board_No (bp)); free_irq(bp->irq, bp); turn_ints_off (bp); + + func_exit(); } /* - * Setting up port characteristics. + * Setting up port characteristics. * Must be called with disabled interrupts */ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *port) @@ -951,13 +1065,19 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p unsigned char cor1 = 0, cor3 = 0; unsigned char mcor1 = 0, mcor2 = 0; static unsigned long again; - - if (!(tty = port->tty) || !tty->termios) + unsigned long flags; + + func_enter(); + + if (!(tty = port->tty) || !tty->termios) { + func_exit(); return; + } port->IER = 0; port->COR2 = 0; /* Select port on the board */ + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); /* The Specialix board doens't implement the RTS lines. @@ -966,14 +1086,13 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p port->MSVR = MSVR_DTR | (sx_in(bp, CD186x_MSVR) & MSVR_RTS); else port->MSVR = (sx_in(bp, CD186x_MSVR) & MSVR_RTS); -#ifdef DEBUG_SPECIALIX - printk (KERN_DEBUG "sx: got MSVR=%02x.\n", port->MSVR); -#endif + spin_unlock_irqrestore(&bp->lock, flags); + dprintk (SX_DEBUG_TERMIOS, "sx: got MSVR=%02x.\n", port->MSVR); baud = C_BAUD(tty); - + if (baud & CBAUDEX) { baud &= ~CBAUDEX; - if (baud < 1 || baud > 2) + if (baud < 1 || baud > 2) port->tty->termios->c_cflag &= ~CBAUDEX; else baud += 15; @@ -984,21 +1103,19 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) baud += 2; } - - + + if (!baud_table[baud]) { /* Drop DTR & exit */ -#ifdef SPECIALIX_DEBUG - printk (KERN_DEBUG "Dropping DTR... Hmm....\n"); -#endif + dprintk (SX_DEBUG_TERMIOS, "Dropping DTR... Hmm....\n"); if (!SX_CRTSCTS (tty)) { port -> MSVR &= ~ MSVR_DTR; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_MSVR, port->MSVR ); - } -#ifdef DEBUG_SPECIALIX + spin_unlock_irqrestore(&bp->lock, flags); + } else - printk (KERN_DEBUG "Can't drop DTR: no DTR.\n"); -#endif + dprintk (SX_DEBUG_TERMIOS, "Can't drop DTR: no DTR.\n"); return; } else { /* Set DTR on */ @@ -1006,9 +1123,9 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p port ->MSVR |= MSVR_DTR; } } - + /* - * Now we must calculate some speed depended things + * Now we must calculate some speed depended things */ /* Set baud rate for port */ @@ -1021,7 +1138,7 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p tmp = (((SX_OSCFREQ + baud_table[baud]/2) / baud_table[baud] + CD186x_TPC/2) / CD186x_TPC); - if ((tmp < 0x10) && time_before(again, jiffies)) { + if ((tmp < 0x10) && time_before(again, jiffies)) { again = jiffies + HZ * 60; /* Page 48 of version 2.0 of the CL-CD1865 databook */ if (tmp >= 12) { @@ -1033,32 +1150,33 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p printk (KERN_INFO "sx%d: Baud rate divisor is %ld. \n" "Warning: overstressing Cirrus chip. " "This might not work.\n" - "Read specialix.txt for more info.\n", + "Read specialix.txt for more info.\n", port_No (port), tmp); } } - - sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff); - sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff); - sx_out(bp, CD186x_RBPRL, tmp & 0xff); + spin_lock_irqsave(&bp->lock, flags); + sx_out(bp, CD186x_RBPRH, (tmp >> 8) & 0xff); + sx_out(bp, CD186x_TBPRH, (tmp >> 8) & 0xff); + sx_out(bp, CD186x_RBPRL, tmp & 0xff); sx_out(bp, CD186x_TBPRL, tmp & 0xff); - + spin_unlock_irqrestore(&bp->lock, flags); if (port->custom_divisor) { baud = (SX_OSCFREQ + port->custom_divisor/2) / port->custom_divisor; baud = ( baud + 5 ) / 10; - } else + } else baud = (baud_table[baud] + 5) / 10; /* Estimated CPS */ /* Two timer ticks seems enough to wakeup something like SLIP driver */ - tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO; + tmp = ((baud + HZ/2) / HZ) * 2 - CD186x_NFIFO; port->wakeup_chars = (tmp < 0) ? 0 : ((tmp >= SERIAL_XMIT_SIZE) ? SERIAL_XMIT_SIZE - 1 : tmp); - + /* Receiver timeout will be transmission time for 1.5 chars */ tmp = (SPECIALIX_TPS + SPECIALIX_TPS/2 + baud/2) / baud; tmp = (tmp > 0xff) ? 0xff : tmp; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_RTPR, tmp); - + spin_unlock_irqrestore(&bp->lock, flags); switch (C_CSIZE(tty)) { case CS5: cor1 |= COR1_5BITS; @@ -1073,29 +1191,29 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p cor1 |= COR1_8BITS; break; } - - if (C_CSTOPB(tty)) + + if (C_CSTOPB(tty)) cor1 |= COR1_2SB; - + cor1 |= COR1_IGNORE; if (C_PARENB(tty)) { cor1 |= COR1_NORMPAR; - if (C_PARODD(tty)) + if (C_PARODD(tty)) cor1 |= COR1_ODDP; - if (I_INPCK(tty)) + if (I_INPCK(tty)) cor1 &= ~COR1_IGNORE; } /* Set marking of some errors */ port->mark_mask = RCSR_OE | RCSR_TOUT; - if (I_INPCK(tty)) + if (I_INPCK(tty)) port->mark_mask |= RCSR_FE | RCSR_PE; - if (I_BRKINT(tty) || I_PARMRK(tty)) + if (I_BRKINT(tty) || I_PARMRK(tty)) port->mark_mask |= RCSR_BREAK; - if (I_IGNPAR(tty)) + if (I_IGNPAR(tty)) port->mark_mask &= ~(RCSR_FE | RCSR_PE); if (I_IGNBRK(tty)) { port->mark_mask &= ~RCSR_BREAK; - if (I_IGNPAR(tty)) + if (I_IGNPAR(tty)) /* Real raw mode. Ignore all */ port->mark_mask &= ~RCSR_OE; } @@ -1105,9 +1223,11 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p port->IER |= IER_DSR | IER_CTS; mcor1 |= MCOR1_DSRZD | MCOR1_CTSZD; mcor2 |= MCOR2_DSROD | MCOR2_CTSOD; + spin_lock_irqsave(&bp->lock, flags); tty->hw_stopped = !(sx_in(bp, CD186x_MSVR) & (MSVR_CTS|MSVR_DSR)); + spin_unlock_irqrestore(&bp->lock, flags); #else - port->COR2 |= COR2_CTSAE; + port->COR2 |= COR2_CTSAE; #endif } /* Enable Software Flow Control. FIXME: I'm not sure about this */ @@ -1117,10 +1237,12 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p cor3 |= (COR3_FCT | COR3_SCDE); if (I_IXANY(tty)) port->COR2 |= COR2_IXM; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_SCHR1, START_CHAR(tty)); sx_out(bp, CD186x_SCHR2, STOP_CHAR(tty)); sx_out(bp, CD186x_SCHR3, START_CHAR(tty)); sx_out(bp, CD186x_SCHR4, STOP_CHAR(tty)); + spin_unlock_irqrestore(&bp->lock, flags); } if (!C_CLOCAL(tty)) { /* Enable CD check */ @@ -1128,33 +1250,39 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p mcor1 |= MCOR1_CDZD; mcor2 |= MCOR2_CDOD; } - - if (C_CREAD(tty)) + + if (C_CREAD(tty)) /* Enable receiver */ port->IER |= IER_RXD; - + /* Set input FIFO size (1-8 bytes) */ - cor3 |= SPECIALIX_RXFIFO; + cor3 |= sx_rxfifo; /* Setting up CD186x channel registers */ + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_COR1, cor1); sx_out(bp, CD186x_COR2, port->COR2); sx_out(bp, CD186x_COR3, cor3); + spin_unlock_irqrestore(&bp->lock, flags); /* Make CD186x know about registers change */ sx_wait_CCR(bp); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CCR, CCR_CORCHG1 | CCR_CORCHG2 | CCR_CORCHG3); /* Setting up modem option registers */ -#ifdef DEBUG_SPECIALIX - printk ("Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2); -#endif + dprintk (SX_DEBUG_TERMIOS, "Mcor1 = %02x, mcor2 = %02x.\n", mcor1, mcor2); sx_out(bp, CD186x_MCOR1, mcor1); sx_out(bp, CD186x_MCOR2, mcor2); + spin_unlock_irqrestore(&bp->lock, flags); /* Enable CD186x transmitter & receiver */ sx_wait_CCR(bp); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CCR, CCR_TXEN | CCR_RXEN); /* Enable interrupts */ sx_out(bp, CD186x_IER, port->IER); /* And finally set the modem lines... */ sx_out(bp, CD186x_MSVR, port->MSVR); + spin_unlock_irqrestore(&bp->lock, flags); + + func_exit(); } @@ -1162,37 +1290,44 @@ static void sx_change_speed(struct specialix_board *bp, struct specialix_port *p static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port) { unsigned long flags; - - if (port->flags & ASYNC_INITIALIZED) + + func_enter(); + + if (port->flags & ASYNC_INITIALIZED) { + func_exit(); return 0; - + } + if (!port->xmit_buf) { /* We may sleep in get_zeroed_page() */ unsigned long tmp; - - if (!(tmp = get_zeroed_page(GFP_KERNEL))) + + if (!(tmp = get_zeroed_page(GFP_KERNEL))) { + func_exit(); return -ENOMEM; + } if (port->xmit_buf) { free_page(tmp); + func_exit(); return -ERESTARTSYS; } port->xmit_buf = (unsigned char *) tmp; } - - save_flags(flags); cli(); - - if (port->tty) + + spin_lock_irqsave(&port->lock, flags); + + if (port->tty) clear_bit(TTY_IO_ERROR, &port->tty->flags); - - if (port->count == 1) - bp->count++; - + port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; sx_change_speed(bp, port); port->flags |= ASYNC_INITIALIZED; - - restore_flags(flags); + + spin_unlock_irqrestore(&port->lock, flags); + + + func_exit(); return 0; } @@ -1201,65 +1336,57 @@ static int sx_setup_port(struct specialix_board *bp, struct specialix_port *port static void sx_shutdown_port(struct specialix_board *bp, struct specialix_port *port) { struct tty_struct *tty; - - if (!(port->flags & ASYNC_INITIALIZED)) + int i; + unsigned long flags; + + func_enter(); + + if (!(port->flags & ASYNC_INITIALIZED)) { + func_exit(); return; - -#ifdef SX_REPORT_OVERRUN - printk(KERN_INFO "sx%d: port %d: Total %ld overruns were detected.\n", - board_No(bp), port_No(port), port->overrun); -#endif -#ifdef SX_REPORT_FIFO - { - int i; - - printk(KERN_INFO "sx%d: port %d: FIFO hits [ ", - board_No(bp), port_No(port)); + } + + if (sx_debug & SX_DEBUG_FIFO) { + dprintk(SX_DEBUG_FIFO, "sx%d: port %d: %ld overruns, FIFO hits [ ", + board_No(bp), port_No(port), port->overrun); for (i = 0; i < 10; i++) { - printk("%ld ", port->hits[i]); + dprintk(SX_DEBUG_FIFO, "%ld ", port->hits[i]); } - printk("].\n"); + dprintk(SX_DEBUG_FIFO, "].\n"); } -#endif + if (port->xmit_buf) { free_page((unsigned long) port->xmit_buf); port->xmit_buf = NULL; } /* Select port */ + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); if (!(tty = port->tty) || C_HUPCL(tty)) { /* Drop DTR */ sx_out(bp, CD186x_MSVDTR, 0); } - + spin_unlock_irqrestore(&bp->lock, flags); /* Reset port */ sx_wait_CCR(bp); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CCR, CCR_SOFTRESET); /* Disable all interrupts from this port */ port->IER = 0; sx_out(bp, CD186x_IER, port->IER); - + spin_unlock_irqrestore(&bp->lock, flags); if (tty) set_bit(TTY_IO_ERROR, &tty->flags); port->flags &= ~ASYNC_INITIALIZED; - - if (--bp->count < 0) { - printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d\n", - board_No(bp), bp->count); - bp->count = 0; - } - - /* - * If this is the last opened port on the board - * shutdown whole board - */ - if (!bp->count) + + if (!bp->count) sx_shutdown_board(bp); + func_exit(); } - + static int block_til_ready(struct tty_struct *tty, struct file * filp, struct specialix_port *port) { @@ -1268,6 +1395,9 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, int retval; int do_clocal = 0; int CD; + unsigned long flags; + + func_enter(); /* * If the device is in the middle of being closed, then block @@ -1275,12 +1405,15 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, */ if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) { interruptible_sleep_on(&port->close_wait); - if (port->flags & ASYNC_HUP_NOTIFY) + if (port->flags & ASYNC_HUP_NOTIFY) { + func_exit(); return -EAGAIN; - else + } else { + func_exit(); return -ERESTARTSYS; + } } - + /* * If non-blocking mode is set, or the port is not enabled, * then make the check up front and then exit. @@ -1288,6 +1421,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) { port->flags |= ASYNC_NORMAL_ACTIVE; + func_exit(); return 0; } @@ -1303,13 +1437,14 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, */ retval = 0; add_wait_queue(&port->open_wait, &wait); - cli(); - if (!tty_hung_up_p(filp)) + spin_lock_irqsave(&port->lock, flags); + if (!tty_hung_up_p(filp)) { port->count--; - sti(); + } + spin_unlock_irqrestore(&port->lock, flags); port->blocked_open++; while (1) { - cli(); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); CD = sx_in(bp, CD186x_MSVR) & MSVR_CD; if (SX_CRTSCTS (tty)) { @@ -1320,15 +1455,15 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, /* Activate DTR */ port->MSVR |= MSVR_DTR; sx_out (bp, CD186x_MSVR, port->MSVR); - } - sti(); + } + spin_unlock_irqrestore(&bp->lock, flags); set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) { if (port->flags & ASYNC_HUP_NOTIFY) retval = -EAGAIN; else - retval = -ERESTARTSYS; + retval = -ERESTARTSYS; break; } if (!(port->flags & ASYNC_CLOSING) && @@ -1340,17 +1475,24 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp, } schedule(); } - current->state = TASK_RUNNING; + + set_current_state(TASK_RUNNING); remove_wait_queue(&port->open_wait, &wait); - if (!tty_hung_up_p(filp)) + spin_lock_irqsave(&port->lock, flags); + if (!tty_hung_up_p(filp)) { port->count++; + } port->blocked_open--; - if (retval) + spin_unlock_irqrestore(&port->lock, flags); + if (retval) { + func_exit(); return retval; - + } + port->flags |= ASYNC_NORMAL_ACTIVE; + func_exit(); return 0; -} +} static int sx_open(struct tty_struct * tty, struct file * filp) @@ -1359,36 +1501,55 @@ static int sx_open(struct tty_struct * tty, struct file * filp) int error; struct specialix_port * port; struct specialix_board * bp; - + int i; + unsigned long flags; + + func_enter(); + board = SX_BOARD(tty->index); - if (board >= SX_NBOARD || !(sx_board[board].flags & SX_BOARD_PRESENT)) + if (board >= SX_NBOARD || !(sx_board[board].flags & SX_BOARD_PRESENT)) { + func_exit(); return -ENODEV; - + } + bp = &sx_board[board]; port = sx_port + board * SX_NPORT + SX_PORT(tty->index); + port->overrun = 0; + for (i = 0; i < 10; i++) + port->hits[i]=0; -#ifdef DEBUG_SPECIALIX - printk (KERN_DEBUG "Board = %d, bp = %p, port = %p, portno = %d.\n", + dprintk (SX_DEBUG_OPEN, "Board = %d, bp = %p, port = %p, portno = %d.\n", board, bp, port, SX_PORT(tty->index)); -#endif - if (sx_paranoia_check(port, tty->name, "sx_open")) + if (sx_paranoia_check(port, tty->name, "sx_open")) { + func_enter(); return -ENODEV; + } - if ((error = sx_setup_board(bp))) + if ((error = sx_setup_board(bp))) { + func_exit(); return error; + } + spin_lock_irqsave(&bp->lock, flags); port->count++; + bp->count++; tty->driver_data = port; port->tty = tty; + spin_unlock_irqrestore(&bp->lock, flags); - if ((error = sx_setup_port(bp, port))) + if ((error = sx_setup_port(bp, port))) { + func_enter(); return error; - - if ((error = block_til_ready(tty, filp, port))) + } + + if ((error = block_til_ready(tty, filp, port))) { + func_enter(); return error; + } + func_exit(); return 0; } @@ -1399,16 +1560,20 @@ static void sx_close(struct tty_struct * tty, struct file * filp) struct specialix_board *bp; unsigned long flags; unsigned long timeout; - - if (!port || sx_paranoia_check(port, tty->name, "close")) + + func_enter(); + if (!port || sx_paranoia_check(port, tty->name, "close")) { + func_exit(); return; - - save_flags(flags); cli(); + } + spin_lock_irqsave(&port->lock, flags); + if (tty_hung_up_p(filp)) { - restore_flags(flags); + spin_unlock_irqrestore(&port->lock, flags); + func_exit(); return; } - + bp = port_Board(port); if ((tty->count == 1) && (port->count != 1)) { printk(KERN_ERR "sx%d: sx_close: bad port count;" @@ -1416,35 +1581,42 @@ static void sx_close(struct tty_struct * tty, struct file * filp) board_No(bp), port->count); port->count = 1; } - if (--port->count < 0) { - printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n", - board_No(bp), port_No(port), port->count); - port->count = 0; - } - if (port->count) { - restore_flags(flags); + + if (port->count > 1) { + port->count--; + bp->count--; + + spin_unlock_irqrestore(&port->lock, flags); + + func_exit(); return; } port->flags |= ASYNC_CLOSING; /* - * Now we wait for the transmit buffer to clear; and we notify + * Now we wait for the transmit buffer to clear; and we notify * the line discipline to only process XON/XOFF characters. */ tty->closing = 1; - if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) + spin_unlock_irqrestore(&port->lock, flags); + dprintk (SX_DEBUG_OPEN, "Closing\n"); + if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE) { tty_wait_until_sent(tty, port->closing_wait); + } /* * At this point we stop accepting input. To do this, we * disable the receive line status interrupts, and tell the * interrupt driver to stop checking the data ready bit in the * line status register. */ + dprintk (SX_DEBUG_OPEN, "Closed\n"); port->IER &= ~IER_RXD; if (port->flags & ASYNC_INITIALIZED) { port->IER &= ~IER_TXRDY; port->IER |= IER_TXEMPTY; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); sx_out(bp, CD186x_IER, port->IER); + spin_unlock_irqrestore(&bp->lock, flags); /* * Before we drop DTR, make sure the UART transmitter * has completely drained; this is especially @@ -1452,8 +1624,8 @@ static void sx_close(struct tty_struct * tty, struct file * filp) */ timeout = jiffies+HZ; while(port->IER & IER_TXEMPTY) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(port->timeout); + set_current_state (TASK_INTERRUPTIBLE); + msleep_interruptible(jiffies_to_msecs(port->timeout)); if (time_after(jiffies, timeout)) { printk (KERN_INFO "Timeout waiting for close\n"); break; @@ -1461,99 +1633,89 @@ static void sx_close(struct tty_struct * tty, struct file * filp) } } + + if (--bp->count < 0) { + printk(KERN_ERR "sx%d: sx_shutdown_port: bad board count: %d port: %d\n", + board_No(bp), bp->count, tty->index); + bp->count = 0; + } + if (--port->count < 0) { + printk(KERN_ERR "sx%d: sx_close: bad port count for tty%d: %d\n", + board_No(bp), port_No(port), port->count); + port->count = 0; + } + sx_shutdown_port(bp, port); if (tty->driver->flush_buffer) tty->driver->flush_buffer(tty); tty_ldisc_flush(tty); + spin_lock_irqsave(&port->lock, flags); tty->closing = 0; port->event = 0; port->tty = NULL; + spin_unlock_irqrestore(&port->lock, flags); if (port->blocked_open) { if (port->close_delay) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(port->close_delay); + msleep_interruptible(jiffies_to_msecs(port->close_delay)); } wake_up_interruptible(&port->open_wait); } port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); wake_up_interruptible(&port->close_wait); - restore_flags(flags); + + func_exit(); } -static int sx_write(struct tty_struct * tty, int from_user, +static int sx_write(struct tty_struct * tty, const unsigned char *buf, int count) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; struct specialix_board *bp; int c, total = 0; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_write")) - return 0; - - bp = port_Board(port); - if (!tty || !port->xmit_buf || !tmp_buf) + func_enter(); + if (sx_paranoia_check(port, tty->name, "sx_write")) { + func_exit(); return 0; + } - save_flags(flags); - if (from_user) { - down(&tmp_buf_sem); - while (1) { - c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, - SERIAL_XMIT_SIZE - port->xmit_head)); - if (c <= 0) - break; + bp = port_Board(port); - c -= copy_from_user(tmp_buf, buf, c); - if (!c) { - if (!total) - total = -EFAULT; - break; - } + if (!tty || !port->xmit_buf || !tmp_buf) { + func_exit(); + return 0; + } - cli(); - c = min_t(int, c, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, - SERIAL_XMIT_SIZE - port->xmit_head)); - memcpy(port->xmit_buf + port->xmit_head, tmp_buf, c); - port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1); - port->xmit_cnt += c; - restore_flags(flags); - - buf += c; - count -= c; - total += c; - } - up(&tmp_buf_sem); - } else { - while (1) { - cli(); - c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, - SERIAL_XMIT_SIZE - port->xmit_head)); - if (c <= 0) { - restore_flags(flags); - break; - } - memcpy(port->xmit_buf + port->xmit_head, buf, c); - port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1); - port->xmit_cnt += c; - restore_flags(flags); - - buf += c; - count -= c; - total += c; + while (1) { + spin_lock_irqsave(&port->lock, flags); + c = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1, + SERIAL_XMIT_SIZE - port->xmit_head)); + if (c <= 0) { + spin_unlock_irqrestore(&port->lock, flags); + break; } + memcpy(port->xmit_buf + port->xmit_head, buf, c); + port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1); + port->xmit_cnt += c; + spin_unlock_irqrestore(&port->lock, flags); + + buf += c; + count -= c; + total += c; } - cli(); + spin_lock_irqsave(&bp->lock, flags); if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped && !(port->IER & IER_TXRDY)) { port->IER |= IER_TXRDY; sx_out(bp, CD186x_CAR, port_No(port)); sx_out(bp, CD186x_IER, port->IER); } - restore_flags(flags); + spin_unlock_irqrestore(&bp->lock, flags); + func_exit(); + return total; } @@ -1562,24 +1724,36 @@ static void sx_put_char(struct tty_struct * tty, unsigned char ch) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; unsigned long flags; + struct specialix_board * bp; - if (sx_paranoia_check(port, tty->name, "sx_put_char")) - return; + func_enter(); - if (!tty || !port->xmit_buf) + if (sx_paranoia_check(port, tty->name, "sx_put_char")) { + func_exit(); return; - - save_flags(flags); cli(); - - if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { - restore_flags(flags); + } + dprintk (SX_DEBUG_TX, "check tty: %p %p\n", tty, port->xmit_buf); + if (!tty || !port->xmit_buf) { + func_exit(); return; } + bp = port_Board(port); + spin_lock_irqsave(&port->lock, flags); + dprintk (SX_DEBUG_TX, "xmit_cnt: %d xmit_buf: %p\n", port->xmit_cnt, port->xmit_buf); + if ((port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) || (!port->xmit_buf)) { + spin_unlock_irqrestore(&port->lock, flags); + dprintk (SX_DEBUG_TX, "Exit size\n"); + func_exit(); + return; + } + dprintk (SX_DEBUG_TX, "Handle xmit: %p %p\n", port, port->xmit_buf); port->xmit_buf[port->xmit_head++] = ch; port->xmit_head &= SERIAL_XMIT_SIZE - 1; port->xmit_cnt++; - restore_flags(flags); + spin_unlock_irqrestore(&port->lock, flags); + + func_exit(); } @@ -1587,19 +1761,26 @@ static void sx_flush_chars(struct tty_struct * tty) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_flush_chars")) + struct specialix_board * bp = port_Board(port); + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_flush_chars")) { + func_exit(); return; - + } if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || - !port->xmit_buf) + !port->xmit_buf) { + func_exit(); return; - - save_flags(flags); cli(); + } + spin_lock_irqsave(&bp->lock, flags); port->IER |= IER_TXRDY; sx_out(port_Board(port), CD186x_CAR, port_No(port)); sx_out(port_Board(port), CD186x_IER, port->IER); - restore_flags(flags); + spin_unlock_irqrestore(&bp->lock, flags); + + func_exit(); } @@ -1607,13 +1788,19 @@ static int sx_write_room(struct tty_struct * tty) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; int ret; - - if (sx_paranoia_check(port, tty->name, "sx_write_room")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_write_room")) { + func_exit(); return 0; + } ret = SERIAL_XMIT_SIZE - port->xmit_cnt - 1; if (ret < 0) ret = 0; + + func_exit(); return ret; } @@ -1621,10 +1808,14 @@ static int sx_write_room(struct tty_struct * tty) static int sx_chars_in_buffer(struct tty_struct *tty) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; - - if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_chars_in_buffer")) { + func_exit(); return 0; - + } + func_exit(); return port->xmit_cnt; } @@ -1633,16 +1824,22 @@ static void sx_flush_buffer(struct tty_struct *tty) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_flush_buffer")) + struct specialix_board * bp; + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_flush_buffer")) { + func_exit(); return; + } - save_flags(flags); cli(); + bp = port_Board(port); + spin_lock_irqsave(&port->lock, flags); port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; - restore_flags(flags); - + spin_unlock_irqrestore(&port->lock, flags); tty_wakeup(tty); - wake_up_interruptible(&tty->write_wait); + + func_exit(); } @@ -1654,33 +1851,37 @@ static int sx_tiocmget(struct tty_struct *tty, struct file *file) unsigned int result; unsigned long flags; - if (sx_paranoia_check(port, tty->name, __FUNCTION__)) + func_enter(); + + if (sx_paranoia_check(port, tty->name, __FUNCTION__)) { + func_exit(); return -ENODEV; + } bp = port_Board(port); - save_flags(flags); cli(); + spin_lock_irqsave (&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); status = sx_in(bp, CD186x_MSVR); - restore_flags(flags); -#ifdef DEBUG_SPECIALIX - printk (KERN_DEBUG "Got msvr[%d] = %02x, car = %d.\n", + spin_unlock_irqrestore(&bp->lock, flags); + dprintk (SX_DEBUG_INIT, "Got msvr[%d] = %02x, car = %d.\n", port_No(port), status, sx_in (bp, CD186x_CAR)); - printk (KERN_DEBUG "sx_port = %p, port = %p\n", sx_port, port); -#endif + dprintk (SX_DEBUG_INIT, "sx_port = %p, port = %p\n", sx_port, port); if (SX_CRTSCTS(port->tty)) { - result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */ + result = /* (status & MSVR_RTS) ? */ TIOCM_DTR /* : 0) */ | ((status & MSVR_DTR) ? TIOCM_RTS : 0) | ((status & MSVR_CD) ? TIOCM_CAR : 0) |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ | ((status & MSVR_CTS) ? TIOCM_CTS : 0); } else { - result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */ + result = /* (status & MSVR_RTS) ? */ TIOCM_RTS /* : 0) */ | ((status & MSVR_DTR) ? TIOCM_DTR : 0) | ((status & MSVR_CD) ? TIOCM_CAR : 0) |/* ((status & MSVR_DSR) ? */ TIOCM_DSR /* : 0) */ | ((status & MSVR_CTS) ? TIOCM_CTS : 0); } + func_exit(); + return result; } @@ -1692,12 +1893,16 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file, unsigned long flags; struct specialix_board *bp; - if (sx_paranoia_check(port, tty->name, __FUNCTION__)) + func_enter(); + + if (sx_paranoia_check(port, tty->name, __FUNCTION__)) { + func_exit(); return -ENODEV; + } bp = port_Board(port); - save_flags(flags); cli(); + spin_lock_irqsave(&port->lock, flags); /* if (set & TIOCM_RTS) port->MSVR |= MSVR_RTS; */ /* if (set & TIOCM_DTR) @@ -1722,10 +1927,12 @@ static int sx_tiocmset(struct tty_struct *tty, struct file *file, if (clear & TIOCM_DTR) port->MSVR &= ~MSVR_DTR; } - + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); sx_out(bp, CD186x_MSVR, port->MSVR); - restore_flags(flags); + spin_unlock_irqrestore(&bp->lock, flags); + spin_unlock_irqrestore(&port->lock, flags); + func_exit(); return 0; } @@ -1734,18 +1941,26 @@ static inline void sx_send_break(struct specialix_port * port, unsigned long len { struct specialix_board *bp = port_Board(port); unsigned long flags; - - save_flags(flags); cli(); + + func_enter(); + + spin_lock_irqsave (&port->lock, flags); port->break_length = SPECIALIX_TPS / HZ * length; port->COR2 |= COR2_ETC; port->IER |= IER_TXRDY; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); sx_out(bp, CD186x_COR2, port->COR2); sx_out(bp, CD186x_IER, port->IER); + spin_unlock_irqrestore(&bp->lock, flags); + spin_unlock_irqrestore (&port->lock, flags); sx_wait_CCR(bp); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CCR, CCR_CORCHG2); + spin_unlock_irqrestore(&bp->lock, flags); sx_wait_CCR(bp); - restore_flags(flags); + + func_exit(); } @@ -1755,32 +1970,44 @@ static inline int sx_set_serial_info(struct specialix_port * port, struct serial_struct tmp; struct specialix_board *bp = port_Board(port); int change_speed; - unsigned long flags; - - if (copy_from_user(&tmp, newinfo, sizeof(tmp))) + + func_enter(); + /* + if (!access_ok(VERIFY_READ, (void *) newinfo, sizeof(tmp))) { + func_exit(); return -EFAULT; - -#if 0 + } + */ + if (copy_from_user(&tmp, newinfo, sizeof(tmp))) { + func_enter(); + return -EFAULT; + } + +#if 0 if ((tmp.irq != bp->irq) || (tmp.port != bp->base) || (tmp.type != PORT_CIRRUS) || (tmp.baud_base != (SX_OSCFREQ + CD186x_TPC/2) / CD186x_TPC) || (tmp.custom_divisor != 0) || (tmp.xmit_fifo_size != CD186x_NFIFO) || - (tmp.flags & ~SPECIALIX_LEGAL_FLAGS)) + (tmp.flags & ~SPECIALIX_LEGAL_FLAGS)) { + func_exit(); return -EINVAL; -#endif + } +#endif change_speed = ((port->flags & ASYNC_SPD_MASK) != (tmp.flags & ASYNC_SPD_MASK)); change_speed |= (tmp.custom_divisor != port->custom_divisor); - + if (!capable(CAP_SYS_ADMIN)) { if ((tmp.close_delay != port->close_delay) || (tmp.closing_wait != port->closing_wait) || ((tmp.flags & ~ASYNC_USR_MASK) != - (port->flags & ~ASYNC_USR_MASK))) + (port->flags & ~ASYNC_USR_MASK))) { + func_exit(); return -EPERM; + } port->flags = ((port->flags & ~ASYNC_USR_MASK) | (tmp.flags & ASYNC_USR_MASK)); port->custom_divisor = tmp.custom_divisor; @@ -1792,10 +2019,9 @@ static inline int sx_set_serial_info(struct specialix_port * port, port->custom_divisor = tmp.custom_divisor; } if (change_speed) { - save_flags(flags); cli(); sx_change_speed(bp, port); - restore_flags(flags); } + func_exit(); return 0; } @@ -1805,7 +2031,14 @@ static inline int sx_get_serial_info(struct specialix_port * port, { struct serial_struct tmp; struct specialix_board *bp = port_Board(port); - + + func_enter(); + + /* + if (!access_ok(VERIFY_WRITE, (void *) retinfo, sizeof(tmp))) + return -EFAULT; + */ + memset(&tmp, 0, sizeof(tmp)); tmp.type = PORT_CIRRUS; tmp.line = port - sx_port; @@ -1817,56 +2050,79 @@ static inline int sx_get_serial_info(struct specialix_port * port, tmp.closing_wait = port->closing_wait * HZ/100; tmp.custom_divisor = port->custom_divisor; tmp.xmit_fifo_size = CD186x_NFIFO; - if (copy_to_user(retinfo, &tmp, sizeof(tmp))) + if (copy_to_user(retinfo, &tmp, sizeof(tmp))) { + func_exit(); return -EFAULT; + } + + func_exit(); return 0; } -static int sx_ioctl(struct tty_struct * tty, struct file * filp, +static int sx_ioctl(struct tty_struct * tty, struct file * filp, unsigned int cmd, unsigned long arg) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; int retval; void __user *argp = (void __user *)arg; - - if (sx_paranoia_check(port, tty->name, "sx_ioctl")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_ioctl")) { + func_exit(); return -ENODEV; - + } + switch (cmd) { case TCSBRK: /* SVID version: non-zero arg --> no break */ retval = tty_check_change(tty); - if (retval) + if (retval) { + func_exit(); return retval; + } tty_wait_until_sent(tty, 0); if (!arg) sx_send_break(port, HZ/4); /* 1/4 second */ return 0; case TCSBRKP: /* support for POSIX tcsendbreak() */ retval = tty_check_change(tty); - if (retval) + if (retval) { + func_exit(); return retval; + } tty_wait_until_sent(tty, 0); sx_send_break(port, arg ? arg*(HZ/10) : HZ/4); + func_exit(); return 0; case TIOCGSOFTCAR: - if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)argp)) - return -EFAULT; + if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)argp)) { + func_exit(); + return -EFAULT; + } + func_exit(); return 0; case TIOCSSOFTCAR: - if (get_user(arg, (unsigned long __user *) argp)) - return -EFAULT; + if (get_user(arg, (unsigned long __user *) argp)) { + func_exit(); + return -EFAULT; + } tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0)); + func_exit(); return 0; - case TIOCGSERIAL: + case TIOCGSERIAL: + func_exit(); return sx_get_serial_info(port, argp); - case TIOCSSERIAL: + case TIOCSSERIAL: + func_exit(); return sx_set_serial_info(port, argp); default: + func_exit(); return -ENOIOCTLCMD; } + func_exit(); return 0; } @@ -1876,33 +2132,43 @@ static void sx_throttle(struct tty_struct * tty) struct specialix_port *port = (struct specialix_port *)tty->driver_data; struct specialix_board *bp; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_throttle")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_throttle")) { + func_exit(); return; - + } + bp = port_Board(port); - - save_flags(flags); cli(); /* Use DTR instead of RTS ! */ - if (SX_CRTSCTS (tty)) + if (SX_CRTSCTS (tty)) port->MSVR &= ~MSVR_DTR; else { /* Auch!!! I think the system shouldn't call this then. */ /* Or maybe we're supposed (allowed?) to do our side of hw - handshake anyway, even when hardware handshake is off. + handshake anyway, even when hardware handshake is off. When you see this in your logs, please report.... */ printk (KERN_ERR "sx%d: Need to throttle, but can't (hardware hs is off)\n", port_No (port)); } + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); + spin_unlock_irqrestore(&bp->lock, flags); if (I_IXOFF(tty)) { + spin_unlock_irqrestore(&bp->lock, flags); sx_wait_CCR(bp); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CCR, CCR_SSCH2); + spin_unlock_irqrestore(&bp->lock, flags); sx_wait_CCR(bp); } + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_MSVR, port->MSVR); - restore_flags(flags); + spin_unlock_irqrestore(&bp->lock, flags); + + func_exit(); } @@ -1911,26 +2177,39 @@ static void sx_unthrottle(struct tty_struct * tty) struct specialix_port *port = (struct specialix_port *)tty->driver_data; struct specialix_board *bp; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_unthrottle")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_unthrottle")) { + func_exit(); return; - + } + bp = port_Board(port); - - save_flags(flags); cli(); + + spin_lock_irqsave(&port->lock, flags); /* XXXX Use DTR INSTEAD???? */ if (SX_CRTSCTS(tty)) { port->MSVR |= MSVR_DTR; } /* Else clause: see remark in "sx_throttle"... */ - + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); + spin_unlock_irqrestore(&bp->lock, flags); if (I_IXOFF(tty)) { + spin_unlock_irqrestore(&port->lock, flags); sx_wait_CCR(bp); + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CCR, CCR_SSCH1); + spin_unlock_irqrestore(&bp->lock, flags); sx_wait_CCR(bp); + spin_lock_irqsave(&port->lock, flags); } + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_MSVR, port->MSVR); - restore_flags(flags); + spin_unlock_irqrestore(&bp->lock, flags); + spin_unlock_irqrestore(&port->lock, flags); + + func_exit(); } @@ -1939,17 +2218,25 @@ static void sx_stop(struct tty_struct * tty) struct specialix_port *port = (struct specialix_port *)tty->driver_data; struct specialix_board *bp; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_stop")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_stop")) { + func_exit(); return; - + } + bp = port_Board(port); - - save_flags(flags); cli(); + + spin_lock_irqsave(&port->lock, flags); port->IER &= ~IER_TXRDY; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); sx_out(bp, CD186x_IER, port->IER); - restore_flags(flags); + spin_unlock_irqrestore(&bp->lock, flags); + spin_unlock_irqrestore(&port->lock, flags); + + func_exit(); } @@ -1958,19 +2245,27 @@ static void sx_start(struct tty_struct * tty) struct specialix_port *port = (struct specialix_port *)tty->driver_data; struct specialix_board *bp; unsigned long flags; - - if (sx_paranoia_check(port, tty->name, "sx_start")) + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_start")) { + func_exit(); return; - + } + bp = port_Board(port); - - save_flags(flags); cli(); + + spin_lock_irqsave(&port->lock, flags); if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) { port->IER |= IER_TXRDY; + spin_lock_irqsave(&bp->lock, flags); sx_out(bp, CD186x_CAR, port_No(port)); sx_out(bp, CD186x_IER, port->IER); + spin_unlock_irqrestore(&bp->lock, flags); } - restore_flags(flags); + spin_unlock_irqrestore(&port->lock, flags); + + func_exit(); } @@ -1981,16 +2276,20 @@ static void sx_start(struct tty_struct * tty) * * serial interrupt routine -> (workqueue) -> * do_sx_hangup() -> tty->hangup() -> sx_hangup() - * + * */ static void do_sx_hangup(void *private_) { struct specialix_port *port = (struct specialix_port *) private_; struct tty_struct *tty; - + + func_enter(); + tty = port->tty; if (tty) tty_hangup(tty); /* FIXME: module removal race here */ + + func_exit(); } @@ -1998,18 +2297,33 @@ static void sx_hangup(struct tty_struct * tty) { struct specialix_port *port = (struct specialix_port *)tty->driver_data; struct specialix_board *bp; - - if (sx_paranoia_check(port, tty->name, "sx_hangup")) + unsigned long flags; + + func_enter(); + + if (sx_paranoia_check(port, tty->name, "sx_hangup")) { + func_exit(); return; - + } + bp = port_Board(port); - + sx_shutdown_port(bp, port); + spin_lock_irqsave(&port->lock, flags); port->event = 0; + bp->count -= port->count; + if (bp->count < 0) { + printk(KERN_ERR "sx%d: sx_hangup: bad board count: %d port: %d\n", + board_No(bp), bp->count, tty->index); + bp->count = 0; + } port->count = 0; port->flags &= ~ASYNC_NORMAL_ACTIVE; port->tty = NULL; + spin_unlock_irqrestore(&port->lock, flags); wake_up_interruptible(&port->open_wait); + + func_exit(); } @@ -2017,17 +2331,19 @@ static void sx_set_termios(struct tty_struct * tty, struct termios * old_termios { struct specialix_port *port = (struct specialix_port *)tty->driver_data; unsigned long flags; - + struct specialix_board * bp; + if (sx_paranoia_check(port, tty->name, "sx_set_termios")) return; - + if (tty->termios->c_cflag == old_termios->c_cflag && tty->termios->c_iflag == old_termios->c_iflag) return; - save_flags(flags); cli(); + bp = port_Board(port); + spin_lock_irqsave(&port->lock, flags); sx_change_speed(port_Board(port), port); - restore_flags(flags); + spin_unlock_irqrestore(&port->lock, flags); if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) { @@ -2041,12 +2357,20 @@ static void do_softint(void *private_) { struct specialix_port *port = (struct specialix_port *) private_; struct tty_struct *tty; - - if(!(tty = port->tty)) + + func_enter(); + + if(!(tty = port->tty)) { + func_exit(); return; + } + + if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) { + tty_wakeup(tty); + //wake_up_interruptible(&tty->write_wait); + } - if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) - tty_wakeup(tty); + func_exit(); } static struct tty_operations sx_ops = { @@ -2074,15 +2398,19 @@ static int sx_init_drivers(void) int error; int i; + func_enter(); + specialix_driver = alloc_tty_driver(SX_NBOARD * SX_NPORT); if (!specialix_driver) { printk(KERN_ERR "sx: Couldn't allocate tty_driver.\n"); + func_exit(); return 1; } - + if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) { printk(KERN_ERR "sx: Couldn't get free page.\n"); put_tty_driver(specialix_driver); + func_exit(); return 1; } specialix_driver->owner = THIS_MODULE; @@ -2101,6 +2429,7 @@ static int sx_init_drivers(void) free_page((unsigned long)tmp_buf); printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n", error); + func_exit(); return 1; } memset(sx_port, 0, sizeof(sx_port)); @@ -2112,55 +2441,33 @@ static int sx_init_drivers(void) sx_port[i].closing_wait = 3000 * HZ/100; init_waitqueue_head(&sx_port[i].open_wait); init_waitqueue_head(&sx_port[i].close_wait); + spin_lock_init(&sx_port[i].lock); } - + + func_exit(); return 0; } - static void sx_release_drivers(void) { + func_enter(); + free_page((unsigned long)tmp_buf); tty_unregister_driver(specialix_driver); put_tty_driver(specialix_driver); + func_exit(); } - -#ifndef MODULE /* - * Called at boot time. - * - * You can specify IO base for up to SX_NBOARD cards, - * using line "specialix=0xiobase1,0xiobase2,.." at LILO prompt. - * Note that there will be no probing at default - * addresses in this case. - * - */ -void specialix_setup(char *str, int * ints) -{ - int i; - - for (i=0;i