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 void jsm_carrier(struct jsm_channel *ch);
36 static inline int jsm_get_mstat(struct jsm_channel *ch)
41 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev, "start\n");
43 mstat = (ch->ch_mostat | ch->ch_mistat);
47 if (mstat & UART_MCR_DTR)
49 if (mstat & UART_MCR_RTS)
51 if (mstat & UART_MSR_CTS)
53 if (mstat & UART_MSR_DSR)
55 if (mstat & UART_MSR_RI)
57 if (mstat & UART_MSR_DCD)
60 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev, "finish\n");
64 static unsigned int jsm_tty_tx_empty(struct uart_port *port)
70 * Return modem signals to ld.
72 static unsigned int jsm_tty_get_mctrl(struct uart_port *port)
75 struct jsm_channel *channel = (struct jsm_channel *)port;
77 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
79 result = jsm_get_mstat(channel);
84 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
90 * jsm_set_modem_info()
92 * Set modem signals, called by ld.
94 static void jsm_tty_set_mctrl(struct uart_port *port, unsigned int mctrl)
96 struct jsm_channel *channel = (struct jsm_channel *)port;
98 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
100 if (mctrl & TIOCM_RTS)
101 channel->ch_mostat |= UART_MCR_RTS;
103 channel->ch_mostat &= ~UART_MCR_RTS;
105 if (mctrl & TIOCM_DTR)
106 channel->ch_mostat |= UART_MCR_DTR;
108 channel->ch_mostat &= ~UART_MCR_DTR;
110 channel->ch_bd->bd_ops->assert_modem_signals(channel);
112 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
116 static void jsm_tty_start_tx(struct uart_port *port)
118 struct jsm_channel *channel = (struct jsm_channel *)port;
120 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
122 channel->ch_flags &= ~(CH_STOP);
125 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
128 static void jsm_tty_stop_tx(struct uart_port *port)
130 struct jsm_channel *channel = (struct jsm_channel *)port;
132 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "start\n");
134 channel->ch_flags |= (CH_STOP);
136 jsm_printk(IOCTL, INFO, &channel->ch_bd->pci_dev, "finish\n");
139 static void jsm_tty_send_xchar(struct uart_port *port, char ch)
141 unsigned long lock_flags;
142 struct jsm_channel *channel = (struct jsm_channel *)port;
144 spin_lock_irqsave(&port->lock, lock_flags);
145 if (ch == port->info->tty->termios->c_cc[VSTART])
146 channel->ch_bd->bd_ops->send_start_character(channel);
148 if (ch == port->info->tty->termios->c_cc[VSTOP])
149 channel->ch_bd->bd_ops->send_stop_character(channel);
150 spin_unlock_irqrestore(&port->lock, lock_flags);
153 static void jsm_tty_stop_rx(struct uart_port *port)
155 struct jsm_channel *channel = (struct jsm_channel *)port;
157 channel->ch_bd->bd_ops->disable_receiver(channel);
160 static void jsm_tty_break(struct uart_port *port, int break_state)
162 unsigned long lock_flags;
163 struct jsm_channel *channel = (struct jsm_channel *)port;
165 spin_lock_irqsave(&port->lock, lock_flags);
166 if (break_state == -1)
167 channel->ch_bd->bd_ops->send_break(channel);
169 channel->ch_bd->bd_ops->clear_break(channel, 0);
171 spin_unlock_irqrestore(&port->lock, lock_flags);
174 static int jsm_tty_open(struct uart_port *port)
176 struct jsm_board *brd;
178 struct jsm_channel *channel = (struct jsm_channel *)port;
180 /* Get board pointer from our array of majors we have allocated */
181 brd = channel->ch_bd;
184 * Allocate channel buffers for read/write/error.
185 * Set flag, so we don't get trounced on.
187 channel->ch_flags |= (CH_OPENING);
189 /* Drop locks, as malloc with GFP_KERNEL can sleep */
191 if (!channel->ch_rqueue) {
192 channel->ch_rqueue = (u8 *) kmalloc(RQUEUESIZE, GFP_KERNEL);
193 if (!channel->ch_rqueue) {
194 jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
195 "unable to allocate read queue buf");
198 memset(channel->ch_rqueue, 0, RQUEUESIZE);
200 if (!channel->ch_equeue) {
201 channel->ch_equeue = (u8 *) kmalloc(EQUEUESIZE, GFP_KERNEL);
202 if (!channel->ch_equeue) {
203 jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
204 "unable to allocate error queue buf");
207 memset(channel->ch_equeue, 0, EQUEUESIZE);
209 if (!channel->ch_wqueue) {
210 channel->ch_wqueue = (u8 *) kmalloc(WQUEUESIZE, GFP_KERNEL);
211 if (!channel->ch_wqueue) {
212 jsm_printk(INIT, ERR, &channel->ch_bd->pci_dev,
213 "unable to allocate write queue buf");
216 memset(channel->ch_wqueue, 0, WQUEUESIZE);
219 channel->ch_flags &= ~(CH_OPENING);
221 * Initialize if neither terminal is open.
223 jsm_printk(OPEN, INFO, &channel->ch_bd->pci_dev,
224 "jsm_open: initializing channel in open...\n");
227 * Flush input queues.
229 channel->ch_r_head = channel->ch_r_tail = 0;
230 channel->ch_e_head = channel->ch_e_tail = 0;
231 channel->ch_w_head = channel->ch_w_tail = 0;
233 brd->bd_ops->flush_uart_write(channel);
234 brd->bd_ops->flush_uart_read(channel);
236 channel->ch_flags = 0;
237 channel->ch_cached_lsr = 0;
238 channel->ch_stops_sent = 0;
240 channel->ch_c_cflag = port->info->tty->termios->c_cflag;
241 channel->ch_c_iflag = port->info->tty->termios->c_iflag;
242 channel->ch_c_oflag = port->info->tty->termios->c_oflag;
243 channel->ch_c_lflag = port->info->tty->termios->c_lflag;
244 channel->ch_startc = port->info->tty->termios->c_cc[VSTART];
245 channel->ch_stopc = port->info->tty->termios->c_cc[VSTOP];
247 /* Tell UART to init itself */
248 brd->bd_ops->uart_init(channel);
251 * Run param in case we changed anything
253 brd->bd_ops->param(channel);
255 jsm_carrier(channel);
257 channel->ch_open_count++;
259 jsm_printk(OPEN, INFO, &channel->ch_bd->pci_dev, "finish\n");
263 static void jsm_tty_close(struct uart_port *port)
265 struct jsm_board *bd;
267 struct jsm_channel *channel = (struct jsm_channel *)port;
269 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "start\n");
272 ts = channel->uart_port.info->tty->termios;
274 channel->ch_flags &= ~(CH_STOPI);
276 channel->ch_open_count--;
279 * If we have HUPCL set, lower DTR and RTS
281 if (channel->ch_c_cflag & HUPCL) {
282 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev,
283 "Close. HUPCL set, dropping DTR/RTS\n");
286 channel->ch_mostat &= ~(UART_MCR_DTR | UART_MCR_RTS);
287 bd->bd_ops->assert_modem_signals(channel);
290 channel->ch_old_baud = 0;
292 /* Turn off UART interrupts for this port */
293 channel->ch_bd->bd_ops->uart_off(channel);
295 jsm_printk(CLOSE, INFO, &channel->ch_bd->pci_dev, "finish\n");
298 static void jsm_tty_set_termios(struct uart_port *port,
299 struct termios *termios,
300 struct termios *old_termios)
302 unsigned long lock_flags;
303 struct jsm_channel *channel = (struct jsm_channel *)port;
305 spin_lock_irqsave(&port->lock, lock_flags);
306 channel->ch_c_cflag = termios->c_cflag;
307 channel->ch_c_iflag = termios->c_iflag;
308 channel->ch_c_oflag = termios->c_oflag;
309 channel->ch_c_lflag = termios->c_lflag;
310 channel->ch_startc = termios->c_cc[VSTART];
311 channel->ch_stopc = termios->c_cc[VSTOP];
313 channel->ch_bd->bd_ops->param(channel);
314 jsm_carrier(channel);
315 spin_unlock_irqrestore(&port->lock, lock_flags);
318 static const char *jsm_tty_type(struct uart_port *port)
323 static void jsm_tty_release_port(struct uart_port *port)
327 static int jsm_tty_request_port(struct uart_port *port)
332 static void jsm_config_port(struct uart_port *port, int flags)
334 port->type = PORT_JSM;
337 static struct uart_ops jsm_ops = {
338 .tx_empty = jsm_tty_tx_empty,
339 .set_mctrl = jsm_tty_set_mctrl,
340 .get_mctrl = jsm_tty_get_mctrl,
341 .stop_tx = jsm_tty_stop_tx,
342 .start_tx = jsm_tty_start_tx,
343 .send_xchar = jsm_tty_send_xchar,
344 .stop_rx = jsm_tty_stop_rx,
345 .break_ctl = jsm_tty_break,
346 .startup = jsm_tty_open,
347 .shutdown = jsm_tty_close,
348 .set_termios = jsm_tty_set_termios,
349 .type = jsm_tty_type,
350 .release_port = jsm_tty_release_port,
351 .request_port = jsm_tty_request_port,
352 .config_port = jsm_config_port,
358 * Init the tty subsystem. Called once per board after board has been
359 * downloaded and init'ed.
361 int jsm_tty_init(struct jsm_board *brd)
365 struct jsm_channel *ch;
370 jsm_printk(INIT, INFO, &brd->pci_dev, "start\n");
373 * Initialize board structure elements.
376 brd->nasync = brd->maxports;
379 * Allocate channel memory that might not have been allocated
380 * when the driver was first loaded.
382 for (i = 0; i < brd->nasync; i++) {
383 if (!brd->channels[i]) {
386 * Okay to malloc with GFP_KERNEL, we are not at
387 * interrupt context, and there are no locks held.
389 brd->channels[i] = kmalloc(sizeof(struct jsm_channel), GFP_KERNEL);
390 if (!brd->channels[i]) {
391 jsm_printk(CORE, ERR, &brd->pci_dev,
392 "%s:%d Unable to allocate memory for channel struct\n",
395 memset(brd->channels[i], 0, sizeof(struct jsm_channel));
399 ch = brd->channels[0];
400 vaddr = brd->re_map_membase;
402 /* Set up channel variables */
403 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
405 if (!brd->channels[i])
408 spin_lock_init(&ch->ch_lock);
410 if (brd->bd_uart_offset == 0x200)
411 ch->ch_neo_uart = vaddr + (brd->bd_uart_offset * i);
416 /* .25 second delay */
417 ch->ch_close_delay = 250;
419 init_waitqueue_head(&ch->ch_flags_wait);
422 jsm_printk(INIT, INFO, &brd->pci_dev, "finish\n");
426 int jsm_uart_port_init(struct jsm_board *brd)
429 struct jsm_channel *ch;
434 jsm_printk(INIT, INFO, &brd->pci_dev, "start\n");
437 * Initialize board structure elements.
440 brd->nasync = brd->maxports;
442 /* Set up channel variables */
443 for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
445 if (!brd->channels[i])
448 brd->channels[i]->uart_port.irq = brd->irq;
449 brd->channels[i]->uart_port.type = PORT_JSM;
450 brd->channels[i]->uart_port.iotype = UPIO_MEM;
451 brd->channels[i]->uart_port.membase = brd->re_map_membase;
452 brd->channels[i]->uart_port.fifosize = 16;
453 brd->channels[i]->uart_port.ops = &jsm_ops;
454 brd->channels[i]->uart_port.line = brd->channels[i]->ch_portnum + brd->boardnum * 2;
455 if (uart_add_one_port (&jsm_uart_driver, &brd->channels[i]->uart_port))
456 printk(KERN_INFO "Added device failed\n");
458 printk(KERN_INFO "Added device \n");
461 jsm_printk(INIT, INFO, &brd->pci_dev, "finish\n");
465 int jsm_remove_uart_port(struct jsm_board *brd)
468 struct jsm_channel *ch;
473 jsm_printk(INIT, INFO, &brd->pci_dev, "start\n");
476 * Initialize board structure elements.
479 brd->nasync = brd->maxports;
481 /* Set up channel variables */
482 for (i = 0; i < brd->nasync; i++) {
484 if (!brd->channels[i])
487 ch = brd->channels[i];
489 uart_remove_one_port(&jsm_uart_driver, &brd->channels[i]->uart_port);
492 jsm_printk(INIT, INFO, &brd->pci_dev, "finish\n");
496 void jsm_input(struct jsm_channel *ch)
498 struct jsm_board *bd;
499 struct tty_struct *tp;
504 unsigned long lock_flags;
513 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "start\n");
518 tp = ch->uart_port.info->tty;
524 spin_lock_irqsave(&ch->ch_lock, lock_flags);
527 *Figure the number of characters in the buffer.
528 *Exit immediately if none.
533 head = ch->ch_r_head & rmask;
534 tail = ch->ch_r_tail & rmask;
536 data_len = (head - tail) & rmask;
538 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
542 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "start\n");
545 *If the device is not open, or CREAD is off, flush
546 *input data and return immediately.
549 !(tp->termios->c_cflag & CREAD) ) {
551 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
552 "input. dropping %d bytes on port %d...\n", data_len, ch->ch_portnum);
553 ch->ch_r_head = tail;
555 /* Force queue flow control to be released, if needed */
556 jsm_check_queue_flow_control(ch);
558 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
563 * If we are throttled, simply don't read any data.
565 if (ch->ch_flags & CH_STOPI) {
566 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
567 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
568 "Port %d throttled, not reading any data. head: %x tail: %x\n",
569 ch->ch_portnum, head, tail);
573 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "start 2\n");
576 * If the rxbuf is empty and we are not throttled, put as much
577 * as we can directly into the linux TTY flip buffer.
578 * The jsm_rawreadok case takes advantage of carnal knowledge that
579 * the char_buf and the flag_buf are next to each other and
580 * are each of (2 * TTY_FLIPBUF_SIZE) size.
582 * NOTE: if(!tty->real_raw), the call to ldisc.receive_buf
583 *actually still uses the flag buffer, so you can't
584 *use it for input data
588 flip_len = MYFLIPLEN;
590 flip_len = 2 * TTY_FLIPBUF_SIZE;
592 flip_len = TTY_FLIPBUF_SIZE - tp->flip.count;
594 len = min(data_len, flip_len);
595 len = min(len, (N_TTY_BUF_SIZE - 1) - tp->read_cnt);
598 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
599 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "jsm_input 1\n");
604 * If we're bypassing flip buffers on rx, we can blast it
605 * right into the beginning of the buffer.
609 if (ch->ch_flags & CH_FLIPBUF_IN_USE) {
610 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
611 "JSM - FLIPBUF in use. delaying input\n");
612 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
615 ch->ch_flags |= CH_FLIPBUF_IN_USE;
616 buf = ch->ch_bd->flipbuf;
619 buf = tp->flip.char_buf;
620 buf2 = tp->flip.flag_buf;
623 buf = tp->flip.char_buf_ptr;
624 buf2 = tp->flip.flag_buf_ptr;
630 * n now contains the most amount of data we can copy,
631 * bounded either by the flip buffer size or the amount
632 * of data the card actually has pending...
635 s = ((head >= tail) ? head : RQUEUESIZE) - tail;
641 memcpy(buf, ch->ch_rqueue + tail, s);
643 /* buf2 is only set when port isn't raw */
645 memcpy(buf2, ch->ch_equeue + tail, s);
652 /* Flip queue if needed */
657 * In high performance mode, we don't have to update
658 * flag_buf or any of the counts or pointers into flip buf.
660 if (!jsm_rawreadok) {
661 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
662 for (i = 0; i < len; i++) {
664 * Give the Linux ld the flags in the
667 if (tp->flip.flag_buf_ptr[i] & UART_LSR_BI)
668 tp->flip.flag_buf_ptr[i] = TTY_BREAK;
669 else if (tp->flip.flag_buf_ptr[i] & UART_LSR_PE)
670 tp->flip.flag_buf_ptr[i] = TTY_PARITY;
671 else if (tp->flip.flag_buf_ptr[i] & UART_LSR_FE)
672 tp->flip.flag_buf_ptr[i] = TTY_FRAME;
674 tp->flip.flag_buf_ptr[i] = TTY_NORMAL;
677 memset(tp->flip.flag_buf_ptr, 0, len);
680 tp->flip.char_buf_ptr += len;
681 tp->flip.flag_buf_ptr += len;
682 tp->flip.count += len;
684 else if (!tp->real_raw) {
685 if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
686 for (i = 0; i < len; i++) {
688 * Give the Linux ld the flags in the
691 if (tp->flip.flag_buf_ptr[i] & UART_LSR_BI)
692 tp->flip.flag_buf_ptr[i] = TTY_BREAK;
693 else if (tp->flip.flag_buf_ptr[i] & UART_LSR_PE)
694 tp->flip.flag_buf_ptr[i] = TTY_PARITY;
695 else if (tp->flip.flag_buf_ptr[i] & UART_LSR_FE)
696 tp->flip.flag_buf_ptr[i] = TTY_FRAME;
698 tp->flip.flag_buf_ptr[i] = TTY_NORMAL;
701 memset(tp->flip.flag_buf, 0, len);
705 * If we're doing raw reads, jam it right into the
706 * line disc bypassing the flip buffers.
710 ch->ch_r_tail = tail & rmask;
711 ch->ch_e_tail = tail & rmask;
713 jsm_check_queue_flow_control(ch);
715 /* !!! WE *MUST* LET GO OF ALL LOCKS BEFORE CALLING RECEIVE BUF !!! */
717 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
719 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
720 "jsm_input. %d real_raw len:%d calling receive_buf for board %d\n",
721 __LINE__, len, ch->ch_bd->boardnum);
722 tp->ldisc.receive_buf(tp, ch->ch_bd->flipbuf, NULL, len);
724 /* Allow use of channel flip buffer again */
725 spin_lock_irqsave(&ch->ch_lock, lock_flags);
726 ch->ch_flags &= ~CH_FLIPBUF_IN_USE;
727 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
730 ch->ch_r_tail = tail & rmask;
731 ch->ch_e_tail = tail & rmask;
733 jsm_check_queue_flow_control(ch);
735 /* !!! WE *MUST* LET GO OF ALL LOCKS BEFORE CALLING RECEIVE BUF !!! */
736 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
738 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
739 "jsm_input. %d not real_raw len:%d calling receive_buf for board %d\n",
740 __LINE__, len, ch->ch_bd->boardnum);
742 tp->ldisc.receive_buf(tp, tp->flip.char_buf, tp->flip.flag_buf, len);
745 ch->ch_r_tail = tail & rmask;
746 ch->ch_e_tail = tail & rmask;
748 jsm_check_queue_flow_control(ch);
750 spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
752 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
753 "jsm_input. %d not jsm_read raw okay scheduling flip\n", __LINE__);
754 tty_schedule_flip(tp);
757 jsm_printk(IOCTL, INFO, &ch->ch_bd->pci_dev, "finish\n");
760 static void jsm_carrier(struct jsm_channel *ch)
762 struct jsm_board *bd;
764 int virt_carrier = 0;
765 int phys_carrier = 0;
767 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev, "start\n");
776 if (ch->ch_mistat & UART_MSR_DCD) {
777 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
778 "mistat: %x D_CD: %x\n", ch->ch_mistat, ch->ch_mistat & UART_MSR_DCD);
782 if (ch->ch_c_cflag & CLOCAL)
785 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
786 "DCD: physical: %d virt: %d\n", phys_carrier, virt_carrier);
789 * Test for a VIRTUAL carrier transition to HIGH.
791 if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
794 * When carrier rises, wake any threads waiting
795 * for carrier in the open routine.
798 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
799 "carrier: virt DCD rose\n");
801 if (waitqueue_active(&(ch->ch_flags_wait)))
802 wake_up_interruptible(&ch->ch_flags_wait);
806 * Test for a PHYSICAL carrier transition to HIGH.
808 if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
811 * When carrier rises, wake any threads waiting
812 * for carrier in the open routine.
815 jsm_printk(CARR, INFO, &ch->ch_bd->pci_dev,
816 "carrier: physical DCD rose\n");
818 if (waitqueue_active(&(ch->ch_flags_wait)))
819 wake_up_interruptible(&ch->ch_flags_wait);
823 * Test for a PHYSICAL transition to low, so long as we aren't
824 * currently ignoring physical transitions (which is what "virtual
825 * carrier" indicates).
827 * The transition of the virtual carrier to low really doesn't
828 * matter... it really only means "ignore carrier state", not
829 * "make pretend that carrier is there".
831 if ((virt_carrier == 0) && ((ch->ch_flags & CH_CD) != 0)
832 && (phys_carrier == 0)) {
834 * When carrier drops:
836 * Drop carrier on all open units.
838 * Flush queues, waking up any task waiting in the
841 * Send a hangup to the control terminal.
843 * Enable all select calls.
845 if (waitqueue_active(&(ch->ch_flags_wait)))
846 wake_up_interruptible(&ch->ch_flags_wait);
850 * Make sure that our cached values reflect the current reality.
852 if (virt_carrier == 1)
853 ch->ch_flags |= CH_FCAR;
855 ch->ch_flags &= ~CH_FCAR;
857 if (phys_carrier == 1)
858 ch->ch_flags |= CH_CD;
860 ch->ch_flags &= ~CH_CD;
864 void jsm_check_queue_flow_control(struct jsm_channel *ch)
868 /* Store how much space we have left in the queue */
869 if ((qleft = ch->ch_r_tail - ch->ch_r_head - 1) < 0)
870 qleft += RQUEUEMASK + 1;
873 * Check to see if we should enforce flow control on our queue because
874 * the ld (or user) isn't reading data out of our queue fast enuf.
876 * NOTE: This is done based on what the current flow control of the
879 * 1) HWFLOW (RTS) - Turn off the UART's Receive interrupt.
880 * This will cause the UART's FIFO to back up, and force
881 * the RTS signal to be dropped.
882 * 2) SWFLOW (IXOFF) - Keep trying to send a stop character to
883 * the other side, in hopes it will stop sending data to us.
884 * 3) NONE - Nothing we can do. We will simply drop any extra data
885 * that gets sent into us when the queue fills up.
889 if (ch->ch_c_cflag & CRTSCTS) {
890 if(!(ch->ch_flags & CH_RECEIVER_OFF)) {
891 ch->ch_bd->bd_ops->disable_receiver(ch);
892 ch->ch_flags |= (CH_RECEIVER_OFF);
893 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
894 "Internal queue hit hilevel mark (%d)! Turning off interrupts.\n",
899 else if (ch->ch_c_iflag & IXOFF) {
900 if (ch->ch_stops_sent <= MAX_STOPS_SENT) {
901 ch->ch_bd->bd_ops->send_stop_character(ch);
903 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
904 "Sending stop char! Times sent: %x\n", ch->ch_stops_sent);
910 * Check to see if we should unenforce flow control because
911 * ld (or user) finally read enuf data out of our queue.
913 * NOTE: This is done based on what the current flow control of the
916 * 1) HWFLOW (RTS) - Turn back on the UART's Receive interrupt.
917 * This will cause the UART's FIFO to raise RTS back up,
918 * which will allow the other side to start sending data again.
919 * 2) SWFLOW (IXOFF) - Send a start character to
920 * the other side, so it will start sending data to us again.
921 * 3) NONE - Do nothing. Since we didn't do anything to turn off the
922 * other side, we don't need to do anything now.
924 if (qleft > (RQUEUESIZE / 2)) {
926 if (ch->ch_c_cflag & CRTSCTS) {
927 if (ch->ch_flags & CH_RECEIVER_OFF) {
928 ch->ch_bd->bd_ops->enable_receiver(ch);
929 ch->ch_flags &= ~(CH_RECEIVER_OFF);
930 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev,
931 "Internal queue hit lowlevel mark (%d)! Turning on interrupts.\n",
936 else if (ch->ch_c_iflag & IXOFF && ch->ch_stops_sent) {
937 ch->ch_stops_sent = 0;
938 ch->ch_bd->bd_ops->send_start_character(ch);
939 jsm_printk(READ, INFO, &ch->ch_bd->pci_dev, "Sending start char!\n");
947 * Take data from the user or kernel and send it out to the FEP.
948 * In here exists all the Transparent Print magic as well.
950 int jsm_tty_write(struct uart_port *port)
952 int bufcount = 0, n = 0;
953 int data_count = 0,data_count1 =0;
958 int temp_tail = port->info->xmit.tail;
959 struct jsm_channel *channel = (struct jsm_channel *)port;
962 head = (channel->ch_w_head) & tmask;
963 tail = (channel->ch_w_tail) & tmask;
965 if ((bufcount = tail - head - 1) < 0)
966 bufcount += WQUEUESIZE;
971 remain = WQUEUESIZE - head;
976 while ((port->info->xmit.head != temp_tail) &&
977 (data_count < remain)) {
978 channel->ch_wqueue[head++] =
979 port->info->xmit.buf[temp_tail];
982 temp_tail &= (UART_XMIT_SIZE - 1);
985 if (data_count == remain) head = 0;
991 while ((port->info->xmit.head != temp_tail) &&
992 (data_count1 < remain)) {
993 channel->ch_wqueue[head++] =
994 port->info->xmit.buf[temp_tail];
997 temp_tail &= (UART_XMIT_SIZE - 1);
1003 port->info->xmit.tail = temp_tail;
1005 data_count += data_count1;
1008 channel->ch_w_head = head;
1012 channel->ch_bd->bd_ops->copy_data_from_queue_to_uart(channel);