4343#include <linux/ratelimit.h>
4444
4545#include <asm/io.h>
46- #include <linux/uaccess.h>
47-
48- #define MOXA 0x400
49- #define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
50- #define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
51- #define MOXA_GETDATACOUNT (MOXA + 23)
52- #define MOXA_GET_IOQUEUE (MOXA + 27)
53- #define MOXA_FLUSH_QUEUE (MOXA + 28)
54- #define MOXA_GETMSTATUS (MOXA + 65)
5546
5647/*
5748 * System Configuration
@@ -397,19 +388,6 @@ static struct moxa_board_conf {
397388 void __iomem * intTable ;
398389} moxa_boards [MAX_BOARDS ];
399390
400- struct mxser_mstatus {
401- tcflag_t cflag ;
402- int cts ;
403- int dsr ;
404- int ri ;
405- int dcd ;
406- };
407-
408- struct moxaq_str {
409- int inq ;
410- int outq ;
411- };
412-
413391struct moxa_port {
414392 struct tty_port port ;
415393 struct moxa_board_conf * board ;
@@ -424,12 +402,6 @@ struct moxa_port {
424402 u8 lowChkFlag ;
425403};
426404
427- struct mon_str {
428- int tick ;
429- int rxcnt [MAX_PORTS ];
430- int txcnt [MAX_PORTS ];
431- };
432-
433405/* statusflags */
434406#define TXSTOPPED 1
435407#define LOWWAIT 2
@@ -439,14 +411,11 @@ struct mon_str {
439411#define WAKEUP_CHARS 256
440412
441413static int ttymajor = MOXAMAJOR ;
442- static struct mon_str moxaLog ;
443414static unsigned int moxaFuncTout = HZ / 2 ;
444415static unsigned int moxaLowWaterChk ;
445416static DEFINE_MUTEX (moxa_openlock );
446417static DEFINE_SPINLOCK (moxa_lock );
447418
448- static struct tty_port moxa_service_port ;
449-
450419MODULE_AUTHOR ("William Chen" );
451420MODULE_DESCRIPTION ("MOXA Intellio Family Multiport Board Device Driver" );
452421MODULE_LICENSE ("GPL" );
@@ -557,104 +526,6 @@ static void moxa_low_water_check(void __iomem *ofsAddr)
557526 * TTY operations
558527 */
559528
560- static int moxa_ioctl (struct tty_struct * tty ,
561- unsigned int cmd , unsigned long arg )
562- {
563- struct moxa_port * ch = tty -> driver_data ;
564- void __user * argp = (void __user * )arg ;
565- int status , ret = 0 ;
566-
567- if (tty -> index == MAX_PORTS ) {
568- if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE &&
569- cmd != MOXA_GETMSTATUS )
570- return - EINVAL ;
571- } else if (!ch )
572- return - ENODEV ;
573-
574- switch (cmd ) {
575- case MOXA_GETDATACOUNT :
576- moxaLog .tick = jiffies ;
577- if (copy_to_user (argp , & moxaLog , sizeof (moxaLog )))
578- ret = - EFAULT ;
579- break ;
580- case MOXA_FLUSH_QUEUE :
581- MoxaPortFlushData (ch , arg );
582- break ;
583- case MOXA_GET_IOQUEUE : {
584- struct moxaq_str __user * argm = argp ;
585- struct moxaq_str tmp ;
586- struct moxa_port * p ;
587- unsigned int i , j ;
588-
589- for (i = 0 ; i < MAX_BOARDS ; i ++ ) {
590- p = moxa_boards [i ].ports ;
591- for (j = 0 ; j < MAX_PORTS_PER_BOARD ; j ++ , p ++ , argm ++ ) {
592- memset (& tmp , 0 , sizeof (tmp ));
593- spin_lock_bh (& moxa_lock );
594- if (moxa_boards [i ].ready ) {
595- tmp .inq = MoxaPortRxQueue (p );
596- tmp .outq = MoxaPortTxQueue (p );
597- }
598- spin_unlock_bh (& moxa_lock );
599- if (copy_to_user (argm , & tmp , sizeof (tmp )))
600- return - EFAULT ;
601- }
602- }
603- break ;
604- } case MOXA_GET_OQUEUE :
605- status = MoxaPortTxQueue (ch );
606- ret = put_user (status , (unsigned long __user * )argp );
607- break ;
608- case MOXA_GET_IQUEUE :
609- status = MoxaPortRxQueue (ch );
610- ret = put_user (status , (unsigned long __user * )argp );
611- break ;
612- case MOXA_GETMSTATUS : {
613- struct mxser_mstatus __user * argm = argp ;
614- struct mxser_mstatus tmp ;
615- struct moxa_port * p ;
616- unsigned int i , j ;
617-
618- for (i = 0 ; i < MAX_BOARDS ; i ++ ) {
619- p = moxa_boards [i ].ports ;
620- for (j = 0 ; j < MAX_PORTS_PER_BOARD ; j ++ , p ++ , argm ++ ) {
621- struct tty_struct * ttyp ;
622- memset (& tmp , 0 , sizeof (tmp ));
623- spin_lock_bh (& moxa_lock );
624- if (!moxa_boards [i ].ready ) {
625- spin_unlock_bh (& moxa_lock );
626- goto copy ;
627- }
628-
629- status = MoxaPortLineStatus (p );
630- spin_unlock_bh (& moxa_lock );
631-
632- if (status & 1 )
633- tmp .cts = 1 ;
634- if (status & 2 )
635- tmp .dsr = 1 ;
636- if (status & 4 )
637- tmp .dcd = 1 ;
638-
639- ttyp = tty_port_tty_get (& p -> port );
640- if (!ttyp )
641- tmp .cflag = p -> cflag ;
642- else
643- tmp .cflag = ttyp -> termios .c_cflag ;
644- tty_kref_put (ttyp );
645- copy :
646- if (copy_to_user (argm , & tmp , sizeof (tmp )))
647- return - EFAULT ;
648- }
649- }
650- break ;
651- }
652- default :
653- ret = - ENOIOCTLCMD ;
654- }
655- return ret ;
656- }
657-
658529static int moxa_break_ctl (struct tty_struct * tty , int state )
659530{
660531 struct moxa_port * port = tty -> driver_data ;
@@ -671,7 +542,6 @@ static const struct tty_operations moxa_ops = {
671542 .write_room = moxa_write_room ,
672543 .flush_buffer = moxa_flush_buffer ,
673544 .chars_in_buffer = moxa_chars_in_buffer ,
674- .ioctl = moxa_ioctl ,
675545 .set_termios = moxa_set_termios ,
676546 .stop = moxa_stop ,
677547 .start = moxa_start ,
@@ -1283,9 +1153,7 @@ static int __init moxa_init(void)
12831153{
12841154 int retval = 0 ;
12851155
1286- tty_port_init (& moxa_service_port );
1287-
1288- moxaDriver = tty_alloc_driver (MAX_PORTS + 1 ,
1156+ moxaDriver = tty_alloc_driver (MAX_PORTS ,
12891157 TTY_DRIVER_REAL_RAW |
12901158 TTY_DRIVER_DYNAMIC_DEV );
12911159 if (IS_ERR (moxaDriver ))
@@ -1301,8 +1169,6 @@ static int __init moxa_init(void)
13011169 moxaDriver -> init_termios .c_ispeed = 9600 ;
13021170 moxaDriver -> init_termios .c_ospeed = 9600 ;
13031171 tty_set_operations (moxaDriver , & moxa_ops );
1304- /* Having one more port only for ioctls is ugly */
1305- tty_port_link_device (& moxa_service_port , moxaDriver , MAX_PORTS );
13061172
13071173 if (tty_register_driver (moxaDriver )) {
13081174 printk (KERN_ERR "can't register MOXA Smartio tty driver!\n" );
@@ -1362,9 +1228,6 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
13621228 int port ;
13631229
13641230 port = tty -> index ;
1365- if (port == MAX_PORTS ) {
1366- return capable (CAP_SYS_ADMIN ) ? 0 : - EPERM ;
1367- }
13681231 if (mutex_lock_interruptible (& moxa_openlock ))
13691232 return - ERESTARTSYS ;
13701233 brd = & moxa_boards [port / MAX_PORTS_PER_BOARD ];
@@ -2087,7 +1950,6 @@ static ssize_t MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer,
20871950 c = (head > tail ) ? (head - tail - 1 ) : (head - tail + tx_mask );
20881951 if (c > len )
20891952 c = len ;
2090- moxaLog .txcnt [port -> port .tty -> index ] += c ;
20911953 total = c ;
20921954 if (spage == epage ) {
20931955 bufhead = readw (ofsAddr + Ofs_txb );
@@ -2129,7 +1991,6 @@ static ssize_t MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer,
21291991
21301992static int MoxaPortReadData (struct moxa_port * port )
21311993{
2132- struct tty_struct * tty = port -> port .tty ;
21331994 void __iomem * baseAddr , * ofsAddr , * ofs ;
21341995 u8 * dst ;
21351996 unsigned int count , len , total ;
@@ -2148,7 +2009,6 @@ static int MoxaPortReadData(struct moxa_port *port)
21482009 return 0 ;
21492010
21502011 total = count ;
2151- moxaLog .rxcnt [tty -> index ] += total ;
21522012 if (spage == epage ) {
21532013 bufhead = readw (ofsAddr + Ofs_rxb );
21542014 writew (spage , baseAddr + Control_reg );
@@ -2236,8 +2096,6 @@ static int moxa_get_serial_info(struct tty_struct *tty,
22362096{
22372097 struct moxa_port * info = tty -> driver_data ;
22382098
2239- if (tty -> index == MAX_PORTS )
2240- return - EINVAL ;
22412099 if (!info )
22422100 return - ENODEV ;
22432101 mutex_lock (& info -> port .mutex );
@@ -2257,8 +2115,6 @@ static int moxa_set_serial_info(struct tty_struct *tty,
22572115 struct moxa_port * info = tty -> driver_data ;
22582116 unsigned int close_delay ;
22592117
2260- if (tty -> index == MAX_PORTS )
2261- return - EINVAL ;
22622118 if (!info )
22632119 return - ENODEV ;
22642120
0 commit comments