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