X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fchar%2Fmoxa.c;h=f391a24a1b442c1e8eb4aaf1c1857d015dfdc89b;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=10ba9bfb5d2c352e33f5c1b1c28ba66da515cb95;hpb=6a77f38946aaee1cd85eeec6cf4229b204c15071;p=linux-2.6.git diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c index 10ba9bfb5..f391a24a1 100644 --- a/drivers/char/moxa.c +++ b/drivers/char/moxa.c @@ -29,7 +29,6 @@ * version : 5.1 */ -#include #include #include #include @@ -131,6 +130,7 @@ static moxa_isa_board_conf moxa_isa_boards[] = typedef struct _moxa_pci_devinfo { ushort busNum; ushort devNum; + struct pci_dev *pdev; } moxa_pci_devinfo; typedef struct _moxa_board_conf { @@ -143,6 +143,7 @@ typedef struct _moxa_board_conf { static moxa_board_conf moxa_boards[MAX_BOARDS]; static void __iomem *moxaBaseAddr[MAX_BOARDS]; +static int loadstat[MAX_BOARDS]; struct moxa_str { int type; @@ -221,7 +222,7 @@ static struct semaphore moxaBuffSem; /* * static functions: */ -static void do_moxa_softint(void *); +static void do_moxa_softint(struct work_struct *); static int moxa_open(struct tty_struct *, struct file *); static void moxa_close(struct tty_struct *, struct file *); static int moxa_write(struct tty_struct *, const unsigned char *, int); @@ -233,7 +234,7 @@ static void moxa_put_char(struct tty_struct *, unsigned char); static int moxa_ioctl(struct tty_struct *, struct file *, unsigned int, unsigned long); static void moxa_throttle(struct tty_struct *); static void moxa_unthrottle(struct tty_struct *); -static void moxa_set_termios(struct tty_struct *, struct termios *); +static void moxa_set_termios(struct tty_struct *, struct ktermios *); static void moxa_stop(struct tty_struct *); static void moxa_start(struct tty_struct *); static void moxa_hangup(struct tty_struct *); @@ -260,7 +261,7 @@ static void MoxaPortEnable(int); static void MoxaPortDisable(int); static long MoxaPortGetMaxBaud(int); static long MoxaPortSetBaud(int, long); -static int MoxaPortSetTermio(int, struct termios *); +static int MoxaPortSetTermio(int, struct ktermios *, speed_t); static int MoxaPortGetLineOut(int, int *, int *); static void MoxaPortLineCtrl(int, int, int); static void MoxaPortFlowCtrl(int, int, int, int, int, int); @@ -269,7 +270,7 @@ static int MoxaPortDCDChange(int); static int MoxaPortDCDON(int); static void MoxaPortFlushData(int, int); static int MoxaPortWriteData(int, unsigned char *, int); -static int MoxaPortReadData(int, unsigned char *, int); +static int MoxaPortReadData(int, struct tty_struct *tty); static int MoxaPortTxQueue(int); static int MoxaPortRxQueue(int); static int MoxaPortTxFree(int); @@ -281,7 +282,7 @@ static int moxa_get_serial_info(struct moxa_str *, struct serial_struct __user * static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *); static void MoxaSetFifo(int port, int enable); -static struct tty_operations moxa_ops = { +static const struct tty_operations moxa_ops = { .open = moxa_open, .close = moxa_close, .write = moxa_write, @@ -301,6 +302,8 @@ static struct tty_operations moxa_ops = { .tiocmset = moxa_tiocmset, }; +static DEFINE_SPINLOCK(moxa_lock); + #ifdef CONFIG_PCI static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf * board) { @@ -322,6 +325,9 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf board->busType = MOXA_BUS_TYPE_PCI; board->pciInfo.busNum = p->bus->number; board->pciInfo.devNum = p->devfn >> 3; + board->pciInfo.pdev = p; + /* don't lose the reference in the next pci_get_device iteration */ + pci_dev_get(p); return (0); } @@ -339,8 +345,7 @@ static int __init moxa_init(void) init_MUTEX(&moxaBuffSem); moxaDriver->owner = THIS_MODULE; - moxaDriver->name = "ttya"; - moxaDriver->devfs_name = "tts/a"; + moxaDriver->name = "ttyMX"; moxaDriver->major = ttymajor; moxaDriver->minor_start = 0; moxaDriver->type = TTY_DRIVER_TYPE_SERIAL; @@ -350,6 +355,8 @@ static int __init moxa_init(void) moxaDriver->init_termios.c_oflag = 0; moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; moxaDriver->init_termios.c_lflag = 0; + moxaDriver->init_termios.c_ispeed = 9600; + moxaDriver->init_termios.c_ospeed = 9600; moxaDriver->flags = TTY_DRIVER_REAL_RAW; tty_set_operations(moxaDriver, &moxa_ops); @@ -358,7 +365,7 @@ static int __init moxa_init(void) for (i = 0, ch = moxaChannels; i < MAX_PORTS; i++, ch++) { ch->type = PORT_16550A; ch->port = i; - INIT_WORK(&ch->tqueue, do_moxa_softint, ch); + INIT_WORK(&ch->tqueue, do_moxa_softint); ch->tty = NULL; ch->close_delay = 5 * HZ / 10; ch->closing_wait = 30 * HZ; @@ -448,10 +455,10 @@ static int __init moxa_init(void) #ifdef CONFIG_PCI { struct pci_dev *p = NULL; - int n = (sizeof(moxa_pcibrds) / sizeof(moxa_pcibrds[0])) - 1; + int n = ARRAY_SIZE(moxa_pcibrds) - 1; i = 0; while (i < n) { - while ((p = pci_find_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) + while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL) { if (pci_enable_device(p)) continue; @@ -492,6 +499,14 @@ static void __exit moxa_exit(void) if (tty_unregister_driver(moxaDriver)) printk("Couldn't unregister MOXA Intellio family serial driver\n"); put_tty_driver(moxaDriver); + + for (i = 0; i < MAX_BOARDS; i++) { + if (moxaBaseAddr[i]) + iounmap(moxaBaseAddr[i]); + if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI) + pci_dev_put(moxa_boards[i].pciInfo.pdev); + } + if (verbose) printk("Done\n"); } @@ -499,9 +514,9 @@ static void __exit moxa_exit(void) module_init(moxa_init); module_exit(moxa_exit); -static void do_moxa_softint(void *private_) +static void do_moxa_softint(struct work_struct *work) { - struct moxa_str *ch = (struct moxa_str *) private_; + struct moxa_str *ch = container_of(work, struct moxa_str, tqueue); struct tty_struct *tty; if (ch && (tty = ch->tty)) { @@ -645,10 +660,10 @@ static int moxa_write(struct tty_struct *tty, if (ch == NULL) return (0); port = ch->port; - save_flags(flags); - cli(); + + spin_lock_irqsave(&moxa_lock, flags); len = MoxaPortWriteData(port, (unsigned char *) buf, count); - restore_flags(flags); + spin_unlock_irqrestore(&moxa_lock, flags); /********************************************* if ( !(ch->statusflags & LOWWAIT) && @@ -723,11 +738,10 @@ static void moxa_put_char(struct tty_struct *tty, unsigned char c) if (ch == NULL) return; port = ch->port; - save_flags(flags); - cli(); + spin_lock_irqsave(&moxa_lock, flags); moxaXmitBuff[0] = c; MoxaPortWriteData(port, moxaXmitBuff, 1); - restore_flags(flags); + spin_unlock_irqrestore(&moxa_lock, flags); /************************************************ if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) ) *************************************************/ @@ -852,7 +866,7 @@ static void moxa_unthrottle(struct tty_struct *tty) } static void moxa_set_termios(struct tty_struct *tty, - struct termios *old_termios) + struct ktermios *old_termios) { struct moxa_str *ch = (struct moxa_str *) tty->driver_data; @@ -966,7 +980,7 @@ static void moxa_poll(unsigned long ignored) static void set_tty_param(struct tty_struct *tty) { - register struct termios *ts; + register struct ktermios *ts; struct moxa_str *ch; int rts, cts, txflow, rxflow, xany; @@ -986,7 +1000,7 @@ static void set_tty_param(struct tty_struct *tty) if (ts->c_iflag & IXANY) xany = 1; MoxaPortFlowCtrl(ch->port, rts, cts, txflow, rxflow, xany); - MoxaPortSetTermio(ch->port, ts); + MoxaPortSetTermio(ch->port, ts, tty_get_baud_rate(tty)); } static int block_till_ready(struct tty_struct *tty, struct file *filp, @@ -1030,12 +1044,12 @@ static int block_till_ready(struct tty_struct *tty, struct file *filp, printk("block_til_ready before block: ttys%d, count = %d\n", ch->line, ch->count); #endif - save_flags(flags); - cli(); + spin_lock_irqsave(&moxa_lock, flags); if (!tty_hung_up_p(filp)) ch->count--; - restore_flags(flags); ch->blocked_open++; + spin_unlock_irqrestore(&moxa_lock, flags); + while (1) { set_current_state(TASK_INTERRUPTIBLE); if (tty_hung_up_p(filp) || @@ -1062,17 +1076,21 @@ static int block_till_ready(struct tty_struct *tty, struct file *filp, } set_current_state(TASK_RUNNING); remove_wait_queue(&ch->open_wait, &wait); + + spin_lock_irqsave(&moxa_lock, flags); if (!tty_hung_up_p(filp)) ch->count++; ch->blocked_open--; + spin_unlock_irqrestore(&moxa_lock, flags); #ifdef SERIAL_DEBUG_OPEN printk("block_til_ready after blocking: ttys%d, count = %d\n", ch->line, ch->count); #endif if (retval) return (retval); + /* FIXME: review to see if we need to use set_bit on these */ ch->asyncflags |= ASYNC_NORMAL_ACTIVE; - return (0); + return 0; } static void setup_empty_event(struct tty_struct *tty) @@ -1080,15 +1098,14 @@ static void setup_empty_event(struct tty_struct *tty) struct moxa_str *ch = tty->driver_data; unsigned long flags; - save_flags(flags); - cli(); + spin_lock_irqsave(&moxa_lock, flags); ch->statusflags |= EMPTYWAIT; moxaEmptyTimer_on[ch->port] = 0; del_timer(&moxaEmptyTimer[ch->port]); moxaEmptyTimer[ch->port].expires = jiffies + HZ; moxaEmptyTimer_on[ch->port] = 1; add_timer(&moxaEmptyTimer[ch->port]); - restore_flags(flags); + spin_unlock_irqrestore(&moxa_lock, flags); } static void check_xmit_empty(unsigned long data) @@ -1134,9 +1151,7 @@ static void shut_down(struct moxa_str *ch) static void receive_data(struct moxa_str *ch) { struct tty_struct *tp; - struct termios *ts; - int i, count, rc, space; - unsigned char *charptr, *flagptr; + struct ktermios *ts; unsigned long flags; ts = NULL; @@ -1150,24 +1165,10 @@ static void receive_data(struct moxa_str *ch) MoxaPortFlushData(ch->port, 0); return; } - space = TTY_FLIPBUF_SIZE - tp->flip.count; - if (space <= 0) - return; - charptr = tp->flip.char_buf_ptr; - flagptr = tp->flip.flag_buf_ptr; - rc = tp->flip.count; - save_flags(flags); - cli(); - count = MoxaPortReadData(ch->port, charptr, space); - restore_flags(flags); - for (i = 0; i < count; i++) - *flagptr++ = 0; - charptr += count; - rc += count; - tp->flip.count = rc; - tp->flip.char_buf_ptr = charptr; - tp->flip.flag_buf_ptr = flagptr; - tty_schedule_flip(ch->tty); + spin_lock_irqsave(&moxa_lock, flags); + MoxaPortReadData(ch->port, tp); + spin_unlock_irqrestore(&moxa_lock, flags); + tty_schedule_flip(tp); } #define Magic_code 0x404 @@ -1661,6 +1662,8 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port) case MOXA_FIND_BOARD: case MOXA_LOAD_C320B: case MOXA_LOAD_CODE: + if (!capable(CAP_SYS_RAWIO)) + return -EPERM; break; } @@ -1700,6 +1703,8 @@ int MoxaDriverPoll(void) if (moxaCard == 0) return (-1); for (card = 0; card < MAX_BOARDS; card++) { + if (loadstat[card] == 0) + continue; if ((ports = moxa_boards[card].numPorts) == 0) continue; if (readb(moxaIntPend[card]) == 0xff) { @@ -1774,7 +1779,7 @@ int MoxaPortsOfCard(int cardno) * 14. MoxaPortDCDON(int port); * * 15. MoxaPortFlushData(int port, int mode); * * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); * - * 17. MoxaPortReadData(int port, unsigned char * buffer, int length); * + * 17. MoxaPortReadData(int port, struct tty_struct *tty); * * 18. MoxaPortTxBufSize(int port); * * 19. MoxaPortRxBufSize(int port); * * 20. MoxaPortTxQueue(int port); * @@ -1909,9 +1914,10 @@ int MoxaPortsOfCard(int cardno) * * Function 12: Configure the port. * Syntax: - * int MoxaPortSetTermio(int port, struct termios *termio); + * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud); * int port : port number (0 - 127) - * struct termios * termio : termio structure pointer + * struct ktermios * termio : termio structure pointer + * speed_t baud : baud rate * * return: -1 : this port is invalid or termio == NULL * 0 : setting O.K. @@ -2003,10 +2009,9 @@ int MoxaPortsOfCard(int cardno) * * Function 21: Read data. * Syntax: - * int MoxaPortReadData(int port, unsigned char * buffer, int length); + * int MoxaPortReadData(int port, struct tty_struct *tty); * int port : port number (0 - 127) - * unsigned char * buffer : pointer to read data buffer. - * int length : read data buffer length + * struct tty_struct *tty : tty for data * * return: 0 - length : real read data length * @@ -2192,11 +2197,10 @@ long MoxaPortSetBaud(int port, long baud) return (baud); } -int MoxaPortSetTermio(int port, struct termios *termio) +int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud) { void __iomem *ofsAddr; tcflag_t cflag; - long baud; tcflag_t mode = 0; if (moxaChkPort[port] == 0 || termio == 0) @@ -2232,77 +2236,9 @@ int MoxaPortSetTermio(int port, struct termios *termio) moxafunc(ofsAddr, FC_SetDataMode, (ushort) mode); - cflag &= (CBAUD | CBAUDEX); -#ifndef B921600 -#define B921600 (B460800+1) -#endif - switch (cflag) { - case B921600: - baud = 921600L; - break; - case B460800: - baud = 460800L; - break; - case B230400: - baud = 230400L; - break; - case B115200: - baud = 115200L; - break; - case B57600: - baud = 57600L; - break; - case B38400: - baud = 38400L; - break; - case B19200: - baud = 19200L; - break; - case B9600: - baud = 9600L; - break; - case B4800: - baud = 4800L; - break; - case B2400: - baud = 2400L; - break; - case B1800: - baud = 1800L; - break; - case B1200: - baud = 1200L; - break; - case B600: - baud = 600L; - break; - case B300: - baud = 300L; - break; - case B200: - baud = 200L; - break; - case B150: - baud = 150L; - break; - case B134: - baud = 134L; - break; - case B110: - baud = 110L; - break; - case B75: - baud = 75L; - break; - case B50: - baud = 50L; - break; - default: - baud = 0; - } if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { - if (baud == 921600L) + if (baud >= 921600L) return (-1); } MoxaPortSetBaud(port, baud); @@ -2504,7 +2440,7 @@ int MoxaPortWriteData(int port, unsigned char * buffer, int len) return (total); } -int MoxaPortReadData(int port, unsigned char * buffer, int space) +int MoxaPortReadData(int port, struct tty_struct *tty) { register ushort head, pageofs; int i, count, cnt, len, total, remain; @@ -2522,9 +2458,9 @@ int MoxaPortReadData(int port, unsigned char * buffer, int space) count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1); if (count == 0) - return (0); + return 0; - total = (space > count) ? count : space; + total = count; remain = count - total; moxaLog.rxcnt[port] += total; count = total; @@ -2539,7 +2475,7 @@ int MoxaPortReadData(int port, unsigned char * buffer, int space) len = (count > len) ? len : count; ofs = baseAddr + DynPage_addr + bufhead + head; for (i = 0; i < len; i++) - *buffer++ = readb(ofs + i); + tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); head = (head + len) & rx_mask; count -= len; } @@ -2556,7 +2492,7 @@ int MoxaPortReadData(int port, unsigned char * buffer, int space) writew(pageno, baseAddr + Control_reg); ofs = baseAddr + DynPage_addr + pageofs; for (i = 0; i < cnt; i++) - *buffer++ = readb(ofs + i); + tty_insert_flip_char(tty, readb(ofs + i), TTY_NORMAL); if (count == 0) { writew((head + len) & rx_mask, ofsAddr + RXrptr); break; @@ -2916,6 +2852,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len) } break; } + loadstat[cardno] = 1; return (0); } @@ -2933,7 +2870,7 @@ static int moxaloadc218(int cardno, void __iomem *baseAddr, int len) len1 = len >> 1; ptr = (ushort *) moxaBuff; for (i = 0; i < len1; i++) - usum += *(ptr + i); + usum += le16_to_cpu(*(ptr + i)); retry = 0; do { len1 = len >> 1; @@ -3005,7 +2942,7 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor wlen = len >> 1; uptr = (ushort *) moxaBuff; for (i = 0; i < wlen; i++) - usum += uptr[i]; + usum += le16_to_cpu(uptr[i]); retry = 0; j = 0; do { @@ -3090,6 +3027,7 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor return (0); } +#if 0 long MoxaPortGetCurBaud(int port) { @@ -3097,6 +3035,7 @@ long MoxaPortGetCurBaud(int port) return (0); return (moxaCurBaud[port]); } +#endif /* 0 */ static void MoxaSetFifo(int port, int enable) {