38 #define DBGINFO(fmt) if (debug_level >= DEBUG_LEVEL_INFO) printk fmt
39 #define DBGERR(fmt) if (debug_level >= DEBUG_LEVEL_ERROR) printk fmt
40 #define DBGBH(fmt) if (debug_level >= DEBUG_LEVEL_BH) printk fmt
41 #define DBGISR(fmt) if (debug_level >= DEBUG_LEVEL_ISR) printk fmt
42 #define DBGDATA(info, buf, size, label) if (debug_level >= DEBUG_LEVEL_DATA) trace_block((info), (buf), (size), (label))
47 #include <linux/module.h>
48 #include <linux/errno.h>
49 #include <linux/signal.h>
50 #include <linux/sched.h>
53 #include <linux/pci.h>
54 #include <linux/tty.h>
56 #include <linux/serial.h>
58 #include <linux/string.h>
59 #include <linux/fcntl.h>
60 #include <linux/ptrace.h>
64 #include <linux/slab.h>
65 #include <linux/netdevice.h>
71 #include <linux/bitops.h>
73 #include <linux/hdlc.h>
74 #include <linux/synclink.h>
79 #include <asm/types.h>
80 #include <asm/uaccess.h>
82 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE))
83 #define SYNCLINK_GENERIC_HDLC 1
85 #define SYNCLINK_GENERIC_HDLC 0
92 static char *tty_driver_name =
"synclink_gt";
93 static char *tty_dev_prefix =
"ttySLG";
95 #define MGSL_MAGIC 0x5401
96 #define MAX_DEVICES 32
110 .
name =
"synclink_gt",
111 .id_table = pci_table,
116 static bool pci_registered;
121 static struct slgt_info *slgt_device_list;
122 static int slgt_device_count;
125 static int debug_level;
132 MODULE_PARM_DESC(ttymajor,
"TTY major device number override: 0=auto assigned");
133 MODULE_PARM_DESC(debug_level,
"Debug syslog output: 0=disabled, 1 to 5=increasing detail");
134 MODULE_PARM_DESC(maxframe,
"Maximum frame size used by device (4096 to 65535)");
147 static int put_char(
struct tty_struct *tty,
unsigned char ch);
148 static void send_xchar(
struct tty_struct *tty,
char ch);
149 static void wait_until_sent(
struct tty_struct *tty,
int timeout);
150 static int write_room(
struct tty_struct *tty);
151 static void flush_chars(
struct tty_struct *tty);
152 static void flush_buffer(
struct tty_struct *tty);
154 static void tx_release(
struct tty_struct *tty);
156 static int ioctl(
struct tty_struct *tty,
unsigned int cmd,
unsigned long arg);
157 static int chars_in_buffer(
struct tty_struct *tty);
158 static void throttle(
struct tty_struct * tty);
159 static void unthrottle(
struct tty_struct * tty);
160 static int set_break(
struct tty_struct *tty,
int break_state);
165 #if SYNCLINK_GENERIC_HDLC
166 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
178 #define SLGT_MAX_PORTS 4
179 #define SLGT_REG_SIZE 256
190 static void init_cond_wait(
struct cond_wait *
w,
unsigned int data);
212 #define set_desc_buffer(a,b) (a).pbuf = cpu_to_le32((unsigned int)(b))
213 #define set_desc_next(a,b) (a).next = cpu_to_le32((unsigned int)(b))
214 #define set_desc_count(a,b)(a).count = cpu_to_le16((unsigned short)(b))
215 #define set_desc_eof(a,b) (a).status = cpu_to_le16((b) ? (le16_to_cpu((a).status) | BIT0) : (le16_to_cpu((a).status) & ~BIT0))
216 #define set_desc_status(a, b) (a).status = cpu_to_le16((unsigned short)(b))
217 #define desc_count(a) (le16_to_cpu((a).count))
218 #define desc_status(a) (le16_to_cpu((a).status))
219 #define desc_complete(a) (le16_to_cpu((a).status) & BIT15)
220 #define desc_eof(a) (le16_to_cpu((a).status) & BIT2)
221 #define desc_crc_error(a) (le16_to_cpu((a).status) & BIT1)
222 #define desc_abort(a) (le16_to_cpu((a).status) & BIT0)
223 #define desc_residue(a) ((le16_to_cpu((a).status) & 0x38) >> 3)
352 #if SYNCLINK_GENERIC_HDLC
376 #define BH_TRANSMIT 2
378 #define IO_PIN_SHUTDOWN_LIMIT 100
380 #define DMABUFSIZE 256
381 #define DESC_LIST_SIZE 4096
383 #define MASK_PARITY BIT1
384 #define MASK_FRAMING BIT0
385 #define MASK_BREAK BIT14
386 #define MASK_OVERRUN BIT4
413 #define RXBREAK BIT14
414 #define IRQ_TXDATA BIT13
415 #define IRQ_TXIDLE BIT12
416 #define IRQ_TXUNDER BIT11
417 #define IRQ_RXDATA BIT10
418 #define IRQ_RXIDLE BIT9
419 #define IRQ_RXBREAK BIT9
420 #define IRQ_RXOVER BIT8
425 #define IRQ_ALL 0x3ff0
426 #define IRQ_MASTER BIT0
428 #define slgt_irq_on(info, mask) \
429 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) | (mask)))
430 #define slgt_irq_off(info, mask) \
431 wr_reg16((info), SCR, (unsigned short)(rd_reg16((info), SCR) & ~(mask)))
461 static void free_rbufs(
struct slgt_info *
info,
unsigned int first,
unsigned int last);
499 static void rx_timeout(
unsigned long context);
507 static int get_txidle(
struct slgt_info *
info,
int __user *idle_mode);
508 static int set_txidle(
struct slgt_info *
info,
int idle_mode);
513 static int wait_mgsl_event(
struct slgt_info *
info,
int __user *mask_ptr);
516 unsigned int set,
unsigned int clear);
517 static int set_break(
struct tty_struct *tty,
int break_state);
532 static void device_init(
int adapter_num,
struct pci_dev *pdev);
559 linecount = (count > 16) ? 16 : count;
560 for(i=0; i < linecount; i++)
561 printk(
"%02X ",(
unsigned char)data[
i]);
564 for(i=0;i<linecount;i++) {
565 if (data[i]>=040 && data[i]<=0176)
576 #define DBGDATA(info, buf, size, label)
580 static void dump_tbufs(
struct slgt_info *info)
585 printk(
"%d: count=%04X status=%04X\n",
590 #define DBGTBUF(info)
594 static void dump_rbufs(
struct slgt_info *info)
599 printk(
"%d: count=%04X status=%04X\n",
604 #define DBGRBUF(info)
607 static inline int sanity_check(
struct slgt_info *info,
char *devname,
const char *
name)
611 printk(
"null struct slgt_info for (%s) in %s\n", devname, name);
615 printk(
"bad magic number struct slgt_info (%s) in %s\n", devname, name);
633 static void ldisc_receive_buf(
struct tty_struct *tty,
634 const __u8 *data,
char *
flags,
int count)
641 if (ld->
ops->receive_buf)
642 ld->
ops->receive_buf(tty, data, flags, count);
656 if (line >= slgt_device_count) {
661 info = slgt_device_list;
662 while(info && info->
line != line)
664 if (sanity_check(info, tty->
name,
"open"))
672 info->
port.tty = tty;
691 spin_unlock_irqrestore(&info->
netlock, flags);
696 spin_unlock_irqrestore(&info->
netlock, flags);
698 if (info->
port.count == 1) {
700 retval = startup(info);
707 retval = block_til_ready(tty, filp, info);
731 if (sanity_check(info, tty->
name,
"close"))
740 wait_until_sent(tty, info->
timeout);
758 if (sanity_check(info, tty->
name,
"hangup"))
768 info->
port.count = 0;
771 spin_unlock_irqrestore(&info->
port.lock, flags);
788 !(tty->termios.c_cflag &
CBAUD)) {
792 spin_unlock_irqrestore(&info->
lock,flags);
797 tty->termios.c_cflag &
CBAUD) {
799 if (!(tty->termios.c_cflag &
CRTSCTS) ||
805 spin_unlock_irqrestore(&info->
lock,flags);
810 !(tty->termios.c_cflag &
CRTSCTS)) {
816 static void update_tx_timer(
struct slgt_info *info)
823 int timeout = (tbuf_bytes(info) * 7) + 1000;
829 const unsigned char *
buf,
int count)
835 if (sanity_check(info, tty->
name,
"write"))
855 if (tx_load(info, buf, count))
859 spin_unlock_irqrestore(&info->
lock, flags);
864 static int put_char(
struct tty_struct *tty,
unsigned char ch)
870 if (sanity_check(info, tty->
name,
"put_char"))
880 spin_unlock_irqrestore(&info->
lock,flags);
884 static void send_xchar(
struct tty_struct *tty,
char ch)
889 if (sanity_check(info, tty->
name,
"send_xchar"))
897 spin_unlock_irqrestore(&info->
lock,flags);
904 unsigned long orig_jiffies, char_time;
908 if (sanity_check(info, tty->
name,
"wait_until_sent"))
923 char_time = info->
timeout/(32 * 5);
930 char_time =
min_t(
unsigned long, char_time, timeout);
936 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
948 if (sanity_check(info, tty->
name,
"write_room"))
955 static void flush_chars(
struct tty_struct *tty)
960 if (sanity_check(info, tty->
name,
"flush_chars"))
973 spin_unlock_irqrestore(&info->
lock,flags);
976 static void flush_buffer(
struct tty_struct *tty)
981 if (sanity_check(info, tty->
name,
"flush_buffer"))
987 spin_unlock_irqrestore(&info->
lock, flags);
1000 if (sanity_check(info, tty->
name,
"tx_hold"))
1006 spin_unlock_irqrestore(&info->
lock,flags);
1012 static void tx_release(
struct tty_struct *tty)
1015 unsigned long flags;
1017 if (sanity_check(info, tty->
name,
"tx_release"))
1023 spin_unlock_irqrestore(&info->
lock, flags);
1038 unsigned int cmd,
unsigned long arg)
1044 if (sanity_check(info, tty->
name,
"ioctl"))
1056 return wait_mgsl_event(info, argp);
1058 return modem_input_wait(info,(
int)arg);
1060 return set_gpio(info, argp);
1062 return get_gpio(info, argp);
1064 return wait_gpio(info, argp);
1066 return get_xsync(info, argp);
1068 return set_xsync(info, (
int)arg);
1070 return get_xctrl(info, argp);
1072 return set_xctrl(info, (
int)arg);
1077 ret = get_params(info, argp);
1080 ret = set_params(info, argp);
1083 ret = get_txidle(info, argp);
1086 ret = set_txidle(info, (
int)arg);
1089 ret = tx_enable(info, (
int)arg);
1092 ret = rx_enable(info, (
int)arg);
1101 ret = get_interface(info, argp);
1104 ret = set_interface(info,(
int)arg);
1113 static int get_icount(
struct tty_struct *tty,
1119 unsigned long flags;
1123 spin_unlock_irqrestore(&info->
lock,flags);
1125 icount->
cts = cnow.cts;
1126 icount->
dsr = cnow.dsr;
1127 icount->
rng = cnow.rng;
1128 icount->
dcd = cnow.dcd;
1129 icount->
rx = cnow.rx;
1130 icount->
tx = cnow.tx;
1131 icount->
frame = cnow.frame;
1132 icount->
overrun = cnow.overrun;
1133 icount->
parity = cnow.parity;
1134 icount->
brk = cnow.brk;
1143 #ifdef CONFIG_COMPAT
1144 static long get_params32(
struct slgt_info *info,
struct MGSL_PARAMS32 __user *user_params)
1146 struct MGSL_PARAMS32 tmp_params;
1149 memset(&tmp_params, 0,
sizeof(tmp_params));
1163 if (
copy_to_user(user_params, &tmp_params,
sizeof(
struct MGSL_PARAMS32)))
1168 static long set_params32(
struct slgt_info *info,
struct MGSL_PARAMS32 __user *new_params)
1170 struct MGSL_PARAMS32 tmp_params;
1173 if (
copy_from_user(&tmp_params, new_params,
sizeof(
struct MGSL_PARAMS32)))
1176 spin_lock(&info->
lock);
1194 spin_unlock(&info->
lock);
1202 unsigned int cmd,
unsigned long arg)
1207 if (sanity_check(info, tty->
name,
"compat_ioctl"))
1213 case MGSL_IOCSPARAMS32:
1214 rc = set_params32(info, compat_ptr(arg));
1217 case MGSL_IOCGPARAMS32:
1218 rc = get_params32(info, compat_ptr(arg));
1240 rc = ioctl(tty, cmd, arg);
1248 #define slgt_compat_ioctl NULL
1257 unsigned long flags;
1259 seq_printf(m,
"%s: IO=%08X IRQ=%d MaxFrameSize=%u\n",
1266 spin_unlock_irqrestore(&info->
lock,flags);
1271 strcat(stat_buf,
"|RTS");
1273 strcat(stat_buf,
"|CTS");
1275 strcat(stat_buf,
"|DTR");
1277 strcat(stat_buf,
"|DSR");
1286 if (info->
icount.txunder)
1288 if (info->
icount.txabort)
1290 if (info->
icount.rxshort)
1307 if (info->
icount.overrun)
1314 seq_printf(m,
"\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
1321 static int synclink_gt_proc_show(
struct seq_file *
m,
void *
v)
1325 seq_puts(m,
"synclink_gt driver\n");
1327 info = slgt_device_list;
1342 .open = synclink_gt_proc_open,
1351 static int chars_in_buffer(
struct tty_struct *tty)
1355 if (sanity_check(info, tty->
name,
"chars_in_buffer"))
1357 count = tbuf_bytes(info);
1365 static void throttle(
struct tty_struct * tty)
1368 unsigned long flags;
1370 if (sanity_check(info, tty->
name,
"throttle"))
1375 if (tty->termios.c_cflag &
CRTSCTS) {
1379 spin_unlock_irqrestore(&info->
lock,flags);
1386 static void unthrottle(
struct tty_struct * tty)
1389 unsigned long flags;
1391 if (sanity_check(info, tty->
name,
"unthrottle"))
1400 if (tty->termios.c_cflag &
CRTSCTS) {
1404 spin_unlock_irqrestore(&info->
lock,flags);
1412 static int set_break(
struct tty_struct *tty,
int break_state)
1415 unsigned short value;
1416 unsigned long flags;
1418 if (sanity_check(info, tty->
name,
"set_break"))
1423 value = rd_reg16(info,
TCR);
1424 if (break_state == -1)
1428 wr_reg16(info,
TCR, value);
1429 spin_unlock_irqrestore(&info->
lock,flags);
1433 #if SYNCLINK_GENERIC_HDLC
1445 static int hdlcdev_attach(
struct net_device *
dev,
unsigned short encoding,
1446 unsigned short parity)
1449 unsigned char new_encoding;
1450 unsigned short new_crctype;
1453 if (info->
port.count)
1496 unsigned long flags;
1504 netif_stop_queue(dev);
1507 dev->
stats.tx_packets++;
1514 tx_load(info, skb->
data, skb->
len);
1515 spin_unlock_irqrestore(&info->
lock, flags);
1531 static int hdlcdev_open(
struct net_device *dev)
1535 unsigned long flags;
1550 spin_unlock_irqrestore(&info->
netlock, flags);
1554 spin_unlock_irqrestore(&info->
netlock, flags);
1557 if ((rc = startup(info)) != 0) {
1560 spin_unlock_irqrestore(&info->
netlock, flags);
1570 netif_start_queue(dev);
1575 spin_unlock_irqrestore(&info->
lock, flags);
1591 static int hdlcdev_close(
struct net_device *dev)
1594 unsigned long flags;
1598 netif_stop_queue(dev);
1607 spin_unlock_irqrestore(&info->
netlock, flags);
1622 static int hdlcdev_ioctl(
struct net_device *dev,
struct ifreq *ifr,
int cmd)
1633 if (info->
port.count)
1639 memset(&new_line, 0,
sizeof(new_line));
1641 switch(ifr->ifr_settings.type) {
1645 if (ifr->ifr_settings.size < size) {
1646 ifr->ifr_settings.size =
size;
1722 static void hdlcdev_tx_timeout(
struct net_device *dev)
1725 unsigned long flags;
1729 dev->
stats.tx_errors++;
1730 dev->
stats.tx_aborted_errors++;
1734 spin_unlock_irqrestore(&info->
lock,flags);
1736 netif_wake_queue(dev);
1745 static void hdlcdev_tx_done(
struct slgt_info *info)
1747 if (netif_queue_stopped(info->netdev))
1748 netif_wake_queue(info->netdev);
1759 static void hdlcdev_rx(
struct slgt_info *info,
char *buf,
int size)
1761 struct sk_buff *skb = dev_alloc_skb(size);
1767 DBGERR((
"%s: can't alloc skb, drop packet\n", dev->
name));
1768 dev->
stats.rx_dropped++;
1774 skb->
protocol = hdlc_type_trans(skb, dev);
1776 dev->
stats.rx_packets++;
1784 .ndo_stop = hdlcdev_close,
1787 .ndo_do_ioctl = hdlcdev_ioctl,
1788 .ndo_tx_timeout = hdlcdev_tx_timeout,
1799 static int hdlcdev_init(
struct slgt_info *info)
1823 hdlc = dev_to_hdlc(dev);
1824 hdlc->
attach = hdlcdev_attach;
1825 hdlc->
xmit = hdlcdev_xmit;
1844 static void hdlcdev_exit(
struct slgt_info *info)
1848 info->netdev =
NULL;
1856 static void rx_async(
struct slgt_info *info)
1876 DBGDATA(info, p, count,
"rx");
1878 for(i=0 ; i <
count; i+=2, p+=2) {
1884 if ((status = *(p+1) & (
BIT1 +
BIT0))) {
1887 else if (status &
BIT0)
1894 else if (status & BIT0)
1898 tty_insert_flip_char(tty, ch, stat);
1911 free_rbufs(info, end, end);
1928 static int bh_action(
struct slgt_info *info)
1930 unsigned long flags;
1951 spin_unlock_irqrestore(&info->
lock,flags);
1968 while((action = bh_action(info))) {
1977 while(rx_get_frame(info));
1983 while(rx_get_buf(info));
2008 static void bh_transmit(
struct slgt_info *info)
2017 static void dsr_change(
struct slgt_info *info,
unsigned short status)
2019 if (status &
BIT3) {
2037 static void cts_change(
struct slgt_info *info,
unsigned short status)
2039 if (status &
BIT2) {
2056 if (tty_port_cts_enabled(&info->
port)) {
2057 if (info->
port.tty) {
2058 if (info->
port.tty->hw_stopped) {
2060 info->
port.tty->hw_stopped = 0;
2066 info->
port.tty->hw_stopped = 1;
2072 static void dcd_change(
struct slgt_info *info,
unsigned short status)
2074 if (status & BIT1) {
2087 #if SYNCLINK_GENERIC_HDLC
2109 static void ri_change(
struct slgt_info *info,
unsigned short status)
2111 if (status & BIT0) {
2129 static void isr_rxdata(
struct slgt_info *info)
2136 reg = rd_reg16(info,
RDR);
2144 info->
rbufs[
i].buf[count++] = (
unsigned char)reg;
2147 info->
rbufs[
i].buf[count++] = (
unsigned char)(reg >> 8);
2163 static void isr_serial(
struct slgt_info *info)
2165 unsigned short status = rd_reg16(info,
SSR);
2169 wr_reg16(info,
SSR, status);
2176 isr_txeom(info, status);
2178 if (info->
rx_pio && (status & IRQ_RXDATA))
2183 if (info->
port.tty) {
2195 isr_txeom(info, status);
2196 if (info->
rx_pio && (status & IRQ_RXDATA))
2211 dsr_change(info, status);
2213 cts_change(info, status);
2215 dcd_change(info, status);
2217 ri_change(info, status);
2220 static void isr_rdma(
struct slgt_info *info)
2222 unsigned int status = rd_reg32(info,
RDCSR);
2237 wr_reg32(info,
RDCSR, status);
2246 static void isr_tdma(
struct slgt_info *info)
2248 unsigned int status = rd_reg32(info,
TDCSR);
2262 wr_reg32(info,
TDCSR, status);
2264 if (status & (
BIT5 +
BIT4 + BIT3)) {
2277 static bool unsent_tbufs(
struct slgt_info *info)
2301 static void isr_txeom(
struct slgt_info *info,
unsigned short status)
2308 unsigned short val = rd_reg16(info,
TCR);
2309 wr_reg16(info,
TCR, (
unsigned short)(val | BIT2));
2310 wr_reg16(info,
TCR, val);
2315 if (status & IRQ_TXUNDER)
2317 else if (status & IRQ_TXIDLE)
2321 if (unsent_tbufs(info)) {
2323 update_tx_timer(info);
2336 #if SYNCLINK_GENERIC_HDLC
2338 hdlcdev_tx_done(info);
2342 if (info->
port.tty && (info->
port.tty->stopped || info->
port.tty->hw_stopped)) {
2357 if (w->
data & changed) {
2382 while((gsr = rd_reg32(info,
GSR) & 0xffffff00)) {
2389 if (gsr & (
BIT8 << i))
2391 if (gsr & (
BIT16 << (i*2)))
2393 if (gsr & (
BIT17 << (i*2)))
2402 spin_lock(&info->
lock);
2403 while ((changed = rd_reg32(info,
IOSR)) != 0) {
2406 state = rd_reg32(info,
IOVR);
2408 wr_reg32(info,
IOSR, changed);
2411 isr_gpio(info->
port_array[i], changed, state);
2414 spin_unlock(&info->
lock);
2421 spin_lock(&port->
lock);
2429 spin_unlock(&port->
lock);
2436 static int startup(
struct slgt_info *info)
2456 change_params(info);
2469 static void shutdown(
struct slgt_info *info)
2471 unsigned long flags;
2496 if (!info->
port.tty || info->
port.tty->termios.c_cflag &
HUPCL) {
2503 spin_unlock_irqrestore(&info->
lock,flags);
2511 static void program_hw(
struct slgt_info *info)
2513 unsigned long flags;
2537 (info->
port.tty && info->
port.tty->termios.c_cflag &
CREAD))
2540 spin_unlock_irqrestore(&info->
lock,flags);
2546 static void change_params(
struct slgt_info *info)
2551 if (!info->
port.tty)
2555 cflag = info->
port.tty->termios.c_cflag;
2566 switch (cflag &
CSIZE) {
2648 unsigned long flags;
2660 spin_unlock_irqrestore(&info->
lock, flags);
2675 static int set_txidle(
struct slgt_info *info,
int idle_mode)
2677 unsigned long flags;
2683 spin_unlock_irqrestore(&info->
lock,flags);
2689 unsigned long flags;
2699 spin_unlock_irqrestore(&info->
lock,flags);
2708 unsigned long flags;
2712 spin_unlock_irqrestore(&info->
lock,flags);
2716 static int rx_enable(
struct slgt_info *info,
int enable)
2718 unsigned long flags;
2727 rbuf_fill_level = ((
unsigned int)enable) >> 16;
2728 if (rbuf_fill_level) {
2729 if ((rbuf_fill_level >
DMABUFSIZE) || (rbuf_fill_level % 4)) {
2730 spin_unlock_irqrestore(&info->
lock, flags);
2734 if (rbuf_fill_level < 128)
2751 else if (enable == 2) {
2753 wr_reg16(info,
RCR, rd_reg16(info,
RCR) | BIT3);
2759 spin_unlock_irqrestore(&info->
lock,flags);
2766 static int wait_mgsl_event(
struct slgt_info *info,
int __user *mask_ptr)
2768 unsigned long flags;
2794 spin_unlock_irqrestore(&info->
lock,flags);
2804 unsigned short val = rd_reg16(info,
SCR);
2805 if (!(val & IRQ_RXIDLE))
2806 wr_reg16(info,
SCR, (
unsigned short)(val | IRQ_RXIDLE));
2812 spin_unlock_irqrestore(&info->
lock,flags);
2816 if (signal_pending(
current)) {
2826 spin_unlock_irqrestore(&info->
lock,flags);
2829 if (newsigs.dsr_up == oldsigs.dsr_up &&
2830 newsigs.dsr_down == oldsigs.dsr_down &&
2831 newsigs.dcd_up == oldsigs.dcd_up &&
2832 newsigs.dcd_down == oldsigs.dcd_down &&
2833 newsigs.cts_up == oldsigs.cts_up &&
2834 newsigs.cts_down == oldsigs.cts_down &&
2835 newsigs.ri_up == oldsigs.ri_up &&
2836 newsigs.ri_down == oldsigs.ri_down &&
2837 cnow.exithunt == cprev.exithunt &&
2838 cnow.rxidle == cprev.rxidle) {
2847 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
2849 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
2851 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
2870 (
unsigned short)(rd_reg16(info,
SCR) & ~IRQ_RXIDLE));
2872 spin_unlock_irqrestore(&info->
lock,flags);
2888 static int set_interface(
struct slgt_info *info,
int if_mode)
2890 unsigned long flags;
2900 val = rd_reg16(info,
TCR);
2905 wr_reg16(info,
TCR, val);
2907 spin_unlock_irqrestore(&info->
lock,flags);
2911 static int get_xsync(
struct slgt_info *info,
int __user *xsync)
2925 static int set_xsync(
struct slgt_info *info,
int xsync)
2927 unsigned long flags;
2931 info->
xsync = xsync;
2932 wr_reg32(info,
XSR, xsync);
2933 spin_unlock_irqrestore(&info->
lock, flags);
2937 static int get_xctrl(
struct slgt_info *info,
int __user *xctrl)
2962 static int set_xctrl(
struct slgt_info *info,
int xctrl)
2964 unsigned long flags;
2968 info->
xctrl = xctrl;
2969 wr_reg32(info,
XCR, xctrl);
2970 spin_unlock_irqrestore(&info->
lock, flags);
2985 unsigned long flags;
2993 DBGINFO((
"%s set_gpio state=%08x smask=%08x dir=%08x dmask=%08x\n",
2999 data = rd_reg32(info,
IODR);
3002 wr_reg32(info,
IODR, data);
3005 data = rd_reg32(info,
IOVR);
3007 data &= ~(
gpio.smask & ~
gpio.state);
3008 wr_reg32(info,
IOVR, data);
3010 spin_unlock_irqrestore(&info->
port_array[0]->lock, flags);
3024 gpio.smask = 0xffffffff;
3026 gpio.dmask = 0xffffffff;
3029 DBGINFO((
"%s get_gpio state=%08x dir=%08x\n",
3037 static void init_cond_wait(
struct cond_wait *w,
unsigned int data)
3057 for (w = *head, prev =
NULL ; w !=
NULL ; prev =
w, w = w->
next) {
3060 prev->
next = w->next;
3068 static void flush_cond_wait(
struct cond_wait **head)
3070 while (*head !=
NULL) {
3072 *head = (*head)->
next;
3094 unsigned long flags;
3104 DBGINFO((
"%s wait_gpio() state=%08x smask=%08x\n",
3107 if ((
gpio.smask &= ~rd_reg32(info,
IODR)) == 0)
3113 wr_reg32(info,
IOER, rd_reg32(info,
IOER) |
gpio.smask);
3115 state = rd_reg32(info,
IOVR);
3117 if (
gpio.smask & ~(state ^
gpio.state)) {
3123 spin_unlock_irqrestore(&info->
port_array[0]->lock, flags);
3135 wr_reg32(info,
IOER, 0);
3136 spin_unlock_irqrestore(&info->
port_array[0]->lock, flags);
3143 static int modem_input_wait(
struct slgt_info *info,
int arg)
3145 unsigned long flags;
3155 spin_unlock_irqrestore(&info->
lock,flags);
3159 if (signal_pending(
current)) {
3168 spin_unlock_irqrestore(&info->
lock,flags);
3171 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
3172 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
3178 if ((arg &
TIOCM_RNG && cnow.rng != cprev.rng) ||
3179 (arg &
TIOCM_DSR && cnow.dsr != cprev.dsr) ||
3180 (arg &
TIOCM_CD && cnow.dcd != cprev.dcd) ||
3181 (arg &
TIOCM_CTS && cnow.cts != cprev.cts)) {
3200 unsigned long flags;
3204 spin_unlock_irqrestore(&info->
lock,flags);
3225 unsigned int set,
unsigned int clear)
3228 unsigned long flags;
3234 if (
set & TIOCM_DTR)
3238 if (clear & TIOCM_DTR)
3239 info->
signals &= ~SerialSignal_DTR;
3243 spin_unlock_irqrestore(&info->
lock,flags);
3247 static int carrier_raised(
struct tty_port *port)
3249 unsigned long flags;
3254 spin_unlock_irqrestore(&info->
lock,flags);
3258 static void dtr_rts(
struct tty_port *port,
int on)
3260 unsigned long flags;
3269 spin_unlock_irqrestore(&info->
lock,flags);
3276 static int block_til_ready(
struct tty_struct *tty,
struct file *filp,
3281 bool do_clocal =
false;
3282 bool extra_count =
false;
3283 unsigned long flags;
3295 if (tty->termios.c_cflag & CLOCAL)
3313 spin_unlock_irqrestore(&info->
lock, flags);
3317 if ((tty->termios.c_cflag & CBAUD))
3333 if (signal_pending(
current)) {
3354 DBGINFO((
"%s block_til_ready ready, rc=%d\n", tty->
driver->name, retval));
3358 static int alloc_tmp_rbuf(
struct slgt_info *info)
3366 static void free_tmp_rbuf(
struct slgt_info *info)
3375 static int alloc_desc(
struct slgt_info *info)
3422 static void free_desc(
struct slgt_info *info)
3435 for (i=0; i <
count; i++) {
3446 for (i=0; i <
count; i++) {
3447 if (bufs[i].buf ==
NULL)
3454 static int alloc_dma_bufs(
struct slgt_info *info)
3459 if (alloc_desc(info) < 0 ||
3462 alloc_tmp_rbuf(info) < 0) {
3470 static void free_dma_bufs(
struct slgt_info *info)
3477 free_tmp_rbuf(info);
3480 static int claim_resources(
struct slgt_info *info)
3483 DBGERR((
"%s reg addr conflict, addr=%08X\n",
3493 DBGERR((
"%s can't map device registers, addr=%08X\n",
3501 release_resources(info);
3505 static void release_resources(
struct slgt_info *info)
3526 static void add_device(
struct slgt_info *info)
3531 info->
line = slgt_device_count;
3535 if (maxframe[info->
line])
3539 slgt_device_count++;
3541 if (!slgt_device_list)
3542 slgt_device_list =
info;
3544 struct slgt_info *current_dev = slgt_device_list;
3555 switch(info->
pdev->device) {
3570 devstr =
"(unknown model)";
3572 printk(
"SyncLink %s %s IO=%08x IRQ=%d MaxFrameSize=%u\n",
3576 #if SYNCLINK_GENERIC_HDLC
3596 DBGERR((
"%s device alloc failed adapter=%d port=%d\n",
3600 info->
port.ops = &slgt_port_ops;
3606 info->
port.close_delay = 5*
HZ/10;
3607 info->
port.closing_wait = 30*
HZ;
3633 static void device_init(
int adapter_num,
struct pci_dev *pdev)
3646 port_array[
i] = alloc_dev(adapter_num, i, pdev);
3647 if (port_array[i] ==
NULL) {
3648 for (--i; i >= 0; --
i)
3649 kfree(port_array[i]);
3656 memcpy(port_array[i]->port_array, port_array,
sizeof(port_array));
3657 add_device(port_array[i]);
3663 if (!claim_resources(port_array[0])) {
3665 alloc_dma_bufs(port_array[0]);
3671 alloc_dma_bufs(port_array[i]);
3678 port_array[0]) < 0) {
3679 DBGERR((
"%s request_irq failed IRQ=%d\n",
3684 adapter_test(port_array[0]);
3703 printk(
"error enabling pci device %p\n", dev);
3707 device_init(slgt_device_count, dev);
3729 .break_ctl = set_break,
3733 .start = tx_release,
3738 .proc_fops = &synclink_gt_proc_fops,
3741 static void slgt_cleanup(
void)
3749 if (serial_driver) {
3753 DBGERR((
"tty_unregister_driver error=%d\n", rc));
3758 info = slgt_device_list;
3765 info = slgt_device_list;
3767 #if SYNCLINK_GENERIC_HDLC
3770 free_dma_bufs(info);
3771 free_tmp_rbuf(info);
3773 release_resources(info);
3786 static int __init slgt_init(
void)
3793 if (!serial_driver) {
3801 serial_driver->
name = tty_dev_prefix;
3802 serial_driver->
major = ttymajor;
3816 serial_driver =
NULL;
3823 slgt_device_count = 0;
3824 if ((rc = pci_register_driver(&pci_driver)) < 0) {
3828 pci_registered =
true;
3830 if (!slgt_device_list)
3840 static void __exit slgt_exit(
void)
3852 #define CALC_REGADDR() \
3853 unsigned long reg_addr = ((unsigned long)info->reg_addr) + addr; \
3855 reg_addr += (info->port_num) * 32; \
3856 else if (addr >= 0x40) \
3857 reg_addr += (info->port_num) * 16;
3877 static void wr_reg16(
struct slgt_info *info,
unsigned int addr,
__u16 value)
3889 static void wr_reg32(
struct slgt_info *info,
unsigned int addr,
__u32 value)
3895 static void rdma_reset(
struct slgt_info *info)
3900 wr_reg32(info,
RDCSR, BIT1);
3903 for(i=0 ; i < 1000 ; i++)
3904 if (!(rd_reg32(info,
RDCSR) & BIT0))
3908 static void tdma_reset(
struct slgt_info *info)
3913 wr_reg32(info,
TDCSR, BIT1);
3916 for(i=0 ; i < 1000 ; i++)
3917 if (!(rd_reg32(info,
TDCSR) & BIT0))
3926 static void enable_loopback(
struct slgt_info *info)
3929 wr_reg16(info,
SCR, (
unsigned short)(rd_reg16(info,
SCR) | BIT2));
3940 wr_reg8(info,
CCR, 0x49);
3946 set_rate(info, 3686400);
3966 if (!(osc % rate) && div)
3968 wr_reg16(info,
BDR, (
unsigned short)div);
3972 static void rx_stop(
struct slgt_info *info)
3977 val = rd_reg16(info,
RCR) & ~BIT1;
3978 wr_reg16(info,
RCR, (
unsigned short)(val | BIT2));
3979 wr_reg16(info,
RCR, val);
4002 val = rd_reg16(info,
RCR) & ~BIT1;
4003 wr_reg16(info,
RCR, (
unsigned short)(val | BIT2));
4004 wr_reg16(info,
RCR, val);
4011 wr_reg16(info,
SCR, (
unsigned short)(rd_reg16(info,
SCR) & ~
BIT14));
4019 wr_reg16(info,
SCR, (
unsigned short)(rd_reg16(info,
SCR) |
BIT14));
4025 wr_reg32(info,
RDCSR, (BIT2 + BIT0));
4028 wr_reg32(info,
RDCSR, (
BIT6 + BIT2 + BIT0));
4035 wr_reg16(info,
RCR, (
unsigned short)(rd_reg16(info,
RCR) | BIT1));
4045 (
unsigned short)((rd_reg16(info,
TCR) | BIT1) & ~BIT2));
4065 wr_reg16(info,
SSR, (
unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
4070 wr_reg16(info,
SSR, IRQ_TXIDLE);
4074 wr_reg32(info,
TDCSR, BIT2 + BIT0);
4079 static void tx_stop(
struct slgt_info *info)
4088 val = rd_reg16(info,
TCR) & ~BIT1;
4089 wr_reg16(info,
TCR, (
unsigned short)(val | BIT2));
4094 wr_reg16(info,
SSR, (
unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER));
4102 static void reset_port(
struct slgt_info *info)
4116 static void reset_adapter(
struct slgt_info *info)
4125 static void async_mode(
struct slgt_info *info)
4164 case 6: val |=
BIT4;
break;
4165 case 7: val |=
BIT5;
break;
4175 wr_reg16(info,
TCR, val);
4204 case 6: val |=
BIT4;
break;
4205 case 7: val |=
BIT5;
break;
4212 wr_reg16(info,
RCR, val);
4223 wr_reg8(info,
CCR, 0x69);
4258 wr_reg16(info,
SCR, val);
4263 enable_loopback(info);
4266 static void sync_mode(
struct slgt_info *info)
4337 wr_reg16(info,
TCR, val);
4348 default: val = 0x7e;
break;
4350 wr_reg8(info,
TPR, (
unsigned char)val);
4400 wr_reg16(info,
RCR, val);
4436 wr_reg8(info,
CCR, (
unsigned char)val);
4449 default: val =
BIT6;
4451 wr_reg16(info,
RCR, (
unsigned short)(rd_reg16(info,
RCR) | val));
4485 enable_loopback(info);
4491 static void tx_set_idle(
struct slgt_info *info)
4499 tcr = rd_reg16(info,
TCR);
4504 wr_reg8(info,
TPR, (
unsigned char)((info->
idle_mode >> 8) & 0xff));
4505 }
else if (!(tcr &
BIT6)) {
4509 wr_reg16(info,
TCR, tcr);
4523 default: val = 0xff;
4527 wr_reg8(info,
TIR, val);
4535 unsigned short status = rd_reg16(info,
SSR);
4553 static void msc_set_vcr(
struct slgt_info *info)
4555 unsigned char val = 0;
4581 if (info->
signals & SerialSignal_DTR)
4583 if (info->
signals & SerialSignal_RTS)
4589 wr_reg8(info,
VCR, val);
4597 unsigned char val = rd_reg8(info,
VCR);
4598 if (info->
signals & SerialSignal_DTR)
4602 if (info->
signals & SerialSignal_RTS)
4606 wr_reg8(info,
VCR, val);
4612 static void free_rbufs(
struct slgt_info *info,
unsigned int i,
unsigned int last)
4618 info->
rbufs[
i].status = 0;
4631 static void reset_rbufs(
struct slgt_info *info)
4643 static bool rx_get_frame(
struct slgt_info *info)
4647 unsigned int framesize = 0;
4648 unsigned long flags;
4650 unsigned char addr_field = 0xff;
4651 unsigned int crc_size = 0;
4669 addr_field = info->
rbufs[
end].buf[0];
4683 spin_unlock_irqrestore(&info->
lock,flags);
4704 if (framesize == 0 ||
4706 free_rbufs(info, start, end);
4710 if (framesize < (2 + crc_size) || status & BIT0) {
4713 }
else if (status & BIT1) {
4719 #if SYNCLINK_GENERIC_HDLC
4720 if (framesize == 0) {
4721 info->netdev->stats.rx_errors++;
4722 info->netdev->stats.rx_frame_errors++;
4726 DBGBH((
"%s rx frame status=%04X size=%d\n",
4732 framesize -= crc_size;
4740 int copy_count = framesize;
4751 copy_count -= partial_count;
4761 #if SYNCLINK_GENERIC_HDLC
4763 hdlcdev_rx(info,info->
tmp_rbuf, framesize);
4769 free_rbufs(info, start, end);
4780 static bool rx_get_buf(
struct slgt_info *info)
4798 DBGINFO((
"rx_get_buf size=%d\n", count));
4800 ldisc_receive_buf(info->
port.tty, info->
rbufs[i].buf,
4802 free_rbufs(info, i, i);
4806 static void reset_tbufs(
struct slgt_info *info)
4811 info->
tbufs[
i].status = 0;
4812 info->
tbufs[
i].count = 0;
4819 static unsigned int free_tbuf_count(
struct slgt_info *info)
4821 unsigned int count = 0;
4834 if (count && (rd_reg32(info,
TDCSR) & BIT0))
4844 static unsigned int tbuf_bytes(
struct slgt_info *info)
4846 unsigned int total_count = 0;
4848 unsigned int reg_value;
4850 unsigned int active_buf_count = 0;
4866 total_count +=
count;
4867 else if (!total_count)
4868 active_buf_count = info->
tbufs[
i].buf_count;
4874 reg_value = rd_reg32(info,
TDCSR);
4877 if (reg_value & BIT0)
4878 total_count += active_buf_count;
4881 total_count += (reg_value >> 8) & 0xff;
4894 static bool tx_load(
struct slgt_info *info,
const char *buf,
unsigned int size)
4896 unsigned short count;
4904 DBGDATA(info, buf, size,
"tx");
4956 update_tx_timer(info);
4963 static unsigned short patterns[] =
4964 {0x0000, 0xffff, 0xaaaa, 0x5555, 0x6969, 0x9696};
4965 static unsigned int count =
ARRAY_SIZE(patterns);
4969 for (i=0 ; i <
count ; i++) {
4970 wr_reg16(info,
TIR, patterns[i]);
4971 wr_reg16(info,
BDR, patterns[(i+1)%count]);
4972 if ((rd_reg16(info,
TIR) != patterns[i]) ||
4973 (rd_reg16(info,
BDR) != patterns[(i+1)%count])) {
4983 static int irq_test(
struct slgt_info *info)
4985 unsigned long timeout;
4986 unsigned long flags;
4999 (
unsigned short)(rd_reg16(info,
TCR) | BIT1));
5002 wr_reg16(info,
TDR, 0);
5008 spin_unlock_irqrestore(&info->
lock, flags);
5016 spin_unlock_irqrestore(&info->
lock,flags);
5019 info->
port.tty = oldtty;
5025 static int loopback_test_rx(
struct slgt_info *info)
5032 src = info->
rbufs[0].buf;
5035 for( ;
count ; count-=2, src+=2) {
5037 if (!(*(src+1) & (
BIT9 + BIT8))) {
5049 static int loopback_test(
struct slgt_info *info)
5051 #define TESTFRAMESIZE 20
5053 unsigned long timeout;
5057 unsigned long flags;
5071 buf[count] = (
unsigned char)
count;
5080 tx_load(info, buf, count);
5081 spin_unlock_irqrestore(&info->
lock, flags);
5084 for (timeout = 100; timeout; --timeout) {
5086 if (loopback_test_rx(info)) {
5099 reset_adapter(info);
5100 spin_unlock_irqrestore(&info->
lock,flags);
5103 info->
port.tty = oldtty;
5109 static int adapter_test(
struct slgt_info *info)
5113 printk(
"register test failure %s addr=%08X\n",
5115 }
else if (irq_test(info) < 0) {
5116 printk(
"IRQ test failure %s IRQ=%d\n",
5118 }
else if (loopback_test(info) < 0) {
5130 unsigned long flags;
5134 info->
icount.txtimeout++;
5138 spin_unlock_irqrestore(&info->
lock,flags);
5140 #if SYNCLINK_GENERIC_HDLC
5142 hdlcdev_tx_done(info);
5151 static void rx_timeout(
unsigned long context)
5154 unsigned long flags;
5159 spin_unlock_irqrestore(&info->
lock, flags);
5160 bh_handler(&info->
task);