14 #include <linux/errno.h>
15 #include <linux/tty.h>
17 #include <linux/serial.h>
20 #include <linux/module.h>
21 #include <linux/pci.h>
22 #include <linux/serial_core.h>
24 #include <linux/slab.h>
30 #define LOGICAL_PORTS 2
31 #define PORTS_PER_CARD 2
32 #define LOGICAL_PORTS_PER_CARD (PORTS_PER_CARD * LOGICAL_PORTS)
34 #define MAX_LOGICAL_PORTS (LOGICAL_PORTS_PER_CARD * MAX_CARDS)
37 #define GET_PORT_FROM_SIO_IR(_x) (_x & SIO_IR_SA) ? 0 : 1
44 #define GET_PHYSICAL_PORT(_x) ((_x) >> 1)
45 #define GET_LOGICAL_PORT(_x) ((_x) & 1)
46 #define IS_PHYSICAL_PORT(_x) !((_x) & 1)
47 #define IS_RS232(_x) !((_x) & 1)
49 static unsigned int Num_of_ioc3_cards;
50 static unsigned int Submodule_slot;
54 #define DPRINT_CONFIG(_x...) ;
56 #define NOT_PROGRESS() ;
61 #define FIFO_SIZE (MAX_CHARS-1)
64 #define DEVICE_NAME "ttySIOC"
65 #define DEVICE_MAJOR 204
66 #define DEVICE_MINOR 116
70 #define NCS_PARITY 0x2
71 #define NCS_FRAMING 0x4
72 #define NCS_OVERRUN 0x8
75 #define MIN_BAUD_SUPPORTED 1200
76 #define MAX_BAUD_SUPPORTED 115200
83 #define N_DATA_READY 0x01
84 #define N_OUTPUT_LOWAT 0x02
86 #define N_PARITY_ERROR 0x08
87 #define N_FRAMING_ERROR 0x10
88 #define N_OVERRUN_ERROR 0x20
92 #define N_ALL_INPUT (N_DATA_READY | N_BREAK \
93 | N_PARITY_ERROR | N_FRAMING_ERROR \
94 | N_OVERRUN_ERROR | N_DDCD | N_DCTS)
96 #define N_ALL_OUTPUT N_OUTPUT_LOWAT
98 #define N_ALL_ERRORS (N_PARITY_ERROR | N_FRAMING_ERROR \
101 #define N_ALL (N_DATA_READY | N_OUTPUT_LOWAT | N_BREAK \
102 | N_PARITY_ERROR | N_FRAMING_ERROR \
103 | N_OVERRUN_ERROR | N_DDCD | N_DCTS)
105 #define SER_CLK_SPEED(prediv) ((22000000 << 1) / prediv)
106 #define SER_DIVISOR(x, clk) (((clk) + (x) * 8) / ((x) * 16))
107 #define DIVISOR_TO_BAUD(div, clk) ((clk) / 16 / (div))
110 #define LCR_MASK_BITS_CHAR (UART_LCR_WLEN5 | UART_LCR_WLEN6 \
111 | UART_LCR_WLEN7 | UART_LCR_WLEN8)
112 #define LCR_MASK_STOP_BITS (UART_LCR_STOP)
114 #define PENDING(_a, _p) (readl(&(_p)->vma->sio_ir) & (_a)->ic_enable)
116 #define RING_BUF_SIZE 4096
117 #define BUF_SIZE_BIT SBBR_L_SIZE
118 #define PROD_CONS_MASK PROD_CONS_PTR_4K
120 #define TOTAL_RING_BUF_SIZE (RING_BUF_SIZE * 4)
182 #define TX_LOWAT_LATENCY 1000
183 #define TX_LOWAT_HZ (1000000 / TX_LOWAT_LATENCY)
184 #define TX_LOWAT_CHARS(baud) (baud / 10 / TX_LOWAT_HZ)
187 #define INPUT_HIGH 0x01
194 #define LOWAT_WRITTEN 0x04
195 #define READ_ABORTED 0x08
199 #define INPUT_ENABLE 0x10
273 #define RING_ANY_VALID \
274 ((uint32_t)(RXSB_MODEM_VALID | RXSB_DATA_VALID) * 0x01010101)
276 #define ring_sc u.s.sc
277 #define ring_data u.s.data
278 #define ring_allsc u.all.allsc
281 #define ENTRIES_PER_RING (RING_BUF_SIZE / (int) sizeof(struct ring_entry))
297 #define RING(_p, _wh) &(((struct ring_buffer *)((_p)->ip_cpu_ringbuf))->_wh)
300 #define MAXITER 10000000
316 for (prediv = 6; prediv < 64; prediv++) {
322 diff = actual_baud -
baud;
327 if (diff * 100 <= actual_baud)
343 writeb((
unsigned char)divisor, &uart->iu_dll);
344 writeb((
unsigned char)(divisor >> 8), &uart->iu_dlm);
367 if (the_port == &card_ptr->
ic_port[ii].icp_uart_port[jj])
368 return card_ptr->
ic_port[ii].icp_port;
385 int reset_loop_counter = 0xfffff;
394 if (reset_loop_counter-- <= 0) {
396 "IOC3 unable to come out of reset"
397 " scr 0x%x\n", sio_cr);
442 if (port->
ip_hooks == &hooks_array[0]) {
443 unsigned long ring_pci_addr;
446 sbbr_l = &idd->
vma->sbbr_l;
447 sbbr_h = &idd->
vma->sbbr_h;
450 __func__, (
void *)ring_pci_addr));
486 if ((port->
ip_card->ic_enable & mask) != mask) {
496 static inline int local_open(
struct ioc3_port *port)
546 static inline int set_rx_timeout(
struct ioc3_port *port,
int timeout)
559 threshold = timeout * port->
ip_baud / 4000;
566 port->
ip_sscr &= ~SSCR_RX_THRESHOLD;
573 timeout = timeout *
SRTR_HZ / 100;
591 int baud,
int byte_size,
int stop_bits,
int parenb,
int parodd)
596 DPRINT_CONFIG((
"%s: line %d baud %d byte_size %d stop %d parenb %d "
599 baud, byte_size, stop_bits, parenb, parodd));
601 if (set_baud(port, baud))
668 set_rx_timeout(port, 2);
681 int prod_ptr, cons_ptr, total = 0;
682 struct ring *outring;
699 while ((prod_ptr != cons_ptr) && (len > 0)) {
706 entry->ring_allsc = 0;
709 for (xx = 0; (xx < 4) && (len > 0); xx++) {
710 entry->ring_data[
xx] = *buf++;
743 if (!uart_tx_stopped(port->
ip_port)) {
764 if (port->
ip_card->ic_enable & mask) {
766 port->
ip_card->ic_enable &= ~mask;
776 static int set_notification(
struct ioc3_port *port,
int mask,
int set_on)
783 intrbits = sscrbits = 0;
797 enable_intrs(port, intrbits);
801 disable_intrs(port, intrbits);
810 if (port->
ip_notify & (N_DATA_READY | N_DDCD))
825 static inline int set_mcr(
struct uart_port *the_port,
826 int mask1,
int mask2)
828 struct ioc3_port *port = get_ioc3_port(the_port);
848 mcr = (shadow & 0xff000000) >> 24;
895 static void transmit_chars(
struct uart_port *the_port)
901 struct ioc3_port *port = get_ioc3_port(the_port);
909 state = the_port->
state;
910 tty = state->
port.tty;
918 head = state->
xmit.head;
919 tail = state->
xmit.tail;
920 start = (
char *)&state->
xmit.buf[tail];
924 if (xmit_count > 0) {
925 result =
do_write(port, start, xmit_count);
934 start = (
char *)&state->
xmit.buf[tail];
941 set_notification(port, N_OUTPUT_LOWAT, 0);
943 set_notification(port, N_OUTPUT_LOWAT, 1);
954 ioc3_change_speed(
struct uart_port *the_port,
957 struct ioc3_port *port = get_ioc3_port(the_port);
958 unsigned int cflag, iflag;
960 int new_parity = 0, new_parity_enable = 0, new_stop = 0, new_data = 8;
966 switch (cflag &
CSIZE) {
988 new_parity_enable = 1;
994 DPRINT_CONFIG((
"%s: returned baud %d for line %d\n", __func__, baud,
1003 state->
port.tty->low_latency = 1;
1013 if (!(cflag &
CREAD)) {
1030 "config_port(baud %d data %d stop %d penable %d "
1031 " parity %d), notification 0x%x\n",
1032 __func__, (
void *)port, the_port->
line, cflag, baud,
1033 new_data, new_stop, new_parity_enable, new_parity,
1036 if ((config_port(port, baud,
1040 new_parity)) >= 0) {
1049 static inline int ic3_startup_local(
struct uart_port *the_port)
1058 port = get_ioc3_port(the_port);
1076 static void ioc3_cb_output_lowat(
struct ioc3_port *port)
1078 unsigned long pflags;
1083 transmit_chars(port->
ip_port);
1084 spin_unlock_irqrestore(&port->
ip_port->lock, pflags);
1093 static void ioc3_cb_post_ncs(
struct uart_port *the_port,
int ncs)
1097 icount = &the_port->
icount;
1119 int prod_ptr, cons_ptr, total;
1120 struct ioc3_port *port = get_ioc3_port(the_port);
1121 struct ring *inring;
1159 if (prod_ptr == cons_ptr) {
1187 if (prod_ptr == cons_ptr) {
1211 loop_counter = 0xfffff;
1214 while ((prod_ptr != cons_ptr) && (len > 0)) {
1217 if (loop_counter-- <= 0) {
1219 "possible hang condition/"
1220 "port stuck on read (line %d).\n",
1241 for (byte_num = 0; byte_num < 4 && len > 0; byte_num++) {
1242 sc = &(entry->ring_sc[byte_num]);
1267 *sc &= ~RXSB_MODEM_VALID;
1279 cons_ptr += (
int)
sizeof
1294 port.delta_msr_wait);
1303 if (*sc & RXSB_MODEM_VALID) {
1307 ioc3_cb_post_ncs(the_port, NCS_OVERRUN);
1310 *sc &= ~RXSB_MODEM_VALID;
1334 ioc3_cb_post_ncs(the_port,
1340 ioc3_cb_post_ncs(the_port,
1346 (the_port, NCS_BREAK);
1351 if (*sc & RXSB_DATA_VALID) {
1352 *sc &= ~RXSB_DATA_VALID;
1353 *buf = entry->ring_data[byte_num];
1394 static int receive_chars(
struct uart_port *the_port)
1398 int read_count = 0, read_room,
flip = 0;
1400 struct ioc3_port *port = get_ioc3_port(the_port);
1401 unsigned long pflags;
1406 if (!state->
port.tty)
1413 tty = state->
port.tty;
1416 if (read_count > 0) {
1418 read_room = tty_insert_flip_string(tty, ch, read_count);
1419 the_port->
icount.rx += read_count;
1421 spin_unlock_irqrestore(&the_port->
lock, pflags);
1439 unsigned int pending)
1443 unsigned int rx_high_rd_aborted = 0;
1444 unsigned long flags;
1449 unsigned int sio_ir;
1451 card_ptr = idd->
data[is->
id];
1478 if (loop_counter-- <= 0) {
1480 "possible hang condition/"
1481 "port stuck on interrupt (line %d).\n",
1495 shadow & SHADOW_DCD);
1497 (&the_port->
state->port.delta_msr_wait);
1499 && !(shadow & SHADOW_DCD)) {
1502 shadow & SHADOW_DCD);
1517 (&the_port->
state->port.delta_msr_wait);
1549 if ((sio_ir =
PENDING(card_ptr, idd))
1552 rx_high_rd_aborted++;
1569 ioc3_cb_output_lowat(port);
1582 ioc3_cb_output_lowat(port);
1588 sio_ir =
PENDING(card_ptr, idd);
1601 & (N_DATA_READY | N_DDCD))) {
1612 sio_ir =
PENDING(card_ptr, idd);
1618 if (rx_high_rd_aborted && (sio_ir == hooks->
intr_rx_high)) {
1621 }
while (sio_ir & hooks->
intr_all);
1623 spin_unlock_irqrestore(&port->
ip_lock, flags);
1638 unsigned int pending)
1648 ret |= ioc3uart_intr_one(is, idd, pending & SIO_IR_SA);
1650 ret |= ioc3uart_intr_one(is, idd, pending & SIO_IR_SB);
1660 static const char *ic3_type(
struct uart_port *the_port)
1663 return "SGI IOC3 Serial [rs232]";
1665 return "SGI IOC3 Serial [rs422]";
1673 static unsigned int ic3_tx_empty(
struct uart_port *the_port)
1675 unsigned int ret = 0;
1676 struct ioc3_port *port = get_ioc3_port(the_port);
1688 static void ic3_stop_tx(
struct uart_port *the_port)
1690 struct ioc3_port *port = get_ioc3_port(the_port);
1693 set_notification(port, N_OUTPUT_LOWAT, 0);
1701 static void ic3_stop_rx(
struct uart_port *the_port)
1703 struct ioc3_port *port = get_ioc3_port(the_port);
1714 static void null_void_function(
struct uart_port *the_port)
1723 static void ic3_shutdown(
struct uart_port *the_port)
1725 unsigned long port_flags;
1729 port = get_ioc3_port(the_port);
1733 state = the_port->
state;
1737 set_notification(port,
N_ALL, 0);
1738 spin_unlock_irqrestore(&the_port->
lock, port_flags);
1747 static void ic3_set_mctrl(
struct uart_port *the_port,
unsigned int mctrl)
1749 unsigned char mcr = 0;
1770 static unsigned int ic3_get_mctrl(
struct uart_port *the_port)
1772 struct ioc3_port *port = get_ioc3_port(the_port);
1774 unsigned int ret = 0;
1780 if (shadow & SHADOW_DCD)
1794 static void ic3_start_tx(
struct uart_port *the_port)
1796 struct ioc3_port *port = get_ioc3_port(the_port);
1799 set_notification(port, N_OUTPUT_LOWAT, 1);
1800 enable_intrs(port, port->
ip_hooks->intr_tx_mt);
1810 static void ic3_break_ctl(
struct uart_port *the_port,
int break_state)
1819 static int ic3_startup(
struct uart_port *the_port)
1824 unsigned long port_flags;
1830 port = get_ioc3_port(the_port);
1845 retval = ic3_startup_local(the_port);
1846 spin_unlock_irqrestore(&the_port->
lock, port_flags);
1858 ic3_set_termios(
struct uart_port *the_port,
1861 unsigned long port_flags;
1864 ioc3_change_speed(the_port, termios, old_termios);
1865 spin_unlock_irqrestore(&the_port->
lock, port_flags);
1873 static int ic3_request_port(
struct uart_port *port)
1879 static struct uart_ops ioc3_ops = {
1880 .tx_empty = ic3_tx_empty,
1881 .set_mctrl = ic3_set_mctrl,
1882 .get_mctrl = ic3_get_mctrl,
1883 .stop_tx = ic3_stop_tx,
1884 .start_tx = ic3_start_tx,
1885 .stop_rx = ic3_stop_rx,
1886 .enable_ms = null_void_function,
1887 .break_ctl = ic3_break_ctl,
1888 .startup = ic3_startup,
1889 .shutdown = ic3_shutdown,
1890 .set_termios = ic3_set_termios,
1892 .release_port = null_void_function,
1893 .request_port = ic3_request_port,
1902 .driver_name =
"ioc3_serial",
1915 static inline int ioc3_serial_core_attach(
struct ioc3_submodule *is,
1925 __func__, pdev, (
void *)card_ptr));
1933 the_port = &card_ptr->
ic_port[phys_port].
1935 port = card_ptr->
ic_port[phys_port].icp_port;
1938 DPRINT_CONFIG((
"%s: attach the_port 0x%p / port 0x%p [%d/%d]\n",
1939 __func__, (
void *)the_port, (
void *)port,
1944 the_port->
iobase = (pdev->
bus->number << 16) | ii;
1945 the_port->
line = (Num_of_ioc3_cards << 2) | ii;
1949 the_port->
ops = &ioc3_ops;
1951 the_port->
dev = &pdev->
dev;
1955 "%s: unable to add port %d bus %d\n",
1956 __func__, the_port->
line, pdev->
bus->number);
1959 the_port->
line, the_port->
irq, pdev->
bus->number));
2029 ": unable to get memory for the IOC3\n");
2032 idd->
data[is->
id] = card_ptr;
2033 Submodule_slot = is->
id;
2039 pci_write_config_dword(pdev,
PCI_LAT, 0xff00);
2049 "IOC3 serial memory not available for port\n");
2058 ports[phys_port] =
port;
2066 port->
ip_hooks = &hooks_array[phys_port];
2069 if (phys_port == 0) {
2074 "ip_uart_regs 0x%p\n",
2088 "ip_dma_ringbuf 0x%p, ip_inring 0x%p "
2089 "ip_outring 0x%p\n",
2101 "ip_uart_regs 0x%p\n",
2114 "ip_dma_ringbuf 0x%p, ip_inring 0x%p "
2115 "ip_outring 0x%p\n",
2125 phys_port, (
void *)port, (
void *)card_ptr));
2136 phys_port, (
void *)port,
2144 if ((ret = ioc3_serial_core_attach(is, idd)))
2147 Num_of_ioc3_cards++;
2153 for (cnt = 0; cnt < phys_port; cnt++)
2162 .probe = ioc3uart_probe,
2163 .remove = ioc3uart_remove,
2166 .intr = ioc3uart_intr,
2173 static int __init ioc3uart_init(
void)
2180 "%s: Couldn't register IOC3 uart serial driver\n",
2190 static void __exit ioc3uart_exit(
void)