aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/moxa.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/moxa.c')
-rw-r--r--drivers/char/moxa.c398
1 files changed, 210 insertions, 188 deletions
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 2899beafeb0f..0c34bc5b04e1 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -102,19 +102,35 @@ static struct moxa_isa_board_conf moxa_isa_boards[] =
102/* {MOXA_BOARD_C218_ISA,8,0xDC000}, */ 102/* {MOXA_BOARD_C218_ISA,8,0xDC000}, */
103}; 103};
104 104
105struct moxa_board_conf { 105static struct moxa_board_conf {
106 int boardType; 106 int boardType;
107 int numPorts; 107 int numPorts;
108 unsigned long baseAddr; 108 unsigned long baseAddr;
109 int busType; 109 int busType;
110 struct pci_dev *pdev; 110 struct pci_dev *pdev;
111
112 int loadstat;
113
114 void __iomem *basemem;
115 void __iomem *intNdx;
116 void __iomem *intPend;
117 void __iomem *intTable;
118} moxa_boards[MAX_BOARDS];
119
120struct mxser_mstatus {
121 tcflag_t cflag;
122 int cts;
123 int dsr;
124 int ri;
125 int dcd;
111}; 126};
112 127
113static struct moxa_board_conf moxa_boards[MAX_BOARDS]; 128struct moxaq_str {
114static void __iomem *moxaBaseAddr[MAX_BOARDS]; 129 int inq;
115static int loadstat[MAX_BOARDS]; 130 int outq;
131};
116 132
117struct moxa_str { 133struct moxa_port {
118 int type; 134 int type;
119 int port; 135 int port;
120 int close_delay; 136 int close_delay;
@@ -128,17 +144,20 @@ struct moxa_str {
128 int cflag; 144 int cflag;
129 wait_queue_head_t open_wait; 145 wait_queue_head_t open_wait;
130 wait_queue_head_t close_wait; 146 wait_queue_head_t close_wait;
131};
132 147
133struct mxser_mstatus { 148 struct timer_list emptyTimer;
134 tcflag_t cflag; 149 struct mxser_mstatus GMStatus;
135 int cts; 150 struct moxaq_str temp_queue;
136 int dsr;
137 int ri;
138 int dcd;
139};
140 151
141static struct mxser_mstatus GMStatus[MAX_PORTS]; 152 char chkPort;
153 char lineCtrl;
154 void __iomem *tableAddr;
155 long curBaud;
156 char DCDState;
157 char lowChkFlag;
158
159 ushort breakCnt;
160};
142 161
143/* statusflags */ 162/* statusflags */
144#define TXSTOPPED 0x1 163#define TXSTOPPED 0x1
@@ -194,11 +213,11 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
194static void moxa_poll(unsigned long); 213static void moxa_poll(unsigned long);
195static void set_tty_param(struct tty_struct *); 214static void set_tty_param(struct tty_struct *);
196static int block_till_ready(struct tty_struct *, struct file *, 215static int block_till_ready(struct tty_struct *, struct file *,
197 struct moxa_str *); 216 struct moxa_port *);
198static void setup_empty_event(struct tty_struct *); 217static void setup_empty_event(struct tty_struct *);
199static void check_xmit_empty(unsigned long); 218static void check_xmit_empty(unsigned long);
200static void shut_down(struct moxa_str *); 219static void shut_down(struct moxa_port *);
201static void receive_data(struct moxa_str *); 220static void receive_data(struct moxa_port *);
202/* 221/*
203 * moxa board interface functions: 222 * moxa board interface functions:
204 */ 223 */
@@ -228,8 +247,8 @@ static void MoxaPortTxDisable(int);
228static void MoxaPortTxEnable(int); 247static void MoxaPortTxEnable(int);
229static int MoxaPortResetBrkCnt(int); 248static int MoxaPortResetBrkCnt(int);
230static void MoxaPortSendBreak(int, int); 249static void MoxaPortSendBreak(int, int);
231static int moxa_get_serial_info(struct moxa_str *, struct serial_struct __user *); 250static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
232static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *); 251static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
233static void MoxaSetFifo(int port, int enable); 252static void MoxaSetFifo(int port, int enable);
234 253
235static const struct tty_operations moxa_ops = { 254static const struct tty_operations moxa_ops = {
@@ -253,9 +272,8 @@ static const struct tty_operations moxa_ops = {
253}; 272};
254 273
255static struct tty_driver *moxaDriver; 274static struct tty_driver *moxaDriver;
256static struct moxa_str moxaChannels[MAX_PORTS]; 275static struct moxa_port moxa_ports[MAX_PORTS];
257static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0); 276static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
258static struct timer_list moxaEmptyTimer[MAX_PORTS];
259static DEFINE_SPINLOCK(moxa_lock); 277static DEFINE_SPINLOCK(moxa_lock);
260 278
261#ifdef CONFIG_PCI 279#ifdef CONFIG_PCI
@@ -288,7 +306,7 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type,
288static int __init moxa_init(void) 306static int __init moxa_init(void)
289{ 307{
290 int i, numBoards; 308 int i, numBoards;
291 struct moxa_str *ch; 309 struct moxa_port *ch;
292 310
293 printk(KERN_INFO "MOXA Intellio family driver version %s\n", MOXA_VERSION); 311 printk(KERN_INFO "MOXA Intellio family driver version %s\n", MOXA_VERSION);
294 moxaDriver = alloc_tty_driver(MAX_PORTS + 1); 312 moxaDriver = alloc_tty_driver(MAX_PORTS + 1);
@@ -308,7 +326,7 @@ static int __init moxa_init(void)
308 moxaDriver->flags = TTY_DRIVER_REAL_RAW; 326 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
309 tty_set_operations(moxaDriver, &moxa_ops); 327 tty_set_operations(moxaDriver, &moxa_ops);
310 328
311 for (i = 0, ch = moxaChannels; i < MAX_PORTS; i++, ch++) { 329 for (i = 0, ch = moxa_ports; i < MAX_PORTS; i++, ch++) {
312 ch->type = PORT_16550A; 330 ch->type = PORT_16550A;
313 ch->port = i; 331 ch->port = i;
314 ch->close_delay = 5 * HZ / 10; 332 ch->close_delay = 5 * HZ / 10;
@@ -316,6 +334,9 @@ static int __init moxa_init(void)
316 ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 334 ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
317 init_waitqueue_head(&ch->open_wait); 335 init_waitqueue_head(&ch->open_wait);
318 init_waitqueue_head(&ch->close_wait); 336 init_waitqueue_head(&ch->close_wait);
337
338 setup_timer(&ch->emptyTimer, check_xmit_empty,
339 (unsigned long)ch);
319 } 340 }
320 341
321 printk("Tty devices major number = %d\n", ttymajor); 342 printk("Tty devices major number = %d\n", ttymajor);
@@ -325,9 +346,6 @@ static int __init moxa_init(void)
325 put_tty_driver(moxaDriver); 346 put_tty_driver(moxaDriver);
326 return -1; 347 return -1;
327 } 348 }
328 for (i = 0; i < MAX_PORTS; i++)
329 setup_timer(&moxaEmptyTimer[i], check_xmit_empty,
330 (unsigned long)&moxaChannels[i]);
331 349
332 mod_timer(&moxaTimer, jiffies + HZ / 50); 350 mod_timer(&moxaTimer, jiffies + HZ / 50);
333 351
@@ -402,7 +420,8 @@ static int __init moxa_init(void)
402 } 420 }
403#endif 421#endif
404 for (i = 0; i < numBoards; i++) { 422 for (i = 0; i < numBoards; i++) {
405 moxaBaseAddr[i] = ioremap((unsigned long) moxa_boards[i].baseAddr, 0x4000); 423 moxa_boards[i].basemem = ioremap(moxa_boards[i].baseAddr,
424 0x4000);
406 } 425 }
407 426
408 return (0); 427 return (0);
@@ -418,15 +437,15 @@ static void __exit moxa_exit(void)
418 del_timer_sync(&moxaTimer); 437 del_timer_sync(&moxaTimer);
419 438
420 for (i = 0; i < MAX_PORTS; i++) 439 for (i = 0; i < MAX_PORTS; i++)
421 del_timer_sync(&moxaEmptyTimer[i]); 440 del_timer_sync(&moxa_ports[i].emptyTimer);
422 441
423 if (tty_unregister_driver(moxaDriver)) 442 if (tty_unregister_driver(moxaDriver))
424 printk("Couldn't unregister MOXA Intellio family serial driver\n"); 443 printk("Couldn't unregister MOXA Intellio family serial driver\n");
425 put_tty_driver(moxaDriver); 444 put_tty_driver(moxaDriver);
426 445
427 for (i = 0; i < MAX_BOARDS; i++) { 446 for (i = 0; i < MAX_BOARDS; i++) {
428 if (moxaBaseAddr[i]) 447 if (moxa_boards[i].basemem)
429 iounmap(moxaBaseAddr[i]); 448 iounmap(moxa_boards[i].basemem);
430 if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI) 449 if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI)
431 pci_dev_put(moxa_boards[i].pdev); 450 pci_dev_put(moxa_boards[i].pdev);
432 } 451 }
@@ -440,7 +459,7 @@ module_exit(moxa_exit);
440 459
441static int moxa_open(struct tty_struct *tty, struct file *filp) 460static int moxa_open(struct tty_struct *tty, struct file *filp)
442{ 461{
443 struct moxa_str *ch; 462 struct moxa_port *ch;
444 int port; 463 int port;
445 int retval; 464 int retval;
446 465
@@ -453,7 +472,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
453 return (-ENODEV); 472 return (-ENODEV);
454 } 473 }
455 474
456 ch = &moxaChannels[port]; 475 ch = &moxa_ports[port];
457 ch->count++; 476 ch->count++;
458 tty->driver_data = ch; 477 tty->driver_data = ch;
459 ch->tty = tty; 478 ch->tty = tty;
@@ -479,7 +498,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
479 498
480static void moxa_close(struct tty_struct *tty, struct file *filp) 499static void moxa_close(struct tty_struct *tty, struct file *filp)
481{ 500{
482 struct moxa_str *ch; 501 struct moxa_port *ch;
483 int port; 502 int port;
484 503
485 port = tty->index; 504 port = tty->index;
@@ -499,7 +518,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
499 if (tty_hung_up_p(filp)) { 518 if (tty_hung_up_p(filp)) {
500 return; 519 return;
501 } 520 }
502 ch = (struct moxa_str *) tty->driver_data; 521 ch = (struct moxa_port *) tty->driver_data;
503 522
504 if ((tty->count == 1) && (ch->count != 1)) { 523 if ((tty->count == 1) && (ch->count != 1)) {
505 printk("moxa_close: bad serial port count; tty->count is 1, " 524 printk("moxa_close: bad serial port count; tty->count is 1, "
@@ -520,7 +539,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
520 if (ch->asyncflags & ASYNC_INITIALIZED) { 539 if (ch->asyncflags & ASYNC_INITIALIZED) {
521 setup_empty_event(tty); 540 setup_empty_event(tty);
522 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ 541 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
523 del_timer_sync(&moxaEmptyTimer[ch->port]); 542 del_timer_sync(&moxa_ports[ch->port].emptyTimer);
524 } 543 }
525 shut_down(ch); 544 shut_down(ch);
526 MoxaPortFlushData(port, 2); 545 MoxaPortFlushData(port, 2);
@@ -545,11 +564,11 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
545static int moxa_write(struct tty_struct *tty, 564static int moxa_write(struct tty_struct *tty,
546 const unsigned char *buf, int count) 565 const unsigned char *buf, int count)
547{ 566{
548 struct moxa_str *ch; 567 struct moxa_port *ch;
549 int len, port; 568 int len, port;
550 unsigned long flags; 569 unsigned long flags;
551 570
552 ch = (struct moxa_str *) tty->driver_data; 571 ch = (struct moxa_port *) tty->driver_data;
553 if (ch == NULL) 572 if (ch == NULL)
554 return (0); 573 return (0);
555 port = ch->port; 574 port = ch->port;
@@ -568,11 +587,11 @@ static int moxa_write(struct tty_struct *tty,
568 587
569static int moxa_write_room(struct tty_struct *tty) 588static int moxa_write_room(struct tty_struct *tty)
570{ 589{
571 struct moxa_str *ch; 590 struct moxa_port *ch;
572 591
573 if (tty->stopped) 592 if (tty->stopped)
574 return (0); 593 return (0);
575 ch = (struct moxa_str *) tty->driver_data; 594 ch = (struct moxa_port *) tty->driver_data;
576 if (ch == NULL) 595 if (ch == NULL)
577 return (0); 596 return (0);
578 return (MoxaPortTxFree(ch->port)); 597 return (MoxaPortTxFree(ch->port));
@@ -580,7 +599,7 @@ static int moxa_write_room(struct tty_struct *tty)
580 599
581static void moxa_flush_buffer(struct tty_struct *tty) 600static void moxa_flush_buffer(struct tty_struct *tty)
582{ 601{
583 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 602 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
584 603
585 if (ch == NULL) 604 if (ch == NULL)
586 return; 605 return;
@@ -591,7 +610,7 @@ static void moxa_flush_buffer(struct tty_struct *tty)
591static int moxa_chars_in_buffer(struct tty_struct *tty) 610static int moxa_chars_in_buffer(struct tty_struct *tty)
592{ 611{
593 int chars; 612 int chars;
594 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 613 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
595 614
596 /* 615 /*
597 * Sigh...I have to check if driver_data is NULL here, because 616 * Sigh...I have to check if driver_data is NULL here, because
@@ -623,11 +642,11 @@ static void moxa_flush_chars(struct tty_struct *tty)
623 642
624static void moxa_put_char(struct tty_struct *tty, unsigned char c) 643static void moxa_put_char(struct tty_struct *tty, unsigned char c)
625{ 644{
626 struct moxa_str *ch; 645 struct moxa_port *ch;
627 int port; 646 int port;
628 unsigned long flags; 647 unsigned long flags;
629 648
630 ch = (struct moxa_str *) tty->driver_data; 649 ch = (struct moxa_port *) tty->driver_data;
631 if (ch == NULL) 650 if (ch == NULL)
632 return; 651 return;
633 port = ch->port; 652 port = ch->port;
@@ -642,7 +661,7 @@ static void moxa_put_char(struct tty_struct *tty, unsigned char c)
642 661
643static int moxa_tiocmget(struct tty_struct *tty, struct file *file) 662static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
644{ 663{
645 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 664 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
646 int port; 665 int port;
647 int flag = 0, dtr, rts; 666 int flag = 0, dtr, rts;
648 667
@@ -668,7 +687,7 @@ static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
668static int moxa_tiocmset(struct tty_struct *tty, struct file *file, 687static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
669 unsigned int set, unsigned int clear) 688 unsigned int set, unsigned int clear)
670{ 689{
671 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 690 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
672 int port; 691 int port;
673 int dtr, rts; 692 int dtr, rts;
674 693
@@ -692,7 +711,7 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
692static int moxa_ioctl(struct tty_struct *tty, struct file *file, 711static int moxa_ioctl(struct tty_struct *tty, struct file *file,
693 unsigned int cmd, unsigned long arg) 712 unsigned int cmd, unsigned long arg)
694{ 713{
695 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 714 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
696 register int port; 715 register int port;
697 void __user *argp = (void __user *)arg; 716 void __user *argp = (void __user *)arg;
698 int retval; 717 int retval;
@@ -745,14 +764,14 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
745 764
746static void moxa_throttle(struct tty_struct *tty) 765static void moxa_throttle(struct tty_struct *tty)
747{ 766{
748 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 767 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
749 768
750 ch->statusflags |= THROTTLE; 769 ch->statusflags |= THROTTLE;
751} 770}
752 771
753static void moxa_unthrottle(struct tty_struct *tty) 772static void moxa_unthrottle(struct tty_struct *tty)
754{ 773{
755 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 774 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
756 775
757 ch->statusflags &= ~THROTTLE; 776 ch->statusflags &= ~THROTTLE;
758} 777}
@@ -760,7 +779,7 @@ static void moxa_unthrottle(struct tty_struct *tty)
760static void moxa_set_termios(struct tty_struct *tty, 779static void moxa_set_termios(struct tty_struct *tty,
761 struct ktermios *old_termios) 780 struct ktermios *old_termios)
762{ 781{
763 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 782 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
764 783
765 if (ch == NULL) 784 if (ch == NULL)
766 return; 785 return;
@@ -772,7 +791,7 @@ static void moxa_set_termios(struct tty_struct *tty,
772 791
773static void moxa_stop(struct tty_struct *tty) 792static void moxa_stop(struct tty_struct *tty)
774{ 793{
775 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 794 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
776 795
777 if (ch == NULL) 796 if (ch == NULL)
778 return; 797 return;
@@ -783,7 +802,7 @@ static void moxa_stop(struct tty_struct *tty)
783 802
784static void moxa_start(struct tty_struct *tty) 803static void moxa_start(struct tty_struct *tty)
785{ 804{
786 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 805 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
787 806
788 if (ch == NULL) 807 if (ch == NULL)
789 return; 808 return;
@@ -797,7 +816,7 @@ static void moxa_start(struct tty_struct *tty)
797 816
798static void moxa_hangup(struct tty_struct *tty) 817static void moxa_hangup(struct tty_struct *tty)
799{ 818{
800 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 819 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
801 820
802 moxa_flush_buffer(tty); 821 moxa_flush_buffer(tty);
803 shut_down(ch); 822 shut_down(ch);
@@ -811,7 +830,7 @@ static void moxa_hangup(struct tty_struct *tty)
811static void moxa_poll(unsigned long ignored) 830static void moxa_poll(unsigned long ignored)
812{ 831{
813 register int card; 832 register int card;
814 struct moxa_str *ch; 833 struct moxa_port *ch;
815 struct tty_struct *tp; 834 struct tty_struct *tp;
816 int i, ports; 835 int i, ports;
817 836
@@ -824,7 +843,7 @@ static void moxa_poll(unsigned long ignored)
824 for (card = 0; card < MAX_BOARDS; card++) { 843 for (card = 0; card < MAX_BOARDS; card++) {
825 if ((ports = MoxaPortsOfCard(card)) <= 0) 844 if ((ports = MoxaPortsOfCard(card)) <= 0)
826 continue; 845 continue;
827 ch = &moxaChannels[card * MAX_PORTS_PER_BOARD]; 846 ch = &moxa_ports[card * MAX_PORTS_PER_BOARD];
828 for (i = 0; i < ports; i++, ch++) { 847 for (i = 0; i < ports; i++, ch++) {
829 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) 848 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0)
830 continue; 849 continue;
@@ -867,10 +886,10 @@ static void moxa_poll(unsigned long ignored)
867static void set_tty_param(struct tty_struct *tty) 886static void set_tty_param(struct tty_struct *tty)
868{ 887{
869 register struct ktermios *ts; 888 register struct ktermios *ts;
870 struct moxa_str *ch; 889 struct moxa_port *ch;
871 int rts, cts, txflow, rxflow, xany; 890 int rts, cts, txflow, rxflow, xany;
872 891
873 ch = (struct moxa_str *) tty->driver_data; 892 ch = (struct moxa_port *) tty->driver_data;
874 ts = tty->termios; 893 ts = tty->termios;
875 if (ts->c_cflag & CLOCAL) 894 if (ts->c_cflag & CLOCAL)
876 ch->asyncflags &= ~ASYNC_CHECK_CD; 895 ch->asyncflags &= ~ASYNC_CHECK_CD;
@@ -890,7 +909,7 @@ static void set_tty_param(struct tty_struct *tty)
890} 909}
891 910
892static int block_till_ready(struct tty_struct *tty, struct file *filp, 911static int block_till_ready(struct tty_struct *tty, struct file *filp,
893 struct moxa_str *ch) 912 struct moxa_port *ch)
894{ 913{
895 DECLARE_WAITQUEUE(wait,current); 914 DECLARE_WAITQUEUE(wait,current);
896 unsigned long flags; 915 unsigned long flags;
@@ -981,33 +1000,33 @@ static int block_till_ready(struct tty_struct *tty, struct file *filp,
981 1000
982static void setup_empty_event(struct tty_struct *tty) 1001static void setup_empty_event(struct tty_struct *tty)
983{ 1002{
984 struct moxa_str *ch = tty->driver_data; 1003 struct moxa_port *ch = tty->driver_data;
985 unsigned long flags; 1004 unsigned long flags;
986 1005
987 spin_lock_irqsave(&moxa_lock, flags); 1006 spin_lock_irqsave(&moxa_lock, flags);
988 ch->statusflags |= EMPTYWAIT; 1007 ch->statusflags |= EMPTYWAIT;
989 mod_timer(&moxaEmptyTimer[ch->port], jiffies + HZ); 1008 mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
990 spin_unlock_irqrestore(&moxa_lock, flags); 1009 spin_unlock_irqrestore(&moxa_lock, flags);
991} 1010}
992 1011
993static void check_xmit_empty(unsigned long data) 1012static void check_xmit_empty(unsigned long data)
994{ 1013{
995 struct moxa_str *ch; 1014 struct moxa_port *ch;
996 1015
997 ch = (struct moxa_str *) data; 1016 ch = (struct moxa_port *) data;
998 del_timer_sync(&moxaEmptyTimer[ch->port]); 1017 del_timer_sync(&moxa_ports[ch->port].emptyTimer);
999 if (ch->tty && (ch->statusflags & EMPTYWAIT)) { 1018 if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
1000 if (MoxaPortTxQueue(ch->port) == 0) { 1019 if (MoxaPortTxQueue(ch->port) == 0) {
1001 ch->statusflags &= ~EMPTYWAIT; 1020 ch->statusflags &= ~EMPTYWAIT;
1002 tty_wakeup(ch->tty); 1021 tty_wakeup(ch->tty);
1003 return; 1022 return;
1004 } 1023 }
1005 mod_timer(&moxaEmptyTimer[ch->port], jiffies + HZ); 1024 mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
1006 } else 1025 } else
1007 ch->statusflags &= ~EMPTYWAIT; 1026 ch->statusflags &= ~EMPTYWAIT;
1008} 1027}
1009 1028
1010static void shut_down(struct moxa_str *ch) 1029static void shut_down(struct moxa_port *ch)
1011{ 1030{
1012 struct tty_struct *tp; 1031 struct tty_struct *tp;
1013 1032
@@ -1027,7 +1046,7 @@ static void shut_down(struct moxa_str *ch)
1027 ch->asyncflags &= ~ASYNC_INITIALIZED; 1046 ch->asyncflags &= ~ASYNC_INITIALIZED;
1028} 1047}
1029 1048
1030static void receive_data(struct moxa_str *ch) 1049static void receive_data(struct moxa_port *ch)
1031{ 1050{
1032 struct tty_struct *tp; 1051 struct tty_struct *tp;
1033 struct ktermios *ts; 1052 struct ktermios *ts;
@@ -1355,20 +1374,10 @@ struct mon_str {
1355#define DCD_oldstate 0x80 1374#define DCD_oldstate 0x80
1356 1375
1357static unsigned char moxaBuff[10240]; 1376static unsigned char moxaBuff[10240];
1358static void __iomem *moxaIntNdx[MAX_BOARDS];
1359static void __iomem *moxaIntPend[MAX_BOARDS];
1360static void __iomem *moxaIntTable[MAX_BOARDS];
1361static char moxaChkPort[MAX_PORTS];
1362static char moxaLineCtrl[MAX_PORTS];
1363static void __iomem *moxaTableAddr[MAX_PORTS];
1364static long moxaCurBaud[MAX_PORTS];
1365static char moxaDCDState[MAX_PORTS];
1366static char moxaLowChkFlag[MAX_PORTS];
1367static int moxaLowWaterChk; 1377static int moxaLowWaterChk;
1368static int moxaCard; 1378static int moxaCard;
1369static struct mon_str moxaLog; 1379static struct mon_str moxaLog;
1370static int moxaFuncTout = HZ / 2; 1380static int moxaFuncTout = HZ / 2;
1371static ushort moxaBreakCnt[MAX_PORTS];
1372 1381
1373static void moxadelay(int); 1382static void moxadelay(int);
1374static void moxafunc(void __iomem *, int, ushort); 1383static void moxafunc(void __iomem *, int, ushort);
@@ -1389,16 +1398,18 @@ static int moxaloadc320(int, void __iomem *, int, int *);
1389 *****************************************************************************/ 1398 *****************************************************************************/
1390void MoxaDriverInit(void) 1399void MoxaDriverInit(void)
1391{ 1400{
1392 int i; 1401 struct moxa_port *p;
1402 unsigned int i;
1393 1403
1394 moxaFuncTout = HZ / 2; /* 500 mini-seconds */ 1404 moxaFuncTout = HZ / 2; /* 500 mini-seconds */
1395 moxaCard = 0; 1405 moxaCard = 0;
1396 moxaLog.tick = 0; 1406 moxaLog.tick = 0;
1397 moxaLowWaterChk = 0; 1407 moxaLowWaterChk = 0;
1398 for (i = 0; i < MAX_PORTS; i++) { 1408 for (i = 0; i < MAX_PORTS; i++) {
1399 moxaChkPort[i] = 0; 1409 p = &moxa_ports[i];
1400 moxaLowChkFlag[i] = 0; 1410 p->chkPort = 0;
1401 moxaLineCtrl[i] = 0; 1411 p->lowChkFlag = 0;
1412 p->lineCtrl = 0;
1402 moxaLog.rxcnt[i] = 0; 1413 moxaLog.rxcnt[i] = 0;
1403 moxaLog.txcnt[i] = 0; 1414 moxaLog.txcnt[i] = 0;
1404 } 1415 }
@@ -1420,19 +1431,12 @@ void MoxaDriverInit(void)
1420#define MOXA_GET_CUMAJOR (MOXA + 64) 1431#define MOXA_GET_CUMAJOR (MOXA + 64)
1421#define MOXA_GETMSTATUS (MOXA + 65) 1432#define MOXA_GETMSTATUS (MOXA + 65)
1422 1433
1423
1424struct moxaq_str {
1425 int inq;
1426 int outq;
1427};
1428
1429struct dl_str { 1434struct dl_str {
1430 char __user *buf; 1435 char __user *buf;
1431 int len; 1436 int len;
1432 int cardno; 1437 int cardno;
1433}; 1438};
1434 1439
1435static struct moxaq_str temp_queue[MAX_PORTS];
1436static struct dl_str dltmp; 1440static struct dl_str dltmp;
1437 1441
1438void MoxaPortFlushData(int port, int mode) 1442void MoxaPortFlushData(int port, int mode)
@@ -1440,10 +1444,10 @@ void MoxaPortFlushData(int port, int mode)
1440 void __iomem *ofsAddr; 1444 void __iomem *ofsAddr;
1441 if ((mode < 0) || (mode > 2)) 1445 if ((mode < 0) || (mode > 2))
1442 return; 1446 return;
1443 ofsAddr = moxaTableAddr[port]; 1447 ofsAddr = moxa_ports[port].tableAddr;
1444 moxafunc(ofsAddr, FC_FlushQueue, mode); 1448 moxafunc(ofsAddr, FC_FlushQueue, mode);
1445 if (mode != 1) { 1449 if (mode != 1) {
1446 moxaLowChkFlag[port] = 0; 1450 moxa_ports[port].lowChkFlag = 0;
1447 low_water_check(ofsAddr); 1451 low_water_check(ofsAddr);
1448 } 1452 }
1449} 1453}
@@ -1481,17 +1485,23 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1481 case MOXA_FLUSH_QUEUE: 1485 case MOXA_FLUSH_QUEUE:
1482 MoxaPortFlushData(port, arg); 1486 MoxaPortFlushData(port, arg);
1483 return (0); 1487 return (0);
1484 case MOXA_GET_IOQUEUE: 1488 case MOXA_GET_IOQUEUE: {
1485 for (i = 0; i < MAX_PORTS; i++) { 1489 struct moxaq_str __user *argm = argp;
1486 if (moxaChkPort[i]) { 1490 struct moxa_port *p;
1487 temp_queue[i].inq = MoxaPortRxQueue(i); 1491
1488 temp_queue[i].outq = MoxaPortTxQueue(i); 1492 for (i = 0; i < MAX_PORTS; i++, argm++) {
1493 p = &moxa_ports[i];
1494 memset(&p->temp_queue, 0, sizeof(p->temp_queue));
1495 if (p->chkPort) {
1496 p->temp_queue.inq = MoxaPortRxQueue(i);
1497 p->temp_queue.outq = MoxaPortTxQueue(i);
1489 } 1498 }
1499 if (copy_to_user(argm, &p->temp_queue,
1500 sizeof(p->temp_queue)))
1501 return -EFAULT;
1490 } 1502 }
1491 if(copy_to_user(argp, temp_queue, sizeof(struct moxaq_str) * MAX_PORTS))
1492 return -EFAULT;
1493 return (0); 1503 return (0);
1494 case MOXA_GET_OQUEUE: 1504 } case MOXA_GET_OQUEUE:
1495 i = MoxaPortTxQueue(port); 1505 i = MoxaPortTxQueue(port);
1496 return put_user(i, (unsigned long __user *)argp); 1506 return put_user(i, (unsigned long __user *)argp);
1497 case MOXA_GET_IQUEUE: 1507 case MOXA_GET_IQUEUE:
@@ -1506,33 +1516,39 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1506 if(copy_to_user(argp, &i, sizeof(int))) 1516 if(copy_to_user(argp, &i, sizeof(int)))
1507 return -EFAULT; 1517 return -EFAULT;
1508 return 0; 1518 return 0;
1509 case MOXA_GETMSTATUS: 1519 case MOXA_GETMSTATUS: {
1510 for (i = 0; i < MAX_PORTS; i++) { 1520 struct mxser_mstatus __user *argm = argp;
1511 GMStatus[i].ri = 0; 1521 struct moxa_port *p;
1512 GMStatus[i].dcd = 0; 1522
1513 GMStatus[i].dsr = 0; 1523 for (i = 0; i < MAX_PORTS; i++, argm++) {
1514 GMStatus[i].cts = 0; 1524 p = &moxa_ports[i];
1515 if (!moxaChkPort[i]) { 1525 p->GMStatus.ri = 0;
1516 continue; 1526 p->GMStatus.dcd = 0;
1527 p->GMStatus.dsr = 0;
1528 p->GMStatus.cts = 0;
1529 if (!p->chkPort) {
1530 goto copy;
1517 } else { 1531 } else {
1518 status = MoxaPortLineStatus(moxaChannels[i].port); 1532 status = MoxaPortLineStatus(p->port);
1519 if (status & 1) 1533 if (status & 1)
1520 GMStatus[i].cts = 1; 1534 p->GMStatus.cts = 1;
1521 if (status & 2) 1535 if (status & 2)
1522 GMStatus[i].dsr = 1; 1536 p->GMStatus.dsr = 1;
1523 if (status & 4) 1537 if (status & 4)
1524 GMStatus[i].dcd = 1; 1538 p->GMStatus.dcd = 1;
1525 } 1539 }
1526 1540
1527 if (!moxaChannels[i].tty || !moxaChannels[i].tty->termios) 1541 if (!p->tty || !p->tty->termios)
1528 GMStatus[i].cflag = moxaChannels[i].cflag; 1542 p->GMStatus.cflag = p->cflag;
1529 else 1543 else
1530 GMStatus[i].cflag = moxaChannels[i].tty->termios->c_cflag; 1544 p->GMStatus.cflag = p->tty->termios->c_cflag;
1545copy:
1546 if (copy_to_user(argm, &p->GMStatus,
1547 sizeof(p->GMStatus)))
1548 return -EFAULT;
1531 } 1549 }
1532 if(copy_to_user(argp, GMStatus, sizeof(struct mxser_mstatus) * MAX_PORTS))
1533 return -EFAULT;
1534 return 0; 1550 return 0;
1535 default: 1551 } default:
1536 return (-ENOIOCTLCMD); 1552 return (-ENOIOCTLCMD);
1537 case MOXA_LOAD_BIOS: 1553 case MOXA_LOAD_BIOS:
1538 case MOXA_FIND_BOARD: 1554 case MOXA_FIND_BOARD:
@@ -1570,6 +1586,7 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1570 1586
1571int MoxaDriverPoll(void) 1587int MoxaDriverPoll(void)
1572{ 1588{
1589 struct moxa_board_conf *brd;
1573 register ushort temp; 1590 register ushort temp;
1574 register int card; 1591 register int card;
1575 void __iomem *ofsAddr; 1592 void __iomem *ofsAddr;
@@ -1579,43 +1596,44 @@ int MoxaDriverPoll(void)
1579 if (moxaCard == 0) 1596 if (moxaCard == 0)
1580 return (-1); 1597 return (-1);
1581 for (card = 0; card < MAX_BOARDS; card++) { 1598 for (card = 0; card < MAX_BOARDS; card++) {
1582 if (loadstat[card] == 0) 1599 brd = &moxa_boards[card];
1600 if (brd->loadstat == 0)
1583 continue; 1601 continue;
1584 if ((ports = moxa_boards[card].numPorts) == 0) 1602 if ((ports = brd->numPorts) == 0)
1585 continue; 1603 continue;
1586 if (readb(moxaIntPend[card]) == 0xff) { 1604 if (readb(brd->intPend) == 0xff) {
1587 ip = moxaIntTable[card] + readb(moxaIntNdx[card]); 1605 ip = brd->intTable + readb(brd->intNdx);
1588 p = card * MAX_PORTS_PER_BOARD; 1606 p = card * MAX_PORTS_PER_BOARD;
1589 ports <<= 1; 1607 ports <<= 1;
1590 for (port = 0; port < ports; port += 2, p++) { 1608 for (port = 0; port < ports; port += 2, p++) {
1591 if ((temp = readw(ip + port)) != 0) { 1609 if ((temp = readw(ip + port)) != 0) {
1592 writew(0, ip + port); 1610 writew(0, ip + port);
1593 ofsAddr = moxaTableAddr[p]; 1611 ofsAddr = moxa_ports[p].tableAddr;
1594 if (temp & IntrTx) 1612 if (temp & IntrTx)
1595 writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat); 1613 writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat);
1596 if (temp & IntrBreak) { 1614 if (temp & IntrBreak) {
1597 moxaBreakCnt[p]++; 1615 moxa_ports[p].breakCnt++;
1598 } 1616 }
1599 if (temp & IntrLine) { 1617 if (temp & IntrLine) {
1600 if (readb(ofsAddr + FlagStat) & DCD_state) { 1618 if (readb(ofsAddr + FlagStat) & DCD_state) {
1601 if ((moxaDCDState[p] & DCD_oldstate) == 0) 1619 if ((moxa_ports[p].DCDState & DCD_oldstate) == 0)
1602 moxaDCDState[p] = (DCD_oldstate | 1620 moxa_ports[p].DCDState = (DCD_oldstate |
1603 DCD_changed); 1621 DCD_changed);
1604 } else { 1622 } else {
1605 if (moxaDCDState[p] & DCD_oldstate) 1623 if (moxa_ports[p].DCDState & DCD_oldstate)
1606 moxaDCDState[p] = DCD_changed; 1624 moxa_ports[p].DCDState = DCD_changed;
1607 } 1625 }
1608 } 1626 }
1609 } 1627 }
1610 } 1628 }
1611 writeb(0, moxaIntPend[card]); 1629 writeb(0, brd->intPend);
1612 } 1630 }
1613 if (moxaLowWaterChk) { 1631 if (moxaLowWaterChk) {
1614 p = card * MAX_PORTS_PER_BOARD; 1632 p = card * MAX_PORTS_PER_BOARD;
1615 for (port = 0; port < ports; port++, p++) { 1633 for (port = 0; port < ports; port++, p++) {
1616 if (moxaLowChkFlag[p]) { 1634 if (moxa_ports[p].lowChkFlag) {
1617 moxaLowChkFlag[p] = 0; 1635 moxa_ports[p].lowChkFlag = 0;
1618 ofsAddr = moxaTableAddr[p]; 1636 ofsAddr = moxa_ports[p].tableAddr;
1619 low_water_check(ofsAddr); 1637 low_water_check(ofsAddr);
1620 } 1638 }
1621 } 1639 }
@@ -1921,7 +1939,7 @@ int MoxaPortIsValid(int port)
1921 1939
1922 if (moxaCard == 0) 1940 if (moxaCard == 0)
1923 return (0); 1941 return (0);
1924 if (moxaChkPort[port] == 0) 1942 if (moxa_ports[port].chkPort == 0)
1925 return (0); 1943 return (0);
1926 return (1); 1944 return (1);
1927} 1945}
@@ -1932,9 +1950,9 @@ void MoxaPortEnable(int port)
1932 int MoxaPortLineStatus(int); 1950 int MoxaPortLineStatus(int);
1933 short lowwater = 512; 1951 short lowwater = 512;
1934 1952
1935 ofsAddr = moxaTableAddr[port]; 1953 ofsAddr = moxa_ports[port].tableAddr;
1936 writew(lowwater, ofsAddr + Low_water); 1954 writew(lowwater, ofsAddr + Low_water);
1937 moxaBreakCnt[port] = 0; 1955 moxa_ports[port].breakCnt = 0;
1938 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 1956 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
1939 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { 1957 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
1940 moxafunc(ofsAddr, FC_SetBreakIrq, 0); 1958 moxafunc(ofsAddr, FC_SetBreakIrq, 0);
@@ -1951,7 +1969,7 @@ void MoxaPortEnable(int port)
1951 1969
1952void MoxaPortDisable(int port) 1970void MoxaPortDisable(int port)
1953{ 1971{
1954 void __iomem *ofsAddr = moxaTableAddr[port]; 1972 void __iomem *ofsAddr = moxa_ports[port].tableAddr;
1955 1973
1956 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ 1974 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */
1957 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); 1975 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code);
@@ -1977,7 +1995,7 @@ long MoxaPortSetBaud(int port, long baud)
1977 1995
1978 if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0)) 1996 if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0))
1979 return (0); 1997 return (0);
1980 ofsAddr = moxaTableAddr[port]; 1998 ofsAddr = moxa_ports[port].tableAddr;
1981 if (baud > max) 1999 if (baud > max)
1982 baud = max; 2000 baud = max;
1983 if (max == 38400L) 2001 if (max == 38400L)
@@ -1989,7 +2007,7 @@ long MoxaPortSetBaud(int port, long baud)
1989 val = clock / baud; 2007 val = clock / baud;
1990 moxafunc(ofsAddr, FC_SetBaud, val); 2008 moxafunc(ofsAddr, FC_SetBaud, val);
1991 baud = clock / val; 2009 baud = clock / val;
1992 moxaCurBaud[port] = baud; 2010 moxa_ports[port].curBaud = baud;
1993 return (baud); 2011 return (baud);
1994} 2012}
1995 2013
@@ -1999,9 +2017,9 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
1999 tcflag_t cflag; 2017 tcflag_t cflag;
2000 tcflag_t mode = 0; 2018 tcflag_t mode = 0;
2001 2019
2002 if (moxaChkPort[port] == 0 || termio == 0) 2020 if (moxa_ports[port].chkPort == 0 || termio == 0)
2003 return (-1); 2021 return (-1);
2004 ofsAddr = moxaTableAddr[port]; 2022 ofsAddr = moxa_ports[port].tableAddr;
2005 cflag = termio->c_cflag; /* termio->c_cflag */ 2023 cflag = termio->c_cflag; /* termio->c_cflag */
2006 2024
2007 mode = termio->c_cflag & CSIZE; 2025 mode = termio->c_cflag & CSIZE;
@@ -2055,13 +2073,13 @@ int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState)
2055 if (!MoxaPortIsValid(port)) 2073 if (!MoxaPortIsValid(port))
2056 return (-1); 2074 return (-1);
2057 if (dtrState) { 2075 if (dtrState) {
2058 if (moxaLineCtrl[port] & DTR_ON) 2076 if (moxa_ports[port].lineCtrl & DTR_ON)
2059 *dtrState = 1; 2077 *dtrState = 1;
2060 else 2078 else
2061 *dtrState = 0; 2079 *dtrState = 0;
2062 } 2080 }
2063 if (rtsState) { 2081 if (rtsState) {
2064 if (moxaLineCtrl[port] & RTS_ON) 2082 if (moxa_ports[port].lineCtrl & RTS_ON)
2065 *rtsState = 1; 2083 *rtsState = 1;
2066 else 2084 else
2067 *rtsState = 0; 2085 *rtsState = 0;
@@ -2074,13 +2092,13 @@ void MoxaPortLineCtrl(int port, int dtr, int rts)
2074 void __iomem *ofsAddr; 2092 void __iomem *ofsAddr;
2075 int mode; 2093 int mode;
2076 2094
2077 ofsAddr = moxaTableAddr[port]; 2095 ofsAddr = moxa_ports[port].tableAddr;
2078 mode = 0; 2096 mode = 0;
2079 if (dtr) 2097 if (dtr)
2080 mode |= DTR_ON; 2098 mode |= DTR_ON;
2081 if (rts) 2099 if (rts)
2082 mode |= RTS_ON; 2100 mode |= RTS_ON;
2083 moxaLineCtrl[port] = mode; 2101 moxa_ports[port].lineCtrl = mode;
2084 moxafunc(ofsAddr, FC_LineControl, mode); 2102 moxafunc(ofsAddr, FC_LineControl, mode);
2085} 2103}
2086 2104
@@ -2089,7 +2107,7 @@ void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int tx
2089 void __iomem *ofsAddr; 2107 void __iomem *ofsAddr;
2090 int mode; 2108 int mode;
2091 2109
2092 ofsAddr = moxaTableAddr[port]; 2110 ofsAddr = moxa_ports[port].tableAddr;
2093 mode = 0; 2111 mode = 0;
2094 if (rts) 2112 if (rts)
2095 mode |= RTS_FlowCtl; 2113 mode |= RTS_FlowCtl;
@@ -2109,7 +2127,7 @@ int MoxaPortLineStatus(int port)
2109 void __iomem *ofsAddr; 2127 void __iomem *ofsAddr;
2110 int val; 2128 int val;
2111 2129
2112 ofsAddr = moxaTableAddr[port]; 2130 ofsAddr = moxa_ports[port].tableAddr;
2113 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 2131 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2114 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { 2132 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2115 moxafunc(ofsAddr, FC_LineStatus, 0); 2133 moxafunc(ofsAddr, FC_LineStatus, 0);
@@ -2120,11 +2138,11 @@ int MoxaPortLineStatus(int port)
2120 val &= 0x0B; 2138 val &= 0x0B;
2121 if (val & 8) { 2139 if (val & 8) {
2122 val |= 4; 2140 val |= 4;
2123 if ((moxaDCDState[port] & DCD_oldstate) == 0) 2141 if ((moxa_ports[port].DCDState & DCD_oldstate) == 0)
2124 moxaDCDState[port] = (DCD_oldstate | DCD_changed); 2142 moxa_ports[port].DCDState = (DCD_oldstate | DCD_changed);
2125 } else { 2143 } else {
2126 if (moxaDCDState[port] & DCD_oldstate) 2144 if (moxa_ports[port].DCDState & DCD_oldstate)
2127 moxaDCDState[port] = DCD_changed; 2145 moxa_ports[port].DCDState = DCD_changed;
2128 } 2146 }
2129 val &= 7; 2147 val &= 7;
2130 return (val); 2148 return (val);
@@ -2134,10 +2152,10 @@ int MoxaPortDCDChange(int port)
2134{ 2152{
2135 int n; 2153 int n;
2136 2154
2137 if (moxaChkPort[port] == 0) 2155 if (moxa_ports[port].chkPort == 0)
2138 return (0); 2156 return (0);
2139 n = moxaDCDState[port]; 2157 n = moxa_ports[port].DCDState;
2140 moxaDCDState[port] &= ~DCD_changed; 2158 moxa_ports[port].DCDState &= ~DCD_changed;
2141 n &= DCD_changed; 2159 n &= DCD_changed;
2142 return (n); 2160 return (n);
2143} 2161}
@@ -2146,9 +2164,9 @@ int MoxaPortDCDON(int port)
2146{ 2164{
2147 int n; 2165 int n;
2148 2166
2149 if (moxaChkPort[port] == 0) 2167 if (moxa_ports[port].chkPort == 0)
2150 return (0); 2168 return (0);
2151 if (moxaDCDState[port] & DCD_oldstate) 2169 if (moxa_ports[port].DCDState & DCD_oldstate)
2152 n = 1; 2170 n = 1;
2153 else 2171 else
2154 n = 0; 2172 n = 0;
@@ -2164,8 +2182,8 @@ int MoxaPortWriteData(int port, unsigned char * buffer, int len)
2164 ushort pageno, pageofs, bufhead; 2182 ushort pageno, pageofs, bufhead;
2165 void __iomem *baseAddr, *ofsAddr, *ofs; 2183 void __iomem *baseAddr, *ofsAddr, *ofs;
2166 2184
2167 ofsAddr = moxaTableAddr[port]; 2185 ofsAddr = moxa_ports[port].tableAddr;
2168 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; 2186 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem;
2169 tx_mask = readw(ofsAddr + TX_mask); 2187 tx_mask = readw(ofsAddr + TX_mask);
2170 spage = readw(ofsAddr + Page_txb); 2188 spage = readw(ofsAddr + Page_txb);
2171 epage = readw(ofsAddr + EndPage_txb); 2189 epage = readw(ofsAddr + EndPage_txb);
@@ -2227,8 +2245,8 @@ int MoxaPortReadData(int port, struct tty_struct *tty)
2227 ushort pageno, bufhead; 2245 ushort pageno, bufhead;
2228 void __iomem *baseAddr, *ofsAddr, *ofs; 2246 void __iomem *baseAddr, *ofsAddr, *ofs;
2229 2247
2230 ofsAddr = moxaTableAddr[port]; 2248 ofsAddr = moxa_ports[port].tableAddr;
2231 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; 2249 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem;
2232 head = readw(ofsAddr + RXrptr); 2250 head = readw(ofsAddr + RXrptr);
2233 tail = readw(ofsAddr + RXwptr); 2251 tail = readw(ofsAddr + RXwptr);
2234 rx_mask = readw(ofsAddr + RX_mask); 2252 rx_mask = readw(ofsAddr + RX_mask);
@@ -2283,7 +2301,7 @@ int MoxaPortReadData(int port, struct tty_struct *tty)
2283 } 2301 }
2284 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { 2302 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) {
2285 moxaLowWaterChk = 1; 2303 moxaLowWaterChk = 1;
2286 moxaLowChkFlag[port] = 1; 2304 moxa_ports[port].lowChkFlag = 1;
2287 } 2305 }
2288 return (total); 2306 return (total);
2289} 2307}
@@ -2295,7 +2313,7 @@ int MoxaPortTxQueue(int port)
2295 ushort rptr, wptr, mask; 2313 ushort rptr, wptr, mask;
2296 int len; 2314 int len;
2297 2315
2298 ofsAddr = moxaTableAddr[port]; 2316 ofsAddr = moxa_ports[port].tableAddr;
2299 rptr = readw(ofsAddr + TXrptr); 2317 rptr = readw(ofsAddr + TXrptr);
2300 wptr = readw(ofsAddr + TXwptr); 2318 wptr = readw(ofsAddr + TXwptr);
2301 mask = readw(ofsAddr + TX_mask); 2319 mask = readw(ofsAddr + TX_mask);
@@ -2309,7 +2327,7 @@ int MoxaPortTxFree(int port)
2309 ushort rptr, wptr, mask; 2327 ushort rptr, wptr, mask;
2310 int len; 2328 int len;
2311 2329
2312 ofsAddr = moxaTableAddr[port]; 2330 ofsAddr = moxa_ports[port].tableAddr;
2313 rptr = readw(ofsAddr + TXrptr); 2331 rptr = readw(ofsAddr + TXrptr);
2314 wptr = readw(ofsAddr + TXwptr); 2332 wptr = readw(ofsAddr + TXwptr);
2315 mask = readw(ofsAddr + TX_mask); 2333 mask = readw(ofsAddr + TX_mask);
@@ -2323,7 +2341,7 @@ int MoxaPortRxQueue(int port)
2323 ushort rptr, wptr, mask; 2341 ushort rptr, wptr, mask;
2324 int len; 2342 int len;
2325 2343
2326 ofsAddr = moxaTableAddr[port]; 2344 ofsAddr = moxa_ports[port].tableAddr;
2327 rptr = readw(ofsAddr + RXrptr); 2345 rptr = readw(ofsAddr + RXrptr);
2328 wptr = readw(ofsAddr + RXwptr); 2346 wptr = readw(ofsAddr + RXwptr);
2329 mask = readw(ofsAddr + RX_mask); 2347 mask = readw(ofsAddr + RX_mask);
@@ -2336,7 +2354,7 @@ void MoxaPortTxDisable(int port)
2336{ 2354{
2337 void __iomem *ofsAddr; 2355 void __iomem *ofsAddr;
2338 2356
2339 ofsAddr = moxaTableAddr[port]; 2357 ofsAddr = moxa_ports[port].tableAddr;
2340 moxafunc(ofsAddr, FC_SetXoffState, Magic_code); 2358 moxafunc(ofsAddr, FC_SetXoffState, Magic_code);
2341} 2359}
2342 2360
@@ -2344,7 +2362,7 @@ void MoxaPortTxEnable(int port)
2344{ 2362{
2345 void __iomem *ofsAddr; 2363 void __iomem *ofsAddr;
2346 2364
2347 ofsAddr = moxaTableAddr[port]; 2365 ofsAddr = moxa_ports[port].tableAddr;
2348 moxafunc(ofsAddr, FC_SetXonState, Magic_code); 2366 moxafunc(ofsAddr, FC_SetXonState, Magic_code);
2349} 2367}
2350 2368
@@ -2352,8 +2370,8 @@ void MoxaPortTxEnable(int port)
2352int MoxaPortResetBrkCnt(int port) 2370int MoxaPortResetBrkCnt(int port)
2353{ 2371{
2354 ushort cnt; 2372 ushort cnt;
2355 cnt = moxaBreakCnt[port]; 2373 cnt = moxa_ports[port].breakCnt;
2356 moxaBreakCnt[port] = 0; 2374 moxa_ports[port].breakCnt = 0;
2357 return (cnt); 2375 return (cnt);
2358} 2376}
2359 2377
@@ -2362,7 +2380,7 @@ void MoxaPortSendBreak(int port, int ms100)
2362{ 2380{
2363 void __iomem *ofsAddr; 2381 void __iomem *ofsAddr;
2364 2382
2365 ofsAddr = moxaTableAddr[port]; 2383 ofsAddr = moxa_ports[port].tableAddr;
2366 if (ms100) { 2384 if (ms100) {
2367 moxafunc(ofsAddr, FC_SendBreak, Magic_code); 2385 moxafunc(ofsAddr, FC_SendBreak, Magic_code);
2368 moxadelay(ms100 * (HZ / 10)); 2386 moxadelay(ms100 * (HZ / 10));
@@ -2373,7 +2391,7 @@ void MoxaPortSendBreak(int port, int ms100)
2373 moxafunc(ofsAddr, FC_StopBreak, Magic_code); 2391 moxafunc(ofsAddr, FC_StopBreak, Magic_code);
2374} 2392}
2375 2393
2376static int moxa_get_serial_info(struct moxa_str *info, 2394static int moxa_get_serial_info(struct moxa_port *info,
2377 struct serial_struct __user *retinfo) 2395 struct serial_struct __user *retinfo)
2378{ 2396{
2379 struct serial_struct tmp; 2397 struct serial_struct tmp;
@@ -2395,7 +2413,7 @@ static int moxa_get_serial_info(struct moxa_str *info,
2395} 2413}
2396 2414
2397 2415
2398static int moxa_set_serial_info(struct moxa_str *info, 2416static int moxa_set_serial_info(struct moxa_port *info,
2399 struct serial_struct __user *new_info) 2417 struct serial_struct __user *new_info)
2400{ 2418{
2401 struct serial_struct new_serial; 2419 struct serial_struct new_serial;
@@ -2492,7 +2510,7 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
2492 2510
2493 if(copy_from_user(moxaBuff, tmp, len)) 2511 if(copy_from_user(moxaBuff, tmp, len))
2494 return -EFAULT; 2512 return -EFAULT;
2495 baseAddr = moxaBaseAddr[cardno]; 2513 baseAddr = moxa_boards[cardno].basemem;
2496 writeb(HW_reset, baseAddr + Control_reg); /* reset */ 2514 writeb(HW_reset, baseAddr + Control_reg); /* reset */
2497 moxadelay(1); /* delay 10 ms */ 2515 moxadelay(1); /* delay 10 ms */
2498 for (i = 0; i < 4096; i++) 2516 for (i = 0; i < 4096; i++)
@@ -2508,7 +2526,7 @@ static int moxafindcard(int cardno)
2508 void __iomem *baseAddr; 2526 void __iomem *baseAddr;
2509 ushort tmp; 2527 ushort tmp;
2510 2528
2511 baseAddr = moxaBaseAddr[cardno]; 2529 baseAddr = moxa_boards[cardno].basemem;
2512 switch (moxa_boards[cardno].boardType) { 2530 switch (moxa_boards[cardno].boardType) {
2513 case MOXA_BOARD_C218_ISA: 2531 case MOXA_BOARD_C218_ISA:
2514 case MOXA_BOARD_C218_PCI: 2532 case MOXA_BOARD_C218_PCI:
@@ -2541,7 +2559,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
2541 return -EINVAL; 2559 return -EINVAL;
2542 if(copy_from_user(moxaBuff, tmp, len)) 2560 if(copy_from_user(moxaBuff, tmp, len))
2543 return -EFAULT; 2561 return -EFAULT;
2544 baseAddr = moxaBaseAddr[cardno]; 2562 baseAddr = moxa_boards[cardno].basemem;
2545 writew(len - 7168 - 2, baseAddr + C320bapi_len); 2563 writew(len - 7168 - 2, baseAddr + C320bapi_len);
2546 writeb(1, baseAddr + Control_reg); /* Select Page 1 */ 2564 writeb(1, baseAddr + Control_reg); /* Select Page 1 */
2547 for (i = 0; i < 7168; i++) 2565 for (i = 0; i < 7168; i++)
@@ -2559,7 +2577,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2559 2577
2560 if(copy_from_user(moxaBuff, tmp, len)) 2578 if(copy_from_user(moxaBuff, tmp, len))
2561 return -EFAULT; 2579 return -EFAULT;
2562 baseAddr = moxaBaseAddr[cardno]; 2580 baseAddr = moxa_boards[cardno].basemem;
2563 switch (moxa_boards[cardno].boardType) { 2581 switch (moxa_boards[cardno].boardType) {
2564 case MOXA_BOARD_C218_ISA: 2582 case MOXA_BOARD_C218_ISA:
2565 case MOXA_BOARD_C218_PCI: 2583 case MOXA_BOARD_C218_PCI:
@@ -2569,11 +2587,13 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2569 return (retval); 2587 return (retval);
2570 port = cardno * MAX_PORTS_PER_BOARD; 2588 port = cardno * MAX_PORTS_PER_BOARD;
2571 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { 2589 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) {
2572 moxaChkPort[port] = 1; 2590 struct moxa_port *p = &moxa_ports[port];
2573 moxaCurBaud[port] = 9600L; 2591
2574 moxaDCDState[port] = 0; 2592 p->chkPort = 1;
2575 moxaTableAddr[port] = baseAddr + Extern_table + Extern_size * i; 2593 p->curBaud = 9600L;
2576 ofsAddr = moxaTableAddr[port]; 2594 p->DCDState = 0;
2595 p->tableAddr = baseAddr + Extern_table + Extern_size * i;
2596 ofsAddr = p->tableAddr;
2577 writew(C218rx_mask, ofsAddr + RX_mask); 2597 writew(C218rx_mask, ofsAddr + RX_mask);
2578 writew(C218tx_mask, ofsAddr + TX_mask); 2598 writew(C218tx_mask, ofsAddr + TX_mask);
2579 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb); 2599 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
@@ -2591,11 +2611,13 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2591 return (retval); 2611 return (retval);
2592 port = cardno * MAX_PORTS_PER_BOARD; 2612 port = cardno * MAX_PORTS_PER_BOARD;
2593 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { 2613 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) {
2594 moxaChkPort[port] = 1; 2614 struct moxa_port *p = &moxa_ports[port];
2595 moxaCurBaud[port] = 9600L; 2615
2596 moxaDCDState[port] = 0; 2616 p->chkPort = 1;
2597 moxaTableAddr[port] = baseAddr + Extern_table + Extern_size * i; 2617 p->curBaud = 9600L;
2598 ofsAddr = moxaTableAddr[port]; 2618 p->DCDState = 0;
2619 p->tableAddr = baseAddr + Extern_table + Extern_size * i;
2620 ofsAddr = p->tableAddr;
2599 if (moxa_boards[cardno].numPorts == 8) { 2621 if (moxa_boards[cardno].numPorts == 8) {
2600 writew(C320p8rx_mask, ofsAddr + RX_mask); 2622 writew(C320p8rx_mask, ofsAddr + RX_mask);
2601 writew(C320p8tx_mask, ofsAddr + TX_mask); 2623 writew(C320p8tx_mask, ofsAddr + TX_mask);
@@ -2631,7 +2653,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2631 } 2653 }
2632 break; 2654 break;
2633 } 2655 }
2634 loadstat[cardno] = 1; 2656 moxa_boards[cardno].loadstat = 1;
2635 return (0); 2657 return (0);
2636} 2658}
2637 2659
@@ -2705,9 +2727,9 @@ static int moxaloadc218(int cardno, void __iomem *baseAddr, int len)
2705 return (-1); 2727 return (-1);
2706 } 2728 }
2707 moxaCard = 1; 2729 moxaCard = 1;
2708 moxaIntNdx[cardno] = baseAddr + IRQindex; 2730 moxa_boards[cardno].intNdx = baseAddr + IRQindex;
2709 moxaIntPend[cardno] = baseAddr + IRQpending; 2731 moxa_boards[cardno].intPend = baseAddr + IRQpending;
2710 moxaIntTable[cardno] = baseAddr + IRQtable; 2732 moxa_boards[cardno].intTable = baseAddr + IRQtable;
2711 return (0); 2733 return (0);
2712} 2734}
2713 2735
@@ -2800,15 +2822,15 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor
2800 if (readw(baseAddr + Magic_no) != Magic_code) 2822 if (readw(baseAddr + Magic_no) != Magic_code)
2801 return (-102); 2823 return (-102);
2802 moxaCard = 1; 2824 moxaCard = 1;
2803 moxaIntNdx[cardno] = baseAddr + IRQindex; 2825 moxa_boards[cardno].intNdx = baseAddr + IRQindex;
2804 moxaIntPend[cardno] = baseAddr + IRQpending; 2826 moxa_boards[cardno].intPend = baseAddr + IRQpending;
2805 moxaIntTable[cardno] = baseAddr + IRQtable; 2827 moxa_boards[cardno].intTable = baseAddr + IRQtable;
2806 return (0); 2828 return (0);
2807} 2829}
2808 2830
2809static void MoxaSetFifo(int port, int enable) 2831static void MoxaSetFifo(int port, int enable)
2810{ 2832{
2811 void __iomem *ofsAddr = moxaTableAddr[port]; 2833 void __iomem *ofsAddr = moxa_ports[port].tableAddr;
2812 2834
2813 if (!enable) { 2835 if (!enable) {
2814 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0); 2836 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0);