2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
12 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 * PURPOSE. See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * NOTE TO LINUX KERNEL HACKERS: DO NOT REFORMAT THIS CODE!
22 * This is shared code between Digi's CVS archive and the
23 * Linux Kernel sources.
24 * Changing the source just for reformatting needlessly breaks
25 * our CVS diff history.
27 * Send any bug fixes/changes to: Eng.Linux at digi dot com.
31 /************************************************************************
33 * This file implements the tty driver functionality for the
34 * Neo and ClassicBoard PCI based product lines.
36 ************************************************************************
40 #include <linux/kernel.h>
41 #include <linux/sched.h> /* For jiffies, task states */
42 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
43 #include <linux/module.h>
44 #include <linux/ctype.h>
45 #include <linux/tty.h>
46 #include <linux/tty_flip.h>
47 #include <linux/serial_reg.h>
48 #include <linux/slab.h>
49 #include <linux/delay.h> /* For udelay */
50 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
51 #include <linux/pci.h>
53 #include "dgnc_driver.h"
55 #include "dgnc_types.h"
56 #include "dgnc_trace.h"
59 #include "dpacompat.h"
60 #include "dgnc_sysfs.h"
62 #define init_MUTEX(sem) sema_init(sem, 1)
63 #define DECLARE_MUTEX(name) \
64 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
69 static struct dgnc_board
*dgnc_BoardsByMajor
[256];
70 static uchar
*dgnc_TmpWriteBuf
= NULL
;
71 static DECLARE_MUTEX(dgnc_TmpWriteSem
);
74 * Default transparent print information.
76 static struct digi_t dgnc_digi_init
= {
77 .digi_flags
= DIGI_COOK
, /* Flags */
78 .digi_maxcps
= 100, /* Max CPS */
79 .digi_maxchar
= 50, /* Max chars in print queue */
80 .digi_bufsize
= 100, /* Printer buffer size */
81 .digi_onlen
= 4, /* size of printer on string */
82 .digi_offlen
= 4, /* size of printer off string */
83 .digi_onstr
= "\033[5i", /* ANSI printer on string ] */
84 .digi_offstr
= "\033[4i", /* ANSI printer off string ] */
85 .digi_term
= "ansi" /* default terminal type */
90 * Define a local default termios struct. All ports will be created
91 * with this termios initially.
93 * This defines a raw port at 9600 baud, 8 data bits, no parity,
96 static struct ktermios DgncDefaultTermios
=
98 .c_iflag
= (DEFAULT_IFLAGS
), /* iflags */
99 .c_oflag
= (DEFAULT_OFLAGS
), /* oflags */
100 .c_cflag
= (DEFAULT_CFLAGS
), /* cflags */
101 .c_lflag
= (DEFAULT_LFLAGS
), /* lflags */
107 /* Our function prototypes */
108 static int dgnc_tty_open(struct tty_struct
*tty
, struct file
*file
);
109 static void dgnc_tty_close(struct tty_struct
*tty
, struct file
*file
);
110 static int dgnc_block_til_ready(struct tty_struct
*tty
, struct file
*file
, struct channel_t
*ch
);
111 static int dgnc_tty_ioctl(struct tty_struct
*tty
, unsigned int cmd
, unsigned long arg
);
112 static int dgnc_tty_digigeta(struct tty_struct
*tty
, struct digi_t __user
*retinfo
);
113 static int dgnc_tty_digiseta(struct tty_struct
*tty
, struct digi_t __user
*new_info
);
114 static int dgnc_tty_write_room(struct tty_struct
*tty
);
115 static int dgnc_tty_put_char(struct tty_struct
*tty
, unsigned char c
);
116 static int dgnc_tty_chars_in_buffer(struct tty_struct
*tty
);
117 static void dgnc_tty_start(struct tty_struct
*tty
);
118 static void dgnc_tty_stop(struct tty_struct
*tty
);
119 static void dgnc_tty_throttle(struct tty_struct
*tty
);
120 static void dgnc_tty_unthrottle(struct tty_struct
*tty
);
121 static void dgnc_tty_flush_chars(struct tty_struct
*tty
);
122 static void dgnc_tty_flush_buffer(struct tty_struct
*tty
);
123 static void dgnc_tty_hangup(struct tty_struct
*tty
);
124 static int dgnc_set_modem_info(struct tty_struct
*tty
, unsigned int command
, unsigned int __user
*value
);
125 static int dgnc_get_modem_info(struct channel_t
*ch
, unsigned int __user
*value
);
126 static int dgnc_tty_tiocmget(struct tty_struct
*tty
);
127 static int dgnc_tty_tiocmset(struct tty_struct
*tty
, unsigned int set
, unsigned int clear
);
128 static int dgnc_tty_send_break(struct tty_struct
*tty
, int msec
);
129 static void dgnc_tty_wait_until_sent(struct tty_struct
*tty
, int timeout
);
130 static int dgnc_tty_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
131 static void dgnc_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
);
132 static void dgnc_tty_send_xchar(struct tty_struct
*tty
, char ch
);
135 static const struct tty_operations dgnc_tty_ops
= {
136 .open
= dgnc_tty_open
,
137 .close
= dgnc_tty_close
,
138 .write
= dgnc_tty_write
,
139 .write_room
= dgnc_tty_write_room
,
140 .flush_buffer
= dgnc_tty_flush_buffer
,
141 .chars_in_buffer
= dgnc_tty_chars_in_buffer
,
142 .flush_chars
= dgnc_tty_flush_chars
,
143 .ioctl
= dgnc_tty_ioctl
,
144 .set_termios
= dgnc_tty_set_termios
,
145 .stop
= dgnc_tty_stop
,
146 .start
= dgnc_tty_start
,
147 .throttle
= dgnc_tty_throttle
,
148 .unthrottle
= dgnc_tty_unthrottle
,
149 .hangup
= dgnc_tty_hangup
,
150 .put_char
= dgnc_tty_put_char
,
151 .tiocmget
= dgnc_tty_tiocmget
,
152 .tiocmset
= dgnc_tty_tiocmset
,
153 .break_ctl
= dgnc_tty_send_break
,
154 .wait_until_sent
= dgnc_tty_wait_until_sent
,
155 .send_xchar
= dgnc_tty_send_xchar
158 /************************************************************************
160 * TTY Initialization/Cleanup Functions
162 ************************************************************************/
167 * Initialize any global tty related data before we download any boards.
169 int dgnc_tty_preinit(void)
172 * Allocate a buffer for doing the copy from user space to
173 * kernel space in dgnc_write(). We only use one buffer and
174 * control access to it with a semaphore. If we are paging, we
175 * are already in trouble so one buffer won't hurt much anyway.
177 * We are okay to sleep in the malloc, as this routine
178 * is only called during module load, (not in interrupt context),
179 * and with no locks held.
181 dgnc_TmpWriteBuf
= kmalloc(WRITEBUFLEN
, GFP_KERNEL
);
183 if (!dgnc_TmpWriteBuf
) {
184 DPR_INIT(("unable to allocate tmp write buf"));
193 * dgnc_tty_register()
195 * Init the tty subsystem for this board.
197 int dgnc_tty_register(struct dgnc_board
*brd
)
201 DPR_INIT(("tty_register start\n"));
203 memset(&brd
->SerialDriver
, 0, sizeof(brd
->SerialDriver
));
204 memset(&brd
->PrintDriver
, 0, sizeof(brd
->PrintDriver
));
206 brd
->SerialDriver
.magic
= TTY_DRIVER_MAGIC
;
208 snprintf(brd
->SerialName
, MAXTTYNAMELEN
, "tty_dgnc_%d_", brd
->boardnum
);
210 brd
->SerialDriver
.name
= brd
->SerialName
;
211 brd
->SerialDriver
.name_base
= 0;
212 brd
->SerialDriver
.major
= 0;
213 brd
->SerialDriver
.minor_start
= 0;
214 brd
->SerialDriver
.num
= brd
->maxports
;
215 brd
->SerialDriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
216 brd
->SerialDriver
.subtype
= SERIAL_TYPE_NORMAL
;
217 brd
->SerialDriver
.init_termios
= DgncDefaultTermios
;
218 brd
->SerialDriver
.driver_name
= DRVSTR
;
219 brd
->SerialDriver
.flags
= (TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
| TTY_DRIVER_HARDWARE_BREAK
);
222 * The kernel wants space to store pointers to
223 * tty_struct's and termios's.
225 brd
->SerialDriver
.ttys
= kzalloc(brd
->maxports
* sizeof(*brd
->SerialDriver
.ttys
), GFP_KERNEL
);
226 if (!brd
->SerialDriver
.ttys
)
229 kref_init(&brd
->SerialDriver
.kref
);
230 brd
->SerialDriver
.termios
= kzalloc(brd
->maxports
* sizeof(*brd
->SerialDriver
.termios
), GFP_KERNEL
);
231 if (!brd
->SerialDriver
.termios
)
235 * Entry points for driver. Called by the kernel from
236 * tty_io.c and n_tty.c.
238 tty_set_operations(&brd
->SerialDriver
, &dgnc_tty_ops
);
240 if (!brd
->dgnc_Major_Serial_Registered
) {
241 /* Register tty devices */
242 rc
= tty_register_driver(&brd
->SerialDriver
);
244 APR(("Can't register tty device (%d)\n", rc
));
247 brd
->dgnc_Major_Serial_Registered
= TRUE
;
251 * If we're doing transparent print, we have to do all of the above
252 * again, separately so we don't get the LD confused about what major
253 * we are when we get into the dgnc_tty_open() routine.
255 brd
->PrintDriver
.magic
= TTY_DRIVER_MAGIC
;
256 snprintf(brd
->PrintName
, MAXTTYNAMELEN
, "pr_dgnc_%d_", brd
->boardnum
);
258 brd
->PrintDriver
.name
= brd
->PrintName
;
259 brd
->PrintDriver
.name_base
= 0;
260 brd
->PrintDriver
.major
= brd
->SerialDriver
.major
;
261 brd
->PrintDriver
.minor_start
= 0x80;
262 brd
->PrintDriver
.num
= brd
->maxports
;
263 brd
->PrintDriver
.type
= TTY_DRIVER_TYPE_SERIAL
;
264 brd
->PrintDriver
.subtype
= SERIAL_TYPE_NORMAL
;
265 brd
->PrintDriver
.init_termios
= DgncDefaultTermios
;
266 brd
->PrintDriver
.driver_name
= DRVSTR
;
267 brd
->PrintDriver
.flags
= (TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
| TTY_DRIVER_HARDWARE_BREAK
);
270 * The kernel wants space to store pointers to
271 * tty_struct's and termios's. Must be separated from
272 * the Serial Driver so we don't get confused
274 brd
->PrintDriver
.ttys
= kzalloc(brd
->maxports
* sizeof(*brd
->PrintDriver
.ttys
), GFP_KERNEL
);
275 if (!brd
->PrintDriver
.ttys
)
277 kref_init(&brd
->PrintDriver
.kref
);
278 brd
->PrintDriver
.termios
= kzalloc(brd
->maxports
* sizeof(*brd
->PrintDriver
.termios
), GFP_KERNEL
);
279 if (!brd
->PrintDriver
.termios
)
283 * Entry points for driver. Called by the kernel from
284 * tty_io.c and n_tty.c.
286 tty_set_operations(&brd
->PrintDriver
, &dgnc_tty_ops
);
288 if (!brd
->dgnc_Major_TransparentPrint_Registered
) {
289 /* Register Transparent Print devices */
290 rc
= tty_register_driver(&brd
->PrintDriver
);
292 APR(("Can't register Transparent Print device (%d)\n", rc
));
295 brd
->dgnc_Major_TransparentPrint_Registered
= TRUE
;
298 dgnc_BoardsByMajor
[brd
->SerialDriver
.major
] = brd
;
299 brd
->dgnc_Serial_Major
= brd
->SerialDriver
.major
;
300 brd
->dgnc_TransparentPrint_Major
= brd
->PrintDriver
.major
;
302 DPR_INIT(("DGNC REGISTER TTY: MAJOR: %d\n", brd
->SerialDriver
.major
));
311 * Init the tty subsystem. Called once per board after board has been
312 * downloaded and init'ed.
314 int dgnc_tty_init(struct dgnc_board
*brd
)
318 struct channel_t
*ch
;
323 DPR_INIT(("dgnc_tty_init start\n"));
326 * Initialize board structure elements.
329 vaddr
= brd
->re_map_membase
;
331 brd
->nasync
= brd
->maxports
;
334 * Allocate channel memory that might not have been allocated
335 * when the driver was first loaded.
337 for (i
= 0; i
< brd
->nasync
; i
++) {
338 if (!brd
->channels
[i
]) {
341 * Okay to malloc with GFP_KERNEL, we are not at
342 * interrupt context, and there are no locks held.
344 brd
->channels
[i
] = kzalloc(sizeof(*brd
->channels
[i
]), GFP_KERNEL
);
345 if (!brd
->channels
[i
]) {
346 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
347 __FILE__
, __LINE__
));
352 ch
= brd
->channels
[0];
353 vaddr
= brd
->re_map_membase
;
355 /* Set up channel variables */
356 for (i
= 0; i
< brd
->nasync
; i
++, ch
= brd
->channels
[i
]) {
358 if (!brd
->channels
[i
])
361 DGNC_SPINLOCK_INIT(ch
->ch_lock
);
363 /* Store all our magic numbers */
364 ch
->magic
= DGNC_CHANNEL_MAGIC
;
365 ch
->ch_tun
.magic
= DGNC_UNIT_MAGIC
;
366 ch
->ch_tun
.un_ch
= ch
;
367 ch
->ch_tun
.un_type
= DGNC_SERIAL
;
368 ch
->ch_tun
.un_dev
= i
;
370 ch
->ch_pun
.magic
= DGNC_UNIT_MAGIC
;
371 ch
->ch_pun
.un_ch
= ch
;
372 ch
->ch_pun
.un_type
= DGNC_PRINT
;
373 ch
->ch_pun
.un_dev
= i
+ 128;
375 if (brd
->bd_uart_offset
== 0x200)
376 ch
->ch_neo_uart
= vaddr
+ (brd
->bd_uart_offset
* i
);
378 ch
->ch_cls_uart
= vaddr
+ (brd
->bd_uart_offset
* i
);
382 ch
->ch_digi
= dgnc_digi_init
;
384 /* .25 second delay */
385 ch
->ch_close_delay
= 250;
387 init_waitqueue_head(&ch
->ch_flags_wait
);
388 init_waitqueue_head(&ch
->ch_tun
.un_flags_wait
);
389 init_waitqueue_head(&ch
->ch_pun
.un_flags_wait
);
390 init_waitqueue_head(&ch
->ch_sniff_wait
);
393 struct device
*classp
;
394 classp
= tty_register_device(&brd
->SerialDriver
, i
,
395 &(ch
->ch_bd
->pdev
->dev
));
396 ch
->ch_tun
.un_sysfs
= classp
;
397 dgnc_create_tty_sysfs(&ch
->ch_tun
, classp
);
399 classp
= tty_register_device(&brd
->PrintDriver
, i
,
400 &(ch
->ch_bd
->pdev
->dev
));
401 ch
->ch_pun
.un_sysfs
= classp
;
402 dgnc_create_tty_sysfs(&ch
->ch_pun
, classp
);
407 DPR_INIT(("dgnc_tty_init finish\n"));
414 * dgnc_tty_post_uninit()
416 * UnInitialize any global tty related data.
418 void dgnc_tty_post_uninit(void)
420 if (dgnc_TmpWriteBuf
) {
421 kfree(dgnc_TmpWriteBuf
);
422 dgnc_TmpWriteBuf
= NULL
;
430 * Uninitialize the TTY portion of this driver. Free all memory and
433 void dgnc_tty_uninit(struct dgnc_board
*brd
)
437 if (brd
->dgnc_Major_Serial_Registered
) {
438 dgnc_BoardsByMajor
[brd
->SerialDriver
.major
] = NULL
;
439 brd
->dgnc_Serial_Major
= 0;
440 for (i
= 0; i
< brd
->nasync
; i
++) {
441 dgnc_remove_tty_sysfs(brd
->channels
[i
]->ch_tun
.un_sysfs
);
442 tty_unregister_device(&brd
->SerialDriver
, i
);
444 tty_unregister_driver(&brd
->SerialDriver
);
445 brd
->dgnc_Major_Serial_Registered
= FALSE
;
448 if (brd
->dgnc_Major_TransparentPrint_Registered
) {
449 dgnc_BoardsByMajor
[brd
->PrintDriver
.major
] = NULL
;
450 brd
->dgnc_TransparentPrint_Major
= 0;
451 for (i
= 0; i
< brd
->nasync
; i
++) {
452 dgnc_remove_tty_sysfs(brd
->channels
[i
]->ch_pun
.un_sysfs
);
453 tty_unregister_device(&brd
->PrintDriver
, i
);
455 tty_unregister_driver(&brd
->PrintDriver
);
456 brd
->dgnc_Major_TransparentPrint_Registered
= FALSE
;
459 if (brd
->SerialDriver
.ttys
) {
460 kfree(brd
->SerialDriver
.ttys
);
461 brd
->SerialDriver
.ttys
= NULL
;
463 if (brd
->PrintDriver
.ttys
) {
464 kfree(brd
->PrintDriver
.ttys
);
465 brd
->PrintDriver
.ttys
= NULL
;
470 #define TMPBUFLEN (1024)
473 * dgnc_sniff - Dump data out to the "sniff" buffer if the
474 * proc sniff file is opened...
476 void dgnc_sniff_nowait_nolock(struct channel_t
*ch
, uchar
*text
, uchar
*buf
, int len
)
484 char tmpbuf
[TMPBUFLEN
];
488 /* Leave if sniff not open */
489 if (!(ch
->ch_sniff_flags
& SNIFF_OPEN
))
492 do_gettimeofday(&tv
);
494 /* Create our header for data dump */
495 p
+= sprintf(p
, "<%ld %ld><%s><", tv
.tv_sec
, tv
.tv_usec
, text
);
496 tmpbuflen
= p
- tmpbuf
;
501 for (i
= 0; i
< len
&& tmpbuflen
< (TMPBUFLEN
- 4); i
++) {
502 p
+= sprintf(p
, "%02x ", *buf
);
504 tmpbuflen
= p
- tmpbuf
;
507 if (tmpbuflen
< (TMPBUFLEN
- 4)) {
509 p
+= sprintf(p
- 1, "%s\n", ">");
511 p
+= sprintf(p
, "%s\n", ">");
517 nbuf
= strlen(tmpbuf
);
521 * Loop while data remains.
523 while (nbuf
> 0 && ch
->ch_sniff_buf
) {
525 * Determine the amount of available space left in the
526 * buffer. If there's none, wait until some appears.
528 n
= (ch
->ch_sniff_out
- ch
->ch_sniff_in
- 1) & SNIFF_MASK
;
531 * If there is no space left to write to in our sniff buffer,
532 * we have no choice but to drop the data.
533 * We *cannot* sleep here waiting for space, because this
534 * function was probably called by the interrupt/timer routines!
541 * Copy as much data as will fit.
547 r
= SNIFF_MAX
- ch
->ch_sniff_in
;
550 memcpy(ch
->ch_sniff_buf
+ ch
->ch_sniff_in
, p
, r
);
558 memcpy(ch
->ch_sniff_buf
+ ch
->ch_sniff_in
, p
, n
);
560 ch
->ch_sniff_in
+= n
;
565 * Wakeup any thread waiting for data
567 if (ch
->ch_sniff_flags
& SNIFF_WAIT_DATA
) {
568 ch
->ch_sniff_flags
&= ~SNIFF_WAIT_DATA
;
569 wake_up_interruptible(&ch
->ch_sniff_wait
);
574 * If the user sent us too much data to push into our tmpbuf,
575 * we need to keep looping around on all the data.
582 } while (too_much_data
);
586 /*=======================================================================
588 * dgnc_wmove - Write data to transmit queue.
590 * ch - Pointer to channel structure.
591 * buf - Poiter to characters to be moved.
592 * n - Number of characters to move.
594 *=======================================================================*/
595 static void dgnc_wmove(struct channel_t
*ch
, char *buf
, uint n
)
600 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
603 head
= ch
->ch_w_head
& WQUEUEMASK
;
606 * If the write wraps over the top of the circular buffer,
607 * move the portion up to the wrap point, and reset the
608 * pointers to the bottom.
610 remain
= WQUEUESIZE
- head
;
614 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
624 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
629 ch
->ch_w_head
= head
;
635 /*=======================================================================
637 * dgnc_input - Process received data.
639 * ch - Pointer to channel structure.
641 *=======================================================================*/
642 void dgnc_input(struct channel_t
*ch
)
644 struct dgnc_board
*bd
;
645 struct tty_struct
*tp
;
646 struct tty_ldisc
*ld
;
658 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
661 tp
= ch
->ch_tun
.un_tty
;
664 if(!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
667 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
670 * Figure the number of characters in the buffer.
671 * Exit immediately if none.
674 head
= ch
->ch_r_head
& rmask
;
675 tail
= ch
->ch_r_tail
& rmask
;
676 data_len
= (head
- tail
) & rmask
;
679 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
683 DPR_READ(("dgnc_input start\n"));
686 * If the device is not open, or CREAD is off,
687 * flush input data and return immediately.
689 if (!tp
|| (tp
->magic
!= TTY_MAGIC
) || !(ch
->ch_tun
.un_flags
& UN_ISOPEN
) ||
690 !(tp
->termios
.c_cflag
& CREAD
) || (ch
->ch_tun
.un_flags
& UN_CLOSING
)) {
692 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len
, ch
->ch_portnum
));
693 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
694 tp
, tp
? tp
->magic
: 0, TTY_MAGIC
, ch
->ch_tun
.un_flags
));
696 ch
->ch_r_head
= tail
;
698 /* Force queue flow control to be released, if needed */
699 dgnc_check_queue_flow_control(ch
);
701 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
706 * If we are throttled, simply don't read any data.
708 if (ch
->ch_flags
& CH_FORCED_STOPI
) {
709 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
710 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
711 ch
->ch_portnum
, head
, tail
));
715 DPR_READ(("dgnc_input start 2\n"));
717 flip_len
= TTY_FLIPBUF_SIZE
;
719 /* Chop down the length, if needed */
720 len
= min(data_len
, flip_len
);
721 len
= min(len
, (N_TTY_BUF_SIZE
- 1));
723 ld
= tty_ldisc_ref(tp
);
727 * If the DONT_FLIP flag is on, don't flush our buffer, and act
728 * like the ld doesn't have any space to put the data right now.
730 if (test_bit(TTY_DONT_FLIP
, &tp
->flags
))
735 * If we were unable to get a reference to the ld,
736 * don't flush our buffer, and act like the ld doesn't
737 * have any space to put the data right now.
743 * If ld doesn't have a pointer to a receive_buf function,
744 * flush the data, then act like the ld doesn't have any
745 * space to put the data right now.
747 if (!ld
->ops
->receive_buf
) {
748 ch
->ch_r_head
= ch
->ch_r_tail
;
754 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
761 * The tty layer in the kernel has changed in 2.6.16+.
763 * The flip buffers in the tty structure are no longer exposed,
764 * and probably will be going away eventually.
766 * If we are completely raw, we don't need to go through a lot
767 * of the tty layers that exist.
768 * In this case, we take the shortest and fastest route we
769 * can to relay the data to the user.
771 * On the other hand, if we are not raw, we need to go through
772 * the new 2.6.16+ tty layer, which has its API more well defined.
774 len
= tty_buffer_request_room(tp
->port
, len
);
778 * n now contains the most amount of data we can copy,
779 * bounded either by how much the Linux tty layer can handle,
780 * or the amount of data the card actually has pending...
783 s
= ((head
>= tail
) ? head
: RQUEUESIZE
) - tail
;
790 * If conditions are such that ld needs to see all
791 * UART errors, we will have to walk each character
792 * and error byte and send them to the buffer one at
795 if (I_PARMRK(tp
) || I_BRKINT(tp
) || I_INPCK(tp
)) {
796 for (i
= 0; i
< s
; i
++) {
797 if (*(ch
->ch_equeue
+ tail
+ i
) & UART_LSR_BI
)
798 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_BREAK
);
799 else if (*(ch
->ch_equeue
+ tail
+ i
) & UART_LSR_PE
)
800 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_PARITY
);
801 else if (*(ch
->ch_equeue
+ tail
+ i
) & UART_LSR_FE
)
802 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_FRAME
);
804 tty_insert_flip_char(tp
->port
, *(ch
->ch_rqueue
+ tail
+ i
), TTY_NORMAL
);
808 tty_insert_flip_string(tp
->port
, ch
->ch_rqueue
+ tail
, s
);
811 dgnc_sniff_nowait_nolock(ch
, "USER READ", ch
->ch_rqueue
+ tail
, s
);
815 /* Flip queue if needed */
819 ch
->ch_r_tail
= tail
& rmask
;
820 ch
->ch_e_tail
= tail
& rmask
;
821 dgnc_check_queue_flow_control(ch
);
822 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
824 /* Tell the tty layer its okay to "eat" the data now */
825 tty_flip_buffer_push(tp
->port
);
830 DPR_READ(("dgnc_input - finish\n"));
834 /************************************************************************
835 * Determines when CARRIER changes state and takes appropriate
837 ************************************************************************/
838 void dgnc_carrier(struct channel_t
*ch
)
840 struct dgnc_board
*bd
;
842 int virt_carrier
= 0;
843 int phys_carrier
= 0;
845 DPR_CARR(("dgnc_carrier called...\n"));
847 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
852 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
855 if (ch
->ch_mistat
& UART_MSR_DCD
) {
856 DPR_CARR(("mistat: %x D_CD: %x\n", ch
->ch_mistat
, ch
->ch_mistat
& UART_MSR_DCD
));
860 if (ch
->ch_digi
.digi_flags
& DIGI_FORCEDCD
) {
864 if (ch
->ch_c_cflag
& CLOCAL
) {
869 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier
, virt_carrier
));
872 * Test for a VIRTUAL carrier transition to HIGH.
874 if (((ch
->ch_flags
& CH_FCAR
) == 0) && (virt_carrier
== 1)) {
877 * When carrier rises, wake any threads waiting
878 * for carrier in the open routine.
881 DPR_CARR(("carrier: virt DCD rose\n"));
883 if (waitqueue_active(&(ch
->ch_flags_wait
)))
884 wake_up_interruptible(&ch
->ch_flags_wait
);
888 * Test for a PHYSICAL carrier transition to HIGH.
890 if (((ch
->ch_flags
& CH_CD
) == 0) && (phys_carrier
== 1)) {
893 * When carrier rises, wake any threads waiting
894 * for carrier in the open routine.
897 DPR_CARR(("carrier: physical DCD rose\n"));
899 if (waitqueue_active(&(ch
->ch_flags_wait
)))
900 wake_up_interruptible(&ch
->ch_flags_wait
);
904 * Test for a PHYSICAL transition to low, so long as we aren't
905 * currently ignoring physical transitions (which is what "virtual
906 * carrier" indicates).
908 * The transition of the virtual carrier to low really doesn't
909 * matter... it really only means "ignore carrier state", not
910 * "make pretend that carrier is there".
912 if ((virt_carrier
== 0) && ((ch
->ch_flags
& CH_CD
) != 0) &&
917 * When carrier drops:
919 * Drop carrier on all open units.
921 * Flush queues, waking up any task waiting in the
924 * Send a hangup to the control terminal.
926 * Enable all select calls.
928 if (waitqueue_active(&(ch
->ch_flags_wait
)))
929 wake_up_interruptible(&ch
->ch_flags_wait
);
931 if (ch
->ch_tun
.un_open_count
> 0) {
932 DPR_CARR(("Sending tty hangup\n"));
933 tty_hangup(ch
->ch_tun
.un_tty
);
936 if (ch
->ch_pun
.un_open_count
> 0) {
937 DPR_CARR(("Sending pr hangup\n"));
938 tty_hangup(ch
->ch_pun
.un_tty
);
943 * Make sure that our cached values reflect the current reality.
945 if (virt_carrier
== 1)
946 ch
->ch_flags
|= CH_FCAR
;
948 ch
->ch_flags
&= ~CH_FCAR
;
950 if (phys_carrier
== 1)
951 ch
->ch_flags
|= CH_CD
;
953 ch
->ch_flags
&= ~CH_CD
;
957 * Assign the custom baud rate to the channel structure
959 static void dgnc_set_custom_speed(struct channel_t
*ch
, uint newrate
)
971 * Since the divisor is stored in a 16-bit integer, we make sure
972 * we don't allow any rates smaller than a 16-bit integer would allow.
973 * And of course, rates above the dividend won't fly.
975 if (newrate
&& newrate
< ((ch
->ch_bd
->bd_dividend
/ 0xFFFF) + 1))
976 newrate
= ((ch
->ch_bd
->bd_dividend
/ 0xFFFF) + 1);
978 if (newrate
&& newrate
> ch
->ch_bd
->bd_dividend
)
979 newrate
= ch
->ch_bd
->bd_dividend
;
981 while (newrate
> 0) {
982 testdiv
= ch
->ch_bd
->bd_dividend
/ newrate
;
985 * If we try to figure out what rate the board would use
986 * with the test divisor, it will be either equal or higher
987 * than the requested baud rate. If we then determine the
988 * rate with a divisor one higher, we will get the next lower
989 * supported rate below the requested.
991 testrate_high
= ch
->ch_bd
->bd_dividend
/ testdiv
;
992 testrate_low
= ch
->ch_bd
->bd_dividend
/ (testdiv
+ 1);
995 * If the rate for the requested divisor is correct, just
996 * use it and be done.
998 if (testrate_high
== newrate
)
1002 * Otherwise, pick the rate that is closer (i.e. whichever rate
1003 * has a smaller delta).
1005 deltahigh
= testrate_high
- newrate
;
1006 deltalow
= newrate
- testrate_low
;
1008 if (deltahigh
< deltalow
) {
1009 newrate
= testrate_high
;
1011 newrate
= testrate_low
;
1017 ch
->ch_custom_speed
= newrate
;
1023 void dgnc_check_queue_flow_control(struct channel_t
*ch
)
1027 /* Store how much space we have left in the queue */
1028 if ((qleft
= ch
->ch_r_tail
- ch
->ch_r_head
- 1) < 0)
1029 qleft
+= RQUEUEMASK
+ 1;
1032 * Check to see if we should enforce flow control on our queue because
1033 * the ld (or user) isn't reading data out of our queue fast enuf.
1035 * NOTE: This is done based on what the current flow control of the
1038 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
1039 * This will cause the UART's FIFO to back up, and force
1040 * the RTS signal to be dropped.
1041 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
1042 * the other side, in hopes it will stop sending data to us.
1043 * 3) NONE - Nothing we can do. We will simply drop any extra data
1044 * that gets sent into us when the queue fills up.
1048 if (ch
->ch_digi
.digi_flags
& CTSPACE
|| ch
->ch_c_cflag
& CRTSCTS
) {
1049 if(!(ch
->ch_flags
& CH_RECEIVER_OFF
)) {
1050 ch
->ch_bd
->bd_ops
->disable_receiver(ch
);
1051 ch
->ch_flags
|= (CH_RECEIVER_OFF
);
1052 DPR_READ(("Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
1057 else if (ch
->ch_c_iflag
& IXOFF
) {
1058 if (ch
->ch_stops_sent
<= MAX_STOPS_SENT
) {
1059 ch
->ch_bd
->bd_ops
->send_stop_character(ch
);
1060 ch
->ch_stops_sent
++;
1061 DPR_READ(("Sending stop char! Times sent: %x\n", ch
->ch_stops_sent
));
1066 /* Empty... Can't do anything about the impending overflow... */
1071 * Check to see if we should unenforce flow control because
1072 * ld (or user) finally read enuf data out of our queue.
1074 * NOTE: This is done based on what the current flow control of the
1077 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
1078 * This will cause the UART's FIFO to raise RTS back up,
1079 * which will allow the other side to start sending data again.
1080 * 2) SWFLOW (IXOFF) - Send a start character to
1081 * the other side, so it will start sending data to us again.
1082 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
1083 * other side, we don't need to do anything now.
1085 if (qleft
> (RQUEUESIZE
/ 2)) {
1087 if (ch
->ch_digi
.digi_flags
& RTSPACE
|| ch
->ch_c_cflag
& CRTSCTS
) {
1088 if (ch
->ch_flags
& CH_RECEIVER_OFF
) {
1089 ch
->ch_bd
->bd_ops
->enable_receiver(ch
);
1090 ch
->ch_flags
&= ~(CH_RECEIVER_OFF
);
1091 DPR_READ(("Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
1096 else if (ch
->ch_c_iflag
& IXOFF
&& ch
->ch_stops_sent
) {
1097 ch
->ch_stops_sent
= 0;
1098 ch
->ch_bd
->bd_ops
->send_start_character(ch
);
1099 DPR_READ(("Sending start char!\n"));
1103 /* Nothing needed. */
1109 void dgnc_wakeup_writes(struct channel_t
*ch
)
1114 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1117 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1120 * If channel now has space, wake up anyone waiting on the condition.
1122 if ((qlen
= ch
->ch_w_head
- ch
->ch_w_tail
) < 0)
1125 if (qlen
>= (WQUEUESIZE
- 256)) {
1126 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1130 if (ch
->ch_tun
.un_flags
& UN_ISOPEN
) {
1131 if ((ch
->ch_tun
.un_tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1132 ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
)
1134 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1135 (ch
->ch_tun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_tun
.un_tty
);
1136 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1139 wake_up_interruptible(&ch
->ch_tun
.un_tty
->write_wait
);
1142 * If unit is set to wait until empty, check to make sure
1143 * the queue AND FIFO are both empty.
1145 if (ch
->ch_tun
.un_flags
& UN_EMPTY
) {
1146 if ((qlen
== 0) && (ch
->ch_bd
->bd_ops
->get_uart_bytes_left(ch
) == 0)) {
1147 ch
->ch_tun
.un_flags
&= ~(UN_EMPTY
);
1150 * If RTS Toggle mode is on, whenever
1151 * the queue and UART is empty, keep RTS low.
1153 if (ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
) {
1154 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
1155 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
1159 * If DTR Toggle mode is on, whenever
1160 * the queue and UART is empty, keep DTR low.
1162 if (ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
) {
1163 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
1164 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
1169 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
1172 if (ch
->ch_pun
.un_flags
& UN_ISOPEN
) {
1173 if ((ch
->ch_pun
.un_tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1174 ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
)
1176 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1177 (ch
->ch_pun
.un_tty
->ldisc
->ops
->write_wakeup
)(ch
->ch_pun
.un_tty
);
1178 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1181 wake_up_interruptible(&ch
->ch_pun
.un_tty
->write_wait
);
1184 * If unit is set to wait until empty, check to make sure
1185 * the queue AND FIFO are both empty.
1187 if (ch
->ch_pun
.un_flags
& UN_EMPTY
) {
1188 if ((qlen
== 0) && (ch
->ch_bd
->bd_ops
->get_uart_bytes_left(ch
) == 0)) {
1189 ch
->ch_pun
.un_flags
&= ~(UN_EMPTY
);
1193 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
1196 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1201 /************************************************************************
1203 * TTY Entry points and helper functions
1205 ************************************************************************/
1211 static int dgnc_tty_open(struct tty_struct
*tty
, struct file
*file
)
1213 struct dgnc_board
*brd
;
1214 struct channel_t
*ch
;
1223 major
= MAJOR(tty_devnum(tty
));
1224 minor
= MINOR(tty_devnum(tty
));
1230 /* Get board pointer from our array of majors we have allocated */
1231 brd
= dgnc_BoardsByMajor
[major
];
1237 * If board is not yet up to a state of READY, go to
1238 * sleep waiting for it to happen or they cancel the open.
1240 rc
= wait_event_interruptible(brd
->state_wait
,
1241 (brd
->state
& BOARD_READY
));
1247 DGNC_LOCK(brd
->bd_lock
, lock_flags
);
1249 /* If opened device is greater than our number of ports, bail. */
1250 if (PORT_NUM(minor
) > brd
->nasync
) {
1251 DGNC_UNLOCK(brd
->bd_lock
, lock_flags
);
1255 ch
= brd
->channels
[PORT_NUM(minor
)];
1257 DGNC_UNLOCK(brd
->bd_lock
, lock_flags
);
1261 /* Drop board lock */
1262 DGNC_UNLOCK(brd
->bd_lock
, lock_flags
);
1264 /* Grab channel lock */
1265 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1267 /* Figure out our type */
1268 if (!IS_PRINT(minor
)) {
1269 un
= &brd
->channels
[PORT_NUM(minor
)]->ch_tun
;
1270 un
->un_type
= DGNC_SERIAL
;
1272 else if (IS_PRINT(minor
)) {
1273 un
= &brd
->channels
[PORT_NUM(minor
)]->ch_pun
;
1274 un
->un_type
= DGNC_PRINT
;
1277 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1278 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__
));
1283 * If the port is still in a previous open, and in a state
1284 * where we simply cannot safely keep going, wait until the
1287 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1289 rc
= wait_event_interruptible(ch
->ch_flags_wait
, ((ch
->ch_flags
& CH_OPENING
) == 0));
1291 /* If ret is non-zero, user ctrl-c'ed us */
1293 DPR_OPEN(("%d User ctrl c'ed\n", __LINE__
));
1298 * If either unit is in the middle of the fragile part of close,
1299 * we just cannot touch the channel safely.
1300 * Go to sleep, knowing that when the channel can be
1301 * touched safely, the close routine will signal the
1302 * ch_flags_wait to wake us back up.
1304 rc
= wait_event_interruptible(ch
->ch_flags_wait
,
1305 (((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_CLOSING
) == 0));
1307 /* If ret is non-zero, user ctrl-c'ed us */
1309 DPR_OPEN(("%d User ctrl c'ed\n", __LINE__
));
1313 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1316 /* Store our unit into driver_data, so we always have it available. */
1317 tty
->driver_data
= un
;
1319 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d PORT_NUM: %x unit: %p NAME: %s\n",
1320 MAJOR(tty_devnum(tty
)), MINOR(tty_devnum(tty
)), PORT_NUM(minor
), un
, brd
->name
));
1322 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__
, ch
->ch_tun
.un_flags
, ch
->ch_pun
.un_flags
));
1327 if (!(un
->un_flags
& UN_ISOPEN
)) {
1328 /* Store important variables. */
1331 /* Maybe do something here to the TTY struct as well? */
1336 * Allocate channel buffers for read/write/error.
1337 * Set flag, so we don't get trounced on.
1339 ch
->ch_flags
|= (CH_OPENING
);
1341 /* Drop locks, as malloc with GFP_KERNEL can sleep */
1342 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1345 ch
->ch_rqueue
= kzalloc(RQUEUESIZE
, GFP_KERNEL
);
1347 ch
->ch_equeue
= kzalloc(EQUEUESIZE
, GFP_KERNEL
);
1349 ch
->ch_wqueue
= kzalloc(WQUEUESIZE
, GFP_KERNEL
);
1351 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1353 ch
->ch_flags
&= ~(CH_OPENING
);
1354 wake_up_interruptible(&ch
->ch_flags_wait
);
1357 * Initialize if neither terminal or printer is open.
1359 if (!((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_ISOPEN
)) {
1361 DPR_OPEN(("dgnc_open: initializing channel in open...\n"));
1364 * Flush input queues.
1366 ch
->ch_r_head
= ch
->ch_r_tail
= 0;
1367 ch
->ch_e_head
= ch
->ch_e_tail
= 0;
1368 ch
->ch_w_head
= ch
->ch_w_tail
= 0;
1370 brd
->bd_ops
->flush_uart_write(ch
);
1371 brd
->bd_ops
->flush_uart_read(ch
);
1374 ch
->ch_cached_lsr
= 0;
1375 ch
->ch_stop_sending_break
= 0;
1376 ch
->ch_stops_sent
= 0;
1378 ch
->ch_c_cflag
= tty
->termios
.c_cflag
;
1379 ch
->ch_c_iflag
= tty
->termios
.c_iflag
;
1380 ch
->ch_c_oflag
= tty
->termios
.c_oflag
;
1381 ch
->ch_c_lflag
= tty
->termios
.c_lflag
;
1382 ch
->ch_startc
= tty
->termios
.c_cc
[VSTART
];
1383 ch
->ch_stopc
= tty
->termios
.c_cc
[VSTOP
];
1386 * Bring up RTS and DTR...
1387 * Also handle RTS or DTR toggle if set.
1389 if (!(ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
))
1390 ch
->ch_mostat
|= (UART_MCR_RTS
);
1391 if (!(ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
))
1392 ch
->ch_mostat
|= (UART_MCR_DTR
);
1394 /* Tell UART to init itself */
1395 brd
->bd_ops
->uart_init(ch
);
1399 * Run param in case we changed anything
1401 brd
->bd_ops
->param(tty
);
1406 * follow protocol for opening port
1409 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1411 rc
= dgnc_block_til_ready(tty
, file
, ch
);
1414 DPR_OPEN(("dgnc_tty_open returning after dgnc_block_til_ready "
1418 /* No going back now, increment our unit and channel counters */
1419 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1420 ch
->ch_open_count
++;
1421 un
->un_open_count
++;
1422 un
->un_flags
|= (UN_ISOPEN
);
1423 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1425 DPR_OPEN(("dgnc_tty_open finished\n"));
1431 * dgnc_block_til_ready()
1433 * Wait for DCD, if needed.
1435 static int dgnc_block_til_ready(struct tty_struct
*tty
, struct file
*file
, struct channel_t
*ch
)
1438 struct un_t
*un
= NULL
;
1441 int sleep_on_un_flags
= 0;
1443 if (!tty
|| tty
->magic
!= TTY_MAGIC
|| !file
|| !ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
) {
1447 un
= tty
->driver_data
;
1448 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
) {
1452 DPR_OPEN(("dgnc_block_til_ready - before block.\n"));
1454 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1461 sleep_on_un_flags
= 0;
1464 * If board has failed somehow during our sleep, bail with error.
1466 if (ch
->ch_bd
->state
== BOARD_FAILED
) {
1471 /* If tty was hung up, break out of loop and set error. */
1472 if (tty_hung_up_p(file
)) {
1478 * If either unit is in the middle of the fragile part of close,
1479 * we just cannot touch the channel safely.
1480 * Go back to sleep, knowing that when the channel can be
1481 * touched safely, the close routine will signal the
1482 * ch_wait_flags to wake us back up.
1484 if (!((ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
) & UN_CLOSING
)) {
1487 * Our conditions to leave cleanly and happily:
1488 * 1) NONBLOCKING on the tty is set.
1490 * 3) DCD (fake or real) is active.
1493 if (file
->f_flags
& O_NONBLOCK
) {
1497 if (tty
->flags
& (1 << TTY_IO_ERROR
)) {
1502 if (ch
->ch_flags
& CH_CD
) {
1503 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__
, ch
->ch_flags
));
1507 if (ch
->ch_flags
& CH_FCAR
) {
1508 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__
, ch
->ch_flags
));
1513 sleep_on_un_flags
= 1;
1517 * If there is a signal pending, the user probably
1518 * interrupted (ctrl-c) us.
1519 * Leave loop with error set.
1521 if (signal_pending(current
)) {
1522 DPR_OPEN(("%d: signal pending...\n", __LINE__
));
1523 retval
= -ERESTARTSYS
;
1527 DPR_OPEN(("dgnc_block_til_ready - blocking.\n"));
1530 * Store the flags before we let go of channel lock
1532 if (sleep_on_un_flags
)
1533 old_flags
= ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
;
1535 old_flags
= ch
->ch_flags
;
1538 * Let go of channel lock before calling schedule.
1539 * Our poller will get any FEP events and wake us up when DCD
1540 * eventually goes active.
1543 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1545 DPR_OPEN(("Going to sleep on %s flags...\n",
1546 (sleep_on_un_flags
? "un" : "ch")));
1549 * Wait for something in the flags to change from the current value.
1551 if (sleep_on_un_flags
) {
1552 retval
= wait_event_interruptible(un
->un_flags_wait
,
1553 (old_flags
!= (ch
->ch_tun
.un_flags
| ch
->ch_pun
.un_flags
)));
1556 retval
= wait_event_interruptible(ch
->ch_flags_wait
,
1557 (old_flags
!= ch
->ch_flags
));
1560 DPR_OPEN(("After sleep... retval: %x\n", retval
));
1563 * We got woken up for some reason.
1564 * Before looping around, grab our channel lock.
1566 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1571 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1573 DPR_OPEN(("dgnc_block_til_ready - after blocking.\n"));
1576 DPR_OPEN(("dgnc_block_til_ready - done. error. retval: %x\n", retval
));
1580 DPR_OPEN(("dgnc_block_til_ready - done no error. jiffies: %lu\n", jiffies
));
1589 * Hangup the port. Like a close, but don't wait for output to drain.
1591 static void dgnc_tty_hangup(struct tty_struct
*tty
)
1595 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
1598 un
= tty
->driver_data
;
1599 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1602 DPR_CLOSE(("dgnc_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
1603 un
->un_ch
->ch_open_count
, un
->un_open_count
));
1605 /* flush the transmit queues */
1606 dgnc_tty_flush_buffer(tty
);
1608 DPR_CLOSE(("dgnc_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
1609 un
->un_ch
->ch_open_count
, un
->un_open_count
));
1617 static void dgnc_tty_close(struct tty_struct
*tty
, struct file
*file
)
1619 struct ktermios
*ts
;
1620 struct dgnc_board
*bd
;
1621 struct channel_t
*ch
;
1626 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
1629 un
= tty
->driver_data
;
1630 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1634 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1638 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
1643 DPR_CLOSE(("Close called\n"));
1645 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1648 * Determine if this is the last close or not - and if we agree about
1649 * which type of close it is with the Line Discipline
1651 if ((tty
->count
== 1) && (un
->un_open_count
!= 1)) {
1653 * Uh, oh. tty->count is 1, which means that the tty
1654 * structure will be freed. un_open_count should always
1655 * be one in these conditions. If it's greater than
1656 * one, we've got real problems, since it means the
1657 * serial port won't be shutdown.
1659 APR(("tty->count is 1, un open count is %d\n", un
->un_open_count
));
1660 un
->un_open_count
= 1;
1663 if (--un
->un_open_count
< 0) {
1664 APR(("bad serial port open count of %d\n", un
->un_open_count
));
1665 un
->un_open_count
= 0;
1668 ch
->ch_open_count
--;
1670 if (ch
->ch_open_count
&& un
->un_open_count
) {
1671 DPR_CLOSE(("dgnc_tty_close: not last close ch: %d un:%d\n",
1672 ch
->ch_open_count
, un
->un_open_count
));
1674 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1678 /* OK, its the last close on the unit */
1679 DPR_CLOSE(("dgnc_tty_close - last close on unit procedures\n"));
1681 un
->un_flags
|= UN_CLOSING
;
1687 * Only officially close channel if count is 0 and
1688 * DIGI_PRINTER bit is not set.
1690 if ((ch
->ch_open_count
== 0) && !(ch
->ch_digi
.digi_flags
& DIGI_PRINTER
)) {
1692 ch
->ch_flags
&= ~(CH_STOPI
| CH_FORCED_STOPI
);
1695 * turn off print device when closing print device.
1697 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
) ) {
1698 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
1699 (int) ch
->ch_digi
.digi_offlen
);
1700 ch
->ch_flags
&= ~CH_PRON
;
1703 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1704 /* wait for output to drain */
1705 /* This will also return if we take an interrupt */
1707 DPR_CLOSE(("Calling wait_for_drain\n"));
1708 rc
= bd
->bd_ops
->drain(tty
, 0);
1710 DPR_CLOSE(("After calling wait_for_drain\n"));
1713 DPR_BASIC(("dgnc_tty_close - bad return: %d ", rc
));
1716 dgnc_tty_flush_buffer(tty
);
1717 tty_ldisc_flush(tty
);
1719 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1724 * If we have HUPCL set, lower DTR and RTS
1726 if (ch
->ch_c_cflag
& HUPCL
) {
1727 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
1730 ch
->ch_mostat
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
1731 bd
->bd_ops
->assert_modem_signals(ch
);
1734 * Go to sleep to ensure RTS/DTR
1735 * have been dropped for modems to see it.
1737 if (ch
->ch_close_delay
) {
1738 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
1740 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1741 dgnc_ms_sleep(ch
->ch_close_delay
);
1742 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1744 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
1748 ch
->ch_old_baud
= 0;
1750 /* Turn off UART interrupts for this port */
1751 ch
->ch_bd
->bd_ops
->uart_off(ch
);
1755 * turn off print device when closing print device.
1757 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
) ) {
1758 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
1759 (int) ch
->ch_digi
.digi_offlen
);
1760 ch
->ch_flags
&= ~CH_PRON
;
1765 un
->un_flags
&= ~(UN_ISOPEN
| UN_CLOSING
);
1767 DPR_CLOSE(("Close. Doing wakeups\n"));
1768 wake_up_interruptible(&ch
->ch_flags_wait
);
1769 wake_up_interruptible(&un
->un_flags_wait
);
1771 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1773 DPR_BASIC(("dgnc_tty_close - complete\n"));
1778 * dgnc_tty_chars_in_buffer()
1780 * Return number of characters that have not been transmitted yet.
1782 * This routine is used by the line discipline to determine if there
1783 * is data waiting to be transmitted/drained/flushed or not.
1785 static int dgnc_tty_chars_in_buffer(struct tty_struct
*tty
)
1787 struct channel_t
*ch
= NULL
;
1788 struct un_t
*un
= NULL
;
1793 ulong lock_flags
= 0;
1798 un
= tty
->driver_data
;
1799 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1803 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1806 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1809 thead
= ch
->ch_w_head
& tmask
;
1810 ttail
= ch
->ch_w_tail
& tmask
;
1812 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1814 if (ttail
== thead
) {
1818 chars
= thead
- ttail
;
1820 chars
= thead
- ttail
+ WQUEUESIZE
;
1823 DPR_WRITE(("dgnc_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d)\n",
1824 ch
->ch_portnum
, chars
, thead
, ttail
));
1833 * Reduces bytes_available to the max number of characters
1834 * that can be sent currently given the maxcps value, and
1835 * returns the new bytes_available. This only affects printer
1838 static int dgnc_maxcps_room(struct tty_struct
*tty
, int bytes_available
)
1840 struct channel_t
*ch
= NULL
;
1841 struct un_t
*un
= NULL
;
1844 return bytes_available
;
1846 un
= tty
->driver_data
;
1847 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1848 return bytes_available
;
1851 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1852 return bytes_available
;
1855 * If its not the Transparent print device, return
1856 * the full data amount.
1858 if (un
->un_type
!= DGNC_PRINT
)
1859 return bytes_available
;
1861 if (ch
->ch_digi
.digi_maxcps
> 0 && ch
->ch_digi
.digi_bufsize
> 0 ) {
1863 unsigned long current_time
= jiffies
;
1864 unsigned long buffer_time
= current_time
+
1865 (HZ
* ch
->ch_digi
.digi_bufsize
) / ch
->ch_digi
.digi_maxcps
;
1867 if (ch
->ch_cpstime
< current_time
) {
1868 /* buffer is empty */
1869 ch
->ch_cpstime
= current_time
; /* reset ch_cpstime */
1870 cps_limit
= ch
->ch_digi
.digi_bufsize
;
1872 else if (ch
->ch_cpstime
< buffer_time
) {
1873 /* still room in the buffer */
1874 cps_limit
= ((buffer_time
- ch
->ch_cpstime
) * ch
->ch_digi
.digi_maxcps
) / HZ
;
1877 /* no room in the buffer */
1881 bytes_available
= min(cps_limit
, bytes_available
);
1884 return bytes_available
;
1889 * dgnc_tty_write_room()
1891 * Return space available in Tx buffer
1893 static int dgnc_tty_write_room(struct tty_struct
*tty
)
1895 struct channel_t
*ch
= NULL
;
1896 struct un_t
*un
= NULL
;
1901 ulong lock_flags
= 0;
1903 if (tty
== NULL
|| dgnc_TmpWriteBuf
== NULL
)
1906 un
= tty
->driver_data
;
1907 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1911 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
1914 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
1917 head
= (ch
->ch_w_head
) & tmask
;
1918 tail
= (ch
->ch_w_tail
) & tmask
;
1920 if ((ret
= tail
- head
- 1) < 0)
1923 /* Limit printer to maxcps */
1924 ret
= dgnc_maxcps_room(tty
, ret
);
1927 * If we are printer device, leave space for
1928 * possibly both the on and off strings.
1930 if (un
->un_type
== DGNC_PRINT
) {
1931 if (!(ch
->ch_flags
& CH_PRON
))
1932 ret
-= ch
->ch_digi
.digi_onlen
;
1933 ret
-= ch
->ch_digi
.digi_offlen
;
1936 if (ch
->ch_flags
& CH_PRON
)
1937 ret
-= ch
->ch_digi
.digi_offlen
;
1943 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
1945 DPR_WRITE(("dgnc_tty_write_room - %d tail: %d head: %d\n", ret
, tail
, head
));
1952 * dgnc_tty_put_char()
1954 * Put a character into ch->ch_buf
1956 * - used by the line discipline for OPOST processing
1958 static int dgnc_tty_put_char(struct tty_struct
*tty
, unsigned char c
)
1961 * Simply call tty_write.
1963 DPR_WRITE(("dgnc_tty_put_char called\n"));
1964 dgnc_tty_write(tty
, &c
, 1);
1972 * Take data from the user or kernel and send it out to the FEP.
1973 * In here exists all the Transparent Print magic as well.
1975 static int dgnc_tty_write(struct tty_struct
*tty
,
1976 const unsigned char *buf
, int count
)
1978 struct channel_t
*ch
= NULL
;
1979 struct un_t
*un
= NULL
;
1980 int bufcount
= 0, n
= 0;
1989 if (tty
== NULL
|| dgnc_TmpWriteBuf
== NULL
)
1992 un
= tty
->driver_data
;
1993 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
1997 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2003 DPR_WRITE(("dgnc_tty_write: Port: %x tty=%p user=%d len=%d\n",
2004 ch
->ch_portnum
, tty
, from_user
, count
));
2007 * Store original amount of characters passed in.
2008 * This helps to figure out if we should ask the FEP
2009 * to send us an event when it has more space available.
2013 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2015 /* Get our space available for the channel from the board */
2017 head
= (ch
->ch_w_head
) & tmask
;
2018 tail
= (ch
->ch_w_tail
) & tmask
;
2020 if ((bufcount
= tail
- head
- 1) < 0)
2021 bufcount
+= WQUEUESIZE
;
2023 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
2024 __LINE__
, bufcount
, count
, tail
, head
, tmask
));
2027 * Limit printer output to maxcps overall, with bursts allowed
2028 * up to bufsize characters.
2030 bufcount
= dgnc_maxcps_room(tty
, bufcount
);
2033 * Take minimum of what the user wants to send, and the
2034 * space available in the FEP buffer.
2036 count
= min(count
, bufcount
);
2039 * Bail if no space left.
2042 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2047 * Output the printer ON string, if we are in terminal mode, but
2048 * need to be in printer mode.
2050 if ((un
->un_type
== DGNC_PRINT
) && !(ch
->ch_flags
& CH_PRON
)) {
2051 dgnc_wmove(ch
, ch
->ch_digi
.digi_onstr
,
2052 (int) ch
->ch_digi
.digi_onlen
);
2053 head
= (ch
->ch_w_head
) & tmask
;
2054 ch
->ch_flags
|= CH_PRON
;
2058 * On the other hand, output the printer OFF string, if we are
2059 * currently in printer mode, but need to output to the terminal.
2061 if ((un
->un_type
!= DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
2062 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
2063 (int) ch
->ch_digi
.digi_offlen
);
2064 head
= (ch
->ch_w_head
) & tmask
;
2065 ch
->ch_flags
&= ~CH_PRON
;
2069 * If there is nothing left to copy, or I can't handle any more data, leave.
2072 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2078 count
= min(count
, WRITEBUFLEN
);
2080 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2083 * If data is coming from user space, copy it into a temporary
2084 * buffer so we don't get swapped out while doing the copy to
2087 /* we're allowed to block if it's from_user */
2088 if (down_interruptible(&dgnc_TmpWriteSem
)) {
2093 * copy_from_user() returns the number
2094 * of bytes that could *NOT* be copied.
2096 count
-= copy_from_user(dgnc_TmpWriteBuf
, (const uchar __user
*) buf
, count
);
2099 up(&dgnc_TmpWriteSem
);
2103 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2105 buf
= dgnc_TmpWriteBuf
;
2112 * If the write wraps over the top of the circular buffer,
2113 * move the portion up to the wrap point, and reset the
2114 * pointers to the bottom.
2116 remain
= WQUEUESIZE
- head
;
2120 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
2121 dgnc_sniff_nowait_nolock(ch
, "USER WRITE", ch
->ch_wqueue
+ head
, remain
);
2128 * Move rest of data.
2131 memcpy(ch
->ch_wqueue
+ head
, buf
, remain
);
2132 dgnc_sniff_nowait_nolock(ch
, "USER WRITE", ch
->ch_wqueue
+ head
, remain
);
2138 ch
->ch_w_head
= head
;
2143 * If this is the print device, and the
2144 * printer is still on, we need to turn it
2145 * off before going idle.
2147 if (count
== orig_count
) {
2148 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_flags
& CH_PRON
)) {
2150 ch
->ch_w_head
= head
;
2151 dgnc_wmove(ch
, ch
->ch_digi
.digi_offstr
,
2152 (int) ch
->ch_digi
.digi_offlen
);
2153 head
= (ch
->ch_w_head
) & tmask
;
2154 ch
->ch_flags
&= ~CH_PRON
;
2159 /* Update printer buffer empty time. */
2160 if ((un
->un_type
== DGNC_PRINT
) && (ch
->ch_digi
.digi_maxcps
> 0)
2161 && (ch
->ch_digi
.digi_bufsize
> 0)) {
2162 ch
->ch_cpstime
+= (HZ
* count
) / ch
->ch_digi
.digi_maxcps
;
2166 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2167 up(&dgnc_TmpWriteSem
);
2169 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2172 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count
, orig_count
));
2176 * Channel lock is grabbed and then released
2177 * inside this routine.
2179 ch
->ch_bd
->bd_ops
->copy_data_from_queue_to_uart(ch
);
2187 * Return modem signals to ld.
2190 static int dgnc_tty_tiocmget(struct tty_struct
*tty
)
2192 struct channel_t
*ch
;
2198 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2201 un
= tty
->driver_data
;
2202 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2206 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2209 DPR_IOCTL(("dgnc_tty_tiocmget start\n"));
2211 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2213 mstat
= (ch
->ch_mostat
| ch
->ch_mistat
);
2215 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2219 if (mstat
& UART_MCR_DTR
)
2220 result
|= TIOCM_DTR
;
2221 if (mstat
& UART_MCR_RTS
)
2222 result
|= TIOCM_RTS
;
2223 if (mstat
& UART_MSR_CTS
)
2224 result
|= TIOCM_CTS
;
2225 if (mstat
& UART_MSR_DSR
)
2226 result
|= TIOCM_DSR
;
2227 if (mstat
& UART_MSR_RI
)
2229 if (mstat
& UART_MSR_DCD
)
2232 DPR_IOCTL(("dgnc_tty_tiocmget finish\n"));
2239 * dgnc_tty_tiocmset()
2241 * Set modem signals, called by ld.
2244 static int dgnc_tty_tiocmset(struct tty_struct
*tty
,
2245 unsigned int set
, unsigned int clear
)
2247 struct dgnc_board
*bd
;
2248 struct channel_t
*ch
;
2253 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2256 un
= tty
->driver_data
;
2257 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2261 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2265 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2268 DPR_IOCTL(("dgnc_tty_tiocmset start\n"));
2271 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2273 if (set
& TIOCM_RTS
) {
2274 ch
->ch_mostat
|= UART_MCR_RTS
;
2277 if (set
& TIOCM_DTR
) {
2278 ch
->ch_mostat
|= UART_MCR_DTR
;
2281 if (clear
& TIOCM_RTS
) {
2282 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2285 if (clear
& TIOCM_DTR
) {
2286 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2289 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
2291 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2293 DPR_IOCTL(("dgnc_tty_tiocmset finish\n"));
2300 * dgnc_tty_send_break()
2302 * Send a Break, called by ld.
2304 static int dgnc_tty_send_break(struct tty_struct
*tty
, int msec
)
2306 struct dgnc_board
*bd
;
2307 struct channel_t
*ch
;
2312 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2315 un
= tty
->driver_data
;
2316 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2320 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2324 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2338 DPR_IOCTL(("dgnc_tty_send_break start 1. %lx\n", jiffies
));
2340 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2342 ch
->ch_bd
->bd_ops
->send_break(ch
, msec
);
2344 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2346 DPR_IOCTL(("dgnc_tty_send_break finish\n"));
2354 * dgnc_tty_wait_until_sent()
2356 * wait until data has been transmitted, called by ld.
2358 static void dgnc_tty_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2360 struct dgnc_board
*bd
;
2361 struct channel_t
*ch
;
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 rc
= bd
->bd_ops
->drain(tty
, 0);
2382 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
2392 * send a high priority character, called by ld.
2394 static void dgnc_tty_send_xchar(struct tty_struct
*tty
, char c
)
2396 struct dgnc_board
*bd
;
2397 struct channel_t
*ch
;
2401 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2404 un
= tty
->driver_data
;
2405 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2409 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2413 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2416 DPR_IOCTL(("dgnc_tty_send_xchar start\n"));
2417 printk("dgnc_tty_send_xchar start\n");
2419 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2420 bd
->bd_ops
->send_immediate_char(ch
, c
);
2421 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2423 DPR_IOCTL(("dgnc_tty_send_xchar finish\n"));
2424 printk("dgnc_tty_send_xchar finish\n");
2432 * Return modem signals to ld.
2434 static inline int dgnc_get_mstat(struct channel_t
*ch
)
2436 unsigned char mstat
;
2440 DPR_IOCTL(("dgnc_getmstat start\n"));
2442 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2445 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2447 mstat
= (ch
->ch_mostat
| ch
->ch_mistat
);
2449 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2453 if (mstat
& UART_MCR_DTR
)
2454 result
|= TIOCM_DTR
;
2455 if (mstat
& UART_MCR_RTS
)
2456 result
|= TIOCM_RTS
;
2457 if (mstat
& UART_MSR_CTS
)
2458 result
|= TIOCM_CTS
;
2459 if (mstat
& UART_MSR_DSR
)
2460 result
|= TIOCM_DSR
;
2461 if (mstat
& UART_MSR_RI
)
2463 if (mstat
& UART_MSR_DCD
)
2466 DPR_IOCTL(("dgnc_getmstat finish\n"));
2474 * Return modem signals to ld.
2476 static int dgnc_get_modem_info(struct channel_t
*ch
, unsigned int __user
*value
)
2481 DPR_IOCTL(("dgnc_get_modem_info start\n"));
2483 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2486 result
= dgnc_get_mstat(ch
);
2491 rc
= put_user(result
, value
);
2493 DPR_IOCTL(("dgnc_get_modem_info finish\n"));
2499 * dgnc_set_modem_info()
2501 * Set modem signals, called by ld.
2503 static int dgnc_set_modem_info(struct tty_struct
*tty
, unsigned int command
, unsigned int __user
*value
)
2505 struct dgnc_board
*bd
;
2506 struct channel_t
*ch
;
2509 unsigned int arg
= 0;
2512 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2515 un
= tty
->driver_data
;
2516 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2520 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2524 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2529 DPR_IOCTL(("dgnc_set_modem_info() start\n"));
2531 ret
= get_user(arg
, value
);
2537 if (arg
& TIOCM_RTS
) {
2538 ch
->ch_mostat
|= UART_MCR_RTS
;
2541 if (arg
& TIOCM_DTR
) {
2542 ch
->ch_mostat
|= UART_MCR_DTR
;
2548 if (arg
& TIOCM_RTS
) {
2549 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2552 if (arg
& TIOCM_DTR
) {
2553 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2560 if (arg
& TIOCM_RTS
) {
2561 ch
->ch_mostat
|= UART_MCR_RTS
;
2564 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2567 if (arg
& TIOCM_DTR
) {
2568 ch
->ch_mostat
|= UART_MCR_DTR
;
2571 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2580 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2582 ch
->ch_bd
->bd_ops
->assert_modem_signals(ch
);
2584 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2586 DPR_IOCTL(("dgnc_set_modem_info finish\n"));
2593 * dgnc_tty_digigeta()
2595 * Ioctl to get the information for ditty.
2600 static int dgnc_tty_digigeta(struct tty_struct
*tty
, struct digi_t __user
*retinfo
)
2602 struct channel_t
*ch
;
2610 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2613 un
= tty
->driver_data
;
2614 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2618 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2621 memset(&tmp
, 0, sizeof(tmp
));
2623 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2624 memcpy(&tmp
, &ch
->ch_digi
, sizeof(tmp
));
2625 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2627 if (copy_to_user(retinfo
, &tmp
, sizeof(*retinfo
)))
2635 * dgnc_tty_digiseta()
2637 * Ioctl to set the information for ditty.
2642 static int dgnc_tty_digiseta(struct tty_struct
*tty
, struct digi_t __user
*new_info
)
2644 struct dgnc_board
*bd
;
2645 struct channel_t
*ch
;
2647 struct digi_t new_digi
;
2650 DPR_IOCTL(("DIGI_SETA start\n"));
2652 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2655 un
= tty
->driver_data
;
2656 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2660 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2664 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2667 if (copy_from_user(&new_digi
, new_info
, sizeof(new_digi
))) {
2668 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
2672 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2675 * Handle transistions to and from RTS Toggle.
2677 if (!(ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
) && (new_digi
.digi_flags
& DIGI_RTS_TOGGLE
))
2678 ch
->ch_mostat
&= ~(UART_MCR_RTS
);
2679 if ((ch
->ch_digi
.digi_flags
& DIGI_RTS_TOGGLE
) && !(new_digi
.digi_flags
& DIGI_RTS_TOGGLE
))
2680 ch
->ch_mostat
|= (UART_MCR_RTS
);
2683 * Handle transistions to and from DTR Toggle.
2685 if (!(ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
) && (new_digi
.digi_flags
& DIGI_DTR_TOGGLE
))
2686 ch
->ch_mostat
&= ~(UART_MCR_DTR
);
2687 if ((ch
->ch_digi
.digi_flags
& DIGI_DTR_TOGGLE
) && !(new_digi
.digi_flags
& DIGI_DTR_TOGGLE
))
2688 ch
->ch_mostat
|= (UART_MCR_DTR
);
2690 memcpy(&ch
->ch_digi
, &new_digi
, sizeof(new_digi
));
2692 if (ch
->ch_digi
.digi_maxcps
< 1)
2693 ch
->ch_digi
.digi_maxcps
= 1;
2695 if (ch
->ch_digi
.digi_maxcps
> 10000)
2696 ch
->ch_digi
.digi_maxcps
= 10000;
2698 if (ch
->ch_digi
.digi_bufsize
< 10)
2699 ch
->ch_digi
.digi_bufsize
= 10;
2701 if (ch
->ch_digi
.digi_maxchar
< 1)
2702 ch
->ch_digi
.digi_maxchar
= 1;
2704 if (ch
->ch_digi
.digi_maxchar
> ch
->ch_digi
.digi_bufsize
)
2705 ch
->ch_digi
.digi_maxchar
= ch
->ch_digi
.digi_bufsize
;
2707 if (ch
->ch_digi
.digi_onlen
> DIGI_PLEN
)
2708 ch
->ch_digi
.digi_onlen
= DIGI_PLEN
;
2710 if (ch
->ch_digi
.digi_offlen
> DIGI_PLEN
)
2711 ch
->ch_digi
.digi_offlen
= DIGI_PLEN
;
2713 ch
->ch_bd
->bd_ops
->param(tty
);
2715 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2717 DPR_IOCTL(("DIGI_SETA finish\n"));
2724 * dgnc_set_termios()
2726 static void dgnc_tty_set_termios(struct tty_struct
*tty
, struct ktermios
*old_termios
)
2728 struct dgnc_board
*bd
;
2729 struct channel_t
*ch
;
2731 unsigned long lock_flags
;
2733 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2736 un
= tty
->driver_data
;
2737 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2741 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2745 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2748 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2750 ch
->ch_c_cflag
= tty
->termios
.c_cflag
;
2751 ch
->ch_c_iflag
= tty
->termios
.c_iflag
;
2752 ch
->ch_c_oflag
= tty
->termios
.c_oflag
;
2753 ch
->ch_c_lflag
= tty
->termios
.c_lflag
;
2754 ch
->ch_startc
= tty
->termios
.c_cc
[VSTART
];
2755 ch
->ch_stopc
= tty
->termios
.c_cc
[VSTOP
];
2757 ch
->ch_bd
->bd_ops
->param(tty
);
2760 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2764 static void dgnc_tty_throttle(struct tty_struct
*tty
)
2766 struct channel_t
*ch
;
2768 ulong lock_flags
= 0;
2770 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2773 un
= tty
->driver_data
;
2774 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2778 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2781 DPR_IOCTL(("dgnc_tty_throttle start\n"));
2783 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2785 ch
->ch_flags
|= (CH_FORCED_STOPI
);
2787 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2789 DPR_IOCTL(("dgnc_tty_throttle finish\n"));
2793 static void dgnc_tty_unthrottle(struct tty_struct
*tty
)
2795 struct channel_t
*ch
;
2799 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2802 un
= tty
->driver_data
;
2803 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2807 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2810 DPR_IOCTL(("dgnc_tty_unthrottle start\n"));
2812 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2814 ch
->ch_flags
&= ~(CH_FORCED_STOPI
);
2816 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2818 DPR_IOCTL(("dgnc_tty_unthrottle finish\n"));
2822 static void dgnc_tty_start(struct tty_struct
*tty
)
2824 struct dgnc_board
*bd
;
2825 struct channel_t
*ch
;
2829 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2832 un
= tty
->driver_data
;
2833 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2837 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2841 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2844 DPR_IOCTL(("dgcn_tty_start start\n"));
2846 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2848 ch
->ch_flags
&= ~(CH_FORCED_STOP
);
2850 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2852 DPR_IOCTL(("dgnc_tty_start finish\n"));
2856 static void dgnc_tty_stop(struct tty_struct
*tty
)
2858 struct dgnc_board
*bd
;
2859 struct channel_t
*ch
;
2863 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2866 un
= tty
->driver_data
;
2867 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2871 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2875 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2878 DPR_IOCTL(("dgnc_tty_stop start\n"));
2880 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2882 ch
->ch_flags
|= (CH_FORCED_STOP
);
2884 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2886 DPR_IOCTL(("dgnc_tty_stop finish\n"));
2891 * dgnc_tty_flush_chars()
2893 * Flush the cook buffer
2895 * Note to self, and any other poor souls who venture here:
2897 * flush in this case DOES NOT mean dispose of the data.
2898 * instead, it means "stop buffering and send it if you
2899 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
2901 * It is also always called in interrupt context - JAR 8-Sept-99
2903 static void dgnc_tty_flush_chars(struct tty_struct
*tty
)
2905 struct dgnc_board
*bd
;
2906 struct channel_t
*ch
;
2910 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2913 un
= tty
->driver_data
;
2914 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2918 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2922 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
2925 DPR_IOCTL(("dgnc_tty_flush_chars start\n"));
2927 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2929 /* Do something maybe here */
2931 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2933 DPR_IOCTL(("dgnc_tty_flush_chars finish\n"));
2939 * dgnc_tty_flush_buffer()
2941 * Flush Tx buffer (make in == out)
2943 static void dgnc_tty_flush_buffer(struct tty_struct
*tty
)
2945 struct channel_t
*ch
;
2949 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
2952 un
= tty
->driver_data
;
2953 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
2957 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
2960 DPR_IOCTL(("dgnc_tty_flush_buffer on port: %d start\n", ch
->ch_portnum
));
2962 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
2964 ch
->ch_flags
&= ~CH_STOP
;
2966 /* Flush our write queue */
2967 ch
->ch_w_head
= ch
->ch_w_tail
;
2969 /* Flush UARTs transmit FIFO */
2970 ch
->ch_bd
->bd_ops
->flush_uart_write(ch
);
2972 if (ch
->ch_tun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
2973 ch
->ch_tun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
2974 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
2976 if (ch
->ch_pun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
2977 ch
->ch_pun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
2978 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
2981 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
2983 DPR_IOCTL(("dgnc_tty_flush_buffer finish\n"));
2988 /*****************************************************************************
2990 * The IOCTL function and all of its helpers
2992 *****************************************************************************/
2997 * The usual assortment of ioctl's
2999 static int dgnc_tty_ioctl(struct tty_struct
*tty
, unsigned int cmd
,
3002 struct dgnc_board
*bd
;
3003 struct channel_t
*ch
;
3007 void __user
*uarg
= (void __user
*) arg
;
3009 if (!tty
|| tty
->magic
!= TTY_MAGIC
)
3012 un
= tty
->driver_data
;
3013 if (!un
|| un
->magic
!= DGNC_UNIT_MAGIC
)
3017 if (!ch
|| ch
->magic
!= DGNC_CHANNEL_MAGIC
)
3021 if (!bd
|| bd
->magic
!= DGNC_BOARD_MAGIC
)
3024 DPR_IOCTL(("dgnc_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
3025 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3027 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3029 if (un
->un_open_count
<= 0) {
3030 DPR_BASIC(("dgnc_tty_ioctl - unit not open.\n"));
3031 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3037 /* Here are all the standard ioctl's that we MUST implement */
3041 * TCSBRK is SVID version: non-zero arg --> no break
3042 * this behaviour is exploited by tcdrain().
3044 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3045 * between 0.25 and 0.5 seconds so we'll ask for something
3046 * in the middle: 0.375 seconds.
3048 rc
= tty_check_change(tty
);
3049 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3054 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3057 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3061 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3063 if(((cmd
== TCSBRK
) && (!arg
)) || (cmd
== TCSBRKP
)) {
3064 ch
->ch_bd
->bd_ops
->send_break(ch
, 250);
3067 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3069 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3070 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3076 /* support for POSIX tcsendbreak()
3077 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3078 * between 0.25 and 0.5 seconds so we'll ask for something
3079 * in the middle: 0.375 seconds.
3081 rc
= tty_check_change(tty
);
3082 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3087 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3089 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3093 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3095 ch
->ch_bd
->bd_ops
->send_break(ch
, 250);
3097 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3099 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3100 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3105 rc
= tty_check_change(tty
);
3106 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3111 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3113 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3117 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3119 ch
->ch_bd
->bd_ops
->send_break(ch
, 250);
3121 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3123 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3124 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3130 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3135 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3137 rc
= put_user(C_CLOCAL(tty
) ? 1 : 0, (unsigned long __user
*) arg
);
3142 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3143 rc
= get_user(arg
, (unsigned long __user
*) arg
);
3147 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3148 tty
->termios
.c_cflag
= ((tty
->termios
.c_cflag
& ~CLOCAL
) | (arg
? CLOCAL
: 0));
3149 ch
->ch_bd
->bd_ops
->param(tty
);
3150 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3155 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3156 return dgnc_get_modem_info(ch
, uarg
);
3161 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3162 return dgnc_set_modem_info(tty
, cmd
, uarg
);
3165 * Here are any additional ioctl's that we want to implement
3170 * The linux tty driver doesn't have a flush
3171 * input routine for the driver, assuming all backed
3172 * up data is in the line disc. buffers. However,
3173 * we all know that's not the case. Here, we
3174 * act on the ioctl, but then lie and say we didn't
3175 * so the line discipline will process the flush
3178 rc
= tty_check_change(tty
);
3180 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3184 if ((arg
== TCIFLUSH
) || (arg
== TCIOFLUSH
)) {
3185 ch
->ch_r_head
= ch
->ch_r_tail
;
3186 ch
->ch_bd
->bd_ops
->flush_uart_read(ch
);
3187 /* Force queue flow control to be released, if needed */
3188 dgnc_check_queue_flow_control(ch
);
3191 if ((arg
== TCOFLUSH
) || (arg
== TCIOFLUSH
)) {
3192 if (!(un
->un_type
== DGNC_PRINT
)) {
3193 ch
->ch_w_head
= ch
->ch_w_tail
;
3194 ch
->ch_bd
->bd_ops
->flush_uart_write(ch
);
3196 if (ch
->ch_tun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
3197 ch
->ch_tun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
3198 wake_up_interruptible(&ch
->ch_tun
.un_flags_wait
);
3201 if (ch
->ch_pun
.un_flags
& (UN_LOW
|UN_EMPTY
)) {
3202 ch
->ch_pun
.un_flags
&= ~(UN_LOW
|UN_EMPTY
);
3203 wake_up_interruptible(&ch
->ch_pun
.un_flags_wait
);
3209 /* pretend we didn't recognize this IOCTL */
3210 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3211 return -ENOIOCTLCMD
;
3215 * The linux tty driver doesn't have a flush
3216 * input routine for the driver, assuming all backed
3217 * up data is in the line disc. buffers. However,
3218 * we all know that's not the case. Here, we
3219 * act on the ioctl, but then lie and say we didn't
3220 * so the line discipline will process the flush
3223 if (cmd
== TCSETSF
) {
3225 ch
->ch_flags
&= ~CH_STOP
;
3226 ch
->ch_r_head
= ch
->ch_r_tail
;
3227 ch
->ch_bd
->bd_ops
->flush_uart_read(ch
);
3228 /* Force queue flow control to be released, if needed */
3229 dgnc_check_queue_flow_control(ch
);
3232 /* now wait for all the output to drain */
3233 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3234 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3236 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d\n", rc
));
3240 DPR_IOCTL(("dgnc_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3241 ch
->ch_portnum
, dgnc_ioctl_name(cmd
), cmd
, arg
));
3243 /* pretend we didn't recognize this */
3244 return -ENOIOCTLCMD
;
3248 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3249 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3251 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3255 /* pretend we didn't recognize this */
3256 return -ENOIOCTLCMD
;
3259 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3260 /* Make the ld do it */
3261 return -ENOIOCTLCMD
;
3264 /* get information for ditty */
3265 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3266 return dgnc_tty_digigeta(tty
, uarg
);
3271 /* set information for ditty */
3272 if (cmd
== (DIGI_SETAW
)) {
3274 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3275 rc
= ch
->ch_bd
->bd_ops
->drain(tty
, 0);
3277 DPR_IOCTL(("dgnc_tty_ioctl - bad return: %d ", rc
));
3280 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3283 tty_ldisc_flush(tty
);
3288 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3289 return dgnc_tty_digiseta(tty
, uarg
);
3294 /* Let go of locks when accessing user space, could sleep */
3295 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3296 rc
= get_user(loopback
, (unsigned int __user
*) arg
);
3299 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3301 /* Enable/disable internal loopback for this port */
3303 ch
->ch_flags
|= CH_LOOPBACK
;
3305 ch
->ch_flags
&= ~(CH_LOOPBACK
);
3307 ch
->ch_bd
->bd_ops
->param(tty
);
3308 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3312 case DIGI_GETCUSTOMBAUD
:
3313 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3314 rc
= put_user(ch
->ch_custom_speed
, (unsigned int __user
*) arg
);
3317 case DIGI_SETCUSTOMBAUD
:
3320 /* Let go of locks when accessing user space, could sleep */
3321 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3322 rc
= get_user(new_rate
, (unsigned int __user
*) arg
);
3325 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3326 dgnc_set_custom_speed(ch
, new_rate
);
3327 ch
->ch_bd
->bd_ops
->param(tty
);
3328 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3333 * This ioctl allows insertion of a character into the front
3334 * of any pending data to be transmitted.
3336 * This ioctl is to satify the "Send Character Immediate"
3337 * call that the RealPort protocol spec requires.
3339 case DIGI_REALPORT_SENDIMMEDIATE
:
3342 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3343 rc
= get_user(c
, (unsigned char __user
*) arg
);
3346 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3347 ch
->ch_bd
->bd_ops
->send_immediate_char(ch
, c
);
3348 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3353 * This ioctl returns all the current counts for the port.
3355 * This ioctl is to satify the "Line Error Counters"
3356 * call that the RealPort protocol spec requires.
3358 case DIGI_REALPORT_GETCOUNTERS
:
3360 struct digi_getcounter buf
;
3362 buf
.norun
= ch
->ch_err_overrun
;
3363 buf
.noflow
= 0; /* The driver doesn't keep this stat */
3364 buf
.nframe
= ch
->ch_err_frame
;
3365 buf
.nparity
= ch
->ch_err_parity
;
3366 buf
.nbreak
= ch
->ch_err_break
;
3367 buf
.rbytes
= ch
->ch_rxcount
;
3368 buf
.tbytes
= ch
->ch_txcount
;
3370 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3372 if (copy_to_user(uarg
, &buf
, sizeof(buf
))) {
3379 * This ioctl returns all current events.
3381 * This ioctl is to satify the "Event Reporting"
3382 * call that the RealPort protocol spec requires.
3384 case DIGI_REALPORT_GETEVENTS
:
3386 unsigned int events
= 0;
3388 /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
3389 if (ch
->ch_flags
& CH_BREAK_SENDING
)
3391 if ((ch
->ch_flags
& CH_STOP
) || (ch
->ch_flags
& CH_FORCED_STOP
)) {
3392 events
|= (EV_OPU
| EV_OPS
);
3394 if ((ch
->ch_flags
& CH_STOPI
) || (ch
->ch_flags
& CH_FORCED_STOPI
)) {
3395 events
|= (EV_IPU
| EV_IPS
);
3398 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3399 rc
= put_user(events
, (unsigned int __user
*) arg
);
3404 * This ioctl returns TOUT and TIN counters based
3405 * upon the values passed in by the RealPort Server.
3406 * It also passes back whether the UART Transmitter is
3409 case DIGI_REALPORT_GETBUFFERS
:
3411 struct digi_getbuffer buf
;
3415 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3418 * Get data from user first.
3420 if (copy_from_user(&buf
, uarg
, sizeof(buf
))) {
3424 DGNC_LOCK(ch
->ch_lock
, lock_flags
);
3427 * Figure out how much data is in our RX and TX queues.
3429 buf
.rxbuf
= (ch
->ch_r_head
- ch
->ch_r_tail
) & RQUEUEMASK
;
3430 buf
.txbuf
= (ch
->ch_w_head
- ch
->ch_w_tail
) & WQUEUEMASK
;
3433 * Is the UART empty? Add that value to whats in our TX queue.
3435 count
= buf
.txbuf
+ ch
->ch_bd
->bd_ops
->get_uart_bytes_left(ch
);
3438 * Figure out how much data the RealPort Server believes should
3439 * be in our TX queue.
3441 tdist
= (buf
.tIn
- buf
.tOut
) & 0xffff;
3444 * If we have more data than the RealPort Server believes we
3445 * should have, reduce our count to its amount.
3447 * This count difference CAN happen because the Linux LD can
3448 * insert more characters into our queue for OPOST processing
3449 * that the RealPort Server doesn't know about.
3451 if (buf
.txbuf
> tdist
) {
3456 * Report whether our queue and UART TX are completely empty.
3464 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3466 if (copy_to_user(uarg
, &buf
, sizeof(buf
))) {
3472 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3474 DPR_IOCTL(("dgnc_tty_ioctl - in default\n"));
3475 DPR_IOCTL(("dgnc_tty_ioctl end - cmd %s (%x), arg %lx\n",
3476 dgnc_ioctl_name(cmd
), cmd
, arg
));
3478 return -ENOIOCTLCMD
;
3481 DGNC_UNLOCK(ch
->ch_lock
, lock_flags
);
3483 DPR_IOCTL(("dgnc_tty_ioctl end - cmd %s (%x), arg %lx\n",
3484 dgnc_ioctl_name(cmd
), cmd
, arg
));