29 #define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
31 # define BREAKPOINT() asm(" int $3");
33 # define BREAKPOINT() { }
36 #define MAX_DEVICE_COUNT 4
38 #include <linux/module.h>
39 #include <linux/errno.h>
40 #include <linux/signal.h>
41 #include <linux/sched.h>
43 #include <linux/time.h>
45 #include <linux/tty.h>
47 #include <linux/serial.h>
49 #include <linux/string.h>
50 #include <linux/fcntl.h>
51 #include <linux/ptrace.h>
55 #include <linux/slab.h>
56 #include <linux/netdevice.h>
61 #include <linux/synclink.h>
66 #include <linux/bitops.h>
67 #include <asm/types.h>
70 #include <linux/hdlc.h>
76 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_CS_MODULE))
77 #define SYNCLINK_GENERIC_HDLC 1
79 #define SYNCLINK_GENERIC_HDLC 0
82 #define GET_USER(error,value,addr) error = get_user(value,addr)
83 #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
84 #define PUT_USER(error,value,addr) error = put_user(value,addr)
85 #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
87 #include <asm/uaccess.h>
115 #define BH_TRANSMIT 2
118 #define IO_PIN_SHUTDOWN_LIMIT 100
120 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
226 #if SYNCLINK_GENERIC_HDLC
232 #define MGSLPC_MAGIC 0x5402
237 #define TXBUFSIZE 4096
291 #define IRQ_BREAK_ON BIT15 // rx break detected
292 #define IRQ_DATAOVERRUN BIT14 // receive data overflow
293 #define IRQ_ALLSENT BIT13 // all sent
294 #define IRQ_UNDERRUN BIT12 // transmit data underrun
295 #define IRQ_TIMER BIT11 // timer interrupt
296 #define IRQ_CTS BIT10 // CTS status change
297 #define IRQ_TXREPEAT BIT9 // tx message repeat
298 #define IRQ_TXFIFO BIT8 // transmit pool ready
299 #define IRQ_RXEOM BIT7 // receive message end
300 #define IRQ_EXITHUNT BIT6 // receive frame start
301 #define IRQ_RXTIME BIT6 // rx char timeout
302 #define IRQ_DCD BIT2 // carrier detect status change
303 #define IRQ_OVERRUN BIT1 // receive frame overflow
304 #define IRQ_RXFIFO BIT0 // receive pool full
308 #define XFW BIT6 // transmit FIFO write enable
309 #define CEC BIT2 // command executing
310 #define CTS BIT1 // CTS state
315 #define PVR_AUTOCTS BIT3
316 #define PVR_RS232 0x20
318 #define PVR_RS422 0x40
322 #define write_reg(info, reg, val) outb((val),(info)->io_base + (reg))
323 #define read_reg(info, reg) inb((info)->io_base + (reg))
325 #define read_reg16(info, reg) inw((info)->io_base + (reg))
326 #define write_reg16(info, reg, val) outw((val), (info)->io_base + (reg))
328 #define set_reg_bits(info, reg, mask) \
329 write_reg(info, (reg), \
330 (unsigned char) (read_reg(info, (reg)) | (mask)))
331 #define clear_reg_bits(info, reg, mask) \
332 write_reg(info, (reg), \
333 (unsigned char) (read_reg(info, (reg)) & ~(mask)))
339 if (channel ==
CHA) {
349 if (channel ==
CHA) {
358 #define port_irq_disable(info, mask) \
359 { info->pim_value |= (mask); write_reg(info, PIM, info->pim_value); }
361 #define port_irq_enable(info, mask) \
362 { info->pim_value &= ~(mask); write_reg(info, PIM, info->pim_value); }
384 #if SYNCLINK_GENERIC_HDLC
385 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
401 static void mgslpc_remove_device(
MGSLPC_INFO *info);
422 unsigned int set,
unsigned int clear);
426 static int get_txidle(
MGSLPC_INFO *info,
int __user *idle_mode);
427 static int set_txidle(
MGSLPC_INFO *info,
int idle_mode);
431 static int wait_events(
MGSLPC_INFO *info,
int __user *mask);
434 static int mgslpc_device_count = 0;
441 static bool break_on_load=0;
447 static int ttymajor=0;
449 static int debug_level = 0;
459 static char *
driver_name =
"SyncLink PC Card driver";
460 static char *driver_version =
"$Revision: 4.34 $";
465 #define WAKEUP_CHARS 256
468 static void mgslpc_wait_until_sent(
struct tty_struct *tty,
int timeout);
472 static int mgslpc_config(
struct pcmcia_device *
link);
474 static void mgslpc_detach(
struct pcmcia_device *p_dev);
482 static void* mgslpc_get_text_ptr(
void)
484 return mgslpc_get_text_ptr;
496 static void ldisc_receive_buf(
struct tty_struct *tty,
504 if (ld->
ops->receive_buf)
505 ld->
ops->receive_buf(tty, data, flags, count);
515 static int mgslpc_probe(
struct pcmcia_device *
link)
521 printk(
"mgslpc_attach\n");
525 printk(
"Error can't allocate device instance data\n");
531 info->
port.ops = &mgslpc_port_ops;
534 info->
port.close_delay = 5*
HZ/10;
535 info->
port.closing_wait = 30*
HZ;
551 ret = mgslpc_config(link);
555 mgslpc_add_device(info);
563 static int mgslpc_ioprobe(
struct pcmcia_device *p_dev,
void *priv_data)
568 static int mgslpc_config(
struct pcmcia_device *link)
574 printk(
"mgslpc_config(0x%p)\n", link);
576 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
578 ret = pcmcia_loop_config(link, mgslpc_ioprobe,
NULL);
582 link->config_index = 8;
583 link->config_regs = PRESENT_OPTION;
592 info->
io_base = link->resource[0]->start;
597 mgslpc_release((
u_long)link);
607 struct pcmcia_device *link = (
struct pcmcia_device *)arg;
610 printk(
"mgslpc_release(0x%p)\n", link);
615 static void mgslpc_detach(
struct pcmcia_device *link)
618 printk(
"mgslpc_detach(0x%p)\n", link);
621 mgslpc_release((
u_long)link);
626 static int mgslpc_suspend(
struct pcmcia_device *link)
635 static int mgslpc_resume(
struct pcmcia_device *link)
645 static inline bool mgslpc_paranoia_check(
MGSLPC_INFO *info,
648 #ifdef MGSLPC_PARANOIA_CHECK
649 static const char *badmagic =
650 "Warning: bad magic number for mgsl struct (%s) in %s\n";
651 static const char *badinfo =
652 "Warning: null mgslpc_info for (%s) in %s\n";
655 printk(badinfo, name, routine);
659 printk(badmagic, name, routine);
670 #define CMD_RXFIFO BIT7 // release current rx FIFO
671 #define CMD_RXRESET BIT6 // receiver reset
672 #define CMD_RXFIFO_READ BIT5
673 #define CMD_START_TIMER BIT4
674 #define CMD_TXFIFO BIT3 // release current tx FIFO
675 #define CMD_TXEOM BIT1 // transmit end message
676 #define CMD_TXRESET BIT0 // transmit reset
678 static bool wait_command_complete(
MGSLPC_INFO *info,
unsigned char channel)
692 wait_command_complete(info, channel);
701 if (mgslpc_paranoia_check(info, tty->
name,
"tx_pause"))
709 spin_unlock_irqrestore(&info->
lock,flags);
712 static void tx_release(
struct tty_struct *tty)
717 if (mgslpc_paranoia_check(info, tty->
name,
"tx_release"))
725 spin_unlock_irqrestore(&info->
lock,flags);
755 spin_unlock_irqrestore(&info->
lock,flags);
770 printk(
"%s(%d):bh_handler(%s) entry\n",
776 while((action = bh_action(info)) != 0) {
780 printk(
"%s(%d):bh_handler() work item action=%d\n",
781 __FILE__,__LINE__,action);
786 while(rx_get_frame(info, tty));
789 bh_transmit(info, tty);
796 printk(
"Unknown work item ID=%08X!\n", action);
803 printk(
"%s(%d):bh_handler(%s) exit\n",
825 static void rx_ready_hdlc(
MGSLPC_INFO *info,
int eom)
827 unsigned char data[2];
828 unsigned char fifo_count, read_count,
i;
832 printk(
"%s(%d):rx_ready_hdlc(eom=%d)\n",__FILE__,__LINE__,eom);
842 info->
icount.buf_overrun++;
854 if (fifo_count == 1) {
861 fifo_count -= read_count;
862 if (!fifo_count && eom)
863 buf->
status = data[--read_count];
865 for (i = 0; i < read_count; i++) {
875 }
while (fifo_count);
898 printk(
"%s(%d):rx_ready_async(tty=NULL)\n",__FILE__,__LINE__);
942 else if (status &
BIT6)
945 work += tty_insert_flip_char(tty, data, flag);
950 printk(
"%s(%d):rx_ready_async",
952 printk(
"%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
953 __FILE__,__LINE__,icount->
rx,icount->
brk,
985 #if SYNCLINK_GENERIC_HDLC
987 hdlcdev_tx_done(info);
1001 unsigned char fifo_count = 32;
1022 while (info->
tx_count && fifo_count) {
1061 if (tty && tty_port_cts_enabled(&info->
port)) {
1065 printk(
"CTS tx start...");
1074 printk(
"CTS tx stop...");
1094 #if SYNCLINK_GENERIC_HDLC
1113 printk(
"doing serial hangup...");
1163 unsigned char gis, pis;
1169 if (!(info->
p_dev->_locked))
1174 spin_lock(&info->
lock);
1180 if ((gis & 0x70) || count > 1000) {
1181 printk(
"synclink_cs:hardware failed or ejected\n");
1189 dcd_change(info, tty);
1191 cts_change(info, tty);
1218 rx_ready_async(info, isr &
IRQ_RXEOM, tty);
1234 tx_ready(info, tty);
1251 printk(
"%s(%d):%s queueing bh task.\n",
1257 spin_unlock(&info->
lock);
1261 printk(
"%s(%d):mgslpc_isr(%d)exit.\n",
1296 retval = claim_resources(info);
1300 retval = adapter_test(info);
1305 release_resources(info);
1310 mgslpc_change_params(info, tty);
1324 unsigned long flags;
1330 printk(
"%s(%d):mgslpc_shutdown(%s)\n",
1353 if (!tty || tty->termios.c_cflag &
HUPCL) {
1358 spin_unlock_irqrestore(&info->
lock,flags);
1360 release_resources(info);
1370 unsigned long flags;
1394 if (info->
netcount || (tty && (tty->termios.c_cflag &
CREAD)))
1397 spin_unlock_irqrestore(&info->
lock,flags);
1411 printk(
"%s(%d):mgslpc_change_params(%s)\n",
1414 cflag = tty->termios.c_cflag;
1425 switch (cflag &
CSIZE) {
1488 mgslpc_program_hw(info, tty);
1493 static int mgslpc_put_char(
struct tty_struct *tty,
unsigned char ch)
1496 unsigned long flags;
1499 printk(
"%s(%d):mgslpc_put_char(%d) on %s\n",
1503 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_put_char"))
1519 spin_unlock_irqrestore(&info->
lock,flags);
1526 static void mgslpc_flush_chars(
struct tty_struct *tty)
1529 unsigned long flags;
1532 printk(
"%s(%d):mgslpc_flush_chars() entry on %s tx_count=%d\n",
1535 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_flush_chars"))
1543 printk(
"%s(%d):mgslpc_flush_chars() entry on %s starting transmitter\n",
1549 spin_unlock_irqrestore(&info->
lock,flags);
1562 static int mgslpc_write(
struct tty_struct * tty,
1563 const unsigned char *buf,
int count)
1567 unsigned long flags;
1570 printk(
"%s(%d):mgslpc_write(%s) count=%d\n",
1573 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_write") ||
1600 spin_unlock_irqrestore(&info->
lock,flags);
1611 spin_unlock_irqrestore(&info->
lock,flags);
1615 printk(
"%s(%d):mgslpc_write(%s) returning=%d\n",
1622 static int mgslpc_write_room(
struct tty_struct *tty)
1627 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_write_room"))
1643 printk(
"%s(%d):mgslpc_write_room(%s)=%d\n",
1650 static int mgslpc_chars_in_buffer(
struct tty_struct *tty)
1656 printk(
"%s(%d):mgslpc_chars_in_buffer(%s)\n",
1659 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_chars_in_buffer"))
1668 printk(
"%s(%d):mgslpc_chars_in_buffer(%s)=%d\n",
1676 static void mgslpc_flush_buffer(
struct tty_struct *tty)
1679 unsigned long flags;
1682 printk(
"%s(%d):mgslpc_flush_buffer(%s) entry\n",
1685 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_flush_buffer"))
1691 spin_unlock_irqrestore(&info->
lock,flags);
1699 static void mgslpc_send_xchar(
struct tty_struct *tty,
char ch)
1702 unsigned long flags;
1705 printk(
"%s(%d):mgslpc_send_xchar(%s,%d)\n",
1708 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_send_xchar"))
1716 spin_unlock_irqrestore(&info->
lock,flags);
1722 static void mgslpc_throttle(
struct tty_struct * tty)
1725 unsigned long flags;
1728 printk(
"%s(%d):mgslpc_throttle(%s) entry\n",
1731 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_throttle"))
1737 if (tty->termios.c_cflag & CRTSCTS) {
1741 spin_unlock_irqrestore(&info->
lock,flags);
1747 static void mgslpc_unthrottle(
struct tty_struct * tty)
1750 unsigned long flags;
1753 printk(
"%s(%d):mgslpc_unthrottle(%s) entry\n",
1756 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_unthrottle"))
1766 if (tty->termios.c_cflag & CRTSCTS) {
1770 spin_unlock_irqrestore(&info->
lock,flags);
1815 unsigned long flags;
1820 printk(
"%s(%d):set_params %s\n", __FILE__,__LINE__,
1825 printk(
"%s(%d):set_params(%s) user buffer copy failed\n",
1832 spin_unlock_irqrestore(&info->
lock,flags);
1834 mgslpc_change_params(info, tty);
1839 static int get_txidle(
MGSLPC_INFO * info,
int __user *idle_mode)
1850 static int set_txidle(
MGSLPC_INFO * info,
int idle_mode)
1852 unsigned long flags;
1858 spin_unlock_irqrestore(&info->
lock,flags);
1873 static int set_interface(
MGSLPC_INFO * info,
int if_mode)
1875 unsigned long flags;
1891 spin_unlock_irqrestore(&info->
lock,flags);
1897 unsigned long flags;
1910 spin_unlock_irqrestore(&info->
lock,flags);
1916 unsigned long flags;
1930 spin_unlock_irqrestore(&info->
lock,flags);
1934 static int set_rxenable(
MGSLPC_INFO * info,
int enable)
1936 unsigned long flags;
1949 spin_unlock_irqrestore(&info->
lock,flags);
1961 static int wait_events(
MGSLPC_INFO * info,
int __user *mask_ptr)
1963 unsigned long flags;
1990 spin_unlock_irqrestore(&info->
lock,flags);
2005 spin_unlock_irqrestore(&info->
lock,flags);
2010 if (signal_pending(
current)) {
2020 spin_unlock_irqrestore(&info->
lock,flags);
2023 if (newsigs.dsr_up == oldsigs.dsr_up &&
2024 newsigs.dsr_down == oldsigs.dsr_down &&
2025 newsigs.dcd_up == oldsigs.dcd_up &&
2026 newsigs.dcd_down == oldsigs.dcd_down &&
2027 newsigs.cts_up == oldsigs.cts_up &&
2028 newsigs.cts_down == oldsigs.cts_down &&
2029 newsigs.ri_up == oldsigs.ri_up &&
2030 newsigs.ri_down == oldsigs.ri_down &&
2031 cnow.exithunt == cprev.exithunt &&
2032 cnow.rxidle == cprev.rxidle) {
2041 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
2043 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
2045 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
2046 (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
2058 if (mask & MgslEvent_ExitHuntMode) {
2062 spin_unlock_irqrestore(&info->
lock,flags);
2070 static int modem_input_wait(
MGSLPC_INFO *info,
int arg)
2072 unsigned long flags;
2082 spin_unlock_irqrestore(&info->
lock,flags);
2086 if (signal_pending(
current)) {
2095 spin_unlock_irqrestore(&info->
lock,flags);
2098 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2099 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2105 if ((arg &
TIOCM_RNG && cnow.rng != cprev.rng) ||
2106 (arg &
TIOCM_DSR && cnow.dsr != cprev.dsr) ||
2107 (arg &
TIOCM_CD && cnow.dcd != cprev.dcd) ||
2108 (arg &
TIOCM_CTS && cnow.cts != cprev.cts)) {
2126 unsigned long flags;
2130 spin_unlock_irqrestore(&info->
lock,flags);
2140 printk(
"%s(%d):%s tiocmget() value=%08X\n",
2148 unsigned int set,
unsigned int clear)
2151 unsigned long flags;
2154 printk(
"%s(%d):%s tiocmset(%x,%x)\n",
2159 if (
set & TIOCM_DTR)
2163 if (clear & TIOCM_DTR)
2168 spin_unlock_irqrestore(&info->
lock,flags);
2178 static int mgslpc_break(
struct tty_struct *tty,
int break_state)
2181 unsigned long flags;
2184 printk(
"%s(%d):mgslpc_break(%s,%d)\n",
2185 __FILE__,__LINE__, info->
device_name, break_state);
2187 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_break"))
2191 if (break_state == -1)
2195 spin_unlock_irqrestore(&info->
lock,flags);
2199 static int mgslpc_get_icount(
struct tty_struct *tty,
2204 unsigned long flags;
2208 spin_unlock_irqrestore(&info->
lock,flags);
2210 icount->
cts = cnow.cts;
2211 icount->
dsr = cnow.dsr;
2212 icount->
rng = cnow.rng;
2213 icount->
dcd = cnow.dcd;
2214 icount->
rx = cnow.rx;
2215 icount->
tx = cnow.tx;
2216 icount->
frame = cnow.frame;
2217 icount->
overrun = cnow.overrun;
2218 icount->
parity = cnow.parity;
2219 icount->
brk = cnow.brk;
2235 static int mgslpc_ioctl(
struct tty_struct *tty,
2236 unsigned int cmd,
unsigned long arg)
2239 void __user *
argp = (
void __user *)
arg;
2242 printk(
"%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
2245 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_ioctl"))
2256 return get_params(info,
argp);
2258 return set_params(info,
argp, tty);
2260 return get_txidle(info,
argp);
2262 return set_txidle(info, (
int)arg);
2264 return get_interface(info,
argp);
2266 return set_interface(info,(
int)arg);
2268 return set_txenable(info,(
int)arg, tty);
2270 return set_rxenable(info,(
int)arg);
2276 return wait_events(info,
argp);
2278 return modem_input_wait(info,(
int)arg);
2295 unsigned long flags;
2298 printk(
"%s(%d):mgslpc_set_termios %s\n", __FILE__,__LINE__,
2302 if ((tty->termios.c_cflag == old_termios->
c_cflag)
2307 mgslpc_change_params(info, tty);
2310 if (old_termios->
c_cflag & CBAUD &&
2311 !(tty->termios.c_cflag & CBAUD)) {
2315 spin_unlock_irqrestore(&info->
lock,flags);
2319 if (!(old_termios->
c_cflag & CBAUD) &&
2320 tty->termios.c_cflag & CBAUD) {
2322 if (!(tty->termios.c_cflag & CRTSCTS) ||
2328 spin_unlock_irqrestore(&info->
lock,flags);
2332 if (old_termios->
c_cflag & CRTSCTS &&
2333 !(tty->termios.c_cflag & CRTSCTS)) {
2339 static void mgslpc_close(
struct tty_struct *tty,
struct file * filp)
2344 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_close"))
2348 printk(
"%s(%d):mgslpc_close(%s) entry, count=%d\n",
2357 mgslpc_wait_until_sent(tty, info->
timeout);
2359 mgslpc_flush_buffer(tty);
2362 shutdown(info, tty);
2368 printk(
"%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
2374 static void mgslpc_wait_until_sent(
struct tty_struct *tty,
int timeout)
2377 unsigned long orig_jiffies, char_time;
2383 printk(
"%s(%d):mgslpc_wait_until_sent(%s) entry\n",
2386 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_wait_until_sent"))
2401 char_time = info->
timeout/(32 * 5);
2408 char_time =
min_t(
unsigned long, char_time, timeout);
2415 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
2424 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
2431 printk(
"%s(%d):mgslpc_wait_until_sent(%s) exit\n",
2438 static void mgslpc_hangup(
struct tty_struct *tty)
2443 printk(
"%s(%d):mgslpc_hangup(%s)\n",
2446 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_hangup"))
2449 mgslpc_flush_buffer(tty);
2450 shutdown(info, tty);
2457 unsigned long flags;
2461 spin_unlock_irqrestore(&info->
lock,flags);
2471 unsigned long flags;
2479 spin_unlock_irqrestore(&info->
lock,flags);
2483 static int mgslpc_open(
struct tty_struct *tty,
struct file * filp)
2488 unsigned long flags;
2492 if (line >= mgslpc_device_count) {
2493 printk(
"%s(%d):mgslpc_open with invalid line #%d.\n",
2494 __FILE__,__LINE__,line);
2499 info = mgslpc_device_list;
2500 while(info && info->
line != line)
2502 if (mgslpc_paranoia_check(info, tty->
name,
"mgslpc_open"))
2510 printk(
"%s(%d):mgslpc_open(%s), old ref count = %d\n",
2511 __FILE__,__LINE__,tty->
driver->name, port->
count);
2527 spin_unlock_irqrestore(&info->
netlock, flags);
2530 spin_lock(&port->
lock);
2532 spin_unlock(&port->
lock);
2533 spin_unlock_irqrestore(&info->
netlock, flags);
2535 if (port->
count == 1) {
2537 retval = startup(info, tty);
2545 printk(
"%s(%d):block_til_ready(%s) returned %d\n",
2551 printk(
"%s(%d):mgslpc_open(%s) success\n",
2566 unsigned long flags;
2574 spin_unlock_irqrestore(&info->
lock,flags);
2579 strcat(stat_buf,
"|RTS");
2581 strcat(stat_buf,
"|CTS");
2583 strcat(stat_buf,
"|DTR");
2585 strcat(stat_buf,
"|DSR");
2594 if (info->
icount.txunder)
2596 if (info->
icount.txabort)
2598 if (info->
icount.rxshort)
2615 if (info->
icount.overrun)
2622 seq_printf(m,
"txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
2629 static int mgslpc_proc_show(
struct seq_file *m,
void *
v)
2633 seq_printf(m,
"synclink driver:%s\n", driver_version);
2635 info = mgslpc_device_list;
2650 .open = mgslpc_proc_open,
2675 rx_reset_buffers(info);
2687 if (rx_alloc_buffers(info) < 0 ) {
2689 release_resources(info);
2699 rx_free_buffers(info);
2710 info->
line = mgslpc_device_count;
2714 if (maxframe[info->
line])
2718 mgslpc_device_count++;
2720 if (!mgslpc_device_list)
2721 mgslpc_device_list =
info;
2734 printk(
"SyncLink PC Card %s:IO=%04X IRQ=%d\n",
2737 #if SYNCLINK_GENERIC_HDLC
2744 static void mgslpc_remove_device(
MGSLPC_INFO *remove_info)
2750 if (info == remove_info) {
2756 #if SYNCLINK_GENERIC_HDLC
2759 release_resources(info);
2761 mgslpc_device_count--;
2770 PCMCIA_DEVICE_MANF_CARD(0x02c5, 0x0050),
2775 static struct pcmcia_driver mgslpc_driver = {
2777 .name =
"synclink_cs",
2778 .probe = mgslpc_probe,
2779 .remove = mgslpc_detach,
2780 .id_table = mgslpc_ids,
2781 .suspend = mgslpc_suspend,
2782 .resume = mgslpc_resume,
2786 .open = mgslpc_open,
2787 .close = mgslpc_close,
2788 .write = mgslpc_write,
2789 .put_char = mgslpc_put_char,
2790 .flush_chars = mgslpc_flush_chars,
2791 .write_room = mgslpc_write_room,
2792 .chars_in_buffer = mgslpc_chars_in_buffer,
2793 .flush_buffer = mgslpc_flush_buffer,
2794 .ioctl = mgslpc_ioctl,
2795 .throttle = mgslpc_throttle,
2796 .unthrottle = mgslpc_unthrottle,
2797 .send_xchar = mgslpc_send_xchar,
2798 .break_ctl = mgslpc_break,
2799 .wait_until_sent = mgslpc_wait_until_sent,
2800 .set_termios = mgslpc_set_termios,
2802 .start = tx_release,
2803 .hangup = mgslpc_hangup,
2806 .get_icount = mgslpc_get_icount,
2807 .proc_fops = &mgslpc_proc_fops,
2810 static int __init synclink_cs_init(
void)
2814 if (break_on_load) {
2815 mgslpc_get_text_ptr();
2822 if (IS_ERR(serial_driver)) {
2823 rc = PTR_ERR(serial_driver);
2829 serial_driver->
name =
"ttySLP";
2830 serial_driver->
major = ttymajor;
2842 __FILE__, __LINE__);
2850 printk(
KERN_INFO "%s %s, tty major#%d\n", driver_name, driver_version,
2851 serial_driver->
major);
2862 static void __exit synclink_cs_exit(
void)
2872 static void mgslpc_set_rate(
MGSLPC_INFO *info,
unsigned char channel,
unsigned int rate)
2886 for (M = 1; N > 64 && M < 16; M++)
2899 (
unsigned char) ((M << 6) + N));
2900 val =
read_reg(info, (
unsigned char) (channel +
CCR2)) & 0x3f;
2901 val |= ((M << 4) & 0xc0);
2992 mgslpc_set_rate(info,
CHB, 921600);
3011 mgslpc_set_rate(info,
CHA, 1843200);
3021 unsigned char clkmode, clksubmode;
3029 clkmode = clksubmode = 0;
3113 val = 0x10 + clkmode;
3129 if (clkmode == 2 || clkmode == 3 || clkmode == 6
3130 || clkmode == 7 || (clkmode == 0 && clksubmode == 1))
3221 enable_auxclk(info);
3223 loopback_enable(info);
3236 wait_command_complete(info,
CHA);
3261 printk(
"%s(%d):rx_stop(%s)\n",
3274 printk(
"%s(%d):rx_start(%s)\n",
3277 rx_reset_buffers(info);
3290 printk(
"%s(%d):tx_start(%s)\n",
3311 tx_ready(info, tty);
3315 tx_ready(info, tty);
3328 printk(
"%s(%d):tx_stop(%s)\n",
3543 enable_auxclk(info);
3554 wait_command_complete(info,
CHA);
3573 unsigned char status = 0;
3640 unsigned int framesize = 0;
3641 unsigned long flags;
3642 bool return_frame =
false;
3656 if ((status & 0xf0) != 0xA0) {
3657 if (!(status & BIT7) || (status &
BIT4))
3659 else if (status &
BIT6)
3661 else if (!(status &
BIT5)) {
3664 return_frame =
true;
3667 #if SYNCLINK_GENERIC_HDLC
3669 info->netdev->stats.rx_errors++;
3670 info->netdev->stats.rx_frame_errors++;
3674 return_frame =
true;
3677 framesize = buf->
count;
3680 printk(
"%s(%d):rx_get_frame(%s) status=%04X size=%d\n",
3681 __FILE__,__LINE__,info->
device_name,status,framesize);
3684 trace_block(info, buf->
data, framesize, 0);
3700 #if SYNCLINK_GENERIC_HDLC
3702 hdlcdev_rx(info, buf->
data, framesize);
3705 ldisc_receive_buf(tty, buf->
data, info->
flag_buf, framesize);
3715 spin_unlock_irqrestore(&info->
lock,flags);
3722 static unsigned char patterns[] =
3723 { 0x00, 0xff, 0xaa, 0x55, 0x69, 0x96, 0x0f };
3724 static unsigned int count =
ARRAY_SIZE(patterns);
3727 unsigned long flags;
3732 for (i = 0; i <
count; i++) {
3742 spin_unlock_irqrestore(&info->
lock,flags);
3748 unsigned long end_time;
3749 unsigned long flags;
3765 spin_unlock_irqrestore(&info->
lock,flags);
3776 spin_unlock_irqrestore(&info->
lock,flags);
3785 printk(
"%s(%d):Register test failure for device %s Addr=%04X\n",
3790 if (!irq_test(info)) {
3792 printk(
"%s(%d):Interrupt test failure for device %s IRQ=%d\n",
3798 printk(
"%s(%d):device %s passed diagnostics\n",
3803 static void trace_block(
MGSLPC_INFO *info,
const char* data,
int count,
int xmit)
3818 for(i=0;i<linecount;i++)
3819 printk(
"%02X ",(
unsigned char)data[i]);
3822 for(i=0;i<linecount;i++) {
3823 if (data[i]>=040 && data[i]<=0176)
3841 unsigned long flags;
3844 printk(
"%s(%d):tx_timeout(%s)\n",
3848 info->
icount.txtimeout++;
3854 spin_unlock_irqrestore(&info->
lock,flags);
3856 #if SYNCLINK_GENERIC_HDLC
3858 hdlcdev_tx_done(info);
3863 bh_transmit(info, tty);
3868 #if SYNCLINK_GENERIC_HDLC
3880 static int hdlcdev_attach(
struct net_device *
dev,
unsigned short encoding,
3881 unsigned short parity)
3885 unsigned char new_encoding;
3886 unsigned short new_crctype;
3889 if (info->
port.count)
3916 mgslpc_program_hw(info, tty);
3933 unsigned long flags;
3939 netif_stop_queue(dev);
3942 skb_copy_from_linear_data(skb, info->
tx_buf, skb->
len);
3947 dev->
stats.tx_packets++;
3963 spin_unlock_irqrestore(&info->
lock,flags);
3976 static int hdlcdev_open(
struct net_device *dev)
3981 unsigned long flags;
3984 printk(
"%s:hdlcdev_open(%s)\n",__FILE__,dev->
name);
3994 spin_unlock_irqrestore(&info->
netlock, flags);
3998 spin_unlock_irqrestore(&info->
netlock, flags);
4002 if ((rc = startup(info, tty)) != 0) {
4006 spin_unlock_irqrestore(&info->
netlock, flags);
4011 mgslpc_program_hw(info, tty);
4016 netif_start_queue(dev);
4021 spin_unlock_irqrestore(&info->
lock, flags);
4037 static int hdlcdev_close(
struct net_device *dev)
4041 unsigned long flags;
4044 printk(
"%s:hdlcdev_close(%s)\n",__FILE__,dev->
name);
4046 netif_stop_queue(dev);
4049 shutdown(info, tty);
4055 spin_unlock_irqrestore(&info->
netlock, flags);
4069 static int hdlcdev_ioctl(
struct net_device *dev,
struct ifreq *ifr,
int cmd)
4078 printk(
"%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->
name);
4081 if (info->
port.count)
4087 memset(&new_line, 0, size);
4089 switch(ifr->ifr_settings.type) {
4093 if (ifr->ifr_settings.size < size) {
4094 ifr->ifr_settings.size =
size;
4158 mgslpc_program_hw(info, tty);
4173 static void hdlcdev_tx_timeout(
struct net_device *dev)
4176 unsigned long flags;
4179 printk(
"hdlcdev_tx_timeout(%s)\n",dev->
name);
4181 dev->
stats.tx_errors++;
4182 dev->
stats.tx_aborted_errors++;
4186 spin_unlock_irqrestore(&info->
lock,flags);
4188 netif_wake_queue(dev);
4199 if (netif_queue_stopped(info->netdev))
4200 netif_wake_queue(info->netdev);
4211 static void hdlcdev_rx(
MGSLPC_INFO *info,
char *buf,
int size)
4213 struct sk_buff *skb = dev_alloc_skb(size);
4221 dev->
stats.rx_dropped++;
4227 skb->
protocol = hdlc_type_trans(skb, dev);
4229 dev->
stats.rx_packets++;
4237 .ndo_stop = hdlcdev_close,
4240 .ndo_do_ioctl = hdlcdev_ioctl,
4241 .ndo_tx_timeout = hdlcdev_tx_timeout,
4275 hdlc = dev_to_hdlc(dev);
4276 hdlc->
attach = hdlcdev_attach;
4277 hdlc->
xmit = hdlcdev_xmit;
4300 info->netdev =
NULL;