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