2 * $Id: synclinkmp.c,v 4.22 2004/06/03 14:50:10 paulkf Exp $
4 * Device driver for Microgate SyncLink Multiport
5 * high speed multiprotocol serial adapter.
7 * written by Paul Fulghum for Microgate Corporation
10 * Microgate and SyncLink are trademarks of Microgate Corporation
12 * Derived from serial.c written by Theodore Ts'o and Linus Torvalds
13 * This code is released under the GNU General Public License (GPL)
15 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
16 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
25 * OF THE POSSIBILITY OF SUCH DAMAGE.
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/config.h>
38 #include <linux/module.h>
39 #include <linux/errno.h>
40 #include <linux/signal.h>
41 #include <linux/sched.h>
42 #include <linux/timer.h>
43 #include <linux/interrupt.h>
44 #include <linux/pci.h>
45 #include <linux/tty.h>
46 #include <linux/tty_flip.h>
47 #include <linux/serial.h>
48 #include <linux/major.h>
49 #include <linux/string.h>
50 #include <linux/fcntl.h>
51 #include <linux/ptrace.h>
52 #include <linux/ioport.h>
54 #include <linux/slab.h>
55 #include <linux/netdevice.h>
56 #include <linux/vmalloc.h>
57 #include <linux/init.h>
58 #include <asm/serial.h>
59 #include <linux/delay.h>
60 #include <linux/ioctl.h>
62 #include <asm/system.h>
66 #include <asm/bitops.h>
67 #include <asm/types.h>
68 #include <linux/termios.h>
69 #include <linux/workqueue.h>
71 #ifdef CONFIG_SYNCLINK_SYNCPPP_MODULE
72 #define CONFIG_SYNCLINK_SYNCPPP 1
75 #ifdef CONFIG_SYNCLINK_SYNCPPP
76 #include <net/syncppp.h>
79 #define GET_USER(error,value,addr) error = get_user(value,addr)
80 #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
81 #define PUT_USER(error,value,addr) error = put_user(value,addr)
82 #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
84 #include <asm/uaccess.h>
86 #include "linux/synclink.h"
88 static MGSL_PARAMS default_params = {
89 MGSL_MODE_HDLC, /* unsigned long mode */
90 0, /* unsigned char loopback; */
91 HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
92 HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
93 0, /* unsigned long clock_speed; */
94 0xff, /* unsigned char addr_filter; */
95 HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
96 HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
97 HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
98 9600, /* unsigned long data_rate; */
99 8, /* unsigned char data_bits; */
100 1, /* unsigned char stop_bits; */
101 ASYNC_PARITY_NONE /* unsigned char parity; */
104 /* size in bytes of DMA data buffers */
105 #define SCABUFSIZE 1024
106 #define SCA_MEM_SIZE 0x40000
107 #define SCA_BASE_SIZE 512
108 #define SCA_REG_SIZE 16
109 #define SCA_MAX_PORTS 4
110 #define SCAMAXDESC 128
112 #define BUFFERLISTSIZE 4096
114 /* SCA-I style DMA buffer descriptor */
115 typedef struct _SCADESC
117 u16 next; /* lower l6 bits of next descriptor addr */
118 u16 buf_ptr; /* lower 16 bits of buffer addr */
119 u8 buf_base; /* upper 8 bits of buffer addr */
121 u16 length; /* length of buffer */
122 u8 status; /* status of buffer */
124 } SCADESC, *PSCADESC;
126 typedef struct _SCADESC_EX
128 /* device driver bookkeeping section */
129 char *virt_addr; /* virtual address of data buffer */
130 u16 phys_entry; /* lower 16-bits of physical address of this descriptor */
131 } SCADESC_EX, *PSCADESC_EX;
133 /* The queue of BH actions to be performed */
136 #define BH_TRANSMIT 2
139 #define IO_PIN_SHUTDOWN_LIMIT 100
141 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
143 struct _input_signal_events {
155 * Device instance data structure
157 typedef struct _synclinkmp_info {
158 void *if_ptr; /* General purpose pointer (used by SPPP) */
161 int count; /* count of opens */
163 unsigned short close_delay;
164 unsigned short closing_wait; /* time to wait before closing */
166 struct mgsl_icount icount;
168 struct tty_struct *tty;
170 int x_char; /* xon/xoff character */
171 int blocked_open; /* # of blocked opens */
172 u16 read_status_mask1; /* break detection (SR1 indications) */
173 u16 read_status_mask2; /* parity/framing/overun (SR2 indications) */
174 unsigned char ignore_status_mask1; /* break detection (SR1 indications) */
175 unsigned char ignore_status_mask2; /* parity/framing/overun (SR2 indications) */
176 unsigned char *tx_buf;
181 wait_queue_head_t open_wait;
182 wait_queue_head_t close_wait;
184 wait_queue_head_t status_event_wait_q;
185 wait_queue_head_t event_wait_q;
186 struct timer_list tx_timer; /* HDLC transmit timeout timer */
187 struct _synclinkmp_info *next_device; /* device list link */
188 struct timer_list status_timer; /* input signal status check timer */
190 spinlock_t lock; /* spinlock for synchronizing with ISR */
191 struct work_struct task; /* task structure for scheduling bh */
193 u32 max_frame_size; /* as set by device config */
197 int bh_running; /* Protection from multiple */
201 int dcd_chkcount; /* check counts to prevent */
202 int cts_chkcount; /* too many IRQs if a signal */
203 int dsr_chkcount; /* is floating */
206 char *buffer_list; /* virtual address of Rx & Tx buffer lists */
207 unsigned long buffer_list_phys;
209 unsigned int rx_buf_count; /* count of total allocated Rx buffers */
210 SCADESC *rx_buf_list; /* list of receive buffer entries */
211 SCADESC_EX rx_buf_list_ex[SCAMAXDESC]; /* list of receive buffer entries */
212 unsigned int current_rx_buf;
214 unsigned int tx_buf_count; /* count of total allocated Tx buffers */
215 SCADESC *tx_buf_list; /* list of transmit buffer entries */
216 SCADESC_EX tx_buf_list_ex[SCAMAXDESC]; /* list of transmit buffer entries */
217 unsigned int last_tx_buf;
219 unsigned char *tmp_rx_buf;
220 unsigned int tmp_rx_buf_count;
229 unsigned char ie0_value;
230 unsigned char ie1_value;
231 unsigned char ie2_value;
232 unsigned char ctrlreg_value;
233 unsigned char old_signals;
235 char device_name[25]; /* device instance name */
241 struct _synclinkmp_info *port_array[SCA_MAX_PORTS];
243 unsigned int bus_type; /* expansion bus type (ISA,EISA,PCI) */
245 unsigned int irq_level; /* interrupt level */
246 unsigned long irq_flags;
247 int irq_requested; /* nonzero if IRQ requested */
249 MGSL_PARAMS params; /* communications parameters */
251 unsigned char serial_signals; /* current serial signal states */
253 int irq_occurred; /* for diagnostics use */
254 unsigned int init_error; /* Initialization startup error */
257 unsigned char* memory_base; /* shared memory address (PCI only) */
258 u32 phys_memory_base;
259 int shared_mem_requested;
261 unsigned char* sca_base; /* HD64570 SCA Memory address */
264 int sca_base_requested;
266 unsigned char* lcr_base; /* local config registers (PCI only) */
269 int lcr_mem_requested;
271 unsigned char* statctrl_base; /* status/control register memory */
272 u32 phys_statctrl_base;
274 int sca_statctrl_requested;
277 char flag_buf[MAX_ASYNC_BUFFER_SIZE];
278 char char_buf[MAX_ASYNC_BUFFER_SIZE];
279 BOOLEAN drop_rts_on_tx_done;
281 struct _input_signal_events input_signal_events;
283 /* SPPP/Cisco HDLC device parts */
287 #ifdef CONFIG_SYNCLINK_SYNCPPP
288 struct ppp_device pppdev;
290 struct net_device *netdev;
291 struct net_device_stats netstats;
295 #define MGSL_MAGIC 0x5401
298 * define serial signal status change macros
300 #define MISCSTATUS_DCD_LATCHED (SerialSignal_DCD<<8) /* indicates change in DCD */
301 #define MISCSTATUS_RI_LATCHED (SerialSignal_RI<<8) /* indicates change in RI */
302 #define MISCSTATUS_CTS_LATCHED (SerialSignal_CTS<<8) /* indicates change in CTS */
303 #define MISCSTATUS_DSR_LATCHED (SerialSignal_DSR<<8) /* change in DSR */
305 /* Common Register macros */
324 /* MSCI Register macros */
354 /* Timer Register Macros */
364 /* DMA Controller Register macros */
396 /* combine with timer or DMA register address */
404 /* SCA Command Codes */
407 #define TXENABLE 0x02
408 #define TXDISABLE 0x03
409 #define TXCRCINIT 0x04
410 #define TXCRCEXCL 0x05
414 #define TXBUFCLR 0x09
416 #define RXENABLE 0x12
417 #define RXDISABLE 0x13
418 #define RXCRCINIT 0x14
419 #define RXREJECT 0x15
420 #define SEARCHMP 0x16
421 #define RXCRCEXCL 0x17
422 #define RXCRCCALC 0x18
426 /* DMA command codes */
428 #define FEICLEAR 0x02
461 #define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
464 * Global linked list of SyncLink devices
466 static SLMP_INFO *synclinkmp_device_list = NULL;
467 static int synclinkmp_adapter_count = -1;
468 static int synclinkmp_device_count = 0;
471 * Set this param to non-zero to load eax with the
472 * .text section address and breakpoint on module load.
473 * This is useful for use with gdb and add-symbol-file command.
475 static int break_on_load=0;
478 * Driver major number, defaults to zero to get auto
479 * assigned major number. May be forced as module parameter.
481 static int ttymajor=0;
484 * Array of user specified options for ISA adapters.
486 static int debug_level = 0;
487 static int maxframe[MAX_DEVICES] = {0,};
488 static int dosyncppp[MAX_DEVICES] = {0,};
490 MODULE_PARM(break_on_load,"i");
491 MODULE_PARM(ttymajor,"i");
492 MODULE_PARM(debug_level,"i");
493 MODULE_PARM(maxframe,"1-" __MODULE_STRING(MAX_DEVICES) "i");
494 MODULE_PARM(dosyncppp,"1-" __MODULE_STRING(MAX_DEVICES) "i");
496 static char *driver_name = "SyncLink MultiPort driver";
497 static char *driver_version = "$Revision: 4.22 $";
499 static int synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent);
500 static void synclinkmp_remove_one(struct pci_dev *dev);
502 static struct pci_device_id synclinkmp_pci_tbl[] = {
503 { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_SCA, PCI_ANY_ID, PCI_ANY_ID, },
504 { 0, }, /* terminate list */
506 MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
508 MODULE_LICENSE("GPL");
510 static struct pci_driver synclinkmp_pci_driver = {
511 .name = "synclinkmp",
512 .id_table = synclinkmp_pci_tbl,
513 .probe = synclinkmp_init_one,
514 .remove = __devexit_p(synclinkmp_remove_one),
518 static struct tty_driver *serial_driver;
520 /* number of characters left in xmit buffer before we ask for more */
521 #define WAKEUP_CHARS 256
524 #define MIN(a,b) ((a) < (b) ? (a) : (b))
530 static int open(struct tty_struct *tty, struct file * filp);
531 static void close(struct tty_struct *tty, struct file * filp);
532 static void hangup(struct tty_struct *tty);
533 static void set_termios(struct tty_struct *tty, struct termios *old_termios);
535 static int write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
536 static void put_char(struct tty_struct *tty, unsigned char ch);
537 static void send_xchar(struct tty_struct *tty, char ch);
538 static void wait_until_sent(struct tty_struct *tty, int timeout);
539 static int write_room(struct tty_struct *tty);
540 static void flush_chars(struct tty_struct *tty);
541 static void flush_buffer(struct tty_struct *tty);
542 static void tx_hold(struct tty_struct *tty);
543 static void tx_release(struct tty_struct *tty);
545 static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
546 static int read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
547 static int chars_in_buffer(struct tty_struct *tty);
548 static void throttle(struct tty_struct * tty);
549 static void unthrottle(struct tty_struct * tty);
550 static void set_break(struct tty_struct *tty, int break_state);
552 /* sppp support and callbacks */
554 #ifdef CONFIG_SYNCLINK_SYNCPPP
555 static void sppp_init(SLMP_INFO *info);
556 static void sppp_delete(SLMP_INFO *info);
557 static void sppp_rx_done(SLMP_INFO *info, char *buf, int size);
558 static void sppp_tx_done(SLMP_INFO *info);
560 static int sppp_cb_open(struct net_device *d);
561 static int sppp_cb_close(struct net_device *d);
562 static int sppp_cb_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
563 static int sppp_cb_tx(struct sk_buff *skb, struct net_device *dev);
564 static void sppp_cb_tx_timeout(struct net_device *dev);
565 static struct net_device_stats *sppp_cb_net_stats(struct net_device *dev);
570 static int get_stats(SLMP_INFO *info, struct mgsl_icount __user *user_icount);
571 static int get_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
572 static int set_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
573 static int get_txidle(SLMP_INFO *info, int __user *idle_mode);
574 static int set_txidle(SLMP_INFO *info, int idle_mode);
575 static int tx_enable(SLMP_INFO *info, int enable);
576 static int tx_abort(SLMP_INFO *info);
577 static int rx_enable(SLMP_INFO *info, int enable);
578 static int map_status(int signals);
579 static int modem_input_wait(SLMP_INFO *info,int arg);
580 static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
581 static int tiocmget(struct tty_struct *tty, struct file *file);
582 static int tiocmset(struct tty_struct *tty, struct file *file,
583 unsigned int set, unsigned int clear);
584 static void set_break(struct tty_struct *tty, int break_state);
586 static void add_device(SLMP_INFO *info);
587 static void device_init(int adapter_num, struct pci_dev *pdev);
588 static int claim_resources(SLMP_INFO *info);
589 static void release_resources(SLMP_INFO *info);
591 static int startup(SLMP_INFO *info);
592 static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
593 static void shutdown(SLMP_INFO *info);
594 static void program_hw(SLMP_INFO *info);
595 static void change_params(SLMP_INFO *info);
597 static int init_adapter(SLMP_INFO *info);
598 static int register_test(SLMP_INFO *info);
599 static int irq_test(SLMP_INFO *info);
600 static int loopback_test(SLMP_INFO *info);
601 static int adapter_test(SLMP_INFO *info);
602 static int memory_test(SLMP_INFO *info);
604 static void reset_adapter(SLMP_INFO *info);
605 static void reset_port(SLMP_INFO *info);
606 static void async_mode(SLMP_INFO *info);
607 static void hdlc_mode(SLMP_INFO *info);
609 static void rx_stop(SLMP_INFO *info);
610 static void rx_start(SLMP_INFO *info);
611 static void rx_reset_buffers(SLMP_INFO *info);
612 static void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last);
613 static int rx_get_frame(SLMP_INFO *info);
615 static void tx_start(SLMP_INFO *info);
616 static void tx_stop(SLMP_INFO *info);
617 static void tx_load_fifo(SLMP_INFO *info);
618 static void tx_set_idle(SLMP_INFO *info);
619 static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count);
621 static void get_signals(SLMP_INFO *info);
622 static void set_signals(SLMP_INFO *info);
623 static void enable_loopback(SLMP_INFO *info, int enable);
624 static void set_rate(SLMP_INFO *info, u32 data_rate);
626 static int bh_action(SLMP_INFO *info);
627 static void bh_handler(void* Context);
628 static void bh_receive(SLMP_INFO *info);
629 static void bh_transmit(SLMP_INFO *info);
630 static void bh_status(SLMP_INFO *info);
631 static void isr_timer(SLMP_INFO *info);
632 static void isr_rxint(SLMP_INFO *info);
633 static void isr_rxrdy(SLMP_INFO *info);
634 static void isr_txint(SLMP_INFO *info);
635 static void isr_txrdy(SLMP_INFO *info);
636 static void isr_rxdmaok(SLMP_INFO *info);
637 static void isr_rxdmaerror(SLMP_INFO *info);
638 static void isr_txdmaok(SLMP_INFO *info);
639 static void isr_txdmaerror(SLMP_INFO *info);
640 static void isr_io_pin(SLMP_INFO *info, u16 status);
642 static int alloc_dma_bufs(SLMP_INFO *info);
643 static void free_dma_bufs(SLMP_INFO *info);
644 static int alloc_buf_list(SLMP_INFO *info);
645 static int alloc_frame_bufs(SLMP_INFO *info, SCADESC *list, SCADESC_EX *list_ex,int count);
646 static int alloc_tmp_rx_buf(SLMP_INFO *info);
647 static void free_tmp_rx_buf(SLMP_INFO *info);
649 static void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count);
650 static void trace_block(SLMP_INFO *info, const char* data, int count, int xmit);
651 static void tx_timeout(unsigned long context);
652 static void status_timeout(unsigned long context);
654 static unsigned char read_reg(SLMP_INFO *info, unsigned char addr);
655 static void write_reg(SLMP_INFO *info, unsigned char addr, unsigned char val);
656 static u16 read_reg16(SLMP_INFO *info, unsigned char addr);
657 static void write_reg16(SLMP_INFO *info, unsigned char addr, u16 val);
658 static unsigned char read_status_reg(SLMP_INFO * info);
659 static void write_control_reg(SLMP_INFO * info);
662 static unsigned char rx_active_fifo_level = 16; // rx request FIFO activation level in bytes
663 static unsigned char tx_active_fifo_level = 16; // tx request FIFO activation level in bytes
664 static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes
666 static u32 misc_ctrl_value = 0x007e4040;
667 static u32 lcr1_brdr_value = 0x0080002d;
669 static u32 read_ahead_count = 8;
671 /* DPCR, DMA Priority Control
673 * 07..05 Not used, must be 0
674 * 04 BRC, bus release condition: 0=all transfers complete
675 * 1=release after 1 xfer on all channels
676 * 03 CCC, channel change condition: 0=every cycle
677 * 1=after each channel completes all xfers
678 * 02..00 PR<2..0>, priority 100=round robin
682 static unsigned char dma_priority = 0x04;
684 // Number of bytes that can be written to shared RAM
685 // in a single write operation
686 static u32 sca_pci_load_interval = 64;
689 * 1st function defined in .text section. Calling this function in
690 * init_module() followed by a breakpoint allows a remote debugger
691 * (gdb) to get the .text address for the add-symbol-file command.
692 * This allows remote debugging of dynamically loadable modules.
694 static void* synclinkmp_get_text_ptr(void);
695 static void* synclinkmp_get_text_ptr(void) {return synclinkmp_get_text_ptr;}
697 static inline int sanity_check(SLMP_INFO *info,
698 char *name, const char *routine)
701 static const char *badmagic =
702 "Warning: bad magic number for synclinkmp_struct (%s) in %s\n";
703 static const char *badinfo =
704 "Warning: null synclinkmp_struct for (%s) in %s\n";
707 printk(badinfo, name, routine);
710 if (info->magic != MGSL_MAGIC) {
711 printk(badmagic, name, routine);
723 /* Called when a port is opened. Init and enable port.
725 static int open(struct tty_struct *tty, struct file *filp)
732 if ((line < 0) || (line >= synclinkmp_device_count)) {
733 printk("%s(%d): open with invalid line #%d.\n",
734 __FILE__,__LINE__,line);
738 info = synclinkmp_device_list;
739 while(info && info->line != line)
740 info = info->next_device;
741 if (sanity_check(info, tty->name, "open"))
743 if ( info->init_error ) {
744 printk("%s(%d):%s device is not allocated, init error=%d\n",
745 __FILE__,__LINE__,info->device_name,info->init_error);
749 tty->driver_data = info;
752 if (debug_level >= DEBUG_LEVEL_INFO)
753 printk("%s(%d):%s open(), old ref count = %d\n",
754 __FILE__,__LINE__,tty->driver->name, info->count);
756 /* If port is closing, signal caller to try again */
757 if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
758 if (info->flags & ASYNC_CLOSING)
759 interruptible_sleep_on(&info->close_wait);
760 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
761 -EAGAIN : -ERESTARTSYS);
765 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
767 spin_lock_irqsave(&info->netlock, flags);
768 if (info->netcount) {
770 spin_unlock_irqrestore(&info->netlock, flags);
774 spin_unlock_irqrestore(&info->netlock, flags);
776 if (info->count == 1) {
777 /* 1st open on this device, init hardware */
778 retval = startup(info);
783 retval = block_til_ready(tty, filp, info);
785 if (debug_level >= DEBUG_LEVEL_INFO)
786 printk("%s(%d):%s block_til_ready() returned %d\n",
787 __FILE__,__LINE__, info->device_name, retval);
791 if (debug_level >= DEBUG_LEVEL_INFO)
792 printk("%s(%d):%s open() success\n",
793 __FILE__,__LINE__, info->device_name);
799 info->tty = 0; /* tty layer will release tty struct */
807 /* Called when port is closed. Wait for remaining data to be
808 * sent. Disable port and free resources.
810 static void close(struct tty_struct *tty, struct file *filp)
812 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
814 if (sanity_check(info, tty->name, "close"))
817 if (debug_level >= DEBUG_LEVEL_INFO)
818 printk("%s(%d):%s close() entry, count=%d\n",
819 __FILE__,__LINE__, info->device_name, info->count);
824 if (tty_hung_up_p(filp))
827 if ((tty->count == 1) && (info->count != 1)) {
829 * tty->count is 1 and the tty structure will be freed.
830 * info->count should be one in this case.
831 * if it's not, correct it so that the port is shutdown.
833 printk("%s(%d):%s close: bad refcount; tty->count is 1, "
834 "info->count is %d\n",
835 __FILE__,__LINE__, info->device_name, info->count);
841 /* if at least one open remaining, leave hardware active */
845 info->flags |= ASYNC_CLOSING;
847 /* set tty->closing to notify line discipline to
848 * only process XON/XOFF characters. Only the N_TTY
849 * discipline appears to use this (ppp does not).
853 /* wait for transmit data to clear all layers */
855 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
856 if (debug_level >= DEBUG_LEVEL_INFO)
857 printk("%s(%d):%s close() calling tty_wait_until_sent\n",
858 __FILE__,__LINE__, info->device_name );
859 tty_wait_until_sent(tty, info->closing_wait);
862 if (info->flags & ASYNC_INITIALIZED)
863 wait_until_sent(tty, info->timeout);
865 if (tty->driver->flush_buffer)
866 tty->driver->flush_buffer(tty);
868 if (tty->ldisc.flush_buffer)
869 tty->ldisc.flush_buffer(tty);
876 if (info->blocked_open) {
877 if (info->close_delay) {
878 set_current_state(TASK_INTERRUPTIBLE);
879 schedule_timeout(info->close_delay);
881 wake_up_interruptible(&info->open_wait);
884 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
886 wake_up_interruptible(&info->close_wait);
889 if (debug_level >= DEBUG_LEVEL_INFO)
890 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
891 tty->driver->name, info->count);
894 /* Called by tty_hangup() when a hangup is signaled.
895 * This is the same as closing all open descriptors for the port.
897 static void hangup(struct tty_struct *tty)
899 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
901 if (debug_level >= DEBUG_LEVEL_INFO)
902 printk("%s(%d):%s hangup()\n",
903 __FILE__,__LINE__, info->device_name );
905 if (sanity_check(info, tty->name, "hangup"))
912 info->flags &= ~ASYNC_NORMAL_ACTIVE;
915 wake_up_interruptible(&info->open_wait);
918 /* Set new termios settings
920 static void set_termios(struct tty_struct *tty, struct termios *old_termios)
922 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
925 if (debug_level >= DEBUG_LEVEL_INFO)
926 printk("%s(%d):%s set_termios()\n", __FILE__,__LINE__,
929 /* just return if nothing has changed */
930 if ((tty->termios->c_cflag == old_termios->c_cflag)
931 && (RELEVANT_IFLAG(tty->termios->c_iflag)
932 == RELEVANT_IFLAG(old_termios->c_iflag)))
937 /* Handle transition to B0 status */
938 if (old_termios->c_cflag & CBAUD &&
939 !(tty->termios->c_cflag & CBAUD)) {
940 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
941 spin_lock_irqsave(&info->lock,flags);
943 spin_unlock_irqrestore(&info->lock,flags);
946 /* Handle transition away from B0 status */
947 if (!(old_termios->c_cflag & CBAUD) &&
948 tty->termios->c_cflag & CBAUD) {
949 info->serial_signals |= SerialSignal_DTR;
950 if (!(tty->termios->c_cflag & CRTSCTS) ||
951 !test_bit(TTY_THROTTLED, &tty->flags)) {
952 info->serial_signals |= SerialSignal_RTS;
954 spin_lock_irqsave(&info->lock,flags);
956 spin_unlock_irqrestore(&info->lock,flags);
959 /* Handle turning off CRTSCTS */
960 if (old_termios->c_cflag & CRTSCTS &&
961 !(tty->termios->c_cflag & CRTSCTS)) {
967 /* Send a block of data
971 * tty pointer to tty information structure
972 * from_user flag: 1 = from user process
973 * buf pointer to buffer containing send data
974 * count size of send data in bytes
976 * Return Value: number of characters written
978 static int write(struct tty_struct *tty, int from_user,
979 const unsigned char *buf, int count)
982 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
985 if (debug_level >= DEBUG_LEVEL_INFO)
986 printk("%s(%d):%s write() count=%d\n",
987 __FILE__,__LINE__,info->device_name,count);
989 if (sanity_check(info, tty->name, "write"))
992 if (!tty || !info->tx_buf)
995 if (info->params.mode == MGSL_MODE_HDLC) {
996 if (count > info->max_frame_size) {
1000 if (info->tx_active)
1002 if (info->tx_count) {
1003 /* send accumulated data from send_char() calls */
1004 /* as frame and wait before accepting more data. */
1005 tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
1009 ret = info->tx_count = count;
1010 tx_load_dma_buffer(info, buf, count);
1017 MIN(info->max_frame_size - info->tx_count - 1,
1018 info->max_frame_size - info->tx_put));
1023 COPY_FROM_USER(err, info->tx_buf + info->tx_put, buf, c);
1030 memcpy(info->tx_buf + info->tx_put, buf, c);
1032 spin_lock_irqsave(&info->lock,flags);
1034 if (info->tx_put >= info->max_frame_size)
1035 info->tx_put -= info->max_frame_size;
1036 info->tx_count += c;
1037 spin_unlock_irqrestore(&info->lock,flags);
1044 if (info->params.mode == MGSL_MODE_HDLC) {
1046 ret = info->tx_count = 0;
1049 tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
1052 if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
1053 spin_lock_irqsave(&info->lock,flags);
1054 if (!info->tx_active)
1056 spin_unlock_irqrestore(&info->lock,flags);
1060 if (debug_level >= DEBUG_LEVEL_INFO)
1061 printk( "%s(%d):%s write() returning=%d\n",
1062 __FILE__,__LINE__,info->device_name,ret);
1066 /* Add a character to the transmit buffer.
1068 static void put_char(struct tty_struct *tty, unsigned char ch)
1070 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1071 unsigned long flags;
1073 if ( debug_level >= DEBUG_LEVEL_INFO ) {
1074 printk( "%s(%d):%s put_char(%d)\n",
1075 __FILE__,__LINE__,info->device_name,ch);
1078 if (sanity_check(info, tty->name, "put_char"))
1081 if (!tty || !info->tx_buf)
1084 spin_lock_irqsave(&info->lock,flags);
1086 if ( (info->params.mode != MGSL_MODE_HDLC) ||
1087 !info->tx_active ) {
1089 if (info->tx_count < info->max_frame_size - 1) {
1090 info->tx_buf[info->tx_put++] = ch;
1091 if (info->tx_put >= info->max_frame_size)
1092 info->tx_put -= info->max_frame_size;
1097 spin_unlock_irqrestore(&info->lock,flags);
1100 /* Send a high-priority XON/XOFF character
1102 static void send_xchar(struct tty_struct *tty, char ch)
1104 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1105 unsigned long flags;
1107 if (debug_level >= DEBUG_LEVEL_INFO)
1108 printk("%s(%d):%s send_xchar(%d)\n",
1109 __FILE__,__LINE__, info->device_name, ch );
1111 if (sanity_check(info, tty->name, "send_xchar"))
1116 /* Make sure transmit interrupts are on */
1117 spin_lock_irqsave(&info->lock,flags);
1118 if (!info->tx_enabled)
1120 spin_unlock_irqrestore(&info->lock,flags);
1124 /* Wait until the transmitter is empty.
1126 static void wait_until_sent(struct tty_struct *tty, int timeout)
1128 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
1129 unsigned long orig_jiffies, char_time;
1134 if (debug_level >= DEBUG_LEVEL_INFO)
1135 printk("%s(%d):%s wait_until_sent() entry\n",
1136 __FILE__,__LINE__, info->device_name );
1138 if (sanity_check(info, tty->name, "wait_until_sent"))
1141 if (!(info->flags & ASYNC_INITIALIZED))
1144 orig_jiffies = jiffies;
1146 /* Set check interval to 1/5 of estimated time to
1147 * send a character, and make it at least 1. The check
1148 * interval should also be less than the timeout.
1149 * Note: use tight timings here to satisfy the NIST-PCTS.
1152 if ( info->params.data_rate ) {
1153 char_time = info->timeout/(32 * 5);
1160 char_time = MIN(char_time, timeout);
1162 if ( info->params.mode == MGSL_MODE_HDLC ) {
1163 while (info->tx_active) {
1164 set_current_state(TASK_INTERRUPTIBLE);
1165 schedule_timeout(char_time);
1166 if (signal_pending(current))
1168 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1172 //TODO: determine if there is something similar to USC16C32
1173 // TXSTATUS_ALL_SENT status
1174 while ( info->tx_active && info->tx_enabled) {
1175 set_current_state(TASK_INTERRUPTIBLE);
1176 schedule_timeout(char_time);
1177 if (signal_pending(current))
1179 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1185 if (debug_level >= DEBUG_LEVEL_INFO)
1186 printk("%s(%d):%s wait_until_sent() exit\n",
1187 __FILE__,__LINE__, info->device_name );
1190 /* Return the count of free bytes in transmit buffer
1192 static int write_room(struct tty_struct *tty)
1194 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1197 if (sanity_check(info, tty->name, "write_room"))
1200 if (info->params.mode == MGSL_MODE_HDLC) {
1201 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
1203 ret = info->max_frame_size - info->tx_count - 1;
1208 if (debug_level >= DEBUG_LEVEL_INFO)
1209 printk("%s(%d):%s write_room()=%d\n",
1210 __FILE__, __LINE__, info->device_name, ret);
1215 /* enable transmitter and send remaining buffered characters
1217 static void flush_chars(struct tty_struct *tty)
1219 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1220 unsigned long flags;
1222 if ( debug_level >= DEBUG_LEVEL_INFO )
1223 printk( "%s(%d):%s flush_chars() entry tx_count=%d\n",
1224 __FILE__,__LINE__,info->device_name,info->tx_count);
1226 if (sanity_check(info, tty->name, "flush_chars"))
1229 if (info->tx_count <= 0 || tty->stopped || tty->hw_stopped ||
1233 if ( debug_level >= DEBUG_LEVEL_INFO )
1234 printk( "%s(%d):%s flush_chars() entry, starting transmitter\n",
1235 __FILE__,__LINE__,info->device_name );
1237 spin_lock_irqsave(&info->lock,flags);
1239 if (!info->tx_active) {
1240 if ( (info->params.mode == MGSL_MODE_HDLC) &&
1242 /* operating in synchronous (frame oriented) mode */
1243 /* copy data from circular tx_buf to */
1244 /* transmit DMA buffer. */
1245 tx_load_dma_buffer(info,
1246 info->tx_buf,info->tx_count);
1251 spin_unlock_irqrestore(&info->lock,flags);
1254 /* Discard all data in the send buffer
1256 static void flush_buffer(struct tty_struct *tty)
1258 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1259 unsigned long flags;
1261 if (debug_level >= DEBUG_LEVEL_INFO)
1262 printk("%s(%d):%s flush_buffer() entry\n",
1263 __FILE__,__LINE__, info->device_name );
1265 if (sanity_check(info, tty->name, "flush_buffer"))
1268 spin_lock_irqsave(&info->lock,flags);
1269 info->tx_count = info->tx_put = info->tx_get = 0;
1270 del_timer(&info->tx_timer);
1271 spin_unlock_irqrestore(&info->lock,flags);
1273 wake_up_interruptible(&tty->write_wait);
1274 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1275 tty->ldisc.write_wakeup)
1276 (tty->ldisc.write_wakeup)(tty);
1279 /* throttle (stop) transmitter
1281 static void tx_hold(struct tty_struct *tty)
1283 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1284 unsigned long flags;
1286 if (sanity_check(info, tty->name, "tx_hold"))
1289 if ( debug_level >= DEBUG_LEVEL_INFO )
1290 printk("%s(%d):%s tx_hold()\n",
1291 __FILE__,__LINE__,info->device_name);
1293 spin_lock_irqsave(&info->lock,flags);
1294 if (info->tx_enabled)
1296 spin_unlock_irqrestore(&info->lock,flags);
1299 /* release (start) transmitter
1301 static void tx_release(struct tty_struct *tty)
1303 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1304 unsigned long flags;
1306 if (sanity_check(info, tty->name, "tx_release"))
1309 if ( debug_level >= DEBUG_LEVEL_INFO )
1310 printk("%s(%d):%s tx_release()\n",
1311 __FILE__,__LINE__,info->device_name);
1313 spin_lock_irqsave(&info->lock,flags);
1314 if (!info->tx_enabled)
1316 spin_unlock_irqrestore(&info->lock,flags);
1319 /* Service an IOCTL request
1323 * tty pointer to tty instance data
1324 * file pointer to associated file object for device
1325 * cmd IOCTL command code
1326 * arg command argument/context
1328 * Return Value: 0 if success, otherwise error code
1330 static int ioctl(struct tty_struct *tty, struct file *file,
1331 unsigned int cmd, unsigned long arg)
1333 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1335 struct mgsl_icount cnow; /* kernel counter temps */
1336 struct serial_icounter_struct __user *p_cuser; /* user space */
1337 unsigned long flags;
1338 void __user *argp = (void __user *)arg;
1340 if (debug_level >= DEBUG_LEVEL_INFO)
1341 printk("%s(%d):%s ioctl() cmd=%08X\n", __FILE__,__LINE__,
1342 info->device_name, cmd );
1344 if (sanity_check(info, tty->name, "ioctl"))
1347 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1348 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1349 if (tty->flags & (1 << TTY_IO_ERROR))
1354 case MGSL_IOCGPARAMS:
1355 return get_params(info, argp);
1356 case MGSL_IOCSPARAMS:
1357 return set_params(info, argp);
1358 case MGSL_IOCGTXIDLE:
1359 return get_txidle(info, argp);
1360 case MGSL_IOCSTXIDLE:
1361 return set_txidle(info, (int)arg);
1362 case MGSL_IOCTXENABLE:
1363 return tx_enable(info, (int)arg);
1364 case MGSL_IOCRXENABLE:
1365 return rx_enable(info, (int)arg);
1366 case MGSL_IOCTXABORT:
1367 return tx_abort(info);
1368 case MGSL_IOCGSTATS:
1369 return get_stats(info, argp);
1370 case MGSL_IOCWAITEVENT:
1371 return wait_mgsl_event(info, argp);
1372 case MGSL_IOCLOOPTXDONE:
1373 return 0; // TODO: Not supported, need to document
1374 /* Wait for modem input (DCD,RI,DSR,CTS) change
1375 * as specified by mask in arg (TIOCM_RNG/DSR/CD/CTS)
1378 return modem_input_wait(info,(int)arg);
1381 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1382 * Return: write counters to the user passed counter struct
1383 * NB: both 1->0 and 0->1 transitions are counted except for
1384 * RI where only 0->1 is counted.
1387 spin_lock_irqsave(&info->lock,flags);
1388 cnow = info->icount;
1389 spin_unlock_irqrestore(&info->lock,flags);
1391 PUT_USER(error,cnow.cts, &p_cuser->cts);
1392 if (error) return error;
1393 PUT_USER(error,cnow.dsr, &p_cuser->dsr);
1394 if (error) return error;
1395 PUT_USER(error,cnow.rng, &p_cuser->rng);
1396 if (error) return error;
1397 PUT_USER(error,cnow.dcd, &p_cuser->dcd);
1398 if (error) return error;
1399 PUT_USER(error,cnow.rx, &p_cuser->rx);
1400 if (error) return error;
1401 PUT_USER(error,cnow.tx, &p_cuser->tx);
1402 if (error) return error;
1403 PUT_USER(error,cnow.frame, &p_cuser->frame);
1404 if (error) return error;
1405 PUT_USER(error,cnow.overrun, &p_cuser->overrun);
1406 if (error) return error;
1407 PUT_USER(error,cnow.parity, &p_cuser->parity);
1408 if (error) return error;
1409 PUT_USER(error,cnow.brk, &p_cuser->brk);
1410 if (error) return error;
1411 PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
1412 if (error) return error;
1415 return -ENOIOCTLCMD;
1421 * /proc fs routines....
1424 static inline int line_info(char *buf, SLMP_INFO *info)
1428 unsigned long flags;
1430 ret = sprintf(buf, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
1431 "\tIRQ=%d MaxFrameSize=%u\n",
1433 info->phys_sca_base,
1434 info->phys_memory_base,
1435 info->phys_statctrl_base,
1436 info->phys_lcr_base,
1438 info->max_frame_size );
1440 /* output current serial signal states */
1441 spin_lock_irqsave(&info->lock,flags);
1443 spin_unlock_irqrestore(&info->lock,flags);
1447 if (info->serial_signals & SerialSignal_RTS)
1448 strcat(stat_buf, "|RTS");
1449 if (info->serial_signals & SerialSignal_CTS)
1450 strcat(stat_buf, "|CTS");
1451 if (info->serial_signals & SerialSignal_DTR)
1452 strcat(stat_buf, "|DTR");
1453 if (info->serial_signals & SerialSignal_DSR)
1454 strcat(stat_buf, "|DSR");
1455 if (info->serial_signals & SerialSignal_DCD)
1456 strcat(stat_buf, "|CD");
1457 if (info->serial_signals & SerialSignal_RI)
1458 strcat(stat_buf, "|RI");
1460 if (info->params.mode == MGSL_MODE_HDLC) {
1461 ret += sprintf(buf+ret, "\tHDLC txok:%d rxok:%d",
1462 info->icount.txok, info->icount.rxok);
1463 if (info->icount.txunder)
1464 ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
1465 if (info->icount.txabort)
1466 ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
1467 if (info->icount.rxshort)
1468 ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);
1469 if (info->icount.rxlong)
1470 ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
1471 if (info->icount.rxover)
1472 ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
1473 if (info->icount.rxcrc)
1474 ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxcrc);
1476 ret += sprintf(buf+ret, "\tASYNC tx:%d rx:%d",
1477 info->icount.tx, info->icount.rx);
1478 if (info->icount.frame)
1479 ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
1480 if (info->icount.parity)
1481 ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
1482 if (info->icount.brk)
1483 ret += sprintf(buf+ret, " brk:%d", info->icount.brk);
1484 if (info->icount.overrun)
1485 ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
1488 /* Append serial signal status to end */
1489 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
1491 ret += sprintf(buf+ret, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
1492 info->tx_active,info->bh_requested,info->bh_running,
1498 /* Called to print information about devices
1500 int read_proc(char *page, char **start, off_t off, int count,
1501 int *eof, void *data)
1507 len += sprintf(page, "synclinkmp driver:%s\n", driver_version);
1509 info = synclinkmp_device_list;
1511 l = line_info(page + len, info);
1513 if (len+begin > off+count)
1515 if (len+begin < off) {
1519 info = info->next_device;
1524 if (off >= len+begin)
1526 *start = page + (off-begin);
1527 return ((count < begin+len-off) ? count : begin+len-off);
1530 /* Return the count of bytes in transmit buffer
1532 static int chars_in_buffer(struct tty_struct *tty)
1534 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1536 if (sanity_check(info, tty->name, "chars_in_buffer"))
1539 if (debug_level >= DEBUG_LEVEL_INFO)
1540 printk("%s(%d):%s chars_in_buffer()=%d\n",
1541 __FILE__, __LINE__, info->device_name, info->tx_count);
1543 return info->tx_count;
1546 /* Signal remote device to throttle send data (our receive data)
1548 static void throttle(struct tty_struct * tty)
1550 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1551 unsigned long flags;
1553 if (debug_level >= DEBUG_LEVEL_INFO)
1554 printk("%s(%d):%s throttle() entry\n",
1555 __FILE__,__LINE__, info->device_name );
1557 if (sanity_check(info, tty->name, "throttle"))
1561 send_xchar(tty, STOP_CHAR(tty));
1563 if (tty->termios->c_cflag & CRTSCTS) {
1564 spin_lock_irqsave(&info->lock,flags);
1565 info->serial_signals &= ~SerialSignal_RTS;
1567 spin_unlock_irqrestore(&info->lock,flags);
1571 /* Signal remote device to stop throttling send data (our receive data)
1573 static void unthrottle(struct tty_struct * tty)
1575 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1576 unsigned long flags;
1578 if (debug_level >= DEBUG_LEVEL_INFO)
1579 printk("%s(%d):%s unthrottle() entry\n",
1580 __FILE__,__LINE__, info->device_name );
1582 if (sanity_check(info, tty->name, "unthrottle"))
1589 send_xchar(tty, START_CHAR(tty));
1592 if (tty->termios->c_cflag & CRTSCTS) {
1593 spin_lock_irqsave(&info->lock,flags);
1594 info->serial_signals |= SerialSignal_RTS;
1596 spin_unlock_irqrestore(&info->lock,flags);
1600 /* set or clear transmit break condition
1601 * break_state -1=set break condition, 0=clear
1603 static void set_break(struct tty_struct *tty, int break_state)
1605 unsigned char RegValue;
1606 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
1607 unsigned long flags;
1609 if (debug_level >= DEBUG_LEVEL_INFO)
1610 printk("%s(%d):%s set_break(%d)\n",
1611 __FILE__,__LINE__, info->device_name, break_state);
1613 if (sanity_check(info, tty->name, "set_break"))
1616 spin_lock_irqsave(&info->lock,flags);
1617 RegValue = read_reg(info, CTL);
1618 if (break_state == -1)
1622 write_reg(info, CTL, RegValue);
1623 spin_unlock_irqrestore(&info->lock,flags);
1626 #ifdef CONFIG_SYNCLINK_SYNCPPP
1628 /* syncppp support and callbacks */
1630 static void cb_setup(struct net_device *dev)
1632 dev->open = sppp_cb_open;
1633 dev->stop = sppp_cb_close;
1634 dev->hard_start_xmit = sppp_cb_tx;
1635 dev->do_ioctl = sppp_cb_ioctl;
1636 dev->get_stats = sppp_cb_net_stats;
1637 dev->tx_timeout = sppp_cb_tx_timeout;
1638 dev->watchdog_timeo = 10*HZ;
1641 static void sppp_init(SLMP_INFO *info)
1643 struct net_device *d;
1645 sprintf(info->netname,"mgslm%dp%d",info->adapter_num,info->port_num);
1647 d = alloc_netdev(0, info->netname, cb_setup);
1649 printk(KERN_WARNING "%s: alloc_netdev failed.\n",
1654 info->if_ptr = &info->pppdev;
1655 info->netdev = info->pppdev.dev = d;
1657 d->irq = info->irq_level;
1660 sppp_attach(&info->pppdev);
1663 if (register_netdev(d)) {
1664 printk(KERN_WARNING "%s: register_netdev failed.\n", d->name);
1665 sppp_detach(info->netdev);
1666 info->netdev = NULL;
1667 info->pppdev.dev = NULL;
1672 if (debug_level >= DEBUG_LEVEL_INFO)
1673 printk("sppp_init(%s)\n",info->netname);
1676 static void sppp_delete(SLMP_INFO *info)
1678 if (debug_level >= DEBUG_LEVEL_INFO)
1679 printk("sppp_delete(%s)\n",info->netname);
1680 unregister_netdev(info->netdev);
1681 sppp_detach(info->netdev);
1682 free_netdev(info->netdev);
1683 info->netdev = NULL;
1684 info->pppdev.dev = NULL;
1687 static int sppp_cb_open(struct net_device *d)
1689 SLMP_INFO *info = d->priv;
1691 unsigned long flags;
1693 if (debug_level >= DEBUG_LEVEL_INFO)
1694 printk("sppp_cb_open(%s)\n",info->netname);
1696 spin_lock_irqsave(&info->netlock, flags);
1697 if (info->count != 0 || info->netcount != 0) {
1698 printk(KERN_WARNING "%s: sppp_cb_open returning busy\n", info->netname);
1699 spin_unlock_irqrestore(&info->netlock, flags);
1703 spin_unlock_irqrestore(&info->netlock, flags);
1705 /* claim resources and init adapter */
1706 if ((err = startup(info)) != 0)
1709 /* allow syncppp module to do open processing */
1710 if ((err = sppp_open(d)) != 0) {
1715 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
1718 d->trans_start = jiffies;
1719 netif_start_queue(d);
1723 spin_lock_irqsave(&info->netlock, flags);
1725 spin_unlock_irqrestore(&info->netlock, flags);
1729 static void sppp_cb_tx_timeout(struct net_device *dev)
1731 SLMP_INFO *info = dev->priv;
1732 unsigned long flags;
1734 if (debug_level >= DEBUG_LEVEL_INFO)
1735 printk("sppp_tx_timeout(%s)\n",info->netname);
1737 info->netstats.tx_errors++;
1738 info->netstats.tx_aborted_errors++;
1740 spin_lock_irqsave(&info->lock,flags);
1742 spin_unlock_irqrestore(&info->lock,flags);
1744 netif_wake_queue(dev);
1747 static int sppp_cb_tx(struct sk_buff *skb, struct net_device *dev)
1749 SLMP_INFO *info = dev->priv;
1750 unsigned long flags;
1752 if (debug_level >= DEBUG_LEVEL_INFO)
1753 printk("sppp_tx(%s)\n",info->netname);
1755 netif_stop_queue(dev);
1757 info->tx_count = skb->len;
1758 tx_load_dma_buffer(info, skb->data, skb->len);
1759 info->netstats.tx_packets++;
1760 info->netstats.tx_bytes += skb->len;
1763 dev->trans_start = jiffies;
1765 spin_lock_irqsave(&info->lock,flags);
1766 if (!info->tx_active)
1768 spin_unlock_irqrestore(&info->lock,flags);
1773 static int sppp_cb_close(struct net_device *d)
1775 SLMP_INFO *info = d->priv;
1776 unsigned long flags;
1778 if (debug_level >= DEBUG_LEVEL_INFO)
1779 printk("sppp_cb_close(%s)\n",info->netname);
1781 /* shutdown adapter and release resources */
1784 /* allow syncppp to do close processing */
1786 netif_stop_queue(d);
1788 spin_lock_irqsave(&info->netlock, flags);
1790 spin_unlock_irqrestore(&info->netlock, flags);
1794 static void sppp_rx_done(SLMP_INFO *info, char *buf, int size)
1796 struct sk_buff *skb = dev_alloc_skb(size);
1797 if (debug_level >= DEBUG_LEVEL_INFO)
1798 printk("sppp_rx_done(%s)\n",info->netname);
1800 printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n",
1802 info->netstats.rx_dropped++;
1806 memcpy(skb_put(skb, size),buf,size);
1808 skb->protocol = htons(ETH_P_WAN_PPP);
1809 skb->dev = info->netdev;
1810 skb->mac.raw = skb->data;
1811 info->netstats.rx_packets++;
1812 info->netstats.rx_bytes += size;
1814 info->netdev->trans_start = jiffies;
1817 static void sppp_tx_done(SLMP_INFO *info)
1819 if (netif_queue_stopped(info->netdev))
1820 netif_wake_queue(info->netdev);
1823 static struct net_device_stats *sppp_cb_net_stats(struct net_device *dev)
1825 SLMP_INFO *info = dev->priv;
1826 if (debug_level >= DEBUG_LEVEL_INFO)
1827 printk("net_stats(%s)\n",info->netname);
1828 return &info->netstats;
1831 static int sppp_cb_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1833 SLMP_INFO *info = dev->priv;
1834 if (debug_level >= DEBUG_LEVEL_INFO)
1835 printk("%s(%d):ioctl %s cmd=%08X\n", __FILE__,__LINE__,
1836 info->netname, cmd );
1837 return sppp_do_ioctl(dev, ifr, cmd);
1840 #endif /* ifdef CONFIG_SYNCLINK_SYNCPPP */
1843 /* Return next bottom half action to perform.
1844 * Return Value: BH action code or 0 if nothing to do.
1846 int bh_action(SLMP_INFO *info)
1848 unsigned long flags;
1851 spin_lock_irqsave(&info->lock,flags);
1853 if (info->pending_bh & BH_RECEIVE) {
1854 info->pending_bh &= ~BH_RECEIVE;
1856 } else if (info->pending_bh & BH_TRANSMIT) {
1857 info->pending_bh &= ~BH_TRANSMIT;
1859 } else if (info->pending_bh & BH_STATUS) {
1860 info->pending_bh &= ~BH_STATUS;
1865 /* Mark BH routine as complete */
1866 info->bh_running = 0;
1867 info->bh_requested = 0;
1870 spin_unlock_irqrestore(&info->lock,flags);
1875 /* Perform bottom half processing of work items queued by ISR.
1877 void bh_handler(void* Context)
1879 SLMP_INFO *info = (SLMP_INFO*)Context;
1885 if ( debug_level >= DEBUG_LEVEL_BH )
1886 printk( "%s(%d):%s bh_handler() entry\n",
1887 __FILE__,__LINE__,info->device_name);
1889 info->bh_running = 1;
1891 while((action = bh_action(info)) != 0) {
1893 /* Process work item */
1894 if ( debug_level >= DEBUG_LEVEL_BH )
1895 printk( "%s(%d):%s bh_handler() work item action=%d\n",
1896 __FILE__,__LINE__,info->device_name, action);
1910 /* unknown work item ID */
1911 printk("%s(%d):%s Unknown work item ID=%08X!\n",
1912 __FILE__,__LINE__,info->device_name,action);
1917 if ( debug_level >= DEBUG_LEVEL_BH )
1918 printk( "%s(%d):%s bh_handler() exit\n",
1919 __FILE__,__LINE__,info->device_name);
1922 void bh_receive(SLMP_INFO *info)
1924 if ( debug_level >= DEBUG_LEVEL_BH )
1925 printk( "%s(%d):%s bh_receive()\n",
1926 __FILE__,__LINE__,info->device_name);
1928 while( rx_get_frame(info) );
1931 void bh_transmit(SLMP_INFO *info)
1933 struct tty_struct *tty = info->tty;
1935 if ( debug_level >= DEBUG_LEVEL_BH )
1936 printk( "%s(%d):%s bh_transmit() entry\n",
1937 __FILE__,__LINE__,info->device_name);
1940 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1941 tty->ldisc.write_wakeup) {
1942 if ( debug_level >= DEBUG_LEVEL_BH )
1943 printk( "%s(%d):%s calling ldisc.write_wakeup\n",
1944 __FILE__,__LINE__,info->device_name);
1945 (tty->ldisc.write_wakeup)(tty);
1947 wake_up_interruptible(&tty->write_wait);
1951 void bh_status(SLMP_INFO *info)
1953 if ( debug_level >= DEBUG_LEVEL_BH )
1954 printk( "%s(%d):%s bh_status() entry\n",
1955 __FILE__,__LINE__,info->device_name);
1957 info->ri_chkcount = 0;
1958 info->dsr_chkcount = 0;
1959 info->dcd_chkcount = 0;
1960 info->cts_chkcount = 0;
1963 void isr_timer(SLMP_INFO * info)
1965 unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
1967 /* IER2<7..4> = timer<3..0> interrupt enables (0=disabled) */
1968 write_reg(info, IER2, 0);
1970 /* TMCS, Timer Control/Status Register
1972 * 07 CMF, Compare match flag (read only) 1=match
1973 * 06 ECMI, CMF Interrupt Enable: 0=disabled
1974 * 05 Reserved, must be 0
1975 * 04 TME, Timer Enable
1976 * 03..00 Reserved, must be 0
1980 write_reg(info, (unsigned char)(timer + TMCS), 0);
1982 info->irq_occurred = TRUE;
1984 if ( debug_level >= DEBUG_LEVEL_ISR )
1985 printk("%s(%d):%s isr_timer()\n",
1986 __FILE__,__LINE__,info->device_name);
1989 void isr_rxint(SLMP_INFO * info)
1991 struct tty_struct *tty = info->tty;
1992 struct mgsl_icount *icount = &info->icount;
1993 unsigned char status = read_reg(info, SR1);
1994 unsigned char status2 = read_reg(info, SR2);
1996 /* clear status bits */
1997 if ( status & (FLGD + IDLD + CDCD + BRKD) )
1998 write_reg(info, SR1,
1999 (unsigned char)(status & (FLGD + IDLD + CDCD + BRKD)));
2001 if ( status2 & OVRN )
2002 write_reg(info, SR2, (unsigned char)(status2 & OVRN));
2004 if ( debug_level >= DEBUG_LEVEL_ISR )
2005 printk("%s(%d):%s isr_rxint status=%02X %02x\n",
2006 __FILE__,__LINE__,info->device_name,status,status2);
2008 if (info->params.mode == MGSL_MODE_ASYNC) {
2009 if (status & BRKD) {
2012 /* process break detection if tty control
2013 * is not set to ignore it
2016 if (!(status & info->ignore_status_mask1)) {
2017 if (info->read_status_mask1 & BRKD) {
2018 *tty->flip.flag_buf_ptr = TTY_BREAK;
2019 if (info->flags & ASYNC_SAK)
2027 if (status & (FLGD|IDLD)) {
2029 info->icount.exithunt++;
2030 else if (status & IDLD)
2031 info->icount.rxidle++;
2032 wake_up_interruptible(&info->event_wait_q);
2036 if (status & CDCD) {
2037 /* simulate a common modem status change interrupt
2040 get_signals( info );
2042 MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD));
2047 * handle async rx data interrupts
2049 void isr_rxrdy(SLMP_INFO * info)
2052 unsigned char DataByte;
2053 struct tty_struct *tty = info->tty;
2054 struct mgsl_icount *icount = &info->icount;
2056 if ( debug_level >= DEBUG_LEVEL_ISR )
2057 printk("%s(%d):%s isr_rxrdy\n",
2058 __FILE__,__LINE__,info->device_name);
2060 while((status = read_reg(info,CST0)) & BIT0)
2062 DataByte = read_reg(info,TRB);
2065 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
2068 *tty->flip.char_buf_ptr = DataByte;
2069 *tty->flip.flag_buf_ptr = 0;
2074 if ( status & (PE + FRME + OVRN) ) {
2075 printk("%s(%d):%s rxerr=%04X\n",
2076 __FILE__,__LINE__,info->device_name,status);
2078 /* update error statistics */
2081 else if (status & FRME)
2083 else if (status & OVRN)
2086 /* discard char if tty control flags say so */
2087 if (status & info->ignore_status_mask2)
2090 status &= info->read_status_mask2;
2094 *tty->flip.flag_buf_ptr = TTY_PARITY;
2095 else if (status & FRME)
2096 *tty->flip.flag_buf_ptr = TTY_FRAME;
2097 if (status & OVRN) {
2098 /* Overrun is special, since it's
2099 * reported immediately, and doesn't
2100 * affect the current character
2102 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
2104 tty->flip.flag_buf_ptr++;
2105 tty->flip.char_buf_ptr++;
2106 *tty->flip.flag_buf_ptr = TTY_OVERRUN;
2110 } /* end of if (error) */
2113 tty->flip.flag_buf_ptr++;
2114 tty->flip.char_buf_ptr++;
2119 if ( debug_level >= DEBUG_LEVEL_ISR ) {
2120 printk("%s(%d):%s isr_rxrdy() flip count=%d\n",
2121 __FILE__,__LINE__,info->device_name,
2122 tty ? tty->flip.count : 0);
2123 printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
2124 __FILE__,__LINE__,info->device_name,
2125 icount->rx,icount->brk,icount->parity,
2126 icount->frame,icount->overrun);
2129 if ( tty && tty->flip.count )
2130 tty_flip_buffer_push(tty);
2133 void isr_txeom(SLMP_INFO * info, unsigned char status)
2135 if ( debug_level >= DEBUG_LEVEL_ISR )
2136 printk("%s(%d):%s isr_txeom status=%02x\n",
2137 __FILE__,__LINE__,info->device_name,status);
2139 /* disable and clear MSCI interrupts */
2140 info->ie1_value &= ~(IDLE + UDRN);
2141 write_reg(info, IE1, info->ie1_value);
2142 write_reg(info, SR1, (unsigned char)(UDRN + IDLE));
2144 write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
2145 write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
2146 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
2148 if ( info->tx_active ) {
2149 if (info->params.mode != MGSL_MODE_ASYNC) {
2151 info->icount.txunder++;
2152 else if (status & IDLE)
2153 info->icount.txok++;
2156 info->tx_active = 0;
2157 info->tx_count = info->tx_put = info->tx_get = 0;
2159 del_timer(&info->tx_timer);
2161 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done ) {
2162 info->serial_signals &= ~SerialSignal_RTS;
2163 info->drop_rts_on_tx_done = 0;
2167 #ifdef CONFIG_SYNCLINK_SYNCPPP
2173 if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
2177 info->pending_bh |= BH_TRANSMIT;
2184 * handle tx status interrupts
2186 void isr_txint(SLMP_INFO * info)
2188 unsigned char status = read_reg(info, SR1);
2190 /* clear status bits */
2191 write_reg(info, SR1, (unsigned char)(status & (UDRN + IDLE + CCTS)));
2193 if ( debug_level >= DEBUG_LEVEL_ISR )
2194 printk("%s(%d):%s isr_txint status=%02x\n",
2195 __FILE__,__LINE__,info->device_name,status);
2197 if (status & (UDRN + IDLE))
2198 isr_txeom(info, status);
2200 if (status & CCTS) {
2201 /* simulate a common modem status change interrupt
2204 get_signals( info );
2206 MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS));
2212 * handle async tx data interrupts
2214 void isr_txrdy(SLMP_INFO * info)
2216 if ( debug_level >= DEBUG_LEVEL_ISR )
2217 printk("%s(%d):%s isr_txrdy() tx_count=%d\n",
2218 __FILE__,__LINE__,info->device_name,info->tx_count);
2220 if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
2225 if ( info->tx_count )
2226 tx_load_fifo( info );
2228 info->tx_active = 0;
2229 info->ie0_value &= ~TXRDYE;
2230 write_reg(info, IE0, info->ie0_value);
2233 if (info->tx_count < WAKEUP_CHARS)
2234 info->pending_bh |= BH_TRANSMIT;
2237 void isr_rxdmaok(SLMP_INFO * info)
2239 /* BIT7 = EOT (end of transfer)
2240 * BIT6 = EOM (end of message/frame)
2242 unsigned char status = read_reg(info,RXDMA + DSR) & 0xc0;
2244 /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
2245 write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
2247 if ( debug_level >= DEBUG_LEVEL_ISR )
2248 printk("%s(%d):%s isr_rxdmaok(), status=%02x\n",
2249 __FILE__,__LINE__,info->device_name,status);
2251 info->pending_bh |= BH_RECEIVE;
2254 void isr_rxdmaerror(SLMP_INFO * info)
2256 /* BIT5 = BOF (buffer overflow)
2257 * BIT4 = COF (counter overflow)
2259 unsigned char status = read_reg(info,RXDMA + DSR) & 0x30;
2261 /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
2262 write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
2264 if ( debug_level >= DEBUG_LEVEL_ISR )
2265 printk("%s(%d):%s isr_rxdmaerror(), status=%02x\n",
2266 __FILE__,__LINE__,info->device_name,status);
2268 info->rx_overflow = TRUE;
2269 info->pending_bh |= BH_RECEIVE;
2272 void isr_txdmaok(SLMP_INFO * info)
2274 /* BIT7 = EOT (end of transfer, used for async mode)
2275 * BIT6 = EOM (end of message/frame, used for sync mode)
2277 * We don't look at DMA status because only EOT is enabled
2278 * and we always clear and disable all tx DMA IRQs.
2280 // unsigned char dma_status = read_reg(info,TXDMA + DSR) & 0xc0;
2281 unsigned char status_reg1 = read_reg(info, SR1);
2283 write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
2284 write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
2285 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
2287 if ( debug_level >= DEBUG_LEVEL_ISR )
2288 printk("%s(%d):%s isr_txdmaok(), status=%02x\n",
2289 __FILE__,__LINE__,info->device_name,status_reg1);
2291 /* If transmitter already idle, do end of frame processing,
2292 * otherwise enable interrupt for tx IDLE.
2294 if (status_reg1 & IDLE)
2295 isr_txeom(info, IDLE);
2297 /* disable and clear underrun IRQ, enable IDLE interrupt */
2298 info->ie1_value |= IDLE;
2299 info->ie1_value &= ~UDRN;
2300 write_reg(info, IE1, info->ie1_value);
2302 write_reg(info, SR1, UDRN);
2306 void isr_txdmaerror(SLMP_INFO * info)
2308 /* BIT5 = BOF (buffer overflow)
2309 * BIT4 = COF (counter overflow)
2311 unsigned char status = read_reg(info,TXDMA + DSR) & 0x30;
2313 /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
2314 write_reg(info, TXDMA + DSR, (unsigned char)(status | 1));
2316 if ( debug_level >= DEBUG_LEVEL_ISR )
2317 printk("%s(%d):%s isr_txdmaerror(), status=%02x\n",
2318 __FILE__,__LINE__,info->device_name,status);
2321 /* handle input serial signal changes
2323 void isr_io_pin( SLMP_INFO *info, u16 status )
2325 struct mgsl_icount *icount;
2327 if ( debug_level >= DEBUG_LEVEL_ISR )
2328 printk("%s(%d):isr_io_pin status=%04X\n",
2329 __FILE__,__LINE__,status);
2331 if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
2332 MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
2333 icount = &info->icount;
2334 /* update input line counters */
2335 if (status & MISCSTATUS_RI_LATCHED) {
2337 if ( status & SerialSignal_RI )
2338 info->input_signal_events.ri_up++;
2340 info->input_signal_events.ri_down++;
2342 if (status & MISCSTATUS_DSR_LATCHED) {
2344 if ( status & SerialSignal_DSR )
2345 info->input_signal_events.dsr_up++;
2347 info->input_signal_events.dsr_down++;
2349 if (status & MISCSTATUS_DCD_LATCHED) {
2350 if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
2351 info->ie1_value &= ~CDCD;
2352 write_reg(info, IE1, info->ie1_value);
2355 if (status & SerialSignal_DCD) {
2356 info->input_signal_events.dcd_up++;
2357 #ifdef CONFIG_SYNCLINK_SYNCPPP
2359 sppp_reopen(info->netdev);
2362 info->input_signal_events.dcd_down++;
2364 if (status & MISCSTATUS_CTS_LATCHED)
2366 if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
2367 info->ie1_value &= ~CCTS;
2368 write_reg(info, IE1, info->ie1_value);
2371 if ( status & SerialSignal_CTS )
2372 info->input_signal_events.cts_up++;
2374 info->input_signal_events.cts_down++;
2376 wake_up_interruptible(&info->status_event_wait_q);
2377 wake_up_interruptible(&info->event_wait_q);
2379 if ( (info->flags & ASYNC_CHECK_CD) &&
2380 (status & MISCSTATUS_DCD_LATCHED) ) {
2381 if ( debug_level >= DEBUG_LEVEL_ISR )
2382 printk("%s CD now %s...", info->device_name,
2383 (status & SerialSignal_DCD) ? "on" : "off");
2384 if (status & SerialSignal_DCD)
2385 wake_up_interruptible(&info->open_wait);
2387 if ( debug_level >= DEBUG_LEVEL_ISR )
2388 printk("doing serial hangup...");
2390 tty_hangup(info->tty);
2394 if ( (info->flags & ASYNC_CTS_FLOW) &&
2395 (status & MISCSTATUS_CTS_LATCHED) ) {
2397 if (info->tty->hw_stopped) {
2398 if (status & SerialSignal_CTS) {
2399 if ( debug_level >= DEBUG_LEVEL_ISR )
2400 printk("CTS tx start...");
2401 info->tty->hw_stopped = 0;
2403 info->pending_bh |= BH_TRANSMIT;
2407 if (!(status & SerialSignal_CTS)) {
2408 if ( debug_level >= DEBUG_LEVEL_ISR )
2409 printk("CTS tx stop...");
2410 info->tty->hw_stopped = 1;
2418 info->pending_bh |= BH_STATUS;
2421 /* Interrupt service routine entry point.
2424 * irq interrupt number that caused interrupt
2425 * dev_id device ID supplied during interrupt registration
2426 * regs interrupted processor context
2428 static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
2429 struct pt_regs *regs)
2432 unsigned char status, status0, status1=0;
2433 unsigned char dmastatus, dmastatus0, dmastatus1=0;
2434 unsigned char timerstatus0, timerstatus1=0;
2435 unsigned char shift;
2439 if ( debug_level >= DEBUG_LEVEL_ISR )
2440 printk("%s(%d): synclinkmp_interrupt(%d)entry.\n",
2441 __FILE__,__LINE__,irq);
2443 info = (SLMP_INFO *)dev_id;
2447 spin_lock(&info->lock);
2451 /* get status for SCA0 (ports 0-1) */
2452 tmp = read_reg16(info, ISR0); /* get ISR0 and ISR1 in one read */
2453 status0 = (unsigned char)tmp;
2454 dmastatus0 = (unsigned char)(tmp>>8);
2455 timerstatus0 = read_reg(info, ISR2);
2457 if ( debug_level >= DEBUG_LEVEL_ISR )
2458 printk("%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
2459 __FILE__,__LINE__,info->device_name,
2460 status0,dmastatus0,timerstatus0);
2462 if (info->port_count == 4) {
2463 /* get status for SCA1 (ports 2-3) */
2464 tmp = read_reg16(info->port_array[2], ISR0);
2465 status1 = (unsigned char)tmp;
2466 dmastatus1 = (unsigned char)(tmp>>8);
2467 timerstatus1 = read_reg(info->port_array[2], ISR2);
2469 if ( debug_level >= DEBUG_LEVEL_ISR )
2470 printk("%s(%d):%s status1=%02x, dmastatus1=%02x, timerstatus1=%02x\n",
2471 __FILE__,__LINE__,info->device_name,
2472 status1,dmastatus1,timerstatus1);
2475 if (!status0 && !dmastatus0 && !timerstatus0 &&
2476 !status1 && !dmastatus1 && !timerstatus1)
2479 for(i=0; i < info->port_count ; i++) {
2480 if (info->port_array[i] == NULL)
2484 dmastatus = dmastatus0;
2487 dmastatus = dmastatus1;
2490 shift = i & 1 ? 4 :0;
2492 if (status & BIT0 << shift)
2493 isr_rxrdy(info->port_array[i]);
2494 if (status & BIT1 << shift)
2495 isr_txrdy(info->port_array[i]);
2496 if (status & BIT2 << shift)
2497 isr_rxint(info->port_array[i]);
2498 if (status & BIT3 << shift)
2499 isr_txint(info->port_array[i]);
2501 if (dmastatus & BIT0 << shift)
2502 isr_rxdmaerror(info->port_array[i]);
2503 if (dmastatus & BIT1 << shift)
2504 isr_rxdmaok(info->port_array[i]);
2505 if (dmastatus & BIT2 << shift)
2506 isr_txdmaerror(info->port_array[i]);
2507 if (dmastatus & BIT3 << shift)
2508 isr_txdmaok(info->port_array[i]);
2511 if (timerstatus0 & (BIT5 | BIT4))
2512 isr_timer(info->port_array[0]);
2513 if (timerstatus0 & (BIT7 | BIT6))
2514 isr_timer(info->port_array[1]);
2515 if (timerstatus1 & (BIT5 | BIT4))
2516 isr_timer(info->port_array[2]);
2517 if (timerstatus1 & (BIT7 | BIT6))
2518 isr_timer(info->port_array[3]);
2521 for(i=0; i < info->port_count ; i++) {
2522 SLMP_INFO * port = info->port_array[i];
2524 /* Request bottom half processing if there's something
2525 * for it to do and the bh is not already running.
2527 * Note: startup adapter diags require interrupts.
2528 * do not request bottom half processing if the
2529 * device is not open in a normal mode.
2531 if ( port && (port->count || port->netcount) &&
2532 port->pending_bh && !port->bh_running &&
2533 !port->bh_requested ) {
2534 if ( debug_level >= DEBUG_LEVEL_ISR )
2535 printk("%s(%d):%s queueing bh task.\n",
2536 __FILE__,__LINE__,port->device_name);
2537 schedule_work(&port->task);
2538 port->bh_requested = 1;
2542 spin_unlock(&info->lock);
2544 if ( debug_level >= DEBUG_LEVEL_ISR )
2545 printk("%s(%d):synclinkmp_interrupt(%d)exit.\n",
2546 __FILE__,__LINE__,irq);
2550 /* Initialize and start device.
2552 static int startup(SLMP_INFO * info)
2554 if ( debug_level >= DEBUG_LEVEL_INFO )
2555 printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name);
2557 if (info->flags & ASYNC_INITIALIZED)
2560 if (!info->tx_buf) {
2561 info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL);
2562 if (!info->tx_buf) {
2563 printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
2564 __FILE__,__LINE__,info->device_name);
2569 info->pending_bh = 0;
2571 /* program hardware for current parameters */
2574 change_params(info);
2576 info->status_timer.expires = jiffies + jiffies_from_ms(10);
2577 add_timer(&info->status_timer);
2580 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2582 info->flags |= ASYNC_INITIALIZED;
2587 /* Called by close() and hangup() to shutdown hardware
2589 static void shutdown(SLMP_INFO * info)
2591 unsigned long flags;
2593 if (!(info->flags & ASYNC_INITIALIZED))
2596 if (debug_level >= DEBUG_LEVEL_INFO)
2597 printk("%s(%d):%s synclinkmp_shutdown()\n",
2598 __FILE__,__LINE__, info->device_name );
2600 /* clear status wait queue because status changes */
2601 /* can't happen after shutting down the hardware */
2602 wake_up_interruptible(&info->status_event_wait_q);
2603 wake_up_interruptible(&info->event_wait_q);
2605 del_timer(&info->tx_timer);
2606 del_timer(&info->status_timer);
2609 kfree(info->tx_buf);
2613 spin_lock_irqsave(&info->lock,flags);
2617 if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
2618 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
2622 spin_unlock_irqrestore(&info->lock,flags);
2625 set_bit(TTY_IO_ERROR, &info->tty->flags);
2627 info->flags &= ~ASYNC_INITIALIZED;
2630 static void program_hw(SLMP_INFO *info)
2632 unsigned long flags;
2634 spin_lock_irqsave(&info->lock,flags);
2639 info->tx_count = info->tx_put = info->tx_get = 0;
2641 if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
2648 info->dcd_chkcount = 0;
2649 info->cts_chkcount = 0;
2650 info->ri_chkcount = 0;
2651 info->dsr_chkcount = 0;
2653 info->ie1_value |= (CDCD|CCTS);
2654 write_reg(info, IE1, info->ie1_value);
2658 if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
2661 spin_unlock_irqrestore(&info->lock,flags);
2664 /* Reconfigure adapter based on new parameters
2666 static void change_params(SLMP_INFO *info)
2671 if (!info->tty || !info->tty->termios)
2674 if (debug_level >= DEBUG_LEVEL_INFO)
2675 printk("%s(%d):%s change_params()\n",
2676 __FILE__,__LINE__, info->device_name );
2678 cflag = info->tty->termios->c_cflag;
2680 /* if B0 rate (hangup) specified then negate DTR and RTS */
2681 /* otherwise assert DTR and RTS */
2683 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
2685 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
2687 /* byte size and parity */
2689 switch (cflag & CSIZE) {
2690 case CS5: info->params.data_bits = 5; break;
2691 case CS6: info->params.data_bits = 6; break;
2692 case CS7: info->params.data_bits = 7; break;
2693 case CS8: info->params.data_bits = 8; break;
2694 /* Never happens, but GCC is too dumb to figure it out */
2695 default: info->params.data_bits = 7; break;
2699 info->params.stop_bits = 2;
2701 info->params.stop_bits = 1;
2703 info->params.parity = ASYNC_PARITY_NONE;
2704 if (cflag & PARENB) {
2706 info->params.parity = ASYNC_PARITY_ODD;
2708 info->params.parity = ASYNC_PARITY_EVEN;
2711 info->params.parity = ASYNC_PARITY_SPACE;
2715 /* calculate number of jiffies to transmit a full
2716 * FIFO (32 bytes) at specified data rate
2718 bits_per_char = info->params.data_bits +
2719 info->params.stop_bits + 1;
2721 /* if port data rate is set to 460800 or less then
2722 * allow tty settings to override, otherwise keep the
2723 * current data rate.
2725 if (info->params.data_rate <= 460800) {
2726 info->params.data_rate = tty_get_baud_rate(info->tty);
2729 if ( info->params.data_rate ) {
2730 info->timeout = (32*HZ*bits_per_char) /
2731 info->params.data_rate;
2733 info->timeout += HZ/50; /* Add .02 seconds of slop */
2735 if (cflag & CRTSCTS)
2736 info->flags |= ASYNC_CTS_FLOW;
2738 info->flags &= ~ASYNC_CTS_FLOW;
2741 info->flags &= ~ASYNC_CHECK_CD;
2743 info->flags |= ASYNC_CHECK_CD;
2745 /* process tty input control flags */
2747 info->read_status_mask2 = OVRN;
2748 if (I_INPCK(info->tty))
2749 info->read_status_mask2 |= PE | FRME;
2750 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2751 info->read_status_mask1 |= BRKD;
2752 if (I_IGNPAR(info->tty))
2753 info->ignore_status_mask2 |= PE | FRME;
2754 if (I_IGNBRK(info->tty)) {
2755 info->ignore_status_mask1 |= BRKD;
2756 /* If ignoring parity and break indicators, ignore
2757 * overruns too. (For real raw support).
2759 if (I_IGNPAR(info->tty))
2760 info->ignore_status_mask2 |= OVRN;
2766 static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
2770 if (debug_level >= DEBUG_LEVEL_INFO)
2771 printk("%s(%d):%s get_params()\n",
2772 __FILE__,__LINE__, info->device_name);
2774 COPY_TO_USER(err,user_icount, &info->icount, sizeof(struct mgsl_icount));
2776 if ( debug_level >= DEBUG_LEVEL_INFO )
2777 printk( "%s(%d):%s get_stats() user buffer copy failed\n",
2778 __FILE__,__LINE__,info->device_name);
2785 static int get_params(SLMP_INFO * info, MGSL_PARAMS __user *user_params)
2788 if (debug_level >= DEBUG_LEVEL_INFO)
2789 printk("%s(%d):%s get_params()\n",
2790 __FILE__,__LINE__, info->device_name);
2792 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
2794 if ( debug_level >= DEBUG_LEVEL_INFO )
2795 printk( "%s(%d):%s get_params() user buffer copy failed\n",
2796 __FILE__,__LINE__,info->device_name);
2803 static int set_params(SLMP_INFO * info, MGSL_PARAMS __user *new_params)
2805 unsigned long flags;
2806 MGSL_PARAMS tmp_params;
2809 if (debug_level >= DEBUG_LEVEL_INFO)
2810 printk("%s(%d):%s set_params\n",
2811 __FILE__,__LINE__,info->device_name );
2812 COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
2814 if ( debug_level >= DEBUG_LEVEL_INFO )
2815 printk( "%s(%d):%s set_params() user buffer copy failed\n",
2816 __FILE__,__LINE__,info->device_name);
2820 spin_lock_irqsave(&info->lock,flags);
2821 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
2822 spin_unlock_irqrestore(&info->lock,flags);
2824 change_params(info);
2829 static int get_txidle(SLMP_INFO * info, int __user *idle_mode)
2833 if (debug_level >= DEBUG_LEVEL_INFO)
2834 printk("%s(%d):%s get_txidle()=%d\n",
2835 __FILE__,__LINE__, info->device_name, info->idle_mode);
2837 COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
2839 if ( debug_level >= DEBUG_LEVEL_INFO )
2840 printk( "%s(%d):%s get_txidle() user buffer copy failed\n",
2841 __FILE__,__LINE__,info->device_name);
2848 static int set_txidle(SLMP_INFO * info, int idle_mode)
2850 unsigned long flags;
2852 if (debug_level >= DEBUG_LEVEL_INFO)
2853 printk("%s(%d):%s set_txidle(%d)\n",
2854 __FILE__,__LINE__,info->device_name, idle_mode );
2856 spin_lock_irqsave(&info->lock,flags);
2857 info->idle_mode = idle_mode;
2858 tx_set_idle( info );
2859 spin_unlock_irqrestore(&info->lock,flags);
2863 static int tx_enable(SLMP_INFO * info, int enable)
2865 unsigned long flags;
2867 if (debug_level >= DEBUG_LEVEL_INFO)
2868 printk("%s(%d):%s tx_enable(%d)\n",
2869 __FILE__,__LINE__,info->device_name, enable);
2871 spin_lock_irqsave(&info->lock,flags);
2873 if ( !info->tx_enabled ) {
2877 if ( info->tx_enabled )
2880 spin_unlock_irqrestore(&info->lock,flags);
2884 /* abort send HDLC frame
2886 static int tx_abort(SLMP_INFO * info)
2888 unsigned long flags;
2890 if (debug_level >= DEBUG_LEVEL_INFO)
2891 printk("%s(%d):%s tx_abort()\n",
2892 __FILE__,__LINE__,info->device_name);
2894 spin_lock_irqsave(&info->lock,flags);
2895 if ( info->tx_active && info->params.mode == MGSL_MODE_HDLC ) {
2896 info->ie1_value &= ~UDRN;
2897 info->ie1_value |= IDLE;
2898 write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
2899 write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
2901 write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
2902 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
2904 write_reg(info, CMD, TXABORT);
2906 spin_unlock_irqrestore(&info->lock,flags);
2910 static int rx_enable(SLMP_INFO * info, int enable)
2912 unsigned long flags;
2914 if (debug_level >= DEBUG_LEVEL_INFO)
2915 printk("%s(%d):%s rx_enable(%d)\n",
2916 __FILE__,__LINE__,info->device_name,enable);
2918 spin_lock_irqsave(&info->lock,flags);
2920 if ( !info->rx_enabled )
2923 if ( info->rx_enabled )
2926 spin_unlock_irqrestore(&info->lock,flags);
2930 static int map_status(int signals)
2932 /* Map status bits to API event bits */
2934 return ((signals & SerialSignal_DSR) ? MgslEvent_DsrActive : MgslEvent_DsrInactive) +
2935 ((signals & SerialSignal_CTS) ? MgslEvent_CtsActive : MgslEvent_CtsInactive) +
2936 ((signals & SerialSignal_DCD) ? MgslEvent_DcdActive : MgslEvent_DcdInactive) +
2937 ((signals & SerialSignal_RI) ? MgslEvent_RiActive : MgslEvent_RiInactive);
2940 /* wait for specified event to occur
2942 static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
2944 unsigned long flags;
2947 struct mgsl_icount cprev, cnow;
2950 struct _input_signal_events oldsigs, newsigs;
2951 DECLARE_WAITQUEUE(wait, current);
2953 COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
2958 if (debug_level >= DEBUG_LEVEL_INFO)
2959 printk("%s(%d):%s wait_mgsl_event(%d)\n",
2960 __FILE__,__LINE__,info->device_name,mask);
2962 spin_lock_irqsave(&info->lock,flags);
2964 /* return immediately if state matches requested events */
2966 s = map_status(info->serial_signals);
2969 ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
2970 ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
2971 ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
2972 ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
2974 spin_unlock_irqrestore(&info->lock,flags);
2978 /* save current irq counts */
2979 cprev = info->icount;
2980 oldsigs = info->input_signal_events;
2982 /* enable hunt and idle irqs if needed */
2983 if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
2984 unsigned char oldval = info->ie1_value;
2985 unsigned char newval = oldval +
2986 (mask & MgslEvent_ExitHuntMode ? FLGD:0) +
2987 (mask & MgslEvent_IdleReceived ? IDLE:0);
2988 if ( oldval != newval ) {
2989 info->ie1_value = newval;
2990 write_reg(info, IE1, info->ie1_value);
2994 set_current_state(TASK_INTERRUPTIBLE);
2995 add_wait_queue(&info->event_wait_q, &wait);
2997 spin_unlock_irqrestore(&info->lock,flags);
3001 if (signal_pending(current)) {
3006 /* get current irq counts */
3007 spin_lock_irqsave(&info->lock,flags);
3008 cnow = info->icount;
3009 newsigs = info->input_signal_events;
3010 set_current_state(TASK_INTERRUPTIBLE);
3011 spin_unlock_irqrestore(&info->lock,flags);
3013 /* if no change, wait aborted for some reason */
3014 if (newsigs.dsr_up == oldsigs.dsr_up &&
3015 newsigs.dsr_down == oldsigs.dsr_down &&
3016 newsigs.dcd_up == oldsigs.dcd_up &&
3017 newsigs.dcd_down == oldsigs.dcd_down &&
3018 newsigs.cts_up == oldsigs.cts_up &&
3019 newsigs.cts_down == oldsigs.cts_down &&
3020 newsigs.ri_up == oldsigs.ri_up &&
3021 newsigs.ri_down == oldsigs.ri_down &&
3022 cnow.exithunt == cprev.exithunt &&
3023 cnow.rxidle == cprev.rxidle) {
3029 ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
3030 (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
3031 (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
3032 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
3033 (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
3034 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
3035 (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
3036 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
3037 (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
3038 (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
3046 remove_wait_queue(&info->event_wait_q, &wait);
3047 set_current_state(TASK_RUNNING);
3050 if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
3051 spin_lock_irqsave(&info->lock,flags);
3052 if (!waitqueue_active(&info->event_wait_q)) {
3053 /* disable enable exit hunt mode/idle rcvd IRQs */
3054 info->ie1_value &= ~(FLGD|IDLE);
3055 write_reg(info, IE1, info->ie1_value);
3057 spin_unlock_irqrestore(&info->lock,flags);
3061 PUT_USER(rc, events, mask_ptr);
3066 static int modem_input_wait(SLMP_INFO *info,int arg)
3068 unsigned long flags;
3070 struct mgsl_icount cprev, cnow;
3071 DECLARE_WAITQUEUE(wait, current);
3073 /* save current irq counts */
3074 spin_lock_irqsave(&info->lock,flags);
3075 cprev = info->icount;
3076 add_wait_queue(&info->status_event_wait_q, &wait);
3077 set_current_state(TASK_INTERRUPTIBLE);
3078 spin_unlock_irqrestore(&info->lock,flags);
3082 if (signal_pending(current)) {
3087 /* get new irq counts */
3088 spin_lock_irqsave(&info->lock,flags);
3089 cnow = info->icount;
3090 set_current_state(TASK_INTERRUPTIBLE);
3091 spin_unlock_irqrestore(&info->lock,flags);
3093 /* if no change, wait aborted for some reason */
3094 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
3095 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
3100 /* check for change in caller specified modem input */
3101 if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
3102 (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
3103 (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
3104 (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
3111 remove_wait_queue(&info->status_event_wait_q, &wait);
3112 set_current_state(TASK_RUNNING);
3116 /* return the state of the serial control and status signals
3118 static int tiocmget(struct tty_struct *tty, struct file *file)
3120 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
3121 unsigned int result;
3122 unsigned long flags;
3124 spin_lock_irqsave(&info->lock,flags);
3126 spin_unlock_irqrestore(&info->lock,flags);
3128 result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
3129 ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
3130 ((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
3131 ((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
3132 ((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
3133 ((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
3135 if (debug_level >= DEBUG_LEVEL_INFO)
3136 printk("%s(%d):%s tiocmget() value=%08X\n",
3137 __FILE__,__LINE__, info->device_name, result );
3141 /* set modem control signals (DTR/RTS)
3143 static int tiocmset(struct tty_struct *tty, struct file *file,
3144 unsigned int set, unsigned int clear)
3146 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
3147 unsigned long flags;
3149 if (debug_level >= DEBUG_LEVEL_INFO)
3150 printk("%s(%d):%s tiocmset(%x,%x)\n",
3151 __FILE__,__LINE__,info->device_name, set, clear);
3153 if (set & TIOCM_RTS)
3154 info->serial_signals |= SerialSignal_RTS;
3155 if (set & TIOCM_DTR)
3156 info->serial_signals |= SerialSignal_DTR;
3157 if (clear & TIOCM_RTS)
3158 info->serial_signals &= ~SerialSignal_RTS;
3159 if (clear & TIOCM_DTR)
3160 info->serial_signals &= ~SerialSignal_DTR;
3162 spin_lock_irqsave(&info->lock,flags);
3164 spin_unlock_irqrestore(&info->lock,flags);
3171 /* Block the current process until the specified port is ready to open.
3173 static int block_til_ready(struct tty_struct *tty, struct file *filp,
3176 DECLARE_WAITQUEUE(wait, current);
3178 int do_clocal = 0, extra_count = 0;
3179 unsigned long flags;
3181 if (debug_level >= DEBUG_LEVEL_INFO)
3182 printk("%s(%d):%s block_til_ready()\n",
3183 __FILE__,__LINE__, tty->driver->name );
3185 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
3186 /* nonblock mode is set or port is not enabled */
3187 /* just verify that callout device is not active */
3188 info->flags |= ASYNC_NORMAL_ACTIVE;
3192 if (tty->termios->c_cflag & CLOCAL)
3195 /* Wait for carrier detect and the line to become
3196 * free (i.e., not in use by the callout). While we are in
3197 * this loop, info->count is dropped by one, so that
3198 * close() knows when to free things. We restore it upon
3199 * exit, either normal or abnormal.
3203 add_wait_queue(&info->open_wait, &wait);
3205 if (debug_level >= DEBUG_LEVEL_INFO)
3206 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
3207 __FILE__,__LINE__, tty->driver->name, info->count );
3209 spin_lock_irqsave(&info->lock, flags);
3210 if (!tty_hung_up_p(filp)) {
3214 spin_unlock_irqrestore(&info->lock, flags);
3215 info->blocked_open++;
3218 if ((tty->termios->c_cflag & CBAUD)) {
3219 spin_lock_irqsave(&info->lock,flags);
3220 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3222 spin_unlock_irqrestore(&info->lock,flags);
3225 set_current_state(TASK_INTERRUPTIBLE);
3227 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
3228 retval = (info->flags & ASYNC_HUP_NOTIFY) ?
3229 -EAGAIN : -ERESTARTSYS;
3233 spin_lock_irqsave(&info->lock,flags);
3235 spin_unlock_irqrestore(&info->lock,flags);
3237 if (!(info->flags & ASYNC_CLOSING) &&
3238 (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
3242 if (signal_pending(current)) {
3243 retval = -ERESTARTSYS;
3247 if (debug_level >= DEBUG_LEVEL_INFO)
3248 printk("%s(%d):%s block_til_ready() count=%d\n",
3249 __FILE__,__LINE__, tty->driver->name, info->count );
3254 set_current_state(TASK_RUNNING);
3255 remove_wait_queue(&info->open_wait, &wait);
3259 info->blocked_open--;
3261 if (debug_level >= DEBUG_LEVEL_INFO)
3262 printk("%s(%d):%s block_til_ready() after, count=%d\n",
3263 __FILE__,__LINE__, tty->driver->name, info->count );
3266 info->flags |= ASYNC_NORMAL_ACTIVE;
3271 int alloc_dma_bufs(SLMP_INFO *info)
3273 unsigned short BuffersPerFrame;
3274 unsigned short BufferCount;
3276 // Force allocation to start at 64K boundary for each port.
3277 // This is necessary because *all* buffer descriptors for a port
3278 // *must* be in the same 64K block. All descriptors on a port
3279 // share a common 'base' address (upper 8 bits of 24 bits) programmed
3280 // into the CBP register.
3281 info->port_array[0]->last_mem_alloc = (SCA_MEM_SIZE/4) * info->port_num;
3283 /* Calculate the number of DMA buffers necessary to hold the */
3284 /* largest allowable frame size. Note: If the max frame size is */
3285 /* not an even multiple of the DMA buffer size then we need to */
3286 /* round the buffer count per frame up one. */
3288 BuffersPerFrame = (unsigned short)(info->max_frame_size/SCABUFSIZE);
3289 if ( info->max_frame_size % SCABUFSIZE )
3292 /* calculate total number of data buffers (SCABUFSIZE) possible
3293 * in one ports memory (SCA_MEM_SIZE/4) after allocating memory
3294 * for the descriptor list (BUFFERLISTSIZE).
3296 BufferCount = (SCA_MEM_SIZE/4 - BUFFERLISTSIZE)/SCABUFSIZE;
3298 /* limit number of buffers to maximum amount of descriptors */
3299 if (BufferCount > BUFFERLISTSIZE/sizeof(SCADESC))
3300 BufferCount = BUFFERLISTSIZE/sizeof(SCADESC);
3302 /* use enough buffers to transmit one max size frame */
3303 info->tx_buf_count = BuffersPerFrame + 1;
3305 /* never use more than half the available buffers for transmit */
3306 if (info->tx_buf_count > (BufferCount/2))
3307 info->tx_buf_count = BufferCount/2;
3309 if (info->tx_buf_count > SCAMAXDESC)
3310 info->tx_buf_count = SCAMAXDESC;
3312 /* use remaining buffers for receive */
3313 info->rx_buf_count = BufferCount - info->tx_buf_count;
3315 if (info->rx_buf_count > SCAMAXDESC)
3316 info->rx_buf_count = SCAMAXDESC;
3318 if ( debug_level >= DEBUG_LEVEL_INFO )
3319 printk("%s(%d):%s Allocating %d TX and %d RX DMA buffers.\n",
3320 __FILE__,__LINE__, info->device_name,
3321 info->tx_buf_count,info->rx_buf_count);
3323 if ( alloc_buf_list( info ) < 0 ||
3324 alloc_frame_bufs(info,
3326 info->rx_buf_list_ex,
3327 info->rx_buf_count) < 0 ||
3328 alloc_frame_bufs(info,
3330 info->tx_buf_list_ex,
3331 info->tx_buf_count) < 0 ||
3332 alloc_tmp_rx_buf(info) < 0 ) {
3333 printk("%s(%d):%s Can't allocate DMA buffer memory\n",
3334 __FILE__,__LINE__, info->device_name);
3338 rx_reset_buffers( info );
3343 /* Allocate DMA buffers for the transmit and receive descriptor lists.
3345 int alloc_buf_list(SLMP_INFO *info)
3349 /* build list in adapter shared memory */
3350 info->buffer_list = info->memory_base + info->port_array[0]->last_mem_alloc;
3351 info->buffer_list_phys = info->port_array[0]->last_mem_alloc;
3352 info->port_array[0]->last_mem_alloc += BUFFERLISTSIZE;
3354 memset(info->buffer_list, 0, BUFFERLISTSIZE);
3356 /* Save virtual address pointers to the receive and */
3357 /* transmit buffer lists. (Receive 1st). These pointers will */
3358 /* be used by the processor to access the lists. */
3359 info->rx_buf_list = (SCADESC *)info->buffer_list;
3361 info->tx_buf_list = (SCADESC *)info->buffer_list;
3362 info->tx_buf_list += info->rx_buf_count;
3364 /* Build links for circular buffer entry lists (tx and rx)
3366 * Note: links are physical addresses read by the SCA device
3367 * to determine the next buffer entry to use.
3370 for ( i = 0; i < info->rx_buf_count; i++ ) {
3371 /* calculate and store physical address of this buffer entry */
3372 info->rx_buf_list_ex[i].phys_entry =
3373 info->buffer_list_phys + (i * sizeof(SCABUFSIZE));
3375 /* calculate and store physical address of */
3376 /* next entry in cirular list of entries */
3377 info->rx_buf_list[i].next = info->buffer_list_phys;
3378 if ( i < info->rx_buf_count - 1 )
3379 info->rx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
3381 info->rx_buf_list[i].length = SCABUFSIZE;
3384 for ( i = 0; i < info->tx_buf_count; i++ ) {
3385 /* calculate and store physical address of this buffer entry */
3386 info->tx_buf_list_ex[i].phys_entry = info->buffer_list_phys +
3387 ((info->rx_buf_count + i) * sizeof(SCADESC));
3389 /* calculate and store physical address of */
3390 /* next entry in cirular list of entries */
3392 info->tx_buf_list[i].next = info->buffer_list_phys +
3393 info->rx_buf_count * sizeof(SCADESC);
3395 if ( i < info->tx_buf_count - 1 )
3396 info->tx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
3402 /* Allocate the frame DMA buffers used by the specified buffer list.
3404 int alloc_frame_bufs(SLMP_INFO *info, SCADESC *buf_list,SCADESC_EX *buf_list_ex,int count)
3407 unsigned long phys_addr;
3409 for ( i = 0; i < count; i++ ) {
3410 buf_list_ex[i].virt_addr = info->memory_base + info->port_array[0]->last_mem_alloc;
3411 phys_addr = info->port_array[0]->last_mem_alloc;
3412 info->port_array[0]->last_mem_alloc += SCABUFSIZE;
3414 buf_list[i].buf_ptr = (unsigned short)phys_addr;
3415 buf_list[i].buf_base = (unsigned char)(phys_addr >> 16);
3421 void free_dma_bufs(SLMP_INFO *info)
3423 info->buffer_list = NULL;
3424 info->rx_buf_list = NULL;
3425 info->tx_buf_list = NULL;
3428 /* allocate buffer large enough to hold max_frame_size.
3429 * This buffer is used to pass an assembled frame to the line discipline.
3431 int alloc_tmp_rx_buf(SLMP_INFO *info)
3433 info->tmp_rx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
3434 if (info->tmp_rx_buf == NULL)
3439 void free_tmp_rx_buf(SLMP_INFO *info)
3441 if (info->tmp_rx_buf)
3442 kfree(info->tmp_rx_buf);
3443 info->tmp_rx_buf = NULL;
3446 int claim_resources(SLMP_INFO *info)
3448 if (request_mem_region(info->phys_memory_base,0x40000,"synclinkmp") == NULL) {
3449 printk( "%s(%d):%s mem addr conflict, Addr=%08X\n",
3450 __FILE__,__LINE__,info->device_name, info->phys_memory_base);
3454 info->shared_mem_requested = 1;
3456 if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclinkmp") == NULL) {
3457 printk( "%s(%d):%s lcr mem addr conflict, Addr=%08X\n",
3458 __FILE__,__LINE__,info->device_name, info->phys_lcr_base);
3462 info->lcr_mem_requested = 1;
3464 if (request_mem_region(info->phys_sca_base + info->sca_offset,512,"synclinkmp") == NULL) {
3465 printk( "%s(%d):%s sca mem addr conflict, Addr=%08X\n",
3466 __FILE__,__LINE__,info->device_name, info->phys_sca_base);
3470 info->sca_base_requested = 1;
3472 if (request_mem_region(info->phys_statctrl_base + info->statctrl_offset,16,"synclinkmp") == NULL) {
3473 printk( "%s(%d):%s stat/ctrl mem addr conflict, Addr=%08X\n",
3474 __FILE__,__LINE__,info->device_name, info->phys_statctrl_base);
3478 info->sca_statctrl_requested = 1;
3480 info->memory_base = ioremap(info->phys_memory_base,SCA_MEM_SIZE);
3481 if (!info->memory_base) {
3482 printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n",
3483 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
3487 if ( !memory_test(info) ) {
3488 printk( "%s(%d):Shared Memory Test failed for device %s MemAddr=%08X\n",
3489 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
3493 info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE) + info->lcr_offset;
3494 if (!info->lcr_base) {
3495 printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n",
3496 __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
3500 info->sca_base = ioremap(info->phys_sca_base,PAGE_SIZE) + info->sca_offset;
3501 if (!info->sca_base) {
3502 printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n",
3503 __FILE__,__LINE__,info->device_name, info->phys_sca_base );
3507 info->statctrl_base = ioremap(info->phys_statctrl_base,PAGE_SIZE) + info->statctrl_offset;
3508 if (!info->statctrl_base) {
3509 printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n",
3510 __FILE__,__LINE__,info->device_name, info->phys_statctrl_base );
3517 release_resources( info );
3521 void release_resources(SLMP_INFO *info)
3523 if ( debug_level >= DEBUG_LEVEL_INFO )
3524 printk( "%s(%d):%s release_resources() entry\n",
3525 __FILE__,__LINE__,info->device_name );
3527 if ( info->irq_requested ) {
3528 free_irq(info->irq_level, info);
3529 info->irq_requested = 0;
3532 if ( info->shared_mem_requested ) {
3533 release_mem_region(info->phys_memory_base,0x40000);
3534 info->shared_mem_requested = 0;
3536 if ( info->lcr_mem_requested ) {
3537 release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
3538 info->lcr_mem_requested = 0;
3540 if ( info->sca_base_requested ) {
3541 release_mem_region(info->phys_sca_base + info->sca_offset,512);
3542 info->sca_base_requested = 0;
3544 if ( info->sca_statctrl_requested ) {
3545 release_mem_region(info->phys_statctrl_base + info->statctrl_offset,16);
3546 info->sca_statctrl_requested = 0;
3549 if (info->memory_base){
3550 iounmap(info->memory_base);
3551 info->memory_base = 0;
3554 if (info->sca_base) {
3555 iounmap(info->sca_base - info->sca_offset);
3559 if (info->statctrl_base) {
3560 iounmap(info->statctrl_base - info->statctrl_offset);
3561 info->statctrl_base=0;
3564 if (info->lcr_base){
3565 iounmap(info->lcr_base - info->lcr_offset);
3569 if ( debug_level >= DEBUG_LEVEL_INFO )
3570 printk( "%s(%d):%s release_resources() exit\n",
3571 __FILE__,__LINE__,info->device_name );
3574 /* Add the specified device instance data structure to the
3575 * global linked list of devices and increment the device count.
3577 void add_device(SLMP_INFO *info)
3579 info->next_device = NULL;
3580 info->line = synclinkmp_device_count;
3581 sprintf(info->device_name,"ttySLM%dp%d",info->adapter_num,info->port_num);
3583 if (info->line < MAX_DEVICES) {
3584 if (maxframe[info->line])
3585 info->max_frame_size = maxframe[info->line];
3586 info->dosyncppp = dosyncppp[info->line];
3589 synclinkmp_device_count++;
3591 if ( !synclinkmp_device_list )
3592 synclinkmp_device_list = info;
3594 SLMP_INFO *current_dev = synclinkmp_device_list;
3595 while( current_dev->next_device )
3596 current_dev = current_dev->next_device;
3597 current_dev->next_device = info;
3600 if ( info->max_frame_size < 4096 )
3601 info->max_frame_size = 4096;
3602 else if ( info->max_frame_size > 65535 )
3603 info->max_frame_size = 65535;
3605 printk( "SyncLink MultiPort %s: "
3606 "Mem=(%08x %08X %08x %08X) IRQ=%d MaxFrameSize=%u\n",
3608 info->phys_sca_base,
3609 info->phys_memory_base,
3610 info->phys_statctrl_base,
3611 info->phys_lcr_base,
3613 info->max_frame_size );
3615 #ifdef CONFIG_SYNCLINK_SYNCPPP
3616 if (info->dosyncppp)
3621 /* Allocate and initialize a device instance structure
3623 * Return Value: pointer to SLMP_INFO if success, otherwise NULL
3625 SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
3629 info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO),
3633 printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
3634 __FILE__,__LINE__, adapter_num, port_num);
3636 memset(info, 0, sizeof(SLMP_INFO));
3637 info->magic = MGSL_MAGIC;
3638 INIT_WORK(&info->task, bh_handler, info);
3639 info->max_frame_size = 4096;
3640 info->close_delay = 5*HZ/10;
3641 info->closing_wait = 30*HZ;
3642 init_waitqueue_head(&info->open_wait);
3643 init_waitqueue_head(&info->close_wait);
3644 init_waitqueue_head(&info->status_event_wait_q);
3645 init_waitqueue_head(&info->event_wait_q);
3646 spin_lock_init(&info->netlock);
3647 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
3648 info->idle_mode = HDLC_TXIDLE_FLAGS;
3649 info->adapter_num = adapter_num;
3650 info->port_num = port_num;
3652 /* Copy configuration info to device instance data */
3653 info->irq_level = pdev->irq;
3654 info->phys_lcr_base = pci_resource_start(pdev,0);
3655 info->phys_sca_base = pci_resource_start(pdev,2);
3656 info->phys_memory_base = pci_resource_start(pdev,3);
3657 info->phys_statctrl_base = pci_resource_start(pdev,4);
3659 /* Because veremap only works on page boundaries we must map
3660 * a larger area than is actually implemented for the LCR
3661 * memory range. We map a full page starting at the page boundary.
3663 info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
3664 info->phys_lcr_base &= ~(PAGE_SIZE-1);
3666 info->sca_offset = info->phys_sca_base & (PAGE_SIZE-1);
3667 info->phys_sca_base &= ~(PAGE_SIZE-1);
3669 info->statctrl_offset = info->phys_statctrl_base & (PAGE_SIZE-1);
3670 info->phys_statctrl_base &= ~(PAGE_SIZE-1);
3672 info->bus_type = MGSL_BUS_TYPE_PCI;
3673 info->irq_flags = SA_SHIRQ;
3675 init_timer(&info->tx_timer);
3676 info->tx_timer.data = (unsigned long)info;
3677 info->tx_timer.function = tx_timeout;
3679 init_timer(&info->status_timer);
3680 info->status_timer.data = (unsigned long)info;
3681 info->status_timer.function = status_timeout;
3683 /* Store the PCI9050 misc control register value because a flaw
3684 * in the PCI9050 prevents LCR registers from being read if
3685 * BIOS assigns an LCR base address with bit 7 set.
3687 * Only the misc control register is accessed for which only
3688 * write access is needed, so set an initial value and change
3689 * bits to the device instance data as we write the value
3690 * to the actual misc control register.
3692 info->misc_ctrl_value = 0x087e4546;
3694 /* initial port state is unknown - if startup errors
3695 * occur, init_error will be set to indicate the
3696 * problem. Once the port is fully initialized,
3697 * this value will be set to 0 to indicate the
3698 * port is available.
3700 info->init_error = -1;
3706 void device_init(int adapter_num, struct pci_dev *pdev)
3708 SLMP_INFO *port_array[SCA_MAX_PORTS];
3711 /* allocate device instances for up to SCA_MAX_PORTS devices */
3712 for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
3713 port_array[port] = alloc_dev(adapter_num,port,pdev);
3714 if( port_array[port] == NULL ) {
3715 for ( --port; port >= 0; --port )
3716 kfree(port_array[port]);
3721 /* give copy of port_array to all ports and add to device list */
3722 for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
3723 memcpy(port_array[port]->port_array,port_array,sizeof(port_array));
3724 add_device( port_array[port] );
3725 spin_lock_init(&port_array[port]->lock);
3728 /* Allocate and claim adapter resources */
3729 if ( !claim_resources(port_array[0]) ) {
3731 alloc_dma_bufs(port_array[0]);
3733 /* copy resource information from first port to others */
3734 for ( port = 1; port < SCA_MAX_PORTS; ++port ) {
3735 port_array[port]->lock = port_array[0]->lock;
3736 port_array[port]->irq_level = port_array[0]->irq_level;
3737 port_array[port]->memory_base = port_array[0]->memory_base;
3738 port_array[port]->sca_base = port_array[0]->sca_base;
3739 port_array[port]->statctrl_base = port_array[0]->statctrl_base;
3740 port_array[port]->lcr_base = port_array[0]->lcr_base;
3741 alloc_dma_bufs(port_array[port]);
3744 if ( request_irq(port_array[0]->irq_level,
3745 synclinkmp_interrupt,
3746 port_array[0]->irq_flags,
3747 port_array[0]->device_name,
3748 port_array[0]) < 0 ) {
3749 printk( "%s(%d):%s Cant request interrupt, IRQ=%d\n",
3751 port_array[0]->device_name,
3752 port_array[0]->irq_level );
3755 port_array[0]->irq_requested = 1;
3756 adapter_test(port_array[0]);
3761 static struct tty_operations ops = {
3765 .put_char = put_char,
3766 .flush_chars = flush_chars,
3767 .write_room = write_room,
3768 .chars_in_buffer = chars_in_buffer,
3769 .flush_buffer = flush_buffer,
3771 .throttle = throttle,
3772 .unthrottle = unthrottle,
3773 .send_xchar = send_xchar,
3774 .break_ctl = set_break,
3775 .wait_until_sent = wait_until_sent,
3776 .read_proc = read_proc,
3777 .set_termios = set_termios,
3779 .start = tx_release,
3781 .tiocmget = tiocmget,
3782 .tiocmset = tiocmset,
3785 static void synclinkmp_cleanup(void)
3787 unsigned long flags;
3792 printk("Unloading %s %s\n", driver_name, driver_version);
3794 if (serial_driver) {
3795 if ((rc = tty_unregister_driver(serial_driver)))
3796 printk("%s(%d) failed to unregister tty driver err=%d\n",
3797 __FILE__,__LINE__,rc);
3798 put_tty_driver(serial_driver);
3801 info = synclinkmp_device_list;
3803 #ifdef CONFIG_SYNCLINK_SYNCPPP
3804 if (info->dosyncppp)
3808 if ( info->port_num == 0 ) {
3809 if ( info->irq_requested ) {
3810 free_irq(info->irq_level, info);
3811 info->irq_requested = 0;
3814 info = info->next_device;
3817 /* port 0 of each adapter originally claimed
3818 * all resources, release those now
3820 info = synclinkmp_device_list;
3822 free_dma_bufs(info);
3823 free_tmp_rx_buf(info);
3824 if ( info->port_num == 0 ) {
3825 spin_lock_irqsave(&info->lock,flags);
3826 reset_adapter(info);
3827 write_reg(info, LPR, 1); /* set low power mode */
3828 spin_unlock_irqrestore(&info->lock,flags);
3829 release_resources(info);
3832 info = info->next_device;
3836 pci_unregister_driver(&synclinkmp_pci_driver);
3839 /* Driver initialization entry point.
3842 static int __init synclinkmp_init(void)
3846 if (break_on_load) {
3847 synclinkmp_get_text_ptr();
3851 printk("%s %s\n", driver_name, driver_version);
3853 if ((rc = pci_register_driver(&synclinkmp_pci_driver)) < 0) {
3854 printk("%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
3858 serial_driver = alloc_tty_driver(128);
3859 if (!serial_driver) {
3864 /* Initialize the tty_driver structure */
3866 serial_driver->owner = THIS_MODULE;
3867 serial_driver->driver_name = "synclinkmp";
3868 serial_driver->name = "ttySLM";
3869 serial_driver->major = ttymajor;
3870 serial_driver->minor_start = 64;
3871 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
3872 serial_driver->subtype = SERIAL_TYPE_NORMAL;
3873 serial_driver->init_termios = tty_std_termios;
3874 serial_driver->init_termios.c_cflag =
3875 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
3876 serial_driver->flags = TTY_DRIVER_REAL_RAW;
3877 tty_set_operations(serial_driver, &ops);
3878 if ((rc = tty_register_driver(serial_driver)) < 0) {
3879 printk("%s(%d):Couldn't register serial driver\n",
3881 put_tty_driver(serial_driver);
3882 serial_driver = NULL;
3886 printk("%s %s, tty major#%d\n",
3887 driver_name, driver_version,
3888 serial_driver->major);
3893 synclinkmp_cleanup();
3897 static void __exit synclinkmp_exit(void)
3899 synclinkmp_cleanup();
3902 module_init(synclinkmp_init);
3903 module_exit(synclinkmp_exit);
3905 /* Set the port for internal loopback mode.
3906 * The TxCLK and RxCLK signals are generated from the BRG and
3907 * the TxD is looped back to the RxD internally.
3909 void enable_loopback(SLMP_INFO *info, int enable)
3912 /* MD2 (Mode Register 2)
3913 * 01..00 CNCT<1..0> Channel Connection 11=Local Loopback
3915 write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) | (BIT1 + BIT0)));
3917 /* degate external TxC clock source */
3918 info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
3919 write_control_reg(info);
3921 /* RXS/TXS (Rx/Tx clock source)
3922 * 07 Reserved, must be 0
3923 * 06..04 Clock Source, 100=BRG
3924 * 03..00 Clock Divisor, 0000=1
3926 write_reg(info, RXS, 0x40);
3927 write_reg(info, TXS, 0x40);
3930 /* MD2 (Mode Register 2)
3931 * 01..00 CNCT<1..0> Channel connection, 0=normal
3933 write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) & ~(BIT1 + BIT0)));
3935 /* RXS/TXS (Rx/Tx clock source)
3936 * 07 Reserved, must be 0
3937 * 06..04 Clock Source, 000=RxC/TxC Pin
3938 * 03..00 Clock Divisor, 0000=1
3940 write_reg(info, RXS, 0x00);
3941 write_reg(info, TXS, 0x00);
3944 /* set LinkSpeed if available, otherwise default to 2Mbps */
3945 if (info->params.clock_speed)
3946 set_rate(info, info->params.clock_speed);
3948 set_rate(info, 3686400);
3951 /* Set the baud rate register to the desired speed
3953 * data_rate data rate of clock in bits per second
3954 * A data rate of 0 disables the AUX clock.
3956 void set_rate( SLMP_INFO *info, u32 data_rate )
3959 unsigned char BRValue;
3962 /* fBRG = fCLK/(TMC * 2^BR)
3964 if (data_rate != 0) {
3965 Divisor = 14745600/data_rate;
3972 if (TMCValue != 1 && TMCValue != 2) {
3973 /* BRValue of 0 provides 50/50 duty cycle *only* when
3974 * TMCValue is 1 or 2. BRValue of 1 to 9 always provides
3981 /* while TMCValue is too big for TMC register, divide
3982 * by 2 and increment BR exponent.
3984 for(; TMCValue > 256 && BRValue < 10; BRValue++)
3987 write_reg(info, TXS,
3988 (unsigned char)((read_reg(info, TXS) & 0xf0) | BRValue));
3989 write_reg(info, RXS,
3990 (unsigned char)((read_reg(info, RXS) & 0xf0) | BRValue));
3991 write_reg(info, TMC, (unsigned char)TMCValue);
3994 write_reg(info, TXS,0);
3995 write_reg(info, RXS,0);
3996 write_reg(info, TMC, 0);
4002 void rx_stop(SLMP_INFO *info)
4004 if (debug_level >= DEBUG_LEVEL_ISR)
4005 printk("%s(%d):%s rx_stop()\n",
4006 __FILE__,__LINE__, info->device_name );
4008 write_reg(info, CMD, RXRESET);
4010 info->ie0_value &= ~RXRDYE;
4011 write_reg(info, IE0, info->ie0_value); /* disable Rx data interrupts */
4013 write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
4014 write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
4015 write_reg(info, RXDMA + DIR, 0); /* disable Rx DMA interrupts */
4017 info->rx_enabled = 0;
4018 info->rx_overflow = 0;
4021 /* enable the receiver
4023 void rx_start(SLMP_INFO *info)
4027 if (debug_level >= DEBUG_LEVEL_ISR)
4028 printk("%s(%d):%s rx_start()\n",
4029 __FILE__,__LINE__, info->device_name );
4031 write_reg(info, CMD, RXRESET);
4033 if ( info->params.mode == MGSL_MODE_HDLC ) {
4034 /* HDLC, disabe IRQ on rxdata */
4035 info->ie0_value &= ~RXRDYE;
4036 write_reg(info, IE0, info->ie0_value);
4038 /* Reset all Rx DMA buffers and program rx dma */
4039 write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
4040 write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
4042 for (i = 0; i < info->rx_buf_count; i++) {
4043 info->rx_buf_list[i].status = 0xff;
4045 // throttle to 4 shared memory writes at a time to prevent
4046 // hogging local bus (keep latency time for DMA requests low).
4048 read_status_reg(info);
4050 info->current_rx_buf = 0;
4052 /* set current/1st descriptor address */
4053 write_reg16(info, RXDMA + CDA,
4054 info->rx_buf_list_ex[0].phys_entry);
4056 /* set new last rx descriptor address */
4057 write_reg16(info, RXDMA + EDA,
4058 info->rx_buf_list_ex[info->rx_buf_count - 1].phys_entry);
4060 /* set buffer length (shared by all rx dma data buffers) */
4061 write_reg16(info, RXDMA + BFL, SCABUFSIZE);
4063 write_reg(info, RXDMA + DIR, 0x60); /* enable Rx DMA interrupts (EOM/BOF) */
4064 write_reg(info, RXDMA + DSR, 0xf2); /* clear Rx DMA IRQs, enable Rx DMA */
4066 /* async, enable IRQ on rxdata */
4067 info->ie0_value |= RXRDYE;
4068 write_reg(info, IE0, info->ie0_value);
4071 write_reg(info, CMD, RXENABLE);
4073 info->rx_overflow = FALSE;
4074 info->rx_enabled = 1;
4077 /* Enable the transmitter and send a transmit frame if
4078 * one is loaded in the DMA buffers.
4080 void tx_start(SLMP_INFO *info)
4082 if (debug_level >= DEBUG_LEVEL_ISR)
4083 printk("%s(%d):%s tx_start() tx_count=%d\n",
4084 __FILE__,__LINE__, info->device_name,info->tx_count );
4086 if (!info->tx_enabled ) {
4087 write_reg(info, CMD, TXRESET);
4088 write_reg(info, CMD, TXENABLE);
4089 info->tx_enabled = TRUE;
4092 if ( info->tx_count ) {
4094 /* If auto RTS enabled and RTS is inactive, then assert */
4095 /* RTS and set a flag indicating that the driver should */
4096 /* negate RTS when the transmission completes. */
4098 info->drop_rts_on_tx_done = 0;
4100 if (info->params.mode != MGSL_MODE_ASYNC) {
4102 if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
4103 get_signals( info );
4104 if ( !(info->serial_signals & SerialSignal_RTS) ) {
4105 info->serial_signals |= SerialSignal_RTS;
4106 set_signals( info );
4107 info->drop_rts_on_tx_done = 1;
4111 write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
4112 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
4114 /* set TX CDA (current descriptor address) */
4115 write_reg16(info, TXDMA + CDA,
4116 info->tx_buf_list_ex[0].phys_entry);
4118 /* set TX EDA (last descriptor address) */
4119 write_reg16(info, TXDMA + EDA,
4120 info->tx_buf_list_ex[info->last_tx_buf].phys_entry);
4122 /* clear IDLE and UDRN status bit */
4123 info->ie1_value &= ~(IDLE + UDRN);
4124 if (info->params.mode != MGSL_MODE_ASYNC)
4125 info->ie1_value |= UDRN; /* HDLC, IRQ on underrun */
4126 write_reg(info, IE1, info->ie1_value); /* enable MSCI interrupts */
4127 write_reg(info, SR1, (unsigned char)(IDLE + UDRN));
4129 write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
4130 write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
4132 info->tx_timer.expires = jiffies + jiffies_from_ms(5000);
4133 add_timer(&info->tx_timer);
4137 /* async, enable IRQ on txdata */
4138 info->ie0_value |= TXRDYE;
4139 write_reg(info, IE0, info->ie0_value);
4142 info->tx_active = 1;
4146 /* stop the transmitter and DMA
4148 void tx_stop( SLMP_INFO *info )
4150 if (debug_level >= DEBUG_LEVEL_ISR)
4151 printk("%s(%d):%s tx_stop()\n",
4152 __FILE__,__LINE__, info->device_name );
4154 del_timer(&info->tx_timer);
4156 write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
4157 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
4159 write_reg(info, CMD, TXRESET);
4161 info->ie1_value &= ~(UDRN + IDLE);
4162 write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
4163 write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
4165 info->ie0_value &= ~TXRDYE;
4166 write_reg(info, IE0, info->ie0_value); /* disable tx data interrupts */
4168 info->tx_enabled = 0;
4169 info->tx_active = 0;
4172 /* Fill the transmit FIFO until the FIFO is full or
4173 * there is no more data to load.
4175 void tx_load_fifo(SLMP_INFO *info)
4179 /* do nothing is now tx data available and no XON/XOFF pending */
4181 if ( !info->tx_count && !info->x_char )
4184 /* load the Transmit FIFO until FIFOs full or all data sent */
4186 while( info->tx_count && (read_reg(info,SR0) & BIT1) ) {
4188 /* there is more space in the transmit FIFO and */
4189 /* there is more data in transmit buffer */
4191 if ( (info->tx_count > 1) && !info->x_char ) {
4193 TwoBytes[0] = info->tx_buf[info->tx_get++];
4194 if (info->tx_get >= info->max_frame_size)
4195 info->tx_get -= info->max_frame_size;
4196 TwoBytes[1] = info->tx_buf[info->tx_get++];
4197 if (info->tx_get >= info->max_frame_size)
4198 info->tx_get -= info->max_frame_size;
4200 write_reg16(info, TRB, *((u16 *)TwoBytes));
4202 info->tx_count -= 2;
4203 info->icount.tx += 2;
4205 /* only 1 byte left to transmit or 1 FIFO slot left */
4208 /* transmit pending high priority char */
4209 write_reg(info, TRB, info->x_char);
4212 write_reg(info, TRB, info->tx_buf[info->tx_get++]);
4213 if (info->tx_get >= info->max_frame_size)
4214 info->tx_get -= info->max_frame_size;
4222 /* Reset a port to a known state
4224 void reset_port(SLMP_INFO *info)
4226 if (info->sca_base) {
4231 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
4234 /* disable all port interrupts */
4235 info->ie0_value = 0;
4236 info->ie1_value = 0;
4237 info->ie2_value = 0;
4238 write_reg(info, IE0, info->ie0_value);
4239 write_reg(info, IE1, info->ie1_value);
4240 write_reg(info, IE2, info->ie2_value);
4242 write_reg(info, CMD, CHRESET);
4246 /* Reset all the ports to a known state.
4248 void reset_adapter(SLMP_INFO *info)
4252 for ( i=0; i < SCA_MAX_PORTS; ++i) {
4253 if (info->port_array[i])
4254 reset_port(info->port_array[i]);
4258 /* Program port for asynchronous communications.
4260 void async_mode(SLMP_INFO *info)
4263 unsigned char RegValue;
4268 /* MD0, Mode Register 0
4270 * 07..05 PRCTL<2..0>, Protocol Mode, 000=async
4271 * 04 AUTO, Auto-enable (RTS/CTS/DCD)
4272 * 03 Reserved, must be 0
4273 * 02 CRCCC, CRC Calculation, 0=disabled
4274 * 01..00 STOP<1..0> Stop bits (00=1,10=2)
4279 if (info->params.stop_bits != 1)
4281 write_reg(info, MD0, RegValue);
4283 /* MD1, Mode Register 1
4285 * 07..06 BRATE<1..0>, bit rate, 00=1/1 01=1/16 10=1/32 11=1/64
4286 * 05..04 TXCHR<1..0>, tx char size, 00=8 bits,01=7,10=6,11=5
4287 * 03..02 RXCHR<1..0>, rx char size
4288 * 01..00 PMPM<1..0>, Parity mode, 00=none 10=even 11=odd
4293 switch (info->params.data_bits) {
4294 case 7: RegValue |= BIT4 + BIT2; break;
4295 case 6: RegValue |= BIT5 + BIT3; break;
4296 case 5: RegValue |= BIT5 + BIT4 + BIT3 + BIT2; break;
4298 if (info->params.parity != ASYNC_PARITY_NONE) {
4300 if (info->params.parity == ASYNC_PARITY_ODD)
4303 write_reg(info, MD1, RegValue);
4305 /* MD2, Mode Register 2
4307 * 07..02 Reserved, must be 0
4308 * 01..00 CNCT<1..0> Channel connection, 0=normal
4313 write_reg(info, MD2, RegValue);
4315 /* RXS, Receive clock source
4317 * 07 Reserved, must be 0
4318 * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
4319 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4322 write_reg(info, RXS, RegValue);
4324 /* TXS, Transmit clock source
4326 * 07 Reserved, must be 0
4327 * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
4328 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4331 write_reg(info, TXS, RegValue);
4335 * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
4337 info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
4338 write_control_reg(info);
4342 /* RRC Receive Ready Control 0
4344 * 07..05 Reserved, must be 0
4345 * 04..00 RRC<4..0> Rx FIFO trigger active 0x00 = 1 byte
4347 write_reg(info, TRC0, 0x00);
4349 /* TRC0 Transmit Ready Control 0
4351 * 07..05 Reserved, must be 0
4352 * 04..00 TRC<4..0> Tx FIFO trigger active 0x10 = 16 bytes
4354 write_reg(info, TRC0, 0x10);
4356 /* TRC1 Transmit Ready Control 1
4358 * 07..05 Reserved, must be 0
4359 * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1e = 31 bytes (full-1)
4361 write_reg(info, TRC1, 0x1e);
4363 /* CTL, MSCI control register
4365 * 07..06 Reserved, set to 0
4366 * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
4367 * 04 IDLC, idle control, 0=mark 1=idle register
4368 * 03 BRK, break, 0=off 1 =on (async)
4369 * 02 SYNCLD, sync char load enable (BSC) 1=enabled
4370 * 01 GOP, go active on poll (LOOP mode) 1=enabled
4371 * 00 RTS, RTS output control, 0=active 1=inactive
4376 if (!(info->serial_signals & SerialSignal_RTS))
4378 write_reg(info, CTL, RegValue);
4380 /* enable status interrupts */
4381 info->ie0_value |= TXINTE + RXINTE;
4382 write_reg(info, IE0, info->ie0_value);
4384 /* enable break detect interrupt */
4385 info->ie1_value = BRKD;
4386 write_reg(info, IE1, info->ie1_value);
4388 /* enable rx overrun interrupt */
4389 info->ie2_value = OVRN;
4390 write_reg(info, IE2, info->ie2_value);
4392 set_rate( info, info->params.data_rate * 16 );
4394 if (info->params.loopback)
4395 enable_loopback(info,1);
4398 /* Program the SCA for HDLC communications.
4400 void hdlc_mode(SLMP_INFO *info)
4402 unsigned char RegValue;
4405 // Can't use DPLL because SCA outputs recovered clock on RxC when
4406 // DPLL mode selected. This causes output contention with RxC receiver.
4407 // Use of DPLL would require external hardware to disable RxC receiver
4408 // when DPLL mode selected.
4409 info->params.flags &= ~(HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL);
4411 /* disable DMA interrupts */
4412 write_reg(info, TXDMA + DIR, 0);
4413 write_reg(info, RXDMA + DIR, 0);
4415 /* MD0, Mode Register 0
4417 * 07..05 PRCTL<2..0>, Protocol Mode, 100=HDLC
4418 * 04 AUTO, Auto-enable (RTS/CTS/DCD)
4419 * 03 Reserved, must be 0
4420 * 02 CRCCC, CRC Calculation, 1=enabled
4421 * 01 CRC1, CRC selection, 0=CRC-16,1=CRC-CCITT-16
4422 * 00 CRC0, CRC initial value, 1 = all 1s
4427 if (info->params.flags & HDLC_FLAG_AUTO_CTS)
4429 if (info->params.flags & HDLC_FLAG_AUTO_DCD)
4431 if (info->params.crc_type == HDLC_CRC_16_CCITT)
4432 RegValue |= BIT2 + BIT1;
4433 write_reg(info, MD0, RegValue);
4435 /* MD1, Mode Register 1
4437 * 07..06 ADDRS<1..0>, Address detect, 00=no addr check
4438 * 05..04 TXCHR<1..0>, tx char size, 00=8 bits
4439 * 03..02 RXCHR<1..0>, rx char size, 00=8 bits
4440 * 01..00 PMPM<1..0>, Parity mode, 00=no parity
4445 write_reg(info, MD1, RegValue);
4447 /* MD2, Mode Register 2
4449 * 07 NRZFM, 0=NRZ, 1=FM
4450 * 06..05 CODE<1..0> Encoding, 00=NRZ
4451 * 04..03 DRATE<1..0> DPLL Divisor, 00=8
4452 * 02 Reserved, must be 0
4453 * 01..00 CNCT<1..0> Channel connection, 0=normal
4458 switch(info->params.encoding) {
4459 case HDLC_ENCODING_NRZI: RegValue |= BIT5; break;
4460 case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT7 + BIT5; break; /* aka FM1 */
4461 case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT7 + BIT6; break; /* aka FM0 */
4462 case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT7; break; /* aka Manchester */
4464 case HDLC_ENCODING_NRZB: /* not supported */
4465 case HDLC_ENCODING_NRZI_MARK: /* not supported */
4466 case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: /* not supported */
4469 if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
4472 } else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
4478 write_reg(info, MD2, RegValue);
4481 /* RXS, Receive clock source
4483 * 07 Reserved, must be 0
4484 * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
4485 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4488 if (info->params.flags & HDLC_FLAG_RXC_BRG)
4490 if (info->params.flags & HDLC_FLAG_RXC_DPLL)
4491 RegValue |= BIT6 + BIT5;
4492 write_reg(info, RXS, RegValue);
4494 /* TXS, Transmit clock source
4496 * 07 Reserved, must be 0
4497 * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
4498 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4501 if (info->params.flags & HDLC_FLAG_TXC_BRG)
4503 if (info->params.flags & HDLC_FLAG_TXC_DPLL)
4504 RegValue |= BIT6 + BIT5;
4505 write_reg(info, TXS, RegValue);
4507 if (info->params.flags & HDLC_FLAG_RXC_DPLL)
4508 set_rate(info, info->params.clock_speed * DpllDivisor);
4510 set_rate(info, info->params.clock_speed);
4512 /* GPDATA (General Purpose I/O Data Register)
4514 * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
4516 if (info->params.flags & HDLC_FLAG_TXC_BRG)
4517 info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
4519 info->port_array[0]->ctrlreg_value &= ~(BIT0 << (info->port_num * 2));
4520 write_control_reg(info);
4522 /* RRC Receive Ready Control 0
4524 * 07..05 Reserved, must be 0
4525 * 04..00 RRC<4..0> Rx FIFO trigger active
4527 write_reg(info, RRC, rx_active_fifo_level);
4529 /* TRC0 Transmit Ready Control 0
4531 * 07..05 Reserved, must be 0
4532 * 04..00 TRC<4..0> Tx FIFO trigger active
4534 write_reg(info, TRC0, tx_active_fifo_level);
4536 /* TRC1 Transmit Ready Control 1
4538 * 07..05 Reserved, must be 0
4539 * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1f = 32 bytes (full)
4541 write_reg(info, TRC1, (unsigned char)(tx_negate_fifo_level - 1));
4543 /* DMR, DMA Mode Register
4545 * 07..05 Reserved, must be 0
4546 * 04 TMOD, Transfer Mode: 1=chained-block
4547 * 03 Reserved, must be 0
4548 * 02 NF, Number of Frames: 1=multi-frame
4549 * 01 CNTE, Frame End IRQ Counter enable: 0=disabled
4550 * 00 Reserved, must be 0
4554 write_reg(info, TXDMA + DMR, 0x14);
4555 write_reg(info, RXDMA + DMR, 0x14);
4557 /* Set chain pointer base (upper 8 bits of 24 bit addr) */
4558 write_reg(info, RXDMA + CPB,
4559 (unsigned char)(info->buffer_list_phys >> 16));
4561 /* Set chain pointer base (upper 8 bits of 24 bit addr) */
4562 write_reg(info, TXDMA + CPB,
4563 (unsigned char)(info->buffer_list_phys >> 16));
4565 /* enable status interrupts. other code enables/disables
4566 * the individual sources for these two interrupt classes.
4568 info->ie0_value |= TXINTE + RXINTE;
4569 write_reg(info, IE0, info->ie0_value);
4571 /* CTL, MSCI control register
4573 * 07..06 Reserved, set to 0
4574 * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
4575 * 04 IDLC, idle control, 0=mark 1=idle register
4576 * 03 BRK, break, 0=off 1 =on (async)
4577 * 02 SYNCLD, sync char load enable (BSC) 1=enabled
4578 * 01 GOP, go active on poll (LOOP mode) 1=enabled
4579 * 00 RTS, RTS output control, 0=active 1=inactive
4584 if (!(info->serial_signals & SerialSignal_RTS))
4586 write_reg(info, CTL, RegValue);
4588 /* preamble not supported ! */
4594 set_rate(info, info->params.clock_speed);
4596 if (info->params.loopback)
4597 enable_loopback(info,1);
4600 /* Set the transmit HDLC idle mode
4602 void tx_set_idle(SLMP_INFO *info)
4604 unsigned char RegValue = 0xff;
4606 /* Map API idle mode to SCA register bits */
4607 switch(info->idle_mode) {
4608 case HDLC_TXIDLE_FLAGS: RegValue = 0x7e; break;
4609 case HDLC_TXIDLE_ALT_ZEROS_ONES: RegValue = 0xaa; break;
4610 case HDLC_TXIDLE_ZEROS: RegValue = 0x00; break;
4611 case HDLC_TXIDLE_ONES: RegValue = 0xff; break;
4612 case HDLC_TXIDLE_ALT_MARK_SPACE: RegValue = 0xaa; break;
4613 case HDLC_TXIDLE_SPACE: RegValue = 0x00; break;
4614 case HDLC_TXIDLE_MARK: RegValue = 0xff; break;
4617 write_reg(info, IDL, RegValue);
4620 /* Query the adapter for the state of the V24 status (input) signals.
4622 void get_signals(SLMP_INFO *info)
4624 u16 status = read_reg(info, SR3);
4625 u16 gpstatus = read_status_reg(info);
4628 /* clear all serial signals except DTR and RTS */
4629 info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
4631 /* set serial signal bits to reflect MISR */
4633 if (!(status & BIT3))
4634 info->serial_signals |= SerialSignal_CTS;
4636 if ( !(status & BIT2))
4637 info->serial_signals |= SerialSignal_DCD;
4639 testbit = BIT1 << (info->port_num * 2); // Port 0..3 RI is GPDATA<1,3,5,7>
4640 if (!(gpstatus & testbit))
4641 info->serial_signals |= SerialSignal_RI;
4643 testbit = BIT0 << (info->port_num * 2); // Port 0..3 DSR is GPDATA<0,2,4,6>
4644 if (!(gpstatus & testbit))
4645 info->serial_signals |= SerialSignal_DSR;
4648 /* Set the state of DTR and RTS based on contents of
4649 * serial_signals member of device context.
4651 void set_signals(SLMP_INFO *info)
4653 unsigned char RegValue;
4656 RegValue = read_reg(info, CTL);
4657 if (info->serial_signals & SerialSignal_RTS)
4661 write_reg(info, CTL, RegValue);
4663 // Port 0..3 DTR is ctrl reg <1,3,5,7>
4664 EnableBit = BIT1 << (info->port_num*2);
4665 if (info->serial_signals & SerialSignal_DTR)
4666 info->port_array[0]->ctrlreg_value &= ~EnableBit;
4668 info->port_array[0]->ctrlreg_value |= EnableBit;
4669 write_control_reg(info);
4672 /*******************/
4673 /* DMA Buffer Code */
4674 /*******************/
4676 /* Set the count for all receive buffers to SCABUFSIZE
4677 * and set the current buffer to the first buffer. This effectively
4678 * makes all buffers free and discards any data in buffers.
4680 void rx_reset_buffers(SLMP_INFO *info)
4682 rx_free_frame_buffers(info, 0, info->rx_buf_count - 1);
4685 /* Free the buffers used by a received frame
4687 * info pointer to device instance data
4688 * first index of 1st receive buffer of frame
4689 * last index of last receive buffer of frame
4691 void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last)
4696 /* reset current buffer for reuse */
4697 info->rx_buf_list[first].status = 0xff;
4699 if (first == last) {
4701 /* set new last rx descriptor address */
4702 write_reg16(info, RXDMA + EDA, info->rx_buf_list_ex[first].phys_entry);
4706 if (first == info->rx_buf_count)
4710 /* set current buffer to next buffer after last buffer of frame */
4711 info->current_rx_buf = first;
4714 /* Return a received frame from the receive DMA buffers.
4715 * Only frames received without errors are returned.
4717 * Return Value: 1 if frame returned, otherwise 0
4719 int rx_get_frame(SLMP_INFO *info)
4721 unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
4722 unsigned short status;
4723 unsigned int framesize = 0;
4725 unsigned long flags;
4726 struct tty_struct *tty = info->tty;
4727 unsigned char addr_field = 0xff;
4729 SCADESC_EX *desc_ex;
4732 /* assume no frame returned, set zero length */
4737 * current_rx_buf points to the 1st buffer of the next available
4738 * receive frame. To find the last buffer of the frame look for
4739 * a non-zero status field in the buffer entries. (The status
4740 * field is set by the 16C32 after completing a receive frame.
4742 StartIndex = EndIndex = info->current_rx_buf;
4745 desc = &info->rx_buf_list[EndIndex];
4746 desc_ex = &info->rx_buf_list_ex[EndIndex];
4748 if (desc->status == 0xff)
4749 goto Cleanup; /* current desc still in use, no frames available */
4751 if (framesize == 0 && info->params.addr_filter != 0xff)
4752 addr_field = desc_ex->virt_addr[0];
4754 framesize += desc->length;
4756 /* Status != 0 means last buffer of frame */
4761 if (EndIndex == info->rx_buf_count)
4764 if (EndIndex == info->current_rx_buf) {
4765 /* all buffers have been 'used' but none mark */
4766 /* the end of a frame. Reset buffers and receiver. */
4767 if ( info->rx_enabled ){
4768 spin_lock_irqsave(&info->lock,flags);
4770 spin_unlock_irqrestore(&info->lock,flags);
4777 /* check status of receive frame */
4779 /* frame status is byte stored after frame data
4781 * 7 EOM (end of msg), 1 = last buffer of frame
4782 * 6 Short Frame, 1 = short frame
4783 * 5 Abort, 1 = frame aborted
4784 * 4 Residue, 1 = last byte is partial
4785 * 3 Overrun, 1 = overrun occurred during frame reception
4786 * 2 CRC, 1 = CRC error detected
4789 status = desc->status;
4791 /* ignore CRC bit if not using CRC (bit is undefined) */
4792 /* Note:CRC is not save to data buffer */
4793 if (info->params.crc_type == HDLC_CRC_NONE)
4796 if (framesize == 0 ||
4797 (addr_field != 0xff && addr_field != info->params.addr_filter)) {
4798 /* discard 0 byte frames, this seems to occur sometime
4799 * when remote is idling flags.
4801 rx_free_frame_buffers(info, StartIndex, EndIndex);
4808 if (status & (BIT6+BIT5+BIT3+BIT2)) {
4809 /* received frame has errors,
4810 * update counts and mark frame size as 0
4813 info->icount.rxshort++;
4814 else if (status & BIT5)
4815 info->icount.rxabort++;
4816 else if (status & BIT3)
4817 info->icount.rxover++;
4819 info->icount.rxcrc++;
4823 #ifdef CONFIG_SYNCLINK_SYNCPPP
4824 info->netstats.rx_errors++;
4825 info->netstats.rx_frame_errors++;
4829 if ( debug_level >= DEBUG_LEVEL_BH )
4830 printk("%s(%d):%s rx_get_frame() status=%04X size=%d\n",
4831 __FILE__,__LINE__,info->device_name,status,framesize);
4833 if ( debug_level >= DEBUG_LEVEL_DATA )
4834 trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
4835 MIN(framesize,SCABUFSIZE),0);
4838 if (framesize > info->max_frame_size)
4839 info->icount.rxlong++;
4841 /* copy dma buffer(s) to contiguous intermediate buffer */
4842 int copy_count = framesize;
4843 int index = StartIndex;
4844 unsigned char *ptmp = info->tmp_rx_buf;
4845 info->tmp_rx_buf_count = framesize;
4847 info->icount.rxok++;
4850 int partial_count = MIN(copy_count,SCABUFSIZE);
4852 info->rx_buf_list_ex[index].virt_addr,
4854 ptmp += partial_count;
4855 copy_count -= partial_count;
4857 if ( ++index == info->rx_buf_count )
4861 #ifdef CONFIG_SYNCLINK_SYNCPPP
4862 if (info->netcount) {
4863 /* pass frame to syncppp device */
4864 sppp_rx_done(info,info->tmp_rx_buf,framesize);
4869 if ( tty && tty->ldisc.receive_buf ) {
4870 /* Call the line discipline receive callback directly. */
4871 tty->ldisc.receive_buf(tty,
4879 /* Free the buffers used by this frame. */
4880 rx_free_frame_buffers( info, StartIndex, EndIndex );
4885 if ( info->rx_enabled && info->rx_overflow ) {
4886 /* Receiver is enabled, but needs to restarted due to
4887 * rx buffer overflow. If buffers are empty, restart receiver.
4889 if (info->rx_buf_list[EndIndex].status == 0xff) {
4890 spin_lock_irqsave(&info->lock,flags);
4892 spin_unlock_irqrestore(&info->lock,flags);
4899 /* load the transmit DMA buffer with data
4901 void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count)
4903 unsigned short copy_count;
4906 SCADESC_EX *desc_ex;
4908 if ( debug_level >= DEBUG_LEVEL_DATA )
4909 trace_block(info,buf, MIN(count,SCABUFSIZE), 1);
4911 /* Copy source buffer to one or more DMA buffers, starting with
4912 * the first transmit dma buffer.
4916 copy_count = MIN(count,SCABUFSIZE);
4918 desc = &info->tx_buf_list[i];
4919 desc_ex = &info->tx_buf_list_ex[i];
4921 load_pci_memory(info, desc_ex->virt_addr,buf,copy_count);
4923 desc->length = copy_count;
4927 count -= copy_count;
4933 if (i >= info->tx_buf_count)
4937 info->tx_buf_list[i].status = 0x81; /* set EOM and EOT status */
4938 info->last_tx_buf = ++i;
4941 int register_test(SLMP_INFO *info)
4943 static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
4944 static unsigned int count = sizeof(testval)/sizeof(unsigned char);
4947 unsigned long flags;
4949 spin_lock_irqsave(&info->lock,flags);
4952 /* assume failure */
4953 info->init_error = DiagStatus_AddressFailure;
4955 /* Write bit patterns to various registers but do it out of */
4956 /* sync, then read back and verify values. */
4958 for (i = 0 ; i < count ; i++) {
4959 write_reg(info, TMC, testval[i]);
4960 write_reg(info, IDL, testval[(i+1)%count]);
4961 write_reg(info, SA0, testval[(i+2)%count]);
4962 write_reg(info, SA1, testval[(i+3)%count]);
4964 if ( (read_reg(info, TMC) != testval[i]) ||
4965 (read_reg(info, IDL) != testval[(i+1)%count]) ||
4966 (read_reg(info, SA0) != testval[(i+2)%count]) ||
4967 (read_reg(info, SA1) != testval[(i+3)%count]) )
4975 spin_unlock_irqrestore(&info->lock,flags);
4980 int irq_test(SLMP_INFO *info)
4982 unsigned long timeout;
4983 unsigned long flags;
4985 unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
4987 spin_lock_irqsave(&info->lock,flags);
4990 /* assume failure */
4991 info->init_error = DiagStatus_IrqFailure;
4992 info->irq_occurred = FALSE;
4994 /* setup timer0 on SCA0 to interrupt */
4996 /* IER2<7..4> = timer<3..0> interrupt enables (1=enabled) */
4997 write_reg(info, IER2, (unsigned char)((info->port_num & 1) ? BIT6 : BIT4));
4999 write_reg(info, (unsigned char)(timer + TEPR), 0); /* timer expand prescale */
5000 write_reg16(info, (unsigned char)(timer + TCONR), 1); /* timer constant */
5003 /* TMCS, Timer Control/Status Register
5005 * 07 CMF, Compare match flag (read only) 1=match
5006 * 06 ECMI, CMF Interrupt Enable: 1=enabled
5007 * 05 Reserved, must be 0
5008 * 04 TME, Timer Enable
5009 * 03..00 Reserved, must be 0
5013 write_reg(info, (unsigned char)(timer + TMCS), 0x50);
5015 spin_unlock_irqrestore(&info->lock,flags);
5018 while( timeout-- && !info->irq_occurred ) {
5019 set_current_state(TASK_INTERRUPTIBLE);
5020 schedule_timeout(jiffies_from_ms(10));
5023 spin_lock_irqsave(&info->lock,flags);
5025 spin_unlock_irqrestore(&info->lock,flags);
5027 return info->irq_occurred;
5030 /* initialize individual SCA device (2 ports)
5032 int sca_init(SLMP_INFO *info)
5034 /* set wait controller to single mem partition (low), no wait states */
5035 write_reg(info, PABR0, 0); /* wait controller addr boundary 0 */
5036 write_reg(info, PABR1, 0); /* wait controller addr boundary 1 */
5037 write_reg(info, WCRL, 0); /* wait controller low range */
5038 write_reg(info, WCRM, 0); /* wait controller mid range */
5039 write_reg(info, WCRH, 0); /* wait controller high range */
5041 /* DPCR, DMA Priority Control
5043 * 07..05 Not used, must be 0
5044 * 04 BRC, bus release condition: 0=all transfers complete
5045 * 03 CCC, channel change condition: 0=every cycle
5046 * 02..00 PR<2..0>, priority 100=round robin
5050 write_reg(info, DPCR, dma_priority);
5052 /* DMA Master Enable, BIT7: 1=enable all channels */
5053 write_reg(info, DMER, 0x80);
5055 /* enable all interrupt classes */
5056 write_reg(info, IER0, 0xff); /* TxRDY,RxRDY,TxINT,RxINT (ports 0-1) */
5057 write_reg(info, IER1, 0xff); /* DMIB,DMIA (channels 0-3) */
5058 write_reg(info, IER2, 0xf0); /* TIRQ (timers 0-3) */
5060 /* ITCR, interrupt control register
5061 * 07 IPC, interrupt priority, 0=MSCI->DMA
5062 * 06..05 IAK<1..0>, Acknowledge cycle, 00=non-ack cycle
5063 * 04 VOS, Vector Output, 0=unmodified vector
5064 * 03..00 Reserved, must be 0
5066 write_reg(info, ITCR, 0);
5071 /* initialize adapter hardware
5073 int init_adapter(SLMP_INFO *info)
5077 /* Set BIT30 of Local Control Reg 0x50 to reset SCA */
5078 volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
5081 info->misc_ctrl_value |= BIT30;
5082 *MiscCtrl = info->misc_ctrl_value;
5085 * Force at least 170ns delay before clearing
5086 * reset bit. Each read from LCR takes at least
5087 * 30ns so 10 times for 300ns to be safe.
5090 readval = *MiscCtrl;
5092 info->misc_ctrl_value &= ~BIT30;
5093 *MiscCtrl = info->misc_ctrl_value;
5095 /* init control reg (all DTRs off, all clksel=input) */
5096 info->ctrlreg_value = 0xaa;
5097 write_control_reg(info);
5100 volatile u32 *LCR1BRDR = (u32 *)(info->lcr_base + 0x2c);
5101 lcr1_brdr_value &= ~(BIT5 + BIT4 + BIT3);
5103 switch(read_ahead_count)
5106 lcr1_brdr_value |= BIT5 + BIT4 + BIT3;
5109 lcr1_brdr_value |= BIT5 + BIT4;
5112 lcr1_brdr_value |= BIT5 + BIT3;
5115 lcr1_brdr_value |= BIT5;
5119 *LCR1BRDR = lcr1_brdr_value;
5120 *MiscCtrl = misc_ctrl_value;
5123 sca_init(info->port_array[0]);
5124 sca_init(info->port_array[2]);
5129 /* Loopback an HDLC frame to test the hardware
5130 * interrupt and DMA functions.
5132 int loopback_test(SLMP_INFO *info)
5134 #define TESTFRAMESIZE 20
5136 unsigned long timeout;
5137 u16 count = TESTFRAMESIZE;
5138 unsigned char buf[TESTFRAMESIZE];
5140 unsigned long flags;
5142 struct tty_struct *oldtty = info->tty;
5143 u32 speed = info->params.clock_speed;
5145 info->params.clock_speed = 3686400;
5148 /* assume failure */
5149 info->init_error = DiagStatus_DmaFailure;
5151 /* build and send transmit frame */
5152 for (count = 0; count < TESTFRAMESIZE;++count)
5153 buf[count] = (unsigned char)count;
5155 memset(info->tmp_rx_buf,0,TESTFRAMESIZE);
5157 /* program hardware for HDLC and enabled receiver */
5158 spin_lock_irqsave(&info->lock,flags);
5160 enable_loopback(info,1);
5162 info->tx_count = count;
5163 tx_load_dma_buffer(info,buf,count);
5165 spin_unlock_irqrestore(&info->lock,flags);
5167 /* wait for receive complete */
5168 /* Set a timeout for waiting for interrupt. */
5169 for ( timeout = 100; timeout; --timeout ) {
5170 set_current_state(TASK_INTERRUPTIBLE);
5171 schedule_timeout(jiffies_from_ms(10));
5173 if (rx_get_frame(info)) {
5179 /* verify received frame length and contents */
5181 ( info->tmp_rx_buf_count != count ||
5182 memcmp(buf, info->tmp_rx_buf,count))) {
5186 spin_lock_irqsave(&info->lock,flags);
5187 reset_adapter(info);
5188 spin_unlock_irqrestore(&info->lock,flags);
5190 info->params.clock_speed = speed;
5196 /* Perform diagnostics on hardware
5198 int adapter_test( SLMP_INFO *info )
5200 unsigned long flags;
5201 if ( debug_level >= DEBUG_LEVEL_INFO )
5202 printk( "%s(%d):Testing device %s\n",
5203 __FILE__,__LINE__,info->device_name );
5205 spin_lock_irqsave(&info->lock,flags);
5207 spin_unlock_irqrestore(&info->lock,flags);
5209 info->port_array[0]->port_count = 0;
5211 if ( register_test(info->port_array[0]) &&
5212 register_test(info->port_array[1])) {
5214 info->port_array[0]->port_count = 2;
5216 if ( register_test(info->port_array[2]) &&
5217 register_test(info->port_array[3]) )
5218 info->port_array[0]->port_count += 2;
5221 printk( "%s(%d):Register test failure for device %s Addr=%08lX\n",
5222 __FILE__,__LINE__,info->device_name, (unsigned long)(info->phys_sca_base));
5226 if ( !irq_test(info->port_array[0]) ||
5227 !irq_test(info->port_array[1]) ||
5228 (info->port_count == 4 && !irq_test(info->port_array[2])) ||
5229 (info->port_count == 4 && !irq_test(info->port_array[3]))) {
5230 printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
5231 __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
5235 if (!loopback_test(info->port_array[0]) ||
5236 !loopback_test(info->port_array[1]) ||
5237 (info->port_count == 4 && !loopback_test(info->port_array[2])) ||
5238 (info->port_count == 4 && !loopback_test(info->port_array[3]))) {
5239 printk( "%s(%d):DMA test failure for device %s\n",
5240 __FILE__,__LINE__,info->device_name);
5244 if ( debug_level >= DEBUG_LEVEL_INFO )
5245 printk( "%s(%d):device %s passed diagnostics\n",
5246 __FILE__,__LINE__,info->device_name );
5248 info->port_array[0]->init_error = 0;
5249 info->port_array[1]->init_error = 0;
5250 if ( info->port_count > 2 ) {
5251 info->port_array[2]->init_error = 0;
5252 info->port_array[3]->init_error = 0;
5258 /* Test the shared memory on a PCI adapter.
5260 int memory_test(SLMP_INFO *info)
5262 static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
5263 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
5264 unsigned long count = sizeof(testval)/sizeof(unsigned long);
5266 unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
5267 unsigned long * addr = (unsigned long *)info->memory_base;
5269 /* Test data lines with test pattern at one location. */
5271 for ( i = 0 ; i < count ; i++ ) {
5273 if ( *addr != testval[i] )
5277 /* Test address lines with incrementing pattern over */
5278 /* entire address range. */
5280 for ( i = 0 ; i < limit ; i++ ) {
5285 addr = (unsigned long *)info->memory_base;
5287 for ( i = 0 ; i < limit ; i++ ) {
5288 if ( *addr != i * 4 )
5293 memset( info->memory_base, 0, SCA_MEM_SIZE );
5297 /* Load data into PCI adapter shared memory.
5299 * The PCI9050 releases control of the local bus
5300 * after completing the current read or write operation.
5302 * While the PCI9050 write FIFO not empty, the
5303 * PCI9050 treats all of the writes as a single transaction
5304 * and does not release the bus. This causes DMA latency problems
5305 * at high speeds when copying large data blocks to the shared memory.
5307 * This function breaks a write into multiple transations by
5308 * interleaving a read which flushes the write FIFO and 'completes'
5309 * the write transation. This allows any pending DMA request to gain control
5310 * of the local bus in a timely fasion.
5312 void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count)
5314 /* A load interval of 16 allows for 4 32-bit writes at */
5315 /* 136ns each for a maximum latency of 542ns on the local bus.*/
5317 unsigned short interval = count / sca_pci_load_interval;
5320 for ( i = 0 ; i < interval ; i++ )
5322 memcpy(dest, src, sca_pci_load_interval);
5323 read_status_reg(info);
5324 dest += sca_pci_load_interval;
5325 src += sca_pci_load_interval;
5328 memcpy(dest, src, count % sca_pci_load_interval);
5331 void trace_block(SLMP_INFO *info,const char* data, int count, int xmit)
5336 printk("%s tx data:\n",info->device_name);
5338 printk("%s rx data:\n",info->device_name);
5346 for(i=0;i<linecount;i++)
5347 printk("%02X ",(unsigned char)data[i]);
5350 for(i=0;i<linecount;i++) {
5351 if (data[i]>=040 && data[i]<=0176)
5352 printk("%c",data[i]);
5361 } /* end of trace_block() */
5363 /* called when HDLC frame times out
5364 * update stats and do tx completion processing
5366 void tx_timeout(unsigned long context)
5368 SLMP_INFO *info = (SLMP_INFO*)context;
5369 unsigned long flags;
5371 if ( debug_level >= DEBUG_LEVEL_INFO )
5372 printk( "%s(%d):%s tx_timeout()\n",
5373 __FILE__,__LINE__,info->device_name);
5374 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
5375 info->icount.txtimeout++;
5377 spin_lock_irqsave(&info->lock,flags);
5378 info->tx_active = 0;
5379 info->tx_count = info->tx_put = info->tx_get = 0;
5381 spin_unlock_irqrestore(&info->lock,flags);
5383 #ifdef CONFIG_SYNCLINK_SYNCPPP
5391 /* called to periodically check the DSR/RI modem signal input status
5393 void status_timeout(unsigned long context)
5396 SLMP_INFO *info = (SLMP_INFO*)context;
5397 unsigned long flags;
5398 unsigned char delta;
5401 spin_lock_irqsave(&info->lock,flags);
5403 spin_unlock_irqrestore(&info->lock,flags);
5405 /* check for DSR/RI state change */
5407 delta = info->old_signals ^ info->serial_signals;
5408 info->old_signals = info->serial_signals;
5410 if (delta & SerialSignal_DSR)
5411 status |= MISCSTATUS_DSR_LATCHED|(info->serial_signals&SerialSignal_DSR);
5413 if (delta & SerialSignal_RI)
5414 status |= MISCSTATUS_RI_LATCHED|(info->serial_signals&SerialSignal_RI);
5416 if (delta & SerialSignal_DCD)
5417 status |= MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD);
5419 if (delta & SerialSignal_CTS)
5420 status |= MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS);
5423 isr_io_pin(info,status);
5425 info->status_timer.data = (unsigned long)info;
5426 info->status_timer.function = status_timeout;
5427 info->status_timer.expires = jiffies + jiffies_from_ms(10);
5428 add_timer(&info->status_timer);
5432 /* Register Access Routines -
5433 * All registers are memory mapped
5435 #define CALC_REGADDR() \
5436 unsigned char * RegAddr = (unsigned char*)(info->sca_base + Addr); \
5437 if (info->port_num > 1) \
5438 RegAddr += 256; /* port 0-1 SCA0, 2-3 SCA1 */ \
5439 if ( info->port_num & 1) { \
5441 RegAddr += 0x40; /* DMA access */ \
5442 else if (Addr > 0x1f && Addr < 0x60) \
5443 RegAddr += 0x20; /* MSCI access */ \
5447 unsigned char read_reg(SLMP_INFO * info, unsigned char Addr)
5452 void write_reg(SLMP_INFO * info, unsigned char Addr, unsigned char Value)
5458 u16 read_reg16(SLMP_INFO * info, unsigned char Addr)
5461 return *((u16 *)RegAddr);
5464 void write_reg16(SLMP_INFO * info, unsigned char Addr, u16 Value)
5467 *((u16 *)RegAddr) = Value;
5470 unsigned char read_status_reg(SLMP_INFO * info)
5472 unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
5476 void write_control_reg(SLMP_INFO * info)
5478 unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
5479 *RegAddr = info->port_array[0]->ctrlreg_value;
5483 static int __devinit synclinkmp_init_one (struct pci_dev *dev,
5484 const struct pci_device_id *ent)
5486 if (pci_enable_device(dev)) {
5487 printk("error enabling pci device %p\n", dev);
5490 device_init( ++synclinkmp_adapter_count, dev );
5494 static void __devexit synclinkmp_remove_one (struct pci_dev *dev)