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.
16 /************************************************************************
18 * This file implements the tty driver functionality for the
19 * Neo and ClassicBoard PCI based product lines.
21 ************************************************************************
25 #include <linux/kernel.h>
26 #include <linux/sched.h> /* For jiffies, task states */
27 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
28 #include <linux/module.h>
29 #include <linux/ctype.h>
30 #include <linux/tty.h>
31 #include <linux/tty_flip.h>
32 #include <linux/types.h>
33 #include <linux/serial_reg.h>
34 #include <linux/slab.h>
35 #include <linux/delay.h> /* For udelay */
36 #include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
37 #include <linux/pci.h>
38 #include "dgnc_driver.h"
42 #include "dgnc_sysfs.h"
43 #include "dgnc_utils.h"
48 static unsigned char *dgnc_TmpWriteBuf;
51 * Default transparent print information.
53 static struct digi_t dgnc_digi_init = {
54 .digi_flags = DIGI_COOK, /* Flags */
55 .digi_maxcps = 100, /* Max CPS */
56 .digi_maxchar = 50, /* Max chars in print queue */
57 .digi_bufsize = 100, /* Printer buffer size */
58 .digi_onlen = 4, /* size of printer on string */
59 .digi_offlen = 4, /* size of printer off string */
60 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
61 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
62 .digi_term = "ansi" /* default terminal type */
66 * Define a local default termios struct. All ports will be created
67 * with this termios initially.
69 * This defines a raw port at 9600 baud, 8 data bits, no parity,
72 static struct ktermios DgncDefaultTermios = {
73 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
74 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
75 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
76 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
81 /* Our function prototypes */
82 static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
83 static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
84 static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file,
85 struct channel_t *ch);
86 static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
88 static int dgnc_tty_digigeta(struct tty_struct *tty,
89 struct digi_t __user *retinfo);
90 static int dgnc_tty_digiseta(struct tty_struct *tty,
91 struct digi_t __user *new_info);
92 static int dgnc_tty_write_room(struct tty_struct *tty);
93 static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c);
94 static int dgnc_tty_chars_in_buffer(struct tty_struct *tty);
95 static void dgnc_tty_start(struct tty_struct *tty);
96 static void dgnc_tty_stop(struct tty_struct *tty);
97 static void dgnc_tty_throttle(struct tty_struct *tty);
98 static void dgnc_tty_unthrottle(struct tty_struct *tty);
99 static void dgnc_tty_flush_chars(struct tty_struct *tty);
100 static void dgnc_tty_flush_buffer(struct tty_struct *tty);
101 static void dgnc_tty_hangup(struct tty_struct *tty);
102 static int dgnc_set_modem_info(struct channel_t *ch, unsigned int command,
103 unsigned int __user *value);
104 static int dgnc_get_modem_info(struct channel_t *ch,
105 unsigned int __user *value);
106 static int dgnc_tty_tiocmget(struct tty_struct *tty);
107 static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set,
109 static int dgnc_tty_send_break(struct tty_struct *tty, int msec);
110 static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout);
111 static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf,
113 static void dgnc_tty_set_termios(struct tty_struct *tty,
114 struct ktermios *old_termios);
115 static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
117 static const struct tty_operations dgnc_tty_ops = {
118 .open = dgnc_tty_open,
119 .close = dgnc_tty_close,
120 .write = dgnc_tty_write,
121 .write_room = dgnc_tty_write_room,
122 .flush_buffer = dgnc_tty_flush_buffer,
123 .chars_in_buffer = dgnc_tty_chars_in_buffer,
124 .flush_chars = dgnc_tty_flush_chars,
125 .ioctl = dgnc_tty_ioctl,
126 .set_termios = dgnc_tty_set_termios,
127 .stop = dgnc_tty_stop,
128 .start = dgnc_tty_start,
129 .throttle = dgnc_tty_throttle,
130 .unthrottle = dgnc_tty_unthrottle,
131 .hangup = dgnc_tty_hangup,
132 .put_char = dgnc_tty_put_char,
133 .tiocmget = dgnc_tty_tiocmget,
134 .tiocmset = dgnc_tty_tiocmset,
135 .break_ctl = dgnc_tty_send_break,
136 .wait_until_sent = dgnc_tty_wait_until_sent,
137 .send_xchar = dgnc_tty_send_xchar
140 /************************************************************************
142 * TTY Initialization/Cleanup Functions
144 ************************************************************************/
149 * Initialize any global tty related data before we download any boards.
151 int dgnc_tty_preinit(void)
154 * Allocate a buffer for doing the copy from user space to
155 * kernel space in dgnc_write(). We only use one buffer and
156 * control access to it with a semaphore. If we are paging, we
157 * are already in trouble so one buffer won't hurt much anyway.
159 * We are okay to sleep in the malloc, as this routine
160 * is only called during module load, (not in interrupt context),
161 * and with no locks held.
163 dgnc_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_KERNEL);
165 if (!dgnc_TmpWriteBuf)
172 * dgnc_tty_register()
174 * Init the tty subsystem for this board.
176 int dgnc_tty_register(struct dgnc_board *brd)
180 brd->serial_driver = tty_alloc_driver(brd->maxports,
181 TTY_DRIVER_REAL_RAW |
182 TTY_DRIVER_DYNAMIC_DEV |
183 TTY_DRIVER_HARDWARE_BREAK);
185 if (IS_ERR(brd->serial_driver))
186 return PTR_ERR(brd->serial_driver);
188 snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgnc_%d_",
191 brd->serial_driver->name = brd->serial_name;
192 brd->serial_driver->name_base = 0;
193 brd->serial_driver->major = 0;
194 brd->serial_driver->minor_start = 0;
195 brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
196 brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
197 brd->serial_driver->init_termios = DgncDefaultTermios;
198 brd->serial_driver->driver_name = DRVSTR;
201 * Entry points for driver. Called by the kernel from
202 * tty_io.c and n_tty.c.
204 tty_set_operations(brd->serial_driver, &dgnc_tty_ops);
206 rc = tty_register_driver(brd->serial_driver);
208 dev_dbg(&brd->pdev->dev,
209 "Can't register tty device (%d)\n", rc);
210 goto free_serial_driver;
214 * If we're doing transparent print, we have to do all of the above
215 * again, separately so we don't get the LD confused about what major
216 * we are when we get into the dgnc_tty_open() routine.
218 brd->print_driver = tty_alloc_driver(brd->maxports,
219 TTY_DRIVER_REAL_RAW |
220 TTY_DRIVER_DYNAMIC_DEV |
221 TTY_DRIVER_HARDWARE_BREAK);
223 if (IS_ERR(brd->print_driver)) {
224 rc = PTR_ERR(brd->print_driver);
225 goto unregister_serial_driver;
228 snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
230 brd->print_driver->name = brd->print_name;
231 brd->print_driver->name_base = 0;
232 brd->print_driver->major = brd->serial_driver->major;
233 brd->print_driver->minor_start = 0x80;
234 brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
235 brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
236 brd->print_driver->init_termios = DgncDefaultTermios;
237 brd->print_driver->driver_name = DRVSTR;
240 * Entry points for driver. Called by the kernel from
241 * tty_io.c and n_tty.c.
243 tty_set_operations(brd->print_driver, &dgnc_tty_ops);
245 rc = tty_register_driver(brd->print_driver);
247 dev_dbg(&brd->pdev->dev,
248 "Can't register Transparent Print device(%d)\n",
250 goto free_print_driver;
256 put_tty_driver(brd->print_driver);
257 unregister_serial_driver:
258 tty_unregister_driver(brd->serial_driver);
260 put_tty_driver(brd->serial_driver);
265 void dgnc_tty_unregister(struct dgnc_board *brd)
267 tty_unregister_driver(brd->print_driver);
268 tty_unregister_driver(brd->serial_driver);
269 put_tty_driver(brd->print_driver);
270 put_tty_driver(brd->serial_driver);
276 * Init the tty subsystem. Called once per board after board has been
277 * downloaded and init'ed.
279 int dgnc_tty_init(struct dgnc_board *brd)
283 struct channel_t *ch;
289 * Initialize board structure elements.
292 vaddr = brd->re_map_membase;
294 brd->nasync = brd->maxports;
296 for (i = 0; i < brd->nasync; i++) {
298 * Okay to malloc with GFP_KERNEL, we are not at
299 * interrupt context, and there are no locks held.
301 brd->channels[i] = kzalloc(sizeof(*brd->channels[i]),
303 if (!brd->channels[i])
304 goto err_free_channels;
307 ch = brd->channels[0];
308 vaddr = brd->re_map_membase;
310 /* Set up channel variables */
311 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
312 spin_lock_init(&ch->ch_lock);
314 /* Store all our magic numbers */
315 ch->magic = DGNC_CHANNEL_MAGIC;
316 ch->ch_tun.magic = DGNC_UNIT_MAGIC;
317 ch->ch_tun.un_ch = ch;
318 ch->ch_tun.un_type = DGNC_SERIAL;
319 ch->ch_tun.un_dev = i;
321 ch->ch_pun.magic = DGNC_UNIT_MAGIC;
322 ch->ch_pun.un_ch = ch;
323 ch->ch_pun.un_type = DGNC_PRINT;
324 ch->ch_pun.un_dev = i + 128;
326 if (brd->bd_uart_offset == 0x200)
327 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
329 ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
333 ch->ch_digi = dgnc_digi_init;
335 /* .25 second delay */
336 ch->ch_close_delay = 250;
338 init_waitqueue_head(&ch->ch_flags_wait);
339 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
340 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
343 struct device *classp;
345 classp = tty_register_device(brd->serial_driver, i,
346 &ch->ch_bd->pdev->dev);
347 ch->ch_tun.un_sysfs = classp;
348 dgnc_create_tty_sysfs(&ch->ch_tun, classp);
350 classp = tty_register_device(brd->print_driver, i,
351 &ch->ch_bd->pdev->dev);
352 ch->ch_pun.un_sysfs = classp;
353 dgnc_create_tty_sysfs(&ch->ch_pun, classp);
360 for (i = i - 1; i >= 0; --i) {
361 kfree(brd->channels[i]);
362 brd->channels[i] = NULL;
368 * dgnc_tty_post_uninit()
370 * UnInitialize any global tty related data.
372 void dgnc_tty_post_uninit(void)
374 kfree(dgnc_TmpWriteBuf);
375 dgnc_TmpWriteBuf = NULL;
381 * Uninitialize the TTY portion of this driver. Free all memory and
384 void dgnc_cleanup_tty(struct dgnc_board *brd)
388 for (i = 0; i < brd->nasync; i++) {
389 if (brd->channels[i])
390 dgnc_remove_tty_sysfs(brd->channels[i]->
392 tty_unregister_device(brd->serial_driver, i);
394 tty_unregister_driver(brd->serial_driver);
396 for (i = 0; i < brd->nasync; i++) {
397 if (brd->channels[i])
398 dgnc_remove_tty_sysfs(brd->channels[i]->
400 tty_unregister_device(brd->print_driver, i);
402 tty_unregister_driver(brd->print_driver);
404 put_tty_driver(brd->serial_driver);
405 put_tty_driver(brd->print_driver);
409 * dgnc_wmove - Write data to transmit queue.
411 * ch - Pointer to channel structure.
412 * buf - Pointer to characters to be moved.
413 * n - Number of characters to move.
415 static void dgnc_wmove(struct channel_t *ch, char *buf, uint n)
420 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
423 head = ch->ch_w_head & WQUEUEMASK;
426 * If the write wraps over the top of the circular buffer,
427 * move the portion up to the wrap point, and reset the
428 * pointers to the bottom.
430 remain = WQUEUESIZE - head;
434 memcpy(ch->ch_wqueue + head, buf, remain);
444 memcpy(ch->ch_wqueue + head, buf, remain);
449 ch->ch_w_head = head;
453 * dgnc_input - Process received data.
455 * ch - Pointer to channel structure.
457 void dgnc_input(struct channel_t *ch)
459 struct dgnc_board *bd;
460 struct tty_struct *tp;
461 struct tty_ldisc *ld = NULL;
473 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
476 tp = ch->ch_tun.un_tty;
479 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
482 spin_lock_irqsave(&ch->ch_lock, flags);
485 * Figure the number of characters in the buffer.
486 * Exit immediately if none.
489 head = ch->ch_r_head & rmask;
490 tail = ch->ch_r_tail & rmask;
491 data_len = (head - tail) & rmask;
497 * If the device is not open, or CREAD is off,
498 * flush input data and return immediately.
500 if (!tp || (tp->magic != TTY_MAGIC) ||
501 !(ch->ch_tun.un_flags & UN_ISOPEN) ||
503 (ch->ch_tun.un_flags & UN_CLOSING)) {
504 ch->ch_r_head = tail;
506 /* Force queue flow control to be released, if needed */
507 dgnc_check_queue_flow_control(ch);
513 * If we are throttled, simply don't read any data.
515 if (ch->ch_flags & CH_FORCED_STOPI)
518 flip_len = TTY_FLIPBUF_SIZE;
520 /* Chop down the length, if needed */
521 len = min(data_len, flip_len);
522 len = min(len, (N_TTY_BUF_SIZE - 1));
524 ld = tty_ldisc_ref(tp);
527 * If we were unable to get a reference to the ld,
528 * don't flush our buffer, and act like the ld doesn't
529 * have any space to put the data right now.
535 * If ld doesn't have a pointer to a receive_buf function,
536 * flush the data, then act like the ld doesn't have any
537 * space to put the data right now.
539 if (!ld->ops->receive_buf) {
540 ch->ch_r_head = ch->ch_r_tail;
549 * The tty layer in the kernel has changed in 2.6.16+.
551 * The flip buffers in the tty structure are no longer exposed,
552 * and probably will be going away eventually.
554 * If we are completely raw, we don't need to go through a lot
555 * of the tty layers that exist.
556 * In this case, we take the shortest and fastest route we
557 * can to relay the data to the user.
559 * On the other hand, if we are not raw, we need to go through
560 * the new 2.6.16+ tty layer, which has its API more well defined.
562 len = tty_buffer_request_room(tp->port, len);
566 * n now contains the most amount of data we can copy,
567 * bounded either by how much the Linux tty layer can handle,
568 * or the amount of data the card actually has pending...
571 unsigned char *ch_pos = ch->ch_equeue + tail;
573 s = ((head >= tail) ? head : RQUEUESIZE) - tail;
580 * If conditions are such that ld needs to see all
581 * UART errors, we will have to walk each character
582 * and error byte and send them to the buffer one at
585 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
586 for (i = 0; i < s; i++) {
587 unsigned char ch = *(ch_pos + i);
588 char flag = TTY_NORMAL;
590 if (ch & UART_LSR_BI)
592 else if (ch & UART_LSR_PE)
594 else if (ch & UART_LSR_FE)
597 tty_insert_flip_char(tp->port, ch, flag);
600 tty_insert_flip_string(tp->port, ch_pos, s);
605 /* Flip queue if needed */
609 ch->ch_r_tail = tail & rmask;
610 ch->ch_e_tail = tail & rmask;
611 dgnc_check_queue_flow_control(ch);
612 spin_unlock_irqrestore(&ch->ch_lock, flags);
614 /* Tell the tty layer its okay to "eat" the data now */
615 tty_flip_buffer_push(tp->port);
622 spin_unlock_irqrestore(&ch->ch_lock, flags);
627 /************************************************************************
628 * Determines when CARRIER changes state and takes appropriate
630 ************************************************************************/
631 void dgnc_carrier(struct channel_t *ch)
633 int virt_carrier = 0;
634 int phys_carrier = 0;
636 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
639 if (ch->ch_mistat & UART_MSR_DCD)
642 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
645 if (ch->ch_c_cflag & CLOCAL)
649 * Test for a VIRTUAL carrier transition to HIGH.
651 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
653 * When carrier rises, wake any threads waiting
654 * for carrier in the open routine.
657 if (waitqueue_active(&ch->ch_flags_wait))
658 wake_up_interruptible(&ch->ch_flags_wait);
662 * Test for a PHYSICAL carrier transition to HIGH.
664 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
666 * When carrier rises, wake any threads waiting
667 * for carrier in the open routine.
670 if (waitqueue_active(&ch->ch_flags_wait))
671 wake_up_interruptible(&ch->ch_flags_wait);
675 * Test for a PHYSICAL transition to low, so long as we aren't
676 * currently ignoring physical transitions (which is what "virtual
677 * carrier" indicates).
679 * The transition of the virtual carrier to low really doesn't
680 * matter... it really only means "ignore carrier state", not
681 * "make pretend that carrier is there".
683 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
684 (phys_carrier == 0)) {
686 * When carrier drops:
688 * Drop carrier on all open units.
690 * Flush queues, waking up any task waiting in the
693 * Send a hangup to the control terminal.
695 * Enable all select calls.
697 if (waitqueue_active(&ch->ch_flags_wait))
698 wake_up_interruptible(&ch->ch_flags_wait);
700 if (ch->ch_tun.un_open_count > 0)
701 tty_hangup(ch->ch_tun.un_tty);
703 if (ch->ch_pun.un_open_count > 0)
704 tty_hangup(ch->ch_pun.un_tty);
708 * Make sure that our cached values reflect the current reality.
710 if (virt_carrier == 1)
711 ch->ch_flags |= CH_FCAR;
713 ch->ch_flags &= ~CH_FCAR;
715 if (phys_carrier == 1)
716 ch->ch_flags |= CH_CD;
718 ch->ch_flags &= ~CH_CD;
722 * Assign the custom baud rate to the channel structure
724 static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
733 ch->ch_custom_speed = 0;
738 * Since the divisor is stored in a 16-bit integer, we make sure
739 * we don't allow any rates smaller than a 16-bit integer would allow.
740 * And of course, rates above the dividend won't fly.
742 if (newrate && newrate < ((ch->ch_bd->bd_dividend / 0xFFFF) + 1))
743 newrate = (ch->ch_bd->bd_dividend / 0xFFFF) + 1;
745 if (newrate && newrate > ch->ch_bd->bd_dividend)
746 newrate = ch->ch_bd->bd_dividend;
749 testdiv = ch->ch_bd->bd_dividend / newrate;
752 * If we try to figure out what rate the board would use
753 * with the test divisor, it will be either equal or higher
754 * than the requested baud rate. If we then determine the
755 * rate with a divisor one higher, we will get the next lower
756 * supported rate below the requested.
758 testrate_high = ch->ch_bd->bd_dividend / testdiv;
759 testrate_low = ch->ch_bd->bd_dividend / (testdiv + 1);
762 * If the rate for the requested divisor is correct, just
763 * use it and be done.
765 if (testrate_high != newrate) {
767 * Otherwise, pick the rate that is closer
768 * (i.e. whichever rate has a smaller delta).
770 deltahigh = testrate_high - newrate;
771 deltalow = newrate - testrate_low;
773 if (deltahigh < deltalow)
774 newrate = testrate_high;
776 newrate = testrate_low;
780 ch->ch_custom_speed = newrate;
783 void dgnc_check_queue_flow_control(struct channel_t *ch)
787 /* Store how much space we have left in the queue */
788 qleft = ch->ch_r_tail - ch->ch_r_head - 1;
790 qleft += RQUEUEMASK + 1;
793 * Check to see if we should enforce flow control on our queue because
794 * the ld (or user) isn't reading data out of our queue fast enuf.
796 * NOTE: This is done based on what the current flow control of the
799 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
800 * This will cause the UART's FIFO to back up, and force
801 * the RTS signal to be dropped.
802 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
803 * the other side, in hopes it will stop sending data to us.
804 * 3) NONE - Nothing we can do. We will simply drop any extra data
805 * that gets sent into us when the queue fills up.
809 if (ch->ch_digi.digi_flags & CTSPACE ||
810 ch->ch_c_cflag & CRTSCTS) {
811 if (!(ch->ch_flags & CH_RECEIVER_OFF)) {
812 ch->ch_bd->bd_ops->disable_receiver(ch);
813 ch->ch_flags |= (CH_RECEIVER_OFF);
817 else if (ch->ch_c_iflag & IXOFF) {
818 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
819 ch->ch_bd->bd_ops->send_stop_character(ch);
826 * Check to see if we should unenforce flow control because
827 * ld (or user) finally read enuf data out of our queue.
829 * NOTE: This is done based on what the current flow control of the
832 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
833 * This will cause the UART's FIFO to raise RTS back up,
834 * which will allow the other side to start sending data again.
835 * 2) SWFLOW (IXOFF) - Send a start character to
836 * the other side, so it will start sending data to us again.
837 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
838 * other side, we don't need to do anything now.
840 if (qleft > (RQUEUESIZE / 2)) {
842 if (ch->ch_digi.digi_flags & RTSPACE ||
843 ch->ch_c_cflag & CRTSCTS) {
844 if (ch->ch_flags & CH_RECEIVER_OFF) {
845 ch->ch_bd->bd_ops->enable_receiver(ch);
846 ch->ch_flags &= ~(CH_RECEIVER_OFF);
850 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
851 ch->ch_stops_sent = 0;
852 ch->ch_bd->bd_ops->send_start_character(ch);
857 void dgnc_wakeup_writes(struct channel_t *ch)
862 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
865 spin_lock_irqsave(&ch->ch_lock, flags);
868 * If channel now has space, wake up anyone waiting on the condition.
870 qlen = ch->ch_w_head - ch->ch_w_tail;
874 if (qlen >= (WQUEUESIZE - 256)) {
875 spin_unlock_irqrestore(&ch->ch_lock, flags);
879 if (ch->ch_tun.un_flags & UN_ISOPEN) {
880 tty_wakeup(ch->ch_tun.un_tty);
883 * If unit is set to wait until empty, check to make sure
884 * the queue AND FIFO are both empty.
886 if (ch->ch_tun.un_flags & UN_EMPTY) {
888 (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
889 ch->ch_tun.un_flags &= ~(UN_EMPTY);
892 * If RTS Toggle mode is on, whenever
893 * the queue and UART is empty, keep RTS low.
895 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
896 ch->ch_mostat &= ~(UART_MCR_RTS);
897 ch->ch_bd->bd_ops->assert_modem_signals(ch);
901 * If DTR Toggle mode is on, whenever
902 * the queue and UART is empty, keep DTR low.
904 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
905 ch->ch_mostat &= ~(UART_MCR_DTR);
906 ch->ch_bd->bd_ops->assert_modem_signals(ch);
911 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
914 if (ch->ch_pun.un_flags & UN_ISOPEN) {
915 tty_wakeup(ch->ch_pun.un_tty);
918 * If unit is set to wait until empty, check to make sure
919 * the queue AND FIFO are both empty.
921 if (ch->ch_pun.un_flags & UN_EMPTY) {
923 (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0))
924 ch->ch_pun.un_flags &= ~(UN_EMPTY);
927 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
930 spin_unlock_irqrestore(&ch->ch_lock, flags);
933 struct dgnc_board *find_board_by_major(unsigned int major)
937 for (i = 0; i < MAXBOARDS; i++) {
938 struct dgnc_board *brd = dgnc_board[i];
943 if (major == brd->serial_driver->major ||
944 major == brd->print_driver->major)
951 /************************************************************************
953 * TTY Entry points and helper functions
955 ************************************************************************/
961 static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
963 struct dgnc_board *brd;
964 struct channel_t *ch;
973 major = MAJOR(tty_devnum(tty));
974 minor = MINOR(tty_devnum(tty));
979 /* Get board pointer from our array of majors we have allocated */
980 brd = find_board_by_major(major);
985 * If board is not yet up to a state of READY, go to
986 * sleep waiting for it to happen or they cancel the open.
988 rc = wait_event_interruptible(brd->state_wait,
989 (brd->state & BOARD_READY));
994 spin_lock_irqsave(&brd->bd_lock, flags);
996 /* If opened device is greater than our number of ports, bail. */
997 if (PORT_NUM(minor) >= brd->nasync) {
998 spin_unlock_irqrestore(&brd->bd_lock, flags);
1002 ch = brd->channels[PORT_NUM(minor)];
1004 spin_unlock_irqrestore(&brd->bd_lock, flags);
1008 /* Drop board lock */
1009 spin_unlock_irqrestore(&brd->bd_lock, flags);
1011 /* Grab channel lock */
1012 spin_lock_irqsave(&ch->ch_lock, flags);
1014 /* Figure out our type */
1015 if (!IS_PRINT(minor)) {
1016 un = &brd->channels[PORT_NUM(minor)]->ch_tun;
1017 un->un_type = DGNC_SERIAL;
1018 } else if (IS_PRINT(minor)) {
1019 un = &brd->channels[PORT_NUM(minor)]->ch_pun;
1020 un->un_type = DGNC_PRINT;
1022 spin_unlock_irqrestore(&ch->ch_lock, flags);
1027 * If the port is still in a previous open, and in a state
1028 * where we simply cannot safely keep going, wait until the
1031 spin_unlock_irqrestore(&ch->ch_lock, flags);
1033 rc = wait_event_interruptible(ch->ch_flags_wait,
1034 ((ch->ch_flags & CH_OPENING) == 0));
1036 /* If ret is non-zero, user ctrl-c'ed us */
1041 * If either unit is in the middle of the fragile part of close,
1042 * we just cannot touch the channel safely.
1043 * Go to sleep, knowing that when the channel can be
1044 * touched safely, the close routine will signal the
1045 * ch_flags_wait to wake us back up.
1047 rc = wait_event_interruptible(ch->ch_flags_wait,
1048 (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
1051 /* If ret is non-zero, user ctrl-c'ed us */
1055 spin_lock_irqsave(&ch->ch_lock, flags);
1057 /* Store our unit into driver_data, so we always have it available. */
1058 tty->driver_data = un;
1063 if (!(un->un_flags & UN_ISOPEN)) {
1064 /* Store important variables. */
1067 /* Maybe do something here to the TTY struct as well? */
1071 * Allocate channel buffers for read/write/error.
1072 * Set flag, so we don't get trounced on.
1074 ch->ch_flags |= (CH_OPENING);
1076 /* Drop locks, as malloc with GFP_KERNEL can sleep */
1077 spin_unlock_irqrestore(&ch->ch_lock, flags);
1080 ch->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
1082 ch->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
1084 ch->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
1086 if (!ch->ch_rqueue || !ch->ch_equeue || !ch->ch_wqueue) {
1087 kfree(ch->ch_rqueue);
1088 kfree(ch->ch_equeue);
1089 kfree(ch->ch_wqueue);
1094 spin_lock_irqsave(&ch->ch_lock, flags);
1096 ch->ch_flags &= ~(CH_OPENING);
1097 wake_up_interruptible(&ch->ch_flags_wait);
1100 * Initialize if neither terminal or printer is open.
1102 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1104 * Flush input queues.
1113 brd->bd_ops->flush_uart_write(ch);
1114 brd->bd_ops->flush_uart_read(ch);
1117 ch->ch_cached_lsr = 0;
1118 ch->ch_stop_sending_break = 0;
1119 ch->ch_stops_sent = 0;
1121 ch->ch_c_cflag = tty->termios.c_cflag;
1122 ch->ch_c_iflag = tty->termios.c_iflag;
1123 ch->ch_c_oflag = tty->termios.c_oflag;
1124 ch->ch_c_lflag = tty->termios.c_lflag;
1125 ch->ch_startc = tty->termios.c_cc[VSTART];
1126 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1129 * Bring up RTS and DTR...
1130 * Also handle RTS or DTR toggle if set.
1132 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
1133 ch->ch_mostat |= (UART_MCR_RTS);
1134 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
1135 ch->ch_mostat |= (UART_MCR_DTR);
1137 /* Tell UART to init itself */
1138 brd->bd_ops->uart_init(ch);
1142 * Run param in case we changed anything
1144 brd->bd_ops->param(tty);
1149 * follow protocol for opening port
1152 spin_unlock_irqrestore(&ch->ch_lock, flags);
1154 rc = dgnc_block_til_ready(tty, file, ch);
1156 /* No going back now, increment our unit and channel counters */
1157 spin_lock_irqsave(&ch->ch_lock, flags);
1158 ch->ch_open_count++;
1159 un->un_open_count++;
1160 un->un_flags |= (UN_ISOPEN);
1161 spin_unlock_irqrestore(&ch->ch_lock, flags);
1167 * dgnc_block_til_ready()
1169 * Wait for DCD, if needed.
1171 static int dgnc_block_til_ready(struct tty_struct *tty,
1173 struct channel_t *ch)
1176 struct un_t *un = tty->driver_data;
1177 unsigned long flags;
1179 int sleep_on_un_flags = 0;
1184 spin_lock_irqsave(&ch->ch_lock, flags);
1190 sleep_on_un_flags = 0;
1193 * If board has failed somehow during our sleep,
1196 if (ch->ch_bd->state == BOARD_FAILED) {
1201 /* If tty was hung up, break out of loop and set error. */
1202 if (tty_hung_up_p(file)) {
1208 * If either unit is in the middle of the fragile part of close,
1209 * we just cannot touch the channel safely.
1210 * Go back to sleep, knowing that when the channel can be
1211 * touched safely, the close routine will signal the
1212 * ch_wait_flags to wake us back up.
1214 if (!((ch->ch_tun.un_flags |
1215 ch->ch_pun.un_flags) &
1218 * Our conditions to leave cleanly and happily:
1219 * 1) NONBLOCKING on the tty is set.
1221 * 3) DCD (fake or real) is active.
1224 if (file->f_flags & O_NONBLOCK)
1227 if (tty_io_error(tty)) {
1232 if (ch->ch_flags & CH_CD)
1235 if (ch->ch_flags & CH_FCAR)
1238 sleep_on_un_flags = 1;
1242 * If there is a signal pending, the user probably
1243 * interrupted (ctrl-c) us.
1244 * Leave loop with error set.
1246 if (signal_pending(current)) {
1247 retval = -ERESTARTSYS;
1252 * Store the flags before we let go of channel lock
1254 if (sleep_on_un_flags)
1255 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
1257 old_flags = ch->ch_flags;
1260 * Let go of channel lock before calling schedule.
1261 * Our poller will get any FEP events and wake us up when DCD
1262 * eventually goes active.
1265 spin_unlock_irqrestore(&ch->ch_lock, flags);
1268 * Wait for something in the flags to change
1269 * from the current value.
1271 if (sleep_on_un_flags)
1272 retval = wait_event_interruptible(un->un_flags_wait,
1273 (old_flags != (ch->ch_tun.un_flags |
1274 ch->ch_pun.un_flags)));
1276 retval = wait_event_interruptible(ch->ch_flags_wait,
1277 (old_flags != ch->ch_flags));
1280 * We got woken up for some reason.
1281 * Before looping around, grab our channel lock.
1283 spin_lock_irqsave(&ch->ch_lock, flags);
1288 spin_unlock_irqrestore(&ch->ch_lock, flags);
1296 * Hangup the port. Like a close, but don't wait for output to drain.
1298 static void dgnc_tty_hangup(struct tty_struct *tty)
1300 if (!tty || tty->magic != TTY_MAGIC)
1303 /* flush the transmit queues */
1304 dgnc_tty_flush_buffer(tty);
1311 static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
1313 struct dgnc_board *bd;
1314 struct channel_t *ch;
1316 unsigned long flags;
1318 if (!tty || tty->magic != TTY_MAGIC)
1321 un = tty->driver_data;
1322 if (!un || un->magic != DGNC_UNIT_MAGIC)
1326 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1330 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1333 spin_lock_irqsave(&ch->ch_lock, flags);
1336 * Determine if this is the last close or not - and if we agree about
1337 * which type of close it is with the Line Discipline
1339 if ((tty->count == 1) && (un->un_open_count != 1)) {
1341 * Uh, oh. tty->count is 1, which means that the tty
1342 * structure will be freed. un_open_count should always
1343 * be one in these conditions. If it's greater than
1344 * one, we've got real problems, since it means the
1345 * serial port won't be shutdown.
1348 "tty->count is 1, un open count is %d\n",
1350 un->un_open_count = 1;
1353 if (un->un_open_count)
1354 un->un_open_count--;
1357 "bad serial port open count of %d\n",
1360 ch->ch_open_count--;
1362 if (ch->ch_open_count && un->un_open_count) {
1363 spin_unlock_irqrestore(&ch->ch_lock, flags);
1367 /* OK, its the last close on the unit */
1368 un->un_flags |= UN_CLOSING;
1373 * Only officially close channel if count is 0 and
1374 * DIGI_PRINTER bit is not set.
1376 if ((ch->ch_open_count == 0) &&
1377 !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
1378 ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI);
1381 * turn off print device when closing print device.
1383 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1384 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1385 (int)ch->ch_digi.digi_offlen);
1386 ch->ch_flags &= ~CH_PRON;
1389 spin_unlock_irqrestore(&ch->ch_lock, flags);
1390 /* wait for output to drain */
1391 /* This will also return if we take an interrupt */
1393 bd->bd_ops->drain(tty, 0);
1395 dgnc_tty_flush_buffer(tty);
1396 tty_ldisc_flush(tty);
1398 spin_lock_irqsave(&ch->ch_lock, flags);
1403 * If we have HUPCL set, lower DTR and RTS
1405 if (ch->ch_c_cflag & HUPCL) {
1407 ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
1408 bd->bd_ops->assert_modem_signals(ch);
1411 * Go to sleep to ensure RTS/DTR
1412 * have been dropped for modems to see it.
1414 if (ch->ch_close_delay) {
1415 spin_unlock_irqrestore(&ch->ch_lock,
1417 dgnc_ms_sleep(ch->ch_close_delay);
1418 spin_lock_irqsave(&ch->ch_lock, flags);
1422 ch->ch_old_baud = 0;
1424 /* Turn off UART interrupts for this port */
1425 ch->ch_bd->bd_ops->uart_off(ch);
1428 * turn off print device when closing print device.
1430 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1431 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1432 (int)ch->ch_digi.digi_offlen);
1433 ch->ch_flags &= ~CH_PRON;
1438 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
1440 wake_up_interruptible(&ch->ch_flags_wait);
1441 wake_up_interruptible(&un->un_flags_wait);
1443 spin_unlock_irqrestore(&ch->ch_lock, flags);
1447 * dgnc_tty_chars_in_buffer()
1449 * Return number of characters that have not been transmitted yet.
1451 * This routine is used by the line discipline to determine if there
1452 * is data waiting to be transmitted/drained/flushed or not.
1454 static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
1456 struct channel_t *ch = NULL;
1457 struct un_t *un = NULL;
1462 unsigned long flags;
1467 un = tty->driver_data;
1468 if (!un || un->magic != DGNC_UNIT_MAGIC)
1472 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1475 spin_lock_irqsave(&ch->ch_lock, flags);
1478 thead = ch->ch_w_head & tmask;
1479 ttail = ch->ch_w_tail & tmask;
1481 spin_unlock_irqrestore(&ch->ch_lock, flags);
1483 if (ttail == thead) {
1487 chars = thead - ttail;
1489 chars = thead - ttail + WQUEUESIZE;
1498 * Reduces bytes_available to the max number of characters
1499 * that can be sent currently given the maxcps value, and
1500 * returns the new bytes_available. This only affects printer
1503 static int dgnc_maxcps_room(struct channel_t *ch, int bytes_available)
1505 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
1507 unsigned long current_time = jiffies;
1508 unsigned long buffer_time = current_time +
1509 (HZ * ch->ch_digi.digi_bufsize) /
1510 ch->ch_digi.digi_maxcps;
1512 if (ch->ch_cpstime < current_time) {
1513 /* buffer is empty */
1514 ch->ch_cpstime = current_time; /* reset ch_cpstime */
1515 cps_limit = ch->ch_digi.digi_bufsize;
1516 } else if (ch->ch_cpstime < buffer_time) {
1517 /* still room in the buffer */
1518 cps_limit = ((buffer_time - ch->ch_cpstime) *
1519 ch->ch_digi.digi_maxcps) / HZ;
1521 /* no room in the buffer */
1525 bytes_available = min(cps_limit, bytes_available);
1528 return bytes_available;
1532 * dgnc_tty_write_room()
1534 * Return space available in Tx buffer
1536 static int dgnc_tty_write_room(struct tty_struct *tty)
1538 struct channel_t *ch = NULL;
1539 struct un_t *un = NULL;
1544 unsigned long flags;
1546 if (!tty || !dgnc_TmpWriteBuf)
1549 un = tty->driver_data;
1550 if (!un || un->magic != DGNC_UNIT_MAGIC)
1554 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1557 spin_lock_irqsave(&ch->ch_lock, flags);
1560 head = (ch->ch_w_head) & tmask;
1561 tail = (ch->ch_w_tail) & tmask;
1563 ret = tail - head - 1;
1567 /* Limit printer to maxcps */
1568 if (un->un_type != DGNC_PRINT)
1569 ret = dgnc_maxcps_room(ch, ret);
1572 * If we are printer device, leave space for
1573 * possibly both the on and off strings.
1575 if (un->un_type == DGNC_PRINT) {
1576 if (!(ch->ch_flags & CH_PRON))
1577 ret -= ch->ch_digi.digi_onlen;
1578 ret -= ch->ch_digi.digi_offlen;
1580 if (ch->ch_flags & CH_PRON)
1581 ret -= ch->ch_digi.digi_offlen;
1587 spin_unlock_irqrestore(&ch->ch_lock, flags);
1593 * dgnc_tty_put_char()
1595 * Put a character into ch->ch_buf
1597 * - used by the line discipline for OPOST processing
1599 static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
1602 * Simply call tty_write.
1604 dgnc_tty_write(tty, &c, 1);
1611 * Take data from the user or kernel and send it out to the FEP.
1612 * In here exists all the Transparent Print magic as well.
1614 static int dgnc_tty_write(struct tty_struct *tty,
1615 const unsigned char *buf, int count)
1617 struct channel_t *ch = NULL;
1618 struct un_t *un = NULL;
1619 int bufcount = 0, n = 0;
1620 unsigned long flags;
1626 if (!tty || !dgnc_TmpWriteBuf)
1629 un = tty->driver_data;
1630 if (!un || un->magic != DGNC_UNIT_MAGIC)
1634 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1641 * Store original amount of characters passed in.
1642 * This helps to figure out if we should ask the FEP
1643 * to send us an event when it has more space available.
1646 spin_lock_irqsave(&ch->ch_lock, flags);
1648 /* Get our space available for the channel from the board */
1650 head = (ch->ch_w_head) & tmask;
1651 tail = (ch->ch_w_tail) & tmask;
1653 bufcount = tail - head - 1;
1655 bufcount += WQUEUESIZE;
1658 * Limit printer output to maxcps overall, with bursts allowed
1659 * up to bufsize characters.
1661 if (un->un_type != DGNC_PRINT)
1662 bufcount = dgnc_maxcps_room(ch, bufcount);
1665 * Take minimum of what the user wants to send, and the
1666 * space available in the FEP buffer.
1668 count = min(count, bufcount);
1671 * Bail if no space left.
1677 * Output the printer ON string, if we are in terminal mode, but
1678 * need to be in printer mode.
1680 if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) {
1681 dgnc_wmove(ch, ch->ch_digi.digi_onstr,
1682 (int)ch->ch_digi.digi_onlen);
1683 head = (ch->ch_w_head) & tmask;
1684 ch->ch_flags |= CH_PRON;
1688 * On the other hand, output the printer OFF string, if we are
1689 * currently in printer mode, but need to output to the terminal.
1691 if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1692 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1693 (int)ch->ch_digi.digi_offlen);
1694 head = (ch->ch_w_head) & tmask;
1695 ch->ch_flags &= ~CH_PRON;
1701 * If the write wraps over the top of the circular buffer,
1702 * move the portion up to the wrap point, and reset the
1703 * pointers to the bottom.
1705 remain = WQUEUESIZE - head;
1709 memcpy(ch->ch_wqueue + head, buf, remain);
1716 * Move rest of data.
1719 memcpy(ch->ch_wqueue + head, buf, remain);
1725 ch->ch_w_head = head;
1728 /* Update printer buffer empty time. */
1729 if ((un->un_type == DGNC_PRINT) && (ch->ch_digi.digi_maxcps > 0) &&
1730 (ch->ch_digi.digi_bufsize > 0)) {
1731 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
1734 spin_unlock_irqrestore(&ch->ch_lock, flags);
1738 * Channel lock is grabbed and then released
1739 * inside this routine.
1741 ch->ch_bd->bd_ops->copy_data_from_queue_to_uart(ch);
1748 spin_unlock_irqrestore(&ch->ch_lock, flags);
1753 * Return modem signals to ld.
1756 static int dgnc_tty_tiocmget(struct tty_struct *tty)
1758 struct channel_t *ch;
1761 unsigned char mstat = 0;
1762 unsigned long flags;
1764 if (!tty || tty->magic != TTY_MAGIC)
1767 un = tty->driver_data;
1768 if (!un || un->magic != DGNC_UNIT_MAGIC)
1772 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1775 spin_lock_irqsave(&ch->ch_lock, flags);
1777 mstat = ch->ch_mostat | ch->ch_mistat;
1779 spin_unlock_irqrestore(&ch->ch_lock, flags);
1783 if (mstat & UART_MCR_DTR)
1784 result |= TIOCM_DTR;
1785 if (mstat & UART_MCR_RTS)
1786 result |= TIOCM_RTS;
1787 if (mstat & UART_MSR_CTS)
1788 result |= TIOCM_CTS;
1789 if (mstat & UART_MSR_DSR)
1790 result |= TIOCM_DSR;
1791 if (mstat & UART_MSR_RI)
1793 if (mstat & UART_MSR_DCD)
1800 * dgnc_tty_tiocmset()
1802 * Set modem signals, called by ld.
1805 static int dgnc_tty_tiocmset(struct tty_struct *tty,
1806 unsigned int set, unsigned int clear)
1808 struct dgnc_board *bd;
1809 struct channel_t *ch;
1812 unsigned long flags;
1814 if (!tty || tty->magic != TTY_MAGIC)
1817 un = tty->driver_data;
1818 if (!un || un->magic != DGNC_UNIT_MAGIC)
1822 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1826 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1829 spin_lock_irqsave(&ch->ch_lock, flags);
1831 if (set & TIOCM_RTS)
1832 ch->ch_mostat |= UART_MCR_RTS;
1834 if (set & TIOCM_DTR)
1835 ch->ch_mostat |= UART_MCR_DTR;
1837 if (clear & TIOCM_RTS)
1838 ch->ch_mostat &= ~(UART_MCR_RTS);
1840 if (clear & TIOCM_DTR)
1841 ch->ch_mostat &= ~(UART_MCR_DTR);
1843 ch->ch_bd->bd_ops->assert_modem_signals(ch);
1845 spin_unlock_irqrestore(&ch->ch_lock, flags);
1851 * dgnc_tty_send_break()
1853 * Send a Break, called by ld.
1855 static int dgnc_tty_send_break(struct tty_struct *tty, int msec)
1857 struct dgnc_board *bd;
1858 struct channel_t *ch;
1861 unsigned long flags;
1863 if (!tty || tty->magic != TTY_MAGIC)
1866 un = tty->driver_data;
1867 if (!un || un->magic != DGNC_UNIT_MAGIC)
1871 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1875 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1889 spin_lock_irqsave(&ch->ch_lock, flags);
1891 ch->ch_bd->bd_ops->send_break(ch, msec);
1893 spin_unlock_irqrestore(&ch->ch_lock, flags);
1899 * dgnc_tty_wait_until_sent()
1901 * wait until data has been transmitted, called by ld.
1903 static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
1905 struct dgnc_board *bd;
1906 struct channel_t *ch;
1909 if (!tty || tty->magic != TTY_MAGIC)
1912 un = tty->driver_data;
1913 if (!un || un->magic != DGNC_UNIT_MAGIC)
1917 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1921 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1924 bd->bd_ops->drain(tty, 0);
1930 * send a high priority character, called by ld.
1932 static void dgnc_tty_send_xchar(struct tty_struct *tty, char c)
1934 struct dgnc_board *bd;
1935 struct channel_t *ch;
1937 unsigned long flags;
1939 if (!tty || tty->magic != TTY_MAGIC)
1942 un = tty->driver_data;
1943 if (!un || un->magic != DGNC_UNIT_MAGIC)
1947 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1951 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1954 dev_dbg(tty->dev, "dgnc_tty_send_xchar start\n");
1956 spin_lock_irqsave(&ch->ch_lock, flags);
1957 bd->bd_ops->send_immediate_char(ch, c);
1958 spin_unlock_irqrestore(&ch->ch_lock, flags);
1960 dev_dbg(tty->dev, "dgnc_tty_send_xchar finish\n");
1964 * Return modem signals to ld.
1966 static inline int dgnc_get_mstat(struct channel_t *ch)
1968 unsigned char mstat;
1970 unsigned long flags;
1972 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1975 spin_lock_irqsave(&ch->ch_lock, flags);
1977 mstat = ch->ch_mostat | ch->ch_mistat;
1979 spin_unlock_irqrestore(&ch->ch_lock, flags);
1981 if (mstat & UART_MCR_DTR)
1982 result |= TIOCM_DTR;
1983 if (mstat & UART_MCR_RTS)
1984 result |= TIOCM_RTS;
1985 if (mstat & UART_MSR_CTS)
1986 result |= TIOCM_CTS;
1987 if (mstat & UART_MSR_DSR)
1988 result |= TIOCM_DSR;
1989 if (mstat & UART_MSR_RI)
1991 if (mstat & UART_MSR_DCD)
1998 * Return modem signals to ld.
2000 static int dgnc_get_modem_info(struct channel_t *ch,
2001 unsigned int __user *value)
2003 return put_user(dgnc_get_mstat(ch), value);
2007 * dgnc_set_modem_info()
2009 * Set modem signals, called by ld.
2011 static int dgnc_set_modem_info(struct channel_t *ch,
2012 unsigned int command,
2013 unsigned int __user *value)
2016 unsigned int arg = 0;
2017 unsigned long flags;
2019 ret = get_user(arg, value);
2025 if (arg & TIOCM_RTS)
2026 ch->ch_mostat |= UART_MCR_RTS;
2028 if (arg & TIOCM_DTR)
2029 ch->ch_mostat |= UART_MCR_DTR;
2034 if (arg & TIOCM_RTS)
2035 ch->ch_mostat &= ~(UART_MCR_RTS);
2037 if (arg & TIOCM_DTR)
2038 ch->ch_mostat &= ~(UART_MCR_DTR);
2044 if (arg & TIOCM_RTS)
2045 ch->ch_mostat |= UART_MCR_RTS;
2047 ch->ch_mostat &= ~(UART_MCR_RTS);
2049 if (arg & TIOCM_DTR)
2050 ch->ch_mostat |= UART_MCR_DTR;
2052 ch->ch_mostat &= ~(UART_MCR_DTR);
2060 spin_lock_irqsave(&ch->ch_lock, flags);
2062 ch->ch_bd->bd_ops->assert_modem_signals(ch);
2064 spin_unlock_irqrestore(&ch->ch_lock, flags);
2070 * dgnc_tty_digigeta()
2072 * Ioctl to get the information for ditty.
2077 static int dgnc_tty_digigeta(struct tty_struct *tty,
2078 struct digi_t __user *retinfo)
2080 struct channel_t *ch;
2083 unsigned long flags;
2088 if (!tty || tty->magic != TTY_MAGIC)
2091 un = tty->driver_data;
2092 if (!un || un->magic != DGNC_UNIT_MAGIC)
2096 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2099 memset(&tmp, 0, sizeof(tmp));
2101 spin_lock_irqsave(&ch->ch_lock, flags);
2102 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
2103 spin_unlock_irqrestore(&ch->ch_lock, flags);
2105 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2112 * dgnc_tty_digiseta()
2114 * Ioctl to set the information for ditty.
2119 static int dgnc_tty_digiseta(struct tty_struct *tty,
2120 struct digi_t __user *new_info)
2122 struct dgnc_board *bd;
2123 struct channel_t *ch;
2125 struct digi_t new_digi;
2126 unsigned long flags;
2128 if (!tty || tty->magic != TTY_MAGIC)
2131 un = tty->driver_data;
2132 if (!un || un->magic != DGNC_UNIT_MAGIC)
2136 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2140 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2143 if (copy_from_user(&new_digi, new_info, sizeof(new_digi)))
2146 spin_lock_irqsave(&ch->ch_lock, flags);
2149 * Handle transistions to and from RTS Toggle.
2151 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
2152 (new_digi.digi_flags & DIGI_RTS_TOGGLE))
2153 ch->ch_mostat &= ~(UART_MCR_RTS);
2154 if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) &&
2155 !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
2156 ch->ch_mostat |= (UART_MCR_RTS);
2159 * Handle transistions to and from DTR Toggle.
2161 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
2162 (new_digi.digi_flags & DIGI_DTR_TOGGLE))
2163 ch->ch_mostat &= ~(UART_MCR_DTR);
2164 if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) &&
2165 !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
2166 ch->ch_mostat |= (UART_MCR_DTR);
2168 memcpy(&ch->ch_digi, &new_digi, sizeof(new_digi));
2170 if (ch->ch_digi.digi_maxcps < 1)
2171 ch->ch_digi.digi_maxcps = 1;
2173 if (ch->ch_digi.digi_maxcps > 10000)
2174 ch->ch_digi.digi_maxcps = 10000;
2176 if (ch->ch_digi.digi_bufsize < 10)
2177 ch->ch_digi.digi_bufsize = 10;
2179 if (ch->ch_digi.digi_maxchar < 1)
2180 ch->ch_digi.digi_maxchar = 1;
2182 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
2183 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
2185 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
2186 ch->ch_digi.digi_onlen = DIGI_PLEN;
2188 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
2189 ch->ch_digi.digi_offlen = DIGI_PLEN;
2191 ch->ch_bd->bd_ops->param(tty);
2193 spin_unlock_irqrestore(&ch->ch_lock, flags);
2199 * dgnc_set_termios()
2201 static void dgnc_tty_set_termios(struct tty_struct *tty,
2202 struct ktermios *old_termios)
2204 struct dgnc_board *bd;
2205 struct channel_t *ch;
2207 unsigned long flags;
2209 if (!tty || tty->magic != TTY_MAGIC)
2212 un = tty->driver_data;
2213 if (!un || un->magic != DGNC_UNIT_MAGIC)
2217 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2221 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2224 spin_lock_irqsave(&ch->ch_lock, flags);
2226 ch->ch_c_cflag = tty->termios.c_cflag;
2227 ch->ch_c_iflag = tty->termios.c_iflag;
2228 ch->ch_c_oflag = tty->termios.c_oflag;
2229 ch->ch_c_lflag = tty->termios.c_lflag;
2230 ch->ch_startc = tty->termios.c_cc[VSTART];
2231 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2233 ch->ch_bd->bd_ops->param(tty);
2236 spin_unlock_irqrestore(&ch->ch_lock, flags);
2239 static void dgnc_tty_throttle(struct tty_struct *tty)
2241 struct channel_t *ch;
2243 unsigned long flags;
2245 if (!tty || tty->magic != TTY_MAGIC)
2248 un = tty->driver_data;
2249 if (!un || un->magic != DGNC_UNIT_MAGIC)
2253 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2256 spin_lock_irqsave(&ch->ch_lock, flags);
2258 ch->ch_flags |= (CH_FORCED_STOPI);
2260 spin_unlock_irqrestore(&ch->ch_lock, flags);
2263 static void dgnc_tty_unthrottle(struct tty_struct *tty)
2265 struct channel_t *ch;
2267 unsigned long flags;
2269 if (!tty || tty->magic != TTY_MAGIC)
2272 un = tty->driver_data;
2273 if (!un || un->magic != DGNC_UNIT_MAGIC)
2277 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2280 spin_lock_irqsave(&ch->ch_lock, flags);
2282 ch->ch_flags &= ~(CH_FORCED_STOPI);
2284 spin_unlock_irqrestore(&ch->ch_lock, flags);
2287 static void dgnc_tty_start(struct tty_struct *tty)
2289 struct dgnc_board *bd;
2290 struct channel_t *ch;
2292 unsigned long flags;
2294 if (!tty || tty->magic != TTY_MAGIC)
2297 un = tty->driver_data;
2298 if (!un || un->magic != DGNC_UNIT_MAGIC)
2302 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2306 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2309 spin_lock_irqsave(&ch->ch_lock, flags);
2311 ch->ch_flags &= ~(CH_FORCED_STOP);
2313 spin_unlock_irqrestore(&ch->ch_lock, flags);
2316 static void dgnc_tty_stop(struct tty_struct *tty)
2318 struct dgnc_board *bd;
2319 struct channel_t *ch;
2321 unsigned long flags;
2323 if (!tty || tty->magic != TTY_MAGIC)
2326 un = tty->driver_data;
2327 if (!un || un->magic != DGNC_UNIT_MAGIC)
2331 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2335 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2338 spin_lock_irqsave(&ch->ch_lock, flags);
2340 ch->ch_flags |= (CH_FORCED_STOP);
2342 spin_unlock_irqrestore(&ch->ch_lock, flags);
2346 * dgnc_tty_flush_chars()
2348 * Flush the cook buffer
2350 * Note to self, and any other poor souls who venture here:
2352 * flush in this case DOES NOT mean dispose of the data.
2353 * instead, it means "stop buffering and send it if you
2354 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
2356 * It is also always called in interrupt context - JAR 8-Sept-99
2358 static void dgnc_tty_flush_chars(struct tty_struct *tty)
2360 struct dgnc_board *bd;
2361 struct channel_t *ch;
2363 unsigned long flags;
2365 if (!tty || tty->magic != TTY_MAGIC)
2368 un = tty->driver_data;
2369 if (!un || un->magic != DGNC_UNIT_MAGIC)
2373 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2377 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2380 spin_lock_irqsave(&ch->ch_lock, flags);
2382 /* Do something maybe here */
2384 spin_unlock_irqrestore(&ch->ch_lock, flags);
2388 * dgnc_tty_flush_buffer()
2390 * Flush Tx buffer (make in == out)
2392 static void dgnc_tty_flush_buffer(struct tty_struct *tty)
2394 struct channel_t *ch;
2396 unsigned long flags;
2398 if (!tty || tty->magic != TTY_MAGIC)
2401 un = tty->driver_data;
2402 if (!un || un->magic != DGNC_UNIT_MAGIC)
2406 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2409 spin_lock_irqsave(&ch->ch_lock, flags);
2411 ch->ch_flags &= ~CH_STOP;
2413 /* Flush our write queue */
2414 ch->ch_w_head = ch->ch_w_tail;
2416 /* Flush UARTs transmit FIFO */
2417 ch->ch_bd->bd_ops->flush_uart_write(ch);
2419 if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
2420 ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
2421 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
2423 if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
2424 ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
2425 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
2428 spin_unlock_irqrestore(&ch->ch_lock, flags);
2431 /*****************************************************************************
2433 * The IOCTL function and all of its helpers
2435 *****************************************************************************/
2440 * The usual assortment of ioctl's
2442 static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
2445 struct dgnc_board *bd;
2446 struct board_ops *ch_bd_ops;
2447 struct channel_t *ch;
2450 unsigned long flags;
2451 void __user *uarg = (void __user *)arg;
2453 if (!tty || tty->magic != TTY_MAGIC)
2456 un = tty->driver_data;
2457 if (!un || un->magic != DGNC_UNIT_MAGIC)
2461 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2465 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2468 ch_bd_ops = bd->bd_ops;
2470 spin_lock_irqsave(&ch->ch_lock, flags);
2472 if (un->un_open_count <= 0) {
2473 spin_unlock_irqrestore(&ch->ch_lock, flags);
2478 /* Here are all the standard ioctl's that we MUST implement */
2482 * TCSBRK is SVID version: non-zero arg --> no break
2483 * this behaviour is exploited by tcdrain().
2485 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
2486 * between 0.25 and 0.5 seconds so we'll ask for something
2487 * in the middle: 0.375 seconds.
2489 rc = tty_check_change(tty);
2490 spin_unlock_irqrestore(&ch->ch_lock, flags);
2494 rc = ch_bd_ops->drain(tty, 0);
2499 spin_lock_irqsave(&ch->ch_lock, flags);
2501 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
2502 ch_bd_ops->send_break(ch, 250);
2504 spin_unlock_irqrestore(&ch->ch_lock, flags);
2509 /* support for POSIX tcsendbreak()
2510 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
2511 * between 0.25 and 0.5 seconds so we'll ask for something
2512 * in the middle: 0.375 seconds.
2514 rc = tty_check_change(tty);
2515 spin_unlock_irqrestore(&ch->ch_lock, flags);
2519 rc = ch_bd_ops->drain(tty, 0);
2523 spin_lock_irqsave(&ch->ch_lock, flags);
2525 ch_bd_ops->send_break(ch, 250);
2527 spin_unlock_irqrestore(&ch->ch_lock, flags);
2532 rc = tty_check_change(tty);
2533 spin_unlock_irqrestore(&ch->ch_lock, flags);
2537 rc = ch_bd_ops->drain(tty, 0);
2541 spin_lock_irqsave(&ch->ch_lock, flags);
2543 ch_bd_ops->send_break(ch, 250);
2545 spin_unlock_irqrestore(&ch->ch_lock, flags);
2551 spin_unlock_irqrestore(&ch->ch_lock, flags);
2556 spin_unlock_irqrestore(&ch->ch_lock, flags);
2558 return put_user(C_CLOCAL(tty) ? 1 : 0,
2559 (unsigned long __user *)arg);
2563 spin_unlock_irqrestore(&ch->ch_lock, flags);
2564 rc = get_user(arg, (unsigned long __user *)arg);
2568 spin_lock_irqsave(&ch->ch_lock, flags);
2569 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
2570 (arg ? CLOCAL : 0));
2571 ch_bd_ops->param(tty);
2572 spin_unlock_irqrestore(&ch->ch_lock, flags);
2577 spin_unlock_irqrestore(&ch->ch_lock, flags);
2578 return dgnc_get_modem_info(ch, uarg);
2583 spin_unlock_irqrestore(&ch->ch_lock, flags);
2584 return dgnc_set_modem_info(ch, cmd, uarg);
2587 * Here are any additional ioctl's that we want to implement
2592 * The linux tty driver doesn't have a flush
2593 * input routine for the driver, assuming all backed
2594 * up data is in the line disc. buffers. However,
2595 * we all know that's not the case. Here, we
2596 * act on the ioctl, but then lie and say we didn't
2597 * so the line discipline will process the flush
2600 rc = tty_check_change(tty);
2602 spin_unlock_irqrestore(&ch->ch_lock, flags);
2606 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
2607 ch->ch_r_head = ch->ch_r_tail;
2608 ch_bd_ops->flush_uart_read(ch);
2609 /* Force queue flow control to be released, if needed */
2610 dgnc_check_queue_flow_control(ch);
2613 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
2614 if (!(un->un_type == DGNC_PRINT)) {
2615 ch->ch_w_head = ch->ch_w_tail;
2616 ch_bd_ops->flush_uart_write(ch);
2618 if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
2619 ch->ch_tun.un_flags &=
2620 ~(UN_LOW | UN_EMPTY);
2621 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
2624 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
2625 ch->ch_pun.un_flags &=
2626 ~(UN_LOW | UN_EMPTY);
2627 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
2632 /* pretend we didn't recognize this IOCTL */
2633 spin_unlock_irqrestore(&ch->ch_lock, flags);
2634 return -ENOIOCTLCMD;
2638 * The linux tty driver doesn't have a flush
2639 * input routine for the driver, assuming all backed
2640 * up data is in the line disc. buffers. However,
2641 * we all know that's not the case. Here, we
2642 * act on the ioctl, but then lie and say we didn't
2643 * so the line discipline will process the flush
2646 if (cmd == TCSETSF) {
2648 ch->ch_flags &= ~CH_STOP;
2649 ch->ch_r_head = ch->ch_r_tail;
2650 ch_bd_ops->flush_uart_read(ch);
2651 /* Force queue flow control to be released, if needed */
2652 dgnc_check_queue_flow_control(ch);
2655 /* now wait for all the output to drain */
2656 spin_unlock_irqrestore(&ch->ch_lock, flags);
2657 rc = ch_bd_ops->drain(tty, 0);
2661 /* pretend we didn't recognize this */
2662 return -ENOIOCTLCMD;
2666 spin_unlock_irqrestore(&ch->ch_lock, flags);
2667 rc = ch_bd_ops->drain(tty, 0);
2671 /* pretend we didn't recognize this */
2672 return -ENOIOCTLCMD;
2675 spin_unlock_irqrestore(&ch->ch_lock, flags);
2676 /* Make the ld do it */
2677 return -ENOIOCTLCMD;
2680 /* get information for ditty */
2681 spin_unlock_irqrestore(&ch->ch_lock, flags);
2682 return dgnc_tty_digigeta(tty, uarg);
2687 /* set information for ditty */
2688 if (cmd == (DIGI_SETAW)) {
2689 spin_unlock_irqrestore(&ch->ch_lock, flags);
2690 rc = ch_bd_ops->drain(tty, 0);
2695 spin_lock_irqsave(&ch->ch_lock, flags);
2697 tty_ldisc_flush(tty);
2702 spin_unlock_irqrestore(&ch->ch_lock, flags);
2703 return dgnc_tty_digiseta(tty, uarg);
2708 /* Let go of locks when accessing user space,
2711 spin_unlock_irqrestore(&ch->ch_lock, flags);
2712 rc = get_user(loopback, (unsigned int __user *)arg);
2715 spin_lock_irqsave(&ch->ch_lock, flags);
2717 /* Enable/disable internal loopback for this port */
2719 ch->ch_flags |= CH_LOOPBACK;
2721 ch->ch_flags &= ~(CH_LOOPBACK);
2723 ch_bd_ops->param(tty);
2724 spin_unlock_irqrestore(&ch->ch_lock, flags);
2728 case DIGI_GETCUSTOMBAUD:
2729 spin_unlock_irqrestore(&ch->ch_lock, flags);
2730 return put_user(ch->ch_custom_speed,
2731 (unsigned int __user *)arg);
2733 case DIGI_SETCUSTOMBAUD:
2736 /* Let go of locks when accessing user space, could sleep */
2737 spin_unlock_irqrestore(&ch->ch_lock, flags);
2738 rc = get_user(new_rate, (int __user *)arg);
2741 spin_lock_irqsave(&ch->ch_lock, flags);
2742 dgnc_set_custom_speed(ch, new_rate);
2743 ch_bd_ops->param(tty);
2744 spin_unlock_irqrestore(&ch->ch_lock, flags);
2749 * This ioctl allows insertion of a character into the front
2750 * of any pending data to be transmitted.
2752 * This ioctl is to satify the "Send Character Immediate"
2753 * call that the RealPort protocol spec requires.
2755 case DIGI_REALPORT_SENDIMMEDIATE:
2759 spin_unlock_irqrestore(&ch->ch_lock, flags);
2760 rc = get_user(c, (unsigned char __user *)arg);
2763 spin_lock_irqsave(&ch->ch_lock, flags);
2764 ch_bd_ops->send_immediate_char(ch, c);
2765 spin_unlock_irqrestore(&ch->ch_lock, flags);
2770 * This ioctl returns all the current counts for the port.
2772 * This ioctl is to satify the "Line Error Counters"
2773 * call that the RealPort protocol spec requires.
2775 case DIGI_REALPORT_GETCOUNTERS:
2777 struct digi_getcounter buf;
2779 buf.norun = ch->ch_err_overrun;
2780 buf.noflow = 0; /* The driver doesn't keep this stat */
2781 buf.nframe = ch->ch_err_frame;
2782 buf.nparity = ch->ch_err_parity;
2783 buf.nbreak = ch->ch_err_break;
2784 buf.rbytes = ch->ch_rxcount;
2785 buf.tbytes = ch->ch_txcount;
2787 spin_unlock_irqrestore(&ch->ch_lock, flags);
2789 if (copy_to_user(uarg, &buf, sizeof(buf)))
2796 * This ioctl returns all current events.
2798 * This ioctl is to satify the "Event Reporting"
2799 * call that the RealPort protocol spec requires.
2801 case DIGI_REALPORT_GETEVENTS:
2803 unsigned int events = 0;
2805 /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
2806 if (ch->ch_flags & CH_BREAK_SENDING)
2808 if ((ch->ch_flags & CH_STOP) ||
2809 (ch->ch_flags & CH_FORCED_STOP))
2810 events |= (EV_OPU | EV_OPS);
2812 if ((ch->ch_flags & CH_STOPI) ||
2813 (ch->ch_flags & CH_FORCED_STOPI))
2814 events |= (EV_IPU | EV_IPS);
2816 spin_unlock_irqrestore(&ch->ch_lock, flags);
2817 return put_user(events, (unsigned int __user *)arg);
2821 * This ioctl returns TOUT and TIN counters based
2822 * upon the values passed in by the RealPort Server.
2823 * It also passes back whether the UART Transmitter is
2826 case DIGI_REALPORT_GETBUFFERS:
2828 struct digi_getbuffer buf;
2832 spin_unlock_irqrestore(&ch->ch_lock, flags);
2835 * Get data from user first.
2837 if (copy_from_user(&buf, uarg, sizeof(buf)))
2840 spin_lock_irqsave(&ch->ch_lock, flags);
2843 * Figure out how much data is in our RX and TX queues.
2845 buf.rxbuf = (ch->ch_r_head - ch->ch_r_tail) & RQUEUEMASK;
2846 buf.txbuf = (ch->ch_w_head - ch->ch_w_tail) & WQUEUEMASK;
2849 * Is the UART empty? Add that value to whats in our TX queue.
2851 count = buf.txbuf + ch_bd_ops->get_uart_bytes_left(ch);
2854 * Figure out how much data the RealPort Server believes should
2855 * be in our TX queue.
2857 tdist = (buf.tx_in - buf.tx_out) & 0xffff;
2860 * If we have more data than the RealPort Server believes we
2861 * should have, reduce our count to its amount.
2863 * This count difference CAN happen because the Linux LD can
2864 * insert more characters into our queue for OPOST processing
2865 * that the RealPort Server doesn't know about.
2867 if (buf.txbuf > tdist)
2871 * Report whether our queue and UART TX are completely empty.
2878 spin_unlock_irqrestore(&ch->ch_lock, flags);
2880 if (copy_to_user(uarg, &buf, sizeof(buf)))
2886 spin_unlock_irqrestore(&ch->ch_lock, flags);
2888 return -ENOIOCTLCMD;