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 * FEP5 based product lines.
36 ************************************************************************
38 * $Id: dgap_tty.c,v 1.3 2011/06/23 12:11:31 markh Exp $
41 #include <linux/kernel.h>
42 #include <linux/version.h>
43 #include <linux/sched.h> /* For jiffies, task states */
44 #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
45 #include <linux/module.h>
46 #include <linux/ctype.h>
47 #include <linux/tty.h>
48 #include <linux/tty_flip.h>
49 #include <linux/serial_reg.h>
50 #include <linux/slab.h>
51 #include <linux/delay.h> /* For udelay */
52 #include <asm/uaccess.h> /* For copy_from_user/copy_to_user */
53 #include <asm/io.h> /* For read[bwl]/write[bwl] */
54 #include <linux/pci.h>
56 #include "dgap_driver.h"
58 #include "dgap_types.h"
59 #include "dgap_fep5.h"
60 #include "dgap_parse.h"
61 #include "dgap_conf.h"
62 #include "dgap_sysfs.h"
64 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)
65 #define init_MUTEX(sem) sema_init(sem, 1)
66 #define DECLARE_MUTEX(name) \
67 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
73 static struct board_t *dgap_BoardsByMajor[256];
74 static uchar *dgap_TmpWriteBuf = NULL;
75 static DECLARE_MUTEX(dgap_TmpWriteSem);
78 * Default transparent print information.
80 static struct digi_t dgap_digi_init = {
81 .digi_flags = DIGI_COOK, /* Flags */
82 .digi_maxcps = 100, /* Max CPS */
83 .digi_maxchar = 50, /* Max chars in print queue */
84 .digi_bufsize = 100, /* Printer buffer size */
85 .digi_onlen = 4, /* size of printer on string */
86 .digi_offlen = 4, /* size of printer off string */
87 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
88 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
89 .digi_term = "ansi" /* default terminal type */
94 * Define a local default termios struct. All ports will be created
95 * with this termios initially.
97 * This defines a raw port at 9600 baud, 8 data bits, no parity,
101 static struct ktermios DgapDefaultTermios =
103 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
104 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
105 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
106 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
111 /* Our function prototypes */
112 static int dgap_tty_open(struct tty_struct *tty, struct file *file);
113 static void dgap_tty_close(struct tty_struct *tty, struct file *file);
114 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
115 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
116 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
117 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
118 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo);
119 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info);
120 static int dgap_tty_write_room(struct tty_struct* tty);
121 static int dgap_tty_chars_in_buffer(struct tty_struct* tty);
122 static void dgap_tty_start(struct tty_struct *tty);
123 static void dgap_tty_stop(struct tty_struct *tty);
124 static void dgap_tty_throttle(struct tty_struct *tty);
125 static void dgap_tty_unthrottle(struct tty_struct *tty);
126 static void dgap_tty_flush_chars(struct tty_struct *tty);
127 static void dgap_tty_flush_buffer(struct tty_struct *tty);
128 static void dgap_tty_hangup(struct tty_struct *tty);
129 static int dgap_wait_for_drain(struct tty_struct *tty);
130 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
131 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value);
132 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info);
133 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo);
134 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
135 static int dgap_tty_tiocmget(struct tty_struct *tty);
136 static int dgap_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
138 static int dgap_tty_tiocmget(struct tty_struct *tty, struct file *file);
139 static int dgap_tty_tiocmset(struct tty_struct *tty, struct file *file, unsigned int set, unsigned int clear);
141 static int dgap_tty_send_break(struct tty_struct *tty, int msec);
142 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout);
143 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
144 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
145 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c);
146 static void dgap_tty_send_xchar(struct tty_struct *tty, char ch);
148 static const struct tty_operations dgap_tty_ops = {
149 .open = dgap_tty_open,
150 .close = dgap_tty_close,
151 .write = dgap_tty_write,
152 .write_room = dgap_tty_write_room,
153 .flush_buffer = dgap_tty_flush_buffer,
154 .chars_in_buffer = dgap_tty_chars_in_buffer,
155 .flush_chars = dgap_tty_flush_chars,
156 .ioctl = dgap_tty_ioctl,
157 .set_termios = dgap_tty_set_termios,
158 .stop = dgap_tty_stop,
159 .start = dgap_tty_start,
160 .throttle = dgap_tty_throttle,
161 .unthrottle = dgap_tty_unthrottle,
162 .hangup = dgap_tty_hangup,
163 .put_char = dgap_tty_put_char,
164 .tiocmget = dgap_tty_tiocmget,
165 .tiocmset = dgap_tty_tiocmset,
166 .break_ctl = dgap_tty_send_break,
167 .wait_until_sent = dgap_tty_wait_until_sent,
168 .send_xchar = dgap_tty_send_xchar
175 /************************************************************************
177 * TTY Initialization/Cleanup Functions
179 ************************************************************************/
184 * Initialize any global tty related data before we download any boards.
186 int dgap_tty_preinit(void)
190 DGAP_LOCK(dgap_global_lock, flags);
193 * Allocate a buffer for doing the copy from user space to
194 * kernel space in dgap_input(). We only use one buffer and
195 * control access to it with a semaphore. If we are paging, we
196 * are already in trouble so one buffer won't hurt much anyway.
198 dgap_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_ATOMIC);
200 if (!dgap_TmpWriteBuf) {
201 DGAP_UNLOCK(dgap_global_lock, flags);
202 DPR_INIT(("unable to allocate tmp write buf"));
206 DGAP_UNLOCK(dgap_global_lock, flags);
212 * dgap_tty_register()
214 * Init the tty subsystem for this board.
216 int dgap_tty_register(struct board_t *brd)
220 DPR_INIT(("tty_register start"));
222 brd->SerialDriver = alloc_tty_driver(MAXPORTS);
224 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgap_%d_", brd->boardnum);
225 brd->SerialDriver->name = brd->SerialName;
226 brd->SerialDriver->name_base = 0;
227 brd->SerialDriver->major = 0;
228 brd->SerialDriver->minor_start = 0;
229 brd->SerialDriver->type = TTY_DRIVER_TYPE_SERIAL;
230 brd->SerialDriver->subtype = SERIAL_TYPE_NORMAL;
231 brd->SerialDriver->init_termios = DgapDefaultTermios;
232 brd->SerialDriver->driver_name = DRVSTR;
233 brd->SerialDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
235 /* The kernel wants space to store pointers to tty_structs */
236 brd->SerialDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
237 if (!brd->SerialDriver->ttys)
240 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
241 brd->SerialDriver->refcount = brd->TtyRefCnt;
245 * Entry points for driver. Called by the kernel from
246 * tty_io.c and n_tty.c.
248 tty_set_operations(brd->SerialDriver, &dgap_tty_ops);
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 dgap_tty_open() routine.
255 brd->PrintDriver = alloc_tty_driver(MAXPORTS);
257 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgap_%d_", brd->boardnum);
258 brd->PrintDriver->name = brd->PrintName;
259 brd->PrintDriver->name_base = 0;
260 brd->PrintDriver->major = 0;
261 brd->PrintDriver->minor_start = 0;
262 brd->PrintDriver->type = TTY_DRIVER_TYPE_SERIAL;
263 brd->PrintDriver->subtype = SERIAL_TYPE_NORMAL;
264 brd->PrintDriver->init_termios = DgapDefaultTermios;
265 brd->PrintDriver->driver_name = DRVSTR;
266 brd->PrintDriver->flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
268 /* The kernel wants space to store pointers to tty_structs */
269 brd->PrintDriver->ttys = kzalloc(MAXPORTS * sizeof(struct tty_struct *), GFP_KERNEL);
270 if (!brd->PrintDriver->ttys)
273 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
274 brd->PrintDriver->refcount = brd->TtyRefCnt;
278 * Entry points for driver. Called by the kernel from
279 * tty_io.c and n_tty.c.
281 tty_set_operations(brd->PrintDriver, &dgap_tty_ops);
283 if (!brd->dgap_Major_Serial_Registered) {
284 /* Register tty devices */
285 rc = tty_register_driver(brd->SerialDriver);
287 APR(("Can't register tty device (%d)\n", rc));
290 brd->dgap_Major_Serial_Registered = TRUE;
291 dgap_BoardsByMajor[brd->SerialDriver->major] = brd;
292 brd->dgap_Serial_Major = brd->SerialDriver->major;
295 if (!brd->dgap_Major_TransparentPrint_Registered) {
296 /* Register Transparent Print devices */
297 rc = tty_register_driver(brd->PrintDriver);
299 APR(("Can't register Transparent Print device (%d)\n", rc));
302 brd->dgap_Major_TransparentPrint_Registered = TRUE;
303 dgap_BoardsByMajor[brd->PrintDriver->major] = brd;
304 brd->dgap_TransparentPrint_Major = brd->PrintDriver->major;
307 DPR_INIT(("DGAP REGISTER TTY: MAJORS: %d %d\n", brd->SerialDriver->major,
308 brd->PrintDriver->major));
317 * Init the tty subsystem. Called once per board after board has been
318 * downloaded and init'ed.
320 int dgap_tty_init(struct board_t *brd)
327 struct channel_t *ch;
334 DPR_INIT(("dgap_tty_init start\n"));
337 * Initialize board structure elements.
340 vaddr = brd->re_map_membase;
341 true_count = readw((vaddr + NCHAN));
343 brd->nasync = dgap_config_get_number_of_ports(brd);
346 brd->nasync = brd->maxports;
349 if (brd->nasync > brd->maxports) {
350 brd->nasync = brd->maxports;
353 if (true_count != brd->nasync) {
354 if ((brd->type == PPCM) && (true_count == 64)) {
355 APR(("***WARNING**** %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
356 brd->name, brd->nasync, true_count));
358 else if ((brd->type == PPCM) && (true_count == 0)) {
359 APR(("***WARNING**** %s configured for %d ports, has %d ports.\nPlease make SURE the EBI cable running from the card\nto each EM module is plugged into EBI IN!\n",
360 brd->name, brd->nasync, true_count));
363 APR(("***WARNING**** %s configured for %d ports, has %d ports.\n",
364 brd->name, brd->nasync, true_count));
367 brd->nasync = true_count;
369 /* If no ports, don't bother going any further */
371 brd->state = BOARD_FAILED;
372 brd->dpastatus = BD_NOFEP;
378 * Allocate channel memory that might not have been allocated
379 * when the driver was first loaded.
381 for (i = 0; i < brd->nasync; i++) {
382 if (!brd->channels[i]) {
383 brd->channels[i] = kzalloc(sizeof(struct channel_t), GFP_ATOMIC);
384 if (!brd->channels[i]) {
385 DPR_CORE(("%s:%d Unable to allocate memory for channel struct\n",
386 __FILE__, __LINE__));
391 ch = brd->channels[0];
392 vaddr = brd->re_map_membase;
394 bs = (struct bs_t *) ((ulong) vaddr + CHANBUF);
395 cm = (struct cm_t *) ((ulong) vaddr + CMDBUF);
399 /* Set up channel variables */
400 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
402 if (!brd->channels[i])
405 DGAP_SPINLOCK_INIT(ch->ch_lock);
407 /* Store all our magic numbers */
408 ch->magic = DGAP_CHANNEL_MAGIC;
409 ch->ch_tun.magic = DGAP_UNIT_MAGIC;
410 ch->ch_tun.un_type = DGAP_SERIAL;
411 ch->ch_tun.un_ch = ch;
412 ch->ch_tun.un_dev = i;
414 ch->ch_pun.magic = DGAP_UNIT_MAGIC;
415 ch->ch_pun.un_type = DGAP_PRINT;
416 ch->ch_pun.un_ch = ch;
417 ch->ch_pun.un_dev = i;
419 ch->ch_vaddr = vaddr;
424 ch->ch_digi = dgap_digi_init;
427 * Set up digi dsr and dcd bits based on altpin flag.
429 if (dgap_config_get_altpin(brd)) {
432 ch->ch_digi.digi_flags |= DIGI_ALTPIN;
439 ch->ch_taddr = vaddr + ((ch->ch_bs->tx_seg) << 4);
440 ch->ch_raddr = vaddr + ((ch->ch_bs->rx_seg) << 4);
443 ch->ch_tsize = readw(&(ch->ch_bs->tx_max)) + 1;
444 ch->ch_rsize = readw(&(ch->ch_bs->rx_max)) + 1;
448 /* .25 second delay */
449 ch->ch_close_delay = 250;
452 * Set queue water marks, interrupt mask,
453 * and general tty parameters.
455 ch->ch_tlw = tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) : ch->ch_tsize / 2;
457 dgap_cmdw(ch, STLOW, tlw, 0);
459 dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
461 dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
463 ch->ch_mistat = readb(&(ch->ch_bs->m_stat));
465 init_waitqueue_head(&ch->ch_flags_wait);
466 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
467 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
468 init_waitqueue_head(&ch->ch_sniff_wait);
470 /* Turn on all modem interrupts for now */
471 modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
472 writeb(modem, &(ch->ch_bs->m_int));
475 * Set edelay to 0 if interrupts are turned on,
476 * otherwise set edelay to the usual 100.
479 writew(0, &(ch->ch_bs->edelay));
481 writew(100, &(ch->ch_bs->edelay));
483 writeb(1, &(ch->ch_bs->idata));
487 DPR_INIT(("dgap_tty_init finish\n"));
494 * dgap_tty_post_uninit()
496 * UnInitialize any global tty related data.
498 void dgap_tty_post_uninit(void)
500 kfree(dgap_TmpWriteBuf);
501 dgap_TmpWriteBuf = NULL;
508 * Uninitialize the TTY portion of this driver. Free all memory and
511 void dgap_tty_uninit(struct board_t *brd)
515 if (brd->dgap_Major_Serial_Registered) {
516 dgap_BoardsByMajor[brd->SerialDriver->major] = NULL;
517 brd->dgap_Serial_Major = 0;
518 for (i = 0; i < brd->nasync; i++) {
519 dgap_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
520 tty_unregister_device(brd->SerialDriver, i);
522 tty_unregister_driver(brd->SerialDriver);
523 kfree(brd->SerialDriver->ttys);
524 brd->SerialDriver->ttys = NULL;
525 put_tty_driver(brd->SerialDriver);
526 brd->dgap_Major_Serial_Registered = FALSE;
529 if (brd->dgap_Major_TransparentPrint_Registered) {
530 dgap_BoardsByMajor[brd->PrintDriver->major] = NULL;
531 brd->dgap_TransparentPrint_Major = 0;
532 for (i = 0; i < brd->nasync; i++) {
533 dgap_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
534 tty_unregister_device(brd->PrintDriver, i);
536 tty_unregister_driver(brd->PrintDriver);
537 kfree(brd->PrintDriver->ttys);
538 brd->PrintDriver->ttys = NULL;
539 put_tty_driver(brd->PrintDriver);
540 brd->dgap_Major_TransparentPrint_Registered = FALSE;
545 #define TMPBUFLEN (1024)
548 * dgap_sniff - Dump data out to the "sniff" buffer if the
549 * proc sniff file is opened...
551 static void dgap_sniff_nowait_nolock(struct channel_t *ch, uchar *text, uchar *buf, int len)
559 char tmpbuf[TMPBUFLEN];
563 /* Leave if sniff not open */
564 if (!(ch->ch_sniff_flags & SNIFF_OPEN))
567 do_gettimeofday(&tv);
569 /* Create our header for data dump */
570 p += sprintf(p, "<%ld %ld><%s><", tv.tv_sec, tv.tv_usec, text);
571 tmpbuflen = p - tmpbuf;
576 for (i = 0; i < len && tmpbuflen < (TMPBUFLEN - 4); i++) {
577 p += sprintf(p, "%02x ", *buf);
579 tmpbuflen = p - tmpbuf;
582 if (tmpbuflen < (TMPBUFLEN - 4)) {
584 p += sprintf(p - 1, "%s\n", ">");
586 p += sprintf(p, "%s\n", ">");
592 nbuf = strlen(tmpbuf);
596 * Loop while data remains.
598 while (nbuf > 0 && ch->ch_sniff_buf) {
600 * Determine the amount of available space left in the
601 * buffer. If there's none, wait until some appears.
603 n = (ch->ch_sniff_out - ch->ch_sniff_in - 1) & SNIFF_MASK;
606 * If there is no space left to write to in our sniff buffer,
607 * we have no choice but to drop the data.
608 * We *cannot* sleep here waiting for space, because this
609 * function was probably called by the interrupt/timer routines!
616 * Copy as much data as will fit.
622 r = SNIFF_MAX - ch->ch_sniff_in;
625 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, r);
633 memcpy(ch->ch_sniff_buf + ch->ch_sniff_in, p, n);
635 ch->ch_sniff_in += n;
640 * Wakeup any thread waiting for data
642 if (ch->ch_sniff_flags & SNIFF_WAIT_DATA) {
643 ch->ch_sniff_flags &= ~SNIFF_WAIT_DATA;
644 wake_up_interruptible(&ch->ch_sniff_wait);
649 * If the user sent us too much data to push into our tmpbuf,
650 * we need to keep looping around on all the data.
657 } while (too_much_data);
661 /*=======================================================================
663 * dgap_input - Process received data.
665 * ch - Pointer to channel structure.
667 *=======================================================================*/
669 void dgap_input(struct channel_t *ch)
673 struct tty_struct *tp;
674 struct tty_ldisc *ld;
688 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
691 tp = ch->ch_tun.un_tty;
699 if(!bd || bd->magic != DGAP_BOARD_MAGIC)
702 DPR_READ(("dgap_input start\n"));
704 DGAP_LOCK(bd->bd_lock, lock_flags);
705 DGAP_LOCK(ch->ch_lock, lock_flags2);
708 * Figure the number of characters in the buffer.
709 * Exit immediately if none.
712 rmask = ch->ch_rsize - 1;
714 head = readw(&(bs->rx_head));
716 tail = readw(&(bs->rx_tail));
719 data_len = (head - tail) & rmask;
722 writeb(1, &(bs->idata));
723 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
724 DGAP_UNLOCK(bd->bd_lock, lock_flags);
725 DPR_READ(("No data on port %d\n", ch->ch_portnum));
730 * If the device is not open, or CREAD is off, flush
731 * input data and return immediately.
733 if ((bd->state != BOARD_READY) || !tp || (tp->magic != TTY_MAGIC) ||
734 !(ch->ch_tun.un_flags & UN_ISOPEN) || !(tp->termios.c_cflag & CREAD) ||
735 (ch->ch_tun.un_flags & UN_CLOSING)) {
737 DPR_READ(("input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum));
738 DPR_READ(("input. tp: %p tp->magic: %x MAGIC:%x ch flags: %x\n",
739 tp, tp ? tp->magic : 0, TTY_MAGIC, ch->ch_tun.un_flags));
740 writew(head, &(bs->rx_tail));
741 writeb(1, &(bs->idata));
742 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
743 DGAP_UNLOCK(bd->bd_lock, lock_flags);
748 * If we are throttled, simply don't read any data.
750 if (ch->ch_flags & CH_RXBLOCK) {
751 writeb(1, &(bs->idata));
752 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
753 DGAP_UNLOCK(bd->bd_lock, lock_flags);
754 DPR_READ(("Port %d throttled, not reading any data. head: %x tail: %x\n",
755 ch->ch_portnum, head, tail));
762 tmpchar = readb(&(bs->orun));
764 ch->ch_err_overrun++;
765 writeb(0, &(bs->orun));
768 DPR_READ(("dgap_input start 2\n"));
770 /* Decide how much data we can send into the tty layer */
771 flip_len = TTY_FLIPBUF_SIZE;
773 /* Chop down the length, if needed */
774 len = min(data_len, flip_len);
775 len = min(len, (N_TTY_BUF_SIZE - 1));
777 ld = tty_ldisc_ref(tp);
781 * If the DONT_FLIP flag is on, don't flush our buffer, and act
782 * like the ld doesn't have any space to put the data right now.
784 if (test_bit(TTY_DONT_FLIP, &tp->flags))
789 * If we were unable to get a reference to the ld,
790 * don't flush our buffer, and act like the ld doesn't
791 * have any space to put the data right now.
797 * If ld doesn't have a pointer to a receive_buf function,
798 * flush the data, then act like the ld doesn't have any
799 * space to put the data right now.
801 if (!ld->ops->receive_buf) {
802 writew(head, &(bs->rx_tail));
808 writeb(1, &(bs->idata));
809 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
810 DGAP_UNLOCK(bd->bd_lock, lock_flags);
811 DPR_READ(("dgap_input 1 - finish\n"));
817 buf = ch->ch_bd->flipbuf;
821 * n now contains the most amount of data we can copy,
822 * bounded either by our buffer size or the amount
823 * of data the card actually has pending...
827 s = ((head >= tail) ? head : ch->ch_rsize) - tail;
833 memcpy_fromio(buf, (char *) ch->ch_raddr + tail, s);
834 dgap_sniff_nowait_nolock(ch, "USER READ", buf, s);
840 /* Flip queue if needed */
844 writew(tail, &(bs->rx_tail));
845 writeb(1, &(bs->idata));
846 ch->ch_rxcount += len;
849 * If we are completely raw, we don't need to go through a lot
850 * of the tty layers that exist.
851 * In this case, we take the shortest and fastest route we
852 * can to relay the data to the user.
854 * On the other hand, if we are not raw, we need to go through
855 * the tty layer, which has its API more well defined.
857 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
858 dgap_parity_scan(ch, ch->ch_bd->flipbuf, ch->ch_bd->flipflagbuf, &len);
860 len = tty_buffer_request_room(tp->port, len);
861 tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
862 ch->ch_bd->flipflagbuf, len);
865 len = tty_buffer_request_room(tp->port, len);
866 tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
869 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
870 DGAP_UNLOCK(bd->bd_lock, lock_flags);
872 /* Tell the tty layer its okay to "eat" the data now */
873 tty_flip_buffer_push(tp->port);
878 DPR_READ(("dgap_input - finish\n"));
882 /************************************************************************
883 * Determines when CARRIER changes state and takes appropriate
885 ************************************************************************/
886 void dgap_carrier(struct channel_t *ch)
890 int virt_carrier = 0;
891 int phys_carrier = 0;
893 DPR_CARR(("dgap_carrier called...\n"));
895 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
900 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
903 /* Make sure altpin is always set correctly */
904 if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
913 if (ch->ch_mistat & D_CD(ch)) {
914 DPR_CARR(("mistat: %x D_CD: %x\n", ch->ch_mistat, D_CD(ch)));
918 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD) {
922 if (ch->ch_c_cflag & CLOCAL) {
927 DPR_CARR(("DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier));
930 * Test for a VIRTUAL carrier transition to HIGH.
932 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
935 * When carrier rises, wake any threads waiting
936 * for carrier in the open routine.
939 DPR_CARR(("carrier: virt DCD rose\n"));
941 if (waitqueue_active(&(ch->ch_flags_wait)))
942 wake_up_interruptible(&ch->ch_flags_wait);
946 * Test for a PHYSICAL carrier transition to HIGH.
948 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
951 * When carrier rises, wake any threads waiting
952 * for carrier in the open routine.
955 DPR_CARR(("carrier: physical DCD rose\n"));
957 if (waitqueue_active(&(ch->ch_flags_wait)))
958 wake_up_interruptible(&ch->ch_flags_wait);
962 * Test for a PHYSICAL transition to low, so long as we aren't
963 * currently ignoring physical transitions (which is what "virtual
964 * carrier" indicates).
966 * The transition of the virtual carrier to low really doesn't
967 * matter... it really only means "ignore carrier state", not
968 * "make pretend that carrier is there".
970 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
975 * When carrier drops:
977 * Drop carrier on all open units.
979 * Flush queues, waking up any task waiting in the
982 * Send a hangup to the control terminal.
984 * Enable all select calls.
986 if (waitqueue_active(&(ch->ch_flags_wait)))
987 wake_up_interruptible(&ch->ch_flags_wait);
989 if (ch->ch_tun.un_open_count > 0) {
990 DPR_CARR(("Sending tty hangup\n"));
991 tty_hangup(ch->ch_tun.un_tty);
994 if (ch->ch_pun.un_open_count > 0) {
995 DPR_CARR(("Sending pr hangup\n"));
996 tty_hangup(ch->ch_pun.un_tty);
1001 * Make sure that our cached values reflect the current reality.
1003 if (virt_carrier == 1)
1004 ch->ch_flags |= CH_FCAR;
1006 ch->ch_flags &= ~CH_FCAR;
1008 if (phys_carrier == 1)
1009 ch->ch_flags |= CH_CD;
1011 ch->ch_flags &= ~CH_CD;
1015 /************************************************************************
1017 * TTY Entry points and helper functions
1019 ************************************************************************/
1025 static int dgap_tty_open(struct tty_struct *tty, struct file *file)
1027 struct board_t *brd;
1028 struct channel_t *ch;
1040 major = MAJOR(tty_devnum(tty));
1041 minor = MINOR(tty_devnum(tty));
1047 /* Get board pointer from our array of majors we have allocated */
1048 brd = dgap_BoardsByMajor[major];
1054 * If board is not yet up to a state of READY, go to
1055 * sleep waiting for it to happen or they cancel the open.
1057 rc = wait_event_interruptible(brd->state_wait,
1058 (brd->state & BOARD_READY));
1064 DGAP_LOCK(brd->bd_lock, lock_flags);
1066 /* The wait above should guarantee this cannot happen */
1067 if (brd->state != BOARD_READY) {
1068 DGAP_UNLOCK(brd->bd_lock, lock_flags);
1072 /* If opened device is greater than our number of ports, bail. */
1073 if (MINOR(tty_devnum(tty)) > brd->nasync) {
1074 DGAP_UNLOCK(brd->bd_lock, lock_flags);
1078 ch = brd->channels[minor];
1080 DGAP_UNLOCK(brd->bd_lock, lock_flags);
1084 /* Grab channel lock */
1085 DGAP_LOCK(ch->ch_lock, lock_flags2);
1087 /* Figure out our type */
1088 if (major == brd->dgap_Serial_Major) {
1089 un = &brd->channels[minor]->ch_tun;
1090 un->un_type = DGAP_SERIAL;
1092 else if (major == brd->dgap_TransparentPrint_Major) {
1093 un = &brd->channels[minor]->ch_pun;
1094 un->un_type = DGAP_PRINT;
1097 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1098 DGAP_UNLOCK(brd->bd_lock, lock_flags);
1099 DPR_OPEN(("%d Unknown TYPE!\n", __LINE__));
1103 /* Store our unit into driver_data, so we always have it available. */
1104 tty->driver_data = un;
1106 DPR_OPEN(("Open called. MAJOR: %d MINOR:%d unit: %p NAME: %s\n",
1107 MAJOR(tty_devnum(tty)), MINOR(tty_devnum(tty)), un, brd->name));
1110 * Error if channel info pointer is NULL.
1114 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1115 DGAP_UNLOCK(brd->bd_lock, lock_flags);
1116 DPR_OPEN(("%d BS is 0!\n", __LINE__));
1120 DPR_OPEN(("%d: tflag=%x pflag=%x\n", __LINE__, ch->ch_tun.un_flags, ch->ch_pun.un_flags));
1125 if (!(un->un_flags & UN_ISOPEN)) {
1126 /* Store important variables. */
1129 /* Maybe do something here to the TTY struct as well? */
1133 * Initialize if neither terminal or printer is open.
1135 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1137 DPR_OPEN(("dgap_open: initializing channel in open...\n"));
1143 * Flush input queue.
1145 head = readw(&(bs->rx_head));
1146 writew(head, &(bs->rx_tail));
1149 ch->pscan_state = 0;
1150 ch->pscan_savechar = 0;
1152 ch->ch_c_cflag = tty->termios.c_cflag;
1153 ch->ch_c_iflag = tty->termios.c_iflag;
1154 ch->ch_c_oflag = tty->termios.c_oflag;
1155 ch->ch_c_lflag = tty->termios.c_lflag;
1156 ch->ch_startc = tty->termios.c_cc[VSTART];
1157 ch->ch_stopc = tty->termios.c_cc[VSTOP];
1159 /* TODO: flush our TTY struct here? */
1164 * Run param in case we changed anything
1169 * follow protocol for opening port
1172 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1173 DGAP_UNLOCK(brd->bd_lock, lock_flags);
1175 rc = dgap_block_til_ready(tty, file, ch);
1182 DPR_OPEN(("dgap_tty_open returning after dgap_block_til_ready "
1186 /* No going back now, increment our unit and channel counters */
1187 DGAP_LOCK(ch->ch_lock, lock_flags);
1188 ch->ch_open_count++;
1189 un->un_open_count++;
1190 un->un_flags |= (UN_ISOPEN);
1191 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1193 DPR_OPEN(("dgap_tty_open finished\n"));
1199 * dgap_block_til_ready()
1201 * Wait for DCD, if needed.
1203 static int dgap_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
1206 struct un_t *un = NULL;
1209 int sleep_on_un_flags = 0;
1211 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGAP_CHANNEL_MAGIC) {
1215 un = tty->driver_data;
1216 if (!un || un->magic != DGAP_UNIT_MAGIC) {
1220 DPR_OPEN(("dgap_block_til_ready - before block.\n"));
1222 DGAP_LOCK(ch->ch_lock, lock_flags);
1229 sleep_on_un_flags = 0;
1232 * If board has failed somehow during our sleep, bail with error.
1234 if (ch->ch_bd->state == BOARD_FAILED) {
1239 /* If tty was hung up, break out of loop and set error. */
1240 if (tty_hung_up_p(file)) {
1246 * If either unit is in the middle of the fragile part of close,
1247 * we just cannot touch the channel safely.
1248 * Go back to sleep, knowing that when the channel can be
1249 * touched safely, the close routine will signal the
1250 * ch_wait_flags to wake us back up.
1252 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
1255 * Our conditions to leave cleanly and happily:
1256 * 1) NONBLOCKING on the tty is set.
1258 * 3) DCD (fake or real) is active.
1261 if (file->f_flags & O_NONBLOCK) {
1265 if (tty->flags & (1 << TTY_IO_ERROR)) {
1269 if (ch->ch_flags & CH_CD) {
1270 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
1274 if (ch->ch_flags & CH_FCAR) {
1275 DPR_OPEN(("%d: ch_flags: %x\n", __LINE__, ch->ch_flags));
1280 sleep_on_un_flags = 1;
1284 * If there is a signal pending, the user probably
1285 * interrupted (ctrl-c) us.
1286 * Leave loop with error set.
1288 if (signal_pending(current)) {
1289 DPR_OPEN(("%d: signal pending...\n", __LINE__));
1290 retval = -ERESTARTSYS;
1294 DPR_OPEN(("dgap_block_til_ready - blocking.\n"));
1297 * Store the flags before we let go of channel lock
1299 if (sleep_on_un_flags)
1300 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
1302 old_flags = ch->ch_flags;
1305 * Let go of channel lock before calling schedule.
1306 * Our poller will get any FEP events and wake us up when DCD
1307 * eventually goes active.
1310 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1312 DPR_OPEN(("Going to sleep on %s flags...\n",
1313 (sleep_on_un_flags ? "un" : "ch")));
1316 * Wait for something in the flags to change from the current value.
1318 if (sleep_on_un_flags) {
1319 retval = wait_event_interruptible(un->un_flags_wait,
1320 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
1323 retval = wait_event_interruptible(ch->ch_flags_wait,
1324 (old_flags != ch->ch_flags));
1327 DPR_OPEN(("After sleep... retval: %x\n", retval));
1330 * We got woken up for some reason.
1331 * Before looping around, grab our channel lock.
1333 DGAP_LOCK(ch->ch_lock, lock_flags);
1338 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1340 DPR_OPEN(("dgap_block_til_ready - after blocking.\n"));
1343 DPR_OPEN(("dgap_block_til_ready - done. error. retval: %x\n", retval));
1347 DPR_OPEN(("dgap_block_til_ready - done no error. jiffies: %lu\n", jiffies));
1356 * Hangup the port. Like a close, but don't wait for output to drain.
1358 static void dgap_tty_hangup(struct tty_struct *tty)
1361 struct channel_t *ch;
1364 if (!tty || tty->magic != TTY_MAGIC)
1367 un = tty->driver_data;
1368 if (!un || un->magic != DGAP_UNIT_MAGIC)
1372 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1376 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1379 DPR_CLOSE(("dgap_hangup called. ch->ch_open_count: %d un->un_open_count: %d\n",
1380 ch->ch_open_count, un->un_open_count));
1382 /* flush the transmit queues */
1383 dgap_tty_flush_buffer(tty);
1385 DPR_CLOSE(("dgap_hangup finished. ch->ch_open_count: %d un->un_open_count: %d\n",
1386 ch->ch_open_count, un->un_open_count));
1395 static void dgap_tty_close(struct tty_struct *tty, struct file *file)
1397 struct ktermios *ts;
1399 struct channel_t *ch;
1404 if (!tty || tty->magic != TTY_MAGIC)
1407 un = tty->driver_data;
1408 if (!un || un->magic != DGAP_UNIT_MAGIC)
1412 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1416 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1421 DPR_CLOSE(("Close called\n"));
1423 DGAP_LOCK(ch->ch_lock, lock_flags);
1426 * Determine if this is the last close or not - and if we agree about
1427 * which type of close it is with the Line Discipline
1429 if ((tty->count == 1) && (un->un_open_count != 1)) {
1431 * Uh, oh. tty->count is 1, which means that the tty
1432 * structure will be freed. un_open_count should always
1433 * be one in these conditions. If it's greater than
1434 * one, we've got real problems, since it means the
1435 * serial port won't be shutdown.
1437 APR(("tty->count is 1, un open count is %d\n", un->un_open_count));
1438 un->un_open_count = 1;
1441 if (--un->un_open_count < 0) {
1442 APR(("bad serial port open count of %d\n", un->un_open_count));
1443 un->un_open_count = 0;
1446 ch->ch_open_count--;
1448 if (ch->ch_open_count && un->un_open_count) {
1449 DPR_CLOSE(("dgap_tty_close: not last close ch: %d un:%d\n",
1450 ch->ch_open_count, un->un_open_count));
1452 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1456 /* OK, its the last close on the unit */
1457 DPR_CLOSE(("dgap_tty_close - last close on unit procedures\n"));
1459 un->un_flags |= UN_CLOSING;
1464 * Only officially close channel if count is 0 and
1465 * DIGI_PRINTER bit is not set.
1467 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
1469 ch->ch_flags &= ~(CH_RXBLOCK);
1471 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1473 /* wait for output to drain */
1474 /* This will also return if we take an interrupt */
1476 DPR_CLOSE(("Calling wait_for_drain\n"));
1477 rc = dgap_wait_for_drain(tty);
1478 DPR_CLOSE(("After calling wait_for_drain\n"));
1481 DPR_BASIC(("dgap_tty_close - bad return: %d ", rc));
1484 dgap_tty_flush_buffer(tty);
1485 tty_ldisc_flush(tty);
1487 DGAP_LOCK(ch->ch_lock, lock_flags);
1492 * If we have HUPCL set, lower DTR and RTS
1494 if (ch->ch_c_cflag & HUPCL ) {
1495 DPR_CLOSE(("Close. HUPCL set, dropping DTR/RTS\n"));
1496 ch->ch_mostat &= ~(D_RTS(ch)|D_DTR(ch));
1497 dgap_cmdb( ch, SMODEM, 0, D_DTR(ch)|D_RTS(ch), 0 );
1500 * Go to sleep to ensure RTS/DTR
1501 * have been dropped for modems to see it.
1503 if (ch->ch_close_delay) {
1504 DPR_CLOSE(("Close. Sleeping for RTS/DTR drop\n"));
1506 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1507 dgap_ms_sleep(ch->ch_close_delay);
1508 DGAP_LOCK(ch->ch_lock, lock_flags);
1510 DPR_CLOSE(("Close. After sleeping for RTS/DTR drop\n"));
1514 ch->pscan_state = 0;
1515 ch->pscan_savechar = 0;
1516 ch->ch_baud_info = 0;
1521 * turn off print device when closing print device.
1523 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON) ) {
1524 dgap_wmove(ch, ch->ch_digi.digi_offstr,
1525 (int) ch->ch_digi.digi_offlen);
1526 ch->ch_flags &= ~CH_PRON;
1530 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
1531 tty->driver_data = NULL;
1533 DPR_CLOSE(("Close. Doing wakeups\n"));
1534 wake_up_interruptible(&ch->ch_flags_wait);
1535 wake_up_interruptible(&un->un_flags_wait);
1537 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1539 DPR_BASIC(("dgap_tty_close - complete\n"));
1544 * dgap_tty_chars_in_buffer()
1546 * Return number of characters that have not been transmitted yet.
1548 * This routine is used by the line discipline to determine if there
1549 * is data waiting to be transmitted/drained/flushed or not.
1551 static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
1553 struct board_t *bd = NULL;
1554 struct channel_t *ch = NULL;
1555 struct un_t *un = NULL;
1556 struct bs_t *bs = NULL;
1559 u16 thead, ttail, tmask, chead, ctail;
1560 ulong lock_flags = 0;
1561 ulong lock_flags2 = 0;
1566 un = tty->driver_data;
1567 if (!un || un->magic != DGAP_UNIT_MAGIC)
1571 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1575 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
1582 DGAP_LOCK(bd->bd_lock, lock_flags);
1583 DGAP_LOCK(ch->ch_lock, lock_flags2);
1585 tmask = (ch->ch_tsize - 1);
1587 /* Get Transmit queue pointers */
1588 thead = readw(&(bs->tx_head)) & tmask;
1589 ttail = readw(&(bs->tx_tail)) & tmask;
1591 /* Get tbusy flag */
1592 tbusy = readb(&(bs->tbusy));
1594 /* Get Command queue pointers */
1595 chead = readw(&(ch->ch_cm->cm_head));
1596 ctail = readw(&(ch->ch_cm->cm_tail));
1598 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
1599 DGAP_UNLOCK(bd->bd_lock, lock_flags);
1602 * The only way we know for sure if there is no pending
1603 * data left to be transferred, is if:
1604 * 1) Transmit head and tail are equal (empty).
1605 * 2) Command queue head and tail are equal (empty).
1606 * 3) The "TBUSY" flag is 0. (Transmitter not busy).
1609 if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
1614 chars = thead - ttail;
1616 chars = thead - ttail + ch->ch_tsize;
1618 * Fudge factor here.
1619 * If chars is zero, we know that the command queue had
1620 * something in it or tbusy was set. Because we cannot
1621 * be sure if there is still some data to be transmitted,
1622 * lets lie, and tell ld we have 1 byte left.
1626 * If TBUSY is still set, and our tx buffers are empty,
1627 * force the firmware to send me another wakeup after
1628 * TBUSY has been cleared.
1631 DGAP_LOCK(ch->ch_lock, lock_flags);
1632 un->un_flags |= UN_EMPTY;
1633 writeb(1, &(bs->iempty));
1634 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1640 DPR_WRITE(("dgap_tty_chars_in_buffer. Port: %x - %d (head: %d tail: %d tsize: %d)\n",
1641 ch->ch_portnum, chars, thead, ttail, ch->ch_tsize));
1646 static int dgap_wait_for_drain(struct tty_struct *tty)
1648 struct channel_t *ch;
1653 ulong lock_flags = 0;
1655 if (!tty || tty->magic != TTY_MAGIC)
1658 un = tty->driver_data;
1659 if (!un || un->magic != DGAP_UNIT_MAGIC)
1663 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1672 DPR_DRAIN(("dgap_wait_for_drain start\n"));
1674 /* Loop until data is drained */
1675 while (count != 0) {
1677 count = dgap_tty_chars_in_buffer(tty);
1682 /* Set flag waiting for drain */
1683 DGAP_LOCK(ch->ch_lock, lock_flags);
1684 un->un_flags |= UN_EMPTY;
1685 writeb(1, &(bs->iempty));
1686 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1688 /* Go to sleep till we get woken up */
1689 ret = wait_event_interruptible(un->un_flags_wait, ((un->un_flags & UN_EMPTY) == 0));
1690 /* If ret is non-zero, user ctrl-c'ed us */
1696 DGAP_LOCK(ch->ch_lock, lock_flags);
1697 un->un_flags &= ~(UN_EMPTY);
1698 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1700 DPR_DRAIN(("dgap_wait_for_drain finish\n"));
1708 * Reduces bytes_available to the max number of characters
1709 * that can be sent currently given the maxcps value, and
1710 * returns the new bytes_available. This only affects printer
1713 static int dgap_maxcps_room(struct tty_struct *tty, int bytes_available)
1715 struct channel_t *ch = NULL;
1716 struct un_t *un = NULL;
1719 return (bytes_available);
1721 un = tty->driver_data;
1722 if (!un || un->magic != DGAP_UNIT_MAGIC)
1723 return (bytes_available);
1726 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1727 return (bytes_available);
1730 * If its not the Transparent print device, return
1731 * the full data amount.
1733 if (un->un_type != DGAP_PRINT)
1734 return (bytes_available);
1736 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0 ) {
1738 unsigned long current_time = jiffies;
1739 unsigned long buffer_time = current_time +
1740 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
1742 if (ch->ch_cpstime < current_time) {
1743 /* buffer is empty */
1744 ch->ch_cpstime = current_time; /* reset ch_cpstime */
1745 cps_limit = ch->ch_digi.digi_bufsize;
1747 else if (ch->ch_cpstime < buffer_time) {
1748 /* still room in the buffer */
1749 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
1752 /* no room in the buffer */
1756 bytes_available = min(cps_limit, bytes_available);
1759 return (bytes_available);
1763 static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
1765 struct channel_t *ch = NULL;
1766 struct bs_t *bs = NULL;
1768 if (!un || un->magic != DGAP_UNIT_MAGIC)
1771 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1777 if ((event & UN_LOW) != 0) {
1778 if ((un->un_flags & UN_LOW) == 0) {
1779 un->un_flags |= UN_LOW;
1780 writeb(1, &(bs->ilow));
1783 if ((event & UN_LOW) != 0) {
1784 if ((un->un_flags & UN_EMPTY) == 0) {
1785 un->un_flags |= UN_EMPTY;
1786 writeb(1, &(bs->iempty));
1793 * dgap_tty_write_room()
1795 * Return space available in Tx buffer
1797 static int dgap_tty_write_room(struct tty_struct *tty)
1799 struct channel_t *ch = NULL;
1800 struct un_t *un = NULL;
1801 struct bs_t *bs = NULL;
1802 u16 head, tail, tmask;
1804 ulong lock_flags = 0;
1806 if (tty == NULL || dgap_TmpWriteBuf == NULL)
1809 un = tty->driver_data;
1810 if (!un || un->magic != DGAP_UNIT_MAGIC)
1814 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1821 DGAP_LOCK(ch->ch_lock, lock_flags);
1823 tmask = ch->ch_tsize - 1;
1824 head = readw(&(bs->tx_head)) & tmask;
1825 tail = readw(&(bs->tx_tail)) & tmask;
1827 if ((ret = tail - head - 1) < 0)
1828 ret += ch->ch_tsize;
1830 /* Limit printer to maxcps */
1831 ret = dgap_maxcps_room(tty, ret);
1834 * If we are printer device, leave space for
1835 * possibly both the on and off strings.
1837 if (un->un_type == DGAP_PRINT) {
1838 if (!(ch->ch_flags & CH_PRON))
1839 ret -= ch->ch_digi.digi_onlen;
1840 ret -= ch->ch_digi.digi_offlen;
1843 if (ch->ch_flags & CH_PRON)
1844 ret -= ch->ch_digi.digi_offlen;
1851 * Schedule FEP to wake us up if needed.
1853 * TODO: This might be overkill...
1854 * Do we really need to schedule callbacks from the FEP
1855 * in every case? Can we get smarter based on ret?
1857 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
1858 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1860 DPR_WRITE(("dgap_tty_write_room - %d tail: %d head: %d\n", ret, tail, head));
1867 * dgap_tty_put_char()
1869 * Put a character into ch->ch_buf
1871 * - used by the line discipline for OPOST processing
1873 static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
1876 * Simply call tty_write.
1878 DPR_WRITE(("dgap_tty_put_char called\n"));
1879 dgap_tty_write(tty, &c, 1);
1887 * Take data from the user or kernel and send it out to the FEP.
1888 * In here exists all the Transparent Print magic as well.
1890 static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf, int count)
1892 struct channel_t *ch = NULL;
1893 struct un_t *un = NULL;
1894 struct bs_t *bs = NULL;
1896 u16 head, tail, tmask, remain;
1897 int bufcount = 0, n = 0;
1902 if (tty == NULL || dgap_TmpWriteBuf == NULL)
1905 un = tty->driver_data;
1906 if (!un || un->magic != DGAP_UNIT_MAGIC)
1910 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
1920 DPR_WRITE(("dgap_tty_write: Port: %x tty=%p user=%d len=%d\n",
1921 ch->ch_portnum, tty, from_user, count));
1924 * Store original amount of characters passed in.
1925 * This helps to figure out if we should ask the FEP
1926 * to send us an event when it has more space available.
1930 DGAP_LOCK(ch->ch_lock, lock_flags);
1932 /* Get our space available for the channel from the board */
1933 tmask = ch->ch_tsize - 1;
1934 head = readw(&(bs->tx_head)) & tmask;
1935 tail = readw(&(bs->tx_tail)) & tmask;
1937 if ((bufcount = tail - head - 1) < 0)
1938 bufcount += ch->ch_tsize;
1940 DPR_WRITE(("%d: bufcount: %x count: %x tail: %x head: %x tmask: %x\n",
1941 __LINE__, bufcount, count, tail, head, tmask));
1944 * Limit printer output to maxcps overall, with bursts allowed
1945 * up to bufsize characters.
1947 bufcount = dgap_maxcps_room(tty, bufcount);
1950 * Take minimum of what the user wants to send, and the
1951 * space available in the FEP buffer.
1953 count = min(count, bufcount);
1956 * Bail if no space left.
1959 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
1960 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1965 * Output the printer ON string, if we are in terminal mode, but
1966 * need to be in printer mode.
1968 if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
1969 dgap_wmove(ch, ch->ch_digi.digi_onstr,
1970 (int) ch->ch_digi.digi_onlen);
1971 head = readw(&(bs->tx_head)) & tmask;
1972 ch->ch_flags |= CH_PRON;
1976 * On the other hand, output the printer OFF string, if we are
1977 * currently in printer mode, but need to output to the terminal.
1979 if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
1980 dgap_wmove(ch, ch->ch_digi.digi_offstr,
1981 (int) ch->ch_digi.digi_offlen);
1982 head = readw(&(bs->tx_head)) & tmask;
1983 ch->ch_flags &= ~CH_PRON;
1987 * If there is nothing left to copy, or I can't handle any more data, leave.
1990 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
1991 DGAP_UNLOCK(ch->ch_lock, lock_flags);
1997 count = min(count, WRITEBUFLEN);
1999 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2002 * If data is coming from user space, copy it into a temporary
2003 * buffer so we don't get swapped out while doing the copy to
2006 /* we're allowed to block if it's from_user */
2007 if (down_interruptible(&dgap_TmpWriteSem)) {
2011 if (copy_from_user(dgap_TmpWriteBuf, (const uchar __user *) buf, count)) {
2012 up(&dgap_TmpWriteSem);
2013 printk("Write: Copy from user failed!\n");
2017 DGAP_LOCK(ch->ch_lock, lock_flags);
2019 buf = dgap_TmpWriteBuf;
2025 * If the write wraps over the top of the circular buffer,
2026 * move the portion up to the wrap point, and reset the
2027 * pointers to the bottom.
2029 remain = ch->ch_tstart + ch->ch_tsize - head;
2033 vaddr = ch->ch_taddr + head;
2035 memcpy_toio(vaddr, (uchar *) buf, remain);
2036 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
2038 head = ch->ch_tstart;
2045 * Move rest of data.
2047 vaddr = ch->ch_taddr + head;
2050 memcpy_toio(vaddr, (uchar *) buf, remain);
2051 dgap_sniff_nowait_nolock(ch, "USER WRITE", (uchar *) buf, remain);
2058 ch->ch_txcount += count;
2060 writew(head, &(bs->tx_head));
2064 dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
2067 * If this is the print device, and the
2068 * printer is still on, we need to turn it
2069 * off before going idle. If the buffer is
2070 * non-empty, wait until it goes empty.
2071 * Otherwise turn it off right now.
2073 if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
2074 tail = readw(&(bs->tx_tail)) & tmask;
2077 un->un_flags |= UN_EMPTY;
2078 writeb(1, &(bs->iempty));
2081 dgap_wmove(ch, ch->ch_digi.digi_offstr,
2082 (int) ch->ch_digi.digi_offlen);
2083 head = readw(&(bs->tx_head)) & tmask;
2084 ch->ch_flags &= ~CH_PRON;
2088 /* Update printer buffer empty time. */
2089 if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
2090 && (ch->ch_digi.digi_bufsize > 0)) {
2091 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
2095 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2096 up(&dgap_TmpWriteSem);
2099 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2102 DPR_WRITE(("Write finished - Write %d bytes of %d.\n", count, orig_count));
2110 * Return modem signals to ld.
2112 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
2113 static int dgap_tty_tiocmget(struct tty_struct *tty)
2115 static int dgap_tty_tiocmget(struct tty_struct *tty, struct file *file)
2118 struct channel_t *ch;
2124 if (!tty || tty->magic != TTY_MAGIC)
2127 un = tty->driver_data;
2128 if (!un || un->magic != DGAP_UNIT_MAGIC)
2132 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2135 DPR_IOCTL(("dgap_tty_tiocmget start\n"));
2137 DGAP_LOCK(ch->ch_lock, lock_flags);
2139 mstat = readb(&(ch->ch_bs->m_stat));
2140 /* Append any outbound signals that might be pending... */
2141 mstat |= ch->ch_mostat;
2143 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2147 if (mstat & D_DTR(ch))
2148 result |= TIOCM_DTR;
2149 if (mstat & D_RTS(ch))
2150 result |= TIOCM_RTS;
2151 if (mstat & D_CTS(ch))
2152 result |= TIOCM_CTS;
2153 if (mstat & D_DSR(ch))
2154 result |= TIOCM_DSR;
2155 if (mstat & D_RI(ch))
2157 if (mstat & D_CD(ch))
2160 DPR_IOCTL(("dgap_tty_tiocmget finish\n"));
2167 * dgap_tty_tiocmset()
2169 * Set modem signals, called by ld.
2171 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,39)
2172 static int dgap_tty_tiocmset(struct tty_struct *tty,
2173 unsigned int set, unsigned int clear)
2175 static int dgap_tty_tiocmset(struct tty_struct *tty, struct file *file,
2176 unsigned int set, unsigned int clear)
2180 struct channel_t *ch;
2186 if (!tty || tty->magic != TTY_MAGIC)
2189 un = tty->driver_data;
2190 if (!un || un->magic != DGAP_UNIT_MAGIC)
2194 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2198 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2201 DPR_IOCTL(("dgap_tty_tiocmset start\n"));
2203 DGAP_LOCK(bd->bd_lock, lock_flags);
2204 DGAP_LOCK(ch->ch_lock, lock_flags2);
2206 if (set & TIOCM_RTS) {
2207 ch->ch_mforce |= D_RTS(ch);
2208 ch->ch_mval |= D_RTS(ch);
2211 if (set & TIOCM_DTR) {
2212 ch->ch_mforce |= D_DTR(ch);
2213 ch->ch_mval |= D_DTR(ch);
2216 if (clear & TIOCM_RTS) {
2217 ch->ch_mforce |= D_RTS(ch);
2218 ch->ch_mval &= ~(D_RTS(ch));
2221 if (clear & TIOCM_DTR) {
2222 ch->ch_mforce |= D_DTR(ch);
2223 ch->ch_mval &= ~(D_DTR(ch));
2228 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2229 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2231 DPR_IOCTL(("dgap_tty_tiocmset finish\n"));
2239 * dgap_tty_send_break()
2241 * Send a Break, called by ld.
2243 static int dgap_tty_send_break(struct tty_struct *tty, int msec)
2246 struct channel_t *ch;
2252 if (!tty || tty->magic != TTY_MAGIC)
2255 un = tty->driver_data;
2256 if (!un || un->magic != DGAP_UNIT_MAGIC)
2260 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2264 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2279 DPR_IOCTL(("dgap_tty_send_break start 1. %lx\n", jiffies));
2281 DGAP_LOCK(bd->bd_lock, lock_flags);
2282 DGAP_LOCK(ch->ch_lock, lock_flags2);
2284 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
2286 dgap_cmdw(ch, SBREAK, (u16) msec, 0);
2288 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2289 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2291 DPR_IOCTL(("dgap_tty_send_break finish\n"));
2300 * dgap_tty_wait_until_sent()
2302 * wait until data has been transmitted, called by ld.
2304 static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2307 rc = dgap_wait_for_drain(tty);
2309 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
2320 * send a high priority character, called by ld.
2322 static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
2325 struct channel_t *ch;
2330 if (!tty || tty->magic != TTY_MAGIC)
2333 un = tty->driver_data;
2334 if (!un || un->magic != DGAP_UNIT_MAGIC)
2338 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2342 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2345 DPR_IOCTL(("dgap_tty_send_xchar start 1. %lx\n", jiffies));
2347 DGAP_LOCK(bd->bd_lock, lock_flags);
2348 DGAP_LOCK(ch->ch_lock, lock_flags2);
2351 * This is technically what we should do.
2352 * However, the NIST tests specifically want
2353 * to see each XON or XOFF character that it
2354 * sends, so lets just send each character
2358 if (c == STOP_CHAR(tty)) {
2359 dgap_cmdw(ch, RPAUSE, 0, 0);
2361 else if (c == START_CHAR(tty)) {
2362 dgap_cmdw(ch, RRESUME, 0, 0);
2365 dgap_wmove(ch, &c, 1);
2368 dgap_wmove(ch, &c, 1);
2371 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2372 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2374 DPR_IOCTL(("dgap_tty_send_xchar finish\n"));
2383 * Return modem signals to ld.
2385 static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
2392 DPR_IOCTL(("dgap_get_modem_info start\n"));
2394 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2397 DGAP_LOCK(ch->ch_lock, lock_flags);
2399 mstat = readb(&(ch->ch_bs->m_stat));
2400 /* Append any outbound signals that might be pending... */
2401 mstat |= ch->ch_mostat;
2403 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2407 if (mstat & D_DTR(ch))
2408 result |= TIOCM_DTR;
2409 if (mstat & D_RTS(ch))
2410 result |= TIOCM_RTS;
2411 if (mstat & D_CTS(ch))
2412 result |= TIOCM_CTS;
2413 if (mstat & D_DSR(ch))
2414 result |= TIOCM_DSR;
2415 if (mstat & D_RI(ch))
2417 if (mstat & D_CD(ch))
2420 rc = put_user(result, value);
2422 DPR_IOCTL(("dgap_get_modem_info finish\n"));
2428 * dgap_set_modem_info()
2430 * Set modem signals, called by ld.
2432 static int dgap_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
2435 struct channel_t *ch;
2438 unsigned int arg = 0;
2442 if (!tty || tty->magic != TTY_MAGIC)
2445 un = tty->driver_data;
2446 if (!un || un->magic != DGAP_UNIT_MAGIC)
2450 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2454 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2457 DPR_IOCTL(("dgap_set_modem_info() start\n"));
2459 ret = get_user(arg, value);
2461 DPR_IOCTL(("dgap_set_modem_info %d ret: %x. finished.\n", __LINE__, ret));
2465 DPR_IOCTL(("dgap_set_modem_info: command: %x arg: %x\n", command, arg));
2469 if (arg & TIOCM_RTS) {
2470 ch->ch_mforce |= D_RTS(ch);
2471 ch->ch_mval |= D_RTS(ch);
2474 if (arg & TIOCM_DTR) {
2475 ch->ch_mforce |= D_DTR(ch);
2476 ch->ch_mval |= D_DTR(ch);
2482 if (arg & TIOCM_RTS) {
2483 ch->ch_mforce |= D_RTS(ch);
2484 ch->ch_mval &= ~(D_RTS(ch));
2487 if (arg & TIOCM_DTR) {
2488 ch->ch_mforce |= D_DTR(ch);
2489 ch->ch_mval &= ~(D_DTR(ch));
2495 ch->ch_mforce = D_DTR(ch)|D_RTS(ch);
2497 if (arg & TIOCM_RTS) {
2498 ch->ch_mval |= D_RTS(ch);
2501 ch->ch_mval &= ~(D_RTS(ch));
2504 if (arg & TIOCM_DTR) {
2505 ch->ch_mval |= (D_DTR(ch));
2508 ch->ch_mval &= ~(D_DTR(ch));
2517 DGAP_LOCK(bd->bd_lock, lock_flags);
2518 DGAP_LOCK(ch->ch_lock, lock_flags2);
2522 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2523 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2525 DPR_IOCTL(("dgap_set_modem_info finish\n"));
2532 * dgap_tty_digigeta()
2534 * Ioctl to get the information for ditty.
2539 static int dgap_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
2541 struct channel_t *ch;
2549 if (!tty || tty->magic != TTY_MAGIC)
2552 un = tty->driver_data;
2553 if (!un || un->magic != DGAP_UNIT_MAGIC)
2557 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2560 memset(&tmp, 0, sizeof(tmp));
2562 DGAP_LOCK(ch->ch_lock, lock_flags);
2563 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
2564 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2566 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2574 * dgap_tty_digiseta()
2576 * Ioctl to set the information for ditty.
2581 static int dgap_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
2584 struct channel_t *ch;
2586 struct digi_t new_digi;
2587 ulong lock_flags = 0;
2588 unsigned long lock_flags2;
2590 DPR_IOCTL(("DIGI_SETA start\n"));
2592 if (!tty || tty->magic != TTY_MAGIC)
2595 un = tty->driver_data;
2596 if (!un || un->magic != DGAP_UNIT_MAGIC)
2600 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2604 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2607 if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t))) {
2608 DPR_IOCTL(("DIGI_SETA failed copy_from_user\n"));
2612 DGAP_LOCK(bd->bd_lock, lock_flags);
2613 DGAP_LOCK(ch->ch_lock, lock_flags2);
2615 memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
2617 if (ch->ch_digi.digi_maxcps < 1)
2618 ch->ch_digi.digi_maxcps = 1;
2620 if (ch->ch_digi.digi_maxcps > 10000)
2621 ch->ch_digi.digi_maxcps = 10000;
2623 if (ch->ch_digi.digi_bufsize < 10)
2624 ch->ch_digi.digi_bufsize = 10;
2626 if (ch->ch_digi.digi_maxchar < 1)
2627 ch->ch_digi.digi_maxchar = 1;
2629 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
2630 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
2632 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
2633 ch->ch_digi.digi_onlen = DIGI_PLEN;
2635 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
2636 ch->ch_digi.digi_offlen = DIGI_PLEN;
2640 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2641 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2643 DPR_IOCTL(("DIGI_SETA finish\n"));
2650 * dgap_tty_digigetedelay()
2652 * Ioctl to get the current edelay setting.
2657 static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
2659 struct channel_t *ch;
2667 if (!tty || tty->magic != TTY_MAGIC)
2670 un = tty->driver_data;
2671 if (!un || un->magic != DGAP_UNIT_MAGIC)
2675 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2678 memset(&tmp, 0, sizeof(tmp));
2680 DGAP_LOCK(ch->ch_lock, lock_flags);
2681 tmp = readw(&(ch->ch_bs->edelay));
2682 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2684 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2692 * dgap_tty_digisetedelay()
2694 * Ioctl to set the EDELAY setting
2697 static int dgap_tty_digisetedelay(struct tty_struct *tty, int __user *new_info)
2700 struct channel_t *ch;
2706 DPR_IOCTL(("DIGI_SETA start\n"));
2708 if (!tty || tty->magic != TTY_MAGIC)
2711 un = tty->driver_data;
2712 if (!un || un->magic != DGAP_UNIT_MAGIC)
2716 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2720 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2723 if (copy_from_user(&new_digi, new_info, sizeof(int))) {
2724 DPR_IOCTL(("DIGI_SETEDELAY failed copy_from_user\n"));
2728 DGAP_LOCK(bd->bd_lock, lock_flags);
2729 DGAP_LOCK(ch->ch_lock, lock_flags2);
2731 writew((u16) new_digi, &(ch->ch_bs->edelay));
2735 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2736 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2738 DPR_IOCTL(("DIGI_SETA finish\n"));
2745 * dgap_tty_digigetcustombaud()
2747 * Ioctl to get the current custom baud rate setting.
2749 static int dgap_tty_digigetcustombaud(struct tty_struct *tty, int __user *retinfo)
2751 struct channel_t *ch;
2759 if (!tty || tty->magic != TTY_MAGIC)
2762 un = tty->driver_data;
2763 if (!un || un->magic != DGAP_UNIT_MAGIC)
2767 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2770 memset(&tmp, 0, sizeof(tmp));
2772 DGAP_LOCK(ch->ch_lock, lock_flags);
2773 tmp = dgap_get_custom_baud(ch);
2774 DGAP_UNLOCK(ch->ch_lock, lock_flags);
2776 DPR_IOCTL(("DIGI_GETCUSTOMBAUD. Returning %d\n", tmp));
2778 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
2786 * dgap_tty_digisetcustombaud()
2788 * Ioctl to set the custom baud rate setting
2790 static int dgap_tty_digisetcustombaud(struct tty_struct *tty, int __user *new_info)
2793 struct channel_t *ch;
2799 DPR_IOCTL(("DIGI_SETCUSTOMBAUD start\n"));
2801 if (!tty || tty->magic != TTY_MAGIC)
2804 un = tty->driver_data;
2805 if (!un || un->magic != DGAP_UNIT_MAGIC)
2809 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2813 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2817 if (copy_from_user(&new_rate, new_info, sizeof(unsigned int))) {
2818 DPR_IOCTL(("DIGI_SETCUSTOMBAUD failed copy_from_user\n"));
2822 if (bd->bd_flags & BD_FEP5PLUS) {
2824 DPR_IOCTL(("DIGI_SETCUSTOMBAUD. Setting %d\n", new_rate));
2826 DGAP_LOCK(bd->bd_lock, lock_flags);
2827 DGAP_LOCK(ch->ch_lock, lock_flags2);
2829 ch->ch_custom_speed = new_rate;
2833 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2834 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2837 DPR_IOCTL(("DIGI_SETCUSTOMBAUD finish\n"));
2844 * dgap_set_termios()
2846 static void dgap_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2849 struct channel_t *ch;
2851 unsigned long lock_flags;
2852 unsigned long lock_flags2;
2854 if (!tty || tty->magic != TTY_MAGIC)
2857 un = tty->driver_data;
2858 if (!un || un->magic != DGAP_UNIT_MAGIC)
2862 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2866 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2869 DGAP_LOCK(bd->bd_lock, lock_flags);
2870 DGAP_LOCK(ch->ch_lock, lock_flags2);
2872 ch->ch_c_cflag = tty->termios.c_cflag;
2873 ch->ch_c_iflag = tty->termios.c_iflag;
2874 ch->ch_c_oflag = tty->termios.c_oflag;
2875 ch->ch_c_lflag = tty->termios.c_lflag;
2876 ch->ch_startc = tty->termios.c_cc[VSTART];
2877 ch->ch_stopc = tty->termios.c_cc[VSTOP];
2882 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2883 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2887 static void dgap_tty_throttle(struct tty_struct *tty)
2890 struct channel_t *ch;
2895 if (!tty || tty->magic != TTY_MAGIC)
2898 un = tty->driver_data;
2899 if (!un || un->magic != DGAP_UNIT_MAGIC)
2903 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2907 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2910 DPR_IOCTL(("dgap_tty_throttle start\n"));
2912 DGAP_LOCK(bd->bd_lock, lock_flags);
2913 DGAP_LOCK(ch->ch_lock, lock_flags2);
2915 ch->ch_flags |= (CH_RXBLOCK);
2917 dgap_cmdw(ch, RPAUSE, 0, 0);
2920 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2921 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2923 DPR_IOCTL(("dgap_tty_throttle finish\n"));
2927 static void dgap_tty_unthrottle(struct tty_struct *tty)
2930 struct channel_t *ch;
2935 if (!tty || tty->magic != TTY_MAGIC)
2938 un = tty->driver_data;
2939 if (!un || un->magic != DGAP_UNIT_MAGIC)
2943 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2947 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2950 DPR_IOCTL(("dgap_tty_unthrottle start\n"));
2952 DGAP_LOCK(bd->bd_lock, lock_flags);
2953 DGAP_LOCK(ch->ch_lock, lock_flags2);
2955 ch->ch_flags &= ~(CH_RXBLOCK);
2958 dgap_cmdw(ch, RRESUME, 0, 0);
2961 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2962 DGAP_UNLOCK(bd->bd_lock, lock_flags);
2964 DPR_IOCTL(("dgap_tty_unthrottle finish\n"));
2968 static void dgap_tty_start(struct tty_struct *tty)
2971 struct channel_t *ch;
2976 if (!tty || tty->magic != TTY_MAGIC)
2979 un = tty->driver_data;
2980 if (!un || un->magic != DGAP_UNIT_MAGIC)
2984 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
2988 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
2991 DPR_IOCTL(("dgap_tty_start start\n"));
2993 DGAP_LOCK(bd->bd_lock, lock_flags);
2994 DGAP_LOCK(ch->ch_lock, lock_flags2);
2996 dgap_cmdw(ch, RESUMETX, 0, 0);
2998 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
2999 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3001 DPR_IOCTL(("dgap_tty_start finish\n"));
3005 static void dgap_tty_stop(struct tty_struct *tty)
3008 struct channel_t *ch;
3013 if (!tty || tty->magic != TTY_MAGIC)
3016 un = tty->driver_data;
3017 if (!un || un->magic != DGAP_UNIT_MAGIC)
3021 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3025 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3028 DPR_IOCTL(("dgap_tty_stop start\n"));
3030 DGAP_LOCK(bd->bd_lock, lock_flags);
3031 DGAP_LOCK(ch->ch_lock, lock_flags2);
3033 dgap_cmdw(ch, PAUSETX, 0, 0);
3035 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3036 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3038 DPR_IOCTL(("dgap_tty_stop finish\n"));
3043 * dgap_tty_flush_chars()
3045 * Flush the cook buffer
3047 * Note to self, and any other poor souls who venture here:
3049 * flush in this case DOES NOT mean dispose of the data.
3050 * instead, it means "stop buffering and send it if you
3051 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
3053 * It is also always called in interrupt context - JAR 8-Sept-99
3055 static void dgap_tty_flush_chars(struct tty_struct *tty)
3058 struct channel_t *ch;
3063 if (!tty || tty->magic != TTY_MAGIC)
3066 un = tty->driver_data;
3067 if (!un || un->magic != DGAP_UNIT_MAGIC)
3071 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3075 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3078 DPR_IOCTL(("dgap_tty_flush_chars start\n"));
3080 DGAP_LOCK(bd->bd_lock, lock_flags);
3081 DGAP_LOCK(ch->ch_lock, lock_flags2);
3083 /* TODO: Do something here */
3085 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3086 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3088 DPR_IOCTL(("dgap_tty_flush_chars finish\n"));
3094 * dgap_tty_flush_buffer()
3096 * Flush Tx buffer (make in == out)
3098 static void dgap_tty_flush_buffer(struct tty_struct *tty)
3101 struct channel_t *ch;
3107 if (!tty || tty->magic != TTY_MAGIC)
3110 un = tty->driver_data;
3111 if (!un || un->magic != DGAP_UNIT_MAGIC)
3115 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3119 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3122 DPR_IOCTL(("dgap_tty_flush_buffer on port: %d start\n", ch->ch_portnum));
3124 DGAP_LOCK(bd->bd_lock, lock_flags);
3125 DGAP_LOCK(ch->ch_lock, lock_flags2);
3127 ch->ch_flags &= ~CH_STOP;
3128 head = readw(&(ch->ch_bs->tx_head));
3129 dgap_cmdw(ch, FLUSHTX, (u16) head, 0);
3130 dgap_cmdw(ch, RESUMETX, 0, 0);
3131 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3132 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3133 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3135 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3136 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3137 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3140 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3141 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3142 if (waitqueue_active(&tty->write_wait))
3143 wake_up_interruptible(&tty->write_wait);
3146 DPR_IOCTL(("dgap_tty_flush_buffer finish\n"));
3151 /*****************************************************************************
3153 * The IOCTL function and all of its helpers
3155 *****************************************************************************/
3160 * The usual assortment of ioctl's
3162 static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
3166 struct channel_t *ch;
3170 ulong lock_flags = 0;
3171 ulong lock_flags2 = 0;
3172 void __user *uarg = (void __user *) arg;
3174 if (!tty || tty->magic != TTY_MAGIC)
3177 un = tty->driver_data;
3178 if (!un || un->magic != DGAP_UNIT_MAGIC)
3182 if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
3186 if (!bd || bd->magic != DGAP_BOARD_MAGIC)
3189 DPR_IOCTL(("dgap_tty_ioctl start on port %d - cmd %s (%x), arg %lx\n",
3190 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
3192 DGAP_LOCK(bd->bd_lock, lock_flags);
3193 DGAP_LOCK(ch->ch_lock, lock_flags2);
3195 if (un->un_open_count <= 0) {
3196 DPR_BASIC(("dgap_tty_ioctl - unit not open.\n"));
3197 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3198 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3204 /* Here are all the standard ioctl's that we MUST implement */
3208 * TCSBRK is SVID version: non-zero arg --> no break
3209 * this behaviour is exploited by tcdrain().
3211 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3212 * between 0.25 and 0.5 seconds so we'll ask for something
3213 * in the middle: 0.375 seconds.
3215 rc = tty_check_change(tty);
3216 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3217 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3222 rc = dgap_wait_for_drain(tty);
3225 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3229 DGAP_LOCK(bd->bd_lock, lock_flags);
3230 DGAP_LOCK(ch->ch_lock, lock_flags2);
3232 if(((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP)) {
3233 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3236 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3237 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3239 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3240 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
3246 /* support for POSIX tcsendbreak()
3248 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
3249 * between 0.25 and 0.5 seconds so we'll ask for something
3250 * in the middle: 0.375 seconds.
3252 rc = tty_check_change(tty);
3253 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3254 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3259 rc = dgap_wait_for_drain(tty);
3261 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3265 DGAP_LOCK(bd->bd_lock, lock_flags);
3266 DGAP_LOCK(ch->ch_lock, lock_flags2);
3268 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3270 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3271 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3273 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3274 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
3280 * FEP5 doesn't support turning on a break unconditionally.
3281 * The FEP5 device will stop sending a break automatically
3282 * after the specified time value that was sent when turning on
3285 rc = tty_check_change(tty);
3286 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3287 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3292 rc = dgap_wait_for_drain(tty);
3294 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3298 DGAP_LOCK(bd->bd_lock, lock_flags);
3299 DGAP_LOCK(ch->ch_lock, lock_flags2);
3301 dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
3303 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3304 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3306 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3307 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
3313 * FEP5 doesn't support turning off a break unconditionally.
3314 * The FEP5 device will stop sending a break automatically
3315 * after the specified time value that was sent when turning on
3318 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3319 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3324 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3325 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3327 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
3331 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3332 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3334 rc = get_user(arg, (unsigned long __user *) arg);
3338 DGAP_LOCK(bd->bd_lock, lock_flags);
3339 DGAP_LOCK(ch->ch_lock, lock_flags2);
3340 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
3342 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3343 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3348 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3349 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3350 return(dgap_get_modem_info(ch, uarg));
3355 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3356 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3357 return(dgap_set_modem_info(tty, cmd, uarg));
3360 * Here are any additional ioctl's that we want to implement
3365 * The linux tty driver doesn't have a flush
3366 * input routine for the driver, assuming all backed
3367 * up data is in the line disc. buffers. However,
3368 * we all know that's not the case. Here, we
3369 * act on the ioctl, but then lie and say we didn't
3370 * so the line discipline will process the flush
3373 rc = tty_check_change(tty);
3375 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3376 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3380 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
3381 if (!(un->un_type == DGAP_PRINT)) {
3382 head = readw(&(ch->ch_bs->rx_head));
3383 writew(head, &(ch->ch_bs->rx_tail));
3384 writeb(0, &(ch->ch_bs->orun));
3388 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
3389 ch->ch_flags &= ~CH_STOP;
3390 head = readw(&(ch->ch_bs->tx_head));
3391 dgap_cmdw(ch, FLUSHTX, (u16) head, 0 );
3392 dgap_cmdw(ch, RESUMETX, 0, 0);
3393 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
3394 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
3395 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
3397 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
3398 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
3399 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
3401 if (waitqueue_active(&tty->write_wait))
3402 wake_up_interruptible(&tty->write_wait);
3404 /* Can't hold any locks when calling tty_wakeup! */
3405 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3406 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3408 DGAP_LOCK(bd->bd_lock, lock_flags);
3409 DGAP_LOCK(ch->ch_lock, lock_flags2);
3412 /* pretend we didn't recognize this IOCTL */
3413 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3414 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3416 DPR_IOCTL(("dgap_tty_ioctl (LINE:%d) finish on port %d - cmd %s (%x), arg %lx\n",
3417 __LINE__, ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
3419 return(-ENOIOCTLCMD);
3424 * The linux tty driver doesn't have a flush
3425 * input routine for the driver, assuming all backed
3426 * up data is in the line disc. buffers. However,
3427 * we all know that's not the case. Here, we
3428 * act on the ioctl, but then lie and say we didn't
3429 * so the line discipline will process the flush
3432 if (cmd == TCSETSF) {
3434 ch->ch_flags &= ~CH_STOP;
3435 head = readw(&(ch->ch_bs->rx_head));
3436 writew(head, &(ch->ch_bs->rx_tail));
3439 /* now wait for all the output to drain */
3440 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3441 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3442 rc = dgap_wait_for_drain(tty);
3444 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3448 DPR_IOCTL(("dgap_tty_ioctl finish on port %d - cmd %s (%x), arg %lx\n",
3449 ch->ch_portnum, dgap_ioctl_name(cmd), cmd, arg));
3451 /* pretend we didn't recognize this */
3452 return(-ENOIOCTLCMD);
3456 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3457 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3458 rc = dgap_wait_for_drain(tty);
3460 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3464 /* pretend we didn't recognize this */
3465 return(-ENOIOCTLCMD);
3469 * The Linux Line Discipline (LD) would do this for us if we
3470 * let it, but we have the special firmware options to do this
3471 * the "right way" regardless of hardware or software flow
3472 * control so we'll do it outselves instead of letting the LD
3475 rc = tty_check_change(tty);
3477 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3478 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3482 DPR_IOCTL(("dgap_ioctl - in TCXONC - %d\n", cmd));
3486 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3487 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3488 dgap_tty_start(tty);
3491 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3492 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3496 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3497 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3498 /* Make the ld do it */
3499 return(-ENOIOCTLCMD);
3501 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3502 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3503 /* Make the ld do it */
3504 return(-ENOIOCTLCMD);
3506 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3507 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3512 /* get information for ditty */
3513 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3514 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3515 return(dgap_tty_digigeta(tty, uarg));
3520 /* set information for ditty */
3521 if (cmd == (DIGI_SETAW)) {
3523 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3524 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3525 rc = dgap_wait_for_drain(tty);
3527 DPR_IOCTL(("dgap_tty_ioctl - bad return: %d ", rc));
3530 DGAP_LOCK(bd->bd_lock, lock_flags);
3531 DGAP_LOCK(ch->ch_lock, lock_flags2);
3534 tty_ldisc_flush(tty);
3539 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3540 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3541 return(dgap_tty_digiseta(tty, uarg));
3544 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3545 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3546 return(dgap_tty_digigetedelay(tty, uarg));
3549 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3550 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3551 return(dgap_tty_digisetedelay(tty, uarg));
3553 case DIGI_GETCUSTOMBAUD:
3554 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3555 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3556 return(dgap_tty_digigetcustombaud(tty, uarg));
3558 case DIGI_SETCUSTOMBAUD:
3559 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3560 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3561 return(dgap_tty_digisetcustombaud(tty, uarg));
3563 case DIGI_RESET_PORT:
3564 dgap_firmware_reset_port(ch);
3566 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3567 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3571 DGAP_UNLOCK(ch->ch_lock, lock_flags2);
3572 DGAP_UNLOCK(bd->bd_lock, lock_flags);
3574 DPR_IOCTL(("dgap_tty_ioctl - in default\n"));
3575 DPR_IOCTL(("dgap_tty_ioctl end - cmd %s (%x), arg %lx\n",
3576 dgap_ioctl_name(cmd), cmd, arg));
3578 return(-ENOIOCTLCMD);