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/version.h>
42 #include <linux/sched.h> /* For jiffies, task states */
43 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
44 #include <linux/module.h>
45 #include <linux/ctype.h>
46 #include <linux/tty.h>
47 #include <linux/tty_flip.h>
48 #include <linux/serial_reg.h>
49 #include <linux/slab.h>
50 #include <linux/delay.h> /* For udelay */
51 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
52 #include <linux/pci.h>
54 #include "dgnc_driver.h"
56 #include "dgnc_types.h"
57 #include "dgnc_trace.h"
60 #include "dpacompat.h"
61 #include "dgnc_sysfs.h"
63 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
64 #define init_MUTEX(sem) sema_init(sem, 1)
65 #define DECLARE_MUTEX(name) \
66 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
72 static struct board_t *dgnc_BoardsByMajor[256];
73 static uchar *dgnc_TmpWriteBuf = NULL;
74 static DECLARE_MUTEX(dgnc_TmpWriteSem);
77 * Default transparent print information.
79 static struct digi_t dgnc_digi_init = {
80 .digi_flags = DIGI_COOK, /* Flags */
81 .digi_maxcps = 100, /* Max CPS */
82 .digi_maxchar = 50, /* Max chars in print queue */
83 .digi_bufsize = 100, /* Printer buffer size */
84 .digi_onlen = 4, /* size of printer on string */
85 .digi_offlen = 4, /* size of printer off string */
86 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
87 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
88 .digi_term = "ansi" /* default terminal type */
93 * Define a local default termios struct. All ports will be created
94 * with this termios initially.
96 * This defines a raw port at 9600 baud, 8 data bits, no parity,
99 static struct ktermios DgncDefaultTermios =
101 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
102 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
103 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
104 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
110 /* Our function prototypes */
111 static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
112 static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
113 static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
114 static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
115 static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
116 static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
117 static int dgnc_tty_write_room(struct tty_struct *tty);
118 static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c);
119 static int dgnc_tty_chars_in_buffer(struct tty_struct *tty);
120 static void dgnc_tty_start(struct tty_struct *tty);
121 static void dgnc_tty_stop(struct tty_struct *tty);
122 static void dgnc_tty_throttle(struct tty_struct *tty);
123 static void dgnc_tty_unthrottle(struct tty_struct *tty);
124 static void dgnc_tty_flush_chars(struct tty_struct *tty);
125 static void dgnc_tty_flush_buffer(struct tty_struct *tty);
126 static void dgnc_tty_hangup(struct tty_struct *tty);
127 static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
128 static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value);
129 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
130 static int dgnc_tty_tiocmget(struct tty_struct *tty);
131 static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
133 static int dgnc_tty_tiocmget(struct tty_struct *tty, struct file *file);
134 static int dgnc_tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear);
136 static int dgnc_tty_send_break(struct tty_struct *tty, int msec);
137 static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout);
138 static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
139 static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
140 static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
143 static const struct tty_operations dgnc_tty_ops = {
144 .open = dgnc_tty_open,
145 .close = dgnc_tty_close,
146 .write = dgnc_tty_write,
147 .write_room = dgnc_tty_write_room,
148 .flush_buffer = dgnc_tty_flush_buffer,
149 .chars_in_buffer = dgnc_tty_chars_in_buffer,
150 .flush_chars = dgnc_tty_flush_chars,
151 .ioctl = dgnc_tty_ioctl,
152 .set_termios = dgnc_tty_set_termios,
153 .stop = dgnc_tty_stop,
154 .start = dgnc_tty_start,
155 .throttle = dgnc_tty_throttle,
156 .unthrottle = dgnc_tty_unthrottle,
157 .hangup = dgnc_tty_hangup,
158 .put_char = dgnc_tty_put_char,
159 .tiocmget = dgnc_tty_tiocmget,
160 .tiocmset = dgnc_tty_tiocmset,
161 .break_ctl = dgnc_tty_send_break,
162 .wait_until_sent = dgnc_tty_wait_until_sent,
163 .send_xchar = dgnc_tty_send_xchar
166 /************************************************************************
168 * TTY Initialization/Cleanup Functions
170 ************************************************************************/
175 * Initialize any global tty related data before we download any boards.
177 int dgnc_tty_preinit(void)
180 * Allocate a buffer for doing the copy from user space to
181 * kernel space in dgnc_write(). We only use one buffer and
182 * control access to it with a semaphore. If we are paging, we
183 * are already in trouble so one buffer won't hurt much anyway.
185 * We are okay to sleep in the malloc, as this routine
186 * is only called during module load, (not in interrupt context),
187 * and with no locks held.
189 dgnc_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_KERNEL);
191 if (!dgnc_TmpWriteBuf) {
192 DPR_INIT(("unable to allocate tmp write buf"));
201 * dgnc_tty_register()
203 * Init the tty subsystem for this board.
205 int dgnc_tty_register(struct board_t *brd)
209 DPR_INIT(("tty_register start\n"));
211 memset(&brd->SerialDriver, 0, sizeof(struct tty_driver));
212 memset(&brd->PrintDriver, 0, sizeof(struct tty_driver));
214 brd->SerialDriver.magic = TTY_DRIVER_MAGIC;
216 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgnc_%d_", brd->boardnum);
218 brd->SerialDriver.name = brd->SerialName;
219 brd->SerialDriver.name_base = 0;
220 brd->SerialDriver.major = 0;
221 brd->SerialDriver.minor_start = 0;
222 brd->SerialDriver.num = brd->maxports;
223 brd->SerialDriver.type = TTY_DRIVER_TYPE_SERIAL;
224 brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
225 brd->SerialDriver.init_termios = DgncDefaultTermios;
226 brd->SerialDriver.driver_name = DRVSTR;
227 brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
230 * The kernel wants space to store pointers to
231 * tty_struct's and termios's.
233 brd->SerialDriver.ttys = kzalloc(brd->maxports * sizeof(struct tty_struct *), GFP_KERNEL);
234 if (!brd->SerialDriver.ttys)
237 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
238 brd->SerialDriver.refcount = brd->TtyRefCnt;
240 kref_init(&brd->SerialDriver.kref);
243 brd->SerialDriver.termios = kzalloc(brd->maxports * sizeof(struct ktermios *), GFP_KERNEL);
244 if (!brd->SerialDriver.termios)
247 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
248 brd->SerialDriver.termios_locked = kzalloc(brd->maxports * sizeof(struct ktermios *), GFP_KERNEL);
249 if (!brd->SerialDriver.termios_locked)
253 * Entry points for driver. Called by the kernel from
254 * tty_io.c and n_tty.c.
256 tty_set_operations(&brd->SerialDriver, &dgnc_tty_ops);
258 if (!brd->dgnc_Major_Serial_Registered) {
259 /* Register tty devices */
260 rc = tty_register_driver(&brd->SerialDriver);
262 APR(("Can't register tty device (%d)\n", rc));
265 brd->dgnc_Major_Serial_Registered = TRUE;
269 * If we're doing transparent print, we have to do all of the above
270 * again, seperately so we don't get the LD confused about what major
271 * we are when we get into the dgnc_tty_open() routine.
273 brd->PrintDriver.magic = TTY_DRIVER_MAGIC;
274 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
276 brd->PrintDriver.name = brd->PrintName;
277 brd->PrintDriver.name_base = 0;
278 brd->PrintDriver.major = brd->SerialDriver.major;
279 brd->PrintDriver.minor_start = 0x80;
280 brd->PrintDriver.num = brd->maxports;
281 brd->PrintDriver.type = TTY_DRIVER_TYPE_SERIAL;
282 brd->PrintDriver.subtype = SERIAL_TYPE_NORMAL;
283 brd->PrintDriver.init_termios = DgncDefaultTermios;
284 brd->PrintDriver.driver_name = DRVSTR;
285 brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
288 * The kernel wants space to store pointers to
289 * tty_struct's and termios's. Must be seperate from
290 * the Serial Driver so we don't get confused
292 brd->PrintDriver.ttys = kzalloc(brd->maxports * sizeof(struct tty_struct *), GFP_KERNEL);
293 if (!brd->PrintDriver.ttys)
296 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
297 brd->PrintDriver.refcount = brd->TtyRefCnt;
299 kref_init(&brd->PrintDriver.kref);
302 brd->PrintDriver.termios = kzalloc(brd->maxports * sizeof(struct ktermios *), GFP_KERNEL);
303 if (!brd->PrintDriver.termios)
306 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
307 brd->PrintDriver.termios_locked = kzalloc(brd->maxports * sizeof(struct ktermios *), GFP_KERNEL);
308 if (!brd->PrintDriver.termios_locked)
313 * Entry points for driver. Called by the kernel from
314 * tty_io.c and n_tty.c.
316 tty_set_operations(&brd->PrintDriver, &dgnc_tty_ops);
318 if (!brd->dgnc_Major_TransparentPrint_Registered) {
319 /* Register Transparent Print devices */
320 rc = tty_register_driver(&brd->PrintDriver);
322 APR(("Can't register Transparent Print device (%d)\n", rc));
325 brd->dgnc_Major_TransparentPrint_Registered = TRUE;
328 dgnc_BoardsByMajor[brd->SerialDriver.major] = brd;
329 brd->dgnc_Serial_Major = brd->SerialDriver.major;
330 brd->dgnc_TransparentPrint_Major = brd->PrintDriver.major;
332 DPR_INIT(("DGNC REGISTER TTY: MAJOR: %d\n", brd->SerialDriver.major));
341 * Init the tty subsystem. Called once per board after board has been
342 * downloaded and init'ed.
344 int dgnc_tty_init(struct board_t *brd)
348 struct channel_t *ch;
353 DPR_INIT(("dgnc_tty_init start\n"));
356 * Initialize board structure elements.
359 vaddr = brd->re_map_membase;
361 brd->nasync = brd->maxports;
364 * Allocate channel memory that might not have been allocated
365 * when the driver was first loaded.
367 for (i = 0; i < brd->nasync; i++) {
368 if (!brd->channels[i]) {
371 * Okay to malloc with GFP_KERNEL, we are not at
372 * interrupt context, and there are no locks held.
374 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_KERNEL);
375 if (!brd->channels[i]) {
376 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
377 __FILE__, __LINE__));
382 ch = brd->channels[0];
383 vaddr = brd->re_map_membase;
385 /* Set up channel variables */
386 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
388 if (!brd->channels[i])
391 DGNC_SPINLOCK_INIT(ch->ch_lock);
393 /* Store all our magic numbers */
394 ch->magic = DGNC_CHANNEL_MAGIC;
395 ch->ch_tun.magic = DGNC_UNIT_MAGIC;
396 ch->ch_tun.un_ch = ch;
397 ch->ch_tun.un_type = DGNC_SERIAL;
398 ch->ch_tun.un_dev = i;
400 ch->ch_pun.magic = DGNC_UNIT_MAGIC;
401 ch->ch_pun.un_ch = ch;
402 ch->ch_pun.un_type = DGNC_PRINT;
403 ch->ch_pun.un_dev = i + 128;
405 if (brd->bd_uart_offset == 0x200)
406 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
408 ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
412 ch->ch_digi = dgnc_digi_init;
414 /* .25 second delay */
415 ch->ch_close_delay = 250;
417 init_waitqueue_head(&ch->ch_flags_wait);
418 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
419 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
420 init_waitqueue_head(&ch->ch_sniff_wait);
423 struct device *classp;
424 classp = tty_register_device(&brd->SerialDriver, i,
425 &(ch->ch_bd->pdev->dev));
426 ch->ch_tun.un_sysfs = classp;
427 dgnc_create_tty_sysfs(&ch->ch_tun, classp);
429 classp = tty_register_device(&brd->PrintDriver, i,
430 &(ch->ch_bd->pdev->dev));
431 ch->ch_pun.un_sysfs = classp;
432 dgnc_create_tty_sysfs(&ch->ch_pun, classp);
437 DPR_INIT(("dgnc_tty_init finish\n"));
444 * dgnc_tty_post_uninit()
446 * UnInitialize any global tty related data.
448 void dgnc_tty_post_uninit(void)
450 if (dgnc_TmpWriteBuf) {
451 kfree(dgnc_TmpWriteBuf);
452 dgnc_TmpWriteBuf = NULL;
460 * Uninitialize the TTY portion of this driver. Free all memory and
463 void dgnc_tty_uninit(struct board_t *brd)
467 if (brd->dgnc_Major_Serial_Registered) {
468 dgnc_BoardsByMajor[brd->SerialDriver.major] = NULL;
469 brd->dgnc_Serial_Major = 0;
470 for (i = 0; i < brd->nasync; i++) {
471 dgnc_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
472 tty_unregister_device(&brd->SerialDriver, i);
474 tty_unregister_driver(&brd->SerialDriver);
475 brd->dgnc_Major_Serial_Registered = FALSE;
478 if (brd->dgnc_Major_TransparentPrint_Registered) {
479 dgnc_BoardsByMajor[brd->PrintDriver.major] = NULL;
480 brd->dgnc_TransparentPrint_Major = 0;
481 for (i = 0; i < brd->nasync; i++) {
482 dgnc_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
483 tty_unregister_device(&brd->PrintDriver, i);
485 tty_unregister_driver(&brd->PrintDriver);
486 brd->dgnc_Major_TransparentPrint_Registered = FALSE;
489 if (brd->SerialDriver.ttys) {
490 kfree(brd->SerialDriver.ttys);
491 brd->SerialDriver.ttys = NULL;
493 if (brd->PrintDriver.ttys) {
494 kfree(brd->PrintDriver.ttys);
495 brd->PrintDriver.ttys = NULL;
500 #define TMPBUFLEN (1024)
503 * dgnc_sniff - Dump data out to the "sniff" buffer if the
504 * proc sniff file is opened...
506 void dgnc_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
514 char tmpbuf[TMPBUFLEN];
518 /* Leave if sniff not open */
519 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
522 do_gettimeofday(&tv);
524 /* Create our header for data dump */
525 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
526 tmpbuflen = p - tmpbuf;
531 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
532 p += sprintf(p, "%02x ", *buf);
534 tmpbuflen = p - tmpbuf;
537 if (tmpbuflen < (TMPBUFLEN - 4)) {
539 p += sprintf(p - 1, "%s\n", ">");
541 p += sprintf(p, "%s\n", ">");
547 nbuf = strlen(tmpbuf);
551 * Loop while data remains.
553 while (nbuf > 0 && ch->ch_sniff_buf != 0) {
555 * Determine the amount of available space left in the
556 * buffer. If there's none, wait until some appears.
558 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
561 * If there is no space left to write to in our sniff buffer,
562 * we have no choice but to drop the data.
563 * We *cannot* sleep here waiting for space, because this
564 * function was probably called by the interrupt/timer routines!
571 * Copy as much data as will fit.
577 r = SNIFF_MAX - ch->ch_sniff_in;
580 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
588 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
590 ch->ch_sniff_in += n;
595 * Wakeup any thread waiting for data
597 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
598 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
599 wake_up_interruptible(&ch->ch_sniff_wait);
604 * If the user sent us too much data to push into our tmpbuf,
605 * we need to keep looping around on all the data.
612 } while (too_much_data);
616 /*=======================================================================
618 * dgnc_wmove - Write data to transmit queue.
620 * ch - Pointer to channel structure.
621 * buf - Poiter to characters to be moved.
622 * n - Number of characters to move.
624 *=======================================================================*/
625 static void dgnc_wmove(struct channel_t *ch, char *buf, uint n)
630 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
633 head = ch->ch_w_head & WQUEUEMASK;
636 * If the write wraps over the top of the circular buffer,
637 * move the portion up to the wrap point, and reset the
638 * pointers to the bottom.
640 remain = WQUEUESIZE - head;
644 memcpy(ch->ch_wqueue + head, buf, remain);
654 memcpy(ch->ch_wqueue + head, buf, remain);
659 ch->ch_w_head = head;
665 /*=======================================================================
667 * dgnc_input - Process received data.
669 * ch - Pointer to channel structure.
671 *=======================================================================*/
672 void dgnc_input(struct channel_t *ch)
675 struct tty_struct *tp;
676 struct tty_ldisc *ld;
688 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
691 tp = ch->ch_tun.un_tty;
694 if(!bd || bd->magic != DGNC_BOARD_MAGIC)
697 DGNC_LOCK(ch->ch_lock, lock_flags);
700 * Figure the number of characters in the buffer.
701 * Exit immediately if none.
704 head = ch->ch_r_head & rmask;
705 tail = ch->ch_r_tail & rmask;
706 data_len = (head - tail) & rmask;
709 DGNC_UNLOCK(ch->ch_lock, lock_flags);
713 DPR_READ(("dgnc_input start\n"));
716 * If the device is not open, or CREAD is off,
717 * flush input data and return immediately.
719 if (!tp || (tp->magic != TTY_MAGIC) || !(ch->ch_tun.un_flags & UN_ISOPEN) ||
720 !(tp->termios.c_cflag & CREAD) || (ch->ch_tun.un_flags & UN_CLOSING)) {
722 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
723 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
724 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
726 ch->ch_r_head = tail;
728 /* Force queue flow control to be released, if needed */
729 dgnc_check_queue_flow_control(ch);
731 DGNC_UNLOCK(ch->ch_lock, lock_flags);
736 * If we are throttled, simply don't read any data.
738 if (ch->ch_flags & CH_FORCED_STOPI) {
739 DGNC_UNLOCK(ch->ch_lock, lock_flags);
740 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
741 ch->ch_portnum, head, tail));
745 DPR_READ(("dgnc_input start 2\n"));
747 flip_len = TTY_FLIPBUF_SIZE;
749 /* Chop down the length, if needed */
750 len = min(data_len, flip_len);
751 len = min(len, (N_TTY_BUF_SIZE - 1));
753 ld = tty_ldisc_ref(tp);
757 * If the DONT_FLIP flag is on, don't flush our buffer, and act
758 * like the ld doesn't have any space to put the data right now.
760 if (test_bit(TTY_DONT_FLIP, &tp->flags))
765 * If we were unable to get a reference to the ld,
766 * don't flush our buffer, and act like the ld doesn't
767 * have any space to put the data right now.
773 * If ld doesn't have a pointer to a receive_buf function,
774 * flush the data, then act like the ld doesn't have any
775 * space to put the data right now.
777 if (!ld->ops->receive_buf) {
778 ch->ch_r_head = ch->ch_r_tail;
784 DGNC_UNLOCK(ch->ch_lock, lock_flags);
791 * The tty layer in the kernel has changed in 2.6.16+.
793 * The flip buffers in the tty structure are no longer exposed,
794 * and probably will be going away eventually.
796 * If we are completely raw, we don't need to go through a lot
797 * of the tty layers that exist.
798 * In this case, we take the shortest and fastest route we
799 * can to relay the data to the user.
801 * On the other hand, if we are not raw, we need to go through
802 * the new 2.6.16+ tty layer, which has its API more well defined.
804 len = tty_buffer_request_room(tp->port, len);
808 * n now contains the most amount of data we can copy,
809 * bounded either by how much the Linux tty layer can handle,
810 * or the amount of data the card actually has pending...
813 s = ((head >= tail) ? head : RQUEUESIZE) - tail;
820 * If conditions are such that ld needs to see all
821 * UART errors, we will have to walk each character
822 * and error byte and send them to the buffer one at
825 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
826 for (i = 0; i < s; i++) {
827 if (*(ch->ch_equeue + tail + i) & UART_LSR_BI)
828 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_BREAK);
829 else if (*(ch->ch_equeue + tail + i) & UART_LSR_PE)
830 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_PARITY);
831 else if (*(ch->ch_equeue + tail + i) & UART_LSR_FE)
832 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_FRAME);
834 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_NORMAL);
838 tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s);
841 dgnc_sniff_nowait_nolock(ch, "USER READ", ch->ch_rqueue + tail, s);
845 /* Flip queue if needed */
849 ch->ch_r_tail = tail & rmask;
850 ch->ch_e_tail = tail & rmask;
851 dgnc_check_queue_flow_control(ch);
852 DGNC_UNLOCK(ch->ch_lock, lock_flags);
854 /* Tell the tty layer its okay to "eat" the data now */
855 tty_flip_buffer_push(tp->port);
860 DPR_READ(("dgnc_input - finish\n"));
864 /************************************************************************
865 * Determines when CARRIER changes state and takes appropriate
867 ************************************************************************/
868 void dgnc_carrier(struct channel_t *ch)
872 int virt_carrier = 0;
873 int phys_carrier = 0;
875 DPR_CARR(("dgnc_carrier called...\n"));
877 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
882 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
885 if (ch->ch_mistat & UART_MSR_DCD) {
886 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, ch->ch_mistat & UART_MSR_DCD));
890 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
894 if (ch->ch_c_cflag & CLOCAL) {
899 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
902 * Test for a VIRTUAL carrier transition to HIGH.
904 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
907 * When carrier rises, wake any threads waiting
908 * for carrier in the open routine.
911 DPR_CARR(("carrier: virt DCD rose\n"));
913 if (waitqueue_active(&(ch->ch_flags_wait)))
914 wake_up_interruptible(&ch->ch_flags_wait);
918 * Test for a PHYSICAL carrier transition to HIGH.
920 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
923 * When carrier rises, wake any threads waiting
924 * for carrier in the open routine.
927 DPR_CARR(("carrier: physical DCD rose\n"));
929 if (waitqueue_active(&(ch->ch_flags_wait)))
930 wake_up_interruptible(&ch->ch_flags_wait);
934 * Test for a PHYSICAL transition to low, so long as we aren't
935 * currently ignoring physical transitions (which is what "virtual
936 * carrier" indicates).
938 * The transition of the virtual carrier to low really doesn't
939 * matter... it really only means "ignore carrier state", not
940 * "make pretend that carrier is there".
942 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
947 * When carrier drops:
949 * Drop carrier on all open units.
951 * Flush queues, waking up any task waiting in the
954 * Send a hangup to the control terminal.
956 * Enable all select calls.
958 if (waitqueue_active(&(ch->ch_flags_wait)))
959 wake_up_interruptible(&ch->ch_flags_wait);
961 if (ch->ch_tun.un_open_count > 0) {
962 DPR_CARR(("Sending tty hangup\n"));
963 tty_hangup(ch->ch_tun.un_tty);
966 if (ch->ch_pun.un_open_count > 0) {
967 DPR_CARR(("Sending pr hangup\n"));
968 tty_hangup(ch->ch_pun.un_tty);
973 * Make sure that our cached values reflect the current reality.
975 if (virt_carrier == 1)
976 ch->ch_flags |= CH_FCAR;
978 ch->ch_flags &= ~CH_FCAR;
980 if (phys_carrier == 1)
981 ch->ch_flags |= CH_CD;
983 ch->ch_flags &= ~CH_CD;
987 * Assign the custom baud rate to the channel structure
989 static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
1001 * Since the divisor is stored in a 16-bit integer, we make sure
1002 * we don't allow any rates smaller than a 16-bit integer would allow.
1003 * And of course, rates above the dividend won't fly.
1005 if (newrate && newrate < ((ch->ch_bd->bd_dividend / 0xFFFF) + 1))
1006 newrate = ((ch->ch_bd->bd_dividend / 0xFFFF) + 1);
1008 if (newrate && newrate > ch->ch_bd->bd_dividend)
1009 newrate = ch->ch_bd->bd_dividend;
1011 while (newrate > 0) {
1012 testdiv = ch->ch_bd->bd_dividend / newrate;
1015 * If we try to figure out what rate the board would use
1016 * with the test divisor, it will be either equal or higher
1017 * than the requested baud rate. If we then determine the
1018 * rate with a divisor one higher, we will get the next lower
1019 * supported rate below the requested.
1021 testrate_high = ch->ch_bd->bd_dividend / testdiv;
1022 testrate_low = ch->ch_bd->bd_dividend / (testdiv + 1);
1025 * If the rate for the requested divisor is correct, just
1026 * use it and be done.
1028 if (testrate_high == newrate )
1032 * Otherwise, pick the rate that is closer (i.e. whichever rate
1033 * has a smaller delta).
1035 deltahigh = testrate_high - newrate;
1036 deltalow = newrate - testrate_low;
1038 if (deltahigh < deltalow) {
1039 newrate = testrate_high;
1041 newrate = testrate_low;
1047 ch->ch_custom_speed = newrate;
1053 void dgnc_check_queue_flow_control(struct channel_t *ch)
1057 /* Store how much space we have left in the queue */
1058 if ((qleft = ch->ch_r_tail - ch->ch_r_head - 1) < 0)
1059 qleft += RQUEUEMASK + 1;
1062 * Check to see if we should enforce flow control on our queue because
1063 * the ld (or user) isn't reading data out of our queue fast enuf.
1065 * NOTE: This is done based on what the current flow control of the
1068 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
1069 * This will cause the UART's FIFO to back up, and force
1070 * the RTS signal to be dropped.
1071 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
1072 * the other side, in hopes it will stop sending data to us.
1073 * 3) NONE - Nothing we can do. We will simply drop any extra data
1074 * that gets sent into us when the queue fills up.
1078 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
1079 if(!(ch->ch_flags & CH_RECEIVER_OFF)) {
1080 ch->ch_bd->bd_ops->disable_receiver(ch);
1081 ch->ch_flags |= (CH_RECEIVER_OFF);
1082 DPR_READ(("Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
1087 else if (ch->ch_c_iflag & IXOFF) {
1088 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
1089 ch->ch_bd->bd_ops->send_stop_character(ch);
1090 ch->ch_stops_sent++;
1091 DPR_READ(("Sending stop char! Times sent: %x\n", ch->ch_stops_sent));
1096 /* Empty... Can't do anything about the impending overflow... */
1101 * Check to see if we should unenforce flow control because
1102 * ld (or user) finally read enuf data out of our queue.
1104 * NOTE: This is done based on what the current flow control of the
1107 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
1108 * This will cause the UART's FIFO to raise RTS back up,
1109 * which will allow the other side to start sending data again.
1110 * 2) SWFLOW (IXOFF) - Send a start character to
1111 * the other side, so it will start sending data to us again.
1112 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
1113 * other side, we don't need to do anything now.
1115 if (qleft > (RQUEUESIZE / 2)) {
1117 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
1118 if (ch->ch_flags & CH_RECEIVER_OFF) {
1119 ch->ch_bd->bd_ops->enable_receiver(ch);
1120 ch->ch_flags &= ~(CH_RECEIVER_OFF);
1121 DPR_READ(("Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
1126 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
1127 ch->ch_stops_sent = 0;
1128 ch->ch_bd->bd_ops->send_start_character(ch);
1129 DPR_READ(("Sending start char!\n"));
1133 /* Nothing needed. */
1139 void dgnc_wakeup_writes(struct channel_t *ch)
1144 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1147 DGNC_LOCK(ch->ch_lock, lock_flags);
1150 * If channel now has space, wake up anyone waiting on the condition.
1152 if ((qlen = ch->ch_w_head - ch->ch_w_tail) < 0)
1155 if (qlen >= (WQUEUESIZE - 256)) {
1156 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1160 if (ch->ch_tun.un_flags & UN_ISOPEN) {
1161 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
1162 if ((ch->ch_tun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1163 ch->ch_tun.un_tty->ldisc->ops->write_wakeup)
1165 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1166 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
1167 DGNC_LOCK(ch->ch_lock, lock_flags);
1170 if ((ch->ch_tun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1171 ch->ch_tun.un_tty->ldisc.ops->write_wakeup)
1173 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1174 (ch->ch_tun.un_tty->ldisc.ops->write_wakeup)(ch->ch_tun.un_tty);
1175 DGNC_LOCK(ch->ch_lock, lock_flags);
1179 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
1182 * If unit is set to wait until empty, check to make sure
1183 * the queue AND FIFO are both empty.
1185 if (ch->ch_tun.un_flags & UN_EMPTY) {
1186 if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
1187 ch->ch_tun.un_flags &= ~(UN_EMPTY);
1190 * If RTS Toggle mode is on, whenever
1191 * the queue and UART is empty, keep RTS low.
1193 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
1194 ch->ch_mostat &= ~(UART_MCR_RTS);
1195 ch->ch_bd->bd_ops->assert_modem_signals(ch);
1199 * If DTR Toggle mode is on, whenever
1200 * the queue and UART is empty, keep DTR low.
1202 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
1203 ch->ch_mostat &= ~(UART_MCR_DTR);
1204 ch->ch_bd->bd_ops->assert_modem_signals(ch);
1209 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
1212 if (ch->ch_pun.un_flags & UN_ISOPEN) {
1213 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
1214 if ((ch->ch_pun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1215 ch->ch_pun.un_tty->ldisc->ops->write_wakeup)
1217 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1218 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
1219 DGNC_LOCK(ch->ch_lock, lock_flags);
1222 if ((ch->ch_pun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1223 ch->ch_pun.un_tty->ldisc.ops->write_wakeup)
1225 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1226 (ch->ch_pun.un_tty->ldisc.ops->write_wakeup)(ch->ch_pun.un_tty);
1227 DGNC_LOCK(ch->ch_lock, lock_flags);
1231 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
1234 * If unit is set to wait until empty, check to make sure
1235 * the queue AND FIFO are both empty.
1237 if (ch->ch_pun.un_flags & UN_EMPTY) {
1238 if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
1239 ch->ch_pun.un_flags &= ~(UN_EMPTY);
1243 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
1246 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1251 /************************************************************************
1253 * TTY Entry points and helper functions
1255 ************************************************************************/
1261 static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
1263 struct board_t *brd;
1264 struct channel_t *ch;
1273 major = MAJOR(tty_devnum(tty));
1274 minor = MINOR(tty_devnum(tty));
1280 /* Get board pointer from our array of majors we have allocated */
1281 brd = dgnc_BoardsByMajor[major];
1287 * If board is not yet up to a state of READY, go to
1288 * sleep waiting for it to happen or they cancel the open.
1290 rc = wait_event_interruptible(brd->state_wait,
1291 (brd->state & BOARD_READY));
1297 DGNC_LOCK(brd->bd_lock, lock_flags);
1299 /* If opened device is greater than our number of ports, bail. */
1300 if (PORT_NUM(minor) > brd->nasync) {
1301 DGNC_UNLOCK(brd->bd_lock, lock_flags);
1305 ch = brd->channels[PORT_NUM(minor)];
1307 DGNC_UNLOCK(brd->bd_lock, lock_flags);
1311 /* Drop board lock */
1312 DGNC_UNLOCK(brd->bd_lock, lock_flags);
1314 /* Grab channel lock */
1315 DGNC_LOCK(ch->ch_lock, lock_flags);
1317 /* Figure out our type */
1318 if (!IS_PRINT(minor)) {
1319 un = &brd->channels[PORT_NUM(minor)]->ch_tun;
1320 un->un_type = DGNC_SERIAL;
1322 else if (IS_PRINT(minor)) {
1323 un = &brd->channels[PORT_NUM(minor)]->ch_pun;
1324 un->un_type = DGNC_PRINT;
1327 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1328 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
1333 * If the port is still in a previous open, and in a state
1334 * where we simply cannot safely keep going, wait until the
1337 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1339 rc = wait_event_interruptible(ch->ch_flags_wait, ((ch->ch_flags & CH_OPENING) == 0));
1341 /* If ret is non-zero, user ctrl-c'ed us */
1343 DPR_OPEN(("%d User ctrl c'ed\n", __LINE__));
1348 * If either unit is in the middle of the fragile part of close,
1349 * we just cannot touch the channel safely.
1350 * Go to sleep, knowing that when the channel can be
1351 * touched safely, the close routine will signal the
1352 * ch_flags_wait to wake us back up.
1354 rc = wait_event_interruptible(ch->ch_flags_wait,
1355 (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING) == 0));
1357 /* If ret is non-zero, user ctrl-c'ed us */
1359 DPR_OPEN(("%d User ctrl c'ed\n", __LINE__));
1363 DGNC_LOCK(ch->ch_lock, lock_flags);
1366 /* Store our unit into driver_data, so we always have it available. */
1367 tty->driver_data = un;
1369 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d PORT_NUM: %x unit: %p NAME: %s\n",
1370 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), PORT_NUM(minor), un, brd->name));
1372 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
1377 if (!(un->un_flags & UN_ISOPEN)) {
1378 /* Store important variables. */
1381 /* Maybe do something here to the TTY struct as well? */
1386 * Allocate channel buffers for read/write/error.
1387 * Set flag, so we don't get trounced on.
1389 ch->ch_flags |= (CH_OPENING);
1391 /* Drop locks, as malloc with GFP_KERNEL can sleep */
1392 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1395 ch->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
1397 ch->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
1399 ch->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
1401 DGNC_LOCK(ch->ch_lock, lock_flags);
1403 ch->ch_flags &= ~(CH_OPENING);
1404 wake_up_interruptible(&ch->ch_flags_wait);
1407 * Initialize if neither terminal or printer is open.
1409 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1411 DPR_OPEN(("dgnc_open: initializing channel in open...\n"));
1414 * Flush input queues.
1416 ch->ch_r_head = ch->ch_r_tail = 0;
1417 ch->ch_e_head = ch->ch_e_tail = 0;
1418 ch->ch_w_head = ch->ch_w_tail = 0;
1420 brd->bd_ops->flush_uart_write(ch);
1421 brd->bd_ops->flush_uart_read(ch);
1424 ch->ch_cached_lsr = 0;
1425 ch->ch_stop_sending_break = 0;
1426 ch->ch_stops_sent = 0;
1428 ch->ch_c_cflag = tty->termios.c_cflag;
1429 ch->ch_c_iflag = tty->termios.c_iflag;
1430 ch->ch_c_oflag = tty->termios.c_oflag;
1431 ch->ch_c_lflag = tty->termios.c_lflag;
1432 ch->ch_startc = tty->termios.c_cc[VSTART];
1433 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1436 * Bring up RTS and DTR...
1437 * Also handle RTS or DTR toggle if set.
1439 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
1440 ch->ch_mostat |= (UART_MCR_RTS);
1441 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
1442 ch->ch_mostat |= (UART_MCR_DTR);
1444 /* Tell UART to init itself */
1445 brd->bd_ops->uart_init(ch);
1449 * Run param in case we changed anything
1451 brd->bd_ops->param(tty);
1456 * follow protocol for opening port
1459 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1461 rc = dgnc_block_til_ready(tty, file, ch);
1464 DPR_OPEN(("dgnc_tty_open returning after dgnc_block_til_ready "
1468 /* No going back now, increment our unit and channel counters */
1469 DGNC_LOCK(ch->ch_lock, lock_flags);
1470 ch->ch_open_count++;
1471 un->un_open_count++;
1472 un->un_flags |= (UN_ISOPEN);
1473 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1475 DPR_OPEN(("dgnc_tty_open finished\n"));
1481 * dgnc_block_til_ready()
1483 * Wait for DCD, if needed.
1485 static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
1488 struct un_t *un = NULL;
1491 int sleep_on_un_flags = 0;
1493 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGNC_CHANNEL_MAGIC) {
1497 un = tty->driver_data;
1498 if (!un || un->magic != DGNC_UNIT_MAGIC) {
1502 DPR_OPEN(("dgnc_block_til_ready - before block.\n"));
1504 DGNC_LOCK(ch->ch_lock, lock_flags);
1511 sleep_on_un_flags = 0;
1514 * If board has failed somehow during our sleep, bail with error.
1516 if (ch->ch_bd->state == BOARD_FAILED) {
1521 /* If tty was hung up, break out of loop and set error. */
1522 if (tty_hung_up_p(file)) {
1528 * If either unit is in the middle of the fragile part of close,
1529 * we just cannot touch the channel safely.
1530 * Go back to sleep, knowing that when the channel can be
1531 * touched safely, the close routine will signal the
1532 * ch_wait_flags to wake us back up.
1534 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
1537 * Our conditions to leave cleanly and happily:
1538 * 1) NONBLOCKING on the tty is set.
1540 * 3) DCD (fake or real) is active.
1543 if (file->f_flags & O_NONBLOCK) {
1547 if (tty->flags & (1 << TTY_IO_ERROR)) {
1552 if (ch->ch_flags & CH_CD) {
1553 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
1557 if (ch->ch_flags & CH_FCAR) {
1558 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
1563 sleep_on_un_flags = 1;
1567 * If there is a signal pending, the user probably
1568 * interrupted (ctrl-c) us.
1569 * Leave loop with error set.
1571 if (signal_pending(current)) {
1572 DPR_OPEN(("%d: signal pending...\n", __LINE__));
1573 retval = -ERESTARTSYS;
1577 DPR_OPEN(("dgnc_block_til_ready - blocking.\n"));
1580 * Store the flags before we let go of channel lock
1582 if (sleep_on_un_flags)
1583 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
1585 old_flags = ch->ch_flags;
1588 * Let go of channel lock before calling schedule.
1589 * Our poller will get any FEP events and wake us up when DCD
1590 * eventually goes active.
1593 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1595 DPR_OPEN(("Going to sleep on %s flags...\n",
1596 (sleep_on_un_flags ? "un" : "ch")));
1599 * Wait for something in the flags to change from the current value.
1601 if (sleep_on_un_flags) {
1602 retval = wait_event_interruptible(un->un_flags_wait,
1603 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
1606 retval = wait_event_interruptible(ch->ch_flags_wait,
1607 (old_flags != ch->ch_flags));
1610 DPR_OPEN(("After sleep... retval: %x\n", retval));
1613 * We got woken up for some reason.
1614 * Before looping around, grab our channel lock.
1616 DGNC_LOCK(ch->ch_lock, lock_flags);
1621 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1623 DPR_OPEN(("dgnc_block_til_ready - after blocking.\n"));
1626 DPR_OPEN(("dgnc_block_til_ready - done. error. retval: %x\n", retval));
1630 DPR_OPEN(("dgnc_block_til_ready - done no error. jiffies: %lu\n", jiffies));
1639 * Hangup the port. Like a close, but don't wait for output to drain.
1641 static void dgnc_tty_hangup(struct tty_struct *tty)
1645 if (!tty || tty->magic != TTY_MAGIC)
1648 un = tty->driver_data;
1649 if (!un || un->magic != DGNC_UNIT_MAGIC)
1652 DPR_CLOSE(("dgnc_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
1653 un->un_ch->ch_open_count, un->un_open_count));
1655 /* flush the transmit queues */
1656 dgnc_tty_flush_buffer(tty);
1658 DPR_CLOSE(("dgnc_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
1659 un->un_ch->ch_open_count, un->un_open_count));
1667 static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
1669 struct ktermios *ts;
1671 struct channel_t *ch;
1676 if (!tty || tty->magic != TTY_MAGIC)
1679 un = tty->driver_data;
1680 if (!un || un->magic != DGNC_UNIT_MAGIC)
1684 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1688 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1693 DPR_CLOSE(("Close called\n"));
1695 DGNC_LOCK(ch->ch_lock, lock_flags);
1698 * Determine if this is the last close or not - and if we agree about
1699 * which type of close it is with the Line Discipline
1701 if ((tty->count == 1) && (un->un_open_count != 1)) {
1703 * Uh, oh. tty->count is 1, which means that the tty
1704 * structure will be freed. un_open_count should always
1705 * be one in these conditions. If it's greater than
1706 * one, we've got real problems, since it means the
1707 * serial port won't be shutdown.
1709 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
1710 un->un_open_count = 1;
1713 if (--un->un_open_count < 0) {
1714 APR(("bad serial port open count of %d\n", un->un_open_count));
1715 un->un_open_count = 0;
1718 ch->ch_open_count--;
1720 if (ch->ch_open_count && un->un_open_count) {
1721 DPR_CLOSE(("dgnc_tty_close: not last close ch: %d un:%d\n",
1722 ch->ch_open_count, un->un_open_count));
1724 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1728 /* OK, its the last close on the unit */
1729 DPR_CLOSE(("dgnc_tty_close - last close on unit procedures\n"));
1731 un->un_flags |= UN_CLOSING;
1737 * Only officially close channel if count is 0 and
1738 * DIGI_PRINTER bit is not set.
1740 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
1742 ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI);
1745 * turn off print device when closing print device.
1747 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON) ) {
1748 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1749 (int) ch->ch_digi.digi_offlen);
1750 ch->ch_flags &= ~CH_PRON;
1753 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1754 /* wait for output to drain */
1755 /* This will also return if we take an interrupt */
1757 DPR_CLOSE(("Calling wait_for_drain\n"));
1758 rc = bd->bd_ops->drain(tty, 0);
1760 DPR_CLOSE(("After calling wait_for_drain\n"));
1763 DPR_BASIC(("dgnc_tty_close - bad return: %d ", rc));
1766 dgnc_tty_flush_buffer(tty);
1767 tty_ldisc_flush(tty);
1769 DGNC_LOCK(ch->ch_lock, lock_flags);
1774 * If we have HUPCL set, lower DTR and RTS
1776 if (ch->ch_c_cflag & HUPCL) {
1777 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
1780 ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
1781 bd->bd_ops->assert_modem_signals(ch);
1784 * Go to sleep to ensure RTS/DTR
1785 * have been dropped for modems to see it.
1787 if (ch->ch_close_delay) {
1788 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
1790 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1791 dgnc_ms_sleep(ch->ch_close_delay);
1792 DGNC_LOCK(ch->ch_lock, lock_flags);
1794 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
1798 ch->ch_old_baud = 0;
1800 /* Turn off UART interrupts for this port */
1801 ch->ch_bd->bd_ops->uart_off(ch);
1805 * turn off print device when closing print device.
1807 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON) ) {
1808 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1809 (int) ch->ch_digi.digi_offlen);
1810 ch->ch_flags &= ~CH_PRON;
1815 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
1817 DPR_CLOSE(("Close. Doing wakeups\n"));
1818 wake_up_interruptible(&ch->ch_flags_wait);
1819 wake_up_interruptible(&un->un_flags_wait);
1821 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1823 DPR_BASIC(("dgnc_tty_close - complete\n"));
1828 * dgnc_tty_chars_in_buffer()
1830 * Return number of characters that have not been transmitted yet.
1832 * This routine is used by the line discipline to determine if there
1833 * is data waiting to be transmitted/drained/flushed or not.
1835 static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
1837 struct channel_t *ch = NULL;
1838 struct un_t *un = NULL;
1843 ulong lock_flags = 0;
1848 un = tty->driver_data;
1849 if (!un || un->magic != DGNC_UNIT_MAGIC)
1853 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1856 DGNC_LOCK(ch->ch_lock, lock_flags);
1859 thead = ch->ch_w_head & tmask;
1860 ttail = ch->ch_w_tail & tmask;
1862 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1864 if (ttail == thead) {
1868 chars = thead - ttail;
1870 chars = thead - ttail + WQUEUESIZE;
1873 DPR_WRITE(("dgnc_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d)\n",
1874 ch->ch_portnum, chars, thead, ttail));
1883 * Reduces bytes_available to the max number of characters
1884 * that can be sent currently given the maxcps value, and
1885 * returns the new bytes_available. This only affects printer
1888 static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available)
1890 struct channel_t *ch = NULL;
1891 struct un_t *un = NULL;
1894 return (bytes_available);
1896 un = tty->driver_data;
1897 if (!un || un->magic != DGNC_UNIT_MAGIC)
1898 return (bytes_available);
1901 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1902 return (bytes_available);
1905 * If its not the Transparent print device, return
1906 * the full data amount.
1908 if (un->un_type != DGNC_PRINT)
1909 return (bytes_available);
1911 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
1913 unsigned long current_time = jiffies;
1914 unsigned long buffer_time = current_time +
1915 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
1917 if (ch->ch_cpstime < current_time) {
1918 /* buffer is empty */
1919 ch->ch_cpstime = current_time; /* reset ch_cpstime */
1920 cps_limit = ch->ch_digi.digi_bufsize;
1922 else if (ch->ch_cpstime < buffer_time) {
1923 /* still room in the buffer */
1924 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
1927 /* no room in the buffer */
1931 bytes_available = min(cps_limit, bytes_available);
1934 return (bytes_available);
1939 * dgnc_tty_write_room()
1941 * Return space available in Tx buffer
1943 static int dgnc_tty_write_room(struct tty_struct *tty)
1945 struct channel_t *ch = NULL;
1946 struct un_t *un = NULL;
1951 ulong lock_flags = 0;
1953 if (tty == NULL || dgnc_TmpWriteBuf == NULL)
1956 un = tty->driver_data;
1957 if (!un || un->magic != DGNC_UNIT_MAGIC)
1961 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1964 DGNC_LOCK(ch->ch_lock, lock_flags);
1967 head = (ch->ch_w_head) & tmask;
1968 tail = (ch->ch_w_tail) & tmask;
1970 if ((ret = tail - head - 1) < 0)
1973 /* Limit printer to maxcps */
1974 ret = dgnc_maxcps_room(tty, ret);
1977 * If we are printer device, leave space for
1978 * possibly both the on and off strings.
1980 if (un->un_type == DGNC_PRINT) {
1981 if (!(ch->ch_flags & CH_PRON))
1982 ret -= ch->ch_digi.digi_onlen;
1983 ret -= ch->ch_digi.digi_offlen;
1986 if (ch->ch_flags & CH_PRON)
1987 ret -= ch->ch_digi.digi_offlen;
1993 DGNC_UNLOCK(ch->ch_lock, lock_flags);
1995 DPR_WRITE(("dgnc_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
2002 * dgnc_tty_put_char()
2004 * Put a character into ch->ch_buf
2006 * - used by the line discipline for OPOST processing
2008 static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
2011 * Simply call tty_write.
2013 DPR_WRITE(("dgnc_tty_put_char called\n"));
2014 dgnc_tty_write(tty, &c, 1);
2022 * Take data from the user or kernel and send it out to the FEP.
2023 * In here exists all the Transparent Print magic as well.
2025 static int dgnc_tty_write(struct tty_struct *tty,
2026 const unsigned char *buf, int count)
2028 struct channel_t *ch = NULL;
2029 struct un_t *un = NULL;
2030 int bufcount = 0, n = 0;
2039 if (tty == NULL || dgnc_TmpWriteBuf == NULL)
2042 un = tty->driver_data;
2043 if (!un || un->magic != DGNC_UNIT_MAGIC)
2047 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2053 DPR_WRITE(("dgnc_tty_write: Port: %x tty=%p user=%d len=%d\n",
2054 ch->ch_portnum, tty, from_user, count));
2057 * Store original amount of characters passed in.
2058 * This helps to figure out if we should ask the FEP
2059 * to send us an event when it has more space available.
2063 DGNC_LOCK(ch->ch_lock, lock_flags);
2065 /* Get our space available for the channel from the board */
2067 head = (ch->ch_w_head) & tmask;
2068 tail = (ch->ch_w_tail) & tmask;
2070 if ((bufcount = tail - head - 1) < 0)
2071 bufcount += WQUEUESIZE;
2073 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
2074 __LINE__, bufcount, count, tail, head, tmask));
2077 * Limit printer output to maxcps overall, with bursts allowed
2078 * up to bufsize characters.
2080 bufcount = dgnc_maxcps_room(tty, bufcount);
2083 * Take minimum of what the user wants to send, and the
2084 * space available in the FEP buffer.
2086 count = min(count, bufcount);
2089 * Bail if no space left.
2092 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2097 * Output the printer ON string, if we are in terminal mode, but
2098 * need to be in printer mode.
2100 if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) {
2101 dgnc_wmove(ch, ch->ch_digi.digi_onstr,
2102 (int) ch->ch_digi.digi_onlen);
2103 head = (ch->ch_w_head) & tmask;
2104 ch->ch_flags |= CH_PRON;
2108 * On the other hand, output the printer OFF string, if we are
2109 * currently in printer mode, but need to output to the terminal.
2111 if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
2112 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
2113 (int) ch->ch_digi.digi_offlen);
2114 head = (ch->ch_w_head) & tmask;
2115 ch->ch_flags &= ~CH_PRON;
2119 * If there is nothing left to copy, or I can't handle any more data, leave.
2122 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2128 count = min(count, WRITEBUFLEN);
2130 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2133 * If data is coming from user space, copy it into a temporary
2134 * buffer so we don't get swapped out while doing the copy to
2137 /* we're allowed to block if it's from_user */
2138 if (down_interruptible(&dgnc_TmpWriteSem)) {
2143 * copy_from_user() returns the number
2144 * of bytes that could *NOT* be copied.
2146 count -= copy_from_user(dgnc_TmpWriteBuf, (const uchar __user *) buf, count);
2149 up(&dgnc_TmpWriteSem);
2153 DGNC_LOCK(ch->ch_lock, lock_flags);
2155 buf = dgnc_TmpWriteBuf;
2162 * If the write wraps over the top of the circular buffer,
2163 * move the portion up to the wrap point, and reset the
2164 * pointers to the bottom.
2166 remain = WQUEUESIZE - head;
2170 memcpy(ch->ch_wqueue + head, buf, remain);
2171 dgnc_sniff_nowait_nolock(ch, "USER WRITE", ch->ch_wqueue + head, remain);
2178 * Move rest of data.
2181 memcpy(ch->ch_wqueue + head, buf, remain);
2182 dgnc_sniff_nowait_nolock(ch, "USER WRITE", ch->ch_wqueue + head, remain);
2188 ch->ch_w_head = head;
2193 * If this is the print device, and the
2194 * printer is still on, we need to turn it
2195 * off before going idle.
2197 if (count == orig_count) {
2198 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
2200 ch->ch_w_head = head;
2201 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
2202 (int) ch->ch_digi.digi_offlen);
2203 head = (ch->ch_w_head) & tmask;
2204 ch->ch_flags &= ~CH_PRON;
2209 /* Update printer buffer empty time. */
2210 if ((un->un_type == DGNC_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2211 && (ch->ch_digi.digi_bufsize > 0)) {
2212 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2216 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2217 up(&dgnc_TmpWriteSem);
2219 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2222 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
2226 * Channel lock is grabbed and then released
2227 * inside this routine.
2229 ch->ch_bd->bd_ops->copy_data_from_queue_to_uart(ch);
2237 * Return modem signals to ld.
2239 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
2240 static int dgnc_tty_tiocmget(struct tty_struct *tty)
2242 static int dgnc_tty_tiocmget(struct tty_struct *tty, struct file *file)
2245 struct channel_t *ch;
2251 if (!tty || tty->magic != TTY_MAGIC)
2254 un = tty->driver_data;
2255 if (!un || un->magic != DGNC_UNIT_MAGIC)
2259 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2262 DPR_IOCTL(("dgnc_tty_tiocmget start\n"));
2264 DGNC_LOCK(ch->ch_lock, lock_flags);
2266 mstat = (ch->ch_mostat | ch->ch_mistat);
2268 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2272 if (mstat & UART_MCR_DTR)
2273 result |= TIOCM_DTR;
2274 if (mstat & UART_MCR_RTS)
2275 result |= TIOCM_RTS;
2276 if (mstat & UART_MSR_CTS)
2277 result |= TIOCM_CTS;
2278 if (mstat & UART_MSR_DSR)
2279 result |= TIOCM_DSR;
2280 if (mstat & UART_MSR_RI)
2282 if (mstat & UART_MSR_DCD)
2285 DPR_IOCTL(("dgnc_tty_tiocmget finish\n"));
2292 * dgnc_tty_tiocmset()
2294 * Set modem signals, called by ld.
2296 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
2297 static int dgnc_tty_tiocmset(struct tty_struct *tty,
2298 unsigned int set, unsigned int clear)
2300 static int dgnc_tty_tiocmset(struct tty_struct *tty, struct file *file,
2301 unsigned int set, unsigned int clear)
2305 struct channel_t *ch;
2310 if (!tty || tty->magic != TTY_MAGIC)
2313 un = tty->driver_data;
2314 if (!un || un->magic != DGNC_UNIT_MAGIC)
2318 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2322 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2325 DPR_IOCTL(("dgnc_tty_tiocmset start\n"));
2328 DGNC_LOCK(ch->ch_lock, lock_flags);
2330 if (set & TIOCM_RTS) {
2331 ch->ch_mostat |= UART_MCR_RTS;
2334 if (set & TIOCM_DTR) {
2335 ch->ch_mostat |= UART_MCR_DTR;
2338 if (clear & TIOCM_RTS) {
2339 ch->ch_mostat &= ~(UART_MCR_RTS);
2342 if (clear & TIOCM_DTR) {
2343 ch->ch_mostat &= ~(UART_MCR_DTR);
2346 ch->ch_bd->bd_ops->assert_modem_signals(ch);
2348 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2350 DPR_IOCTL(("dgnc_tty_tiocmset finish\n"));
2357 * dgnc_tty_send_break()
2359 * Send a Break, called by ld.
2361 static int dgnc_tty_send_break(struct tty_struct *tty, int msec)
2364 struct channel_t *ch;
2369 if (!tty || tty->magic != TTY_MAGIC)
2372 un = tty->driver_data;
2373 if (!un || un->magic != DGNC_UNIT_MAGIC)
2377 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2381 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2395 DPR_IOCTL(("dgnc_tty_send_break start 1. %lx\n", jiffies));
2397 DGNC_LOCK(ch->ch_lock, lock_flags);
2399 ch->ch_bd->bd_ops->send_break(ch, msec);
2401 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2403 DPR_IOCTL(("dgnc_tty_send_break finish\n"));
2411 * dgnc_tty_wait_until_sent()
2413 * wait until data has been transmitted, called by ld.
2415 static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2418 struct channel_t *ch;
2422 if (!tty || tty->magic != TTY_MAGIC)
2425 un = tty->driver_data;
2426 if (!un || un->magic != DGNC_UNIT_MAGIC)
2430 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2434 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2437 rc = bd->bd_ops->drain(tty, 0);
2439 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc));
2449 * send a high priority character, called by ld.
2451 static void dgnc_tty_send_xchar(struct tty_struct *tty, char c)
2454 struct channel_t *ch;
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)
2473 DPR_IOCTL(("dgnc_tty_send_xchar start\n"));
2474 printk("dgnc_tty_send_xchar start\n");
2476 DGNC_LOCK(ch->ch_lock, lock_flags);
2477 bd->bd_ops->send_immediate_char(ch, c);
2478 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2480 DPR_IOCTL(("dgnc_tty_send_xchar finish\n"));
2481 printk("dgnc_tty_send_xchar finish\n");
2489 * Return modem signals to ld.
2491 static inline int dgnc_get_mstat(struct channel_t *ch)
2493 unsigned char mstat;
2497 DPR_IOCTL(("dgnc_getmstat start\n"));
2499 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2502 DGNC_LOCK(ch->ch_lock, lock_flags);
2504 mstat = (ch->ch_mostat | ch->ch_mistat);
2506 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2510 if (mstat & UART_MCR_DTR)
2511 result |= TIOCM_DTR;
2512 if (mstat & UART_MCR_RTS)
2513 result |= TIOCM_RTS;
2514 if (mstat & UART_MSR_CTS)
2515 result |= TIOCM_CTS;
2516 if (mstat & UART_MSR_DSR)
2517 result |= TIOCM_DSR;
2518 if (mstat & UART_MSR_RI)
2520 if (mstat & UART_MSR_DCD)
2523 DPR_IOCTL(("dgnc_getmstat finish\n"));
2531 * Return modem signals to ld.
2533 static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value)
2538 DPR_IOCTL(("dgnc_get_modem_info start\n"));
2540 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2543 result = dgnc_get_mstat(ch);
2548 rc = put_user(result, value);
2550 DPR_IOCTL(("dgnc_get_modem_info finish\n"));
2556 * dgnc_set_modem_info()
2558 * Set modem signals, called by ld.
2560 static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
2563 struct channel_t *ch;
2566 unsigned int arg = 0;
2569 if (!tty || tty->magic != TTY_MAGIC)
2572 un = tty->driver_data;
2573 if (!un || un->magic != DGNC_UNIT_MAGIC)
2577 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2581 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2586 DPR_IOCTL(("dgnc_set_modem_info() start\n"));
2588 ret = get_user(arg, value);
2594 if (arg & TIOCM_RTS) {
2595 ch->ch_mostat |= UART_MCR_RTS;
2598 if (arg & TIOCM_DTR) {
2599 ch->ch_mostat |= UART_MCR_DTR;
2605 if (arg & TIOCM_RTS) {
2606 ch->ch_mostat &= ~(UART_MCR_RTS);
2609 if (arg & TIOCM_DTR) {
2610 ch->ch_mostat &= ~(UART_MCR_DTR);
2617 if (arg & TIOCM_RTS) {
2618 ch->ch_mostat |= UART_MCR_RTS;
2621 ch->ch_mostat &= ~(UART_MCR_RTS);
2624 if (arg & TIOCM_DTR) {
2625 ch->ch_mostat |= UART_MCR_DTR;
2628 ch->ch_mostat &= ~(UART_MCR_DTR);
2637 DGNC_LOCK(ch->ch_lock, lock_flags);
2639 ch->ch_bd->bd_ops->assert_modem_signals(ch);
2641 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2643 DPR_IOCTL(("dgnc_set_modem_info finish\n"));
2650 * dgnc_tty_digigeta()
2652 * Ioctl to get the information for ditty.
2657 static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
2659 struct channel_t *ch;
2667 if (!tty || tty->magic != TTY_MAGIC)
2670 un = tty->driver_data;
2671 if (!un || un->magic != DGNC_UNIT_MAGIC)
2675 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2678 memset(&tmp, 0, sizeof(tmp));
2680 DGNC_LOCK(ch->ch_lock, lock_flags);
2681 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
2682 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2684 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2692 * dgnc_tty_digiseta()
2694 * Ioctl to set the information for ditty.
2699 static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
2702 struct channel_t *ch;
2704 struct digi_t new_digi;
2707 DPR_IOCTL(("DIGI_SETA start\n"));
2709 if (!tty || tty->magic != TTY_MAGIC)
2712 un = tty->driver_data;
2713 if (!un || un->magic != DGNC_UNIT_MAGIC)
2717 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2721 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2724 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
2725 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
2729 DGNC_LOCK(ch->ch_lock, lock_flags);
2732 * Handle transistions to and from RTS Toggle.
2734 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && (new_digi.digi_flags & DIGI_RTS_TOGGLE))
2735 ch->ch_mostat &= ~(UART_MCR_RTS);
2736 if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
2737 ch->ch_mostat |= (UART_MCR_RTS);
2740 * Handle transistions to and from DTR Toggle.
2742 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && (new_digi.digi_flags & DIGI_DTR_TOGGLE))
2743 ch->ch_mostat &= ~(UART_MCR_DTR);
2744 if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
2745 ch->ch_mostat |= (UART_MCR_DTR);
2747 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
2749 if (ch->ch_digi.digi_maxcps < 1)
2750 ch->ch_digi.digi_maxcps = 1;
2752 if (ch->ch_digi.digi_maxcps > 10000)
2753 ch->ch_digi.digi_maxcps = 10000;
2755 if (ch->ch_digi.digi_bufsize < 10)
2756 ch->ch_digi.digi_bufsize = 10;
2758 if (ch->ch_digi.digi_maxchar < 1)
2759 ch->ch_digi.digi_maxchar = 1;
2761 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
2762 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
2764 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
2765 ch->ch_digi.digi_onlen = DIGI_PLEN;
2767 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
2768 ch->ch_digi.digi_offlen = DIGI_PLEN;
2770 ch->ch_bd->bd_ops->param(tty);
2772 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2774 DPR_IOCTL(("DIGI_SETA finish\n"));
2781 * dgnc_set_termios()
2783 static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2786 struct channel_t *ch;
2788 unsigned long lock_flags;
2790 if (!tty || tty->magic != TTY_MAGIC)
2793 un = tty->driver_data;
2794 if (!un || un->magic != DGNC_UNIT_MAGIC)
2798 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2802 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2805 DGNC_LOCK(ch->ch_lock, lock_flags);
2807 ch->ch_c_cflag = tty->termios.c_cflag;
2808 ch->ch_c_iflag = tty->termios.c_iflag;
2809 ch->ch_c_oflag = tty->termios.c_oflag;
2810 ch->ch_c_lflag = tty->termios.c_lflag;
2811 ch->ch_startc = tty->termios.c_cc[VSTART];
2812 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2814 ch->ch_bd->bd_ops->param(tty);
2817 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2821 static void dgnc_tty_throttle(struct tty_struct *tty)
2823 struct channel_t *ch;
2825 ulong lock_flags = 0;
2827 if (!tty || tty->magic != TTY_MAGIC)
2830 un = tty->driver_data;
2831 if (!un || un->magic != DGNC_UNIT_MAGIC)
2835 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2838 DPR_IOCTL(("dgnc_tty_throttle start\n"));
2840 DGNC_LOCK(ch->ch_lock, lock_flags);
2842 ch->ch_flags |= (CH_FORCED_STOPI);
2844 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2846 DPR_IOCTL(("dgnc_tty_throttle finish\n"));
2850 static void dgnc_tty_unthrottle(struct tty_struct *tty)
2852 struct channel_t *ch;
2856 if (!tty || tty->magic != TTY_MAGIC)
2859 un = tty->driver_data;
2860 if (!un || un->magic != DGNC_UNIT_MAGIC)
2864 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2867 DPR_IOCTL(("dgnc_tty_unthrottle start\n"));
2869 DGNC_LOCK(ch->ch_lock, lock_flags);
2871 ch->ch_flags &= ~(CH_FORCED_STOPI);
2873 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2875 DPR_IOCTL(("dgnc_tty_unthrottle finish\n"));
2879 static void dgnc_tty_start(struct tty_struct *tty)
2882 struct channel_t *ch;
2886 if (!tty || tty->magic != TTY_MAGIC)
2889 un = tty->driver_data;
2890 if (!un || un->magic != DGNC_UNIT_MAGIC)
2894 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2898 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2901 DPR_IOCTL(("dgcn_tty_start start\n"));
2903 DGNC_LOCK(ch->ch_lock, lock_flags);
2905 ch->ch_flags &= ~(CH_FORCED_STOP);
2907 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2909 DPR_IOCTL(("dgnc_tty_start finish\n"));
2913 static void dgnc_tty_stop(struct tty_struct *tty)
2916 struct channel_t *ch;
2920 if (!tty || tty->magic != TTY_MAGIC)
2923 un = tty->driver_data;
2924 if (!un || un->magic != DGNC_UNIT_MAGIC)
2928 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2932 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2935 DPR_IOCTL(("dgnc_tty_stop start\n"));
2937 DGNC_LOCK(ch->ch_lock, lock_flags);
2939 ch->ch_flags |= (CH_FORCED_STOP);
2941 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2943 DPR_IOCTL(("dgnc_tty_stop finish\n"));
2948 * dgnc_tty_flush_chars()
2950 * Flush the cook buffer
2952 * Note to self, and any other poor souls who venture here:
2954 * flush in this case DOES NOT mean dispose of the data.
2955 * instead, it means "stop buffering and send it if you
2956 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
2958 * It is also always called in interrupt context - JAR 8-Sept-99
2960 static void dgnc_tty_flush_chars(struct tty_struct *tty)
2963 struct channel_t *ch;
2967 if (!tty || tty->magic != TTY_MAGIC)
2970 un = tty->driver_data;
2971 if (!un || un->magic != DGNC_UNIT_MAGIC)
2975 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2979 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2982 DPR_IOCTL(("dgnc_tty_flush_chars start\n"));
2984 DGNC_LOCK(ch->ch_lock, lock_flags);
2986 /* Do something maybe here */
2988 DGNC_UNLOCK(ch->ch_lock, lock_flags);
2990 DPR_IOCTL(("dgnc_tty_flush_chars finish\n"));
2996 * dgnc_tty_flush_buffer()
2998 * Flush Tx buffer (make in == out)
3000 static void dgnc_tty_flush_buffer(struct tty_struct *tty)
3002 struct channel_t *ch;
3006 if (!tty || tty->magic != TTY_MAGIC)
3009 un = tty->driver_data;
3010 if (!un || un->magic != DGNC_UNIT_MAGIC)
3014 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
3017 DPR_IOCTL(("dgnc_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
3019 DGNC_LOCK(ch->ch_lock, lock_flags);
3021 ch->ch_flags &= ~CH_STOP;
3023 /* Flush our write queue */
3024 ch->ch_w_head = ch->ch_w_tail;
3026 /* Flush UARTs transmit FIFO */
3027 ch->ch_bd->bd_ops->flush_uart_write(ch);
3029 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3030 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3031 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3033 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3034 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3035 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3038 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3040 DPR_IOCTL(("dgnc_tty_flush_buffer finish\n"));
3045 /*****************************************************************************
3047 * The IOCTL function and all of its helpers
3049 *****************************************************************************/
3054 * The usual assortment of ioctl's
3056 static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3060 struct channel_t *ch;
3064 void __user *uarg = (void __user *) arg;
3066 if (!tty || tty->magic != TTY_MAGIC)
3069 un = tty->driver_data;
3070 if (!un || un->magic != DGNC_UNIT_MAGIC)
3074 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
3078 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
3081 DPR_IOCTL(("dgnc_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
3082 ch->ch_portnum, dgnc_ioctl_name(cmd), cmd, arg));
3084 DGNC_LOCK(ch->ch_lock, lock_flags);
3086 if (un->un_open_count <= 0) {
3087 DPR_BASIC(("dgnc_tty_ioctl - unit not open.\n"));
3088 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3094 /* Here are all the standard ioctl's that we MUST implement */
3098 * TCSBRK is SVID version: non-zero arg --> no break
3099 * this behaviour is exploited by tcdrain().
3101 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3102 * between 0.25 and 0.5 seconds so we'll ask for something
3103 * in the middle: 0.375 seconds.
3105 rc = tty_check_change(tty);
3106 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3111 rc = ch->ch_bd->bd_ops->drain(tty, 0);
3114 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc));
3118 DGNC_LOCK(ch->ch_lock, lock_flags);
3120 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
3121 ch->ch_bd->bd_ops->send_break(ch, 250);
3124 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3126 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3127 ch->ch_portnum, dgnc_ioctl_name(cmd), cmd, arg));
3133 /* support for POSIX tcsendbreak()
3134 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3135 * between 0.25 and 0.5 seconds so we'll ask for something
3136 * in the middle: 0.375 seconds.
3138 rc = tty_check_change(tty);
3139 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3144 rc = ch->ch_bd->bd_ops->drain(tty, 0);
3146 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc));
3150 DGNC_LOCK(ch->ch_lock, lock_flags);
3152 ch->ch_bd->bd_ops->send_break(ch, 250);
3154 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3156 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3157 ch->ch_portnum, dgnc_ioctl_name(cmd), cmd, arg));
3162 rc = tty_check_change(tty);
3163 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3168 rc = ch->ch_bd->bd_ops->drain(tty, 0);
3170 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc));
3174 DGNC_LOCK(ch->ch_lock, lock_flags);
3176 ch->ch_bd->bd_ops->send_break(ch, 250);
3178 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3180 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3181 ch->ch_portnum, dgnc_ioctl_name(cmd), cmd, arg));
3187 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3192 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3194 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
3199 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3200 rc = get_user(arg, (unsigned long __user *) arg);
3204 DGNC_LOCK(ch->ch_lock, lock_flags);
3205 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
3206 ch->ch_bd->bd_ops->param(tty);
3207 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3212 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3213 return(dgnc_get_modem_info(ch, uarg));
3218 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3219 return(dgnc_set_modem_info(tty, cmd, uarg));
3222 * Here are any additional ioctl's that we want to implement
3227 * The linux tty driver doesn't have a flush
3228 * input routine for the driver, assuming all backed
3229 * up data is in the line disc. buffers. However,
3230 * we all know that's not the case. Here, we
3231 * act on the ioctl, but then lie and say we didn't
3232 * so the line discipline will process the flush
3235 rc = tty_check_change(tty);
3237 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3241 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3242 ch->ch_r_head = ch->ch_r_tail;
3243 ch->ch_bd->bd_ops->flush_uart_read(ch);
3244 /* Force queue flow control to be released, if needed */
3245 dgnc_check_queue_flow_control(ch);
3248 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
3249 if (!(un->un_type == DGNC_PRINT)) {
3250 ch->ch_w_head = ch->ch_w_tail;
3251 ch->ch_bd->bd_ops->flush_uart_write(ch);
3253 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3254 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3255 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3258 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3259 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3260 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3266 /* pretend we didn't recognize this IOCTL */
3267 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3268 return(-ENOIOCTLCMD);
3272 * The linux tty driver doesn't have a flush
3273 * input routine for the driver, assuming all backed
3274 * up data is in the line disc. buffers. However,
3275 * we all know that's not the case. Here, we
3276 * act on the ioctl, but then lie and say we didn't
3277 * so the line discipline will process the flush
3280 if (cmd == TCSETSF) {
3282 ch->ch_flags &= ~CH_STOP;
3283 ch->ch_r_head = ch->ch_r_tail;
3284 ch->ch_bd->bd_ops->flush_uart_read(ch);
3285 /* Force queue flow control to be released, if needed */
3286 dgnc_check_queue_flow_control(ch);
3289 /* now wait for all the output to drain */
3290 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3291 rc = ch->ch_bd->bd_ops->drain(tty, 0);
3293 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d\n", rc));
3297 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3298 ch->ch_portnum, dgnc_ioctl_name(cmd), cmd, arg));
3300 /* pretend we didn't recognize this */
3301 return(-ENOIOCTLCMD);
3305 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3306 rc = ch->ch_bd->bd_ops->drain(tty, 0);
3308 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc));
3312 /* pretend we didn't recognize this */
3313 return(-ENOIOCTLCMD);
3316 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3317 /* Make the ld do it */
3318 return(-ENOIOCTLCMD);
3321 /* get information for ditty */
3322 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3323 return(dgnc_tty_digigeta(tty, uarg));
3328 /* set information for ditty */
3329 if (cmd == (DIGI_SETAW)) {
3331 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3332 rc = ch->ch_bd->bd_ops->drain(tty, 0);
3334 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc));
3337 DGNC_LOCK(ch->ch_lock, lock_flags);
3340 tty_ldisc_flush(tty);
3345 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3346 return(dgnc_tty_digiseta(tty, uarg));
3351 /* Let go of locks when accessing user space, could sleep */
3352 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3353 rc = get_user(loopback, (unsigned int __user *) arg);
3356 DGNC_LOCK(ch->ch_lock, lock_flags);
3358 /* Enable/disable internal loopback for this port */
3360 ch->ch_flags |= CH_LOOPBACK;
3362 ch->ch_flags &= ~(CH_LOOPBACK);
3364 ch->ch_bd->bd_ops->param(tty);
3365 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3369 case DIGI_GETCUSTOMBAUD:
3370 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3371 rc = put_user(ch->ch_custom_speed, (unsigned int __user *) arg);
3374 case DIGI_SETCUSTOMBAUD:
3377 /* Let go of locks when accessing user space, could sleep */
3378 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3379 rc = get_user(new_rate, (unsigned int __user *) arg);
3382 DGNC_LOCK(ch->ch_lock, lock_flags);
3383 dgnc_set_custom_speed(ch, new_rate);
3384 ch->ch_bd->bd_ops->param(tty);
3385 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3390 * This ioctl allows insertion of a character into the front
3391 * of any pending data to be transmitted.
3393 * This ioctl is to satify the "Send Character Immediate"
3394 * call that the RealPort protocol spec requires.
3396 case DIGI_REALPORT_SENDIMMEDIATE:
3399 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3400 rc = get_user(c, (unsigned char __user *) arg);
3403 DGNC_LOCK(ch->ch_lock, lock_flags);
3404 ch->ch_bd->bd_ops->send_immediate_char(ch, c);
3405 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3410 * This ioctl returns all the current counts for the port.
3412 * This ioctl is to satify the "Line Error Counters"
3413 * call that the RealPort protocol spec requires.
3415 case DIGI_REALPORT_GETCOUNTERS:
3417 struct digi_getcounter buf;
3419 buf.norun = ch->ch_err_overrun;
3420 buf.noflow = 0; /* The driver doesn't keep this stat */
3421 buf.nframe = ch->ch_err_frame;
3422 buf.nparity = ch->ch_err_parity;
3423 buf.nbreak = ch->ch_err_break;
3424 buf.rbytes = ch->ch_rxcount;
3425 buf.tbytes = ch->ch_txcount;
3427 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3429 if (copy_to_user(uarg, &buf, sizeof(struct digi_getcounter))) {
3436 * This ioctl returns all current events.
3438 * This ioctl is to satify the "Event Reporting"
3439 * call that the RealPort protocol spec requires.
3441 case DIGI_REALPORT_GETEVENTS:
3443 unsigned int events = 0;
3445 /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
3446 if (ch->ch_flags & CH_BREAK_SENDING)
3448 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP)) {
3449 events |= (EV_OPU | EV_OPS);
3451 if ((ch->ch_flags & CH_STOPI) || (ch->ch_flags & CH_FORCED_STOPI)) {
3452 events |= (EV_IPU | EV_IPS);
3455 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3456 rc = put_user(events, (unsigned int __user *) arg);
3461 * This ioctl returns TOUT and TIN counters based
3462 * upon the values passed in by the RealPort Server.
3463 * It also passes back whether the UART Transmitter is
3466 case DIGI_REALPORT_GETBUFFERS:
3468 struct digi_getbuffer buf;
3472 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3475 * Get data from user first.
3477 if (copy_from_user(&buf, uarg, sizeof(struct digi_getbuffer))) {
3481 DGNC_LOCK(ch->ch_lock, lock_flags);
3484 * Figure out how much data is in our RX and TX queues.
3486 buf.rxbuf = (ch->ch_r_head - ch->ch_r_tail) & RQUEUEMASK;
3487 buf.txbuf = (ch->ch_w_head - ch->ch_w_tail) & WQUEUEMASK;
3490 * Is the UART empty? Add that value to whats in our TX queue.
3492 count = buf.txbuf + ch->ch_bd->bd_ops->get_uart_bytes_left(ch);
3495 * Figure out how much data the RealPort Server believes should
3496 * be in our TX queue.
3498 tdist = (buf.tIn - buf.tOut) & 0xffff;
3501 * If we have more data than the RealPort Server believes we
3502 * should have, reduce our count to its amount.
3504 * This count difference CAN happen because the Linux LD can
3505 * insert more characters into our queue for OPOST processing
3506 * that the RealPort Server doesn't know about.
3508 if (buf.txbuf > tdist) {
3513 * Report whether our queue and UART TX are completely empty.
3521 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3523 if (copy_to_user(uarg, &buf, sizeof(struct digi_getbuffer))) {
3529 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3531 DPR_IOCTL(("dgnc_tty_ioctl - in default\n"));
3532 DPR_IOCTL(("dgnc_tty_ioctl end - cmd %s (%x), arg %lx\n",
3533 dgnc_ioctl_name(cmd), cmd, arg));
3535 return(-ENOIOCTLCMD);
3538 DGNC_UNLOCK(ch->ch_lock, lock_flags);
3540 DPR_IOCTL(("dgnc_tty_ioctl end - cmd %s (%x), arg %lx\n",
3541 dgnc_ioctl_name(cmd), cmd, arg));