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