2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
31 /************************************************************************
33 * This file implements the tty driver functionality for the
34 * Neo and ClassicBoard PCI based product lines.
36 ************************************************************************
40 #include <linux/kernel.h>
41 #include <linux/sched.h> /* For jiffies, task states */
42 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
43 #include <linux/module.h>
44 #include <linux/ctype.h>
45 #include <linux/tty.h>
46 #include <linux/tty_flip.h>
47 #include <linux/serial_reg.h>
48 #include <linux/slab.h>
49 #include <linux/delay.h> /* For udelay */
50 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
51 #include <linux/pci.h>
53 #include "dgnc_driver.h"
55 #include "dgnc_types.h"
58 #include "dpacompat.h"
59 #include "dgnc_sysfs.h"
61 #define init_MUTEX(sem) sema_init(sem, 1)
62 #define DECLARE_MUTEX(name) \
63 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
68 static struct dgnc_board
*dgnc_BoardsByMajor
[256];
69 static uchar
*dgnc_TmpWriteBuf
= NULL
;
70 static DECLARE_MUTEX(dgnc_TmpWriteSem
);
73 * Default transparent print information.
75 static struct digi_t dgnc_digi_init
= {
76 .digi_flags
= DIGI_COOK
, /* Flags */
77 .digi_maxcps
= 100, /* Max CPS */
78 .digi_maxchar
= 50, /* Max chars in print queue */
79 .digi_bufsize
= 100, /* Printer buffer size */
80 .digi_onlen
= 4, /* size of printer on string */
81 .digi_offlen
= 4, /* size of printer off string */
82 .digi_onstr
= "\033[5i", /* ANSI printer on string ] */
83 .digi_offstr
= "\033[4i", /* ANSI printer off string ] */
84 .digi_term
= "ansi" /* default terminal type */
89 * Define a local default termios struct. All ports will be created
90 * with this termios initially.
92 * This defines a raw port at 9600 baud, 8 data bits, no parity,
95 static struct ktermios DgncDefaultTermios
=
97 .c_iflag
= (DEFAULT_IFLAGS
), /* iflags */
98 .c_oflag
= (DEFAULT_OFLAGS
), /* oflags */
99 .c_cflag
= (DEFAULT_CFLAGS
), /* cflags */
100 .c_lflag
= (DEFAULT_LFLAGS
), /* lflags */
106 /* Our function prototypes */
107 static int dgnc_tty_open(struct tty_struct
*tty
, struct file
*file
);
108 static void dgnc_tty_close(struct tty_struct
*tty
, struct file
*file
);
109 static int dgnc_block_til_ready(struct tty_struct
*tty
, struct file
*file
, struct channel_t
*ch
);
110 static int dgnc_tty_ioctl(struct tty_struct
*tty
, unsigned int cmd
, unsigned long arg
);
111 static int dgnc_tty_digigeta(struct tty_struct
*tty
, struct digi_t __user
*retinfo
);
112 static int dgnc_tty_digiseta(struct tty_struct
*tty
, struct digi_t __user
*new_info
);
113 static int dgnc_tty_write_room(struct tty_struct
*tty
);
114 static int dgnc_tty_put_char(struct tty_struct
*tty
, unsigned char c
);
115 static int dgnc_tty_chars_in_buffer(struct tty_struct
*tty
);
116 static void dgnc_tty_start(struct tty_struct
*tty
);
117 static void dgnc_tty_stop(struct tty_struct
*tty
);
118 static void dgnc_tty_throttle(struct tty_struct
*tty
);
119 static void dgnc_tty_unthrottle(struct tty_struct
*tty
);
120 static void dgnc_tty_flush_chars(struct tty_struct
*tty
);
121 static void dgnc_tty_flush_buffer(struct tty_struct
*tty
);
122 static void dgnc_tty_hangup(struct tty_struct
*tty
);
123 static int dgnc_set_modem_info(struct tty_struct
*tty
, unsigned int command
, unsigned int __user
*value
);
124 static int dgnc_get_modem_info(struct channel_t
*ch
, unsigned int __user
*value
);
125 static int dgnc_tty_tiocmget(struct tty_struct
*tty
);
126 static int dgnc_tty_tiocmset(struct tty_struct
*tty
, unsigned int set
, unsigned int clear
);
127 static int dgnc_tty_send_break(struct tty_struct
*tty
, int msec
);
128 static void dgnc_tty_wait_until_sent(struct tty_struct
*tty
, int timeout
);
129 static int dgnc_tty_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
130 static void dgnc_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
);
131 static void dgnc_tty_send_xchar(struct tty_struct
*tty
, char ch
);
134 static const struct tty_operations dgnc_tty_ops
= {
135 .open
= dgnc_tty_open
,
136 .close
= dgnc_tty_close
,
137 .write
= dgnc_tty_write
,
138 .write_room
= dgnc_tty_write_room
,
139 .flush_buffer
= dgnc_tty_flush_buffer
,
140 .chars_in_buffer
= dgnc_tty_chars_in_buffer
,
141 .flush_chars
= dgnc_tty_flush_chars
,
142 .ioctl
= dgnc_tty_ioctl
,
143 .set_termios
= dgnc_tty_set_termios
,
144 .stop
= dgnc_tty_stop
,
145 .start
= dgnc_tty_start
,
146 .throttle
= dgnc_tty_throttle
,
147 .unthrottle
= dgnc_tty_unthrottle
,
148 .hangup
= dgnc_tty_hangup
,
149 .put_char
= dgnc_tty_put_char
,
150 .tiocmget
= dgnc_tty_tiocmget
,
151 .tiocmset
= dgnc_tty_tiocmset
,
152 .break_ctl
= dgnc_tty_send_break
,
153 .wait_until_sent
= dgnc_tty_wait_until_sent
,
154 .send_xchar
= dgnc_tty_send_xchar
157 /************************************************************************
159 * TTY Initialization/Cleanup Functions
161 ************************************************************************/
166 * Initialize any global tty related data before we download any boards.
168 int dgnc_tty_preinit(void)
171 * Allocate a buffer for doing the copy from user space to
172 * kernel space in dgnc_write(). We only use one buffer and
173 * control access to it with a semaphore. If we are paging, we
174 * are already in trouble so one buffer won't hurt much anyway.
176 * We are okay to sleep in the malloc, as this routine
177 * is only called during module load, (not in interrupt context),
178 * and with no locks held.
180 dgnc_TmpWriteBuf
= kmalloc(WRITEBUFLEN
, GFP_KERNEL
);
182 if (!dgnc_TmpWriteBuf
) {
183 DPR_INIT(("unable to allocate tmp write buf"));
192 * dgnc_tty_register()
194 * Init the tty subsystem for this board.
196 int dgnc_tty_register(struct dgnc_board
*brd
)
200 DPR_INIT(("tty_register start\n"));
202 brd
->SerialDriver
.magic
= TTY_DRIVER_MAGIC
;
204 snprintf(brd
->SerialName
, MAXTTYNAMELEN
, "tty_dgnc_%d_", brd
->boardnum
);
206 brd
->SerialDriver
.name
= brd
->SerialName
;
207 brd
->SerialDriver
.name_base
= 0;
208 brd
->SerialDriver
.major
= 0;
209 brd
->SerialDriver
.minor_start
= 0;
210 brd
->SerialDriver
.num
= brd
->maxports
;
211 brd
->SerialDriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
212 brd
->SerialDriver
.subtype
= SERIAL_TYPE_NORMAL
;
213 brd
->SerialDriver
.init_termios
= DgncDefaultTermios
;
214 brd
->SerialDriver
.driver_name
= DRVSTR
;
215 brd
->SerialDriver
.flags
= (TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
| TTY_DRIVER_HARDWARE_BREAK
);
218 * The kernel wants space to store pointers to
219 * tty_struct's and termios's.
221 brd
->SerialDriver
.ttys
= kzalloc(brd
->maxports
* sizeof(*brd
->SerialDriver
.ttys
), GFP_KERNEL
);
222 if (!brd
->SerialDriver
.ttys
)
225 kref_init(&brd
->SerialDriver
.kref
);
226 brd
->SerialDriver
.termios
= kzalloc(brd
->maxports
* sizeof(*brd
->SerialDriver
.termios
), GFP_KERNEL
);
227 if (!brd
->SerialDriver
.termios
)
231 * Entry points for driver. Called by the kernel from
232 * tty_io.c and n_tty.c.
234 tty_set_operations(&brd
->SerialDriver
, &dgnc_tty_ops
);
236 if (!brd
->dgnc_Major_Serial_Registered
) {
237 /* Register tty devices */
238 rc
= tty_register_driver(&brd
->SerialDriver
);
240 APR(("Can't register tty device (%d)\n", rc
));
243 brd
->dgnc_Major_Serial_Registered
= TRUE
;
247 * If we're doing transparent print, we have to do all of the above
248 * again, separately so we don't get the LD confused about what major
249 * we are when we get into the dgnc_tty_open() routine.
251 brd
->PrintDriver
.magic
= TTY_DRIVER_MAGIC
;
252 snprintf(brd
->PrintName
, MAXTTYNAMELEN
, "pr_dgnc_%d_", brd
->boardnum
);
254 brd
->PrintDriver
.name
= brd
->PrintName
;
255 brd
->PrintDriver
.name_base
= 0;
256 brd
->PrintDriver
.major
= brd
->SerialDriver
.major
;
257 brd
->PrintDriver
.minor_start
= 0x80;
258 brd
->PrintDriver
.num
= brd
->maxports
;
259 brd
->PrintDriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
260 brd
->PrintDriver
.subtype
= SERIAL_TYPE_NORMAL
;
261 brd
->PrintDriver
.init_termios
= DgncDefaultTermios
;
262 brd
->PrintDriver
.driver_name
= DRVSTR
;
263 brd
->PrintDriver
.flags
= (TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
| TTY_DRIVER_HARDWARE_BREAK
);
266 * The kernel wants space to store pointers to
267 * tty_struct's and termios's. Must be separated from
268 * the Serial Driver so we don't get confused
270 brd
->PrintDriver
.ttys
= kzalloc(brd
->maxports
* sizeof(*brd
->PrintDriver
.ttys
), GFP_KERNEL
);
271 if (!brd
->PrintDriver
.ttys
)
273 kref_init(&brd
->PrintDriver
.kref
);
274 brd
->PrintDriver
.termios
= kzalloc(brd
->maxports
* sizeof(*brd
->PrintDriver
.termios
), GFP_KERNEL
);
275 if (!brd
->PrintDriver
.termios
)
279 * Entry points for driver. Called by the kernel from
280 * tty_io.c and n_tty.c.
282 tty_set_operations(&brd
->PrintDriver
, &dgnc_tty_ops
);
284 if (!brd
->dgnc_Major_TransparentPrint_Registered
) {
285 /* Register Transparent Print devices */
286 rc
= tty_register_driver(&brd
->PrintDriver
);
288 APR(("Can't register Transparent Print device (%d)\n", rc
));
291 brd
->dgnc_Major_TransparentPrint_Registered
= TRUE
;
294 dgnc_BoardsByMajor
[brd
->SerialDriver
.major
] = brd
;
295 brd
->dgnc_Serial_Major
= brd
->SerialDriver
.major
;
296 brd
->dgnc_TransparentPrint_Major
= brd
->PrintDriver
.major
;
298 DPR_INIT(("DGNC REGISTER TTY: MAJOR: %d\n", brd
->SerialDriver
.major
));
307 * Init the tty subsystem. Called once per board after board has been
308 * downloaded and init'ed.
310 int dgnc_tty_init(struct dgnc_board
*brd
)
314 struct channel_t
*ch
;
319 DPR_INIT(("dgnc_tty_init start\n"));
322 * Initialize board structure elements.
325 vaddr
= brd
->re_map_membase
;
327 brd
->nasync
= brd
->maxports
;
330 * Allocate channel memory that might not have been allocated
331 * when the driver was first loaded.
333 for (i
= 0; i
< brd
->nasync
; i
++) {
334 if (!brd
->channels
[i
]) {
337 * Okay to malloc with GFP_KERNEL, we are not at
338 * interrupt context, and there are no locks held.
340 brd
->channels
[i
] = kzalloc(sizeof(*brd
->channels
[i
]), GFP_KERNEL
);
341 if (!brd
->channels
[i
]) {
342 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
343 __FILE__
, __LINE__
));
348 ch
= brd
->channels
[0];
349 vaddr
= brd
->re_map_membase
;
351 /* Set up channel variables */
352 for (i
= 0; i
< brd
->nasync
; i
++, ch
= brd
->channels
[i
]) {
354 if (!brd
->channels
[i
])
357 DGNC_SPINLOCK_INIT(ch
->ch_lock
);
359 /* Store all our magic numbers */
360 ch
->magic
= DGNC_CHANNEL_MAGIC
;
361 ch
->ch_tun
.magic
= DGNC_UNIT_MAGIC
;
362 ch
->ch_tun
.un_ch
= ch
;
363 ch
->ch_tun
.un_type
= DGNC_SERIAL
;
364 ch
->ch_tun
.un_dev
= i
;
366 ch
->ch_pun
.magic
= DGNC_UNIT_MAGIC
;
367 ch
->ch_pun
.un_ch
= ch
;
368 ch
->ch_pun
.un_type
= DGNC_PRINT
;
369 ch
->ch_pun
.un_dev
= i
+ 128;
371 if (brd
->bd_uart_offset
== 0x200)
372 ch
->ch_neo_uart
= vaddr
+ (brd
->bd_uart_offset
* i
);
374 ch
->ch_cls_uart
= vaddr
+ (brd
->bd_uart_offset
* i
);
378 ch
->ch_digi
= dgnc_digi_init
;
380 /* .25 second delay */
381 ch
->ch_close_delay
= 250;
383 init_waitqueue_head(&ch
->ch_flags_wait
);
384 init_waitqueue_head(&ch
->ch_tun
.un_flags_wait
);
385 init_waitqueue_head(&ch
->ch_pun
.un_flags_wait
);
386 init_waitqueue_head(&ch
->ch_sniff_wait
);
389 struct device
*classp
;
390 classp
= tty_register_device(&brd
->SerialDriver
, i
,
391 &(ch
->ch_bd
->pdev
->dev
));
392 ch
->ch_tun
.un_sysfs
= classp
;
393 dgnc_create_tty_sysfs(&ch
->ch_tun
, classp
);
395 classp
= tty_register_device(&brd
->PrintDriver
, i
,
396 &(ch
->ch_bd
->pdev
->dev
));
397 ch
->ch_pun
.un_sysfs
= classp
;
398 dgnc_create_tty_sysfs(&ch
->ch_pun
, classp
);
403 DPR_INIT(("dgnc_tty_init finish\n"));
410 * dgnc_tty_post_uninit()
412 * UnInitialize any global tty related data.
414 void dgnc_tty_post_uninit(void)
416 kfree(dgnc_TmpWriteBuf
);
417 dgnc_TmpWriteBuf
= NULL
;
424 * Uninitialize the TTY portion of this driver. Free all memory and
427 void dgnc_tty_uninit(struct dgnc_board
*brd
)
431 if (brd
->dgnc_Major_Serial_Registered
) {
432 dgnc_BoardsByMajor
[brd
->SerialDriver
.major
] = NULL
;
433 brd
->dgnc_Serial_Major
= 0;
434 for (i
= 0; i
< brd
->nasync
; i
++) {
435 dgnc_remove_tty_sysfs(brd
->channels
[i
]->ch_tun
.un_sysfs
);
436 tty_unregister_device(&brd
->SerialDriver
, i
);
438 tty_unregister_driver(&brd
->SerialDriver
);
439 brd
->dgnc_Major_Serial_Registered
= FALSE
;
442 if (brd
->dgnc_Major_TransparentPrint_Registered
) {
443 dgnc_BoardsByMajor
[brd
->PrintDriver
.major
] = NULL
;
444 brd
->dgnc_TransparentPrint_Major
= 0;
445 for (i
= 0; i
< brd
->nasync
; i
++) {
446 dgnc_remove_tty_sysfs(brd
->channels
[i
]->ch_pun
.un_sysfs
);
447 tty_unregister_device(&brd
->PrintDriver
, i
);
449 tty_unregister_driver(&brd
->PrintDriver
);
450 brd
->dgnc_Major_TransparentPrint_Registered
= FALSE
;
453 kfree(brd
->SerialDriver
.ttys
);
454 brd
->SerialDriver
.ttys
= NULL
;
455 kfree(brd
->PrintDriver
.ttys
);
456 brd
->PrintDriver
.ttys
= NULL
;
460 #define TMPBUFLEN (1024)
463 * dgnc_sniff - Dump data out to the "sniff" buffer if the
464 * proc sniff file is opened...
466 void dgnc_sniff_nowait_nolock(struct channel_t
*ch
, uchar
*text
, uchar
*buf
, int len
)
474 char tmpbuf
[TMPBUFLEN
];
478 /* Leave if sniff not open */
479 if (!(ch
->ch_sniff_flags
& SNIFF_OPEN
))
482 do_gettimeofday(&tv
);
484 /* Create our header for data dump */
485 p
+= sprintf(p
, "<%ld %ld><%s><", tv
.tv_sec
, tv
.tv_usec
, text
);
486 tmpbuflen
= p
- tmpbuf
;
491 for (i
= 0; i
< len
&& tmpbuflen
< (TMPBUFLEN
- 4); i
++) {
492 p
+= sprintf(p
, "%02x ", *buf
);
494 tmpbuflen
= p
- tmpbuf
;
497 if (tmpbuflen
< (TMPBUFLEN
- 4)) {
499 p
+= sprintf(p
- 1, "%s\n", ">");
501 p
+= sprintf(p
, "%s\n", ">");
507 nbuf
= strlen(tmpbuf
);
511 * Loop while data remains.
513 while (nbuf
> 0 && ch
->ch_sniff_buf
) {
515 * Determine the amount of available space left in the
516 * buffer. If there's none, wait until some appears.
518 n
= (ch
->ch_sniff_out
- ch
->ch_sniff_in
- 1) & SNIFF_MASK
;
521 * If there is no space left to write to in our sniff buffer,
522 * we have no choice but to drop the data.
523 * We *cannot* sleep here waiting for space, because this
524 * function was probably called by the interrupt/timer routines!
530 * Copy as much data as will fit.
536 r
= SNIFF_MAX
- ch
->ch_sniff_in
;
539 memcpy(ch
->ch_sniff_buf
+ ch
->ch_sniff_in
, p
, r
);
547 memcpy(ch
->ch_sniff_buf
+ ch
->ch_sniff_in
, p
, n
);
549 ch
->ch_sniff_in
+= n
;
554 * Wakeup any thread waiting for data
556 if (ch
->ch_sniff_flags
& SNIFF_WAIT_DATA
) {
557 ch
->ch_sniff_flags
&= ~SNIFF_WAIT_DATA
;
558 wake_up_interruptible(&ch
->ch_sniff_wait
);
563 * If the user sent us too much data to push into our tmpbuf,
564 * we need to keep looping around on all the data.
571 } while (too_much_data
);
575 /*=======================================================================
577 * dgnc_wmove - Write data to transmit queue.
579 * ch - Pointer to channel structure.
580 * buf - Poiter to characters to be moved.
581 * n - Number of characters to move.
583 *=======================================================================*/
584 static void dgnc_wmove(struct channel_t
*ch
, char *buf
, uint n
)
589 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
592 head
= ch
->ch_w_head
& WQUEUEMASK
;
595 * If the write wraps over the top of the circular buffer,
596 * move the portion up to the wrap point, and reset the
597 * pointers to the bottom.
599 remain
= WQUEUESIZE
- head
;
603 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
613 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
618 ch
->ch_w_head
= head
;
624 /*=======================================================================
626 * dgnc_input - Process received data.
628 * ch - Pointer to channel structure.
630 *=======================================================================*/
631 void dgnc_input(struct channel_t
*ch
)
633 struct dgnc_board
*bd
;
634 struct tty_struct
*tp
;
635 struct tty_ldisc
*ld
;
647 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
650 tp
= ch
->ch_tun
.un_tty
;
653 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
656 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
659 * Figure the number of characters in the buffer.
660 * Exit immediately if none.
663 head
= ch
->ch_r_head
& rmask
;
664 tail
= ch
->ch_r_tail
& rmask
;
665 data_len
= (head
- tail
) & rmask
;
668 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
672 DPR_READ(("dgnc_input start\n"));
675 * If the device is not open, or CREAD is off,
676 * flush input data and return immediately.
678 if (!tp
|| (tp
->magic
!= TTY_MAGIC
) || !(ch
->ch_tun
.un_flags
& UN_ISOPEN
) ||
679 !(tp
->termios
.c_cflag
& CREAD
) || (ch
->ch_tun
.un_flags
& UN_CLOSING
)) {
681 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len
, ch
->ch_portnum
));
682 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
683 tp
, tp
? tp
->magic
: 0, TTY_MAGIC
, ch
->ch_tun
.un_flags
));
685 ch
->ch_r_head
= tail
;
687 /* Force queue flow control to be released, if needed */
688 dgnc_check_queue_flow_control(ch
);
690 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
695 * If we are throttled, simply don't read any data.
697 if (ch
->ch_flags
& CH_FORCED_STOPI
) {
698 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
699 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
700 ch
->ch_portnum
, head
, tail
));
704 DPR_READ(("dgnc_input start 2\n"));
706 flip_len
= TTY_FLIPBUF_SIZE
;
708 /* Chop down the length, if needed */
709 len
= min(data_len
, flip_len
);
710 len
= min(len
, (N_TTY_BUF_SIZE
- 1));
712 ld
= tty_ldisc_ref(tp
);
716 * If the DONT_FLIP flag is on, don't flush our buffer, and act
717 * like the ld doesn't have any space to put the data right now.
719 if (test_bit(TTY_DONT_FLIP
, &tp
->flags
))
724 * If we were unable to get a reference to the ld,
725 * don't flush our buffer, and act like the ld doesn't
726 * have any space to put the data right now.
732 * If ld doesn't have a pointer to a receive_buf function,
733 * flush the data, then act like the ld doesn't have any
734 * space to put the data right now.
736 if (!ld
->ops
->receive_buf
) {
737 ch
->ch_r_head
= ch
->ch_r_tail
;
743 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
750 * The tty layer in the kernel has changed in 2.6.16+.
752 * The flip buffers in the tty structure are no longer exposed,
753 * and probably will be going away eventually.
755 * If we are completely raw, we don't need to go through a lot
756 * of the tty layers that exist.
757 * In this case, we take the shortest and fastest route we
758 * can to relay the data to the user.
760 * On the other hand, if we are not raw, we need to go through
761 * the new 2.6.16+ tty layer, which has its API more well defined.
763 len
= tty_buffer_request_room(tp
->port
, len
);
767 * n now contains the most amount of data we can copy,
768 * bounded either by how much the Linux tty layer can handle,
769 * or the amount of data the card actually has pending...
772 s
= ((head
>= tail
) ? head
: RQUEUESIZE
) - tail
;
779 * If conditions are such that ld needs to see all
780 * UART errors, we will have to walk each character
781 * and error byte and send them to the buffer one at
784 if (I_PARMRK(tp
) || I_BRKINT(tp
) || I_INPCK(tp
)) {
785 for (i
= 0; i
< s
; i
++) {
786 if (*(ch
->ch_equeue
+ tail
+ i
) & UART_LSR_BI
)
787 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_BREAK
);
788 else if (*(ch
->ch_equeue
+ tail
+ i
) & UART_LSR_PE
)
789 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_PARITY
);
790 else if (*(ch
->ch_equeue
+ tail
+ i
) & UART_LSR_FE
)
791 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_FRAME
);
793 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_NORMAL
);
796 tty_insert_flip_string(tp
->port
, ch
->ch_rqueue
+ tail
, s
);
799 dgnc_sniff_nowait_nolock(ch
, "USER READ", ch
->ch_rqueue
+ tail
, s
);
803 /* Flip queue if needed */
807 ch
->ch_r_tail
= tail
& rmask
;
808 ch
->ch_e_tail
= tail
& rmask
;
809 dgnc_check_queue_flow_control(ch
);
810 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
812 /* Tell the tty layer its okay to "eat" the data now */
813 tty_flip_buffer_push(tp
->port
);
818 DPR_READ(("dgnc_input - finish\n"));
822 /************************************************************************
823 * Determines when CARRIER changes state and takes appropriate
825 ************************************************************************/
826 void dgnc_carrier(struct channel_t
*ch
)
828 struct dgnc_board
*bd
;
830 int virt_carrier
= 0;
831 int phys_carrier
= 0;
833 DPR_CARR(("dgnc_carrier called...\n"));
835 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
840 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
843 if (ch
->ch_mistat
& UART_MSR_DCD
) {
844 DPR_CARR(("mistat: %x D_CD: %x\n", ch
->ch_mistat
, ch
->ch_mistat
& UART_MSR_DCD
));
848 if (ch
->ch_digi
.digi_flags
& DIGI_FORCEDCD
)
851 if (ch
->ch_c_cflag
& CLOCAL
)
854 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier
, virt_carrier
));
857 * Test for a VIRTUAL carrier transition to HIGH.
859 if (((ch
->ch_flags
& CH_FCAR
) == 0) && (virt_carrier
== 1)) {
862 * When carrier rises, wake any threads waiting
863 * for carrier in the open routine.
866 DPR_CARR(("carrier: virt DCD rose\n"));
868 if (waitqueue_active(&(ch
->ch_flags_wait
)))
869 wake_up_interruptible(&ch
->ch_flags_wait
);
873 * Test for a PHYSICAL carrier transition to HIGH.
875 if (((ch
->ch_flags
& CH_CD
) == 0) && (phys_carrier
== 1)) {
878 * When carrier rises, wake any threads waiting
879 * for carrier in the open routine.
882 DPR_CARR(("carrier: physical DCD rose\n"));
884 if (waitqueue_active(&(ch
->ch_flags_wait
)))
885 wake_up_interruptible(&ch
->ch_flags_wait
);
889 * Test for a PHYSICAL transition to low, so long as we aren't
890 * currently ignoring physical transitions (which is what "virtual
891 * carrier" indicates).
893 * The transition of the virtual carrier to low really doesn't
894 * matter... it really only means "ignore carrier state", not
895 * "make pretend that carrier is there".
897 if ((virt_carrier
== 0) && ((ch
->ch_flags
& CH_CD
) != 0) &&
902 * When carrier drops:
904 * Drop carrier on all open units.
906 * Flush queues, waking up any task waiting in the
909 * Send a hangup to the control terminal.
911 * Enable all select calls.
913 if (waitqueue_active(&(ch
->ch_flags_wait
)))
914 wake_up_interruptible(&ch
->ch_flags_wait
);
916 if (ch
->ch_tun
.un_open_count
> 0) {
917 DPR_CARR(("Sending tty hangup\n"));
918 tty_hangup(ch
->ch_tun
.un_tty
);
921 if (ch
->ch_pun
.un_open_count
> 0) {
922 DPR_CARR(("Sending pr hangup\n"));
923 tty_hangup(ch
->ch_pun
.un_tty
);
928 * Make sure that our cached values reflect the current reality.
930 if (virt_carrier
== 1)
931 ch
->ch_flags
|= CH_FCAR
;
933 ch
->ch_flags
&= ~CH_FCAR
;
935 if (phys_carrier
== 1)
936 ch
->ch_flags
|= CH_CD
;
938 ch
->ch_flags
&= ~CH_CD
;
942 * Assign the custom baud rate to the channel structure
944 static void dgnc_set_custom_speed(struct channel_t
*ch
, uint newrate
)
953 ch
->ch_custom_speed
= 0;
958 * Since the divisor is stored in a 16-bit integer, we make sure
959 * we don't allow any rates smaller than a 16-bit integer would allow.
960 * And of course, rates above the dividend won't fly.
962 if (newrate
&& newrate
< ((ch
->ch_bd
->bd_dividend
/ 0xFFFF) + 1))
963 newrate
= ((ch
->ch_bd
->bd_dividend
/ 0xFFFF) + 1);
965 if (newrate
&& newrate
> ch
->ch_bd
->bd_dividend
)
966 newrate
= ch
->ch_bd
->bd_dividend
;
969 testdiv
= ch
->ch_bd
->bd_dividend
/ newrate
;
972 * If we try to figure out what rate the board would use
973 * with the test divisor, it will be either equal or higher
974 * than the requested baud rate. If we then determine the
975 * rate with a divisor one higher, we will get the next lower
976 * supported rate below the requested.
978 testrate_high
= ch
->ch_bd
->bd_dividend
/ testdiv
;
979 testrate_low
= ch
->ch_bd
->bd_dividend
/ (testdiv
+ 1);
982 * If the rate for the requested divisor is correct, just
983 * use it and be done.
985 if (testrate_high
!= newrate
) {
987 * Otherwise, pick the rate that is closer (i.e. whichever rate
988 * has a smaller delta).
990 deltahigh
= testrate_high
- newrate
;
991 deltalow
= newrate
- testrate_low
;
993 if (deltahigh
< deltalow
)
994 newrate
= testrate_high
;
996 newrate
= testrate_low
;
1000 ch
->ch_custom_speed
= newrate
;
1004 void dgnc_check_queue_flow_control(struct channel_t
*ch
)
1008 /* Store how much space we have left in the queue */
1009 qleft
= ch
->ch_r_tail
- ch
->ch_r_head
- 1;
1011 qleft
+= RQUEUEMASK
+ 1;
1014 * Check to see if we should enforce flow control on our queue because
1015 * the ld (or user) isn't reading data out of our queue fast enuf.
1017 * NOTE: This is done based on what the current flow control of the
1020 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
1021 * This will cause the UART's FIFO to back up, and force
1022 * the RTS signal to be dropped.
1023 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
1024 * the other side, in hopes it will stop sending data to us.
1025 * 3) NONE - Nothing we can do. We will simply drop any extra data
1026 * that gets sent into us when the queue fills up.
1030 if (ch
->ch_digi
.digi_flags
& CTSPACE
|| ch
->ch_c_cflag
& CRTSCTS
) {
1031 if (!(ch
->ch_flags
& CH_RECEIVER_OFF
)) {
1032 ch
->ch_bd
->bd_ops
->disable_receiver(ch
);
1033 ch
->ch_flags
|= (CH_RECEIVER_OFF
);
1034 DPR_READ(("Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
1039 else if (ch
->ch_c_iflag
& IXOFF
) {
1040 if (ch
->ch_stops_sent
<= MAX_STOPS_SENT
) {
1041 ch
->ch_bd
->bd_ops
->send_stop_character(ch
);
1042 ch
->ch_stops_sent
++;
1043 DPR_READ(("Sending stop char! Times sent: %x\n", ch
->ch_stops_sent
));
1048 /* Empty... Can't do anything about the impending overflow... */
1053 * Check to see if we should unenforce flow control because
1054 * ld (or user) finally read enuf data out of our queue.
1056 * NOTE: This is done based on what the current flow control of the
1059 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
1060 * This will cause the UART's FIFO to raise RTS back up,
1061 * which will allow the other side to start sending data again.
1062 * 2) SWFLOW (IXOFF) - Send a start character to
1063 * the other side, so it will start sending data to us again.
1064 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
1065 * other side, we don't need to do anything now.
1067 if (qleft
> (RQUEUESIZE
/ 2)) {
1069 if (ch
->ch_digi
.digi_flags
& RTSPACE
|| ch
->ch_c_cflag
& CRTSCTS
) {
1070 if (ch
->ch_flags
& CH_RECEIVER_OFF
) {
1071 ch
->ch_bd
->bd_ops
->enable_receiver(ch
);
1072 ch
->ch_flags
&= ~(CH_RECEIVER_OFF
);
1073 DPR_READ(("Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
1078 else if (ch
->ch_c_iflag
& IXOFF
&& ch
->ch_stops_sent
) {
1079 ch
->ch_stops_sent
= 0;
1080 ch
->ch_bd
->bd_ops
->send_start_character(ch
);
1081 DPR_READ(("Sending start char!\n"));
1085 /* Nothing needed. */
1091 void dgnc_wakeup_writes(struct channel_t
*ch
)
1096 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1099 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1102 * If channel now has space, wake up anyone waiting on the condition.
1104 qlen
= ch
->ch_w_head
- ch
->ch_w_tail
;
1108 if (qlen
>= (WQUEUESIZE
- 256)) {
1109 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1113 if (ch
->ch_tun
.un_flags
& UN_ISOPEN
) {
1114 if ((ch
->ch_tun
.un_tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1115 ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
)
1117 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1118 (ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_tun
.un_tty
);
1119 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1122 wake_up_interruptible(&ch
->ch_tun
.un_tty
->write_wait
);
1125 * If unit is set to wait until empty, check to make sure
1126 * the queue AND FIFO are both empty.
1128 if (ch
->ch_tun
.un_flags
& UN_EMPTY
) {
1129 if ((qlen
== 0) && (ch
->ch_bd
->bd_ops
->get_uart_bytes_left(ch
) == 0)) {
1130 ch
->ch_tun
.un_flags
&= ~(UN_EMPTY
);
1133 * If RTS Toggle mode is on, whenever
1134 * the queue and UART is empty, keep RTS low.
1136 if (ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
) {
1137 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
1138 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
1142 * If DTR Toggle mode is on, whenever
1143 * the queue and UART is empty, keep DTR low.
1145 if (ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
) {
1146 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
1147 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
1152 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
1155 if (ch
->ch_pun
.un_flags
& UN_ISOPEN
) {
1156 if ((ch
->ch_pun
.un_tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1157 ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
)
1159 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1160 (ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_pun
.un_tty
);
1161 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1164 wake_up_interruptible(&ch
->ch_pun
.un_tty
->write_wait
);
1167 * If unit is set to wait until empty, check to make sure
1168 * the queue AND FIFO are both empty.
1170 if (ch
->ch_pun
.un_flags
& UN_EMPTY
) {
1171 if ((qlen
== 0) && (ch
->ch_bd
->bd_ops
->get_uart_bytes_left(ch
) == 0)) {
1172 ch
->ch_pun
.un_flags
&= ~(UN_EMPTY
);
1176 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
1179 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1184 /************************************************************************
1186 * TTY Entry points and helper functions
1188 ************************************************************************/
1194 static int dgnc_tty_open(struct tty_struct
*tty
, struct file
*file
)
1196 struct dgnc_board
*brd
;
1197 struct channel_t
*ch
;
1206 major
= MAJOR(tty_devnum(tty
));
1207 minor
= MINOR(tty_devnum(tty
));
1212 /* Get board pointer from our array of majors we have allocated */
1213 brd
= dgnc_BoardsByMajor
[major
];
1218 * If board is not yet up to a state of READY, go to
1219 * sleep waiting for it to happen or they cancel the open.
1221 rc
= wait_event_interruptible(brd
->state_wait
,
1222 (brd
->state
& BOARD_READY
));
1227 DGNC_LOCK(brd
->bd_lock
, lock_flags
);
1229 /* If opened device is greater than our number of ports, bail. */
1230 if (PORT_NUM(minor
) > brd
->nasync
) {
1231 DGNC_UNLOCK(brd
->bd_lock
, lock_flags
);
1235 ch
= brd
->channels
[PORT_NUM(minor
)];
1237 DGNC_UNLOCK(brd
->bd_lock
, lock_flags
);
1241 /* Drop board lock */
1242 DGNC_UNLOCK(brd
->bd_lock
, lock_flags
);
1244 /* Grab channel lock */
1245 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1247 /* Figure out our type */
1248 if (!IS_PRINT(minor
)) {
1249 un
= &brd
->channels
[PORT_NUM(minor
)]->ch_tun
;
1250 un
->un_type
= DGNC_SERIAL
;
1251 } else if (IS_PRINT(minor
)) {
1252 un
= &brd
->channels
[PORT_NUM(minor
)]->ch_pun
;
1253 un
->un_type
= DGNC_PRINT
;
1255 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1256 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__
));
1261 * If the port is still in a previous open, and in a state
1262 * where we simply cannot safely keep going, wait until the
1265 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1267 rc
= wait_event_interruptible(ch
->ch_flags_wait
, ((ch
->ch_flags
& CH_OPENING
) == 0));
1269 /* If ret is non-zero, user ctrl-c'ed us */
1271 DPR_OPEN(("%d User ctrl c'ed\n", __LINE__
));
1276 * If either unit is in the middle of the fragile part of close,
1277 * we just cannot touch the channel safely.
1278 * Go to sleep, knowing that when the channel can be
1279 * touched safely, the close routine will signal the
1280 * ch_flags_wait to wake us back up.
1282 rc
= wait_event_interruptible(ch
->ch_flags_wait
,
1283 (((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_CLOSING
) == 0));
1285 /* If ret is non-zero, user ctrl-c'ed us */
1287 DPR_OPEN(("%d User ctrl c'ed\n", __LINE__
));
1291 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1294 /* Store our unit into driver_data, so we always have it available. */
1295 tty
->driver_data
= un
;
1297 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d PORT_NUM: %x unit: %p NAME: %s\n",
1298 MAJOR(tty_devnum(tty
)), MINOR(tty_devnum(tty
)), PORT_NUM(minor
), un
, brd
->name
));
1300 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__
, ch
->ch_tun
.un_flags
, ch
->ch_pun
.un_flags
));
1305 if (!(un
->un_flags
& UN_ISOPEN
)) {
1306 /* Store important variables. */
1309 /* Maybe do something here to the TTY struct as well? */
1314 * Allocate channel buffers for read/write/error.
1315 * Set flag, so we don't get trounced on.
1317 ch
->ch_flags
|= (CH_OPENING
);
1319 /* Drop locks, as malloc with GFP_KERNEL can sleep */
1320 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1323 ch
->ch_rqueue
= kzalloc(RQUEUESIZE
, GFP_KERNEL
);
1325 ch
->ch_equeue
= kzalloc(EQUEUESIZE
, GFP_KERNEL
);
1327 ch
->ch_wqueue
= kzalloc(WQUEUESIZE
, GFP_KERNEL
);
1329 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1331 ch
->ch_flags
&= ~(CH_OPENING
);
1332 wake_up_interruptible(&ch
->ch_flags_wait
);
1335 * Initialize if neither terminal or printer is open.
1337 if (!((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_ISOPEN
)) {
1339 DPR_OPEN(("dgnc_open: initializing channel in open...\n"));
1342 * Flush input queues.
1344 ch
->ch_r_head
= ch
->ch_r_tail
= 0;
1345 ch
->ch_e_head
= ch
->ch_e_tail
= 0;
1346 ch
->ch_w_head
= ch
->ch_w_tail
= 0;
1348 brd
->bd_ops
->flush_uart_write(ch
);
1349 brd
->bd_ops
->flush_uart_read(ch
);
1352 ch
->ch_cached_lsr
= 0;
1353 ch
->ch_stop_sending_break
= 0;
1354 ch
->ch_stops_sent
= 0;
1356 ch
->ch_c_cflag
= tty
->termios
.c_cflag
;
1357 ch
->ch_c_iflag
= tty
->termios
.c_iflag
;
1358 ch
->ch_c_oflag
= tty
->termios
.c_oflag
;
1359 ch
->ch_c_lflag
= tty
->termios
.c_lflag
;
1360 ch
->ch_startc
= tty
->termios
.c_cc
[VSTART
];
1361 ch
->ch_stopc
= tty
->termios
.c_cc
[VSTOP
];
1364 * Bring up RTS and DTR...
1365 * Also handle RTS or DTR toggle if set.
1367 if (!(ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
))
1368 ch
->ch_mostat
|= (UART_MCR_RTS
);
1369 if (!(ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
))
1370 ch
->ch_mostat
|= (UART_MCR_DTR
);
1372 /* Tell UART to init itself */
1373 brd
->bd_ops
->uart_init(ch
);
1377 * Run param in case we changed anything
1379 brd
->bd_ops
->param(tty
);
1384 * follow protocol for opening port
1387 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1389 rc
= dgnc_block_til_ready(tty
, file
, ch
);
1392 DPR_OPEN(("dgnc_tty_open returning after dgnc_block_til_ready "
1395 /* No going back now, increment our unit and channel counters */
1396 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1397 ch
->ch_open_count
++;
1398 un
->un_open_count
++;
1399 un
->un_flags
|= (UN_ISOPEN
);
1400 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1402 DPR_OPEN(("dgnc_tty_open finished\n"));
1408 * dgnc_block_til_ready()
1410 * Wait for DCD, if needed.
1412 static int dgnc_block_til_ready(struct tty_struct
*tty
, struct file
*file
, struct channel_t
*ch
)
1415 struct un_t
*un
= NULL
;
1418 int sleep_on_un_flags
= 0;
1420 if (!tty
|| tty
->magic
!= TTY_MAGIC
|| !file
|| !ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
) {
1424 un
= tty
->driver_data
;
1425 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1428 DPR_OPEN(("dgnc_block_til_ready - before block.\n"));
1430 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1437 sleep_on_un_flags
= 0;
1440 * If board has failed somehow during our sleep, bail with error.
1442 if (ch
->ch_bd
->state
== BOARD_FAILED
) {
1447 /* If tty was hung up, break out of loop and set error. */
1448 if (tty_hung_up_p(file
)) {
1454 * If either unit is in the middle of the fragile part of close,
1455 * we just cannot touch the channel safely.
1456 * Go back to sleep, knowing that when the channel can be
1457 * touched safely, the close routine will signal the
1458 * ch_wait_flags to wake us back up.
1460 if (!((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_CLOSING
)) {
1463 * Our conditions to leave cleanly and happily:
1464 * 1) NONBLOCKING on the tty is set.
1466 * 3) DCD (fake or real) is active.
1469 if (file
->f_flags
& O_NONBLOCK
)
1472 if (tty
->flags
& (1 << TTY_IO_ERROR
)) {
1477 if (ch
->ch_flags
& CH_CD
) {
1478 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__
, ch
->ch_flags
));
1482 if (ch
->ch_flags
& CH_FCAR
) {
1483 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__
, ch
->ch_flags
));
1487 sleep_on_un_flags
= 1;
1491 * If there is a signal pending, the user probably
1492 * interrupted (ctrl-c) us.
1493 * Leave loop with error set.
1495 if (signal_pending(current
)) {
1496 DPR_OPEN(("%d: signal pending...\n", __LINE__
));
1497 retval
= -ERESTARTSYS
;
1501 DPR_OPEN(("dgnc_block_til_ready - blocking.\n"));
1504 * Store the flags before we let go of channel lock
1506 if (sleep_on_un_flags
)
1507 old_flags
= ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
;
1509 old_flags
= ch
->ch_flags
;
1512 * Let go of channel lock before calling schedule.
1513 * Our poller will get any FEP events and wake us up when DCD
1514 * eventually goes active.
1517 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1519 DPR_OPEN(("Going to sleep on %s flags...\n",
1520 (sleep_on_un_flags
? "un" : "ch")));
1523 * Wait for something in the flags to change from the current value.
1525 if (sleep_on_un_flags
)
1526 retval
= wait_event_interruptible(un
->un_flags_wait
,
1527 (old_flags
!= (ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
)));
1529 retval
= wait_event_interruptible(ch
->ch_flags_wait
,
1530 (old_flags
!= ch
->ch_flags
));
1532 DPR_OPEN(("After sleep... retval: %x\n", retval
));
1535 * We got woken up for some reason.
1536 * Before looping around, grab our channel lock.
1538 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1543 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1545 DPR_OPEN(("dgnc_block_til_ready - after blocking.\n"));
1548 DPR_OPEN(("dgnc_block_til_ready - done. error. retval: %x\n", retval
));
1552 DPR_OPEN(("dgnc_block_til_ready - done no error. jiffies: %lu\n", jiffies
));
1561 * Hangup the port. Like a close, but don't wait for output to drain.
1563 static void dgnc_tty_hangup(struct tty_struct
*tty
)
1567 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
1570 un
= tty
->driver_data
;
1571 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1574 DPR_CLOSE(("dgnc_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
1575 un
->un_ch
->ch_open_count
, un
->un_open_count
));
1577 /* flush the transmit queues */
1578 dgnc_tty_flush_buffer(tty
);
1580 DPR_CLOSE(("dgnc_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
1581 un
->un_ch
->ch_open_count
, un
->un_open_count
));
1589 static void dgnc_tty_close(struct tty_struct
*tty
, struct file
*file
)
1591 struct ktermios
*ts
;
1592 struct dgnc_board
*bd
;
1593 struct channel_t
*ch
;
1598 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
1601 un
= tty
->driver_data
;
1602 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1606 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1610 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
1615 DPR_CLOSE(("Close called\n"));
1617 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1620 * Determine if this is the last close or not - and if we agree about
1621 * which type of close it is with the Line Discipline
1623 if ((tty
->count
== 1) && (un
->un_open_count
!= 1)) {
1625 * Uh, oh. tty->count is 1, which means that the tty
1626 * structure will be freed. un_open_count should always
1627 * be one in these conditions. If it's greater than
1628 * one, we've got real problems, since it means the
1629 * serial port won't be shutdown.
1631 APR(("tty->count is 1, un open count is %d\n", un
->un_open_count
));
1632 un
->un_open_count
= 1;
1635 if (un
->un_open_count
)
1636 un
->un_open_count
--;
1638 APR(("bad serial port open count of %d\n", un
->un_open_count
));
1640 ch
->ch_open_count
--;
1642 if (ch
->ch_open_count
&& un
->un_open_count
) {
1643 DPR_CLOSE(("dgnc_tty_close: not last close ch: %d un:%d\n",
1644 ch
->ch_open_count
, un
->un_open_count
));
1646 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1650 /* OK, its the last close on the unit */
1651 DPR_CLOSE(("dgnc_tty_close - last close on unit procedures\n"));
1653 un
->un_flags
|= UN_CLOSING
;
1659 * Only officially close channel if count is 0 and
1660 * DIGI_PRINTER bit is not set.
1662 if ((ch
->ch_open_count
== 0) && !(ch
->ch_digi
.digi_flags
& DIGI_PRINTER
)) {
1664 ch
->ch_flags
&= ~(CH_STOPI
| CH_FORCED_STOPI
);
1667 * turn off print device when closing print device.
1669 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
1670 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
1671 (int) ch
->ch_digi
.digi_offlen
);
1672 ch
->ch_flags
&= ~CH_PRON
;
1675 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1676 /* wait for output to drain */
1677 /* This will also return if we take an interrupt */
1679 DPR_CLOSE(("Calling wait_for_drain\n"));
1680 rc
= bd
->bd_ops
->drain(tty
, 0);
1682 DPR_CLOSE(("After calling wait_for_drain\n"));
1685 DPR_BASIC(("dgnc_tty_close - bad return: %d ", rc
));
1687 dgnc_tty_flush_buffer(tty
);
1688 tty_ldisc_flush(tty
);
1690 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1695 * If we have HUPCL set, lower DTR and RTS
1697 if (ch
->ch_c_cflag
& HUPCL
) {
1698 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
1701 ch
->ch_mostat
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1702 bd
->bd_ops
->assert_modem_signals(ch
);
1705 * Go to sleep to ensure RTS/DTR
1706 * have been dropped for modems to see it.
1708 if (ch
->ch_close_delay
) {
1709 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
1711 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1712 dgnc_ms_sleep(ch
->ch_close_delay
);
1713 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1715 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
1719 ch
->ch_old_baud
= 0;
1721 /* Turn off UART interrupts for this port */
1722 ch
->ch_bd
->bd_ops
->uart_off(ch
);
1725 * turn off print device when closing print device.
1727 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
1728 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
1729 (int) ch
->ch_digi
.digi_offlen
);
1730 ch
->ch_flags
&= ~CH_PRON
;
1735 un
->un_flags
&= ~(UN_ISOPEN
| UN_CLOSING
);
1737 DPR_CLOSE(("Close. Doing wakeups\n"));
1738 wake_up_interruptible(&ch
->ch_flags_wait
);
1739 wake_up_interruptible(&un
->un_flags_wait
);
1741 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1743 DPR_BASIC(("dgnc_tty_close - complete\n"));
1748 * dgnc_tty_chars_in_buffer()
1750 * Return number of characters that have not been transmitted yet.
1752 * This routine is used by the line discipline to determine if there
1753 * is data waiting to be transmitted/drained/flushed or not.
1755 static int dgnc_tty_chars_in_buffer(struct tty_struct
*tty
)
1757 struct channel_t
*ch
= NULL
;
1758 struct un_t
*un
= NULL
;
1763 ulong lock_flags
= 0;
1768 un
= tty
->driver_data
;
1769 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1773 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1776 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1779 thead
= ch
->ch_w_head
& tmask
;
1780 ttail
= ch
->ch_w_tail
& tmask
;
1782 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1784 if (ttail
== thead
) {
1788 chars
= thead
- ttail
;
1790 chars
= thead
- ttail
+ WQUEUESIZE
;
1793 DPR_WRITE(("dgnc_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d)\n",
1794 ch
->ch_portnum
, chars
, thead
, ttail
));
1803 * Reduces bytes_available to the max number of characters
1804 * that can be sent currently given the maxcps value, and
1805 * returns the new bytes_available. This only affects printer
1808 static int dgnc_maxcps_room(struct tty_struct
*tty
, int bytes_available
)
1810 struct channel_t
*ch
= NULL
;
1811 struct un_t
*un
= NULL
;
1814 return bytes_available
;
1816 un
= tty
->driver_data
;
1817 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1818 return bytes_available
;
1821 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1822 return bytes_available
;
1825 * If its not the Transparent print device, return
1826 * the full data amount.
1828 if (un
->un_type
!= DGNC_PRINT
)
1829 return bytes_available
;
1831 if (ch
->ch_digi
.digi_maxcps
> 0 && ch
->ch_digi
.digi_bufsize
> 0) {
1833 unsigned long current_time
= jiffies
;
1834 unsigned long buffer_time
= current_time
+
1835 (HZ
* ch
->ch_digi
.digi_bufsize
) / ch
->ch_digi
.digi_maxcps
;
1837 if (ch
->ch_cpstime
< current_time
) {
1838 /* buffer is empty */
1839 ch
->ch_cpstime
= current_time
; /* reset ch_cpstime */
1840 cps_limit
= ch
->ch_digi
.digi_bufsize
;
1841 } else if (ch
->ch_cpstime
< buffer_time
) {
1842 /* still room in the buffer */
1843 cps_limit
= ((buffer_time
- ch
->ch_cpstime
) * ch
->ch_digi
.digi_maxcps
) / HZ
;
1845 /* no room in the buffer */
1849 bytes_available
= min(cps_limit
, bytes_available
);
1852 return bytes_available
;
1857 * dgnc_tty_write_room()
1859 * Return space available in Tx buffer
1861 static int dgnc_tty_write_room(struct tty_struct
*tty
)
1863 struct channel_t
*ch
= NULL
;
1864 struct un_t
*un
= NULL
;
1869 ulong lock_flags
= 0;
1871 if (tty
== NULL
|| dgnc_TmpWriteBuf
== NULL
)
1874 un
= tty
->driver_data
;
1875 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1879 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1882 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1885 head
= (ch
->ch_w_head
) & tmask
;
1886 tail
= (ch
->ch_w_tail
) & tmask
;
1888 ret
= tail
- head
- 1;
1892 /* Limit printer to maxcps */
1893 ret
= dgnc_maxcps_room(tty
, ret
);
1896 * If we are printer device, leave space for
1897 * possibly both the on and off strings.
1899 if (un
->un_type
== DGNC_PRINT
) {
1900 if (!(ch
->ch_flags
& CH_PRON
))
1901 ret
-= ch
->ch_digi
.digi_onlen
;
1902 ret
-= ch
->ch_digi
.digi_offlen
;
1904 if (ch
->ch_flags
& CH_PRON
)
1905 ret
-= ch
->ch_digi
.digi_offlen
;
1911 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1913 DPR_WRITE(("dgnc_tty_write_room - %d tail: %d head: %d\n", ret
, tail
, head
));
1920 * dgnc_tty_put_char()
1922 * Put a character into ch->ch_buf
1924 * - used by the line discipline for OPOST processing
1926 static int dgnc_tty_put_char(struct tty_struct
*tty
, unsigned char c
)
1929 * Simply call tty_write.
1931 DPR_WRITE(("dgnc_tty_put_char called\n"));
1932 dgnc_tty_write(tty
, &c
, 1);
1940 * Take data from the user or kernel and send it out to the FEP.
1941 * In here exists all the Transparent Print magic as well.
1943 static int dgnc_tty_write(struct tty_struct
*tty
,
1944 const unsigned char *buf
, int count
)
1946 struct channel_t
*ch
= NULL
;
1947 struct un_t
*un
= NULL
;
1948 int bufcount
= 0, n
= 0;
1957 if (tty
== NULL
|| dgnc_TmpWriteBuf
== NULL
)
1960 un
= tty
->driver_data
;
1961 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1965 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1971 DPR_WRITE(("dgnc_tty_write: Port: %x tty=%p user=%d len=%d\n",
1972 ch
->ch_portnum
, tty
, from_user
, count
));
1975 * Store original amount of characters passed in.
1976 * This helps to figure out if we should ask the FEP
1977 * to send us an event when it has more space available.
1981 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1983 /* Get our space available for the channel from the board */
1985 head
= (ch
->ch_w_head
) & tmask
;
1986 tail
= (ch
->ch_w_tail
) & tmask
;
1988 bufcount
= tail
- head
- 1;
1990 bufcount
+= WQUEUESIZE
;
1992 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
1993 __LINE__
, bufcount
, count
, tail
, head
, tmask
));
1996 * Limit printer output to maxcps overall, with bursts allowed
1997 * up to bufsize characters.
1999 bufcount
= dgnc_maxcps_room(tty
, bufcount
);
2002 * Take minimum of what the user wants to send, and the
2003 * space available in the FEP buffer.
2005 count
= min(count
, bufcount
);
2008 * Bail if no space left.
2011 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2016 * Output the printer ON string, if we are in terminal mode, but
2017 * need to be in printer mode.
2019 if ((un
->un_type
== DGNC_PRINT
) && !(ch
->ch_flags
& CH_PRON
)) {
2020 dgnc_wmove(ch
, ch
->ch_digi
.digi_onstr
,
2021 (int) ch
->ch_digi
.digi_onlen
);
2022 head
= (ch
->ch_w_head
) & tmask
;
2023 ch
->ch_flags
|= CH_PRON
;
2027 * On the other hand, output the printer OFF string, if we are
2028 * currently in printer mode, but need to output to the terminal.
2030 if ((un
->un_type
!= DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
2031 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
2032 (int) ch
->ch_digi
.digi_offlen
);
2033 head
= (ch
->ch_w_head
) & tmask
;
2034 ch
->ch_flags
&= ~CH_PRON
;
2038 * If there is nothing left to copy, or I can't handle any more data, leave.
2041 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2047 count
= min(count
, WRITEBUFLEN
);
2049 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2052 * If data is coming from user space, copy it into a temporary
2053 * buffer so we don't get swapped out while doing the copy to
2056 /* we're allowed to block if it's from_user */
2057 if (down_interruptible(&dgnc_TmpWriteSem
))
2061 * copy_from_user() returns the number
2062 * of bytes that could *NOT* be copied.
2064 count
-= copy_from_user(dgnc_TmpWriteBuf
, (const uchar __user
*) buf
, count
);
2067 up(&dgnc_TmpWriteSem
);
2071 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2073 buf
= dgnc_TmpWriteBuf
;
2080 * If the write wraps over the top of the circular buffer,
2081 * move the portion up to the wrap point, and reset the
2082 * pointers to the bottom.
2084 remain
= WQUEUESIZE
- head
;
2088 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
2089 dgnc_sniff_nowait_nolock(ch
, "USER WRITE", ch
->ch_wqueue
+ head
, remain
);
2096 * Move rest of data.
2099 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
2100 dgnc_sniff_nowait_nolock(ch
, "USER WRITE", ch
->ch_wqueue
+ head
, remain
);
2106 ch
->ch_w_head
= head
;
2109 /* Update printer buffer empty time. */
2110 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_digi
.digi_maxcps
> 0)
2111 && (ch
->ch_digi
.digi_bufsize
> 0)) {
2112 ch
->ch_cpstime
+= (HZ
* count
) / ch
->ch_digi
.digi_maxcps
;
2116 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2117 up(&dgnc_TmpWriteSem
);
2119 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2122 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count
, orig_count
));
2126 * Channel lock is grabbed and then released
2127 * inside this routine.
2129 ch
->ch_bd
->bd_ops
->copy_data_from_queue_to_uart(ch
);
2137 * Return modem signals to ld.
2140 static int dgnc_tty_tiocmget(struct tty_struct
*tty
)
2142 struct channel_t
*ch
;
2148 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2151 un
= tty
->driver_data
;
2152 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2156 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2159 DPR_IOCTL(("dgnc_tty_tiocmget start\n"));
2161 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2163 mstat
= (ch
->ch_mostat
| ch
->ch_mistat
);
2165 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2169 if (mstat
& UART_MCR_DTR
)
2170 result
|= TIOCM_DTR
;
2171 if (mstat
& UART_MCR_RTS
)
2172 result
|= TIOCM_RTS
;
2173 if (mstat
& UART_MSR_CTS
)
2174 result
|= TIOCM_CTS
;
2175 if (mstat
& UART_MSR_DSR
)
2176 result
|= TIOCM_DSR
;
2177 if (mstat
& UART_MSR_RI
)
2179 if (mstat
& UART_MSR_DCD
)
2182 DPR_IOCTL(("dgnc_tty_tiocmget finish\n"));
2189 * dgnc_tty_tiocmset()
2191 * Set modem signals, called by ld.
2194 static int dgnc_tty_tiocmset(struct tty_struct
*tty
,
2195 unsigned int set
, unsigned int clear
)
2197 struct dgnc_board
*bd
;
2198 struct channel_t
*ch
;
2203 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2206 un
= tty
->driver_data
;
2207 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2211 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2215 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2218 DPR_IOCTL(("dgnc_tty_tiocmset start\n"));
2221 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2223 if (set
& TIOCM_RTS
)
2224 ch
->ch_mostat
|= UART_MCR_RTS
;
2226 if (set
& TIOCM_DTR
)
2227 ch
->ch_mostat
|= UART_MCR_DTR
;
2229 if (clear
& TIOCM_RTS
)
2230 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2232 if (clear
& TIOCM_DTR
)
2233 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2235 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
2237 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2239 DPR_IOCTL(("dgnc_tty_tiocmset finish\n"));
2246 * dgnc_tty_send_break()
2248 * Send a Break, called by ld.
2250 static int dgnc_tty_send_break(struct tty_struct
*tty
, int msec
)
2252 struct dgnc_board
*bd
;
2253 struct channel_t
*ch
;
2258 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2261 un
= tty
->driver_data
;
2262 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2266 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2270 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2284 DPR_IOCTL(("dgnc_tty_send_break start 1. %lx\n", jiffies
));
2286 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2288 ch
->ch_bd
->bd_ops
->send_break(ch
, msec
);
2290 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2292 DPR_IOCTL(("dgnc_tty_send_break finish\n"));
2300 * dgnc_tty_wait_until_sent()
2302 * wait until data has been transmitted, called by ld.
2304 static void dgnc_tty_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2306 struct dgnc_board
*bd
;
2307 struct channel_t
*ch
;
2311 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2314 un
= tty
->driver_data
;
2315 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2319 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2323 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2326 rc
= bd
->bd_ops
->drain(tty
, 0);
2328 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
2338 * send a high priority character, called by ld.
2340 static void dgnc_tty_send_xchar(struct tty_struct
*tty
, char c
)
2342 struct dgnc_board
*bd
;
2343 struct channel_t
*ch
;
2347 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2350 un
= tty
->driver_data
;
2351 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2355 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2359 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2362 DPR_IOCTL(("dgnc_tty_send_xchar start\n"));
2363 printk("dgnc_tty_send_xchar start\n");
2365 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2366 bd
->bd_ops
->send_immediate_char(ch
, c
);
2367 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2369 DPR_IOCTL(("dgnc_tty_send_xchar finish\n"));
2370 printk("dgnc_tty_send_xchar finish\n");
2378 * Return modem signals to ld.
2380 static inline int dgnc_get_mstat(struct channel_t
*ch
)
2382 unsigned char mstat
;
2386 DPR_IOCTL(("dgnc_getmstat start\n"));
2388 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2391 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2393 mstat
= (ch
->ch_mostat
| ch
->ch_mistat
);
2395 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2399 if (mstat
& UART_MCR_DTR
)
2400 result
|= TIOCM_DTR
;
2401 if (mstat
& UART_MCR_RTS
)
2402 result
|= TIOCM_RTS
;
2403 if (mstat
& UART_MSR_CTS
)
2404 result
|= TIOCM_CTS
;
2405 if (mstat
& UART_MSR_DSR
)
2406 result
|= TIOCM_DSR
;
2407 if (mstat
& UART_MSR_RI
)
2409 if (mstat
& UART_MSR_DCD
)
2412 DPR_IOCTL(("dgnc_getmstat finish\n"));
2420 * Return modem signals to ld.
2422 static int dgnc_get_modem_info(struct channel_t
*ch
, unsigned int __user
*value
)
2427 DPR_IOCTL(("dgnc_get_modem_info start\n"));
2429 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2432 result
= dgnc_get_mstat(ch
);
2437 rc
= put_user(result
, value
);
2439 DPR_IOCTL(("dgnc_get_modem_info finish\n"));
2445 * dgnc_set_modem_info()
2447 * Set modem signals, called by ld.
2449 static int dgnc_set_modem_info(struct tty_struct
*tty
, unsigned int command
, unsigned int __user
*value
)
2451 struct dgnc_board
*bd
;
2452 struct channel_t
*ch
;
2455 unsigned int arg
= 0;
2458 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2461 un
= tty
->driver_data
;
2462 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2466 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2470 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2475 DPR_IOCTL(("dgnc_set_modem_info() start\n"));
2477 ret
= get_user(arg
, value
);
2483 if (arg
& TIOCM_RTS
)
2484 ch
->ch_mostat
|= UART_MCR_RTS
;
2486 if (arg
& TIOCM_DTR
)
2487 ch
->ch_mostat
|= UART_MCR_DTR
;
2492 if (arg
& TIOCM_RTS
)
2493 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2495 if (arg
& TIOCM_DTR
)
2496 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2502 if (arg
& TIOCM_RTS
)
2503 ch
->ch_mostat
|= UART_MCR_RTS
;
2505 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2507 if (arg
& TIOCM_DTR
)
2508 ch
->ch_mostat
|= UART_MCR_DTR
;
2510 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2518 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2520 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
2522 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2524 DPR_IOCTL(("dgnc_set_modem_info finish\n"));
2531 * dgnc_tty_digigeta()
2533 * Ioctl to get the information for ditty.
2538 static int dgnc_tty_digigeta(struct tty_struct
*tty
, struct digi_t __user
*retinfo
)
2540 struct channel_t
*ch
;
2548 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2551 un
= tty
->driver_data
;
2552 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2556 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2559 memset(&tmp
, 0, sizeof(tmp
));
2561 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2562 memcpy(&tmp
, &ch
->ch_digi
, sizeof(tmp
));
2563 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2565 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2573 * dgnc_tty_digiseta()
2575 * Ioctl to set the information for ditty.
2580 static int dgnc_tty_digiseta(struct tty_struct
*tty
, struct digi_t __user
*new_info
)
2582 struct dgnc_board
*bd
;
2583 struct channel_t
*ch
;
2585 struct digi_t new_digi
;
2588 DPR_IOCTL(("DIGI_SETA start\n"));
2590 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2593 un
= tty
->driver_data
;
2594 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2598 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2602 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2605 if (copy_from_user(&new_digi
, new_info
, sizeof(new_digi
))) {
2606 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
2610 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2613 * Handle transistions to and from RTS Toggle.
2615 if (!(ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
) && (new_digi
.digi_flags
& DIGI_RTS_TOGGLE
))
2616 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2617 if ((ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
) && !(new_digi
.digi_flags
& DIGI_RTS_TOGGLE
))
2618 ch
->ch_mostat
|= (UART_MCR_RTS
);
2621 * Handle transistions to and from DTR Toggle.
2623 if (!(ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
) && (new_digi
.digi_flags
& DIGI_DTR_TOGGLE
))
2624 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2625 if ((ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
) && !(new_digi
.digi_flags
& DIGI_DTR_TOGGLE
))
2626 ch
->ch_mostat
|= (UART_MCR_DTR
);
2628 memcpy(&ch
->ch_digi
, &new_digi
, sizeof(new_digi
));
2630 if (ch
->ch_digi
.digi_maxcps
< 1)
2631 ch
->ch_digi
.digi_maxcps
= 1;
2633 if (ch
->ch_digi
.digi_maxcps
> 10000)
2634 ch
->ch_digi
.digi_maxcps
= 10000;
2636 if (ch
->ch_digi
.digi_bufsize
< 10)
2637 ch
->ch_digi
.digi_bufsize
= 10;
2639 if (ch
->ch_digi
.digi_maxchar
< 1)
2640 ch
->ch_digi
.digi_maxchar
= 1;
2642 if (ch
->ch_digi
.digi_maxchar
> ch
->ch_digi
.digi_bufsize
)
2643 ch
->ch_digi
.digi_maxchar
= ch
->ch_digi
.digi_bufsize
;
2645 if (ch
->ch_digi
.digi_onlen
> DIGI_PLEN
)
2646 ch
->ch_digi
.digi_onlen
= DIGI_PLEN
;
2648 if (ch
->ch_digi
.digi_offlen
> DIGI_PLEN
)
2649 ch
->ch_digi
.digi_offlen
= DIGI_PLEN
;
2651 ch
->ch_bd
->bd_ops
->param(tty
);
2653 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2655 DPR_IOCTL(("DIGI_SETA finish\n"));
2662 * dgnc_set_termios()
2664 static void dgnc_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
2666 struct dgnc_board
*bd
;
2667 struct channel_t
*ch
;
2669 unsigned long lock_flags
;
2671 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2674 un
= tty
->driver_data
;
2675 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2679 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2683 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2686 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2688 ch
->ch_c_cflag
= tty
->termios
.c_cflag
;
2689 ch
->ch_c_iflag
= tty
->termios
.c_iflag
;
2690 ch
->ch_c_oflag
= tty
->termios
.c_oflag
;
2691 ch
->ch_c_lflag
= tty
->termios
.c_lflag
;
2692 ch
->ch_startc
= tty
->termios
.c_cc
[VSTART
];
2693 ch
->ch_stopc
= tty
->termios
.c_cc
[VSTOP
];
2695 ch
->ch_bd
->bd_ops
->param(tty
);
2698 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2702 static void dgnc_tty_throttle(struct tty_struct
*tty
)
2704 struct channel_t
*ch
;
2706 ulong lock_flags
= 0;
2708 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2711 un
= tty
->driver_data
;
2712 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2716 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2719 DPR_IOCTL(("dgnc_tty_throttle start\n"));
2721 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2723 ch
->ch_flags
|= (CH_FORCED_STOPI
);
2725 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2727 DPR_IOCTL(("dgnc_tty_throttle finish\n"));
2731 static void dgnc_tty_unthrottle(struct tty_struct
*tty
)
2733 struct channel_t
*ch
;
2737 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2740 un
= tty
->driver_data
;
2741 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2745 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2748 DPR_IOCTL(("dgnc_tty_unthrottle start\n"));
2750 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2752 ch
->ch_flags
&= ~(CH_FORCED_STOPI
);
2754 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2756 DPR_IOCTL(("dgnc_tty_unthrottle finish\n"));
2760 static void dgnc_tty_start(struct tty_struct
*tty
)
2762 struct dgnc_board
*bd
;
2763 struct channel_t
*ch
;
2767 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2770 un
= tty
->driver_data
;
2771 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2775 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2779 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2782 DPR_IOCTL(("dgcn_tty_start start\n"));
2784 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2786 ch
->ch_flags
&= ~(CH_FORCED_STOP
);
2788 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2790 DPR_IOCTL(("dgnc_tty_start finish\n"));
2794 static void dgnc_tty_stop(struct tty_struct
*tty
)
2796 struct dgnc_board
*bd
;
2797 struct channel_t
*ch
;
2801 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2804 un
= tty
->driver_data
;
2805 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2809 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2813 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2816 DPR_IOCTL(("dgnc_tty_stop start\n"));
2818 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2820 ch
->ch_flags
|= (CH_FORCED_STOP
);
2822 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2824 DPR_IOCTL(("dgnc_tty_stop finish\n"));
2829 * dgnc_tty_flush_chars()
2831 * Flush the cook buffer
2833 * Note to self, and any other poor souls who venture here:
2835 * flush in this case DOES NOT mean dispose of the data.
2836 * instead, it means "stop buffering and send it if you
2837 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
2839 * It is also always called in interrupt context - JAR 8-Sept-99
2841 static void dgnc_tty_flush_chars(struct tty_struct
*tty
)
2843 struct dgnc_board
*bd
;
2844 struct channel_t
*ch
;
2848 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2851 un
= tty
->driver_data
;
2852 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2856 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2860 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2863 DPR_IOCTL(("dgnc_tty_flush_chars start\n"));
2865 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2867 /* Do something maybe here */
2869 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2871 DPR_IOCTL(("dgnc_tty_flush_chars finish\n"));
2877 * dgnc_tty_flush_buffer()
2879 * Flush Tx buffer (make in == out)
2881 static void dgnc_tty_flush_buffer(struct tty_struct
*tty
)
2883 struct channel_t
*ch
;
2887 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2890 un
= tty
->driver_data
;
2891 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2895 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2898 DPR_IOCTL(("dgnc_tty_flush_buffer on port: %d start\n", ch
->ch_portnum
));
2900 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2902 ch
->ch_flags
&= ~CH_STOP
;
2904 /* Flush our write queue */
2905 ch
->ch_w_head
= ch
->ch_w_tail
;
2907 /* Flush UARTs transmit FIFO */
2908 ch
->ch_bd
->bd_ops
->flush_uart_write(ch
);
2910 if (ch
->ch_tun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
2911 ch
->ch_tun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
2912 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
2914 if (ch
->ch_pun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
2915 ch
->ch_pun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
2916 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
2919 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2921 DPR_IOCTL(("dgnc_tty_flush_buffer finish\n"));
2926 /*****************************************************************************
2928 * The IOCTL function and all of its helpers
2930 *****************************************************************************/
2935 * The usual assortment of ioctl's
2937 static int dgnc_tty_ioctl(struct tty_struct
*tty
, unsigned int cmd
,
2940 struct dgnc_board
*bd
;
2941 struct channel_t
*ch
;
2945 void __user
*uarg
= (void __user
*) arg
;
2947 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2950 un
= tty
->driver_data
;
2951 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2955 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2959 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2962 DPR_IOCTL(("dgnc_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
2963 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
2965 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2967 if (un
->un_open_count
<= 0) {
2968 DPR_BASIC(("dgnc_tty_ioctl - unit not open.\n"));
2969 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2975 /* Here are all the standard ioctl's that we MUST implement */
2979 * TCSBRK is SVID version: non-zero arg --> no break
2980 * this behaviour is exploited by tcdrain().
2982 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
2983 * between 0.25 and 0.5 seconds so we'll ask for something
2984 * in the middle: 0.375 seconds.
2986 rc
= tty_check_change(tty
);
2987 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2991 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
2994 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
2998 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3000 if (((cmd
== TCSBRK
) && (!arg
)) || (cmd
== TCSBRKP
)) {
3001 ch
->ch_bd
->bd_ops
->send_break(ch
, 250);
3004 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3006 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3007 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3013 /* support for POSIX tcsendbreak()
3014 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3015 * between 0.25 and 0.5 seconds so we'll ask for something
3016 * in the middle: 0.375 seconds.
3018 rc
= tty_check_change(tty
);
3019 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3023 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3025 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3029 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3031 ch
->ch_bd
->bd_ops
->send_break(ch
, 250);
3033 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3035 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3036 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3041 rc
= tty_check_change(tty
);
3042 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3046 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3048 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3052 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3054 ch
->ch_bd
->bd_ops
->send_break(ch
, 250);
3056 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3058 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3059 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3065 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3070 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3072 rc
= put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*) arg
);
3077 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3078 rc
= get_user(arg
, (unsigned long __user
*) arg
);
3082 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3083 tty
->termios
.c_cflag
= ((tty
->termios
.c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
3084 ch
->ch_bd
->bd_ops
->param(tty
);
3085 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3090 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3091 return dgnc_get_modem_info(ch
, uarg
);
3096 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3097 return dgnc_set_modem_info(tty
, cmd
, uarg
);
3100 * Here are any additional ioctl's that we want to implement
3105 * The linux tty driver doesn't have a flush
3106 * input routine for the driver, assuming all backed
3107 * up data is in the line disc. buffers. However,
3108 * we all know that's not the case. Here, we
3109 * act on the ioctl, but then lie and say we didn't
3110 * so the line discipline will process the flush
3113 rc
= tty_check_change(tty
);
3115 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3119 if ((arg
== TCIFLUSH
) || (arg
== TCIOFLUSH
)) {
3120 ch
->ch_r_head
= ch
->ch_r_tail
;
3121 ch
->ch_bd
->bd_ops
->flush_uart_read(ch
);
3122 /* Force queue flow control to be released, if needed */
3123 dgnc_check_queue_flow_control(ch
);
3126 if ((arg
== TCOFLUSH
) || (arg
== TCIOFLUSH
)) {
3127 if (!(un
->un_type
== DGNC_PRINT
)) {
3128 ch
->ch_w_head
= ch
->ch_w_tail
;
3129 ch
->ch_bd
->bd_ops
->flush_uart_write(ch
);
3131 if (ch
->ch_tun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
3132 ch
->ch_tun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
3133 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
3136 if (ch
->ch_pun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
3137 ch
->ch_pun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
3138 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
3144 /* pretend we didn't recognize this IOCTL */
3145 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3146 return -ENOIOCTLCMD
;
3150 * The linux tty driver doesn't have a flush
3151 * input routine for the driver, assuming all backed
3152 * up data is in the line disc. buffers. However,
3153 * we all know that's not the case. Here, we
3154 * act on the ioctl, but then lie and say we didn't
3155 * so the line discipline will process the flush
3158 if (cmd
== TCSETSF
) {
3160 ch
->ch_flags
&= ~CH_STOP
;
3161 ch
->ch_r_head
= ch
->ch_r_tail
;
3162 ch
->ch_bd
->bd_ops
->flush_uart_read(ch
);
3163 /* Force queue flow control to be released, if needed */
3164 dgnc_check_queue_flow_control(ch
);
3167 /* now wait for all the output to drain */
3168 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3169 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3171 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d\n", rc
));
3175 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3176 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3178 /* pretend we didn't recognize this */
3179 return -ENOIOCTLCMD
;
3183 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3184 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3186 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3190 /* pretend we didn't recognize this */
3191 return -ENOIOCTLCMD
;
3194 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3195 /* Make the ld do it */
3196 return -ENOIOCTLCMD
;
3199 /* get information for ditty */
3200 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3201 return dgnc_tty_digigeta(tty
, uarg
);
3206 /* set information for ditty */
3207 if (cmd
== (DIGI_SETAW
)) {
3209 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3210 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3212 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3215 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3217 tty_ldisc_flush(tty
);
3222 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3223 return dgnc_tty_digiseta(tty
, uarg
);
3228 /* Let go of locks when accessing user space, could sleep */
3229 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3230 rc
= get_user(loopback
, (unsigned int __user
*) arg
);
3233 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3235 /* Enable/disable internal loopback for this port */
3237 ch
->ch_flags
|= CH_LOOPBACK
;
3239 ch
->ch_flags
&= ~(CH_LOOPBACK
);
3241 ch
->ch_bd
->bd_ops
->param(tty
);
3242 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3246 case DIGI_GETCUSTOMBAUD
:
3247 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3248 rc
= put_user(ch
->ch_custom_speed
, (unsigned int __user
*) arg
);
3251 case DIGI_SETCUSTOMBAUD
:
3254 /* Let go of locks when accessing user space, could sleep */
3255 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3256 rc
= get_user(new_rate
, (int __user
*) arg
);
3259 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3260 dgnc_set_custom_speed(ch
, new_rate
);
3261 ch
->ch_bd
->bd_ops
->param(tty
);
3262 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3267 * This ioctl allows insertion of a character into the front
3268 * of any pending data to be transmitted.
3270 * This ioctl is to satify the "Send Character Immediate"
3271 * call that the RealPort protocol spec requires.
3273 case DIGI_REALPORT_SENDIMMEDIATE
:
3276 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3277 rc
= get_user(c
, (unsigned char __user
*) arg
);
3280 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3281 ch
->ch_bd
->bd_ops
->send_immediate_char(ch
, c
);
3282 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3287 * This ioctl returns all the current counts for the port.
3289 * This ioctl is to satify the "Line Error Counters"
3290 * call that the RealPort protocol spec requires.
3292 case DIGI_REALPORT_GETCOUNTERS
:
3294 struct digi_getcounter buf
;
3296 buf
.norun
= ch
->ch_err_overrun
;
3297 buf
.noflow
= 0; /* The driver doesn't keep this stat */
3298 buf
.nframe
= ch
->ch_err_frame
;
3299 buf
.nparity
= ch
->ch_err_parity
;
3300 buf
.nbreak
= ch
->ch_err_break
;
3301 buf
.rbytes
= ch
->ch_rxcount
;
3302 buf
.tbytes
= ch
->ch_txcount
;
3304 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3306 if (copy_to_user(uarg
, &buf
, sizeof(buf
)))
3313 * This ioctl returns all current events.
3315 * This ioctl is to satify the "Event Reporting"
3316 * call that the RealPort protocol spec requires.
3318 case DIGI_REALPORT_GETEVENTS
:
3320 unsigned int events
= 0;
3322 /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
3323 if (ch
->ch_flags
& CH_BREAK_SENDING
)
3325 if ((ch
->ch_flags
& CH_STOP
) || (ch
->ch_flags
& CH_FORCED_STOP
))
3326 events
|= (EV_OPU
| EV_OPS
);
3328 if ((ch
->ch_flags
& CH_STOPI
) || (ch
->ch_flags
& CH_FORCED_STOPI
)) {
3329 events
|= (EV_IPU
| EV_IPS
);
3332 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3333 rc
= put_user(events
, (unsigned int __user
*) arg
);
3338 * This ioctl returns TOUT and TIN counters based
3339 * upon the values passed in by the RealPort Server.
3340 * It also passes back whether the UART Transmitter is
3343 case DIGI_REALPORT_GETBUFFERS
:
3345 struct digi_getbuffer buf
;
3349 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3352 * Get data from user first.
3354 if (copy_from_user(&buf
, uarg
, sizeof(buf
)))
3357 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3360 * Figure out how much data is in our RX and TX queues.
3362 buf
.rxbuf
= (ch
->ch_r_head
- ch
->ch_r_tail
) & RQUEUEMASK
;
3363 buf
.txbuf
= (ch
->ch_w_head
- ch
->ch_w_tail
) & WQUEUEMASK
;
3366 * Is the UART empty? Add that value to whats in our TX queue.
3368 count
= buf
.txbuf
+ ch
->ch_bd
->bd_ops
->get_uart_bytes_left(ch
);
3371 * Figure out how much data the RealPort Server believes should
3372 * be in our TX queue.
3374 tdist
= (buf
.tIn
- buf
.tOut
) & 0xffff;
3377 * If we have more data than the RealPort Server believes we
3378 * should have, reduce our count to its amount.
3380 * This count difference CAN happen because the Linux LD can
3381 * insert more characters into our queue for OPOST processing
3382 * that the RealPort Server doesn't know about.
3384 if (buf
.txbuf
> tdist
)
3388 * Report whether our queue and UART TX are completely empty.
3395 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3397 if (copy_to_user(uarg
, &buf
, sizeof(buf
)))
3403 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3405 DPR_IOCTL(("dgnc_tty_ioctl - in default\n"));
3406 DPR_IOCTL(("dgnc_tty_ioctl end - cmd %s (%x), arg %lx\n",
3407 dgnc_ioctl_name(cmd
), cmd
, arg
));
3409 return -ENOIOCTLCMD
;