28 #define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
30 # define BREAKPOINT() asm(" int $3");
32 # define BREAKPOINT() { }
35 #define MAX_DEVICES 12
37 #include <linux/module.h>
38 #include <linux/errno.h>
39 #include <linux/signal.h>
40 #include <linux/sched.h>
43 #include <linux/pci.h>
44 #include <linux/tty.h>
46 #include <linux/serial.h>
48 #include <linux/string.h>
49 #include <linux/fcntl.h>
50 #include <linux/ptrace.h>
54 #include <linux/slab.h>
55 #include <linux/netdevice.h>
64 #include <linux/bitops.h>
65 #include <asm/types.h>
68 #include <linux/hdlc.h>
69 #include <linux/synclink.h>
71 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINKMP_MODULE))
72 #define SYNCLINK_GENERIC_HDLC 1
74 #define SYNCLINK_GENERIC_HDLC 0
77 #define GET_USER(error,value,addr) error = get_user(value,addr)
78 #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
79 #define PUT_USER(error,value,addr) error = put_user(value,addr)
80 #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
82 #include <asm/uaccess.h>
101 #define SCABUFSIZE 1024
102 #define SCA_MEM_SIZE 0x40000
103 #define SCA_BASE_SIZE 512
104 #define SCA_REG_SIZE 16
105 #define SCA_MAX_PORTS 4
106 #define SCAMAXDESC 128
108 #define BUFFERLISTSIZE 4096
132 #define BH_TRANSMIT 2
135 #define IO_PIN_SHUTDOWN_LIMIT 100
275 #if SYNCLINK_GENERIC_HDLC
281 #define MGSL_MAGIC 0x5401
286 #define MISCSTATUS_DCD_LATCHED (SerialSignal_DCD<<8)
287 #define MISCSTATUS_RI_LATCHED (SerialSignal_RI<<8)
288 #define MISCSTATUS_CTS_LATCHED (SerialSignal_CTS<<8)
289 #define MISCSTATUS_DSR_LATCHED (SerialSignal_DSR<<8)
392 #define TXENABLE 0x02
393 #define TXDISABLE 0x03
394 #define TXCRCINIT 0x04
395 #define TXCRCEXCL 0x05
399 #define TXBUFCLR 0x09
401 #define RXENABLE 0x12
402 #define RXDISABLE 0x13
403 #define RXCRCINIT 0x14
404 #define RXREJECT 0x15
405 #define SEARCHMP 0x16
406 #define RXCRCEXCL 0x17
407 #define RXCRCCALC 0x18
413 #define FEICLEAR 0x02
450 static int synclinkmp_adapter_count = -1;
451 static int synclinkmp_device_count = 0;
458 static bool break_on_load = 0;
464 static int ttymajor = 0;
469 static int debug_level = 0;
477 static char *
driver_name =
"SyncLink MultiPort driver";
481 static void synclinkmp_remove_one(
struct pci_dev *
dev);
491 static struct pci_driver synclinkmp_pci_driver = {
492 .name =
"synclinkmp",
493 .id_table = synclinkmp_pci_tbl,
494 .probe = synclinkmp_init_one,
502 #define WAKEUP_CHARS 256
513 static int put_char(
struct tty_struct *tty,
unsigned char ch);
514 static void send_xchar(
struct tty_struct *tty,
char ch);
515 static void wait_until_sent(
struct tty_struct *tty,
int timeout);
516 static int write_room(
struct tty_struct *tty);
517 static void flush_chars(
struct tty_struct *tty);
518 static void flush_buffer(
struct tty_struct *tty);
520 static void tx_release(
struct tty_struct *tty);
522 static int ioctl(
struct tty_struct *tty,
unsigned int cmd,
unsigned long arg);
523 static int chars_in_buffer(
struct tty_struct *tty);
524 static void throttle(
struct tty_struct * tty);
525 static void unthrottle(
struct tty_struct * tty);
526 static int set_break(
struct tty_struct *tty,
int break_state);
528 #if SYNCLINK_GENERIC_HDLC
529 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
541 static int get_txidle(
SLMP_INFO *
info,
int __user *idle_mode);
547 static int wait_mgsl_event(
SLMP_INFO *
info,
int __user *mask_ptr);
550 unsigned int set,
unsigned int clear);
551 static int set_break(
struct tty_struct *tty,
int break_state);
554 static void device_init(
int adapter_num,
struct pci_dev *pdev);
580 static void rx_free_frame_buffers(
SLMP_INFO *
info,
unsigned int first,
unsigned int last);
620 static void status_timeout(
unsigned long context);
630 static unsigned char rx_active_fifo_level = 16;
631 static unsigned char tx_active_fifo_level = 16;
632 static unsigned char tx_negate_fifo_level = 32;
634 static u32 misc_ctrl_value = 0x007e4040;
635 static u32 lcr1_brdr_value = 0x00800028;
637 static u32 read_ahead_count = 8;
650 static unsigned char dma_priority = 0x04;
654 static u32 sca_pci_load_interval = 64;
662 static void* synclinkmp_get_text_ptr(
void);
663 static void* synclinkmp_get_text_ptr(
void) {
return synclinkmp_get_text_ptr;}
669 static const char *badmagic =
670 "Warning: bad magic number for synclinkmp_struct (%s) in %s\n";
671 static const char *badinfo =
672 "Warning: null synclinkmp_struct for (%s) in %s\n";
675 printk(badinfo, name, routine);
679 printk(badmagic, name, routine);
698 static void ldisc_receive_buf(
struct tty_struct *tty,
706 if (ld->
ops->receive_buf)
707 ld->
ops->receive_buf(tty, data, flags, count);
719 if (line >= synclinkmp_device_count) {
720 printk(
"%s(%d): open with invalid line #%d.\n",
721 __FILE__,__LINE__,line);
725 info = synclinkmp_device_list;
726 while (info && info->
line != line)
728 if (sanity_check(info, tty->
name,
"open"))
731 printk(
"%s(%d):%s device is not allocated, init error=%d\n",
750 info->
port.tty = tty;
753 printk(
"%s(%d):%s open(), old ref count = %d\n",
754 __FILE__,__LINE__,tty->
driver->name, info->
port.count);
770 spin_unlock_irqrestore(&info->
netlock, flags);
774 spin_unlock_irqrestore(&info->
netlock, flags);
776 if (info->
port.count == 1) {
778 retval = startup(info);
783 retval = block_til_ready(tty, filp, info);
786 printk(
"%s(%d):%s block_til_ready() returned %d\n",
792 printk(
"%s(%d):%s open() success\n",
814 if (sanity_check(info, tty->
name,
"close"))
818 printk(
"%s(%d):%s close() entry, count=%d\n",
826 wait_until_sent(tty, info->
timeout);
837 printk(
"%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
850 printk(
"%s(%d):%s hangup()\n",
853 if (sanity_check(info, tty->
name,
"hangup"))
861 info->
port.count = 0;
864 spin_unlock_irqrestore(&info->
port.lock, flags);
878 printk(
"%s(%d):%s set_termios()\n", __FILE__,__LINE__,
885 !(tty->termios.c_cflag &
CBAUD)) {
889 spin_unlock_irqrestore(&info->
lock,flags);
894 tty->termios.c_cflag &
CBAUD) {
896 if (!(tty->termios.c_cflag &
CRTSCTS) ||
902 spin_unlock_irqrestore(&info->
lock,flags);
907 !(tty->termios.c_cflag &
CRTSCTS)) {
924 const unsigned char *
buf,
int count)
931 printk(
"%s(%d):%s write() count=%d\n",
934 if (sanity_check(info, tty->
name,
"write"))
954 tx_load_dma_buffer(info, buf, count);
959 c =
min_t(
int, count,
972 spin_unlock_irqrestore(&info->
lock,flags);
991 spin_unlock_irqrestore(&info->
lock,flags);
996 printk(
"%s(%d):%s write() returning=%d\n",
1003 static int put_char(
struct tty_struct *tty,
unsigned char ch)
1006 unsigned long flags;
1010 printk(
"%s(%d):%s put_char(%d)\n",
1014 if (sanity_check(info, tty->
name,
"put_char"))
1034 spin_unlock_irqrestore(&info->
lock,flags);
1040 static void send_xchar(
struct tty_struct *tty,
char ch)
1043 unsigned long flags;
1046 printk(
"%s(%d):%s send_xchar(%d)\n",
1049 if (sanity_check(info, tty->
name,
"send_xchar"))
1058 spin_unlock_irqrestore(&info->
lock,flags);
1064 static void wait_until_sent(
struct tty_struct *tty,
int timeout)
1067 unsigned long orig_jiffies, char_time;
1073 printk(
"%s(%d):%s wait_until_sent() entry\n",
1076 if (sanity_check(info, tty->
name,
"wait_until_sent"))
1091 char_time = info->
timeout/(32 * 5);
1098 char_time =
min_t(
unsigned long, char_time, timeout);
1105 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
1117 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
1124 printk(
"%s(%d):%s wait_until_sent() exit\n",
1130 static int write_room(
struct tty_struct *tty)
1135 if (sanity_check(info, tty->
name,
"write_room"))
1147 printk(
"%s(%d):%s write_room()=%d\n",
1155 static void flush_chars(
struct tty_struct *tty)
1158 unsigned long flags;
1161 printk(
"%s(%d):%s flush_chars() entry tx_count=%d\n",
1164 if (sanity_check(info, tty->
name,
"flush_chars"))
1172 printk(
"%s(%d):%s flush_chars() entry, starting transmitter\n",
1183 tx_load_dma_buffer(info,
1189 spin_unlock_irqrestore(&info->
lock,flags);
1194 static void flush_buffer(
struct tty_struct *tty)
1197 unsigned long flags;
1200 printk(
"%s(%d):%s flush_buffer() entry\n",
1203 if (sanity_check(info, tty->
name,
"flush_buffer"))
1209 spin_unlock_irqrestore(&info->
lock,flags);
1219 unsigned long flags;
1221 if (sanity_check(info, tty->
name,
"tx_hold"))
1225 printk(
"%s(%d):%s tx_hold()\n",
1231 spin_unlock_irqrestore(&info->
lock,flags);
1236 static void tx_release(
struct tty_struct *tty)
1239 unsigned long flags;
1241 if (sanity_check(info, tty->
name,
"tx_release"))
1245 printk(
"%s(%d):%s tx_release()\n",
1251 spin_unlock_irqrestore(&info->
lock,flags);
1265 unsigned int cmd,
unsigned long arg)
1271 printk(
"%s(%d):%s ioctl() cmd=%08X\n", __FILE__,__LINE__,
1274 if (sanity_check(info, tty->
name,
"ioctl"))
1285 return get_params(info, argp);
1287 return set_params(info, argp);
1289 return get_txidle(info, argp);
1291 return set_txidle(info, (
int)arg);
1293 return tx_enable(info, (
int)arg);
1295 return rx_enable(info, (
int)arg);
1301 return wait_mgsl_event(info, argp);
1308 return modem_input_wait(info,(
int)arg);
1322 static int get_icount(
struct tty_struct *tty,
1327 unsigned long flags;
1331 spin_unlock_irqrestore(&info->
lock,flags);
1333 icount->
cts = cnow.cts;
1334 icount->
dsr = cnow.dsr;
1335 icount->
rng = cnow.rng;
1336 icount->
dcd = cnow.dcd;
1337 icount->
rx = cnow.rx;
1338 icount->
tx = cnow.tx;
1339 icount->
frame = cnow.frame;
1340 icount->
overrun = cnow.overrun;
1341 icount->
parity = cnow.parity;
1342 icount->
brk = cnow.brk;
1355 unsigned long flags;
1357 seq_printf(m,
"%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
1358 "\tIRQ=%d MaxFrameSize=%u\n",
1370 spin_unlock_irqrestore(&info->
lock,flags);
1375 strcat(stat_buf,
"|RTS");
1377 strcat(stat_buf,
"|CTS");
1379 strcat(stat_buf,
"|DTR");
1381 strcat(stat_buf,
"|DSR");
1390 if (info->
icount.txunder)
1392 if (info->
icount.txabort)
1394 if (info->
icount.rxshort)
1411 if (info->
icount.overrun)
1418 seq_printf(m,
"\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
1425 static int synclinkmp_proc_show(
struct seq_file *m,
void *
v)
1429 seq_printf(m,
"synclinkmp driver:%s\n", driver_version);
1431 info = synclinkmp_device_list;
1446 .open = synclinkmp_proc_open,
1454 static int chars_in_buffer(
struct tty_struct *tty)
1458 if (sanity_check(info, tty->
name,
"chars_in_buffer"))
1462 printk(
"%s(%d):%s chars_in_buffer()=%d\n",
1470 static void throttle(
struct tty_struct * tty)
1473 unsigned long flags;
1476 printk(
"%s(%d):%s throttle() entry\n",
1479 if (sanity_check(info, tty->
name,
"throttle"))
1485 if (tty->termios.c_cflag &
CRTSCTS) {
1489 spin_unlock_irqrestore(&info->
lock,flags);
1495 static void unthrottle(
struct tty_struct * tty)
1498 unsigned long flags;
1501 printk(
"%s(%d):%s unthrottle() entry\n",
1504 if (sanity_check(info, tty->
name,
"unthrottle"))
1514 if (tty->termios.c_cflag &
CRTSCTS) {
1518 spin_unlock_irqrestore(&info->
lock,flags);
1525 static int set_break(
struct tty_struct *tty,
int break_state)
1527 unsigned char RegValue;
1529 unsigned long flags;
1532 printk(
"%s(%d):%s set_break(%d)\n",
1533 __FILE__,__LINE__, info->
device_name, break_state);
1535 if (sanity_check(info, tty->
name,
"set_break"))
1540 if (break_state == -1)
1545 spin_unlock_irqrestore(&info->
lock,flags);
1549 #if SYNCLINK_GENERIC_HDLC
1561 static int hdlcdev_attach(
struct net_device *
dev,
unsigned short encoding,
1562 unsigned short parity)
1565 unsigned char new_encoding;
1566 unsigned short new_crctype;
1569 if (info->
port.count)
1610 unsigned long flags;
1616 netif_stop_queue(dev);
1620 tx_load_dma_buffer(info, skb->
data, skb->
len);
1623 dev->
stats.tx_packets++;
1636 spin_unlock_irqrestore(&info->
lock,flags);
1649 static int hdlcdev_open(
struct net_device *dev)
1653 unsigned long flags;
1656 printk(
"%s:hdlcdev_open(%s)\n",__FILE__,dev->
name);
1666 spin_unlock_irqrestore(&info->
netlock, flags);
1670 spin_unlock_irqrestore(&info->
netlock, flags);
1673 if ((rc = startup(info)) != 0) {
1676 spin_unlock_irqrestore(&info->
netlock, flags);
1686 netif_start_queue(dev);
1691 spin_unlock_irqrestore(&info->
lock, flags);
1707 static int hdlcdev_close(
struct net_device *dev)
1710 unsigned long flags;
1713 printk(
"%s:hdlcdev_close(%s)\n",__FILE__,dev->
name);
1715 netif_stop_queue(dev);
1724 spin_unlock_irqrestore(&info->
netlock, flags);
1738 static int hdlcdev_ioctl(
struct net_device *dev,
struct ifreq *ifr,
int cmd)
1747 printk(
"%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->
name);
1750 if (info->
port.count)
1756 switch(ifr->ifr_settings.type) {
1760 if (ifr->ifr_settings.size < size) {
1761 ifr->ifr_settings.size =
size;
1837 static void hdlcdev_tx_timeout(
struct net_device *dev)
1840 unsigned long flags;
1843 printk(
"hdlcdev_tx_timeout(%s)\n",dev->
name);
1845 dev->
stats.tx_errors++;
1846 dev->
stats.tx_aborted_errors++;
1850 spin_unlock_irqrestore(&info->
lock,flags);
1852 netif_wake_queue(dev);
1861 static void hdlcdev_tx_done(
SLMP_INFO *info)
1863 if (netif_queue_stopped(info->netdev))
1864 netif_wake_queue(info->netdev);
1875 static void hdlcdev_rx(
SLMP_INFO *info,
char *buf,
int size)
1877 struct sk_buff *skb = dev_alloc_skb(size);
1886 dev->
stats.rx_dropped++;
1892 skb->
protocol = hdlc_type_trans(skb, dev);
1894 dev->
stats.rx_packets++;
1902 .ndo_stop = hdlcdev_close,
1905 .ndo_do_ioctl = hdlcdev_ioctl,
1906 .ndo_tx_timeout = hdlcdev_tx_timeout,
1917 static int hdlcdev_init(
SLMP_INFO *info)
1941 hdlc = dev_to_hdlc(dev);
1942 hdlc->
attach = hdlcdev_attach;
1943 hdlc->
xmit = hdlcdev_xmit;
1962 static void hdlcdev_exit(
SLMP_INFO *info)
1966 info->netdev =
NULL;
1977 unsigned long flags;
1999 spin_unlock_irqrestore(&info->
lock,flags);
2015 printk(
"%s(%d):%s bh_handler() entry\n",
2020 while((action = bh_action(info)) != 0) {
2024 printk(
"%s(%d):%s bh_handler() work item action=%d\n",
2040 printk(
"%s(%d):%s Unknown work item ID=%08X!\n",
2047 printk(
"%s(%d):%s bh_handler() exit\n",
2054 printk(
"%s(%d):%s bh_receive()\n",
2057 while( rx_get_frame(info) );
2060 static void bh_transmit(
SLMP_INFO *info)
2065 printk(
"%s(%d):%s bh_transmit() entry\n",
2075 printk(
"%s(%d):%s bh_status() entry\n",
2106 printk(
"%s(%d):%s isr_timer()\n",
2125 printk(
"%s(%d):%s isr_rxint status=%02X %02x\n",
2126 __FILE__,__LINE__,info->
device_name,status,status2);
2129 if (status &
BRKD) {
2138 tty_insert_flip_char(tty, 0,
TTY_BREAK);
2150 else if (status &
IDLD)
2156 if (status &
CDCD) {
2172 unsigned char DataByte;
2177 printk(
"%s(%d):%s isr_rxrdy\n",
2189 printk(
"%s(%d):%s rxerr=%04X\n",
2195 else if (status &
FRME)
2197 else if (status &
OVRN)
2209 else if (status & FRME)
2211 if (status & OVRN) {
2222 tty_insert_flip_char(tty, DataByte, flag);
2229 printk(
"%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
2239 static void isr_txeom(
SLMP_INFO * info,
unsigned char status)
2242 printk(
"%s(%d):%s isr_txeom status=%02x\n",
2249 if (status &
UDRN) {
2265 else if (status &
IDLE)
2280 #if SYNCLINK_GENERIC_HDLC
2282 hdlcdev_tx_done(info);
2286 if (info->
port.tty && (info->
port.tty->stopped || info->
port.tty->hw_stopped)) {
2307 printk(
"%s(%d):%s isr_txint status=%02x\n",
2310 if (status & (UDRN +
IDLE))
2311 isr_txeom(info, status);
2313 if (status &
CCTS) {
2330 printk(
"%s(%d):%s isr_txrdy() tx_count=%d\n",
2341 if (info->
port.tty && (info->
port.tty->stopped || info->
port.tty->hw_stopped)) {
2347 tx_load_fifo( info );
2358 static void isr_rxdmaok(
SLMP_INFO * info)
2369 printk(
"%s(%d):%s isr_rxdmaok(), status=%02x\n",
2375 static void isr_rxdmaerror(
SLMP_INFO * info)
2386 printk(
"%s(%d):%s isr_rxdmaerror(), status=%02x\n",
2393 static void isr_txdmaok(
SLMP_INFO * info)
2402 printk(
"%s(%d):%s isr_txdmaok(), status=%02x\n",
2411 static void isr_txdmaerror(
SLMP_INFO * info)
2422 printk(
"%s(%d):%s isr_txdmaerror(), status=%02x\n",
2433 printk(
"%s(%d):isr_io_pin status=%04X\n",
2434 __FILE__,__LINE__,status);
2464 #if SYNCLINK_GENERIC_HDLC
2466 if (status & SerialSignal_DCD)
2489 (status & MISCSTATUS_DCD_LATCHED) ) {
2492 (status & SerialSignal_DCD) ?
"on" :
"off");
2493 if (status & SerialSignal_DCD)
2497 printk(
"doing serial hangup...");
2503 if (tty_port_cts_enabled(&info->
port) &&
2504 (status & MISCSTATUS_CTS_LATCHED) ) {
2505 if ( info->
port.tty ) {
2506 if (info->
port.tty->hw_stopped) {
2509 printk(
"CTS tx start...");
2510 info->
port.tty->hw_stopped = 0;
2516 if (!(status & SerialSignal_CTS)) {
2518 printk(
"CTS tx stop...");
2519 info->
port.tty->hw_stopped = 1;
2541 unsigned char dmastatus, dmastatus0, dmastatus1=0;
2542 unsigned char timerstatus0, timerstatus1=0;
2543 unsigned char shift;
2551 spin_lock(&info->
lock);
2557 status0 = (
unsigned char)tmp;
2558 dmastatus0 = (
unsigned char)(tmp>>8);
2562 printk(
KERN_DEBUG "%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
2564 status0, dmastatus0, timerstatus0);
2569 status1 = (
unsigned char)tmp;
2570 dmastatus1 = (
unsigned char)(tmp>>8);
2574 printk(
"%s(%d):%s status1=%02x, dmastatus1=%02x, timerstatus1=%02x\n",
2576 status1,dmastatus1,timerstatus1);
2579 if (!status0 && !dmastatus0 && !timerstatus0 &&
2580 !status1 && !dmastatus1 && !timerstatus1)
2588 dmastatus = dmastatus0;
2591 dmastatus = dmastatus1;
2594 shift = i & 1 ? 4 :0;
2596 if (status & BIT0 << shift)
2598 if (status &
BIT1 << shift)
2600 if (status &
BIT2 << shift)
2602 if (status &
BIT3 << shift)
2605 if (dmastatus & BIT0 << shift)
2607 if (dmastatus &
BIT1 << shift)
2609 if (dmastatus &
BIT2 << shift)
2611 if (dmastatus &
BIT3 << shift)
2639 printk(
"%s(%d):%s queueing bh task.\n",
2646 spin_unlock(&info->
lock);
2680 change_params(info);
2696 unsigned long flags;
2702 printk(
"%s(%d):%s synclinkmp_shutdown()\n",
2720 if (!info->
port.tty || info->
port.tty->termios.c_cflag &
HUPCL) {
2725 spin_unlock_irqrestore(&info->
lock,flags);
2735 unsigned long flags;
2764 spin_unlock_irqrestore(&info->
lock,flags);
2769 static void change_params(
SLMP_INFO *info)
2774 if (!info->
port.tty)
2778 printk(
"%s(%d):%s change_params()\n",
2781 cflag = info->
port.tty->termios.c_cflag;
2792 switch (cflag &
CSIZE) {
2874 printk(
"%s(%d):%s get_params()\n",
2894 printk(
"%s(%d):%s get_params()\n",
2902 printk(
"%s(%d):%s get_params() user buffer copy failed\n",
2912 unsigned long flags;
2917 printk(
"%s(%d):%s set_params\n",
2922 printk(
"%s(%d):%s set_params() user buffer copy failed\n",
2930 spin_unlock_irqrestore(&info->
lock,flags);
2932 change_params(info);
2938 static int get_txidle(
SLMP_INFO * info,
int __user *idle_mode)
2943 printk(
"%s(%d):%s get_txidle()=%d\n",
2949 printk(
"%s(%d):%s get_txidle() user buffer copy failed\n",
2957 static int set_txidle(
SLMP_INFO * info,
int idle_mode)
2959 unsigned long flags;
2962 printk(
"%s(%d):%s set_txidle(%d)\n",
2967 tx_set_idle( info );
2968 spin_unlock_irqrestore(&info->
lock,flags);
2974 unsigned long flags;
2977 printk(
"%s(%d):%s tx_enable(%d)\n",
2989 spin_unlock_irqrestore(&info->
lock,flags);
2997 unsigned long flags;
3000 printk(
"%s(%d):%s tx_abort()\n",
3015 spin_unlock_irqrestore(&info->
lock,flags);
3019 static int rx_enable(
SLMP_INFO * info,
int enable)
3021 unsigned long flags;
3024 printk(
"%s(%d):%s rx_enable(%d)\n",
3035 spin_unlock_irqrestore(&info->
lock,flags);
3041 static int wait_mgsl_event(
SLMP_INFO * info,
int __user *mask_ptr)
3043 unsigned long flags;
3058 printk(
"%s(%d):%s wait_mgsl_event(%d)\n",
3073 spin_unlock_irqrestore(&info->
lock,flags);
3084 unsigned char newval = oldval +
3087 if ( oldval != newval ) {
3096 spin_unlock_irqrestore(&info->
lock,flags);
3100 if (signal_pending(
current)) {
3110 spin_unlock_irqrestore(&info->
lock,flags);
3113 if (newsigs.dsr_up == oldsigs.dsr_up &&
3114 newsigs.dsr_down == oldsigs.dsr_down &&
3115 newsigs.dcd_up == oldsigs.dcd_up &&
3116 newsigs.dcd_down == oldsigs.dcd_down &&
3117 newsigs.cts_up == oldsigs.cts_up &&
3118 newsigs.cts_down == oldsigs.cts_down &&
3119 newsigs.ri_up == oldsigs.ri_up &&
3120 newsigs.ri_down == oldsigs.ri_down &&
3121 cnow.exithunt == cprev.exithunt &&
3122 cnow.rxidle == cprev.rxidle) {
3131 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
3133 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
3135 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
3156 spin_unlock_irqrestore(&info->
lock,flags);
3165 static int modem_input_wait(
SLMP_INFO *info,
int arg)
3167 unsigned long flags;
3177 spin_unlock_irqrestore(&info->
lock,flags);
3181 if (signal_pending(
current)) {
3190 spin_unlock_irqrestore(&info->
lock,flags);
3193 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
3194 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
3200 if ((arg &
TIOCM_RNG && cnow.rng != cprev.rng) ||
3201 (arg &
TIOCM_DSR && cnow.dsr != cprev.dsr) ||
3202 (arg &
TIOCM_CD && cnow.dcd != cprev.dcd) ||
3203 (arg &
TIOCM_CTS && cnow.cts != cprev.cts)) {
3221 unsigned long flags;
3225 spin_unlock_irqrestore(&info->
lock,flags);
3235 printk(
"%s(%d):%s tiocmget() value=%08X\n",
3243 unsigned int set,
unsigned int clear)
3246 unsigned long flags;
3249 printk(
"%s(%d):%s tiocmset(%x,%x)\n",
3254 if (
set & TIOCM_DTR)
3258 if (clear & TIOCM_DTR)
3263 spin_unlock_irqrestore(&info->
lock,flags);
3268 static int carrier_raised(
struct tty_port *port)
3271 unsigned long flags;
3275 spin_unlock_irqrestore(&info->
lock,flags);
3280 static void dtr_rts(
struct tty_port *port,
int on)
3283 unsigned long flags;
3291 spin_unlock_irqrestore(&info->
lock,flags);
3296 static int block_til_ready(
struct tty_struct *tty,
struct file *filp,
3301 bool do_clocal =
false;
3302 bool extra_count =
false;
3303 unsigned long flags;
3308 printk(
"%s(%d):%s block_til_ready()\n",
3309 __FILE__,__LINE__, tty->
driver->name );
3318 if (tty->termios.c_cflag & CLOCAL)
3332 printk(
"%s(%d):%s block_til_ready() before block, count=%d\n",
3333 __FILE__,__LINE__, tty->
driver->name, port->
count );
3340 spin_unlock_irqrestore(&info->
lock, flags);
3344 if (tty->termios.c_cflag & CBAUD)
3360 if (signal_pending(
current)) {
3366 printk(
"%s(%d):%s block_til_ready() count=%d\n",
3367 __FILE__,__LINE__, tty->
driver->name, port->
count );
3382 printk(
"%s(%d):%s block_til_ready() after, count=%d\n",
3383 __FILE__,__LINE__, tty->
driver->name, port->
count );
3391 static int alloc_dma_bufs(
SLMP_INFO *info)
3393 unsigned short BuffersPerFrame;
3394 unsigned short BufferCount;
3439 printk(
"%s(%d):%s Allocating %d TX and %d RX DMA buffers.\n",
3443 if ( alloc_buf_list( info ) < 0 ||
3444 alloc_frame_bufs(info,
3448 alloc_frame_bufs(info,
3452 alloc_tmp_rx_buf(info) < 0 ) {
3453 printk(
"%s(%d):%s Can't allocate DMA buffer memory\n",
3458 rx_reset_buffers( info );
3465 static int alloc_buf_list(
SLMP_INFO *info)
3498 if ( i < info->rx_buf_count - 1 )
3515 if ( i < info->tx_buf_count - 1 )
3529 for ( i = 0; i <
count; i++ ) {
3531 phys_addr = info->
port_array[0]->last_mem_alloc;
3541 static void free_dma_bufs(
SLMP_INFO *info)
3551 static int alloc_tmp_rx_buf(
SLMP_INFO *info)
3559 static void free_tmp_rx_buf(
SLMP_INFO *info)
3565 static int claim_resources(
SLMP_INFO *info)
3568 printk(
"%s(%d):%s mem addr conflict, Addr=%08X\n",
3577 printk(
"%s(%d):%s lcr mem addr conflict, Addr=%08X\n",
3586 printk(
"%s(%d):%s sca mem addr conflict, Addr=%08X\n",
3595 printk(
"%s(%d):%s stat/ctrl mem addr conflict, Addr=%08X\n",
3606 printk(
"%s(%d):%s Can't map shared memory, MemAddr=%08X\n",
3614 printk(
"%s(%d):%s Can't map LCR memory, MemAddr=%08X\n",
3623 printk(
"%s(%d):%s Can't map SCA memory, MemAddr=%08X\n",
3633 printk(
"%s(%d):%s Can't map SCA Status/Control memory, MemAddr=%08X\n",
3640 if ( !memory_test(info) ) {
3641 printk(
"%s(%d):Shared Memory Test failed for device %s MemAddr=%08X\n",
3650 release_resources( info );
3654 static void release_resources(
SLMP_INFO *info)
3657 printk(
"%s(%d):%s release_resources() entry\n",
3703 printk(
"%s(%d):%s release_resources() exit\n",
3713 info->
line = synclinkmp_device_count;
3717 if (maxframe[info->
line])
3721 synclinkmp_device_count++;
3723 if ( !synclinkmp_device_list )
3724 synclinkmp_device_list =
info;
3726 SLMP_INFO *current_dev = synclinkmp_device_list;
3737 printk(
"SyncLink MultiPort %s: "
3738 "Mem=(%08x %08X %08x %08X) IRQ=%d MaxFrameSize=%u\n",
3747 #if SYNCLINK_GENERIC_HDLC
3769 printk(
"%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
3770 __FILE__,__LINE__, adapter_num, port_num);
3777 info->
port.close_delay = 5*
HZ/10;
3778 info->
port.closing_wait = 30*
HZ;
3812 (
unsigned long)info);
3837 static void device_init(
int adapter_num,
struct pci_dev *pdev)
3844 port_array[
port] = alloc_dev(adapter_num,port,pdev);
3845 if( port_array[port] ==
NULL ) {
3846 for ( --port; port >= 0; --
port )
3847 kfree(port_array[port]);
3854 memcpy(port_array[port]->port_array,port_array,
sizeof(port_array));
3855 add_device( port_array[port] );
3860 if ( !claim_resources(port_array[0]) ) {
3862 alloc_dma_bufs(port_array[0]);
3872 alloc_dma_bufs(port_array[port]);
3876 synclinkmp_interrupt,
3877 port_array[0]->irq_flags,
3879 port_array[0]) < 0 ) {
3880 printk(
"%s(%d):%s Can't request interrupt, IRQ=%d\n",
3883 port_array[0]->irq_level );
3887 adapter_test(port_array[0]);
3906 .break_ctl = set_break,
3910 .start = tx_release,
3915 .proc_fops = &synclinkmp_proc_fops,
3919 static void synclinkmp_cleanup(
void)
3927 if (serial_driver) {
3929 printk(
"%s(%d) failed to unregister tty driver err=%d\n",
3930 __FILE__,__LINE__,rc);
3935 info = synclinkmp_device_list;
3942 info = synclinkmp_device_list;
3944 #if SYNCLINK_GENERIC_HDLC
3947 free_dma_bufs(info);
3948 free_tmp_rx_buf(info);
3952 release_resources(info);
3965 static int __init synclinkmp_init(
void)
3969 if (break_on_load) {
3970 synclinkmp_get_text_ptr();
3976 if ((rc = pci_register_driver(&synclinkmp_pci_driver)) < 0) {
3977 printk(
"%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
3981 serial_driver = alloc_tty_driver(128);
3982 if (!serial_driver) {
3990 serial_driver->
name =
"ttySLM";
3991 serial_driver->
major = ttymajor;
4003 printk(
"%s(%d):Couldn't register serial driver\n",
4006 serial_driver =
NULL;
4010 printk(
"%s %s, tty major#%d\n",
4012 serial_driver->
major);
4017 synclinkmp_cleanup();
4021 static void __exit synclinkmp_exit(
void)
4023 synclinkmp_cleanup();
4033 static void enable_loopback(
SLMP_INFO *info,
int enable)
4043 write_control_reg(info);
4072 set_rate(info, 3686400);
4083 unsigned char BRValue;
4088 if (data_rate != 0) {
4089 Divisor = 14745600/data_rate;
4096 if (TMCValue != 1 && TMCValue != 2) {
4108 for(; TMCValue > 256 && BRValue < 10; BRValue++)
4112 (
unsigned char)((
read_reg(info,
TXS) & 0xf0) | BRValue));
4114 (
unsigned char)((
read_reg(info,
RXS) & 0xf0) | BRValue));
4129 printk(
"%s(%d):%s rx_stop()\n",
4152 printk(
"%s(%d):%s rx_start()\n",
4172 read_status_reg(info);
4207 printk(
"%s(%d):%s tx_start() tx_count=%d\n",
4236 (
unsigned short)(((tx_negate_fifo_level-1)<<8) + tx_active_fifo_level));
4277 printk(
"%s(%d):%s tx_stop()\n",
4301 static void tx_load_fifo(
SLMP_INFO *info)
4374 static void reset_adapter(
SLMP_INFO *info)
4389 unsigned char RegValue;
4420 case 7: RegValue |=
BIT4 +
BIT2;
break;
4421 case 6: RegValue |=
BIT5 +
BIT3;
break;
4440 RegValue |= (BIT1 +
BIT0);
4466 write_control_reg(info);
4527 unsigned char RegValue;
4645 write_control_reg(info);
4666 write_reg(info,
TRC1, (
unsigned char)(tx_negate_fifo_level - 1));
4722 enable_loopback(info,1);
4727 static void tx_set_idle(
SLMP_INFO *info)
4729 unsigned char RegValue = 0xff;
4750 u16 gpstatus = read_status_reg(info);
4758 if (!(status &
BIT3))
4761 if ( !(status &
BIT2))
4764 testbit = BIT1 << (info->
port_num * 2);
4765 if (!(gpstatus & testbit))
4768 testbit = BIT0 << (info->
port_num * 2);
4769 if (!(gpstatus & testbit))
4778 unsigned char RegValue;
4789 EnableBit = BIT1 << (info->
port_num*2);
4791 info->
port_array[0]->ctrlreg_value &= ~EnableBit;
4793 info->
port_array[0]->ctrlreg_value |= EnableBit;
4794 write_control_reg(info);
4805 static void rx_reset_buffers(
SLMP_INFO *info)
4807 rx_free_frame_buffers(info, 0, info->
rx_buf_count - 1);
4816 static void rx_free_frame_buffers(
SLMP_INFO *info,
unsigned int first,
unsigned int last)
4824 if (first == last) {
4844 static bool rx_get_frame(
SLMP_INFO *info)
4846 unsigned int StartIndex, EndIndex;
4848 unsigned int framesize = 0;
4849 bool ReturnCode =
false;
4850 unsigned long flags;
4852 unsigned char addr_field = 0xff;
4873 if (desc->
status == 0xff)
4879 framesize += desc->
length;
4895 spin_unlock_irqrestore(&info->
lock,flags);
4921 if (framesize == 0 ||
4926 rx_free_frame_buffers(info, StartIndex, EndIndex);
4933 if (status & (
BIT6+BIT5+BIT3+BIT2)) {
4939 else if (status & BIT5)
4941 else if (status & BIT3)
4947 #if SYNCLINK_GENERIC_HDLC
4949 info->netdev->stats.rx_errors++;
4950 info->netdev->stats.rx_frame_errors++;
4956 printk(
"%s(%d):%s rx_get_frame() status=%04X size=%d\n",
4957 __FILE__,__LINE__,info->
device_name,status,framesize);
4968 int copy_count = framesize;
4969 int index = StartIndex;
4980 ptmp += partial_count;
4981 copy_count -= partial_count;
4987 #if SYNCLINK_GENERIC_HDLC
4997 rx_free_frame_buffers( info, StartIndex, EndIndex );
5009 spin_unlock_irqrestore(&info->
lock,flags);
5018 static void tx_load_dma_buffer(
SLMP_INFO *info,
const char *buf,
unsigned int count)
5020 unsigned short copy_count;
5038 load_pci_memory(info, desc_ex->
virt_addr,buf,copy_count);
5040 desc->
length = copy_count;
5044 count -= copy_count;
5060 static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
5061 static unsigned int count =
ARRAY_SIZE(testval);
5064 unsigned long flags;
5075 for (i = 0 ; i <
count ; i++) {
5092 spin_unlock_irqrestore(&info->
lock,flags);
5099 unsigned long timeout;
5100 unsigned long flags;
5132 spin_unlock_irqrestore(&info->
lock,flags);
5141 spin_unlock_irqrestore(&info->
lock,flags);
5189 static bool init_adapter(
SLMP_INFO *info)
5206 readval = *MiscCtrl;
5213 write_control_reg(info);
5217 lcr1_brdr_value &= ~(BIT5 +
BIT4 +
BIT3);
5219 switch(read_ahead_count)
5222 lcr1_brdr_value |= BIT5 +
BIT4 +
BIT3;
5225 lcr1_brdr_value |= BIT5 +
BIT4;
5228 lcr1_brdr_value |= BIT5 +
BIT3;
5231 lcr1_brdr_value |=
BIT5;
5235 *LCR1BRDR = lcr1_brdr_value;
5236 *MiscCtrl = misc_ctrl_value;
5248 static bool loopback_test(
SLMP_INFO *info)
5250 #define TESTFRAMESIZE 20
5252 unsigned long timeout;
5256 unsigned long flags;
5269 buf[count] = (
unsigned char)
count;
5276 enable_loopback(info,1);
5279 tx_load_dma_buffer(info,buf,count);
5281 spin_unlock_irqrestore(&info->
lock,flags);
5285 for ( timeout = 100; timeout; --timeout ) {
5288 if (rx_get_frame(info)) {
5302 reset_adapter(info);
5303 spin_unlock_irqrestore(&info->
lock,flags);
5306 info->
port.tty = oldtty;
5313 static int adapter_test(
SLMP_INFO *info )
5315 unsigned long flags;
5317 printk(
"%s(%d):Testing device %s\n",
5322 spin_unlock_irqrestore(&info->
lock,flags);
5336 printk(
"%s(%d):Register test failure for device %s Addr=%08lX\n",
5345 printk(
"%s(%d):Interrupt test failure for device %s IRQ=%d\n",
5354 printk(
"%s(%d):DMA test failure for device %s\n",
5360 printk(
"%s(%d):device %s passed diagnostics\n",
5375 static bool memory_test(
SLMP_INFO *info)
5377 static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
5378 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
5388 if ( *addr != testval[i] )
5395 for ( i = 0 ; i <
limit ; i++ ) {
5403 if ( *addr != i * 4 )
5427 static void load_pci_memory(
SLMP_INFO *info,
char*
dest,
const char*
src,
unsigned short count)
5432 unsigned short interval = count / sca_pci_load_interval;
5437 memcpy(dest, src, sca_pci_load_interval);
5438 read_status_reg(info);
5439 dest += sca_pci_load_interval;
5440 src += sca_pci_load_interval;
5443 memcpy(dest, src, count % sca_pci_load_interval);
5446 static void trace_block(
SLMP_INFO *info,
const char* data,
int count,
int xmit)
5461 for(i=0;i<linecount;i++)
5462 printk(
"%02X ",(
unsigned char)data[i]);
5465 for(i=0;i<linecount;i++) {
5466 if (data[i]>=040 && data[i]<=0176)
5484 unsigned long flags;
5487 printk(
"%s(%d):%s tx_timeout()\n",
5490 info->
icount.txtimeout++;
5496 spin_unlock_irqrestore(&info->
lock,flags);
5498 #if SYNCLINK_GENERIC_HDLC
5500 hdlcdev_tx_done(info);
5508 static void status_timeout(
unsigned long context)
5512 unsigned long flags;
5513 unsigned char delta;
5518 spin_unlock_irqrestore(&info->
lock,flags);
5531 if (delta & SerialSignal_DCD)
5538 isr_io_pin(info,status);
5547 #define CALC_REGADDR() \
5548 unsigned char * RegAddr = (unsigned char*)(info->sca_base + Addr); \
5549 if (info->port_num > 1) \
5551 if ( info->port_num & 1) { \
5554 else if (Addr > 0x1f && Addr < 0x60) \
5573 return *((
u16 *)RegAddr);
5579 *((
u16 *)RegAddr) = Value;
5582 static unsigned char read_status_reg(
SLMP_INFO * info)
5584 unsigned char *RegAddr = (
unsigned char *)info->
statctrl_base;
5588 static void write_control_reg(
SLMP_INFO * info)
5590 unsigned char *RegAddr = (
unsigned char *)info->
statctrl_base;
5591 *RegAddr = info->
port_array[0]->ctrlreg_value;
5599 printk(
"error enabling pci device %p\n", dev);
5602 device_init( ++synclinkmp_adapter_count, dev );