dgnc: get rid of dpacompat.h, move remaining stuff to digi.h
[linux-2.6-block.git] / drivers / staging / dgnc / dgnc_tty.c
CommitLineData
0b99d589
LL
1/*
2 * Copyright 2003 Digi International (www.digi.com)
3 * Scott H Kilau <Scott_Kilau at digi dot com>
4 *
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)
8 * any later version.
9 *
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.
0b99d589
LL
14 */
15
16/************************************************************************
8b07d521 17 *
0b99d589
LL
18 * This file implements the tty driver functionality for the
19 * Neo and ClassicBoard PCI based product lines.
8b07d521 20 *
0b99d589
LL
21 ************************************************************************
22 *
0b99d589
LL
23 */
24
25#include <linux/kernel.h>
0b99d589
LL
26#include <linux/sched.h> /* For jiffies, task states */
27#include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
28#include <linux/module.h>
29#include <linux/ctype.h>
30#include <linux/tty.h>
31#include <linux/tty_flip.h>
32#include <linux/serial_reg.h>
33#include <linux/slab.h>
90d2a471 34#include <linux/delay.h> /* For udelay */
fb33cac8 35#include <linux/uaccess.h> /* For copy_from_user/copy_to_user */
0b99d589 36#include <linux/pci.h>
0b99d589
LL
37#include "dgnc_driver.h"
38#include "dgnc_tty.h"
39#include "dgnc_types.h"
0b99d589
LL
40#include "dgnc_neo.h"
41#include "dgnc_cls.h"
0b99d589 42#include "dgnc_sysfs.h"
9a633d00 43#include "dgnc_utils.h"
0b99d589 44
90d2a471 45#define init_MUTEX(sem) sema_init(sem, 1)
0b99d589 46#define DECLARE_MUTEX(name) \
90d2a471 47 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
0b99d589
LL
48
49/*
50 * internal variables
51 */
03425f55 52static struct dgnc_board *dgnc_BoardsByMajor[256];
446393e9 53static unsigned char *dgnc_TmpWriteBuf;
0b99d589
LL
54static DECLARE_MUTEX(dgnc_TmpWriteSem);
55
56/*
57 * Default transparent print information.
58 */
59static struct digi_t dgnc_digi_init = {
60 .digi_flags = DIGI_COOK, /* Flags */
61 .digi_maxcps = 100, /* Max CPS */
62 .digi_maxchar = 50, /* Max chars in print queue */
63 .digi_bufsize = 100, /* Printer buffer size */
64 .digi_onlen = 4, /* size of printer on string */
65 .digi_offlen = 4, /* size of printer off string */
66 .digi_onstr = "\033[5i", /* ANSI printer on string ] */
67 .digi_offstr = "\033[4i", /* ANSI printer off string ] */
68 .digi_term = "ansi" /* default terminal type */
69};
70
71
72/*
73 * Define a local default termios struct. All ports will be created
74 * with this termios initially.
75 *
76 * This defines a raw port at 9600 baud, 8 data bits, no parity,
77 * 1 stop bit.
78 */
10352c2a 79static struct ktermios DgncDefaultTermios = {
0b99d589
LL
80 .c_iflag = (DEFAULT_IFLAGS), /* iflags */
81 .c_oflag = (DEFAULT_OFLAGS), /* oflags */
82 .c_cflag = (DEFAULT_CFLAGS), /* cflags */
83 .c_lflag = (DEFAULT_LFLAGS), /* lflags */
84 .c_cc = INIT_C_CC,
85 .c_line = 0,
86};
87
88
89/* Our function prototypes */
90static int dgnc_tty_open(struct tty_struct *tty, struct file *file);
91static void dgnc_tty_close(struct tty_struct *tty, struct file *file);
92static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch);
a31cefa2 93static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg);
0b99d589
LL
94static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo);
95static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info);
58b905b3 96static int dgnc_tty_write_room(struct tty_struct *tty);
0b99d589 97static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c);
58b905b3 98static int dgnc_tty_chars_in_buffer(struct tty_struct *tty);
0b99d589
LL
99static void dgnc_tty_start(struct tty_struct *tty);
100static void dgnc_tty_stop(struct tty_struct *tty);
101static void dgnc_tty_throttle(struct tty_struct *tty);
102static void dgnc_tty_unthrottle(struct tty_struct *tty);
103static void dgnc_tty_flush_chars(struct tty_struct *tty);
104static void dgnc_tty_flush_buffer(struct tty_struct *tty);
105static void dgnc_tty_hangup(struct tty_struct *tty);
106static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value);
107static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value);
0b99d589
LL
108static int dgnc_tty_tiocmget(struct tty_struct *tty);
109static int dgnc_tty_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
0b99d589
LL
110static int dgnc_tty_send_break(struct tty_struct *tty, int msec);
111static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout);
112static int dgnc_tty_write(struct tty_struct *tty, const unsigned char *buf, int count);
113static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios);
114static void dgnc_tty_send_xchar(struct tty_struct *tty, char ch);
115
116
117static const struct tty_operations dgnc_tty_ops = {
118 .open = dgnc_tty_open,
119 .close = dgnc_tty_close,
120 .write = dgnc_tty_write,
121 .write_room = dgnc_tty_write_room,
122 .flush_buffer = dgnc_tty_flush_buffer,
123 .chars_in_buffer = dgnc_tty_chars_in_buffer,
124 .flush_chars = dgnc_tty_flush_chars,
125 .ioctl = dgnc_tty_ioctl,
126 .set_termios = dgnc_tty_set_termios,
127 .stop = dgnc_tty_stop,
128 .start = dgnc_tty_start,
129 .throttle = dgnc_tty_throttle,
130 .unthrottle = dgnc_tty_unthrottle,
131 .hangup = dgnc_tty_hangup,
132 .put_char = dgnc_tty_put_char,
133 .tiocmget = dgnc_tty_tiocmget,
134 .tiocmset = dgnc_tty_tiocmset,
135 .break_ctl = dgnc_tty_send_break,
136 .wait_until_sent = dgnc_tty_wait_until_sent,
137 .send_xchar = dgnc_tty_send_xchar
138};
139
140/************************************************************************
8b07d521 141 *
0b99d589 142 * TTY Initialization/Cleanup Functions
8b07d521 143 *
0b99d589 144 ************************************************************************/
8b07d521 145
0b99d589
LL
146/*
147 * dgnc_tty_preinit()
148 *
149 * Initialize any global tty related data before we download any boards.
150 */
151int dgnc_tty_preinit(void)
152{
153 /*
154 * Allocate a buffer for doing the copy from user space to
155 * kernel space in dgnc_write(). We only use one buffer and
156 * control access to it with a semaphore. If we are paging, we
157 * are already in trouble so one buffer won't hurt much anyway.
158 *
159 * We are okay to sleep in the malloc, as this routine
160 * is only called during module load, (not in interrupt context),
161 * and with no locks held.
162 */
163 dgnc_TmpWriteBuf = kmalloc(WRITEBUFLEN, GFP_KERNEL);
164
f1e51745 165 if (!dgnc_TmpWriteBuf)
8f90ef80 166 return -ENOMEM;
0b99d589 167
8f90ef80 168 return 0;
0b99d589
LL
169}
170
171
172/*
173 * dgnc_tty_register()
174 *
175 * Init the tty subsystem for this board.
176 */
03425f55 177int dgnc_tty_register(struct dgnc_board *brd)
0b99d589
LL
178{
179 int rc = 0;
180
0b99d589 181 brd->SerialDriver.magic = TTY_DRIVER_MAGIC;
8b07d521 182
0b99d589
LL
183 snprintf(brd->SerialName, MAXTTYNAMELEN, "tty_dgnc_%d_", brd->boardnum);
184
185 brd->SerialDriver.name = brd->SerialName;
186 brd->SerialDriver.name_base = 0;
187 brd->SerialDriver.major = 0;
188 brd->SerialDriver.minor_start = 0;
189 brd->SerialDriver.num = brd->maxports;
8b07d521
LL
190 brd->SerialDriver.type = TTY_DRIVER_TYPE_SERIAL;
191 brd->SerialDriver.subtype = SERIAL_TYPE_NORMAL;
0b99d589
LL
192 brd->SerialDriver.init_termios = DgncDefaultTermios;
193 brd->SerialDriver.driver_name = DRVSTR;
194 brd->SerialDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
195
8b07d521 196 /*
0b99d589 197 * The kernel wants space to store pointers to
8b07d521 198 * tty_struct's and termios's.
0b99d589 199 */
b051017f 200 brd->SerialDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.ttys), GFP_KERNEL);
0b99d589 201 if (!brd->SerialDriver.ttys)
8f90ef80 202 return -ENOMEM;
0b99d589 203
90d2a471 204 kref_init(&brd->SerialDriver.kref);
b051017f 205 brd->SerialDriver.termios = kcalloc(brd->maxports, sizeof(*brd->SerialDriver.termios), GFP_KERNEL);
0b99d589 206 if (!brd->SerialDriver.termios)
8f90ef80 207 return -ENOMEM;
0b99d589 208
0b99d589
LL
209 /*
210 * Entry points for driver. Called by the kernel from
211 * tty_io.c and n_tty.c.
212 */
213 tty_set_operations(&brd->SerialDriver, &dgnc_tty_ops);
214
215 if (!brd->dgnc_Major_Serial_Registered) {
216 /* Register tty devices */
217 rc = tty_register_driver(&brd->SerialDriver);
218 if (rc < 0) {
1f26adc9
RD
219 dev_dbg(&brd->pdev->dev,
220 "Can't register tty device (%d)\n", rc);
8f90ef80 221 return rc;
0b99d589
LL
222 }
223 brd->dgnc_Major_Serial_Registered = TRUE;
224 }
225
226 /*
227 * If we're doing transparent print, we have to do all of the above
79e30af2 228 * again, separately so we don't get the LD confused about what major
0b99d589
LL
229 * we are when we get into the dgnc_tty_open() routine.
230 */
231 brd->PrintDriver.magic = TTY_DRIVER_MAGIC;
232 snprintf(brd->PrintName, MAXTTYNAMELEN, "pr_dgnc_%d_", brd->boardnum);
233
234 brd->PrintDriver.name = brd->PrintName;
235 brd->PrintDriver.name_base = 0;
236 brd->PrintDriver.major = brd->SerialDriver.major;
237 brd->PrintDriver.minor_start = 0x80;
238 brd->PrintDriver.num = brd->maxports;
8b07d521 239 brd->PrintDriver.type = TTY_DRIVER_TYPE_SERIAL;
0b99d589
LL
240 brd->PrintDriver.subtype = SERIAL_TYPE_NORMAL;
241 brd->PrintDriver.init_termios = DgncDefaultTermios;
242 brd->PrintDriver.driver_name = DRVSTR;
243 brd->PrintDriver.flags = (TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_HARDWARE_BREAK);
244
245 /*
246 * The kernel wants space to store pointers to
79e30af2 247 * tty_struct's and termios's. Must be separated from
0b99d589
LL
248 * the Serial Driver so we don't get confused
249 */
b051017f 250 brd->PrintDriver.ttys = kcalloc(brd->maxports, sizeof(*brd->PrintDriver.ttys), GFP_KERNEL);
0b99d589 251 if (!brd->PrintDriver.ttys)
8f90ef80 252 return -ENOMEM;
90d2a471 253 kref_init(&brd->PrintDriver.kref);
b051017f 254 brd->PrintDriver.termios = kcalloc(brd->maxports, sizeof(*brd->PrintDriver.termios), GFP_KERNEL);
0b99d589 255 if (!brd->PrintDriver.termios)
8f90ef80 256 return -ENOMEM;
0b99d589 257
0b99d589
LL
258 /*
259 * Entry points for driver. Called by the kernel from
260 * tty_io.c and n_tty.c.
261 */
262 tty_set_operations(&brd->PrintDriver, &dgnc_tty_ops);
263
264 if (!brd->dgnc_Major_TransparentPrint_Registered) {
265 /* Register Transparent Print devices */
90d2a471 266 rc = tty_register_driver(&brd->PrintDriver);
0b99d589 267 if (rc < 0) {
1f26adc9
RD
268 dev_dbg(&brd->pdev->dev,
269 "Can't register Transparent Print device(%d)\n",
270 rc);
8f90ef80 271 return rc;
0b99d589
LL
272 }
273 brd->dgnc_Major_TransparentPrint_Registered = TRUE;
274 }
275
276 dgnc_BoardsByMajor[brd->SerialDriver.major] = brd;
277 brd->dgnc_Serial_Major = brd->SerialDriver.major;
278 brd->dgnc_TransparentPrint_Major = brd->PrintDriver.major;
279
8f90ef80 280 return rc;
0b99d589
LL
281}
282
283
284/*
285 * dgnc_tty_init()
286 *
287 * Init the tty subsystem. Called once per board after board has been
288 * downloaded and init'ed.
289 */
03425f55 290int dgnc_tty_init(struct dgnc_board *brd)
0b99d589
LL
291{
292 int i;
a7a75386 293 void __iomem *vaddr;
0b99d589
LL
294 struct channel_t *ch;
295
296 if (!brd)
8f90ef80 297 return -ENXIO;
0b99d589 298
0b99d589
LL
299 /*
300 * Initialize board structure elements.
301 */
302
303 vaddr = brd->re_map_membase;
304
305 brd->nasync = brd->maxports;
306
307 /*
308 * Allocate channel memory that might not have been allocated
309 * when the driver was first loaded.
310 */
311 for (i = 0; i < brd->nasync; i++) {
312 if (!brd->channels[i]) {
313
314 /*
315 * Okay to malloc with GFP_KERNEL, we are not at
316 * interrupt context, and there are no locks held.
317 */
a07bf39a 318 brd->channels[i] = kzalloc(sizeof(*brd->channels[i]), GFP_KERNEL);
0b99d589
LL
319 }
320 }
321
322 ch = brd->channels[0];
323 vaddr = brd->re_map_membase;
324
325 /* Set up channel variables */
326 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
327
328 if (!brd->channels[i])
329 continue;
330
a44b508a 331 spin_lock_init(&ch->ch_lock);
0b99d589
LL
332
333 /* Store all our magic numbers */
334 ch->magic = DGNC_CHANNEL_MAGIC;
335 ch->ch_tun.magic = DGNC_UNIT_MAGIC;
336 ch->ch_tun.un_ch = ch;
337 ch->ch_tun.un_type = DGNC_SERIAL;
338 ch->ch_tun.un_dev = i;
339
340 ch->ch_pun.magic = DGNC_UNIT_MAGIC;
341 ch->ch_pun.un_ch = ch;
342 ch->ch_pun.un_type = DGNC_PRINT;
343 ch->ch_pun.un_dev = i + 128;
344
345 if (brd->bd_uart_offset == 0x200)
a7a75386 346 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
0b99d589 347 else
a7a75386 348 ch->ch_cls_uart = vaddr + (brd->bd_uart_offset * i);
0b99d589
LL
349
350 ch->ch_bd = brd;
351 ch->ch_portnum = i;
352 ch->ch_digi = dgnc_digi_init;
353
354 /* .25 second delay */
355 ch->ch_close_delay = 250;
356
357 init_waitqueue_head(&ch->ch_flags_wait);
358 init_waitqueue_head(&ch->ch_tun.un_flags_wait);
359 init_waitqueue_head(&ch->ch_pun.un_flags_wait);
0b99d589
LL
360
361 {
362 struct device *classp;
0eaa02e6 363
0b99d589
LL
364 classp = tty_register_device(&brd->SerialDriver, i,
365 &(ch->ch_bd->pdev->dev));
366 ch->ch_tun.un_sysfs = classp;
367 dgnc_create_tty_sysfs(&ch->ch_tun, classp);
368
369 classp = tty_register_device(&brd->PrintDriver, i,
370 &(ch->ch_bd->pdev->dev));
371 ch->ch_pun.un_sysfs = classp;
372 dgnc_create_tty_sysfs(&ch->ch_pun, classp);
373 }
374
375 }
376
8f90ef80 377 return 0;
0b99d589
LL
378}
379
380
381/*
382 * dgnc_tty_post_uninit()
383 *
384 * UnInitialize any global tty related data.
385 */
386void dgnc_tty_post_uninit(void)
387{
5b4af85e
DY
388 kfree(dgnc_TmpWriteBuf);
389 dgnc_TmpWriteBuf = NULL;
0b99d589
LL
390}
391
392
393/*
394 * dgnc_tty_uninit()
395 *
396 * Uninitialize the TTY portion of this driver. Free all memory and
8b07d521 397 * resources.
0b99d589 398 */
03425f55 399void dgnc_tty_uninit(struct dgnc_board *brd)
0b99d589
LL
400{
401 int i = 0;
402
403 if (brd->dgnc_Major_Serial_Registered) {
404 dgnc_BoardsByMajor[brd->SerialDriver.major] = NULL;
405 brd->dgnc_Serial_Major = 0;
406 for (i = 0; i < brd->nasync; i++) {
407 dgnc_remove_tty_sysfs(brd->channels[i]->ch_tun.un_sysfs);
408 tty_unregister_device(&brd->SerialDriver, i);
409 }
410 tty_unregister_driver(&brd->SerialDriver);
411 brd->dgnc_Major_Serial_Registered = FALSE;
412 }
413
414 if (brd->dgnc_Major_TransparentPrint_Registered) {
415 dgnc_BoardsByMajor[brd->PrintDriver.major] = NULL;
416 brd->dgnc_TransparentPrint_Major = 0;
417 for (i = 0; i < brd->nasync; i++) {
418 dgnc_remove_tty_sysfs(brd->channels[i]->ch_pun.un_sysfs);
419 tty_unregister_device(&brd->PrintDriver, i);
420 }
421 tty_unregister_driver(&brd->PrintDriver);
422 brd->dgnc_Major_TransparentPrint_Registered = FALSE;
423 }
424
5b4af85e
DY
425 kfree(brd->SerialDriver.ttys);
426 brd->SerialDriver.ttys = NULL;
427 kfree(brd->PrintDriver.ttys);
428 brd->PrintDriver.ttys = NULL;
0b99d589
LL
429}
430
431
432#define TMPBUFLEN (1024)
433
0b99d589
LL
434/*=======================================================================
435 *
436 * dgnc_wmove - Write data to transmit queue.
437 *
438 * ch - Pointer to channel structure.
439 * buf - Poiter to characters to be moved.
440 * n - Number of characters to move.
441 *
442 *=======================================================================*/
443static void dgnc_wmove(struct channel_t *ch, char *buf, uint n)
444{
445 int remain;
446 uint head;
447
448 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
449 return;
8b07d521 450
0b99d589
LL
451 head = ch->ch_w_head & WQUEUEMASK;
452
453 /*
454 * If the write wraps over the top of the circular buffer,
455 * move the portion up to the wrap point, and reset the
456 * pointers to the bottom.
457 */
458 remain = WQUEUESIZE - head;
459
460 if (n >= remain) {
8b07d521 461 n -= remain;
0b99d589
LL
462 memcpy(ch->ch_wqueue + head, buf, remain);
463 head = 0;
464 buf += remain;
465 }
466
467 if (n > 0) {
468 /*
469 * Move rest of data.
470 */
471 remain = n;
472 memcpy(ch->ch_wqueue + head, buf, remain);
473 head += remain;
474 }
475
476 head &= WQUEUEMASK;
477 ch->ch_w_head = head;
478}
479
480
481
482
483/*=======================================================================
484 *
485 * dgnc_input - Process received data.
8b07d521 486 *
90d2a471 487 * ch - Pointer to channel structure.
8b07d521 488 *
0b99d589
LL
489 *=======================================================================*/
490void dgnc_input(struct channel_t *ch)
491{
03425f55 492 struct dgnc_board *bd;
0b99d589 493 struct tty_struct *tp;
c84a083b 494 struct tty_ldisc *ld = NULL;
0b99d589
LL
495 uint rmask;
496 ushort head;
497 ushort tail;
498 int data_len;
a44b508a 499 unsigned long flags;
0b99d589
LL
500 int flip_len;
501 int len = 0;
502 int n = 0;
0b99d589
LL
503 int s = 0;
504 int i = 0;
505
506 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
507 return;
508
509 tp = ch->ch_tun.un_tty;
510
511 bd = ch->ch_bd;
a82477c3 512 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
0b99d589
LL
513 return;
514
a44b508a 515 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 516
8b07d521
LL
517 /*
518 * Figure the number of characters in the buffer.
0b99d589
LL
519 * Exit immediately if none.
520 */
521 rmask = RQUEUEMASK;
522 head = ch->ch_r_head & rmask;
523 tail = ch->ch_r_tail & rmask;
524 data_len = (head - tail) & rmask;
525
c84a083b
QL
526 if (data_len == 0)
527 goto exit_unlock;
0b99d589 528
0b99d589
LL
529 /*
530 * If the device is not open, or CREAD is off,
90d2a471 531 * flush input data and return immediately.
0b99d589 532 */
8b07d521 533 if (!tp || (tp->magic != TTY_MAGIC) || !(ch->ch_tun.un_flags & UN_ISOPEN) ||
22e3de76 534 !(tp->termios.c_cflag & CREAD) || (ch->ch_tun.un_flags & UN_CLOSING)) {
0b99d589 535
0b99d589
LL
536 ch->ch_r_head = tail;
537
538 /* Force queue flow control to be released, if needed */
539 dgnc_check_queue_flow_control(ch);
540
c84a083b 541 goto exit_unlock;
0b99d589
LL
542 }
543
544 /*
545 * If we are throttled, simply don't read any data.
546 */
c84a083b
QL
547 if (ch->ch_flags & CH_FORCED_STOPI)
548 goto exit_unlock;
0b99d589 549
100013fa 550 flip_len = TTY_FLIPBUF_SIZE;
0b99d589
LL
551
552 /* Chop down the length, if needed */
553 len = min(data_len, flip_len);
100013fa 554 len = min(len, (N_TTY_BUF_SIZE - 1));
0b99d589
LL
555
556 ld = tty_ldisc_ref(tp);
557
558#ifdef TTY_DONT_FLIP
559 /*
560 * If the DONT_FLIP flag is on, don't flush our buffer, and act
561 * like the ld doesn't have any space to put the data right now.
562 */
563 if (test_bit(TTY_DONT_FLIP, &tp->flags))
564 len = 0;
565#endif
566
567 /*
568 * If we were unable to get a reference to the ld,
569 * don't flush our buffer, and act like the ld doesn't
570 * have any space to put the data right now.
571 */
572 if (!ld) {
573 len = 0;
574 } else {
575 /*
576 * If ld doesn't have a pointer to a receive_buf function,
577 * flush the data, then act like the ld doesn't have any
578 * space to put the data right now.
579 */
580 if (!ld->ops->receive_buf) {
581 ch->ch_r_head = ch->ch_r_tail;
582 len = 0;
8b07d521 583 }
0b99d589
LL
584 }
585
c84a083b
QL
586 if (len <= 0)
587 goto exit_unlock;
0b99d589
LL
588
589 /*
590 * The tty layer in the kernel has changed in 2.6.16+.
591 *
592 * The flip buffers in the tty structure are no longer exposed,
593 * and probably will be going away eventually.
8b07d521 594 *
0b99d589
LL
595 * If we are completely raw, we don't need to go through a lot
596 * of the tty layers that exist.
597 * In this case, we take the shortest and fastest route we
598 * can to relay the data to the user.
599 *
600 * On the other hand, if we are not raw, we need to go through
601 * the new 2.6.16+ tty layer, which has its API more well defined.
602 */
100013fa
LL
603 len = tty_buffer_request_room(tp->port, len);
604 n = len;
0b99d589 605
100013fa
LL
606 /*
607 * n now contains the most amount of data we can copy,
608 * bounded either by how much the Linux tty layer can handle,
609 * or the amount of data the card actually has pending...
610 */
611 while (n) {
612 s = ((head >= tail) ? head : RQUEUESIZE) - tail;
613 s = min(s, n);
0b99d589 614
100013fa
LL
615 if (s <= 0)
616 break;
0b99d589
LL
617
618 /*
8b07d521 619 * If conditions are such that ld needs to see all
100013fa
LL
620 * UART errors, we will have to walk each character
621 * and error byte and send them to the buffer one at
622 * a time.
0b99d589 623 */
100013fa
LL
624 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
625 for (i = 0; i < s; i++) {
626 if (*(ch->ch_equeue + tail + i) & UART_LSR_BI)
627 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_BREAK);
628 else if (*(ch->ch_equeue + tail + i) & UART_LSR_PE)
629 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_PARITY);
630 else if (*(ch->ch_equeue + tail + i) & UART_LSR_FE)
631 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_FRAME);
632 else
633 tty_insert_flip_char(tp->port, *(ch->ch_rqueue + tail + i), TTY_NORMAL);
634 }
2000c581 635 } else {
100013fa 636 tty_insert_flip_string(tp->port, ch->ch_rqueue + tail, s);
0b99d589
LL
637 }
638
100013fa
LL
639 tail += s;
640 n -= s;
641 /* Flip queue if needed */
642 tail &= rmask;
0b99d589 643 }
0b99d589 644
100013fa
LL
645 ch->ch_r_tail = tail & rmask;
646 ch->ch_e_tail = tail & rmask;
647 dgnc_check_queue_flow_control(ch);
a44b508a 648 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 649
100013fa
LL
650 /* Tell the tty layer its okay to "eat" the data now */
651 tty_flip_buffer_push(tp->port);
0b99d589
LL
652
653 if (ld)
654 tty_ldisc_deref(ld);
c84a083b
QL
655 return;
656
657exit_unlock:
5ec29365 658 spin_unlock_irqrestore(&ch->ch_lock, flags);
c84a083b
QL
659 if (ld)
660 tty_ldisc_deref(ld);
0b99d589
LL
661}
662
663
8b07d521 664/************************************************************************
0b99d589 665 * Determines when CARRIER changes state and takes appropriate
8b07d521 666 * action.
0b99d589
LL
667 ************************************************************************/
668void dgnc_carrier(struct channel_t *ch)
669{
03425f55 670 struct dgnc_board *bd;
0b99d589 671
90d2a471
LL
672 int virt_carrier = 0;
673 int phys_carrier = 0;
8b07d521 674
0b99d589
LL
675 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
676 return;
677
678 bd = ch->ch_bd;
679
680 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
681 return;
682
f1e51745 683 if (ch->ch_mistat & UART_MSR_DCD)
0b99d589 684 phys_carrier = 1;
0b99d589 685
50667c67 686 if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
0b99d589 687 virt_carrier = 1;
0b99d589 688
50667c67 689 if (ch->ch_c_cflag & CLOCAL)
0b99d589 690 virt_carrier = 1;
0b99d589 691
0b99d589
LL
692 /*
693 * Test for a VIRTUAL carrier transition to HIGH.
694 */
695 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
696
697 /*
698 * When carrier rises, wake any threads waiting
699 * for carrier in the open routine.
700 */
701
0b99d589
LL
702 if (waitqueue_active(&(ch->ch_flags_wait)))
703 wake_up_interruptible(&ch->ch_flags_wait);
704 }
705
706 /*
707 * Test for a PHYSICAL carrier transition to HIGH.
708 */
709 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
710
711 /*
712 * When carrier rises, wake any threads waiting
713 * for carrier in the open routine.
714 */
715
0b99d589
LL
716 if (waitqueue_active(&(ch->ch_flags_wait)))
717 wake_up_interruptible(&ch->ch_flags_wait);
718 }
719
720 /*
721 * Test for a PHYSICAL transition to low, so long as we aren't
722 * currently ignoring physical transitions (which is what "virtual
723 * carrier" indicates).
724 *
725 * The transition of the virtual carrier to low really doesn't
726 * matter... it really only means "ignore carrier state", not
727 * "make pretend that carrier is there".
728 */
729 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0) &&
10352c2a 730 (phys_carrier == 0)) {
0b99d589
LL
731
732 /*
733 * When carrier drops:
734 *
735 * Drop carrier on all open units.
736 *
737 * Flush queues, waking up any task waiting in the
738 * line discipline.
739 *
740 * Send a hangup to the control terminal.
741 *
742 * Enable all select calls.
743 */
744 if (waitqueue_active(&(ch->ch_flags_wait)))
745 wake_up_interruptible(&ch->ch_flags_wait);
746
f1e51745 747 if (ch->ch_tun.un_open_count > 0)
0b99d589 748 tty_hangup(ch->ch_tun.un_tty);
0b99d589 749
f1e51745 750 if (ch->ch_pun.un_open_count > 0)
0b99d589 751 tty_hangup(ch->ch_pun.un_tty);
0b99d589
LL
752 }
753
754 /*
755 * Make sure that our cached values reflect the current reality.
756 */
757 if (virt_carrier == 1)
758 ch->ch_flags |= CH_FCAR;
8b07d521 759 else
0b99d589
LL
760 ch->ch_flags &= ~CH_FCAR;
761
762 if (phys_carrier == 1)
763 ch->ch_flags |= CH_CD;
764 else
765 ch->ch_flags &= ~CH_CD;
766}
767
768/*
769 * Assign the custom baud rate to the channel structure
770 */
771static void dgnc_set_custom_speed(struct channel_t *ch, uint newrate)
772{
773 int testdiv;
774 int testrate_high;
8b07d521 775 int testrate_low;
0b99d589
LL
776 int deltahigh;
777 int deltalow;
778
93c76c9c
DY
779 if (newrate <= 0) {
780 ch->ch_custom_speed = 0;
781 return;
782 }
0b99d589
LL
783
784 /*
785 * Since the divisor is stored in a 16-bit integer, we make sure
786 * we don't allow any rates smaller than a 16-bit integer would allow.
787 * And of course, rates above the dividend won't fly.
788 */
789 if (newrate && newrate < ((ch->ch_bd->bd_dividend / 0xFFFF) + 1))
790 newrate = ((ch->ch_bd->bd_dividend / 0xFFFF) + 1);
791
792 if (newrate && newrate > ch->ch_bd->bd_dividend)
90d2a471 793 newrate = ch->ch_bd->bd_dividend;
0b99d589 794
93c76c9c 795 if (newrate > 0) {
0b99d589
LL
796 testdiv = ch->ch_bd->bd_dividend / newrate;
797
798 /*
799 * If we try to figure out what rate the board would use
800 * with the test divisor, it will be either equal or higher
801 * than the requested baud rate. If we then determine the
8b07d521 802 * rate with a divisor one higher, we will get the next lower
0b99d589
LL
803 * supported rate below the requested.
804 */
805 testrate_high = ch->ch_bd->bd_dividend / testdiv;
806 testrate_low = ch->ch_bd->bd_dividend / (testdiv + 1);
807
808 /*
809 * If the rate for the requested divisor is correct, just
810 * use it and be done.
811 */
93c76c9c
DY
812 if (testrate_high != newrate) {
813 /*
814 * Otherwise, pick the rate that is closer (i.e. whichever rate
815 * has a smaller delta).
816 */
817 deltahigh = testrate_high - newrate;
818 deltalow = newrate - testrate_low;
0b99d589 819
50667c67 820 if (deltahigh < deltalow)
93c76c9c 821 newrate = testrate_high;
50667c67 822 else
93c76c9c 823 newrate = testrate_low;
0b99d589 824 }
0b99d589 825 }
8b07d521 826
0b99d589 827 ch->ch_custom_speed = newrate;
0b99d589
LL
828}
829
830
831void dgnc_check_queue_flow_control(struct channel_t *ch)
832{
833 int qleft = 0;
834
835 /* Store how much space we have left in the queue */
f7c851d4
CP
836 qleft = ch->ch_r_tail - ch->ch_r_head - 1;
837 if (qleft < 0)
0b99d589
LL
838 qleft += RQUEUEMASK + 1;
839
840 /*
841 * Check to see if we should enforce flow control on our queue because
842 * the ld (or user) isn't reading data out of our queue fast enuf.
843 *
844 * NOTE: This is done based on what the current flow control of the
845 * port is set for.
846 *
847 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
848 * This will cause the UART's FIFO to back up, and force
849 * the RTS signal to be dropped.
850 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
851 * the other side, in hopes it will stop sending data to us.
852 * 3) NONE - Nothing we can do. We will simply drop any extra data
853 * that gets sent into us when the queue fills up.
854 */
855 if (qleft < 256) {
856 /* HWFLOW */
857 if (ch->ch_digi.digi_flags & CTSPACE || ch->ch_c_cflag & CRTSCTS) {
a82477c3 858 if (!(ch->ch_flags & CH_RECEIVER_OFF)) {
0b99d589
LL
859 ch->ch_bd->bd_ops->disable_receiver(ch);
860 ch->ch_flags |= (CH_RECEIVER_OFF);
0b99d589
LL
861 }
862 }
863 /* SWFLOW */
864 else if (ch->ch_c_iflag & IXOFF) {
865 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
866 ch->ch_bd->bd_ops->send_stop_character(ch);
867 ch->ch_stops_sent++;
0b99d589
LL
868 }
869 }
0b99d589
LL
870 }
871
872 /*
873 * Check to see if we should unenforce flow control because
874 * ld (or user) finally read enuf data out of our queue.
875 *
876 * NOTE: This is done based on what the current flow control of the
877 * port is set for.
878 *
879 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
880 * This will cause the UART's FIFO to raise RTS back up,
881 * which will allow the other side to start sending data again.
882 * 2) SWFLOW (IXOFF) - Send a start character to
883 * the other side, so it will start sending data to us again.
884 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
885 * other side, we don't need to do anything now.
886 */
887 if (qleft > (RQUEUESIZE / 2)) {
888 /* HWFLOW */
889 if (ch->ch_digi.digi_flags & RTSPACE || ch->ch_c_cflag & CRTSCTS) {
890 if (ch->ch_flags & CH_RECEIVER_OFF) {
891 ch->ch_bd->bd_ops->enable_receiver(ch);
892 ch->ch_flags &= ~(CH_RECEIVER_OFF);
0b99d589
LL
893 }
894 }
895 /* SWFLOW */
896 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
897 ch->ch_stops_sent = 0;
898 ch->ch_bd->bd_ops->send_start_character(ch);
0b99d589
LL
899 }
900 /* No FLOW */
901 else {
902 /* Nothing needed. */
903 }
904 }
905}
906
907
908void dgnc_wakeup_writes(struct channel_t *ch)
909{
910 int qlen = 0;
a44b508a 911 unsigned long flags;
0b99d589
LL
912
913 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
914 return;
915
a44b508a 916 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
917
918 /*
919 * If channel now has space, wake up anyone waiting on the condition.
920 */
f7c851d4
CP
921 qlen = ch->ch_w_head - ch->ch_w_tail;
922 if (qlen < 0)
90d2a471 923 qlen += WQUEUESIZE;
0b99d589
LL
924
925 if (qlen >= (WQUEUESIZE - 256)) {
a44b508a 926 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
927 return;
928 }
929
930 if (ch->ch_tun.un_flags & UN_ISOPEN) {
90d2a471 931 if ((ch->ch_tun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
10352c2a 932 ch->ch_tun.un_tty->ldisc->ops->write_wakeup) {
a44b508a 933 spin_unlock_irqrestore(&ch->ch_lock, flags);
90d2a471 934 (ch->ch_tun.un_tty->ldisc->ops->write_wakeup)(ch->ch_tun.un_tty);
a44b508a 935 spin_lock_irqsave(&ch->ch_lock, flags);
90d2a471 936 }
0b99d589
LL
937
938 wake_up_interruptible(&ch->ch_tun.un_tty->write_wait);
939
940 /*
941 * If unit is set to wait until empty, check to make sure
942 * the queue AND FIFO are both empty.
943 */
944 if (ch->ch_tun.un_flags & UN_EMPTY) {
945 if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0)) {
946 ch->ch_tun.un_flags &= ~(UN_EMPTY);
947
948 /*
949 * If RTS Toggle mode is on, whenever
950 * the queue and UART is empty, keep RTS low.
951 */
952 if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) {
953 ch->ch_mostat &= ~(UART_MCR_RTS);
954 ch->ch_bd->bd_ops->assert_modem_signals(ch);
955 }
956
957 /*
958 * If DTR Toggle mode is on, whenever
959 * the queue and UART is empty, keep DTR low.
960 */
961 if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) {
962 ch->ch_mostat &= ~(UART_MCR_DTR);
963 ch->ch_bd->bd_ops->assert_modem_signals(ch);
964 }
965 }
966 }
967
968 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
969 }
970
971 if (ch->ch_pun.un_flags & UN_ISOPEN) {
90d2a471 972 if ((ch->ch_pun.un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
10352c2a 973 ch->ch_pun.un_tty->ldisc->ops->write_wakeup) {
a44b508a 974 spin_unlock_irqrestore(&ch->ch_lock, flags);
90d2a471 975 (ch->ch_pun.un_tty->ldisc->ops->write_wakeup)(ch->ch_pun.un_tty);
a44b508a 976 spin_lock_irqsave(&ch->ch_lock, flags);
90d2a471 977 }
0b99d589
LL
978
979 wake_up_interruptible(&ch->ch_pun.un_tty->write_wait);
980
981 /*
982 * If unit is set to wait until empty, check to make sure
983 * the queue AND FIFO are both empty.
984 */
985 if (ch->ch_pun.un_flags & UN_EMPTY) {
3c4019d3 986 if ((qlen == 0) && (ch->ch_bd->bd_ops->get_uart_bytes_left(ch) == 0))
0b99d589 987 ch->ch_pun.un_flags &= ~(UN_EMPTY);
0b99d589
LL
988 }
989
990 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
991 }
992
a44b508a 993 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
994}
995
996
997
998/************************************************************************
8b07d521 999 *
0b99d589 1000 * TTY Entry points and helper functions
8b07d521 1001 *
0b99d589
LL
1002 ************************************************************************/
1003
1004/*
1005 * dgnc_tty_open()
1006 *
1007 */
1008static int dgnc_tty_open(struct tty_struct *tty, struct file *file)
1009{
03425f55 1010 struct dgnc_board *brd;
0b99d589
LL
1011 struct channel_t *ch;
1012 struct un_t *un;
1013 uint major = 0;
1014 uint minor = 0;
1015 int rc = 0;
a44b508a 1016 unsigned long flags;
0b99d589
LL
1017
1018 rc = 0;
1019
1020 major = MAJOR(tty_devnum(tty));
1021 minor = MINOR(tty_devnum(tty));
1022
50667c67 1023 if (major > 255)
0b99d589 1024 return -ENXIO;
0b99d589
LL
1025
1026 /* Get board pointer from our array of majors we have allocated */
1027 brd = dgnc_BoardsByMajor[major];
50667c67 1028 if (!brd)
0b99d589 1029 return -ENXIO;
0b99d589
LL
1030
1031 /*
1032 * If board is not yet up to a state of READY, go to
1033 * sleep waiting for it to happen or they cancel the open.
1034 */
1035 rc = wait_event_interruptible(brd->state_wait,
1036 (brd->state & BOARD_READY));
1037
50667c67 1038 if (rc)
0b99d589 1039 return rc;
0b99d589 1040
a44b508a 1041 spin_lock_irqsave(&brd->bd_lock, flags);
0b99d589
LL
1042
1043 /* If opened device is greater than our number of ports, bail. */
4bef52f3 1044 if (PORT_NUM(minor) >= brd->nasync) {
a44b508a 1045 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
1046 return -ENXIO;
1047 }
1048
1049 ch = brd->channels[PORT_NUM(minor)];
1050 if (!ch) {
a44b508a 1051 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
1052 return -ENXIO;
1053 }
1054
1055 /* Drop board lock */
a44b508a 1056 spin_unlock_irqrestore(&brd->bd_lock, flags);
0b99d589
LL
1057
1058 /* Grab channel lock */
a44b508a 1059 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1060
1061 /* Figure out our type */
1062 if (!IS_PRINT(minor)) {
1063 un = &brd->channels[PORT_NUM(minor)]->ch_tun;
1064 un->un_type = DGNC_SERIAL;
2000c581 1065 } else if (IS_PRINT(minor)) {
0b99d589
LL
1066 un = &brd->channels[PORT_NUM(minor)]->ch_pun;
1067 un->un_type = DGNC_PRINT;
2000c581 1068 } else {
a44b508a 1069 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1070 return -ENXIO;
1071 }
1072
1073 /*
1074 * If the port is still in a previous open, and in a state
1075 * where we simply cannot safely keep going, wait until the
1076 * state clears.
1077 */
a44b508a 1078 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1079
1080 rc = wait_event_interruptible(ch->ch_flags_wait, ((ch->ch_flags & CH_OPENING) == 0));
1081
1082 /* If ret is non-zero, user ctrl-c'ed us */
f1e51745 1083 if (rc)
0b99d589 1084 return -EINTR;
0b99d589
LL
1085
1086 /*
1087 * If either unit is in the middle of the fragile part of close,
1088 * we just cannot touch the channel safely.
1089 * Go to sleep, knowing that when the channel can be
1090 * touched safely, the close routine will signal the
1091 * ch_flags_wait to wake us back up.
1092 */
1093 rc = wait_event_interruptible(ch->ch_flags_wait,
1094 (((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING) == 0));
1095
1096 /* If ret is non-zero, user ctrl-c'ed us */
f1e51745 1097 if (rc)
0b99d589 1098 return -EINTR;
0b99d589 1099
a44b508a 1100 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1101
1102
1103 /* Store our unit into driver_data, so we always have it available. */
1104 tty->driver_data = un;
1105
0b99d589
LL
1106
1107 /*
1108 * Initialize tty's
1109 */
1110 if (!(un->un_flags & UN_ISOPEN)) {
1111 /* Store important variables. */
1112 un->un_tty = tty;
1113
1114 /* Maybe do something here to the TTY struct as well? */
1115 }
1116
1117
1118 /*
1119 * Allocate channel buffers for read/write/error.
1120 * Set flag, so we don't get trounced on.
1121 */
1122 ch->ch_flags |= (CH_OPENING);
1123
1124 /* Drop locks, as malloc with GFP_KERNEL can sleep */
a44b508a 1125 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1126
1127 if (!ch->ch_rqueue)
52f9d668 1128 ch->ch_rqueue = kzalloc(RQUEUESIZE, GFP_KERNEL);
0b99d589 1129 if (!ch->ch_equeue)
52f9d668 1130 ch->ch_equeue = kzalloc(EQUEUESIZE, GFP_KERNEL);
0b99d589 1131 if (!ch->ch_wqueue)
52f9d668 1132 ch->ch_wqueue = kzalloc(WQUEUESIZE, GFP_KERNEL);
0b99d589 1133
a44b508a 1134 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1135
1136 ch->ch_flags &= ~(CH_OPENING);
1137 wake_up_interruptible(&ch->ch_flags_wait);
1138
1139 /*
1140 * Initialize if neither terminal or printer is open.
1141 */
1142 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
1143
0b99d589
LL
1144 /*
1145 * Flush input queues.
1146 */
587abd7b
SL
1147 ch->ch_r_head = 0;
1148 ch->ch_r_tail = 0;
1149 ch->ch_e_head = 0;
1150 ch->ch_e_tail = 0;
1151 ch->ch_w_head = 0;
1152 ch->ch_w_tail = 0;
0b99d589
LL
1153
1154 brd->bd_ops->flush_uart_write(ch);
1155 brd->bd_ops->flush_uart_read(ch);
1156
1157 ch->ch_flags = 0;
1158 ch->ch_cached_lsr = 0;
1159 ch->ch_stop_sending_break = 0;
1160 ch->ch_stops_sent = 0;
1161
22e3de76
LL
1162 ch->ch_c_cflag = tty->termios.c_cflag;
1163 ch->ch_c_iflag = tty->termios.c_iflag;
1164 ch->ch_c_oflag = tty->termios.c_oflag;
1165 ch->ch_c_lflag = tty->termios.c_lflag;
1166 ch->ch_startc = tty->termios.c_cc[VSTART];
1167 ch->ch_stopc = tty->termios.c_cc[VSTOP];
0b99d589
LL
1168
1169 /*
1170 * Bring up RTS and DTR...
1171 * Also handle RTS or DTR toggle if set.
1172 */
1173 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE))
1174 ch->ch_mostat |= (UART_MCR_RTS);
1175 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE))
1176 ch->ch_mostat |= (UART_MCR_DTR);
1177
1178 /* Tell UART to init itself */
1179 brd->bd_ops->uart_init(ch);
1180 }
1181
1182 /*
1183 * Run param in case we changed anything
1184 */
1185 brd->bd_ops->param(tty);
1186
1187 dgnc_carrier(ch);
1188
8b07d521 1189 /*
0b99d589
LL
1190 * follow protocol for opening port
1191 */
1192
a44b508a 1193 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1194
1195 rc = dgnc_block_til_ready(tty, file, ch);
1196
0b99d589 1197 /* No going back now, increment our unit and channel counters */
a44b508a 1198 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1199 ch->ch_open_count++;
1200 un->un_open_count++;
1201 un->un_flags |= (UN_ISOPEN);
a44b508a 1202 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 1203
8f90ef80 1204 return rc;
0b99d589
LL
1205}
1206
1207
8b07d521 1208/*
0b99d589
LL
1209 * dgnc_block_til_ready()
1210 *
1211 * Wait for DCD, if needed.
1212 */
1213static int dgnc_block_til_ready(struct tty_struct *tty, struct file *file, struct channel_t *ch)
8b07d521 1214{
0b99d589
LL
1215 int retval = 0;
1216 struct un_t *un = NULL;
a44b508a 1217 unsigned long flags;
0b99d589
LL
1218 uint old_flags = 0;
1219 int sleep_on_un_flags = 0;
1220
3c4019d3 1221 if (!tty || tty->magic != TTY_MAGIC || !file || !ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 1222 return -ENXIO;
0b99d589
LL
1223
1224 un = tty->driver_data;
50667c67 1225 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 1226 return -ENXIO;
0b99d589 1227
a44b508a 1228 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1229
1230 ch->ch_wopen++;
1231
1232 /* Loop forever */
1233 while (1) {
1234
1235 sleep_on_un_flags = 0;
1236
1237 /*
1238 * If board has failed somehow during our sleep, bail with error.
1239 */
1240 if (ch->ch_bd->state == BOARD_FAILED) {
1241 retval = -ENXIO;
1242 break;
1243 }
1244
1245 /* If tty was hung up, break out of loop and set error. */
1246 if (tty_hung_up_p(file)) {
1247 retval = -EAGAIN;
1248 break;
1249 }
1250
1251 /*
1252 * If either unit is in the middle of the fragile part of close,
1253 * we just cannot touch the channel safely.
1254 * Go back to sleep, knowing that when the channel can be
8b07d521 1255 * touched safely, the close routine will signal the
0b99d589
LL
1256 * ch_wait_flags to wake us back up.
1257 */
1258 if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_CLOSING)) {
1259
1260 /*
1261 * Our conditions to leave cleanly and happily:
1262 * 1) NONBLOCKING on the tty is set.
1263 * 2) CLOCAL is set.
1264 * 3) DCD (fake or real) is active.
1265 */
1266
50667c67 1267 if (file->f_flags & O_NONBLOCK)
0b99d589 1268 break;
0b99d589
LL
1269
1270 if (tty->flags & (1 << TTY_IO_ERROR)) {
1271 retval = -EIO;
1272 break;
1273 }
1274
f1e51745 1275 if (ch->ch_flags & CH_CD)
0b99d589 1276 break;
0b99d589 1277
f1e51745 1278 if (ch->ch_flags & CH_FCAR)
0b99d589 1279 break;
2000c581 1280 } else {
0b99d589
LL
1281 sleep_on_un_flags = 1;
1282 }
1283
1284 /*
1285 * If there is a signal pending, the user probably
1286 * interrupted (ctrl-c) us.
1287 * Leave loop with error set.
1288 */
1289 if (signal_pending(current)) {
0b99d589
LL
1290 retval = -ERESTARTSYS;
1291 break;
1292 }
1293
0b99d589
LL
1294 /*
1295 * Store the flags before we let go of channel lock
1296 */
1297 if (sleep_on_un_flags)
1298 old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
1299 else
1300 old_flags = ch->ch_flags;
1301
1302 /*
1303 * Let go of channel lock before calling schedule.
1304 * Our poller will get any FEP events and wake us up when DCD
1305 * eventually goes active.
1306 */
1307
a44b508a 1308 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 1309
0b99d589
LL
1310 /*
1311 * Wait for something in the flags to change from the current value.
1312 */
50667c67 1313 if (sleep_on_un_flags)
0b99d589
LL
1314 retval = wait_event_interruptible(un->un_flags_wait,
1315 (old_flags != (ch->ch_tun.un_flags | ch->ch_pun.un_flags)));
50667c67 1316 else
0b99d589
LL
1317 retval = wait_event_interruptible(ch->ch_flags_wait,
1318 (old_flags != ch->ch_flags));
0b99d589 1319
0b99d589
LL
1320 /*
1321 * We got woken up for some reason.
1322 * Before looping around, grab our channel lock.
1323 */
a44b508a 1324 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1325 }
1326
1327 ch->ch_wopen--;
1328
a44b508a 1329 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 1330
f1e51745 1331 if (retval)
8f90ef80 1332 return retval;
0b99d589 1333
8f90ef80 1334 return 0;
0b99d589
LL
1335}
1336
1337
1338/*
1339 * dgnc_tty_hangup()
1340 *
1341 * Hangup the port. Like a close, but don't wait for output to drain.
8b07d521 1342 */
0b99d589
LL
1343static void dgnc_tty_hangup(struct tty_struct *tty)
1344{
1345 struct un_t *un;
1346
1347 if (!tty || tty->magic != TTY_MAGIC)
1348 return;
1349
1350 un = tty->driver_data;
1351 if (!un || un->magic != DGNC_UNIT_MAGIC)
1352 return;
1353
0b99d589
LL
1354 /* flush the transmit queues */
1355 dgnc_tty_flush_buffer(tty);
1356
0b99d589
LL
1357}
1358
1359
1360/*
1361 * dgnc_tty_close()
1362 *
1363 */
1364static void dgnc_tty_close(struct tty_struct *tty, struct file *file)
1365{
1366 struct ktermios *ts;
03425f55 1367 struct dgnc_board *bd;
0b99d589
LL
1368 struct channel_t *ch;
1369 struct un_t *un;
a44b508a 1370 unsigned long flags;
0b99d589
LL
1371 int rc = 0;
1372
1373 if (!tty || tty->magic != TTY_MAGIC)
1374 return;
1375
1376 un = tty->driver_data;
1377 if (!un || un->magic != DGNC_UNIT_MAGIC)
1378 return;
1379
1380 ch = un->un_ch;
1381 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1382 return;
1383
1384 bd = ch->ch_bd;
1385 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1386 return;
1387
5857a0b5 1388 ts = &tty->termios;
0b99d589 1389
a44b508a 1390 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1391
1392 /*
1393 * Determine if this is the last close or not - and if we agree about
1394 * which type of close it is with the Line Discipline
1395 */
1396 if ((tty->count == 1) && (un->un_open_count != 1)) {
1397 /*
1398 * Uh, oh. tty->count is 1, which means that the tty
1399 * structure will be freed. un_open_count should always
1400 * be one in these conditions. If it's greater than
1401 * one, we've got real problems, since it means the
1402 * serial port won't be shutdown.
1403 */
1f26adc9
RD
1404 dev_dbg(tty->dev,
1405 "tty->count is 1, un open count is %d\n",
1406 un->un_open_count);
0b99d589 1407 un->un_open_count = 1;
8b07d521 1408 }
0b99d589 1409
3098e514
DY
1410 if (un->un_open_count)
1411 un->un_open_count--;
1412 else
1f26adc9
RD
1413 dev_dbg(tty->dev,
1414 "bad serial port open count of %d\n",
1415 un->un_open_count);
0b99d589
LL
1416
1417 ch->ch_open_count--;
1418
1419 if (ch->ch_open_count && un->un_open_count) {
a44b508a 1420 spin_unlock_irqrestore(&ch->ch_lock, flags);
90d2a471
LL
1421 return;
1422 }
0b99d589
LL
1423
1424 /* OK, its the last close on the unit */
0b99d589
LL
1425 un->un_flags |= UN_CLOSING;
1426
1427 tty->closing = 1;
1428
1429
1430 /*
1431 * Only officially close channel if count is 0 and
90d2a471 1432 * DIGI_PRINTER bit is not set.
0b99d589
LL
1433 */
1434 if ((ch->ch_open_count == 0) && !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
1435
1436 ch->ch_flags &= ~(CH_STOPI | CH_FORCED_STOPI);
1437
1438 /*
1439 * turn off print device when closing print device.
1440 */
9cdf838b 1441 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
0b99d589
LL
1442 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1443 (int) ch->ch_digi.digi_offlen);
1444 ch->ch_flags &= ~CH_PRON;
1445 }
1446
a44b508a 1447 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1448 /* wait for output to drain */
1449 /* This will also return if we take an interrupt */
1450
0b99d589
LL
1451 rc = bd->bd_ops->drain(tty, 0);
1452
0b99d589
LL
1453 dgnc_tty_flush_buffer(tty);
1454 tty_ldisc_flush(tty);
1455
a44b508a 1456 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1457
1458 tty->closing = 0;
1459
1460 /*
1461 * If we have HUPCL set, lower DTR and RTS
1462 */
1463 if (ch->ch_c_cflag & HUPCL) {
0b99d589
LL
1464
1465 /* Drop RTS/DTR */
1466 ch->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
1467 bd->bd_ops->assert_modem_signals(ch);
1468
1469 /*
8b07d521 1470 * Go to sleep to ensure RTS/DTR
0b99d589
LL
1471 * have been dropped for modems to see it.
1472 */
1473 if (ch->ch_close_delay) {
a44b508a
RD
1474 spin_unlock_irqrestore(&ch->ch_lock,
1475 flags);
0b99d589 1476 dgnc_ms_sleep(ch->ch_close_delay);
a44b508a 1477 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1478 }
1479 }
1480
1481 ch->ch_old_baud = 0;
1482
1483 /* Turn off UART interrupts for this port */
1484 ch->ch_bd->bd_ops->uart_off(ch);
2000c581 1485 } else {
0b99d589
LL
1486 /*
1487 * turn off print device when closing print device.
1488 */
9cdf838b 1489 if ((un->un_type == DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
0b99d589
LL
1490 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1491 (int) ch->ch_digi.digi_offlen);
1492 ch->ch_flags &= ~CH_PRON;
1493 }
1494 }
1495
1496 un->un_tty = NULL;
1497 un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
1498
0b99d589
LL
1499 wake_up_interruptible(&ch->ch_flags_wait);
1500 wake_up_interruptible(&un->un_flags_wait);
1501
a44b508a 1502 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1503}
1504
1505
1506/*
1507 * dgnc_tty_chars_in_buffer()
1508 *
1509 * Return number of characters that have not been transmitted yet.
1510 *
1511 * This routine is used by the line discipline to determine if there
1512 * is data waiting to be transmitted/drained/flushed or not.
1513 */
1514static int dgnc_tty_chars_in_buffer(struct tty_struct *tty)
1515{
1516 struct channel_t *ch = NULL;
1517 struct un_t *un = NULL;
1518 ushort thead;
1519 ushort ttail;
1520 uint tmask;
1521 uint chars = 0;
a44b508a 1522 unsigned long flags;
0b99d589
LL
1523
1524 if (tty == NULL)
8f90ef80 1525 return 0;
0b99d589
LL
1526
1527 un = tty->driver_data;
1528 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 1529 return 0;
0b99d589
LL
1530
1531 ch = un->un_ch;
1532 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 1533 return 0;
0b99d589 1534
a44b508a 1535 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1536
1537 tmask = WQUEUEMASK;
1538 thead = ch->ch_w_head & tmask;
1539 ttail = ch->ch_w_tail & tmask;
1540
a44b508a 1541 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1542
1543 if (ttail == thead) {
1544 chars = 0;
1545 } else {
1546 if (thead >= ttail)
1547 chars = thead - ttail;
1548 else
1549 chars = thead - ttail + WQUEUESIZE;
1550 }
1551
8f90ef80 1552 return chars;
0b99d589
LL
1553}
1554
1555
8b07d521 1556/*
0b99d589
LL
1557 * dgnc_maxcps_room
1558 *
1559 * Reduces bytes_available to the max number of characters
1560 * that can be sent currently given the maxcps value, and
1561 * returns the new bytes_available. This only affects printer
1562 * output.
8b07d521 1563 */
0b99d589
LL
1564static int dgnc_maxcps_room(struct tty_struct *tty, int bytes_available)
1565{
1566 struct channel_t *ch = NULL;
1567 struct un_t *un = NULL;
1568
1569 if (!tty)
8f90ef80 1570 return bytes_available;
0b99d589
LL
1571
1572 un = tty->driver_data;
1573 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 1574 return bytes_available;
0b99d589
LL
1575
1576 ch = un->un_ch;
1577 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 1578 return bytes_available;
0b99d589
LL
1579
1580 /*
1581 * If its not the Transparent print device, return
1582 * the full data amount.
1583 */
1584 if (un->un_type != DGNC_PRINT)
8f90ef80 1585 return bytes_available;
0b99d589 1586
9cdf838b 1587 if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
0b99d589
LL
1588 int cps_limit = 0;
1589 unsigned long current_time = jiffies;
1590 unsigned long buffer_time = current_time +
1591 (HZ * ch->ch_digi.digi_bufsize) / ch->ch_digi.digi_maxcps;
1592
1593 if (ch->ch_cpstime < current_time) {
1594 /* buffer is empty */
90d2a471 1595 ch->ch_cpstime = current_time; /* reset ch_cpstime */
0b99d589 1596 cps_limit = ch->ch_digi.digi_bufsize;
2000c581 1597 } else if (ch->ch_cpstime < buffer_time) {
0b99d589
LL
1598 /* still room in the buffer */
1599 cps_limit = ((buffer_time - ch->ch_cpstime) * ch->ch_digi.digi_maxcps) / HZ;
2000c581 1600 } else {
0b99d589 1601 /* no room in the buffer */
8b07d521 1602 cps_limit = 0;
0b99d589
LL
1603 }
1604
1605 bytes_available = min(cps_limit, bytes_available);
1606 }
1607
8f90ef80 1608 return bytes_available;
0b99d589
LL
1609}
1610
1611
1612/*
1613 * dgnc_tty_write_room()
1614 *
1615 * Return space available in Tx buffer
8b07d521 1616 */
0b99d589
LL
1617static int dgnc_tty_write_room(struct tty_struct *tty)
1618{
1619 struct channel_t *ch = NULL;
1620 struct un_t *un = NULL;
1621 ushort head;
1622 ushort tail;
1623 ushort tmask;
1624 int ret = 0;
a44b508a 1625 unsigned long flags;
0b99d589
LL
1626
1627 if (tty == NULL || dgnc_TmpWriteBuf == NULL)
8f90ef80 1628 return 0;
0b99d589
LL
1629
1630 un = tty->driver_data;
1631 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 1632 return 0;
0b99d589
LL
1633
1634 ch = un->un_ch;
1635 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 1636 return 0;
0b99d589 1637
a44b508a 1638 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1639
1640 tmask = WQUEUEMASK;
1641 head = (ch->ch_w_head) & tmask;
1642 tail = (ch->ch_w_tail) & tmask;
1643
f7c851d4
CP
1644 ret = tail - head - 1;
1645 if (ret < 0)
0b99d589
LL
1646 ret += WQUEUESIZE;
1647
1648 /* Limit printer to maxcps */
1649 ret = dgnc_maxcps_room(tty, ret);
1650
1651 /*
8b07d521 1652 * If we are printer device, leave space for
0b99d589
LL
1653 * possibly both the on and off strings.
1654 */
1655 if (un->un_type == DGNC_PRINT) {
1656 if (!(ch->ch_flags & CH_PRON))
1657 ret -= ch->ch_digi.digi_onlen;
1658 ret -= ch->ch_digi.digi_offlen;
2000c581 1659 } else {
0b99d589
LL
1660 if (ch->ch_flags & CH_PRON)
1661 ret -= ch->ch_digi.digi_offlen;
1662 }
1663
1664 if (ret < 0)
1665 ret = 0;
1666
a44b508a 1667 spin_unlock_irqrestore(&ch->ch_lock, flags);
8b07d521 1668
8f90ef80 1669 return ret;
0b99d589
LL
1670}
1671
1672
1673/*
1674 * dgnc_tty_put_char()
1675 *
1676 * Put a character into ch->ch_buf
8b07d521 1677 *
0b99d589
LL
1678 * - used by the line discipline for OPOST processing
1679 */
1680static int dgnc_tty_put_char(struct tty_struct *tty, unsigned char c)
1681{
1682 /*
1683 * Simply call tty_write.
1684 */
0b99d589
LL
1685 dgnc_tty_write(tty, &c, 1);
1686 return 1;
1687}
1688
1689
1690/*
1691 * dgnc_tty_write()
1692 *
1693 * Take data from the user or kernel and send it out to the FEP.
1694 * In here exists all the Transparent Print magic as well.
1695 */
1696static int dgnc_tty_write(struct tty_struct *tty,
1697 const unsigned char *buf, int count)
1698{
1699 struct channel_t *ch = NULL;
1700 struct un_t *un = NULL;
1701 int bufcount = 0, n = 0;
1702 int orig_count = 0;
a44b508a 1703 unsigned long flags;
0b99d589
LL
1704 ushort head;
1705 ushort tail;
1706 ushort tmask;
1707 uint remain;
1708 int from_user = 0;
1709
1710 if (tty == NULL || dgnc_TmpWriteBuf == NULL)
8f90ef80 1711 return 0;
0b99d589
LL
1712
1713 un = tty->driver_data;
1714 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 1715 return 0;
0b99d589
LL
1716
1717 ch = un->un_ch;
1718 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 1719 return 0;
0b99d589
LL
1720
1721 if (!count)
8f90ef80 1722 return 0;
0b99d589 1723
0b99d589
LL
1724 /*
1725 * Store original amount of characters passed in.
1726 * This helps to figure out if we should ask the FEP
1727 * to send us an event when it has more space available.
1728 */
1729 orig_count = count;
1730
a44b508a 1731 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1732
1733 /* Get our space available for the channel from the board */
1734 tmask = WQUEUEMASK;
1735 head = (ch->ch_w_head) & tmask;
1736 tail = (ch->ch_w_tail) & tmask;
1737
f7c851d4
CP
1738 bufcount = tail - head - 1;
1739 if (bufcount < 0)
0b99d589
LL
1740 bufcount += WQUEUESIZE;
1741
0b99d589
LL
1742 /*
1743 * Limit printer output to maxcps overall, with bursts allowed
1744 * up to bufsize characters.
1745 */
1746 bufcount = dgnc_maxcps_room(tty, bufcount);
1747
1748 /*
1749 * Take minimum of what the user wants to send, and the
1750 * space available in the FEP buffer.
1751 */
1752 count = min(count, bufcount);
1753
1754 /*
1755 * Bail if no space left.
1756 */
c84a083b
QL
1757 if (count <= 0)
1758 goto exit_retry;
0b99d589
LL
1759
1760 /*
1761 * Output the printer ON string, if we are in terminal mode, but
1762 * need to be in printer mode.
1763 */
1764 if ((un->un_type == DGNC_PRINT) && !(ch->ch_flags & CH_PRON)) {
1765 dgnc_wmove(ch, ch->ch_digi.digi_onstr,
1766 (int) ch->ch_digi.digi_onlen);
1767 head = (ch->ch_w_head) & tmask;
1768 ch->ch_flags |= CH_PRON;
1769 }
1770
1771 /*
1772 * On the other hand, output the printer OFF string, if we are
1773 * currently in printer mode, but need to output to the terminal.
1774 */
1775 if ((un->un_type != DGNC_PRINT) && (ch->ch_flags & CH_PRON)) {
1776 dgnc_wmove(ch, ch->ch_digi.digi_offstr,
1777 (int) ch->ch_digi.digi_offlen);
1778 head = (ch->ch_w_head) & tmask;
1779 ch->ch_flags &= ~CH_PRON;
1780 }
1781
1782 /*
1783 * If there is nothing left to copy, or I can't handle any more data, leave.
8b07d521 1784 */
c84a083b
QL
1785 if (count <= 0)
1786 goto exit_retry;
0b99d589
LL
1787
1788 if (from_user) {
1789
1790 count = min(count, WRITEBUFLEN);
1791
a44b508a 1792 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1793
1794 /*
1795 * If data is coming from user space, copy it into a temporary
1796 * buffer so we don't get swapped out while doing the copy to
1797 * the board.
1798 */
1799 /* we're allowed to block if it's from_user */
50667c67 1800 if (down_interruptible(&dgnc_TmpWriteSem))
8f90ef80 1801 return -EINTR;
0b99d589
LL
1802
1803 /*
1804 * copy_from_user() returns the number
1805 * of bytes that could *NOT* be copied.
1806 */
446393e9 1807 count -= copy_from_user(dgnc_TmpWriteBuf, (const unsigned char __user *) buf, count);
0b99d589
LL
1808
1809 if (!count) {
1810 up(&dgnc_TmpWriteSem);
8f90ef80 1811 return -EFAULT;
0b99d589
LL
1812 }
1813
a44b508a 1814 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1815
1816 buf = dgnc_TmpWriteBuf;
1817
1818 }
1819
1820 n = count;
1821
1822 /*
1823 * If the write wraps over the top of the circular buffer,
1824 * move the portion up to the wrap point, and reset the
1825 * pointers to the bottom.
1826 */
1827 remain = WQUEUESIZE - head;
1828
1829 if (n >= remain) {
1830 n -= remain;
1831 memcpy(ch->ch_wqueue + head, buf, remain);
0b99d589
LL
1832 head = 0;
1833 buf += remain;
1834 }
1835
1836 if (n > 0) {
1837 /*
1838 * Move rest of data.
1839 */
1840 remain = n;
1841 memcpy(ch->ch_wqueue + head, buf, remain);
0b99d589
LL
1842 head += remain;
1843 }
1844
1845 if (count) {
1846 head &= tmask;
1847 ch->ch_w_head = head;
1848 }
1849
0b99d589
LL
1850 /* Update printer buffer empty time. */
1851 if ((un->un_type == DGNC_PRINT) && (ch->ch_digi.digi_maxcps > 0)
1852 && (ch->ch_digi.digi_bufsize > 0)) {
90d2a471 1853 ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
0b99d589
LL
1854 }
1855
1856 if (from_user) {
a44b508a 1857 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1858 up(&dgnc_TmpWriteSem);
1859 } else {
a44b508a 1860 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1861 }
1862
0b99d589
LL
1863 if (count) {
1864 /*
1865 * Channel lock is grabbed and then released
1866 * inside this routine.
1867 */
1868 ch->ch_bd->bd_ops->copy_data_from_queue_to_uart(ch);
1869 }
1870
8f90ef80 1871 return count;
c84a083b
QL
1872
1873exit_retry:
1874
1875 spin_unlock_irqrestore(&ch->ch_lock, flags);
1876 return 0;
0b99d589
LL
1877}
1878
1879
1880/*
1881 * Return modem signals to ld.
1882 */
b74c7461 1883
0b99d589 1884static int dgnc_tty_tiocmget(struct tty_struct *tty)
0b99d589
LL
1885{
1886 struct channel_t *ch;
1887 struct un_t *un;
1888 int result = -EIO;
446393e9 1889 unsigned char mstat = 0;
a44b508a 1890 unsigned long flags;
0b99d589
LL
1891
1892 if (!tty || tty->magic != TTY_MAGIC)
1893 return result;
1894
1895 un = tty->driver_data;
1896 if (!un || un->magic != DGNC_UNIT_MAGIC)
1897 return result;
1898
1899 ch = un->un_ch;
1900 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1901 return result;
1902
a44b508a 1903 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
1904
1905 mstat = (ch->ch_mostat | ch->ch_mistat);
1906
a44b508a 1907 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
1908
1909 result = 0;
1910
1911 if (mstat & UART_MCR_DTR)
1912 result |= TIOCM_DTR;
1913 if (mstat & UART_MCR_RTS)
1914 result |= TIOCM_RTS;
1915 if (mstat & UART_MSR_CTS)
1916 result |= TIOCM_CTS;
1917 if (mstat & UART_MSR_DSR)
1918 result |= TIOCM_DSR;
1919 if (mstat & UART_MSR_RI)
1920 result |= TIOCM_RI;
1921 if (mstat & UART_MSR_DCD)
1922 result |= TIOCM_CD;
1923
0b99d589
LL
1924 return result;
1925}
1926
1927
1928/*
1929 * dgnc_tty_tiocmset()
1930 *
1931 * Set modem signals, called by ld.
1932 */
b74c7461 1933
0b99d589 1934static int dgnc_tty_tiocmset(struct tty_struct *tty,
90d2a471 1935 unsigned int set, unsigned int clear)
0b99d589 1936{
03425f55 1937 struct dgnc_board *bd;
0b99d589
LL
1938 struct channel_t *ch;
1939 struct un_t *un;
1940 int ret = -EIO;
a44b508a 1941 unsigned long flags;
0b99d589
LL
1942
1943 if (!tty || tty->magic != TTY_MAGIC)
1944 return ret;
1945
1946 un = tty->driver_data;
1947 if (!un || un->magic != DGNC_UNIT_MAGIC)
1948 return ret;
1949
1950 ch = un->un_ch;
1951 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
1952 return ret;
1953
1954 bd = ch->ch_bd;
1955 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
1956 return ret;
1957
a44b508a 1958 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 1959
50667c67 1960 if (set & TIOCM_RTS)
0b99d589 1961 ch->ch_mostat |= UART_MCR_RTS;
0b99d589 1962
50667c67 1963 if (set & TIOCM_DTR)
0b99d589 1964 ch->ch_mostat |= UART_MCR_DTR;
0b99d589 1965
50667c67 1966 if (clear & TIOCM_RTS)
0b99d589 1967 ch->ch_mostat &= ~(UART_MCR_RTS);
0b99d589 1968
50667c67 1969 if (clear & TIOCM_DTR)
0b99d589 1970 ch->ch_mostat &= ~(UART_MCR_DTR);
0b99d589
LL
1971
1972 ch->ch_bd->bd_ops->assert_modem_signals(ch);
1973
a44b508a 1974 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 1975
8f90ef80 1976 return 0;
0b99d589
LL
1977}
1978
1979
1980/*
1981 * dgnc_tty_send_break()
1982 *
1983 * Send a Break, called by ld.
1984 */
1985static int dgnc_tty_send_break(struct tty_struct *tty, int msec)
1986{
03425f55 1987 struct dgnc_board *bd;
0b99d589
LL
1988 struct channel_t *ch;
1989 struct un_t *un;
1990 int ret = -EIO;
a44b508a 1991 unsigned long flags;
0b99d589
LL
1992
1993 if (!tty || tty->magic != TTY_MAGIC)
1994 return ret;
1995
1996 un = tty->driver_data;
1997 if (!un || un->magic != DGNC_UNIT_MAGIC)
1998 return ret;
1999
2000 ch = un->un_ch;
2001 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2002 return ret;
2003
2004 bd = ch->ch_bd;
2005 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2006 return ret;
2007
2008 switch (msec) {
2009 case -1:
2010 msec = 0xFFFF;
2011 break;
2012 case 0:
2013 msec = 0;
2014 break;
2015 default:
2016 break;
2017 }
2018
a44b508a 2019 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2020
2021 ch->ch_bd->bd_ops->send_break(ch, msec);
2022
a44b508a 2023 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2024
8f90ef80 2025 return 0;
0b99d589
LL
2026
2027}
2028
2029
2030/*
2031 * dgnc_tty_wait_until_sent()
2032 *
2033 * wait until data has been transmitted, called by ld.
2034 */
2035static void dgnc_tty_wait_until_sent(struct tty_struct *tty, int timeout)
2036{
03425f55 2037 struct dgnc_board *bd;
0b99d589
LL
2038 struct channel_t *ch;
2039 struct un_t *un;
2040 int rc;
2041
2042 if (!tty || tty->magic != TTY_MAGIC)
2043 return;
2044
2045 un = tty->driver_data;
2046 if (!un || un->magic != DGNC_UNIT_MAGIC)
2047 return;
2048
2049 ch = un->un_ch;
2050 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2051 return;
2052
2053 bd = ch->ch_bd;
2054 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2055 return;
2056
2057 rc = bd->bd_ops->drain(tty, 0);
8b07d521 2058}
0b99d589
LL
2059
2060
2061/*
2062 * dgnc_send_xchar()
2063 *
2064 * send a high priority character, called by ld.
2065 */
2066static void dgnc_tty_send_xchar(struct tty_struct *tty, char c)
2067{
03425f55 2068 struct dgnc_board *bd;
0b99d589
LL
2069 struct channel_t *ch;
2070 struct un_t *un;
a44b508a 2071 unsigned long flags;
0b99d589
LL
2072
2073 if (!tty || tty->magic != TTY_MAGIC)
2074 return;
2075
2076 un = tty->driver_data;
2077 if (!un || un->magic != DGNC_UNIT_MAGIC)
2078 return;
2079
2080 ch = un->un_ch;
2081 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2082 return;
2083
2084 bd = ch->ch_bd;
2085 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2086 return;
2087
f3dadd29 2088 dev_dbg(tty->dev, "dgnc_tty_send_xchar start\n");
0b99d589 2089
a44b508a 2090 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 2091 bd->bd_ops->send_immediate_char(ch, c);
a44b508a 2092 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2093
f3dadd29 2094 dev_dbg(tty->dev, "dgnc_tty_send_xchar finish\n");
8b07d521 2095}
0b99d589
LL
2096
2097
2098
2099
2100/*
2101 * Return modem signals to ld.
2102 */
2103static inline int dgnc_get_mstat(struct channel_t *ch)
2104{
2105 unsigned char mstat;
2106 int result = -EIO;
a44b508a 2107 unsigned long flags;
0b99d589 2108
0b99d589 2109 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 2110 return -ENXIO;
0b99d589 2111
a44b508a 2112 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2113
2114 mstat = (ch->ch_mostat | ch->ch_mistat);
2115
a44b508a 2116 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2117
2118 result = 0;
2119
2120 if (mstat & UART_MCR_DTR)
2121 result |= TIOCM_DTR;
2122 if (mstat & UART_MCR_RTS)
2123 result |= TIOCM_RTS;
2124 if (mstat & UART_MSR_CTS)
2125 result |= TIOCM_CTS;
2126 if (mstat & UART_MSR_DSR)
2127 result |= TIOCM_DSR;
2128 if (mstat & UART_MSR_RI)
2129 result |= TIOCM_RI;
2130 if (mstat & UART_MSR_DCD)
2131 result |= TIOCM_CD;
2132
8f90ef80 2133 return result;
0b99d589
LL
2134}
2135
2136
2137
2138/*
2139 * Return modem signals to ld.
2140 */
2141static int dgnc_get_modem_info(struct channel_t *ch, unsigned int __user *value)
2142{
2143 int result;
0b99d589 2144
0b99d589 2145 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 2146 return -ENXIO;
0b99d589
LL
2147
2148 result = dgnc_get_mstat(ch);
2149
2150 if (result < 0)
8f90ef80 2151 return -ENXIO;
0b99d589 2152
3dfe7557 2153 return put_user(result, value);
0b99d589
LL
2154}
2155
2156
2157/*
2158 * dgnc_set_modem_info()
2159 *
2160 * Set modem signals, called by ld.
2161 */
2162static int dgnc_set_modem_info(struct tty_struct *tty, unsigned int command, unsigned int __user *value)
2163{
03425f55 2164 struct dgnc_board *bd;
0b99d589
LL
2165 struct channel_t *ch;
2166 struct un_t *un;
2167 int ret = -ENXIO;
2168 unsigned int arg = 0;
a44b508a 2169 unsigned long flags;
0b99d589
LL
2170
2171 if (!tty || tty->magic != TTY_MAGIC)
2172 return ret;
2173
2174 un = tty->driver_data;
2175 if (!un || un->magic != DGNC_UNIT_MAGIC)
2176 return ret;
2177
2178 ch = un->un_ch;
2179 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2180 return ret;
2181
2182 bd = ch->ch_bd;
2183 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2184 return ret;
2185
0b99d589
LL
2186 ret = get_user(arg, value);
2187 if (ret)
8f90ef80 2188 return ret;
0b99d589
LL
2189
2190 switch (command) {
2191 case TIOCMBIS:
50667c67 2192 if (arg & TIOCM_RTS)
0b99d589 2193 ch->ch_mostat |= UART_MCR_RTS;
0b99d589 2194
50667c67 2195 if (arg & TIOCM_DTR)
0b99d589 2196 ch->ch_mostat |= UART_MCR_DTR;
0b99d589
LL
2197
2198 break;
2199
2200 case TIOCMBIC:
50667c67 2201 if (arg & TIOCM_RTS)
0b99d589 2202 ch->ch_mostat &= ~(UART_MCR_RTS);
0b99d589 2203
50667c67 2204 if (arg & TIOCM_DTR)
0b99d589 2205 ch->ch_mostat &= ~(UART_MCR_DTR);
0b99d589
LL
2206
2207 break;
2208
90d2a471 2209 case TIOCMSET:
0b99d589 2210
50667c67 2211 if (arg & TIOCM_RTS)
0b99d589 2212 ch->ch_mostat |= UART_MCR_RTS;
50667c67 2213 else
0b99d589 2214 ch->ch_mostat &= ~(UART_MCR_RTS);
0b99d589 2215
50667c67 2216 if (arg & TIOCM_DTR)
0b99d589 2217 ch->ch_mostat |= UART_MCR_DTR;
50667c67 2218 else
0b99d589 2219 ch->ch_mostat &= ~(UART_MCR_DTR);
0b99d589
LL
2220
2221 break;
2222
2223 default:
8f90ef80 2224 return -EINVAL;
0b99d589
LL
2225 }
2226
a44b508a 2227 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2228
2229 ch->ch_bd->bd_ops->assert_modem_signals(ch);
2230
a44b508a 2231 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2232
8f90ef80 2233 return 0;
0b99d589
LL
2234}
2235
2236
2237/*
8b07d521 2238 * dgnc_tty_digigeta()
0b99d589
LL
2239 *
2240 * Ioctl to get the information for ditty.
2241 *
2242 *
2243 *
2244 */
2245static int dgnc_tty_digigeta(struct tty_struct *tty, struct digi_t __user *retinfo)
2246{
2247 struct channel_t *ch;
2248 struct un_t *un;
2249 struct digi_t tmp;
a44b508a 2250 unsigned long flags;
0b99d589
LL
2251
2252 if (!retinfo)
8f90ef80 2253 return -EFAULT;
0b99d589
LL
2254
2255 if (!tty || tty->magic != TTY_MAGIC)
8f90ef80 2256 return -EFAULT;
0b99d589
LL
2257
2258 un = tty->driver_data;
2259 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 2260 return -EFAULT;
0b99d589
LL
2261
2262 ch = un->un_ch;
2263 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 2264 return -EFAULT;
0b99d589
LL
2265
2266 memset(&tmp, 0, sizeof(tmp));
2267
a44b508a 2268 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 2269 memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
a44b508a 2270 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2271
2272 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
8f90ef80 2273 return -EFAULT;
0b99d589 2274
8f90ef80 2275 return 0;
0b99d589
LL
2276}
2277
2278
2279/*
8b07d521 2280 * dgnc_tty_digiseta()
0b99d589
LL
2281 *
2282 * Ioctl to set the information for ditty.
2283 *
2284 *
2285 *
2286 */
2287static int dgnc_tty_digiseta(struct tty_struct *tty, struct digi_t __user *new_info)
2288{
03425f55 2289 struct dgnc_board *bd;
0b99d589
LL
2290 struct channel_t *ch;
2291 struct un_t *un;
2292 struct digi_t new_digi;
a44b508a 2293 unsigned long flags;
0b99d589 2294
0b99d589 2295 if (!tty || tty->magic != TTY_MAGIC)
8f90ef80 2296 return -EFAULT;
0b99d589
LL
2297
2298 un = tty->driver_data;
2299 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 2300 return -EFAULT;
0b99d589
LL
2301
2302 ch = un->un_ch;
2303 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 2304 return -EFAULT;
0b99d589
LL
2305
2306 bd = ch->ch_bd;
2307 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
8f90ef80 2308 return -EFAULT;
0b99d589 2309
f1e51745 2310 if (copy_from_user(&new_digi, new_info, sizeof(new_digi)))
8f90ef80 2311 return -EFAULT;
0b99d589 2312
a44b508a 2313 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2314
2315 /*
2316 * Handle transistions to and from RTS Toggle.
2317 */
2318 if (!(ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && (new_digi.digi_flags & DIGI_RTS_TOGGLE))
2319 ch->ch_mostat &= ~(UART_MCR_RTS);
2320 if ((ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE) && !(new_digi.digi_flags & DIGI_RTS_TOGGLE))
2321 ch->ch_mostat |= (UART_MCR_RTS);
2322
2323 /*
2324 * Handle transistions to and from DTR Toggle.
2325 */
2326 if (!(ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && (new_digi.digi_flags & DIGI_DTR_TOGGLE))
2327 ch->ch_mostat &= ~(UART_MCR_DTR);
2328 if ((ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE) && !(new_digi.digi_flags & DIGI_DTR_TOGGLE))
2329 ch->ch_mostat |= (UART_MCR_DTR);
2330
a07bf39a 2331 memcpy(&ch->ch_digi, &new_digi, sizeof(new_digi));
0b99d589 2332
8b07d521 2333 if (ch->ch_digi.digi_maxcps < 1)
0b99d589
LL
2334 ch->ch_digi.digi_maxcps = 1;
2335
8b07d521 2336 if (ch->ch_digi.digi_maxcps > 10000)
0b99d589
LL
2337 ch->ch_digi.digi_maxcps = 10000;
2338
2339 if (ch->ch_digi.digi_bufsize < 10)
2340 ch->ch_digi.digi_bufsize = 10;
2341
2342 if (ch->ch_digi.digi_maxchar < 1)
2343 ch->ch_digi.digi_maxchar = 1;
2344
2345 if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
2346 ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
2347
2348 if (ch->ch_digi.digi_onlen > DIGI_PLEN)
2349 ch->ch_digi.digi_onlen = DIGI_PLEN;
2350
2351 if (ch->ch_digi.digi_offlen > DIGI_PLEN)
2352 ch->ch_digi.digi_offlen = DIGI_PLEN;
2353
2354 ch->ch_bd->bd_ops->param(tty);
2355
a44b508a 2356 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2357
8f90ef80 2358 return 0;
0b99d589
LL
2359}
2360
2361
2362/*
2363 * dgnc_set_termios()
2364 */
2365static void dgnc_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2366{
03425f55 2367 struct dgnc_board *bd;
0b99d589
LL
2368 struct channel_t *ch;
2369 struct un_t *un;
a44b508a 2370 unsigned long flags;
0b99d589
LL
2371
2372 if (!tty || tty->magic != TTY_MAGIC)
2373 return;
2374
2375 un = tty->driver_data;
2376 if (!un || un->magic != DGNC_UNIT_MAGIC)
2377 return;
2378
2379 ch = un->un_ch;
2380 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2381 return;
2382
2383 bd = ch->ch_bd;
2384 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2385 return;
2386
a44b508a 2387 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 2388
22e3de76
LL
2389 ch->ch_c_cflag = tty->termios.c_cflag;
2390 ch->ch_c_iflag = tty->termios.c_iflag;
2391 ch->ch_c_oflag = tty->termios.c_oflag;
2392 ch->ch_c_lflag = tty->termios.c_lflag;
2393 ch->ch_startc = tty->termios.c_cc[VSTART];
2394 ch->ch_stopc = tty->termios.c_cc[VSTOP];
0b99d589
LL
2395
2396 ch->ch_bd->bd_ops->param(tty);
2397 dgnc_carrier(ch);
2398
a44b508a 2399 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2400}
2401
2402
2403static void dgnc_tty_throttle(struct tty_struct *tty)
2404{
2405 struct channel_t *ch;
2406 struct un_t *un;
a44b508a 2407 unsigned long flags;
0b99d589
LL
2408
2409 if (!tty || tty->magic != TTY_MAGIC)
2410 return;
2411
2412 un = tty->driver_data;
2413 if (!un || un->magic != DGNC_UNIT_MAGIC)
2414 return;
8b07d521 2415
90d2a471
LL
2416 ch = un->un_ch;
2417 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2418 return;
0b99d589 2419
a44b508a 2420 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2421
2422 ch->ch_flags |= (CH_FORCED_STOPI);
2423
a44b508a 2424 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2425}
2426
2427
2428static void dgnc_tty_unthrottle(struct tty_struct *tty)
2429{
2430 struct channel_t *ch;
2431 struct un_t *un;
a44b508a 2432 unsigned long flags;
0b99d589
LL
2433
2434 if (!tty || tty->magic != TTY_MAGIC)
2435 return;
2436
2437 un = tty->driver_data;
2438 if (!un || un->magic != DGNC_UNIT_MAGIC)
2439 return;
8b07d521 2440
90d2a471
LL
2441 ch = un->un_ch;
2442 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2443 return;
0b99d589 2444
a44b508a 2445 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2446
2447 ch->ch_flags &= ~(CH_FORCED_STOPI);
2448
a44b508a 2449 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2450}
2451
2452
2453static void dgnc_tty_start(struct tty_struct *tty)
2454{
03425f55 2455 struct dgnc_board *bd;
0b99d589
LL
2456 struct channel_t *ch;
2457 struct un_t *un;
a44b508a 2458 unsigned long flags;
0b99d589
LL
2459
2460 if (!tty || tty->magic != TTY_MAGIC)
2461 return;
2462
2463 un = tty->driver_data;
2464 if (!un || un->magic != DGNC_UNIT_MAGIC)
2465 return;
8b07d521 2466
90d2a471
LL
2467 ch = un->un_ch;
2468 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2469 return;
0b99d589
LL
2470
2471 bd = ch->ch_bd;
2472 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2473 return;
2474
a44b508a 2475 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2476
2477 ch->ch_flags &= ~(CH_FORCED_STOP);
2478
a44b508a 2479 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2480}
2481
2482
2483static void dgnc_tty_stop(struct tty_struct *tty)
2484{
03425f55 2485 struct dgnc_board *bd;
0b99d589
LL
2486 struct channel_t *ch;
2487 struct un_t *un;
a44b508a 2488 unsigned long flags;
0b99d589
LL
2489
2490 if (!tty || tty->magic != TTY_MAGIC)
2491 return;
2492
2493 un = tty->driver_data;
2494 if (!un || un->magic != DGNC_UNIT_MAGIC)
2495 return;
8b07d521 2496
90d2a471
LL
2497 ch = un->un_ch;
2498 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2499 return;
0b99d589
LL
2500
2501 bd = ch->ch_bd;
2502 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2503 return;
2504
a44b508a 2505 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2506
2507 ch->ch_flags |= (CH_FORCED_STOP);
2508
a44b508a 2509 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2510}
2511
2512
8b07d521 2513/*
0b99d589
LL
2514 * dgnc_tty_flush_chars()
2515 *
2516 * Flush the cook buffer
2517 *
2518 * Note to self, and any other poor souls who venture here:
2519 *
2520 * flush in this case DOES NOT mean dispose of the data.
2521 * instead, it means "stop buffering and send it if you
2522 * haven't already." Just guess how I figured that out... SRW 2-Jun-98
2523 *
2524 * It is also always called in interrupt context - JAR 8-Sept-99
2525 */
2526static void dgnc_tty_flush_chars(struct tty_struct *tty)
2527{
03425f55 2528 struct dgnc_board *bd;
0b99d589
LL
2529 struct channel_t *ch;
2530 struct un_t *un;
a44b508a 2531 unsigned long flags;
0b99d589
LL
2532
2533 if (!tty || tty->magic != TTY_MAGIC)
2534 return;
2535
2536 un = tty->driver_data;
2537 if (!un || un->magic != DGNC_UNIT_MAGIC)
2538 return;
8b07d521 2539
90d2a471
LL
2540 ch = un->un_ch;
2541 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2542 return;
0b99d589
LL
2543
2544 bd = ch->ch_bd;
2545 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
2546 return;
2547
a44b508a 2548 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2549
2550 /* Do something maybe here */
2551
a44b508a 2552 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2553}
2554
2555
2556
2557/*
2558 * dgnc_tty_flush_buffer()
8b07d521 2559 *
0b99d589
LL
2560 * Flush Tx buffer (make in == out)
2561 */
2562static void dgnc_tty_flush_buffer(struct tty_struct *tty)
2563{
2564 struct channel_t *ch;
2565 struct un_t *un;
a44b508a 2566 unsigned long flags;
0b99d589
LL
2567
2568 if (!tty || tty->magic != TTY_MAGIC)
2569 return;
2570
2571 un = tty->driver_data;
2572 if (!un || un->magic != DGNC_UNIT_MAGIC)
2573 return;
8b07d521 2574
90d2a471
LL
2575 ch = un->un_ch;
2576 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
2577 return;
0b99d589 2578
a44b508a 2579 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2580
2581 ch->ch_flags &= ~CH_STOP;
2582
2583 /* Flush our write queue */
2584 ch->ch_w_head = ch->ch_w_tail;
2585
2586 /* Flush UARTs transmit FIFO */
2587 ch->ch_bd->bd_ops->flush_uart_write(ch);
2588
2589 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
2590 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
2591 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
2592 }
2593 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
2594 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
2595 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
2596 }
2597
a44b508a 2598 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2599}
2600
2601
2602
2603/*****************************************************************************
2604 *
2605 * The IOCTL function and all of its helpers
2606 *
2607 *****************************************************************************/
8b07d521 2608
0b99d589
LL
2609/*
2610 * dgnc_tty_ioctl()
2611 *
2612 * The usual assortment of ioctl's
2613 */
a31cefa2 2614static int dgnc_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
0b99d589
LL
2615 unsigned long arg)
2616{
03425f55 2617 struct dgnc_board *bd;
0b99d589
LL
2618 struct channel_t *ch;
2619 struct un_t *un;
2620 int rc;
a44b508a 2621 unsigned long flags;
0b99d589
LL
2622 void __user *uarg = (void __user *) arg;
2623
2624 if (!tty || tty->magic != TTY_MAGIC)
8f90ef80 2625 return -ENODEV;
0b99d589
LL
2626
2627 un = tty->driver_data;
2628 if (!un || un->magic != DGNC_UNIT_MAGIC)
8f90ef80 2629 return -ENODEV;
0b99d589
LL
2630
2631 ch = un->un_ch;
2632 if (!ch || ch->magic != DGNC_CHANNEL_MAGIC)
8f90ef80 2633 return -ENODEV;
0b99d589
LL
2634
2635 bd = ch->ch_bd;
2636 if (!bd || bd->magic != DGNC_BOARD_MAGIC)
8f90ef80 2637 return -ENODEV;
0b99d589 2638
a44b508a 2639 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2640
2641 if (un->un_open_count <= 0) {
a44b508a 2642 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2643 return -EIO;
0b99d589
LL
2644 }
2645
2646 switch (cmd) {
2647
2648 /* Here are all the standard ioctl's that we MUST implement */
2649
2650 case TCSBRK:
2651 /*
8b07d521 2652 * TCSBRK is SVID version: non-zero arg --> no break
0b99d589
LL
2653 * this behaviour is exploited by tcdrain().
2654 *
2655 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
2656 * between 0.25 and 0.5 seconds so we'll ask for something
2657 * in the middle: 0.375 seconds.
2658 */
2659 rc = tty_check_change(tty);
a44b508a 2660 spin_unlock_irqrestore(&ch->ch_lock, flags);
50667c67 2661 if (rc)
8f90ef80 2662 return rc;
0b99d589
LL
2663
2664 rc = ch->ch_bd->bd_ops->drain(tty, 0);
2665
f1e51745 2666 if (rc)
8f90ef80 2667 return -EINTR;
0b99d589 2668
a44b508a 2669 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 2670
3c4019d3 2671 if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
0b99d589 2672 ch->ch_bd->bd_ops->send_break(ch, 250);
0b99d589 2673
a44b508a 2674 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2675
8f90ef80 2676 return 0;
0b99d589
LL
2677
2678
2679 case TCSBRKP:
90d2a471 2680 /* support for POSIX tcsendbreak()
0b99d589
LL
2681 * According to POSIX.1 spec (7.2.2.1.2) breaks should be
2682 * between 0.25 and 0.5 seconds so we'll ask for something
2683 * in the middle: 0.375 seconds.
2684 */
2685 rc = tty_check_change(tty);
a44b508a 2686 spin_unlock_irqrestore(&ch->ch_lock, flags);
50667c67 2687 if (rc)
8f90ef80 2688 return rc;
0b99d589
LL
2689
2690 rc = ch->ch_bd->bd_ops->drain(tty, 0);
f1e51745 2691 if (rc)
8f90ef80 2692 return -EINTR;
0b99d589 2693
a44b508a 2694 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2695
2696 ch->ch_bd->bd_ops->send_break(ch, 250);
2697
a44b508a 2698 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2699
8f90ef80 2700 return 0;
0b99d589
LL
2701
2702 case TIOCSBRK:
2703 rc = tty_check_change(tty);
a44b508a 2704 spin_unlock_irqrestore(&ch->ch_lock, flags);
50667c67 2705 if (rc)
8f90ef80 2706 return rc;
0b99d589
LL
2707
2708 rc = ch->ch_bd->bd_ops->drain(tty, 0);
f1e51745 2709 if (rc)
8f90ef80 2710 return -EINTR;
0b99d589 2711
a44b508a 2712 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2713
2714 ch->ch_bd->bd_ops->send_break(ch, 250);
2715
a44b508a 2716 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2717
8f90ef80 2718 return 0;
0b99d589
LL
2719
2720 case TIOCCBRK:
2721 /* Do Nothing */
a44b508a 2722 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2723 return 0;
2724
2725 case TIOCGSOFTCAR:
2726
a44b508a 2727 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2728
2729 rc = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) arg);
8f90ef80 2730 return rc;
0b99d589
LL
2731
2732 case TIOCSSOFTCAR:
2733
a44b508a 2734 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2735 rc = get_user(arg, (unsigned long __user *) arg);
2736 if (rc)
8f90ef80 2737 return rc;
0b99d589 2738
a44b508a 2739 spin_lock_irqsave(&ch->ch_lock, flags);
22e3de76 2740 tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
0b99d589 2741 ch->ch_bd->bd_ops->param(tty);
a44b508a 2742 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2743
8f90ef80 2744 return 0;
8b07d521 2745
0b99d589 2746 case TIOCMGET:
a44b508a 2747 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2748 return dgnc_get_modem_info(ch, uarg);
0b99d589
LL
2749
2750 case TIOCMBIS:
2751 case TIOCMBIC:
2752 case TIOCMSET:
a44b508a 2753 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2754 return dgnc_set_modem_info(tty, cmd, uarg);
0b99d589
LL
2755
2756 /*
2757 * Here are any additional ioctl's that we want to implement
2758 */
8b07d521
LL
2759
2760 case TCFLSH:
0b99d589
LL
2761 /*
2762 * The linux tty driver doesn't have a flush
2763 * input routine for the driver, assuming all backed
2764 * up data is in the line disc. buffers. However,
2765 * we all know that's not the case. Here, we
2766 * act on the ioctl, but then lie and say we didn't
2767 * so the line discipline will process the flush
2768 * also.
8b07d521 2769 */
0b99d589
LL
2770 rc = tty_check_change(tty);
2771 if (rc) {
a44b508a 2772 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2773 return rc;
0b99d589
LL
2774 }
2775
2776 if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
2777 ch->ch_r_head = ch->ch_r_tail;
2778 ch->ch_bd->bd_ops->flush_uart_read(ch);
2779 /* Force queue flow control to be released, if needed */
2780 dgnc_check_queue_flow_control(ch);
2781 }
2782
2783 if ((arg == TCOFLUSH) || (arg == TCIOFLUSH)) {
2784 if (!(un->un_type == DGNC_PRINT)) {
2785 ch->ch_w_head = ch->ch_w_tail;
2786 ch->ch_bd->bd_ops->flush_uart_write(ch);
2787
2788 if (ch->ch_tun.un_flags & (UN_LOW|UN_EMPTY)) {
2789 ch->ch_tun.un_flags &= ~(UN_LOW|UN_EMPTY);
2790 wake_up_interruptible(&ch->ch_tun.un_flags_wait);
2791 }
2792
2793 if (ch->ch_pun.un_flags & (UN_LOW|UN_EMPTY)) {
2794 ch->ch_pun.un_flags &= ~(UN_LOW|UN_EMPTY);
2795 wake_up_interruptible(&ch->ch_pun.un_flags_wait);
2796 }
2797
2798 }
2799 }
2800
8b07d521 2801 /* pretend we didn't recognize this IOCTL */
a44b508a 2802 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2803 return -ENOIOCTLCMD;
0b99d589
LL
2804 case TCSETSF:
2805 case TCSETSW:
2806 /*
2807 * The linux tty driver doesn't have a flush
2808 * input routine for the driver, assuming all backed
2809 * up data is in the line disc. buffers. However,
2810 * we all know that's not the case. Here, we
2811 * act on the ioctl, but then lie and say we didn't
2812 * so the line discipline will process the flush
2813 * also.
2814 */
2815 if (cmd == TCSETSF) {
2816 /* flush rx */
2817 ch->ch_flags &= ~CH_STOP;
2818 ch->ch_r_head = ch->ch_r_tail;
2819 ch->ch_bd->bd_ops->flush_uart_read(ch);
2820 /* Force queue flow control to be released, if needed */
2821 dgnc_check_queue_flow_control(ch);
2822 }
2823
2824 /* now wait for all the output to drain */
a44b508a 2825 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2826 rc = ch->ch_bd->bd_ops->drain(tty, 0);
f1e51745 2827 if (rc)
8f90ef80 2828 return -EINTR;
0b99d589
LL
2829
2830 /* pretend we didn't recognize this */
8f90ef80 2831 return -ENOIOCTLCMD;
0b99d589
LL
2832
2833 case TCSETAW:
2834
a44b508a 2835 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2836 rc = ch->ch_bd->bd_ops->drain(tty, 0);
f1e51745 2837 if (rc)
8f90ef80 2838 return -EINTR;
0b99d589
LL
2839
2840 /* pretend we didn't recognize this */
8f90ef80 2841 return -ENOIOCTLCMD;
0b99d589
LL
2842
2843 case TCXONC:
a44b508a 2844 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2845 /* Make the ld do it */
8f90ef80 2846 return -ENOIOCTLCMD;
0b99d589
LL
2847
2848 case DIGI_GETA:
2849 /* get information for ditty */
a44b508a 2850 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2851 return dgnc_tty_digigeta(tty, uarg);
0b99d589
LL
2852
2853 case DIGI_SETAW:
2854 case DIGI_SETAF:
2855
2856 /* set information for ditty */
2857 if (cmd == (DIGI_SETAW)) {
2858
a44b508a 2859 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2860 rc = ch->ch_bd->bd_ops->drain(tty, 0);
f1e51745
SL
2861
2862 if (rc)
8f90ef80 2863 return -EINTR;
f1e51745 2864
a44b508a 2865 spin_lock_irqsave(&ch->ch_lock, flags);
2000c581 2866 } else {
0b99d589
LL
2867 tty_ldisc_flush(tty);
2868 }
2869 /* fall thru */
2870
2871 case DIGI_SETA:
a44b508a 2872 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2873 return dgnc_tty_digiseta(tty, uarg);
8b07d521 2874
0b99d589
LL
2875 case DIGI_LOOPBACK:
2876 {
2877 uint loopback = 0;
2878 /* Let go of locks when accessing user space, could sleep */
a44b508a 2879 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2880 rc = get_user(loopback, (unsigned int __user *) arg);
2881 if (rc)
8f90ef80 2882 return rc;
a44b508a 2883 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 2884
8b07d521 2885 /* Enable/disable internal loopback for this port */
0b99d589
LL
2886 if (loopback)
2887 ch->ch_flags |= CH_LOOPBACK;
2888 else
2889 ch->ch_flags &= ~(CH_LOOPBACK);
2890
2891 ch->ch_bd->bd_ops->param(tty);
a44b508a 2892 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2893 return 0;
90d2a471 2894 }
0b99d589
LL
2895
2896 case DIGI_GETCUSTOMBAUD:
a44b508a 2897 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2898 rc = put_user(ch->ch_custom_speed, (unsigned int __user *) arg);
8f90ef80 2899 return rc;
0b99d589
LL
2900
2901 case DIGI_SETCUSTOMBAUD:
2902 {
93c76c9c 2903 int new_rate;
0b99d589 2904 /* Let go of locks when accessing user space, could sleep */
a44b508a 2905 spin_unlock_irqrestore(&ch->ch_lock, flags);
93c76c9c 2906 rc = get_user(new_rate, (int __user *) arg);
0b99d589 2907 if (rc)
8f90ef80 2908 return rc;
a44b508a 2909 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
2910 dgnc_set_custom_speed(ch, new_rate);
2911 ch->ch_bd->bd_ops->param(tty);
a44b508a 2912 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2913 return 0;
90d2a471 2914 }
0b99d589
LL
2915
2916 /*
2917 * This ioctl allows insertion of a character into the front
2918 * of any pending data to be transmitted.
2919 *
2920 * This ioctl is to satify the "Send Character Immediate"
2921 * call that the RealPort protocol spec requires.
2922 */
2923 case DIGI_REALPORT_SENDIMMEDIATE:
2924 {
2925 unsigned char c;
0eaa02e6 2926
a44b508a 2927 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
2928 rc = get_user(c, (unsigned char __user *) arg);
2929 if (rc)
8f90ef80 2930 return rc;
a44b508a 2931 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589 2932 ch->ch_bd->bd_ops->send_immediate_char(ch, c);
a44b508a 2933 spin_unlock_irqrestore(&ch->ch_lock, flags);
8f90ef80 2934 return 0;
0b99d589
LL
2935 }
2936
2937 /*
2938 * This ioctl returns all the current counts for the port.
2939 *
2940 * This ioctl is to satify the "Line Error Counters"
2941 * call that the RealPort protocol spec requires.
2942 */
2943 case DIGI_REALPORT_GETCOUNTERS:
2944 {
2945 struct digi_getcounter buf;
2946
2947 buf.norun = ch->ch_err_overrun;
feba47a7 2948 buf.noflow = 0; /* The driver doesn't keep this stat */
0b99d589
LL
2949 buf.nframe = ch->ch_err_frame;
2950 buf.nparity = ch->ch_err_parity;
2951 buf.nbreak = ch->ch_err_break;
2952 buf.rbytes = ch->ch_rxcount;
2953 buf.tbytes = ch->ch_txcount;
2954
a44b508a 2955 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2956
50667c67 2957 if (copy_to_user(uarg, &buf, sizeof(buf)))
8f90ef80 2958 return -EFAULT;
50667c67 2959
8f90ef80 2960 return 0;
0b99d589
LL
2961 }
2962
2963 /*
2964 * This ioctl returns all current events.
2965 *
2966 * This ioctl is to satify the "Event Reporting"
2967 * call that the RealPort protocol spec requires.
90d2a471 2968 */
0b99d589
LL
2969 case DIGI_REALPORT_GETEVENTS:
2970 {
2971 unsigned int events = 0;
2972
2973 /* NOTE: MORE EVENTS NEEDS TO BE ADDED HERE */
2974 if (ch->ch_flags & CH_BREAK_SENDING)
2975 events |= EV_TXB;
50667c67 2976 if ((ch->ch_flags & CH_STOP) || (ch->ch_flags & CH_FORCED_STOP))
0b99d589 2977 events |= (EV_OPU | EV_OPS);
50667c67 2978
3c4019d3 2979 if ((ch->ch_flags & CH_STOPI) || (ch->ch_flags & CH_FORCED_STOPI))
0b99d589 2980 events |= (EV_IPU | EV_IPS);
0b99d589 2981
a44b508a 2982 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 2983 rc = put_user(events, (unsigned int __user *) arg);
8f90ef80 2984 return rc;
0b99d589
LL
2985 }
2986
2987 /*
2988 * This ioctl returns TOUT and TIN counters based
2989 * upon the values passed in by the RealPort Server.
2990 * It also passes back whether the UART Transmitter is
2991 * empty as well.
90d2a471 2992 */
0b99d589
LL
2993 case DIGI_REALPORT_GETBUFFERS:
2994 {
2995 struct digi_getbuffer buf;
2996 int tdist;
2997 int count;
2998
a44b508a 2999 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589
LL
3000
3001 /*
3002 * Get data from user first.
3003 */
50667c67 3004 if (copy_from_user(&buf, uarg, sizeof(buf)))
8f90ef80 3005 return -EFAULT;
0b99d589 3006
a44b508a 3007 spin_lock_irqsave(&ch->ch_lock, flags);
0b99d589
LL
3008
3009 /*
3010 * Figure out how much data is in our RX and TX queues.
3011 */
3012 buf.rxbuf = (ch->ch_r_head - ch->ch_r_tail) & RQUEUEMASK;
3013 buf.txbuf = (ch->ch_w_head - ch->ch_w_tail) & WQUEUEMASK;
3014
3015 /*
3016 * Is the UART empty? Add that value to whats in our TX queue.
3017 */
3018 count = buf.txbuf + ch->ch_bd->bd_ops->get_uart_bytes_left(ch);
3019
3020 /*
3021 * Figure out how much data the RealPort Server believes should
3022 * be in our TX queue.
3023 */
3024 tdist = (buf.tIn - buf.tOut) & 0xffff;
3025
3026 /*
3027 * If we have more data than the RealPort Server believes we
3028 * should have, reduce our count to its amount.
3029 *
3030 * This count difference CAN happen because the Linux LD can
3031 * insert more characters into our queue for OPOST processing
3032 * that the RealPort Server doesn't know about.
3033 */
50667c67 3034 if (buf.txbuf > tdist)
0b99d589 3035 buf.txbuf = tdist;
0b99d589
LL
3036
3037 /*
3038 * Report whether our queue and UART TX are completely empty.
3039 */
50667c67 3040 if (count)
0b99d589 3041 buf.txdone = 0;
50667c67 3042 else
0b99d589 3043 buf.txdone = 1;
0b99d589 3044
a44b508a 3045 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 3046
50667c67 3047 if (copy_to_user(uarg, &buf, sizeof(buf)))
8f90ef80 3048 return -EFAULT;
50667c67 3049
8f90ef80 3050 return 0;
0b99d589
LL
3051 }
3052 default:
a44b508a 3053 spin_unlock_irqrestore(&ch->ch_lock, flags);
0b99d589 3054
8f90ef80 3055 return -ENOIOCTLCMD;
0b99d589 3056 }
0b99d589 3057}