1 /************************************************************************
2 * Copyright 2003 Digi International (www.digi.com)
4 * Copyright (C) 2004 IBM Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
13 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 * Temple Place - Suite 330, Boston,
21 * Contact Information:
22 * Scott H Kilau <Scott_Kilau@digi.com>
23 * Wendy Xiong <wendyx@us.ltcfwd.linux.ibm.com>
25 ***********************************************************************/
26 #include <linux/tty.h>
27 #include <linux/tty_flip.h>
28 #include <linux/serial_reg.h>
29 #include <linux/delay.h> /* For udelay */
30 #include <linux/pci.h>
34 static inline int jsm_get_mstat(struct jsm_channel
*ch
)
39 jsm_printk(IOCTL
, INFO
, &ch
->ch_bd
->pci_dev
, "start\n");
41 mstat
= (ch
->ch_mostat
| ch
->ch_mistat
);
45 if (mstat
& UART_MCR_DTR
)
47 if (mstat
& UART_MCR_RTS
)
49 if (mstat
& UART_MSR_CTS
)
51 if (mstat
& UART_MSR_DSR
)
53 if (mstat
& UART_MSR_RI
)
55 if (mstat
& UART_MSR_DCD
)
58 jsm_printk(IOCTL
, INFO
, &ch
->ch_bd
->pci_dev
, "finish\n");
62 static unsigned int jsm_tty_tx_empty(struct uart_port
*port
)
68 * Return modem signals to ld.
70 static unsigned int jsm_tty_get_mctrl(struct uart_port
*port
)
73 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
75 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "start\n");
77 result
= jsm_get_mstat(channel
);
82 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "finish\n");
88 * jsm_set_modem_info()
90 * Set modem signals, called by ld.
92 static void jsm_tty_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
94 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
96 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "start\n");
98 if (mctrl
& TIOCM_RTS
)
99 channel
->ch_mostat
|= UART_MCR_RTS
;
101 channel
->ch_mostat
&= ~UART_MCR_RTS
;
103 if (mctrl
& TIOCM_DTR
)
104 channel
->ch_mostat
|= UART_MCR_DTR
;
106 channel
->ch_mostat
&= ~UART_MCR_DTR
;
108 channel
->ch_bd
->bd_ops
->assert_modem_signals(channel
);
110 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "finish\n");
114 static void jsm_tty_start_tx(struct uart_port
*port
, unsigned int tty_start
)
116 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
118 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "start\n");
120 channel
->ch_flags
&= ~(CH_STOP
);
123 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "finish\n");
126 static void jsm_tty_stop_tx(struct uart_port
*port
, unsigned int tty_stop
)
128 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
130 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "start\n");
132 channel
->ch_flags
|= (CH_STOP
);
134 jsm_printk(IOCTL
, INFO
, &channel
->ch_bd
->pci_dev
, "finish\n");
137 static void jsm_tty_send_xchar(struct uart_port
*port
, char ch
)
139 unsigned long lock_flags
;
140 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
142 spin_lock_irqsave(&port
->lock
, lock_flags
);
143 if (ch
== port
->info
->tty
->termios
->c_cc
[VSTART
])
144 channel
->ch_bd
->bd_ops
->send_start_character(channel
);
146 if (ch
== port
->info
->tty
->termios
->c_cc
[VSTOP
])
147 channel
->ch_bd
->bd_ops
->send_stop_character(channel
);
148 spin_unlock_irqrestore(&port
->lock
, lock_flags
);
151 static void jsm_tty_stop_rx(struct uart_port
*port
)
153 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
155 channel
->ch_bd
->bd_ops
->disable_receiver(channel
);
158 static void jsm_tty_break(struct uart_port
*port
, int break_state
)
160 unsigned long lock_flags
;
161 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
163 spin_lock_irqsave(&port
->lock
, lock_flags
);
164 if (break_state
== -1)
165 channel
->ch_bd
->bd_ops
->send_break(channel
);
167 channel
->ch_bd
->bd_ops
->clear_break(channel
, 0);
169 spin_unlock_irqrestore(&port
->lock
, lock_flags
);
172 static int jsm_tty_open(struct uart_port
*port
)
174 struct jsm_board
*brd
;
176 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
178 /* Get board pointer from our array of majors we have allocated */
179 brd
= channel
->ch_bd
;
182 * Allocate channel buffers for read/write/error.
183 * Set flag, so we don't get trounced on.
185 channel
->ch_flags
|= (CH_OPENING
);
187 /* Drop locks, as malloc with GFP_KERNEL can sleep */
189 if (!channel
->ch_rqueue
) {
190 channel
->ch_rqueue
= (u8
*) kmalloc(RQUEUESIZE
, GFP_KERNEL
);
191 if (!channel
->ch_rqueue
) {
192 jsm_printk(INIT
, ERR
, &channel
->ch_bd
->pci_dev
,
193 "unable to allocate read queue buf");
196 memset(channel
->ch_rqueue
, 0, RQUEUESIZE
);
198 if (!channel
->ch_equeue
) {
199 channel
->ch_equeue
= (u8
*) kmalloc(EQUEUESIZE
, GFP_KERNEL
);
200 if (!channel
->ch_equeue
) {
201 jsm_printk(INIT
, ERR
, &channel
->ch_bd
->pci_dev
,
202 "unable to allocate error queue buf");
205 memset(channel
->ch_equeue
, 0, EQUEUESIZE
);
207 if (!channel
->ch_wqueue
) {
208 channel
->ch_wqueue
= (u8
*) kmalloc(WQUEUESIZE
, GFP_KERNEL
);
209 if (!channel
->ch_wqueue
) {
210 jsm_printk(INIT
, ERR
, &channel
->ch_bd
->pci_dev
,
211 "unable to allocate write queue buf");
214 memset(channel
->ch_wqueue
, 0, WQUEUESIZE
);
217 channel
->ch_flags
&= ~(CH_OPENING
);
219 * Initialize if neither terminal is open.
221 jsm_printk(OPEN
, INFO
, &channel
->ch_bd
->pci_dev
,
222 "jsm_open: initializing channel in open...\n");
225 * Flush input queues.
227 channel
->ch_r_head
= channel
->ch_r_tail
= 0;
228 channel
->ch_e_head
= channel
->ch_e_tail
= 0;
229 channel
->ch_w_head
= channel
->ch_w_tail
= 0;
231 brd
->bd_ops
->flush_uart_write(channel
);
232 brd
->bd_ops
->flush_uart_read(channel
);
234 channel
->ch_flags
= 0;
235 channel
->ch_cached_lsr
= 0;
236 channel
->ch_stops_sent
= 0;
238 channel
->ch_c_cflag
= port
->info
->tty
->termios
->c_cflag
;
239 channel
->ch_c_iflag
= port
->info
->tty
->termios
->c_iflag
;
240 channel
->ch_c_oflag
= port
->info
->tty
->termios
->c_oflag
;
241 channel
->ch_c_lflag
= port
->info
->tty
->termios
->c_lflag
;
242 channel
->ch_startc
= port
->info
->tty
->termios
->c_cc
[VSTART
];
243 channel
->ch_stopc
= port
->info
->tty
->termios
->c_cc
[VSTOP
];
245 /* Tell UART to init itself */
246 brd
->bd_ops
->uart_init(channel
);
249 * Run param in case we changed anything
251 brd
->bd_ops
->param(channel
);
253 jsm_carrier(channel
);
255 channel
->ch_open_count
++;
257 jsm_printk(OPEN
, INFO
, &channel
->ch_bd
->pci_dev
, "finish\n");
261 static void jsm_tty_close(struct uart_port
*port
)
263 struct jsm_board
*bd
;
265 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
267 jsm_printk(CLOSE
, INFO
, &channel
->ch_bd
->pci_dev
, "start\n");
270 ts
= channel
->uart_port
.info
->tty
->termios
;
272 channel
->ch_flags
&= ~(CH_STOPI
);
274 channel
->ch_open_count
--;
277 * If we have HUPCL set, lower DTR and RTS
279 if (channel
->ch_c_cflag
& HUPCL
) {
280 jsm_printk(CLOSE
, INFO
, &channel
->ch_bd
->pci_dev
,
281 "Close. HUPCL set, dropping DTR/RTS\n");
284 channel
->ch_mostat
&= ~(UART_MCR_DTR
| UART_MCR_RTS
);
285 bd
->bd_ops
->assert_modem_signals(channel
);
288 channel
->ch_old_baud
= 0;
290 /* Turn off UART interrupts for this port */
291 channel
->ch_bd
->bd_ops
->uart_off(channel
);
293 jsm_printk(CLOSE
, INFO
, &channel
->ch_bd
->pci_dev
, "finish\n");
296 static void jsm_tty_set_termios(struct uart_port
*port
,
297 struct termios
*termios
,
298 struct termios
*old_termios
)
300 unsigned long lock_flags
;
301 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
303 spin_lock_irqsave(&port
->lock
, lock_flags
);
304 channel
->ch_c_cflag
= termios
->c_cflag
;
305 channel
->ch_c_iflag
= termios
->c_iflag
;
306 channel
->ch_c_oflag
= termios
->c_oflag
;
307 channel
->ch_c_lflag
= termios
->c_lflag
;
308 channel
->ch_startc
= termios
->c_cc
[VSTART
];
309 channel
->ch_stopc
= termios
->c_cc
[VSTOP
];
311 channel
->ch_bd
->bd_ops
->param(channel
);
312 jsm_carrier(channel
);
313 spin_unlock_irqrestore(&port
->lock
, lock_flags
);
316 static const char *jsm_tty_type(struct uart_port
*port
)
321 static void jsm_tty_release_port(struct uart_port
*port
)
325 static int jsm_tty_request_port(struct uart_port
*port
)
330 static void jsm_config_port(struct uart_port
*port
, int flags
)
332 port
->type
= PORT_JSM
;
335 static struct uart_ops jsm_ops
= {
336 .tx_empty
= jsm_tty_tx_empty
,
337 .set_mctrl
= jsm_tty_set_mctrl
,
338 .get_mctrl
= jsm_tty_get_mctrl
,
339 .stop_tx
= jsm_tty_stop_tx
,
340 .start_tx
= jsm_tty_start_tx
,
341 .send_xchar
= jsm_tty_send_xchar
,
342 .stop_rx
= jsm_tty_stop_rx
,
343 .break_ctl
= jsm_tty_break
,
344 .startup
= jsm_tty_open
,
345 .shutdown
= jsm_tty_close
,
346 .set_termios
= jsm_tty_set_termios
,
347 .type
= jsm_tty_type
,
348 .release_port
= jsm_tty_release_port
,
349 .request_port
= jsm_tty_request_port
,
350 .config_port
= jsm_config_port
,
356 * Init the tty subsystem. Called once per board after board has been
357 * downloaded and init'ed.
359 int jsm_tty_init(struct jsm_board
*brd
)
363 struct jsm_channel
*ch
;
368 jsm_printk(INIT
, INFO
, &brd
->pci_dev
, "start\n");
371 * Initialize board structure elements.
374 brd
->nasync
= brd
->maxports
;
377 * Allocate channel memory that might not have been allocated
378 * when the driver was first loaded.
380 for (i
= 0; i
< brd
->nasync
; i
++) {
381 if (!brd
->channels
[i
]) {
384 * Okay to malloc with GFP_KERNEL, we are not at
385 * interrupt context, and there are no locks held.
387 brd
->channels
[i
] = kmalloc(sizeof(struct jsm_channel
), GFP_KERNEL
);
388 if (!brd
->channels
[i
]) {
389 jsm_printk(CORE
, ERR
, &brd
->pci_dev
,
390 "%s:%d Unable to allocate memory for channel struct\n",
393 memset(brd
->channels
[i
], 0, sizeof(struct jsm_channel
));
397 ch
= brd
->channels
[0];
398 vaddr
= brd
->re_map_membase
;
400 /* Set up channel variables */
401 for (i
= 0; i
< brd
->nasync
; i
++, ch
= brd
->channels
[i
]) {
403 if (!brd
->channels
[i
])
406 spin_lock_init(&ch
->ch_lock
);
408 if (brd
->bd_uart_offset
== 0x200)
409 ch
->ch_neo_uart
= vaddr
+ (brd
->bd_uart_offset
* i
);
414 /* .25 second delay */
415 ch
->ch_close_delay
= 250;
417 init_waitqueue_head(&ch
->ch_flags_wait
);
420 jsm_printk(INIT
, INFO
, &brd
->pci_dev
, "finish\n");
424 int jsm_uart_port_init(struct jsm_board
*brd
)
427 struct jsm_channel
*ch
;
432 jsm_printk(INIT
, INFO
, &brd
->pci_dev
, "start\n");
435 * Initialize board structure elements.
438 brd
->nasync
= brd
->maxports
;
440 /* Set up channel variables */
441 for (i
= 0; i
< brd
->nasync
; i
++, ch
= brd
->channels
[i
]) {
443 if (!brd
->channels
[i
])
446 brd
->channels
[i
]->uart_port
.irq
= brd
->irq
;
447 brd
->channels
[i
]->uart_port
.type
= PORT_JSM
;
448 brd
->channels
[i
]->uart_port
.iotype
= UPIO_MEM
;
449 brd
->channels
[i
]->uart_port
.membase
= brd
->re_map_membase
;
450 brd
->channels
[i
]->uart_port
.fifosize
= 16;
451 brd
->channels
[i
]->uart_port
.ops
= &jsm_ops
;
452 brd
->channels
[i
]->uart_port
.line
= brd
->channels
[i
]->ch_portnum
+ brd
->boardnum
* 2;
453 if (uart_add_one_port (&jsm_uart_driver
, &brd
->channels
[i
]->uart_port
))
454 printk(KERN_INFO
"Added device failed\n");
456 printk(KERN_INFO
"Added device \n");
459 jsm_printk(INIT
, INFO
, &brd
->pci_dev
, "finish\n");
463 int jsm_remove_uart_port(struct jsm_board
*brd
)
466 struct jsm_channel
*ch
;
471 jsm_printk(INIT
, INFO
, &brd
->pci_dev
, "start\n");
474 * Initialize board structure elements.
477 brd
->nasync
= brd
->maxports
;
479 /* Set up channel variables */
480 for (i
= 0; i
< brd
->nasync
; i
++) {
482 if (!brd
->channels
[i
])
485 ch
= brd
->channels
[i
];
487 uart_remove_one_port(&jsm_uart_driver
, &brd
->channels
[i
]->uart_port
);
490 jsm_printk(INIT
, INFO
, &brd
->pci_dev
, "finish\n");
494 void jsm_input(struct jsm_channel
*ch
)
496 struct jsm_board
*bd
;
497 struct tty_struct
*tp
;
502 unsigned long lock_flags
;
511 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
, "start\n");
516 tp
= ch
->uart_port
.info
->tty
;
522 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
525 *Figure the number of characters in the buffer.
526 *Exit immediately if none.
531 head
= ch
->ch_r_head
& rmask
;
532 tail
= ch
->ch_r_tail
& rmask
;
534 data_len
= (head
- tail
) & rmask
;
536 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
540 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
, "start\n");
543 *If the device is not open, or CREAD is off, flush
544 *input data and return immediately.
547 !(tp
->termios
->c_cflag
& CREAD
) ) {
549 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
550 "input. dropping %d bytes on port %d...\n", data_len
, ch
->ch_portnum
);
551 ch
->ch_r_head
= tail
;
553 /* Force queue flow control to be released, if needed */
554 jsm_check_queue_flow_control(ch
);
556 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
561 * If we are throttled, simply don't read any data.
563 if (ch
->ch_flags
& CH_STOPI
) {
564 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
565 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
566 "Port %d throttled, not reading any data. head: %x tail: %x\n",
567 ch
->ch_portnum
, head
, tail
);
571 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
, "start 2\n");
574 * If the rxbuf is empty and we are not throttled, put as much
575 * as we can directly into the linux TTY flip buffer.
576 * The jsm_rawreadok case takes advantage of carnal knowledge that
577 * the char_buf and the flag_buf are next to each other and
578 * are each of (2 * TTY_FLIPBUF_SIZE) size.
580 * NOTE: if(!tty->real_raw), the call to ldisc.receive_buf
581 *actually still uses the flag buffer, so you can't
582 *use it for input data
586 flip_len
= MYFLIPLEN
;
588 flip_len
= 2 * TTY_FLIPBUF_SIZE
;
590 flip_len
= TTY_FLIPBUF_SIZE
- tp
->flip
.count
;
592 len
= min(data_len
, flip_len
);
593 len
= min(len
, (N_TTY_BUF_SIZE
- 1) - tp
->read_cnt
);
596 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
597 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
, "jsm_input 1\n");
602 * If we're bypassing flip buffers on rx, we can blast it
603 * right into the beginning of the buffer.
607 if (ch
->ch_flags
& CH_FLIPBUF_IN_USE
) {
608 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
609 "JSM - FLIPBUF in use. delaying input\n");
610 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
613 ch
->ch_flags
|= CH_FLIPBUF_IN_USE
;
614 buf
= ch
->ch_bd
->flipbuf
;
617 buf
= tp
->flip
.char_buf
;
618 buf2
= tp
->flip
.flag_buf
;
621 buf
= tp
->flip
.char_buf_ptr
;
622 buf2
= tp
->flip
.flag_buf_ptr
;
628 * n now contains the most amount of data we can copy,
629 * bounded either by the flip buffer size or the amount
630 * of data the card actually has pending...
633 s
= ((head
>= tail
) ? head
: RQUEUESIZE
) - tail
;
639 memcpy(buf
, ch
->ch_rqueue
+ tail
, s
);
641 /* buf2 is only set when port isn't raw */
643 memcpy(buf2
, ch
->ch_equeue
+ tail
, s
);
650 /* Flip queue if needed */
655 * In high performance mode, we don't have to update
656 * flag_buf or any of the counts or pointers into flip buf.
658 if (!jsm_rawreadok
) {
659 if (I_PARMRK(tp
) || I_BRKINT(tp
) || I_INPCK(tp
)) {
660 for (i
= 0; i
< len
; i
++) {
662 * Give the Linux ld the flags in the
665 if (tp
->flip
.flag_buf_ptr
[i
] & UART_LSR_BI
)
666 tp
->flip
.flag_buf_ptr
[i
] = TTY_BREAK
;
667 else if (tp
->flip
.flag_buf_ptr
[i
] & UART_LSR_PE
)
668 tp
->flip
.flag_buf_ptr
[i
] = TTY_PARITY
;
669 else if (tp
->flip
.flag_buf_ptr
[i
] & UART_LSR_FE
)
670 tp
->flip
.flag_buf_ptr
[i
] = TTY_FRAME
;
672 tp
->flip
.flag_buf_ptr
[i
] = TTY_NORMAL
;
675 memset(tp
->flip
.flag_buf_ptr
, 0, len
);
678 tp
->flip
.char_buf_ptr
+= len
;
679 tp
->flip
.flag_buf_ptr
+= len
;
680 tp
->flip
.count
+= len
;
682 else if (!tp
->real_raw
) {
683 if (I_PARMRK(tp
) || I_BRKINT(tp
) || I_INPCK(tp
)) {
684 for (i
= 0; i
< len
; i
++) {
686 * Give the Linux ld the flags in the
689 if (tp
->flip
.flag_buf_ptr
[i
] & UART_LSR_BI
)
690 tp
->flip
.flag_buf_ptr
[i
] = TTY_BREAK
;
691 else if (tp
->flip
.flag_buf_ptr
[i
] & UART_LSR_PE
)
692 tp
->flip
.flag_buf_ptr
[i
] = TTY_PARITY
;
693 else if (tp
->flip
.flag_buf_ptr
[i
] & UART_LSR_FE
)
694 tp
->flip
.flag_buf_ptr
[i
] = TTY_FRAME
;
696 tp
->flip
.flag_buf_ptr
[i
] = TTY_NORMAL
;
699 memset(tp
->flip
.flag_buf
, 0, len
);
703 * If we're doing raw reads, jam it right into the
704 * line disc bypassing the flip buffers.
708 ch
->ch_r_tail
= tail
& rmask
;
709 ch
->ch_e_tail
= tail
& rmask
;
711 jsm_check_queue_flow_control(ch
);
713 /* !!! WE *MUST* LET GO OF ALL LOCKS BEFORE CALLING RECEIVE BUF !!! */
715 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
717 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
718 "jsm_input. %d real_raw len:%d calling receive_buf for board %d\n",
719 __LINE__
, len
, ch
->ch_bd
->boardnum
);
720 tp
->ldisc
.receive_buf(tp
, ch
->ch_bd
->flipbuf
, NULL
, len
);
722 /* Allow use of channel flip buffer again */
723 spin_lock_irqsave(&ch
->ch_lock
, lock_flags
);
724 ch
->ch_flags
&= ~CH_FLIPBUF_IN_USE
;
725 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
728 ch
->ch_r_tail
= tail
& rmask
;
729 ch
->ch_e_tail
= tail
& rmask
;
731 jsm_check_queue_flow_control(ch
);
733 /* !!! WE *MUST* LET GO OF ALL LOCKS BEFORE CALLING RECEIVE BUF !!! */
734 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
736 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
737 "jsm_input. %d not real_raw len:%d calling receive_buf for board %d\n",
738 __LINE__
, len
, ch
->ch_bd
->boardnum
);
740 tp
->ldisc
.receive_buf(tp
, tp
->flip
.char_buf
, tp
->flip
.flag_buf
, len
);
743 ch
->ch_r_tail
= tail
& rmask
;
744 ch
->ch_e_tail
= tail
& rmask
;
746 jsm_check_queue_flow_control(ch
);
748 spin_unlock_irqrestore(&ch
->ch_lock
, lock_flags
);
750 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
751 "jsm_input. %d not jsm_read raw okay scheduling flip\n", __LINE__
);
752 tty_schedule_flip(tp
);
755 jsm_printk(IOCTL
, INFO
, &ch
->ch_bd
->pci_dev
, "finish\n");
758 void jsm_carrier(struct jsm_channel
*ch
)
760 struct jsm_board
*bd
;
762 int virt_carrier
= 0;
763 int phys_carrier
= 0;
765 jsm_printk(CARR
, INFO
, &ch
->ch_bd
->pci_dev
, "start\n");
774 if (ch
->ch_mistat
& UART_MSR_DCD
) {
775 jsm_printk(CARR
, INFO
, &ch
->ch_bd
->pci_dev
,
776 "mistat: %x D_CD: %x\n", ch
->ch_mistat
, ch
->ch_mistat
& UART_MSR_DCD
);
780 if (ch
->ch_c_cflag
& CLOCAL
)
783 jsm_printk(CARR
, INFO
, &ch
->ch_bd
->pci_dev
,
784 "DCD: physical: %d virt: %d\n", phys_carrier
, virt_carrier
);
787 * Test for a VIRTUAL carrier transition to HIGH.
789 if (((ch
->ch_flags
& CH_FCAR
) == 0) && (virt_carrier
== 1)) {
792 * When carrier rises, wake any threads waiting
793 * for carrier in the open routine.
796 jsm_printk(CARR
, INFO
, &ch
->ch_bd
->pci_dev
,
797 "carrier: virt DCD rose\n");
799 if (waitqueue_active(&(ch
->ch_flags_wait
)))
800 wake_up_interruptible(&ch
->ch_flags_wait
);
804 * Test for a PHYSICAL carrier transition to HIGH.
806 if (((ch
->ch_flags
& CH_CD
) == 0) && (phys_carrier
== 1)) {
809 * When carrier rises, wake any threads waiting
810 * for carrier in the open routine.
813 jsm_printk(CARR
, INFO
, &ch
->ch_bd
->pci_dev
,
814 "carrier: physical DCD rose\n");
816 if (waitqueue_active(&(ch
->ch_flags_wait
)))
817 wake_up_interruptible(&ch
->ch_flags_wait
);
821 * Test for a PHYSICAL transition to low, so long as we aren't
822 * currently ignoring physical transitions (which is what "virtual
823 * carrier" indicates).
825 * The transition of the virtual carrier to low really doesn't
826 * matter... it really only means "ignore carrier state", not
827 * "make pretend that carrier is there".
829 if ((virt_carrier
== 0) && ((ch
->ch_flags
& CH_CD
) != 0)
830 && (phys_carrier
== 0)) {
832 * When carrier drops:
834 * Drop carrier on all open units.
836 * Flush queues, waking up any task waiting in the
839 * Send a hangup to the control terminal.
841 * Enable all select calls.
843 if (waitqueue_active(&(ch
->ch_flags_wait
)))
844 wake_up_interruptible(&ch
->ch_flags_wait
);
848 * Make sure that our cached values reflect the current reality.
850 if (virt_carrier
== 1)
851 ch
->ch_flags
|= CH_FCAR
;
853 ch
->ch_flags
&= ~CH_FCAR
;
855 if (phys_carrier
== 1)
856 ch
->ch_flags
|= CH_CD
;
858 ch
->ch_flags
&= ~CH_CD
;
862 void jsm_check_queue_flow_control(struct jsm_channel
*ch
)
866 /* Store how much space we have left in the queue */
867 if ((qleft
= ch
->ch_r_tail
- ch
->ch_r_head
- 1) < 0)
868 qleft
+= RQUEUEMASK
+ 1;
871 * Check to see if we should enforce flow control on our queue because
872 * the ld (or user) isn't reading data out of our queue fast enuf.
874 * NOTE: This is done based on what the current flow control of the
877 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
878 * This will cause the UART's FIFO to back up, and force
879 * the RTS signal to be dropped.
880 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
881 * the other side, in hopes it will stop sending data to us.
882 * 3) NONE - Nothing we can do. We will simply drop any extra data
883 * that gets sent into us when the queue fills up.
887 if (ch
->ch_c_cflag
& CRTSCTS
) {
888 if(!(ch
->ch_flags
& CH_RECEIVER_OFF
)) {
889 ch
->ch_bd
->bd_ops
->disable_receiver(ch
);
890 ch
->ch_flags
|= (CH_RECEIVER_OFF
);
891 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
892 "Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
897 else if (ch
->ch_c_iflag
& IXOFF
) {
898 if (ch
->ch_stops_sent
<= MAX_STOPS_SENT
) {
899 ch
->ch_bd
->bd_ops
->send_stop_character(ch
);
901 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
902 "Sending stop char! Times sent: %x\n", ch
->ch_stops_sent
);
908 * Check to see if we should unenforce flow control because
909 * ld (or user) finally read enuf data out of our queue.
911 * NOTE: This is done based on what the current flow control of the
914 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
915 * This will cause the UART's FIFO to raise RTS back up,
916 * which will allow the other side to start sending data again.
917 * 2) SWFLOW (IXOFF) - Send a start character to
918 * the other side, so it will start sending data to us again.
919 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
920 * other side, we don't need to do anything now.
922 if (qleft
> (RQUEUESIZE
/ 2)) {
924 if (ch
->ch_c_cflag
& CRTSCTS
) {
925 if (ch
->ch_flags
& CH_RECEIVER_OFF
) {
926 ch
->ch_bd
->bd_ops
->enable_receiver(ch
);
927 ch
->ch_flags
&= ~(CH_RECEIVER_OFF
);
928 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
,
929 "Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
934 else if (ch
->ch_c_iflag
& IXOFF
&& ch
->ch_stops_sent
) {
935 ch
->ch_stops_sent
= 0;
936 ch
->ch_bd
->bd_ops
->send_start_character(ch
);
937 jsm_printk(READ
, INFO
, &ch
->ch_bd
->pci_dev
, "Sending start char!\n");
945 * Take data from the user or kernel and send it out to the FEP.
946 * In here exists all the Transparent Print magic as well.
948 int jsm_tty_write(struct uart_port
*port
)
950 int bufcount
= 0, n
= 0;
951 int data_count
= 0,data_count1
=0;
956 int temp_tail
= port
->info
->xmit
.tail
;
957 struct jsm_channel
*channel
= (struct jsm_channel
*)port
;
960 head
= (channel
->ch_w_head
) & tmask
;
961 tail
= (channel
->ch_w_tail
) & tmask
;
963 if ((bufcount
= tail
- head
- 1) < 0)
964 bufcount
+= WQUEUESIZE
;
969 remain
= WQUEUESIZE
- head
;
974 while ((port
->info
->xmit
.head
!= temp_tail
) &&
975 (data_count
< remain
)) {
976 channel
->ch_wqueue
[head
++] =
977 port
->info
->xmit
.buf
[temp_tail
];
980 temp_tail
&= (UART_XMIT_SIZE
- 1);
983 if (data_count
== remain
) head
= 0;
989 while ((port
->info
->xmit
.head
!= temp_tail
) &&
990 (data_count1
< remain
)) {
991 channel
->ch_wqueue
[head
++] =
992 port
->info
->xmit
.buf
[temp_tail
];
995 temp_tail
&= (UART_XMIT_SIZE
- 1);
1001 port
->info
->xmit
.tail
= temp_tail
;
1003 data_count
+= data_count1
;
1006 channel
->ch_w_head
= head
;
1010 channel
->ch_bd
->bd_ops
->copy_data_from_queue_to_uart(channel
);
1016 static ssize_t
jsm_driver_version_show(struct device_driver
*ddp
, char *buf
)
1018 return snprintf(buf
, PAGE_SIZE
, "%s\n", JSM_VERSION
);
1020 static DRIVER_ATTR(version
, S_IRUSR
, jsm_driver_version_show
, NULL
);
1022 static ssize_t
jsm_driver_state_show(struct device_driver
*ddp
, char *buf
)
1024 return snprintf(buf
, PAGE_SIZE
, "%s\n", jsm_driver_state_text
[jsm_driver_state
]);
1026 static DRIVER_ATTR(state
, S_IRUSR
, jsm_driver_state_show
, NULL
);
1028 void jsm_create_driver_sysfiles(struct device_driver
*driverfs
)
1030 driver_create_file(driverfs
, &driver_attr_version
);
1031 driver_create_file(driverfs
, &driver_attr_state
);
1034 void jsm_remove_driver_sysfiles(struct device_driver
*driverfs
)
1036 driver_remove_file(driverfs
, &driver_attr_version
);
1037 driver_remove_file(driverfs
, &driver_attr_state
);