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 */
365 * FIXME: DAR here clashed with asm-ppc/reg.h and asm-sh/.../dma.h
368 /* DMA Controller Register macros */
400 /* combine with timer or DMA register address */
408 /* SCA Command Codes */
411 #define TXENABLE 0x02
412 #define TXDISABLE 0x03
413 #define TXCRCINIT 0x04
414 #define TXCRCEXCL 0x05
418 #define TXBUFCLR 0x09
420 #define RXENABLE 0x12
421 #define RXDISABLE 0x13
422 #define RXCRCINIT 0x14
423 #define RXREJECT 0x15
424 #define SEARCHMP 0x16
425 #define RXCRCEXCL 0x17
426 #define RXCRCCALC 0x18
430 /* DMA command codes */
432 #define FEICLEAR 0x02
465 #define jiffies_from_ms(a) ((((a) * HZ)/1000)+1)
468 * Global linked list of SyncLink devices
470 static SLMP_INFO *synclinkmp_device_list = NULL;
471 static int synclinkmp_adapter_count = -1;
472 static int synclinkmp_device_count = 0;
475 * Set this param to non-zero to load eax with the
476 * .text section address and breakpoint on module load.
477 * This is useful for use with gdb and add-symbol-file command.
479 static int break_on_load=0;
482 * Driver major number, defaults to zero to get auto
483 * assigned major number. May be forced as module parameter.
485 static int ttymajor=0;
488 * Array of user specified options for ISA adapters.
490 static int debug_level = 0;
491 static int maxframe[MAX_DEVICES] = {0,};
492 static int dosyncppp[MAX_DEVICES] = {0,};
494 MODULE_PARM(break_on_load,"i");
495 MODULE_PARM(ttymajor,"i");
496 MODULE_PARM(debug_level,"i");
497 MODULE_PARM(maxframe,"1-" __MODULE_STRING(MAX_DEVICES) "i");
498 MODULE_PARM(dosyncppp,"1-" __MODULE_STRING(MAX_DEVICES) "i");
500 static char *driver_name = "SyncLink MultiPort driver";
501 static char *driver_version = "$Revision: 4.22 $";
503 static int synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent);
504 static void synclinkmp_remove_one(struct pci_dev *dev);
506 static struct pci_device_id synclinkmp_pci_tbl[] = {
507 { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_SCA, PCI_ANY_ID, PCI_ANY_ID, },
508 { 0, }, /* terminate list */
510 MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
512 MODULE_LICENSE("GPL");
514 static struct pci_driver synclinkmp_pci_driver = {
515 .name = "synclinkmp",
516 .id_table = synclinkmp_pci_tbl,
517 .probe = synclinkmp_init_one,
518 .remove = __devexit_p(synclinkmp_remove_one),
522 static struct tty_driver *serial_driver;
524 /* number of characters left in xmit buffer before we ask for more */
525 #define WAKEUP_CHARS 256
528 #define MIN(a,b) ((a) < (b) ? (a) : (b))
534 static int open(struct tty_struct *tty, struct file * filp);
535 static void close(struct tty_struct *tty, struct file * filp);
536 static void hangup(struct tty_struct *tty);
537 static void set_termios(struct tty_struct *tty, struct termios *old_termios);
539 static int write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
540 static void put_char(struct tty_struct *tty, unsigned char ch);
541 static void send_xchar(struct tty_struct *tty, char ch);
542 static void wait_until_sent(struct tty_struct *tty, int timeout);
543 static int write_room(struct tty_struct *tty);
544 static void flush_chars(struct tty_struct *tty);
545 static void flush_buffer(struct tty_struct *tty);
546 static void tx_hold(struct tty_struct *tty);
547 static void tx_release(struct tty_struct *tty);
549 static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
550 static int read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
551 static int chars_in_buffer(struct tty_struct *tty);
552 static void throttle(struct tty_struct * tty);
553 static void unthrottle(struct tty_struct * tty);
554 static void set_break(struct tty_struct *tty, int break_state);
556 /* sppp support and callbacks */
558 #ifdef CONFIG_SYNCLINK_SYNCPPP
559 static void sppp_init(SLMP_INFO *info);
560 static void sppp_delete(SLMP_INFO *info);
561 static void sppp_rx_done(SLMP_INFO *info, char *buf, int size);
562 static void sppp_tx_done(SLMP_INFO *info);
564 static int sppp_cb_open(struct net_device *d);
565 static int sppp_cb_close(struct net_device *d);
566 static int sppp_cb_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
567 static int sppp_cb_tx(struct sk_buff *skb, struct net_device *dev);
568 static void sppp_cb_tx_timeout(struct net_device *dev);
569 static struct net_device_stats *sppp_cb_net_stats(struct net_device *dev);
574 static int get_stats(SLMP_INFO *info, struct mgsl_icount __user *user_icount);
575 static int get_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
576 static int set_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
577 static int get_txidle(SLMP_INFO *info, int __user *idle_mode);
578 static int set_txidle(SLMP_INFO *info, int idle_mode);
579 static int tx_enable(SLMP_INFO *info, int enable);
580 static int tx_abort(SLMP_INFO *info);
581 static int rx_enable(SLMP_INFO *info, int enable);
582 static int map_status(int signals);
583 static int modem_input_wait(SLMP_INFO *info,int arg);
584 static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
585 static int tiocmget(struct tty_struct *tty, struct file *file);
586 static int tiocmset(struct tty_struct *tty, struct file *file,
587 unsigned int set, unsigned int clear);
588 static void set_break(struct tty_struct *tty, int break_state);
590 static void add_device(SLMP_INFO *info);
591 static void device_init(int adapter_num, struct pci_dev *pdev);
592 static int claim_resources(SLMP_INFO *info);
593 static void release_resources(SLMP_INFO *info);
595 static int startup(SLMP_INFO *info);
596 static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
597 static void shutdown(SLMP_INFO *info);
598 static void program_hw(SLMP_INFO *info);
599 static void change_params(SLMP_INFO *info);
601 static int init_adapter(SLMP_INFO *info);
602 static int register_test(SLMP_INFO *info);
603 static int irq_test(SLMP_INFO *info);
604 static int loopback_test(SLMP_INFO *info);
605 static int adapter_test(SLMP_INFO *info);
606 static int memory_test(SLMP_INFO *info);
608 static void reset_adapter(SLMP_INFO *info);
609 static void reset_port(SLMP_INFO *info);
610 static void async_mode(SLMP_INFO *info);
611 static void hdlc_mode(SLMP_INFO *info);
613 static void rx_stop(SLMP_INFO *info);
614 static void rx_start(SLMP_INFO *info);
615 static void rx_reset_buffers(SLMP_INFO *info);
616 static void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last);
617 static int rx_get_frame(SLMP_INFO *info);
619 static void tx_start(SLMP_INFO *info);
620 static void tx_stop(SLMP_INFO *info);
621 static void tx_load_fifo(SLMP_INFO *info);
622 static void tx_set_idle(SLMP_INFO *info);
623 static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count);
625 static void get_signals(SLMP_INFO *info);
626 static void set_signals(SLMP_INFO *info);
627 static void enable_loopback(SLMP_INFO *info, int enable);
628 static void set_rate(SLMP_INFO *info, u32 data_rate);
630 static int bh_action(SLMP_INFO *info);
631 static void bh_handler(void* Context);
632 static void bh_receive(SLMP_INFO *info);
633 static void bh_transmit(SLMP_INFO *info);
634 static void bh_status(SLMP_INFO *info);
635 static void isr_timer(SLMP_INFO *info);
636 static void isr_rxint(SLMP_INFO *info);
637 static void isr_rxrdy(SLMP_INFO *info);
638 static void isr_txint(SLMP_INFO *info);
639 static void isr_txrdy(SLMP_INFO *info);
640 static void isr_rxdmaok(SLMP_INFO *info);
641 static void isr_rxdmaerror(SLMP_INFO *info);
642 static void isr_txdmaok(SLMP_INFO *info);
643 static void isr_txdmaerror(SLMP_INFO *info);
644 static void isr_io_pin(SLMP_INFO *info, u16 status);
646 static int alloc_dma_bufs(SLMP_INFO *info);
647 static void free_dma_bufs(SLMP_INFO *info);
648 static int alloc_buf_list(SLMP_INFO *info);
649 static int alloc_frame_bufs(SLMP_INFO *info, SCADESC *list, SCADESC_EX *list_ex,int count);
650 static int alloc_tmp_rx_buf(SLMP_INFO *info);
651 static void free_tmp_rx_buf(SLMP_INFO *info);
653 static void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count);
654 static void trace_block(SLMP_INFO *info, const char* data, int count, int xmit);
655 static void tx_timeout(unsigned long context);
656 static void status_timeout(unsigned long context);
658 static unsigned char read_reg(SLMP_INFO *info, unsigned char addr);
659 static void write_reg(SLMP_INFO *info, unsigned char addr, unsigned char val);
660 static u16 read_reg16(SLMP_INFO *info, unsigned char addr);
661 static void write_reg16(SLMP_INFO *info, unsigned char addr, u16 val);
662 static unsigned char read_status_reg(SLMP_INFO * info);
663 static void write_control_reg(SLMP_INFO * info);
666 static unsigned char rx_active_fifo_level = 16; // rx request FIFO activation level in bytes
667 static unsigned char tx_active_fifo_level = 16; // tx request FIFO activation level in bytes
668 static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes
670 static u32 misc_ctrl_value = 0x007e4040;
671 static u32 lcr1_brdr_value = 0x0080002d;
673 static u32 read_ahead_count = 8;
675 /* DPCR, DMA Priority Control
677 * 07..05 Not used, must be 0
678 * 04 BRC, bus release condition: 0=all transfers complete
679 * 1=release after 1 xfer on all channels
680 * 03 CCC, channel change condition: 0=every cycle
681 * 1=after each channel completes all xfers
682 * 02..00 PR<2..0>, priority 100=round robin
686 static unsigned char dma_priority = 0x04;
688 // Number of bytes that can be written to shared RAM
689 // in a single write operation
690 static u32 sca_pci_load_interval = 64;
693 * 1st function defined in .text section. Calling this function in
694 * init_module() followed by a breakpoint allows a remote debugger
695 * (gdb) to get the .text address for the add-symbol-file command.
696 * This allows remote debugging of dynamically loadable modules.
698 static void* synclinkmp_get_text_ptr(void);
699 static void* synclinkmp_get_text_ptr(void) {return synclinkmp_get_text_ptr;}
701 static inline int sanity_check(SLMP_INFO *info,
702 char *name, const char *routine)
705 static const char *badmagic =
706 "Warning: bad magic number for synclinkmp_struct (%s) in %s\n";
707 static const char *badinfo =
708 "Warning: null synclinkmp_struct for (%s) in %s\n";
711 printk(badinfo, name, routine);
714 if (info->magic != MGSL_MAGIC) {
715 printk(badmagic, name, routine);
727 /* Called when a port is opened. Init and enable port.
729 static int open(struct tty_struct *tty, struct file *filp)
736 if ((line < 0) || (line >= synclinkmp_device_count)) {
737 printk("%s(%d): open with invalid line #%d.\n",
738 __FILE__,__LINE__,line);
742 info = synclinkmp_device_list;
743 while(info && info->line != line)
744 info = info->next_device;
745 if (sanity_check(info, tty->name, "open"))
747 if ( info->init_error ) {
748 printk("%s(%d):%s device is not allocated, init error=%d\n",
749 __FILE__,__LINE__,info->device_name,info->init_error);
753 tty->driver_data = info;
756 if (debug_level >= DEBUG_LEVEL_INFO)
757 printk("%s(%d):%s open(), old ref count = %d\n",
758 __FILE__,__LINE__,tty->driver->name, info->count);
760 /* If port is closing, signal caller to try again */
761 if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
762 if (info->flags & ASYNC_CLOSING)
763 interruptible_sleep_on(&info->close_wait);
764 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
765 -EAGAIN : -ERESTARTSYS);
769 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
771 spin_lock_irqsave(&info->netlock, flags);
772 if (info->netcount) {
774 spin_unlock_irqrestore(&info->netlock, flags);
778 spin_unlock_irqrestore(&info->netlock, flags);
780 if (info->count == 1) {
781 /* 1st open on this device, init hardware */
782 retval = startup(info);
787 retval = block_til_ready(tty, filp, info);
789 if (debug_level >= DEBUG_LEVEL_INFO)
790 printk("%s(%d):%s block_til_ready() returned %d\n",
791 __FILE__,__LINE__, info->device_name, retval);
795 if (debug_level >= DEBUG_LEVEL_INFO)
796 printk("%s(%d):%s open() success\n",
797 __FILE__,__LINE__, info->device_name);
803 info->tty = NULL;/* tty layer will release tty struct */
811 /* Called when port is closed. Wait for remaining data to be
812 * sent. Disable port and free resources.
814 static void close(struct tty_struct *tty, struct file *filp)
816 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
818 if (sanity_check(info, tty->name, "close"))
821 if (debug_level >= DEBUG_LEVEL_INFO)
822 printk("%s(%d):%s close() entry, count=%d\n",
823 __FILE__,__LINE__, info->device_name, info->count);
828 if (tty_hung_up_p(filp))
831 if ((tty->count == 1) && (info->count != 1)) {
833 * tty->count is 1 and the tty structure will be freed.
834 * info->count should be one in this case.
835 * if it's not, correct it so that the port is shutdown.
837 printk("%s(%d):%s close: bad refcount; tty->count is 1, "
838 "info->count is %d\n",
839 __FILE__,__LINE__, info->device_name, info->count);
845 /* if at least one open remaining, leave hardware active */
849 info->flags |= ASYNC_CLOSING;
851 /* set tty->closing to notify line discipline to
852 * only process XON/XOFF characters. Only the N_TTY
853 * discipline appears to use this (ppp does not).
857 /* wait for transmit data to clear all layers */
859 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
860 if (debug_level >= DEBUG_LEVEL_INFO)
861 printk("%s(%d):%s close() calling tty_wait_until_sent\n",
862 __FILE__,__LINE__, info->device_name );
863 tty_wait_until_sent(tty, info->closing_wait);
866 if (info->flags & ASYNC_INITIALIZED)
867 wait_until_sent(tty, info->timeout);
869 if (tty->driver->flush_buffer)
870 tty->driver->flush_buffer(tty);
872 if (tty->ldisc.flush_buffer)
873 tty->ldisc.flush_buffer(tty);
880 if (info->blocked_open) {
881 if (info->close_delay) {
882 set_current_state(TASK_INTERRUPTIBLE);
883 schedule_timeout(info->close_delay);
885 wake_up_interruptible(&info->open_wait);
888 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
890 wake_up_interruptible(&info->close_wait);
893 if (debug_level >= DEBUG_LEVEL_INFO)
894 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
895 tty->driver->name, info->count);
898 /* Called by tty_hangup() when a hangup is signaled.
899 * This is the same as closing all open descriptors for the port.
901 static void hangup(struct tty_struct *tty)
903 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
905 if (debug_level >= DEBUG_LEVEL_INFO)
906 printk("%s(%d):%s hangup()\n",
907 __FILE__,__LINE__, info->device_name );
909 if (sanity_check(info, tty->name, "hangup"))
916 info->flags &= ~ASYNC_NORMAL_ACTIVE;
919 wake_up_interruptible(&info->open_wait);
922 /* Set new termios settings
924 static void set_termios(struct tty_struct *tty, struct termios *old_termios)
926 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
929 if (debug_level >= DEBUG_LEVEL_INFO)
930 printk("%s(%d):%s set_termios()\n", __FILE__,__LINE__,
933 /* just return if nothing has changed */
934 if ((tty->termios->c_cflag == old_termios->c_cflag)
935 && (RELEVANT_IFLAG(tty->termios->c_iflag)
936 == RELEVANT_IFLAG(old_termios->c_iflag)))
941 /* Handle transition to B0 status */
942 if (old_termios->c_cflag & CBAUD &&
943 !(tty->termios->c_cflag & CBAUD)) {
944 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
945 spin_lock_irqsave(&info->lock,flags);
947 spin_unlock_irqrestore(&info->lock,flags);
950 /* Handle transition away from B0 status */
951 if (!(old_termios->c_cflag & CBAUD) &&
952 tty->termios->c_cflag & CBAUD) {
953 info->serial_signals |= SerialSignal_DTR;
954 if (!(tty->termios->c_cflag & CRTSCTS) ||
955 !test_bit(TTY_THROTTLED, &tty->flags)) {
956 info->serial_signals |= SerialSignal_RTS;
958 spin_lock_irqsave(&info->lock,flags);
960 spin_unlock_irqrestore(&info->lock,flags);
963 /* Handle turning off CRTSCTS */
964 if (old_termios->c_cflag & CRTSCTS &&
965 !(tty->termios->c_cflag & CRTSCTS)) {
971 /* Send a block of data
975 * tty pointer to tty information structure
976 * from_user flag: 1 = from user process
977 * buf pointer to buffer containing send data
978 * count size of send data in bytes
980 * Return Value: number of characters written
982 static int write(struct tty_struct *tty, int from_user,
983 const unsigned char *buf, int count)
986 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
989 if (debug_level >= DEBUG_LEVEL_INFO)
990 printk("%s(%d):%s write() count=%d\n",
991 __FILE__,__LINE__,info->device_name,count);
993 if (sanity_check(info, tty->name, "write"))
996 if (!tty || !info->tx_buf)
999 if (info->params.mode == MGSL_MODE_HDLC) {
1000 if (count > info->max_frame_size) {
1004 if (info->tx_active)
1006 if (info->tx_count) {
1007 /* send accumulated data from send_char() calls */
1008 /* as frame and wait before accepting more data. */
1009 tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
1013 ret = info->tx_count = count;
1014 tx_load_dma_buffer(info, buf, count);
1021 MIN(info->max_frame_size - info->tx_count - 1,
1022 info->max_frame_size - info->tx_put));
1027 COPY_FROM_USER(err, info->tx_buf + info->tx_put, buf, c);
1034 memcpy(info->tx_buf + info->tx_put, buf, c);
1036 spin_lock_irqsave(&info->lock,flags);
1038 if (info->tx_put >= info->max_frame_size)
1039 info->tx_put -= info->max_frame_size;
1040 info->tx_count += c;
1041 spin_unlock_irqrestore(&info->lock,flags);
1048 if (info->params.mode == MGSL_MODE_HDLC) {
1050 ret = info->tx_count = 0;
1053 tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
1056 if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
1057 spin_lock_irqsave(&info->lock,flags);
1058 if (!info->tx_active)
1060 spin_unlock_irqrestore(&info->lock,flags);
1064 if (debug_level >= DEBUG_LEVEL_INFO)
1065 printk( "%s(%d):%s write() returning=%d\n",
1066 __FILE__,__LINE__,info->device_name,ret);
1070 /* Add a character to the transmit buffer.
1072 static void put_char(struct tty_struct *tty, unsigned char ch)
1074 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1075 unsigned long flags;
1077 if ( debug_level >= DEBUG_LEVEL_INFO ) {
1078 printk( "%s(%d):%s put_char(%d)\n",
1079 __FILE__,__LINE__,info->device_name,ch);
1082 if (sanity_check(info, tty->name, "put_char"))
1085 if (!tty || !info->tx_buf)
1088 spin_lock_irqsave(&info->lock,flags);
1090 if ( (info->params.mode != MGSL_MODE_HDLC) ||
1091 !info->tx_active ) {
1093 if (info->tx_count < info->max_frame_size - 1) {
1094 info->tx_buf[info->tx_put++] = ch;
1095 if (info->tx_put >= info->max_frame_size)
1096 info->tx_put -= info->max_frame_size;
1101 spin_unlock_irqrestore(&info->lock,flags);
1104 /* Send a high-priority XON/XOFF character
1106 static void send_xchar(struct tty_struct *tty, char ch)
1108 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1109 unsigned long flags;
1111 if (debug_level >= DEBUG_LEVEL_INFO)
1112 printk("%s(%d):%s send_xchar(%d)\n",
1113 __FILE__,__LINE__, info->device_name, ch );
1115 if (sanity_check(info, tty->name, "send_xchar"))
1120 /* Make sure transmit interrupts are on */
1121 spin_lock_irqsave(&info->lock,flags);
1122 if (!info->tx_enabled)
1124 spin_unlock_irqrestore(&info->lock,flags);
1128 /* Wait until the transmitter is empty.
1130 static void wait_until_sent(struct tty_struct *tty, int timeout)
1132 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
1133 unsigned long orig_jiffies, char_time;
1138 if (debug_level >= DEBUG_LEVEL_INFO)
1139 printk("%s(%d):%s wait_until_sent() entry\n",
1140 __FILE__,__LINE__, info->device_name );
1142 if (sanity_check(info, tty->name, "wait_until_sent"))
1145 if (!(info->flags & ASYNC_INITIALIZED))
1148 orig_jiffies = jiffies;
1150 /* Set check interval to 1/5 of estimated time to
1151 * send a character, and make it at least 1. The check
1152 * interval should also be less than the timeout.
1153 * Note: use tight timings here to satisfy the NIST-PCTS.
1156 if ( info->params.data_rate ) {
1157 char_time = info->timeout/(32 * 5);
1164 char_time = MIN(char_time, timeout);
1166 if ( info->params.mode == MGSL_MODE_HDLC ) {
1167 while (info->tx_active) {
1168 set_current_state(TASK_INTERRUPTIBLE);
1169 schedule_timeout(char_time);
1170 if (signal_pending(current))
1172 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1176 //TODO: determine if there is something similar to USC16C32
1177 // TXSTATUS_ALL_SENT status
1178 while ( info->tx_active && info->tx_enabled) {
1179 set_current_state(TASK_INTERRUPTIBLE);
1180 schedule_timeout(char_time);
1181 if (signal_pending(current))
1183 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1189 if (debug_level >= DEBUG_LEVEL_INFO)
1190 printk("%s(%d):%s wait_until_sent() exit\n",
1191 __FILE__,__LINE__, info->device_name );
1194 /* Return the count of free bytes in transmit buffer
1196 static int write_room(struct tty_struct *tty)
1198 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1201 if (sanity_check(info, tty->name, "write_room"))
1204 if (info->params.mode == MGSL_MODE_HDLC) {
1205 ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
1207 ret = info->max_frame_size - info->tx_count - 1;
1212 if (debug_level >= DEBUG_LEVEL_INFO)
1213 printk("%s(%d):%s write_room()=%d\n",
1214 __FILE__, __LINE__, info->device_name, ret);
1219 /* enable transmitter and send remaining buffered characters
1221 static void flush_chars(struct tty_struct *tty)
1223 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1224 unsigned long flags;
1226 if ( debug_level >= DEBUG_LEVEL_INFO )
1227 printk( "%s(%d):%s flush_chars() entry tx_count=%d\n",
1228 __FILE__,__LINE__,info->device_name,info->tx_count);
1230 if (sanity_check(info, tty->name, "flush_chars"))
1233 if (info->tx_count <= 0 || tty->stopped || tty->hw_stopped ||
1237 if ( debug_level >= DEBUG_LEVEL_INFO )
1238 printk( "%s(%d):%s flush_chars() entry, starting transmitter\n",
1239 __FILE__,__LINE__,info->device_name );
1241 spin_lock_irqsave(&info->lock,flags);
1243 if (!info->tx_active) {
1244 if ( (info->params.mode == MGSL_MODE_HDLC) &&
1246 /* operating in synchronous (frame oriented) mode */
1247 /* copy data from circular tx_buf to */
1248 /* transmit DMA buffer. */
1249 tx_load_dma_buffer(info,
1250 info->tx_buf,info->tx_count);
1255 spin_unlock_irqrestore(&info->lock,flags);
1258 /* Discard all data in the send buffer
1260 static void flush_buffer(struct tty_struct *tty)
1262 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1263 unsigned long flags;
1265 if (debug_level >= DEBUG_LEVEL_INFO)
1266 printk("%s(%d):%s flush_buffer() entry\n",
1267 __FILE__,__LINE__, info->device_name );
1269 if (sanity_check(info, tty->name, "flush_buffer"))
1272 spin_lock_irqsave(&info->lock,flags);
1273 info->tx_count = info->tx_put = info->tx_get = 0;
1274 del_timer(&info->tx_timer);
1275 spin_unlock_irqrestore(&info->lock,flags);
1277 wake_up_interruptible(&tty->write_wait);
1278 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1279 tty->ldisc.write_wakeup)
1280 (tty->ldisc.write_wakeup)(tty);
1283 /* throttle (stop) transmitter
1285 static void tx_hold(struct tty_struct *tty)
1287 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1288 unsigned long flags;
1290 if (sanity_check(info, tty->name, "tx_hold"))
1293 if ( debug_level >= DEBUG_LEVEL_INFO )
1294 printk("%s(%d):%s tx_hold()\n",
1295 __FILE__,__LINE__,info->device_name);
1297 spin_lock_irqsave(&info->lock,flags);
1298 if (info->tx_enabled)
1300 spin_unlock_irqrestore(&info->lock,flags);
1303 /* release (start) transmitter
1305 static void tx_release(struct tty_struct *tty)
1307 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1308 unsigned long flags;
1310 if (sanity_check(info, tty->name, "tx_release"))
1313 if ( debug_level >= DEBUG_LEVEL_INFO )
1314 printk("%s(%d):%s tx_release()\n",
1315 __FILE__,__LINE__,info->device_name);
1317 spin_lock_irqsave(&info->lock,flags);
1318 if (!info->tx_enabled)
1320 spin_unlock_irqrestore(&info->lock,flags);
1323 /* Service an IOCTL request
1327 * tty pointer to tty instance data
1328 * file pointer to associated file object for device
1329 * cmd IOCTL command code
1330 * arg command argument/context
1332 * Return Value: 0 if success, otherwise error code
1334 static int ioctl(struct tty_struct *tty, struct file *file,
1335 unsigned int cmd, unsigned long arg)
1337 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1339 struct mgsl_icount cnow; /* kernel counter temps */
1340 struct serial_icounter_struct __user *p_cuser; /* user space */
1341 unsigned long flags;
1342 void __user *argp = (void __user *)arg;
1344 if (debug_level >= DEBUG_LEVEL_INFO)
1345 printk("%s(%d):%s ioctl() cmd=%08X\n", __FILE__,__LINE__,
1346 info->device_name, cmd );
1348 if (sanity_check(info, tty->name, "ioctl"))
1351 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1352 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
1353 if (tty->flags & (1 << TTY_IO_ERROR))
1358 case MGSL_IOCGPARAMS:
1359 return get_params(info, argp);
1360 case MGSL_IOCSPARAMS:
1361 return set_params(info, argp);
1362 case MGSL_IOCGTXIDLE:
1363 return get_txidle(info, argp);
1364 case MGSL_IOCSTXIDLE:
1365 return set_txidle(info, (int)arg);
1366 case MGSL_IOCTXENABLE:
1367 return tx_enable(info, (int)arg);
1368 case MGSL_IOCRXENABLE:
1369 return rx_enable(info, (int)arg);
1370 case MGSL_IOCTXABORT:
1371 return tx_abort(info);
1372 case MGSL_IOCGSTATS:
1373 return get_stats(info, argp);
1374 case MGSL_IOCWAITEVENT:
1375 return wait_mgsl_event(info, argp);
1376 case MGSL_IOCLOOPTXDONE:
1377 return 0; // TODO: Not supported, need to document
1378 /* Wait for modem input (DCD,RI,DSR,CTS) change
1379 * as specified by mask in arg (TIOCM_RNG/DSR/CD/CTS)
1382 return modem_input_wait(info,(int)arg);
1385 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1386 * Return: write counters to the user passed counter struct
1387 * NB: both 1->0 and 0->1 transitions are counted except for
1388 * RI where only 0->1 is counted.
1391 spin_lock_irqsave(&info->lock,flags);
1392 cnow = info->icount;
1393 spin_unlock_irqrestore(&info->lock,flags);
1395 PUT_USER(error,cnow.cts, &p_cuser->cts);
1396 if (error) return error;
1397 PUT_USER(error,cnow.dsr, &p_cuser->dsr);
1398 if (error) return error;
1399 PUT_USER(error,cnow.rng, &p_cuser->rng);
1400 if (error) return error;
1401 PUT_USER(error,cnow.dcd, &p_cuser->dcd);
1402 if (error) return error;
1403 PUT_USER(error,cnow.rx, &p_cuser->rx);
1404 if (error) return error;
1405 PUT_USER(error,cnow.tx, &p_cuser->tx);
1406 if (error) return error;
1407 PUT_USER(error,cnow.frame, &p_cuser->frame);
1408 if (error) return error;
1409 PUT_USER(error,cnow.overrun, &p_cuser->overrun);
1410 if (error) return error;
1411 PUT_USER(error,cnow.parity, &p_cuser->parity);
1412 if (error) return error;
1413 PUT_USER(error,cnow.brk, &p_cuser->brk);
1414 if (error) return error;
1415 PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
1416 if (error) return error;
1419 return -ENOIOCTLCMD;
1425 * /proc fs routines....
1428 static inline int line_info(char *buf, SLMP_INFO *info)
1432 unsigned long flags;
1434 ret = sprintf(buf, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
1435 "\tIRQ=%d MaxFrameSize=%u\n",
1437 info->phys_sca_base,
1438 info->phys_memory_base,
1439 info->phys_statctrl_base,
1440 info->phys_lcr_base,
1442 info->max_frame_size );
1444 /* output current serial signal states */
1445 spin_lock_irqsave(&info->lock,flags);
1447 spin_unlock_irqrestore(&info->lock,flags);
1451 if (info->serial_signals & SerialSignal_RTS)
1452 strcat(stat_buf, "|RTS");
1453 if (info->serial_signals & SerialSignal_CTS)
1454 strcat(stat_buf, "|CTS");
1455 if (info->serial_signals & SerialSignal_DTR)
1456 strcat(stat_buf, "|DTR");
1457 if (info->serial_signals & SerialSignal_DSR)
1458 strcat(stat_buf, "|DSR");
1459 if (info->serial_signals & SerialSignal_DCD)
1460 strcat(stat_buf, "|CD");
1461 if (info->serial_signals & SerialSignal_RI)
1462 strcat(stat_buf, "|RI");
1464 if (info->params.mode == MGSL_MODE_HDLC) {
1465 ret += sprintf(buf+ret, "\tHDLC txok:%d rxok:%d",
1466 info->icount.txok, info->icount.rxok);
1467 if (info->icount.txunder)
1468 ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
1469 if (info->icount.txabort)
1470 ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
1471 if (info->icount.rxshort)
1472 ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);
1473 if (info->icount.rxlong)
1474 ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
1475 if (info->icount.rxover)
1476 ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
1477 if (info->icount.rxcrc)
1478 ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxcrc);
1480 ret += sprintf(buf+ret, "\tASYNC tx:%d rx:%d",
1481 info->icount.tx, info->icount.rx);
1482 if (info->icount.frame)
1483 ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
1484 if (info->icount.parity)
1485 ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
1486 if (info->icount.brk)
1487 ret += sprintf(buf+ret, " brk:%d", info->icount.brk);
1488 if (info->icount.overrun)
1489 ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
1492 /* Append serial signal status to end */
1493 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
1495 ret += sprintf(buf+ret, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
1496 info->tx_active,info->bh_requested,info->bh_running,
1502 /* Called to print information about devices
1504 int read_proc(char *page, char **start, off_t off, int count,
1505 int *eof, void *data)
1511 len += sprintf(page, "synclinkmp driver:%s\n", driver_version);
1513 info = synclinkmp_device_list;
1515 l = line_info(page + len, info);
1517 if (len+begin > off+count)
1519 if (len+begin < off) {
1523 info = info->next_device;
1528 if (off >= len+begin)
1530 *start = page + (off-begin);
1531 return ((count < begin+len-off) ? count : begin+len-off);
1534 /* Return the count of bytes in transmit buffer
1536 static int chars_in_buffer(struct tty_struct *tty)
1538 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1540 if (sanity_check(info, tty->name, "chars_in_buffer"))
1543 if (debug_level >= DEBUG_LEVEL_INFO)
1544 printk("%s(%d):%s chars_in_buffer()=%d\n",
1545 __FILE__, __LINE__, info->device_name, info->tx_count);
1547 return info->tx_count;
1550 /* Signal remote device to throttle send data (our receive data)
1552 static void throttle(struct tty_struct * tty)
1554 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1555 unsigned long flags;
1557 if (debug_level >= DEBUG_LEVEL_INFO)
1558 printk("%s(%d):%s throttle() entry\n",
1559 __FILE__,__LINE__, info->device_name );
1561 if (sanity_check(info, tty->name, "throttle"))
1565 send_xchar(tty, STOP_CHAR(tty));
1567 if (tty->termios->c_cflag & CRTSCTS) {
1568 spin_lock_irqsave(&info->lock,flags);
1569 info->serial_signals &= ~SerialSignal_RTS;
1571 spin_unlock_irqrestore(&info->lock,flags);
1575 /* Signal remote device to stop throttling send data (our receive data)
1577 static void unthrottle(struct tty_struct * tty)
1579 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
1580 unsigned long flags;
1582 if (debug_level >= DEBUG_LEVEL_INFO)
1583 printk("%s(%d):%s unthrottle() entry\n",
1584 __FILE__,__LINE__, info->device_name );
1586 if (sanity_check(info, tty->name, "unthrottle"))
1593 send_xchar(tty, START_CHAR(tty));
1596 if (tty->termios->c_cflag & CRTSCTS) {
1597 spin_lock_irqsave(&info->lock,flags);
1598 info->serial_signals |= SerialSignal_RTS;
1600 spin_unlock_irqrestore(&info->lock,flags);
1604 /* set or clear transmit break condition
1605 * break_state -1=set break condition, 0=clear
1607 static void set_break(struct tty_struct *tty, int break_state)
1609 unsigned char RegValue;
1610 SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
1611 unsigned long flags;
1613 if (debug_level >= DEBUG_LEVEL_INFO)
1614 printk("%s(%d):%s set_break(%d)\n",
1615 __FILE__,__LINE__, info->device_name, break_state);
1617 if (sanity_check(info, tty->name, "set_break"))
1620 spin_lock_irqsave(&info->lock,flags);
1621 RegValue = read_reg(info, CTL);
1622 if (break_state == -1)
1626 write_reg(info, CTL, RegValue);
1627 spin_unlock_irqrestore(&info->lock,flags);
1630 #ifdef CONFIG_SYNCLINK_SYNCPPP
1632 /* syncppp support and callbacks */
1634 static void cb_setup(struct net_device *dev)
1636 dev->open = sppp_cb_open;
1637 dev->stop = sppp_cb_close;
1638 dev->hard_start_xmit = sppp_cb_tx;
1639 dev->do_ioctl = sppp_cb_ioctl;
1640 dev->get_stats = sppp_cb_net_stats;
1641 dev->tx_timeout = sppp_cb_tx_timeout;
1642 dev->watchdog_timeo = 10*HZ;
1645 static void sppp_init(SLMP_INFO *info)
1647 struct net_device *d;
1649 sprintf(info->netname,"mgslm%dp%d",info->adapter_num,info->port_num);
1651 d = alloc_netdev(0, info->netname, cb_setup);
1653 printk(KERN_WARNING "%s: alloc_netdev failed.\n",
1658 info->if_ptr = &info->pppdev;
1659 info->netdev = info->pppdev.dev = d;
1661 d->irq = info->irq_level;
1664 sppp_attach(&info->pppdev);
1667 if (register_netdev(d)) {
1668 printk(KERN_WARNING "%s: register_netdev failed.\n", d->name);
1669 sppp_detach(info->netdev);
1670 info->netdev = NULL;
1671 info->pppdev.dev = NULL;
1676 if (debug_level >= DEBUG_LEVEL_INFO)
1677 printk("sppp_init(%s)\n",info->netname);
1680 static void sppp_delete(SLMP_INFO *info)
1682 if (debug_level >= DEBUG_LEVEL_INFO)
1683 printk("sppp_delete(%s)\n",info->netname);
1684 unregister_netdev(info->netdev);
1685 sppp_detach(info->netdev);
1686 free_netdev(info->netdev);
1687 info->netdev = NULL;
1688 info->pppdev.dev = NULL;
1691 static int sppp_cb_open(struct net_device *d)
1693 SLMP_INFO *info = d->priv;
1695 unsigned long flags;
1697 if (debug_level >= DEBUG_LEVEL_INFO)
1698 printk("sppp_cb_open(%s)\n",info->netname);
1700 spin_lock_irqsave(&info->netlock, flags);
1701 if (info->count != 0 || info->netcount != 0) {
1702 printk(KERN_WARNING "%s: sppp_cb_open returning busy\n", info->netname);
1703 spin_unlock_irqrestore(&info->netlock, flags);
1707 spin_unlock_irqrestore(&info->netlock, flags);
1709 /* claim resources and init adapter */
1710 if ((err = startup(info)) != 0)
1713 /* allow syncppp module to do open processing */
1714 if ((err = sppp_open(d)) != 0) {
1719 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
1722 d->trans_start = jiffies;
1723 netif_start_queue(d);
1727 spin_lock_irqsave(&info->netlock, flags);
1729 spin_unlock_irqrestore(&info->netlock, flags);
1733 static void sppp_cb_tx_timeout(struct net_device *dev)
1735 SLMP_INFO *info = dev->priv;
1736 unsigned long flags;
1738 if (debug_level >= DEBUG_LEVEL_INFO)
1739 printk("sppp_tx_timeout(%s)\n",info->netname);
1741 info->netstats.tx_errors++;
1742 info->netstats.tx_aborted_errors++;
1744 spin_lock_irqsave(&info->lock,flags);
1746 spin_unlock_irqrestore(&info->lock,flags);
1748 netif_wake_queue(dev);
1751 static int sppp_cb_tx(struct sk_buff *skb, struct net_device *dev)
1753 SLMP_INFO *info = dev->priv;
1754 unsigned long flags;
1756 if (debug_level >= DEBUG_LEVEL_INFO)
1757 printk("sppp_tx(%s)\n",info->netname);
1759 netif_stop_queue(dev);
1761 info->tx_count = skb->len;
1762 tx_load_dma_buffer(info, skb->data, skb->len);
1763 info->netstats.tx_packets++;
1764 info->netstats.tx_bytes += skb->len;
1767 dev->trans_start = jiffies;
1769 spin_lock_irqsave(&info->lock,flags);
1770 if (!info->tx_active)
1772 spin_unlock_irqrestore(&info->lock,flags);
1777 static int sppp_cb_close(struct net_device *d)
1779 SLMP_INFO *info = d->priv;
1780 unsigned long flags;
1782 if (debug_level >= DEBUG_LEVEL_INFO)
1783 printk("sppp_cb_close(%s)\n",info->netname);
1785 /* shutdown adapter and release resources */
1788 /* allow syncppp to do close processing */
1790 netif_stop_queue(d);
1792 spin_lock_irqsave(&info->netlock, flags);
1794 spin_unlock_irqrestore(&info->netlock, flags);
1798 static void sppp_rx_done(SLMP_INFO *info, char *buf, int size)
1800 struct sk_buff *skb = dev_alloc_skb(size);
1801 if (debug_level >= DEBUG_LEVEL_INFO)
1802 printk("sppp_rx_done(%s)\n",info->netname);
1804 printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n",
1806 info->netstats.rx_dropped++;
1810 memcpy(skb_put(skb, size),buf,size);
1812 skb->protocol = htons(ETH_P_WAN_PPP);
1813 skb->dev = info->netdev;
1814 skb->mac.raw = skb->data;
1815 info->netstats.rx_packets++;
1816 info->netstats.rx_bytes += size;
1818 info->netdev->trans_start = jiffies;
1821 static void sppp_tx_done(SLMP_INFO *info)
1823 if (netif_queue_stopped(info->netdev))
1824 netif_wake_queue(info->netdev);
1827 static struct net_device_stats *sppp_cb_net_stats(struct net_device *dev)
1829 SLMP_INFO *info = dev->priv;
1830 if (debug_level >= DEBUG_LEVEL_INFO)
1831 printk("net_stats(%s)\n",info->netname);
1832 return &info->netstats;
1835 static int sppp_cb_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1837 SLMP_INFO *info = dev->priv;
1838 if (debug_level >= DEBUG_LEVEL_INFO)
1839 printk("%s(%d):ioctl %s cmd=%08X\n", __FILE__,__LINE__,
1840 info->netname, cmd );
1841 return sppp_do_ioctl(dev, ifr, cmd);
1844 #endif /* ifdef CONFIG_SYNCLINK_SYNCPPP */
1847 /* Return next bottom half action to perform.
1848 * Return Value: BH action code or 0 if nothing to do.
1850 int bh_action(SLMP_INFO *info)
1852 unsigned long flags;
1855 spin_lock_irqsave(&info->lock,flags);
1857 if (info->pending_bh & BH_RECEIVE) {
1858 info->pending_bh &= ~BH_RECEIVE;
1860 } else if (info->pending_bh & BH_TRANSMIT) {
1861 info->pending_bh &= ~BH_TRANSMIT;
1863 } else if (info->pending_bh & BH_STATUS) {
1864 info->pending_bh &= ~BH_STATUS;
1869 /* Mark BH routine as complete */
1870 info->bh_running = 0;
1871 info->bh_requested = 0;
1874 spin_unlock_irqrestore(&info->lock,flags);
1879 /* Perform bottom half processing of work items queued by ISR.
1881 void bh_handler(void* Context)
1883 SLMP_INFO *info = (SLMP_INFO*)Context;
1889 if ( debug_level >= DEBUG_LEVEL_BH )
1890 printk( "%s(%d):%s bh_handler() entry\n",
1891 __FILE__,__LINE__,info->device_name);
1893 info->bh_running = 1;
1895 while((action = bh_action(info)) != 0) {
1897 /* Process work item */
1898 if ( debug_level >= DEBUG_LEVEL_BH )
1899 printk( "%s(%d):%s bh_handler() work item action=%d\n",
1900 __FILE__,__LINE__,info->device_name, action);
1914 /* unknown work item ID */
1915 printk("%s(%d):%s Unknown work item ID=%08X!\n",
1916 __FILE__,__LINE__,info->device_name,action);
1921 if ( debug_level >= DEBUG_LEVEL_BH )
1922 printk( "%s(%d):%s bh_handler() exit\n",
1923 __FILE__,__LINE__,info->device_name);
1926 void bh_receive(SLMP_INFO *info)
1928 if ( debug_level >= DEBUG_LEVEL_BH )
1929 printk( "%s(%d):%s bh_receive()\n",
1930 __FILE__,__LINE__,info->device_name);
1932 while( rx_get_frame(info) );
1935 void bh_transmit(SLMP_INFO *info)
1937 struct tty_struct *tty = info->tty;
1939 if ( debug_level >= DEBUG_LEVEL_BH )
1940 printk( "%s(%d):%s bh_transmit() entry\n",
1941 __FILE__,__LINE__,info->device_name);
1944 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1945 tty->ldisc.write_wakeup) {
1946 if ( debug_level >= DEBUG_LEVEL_BH )
1947 printk( "%s(%d):%s calling ldisc.write_wakeup\n",
1948 __FILE__,__LINE__,info->device_name);
1949 (tty->ldisc.write_wakeup)(tty);
1951 wake_up_interruptible(&tty->write_wait);
1955 void bh_status(SLMP_INFO *info)
1957 if ( debug_level >= DEBUG_LEVEL_BH )
1958 printk( "%s(%d):%s bh_status() entry\n",
1959 __FILE__,__LINE__,info->device_name);
1961 info->ri_chkcount = 0;
1962 info->dsr_chkcount = 0;
1963 info->dcd_chkcount = 0;
1964 info->cts_chkcount = 0;
1967 void isr_timer(SLMP_INFO * info)
1969 unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
1971 /* IER2<7..4> = timer<3..0> interrupt enables (0=disabled) */
1972 write_reg(info, IER2, 0);
1974 /* TMCS, Timer Control/Status Register
1976 * 07 CMF, Compare match flag (read only) 1=match
1977 * 06 ECMI, CMF Interrupt Enable: 0=disabled
1978 * 05 Reserved, must be 0
1979 * 04 TME, Timer Enable
1980 * 03..00 Reserved, must be 0
1984 write_reg(info, (unsigned char)(timer + TMCS), 0);
1986 info->irq_occurred = TRUE;
1988 if ( debug_level >= DEBUG_LEVEL_ISR )
1989 printk("%s(%d):%s isr_timer()\n",
1990 __FILE__,__LINE__,info->device_name);
1993 void isr_rxint(SLMP_INFO * info)
1995 struct tty_struct *tty = info->tty;
1996 struct mgsl_icount *icount = &info->icount;
1997 unsigned char status = read_reg(info, SR1);
1998 unsigned char status2 = read_reg(info, SR2);
2000 /* clear status bits */
2001 if ( status & (FLGD + IDLD + CDCD + BRKD) )
2002 write_reg(info, SR1,
2003 (unsigned char)(status & (FLGD + IDLD + CDCD + BRKD)));
2005 if ( status2 & OVRN )
2006 write_reg(info, SR2, (unsigned char)(status2 & OVRN));
2008 if ( debug_level >= DEBUG_LEVEL_ISR )
2009 printk("%s(%d):%s isr_rxint status=%02X %02x\n",
2010 __FILE__,__LINE__,info->device_name,status,status2);
2012 if (info->params.mode == MGSL_MODE_ASYNC) {
2013 if (status & BRKD) {
2016 /* process break detection if tty control
2017 * is not set to ignore it
2020 if (!(status & info->ignore_status_mask1)) {
2021 if (info->read_status_mask1 & BRKD) {
2022 *tty->flip.flag_buf_ptr = TTY_BREAK;
2023 if (info->flags & ASYNC_SAK)
2031 if (status & (FLGD|IDLD)) {
2033 info->icount.exithunt++;
2034 else if (status & IDLD)
2035 info->icount.rxidle++;
2036 wake_up_interruptible(&info->event_wait_q);
2040 if (status & CDCD) {
2041 /* simulate a common modem status change interrupt
2044 get_signals( info );
2046 MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD));
2051 * handle async rx data interrupts
2053 void isr_rxrdy(SLMP_INFO * info)
2056 unsigned char DataByte;
2057 struct tty_struct *tty = info->tty;
2058 struct mgsl_icount *icount = &info->icount;
2060 if ( debug_level >= DEBUG_LEVEL_ISR )
2061 printk("%s(%d):%s isr_rxrdy\n",
2062 __FILE__,__LINE__,info->device_name);
2064 while((status = read_reg(info,CST0)) & BIT0)
2066 DataByte = read_reg(info,TRB);
2069 if (tty->flip.count >= TTY_FLIPBUF_SIZE)
2072 *tty->flip.char_buf_ptr = DataByte;
2073 *tty->flip.flag_buf_ptr = 0;
2078 if ( status & (PE + FRME + OVRN) ) {
2079 printk("%s(%d):%s rxerr=%04X\n",
2080 __FILE__,__LINE__,info->device_name,status);
2082 /* update error statistics */
2085 else if (status & FRME)
2087 else if (status & OVRN)
2090 /* discard char if tty control flags say so */
2091 if (status & info->ignore_status_mask2)
2094 status &= info->read_status_mask2;
2098 *tty->flip.flag_buf_ptr = TTY_PARITY;
2099 else if (status & FRME)
2100 *tty->flip.flag_buf_ptr = TTY_FRAME;
2101 if (status & OVRN) {
2102 /* Overrun is special, since it's
2103 * reported immediately, and doesn't
2104 * affect the current character
2106 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
2108 tty->flip.flag_buf_ptr++;
2109 tty->flip.char_buf_ptr++;
2110 *tty->flip.flag_buf_ptr = TTY_OVERRUN;
2114 } /* end of if (error) */
2117 tty->flip.flag_buf_ptr++;
2118 tty->flip.char_buf_ptr++;
2123 if ( debug_level >= DEBUG_LEVEL_ISR ) {
2124 printk("%s(%d):%s isr_rxrdy() flip count=%d\n",
2125 __FILE__,__LINE__,info->device_name,
2126 tty ? tty->flip.count : 0);
2127 printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
2128 __FILE__,__LINE__,info->device_name,
2129 icount->rx,icount->brk,icount->parity,
2130 icount->frame,icount->overrun);
2133 if ( tty && tty->flip.count )
2134 tty_flip_buffer_push(tty);
2137 void isr_txeom(SLMP_INFO * info, unsigned char status)
2139 if ( debug_level >= DEBUG_LEVEL_ISR )
2140 printk("%s(%d):%s isr_txeom status=%02x\n",
2141 __FILE__,__LINE__,info->device_name,status);
2143 /* disable and clear MSCI interrupts */
2144 info->ie1_value &= ~(IDLE + UDRN);
2145 write_reg(info, IE1, info->ie1_value);
2146 write_reg(info, SR1, (unsigned char)(UDRN + IDLE));
2148 write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
2149 write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
2150 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
2152 if ( info->tx_active ) {
2153 if (info->params.mode != MGSL_MODE_ASYNC) {
2155 info->icount.txunder++;
2156 else if (status & IDLE)
2157 info->icount.txok++;
2160 info->tx_active = 0;
2161 info->tx_count = info->tx_put = info->tx_get = 0;
2163 del_timer(&info->tx_timer);
2165 if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done ) {
2166 info->serial_signals &= ~SerialSignal_RTS;
2167 info->drop_rts_on_tx_done = 0;
2171 #ifdef CONFIG_SYNCLINK_SYNCPPP
2177 if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
2181 info->pending_bh |= BH_TRANSMIT;
2188 * handle tx status interrupts
2190 void isr_txint(SLMP_INFO * info)
2192 unsigned char status = read_reg(info, SR1);
2194 /* clear status bits */
2195 write_reg(info, SR1, (unsigned char)(status & (UDRN + IDLE + CCTS)));
2197 if ( debug_level >= DEBUG_LEVEL_ISR )
2198 printk("%s(%d):%s isr_txint status=%02x\n",
2199 __FILE__,__LINE__,info->device_name,status);
2201 if (status & (UDRN + IDLE))
2202 isr_txeom(info, status);
2204 if (status & CCTS) {
2205 /* simulate a common modem status change interrupt
2208 get_signals( info );
2210 MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS));
2216 * handle async tx data interrupts
2218 void isr_txrdy(SLMP_INFO * info)
2220 if ( debug_level >= DEBUG_LEVEL_ISR )
2221 printk("%s(%d):%s isr_txrdy() tx_count=%d\n",
2222 __FILE__,__LINE__,info->device_name,info->tx_count);
2224 if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
2229 if ( info->tx_count )
2230 tx_load_fifo( info );
2232 info->tx_active = 0;
2233 info->ie0_value &= ~TXRDYE;
2234 write_reg(info, IE0, info->ie0_value);
2237 if (info->tx_count < WAKEUP_CHARS)
2238 info->pending_bh |= BH_TRANSMIT;
2241 void isr_rxdmaok(SLMP_INFO * info)
2243 /* BIT7 = EOT (end of transfer)
2244 * BIT6 = EOM (end of message/frame)
2246 unsigned char status = read_reg(info,RXDMA + DSR) & 0xc0;
2248 /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
2249 write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
2251 if ( debug_level >= DEBUG_LEVEL_ISR )
2252 printk("%s(%d):%s isr_rxdmaok(), status=%02x\n",
2253 __FILE__,__LINE__,info->device_name,status);
2255 info->pending_bh |= BH_RECEIVE;
2258 void isr_rxdmaerror(SLMP_INFO * info)
2260 /* BIT5 = BOF (buffer overflow)
2261 * BIT4 = COF (counter overflow)
2263 unsigned char status = read_reg(info,RXDMA + DSR) & 0x30;
2265 /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
2266 write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
2268 if ( debug_level >= DEBUG_LEVEL_ISR )
2269 printk("%s(%d):%s isr_rxdmaerror(), status=%02x\n",
2270 __FILE__,__LINE__,info->device_name,status);
2272 info->rx_overflow = TRUE;
2273 info->pending_bh |= BH_RECEIVE;
2276 void isr_txdmaok(SLMP_INFO * info)
2278 /* BIT7 = EOT (end of transfer, used for async mode)
2279 * BIT6 = EOM (end of message/frame, used for sync mode)
2281 * We don't look at DMA status because only EOT is enabled
2282 * and we always clear and disable all tx DMA IRQs.
2284 // unsigned char dma_status = read_reg(info,TXDMA + DSR) & 0xc0;
2285 unsigned char status_reg1 = read_reg(info, SR1);
2287 write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
2288 write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
2289 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
2291 if ( debug_level >= DEBUG_LEVEL_ISR )
2292 printk("%s(%d):%s isr_txdmaok(), status=%02x\n",
2293 __FILE__,__LINE__,info->device_name,status_reg1);
2295 /* If transmitter already idle, do end of frame processing,
2296 * otherwise enable interrupt for tx IDLE.
2298 if (status_reg1 & IDLE)
2299 isr_txeom(info, IDLE);
2301 /* disable and clear underrun IRQ, enable IDLE interrupt */
2302 info->ie1_value |= IDLE;
2303 info->ie1_value &= ~UDRN;
2304 write_reg(info, IE1, info->ie1_value);
2306 write_reg(info, SR1, UDRN);
2310 void isr_txdmaerror(SLMP_INFO * info)
2312 /* BIT5 = BOF (buffer overflow)
2313 * BIT4 = COF (counter overflow)
2315 unsigned char status = read_reg(info,TXDMA + DSR) & 0x30;
2317 /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
2318 write_reg(info, TXDMA + DSR, (unsigned char)(status | 1));
2320 if ( debug_level >= DEBUG_LEVEL_ISR )
2321 printk("%s(%d):%s isr_txdmaerror(), status=%02x\n",
2322 __FILE__,__LINE__,info->device_name,status);
2325 /* handle input serial signal changes
2327 void isr_io_pin( SLMP_INFO *info, u16 status )
2329 struct mgsl_icount *icount;
2331 if ( debug_level >= DEBUG_LEVEL_ISR )
2332 printk("%s(%d):isr_io_pin status=%04X\n",
2333 __FILE__,__LINE__,status);
2335 if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
2336 MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
2337 icount = &info->icount;
2338 /* update input line counters */
2339 if (status & MISCSTATUS_RI_LATCHED) {
2341 if ( status & SerialSignal_RI )
2342 info->input_signal_events.ri_up++;
2344 info->input_signal_events.ri_down++;
2346 if (status & MISCSTATUS_DSR_LATCHED) {
2348 if ( status & SerialSignal_DSR )
2349 info->input_signal_events.dsr_up++;
2351 info->input_signal_events.dsr_down++;
2353 if (status & MISCSTATUS_DCD_LATCHED) {
2354 if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
2355 info->ie1_value &= ~CDCD;
2356 write_reg(info, IE1, info->ie1_value);
2359 if (status & SerialSignal_DCD) {
2360 info->input_signal_events.dcd_up++;
2361 #ifdef CONFIG_SYNCLINK_SYNCPPP
2363 sppp_reopen(info->netdev);
2366 info->input_signal_events.dcd_down++;
2368 if (status & MISCSTATUS_CTS_LATCHED)
2370 if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
2371 info->ie1_value &= ~CCTS;
2372 write_reg(info, IE1, info->ie1_value);
2375 if ( status & SerialSignal_CTS )
2376 info->input_signal_events.cts_up++;
2378 info->input_signal_events.cts_down++;
2380 wake_up_interruptible(&info->status_event_wait_q);
2381 wake_up_interruptible(&info->event_wait_q);
2383 if ( (info->flags & ASYNC_CHECK_CD) &&
2384 (status & MISCSTATUS_DCD_LATCHED) ) {
2385 if ( debug_level >= DEBUG_LEVEL_ISR )
2386 printk("%s CD now %s...", info->device_name,
2387 (status & SerialSignal_DCD) ? "on" : "off");
2388 if (status & SerialSignal_DCD)
2389 wake_up_interruptible(&info->open_wait);
2391 if ( debug_level >= DEBUG_LEVEL_ISR )
2392 printk("doing serial hangup...");
2394 tty_hangup(info->tty);
2398 if ( (info->flags & ASYNC_CTS_FLOW) &&
2399 (status & MISCSTATUS_CTS_LATCHED) ) {
2401 if (info->tty->hw_stopped) {
2402 if (status & SerialSignal_CTS) {
2403 if ( debug_level >= DEBUG_LEVEL_ISR )
2404 printk("CTS tx start...");
2405 info->tty->hw_stopped = 0;
2407 info->pending_bh |= BH_TRANSMIT;
2411 if (!(status & SerialSignal_CTS)) {
2412 if ( debug_level >= DEBUG_LEVEL_ISR )
2413 printk("CTS tx stop...");
2414 info->tty->hw_stopped = 1;
2422 info->pending_bh |= BH_STATUS;
2425 /* Interrupt service routine entry point.
2428 * irq interrupt number that caused interrupt
2429 * dev_id device ID supplied during interrupt registration
2430 * regs interrupted processor context
2432 static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
2433 struct pt_regs *regs)
2436 unsigned char status, status0, status1=0;
2437 unsigned char dmastatus, dmastatus0, dmastatus1=0;
2438 unsigned char timerstatus0, timerstatus1=0;
2439 unsigned char shift;
2443 if ( debug_level >= DEBUG_LEVEL_ISR )
2444 printk("%s(%d): synclinkmp_interrupt(%d)entry.\n",
2445 __FILE__,__LINE__,irq);
2447 info = (SLMP_INFO *)dev_id;
2451 spin_lock(&info->lock);
2455 /* get status for SCA0 (ports 0-1) */
2456 tmp = read_reg16(info, ISR0); /* get ISR0 and ISR1 in one read */
2457 status0 = (unsigned char)tmp;
2458 dmastatus0 = (unsigned char)(tmp>>8);
2459 timerstatus0 = read_reg(info, ISR2);
2461 if ( debug_level >= DEBUG_LEVEL_ISR )
2462 printk("%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
2463 __FILE__,__LINE__,info->device_name,
2464 status0,dmastatus0,timerstatus0);
2466 if (info->port_count == 4) {
2467 /* get status for SCA1 (ports 2-3) */
2468 tmp = read_reg16(info->port_array[2], ISR0);
2469 status1 = (unsigned char)tmp;
2470 dmastatus1 = (unsigned char)(tmp>>8);
2471 timerstatus1 = read_reg(info->port_array[2], ISR2);
2473 if ( debug_level >= DEBUG_LEVEL_ISR )
2474 printk("%s(%d):%s status1=%02x, dmastatus1=%02x, timerstatus1=%02x\n",
2475 __FILE__,__LINE__,info->device_name,
2476 status1,dmastatus1,timerstatus1);
2479 if (!status0 && !dmastatus0 && !timerstatus0 &&
2480 !status1 && !dmastatus1 && !timerstatus1)
2483 for(i=0; i < info->port_count ; i++) {
2484 if (info->port_array[i] == NULL)
2488 dmastatus = dmastatus0;
2491 dmastatus = dmastatus1;
2494 shift = i & 1 ? 4 :0;
2496 if (status & BIT0 << shift)
2497 isr_rxrdy(info->port_array[i]);
2498 if (status & BIT1 << shift)
2499 isr_txrdy(info->port_array[i]);
2500 if (status & BIT2 << shift)
2501 isr_rxint(info->port_array[i]);
2502 if (status & BIT3 << shift)
2503 isr_txint(info->port_array[i]);
2505 if (dmastatus & BIT0 << shift)
2506 isr_rxdmaerror(info->port_array[i]);
2507 if (dmastatus & BIT1 << shift)
2508 isr_rxdmaok(info->port_array[i]);
2509 if (dmastatus & BIT2 << shift)
2510 isr_txdmaerror(info->port_array[i]);
2511 if (dmastatus & BIT3 << shift)
2512 isr_txdmaok(info->port_array[i]);
2515 if (timerstatus0 & (BIT5 | BIT4))
2516 isr_timer(info->port_array[0]);
2517 if (timerstatus0 & (BIT7 | BIT6))
2518 isr_timer(info->port_array[1]);
2519 if (timerstatus1 & (BIT5 | BIT4))
2520 isr_timer(info->port_array[2]);
2521 if (timerstatus1 & (BIT7 | BIT6))
2522 isr_timer(info->port_array[3]);
2525 for(i=0; i < info->port_count ; i++) {
2526 SLMP_INFO * port = info->port_array[i];
2528 /* Request bottom half processing if there's something
2529 * for it to do and the bh is not already running.
2531 * Note: startup adapter diags require interrupts.
2532 * do not request bottom half processing if the
2533 * device is not open in a normal mode.
2535 if ( port && (port->count || port->netcount) &&
2536 port->pending_bh && !port->bh_running &&
2537 !port->bh_requested ) {
2538 if ( debug_level >= DEBUG_LEVEL_ISR )
2539 printk("%s(%d):%s queueing bh task.\n",
2540 __FILE__,__LINE__,port->device_name);
2541 schedule_work(&port->task);
2542 port->bh_requested = 1;
2546 spin_unlock(&info->lock);
2548 if ( debug_level >= DEBUG_LEVEL_ISR )
2549 printk("%s(%d):synclinkmp_interrupt(%d)exit.\n",
2550 __FILE__,__LINE__,irq);
2554 /* Initialize and start device.
2556 static int startup(SLMP_INFO * info)
2558 if ( debug_level >= DEBUG_LEVEL_INFO )
2559 printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name);
2561 if (info->flags & ASYNC_INITIALIZED)
2564 if (!info->tx_buf) {
2565 info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL);
2566 if (!info->tx_buf) {
2567 printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
2568 __FILE__,__LINE__,info->device_name);
2573 info->pending_bh = 0;
2575 /* program hardware for current parameters */
2578 change_params(info);
2580 info->status_timer.expires = jiffies + jiffies_from_ms(10);
2581 add_timer(&info->status_timer);
2584 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2586 info->flags |= ASYNC_INITIALIZED;
2591 /* Called by close() and hangup() to shutdown hardware
2593 static void shutdown(SLMP_INFO * info)
2595 unsigned long flags;
2597 if (!(info->flags & ASYNC_INITIALIZED))
2600 if (debug_level >= DEBUG_LEVEL_INFO)
2601 printk("%s(%d):%s synclinkmp_shutdown()\n",
2602 __FILE__,__LINE__, info->device_name );
2604 /* clear status wait queue because status changes */
2605 /* can't happen after shutting down the hardware */
2606 wake_up_interruptible(&info->status_event_wait_q);
2607 wake_up_interruptible(&info->event_wait_q);
2609 del_timer(&info->tx_timer);
2610 del_timer(&info->status_timer);
2613 kfree(info->tx_buf);
2614 info->tx_buf = NULL;
2617 spin_lock_irqsave(&info->lock,flags);
2621 if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
2622 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
2626 spin_unlock_irqrestore(&info->lock,flags);
2629 set_bit(TTY_IO_ERROR, &info->tty->flags);
2631 info->flags &= ~ASYNC_INITIALIZED;
2634 static void program_hw(SLMP_INFO *info)
2636 unsigned long flags;
2638 spin_lock_irqsave(&info->lock,flags);
2643 info->tx_count = info->tx_put = info->tx_get = 0;
2645 if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
2652 info->dcd_chkcount = 0;
2653 info->cts_chkcount = 0;
2654 info->ri_chkcount = 0;
2655 info->dsr_chkcount = 0;
2657 info->ie1_value |= (CDCD|CCTS);
2658 write_reg(info, IE1, info->ie1_value);
2662 if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
2665 spin_unlock_irqrestore(&info->lock,flags);
2668 /* Reconfigure adapter based on new parameters
2670 static void change_params(SLMP_INFO *info)
2675 if (!info->tty || !info->tty->termios)
2678 if (debug_level >= DEBUG_LEVEL_INFO)
2679 printk("%s(%d):%s change_params()\n",
2680 __FILE__,__LINE__, info->device_name );
2682 cflag = info->tty->termios->c_cflag;
2684 /* if B0 rate (hangup) specified then negate DTR and RTS */
2685 /* otherwise assert DTR and RTS */
2687 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
2689 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
2691 /* byte size and parity */
2693 switch (cflag & CSIZE) {
2694 case CS5: info->params.data_bits = 5; break;
2695 case CS6: info->params.data_bits = 6; break;
2696 case CS7: info->params.data_bits = 7; break;
2697 case CS8: info->params.data_bits = 8; break;
2698 /* Never happens, but GCC is too dumb to figure it out */
2699 default: info->params.data_bits = 7; break;
2703 info->params.stop_bits = 2;
2705 info->params.stop_bits = 1;
2707 info->params.parity = ASYNC_PARITY_NONE;
2708 if (cflag & PARENB) {
2710 info->params.parity = ASYNC_PARITY_ODD;
2712 info->params.parity = ASYNC_PARITY_EVEN;
2715 info->params.parity = ASYNC_PARITY_SPACE;
2719 /* calculate number of jiffies to transmit a full
2720 * FIFO (32 bytes) at specified data rate
2722 bits_per_char = info->params.data_bits +
2723 info->params.stop_bits + 1;
2725 /* if port data rate is set to 460800 or less then
2726 * allow tty settings to override, otherwise keep the
2727 * current data rate.
2729 if (info->params.data_rate <= 460800) {
2730 info->params.data_rate = tty_get_baud_rate(info->tty);
2733 if ( info->params.data_rate ) {
2734 info->timeout = (32*HZ*bits_per_char) /
2735 info->params.data_rate;
2737 info->timeout += HZ/50; /* Add .02 seconds of slop */
2739 if (cflag & CRTSCTS)
2740 info->flags |= ASYNC_CTS_FLOW;
2742 info->flags &= ~ASYNC_CTS_FLOW;
2745 info->flags &= ~ASYNC_CHECK_CD;
2747 info->flags |= ASYNC_CHECK_CD;
2749 /* process tty input control flags */
2751 info->read_status_mask2 = OVRN;
2752 if (I_INPCK(info->tty))
2753 info->read_status_mask2 |= PE | FRME;
2754 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2755 info->read_status_mask1 |= BRKD;
2756 if (I_IGNPAR(info->tty))
2757 info->ignore_status_mask2 |= PE | FRME;
2758 if (I_IGNBRK(info->tty)) {
2759 info->ignore_status_mask1 |= BRKD;
2760 /* If ignoring parity and break indicators, ignore
2761 * overruns too. (For real raw support).
2763 if (I_IGNPAR(info->tty))
2764 info->ignore_status_mask2 |= OVRN;
2770 static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
2774 if (debug_level >= DEBUG_LEVEL_INFO)
2775 printk("%s(%d):%s get_params()\n",
2776 __FILE__,__LINE__, info->device_name);
2778 COPY_TO_USER(err,user_icount, &info->icount, sizeof(struct mgsl_icount));
2780 if ( debug_level >= DEBUG_LEVEL_INFO )
2781 printk( "%s(%d):%s get_stats() user buffer copy failed\n",
2782 __FILE__,__LINE__,info->device_name);
2789 static int get_params(SLMP_INFO * info, MGSL_PARAMS __user *user_params)
2792 if (debug_level >= DEBUG_LEVEL_INFO)
2793 printk("%s(%d):%s get_params()\n",
2794 __FILE__,__LINE__, info->device_name);
2796 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
2798 if ( debug_level >= DEBUG_LEVEL_INFO )
2799 printk( "%s(%d):%s get_params() user buffer copy failed\n",
2800 __FILE__,__LINE__,info->device_name);
2807 static int set_params(SLMP_INFO * info, MGSL_PARAMS __user *new_params)
2809 unsigned long flags;
2810 MGSL_PARAMS tmp_params;
2813 if (debug_level >= DEBUG_LEVEL_INFO)
2814 printk("%s(%d):%s set_params\n",
2815 __FILE__,__LINE__,info->device_name );
2816 COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
2818 if ( debug_level >= DEBUG_LEVEL_INFO )
2819 printk( "%s(%d):%s set_params() user buffer copy failed\n",
2820 __FILE__,__LINE__,info->device_name);
2824 spin_lock_irqsave(&info->lock,flags);
2825 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
2826 spin_unlock_irqrestore(&info->lock,flags);
2828 change_params(info);
2833 static int get_txidle(SLMP_INFO * info, int __user *idle_mode)
2837 if (debug_level >= DEBUG_LEVEL_INFO)
2838 printk("%s(%d):%s get_txidle()=%d\n",
2839 __FILE__,__LINE__, info->device_name, info->idle_mode);
2841 COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
2843 if ( debug_level >= DEBUG_LEVEL_INFO )
2844 printk( "%s(%d):%s get_txidle() user buffer copy failed\n",
2845 __FILE__,__LINE__,info->device_name);
2852 static int set_txidle(SLMP_INFO * info, int idle_mode)
2854 unsigned long flags;
2856 if (debug_level >= DEBUG_LEVEL_INFO)
2857 printk("%s(%d):%s set_txidle(%d)\n",
2858 __FILE__,__LINE__,info->device_name, idle_mode );
2860 spin_lock_irqsave(&info->lock,flags);
2861 info->idle_mode = idle_mode;
2862 tx_set_idle( info );
2863 spin_unlock_irqrestore(&info->lock,flags);
2867 static int tx_enable(SLMP_INFO * info, int enable)
2869 unsigned long flags;
2871 if (debug_level >= DEBUG_LEVEL_INFO)
2872 printk("%s(%d):%s tx_enable(%d)\n",
2873 __FILE__,__LINE__,info->device_name, enable);
2875 spin_lock_irqsave(&info->lock,flags);
2877 if ( !info->tx_enabled ) {
2881 if ( info->tx_enabled )
2884 spin_unlock_irqrestore(&info->lock,flags);
2888 /* abort send HDLC frame
2890 static int tx_abort(SLMP_INFO * info)
2892 unsigned long flags;
2894 if (debug_level >= DEBUG_LEVEL_INFO)
2895 printk("%s(%d):%s tx_abort()\n",
2896 __FILE__,__LINE__,info->device_name);
2898 spin_lock_irqsave(&info->lock,flags);
2899 if ( info->tx_active && info->params.mode == MGSL_MODE_HDLC ) {
2900 info->ie1_value &= ~UDRN;
2901 info->ie1_value |= IDLE;
2902 write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
2903 write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
2905 write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
2906 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
2908 write_reg(info, CMD, TXABORT);
2910 spin_unlock_irqrestore(&info->lock,flags);
2914 static int rx_enable(SLMP_INFO * info, int enable)
2916 unsigned long flags;
2918 if (debug_level >= DEBUG_LEVEL_INFO)
2919 printk("%s(%d):%s rx_enable(%d)\n",
2920 __FILE__,__LINE__,info->device_name,enable);
2922 spin_lock_irqsave(&info->lock,flags);
2924 if ( !info->rx_enabled )
2927 if ( info->rx_enabled )
2930 spin_unlock_irqrestore(&info->lock,flags);
2934 static int map_status(int signals)
2936 /* Map status bits to API event bits */
2938 return ((signals & SerialSignal_DSR) ? MgslEvent_DsrActive : MgslEvent_DsrInactive) +
2939 ((signals & SerialSignal_CTS) ? MgslEvent_CtsActive : MgslEvent_CtsInactive) +
2940 ((signals & SerialSignal_DCD) ? MgslEvent_DcdActive : MgslEvent_DcdInactive) +
2941 ((signals & SerialSignal_RI) ? MgslEvent_RiActive : MgslEvent_RiInactive);
2944 /* wait for specified event to occur
2946 static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
2948 unsigned long flags;
2951 struct mgsl_icount cprev, cnow;
2954 struct _input_signal_events oldsigs, newsigs;
2955 DECLARE_WAITQUEUE(wait, current);
2957 COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
2962 if (debug_level >= DEBUG_LEVEL_INFO)
2963 printk("%s(%d):%s wait_mgsl_event(%d)\n",
2964 __FILE__,__LINE__,info->device_name,mask);
2966 spin_lock_irqsave(&info->lock,flags);
2968 /* return immediately if state matches requested events */
2970 s = map_status(info->serial_signals);
2973 ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
2974 ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
2975 ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
2976 ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
2978 spin_unlock_irqrestore(&info->lock,flags);
2982 /* save current irq counts */
2983 cprev = info->icount;
2984 oldsigs = info->input_signal_events;
2986 /* enable hunt and idle irqs if needed */
2987 if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
2988 unsigned char oldval = info->ie1_value;
2989 unsigned char newval = oldval +
2990 (mask & MgslEvent_ExitHuntMode ? FLGD:0) +
2991 (mask & MgslEvent_IdleReceived ? IDLE:0);
2992 if ( oldval != newval ) {
2993 info->ie1_value = newval;
2994 write_reg(info, IE1, info->ie1_value);
2998 set_current_state(TASK_INTERRUPTIBLE);
2999 add_wait_queue(&info->event_wait_q, &wait);
3001 spin_unlock_irqrestore(&info->lock,flags);
3005 if (signal_pending(current)) {
3010 /* get current irq counts */
3011 spin_lock_irqsave(&info->lock,flags);
3012 cnow = info->icount;
3013 newsigs = info->input_signal_events;
3014 set_current_state(TASK_INTERRUPTIBLE);
3015 spin_unlock_irqrestore(&info->lock,flags);
3017 /* if no change, wait aborted for some reason */
3018 if (newsigs.dsr_up == oldsigs.dsr_up &&
3019 newsigs.dsr_down == oldsigs.dsr_down &&
3020 newsigs.dcd_up == oldsigs.dcd_up &&
3021 newsigs.dcd_down == oldsigs.dcd_down &&
3022 newsigs.cts_up == oldsigs.cts_up &&
3023 newsigs.cts_down == oldsigs.cts_down &&
3024 newsigs.ri_up == oldsigs.ri_up &&
3025 newsigs.ri_down == oldsigs.ri_down &&
3026 cnow.exithunt == cprev.exithunt &&
3027 cnow.rxidle == cprev.rxidle) {
3033 ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
3034 (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
3035 (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
3036 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
3037 (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
3038 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
3039 (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
3040 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
3041 (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
3042 (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
3050 remove_wait_queue(&info->event_wait_q, &wait);
3051 set_current_state(TASK_RUNNING);
3054 if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
3055 spin_lock_irqsave(&info->lock,flags);
3056 if (!waitqueue_active(&info->event_wait_q)) {
3057 /* disable enable exit hunt mode/idle rcvd IRQs */
3058 info->ie1_value &= ~(FLGD|IDLE);
3059 write_reg(info, IE1, info->ie1_value);
3061 spin_unlock_irqrestore(&info->lock,flags);
3065 PUT_USER(rc, events, mask_ptr);
3070 static int modem_input_wait(SLMP_INFO *info,int arg)
3072 unsigned long flags;
3074 struct mgsl_icount cprev, cnow;
3075 DECLARE_WAITQUEUE(wait, current);
3077 /* save current irq counts */
3078 spin_lock_irqsave(&info->lock,flags);
3079 cprev = info->icount;
3080 add_wait_queue(&info->status_event_wait_q, &wait);
3081 set_current_state(TASK_INTERRUPTIBLE);
3082 spin_unlock_irqrestore(&info->lock,flags);
3086 if (signal_pending(current)) {
3091 /* get new irq counts */
3092 spin_lock_irqsave(&info->lock,flags);
3093 cnow = info->icount;
3094 set_current_state(TASK_INTERRUPTIBLE);
3095 spin_unlock_irqrestore(&info->lock,flags);
3097 /* if no change, wait aborted for some reason */
3098 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
3099 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
3104 /* check for change in caller specified modem input */
3105 if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
3106 (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
3107 (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
3108 (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
3115 remove_wait_queue(&info->status_event_wait_q, &wait);
3116 set_current_state(TASK_RUNNING);
3120 /* return the state of the serial control and status signals
3122 static int tiocmget(struct tty_struct *tty, struct file *file)
3124 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
3125 unsigned int result;
3126 unsigned long flags;
3128 spin_lock_irqsave(&info->lock,flags);
3130 spin_unlock_irqrestore(&info->lock,flags);
3132 result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
3133 ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
3134 ((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
3135 ((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
3136 ((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
3137 ((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
3139 if (debug_level >= DEBUG_LEVEL_INFO)
3140 printk("%s(%d):%s tiocmget() value=%08X\n",
3141 __FILE__,__LINE__, info->device_name, result );
3145 /* set modem control signals (DTR/RTS)
3147 static int tiocmset(struct tty_struct *tty, struct file *file,
3148 unsigned int set, unsigned int clear)
3150 SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
3151 unsigned long flags;
3153 if (debug_level >= DEBUG_LEVEL_INFO)
3154 printk("%s(%d):%s tiocmset(%x,%x)\n",
3155 __FILE__,__LINE__,info->device_name, set, clear);
3157 if (set & TIOCM_RTS)
3158 info->serial_signals |= SerialSignal_RTS;
3159 if (set & TIOCM_DTR)
3160 info->serial_signals |= SerialSignal_DTR;
3161 if (clear & TIOCM_RTS)
3162 info->serial_signals &= ~SerialSignal_RTS;
3163 if (clear & TIOCM_DTR)
3164 info->serial_signals &= ~SerialSignal_DTR;
3166 spin_lock_irqsave(&info->lock,flags);
3168 spin_unlock_irqrestore(&info->lock,flags);
3175 /* Block the current process until the specified port is ready to open.
3177 static int block_til_ready(struct tty_struct *tty, struct file *filp,
3180 DECLARE_WAITQUEUE(wait, current);
3182 int do_clocal = 0, extra_count = 0;
3183 unsigned long flags;
3185 if (debug_level >= DEBUG_LEVEL_INFO)
3186 printk("%s(%d):%s block_til_ready()\n",
3187 __FILE__,__LINE__, tty->driver->name );
3189 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
3190 /* nonblock mode is set or port is not enabled */
3191 /* just verify that callout device is not active */
3192 info->flags |= ASYNC_NORMAL_ACTIVE;
3196 if (tty->termios->c_cflag & CLOCAL)
3199 /* Wait for carrier detect and the line to become
3200 * free (i.e., not in use by the callout). While we are in
3201 * this loop, info->count is dropped by one, so that
3202 * close() knows when to free things. We restore it upon
3203 * exit, either normal or abnormal.
3207 add_wait_queue(&info->open_wait, &wait);
3209 if (debug_level >= DEBUG_LEVEL_INFO)
3210 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
3211 __FILE__,__LINE__, tty->driver->name, info->count );
3213 spin_lock_irqsave(&info->lock, flags);
3214 if (!tty_hung_up_p(filp)) {
3218 spin_unlock_irqrestore(&info->lock, flags);
3219 info->blocked_open++;
3222 if ((tty->termios->c_cflag & CBAUD)) {
3223 spin_lock_irqsave(&info->lock,flags);
3224 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3226 spin_unlock_irqrestore(&info->lock,flags);
3229 set_current_state(TASK_INTERRUPTIBLE);
3231 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
3232 retval = (info->flags & ASYNC_HUP_NOTIFY) ?
3233 -EAGAIN : -ERESTARTSYS;
3237 spin_lock_irqsave(&info->lock,flags);
3239 spin_unlock_irqrestore(&info->lock,flags);
3241 if (!(info->flags & ASYNC_CLOSING) &&
3242 (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
3246 if (signal_pending(current)) {
3247 retval = -ERESTARTSYS;
3251 if (debug_level >= DEBUG_LEVEL_INFO)
3252 printk("%s(%d):%s block_til_ready() count=%d\n",
3253 __FILE__,__LINE__, tty->driver->name, info->count );
3258 set_current_state(TASK_RUNNING);
3259 remove_wait_queue(&info->open_wait, &wait);
3263 info->blocked_open--;
3265 if (debug_level >= DEBUG_LEVEL_INFO)
3266 printk("%s(%d):%s block_til_ready() after, count=%d\n",
3267 __FILE__,__LINE__, tty->driver->name, info->count );
3270 info->flags |= ASYNC_NORMAL_ACTIVE;
3275 int alloc_dma_bufs(SLMP_INFO *info)
3277 unsigned short BuffersPerFrame;
3278 unsigned short BufferCount;
3280 // Force allocation to start at 64K boundary for each port.
3281 // This is necessary because *all* buffer descriptors for a port
3282 // *must* be in the same 64K block. All descriptors on a port
3283 // share a common 'base' address (upper 8 bits of 24 bits) programmed
3284 // into the CBP register.
3285 info->port_array[0]->last_mem_alloc = (SCA_MEM_SIZE/4) * info->port_num;
3287 /* Calculate the number of DMA buffers necessary to hold the */
3288 /* largest allowable frame size. Note: If the max frame size is */
3289 /* not an even multiple of the DMA buffer size then we need to */
3290 /* round the buffer count per frame up one. */
3292 BuffersPerFrame = (unsigned short)(info->max_frame_size/SCABUFSIZE);
3293 if ( info->max_frame_size % SCABUFSIZE )
3296 /* calculate total number of data buffers (SCABUFSIZE) possible
3297 * in one ports memory (SCA_MEM_SIZE/4) after allocating memory
3298 * for the descriptor list (BUFFERLISTSIZE).
3300 BufferCount = (SCA_MEM_SIZE/4 - BUFFERLISTSIZE)/SCABUFSIZE;
3302 /* limit number of buffers to maximum amount of descriptors */
3303 if (BufferCount > BUFFERLISTSIZE/sizeof(SCADESC))
3304 BufferCount = BUFFERLISTSIZE/sizeof(SCADESC);
3306 /* use enough buffers to transmit one max size frame */
3307 info->tx_buf_count = BuffersPerFrame + 1;
3309 /* never use more than half the available buffers for transmit */
3310 if (info->tx_buf_count > (BufferCount/2))
3311 info->tx_buf_count = BufferCount/2;
3313 if (info->tx_buf_count > SCAMAXDESC)
3314 info->tx_buf_count = SCAMAXDESC;
3316 /* use remaining buffers for receive */
3317 info->rx_buf_count = BufferCount - info->tx_buf_count;
3319 if (info->rx_buf_count > SCAMAXDESC)
3320 info->rx_buf_count = SCAMAXDESC;
3322 if ( debug_level >= DEBUG_LEVEL_INFO )
3323 printk("%s(%d):%s Allocating %d TX and %d RX DMA buffers.\n",
3324 __FILE__,__LINE__, info->device_name,
3325 info->tx_buf_count,info->rx_buf_count);
3327 if ( alloc_buf_list( info ) < 0 ||
3328 alloc_frame_bufs(info,
3330 info->rx_buf_list_ex,
3331 info->rx_buf_count) < 0 ||
3332 alloc_frame_bufs(info,
3334 info->tx_buf_list_ex,
3335 info->tx_buf_count) < 0 ||
3336 alloc_tmp_rx_buf(info) < 0 ) {
3337 printk("%s(%d):%s Can't allocate DMA buffer memory\n",
3338 __FILE__,__LINE__, info->device_name);
3342 rx_reset_buffers( info );
3347 /* Allocate DMA buffers for the transmit and receive descriptor lists.
3349 int alloc_buf_list(SLMP_INFO *info)
3353 /* build list in adapter shared memory */
3354 info->buffer_list = info->memory_base + info->port_array[0]->last_mem_alloc;
3355 info->buffer_list_phys = info->port_array[0]->last_mem_alloc;
3356 info->port_array[0]->last_mem_alloc += BUFFERLISTSIZE;
3358 memset(info->buffer_list, 0, BUFFERLISTSIZE);
3360 /* Save virtual address pointers to the receive and */
3361 /* transmit buffer lists. (Receive 1st). These pointers will */
3362 /* be used by the processor to access the lists. */
3363 info->rx_buf_list = (SCADESC *)info->buffer_list;
3365 info->tx_buf_list = (SCADESC *)info->buffer_list;
3366 info->tx_buf_list += info->rx_buf_count;
3368 /* Build links for circular buffer entry lists (tx and rx)
3370 * Note: links are physical addresses read by the SCA device
3371 * to determine the next buffer entry to use.
3374 for ( i = 0; i < info->rx_buf_count; i++ ) {
3375 /* calculate and store physical address of this buffer entry */
3376 info->rx_buf_list_ex[i].phys_entry =
3377 info->buffer_list_phys + (i * sizeof(SCABUFSIZE));
3379 /* calculate and store physical address of */
3380 /* next entry in cirular list of entries */
3381 info->rx_buf_list[i].next = info->buffer_list_phys;
3382 if ( i < info->rx_buf_count - 1 )
3383 info->rx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
3385 info->rx_buf_list[i].length = SCABUFSIZE;
3388 for ( i = 0; i < info->tx_buf_count; i++ ) {
3389 /* calculate and store physical address of this buffer entry */
3390 info->tx_buf_list_ex[i].phys_entry = info->buffer_list_phys +
3391 ((info->rx_buf_count + i) * sizeof(SCADESC));
3393 /* calculate and store physical address of */
3394 /* next entry in cirular list of entries */
3396 info->tx_buf_list[i].next = info->buffer_list_phys +
3397 info->rx_buf_count * sizeof(SCADESC);
3399 if ( i < info->tx_buf_count - 1 )
3400 info->tx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
3406 /* Allocate the frame DMA buffers used by the specified buffer list.
3408 int alloc_frame_bufs(SLMP_INFO *info, SCADESC *buf_list,SCADESC_EX *buf_list_ex,int count)
3411 unsigned long phys_addr;
3413 for ( i = 0; i < count; i++ ) {
3414 buf_list_ex[i].virt_addr = info->memory_base + info->port_array[0]->last_mem_alloc;
3415 phys_addr = info->port_array[0]->last_mem_alloc;
3416 info->port_array[0]->last_mem_alloc += SCABUFSIZE;
3418 buf_list[i].buf_ptr = (unsigned short)phys_addr;
3419 buf_list[i].buf_base = (unsigned char)(phys_addr >> 16);
3425 void free_dma_bufs(SLMP_INFO *info)
3427 info->buffer_list = NULL;
3428 info->rx_buf_list = NULL;
3429 info->tx_buf_list = NULL;
3432 /* allocate buffer large enough to hold max_frame_size.
3433 * This buffer is used to pass an assembled frame to the line discipline.
3435 int alloc_tmp_rx_buf(SLMP_INFO *info)
3437 info->tmp_rx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
3438 if (info->tmp_rx_buf == NULL)
3443 void free_tmp_rx_buf(SLMP_INFO *info)
3445 if (info->tmp_rx_buf)
3446 kfree(info->tmp_rx_buf);
3447 info->tmp_rx_buf = NULL;
3450 int claim_resources(SLMP_INFO *info)
3452 if (request_mem_region(info->phys_memory_base,0x40000,"synclinkmp") == NULL) {
3453 printk( "%s(%d):%s mem addr conflict, Addr=%08X\n",
3454 __FILE__,__LINE__,info->device_name, info->phys_memory_base);
3458 info->shared_mem_requested = 1;
3460 if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclinkmp") == NULL) {
3461 printk( "%s(%d):%s lcr mem addr conflict, Addr=%08X\n",
3462 __FILE__,__LINE__,info->device_name, info->phys_lcr_base);
3466 info->lcr_mem_requested = 1;
3468 if (request_mem_region(info->phys_sca_base + info->sca_offset,512,"synclinkmp") == NULL) {
3469 printk( "%s(%d):%s sca mem addr conflict, Addr=%08X\n",
3470 __FILE__,__LINE__,info->device_name, info->phys_sca_base);
3474 info->sca_base_requested = 1;
3476 if (request_mem_region(info->phys_statctrl_base + info->statctrl_offset,16,"synclinkmp") == NULL) {
3477 printk( "%s(%d):%s stat/ctrl mem addr conflict, Addr=%08X\n",
3478 __FILE__,__LINE__,info->device_name, info->phys_statctrl_base);
3482 info->sca_statctrl_requested = 1;
3484 info->memory_base = ioremap(info->phys_memory_base,SCA_MEM_SIZE);
3485 if (!info->memory_base) {
3486 printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n",
3487 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
3491 if ( !memory_test(info) ) {
3492 printk( "%s(%d):Shared Memory Test failed for device %s MemAddr=%08X\n",
3493 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
3497 info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE) + info->lcr_offset;
3498 if (!info->lcr_base) {
3499 printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n",
3500 __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
3504 info->sca_base = ioremap(info->phys_sca_base,PAGE_SIZE) + info->sca_offset;
3505 if (!info->sca_base) {
3506 printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n",
3507 __FILE__,__LINE__,info->device_name, info->phys_sca_base );
3511 info->statctrl_base = ioremap(info->phys_statctrl_base,PAGE_SIZE) + info->statctrl_offset;
3512 if (!info->statctrl_base) {
3513 printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n",
3514 __FILE__,__LINE__,info->device_name, info->phys_statctrl_base );
3521 release_resources( info );
3525 void release_resources(SLMP_INFO *info)
3527 if ( debug_level >= DEBUG_LEVEL_INFO )
3528 printk( "%s(%d):%s release_resources() entry\n",
3529 __FILE__,__LINE__,info->device_name );
3531 if ( info->irq_requested ) {
3532 free_irq(info->irq_level, info);
3533 info->irq_requested = 0;
3536 if ( info->shared_mem_requested ) {
3537 release_mem_region(info->phys_memory_base,0x40000);
3538 info->shared_mem_requested = 0;
3540 if ( info->lcr_mem_requested ) {
3541 release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
3542 info->lcr_mem_requested = 0;
3544 if ( info->sca_base_requested ) {
3545 release_mem_region(info->phys_sca_base + info->sca_offset,512);
3546 info->sca_base_requested = 0;
3548 if ( info->sca_statctrl_requested ) {
3549 release_mem_region(info->phys_statctrl_base + info->statctrl_offset,16);
3550 info->sca_statctrl_requested = 0;
3553 if (info->memory_base){
3554 iounmap(info->memory_base);
3555 info->memory_base = NULL;
3558 if (info->sca_base) {
3559 iounmap(info->sca_base - info->sca_offset);
3560 info->sca_base=NULL;
3563 if (info->statctrl_base) {
3564 iounmap(info->statctrl_base - info->statctrl_offset);
3565 info->statctrl_base=NULL;
3568 if (info->lcr_base){
3569 iounmap(info->lcr_base - info->lcr_offset);
3570 info->lcr_base = NULL;
3573 if ( debug_level >= DEBUG_LEVEL_INFO )
3574 printk( "%s(%d):%s release_resources() exit\n",
3575 __FILE__,__LINE__,info->device_name );
3578 /* Add the specified device instance data structure to the
3579 * global linked list of devices and increment the device count.
3581 void add_device(SLMP_INFO *info)
3583 info->next_device = NULL;
3584 info->line = synclinkmp_device_count;
3585 sprintf(info->device_name,"ttySLM%dp%d",info->adapter_num,info->port_num);
3587 if (info->line < MAX_DEVICES) {
3588 if (maxframe[info->line])
3589 info->max_frame_size = maxframe[info->line];
3590 info->dosyncppp = dosyncppp[info->line];
3593 synclinkmp_device_count++;
3595 if ( !synclinkmp_device_list )
3596 synclinkmp_device_list = info;
3598 SLMP_INFO *current_dev = synclinkmp_device_list;
3599 while( current_dev->next_device )
3600 current_dev = current_dev->next_device;
3601 current_dev->next_device = info;
3604 if ( info->max_frame_size < 4096 )
3605 info->max_frame_size = 4096;
3606 else if ( info->max_frame_size > 65535 )
3607 info->max_frame_size = 65535;
3609 printk( "SyncLink MultiPort %s: "
3610 "Mem=(%08x %08X %08x %08X) IRQ=%d MaxFrameSize=%u\n",
3612 info->phys_sca_base,
3613 info->phys_memory_base,
3614 info->phys_statctrl_base,
3615 info->phys_lcr_base,
3617 info->max_frame_size );
3619 #ifdef CONFIG_SYNCLINK_SYNCPPP
3620 if (info->dosyncppp)
3625 /* Allocate and initialize a device instance structure
3627 * Return Value: pointer to SLMP_INFO if success, otherwise NULL
3629 SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
3633 info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO),
3637 printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
3638 __FILE__,__LINE__, adapter_num, port_num);
3640 memset(info, 0, sizeof(SLMP_INFO));
3641 info->magic = MGSL_MAGIC;
3642 INIT_WORK(&info->task, bh_handler, info);
3643 info->max_frame_size = 4096;
3644 info->close_delay = 5*HZ/10;
3645 info->closing_wait = 30*HZ;
3646 init_waitqueue_head(&info->open_wait);
3647 init_waitqueue_head(&info->close_wait);
3648 init_waitqueue_head(&info->status_event_wait_q);
3649 init_waitqueue_head(&info->event_wait_q);
3650 spin_lock_init(&info->netlock);
3651 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
3652 info->idle_mode = HDLC_TXIDLE_FLAGS;
3653 info->adapter_num = adapter_num;
3654 info->port_num = port_num;
3656 /* Copy configuration info to device instance data */
3657 info->irq_level = pdev->irq;
3658 info->phys_lcr_base = pci_resource_start(pdev,0);
3659 info->phys_sca_base = pci_resource_start(pdev,2);
3660 info->phys_memory_base = pci_resource_start(pdev,3);
3661 info->phys_statctrl_base = pci_resource_start(pdev,4);
3663 /* Because veremap only works on page boundaries we must map
3664 * a larger area than is actually implemented for the LCR
3665 * memory range. We map a full page starting at the page boundary.
3667 info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
3668 info->phys_lcr_base &= ~(PAGE_SIZE-1);
3670 info->sca_offset = info->phys_sca_base & (PAGE_SIZE-1);
3671 info->phys_sca_base &= ~(PAGE_SIZE-1);
3673 info->statctrl_offset = info->phys_statctrl_base & (PAGE_SIZE-1);
3674 info->phys_statctrl_base &= ~(PAGE_SIZE-1);
3676 info->bus_type = MGSL_BUS_TYPE_PCI;
3677 info->irq_flags = SA_SHIRQ;
3679 init_timer(&info->tx_timer);
3680 info->tx_timer.data = (unsigned long)info;
3681 info->tx_timer.function = tx_timeout;
3683 init_timer(&info->status_timer);
3684 info->status_timer.data = (unsigned long)info;
3685 info->status_timer.function = status_timeout;
3687 /* Store the PCI9050 misc control register value because a flaw
3688 * in the PCI9050 prevents LCR registers from being read if
3689 * BIOS assigns an LCR base address with bit 7 set.
3691 * Only the misc control register is accessed for which only
3692 * write access is needed, so set an initial value and change
3693 * bits to the device instance data as we write the value
3694 * to the actual misc control register.
3696 info->misc_ctrl_value = 0x087e4546;
3698 /* initial port state is unknown - if startup errors
3699 * occur, init_error will be set to indicate the
3700 * problem. Once the port is fully initialized,
3701 * this value will be set to 0 to indicate the
3702 * port is available.
3704 info->init_error = -1;
3710 void device_init(int adapter_num, struct pci_dev *pdev)
3712 SLMP_INFO *port_array[SCA_MAX_PORTS];
3715 /* allocate device instances for up to SCA_MAX_PORTS devices */
3716 for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
3717 port_array[port] = alloc_dev(adapter_num,port,pdev);
3718 if( port_array[port] == NULL ) {
3719 for ( --port; port >= 0; --port )
3720 kfree(port_array[port]);
3725 /* give copy of port_array to all ports and add to device list */
3726 for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
3727 memcpy(port_array[port]->port_array,port_array,sizeof(port_array));
3728 add_device( port_array[port] );
3729 spin_lock_init(&port_array[port]->lock);
3732 /* Allocate and claim adapter resources */
3733 if ( !claim_resources(port_array[0]) ) {
3735 alloc_dma_bufs(port_array[0]);
3737 /* copy resource information from first port to others */
3738 for ( port = 1; port < SCA_MAX_PORTS; ++port ) {
3739 port_array[port]->lock = port_array[0]->lock;
3740 port_array[port]->irq_level = port_array[0]->irq_level;
3741 port_array[port]->memory_base = port_array[0]->memory_base;
3742 port_array[port]->sca_base = port_array[0]->sca_base;
3743 port_array[port]->statctrl_base = port_array[0]->statctrl_base;
3744 port_array[port]->lcr_base = port_array[0]->lcr_base;
3745 alloc_dma_bufs(port_array[port]);
3748 if ( request_irq(port_array[0]->irq_level,
3749 synclinkmp_interrupt,
3750 port_array[0]->irq_flags,
3751 port_array[0]->device_name,
3752 port_array[0]) < 0 ) {
3753 printk( "%s(%d):%s Cant request interrupt, IRQ=%d\n",
3755 port_array[0]->device_name,
3756 port_array[0]->irq_level );
3759 port_array[0]->irq_requested = 1;
3760 adapter_test(port_array[0]);
3765 static struct tty_operations ops = {
3769 .put_char = put_char,
3770 .flush_chars = flush_chars,
3771 .write_room = write_room,
3772 .chars_in_buffer = chars_in_buffer,
3773 .flush_buffer = flush_buffer,
3775 .throttle = throttle,
3776 .unthrottle = unthrottle,
3777 .send_xchar = send_xchar,
3778 .break_ctl = set_break,
3779 .wait_until_sent = wait_until_sent,
3780 .read_proc = read_proc,
3781 .set_termios = set_termios,
3783 .start = tx_release,
3785 .tiocmget = tiocmget,
3786 .tiocmset = tiocmset,
3789 static void synclinkmp_cleanup(void)
3791 unsigned long flags;
3796 printk("Unloading %s %s\n", driver_name, driver_version);
3798 if (serial_driver) {
3799 if ((rc = tty_unregister_driver(serial_driver)))
3800 printk("%s(%d) failed to unregister tty driver err=%d\n",
3801 __FILE__,__LINE__,rc);
3802 put_tty_driver(serial_driver);
3805 info = synclinkmp_device_list;
3807 #ifdef CONFIG_SYNCLINK_SYNCPPP
3808 if (info->dosyncppp)
3812 if ( info->port_num == 0 ) {
3813 if ( info->irq_requested ) {
3814 free_irq(info->irq_level, info);
3815 info->irq_requested = 0;
3818 info = info->next_device;
3821 /* port 0 of each adapter originally claimed
3822 * all resources, release those now
3824 info = synclinkmp_device_list;
3826 free_dma_bufs(info);
3827 free_tmp_rx_buf(info);
3828 if ( info->port_num == 0 ) {
3829 spin_lock_irqsave(&info->lock,flags);
3830 reset_adapter(info);
3831 write_reg(info, LPR, 1); /* set low power mode */
3832 spin_unlock_irqrestore(&info->lock,flags);
3833 release_resources(info);
3836 info = info->next_device;
3840 pci_unregister_driver(&synclinkmp_pci_driver);
3843 /* Driver initialization entry point.
3846 static int __init synclinkmp_init(void)
3850 if (break_on_load) {
3851 synclinkmp_get_text_ptr();
3855 printk("%s %s\n", driver_name, driver_version);
3857 if ((rc = pci_register_driver(&synclinkmp_pci_driver)) < 0) {
3858 printk("%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
3862 serial_driver = alloc_tty_driver(128);
3863 if (!serial_driver) {
3868 /* Initialize the tty_driver structure */
3870 serial_driver->owner = THIS_MODULE;
3871 serial_driver->driver_name = "synclinkmp";
3872 serial_driver->name = "ttySLM";
3873 serial_driver->major = ttymajor;
3874 serial_driver->minor_start = 64;
3875 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
3876 serial_driver->subtype = SERIAL_TYPE_NORMAL;
3877 serial_driver->init_termios = tty_std_termios;
3878 serial_driver->init_termios.c_cflag =
3879 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
3880 serial_driver->flags = TTY_DRIVER_REAL_RAW;
3881 tty_set_operations(serial_driver, &ops);
3882 if ((rc = tty_register_driver(serial_driver)) < 0) {
3883 printk("%s(%d):Couldn't register serial driver\n",
3885 put_tty_driver(serial_driver);
3886 serial_driver = NULL;
3890 printk("%s %s, tty major#%d\n",
3891 driver_name, driver_version,
3892 serial_driver->major);
3897 synclinkmp_cleanup();
3901 static void __exit synclinkmp_exit(void)
3903 synclinkmp_cleanup();
3906 module_init(synclinkmp_init);
3907 module_exit(synclinkmp_exit);
3909 /* Set the port for internal loopback mode.
3910 * The TxCLK and RxCLK signals are generated from the BRG and
3911 * the TxD is looped back to the RxD internally.
3913 void enable_loopback(SLMP_INFO *info, int enable)
3916 /* MD2 (Mode Register 2)
3917 * 01..00 CNCT<1..0> Channel Connection 11=Local Loopback
3919 write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) | (BIT1 + BIT0)));
3921 /* degate external TxC clock source */
3922 info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
3923 write_control_reg(info);
3925 /* RXS/TXS (Rx/Tx clock source)
3926 * 07 Reserved, must be 0
3927 * 06..04 Clock Source, 100=BRG
3928 * 03..00 Clock Divisor, 0000=1
3930 write_reg(info, RXS, 0x40);
3931 write_reg(info, TXS, 0x40);
3934 /* MD2 (Mode Register 2)
3935 * 01..00 CNCT<1..0> Channel connection, 0=normal
3937 write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) & ~(BIT1 + BIT0)));
3939 /* RXS/TXS (Rx/Tx clock source)
3940 * 07 Reserved, must be 0
3941 * 06..04 Clock Source, 000=RxC/TxC Pin
3942 * 03..00 Clock Divisor, 0000=1
3944 write_reg(info, RXS, 0x00);
3945 write_reg(info, TXS, 0x00);
3948 /* set LinkSpeed if available, otherwise default to 2Mbps */
3949 if (info->params.clock_speed)
3950 set_rate(info, info->params.clock_speed);
3952 set_rate(info, 3686400);
3955 /* Set the baud rate register to the desired speed
3957 * data_rate data rate of clock in bits per second
3958 * A data rate of 0 disables the AUX clock.
3960 void set_rate( SLMP_INFO *info, u32 data_rate )
3963 unsigned char BRValue;
3966 /* fBRG = fCLK/(TMC * 2^BR)
3968 if (data_rate != 0) {
3969 Divisor = 14745600/data_rate;
3976 if (TMCValue != 1 && TMCValue != 2) {
3977 /* BRValue of 0 provides 50/50 duty cycle *only* when
3978 * TMCValue is 1 or 2. BRValue of 1 to 9 always provides
3985 /* while TMCValue is too big for TMC register, divide
3986 * by 2 and increment BR exponent.
3988 for(; TMCValue > 256 && BRValue < 10; BRValue++)
3991 write_reg(info, TXS,
3992 (unsigned char)((read_reg(info, TXS) & 0xf0) | BRValue));
3993 write_reg(info, RXS,
3994 (unsigned char)((read_reg(info, RXS) & 0xf0) | BRValue));
3995 write_reg(info, TMC, (unsigned char)TMCValue);
3998 write_reg(info, TXS,0);
3999 write_reg(info, RXS,0);
4000 write_reg(info, TMC, 0);
4006 void rx_stop(SLMP_INFO *info)
4008 if (debug_level >= DEBUG_LEVEL_ISR)
4009 printk("%s(%d):%s rx_stop()\n",
4010 __FILE__,__LINE__, info->device_name );
4012 write_reg(info, CMD, RXRESET);
4014 info->ie0_value &= ~RXRDYE;
4015 write_reg(info, IE0, info->ie0_value); /* disable Rx data interrupts */
4017 write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
4018 write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
4019 write_reg(info, RXDMA + DIR, 0); /* disable Rx DMA interrupts */
4021 info->rx_enabled = 0;
4022 info->rx_overflow = 0;
4025 /* enable the receiver
4027 void rx_start(SLMP_INFO *info)
4031 if (debug_level >= DEBUG_LEVEL_ISR)
4032 printk("%s(%d):%s rx_start()\n",
4033 __FILE__,__LINE__, info->device_name );
4035 write_reg(info, CMD, RXRESET);
4037 if ( info->params.mode == MGSL_MODE_HDLC ) {
4038 /* HDLC, disabe IRQ on rxdata */
4039 info->ie0_value &= ~RXRDYE;
4040 write_reg(info, IE0, info->ie0_value);
4042 /* Reset all Rx DMA buffers and program rx dma */
4043 write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
4044 write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
4046 for (i = 0; i < info->rx_buf_count; i++) {
4047 info->rx_buf_list[i].status = 0xff;
4049 // throttle to 4 shared memory writes at a time to prevent
4050 // hogging local bus (keep latency time for DMA requests low).
4052 read_status_reg(info);
4054 info->current_rx_buf = 0;
4056 /* set current/1st descriptor address */
4057 write_reg16(info, RXDMA + CDA,
4058 info->rx_buf_list_ex[0].phys_entry);
4060 /* set new last rx descriptor address */
4061 write_reg16(info, RXDMA + EDA,
4062 info->rx_buf_list_ex[info->rx_buf_count - 1].phys_entry);
4064 /* set buffer length (shared by all rx dma data buffers) */
4065 write_reg16(info, RXDMA + BFL, SCABUFSIZE);
4067 write_reg(info, RXDMA + DIR, 0x60); /* enable Rx DMA interrupts (EOM/BOF) */
4068 write_reg(info, RXDMA + DSR, 0xf2); /* clear Rx DMA IRQs, enable Rx DMA */
4070 /* async, enable IRQ on rxdata */
4071 info->ie0_value |= RXRDYE;
4072 write_reg(info, IE0, info->ie0_value);
4075 write_reg(info, CMD, RXENABLE);
4077 info->rx_overflow = FALSE;
4078 info->rx_enabled = 1;
4081 /* Enable the transmitter and send a transmit frame if
4082 * one is loaded in the DMA buffers.
4084 void tx_start(SLMP_INFO *info)
4086 if (debug_level >= DEBUG_LEVEL_ISR)
4087 printk("%s(%d):%s tx_start() tx_count=%d\n",
4088 __FILE__,__LINE__, info->device_name,info->tx_count );
4090 if (!info->tx_enabled ) {
4091 write_reg(info, CMD, TXRESET);
4092 write_reg(info, CMD, TXENABLE);
4093 info->tx_enabled = TRUE;
4096 if ( info->tx_count ) {
4098 /* If auto RTS enabled and RTS is inactive, then assert */
4099 /* RTS and set a flag indicating that the driver should */
4100 /* negate RTS when the transmission completes. */
4102 info->drop_rts_on_tx_done = 0;
4104 if (info->params.mode != MGSL_MODE_ASYNC) {
4106 if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
4107 get_signals( info );
4108 if ( !(info->serial_signals & SerialSignal_RTS) ) {
4109 info->serial_signals |= SerialSignal_RTS;
4110 set_signals( info );
4111 info->drop_rts_on_tx_done = 1;
4115 write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
4116 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
4118 /* set TX CDA (current descriptor address) */
4119 write_reg16(info, TXDMA + CDA,
4120 info->tx_buf_list_ex[0].phys_entry);
4122 /* set TX EDA (last descriptor address) */
4123 write_reg16(info, TXDMA + EDA,
4124 info->tx_buf_list_ex[info->last_tx_buf].phys_entry);
4126 /* clear IDLE and UDRN status bit */
4127 info->ie1_value &= ~(IDLE + UDRN);
4128 if (info->params.mode != MGSL_MODE_ASYNC)
4129 info->ie1_value |= UDRN; /* HDLC, IRQ on underrun */
4130 write_reg(info, IE1, info->ie1_value); /* enable MSCI interrupts */
4131 write_reg(info, SR1, (unsigned char)(IDLE + UDRN));
4133 write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
4134 write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
4136 info->tx_timer.expires = jiffies + jiffies_from_ms(5000);
4137 add_timer(&info->tx_timer);
4141 /* async, enable IRQ on txdata */
4142 info->ie0_value |= TXRDYE;
4143 write_reg(info, IE0, info->ie0_value);
4146 info->tx_active = 1;
4150 /* stop the transmitter and DMA
4152 void tx_stop( SLMP_INFO *info )
4154 if (debug_level >= DEBUG_LEVEL_ISR)
4155 printk("%s(%d):%s tx_stop()\n",
4156 __FILE__,__LINE__, info->device_name );
4158 del_timer(&info->tx_timer);
4160 write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
4161 write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
4163 write_reg(info, CMD, TXRESET);
4165 info->ie1_value &= ~(UDRN + IDLE);
4166 write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
4167 write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
4169 info->ie0_value &= ~TXRDYE;
4170 write_reg(info, IE0, info->ie0_value); /* disable tx data interrupts */
4172 info->tx_enabled = 0;
4173 info->tx_active = 0;
4176 /* Fill the transmit FIFO until the FIFO is full or
4177 * there is no more data to load.
4179 void tx_load_fifo(SLMP_INFO *info)
4183 /* do nothing is now tx data available and no XON/XOFF pending */
4185 if ( !info->tx_count && !info->x_char )
4188 /* load the Transmit FIFO until FIFOs full or all data sent */
4190 while( info->tx_count && (read_reg(info,SR0) & BIT1) ) {
4192 /* there is more space in the transmit FIFO and */
4193 /* there is more data in transmit buffer */
4195 if ( (info->tx_count > 1) && !info->x_char ) {
4197 TwoBytes[0] = info->tx_buf[info->tx_get++];
4198 if (info->tx_get >= info->max_frame_size)
4199 info->tx_get -= info->max_frame_size;
4200 TwoBytes[1] = info->tx_buf[info->tx_get++];
4201 if (info->tx_get >= info->max_frame_size)
4202 info->tx_get -= info->max_frame_size;
4204 write_reg16(info, TRB, *((u16 *)TwoBytes));
4206 info->tx_count -= 2;
4207 info->icount.tx += 2;
4209 /* only 1 byte left to transmit or 1 FIFO slot left */
4212 /* transmit pending high priority char */
4213 write_reg(info, TRB, info->x_char);
4216 write_reg(info, TRB, info->tx_buf[info->tx_get++]);
4217 if (info->tx_get >= info->max_frame_size)
4218 info->tx_get -= info->max_frame_size;
4226 /* Reset a port to a known state
4228 void reset_port(SLMP_INFO *info)
4230 if (info->sca_base) {
4235 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
4238 /* disable all port interrupts */
4239 info->ie0_value = 0;
4240 info->ie1_value = 0;
4241 info->ie2_value = 0;
4242 write_reg(info, IE0, info->ie0_value);
4243 write_reg(info, IE1, info->ie1_value);
4244 write_reg(info, IE2, info->ie2_value);
4246 write_reg(info, CMD, CHRESET);
4250 /* Reset all the ports to a known state.
4252 void reset_adapter(SLMP_INFO *info)
4256 for ( i=0; i < SCA_MAX_PORTS; ++i) {
4257 if (info->port_array[i])
4258 reset_port(info->port_array[i]);
4262 /* Program port for asynchronous communications.
4264 void async_mode(SLMP_INFO *info)
4267 unsigned char RegValue;
4272 /* MD0, Mode Register 0
4274 * 07..05 PRCTL<2..0>, Protocol Mode, 000=async
4275 * 04 AUTO, Auto-enable (RTS/CTS/DCD)
4276 * 03 Reserved, must be 0
4277 * 02 CRCCC, CRC Calculation, 0=disabled
4278 * 01..00 STOP<1..0> Stop bits (00=1,10=2)
4283 if (info->params.stop_bits != 1)
4285 write_reg(info, MD0, RegValue);
4287 /* MD1, Mode Register 1
4289 * 07..06 BRATE<1..0>, bit rate, 00=1/1 01=1/16 10=1/32 11=1/64
4290 * 05..04 TXCHR<1..0>, tx char size, 00=8 bits,01=7,10=6,11=5
4291 * 03..02 RXCHR<1..0>, rx char size
4292 * 01..00 PMPM<1..0>, Parity mode, 00=none 10=even 11=odd
4297 switch (info->params.data_bits) {
4298 case 7: RegValue |= BIT4 + BIT2; break;
4299 case 6: RegValue |= BIT5 + BIT3; break;
4300 case 5: RegValue |= BIT5 + BIT4 + BIT3 + BIT2; break;
4302 if (info->params.parity != ASYNC_PARITY_NONE) {
4304 if (info->params.parity == ASYNC_PARITY_ODD)
4307 write_reg(info, MD1, RegValue);
4309 /* MD2, Mode Register 2
4311 * 07..02 Reserved, must be 0
4312 * 01..00 CNCT<1..0> Channel connection, 0=normal
4317 write_reg(info, MD2, RegValue);
4319 /* RXS, Receive clock source
4321 * 07 Reserved, must be 0
4322 * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
4323 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4326 write_reg(info, RXS, RegValue);
4328 /* TXS, Transmit clock source
4330 * 07 Reserved, must be 0
4331 * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
4332 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4335 write_reg(info, TXS, RegValue);
4339 * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
4341 info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
4342 write_control_reg(info);
4346 /* RRC Receive Ready Control 0
4348 * 07..05 Reserved, must be 0
4349 * 04..00 RRC<4..0> Rx FIFO trigger active 0x00 = 1 byte
4351 write_reg(info, TRC0, 0x00);
4353 /* TRC0 Transmit Ready Control 0
4355 * 07..05 Reserved, must be 0
4356 * 04..00 TRC<4..0> Tx FIFO trigger active 0x10 = 16 bytes
4358 write_reg(info, TRC0, 0x10);
4360 /* TRC1 Transmit Ready Control 1
4362 * 07..05 Reserved, must be 0
4363 * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1e = 31 bytes (full-1)
4365 write_reg(info, TRC1, 0x1e);
4367 /* CTL, MSCI control register
4369 * 07..06 Reserved, set to 0
4370 * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
4371 * 04 IDLC, idle control, 0=mark 1=idle register
4372 * 03 BRK, break, 0=off 1 =on (async)
4373 * 02 SYNCLD, sync char load enable (BSC) 1=enabled
4374 * 01 GOP, go active on poll (LOOP mode) 1=enabled
4375 * 00 RTS, RTS output control, 0=active 1=inactive
4380 if (!(info->serial_signals & SerialSignal_RTS))
4382 write_reg(info, CTL, RegValue);
4384 /* enable status interrupts */
4385 info->ie0_value |= TXINTE + RXINTE;
4386 write_reg(info, IE0, info->ie0_value);
4388 /* enable break detect interrupt */
4389 info->ie1_value = BRKD;
4390 write_reg(info, IE1, info->ie1_value);
4392 /* enable rx overrun interrupt */
4393 info->ie2_value = OVRN;
4394 write_reg(info, IE2, info->ie2_value);
4396 set_rate( info, info->params.data_rate * 16 );
4398 if (info->params.loopback)
4399 enable_loopback(info,1);
4402 /* Program the SCA for HDLC communications.
4404 void hdlc_mode(SLMP_INFO *info)
4406 unsigned char RegValue;
4409 // Can't use DPLL because SCA outputs recovered clock on RxC when
4410 // DPLL mode selected. This causes output contention with RxC receiver.
4411 // Use of DPLL would require external hardware to disable RxC receiver
4412 // when DPLL mode selected.
4413 info->params.flags &= ~(HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL);
4415 /* disable DMA interrupts */
4416 write_reg(info, TXDMA + DIR, 0);
4417 write_reg(info, RXDMA + DIR, 0);
4419 /* MD0, Mode Register 0
4421 * 07..05 PRCTL<2..0>, Protocol Mode, 100=HDLC
4422 * 04 AUTO, Auto-enable (RTS/CTS/DCD)
4423 * 03 Reserved, must be 0
4424 * 02 CRCCC, CRC Calculation, 1=enabled
4425 * 01 CRC1, CRC selection, 0=CRC-16,1=CRC-CCITT-16
4426 * 00 CRC0, CRC initial value, 1 = all 1s
4431 if (info->params.flags & HDLC_FLAG_AUTO_CTS)
4433 if (info->params.flags & HDLC_FLAG_AUTO_DCD)
4435 if (info->params.crc_type == HDLC_CRC_16_CCITT)
4436 RegValue |= BIT2 + BIT1;
4437 write_reg(info, MD0, RegValue);
4439 /* MD1, Mode Register 1
4441 * 07..06 ADDRS<1..0>, Address detect, 00=no addr check
4442 * 05..04 TXCHR<1..0>, tx char size, 00=8 bits
4443 * 03..02 RXCHR<1..0>, rx char size, 00=8 bits
4444 * 01..00 PMPM<1..0>, Parity mode, 00=no parity
4449 write_reg(info, MD1, RegValue);
4451 /* MD2, Mode Register 2
4453 * 07 NRZFM, 0=NRZ, 1=FM
4454 * 06..05 CODE<1..0> Encoding, 00=NRZ
4455 * 04..03 DRATE<1..0> DPLL Divisor, 00=8
4456 * 02 Reserved, must be 0
4457 * 01..00 CNCT<1..0> Channel connection, 0=normal
4462 switch(info->params.encoding) {
4463 case HDLC_ENCODING_NRZI: RegValue |= BIT5; break;
4464 case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT7 + BIT5; break; /* aka FM1 */
4465 case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT7 + BIT6; break; /* aka FM0 */
4466 case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT7; break; /* aka Manchester */
4468 case HDLC_ENCODING_NRZB: /* not supported */
4469 case HDLC_ENCODING_NRZI_MARK: /* not supported */
4470 case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: /* not supported */
4473 if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
4476 } else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
4482 write_reg(info, MD2, RegValue);
4485 /* RXS, Receive clock source
4487 * 07 Reserved, must be 0
4488 * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
4489 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4492 if (info->params.flags & HDLC_FLAG_RXC_BRG)
4494 if (info->params.flags & HDLC_FLAG_RXC_DPLL)
4495 RegValue |= BIT6 + BIT5;
4496 write_reg(info, RXS, RegValue);
4498 /* TXS, Transmit clock source
4500 * 07 Reserved, must be 0
4501 * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
4502 * 03..00 RXBR<3..0>, rate divisor, 0000=1
4505 if (info->params.flags & HDLC_FLAG_TXC_BRG)
4507 if (info->params.flags & HDLC_FLAG_TXC_DPLL)
4508 RegValue |= BIT6 + BIT5;
4509 write_reg(info, TXS, RegValue);
4511 if (info->params.flags & HDLC_FLAG_RXC_DPLL)
4512 set_rate(info, info->params.clock_speed * DpllDivisor);
4514 set_rate(info, info->params.clock_speed);
4516 /* GPDATA (General Purpose I/O Data Register)
4518 * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
4520 if (info->params.flags & HDLC_FLAG_TXC_BRG)
4521 info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
4523 info->port_array[0]->ctrlreg_value &= ~(BIT0 << (info->port_num * 2));
4524 write_control_reg(info);
4526 /* RRC Receive Ready Control 0
4528 * 07..05 Reserved, must be 0
4529 * 04..00 RRC<4..0> Rx FIFO trigger active
4531 write_reg(info, RRC, rx_active_fifo_level);
4533 /* TRC0 Transmit Ready Control 0
4535 * 07..05 Reserved, must be 0
4536 * 04..00 TRC<4..0> Tx FIFO trigger active
4538 write_reg(info, TRC0, tx_active_fifo_level);
4540 /* TRC1 Transmit Ready Control 1
4542 * 07..05 Reserved, must be 0
4543 * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1f = 32 bytes (full)
4545 write_reg(info, TRC1, (unsigned char)(tx_negate_fifo_level - 1));
4547 /* DMR, DMA Mode Register
4549 * 07..05 Reserved, must be 0
4550 * 04 TMOD, Transfer Mode: 1=chained-block
4551 * 03 Reserved, must be 0
4552 * 02 NF, Number of Frames: 1=multi-frame
4553 * 01 CNTE, Frame End IRQ Counter enable: 0=disabled
4554 * 00 Reserved, must be 0
4558 write_reg(info, TXDMA + DMR, 0x14);
4559 write_reg(info, RXDMA + DMR, 0x14);
4561 /* Set chain pointer base (upper 8 bits of 24 bit addr) */
4562 write_reg(info, RXDMA + CPB,
4563 (unsigned char)(info->buffer_list_phys >> 16));
4565 /* Set chain pointer base (upper 8 bits of 24 bit addr) */
4566 write_reg(info, TXDMA + CPB,
4567 (unsigned char)(info->buffer_list_phys >> 16));
4569 /* enable status interrupts. other code enables/disables
4570 * the individual sources for these two interrupt classes.
4572 info->ie0_value |= TXINTE + RXINTE;
4573 write_reg(info, IE0, info->ie0_value);
4575 /* CTL, MSCI control register
4577 * 07..06 Reserved, set to 0
4578 * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
4579 * 04 IDLC, idle control, 0=mark 1=idle register
4580 * 03 BRK, break, 0=off 1 =on (async)
4581 * 02 SYNCLD, sync char load enable (BSC) 1=enabled
4582 * 01 GOP, go active on poll (LOOP mode) 1=enabled
4583 * 00 RTS, RTS output control, 0=active 1=inactive
4588 if (!(info->serial_signals & SerialSignal_RTS))
4590 write_reg(info, CTL, RegValue);
4592 /* preamble not supported ! */
4598 set_rate(info, info->params.clock_speed);
4600 if (info->params.loopback)
4601 enable_loopback(info,1);
4604 /* Set the transmit HDLC idle mode
4606 void tx_set_idle(SLMP_INFO *info)
4608 unsigned char RegValue = 0xff;
4610 /* Map API idle mode to SCA register bits */
4611 switch(info->idle_mode) {
4612 case HDLC_TXIDLE_FLAGS: RegValue = 0x7e; break;
4613 case HDLC_TXIDLE_ALT_ZEROS_ONES: RegValue = 0xaa; break;
4614 case HDLC_TXIDLE_ZEROS: RegValue = 0x00; break;
4615 case HDLC_TXIDLE_ONES: RegValue = 0xff; break;
4616 case HDLC_TXIDLE_ALT_MARK_SPACE: RegValue = 0xaa; break;
4617 case HDLC_TXIDLE_SPACE: RegValue = 0x00; break;
4618 case HDLC_TXIDLE_MARK: RegValue = 0xff; break;
4621 write_reg(info, IDL, RegValue);
4624 /* Query the adapter for the state of the V24 status (input) signals.
4626 void get_signals(SLMP_INFO *info)
4628 u16 status = read_reg(info, SR3);
4629 u16 gpstatus = read_status_reg(info);
4632 /* clear all serial signals except DTR and RTS */
4633 info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
4635 /* set serial signal bits to reflect MISR */
4637 if (!(status & BIT3))
4638 info->serial_signals |= SerialSignal_CTS;
4640 if ( !(status & BIT2))
4641 info->serial_signals |= SerialSignal_DCD;
4643 testbit = BIT1 << (info->port_num * 2); // Port 0..3 RI is GPDATA<1,3,5,7>
4644 if (!(gpstatus & testbit))
4645 info->serial_signals |= SerialSignal_RI;
4647 testbit = BIT0 << (info->port_num * 2); // Port 0..3 DSR is GPDATA<0,2,4,6>
4648 if (!(gpstatus & testbit))
4649 info->serial_signals |= SerialSignal_DSR;
4652 /* Set the state of DTR and RTS based on contents of
4653 * serial_signals member of device context.
4655 void set_signals(SLMP_INFO *info)
4657 unsigned char RegValue;
4660 RegValue = read_reg(info, CTL);
4661 if (info->serial_signals & SerialSignal_RTS)
4665 write_reg(info, CTL, RegValue);
4667 // Port 0..3 DTR is ctrl reg <1,3,5,7>
4668 EnableBit = BIT1 << (info->port_num*2);
4669 if (info->serial_signals & SerialSignal_DTR)
4670 info->port_array[0]->ctrlreg_value &= ~EnableBit;
4672 info->port_array[0]->ctrlreg_value |= EnableBit;
4673 write_control_reg(info);
4676 /*******************/
4677 /* DMA Buffer Code */
4678 /*******************/
4680 /* Set the count for all receive buffers to SCABUFSIZE
4681 * and set the current buffer to the first buffer. This effectively
4682 * makes all buffers free and discards any data in buffers.
4684 void rx_reset_buffers(SLMP_INFO *info)
4686 rx_free_frame_buffers(info, 0, info->rx_buf_count - 1);
4689 /* Free the buffers used by a received frame
4691 * info pointer to device instance data
4692 * first index of 1st receive buffer of frame
4693 * last index of last receive buffer of frame
4695 void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last)
4700 /* reset current buffer for reuse */
4701 info->rx_buf_list[first].status = 0xff;
4703 if (first == last) {
4705 /* set new last rx descriptor address */
4706 write_reg16(info, RXDMA + EDA, info->rx_buf_list_ex[first].phys_entry);
4710 if (first == info->rx_buf_count)
4714 /* set current buffer to next buffer after last buffer of frame */
4715 info->current_rx_buf = first;
4718 /* Return a received frame from the receive DMA buffers.
4719 * Only frames received without errors are returned.
4721 * Return Value: 1 if frame returned, otherwise 0
4723 int rx_get_frame(SLMP_INFO *info)
4725 unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
4726 unsigned short status;
4727 unsigned int framesize = 0;
4729 unsigned long flags;
4730 struct tty_struct *tty = info->tty;
4731 unsigned char addr_field = 0xff;
4733 SCADESC_EX *desc_ex;
4736 /* assume no frame returned, set zero length */
4741 * current_rx_buf points to the 1st buffer of the next available
4742 * receive frame. To find the last buffer of the frame look for
4743 * a non-zero status field in the buffer entries. (The status
4744 * field is set by the 16C32 after completing a receive frame.
4746 StartIndex = EndIndex = info->current_rx_buf;
4749 desc = &info->rx_buf_list[EndIndex];
4750 desc_ex = &info->rx_buf_list_ex[EndIndex];
4752 if (desc->status == 0xff)
4753 goto Cleanup; /* current desc still in use, no frames available */
4755 if (framesize == 0 && info->params.addr_filter != 0xff)
4756 addr_field = desc_ex->virt_addr[0];
4758 framesize += desc->length;
4760 /* Status != 0 means last buffer of frame */
4765 if (EndIndex == info->rx_buf_count)
4768 if (EndIndex == info->current_rx_buf) {
4769 /* all buffers have been 'used' but none mark */
4770 /* the end of a frame. Reset buffers and receiver. */
4771 if ( info->rx_enabled ){
4772 spin_lock_irqsave(&info->lock,flags);
4774 spin_unlock_irqrestore(&info->lock,flags);
4781 /* check status of receive frame */
4783 /* frame status is byte stored after frame data
4785 * 7 EOM (end of msg), 1 = last buffer of frame
4786 * 6 Short Frame, 1 = short frame
4787 * 5 Abort, 1 = frame aborted
4788 * 4 Residue, 1 = last byte is partial
4789 * 3 Overrun, 1 = overrun occurred during frame reception
4790 * 2 CRC, 1 = CRC error detected
4793 status = desc->status;
4795 /* ignore CRC bit if not using CRC (bit is undefined) */
4796 /* Note:CRC is not save to data buffer */
4797 if (info->params.crc_type == HDLC_CRC_NONE)
4800 if (framesize == 0 ||
4801 (addr_field != 0xff && addr_field != info->params.addr_filter)) {
4802 /* discard 0 byte frames, this seems to occur sometime
4803 * when remote is idling flags.
4805 rx_free_frame_buffers(info, StartIndex, EndIndex);
4812 if (status & (BIT6+BIT5+BIT3+BIT2)) {
4813 /* received frame has errors,
4814 * update counts and mark frame size as 0
4817 info->icount.rxshort++;
4818 else if (status & BIT5)
4819 info->icount.rxabort++;
4820 else if (status & BIT3)
4821 info->icount.rxover++;
4823 info->icount.rxcrc++;
4827 #ifdef CONFIG_SYNCLINK_SYNCPPP
4828 info->netstats.rx_errors++;
4829 info->netstats.rx_frame_errors++;
4833 if ( debug_level >= DEBUG_LEVEL_BH )
4834 printk("%s(%d):%s rx_get_frame() status=%04X size=%d\n",
4835 __FILE__,__LINE__,info->device_name,status,framesize);
4837 if ( debug_level >= DEBUG_LEVEL_DATA )
4838 trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
4839 MIN(framesize,SCABUFSIZE),0);
4842 if (framesize > info->max_frame_size)
4843 info->icount.rxlong++;
4845 /* copy dma buffer(s) to contiguous intermediate buffer */
4846 int copy_count = framesize;
4847 int index = StartIndex;
4848 unsigned char *ptmp = info->tmp_rx_buf;
4849 info->tmp_rx_buf_count = framesize;
4851 info->icount.rxok++;
4854 int partial_count = MIN(copy_count,SCABUFSIZE);
4856 info->rx_buf_list_ex[index].virt_addr,
4858 ptmp += partial_count;
4859 copy_count -= partial_count;
4861 if ( ++index == info->rx_buf_count )
4865 #ifdef CONFIG_SYNCLINK_SYNCPPP
4866 if (info->netcount) {
4867 /* pass frame to syncppp device */
4868 sppp_rx_done(info,info->tmp_rx_buf,framesize);
4873 if ( tty && tty->ldisc.receive_buf ) {
4874 /* Call the line discipline receive callback directly. */
4875 tty->ldisc.receive_buf(tty,
4883 /* Free the buffers used by this frame. */
4884 rx_free_frame_buffers( info, StartIndex, EndIndex );
4889 if ( info->rx_enabled && info->rx_overflow ) {
4890 /* Receiver is enabled, but needs to restarted due to
4891 * rx buffer overflow. If buffers are empty, restart receiver.
4893 if (info->rx_buf_list[EndIndex].status == 0xff) {
4894 spin_lock_irqsave(&info->lock,flags);
4896 spin_unlock_irqrestore(&info->lock,flags);
4903 /* load the transmit DMA buffer with data
4905 void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count)
4907 unsigned short copy_count;
4910 SCADESC_EX *desc_ex;
4912 if ( debug_level >= DEBUG_LEVEL_DATA )
4913 trace_block(info,buf, MIN(count,SCABUFSIZE), 1);
4915 /* Copy source buffer to one or more DMA buffers, starting with
4916 * the first transmit dma buffer.
4920 copy_count = MIN(count,SCABUFSIZE);
4922 desc = &info->tx_buf_list[i];
4923 desc_ex = &info->tx_buf_list_ex[i];
4925 load_pci_memory(info, desc_ex->virt_addr,buf,copy_count);
4927 desc->length = copy_count;
4931 count -= copy_count;
4937 if (i >= info->tx_buf_count)
4941 info->tx_buf_list[i].status = 0x81; /* set EOM and EOT status */
4942 info->last_tx_buf = ++i;
4945 int register_test(SLMP_INFO *info)
4947 static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
4948 static unsigned int count = sizeof(testval)/sizeof(unsigned char);
4951 unsigned long flags;
4953 spin_lock_irqsave(&info->lock,flags);
4956 /* assume failure */
4957 info->init_error = DiagStatus_AddressFailure;
4959 /* Write bit patterns to various registers but do it out of */
4960 /* sync, then read back and verify values. */
4962 for (i = 0 ; i < count ; i++) {
4963 write_reg(info, TMC, testval[i]);
4964 write_reg(info, IDL, testval[(i+1)%count]);
4965 write_reg(info, SA0, testval[(i+2)%count]);
4966 write_reg(info, SA1, testval[(i+3)%count]);
4968 if ( (read_reg(info, TMC) != testval[i]) ||
4969 (read_reg(info, IDL) != testval[(i+1)%count]) ||
4970 (read_reg(info, SA0) != testval[(i+2)%count]) ||
4971 (read_reg(info, SA1) != testval[(i+3)%count]) )
4979 spin_unlock_irqrestore(&info->lock,flags);
4984 int irq_test(SLMP_INFO *info)
4986 unsigned long timeout;
4987 unsigned long flags;
4989 unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
4991 spin_lock_irqsave(&info->lock,flags);
4994 /* assume failure */
4995 info->init_error = DiagStatus_IrqFailure;
4996 info->irq_occurred = FALSE;
4998 /* setup timer0 on SCA0 to interrupt */
5000 /* IER2<7..4> = timer<3..0> interrupt enables (1=enabled) */
5001 write_reg(info, IER2, (unsigned char)((info->port_num & 1) ? BIT6 : BIT4));
5003 write_reg(info, (unsigned char)(timer + TEPR), 0); /* timer expand prescale */
5004 write_reg16(info, (unsigned char)(timer + TCONR), 1); /* timer constant */
5007 /* TMCS, Timer Control/Status Register
5009 * 07 CMF, Compare match flag (read only) 1=match
5010 * 06 ECMI, CMF Interrupt Enable: 1=enabled
5011 * 05 Reserved, must be 0
5012 * 04 TME, Timer Enable
5013 * 03..00 Reserved, must be 0
5017 write_reg(info, (unsigned char)(timer + TMCS), 0x50);
5019 spin_unlock_irqrestore(&info->lock,flags);
5022 while( timeout-- && !info->irq_occurred ) {
5023 set_current_state(TASK_INTERRUPTIBLE);
5024 schedule_timeout(jiffies_from_ms(10));
5027 spin_lock_irqsave(&info->lock,flags);
5029 spin_unlock_irqrestore(&info->lock,flags);
5031 return info->irq_occurred;
5034 /* initialize individual SCA device (2 ports)
5036 int sca_init(SLMP_INFO *info)
5038 /* set wait controller to single mem partition (low), no wait states */
5039 write_reg(info, PABR0, 0); /* wait controller addr boundary 0 */
5040 write_reg(info, PABR1, 0); /* wait controller addr boundary 1 */
5041 write_reg(info, WCRL, 0); /* wait controller low range */
5042 write_reg(info, WCRM, 0); /* wait controller mid range */
5043 write_reg(info, WCRH, 0); /* wait controller high range */
5045 /* DPCR, DMA Priority Control
5047 * 07..05 Not used, must be 0
5048 * 04 BRC, bus release condition: 0=all transfers complete
5049 * 03 CCC, channel change condition: 0=every cycle
5050 * 02..00 PR<2..0>, priority 100=round robin
5054 write_reg(info, DPCR, dma_priority);
5056 /* DMA Master Enable, BIT7: 1=enable all channels */
5057 write_reg(info, DMER, 0x80);
5059 /* enable all interrupt classes */
5060 write_reg(info, IER0, 0xff); /* TxRDY,RxRDY,TxINT,RxINT (ports 0-1) */
5061 write_reg(info, IER1, 0xff); /* DMIB,DMIA (channels 0-3) */
5062 write_reg(info, IER2, 0xf0); /* TIRQ (timers 0-3) */
5064 /* ITCR, interrupt control register
5065 * 07 IPC, interrupt priority, 0=MSCI->DMA
5066 * 06..05 IAK<1..0>, Acknowledge cycle, 00=non-ack cycle
5067 * 04 VOS, Vector Output, 0=unmodified vector
5068 * 03..00 Reserved, must be 0
5070 write_reg(info, ITCR, 0);
5075 /* initialize adapter hardware
5077 int init_adapter(SLMP_INFO *info)
5081 /* Set BIT30 of Local Control Reg 0x50 to reset SCA */
5082 volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
5085 info->misc_ctrl_value |= BIT30;
5086 *MiscCtrl = info->misc_ctrl_value;
5089 * Force at least 170ns delay before clearing
5090 * reset bit. Each read from LCR takes at least
5091 * 30ns so 10 times for 300ns to be safe.
5094 readval = *MiscCtrl;
5096 info->misc_ctrl_value &= ~BIT30;
5097 *MiscCtrl = info->misc_ctrl_value;
5099 /* init control reg (all DTRs off, all clksel=input) */
5100 info->ctrlreg_value = 0xaa;
5101 write_control_reg(info);
5104 volatile u32 *LCR1BRDR = (u32 *)(info->lcr_base + 0x2c);
5105 lcr1_brdr_value &= ~(BIT5 + BIT4 + BIT3);
5107 switch(read_ahead_count)
5110 lcr1_brdr_value |= BIT5 + BIT4 + BIT3;
5113 lcr1_brdr_value |= BIT5 + BIT4;
5116 lcr1_brdr_value |= BIT5 + BIT3;
5119 lcr1_brdr_value |= BIT5;
5123 *LCR1BRDR = lcr1_brdr_value;
5124 *MiscCtrl = misc_ctrl_value;
5127 sca_init(info->port_array[0]);
5128 sca_init(info->port_array[2]);
5133 /* Loopback an HDLC frame to test the hardware
5134 * interrupt and DMA functions.
5136 int loopback_test(SLMP_INFO *info)
5138 #define TESTFRAMESIZE 20
5140 unsigned long timeout;
5141 u16 count = TESTFRAMESIZE;
5142 unsigned char buf[TESTFRAMESIZE];
5144 unsigned long flags;
5146 struct tty_struct *oldtty = info->tty;
5147 u32 speed = info->params.clock_speed;
5149 info->params.clock_speed = 3686400;
5152 /* assume failure */
5153 info->init_error = DiagStatus_DmaFailure;
5155 /* build and send transmit frame */
5156 for (count = 0; count < TESTFRAMESIZE;++count)
5157 buf[count] = (unsigned char)count;
5159 memset(info->tmp_rx_buf,0,TESTFRAMESIZE);
5161 /* program hardware for HDLC and enabled receiver */
5162 spin_lock_irqsave(&info->lock,flags);
5164 enable_loopback(info,1);
5166 info->tx_count = count;
5167 tx_load_dma_buffer(info,buf,count);
5169 spin_unlock_irqrestore(&info->lock,flags);
5171 /* wait for receive complete */
5172 /* Set a timeout for waiting for interrupt. */
5173 for ( timeout = 100; timeout; --timeout ) {
5174 set_current_state(TASK_INTERRUPTIBLE);
5175 schedule_timeout(jiffies_from_ms(10));
5177 if (rx_get_frame(info)) {
5183 /* verify received frame length and contents */
5185 ( info->tmp_rx_buf_count != count ||
5186 memcmp(buf, info->tmp_rx_buf,count))) {
5190 spin_lock_irqsave(&info->lock,flags);
5191 reset_adapter(info);
5192 spin_unlock_irqrestore(&info->lock,flags);
5194 info->params.clock_speed = speed;
5200 /* Perform diagnostics on hardware
5202 int adapter_test( SLMP_INFO *info )
5204 unsigned long flags;
5205 if ( debug_level >= DEBUG_LEVEL_INFO )
5206 printk( "%s(%d):Testing device %s\n",
5207 __FILE__,__LINE__,info->device_name );
5209 spin_lock_irqsave(&info->lock,flags);
5211 spin_unlock_irqrestore(&info->lock,flags);
5213 info->port_array[0]->port_count = 0;
5215 if ( register_test(info->port_array[0]) &&
5216 register_test(info->port_array[1])) {
5218 info->port_array[0]->port_count = 2;
5220 if ( register_test(info->port_array[2]) &&
5221 register_test(info->port_array[3]) )
5222 info->port_array[0]->port_count += 2;
5225 printk( "%s(%d):Register test failure for device %s Addr=%08lX\n",
5226 __FILE__,__LINE__,info->device_name, (unsigned long)(info->phys_sca_base));
5230 if ( !irq_test(info->port_array[0]) ||
5231 !irq_test(info->port_array[1]) ||
5232 (info->port_count == 4 && !irq_test(info->port_array[2])) ||
5233 (info->port_count == 4 && !irq_test(info->port_array[3]))) {
5234 printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
5235 __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
5239 if (!loopback_test(info->port_array[0]) ||
5240 !loopback_test(info->port_array[1]) ||
5241 (info->port_count == 4 && !loopback_test(info->port_array[2])) ||
5242 (info->port_count == 4 && !loopback_test(info->port_array[3]))) {
5243 printk( "%s(%d):DMA test failure for device %s\n",
5244 __FILE__,__LINE__,info->device_name);
5248 if ( debug_level >= DEBUG_LEVEL_INFO )
5249 printk( "%s(%d):device %s passed diagnostics\n",
5250 __FILE__,__LINE__,info->device_name );
5252 info->port_array[0]->init_error = 0;
5253 info->port_array[1]->init_error = 0;
5254 if ( info->port_count > 2 ) {
5255 info->port_array[2]->init_error = 0;
5256 info->port_array[3]->init_error = 0;
5262 /* Test the shared memory on a PCI adapter.
5264 int memory_test(SLMP_INFO *info)
5266 static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
5267 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
5268 unsigned long count = sizeof(testval)/sizeof(unsigned long);
5270 unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
5271 unsigned long * addr = (unsigned long *)info->memory_base;
5273 /* Test data lines with test pattern at one location. */
5275 for ( i = 0 ; i < count ; i++ ) {
5277 if ( *addr != testval[i] )
5281 /* Test address lines with incrementing pattern over */
5282 /* entire address range. */
5284 for ( i = 0 ; i < limit ; i++ ) {
5289 addr = (unsigned long *)info->memory_base;
5291 for ( i = 0 ; i < limit ; i++ ) {
5292 if ( *addr != i * 4 )
5297 memset( info->memory_base, 0, SCA_MEM_SIZE );
5301 /* Load data into PCI adapter shared memory.
5303 * The PCI9050 releases control of the local bus
5304 * after completing the current read or write operation.
5306 * While the PCI9050 write FIFO not empty, the
5307 * PCI9050 treats all of the writes as a single transaction
5308 * and does not release the bus. This causes DMA latency problems
5309 * at high speeds when copying large data blocks to the shared memory.
5311 * This function breaks a write into multiple transations by
5312 * interleaving a read which flushes the write FIFO and 'completes'
5313 * the write transation. This allows any pending DMA request to gain control
5314 * of the local bus in a timely fasion.
5316 void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count)
5318 /* A load interval of 16 allows for 4 32-bit writes at */
5319 /* 136ns each for a maximum latency of 542ns on the local bus.*/
5321 unsigned short interval = count / sca_pci_load_interval;
5324 for ( i = 0 ; i < interval ; i++ )
5326 memcpy(dest, src, sca_pci_load_interval);
5327 read_status_reg(info);
5328 dest += sca_pci_load_interval;
5329 src += sca_pci_load_interval;
5332 memcpy(dest, src, count % sca_pci_load_interval);
5335 void trace_block(SLMP_INFO *info,const char* data, int count, int xmit)
5340 printk("%s tx data:\n",info->device_name);
5342 printk("%s rx data:\n",info->device_name);
5350 for(i=0;i<linecount;i++)
5351 printk("%02X ",(unsigned char)data[i]);
5354 for(i=0;i<linecount;i++) {
5355 if (data[i]>=040 && data[i]<=0176)
5356 printk("%c",data[i]);
5365 } /* end of trace_block() */
5367 /* called when HDLC frame times out
5368 * update stats and do tx completion processing
5370 void tx_timeout(unsigned long context)
5372 SLMP_INFO *info = (SLMP_INFO*)context;
5373 unsigned long flags;
5375 if ( debug_level >= DEBUG_LEVEL_INFO )
5376 printk( "%s(%d):%s tx_timeout()\n",
5377 __FILE__,__LINE__,info->device_name);
5378 if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
5379 info->icount.txtimeout++;
5381 spin_lock_irqsave(&info->lock,flags);
5382 info->tx_active = 0;
5383 info->tx_count = info->tx_put = info->tx_get = 0;
5385 spin_unlock_irqrestore(&info->lock,flags);
5387 #ifdef CONFIG_SYNCLINK_SYNCPPP
5395 /* called to periodically check the DSR/RI modem signal input status
5397 void status_timeout(unsigned long context)
5400 SLMP_INFO *info = (SLMP_INFO*)context;
5401 unsigned long flags;
5402 unsigned char delta;
5405 spin_lock_irqsave(&info->lock,flags);
5407 spin_unlock_irqrestore(&info->lock,flags);
5409 /* check for DSR/RI state change */
5411 delta = info->old_signals ^ info->serial_signals;
5412 info->old_signals = info->serial_signals;
5414 if (delta & SerialSignal_DSR)
5415 status |= MISCSTATUS_DSR_LATCHED|(info->serial_signals&SerialSignal_DSR);
5417 if (delta & SerialSignal_RI)
5418 status |= MISCSTATUS_RI_LATCHED|(info->serial_signals&SerialSignal_RI);
5420 if (delta & SerialSignal_DCD)
5421 status |= MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD);
5423 if (delta & SerialSignal_CTS)
5424 status |= MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS);
5427 isr_io_pin(info,status);
5429 info->status_timer.data = (unsigned long)info;
5430 info->status_timer.function = status_timeout;
5431 info->status_timer.expires = jiffies + jiffies_from_ms(10);
5432 add_timer(&info->status_timer);
5436 /* Register Access Routines -
5437 * All registers are memory mapped
5439 #define CALC_REGADDR() \
5440 unsigned char * RegAddr = (unsigned char*)(info->sca_base + Addr); \
5441 if (info->port_num > 1) \
5442 RegAddr += 256; /* port 0-1 SCA0, 2-3 SCA1 */ \
5443 if ( info->port_num & 1) { \
5445 RegAddr += 0x40; /* DMA access */ \
5446 else if (Addr > 0x1f && Addr < 0x60) \
5447 RegAddr += 0x20; /* MSCI access */ \
5451 unsigned char read_reg(SLMP_INFO * info, unsigned char Addr)
5456 void write_reg(SLMP_INFO * info, unsigned char Addr, unsigned char Value)
5462 u16 read_reg16(SLMP_INFO * info, unsigned char Addr)
5465 return *((u16 *)RegAddr);
5468 void write_reg16(SLMP_INFO * info, unsigned char Addr, u16 Value)
5471 *((u16 *)RegAddr) = Value;
5474 unsigned char read_status_reg(SLMP_INFO * info)
5476 unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
5480 void write_control_reg(SLMP_INFO * info)
5482 unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
5483 *RegAddr = info->port_array[0]->ctrlreg_value;
5487 static int __devinit synclinkmp_init_one (struct pci_dev *dev,
5488 const struct pci_device_id *ent)
5490 if (pci_enable_device(dev)) {
5491 printk("error enabling pci device %p\n", dev);
5494 device_init( ++synclinkmp_adapter_count, dev );
5498 static void __devexit synclinkmp_remove_one (struct pci_dev *dev)