2 * linux/drivers/char/pcmcia/synclink_cs.c
4 * $Id: synclink_cs.c,v 4.34 2005/09/08 13:20:54 paulkf Exp $
6 * Device driver for Microgate SyncLink PC Card
7 * multiprotocol serial adapter.
9 * written by Paul Fulghum for Microgate Corporation
10 * paulkf@microgate.com
12 * Microgate and SyncLink are trademarks of Microgate Corporation
14 * This code is released under the GNU General Public License (GPL)
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26 * OF THE POSSIBILITY OF SUCH DAMAGE.
29 #define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
31 # define BREAKPOINT() asm(" int $3");
33 # define BREAKPOINT() { }
36 #define MAX_DEVICE_COUNT 4
38 #include <linux/config.h>
39 #include <linux/module.h>
40 #include <linux/errno.h>
41 #include <linux/signal.h>
42 #include <linux/sched.h>
43 #include <linux/timer.h>
44 #include <linux/time.h>
45 #include <linux/interrupt.h>
46 #include <linux/pci.h>
47 #include <linux/tty.h>
48 #include <linux/tty_flip.h>
49 #include <linux/serial.h>
50 #include <linux/major.h>
51 #include <linux/string.h>
52 #include <linux/fcntl.h>
53 #include <linux/ptrace.h>
54 #include <linux/ioport.h>
56 #include <linux/slab.h>
57 #include <linux/netdevice.h>
58 #include <linux/vmalloc.h>
59 #include <linux/init.h>
60 #include <asm/serial.h>
61 #include <linux/delay.h>
62 #include <linux/ioctl.h>
64 #include <asm/system.h>
68 #include <linux/bitops.h>
69 #include <asm/types.h>
70 #include <linux/termios.h>
71 #include <linux/workqueue.h>
72 #include <linux/hdlc.h>
74 #include <pcmcia/cs_types.h>
75 #include <pcmcia/cs.h>
76 #include <pcmcia/cistpl.h>
77 #include <pcmcia/cisreg.h>
78 #include <pcmcia/ds.h>
80 #ifdef CONFIG_HDLC_MODULE
84 #define GET_USER(error,value,addr) error = get_user(value,addr)
85 #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
86 #define PUT_USER(error,value,addr) error = put_user(value,addr)
87 #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
89 #include <asm/uaccess.h>
91 #include "linux/synclink.h"
93 static MGSL_PARAMS default_params
= {
94 MGSL_MODE_HDLC
, /* unsigned long mode */
95 0, /* unsigned char loopback; */
96 HDLC_FLAG_UNDERRUN_ABORT15
, /* unsigned short flags; */
97 HDLC_ENCODING_NRZI_SPACE
, /* unsigned char encoding; */
98 0, /* unsigned long clock_speed; */
99 0xff, /* unsigned char addr_filter; */
100 HDLC_CRC_16_CCITT
, /* unsigned short crc_type; */
101 HDLC_PREAMBLE_LENGTH_8BITS
, /* unsigned char preamble_length; */
102 HDLC_PREAMBLE_PATTERN_NONE
, /* unsigned char preamble; */
103 9600, /* unsigned long data_rate; */
104 8, /* unsigned char data_bits; */
105 1, /* unsigned char stop_bits; */
106 ASYNC_PARITY_NONE
/* unsigned char parity; */
112 unsigned char status
;
116 /* The queue of BH actions to be performed */
119 #define BH_TRANSMIT 2
122 #define IO_PIN_SHUTDOWN_LIMIT 100
124 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
126 struct _input_signal_events
{
139 * Device instance data structure
142 typedef struct _mgslpc_info
{
143 void *if_ptr
; /* General purpose pointer (used by SPPP) */
146 int count
; /* count of opens */
148 unsigned short close_delay
;
149 unsigned short closing_wait
; /* time to wait before closing */
151 struct mgsl_icount icount
;
153 struct tty_struct
*tty
;
155 int x_char
; /* xon/xoff character */
156 int blocked_open
; /* # of blocked opens */
157 unsigned char read_status_mask
;
158 unsigned char ignore_status_mask
;
160 unsigned char *tx_buf
;
165 /* circular list of fixed length rx buffers */
167 unsigned char *rx_buf
; /* memory allocated for all rx buffers */
168 int rx_buf_total_size
; /* size of memory allocated for rx buffers */
169 int rx_put
; /* index of next empty rx buffer */
170 int rx_get
; /* index of next full rx buffer */
171 int rx_buf_size
; /* size in bytes of single rx buffer */
172 int rx_buf_count
; /* total number of rx buffers */
173 int rx_frame_count
; /* number of full rx buffers */
175 wait_queue_head_t open_wait
;
176 wait_queue_head_t close_wait
;
178 wait_queue_head_t status_event_wait_q
;
179 wait_queue_head_t event_wait_q
;
180 struct timer_list tx_timer
; /* HDLC transmit timeout timer */
181 struct _mgslpc_info
*next_device
; /* device list link */
183 unsigned short imra_value
;
184 unsigned short imrb_value
;
185 unsigned char pim_value
;
188 struct work_struct task
; /* task structure for scheduling bh */
197 int dcd_chkcount
; /* check counts to prevent */
198 int cts_chkcount
; /* too many IRQs if a signal */
199 int dsr_chkcount
; /* is floating */
210 int if_mode
; /* serial interface selection (RS-232, v.35 etc) */
212 char device_name
[25]; /* device instance name */
214 unsigned int io_base
; /* base I/O address of adapter */
215 unsigned int irq_level
;
217 MGSL_PARAMS params
; /* communications parameters */
219 unsigned char serial_signals
; /* current serial signal states */
221 char irq_occurred
; /* for diagnostics use */
223 unsigned int init_error
; /* startup error (DIAGS) */
225 char flag_buf
[MAX_ASYNC_BUFFER_SIZE
];
226 BOOLEAN drop_rts_on_tx_done
;
228 struct _input_signal_events input_signal_events
;
231 struct pcmcia_device
*p_dev
;
235 /* SPPP/Cisco HDLC device parts */
241 struct net_device
*netdev
;
246 #define MGSLPC_MAGIC 0x5402
249 * The size of the serial xmit buffer is 1 page, or 4096 bytes
251 #define TXBUFSIZE 4096
254 #define CHA 0x00 /* channel A offset */
255 #define CHB 0x40 /* channel B offset */
258 * FIXME: PPC has PVR defined in asm/reg.h. For now we just undef it.
305 #define IRQ_BREAK_ON BIT15 // rx break detected
306 #define IRQ_DATAOVERRUN BIT14 // receive data overflow
307 #define IRQ_ALLSENT BIT13 // all sent
308 #define IRQ_UNDERRUN BIT12 // transmit data underrun
309 #define IRQ_TIMER BIT11 // timer interrupt
310 #define IRQ_CTS BIT10 // CTS status change
311 #define IRQ_TXREPEAT BIT9 // tx message repeat
312 #define IRQ_TXFIFO BIT8 // transmit pool ready
313 #define IRQ_RXEOM BIT7 // receive message end
314 #define IRQ_EXITHUNT BIT6 // receive frame start
315 #define IRQ_RXTIME BIT6 // rx char timeout
316 #define IRQ_DCD BIT2 // carrier detect status change
317 #define IRQ_OVERRUN BIT1 // receive frame overflow
318 #define IRQ_RXFIFO BIT0 // receive pool full
322 #define XFW BIT6 // transmit FIFO write enable
323 #define CEC BIT2 // command executing
324 #define CTS BIT1 // CTS state
329 #define PVR_AUTOCTS BIT3
330 #define PVR_RS232 0x20 /* 0010b */
331 #define PVR_V35 0xe0 /* 1110b */
332 #define PVR_RS422 0x40 /* 0100b */
334 /* Register access functions */
336 #define write_reg(info, reg, val) outb((val),(info)->io_base + (reg))
337 #define read_reg(info, reg) inb((info)->io_base + (reg))
339 #define read_reg16(info, reg) inw((info)->io_base + (reg))
340 #define write_reg16(info, reg, val) outw((val), (info)->io_base + (reg))
342 #define set_reg_bits(info, reg, mask) \
343 write_reg(info, (reg), \
344 (unsigned char) (read_reg(info, (reg)) | (mask)))
345 #define clear_reg_bits(info, reg, mask) \
346 write_reg(info, (reg), \
347 (unsigned char) (read_reg(info, (reg)) & ~(mask)))
349 * interrupt enable/disable routines
351 static void irq_disable(MGSLPC_INFO
*info
, unsigned char channel
, unsigned short mask
)
353 if (channel
== CHA
) {
354 info
->imra_value
|= mask
;
355 write_reg16(info
, CHA
+ IMR
, info
->imra_value
);
357 info
->imrb_value
|= mask
;
358 write_reg16(info
, CHB
+ IMR
, info
->imrb_value
);
361 static void irq_enable(MGSLPC_INFO
*info
, unsigned char channel
, unsigned short mask
)
363 if (channel
== CHA
) {
364 info
->imra_value
&= ~mask
;
365 write_reg16(info
, CHA
+ IMR
, info
->imra_value
);
367 info
->imrb_value
&= ~mask
;
368 write_reg16(info
, CHB
+ IMR
, info
->imrb_value
);
372 #define port_irq_disable(info, mask) \
373 { info->pim_value |= (mask); write_reg(info, PIM, info->pim_value); }
375 #define port_irq_enable(info, mask) \
376 { info->pim_value &= ~(mask); write_reg(info, PIM, info->pim_value); }
378 static void rx_start(MGSLPC_INFO
*info
);
379 static void rx_stop(MGSLPC_INFO
*info
);
381 static void tx_start(MGSLPC_INFO
*info
);
382 static void tx_stop(MGSLPC_INFO
*info
);
383 static void tx_set_idle(MGSLPC_INFO
*info
);
385 static void get_signals(MGSLPC_INFO
*info
);
386 static void set_signals(MGSLPC_INFO
*info
);
388 static void reset_device(MGSLPC_INFO
*info
);
390 static void hdlc_mode(MGSLPC_INFO
*info
);
391 static void async_mode(MGSLPC_INFO
*info
);
393 static void tx_timeout(unsigned long context
);
395 static int ioctl_common(MGSLPC_INFO
*info
, unsigned int cmd
, unsigned long arg
);
398 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
399 static void hdlcdev_tx_done(MGSLPC_INFO
*info
);
400 static void hdlcdev_rx(MGSLPC_INFO
*info
, char *buf
, int size
);
401 static int hdlcdev_init(MGSLPC_INFO
*info
);
402 static void hdlcdev_exit(MGSLPC_INFO
*info
);
405 static void trace_block(MGSLPC_INFO
*info
,const char* data
, int count
, int xmit
);
407 static BOOLEAN
register_test(MGSLPC_INFO
*info
);
408 static BOOLEAN
irq_test(MGSLPC_INFO
*info
);
409 static int adapter_test(MGSLPC_INFO
*info
);
411 static int claim_resources(MGSLPC_INFO
*info
);
412 static void release_resources(MGSLPC_INFO
*info
);
413 static void mgslpc_add_device(MGSLPC_INFO
*info
);
414 static void mgslpc_remove_device(MGSLPC_INFO
*info
);
416 static int rx_get_frame(MGSLPC_INFO
*info
);
417 static void rx_reset_buffers(MGSLPC_INFO
*info
);
418 static int rx_alloc_buffers(MGSLPC_INFO
*info
);
419 static void rx_free_buffers(MGSLPC_INFO
*info
);
421 static irqreturn_t
mgslpc_isr(int irq
, void *dev_id
, struct pt_regs
* regs
);
424 * Bottom half interrupt handlers
426 static void bh_handler(void* Context
);
427 static void bh_transmit(MGSLPC_INFO
*info
);
428 static void bh_status(MGSLPC_INFO
*info
);
433 static int tiocmget(struct tty_struct
*tty
, struct file
*file
);
434 static int tiocmset(struct tty_struct
*tty
, struct file
*file
,
435 unsigned int set
, unsigned int clear
);
436 static int get_stats(MGSLPC_INFO
*info
, struct mgsl_icount __user
*user_icount
);
437 static int get_params(MGSLPC_INFO
*info
, MGSL_PARAMS __user
*user_params
);
438 static int set_params(MGSLPC_INFO
*info
, MGSL_PARAMS __user
*new_params
);
439 static int get_txidle(MGSLPC_INFO
*info
, int __user
*idle_mode
);
440 static int set_txidle(MGSLPC_INFO
*info
, int idle_mode
);
441 static int set_txenable(MGSLPC_INFO
*info
, int enable
);
442 static int tx_abort(MGSLPC_INFO
*info
);
443 static int set_rxenable(MGSLPC_INFO
*info
, int enable
);
444 static int wait_events(MGSLPC_INFO
*info
, int __user
*mask
);
446 static MGSLPC_INFO
*mgslpc_device_list
= NULL
;
447 static int mgslpc_device_count
= 0;
450 * Set this param to non-zero to load eax with the
451 * .text section address and breakpoint on module load.
452 * This is useful for use with gdb and add-symbol-file command.
454 static int break_on_load
=0;
457 * Driver major number, defaults to zero to get auto
458 * assigned major number. May be forced as module parameter.
460 static int ttymajor
=0;
462 static int debug_level
= 0;
463 static int maxframe
[MAX_DEVICE_COUNT
] = {0,};
464 static int dosyncppp
[MAX_DEVICE_COUNT
] = {1,1,1,1};
466 module_param(break_on_load
, bool, 0);
467 module_param(ttymajor
, int, 0);
468 module_param(debug_level
, int, 0);
469 module_param_array(maxframe
, int, NULL
, 0);
470 module_param_array(dosyncppp
, int, NULL
, 0);
472 MODULE_LICENSE("GPL");
474 static char *driver_name
= "SyncLink PC Card driver";
475 static char *driver_version
= "$Revision: 4.34 $";
477 static struct tty_driver
*serial_driver
;
479 /* number of characters left in xmit buffer before we ask for more */
480 #define WAKEUP_CHARS 256
482 static void mgslpc_change_params(MGSLPC_INFO
*info
);
483 static void mgslpc_wait_until_sent(struct tty_struct
*tty
, int timeout
);
485 /* PCMCIA prototypes */
487 static int mgslpc_config(struct pcmcia_device
*link
);
488 static void mgslpc_release(u_long arg
);
489 static void mgslpc_detach(struct pcmcia_device
*p_dev
);
492 * 1st function defined in .text section. Calling this function in
493 * init_module() followed by a breakpoint allows a remote debugger
494 * (gdb) to get the .text address for the add-symbol-file command.
495 * This allows remote debugging of dynamically loadable modules.
497 static void* mgslpc_get_text_ptr(void)
499 return mgslpc_get_text_ptr
;
503 * line discipline callback wrappers
505 * The wrappers maintain line discipline references
506 * while calling into the line discipline.
508 * ldisc_flush_buffer - flush line discipline receive buffers
509 * ldisc_receive_buf - pass receive data to line discipline
512 static void ldisc_flush_buffer(struct tty_struct
*tty
)
514 struct tty_ldisc
*ld
= tty_ldisc_ref(tty
);
516 if (ld
->flush_buffer
)
517 ld
->flush_buffer(tty
);
522 static void ldisc_receive_buf(struct tty_struct
*tty
,
523 const __u8
*data
, char *flags
, int count
)
525 struct tty_ldisc
*ld
;
528 ld
= tty_ldisc_ref(tty
);
531 ld
->receive_buf(tty
, data
, flags
, count
);
536 static int mgslpc_probe(struct pcmcia_device
*link
)
541 if (debug_level
>= DEBUG_LEVEL_INFO
)
542 printk("mgslpc_attach\n");
544 info
= (MGSLPC_INFO
*)kmalloc(sizeof(MGSLPC_INFO
), GFP_KERNEL
);
546 printk("Error can't allocate device instance data\n");
550 memset(info
, 0, sizeof(MGSLPC_INFO
));
551 info
->magic
= MGSLPC_MAGIC
;
552 INIT_WORK(&info
->task
, bh_handler
, info
);
553 info
->max_frame_size
= 4096;
554 info
->close_delay
= 5*HZ
/10;
555 info
->closing_wait
= 30*HZ
;
556 init_waitqueue_head(&info
->open_wait
);
557 init_waitqueue_head(&info
->close_wait
);
558 init_waitqueue_head(&info
->status_event_wait_q
);
559 init_waitqueue_head(&info
->event_wait_q
);
560 spin_lock_init(&info
->lock
);
561 spin_lock_init(&info
->netlock
);
562 memcpy(&info
->params
,&default_params
,sizeof(MGSL_PARAMS
));
563 info
->idle_mode
= HDLC_TXIDLE_FLAGS
;
564 info
->imra_value
= 0xffff;
565 info
->imrb_value
= 0xffff;
566 info
->pim_value
= 0xff;
571 /* Initialize the struct pcmcia_device structure */
573 /* Interrupt setup */
574 link
->irq
.Attributes
= IRQ_TYPE_EXCLUSIVE
;
575 link
->irq
.IRQInfo1
= IRQ_LEVEL_ID
;
576 link
->irq
.Handler
= NULL
;
578 link
->conf
.Attributes
= 0;
579 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
581 ret
= mgslpc_config(link
);
585 mgslpc_add_device(info
);
590 /* Card has been inserted.
593 #define CS_CHECK(fn, ret) \
594 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
596 static int mgslpc_config(struct pcmcia_device
*link
)
598 MGSLPC_INFO
*info
= link
->priv
;
601 int last_fn
, last_ret
;
603 cistpl_cftable_entry_t dflt
= { 0 };
604 cistpl_cftable_entry_t
*cfg
;
606 if (debug_level
>= DEBUG_LEVEL_INFO
)
607 printk("mgslpc_config(0x%p)\n", link
);
609 /* read CONFIG tuple to find its configuration registers */
610 tuple
.DesiredTuple
= CISTPL_CONFIG
;
611 tuple
.Attributes
= 0;
612 tuple
.TupleData
= buf
;
613 tuple
.TupleDataMax
= sizeof(buf
);
614 tuple
.TupleOffset
= 0;
615 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(link
, &tuple
));
616 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(link
, &tuple
));
617 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(link
, &tuple
, &parse
));
618 link
->conf
.ConfigBase
= parse
.config
.base
;
619 link
->conf
.Present
= parse
.config
.rmask
[0];
621 /* get CIS configuration entry */
623 tuple
.DesiredTuple
= CISTPL_CFTABLE_ENTRY
;
624 CS_CHECK(GetFirstTuple
, pcmcia_get_first_tuple(link
, &tuple
));
626 cfg
= &(parse
.cftable_entry
);
627 CS_CHECK(GetTupleData
, pcmcia_get_tuple_data(link
, &tuple
));
628 CS_CHECK(ParseTuple
, pcmcia_parse_tuple(link
, &tuple
, &parse
));
630 if (cfg
->flags
& CISTPL_CFTABLE_DEFAULT
) dflt
= *cfg
;
634 link
->conf
.ConfigIndex
= cfg
->index
;
635 link
->conf
.Attributes
|= CONF_ENABLE_IRQ
;
637 /* IO window settings */
638 link
->io
.NumPorts1
= 0;
639 if ((cfg
->io
.nwin
> 0) || (dflt
.io
.nwin
> 0)) {
640 cistpl_io_t
*io
= (cfg
->io
.nwin
) ? &cfg
->io
: &dflt
.io
;
641 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_AUTO
;
642 if (!(io
->flags
& CISTPL_IO_8BIT
))
643 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_16
;
644 if (!(io
->flags
& CISTPL_IO_16BIT
))
645 link
->io
.Attributes1
= IO_DATA_PATH_WIDTH_8
;
646 link
->io
.IOAddrLines
= io
->flags
& CISTPL_IO_LINES_MASK
;
647 link
->io
.BasePort1
= io
->win
[0].base
;
648 link
->io
.NumPorts1
= io
->win
[0].len
;
649 CS_CHECK(RequestIO
, pcmcia_request_io(link
, &link
->io
));
652 link
->conf
.Attributes
= CONF_ENABLE_IRQ
;
653 link
->conf
.IntType
= INT_MEMORY_AND_IO
;
654 link
->conf
.ConfigIndex
= 8;
655 link
->conf
.Present
= PRESENT_OPTION
;
657 link
->irq
.Attributes
|= IRQ_HANDLE_PRESENT
;
658 link
->irq
.Handler
= mgslpc_isr
;
659 link
->irq
.Instance
= info
;
660 CS_CHECK(RequestIRQ
, pcmcia_request_irq(link
, &link
->irq
));
662 CS_CHECK(RequestConfiguration
, pcmcia_request_configuration(link
, &link
->conf
));
664 info
->io_base
= link
->io
.BasePort1
;
665 info
->irq_level
= link
->irq
.AssignedIRQ
;
667 /* add to linked list of devices */
668 sprintf(info
->node
.dev_name
, "mgslpc0");
669 info
->node
.major
= info
->node
.minor
= 0;
670 link
->dev_node
= &info
->node
;
672 printk(KERN_INFO
"%s: index 0x%02x:",
673 info
->node
.dev_name
, link
->conf
.ConfigIndex
);
674 if (link
->conf
.Attributes
& CONF_ENABLE_IRQ
)
675 printk(", irq %d", link
->irq
.AssignedIRQ
);
676 if (link
->io
.NumPorts1
)
677 printk(", io 0x%04x-0x%04x", link
->io
.BasePort1
,
678 link
->io
.BasePort1
+link
->io
.NumPorts1
-1);
683 cs_error(link
, last_fn
, last_ret
);
684 mgslpc_release((u_long
)link
);
688 /* Card has been removed.
689 * Unregister device and release PCMCIA configuration.
690 * If device is open, postpone until it is closed.
692 static void mgslpc_release(u_long arg
)
694 struct pcmcia_device
*link
= (struct pcmcia_device
*)arg
;
696 if (debug_level
>= DEBUG_LEVEL_INFO
)
697 printk("mgslpc_release(0x%p)\n", link
);
699 pcmcia_disable_device(link
);
702 static void mgslpc_detach(struct pcmcia_device
*link
)
704 if (debug_level
>= DEBUG_LEVEL_INFO
)
705 printk("mgslpc_detach(0x%p)\n", link
);
707 ((MGSLPC_INFO
*)link
->priv
)->stop
= 1;
708 mgslpc_release((u_long
)link
);
710 mgslpc_remove_device((MGSLPC_INFO
*)link
->priv
);
713 static int mgslpc_suspend(struct pcmcia_device
*link
)
715 MGSLPC_INFO
*info
= link
->priv
;
722 static int mgslpc_resume(struct pcmcia_device
*link
)
724 MGSLPC_INFO
*info
= link
->priv
;
732 static inline int mgslpc_paranoia_check(MGSLPC_INFO
*info
,
733 char *name
, const char *routine
)
735 #ifdef MGSLPC_PARANOIA_CHECK
736 static const char *badmagic
=
737 "Warning: bad magic number for mgsl struct (%s) in %s\n";
738 static const char *badinfo
=
739 "Warning: null mgslpc_info for (%s) in %s\n";
742 printk(badinfo
, name
, routine
);
745 if (info
->magic
!= MGSLPC_MAGIC
) {
746 printk(badmagic
, name
, routine
);
757 #define CMD_RXFIFO BIT7 // release current rx FIFO
758 #define CMD_RXRESET BIT6 // receiver reset
759 #define CMD_RXFIFO_READ BIT5
760 #define CMD_START_TIMER BIT4
761 #define CMD_TXFIFO BIT3 // release current tx FIFO
762 #define CMD_TXEOM BIT1 // transmit end message
763 #define CMD_TXRESET BIT0 // transmit reset
765 static BOOLEAN
wait_command_complete(MGSLPC_INFO
*info
, unsigned char channel
)
768 /* wait for command completion */
769 while (read_reg(info
, (unsigned char)(channel
+STAR
)) & BIT2
) {
777 static void issue_command(MGSLPC_INFO
*info
, unsigned char channel
, unsigned char cmd
)
779 wait_command_complete(info
, channel
);
780 write_reg(info
, (unsigned char) (channel
+ CMDR
), cmd
);
783 static void tx_pause(struct tty_struct
*tty
)
785 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
788 if (mgslpc_paranoia_check(info
, tty
->name
, "tx_pause"))
790 if (debug_level
>= DEBUG_LEVEL_INFO
)
791 printk("tx_pause(%s)\n",info
->device_name
);
793 spin_lock_irqsave(&info
->lock
,flags
);
794 if (info
->tx_enabled
)
796 spin_unlock_irqrestore(&info
->lock
,flags
);
799 static void tx_release(struct tty_struct
*tty
)
801 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
804 if (mgslpc_paranoia_check(info
, tty
->name
, "tx_release"))
806 if (debug_level
>= DEBUG_LEVEL_INFO
)
807 printk("tx_release(%s)\n",info
->device_name
);
809 spin_lock_irqsave(&info
->lock
,flags
);
810 if (!info
->tx_enabled
)
812 spin_unlock_irqrestore(&info
->lock
,flags
);
815 /* Return next bottom half action to perform.
816 * or 0 if nothing to do.
818 static int bh_action(MGSLPC_INFO
*info
)
823 spin_lock_irqsave(&info
->lock
,flags
);
825 if (info
->pending_bh
& BH_RECEIVE
) {
826 info
->pending_bh
&= ~BH_RECEIVE
;
828 } else if (info
->pending_bh
& BH_TRANSMIT
) {
829 info
->pending_bh
&= ~BH_TRANSMIT
;
831 } else if (info
->pending_bh
& BH_STATUS
) {
832 info
->pending_bh
&= ~BH_STATUS
;
837 /* Mark BH routine as complete */
838 info
->bh_running
= 0;
839 info
->bh_requested
= 0;
842 spin_unlock_irqrestore(&info
->lock
,flags
);
847 static void bh_handler(void* Context
)
849 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)Context
;
855 if (debug_level
>= DEBUG_LEVEL_BH
)
856 printk( "%s(%d):bh_handler(%s) entry\n",
857 __FILE__
,__LINE__
,info
->device_name
);
859 info
->bh_running
= 1;
861 while((action
= bh_action(info
)) != 0) {
863 /* Process work item */
864 if ( debug_level
>= DEBUG_LEVEL_BH
)
865 printk( "%s(%d):bh_handler() work item action=%d\n",
866 __FILE__
,__LINE__
,action
);
871 while(rx_get_frame(info
));
880 /* unknown work item ID */
881 printk("Unknown work item ID=%08X!\n", action
);
886 if (debug_level
>= DEBUG_LEVEL_BH
)
887 printk( "%s(%d):bh_handler(%s) exit\n",
888 __FILE__
,__LINE__
,info
->device_name
);
891 static void bh_transmit(MGSLPC_INFO
*info
)
893 struct tty_struct
*tty
= info
->tty
;
894 if (debug_level
>= DEBUG_LEVEL_BH
)
895 printk("bh_transmit() entry on %s\n", info
->device_name
);
899 wake_up_interruptible(&tty
->write_wait
);
903 static void bh_status(MGSLPC_INFO
*info
)
905 info
->ri_chkcount
= 0;
906 info
->dsr_chkcount
= 0;
907 info
->dcd_chkcount
= 0;
908 info
->cts_chkcount
= 0;
911 /* eom: non-zero = end of frame */
912 static void rx_ready_hdlc(MGSLPC_INFO
*info
, int eom
)
914 unsigned char data
[2];
915 unsigned char fifo_count
, read_count
, i
;
916 RXBUF
*buf
= (RXBUF
*)(info
->rx_buf
+ (info
->rx_put
* info
->rx_buf_size
));
918 if (debug_level
>= DEBUG_LEVEL_ISR
)
919 printk("%s(%d):rx_ready_hdlc(eom=%d)\n",__FILE__
,__LINE__
,eom
);
921 if (!info
->rx_enabled
)
924 if (info
->rx_frame_count
>= info
->rx_buf_count
) {
925 /* no more free buffers */
926 issue_command(info
, CHA
, CMD_RXRESET
);
927 info
->pending_bh
|= BH_RECEIVE
;
928 info
->rx_overflow
= 1;
929 info
->icount
.buf_overrun
++;
934 /* end of frame, get FIFO count from RBCL register */
935 if (!(fifo_count
= (unsigned char)(read_reg(info
, CHA
+RBCL
) & 0x1f)))
941 if (fifo_count
== 1) {
943 data
[0] = read_reg(info
, CHA
+ RXFIFO
);
946 *((unsigned short *) data
) = read_reg16(info
, CHA
+ RXFIFO
);
948 fifo_count
-= read_count
;
949 if (!fifo_count
&& eom
)
950 buf
->status
= data
[--read_count
];
952 for (i
= 0; i
< read_count
; i
++) {
953 if (buf
->count
>= info
->max_frame_size
) {
954 /* frame too large, reset receiver and reset current buffer */
955 issue_command(info
, CHA
, CMD_RXRESET
);
959 *(buf
->data
+ buf
->count
) = data
[i
];
962 } while (fifo_count
);
965 info
->pending_bh
|= BH_RECEIVE
;
966 info
->rx_frame_count
++;
968 if (info
->rx_put
>= info
->rx_buf_count
)
971 issue_command(info
, CHA
, CMD_RXFIFO
);
974 static void rx_ready_async(MGSLPC_INFO
*info
, int tcd
)
976 unsigned char data
, status
, flag
;
979 struct tty_struct
*tty
= info
->tty
;
980 struct mgsl_icount
*icount
= &info
->icount
;
983 /* early termination, get FIFO count from RBCL register */
984 fifo_count
= (unsigned char)(read_reg(info
, CHA
+RBCL
) & 0x1f);
986 /* Zero fifo count could mean 0 or 32 bytes available.
987 * If BIT5 of STAR is set then at least 1 byte is available.
989 if (!fifo_count
&& (read_reg(info
,CHA
+STAR
) & BIT5
))
994 tty_buffer_request_room(tty
, fifo_count
);
995 /* Flush received async data to receive data buffer. */
997 data
= read_reg(info
, CHA
+ RXFIFO
);
998 status
= read_reg(info
, CHA
+ RXFIFO
);
1004 // if no frameing/crc error then save data
1005 // BIT7:parity error
1006 // BIT6:framing error
1008 if (status
& (BIT7
+ BIT6
)) {
1014 /* discard char if tty control flags say so */
1015 if (status
& info
->ignore_status_mask
)
1018 status
&= info
->read_status_mask
;
1022 else if (status
& BIT6
)
1025 work
+= tty_insert_flip_char(tty
, data
, flag
);
1027 issue_command(info
, CHA
, CMD_RXFIFO
);
1029 if (debug_level
>= DEBUG_LEVEL_ISR
) {
1030 printk("%s(%d):rx_ready_async",
1032 printk("%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
1033 __FILE__
,__LINE__
,icount
->rx
,icount
->brk
,
1034 icount
->parity
,icount
->frame
,icount
->overrun
);
1038 tty_flip_buffer_push(tty
);
1042 static void tx_done(MGSLPC_INFO
*info
)
1044 if (!info
->tx_active
)
1047 info
->tx_active
= 0;
1048 info
->tx_aborting
= 0;
1050 if (info
->params
.mode
== MGSL_MODE_ASYNC
)
1053 info
->tx_count
= info
->tx_put
= info
->tx_get
= 0;
1054 del_timer(&info
->tx_timer
);
1056 if (info
->drop_rts_on_tx_done
) {
1058 if (info
->serial_signals
& SerialSignal_RTS
) {
1059 info
->serial_signals
&= ~SerialSignal_RTS
;
1062 info
->drop_rts_on_tx_done
= 0;
1067 hdlcdev_tx_done(info
);
1071 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
) {
1075 info
->pending_bh
|= BH_TRANSMIT
;
1079 static void tx_ready(MGSLPC_INFO
*info
)
1081 unsigned char fifo_count
= 32;
1084 if (debug_level
>= DEBUG_LEVEL_ISR
)
1085 printk("%s(%d):tx_ready(%s)\n", __FILE__
,__LINE__
,info
->device_name
);
1087 if (info
->params
.mode
== MGSL_MODE_HDLC
) {
1088 if (!info
->tx_active
)
1091 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
) {
1095 if (!info
->tx_count
)
1096 info
->tx_active
= 0;
1099 if (!info
->tx_count
)
1102 while (info
->tx_count
&& fifo_count
) {
1103 c
= min(2, min_t(int, fifo_count
, min(info
->tx_count
, TXBUFSIZE
- info
->tx_get
)));
1106 write_reg(info
, CHA
+ TXFIFO
, *(info
->tx_buf
+ info
->tx_get
));
1108 write_reg16(info
, CHA
+ TXFIFO
,
1109 *((unsigned short*)(info
->tx_buf
+ info
->tx_get
)));
1111 info
->tx_count
-= c
;
1112 info
->tx_get
= (info
->tx_get
+ c
) & (TXBUFSIZE
- 1);
1116 if (info
->params
.mode
== MGSL_MODE_ASYNC
) {
1117 if (info
->tx_count
< WAKEUP_CHARS
)
1118 info
->pending_bh
|= BH_TRANSMIT
;
1119 issue_command(info
, CHA
, CMD_TXFIFO
);
1122 issue_command(info
, CHA
, CMD_TXFIFO
);
1124 issue_command(info
, CHA
, CMD_TXFIFO
+ CMD_TXEOM
);
1128 static void cts_change(MGSLPC_INFO
*info
)
1131 if ((info
->cts_chkcount
)++ >= IO_PIN_SHUTDOWN_LIMIT
)
1132 irq_disable(info
, CHB
, IRQ_CTS
);
1134 if (info
->serial_signals
& SerialSignal_CTS
)
1135 info
->input_signal_events
.cts_up
++;
1137 info
->input_signal_events
.cts_down
++;
1138 wake_up_interruptible(&info
->status_event_wait_q
);
1139 wake_up_interruptible(&info
->event_wait_q
);
1141 if (info
->flags
& ASYNC_CTS_FLOW
) {
1142 if (info
->tty
->hw_stopped
) {
1143 if (info
->serial_signals
& SerialSignal_CTS
) {
1144 if (debug_level
>= DEBUG_LEVEL_ISR
)
1145 printk("CTS tx start...");
1147 info
->tty
->hw_stopped
= 0;
1149 info
->pending_bh
|= BH_TRANSMIT
;
1153 if (!(info
->serial_signals
& SerialSignal_CTS
)) {
1154 if (debug_level
>= DEBUG_LEVEL_ISR
)
1155 printk("CTS tx stop...");
1157 info
->tty
->hw_stopped
= 1;
1162 info
->pending_bh
|= BH_STATUS
;
1165 static void dcd_change(MGSLPC_INFO
*info
)
1168 if ((info
->dcd_chkcount
)++ >= IO_PIN_SHUTDOWN_LIMIT
)
1169 irq_disable(info
, CHB
, IRQ_DCD
);
1171 if (info
->serial_signals
& SerialSignal_DCD
) {
1172 info
->input_signal_events
.dcd_up
++;
1175 info
->input_signal_events
.dcd_down
++;
1177 if (info
->netcount
) {
1178 if (info
->serial_signals
& SerialSignal_DCD
)
1179 netif_carrier_on(info
->netdev
);
1181 netif_carrier_off(info
->netdev
);
1184 wake_up_interruptible(&info
->status_event_wait_q
);
1185 wake_up_interruptible(&info
->event_wait_q
);
1187 if (info
->flags
& ASYNC_CHECK_CD
) {
1188 if (debug_level
>= DEBUG_LEVEL_ISR
)
1189 printk("%s CD now %s...", info
->device_name
,
1190 (info
->serial_signals
& SerialSignal_DCD
) ? "on" : "off");
1191 if (info
->serial_signals
& SerialSignal_DCD
)
1192 wake_up_interruptible(&info
->open_wait
);
1194 if (debug_level
>= DEBUG_LEVEL_ISR
)
1195 printk("doing serial hangup...");
1197 tty_hangup(info
->tty
);
1200 info
->pending_bh
|= BH_STATUS
;
1203 static void dsr_change(MGSLPC_INFO
*info
)
1206 if ((info
->dsr_chkcount
)++ >= IO_PIN_SHUTDOWN_LIMIT
)
1207 port_irq_disable(info
, PVR_DSR
);
1209 if (info
->serial_signals
& SerialSignal_DSR
)
1210 info
->input_signal_events
.dsr_up
++;
1212 info
->input_signal_events
.dsr_down
++;
1213 wake_up_interruptible(&info
->status_event_wait_q
);
1214 wake_up_interruptible(&info
->event_wait_q
);
1215 info
->pending_bh
|= BH_STATUS
;
1218 static void ri_change(MGSLPC_INFO
*info
)
1221 if ((info
->ri_chkcount
)++ >= IO_PIN_SHUTDOWN_LIMIT
)
1222 port_irq_disable(info
, PVR_RI
);
1224 if (info
->serial_signals
& SerialSignal_RI
)
1225 info
->input_signal_events
.ri_up
++;
1227 info
->input_signal_events
.ri_down
++;
1228 wake_up_interruptible(&info
->status_event_wait_q
);
1229 wake_up_interruptible(&info
->event_wait_q
);
1230 info
->pending_bh
|= BH_STATUS
;
1233 /* Interrupt service routine entry point.
1237 * irq interrupt number that caused interrupt
1238 * dev_id device ID supplied during interrupt registration
1239 * regs interrupted processor context
1241 static irqreturn_t
mgslpc_isr(int irq
, void *dev_id
, struct pt_regs
* regs
)
1243 MGSLPC_INFO
* info
= (MGSLPC_INFO
*)dev_id
;
1245 unsigned char gis
, pis
;
1248 if (debug_level
>= DEBUG_LEVEL_ISR
)
1249 printk("mgslpc_isr(%d) entry.\n", irq
);
1253 if (!(info
->p_dev
->_locked
))
1256 spin_lock(&info
->lock
);
1258 while ((gis
= read_reg(info
, CHA
+ GIS
))) {
1259 if (debug_level
>= DEBUG_LEVEL_ISR
)
1260 printk("mgslpc_isr %s gis=%04X\n", info
->device_name
,gis
);
1262 if ((gis
& 0x70) || count
> 1000) {
1263 printk("synclink_cs:hardware failed or ejected\n");
1268 if (gis
& (BIT1
+ BIT0
)) {
1269 isr
= read_reg16(info
, CHB
+ ISR
);
1275 if (gis
& (BIT3
+ BIT2
))
1277 isr
= read_reg16(info
, CHA
+ ISR
);
1278 if (isr
& IRQ_TIMER
) {
1279 info
->irq_occurred
= 1;
1280 irq_disable(info
, CHA
, IRQ_TIMER
);
1284 if (isr
& IRQ_EXITHUNT
) {
1285 info
->icount
.exithunt
++;
1286 wake_up_interruptible(&info
->event_wait_q
);
1288 if (isr
& IRQ_BREAK_ON
) {
1290 if (info
->flags
& ASYNC_SAK
)
1293 if (isr
& IRQ_RXTIME
) {
1294 issue_command(info
, CHA
, CMD_RXFIFO_READ
);
1296 if (isr
& (IRQ_RXEOM
+ IRQ_RXFIFO
)) {
1297 if (info
->params
.mode
== MGSL_MODE_HDLC
)
1298 rx_ready_hdlc(info
, isr
& IRQ_RXEOM
);
1300 rx_ready_async(info
, isr
& IRQ_RXEOM
);
1304 if (isr
& IRQ_UNDERRUN
) {
1305 if (info
->tx_aborting
)
1306 info
->icount
.txabort
++;
1308 info
->icount
.txunder
++;
1311 else if (isr
& IRQ_ALLSENT
) {
1312 info
->icount
.txok
++;
1315 else if (isr
& IRQ_TXFIFO
)
1319 pis
= read_reg(info
, CHA
+ PIS
);
1327 /* Request bottom half processing if there's something
1328 * for it to do and the bh is not already running
1331 if (info
->pending_bh
&& !info
->bh_running
&& !info
->bh_requested
) {
1332 if ( debug_level
>= DEBUG_LEVEL_ISR
)
1333 printk("%s(%d):%s queueing bh task.\n",
1334 __FILE__
,__LINE__
,info
->device_name
);
1335 schedule_work(&info
->task
);
1336 info
->bh_requested
= 1;
1339 spin_unlock(&info
->lock
);
1341 if (debug_level
>= DEBUG_LEVEL_ISR
)
1342 printk("%s(%d):mgslpc_isr(%d)exit.\n",
1343 __FILE__
,__LINE__
,irq
);
1348 /* Initialize and start device.
1350 static int startup(MGSLPC_INFO
* info
)
1354 if (debug_level
>= DEBUG_LEVEL_INFO
)
1355 printk("%s(%d):startup(%s)\n",__FILE__
,__LINE__
,info
->device_name
);
1357 if (info
->flags
& ASYNC_INITIALIZED
)
1360 if (!info
->tx_buf
) {
1361 /* allocate a page of memory for a transmit buffer */
1362 info
->tx_buf
= (unsigned char *)get_zeroed_page(GFP_KERNEL
);
1363 if (!info
->tx_buf
) {
1364 printk(KERN_ERR
"%s(%d):%s can't allocate transmit buffer\n",
1365 __FILE__
,__LINE__
,info
->device_name
);
1370 info
->pending_bh
= 0;
1372 memset(&info
->icount
, 0, sizeof(info
->icount
));
1374 init_timer(&info
->tx_timer
);
1375 info
->tx_timer
.data
= (unsigned long)info
;
1376 info
->tx_timer
.function
= tx_timeout
;
1378 /* Allocate and claim adapter resources */
1379 retval
= claim_resources(info
);
1381 /* perform existance check and diagnostics */
1383 retval
= adapter_test(info
);
1386 if (capable(CAP_SYS_ADMIN
) && info
->tty
)
1387 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1388 release_resources(info
);
1392 /* program hardware for current parameters */
1393 mgslpc_change_params(info
);
1396 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1398 info
->flags
|= ASYNC_INITIALIZED
;
1403 /* Called by mgslpc_close() and mgslpc_hangup() to shutdown hardware
1405 static void shutdown(MGSLPC_INFO
* info
)
1407 unsigned long flags
;
1409 if (!(info
->flags
& ASYNC_INITIALIZED
))
1412 if (debug_level
>= DEBUG_LEVEL_INFO
)
1413 printk("%s(%d):mgslpc_shutdown(%s)\n",
1414 __FILE__
,__LINE__
, info
->device_name
);
1416 /* clear status wait queue because status changes */
1417 /* can't happen after shutting down the hardware */
1418 wake_up_interruptible(&info
->status_event_wait_q
);
1419 wake_up_interruptible(&info
->event_wait_q
);
1421 del_timer(&info
->tx_timer
);
1424 free_page((unsigned long) info
->tx_buf
);
1425 info
->tx_buf
= NULL
;
1428 spin_lock_irqsave(&info
->lock
,flags
);
1433 /* TODO:disable interrupts instead of reset to preserve signal states */
1436 if (!info
->tty
|| info
->tty
->termios
->c_cflag
& HUPCL
) {
1437 info
->serial_signals
&= ~(SerialSignal_DTR
+ SerialSignal_RTS
);
1441 spin_unlock_irqrestore(&info
->lock
,flags
);
1443 release_resources(info
);
1446 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1448 info
->flags
&= ~ASYNC_INITIALIZED
;
1451 static void mgslpc_program_hw(MGSLPC_INFO
*info
)
1453 unsigned long flags
;
1455 spin_lock_irqsave(&info
->lock
,flags
);
1459 info
->tx_count
= info
->tx_put
= info
->tx_get
= 0;
1461 if (info
->params
.mode
== MGSL_MODE_HDLC
|| info
->netcount
)
1468 info
->dcd_chkcount
= 0;
1469 info
->cts_chkcount
= 0;
1470 info
->ri_chkcount
= 0;
1471 info
->dsr_chkcount
= 0;
1473 irq_enable(info
, CHB
, IRQ_DCD
| IRQ_CTS
);
1474 port_irq_enable(info
, (unsigned char) PVR_DSR
| PVR_RI
);
1477 if (info
->netcount
|| info
->tty
->termios
->c_cflag
& CREAD
)
1480 spin_unlock_irqrestore(&info
->lock
,flags
);
1483 /* Reconfigure adapter based on new parameters
1485 static void mgslpc_change_params(MGSLPC_INFO
*info
)
1490 if (!info
->tty
|| !info
->tty
->termios
)
1493 if (debug_level
>= DEBUG_LEVEL_INFO
)
1494 printk("%s(%d):mgslpc_change_params(%s)\n",
1495 __FILE__
,__LINE__
, info
->device_name
);
1497 cflag
= info
->tty
->termios
->c_cflag
;
1499 /* if B0 rate (hangup) specified then negate DTR and RTS */
1500 /* otherwise assert DTR and RTS */
1502 info
->serial_signals
|= SerialSignal_RTS
+ SerialSignal_DTR
;
1504 info
->serial_signals
&= ~(SerialSignal_RTS
+ SerialSignal_DTR
);
1506 /* byte size and parity */
1508 switch (cflag
& CSIZE
) {
1509 case CS5
: info
->params
.data_bits
= 5; break;
1510 case CS6
: info
->params
.data_bits
= 6; break;
1511 case CS7
: info
->params
.data_bits
= 7; break;
1512 case CS8
: info
->params
.data_bits
= 8; break;
1513 default: info
->params
.data_bits
= 7; break;
1517 info
->params
.stop_bits
= 2;
1519 info
->params
.stop_bits
= 1;
1521 info
->params
.parity
= ASYNC_PARITY_NONE
;
1522 if (cflag
& PARENB
) {
1524 info
->params
.parity
= ASYNC_PARITY_ODD
;
1526 info
->params
.parity
= ASYNC_PARITY_EVEN
;
1529 info
->params
.parity
= ASYNC_PARITY_SPACE
;
1533 /* calculate number of jiffies to transmit a full
1534 * FIFO (32 bytes) at specified data rate
1536 bits_per_char
= info
->params
.data_bits
+
1537 info
->params
.stop_bits
+ 1;
1539 /* if port data rate is set to 460800 or less then
1540 * allow tty settings to override, otherwise keep the
1541 * current data rate.
1543 if (info
->params
.data_rate
<= 460800) {
1544 info
->params
.data_rate
= tty_get_baud_rate(info
->tty
);
1547 if ( info
->params
.data_rate
) {
1548 info
->timeout
= (32*HZ
*bits_per_char
) /
1549 info
->params
.data_rate
;
1551 info
->timeout
+= HZ
/50; /* Add .02 seconds of slop */
1553 if (cflag
& CRTSCTS
)
1554 info
->flags
|= ASYNC_CTS_FLOW
;
1556 info
->flags
&= ~ASYNC_CTS_FLOW
;
1559 info
->flags
&= ~ASYNC_CHECK_CD
;
1561 info
->flags
|= ASYNC_CHECK_CD
;
1563 /* process tty input control flags */
1565 info
->read_status_mask
= 0;
1566 if (I_INPCK(info
->tty
))
1567 info
->read_status_mask
|= BIT7
| BIT6
;
1568 if (I_IGNPAR(info
->tty
))
1569 info
->ignore_status_mask
|= BIT7
| BIT6
;
1571 mgslpc_program_hw(info
);
1574 /* Add a character to the transmit buffer
1576 static void mgslpc_put_char(struct tty_struct
*tty
, unsigned char ch
)
1578 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1579 unsigned long flags
;
1581 if (debug_level
>= DEBUG_LEVEL_INFO
) {
1582 printk( "%s(%d):mgslpc_put_char(%d) on %s\n",
1583 __FILE__
,__LINE__
,ch
,info
->device_name
);
1586 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_put_char"))
1592 spin_lock_irqsave(&info
->lock
,flags
);
1594 if (info
->params
.mode
== MGSL_MODE_ASYNC
|| !info
->tx_active
) {
1595 if (info
->tx_count
< TXBUFSIZE
- 1) {
1596 info
->tx_buf
[info
->tx_put
++] = ch
;
1597 info
->tx_put
&= TXBUFSIZE
-1;
1602 spin_unlock_irqrestore(&info
->lock
,flags
);
1605 /* Enable transmitter so remaining characters in the
1606 * transmit buffer are sent.
1608 static void mgslpc_flush_chars(struct tty_struct
*tty
)
1610 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1611 unsigned long flags
;
1613 if (debug_level
>= DEBUG_LEVEL_INFO
)
1614 printk( "%s(%d):mgslpc_flush_chars() entry on %s tx_count=%d\n",
1615 __FILE__
,__LINE__
,info
->device_name
,info
->tx_count
);
1617 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_flush_chars"))
1620 if (info
->tx_count
<= 0 || tty
->stopped
||
1621 tty
->hw_stopped
|| !info
->tx_buf
)
1624 if (debug_level
>= DEBUG_LEVEL_INFO
)
1625 printk( "%s(%d):mgslpc_flush_chars() entry on %s starting transmitter\n",
1626 __FILE__
,__LINE__
,info
->device_name
);
1628 spin_lock_irqsave(&info
->lock
,flags
);
1629 if (!info
->tx_active
)
1631 spin_unlock_irqrestore(&info
->lock
,flags
);
1634 /* Send a block of data
1638 * tty pointer to tty information structure
1639 * buf pointer to buffer containing send data
1640 * count size of send data in bytes
1642 * Returns: number of characters written
1644 static int mgslpc_write(struct tty_struct
* tty
,
1645 const unsigned char *buf
, int count
)
1648 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1649 unsigned long flags
;
1651 if (debug_level
>= DEBUG_LEVEL_INFO
)
1652 printk( "%s(%d):mgslpc_write(%s) count=%d\n",
1653 __FILE__
,__LINE__
,info
->device_name
,count
);
1655 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_write") ||
1659 if (info
->params
.mode
== MGSL_MODE_HDLC
) {
1660 if (count
> TXBUFSIZE
) {
1664 if (info
->tx_active
)
1666 else if (info
->tx_count
)
1672 min(TXBUFSIZE
- info
->tx_count
- 1,
1673 TXBUFSIZE
- info
->tx_put
));
1677 memcpy(info
->tx_buf
+ info
->tx_put
, buf
, c
);
1679 spin_lock_irqsave(&info
->lock
,flags
);
1680 info
->tx_put
= (info
->tx_put
+ c
) & (TXBUFSIZE
-1);
1681 info
->tx_count
+= c
;
1682 spin_unlock_irqrestore(&info
->lock
,flags
);
1689 if (info
->tx_count
&& !tty
->stopped
&& !tty
->hw_stopped
) {
1690 spin_lock_irqsave(&info
->lock
,flags
);
1691 if (!info
->tx_active
)
1693 spin_unlock_irqrestore(&info
->lock
,flags
);
1696 if (debug_level
>= DEBUG_LEVEL_INFO
)
1697 printk( "%s(%d):mgslpc_write(%s) returning=%d\n",
1698 __FILE__
,__LINE__
,info
->device_name
,ret
);
1702 /* Return the count of free bytes in transmit buffer
1704 static int mgslpc_write_room(struct tty_struct
*tty
)
1706 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1709 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_write_room"))
1712 if (info
->params
.mode
== MGSL_MODE_HDLC
) {
1713 /* HDLC (frame oriented) mode */
1714 if (info
->tx_active
)
1717 return HDLC_MAX_FRAME_SIZE
;
1719 ret
= TXBUFSIZE
- info
->tx_count
- 1;
1724 if (debug_level
>= DEBUG_LEVEL_INFO
)
1725 printk("%s(%d):mgslpc_write_room(%s)=%d\n",
1726 __FILE__
,__LINE__
, info
->device_name
, ret
);
1730 /* Return the count of bytes in transmit buffer
1732 static int mgslpc_chars_in_buffer(struct tty_struct
*tty
)
1734 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1737 if (debug_level
>= DEBUG_LEVEL_INFO
)
1738 printk("%s(%d):mgslpc_chars_in_buffer(%s)\n",
1739 __FILE__
,__LINE__
, info
->device_name
);
1741 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_chars_in_buffer"))
1744 if (info
->params
.mode
== MGSL_MODE_HDLC
)
1745 rc
= info
->tx_active
? info
->max_frame_size
: 0;
1747 rc
= info
->tx_count
;
1749 if (debug_level
>= DEBUG_LEVEL_INFO
)
1750 printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n",
1751 __FILE__
,__LINE__
, info
->device_name
, rc
);
1756 /* Discard all data in the send buffer
1758 static void mgslpc_flush_buffer(struct tty_struct
*tty
)
1760 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1761 unsigned long flags
;
1763 if (debug_level
>= DEBUG_LEVEL_INFO
)
1764 printk("%s(%d):mgslpc_flush_buffer(%s) entry\n",
1765 __FILE__
,__LINE__
, info
->device_name
);
1767 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_flush_buffer"))
1770 spin_lock_irqsave(&info
->lock
,flags
);
1771 info
->tx_count
= info
->tx_put
= info
->tx_get
= 0;
1772 del_timer(&info
->tx_timer
);
1773 spin_unlock_irqrestore(&info
->lock
,flags
);
1775 wake_up_interruptible(&tty
->write_wait
);
1779 /* Send a high-priority XON/XOFF character
1781 static void mgslpc_send_xchar(struct tty_struct
*tty
, char ch
)
1783 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1784 unsigned long flags
;
1786 if (debug_level
>= DEBUG_LEVEL_INFO
)
1787 printk("%s(%d):mgslpc_send_xchar(%s,%d)\n",
1788 __FILE__
,__LINE__
, info
->device_name
, ch
);
1790 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_send_xchar"))
1795 spin_lock_irqsave(&info
->lock
,flags
);
1796 if (!info
->tx_enabled
)
1798 spin_unlock_irqrestore(&info
->lock
,flags
);
1802 /* Signal remote device to throttle send data (our receive data)
1804 static void mgslpc_throttle(struct tty_struct
* tty
)
1806 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1807 unsigned long flags
;
1809 if (debug_level
>= DEBUG_LEVEL_INFO
)
1810 printk("%s(%d):mgslpc_throttle(%s) entry\n",
1811 __FILE__
,__LINE__
, info
->device_name
);
1813 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_throttle"))
1817 mgslpc_send_xchar(tty
, STOP_CHAR(tty
));
1819 if (tty
->termios
->c_cflag
& CRTSCTS
) {
1820 spin_lock_irqsave(&info
->lock
,flags
);
1821 info
->serial_signals
&= ~SerialSignal_RTS
;
1823 spin_unlock_irqrestore(&info
->lock
,flags
);
1827 /* Signal remote device to stop throttling send data (our receive data)
1829 static void mgslpc_unthrottle(struct tty_struct
* tty
)
1831 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
1832 unsigned long flags
;
1834 if (debug_level
>= DEBUG_LEVEL_INFO
)
1835 printk("%s(%d):mgslpc_unthrottle(%s) entry\n",
1836 __FILE__
,__LINE__
, info
->device_name
);
1838 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_unthrottle"))
1845 mgslpc_send_xchar(tty
, START_CHAR(tty
));
1848 if (tty
->termios
->c_cflag
& CRTSCTS
) {
1849 spin_lock_irqsave(&info
->lock
,flags
);
1850 info
->serial_signals
|= SerialSignal_RTS
;
1852 spin_unlock_irqrestore(&info
->lock
,flags
);
1856 /* get the current serial statistics
1858 static int get_stats(MGSLPC_INFO
* info
, struct mgsl_icount __user
*user_icount
)
1861 if (debug_level
>= DEBUG_LEVEL_INFO
)
1862 printk("get_params(%s)\n", info
->device_name
);
1864 memset(&info
->icount
, 0, sizeof(info
->icount
));
1866 COPY_TO_USER(err
, user_icount
, &info
->icount
, sizeof(struct mgsl_icount
));
1873 /* get the current serial parameters
1875 static int get_params(MGSLPC_INFO
* info
, MGSL_PARAMS __user
*user_params
)
1878 if (debug_level
>= DEBUG_LEVEL_INFO
)
1879 printk("get_params(%s)\n", info
->device_name
);
1880 COPY_TO_USER(err
,user_params
, &info
->params
, sizeof(MGSL_PARAMS
));
1886 /* set the serial parameters
1890 * info pointer to device instance data
1891 * new_params user buffer containing new serial params
1893 * Returns: 0 if success, otherwise error code
1895 static int set_params(MGSLPC_INFO
* info
, MGSL_PARAMS __user
*new_params
)
1897 unsigned long flags
;
1898 MGSL_PARAMS tmp_params
;
1901 if (debug_level
>= DEBUG_LEVEL_INFO
)
1902 printk("%s(%d):set_params %s\n", __FILE__
,__LINE__
,
1903 info
->device_name
);
1904 COPY_FROM_USER(err
,&tmp_params
, new_params
, sizeof(MGSL_PARAMS
));
1906 if ( debug_level
>= DEBUG_LEVEL_INFO
)
1907 printk( "%s(%d):set_params(%s) user buffer copy failed\n",
1908 __FILE__
,__LINE__
,info
->device_name
);
1912 spin_lock_irqsave(&info
->lock
,flags
);
1913 memcpy(&info
->params
,&tmp_params
,sizeof(MGSL_PARAMS
));
1914 spin_unlock_irqrestore(&info
->lock
,flags
);
1916 mgslpc_change_params(info
);
1921 static int get_txidle(MGSLPC_INFO
* info
, int __user
*idle_mode
)
1924 if (debug_level
>= DEBUG_LEVEL_INFO
)
1925 printk("get_txidle(%s)=%d\n", info
->device_name
, info
->idle_mode
);
1926 COPY_TO_USER(err
,idle_mode
, &info
->idle_mode
, sizeof(int));
1932 static int set_txidle(MGSLPC_INFO
* info
, int idle_mode
)
1934 unsigned long flags
;
1935 if (debug_level
>= DEBUG_LEVEL_INFO
)
1936 printk("set_txidle(%s,%d)\n", info
->device_name
, idle_mode
);
1937 spin_lock_irqsave(&info
->lock
,flags
);
1938 info
->idle_mode
= idle_mode
;
1940 spin_unlock_irqrestore(&info
->lock
,flags
);
1944 static int get_interface(MGSLPC_INFO
* info
, int __user
*if_mode
)
1947 if (debug_level
>= DEBUG_LEVEL_INFO
)
1948 printk("get_interface(%s)=%d\n", info
->device_name
, info
->if_mode
);
1949 COPY_TO_USER(err
,if_mode
, &info
->if_mode
, sizeof(int));
1955 static int set_interface(MGSLPC_INFO
* info
, int if_mode
)
1957 unsigned long flags
;
1959 if (debug_level
>= DEBUG_LEVEL_INFO
)
1960 printk("set_interface(%s,%d)\n", info
->device_name
, if_mode
);
1961 spin_lock_irqsave(&info
->lock
,flags
);
1962 info
->if_mode
= if_mode
;
1964 val
= read_reg(info
, PVR
) & 0x0f;
1965 switch (info
->if_mode
)
1967 case MGSL_INTERFACE_RS232
: val
|= PVR_RS232
; break;
1968 case MGSL_INTERFACE_V35
: val
|= PVR_V35
; break;
1969 case MGSL_INTERFACE_RS422
: val
|= PVR_RS422
; break;
1971 write_reg(info
, PVR
, val
);
1973 spin_unlock_irqrestore(&info
->lock
,flags
);
1977 static int set_txenable(MGSLPC_INFO
* info
, int enable
)
1979 unsigned long flags
;
1981 if (debug_level
>= DEBUG_LEVEL_INFO
)
1982 printk("set_txenable(%s,%d)\n", info
->device_name
, enable
);
1984 spin_lock_irqsave(&info
->lock
,flags
);
1986 if (!info
->tx_enabled
)
1989 if (info
->tx_enabled
)
1992 spin_unlock_irqrestore(&info
->lock
,flags
);
1996 static int tx_abort(MGSLPC_INFO
* info
)
1998 unsigned long flags
;
2000 if (debug_level
>= DEBUG_LEVEL_INFO
)
2001 printk("tx_abort(%s)\n", info
->device_name
);
2003 spin_lock_irqsave(&info
->lock
,flags
);
2004 if (info
->tx_active
&& info
->tx_count
&&
2005 info
->params
.mode
== MGSL_MODE_HDLC
) {
2006 /* clear data count so FIFO is not filled on next IRQ.
2007 * This results in underrun and abort transmission.
2009 info
->tx_count
= info
->tx_put
= info
->tx_get
= 0;
2010 info
->tx_aborting
= TRUE
;
2012 spin_unlock_irqrestore(&info
->lock
,flags
);
2016 static int set_rxenable(MGSLPC_INFO
* info
, int enable
)
2018 unsigned long flags
;
2020 if (debug_level
>= DEBUG_LEVEL_INFO
)
2021 printk("set_rxenable(%s,%d)\n", info
->device_name
, enable
);
2023 spin_lock_irqsave(&info
->lock
,flags
);
2025 if (!info
->rx_enabled
)
2028 if (info
->rx_enabled
)
2031 spin_unlock_irqrestore(&info
->lock
,flags
);
2035 /* wait for specified event to occur
2037 * Arguments: info pointer to device instance data
2038 * mask pointer to bitmask of events to wait for
2039 * Return Value: 0 if successful and bit mask updated with
2040 * of events triggerred,
2041 * otherwise error code
2043 static int wait_events(MGSLPC_INFO
* info
, int __user
*mask_ptr
)
2045 unsigned long flags
;
2048 struct mgsl_icount cprev
, cnow
;
2051 struct _input_signal_events oldsigs
, newsigs
;
2052 DECLARE_WAITQUEUE(wait
, current
);
2054 COPY_FROM_USER(rc
,&mask
, mask_ptr
, sizeof(int));
2058 if (debug_level
>= DEBUG_LEVEL_INFO
)
2059 printk("wait_events(%s,%d)\n", info
->device_name
, mask
);
2061 spin_lock_irqsave(&info
->lock
,flags
);
2063 /* return immediately if state matches requested events */
2065 s
= info
->serial_signals
;
2067 ( ((s
& SerialSignal_DSR
) ? MgslEvent_DsrActive
:MgslEvent_DsrInactive
) +
2068 ((s
& SerialSignal_DCD
) ? MgslEvent_DcdActive
:MgslEvent_DcdInactive
) +
2069 ((s
& SerialSignal_CTS
) ? MgslEvent_CtsActive
:MgslEvent_CtsInactive
) +
2070 ((s
& SerialSignal_RI
) ? MgslEvent_RiActive
:MgslEvent_RiInactive
) );
2072 spin_unlock_irqrestore(&info
->lock
,flags
);
2076 /* save current irq counts */
2077 cprev
= info
->icount
;
2078 oldsigs
= info
->input_signal_events
;
2080 if ((info
->params
.mode
== MGSL_MODE_HDLC
) &&
2081 (mask
& MgslEvent_ExitHuntMode
))
2082 irq_enable(info
, CHA
, IRQ_EXITHUNT
);
2084 set_current_state(TASK_INTERRUPTIBLE
);
2085 add_wait_queue(&info
->event_wait_q
, &wait
);
2087 spin_unlock_irqrestore(&info
->lock
,flags
);
2092 if (signal_pending(current
)) {
2097 /* get current irq counts */
2098 spin_lock_irqsave(&info
->lock
,flags
);
2099 cnow
= info
->icount
;
2100 newsigs
= info
->input_signal_events
;
2101 set_current_state(TASK_INTERRUPTIBLE
);
2102 spin_unlock_irqrestore(&info
->lock
,flags
);
2104 /* if no change, wait aborted for some reason */
2105 if (newsigs
.dsr_up
== oldsigs
.dsr_up
&&
2106 newsigs
.dsr_down
== oldsigs
.dsr_down
&&
2107 newsigs
.dcd_up
== oldsigs
.dcd_up
&&
2108 newsigs
.dcd_down
== oldsigs
.dcd_down
&&
2109 newsigs
.cts_up
== oldsigs
.cts_up
&&
2110 newsigs
.cts_down
== oldsigs
.cts_down
&&
2111 newsigs
.ri_up
== oldsigs
.ri_up
&&
2112 newsigs
.ri_down
== oldsigs
.ri_down
&&
2113 cnow
.exithunt
== cprev
.exithunt
&&
2114 cnow
.rxidle
== cprev
.rxidle
) {
2120 ( (newsigs
.dsr_up
!= oldsigs
.dsr_up
? MgslEvent_DsrActive
:0) +
2121 (newsigs
.dsr_down
!= oldsigs
.dsr_down
? MgslEvent_DsrInactive
:0) +
2122 (newsigs
.dcd_up
!= oldsigs
.dcd_up
? MgslEvent_DcdActive
:0) +
2123 (newsigs
.dcd_down
!= oldsigs
.dcd_down
? MgslEvent_DcdInactive
:0) +
2124 (newsigs
.cts_up
!= oldsigs
.cts_up
? MgslEvent_CtsActive
:0) +
2125 (newsigs
.cts_down
!= oldsigs
.cts_down
? MgslEvent_CtsInactive
:0) +
2126 (newsigs
.ri_up
!= oldsigs
.ri_up
? MgslEvent_RiActive
:0) +
2127 (newsigs
.ri_down
!= oldsigs
.ri_down
? MgslEvent_RiInactive
:0) +
2128 (cnow
.exithunt
!= cprev
.exithunt
? MgslEvent_ExitHuntMode
:0) +
2129 (cnow
.rxidle
!= cprev
.rxidle
? MgslEvent_IdleReceived
:0) );
2137 remove_wait_queue(&info
->event_wait_q
, &wait
);
2138 set_current_state(TASK_RUNNING
);
2140 if (mask
& MgslEvent_ExitHuntMode
) {
2141 spin_lock_irqsave(&info
->lock
,flags
);
2142 if (!waitqueue_active(&info
->event_wait_q
))
2143 irq_disable(info
, CHA
, IRQ_EXITHUNT
);
2144 spin_unlock_irqrestore(&info
->lock
,flags
);
2148 PUT_USER(rc
, events
, mask_ptr
);
2152 static int modem_input_wait(MGSLPC_INFO
*info
,int arg
)
2154 unsigned long flags
;
2156 struct mgsl_icount cprev
, cnow
;
2157 DECLARE_WAITQUEUE(wait
, current
);
2159 /* save current irq counts */
2160 spin_lock_irqsave(&info
->lock
,flags
);
2161 cprev
= info
->icount
;
2162 add_wait_queue(&info
->status_event_wait_q
, &wait
);
2163 set_current_state(TASK_INTERRUPTIBLE
);
2164 spin_unlock_irqrestore(&info
->lock
,flags
);
2168 if (signal_pending(current
)) {
2173 /* get new irq counts */
2174 spin_lock_irqsave(&info
->lock
,flags
);
2175 cnow
= info
->icount
;
2176 set_current_state(TASK_INTERRUPTIBLE
);
2177 spin_unlock_irqrestore(&info
->lock
,flags
);
2179 /* if no change, wait aborted for some reason */
2180 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
2181 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
2186 /* check for change in caller specified modem input */
2187 if ((arg
& TIOCM_RNG
&& cnow
.rng
!= cprev
.rng
) ||
2188 (arg
& TIOCM_DSR
&& cnow
.dsr
!= cprev
.dsr
) ||
2189 (arg
& TIOCM_CD
&& cnow
.dcd
!= cprev
.dcd
) ||
2190 (arg
& TIOCM_CTS
&& cnow
.cts
!= cprev
.cts
)) {
2197 remove_wait_queue(&info
->status_event_wait_q
, &wait
);
2198 set_current_state(TASK_RUNNING
);
2202 /* return the state of the serial control and status signals
2204 static int tiocmget(struct tty_struct
*tty
, struct file
*file
)
2206 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
2207 unsigned int result
;
2208 unsigned long flags
;
2210 spin_lock_irqsave(&info
->lock
,flags
);
2212 spin_unlock_irqrestore(&info
->lock
,flags
);
2214 result
= ((info
->serial_signals
& SerialSignal_RTS
) ? TIOCM_RTS
:0) +
2215 ((info
->serial_signals
& SerialSignal_DTR
) ? TIOCM_DTR
:0) +
2216 ((info
->serial_signals
& SerialSignal_DCD
) ? TIOCM_CAR
:0) +
2217 ((info
->serial_signals
& SerialSignal_RI
) ? TIOCM_RNG
:0) +
2218 ((info
->serial_signals
& SerialSignal_DSR
) ? TIOCM_DSR
:0) +
2219 ((info
->serial_signals
& SerialSignal_CTS
) ? TIOCM_CTS
:0);
2221 if (debug_level
>= DEBUG_LEVEL_INFO
)
2222 printk("%s(%d):%s tiocmget() value=%08X\n",
2223 __FILE__
,__LINE__
, info
->device_name
, result
);
2227 /* set modem control signals (DTR/RTS)
2229 static int tiocmset(struct tty_struct
*tty
, struct file
*file
,
2230 unsigned int set
, unsigned int clear
)
2232 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
2233 unsigned long flags
;
2235 if (debug_level
>= DEBUG_LEVEL_INFO
)
2236 printk("%s(%d):%s tiocmset(%x,%x)\n",
2237 __FILE__
,__LINE__
,info
->device_name
, set
, clear
);
2239 if (set
& TIOCM_RTS
)
2240 info
->serial_signals
|= SerialSignal_RTS
;
2241 if (set
& TIOCM_DTR
)
2242 info
->serial_signals
|= SerialSignal_DTR
;
2243 if (clear
& TIOCM_RTS
)
2244 info
->serial_signals
&= ~SerialSignal_RTS
;
2245 if (clear
& TIOCM_DTR
)
2246 info
->serial_signals
&= ~SerialSignal_DTR
;
2248 spin_lock_irqsave(&info
->lock
,flags
);
2250 spin_unlock_irqrestore(&info
->lock
,flags
);
2255 /* Set or clear transmit break condition
2257 * Arguments: tty pointer to tty instance data
2258 * break_state -1=set break condition, 0=clear
2260 static void mgslpc_break(struct tty_struct
*tty
, int break_state
)
2262 MGSLPC_INFO
* info
= (MGSLPC_INFO
*)tty
->driver_data
;
2263 unsigned long flags
;
2265 if (debug_level
>= DEBUG_LEVEL_INFO
)
2266 printk("%s(%d):mgslpc_break(%s,%d)\n",
2267 __FILE__
,__LINE__
, info
->device_name
, break_state
);
2269 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_break"))
2272 spin_lock_irqsave(&info
->lock
,flags
);
2273 if (break_state
== -1)
2274 set_reg_bits(info
, CHA
+DAFO
, BIT6
);
2276 clear_reg_bits(info
, CHA
+DAFO
, BIT6
);
2277 spin_unlock_irqrestore(&info
->lock
,flags
);
2280 /* Service an IOCTL request
2284 * tty pointer to tty instance data
2285 * file pointer to associated file object for device
2286 * cmd IOCTL command code
2287 * arg command argument/context
2289 * Return Value: 0 if success, otherwise error code
2291 static int mgslpc_ioctl(struct tty_struct
*tty
, struct file
* file
,
2292 unsigned int cmd
, unsigned long arg
)
2294 MGSLPC_INFO
* info
= (MGSLPC_INFO
*)tty
->driver_data
;
2296 if (debug_level
>= DEBUG_LEVEL_INFO
)
2297 printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__
,__LINE__
,
2298 info
->device_name
, cmd
);
2300 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_ioctl"))
2303 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
2304 (cmd
!= TIOCMIWAIT
) && (cmd
!= TIOCGICOUNT
)) {
2305 if (tty
->flags
& (1 << TTY_IO_ERROR
))
2309 return ioctl_common(info
, cmd
, arg
);
2312 static int ioctl_common(MGSLPC_INFO
*info
, unsigned int cmd
, unsigned long arg
)
2315 struct mgsl_icount cnow
; /* kernel counter temps */
2316 struct serial_icounter_struct __user
*p_cuser
; /* user space */
2317 void __user
*argp
= (void __user
*)arg
;
2318 unsigned long flags
;
2321 case MGSL_IOCGPARAMS
:
2322 return get_params(info
, argp
);
2323 case MGSL_IOCSPARAMS
:
2324 return set_params(info
, argp
);
2325 case MGSL_IOCGTXIDLE
:
2326 return get_txidle(info
, argp
);
2327 case MGSL_IOCSTXIDLE
:
2328 return set_txidle(info
, (int)arg
);
2330 return get_interface(info
, argp
);
2332 return set_interface(info
,(int)arg
);
2333 case MGSL_IOCTXENABLE
:
2334 return set_txenable(info
,(int)arg
);
2335 case MGSL_IOCRXENABLE
:
2336 return set_rxenable(info
,(int)arg
);
2337 case MGSL_IOCTXABORT
:
2338 return tx_abort(info
);
2339 case MGSL_IOCGSTATS
:
2340 return get_stats(info
, argp
);
2341 case MGSL_IOCWAITEVENT
:
2342 return wait_events(info
, argp
);
2344 return modem_input_wait(info
,(int)arg
);
2346 spin_lock_irqsave(&info
->lock
,flags
);
2347 cnow
= info
->icount
;
2348 spin_unlock_irqrestore(&info
->lock
,flags
);
2350 PUT_USER(error
,cnow
.cts
, &p_cuser
->cts
);
2351 if (error
) return error
;
2352 PUT_USER(error
,cnow
.dsr
, &p_cuser
->dsr
);
2353 if (error
) return error
;
2354 PUT_USER(error
,cnow
.rng
, &p_cuser
->rng
);
2355 if (error
) return error
;
2356 PUT_USER(error
,cnow
.dcd
, &p_cuser
->dcd
);
2357 if (error
) return error
;
2358 PUT_USER(error
,cnow
.rx
, &p_cuser
->rx
);
2359 if (error
) return error
;
2360 PUT_USER(error
,cnow
.tx
, &p_cuser
->tx
);
2361 if (error
) return error
;
2362 PUT_USER(error
,cnow
.frame
, &p_cuser
->frame
);
2363 if (error
) return error
;
2364 PUT_USER(error
,cnow
.overrun
, &p_cuser
->overrun
);
2365 if (error
) return error
;
2366 PUT_USER(error
,cnow
.parity
, &p_cuser
->parity
);
2367 if (error
) return error
;
2368 PUT_USER(error
,cnow
.brk
, &p_cuser
->brk
);
2369 if (error
) return error
;
2370 PUT_USER(error
,cnow
.buf_overrun
, &p_cuser
->buf_overrun
);
2371 if (error
) return error
;
2374 return -ENOIOCTLCMD
;
2379 /* Set new termios settings
2383 * tty pointer to tty structure
2384 * termios pointer to buffer to hold returned old termios
2386 static void mgslpc_set_termios(struct tty_struct
*tty
, struct termios
*old_termios
)
2388 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)tty
->driver_data
;
2389 unsigned long flags
;
2391 if (debug_level
>= DEBUG_LEVEL_INFO
)
2392 printk("%s(%d):mgslpc_set_termios %s\n", __FILE__
,__LINE__
,
2393 tty
->driver
->name
);
2395 /* just return if nothing has changed */
2396 if ((tty
->termios
->c_cflag
== old_termios
->c_cflag
)
2397 && (RELEVANT_IFLAG(tty
->termios
->c_iflag
)
2398 == RELEVANT_IFLAG(old_termios
->c_iflag
)))
2401 mgslpc_change_params(info
);
2403 /* Handle transition to B0 status */
2404 if (old_termios
->c_cflag
& CBAUD
&&
2405 !(tty
->termios
->c_cflag
& CBAUD
)) {
2406 info
->serial_signals
&= ~(SerialSignal_RTS
+ SerialSignal_DTR
);
2407 spin_lock_irqsave(&info
->lock
,flags
);
2409 spin_unlock_irqrestore(&info
->lock
,flags
);
2412 /* Handle transition away from B0 status */
2413 if (!(old_termios
->c_cflag
& CBAUD
) &&
2414 tty
->termios
->c_cflag
& CBAUD
) {
2415 info
->serial_signals
|= SerialSignal_DTR
;
2416 if (!(tty
->termios
->c_cflag
& CRTSCTS
) ||
2417 !test_bit(TTY_THROTTLED
, &tty
->flags
)) {
2418 info
->serial_signals
|= SerialSignal_RTS
;
2420 spin_lock_irqsave(&info
->lock
,flags
);
2422 spin_unlock_irqrestore(&info
->lock
,flags
);
2425 /* Handle turning off CRTSCTS */
2426 if (old_termios
->c_cflag
& CRTSCTS
&&
2427 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
2428 tty
->hw_stopped
= 0;
2433 static void mgslpc_close(struct tty_struct
*tty
, struct file
* filp
)
2435 MGSLPC_INFO
* info
= (MGSLPC_INFO
*)tty
->driver_data
;
2437 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_close"))
2440 if (debug_level
>= DEBUG_LEVEL_INFO
)
2441 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
2442 __FILE__
,__LINE__
, info
->device_name
, info
->count
);
2447 if (tty_hung_up_p(filp
))
2450 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2452 * tty->count is 1 and the tty structure will be freed.
2453 * info->count should be one in this case.
2454 * if it's not, correct it so that the port is shutdown.
2456 printk("mgslpc_close: bad refcount; tty->count is 1, "
2457 "info->count is %d\n", info
->count
);
2463 /* if at least one open remaining, leave hardware active */
2467 info
->flags
|= ASYNC_CLOSING
;
2469 /* set tty->closing to notify line discipline to
2470 * only process XON/XOFF characters. Only the N_TTY
2471 * discipline appears to use this (ppp does not).
2475 /* wait for transmit data to clear all layers */
2477 if (info
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
) {
2478 if (debug_level
>= DEBUG_LEVEL_INFO
)
2479 printk("%s(%d):mgslpc_close(%s) calling tty_wait_until_sent\n",
2480 __FILE__
,__LINE__
, info
->device_name
);
2481 tty_wait_until_sent(tty
, info
->closing_wait
);
2484 if (info
->flags
& ASYNC_INITIALIZED
)
2485 mgslpc_wait_until_sent(tty
, info
->timeout
);
2487 if (tty
->driver
->flush_buffer
)
2488 tty
->driver
->flush_buffer(tty
);
2490 ldisc_flush_buffer(tty
);
2497 if (info
->blocked_open
) {
2498 if (info
->close_delay
) {
2499 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
2501 wake_up_interruptible(&info
->open_wait
);
2504 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
2506 wake_up_interruptible(&info
->close_wait
);
2509 if (debug_level
>= DEBUG_LEVEL_INFO
)
2510 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__
,__LINE__
,
2511 tty
->driver
->name
, info
->count
);
2514 /* Wait until the transmitter is empty.
2516 static void mgslpc_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2518 MGSLPC_INFO
* info
= (MGSLPC_INFO
*)tty
->driver_data
;
2519 unsigned long orig_jiffies
, char_time
;
2524 if (debug_level
>= DEBUG_LEVEL_INFO
)
2525 printk("%s(%d):mgslpc_wait_until_sent(%s) entry\n",
2526 __FILE__
,__LINE__
, info
->device_name
);
2528 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_wait_until_sent"))
2531 if (!(info
->flags
& ASYNC_INITIALIZED
))
2534 orig_jiffies
= jiffies
;
2536 /* Set check interval to 1/5 of estimated time to
2537 * send a character, and make it at least 1. The check
2538 * interval should also be less than the timeout.
2539 * Note: use tight timings here to satisfy the NIST-PCTS.
2542 if ( info
->params
.data_rate
) {
2543 char_time
= info
->timeout
/(32 * 5);
2550 char_time
= min_t(unsigned long, char_time
, timeout
);
2552 if (info
->params
.mode
== MGSL_MODE_HDLC
) {
2553 while (info
->tx_active
) {
2554 msleep_interruptible(jiffies_to_msecs(char_time
));
2555 if (signal_pending(current
))
2557 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2561 while ((info
->tx_count
|| info
->tx_active
) &&
2563 msleep_interruptible(jiffies_to_msecs(char_time
));
2564 if (signal_pending(current
))
2566 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2572 if (debug_level
>= DEBUG_LEVEL_INFO
)
2573 printk("%s(%d):mgslpc_wait_until_sent(%s) exit\n",
2574 __FILE__
,__LINE__
, info
->device_name
);
2577 /* Called by tty_hangup() when a hangup is signaled.
2578 * This is the same as closing all open files for the port.
2580 static void mgslpc_hangup(struct tty_struct
*tty
)
2582 MGSLPC_INFO
* info
= (MGSLPC_INFO
*)tty
->driver_data
;
2584 if (debug_level
>= DEBUG_LEVEL_INFO
)
2585 printk("%s(%d):mgslpc_hangup(%s)\n",
2586 __FILE__
,__LINE__
, info
->device_name
);
2588 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_hangup"))
2591 mgslpc_flush_buffer(tty
);
2595 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
2598 wake_up_interruptible(&info
->open_wait
);
2601 /* Block the current process until the specified port
2602 * is ready to be opened.
2604 static int block_til_ready(struct tty_struct
*tty
, struct file
*filp
,
2607 DECLARE_WAITQUEUE(wait
, current
);
2609 int do_clocal
= 0, extra_count
= 0;
2610 unsigned long flags
;
2612 if (debug_level
>= DEBUG_LEVEL_INFO
)
2613 printk("%s(%d):block_til_ready on %s\n",
2614 __FILE__
,__LINE__
, tty
->driver
->name
);
2616 if (filp
->f_flags
& O_NONBLOCK
|| tty
->flags
& (1 << TTY_IO_ERROR
)){
2617 /* nonblock mode is set or port is not enabled */
2618 /* just verify that callout device is not active */
2619 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2623 if (tty
->termios
->c_cflag
& CLOCAL
)
2626 /* Wait for carrier detect and the line to become
2627 * free (i.e., not in use by the callout). While we are in
2628 * this loop, info->count is dropped by one, so that
2629 * mgslpc_close() knows when to free things. We restore it upon
2630 * exit, either normal or abnormal.
2634 add_wait_queue(&info
->open_wait
, &wait
);
2636 if (debug_level
>= DEBUG_LEVEL_INFO
)
2637 printk("%s(%d):block_til_ready before block on %s count=%d\n",
2638 __FILE__
,__LINE__
, tty
->driver
->name
, info
->count
);
2640 spin_lock_irqsave(&info
->lock
, flags
);
2641 if (!tty_hung_up_p(filp
)) {
2645 spin_unlock_irqrestore(&info
->lock
, flags
);
2646 info
->blocked_open
++;
2649 if ((tty
->termios
->c_cflag
& CBAUD
)) {
2650 spin_lock_irqsave(&info
->lock
,flags
);
2651 info
->serial_signals
|= SerialSignal_RTS
+ SerialSignal_DTR
;
2653 spin_unlock_irqrestore(&info
->lock
,flags
);
2656 set_current_state(TASK_INTERRUPTIBLE
);
2658 if (tty_hung_up_p(filp
) || !(info
->flags
& ASYNC_INITIALIZED
)){
2659 retval
= (info
->flags
& ASYNC_HUP_NOTIFY
) ?
2660 -EAGAIN
: -ERESTARTSYS
;
2664 spin_lock_irqsave(&info
->lock
,flags
);
2666 spin_unlock_irqrestore(&info
->lock
,flags
);
2668 if (!(info
->flags
& ASYNC_CLOSING
) &&
2669 (do_clocal
|| (info
->serial_signals
& SerialSignal_DCD
)) ) {
2673 if (signal_pending(current
)) {
2674 retval
= -ERESTARTSYS
;
2678 if (debug_level
>= DEBUG_LEVEL_INFO
)
2679 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
2680 __FILE__
,__LINE__
, tty
->driver
->name
, info
->count
);
2685 set_current_state(TASK_RUNNING
);
2686 remove_wait_queue(&info
->open_wait
, &wait
);
2690 info
->blocked_open
--;
2692 if (debug_level
>= DEBUG_LEVEL_INFO
)
2693 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
2694 __FILE__
,__LINE__
, tty
->driver
->name
, info
->count
);
2697 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2702 static int mgslpc_open(struct tty_struct
*tty
, struct file
* filp
)
2706 unsigned long flags
;
2708 /* verify range of specified line number */
2710 if ((line
< 0) || (line
>= mgslpc_device_count
)) {
2711 printk("%s(%d):mgslpc_open with invalid line #%d.\n",
2712 __FILE__
,__LINE__
,line
);
2716 /* find the info structure for the specified line */
2717 info
= mgslpc_device_list
;
2718 while(info
&& info
->line
!= line
)
2719 info
= info
->next_device
;
2720 if (mgslpc_paranoia_check(info
, tty
->name
, "mgslpc_open"))
2723 tty
->driver_data
= info
;
2726 if (debug_level
>= DEBUG_LEVEL_INFO
)
2727 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
2728 __FILE__
,__LINE__
,tty
->driver
->name
, info
->count
);
2730 /* If port is closing, signal caller to try again */
2731 if (tty_hung_up_p(filp
) || info
->flags
& ASYNC_CLOSING
){
2732 if (info
->flags
& ASYNC_CLOSING
)
2733 interruptible_sleep_on(&info
->close_wait
);
2734 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2735 -EAGAIN
: -ERESTARTSYS
);
2739 info
->tty
->low_latency
= (info
->flags
& ASYNC_LOW_LATENCY
) ? 1 : 0;
2741 spin_lock_irqsave(&info
->netlock
, flags
);
2742 if (info
->netcount
) {
2744 spin_unlock_irqrestore(&info
->netlock
, flags
);
2748 spin_unlock_irqrestore(&info
->netlock
, flags
);
2750 if (info
->count
== 1) {
2751 /* 1st open on this device, init hardware */
2752 retval
= startup(info
);
2757 retval
= block_til_ready(tty
, filp
, info
);
2759 if (debug_level
>= DEBUG_LEVEL_INFO
)
2760 printk("%s(%d):block_til_ready(%s) returned %d\n",
2761 __FILE__
,__LINE__
, info
->device_name
, retval
);
2765 if (debug_level
>= DEBUG_LEVEL_INFO
)
2766 printk("%s(%d):mgslpc_open(%s) success\n",
2767 __FILE__
,__LINE__
, info
->device_name
);
2772 if (tty
->count
== 1)
2773 info
->tty
= NULL
; /* tty layer will release tty struct */
2782 * /proc fs routines....
2785 static inline int line_info(char *buf
, MGSLPC_INFO
*info
)
2789 unsigned long flags
;
2791 ret
= sprintf(buf
, "%s:io:%04X irq:%d",
2792 info
->device_name
, info
->io_base
, info
->irq_level
);
2794 /* output current serial signal states */
2795 spin_lock_irqsave(&info
->lock
,flags
);
2797 spin_unlock_irqrestore(&info
->lock
,flags
);
2801 if (info
->serial_signals
& SerialSignal_RTS
)
2802 strcat(stat_buf
, "|RTS");
2803 if (info
->serial_signals
& SerialSignal_CTS
)
2804 strcat(stat_buf
, "|CTS");
2805 if (info
->serial_signals
& SerialSignal_DTR
)
2806 strcat(stat_buf
, "|DTR");
2807 if (info
->serial_signals
& SerialSignal_DSR
)
2808 strcat(stat_buf
, "|DSR");
2809 if (info
->serial_signals
& SerialSignal_DCD
)
2810 strcat(stat_buf
, "|CD");
2811 if (info
->serial_signals
& SerialSignal_RI
)
2812 strcat(stat_buf
, "|RI");
2814 if (info
->params
.mode
== MGSL_MODE_HDLC
) {
2815 ret
+= sprintf(buf
+ret
, " HDLC txok:%d rxok:%d",
2816 info
->icount
.txok
, info
->icount
.rxok
);
2817 if (info
->icount
.txunder
)
2818 ret
+= sprintf(buf
+ret
, " txunder:%d", info
->icount
.txunder
);
2819 if (info
->icount
.txabort
)
2820 ret
+= sprintf(buf
+ret
, " txabort:%d", info
->icount
.txabort
);
2821 if (info
->icount
.rxshort
)
2822 ret
+= sprintf(buf
+ret
, " rxshort:%d", info
->icount
.rxshort
);
2823 if (info
->icount
.rxlong
)
2824 ret
+= sprintf(buf
+ret
, " rxlong:%d", info
->icount
.rxlong
);
2825 if (info
->icount
.rxover
)
2826 ret
+= sprintf(buf
+ret
, " rxover:%d", info
->icount
.rxover
);
2827 if (info
->icount
.rxcrc
)
2828 ret
+= sprintf(buf
+ret
, " rxcrc:%d", info
->icount
.rxcrc
);
2830 ret
+= sprintf(buf
+ret
, " ASYNC tx:%d rx:%d",
2831 info
->icount
.tx
, info
->icount
.rx
);
2832 if (info
->icount
.frame
)
2833 ret
+= sprintf(buf
+ret
, " fe:%d", info
->icount
.frame
);
2834 if (info
->icount
.parity
)
2835 ret
+= sprintf(buf
+ret
, " pe:%d", info
->icount
.parity
);
2836 if (info
->icount
.brk
)
2837 ret
+= sprintf(buf
+ret
, " brk:%d", info
->icount
.brk
);
2838 if (info
->icount
.overrun
)
2839 ret
+= sprintf(buf
+ret
, " oe:%d", info
->icount
.overrun
);
2842 /* Append serial signal status to end */
2843 ret
+= sprintf(buf
+ret
, " %s\n", stat_buf
+1);
2845 ret
+= sprintf(buf
+ret
, "txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
2846 info
->tx_active
,info
->bh_requested
,info
->bh_running
,
2852 /* Called to print information about devices
2854 static int mgslpc_read_proc(char *page
, char **start
, off_t off
, int count
,
2855 int *eof
, void *data
)
2861 len
+= sprintf(page
, "synclink driver:%s\n", driver_version
);
2863 info
= mgslpc_device_list
;
2865 l
= line_info(page
+ len
, info
);
2867 if (len
+begin
> off
+count
)
2869 if (len
+begin
< off
) {
2873 info
= info
->next_device
;
2878 if (off
>= len
+begin
)
2880 *start
= page
+ (off
-begin
);
2881 return ((count
< begin
+len
-off
) ? count
: begin
+len
-off
);
2884 static int rx_alloc_buffers(MGSLPC_INFO
*info
)
2886 /* each buffer has header and data */
2887 info
->rx_buf_size
= sizeof(RXBUF
) + info
->max_frame_size
;
2889 /* calculate total allocation size for 8 buffers */
2890 info
->rx_buf_total_size
= info
->rx_buf_size
* 8;
2892 /* limit total allocated memory */
2893 if (info
->rx_buf_total_size
> 0x10000)
2894 info
->rx_buf_total_size
= 0x10000;
2896 /* calculate number of buffers */
2897 info
->rx_buf_count
= info
->rx_buf_total_size
/ info
->rx_buf_size
;
2899 info
->rx_buf
= kmalloc(info
->rx_buf_total_size
, GFP_KERNEL
);
2900 if (info
->rx_buf
== NULL
)
2903 rx_reset_buffers(info
);
2907 static void rx_free_buffers(MGSLPC_INFO
*info
)
2909 kfree(info
->rx_buf
);
2910 info
->rx_buf
= NULL
;
2913 static int claim_resources(MGSLPC_INFO
*info
)
2915 if (rx_alloc_buffers(info
) < 0 ) {
2916 printk( "Cant allocate rx buffer %s\n", info
->device_name
);
2917 release_resources(info
);
2923 static void release_resources(MGSLPC_INFO
*info
)
2925 if (debug_level
>= DEBUG_LEVEL_INFO
)
2926 printk("release_resources(%s)\n", info
->device_name
);
2927 rx_free_buffers(info
);
2930 /* Add the specified device instance data structure to the
2931 * global linked list of devices and increment the device count.
2933 * Arguments: info pointer to device instance data
2935 static void mgslpc_add_device(MGSLPC_INFO
*info
)
2937 info
->next_device
= NULL
;
2938 info
->line
= mgslpc_device_count
;
2939 sprintf(info
->device_name
,"ttySLP%d",info
->line
);
2941 if (info
->line
< MAX_DEVICE_COUNT
) {
2942 if (maxframe
[info
->line
])
2943 info
->max_frame_size
= maxframe
[info
->line
];
2944 info
->dosyncppp
= dosyncppp
[info
->line
];
2947 mgslpc_device_count
++;
2949 if (!mgslpc_device_list
)
2950 mgslpc_device_list
= info
;
2952 MGSLPC_INFO
*current_dev
= mgslpc_device_list
;
2953 while( current_dev
->next_device
)
2954 current_dev
= current_dev
->next_device
;
2955 current_dev
->next_device
= info
;
2958 if (info
->max_frame_size
< 4096)
2959 info
->max_frame_size
= 4096;
2960 else if (info
->max_frame_size
> 65535)
2961 info
->max_frame_size
= 65535;
2963 printk( "SyncLink PC Card %s:IO=%04X IRQ=%d\n",
2964 info
->device_name
, info
->io_base
, info
->irq_level
);
2971 static void mgslpc_remove_device(MGSLPC_INFO
*remove_info
)
2973 MGSLPC_INFO
*info
= mgslpc_device_list
;
2974 MGSLPC_INFO
*last
= NULL
;
2977 if (info
== remove_info
) {
2979 last
->next_device
= info
->next_device
;
2981 mgslpc_device_list
= info
->next_device
;
2985 release_resources(info
);
2987 mgslpc_device_count
--;
2991 info
= info
->next_device
;
2995 static struct pcmcia_device_id mgslpc_ids
[] = {
2996 PCMCIA_DEVICE_MANF_CARD(0x02c5, 0x0050),
2999 MODULE_DEVICE_TABLE(pcmcia
, mgslpc_ids
);
3001 static struct pcmcia_driver mgslpc_driver
= {
3002 .owner
= THIS_MODULE
,
3004 .name
= "synclink_cs",
3006 .probe
= mgslpc_probe
,
3007 .remove
= mgslpc_detach
,
3008 .id_table
= mgslpc_ids
,
3009 .suspend
= mgslpc_suspend
,
3010 .resume
= mgslpc_resume
,
3013 static struct tty_operations mgslpc_ops
= {
3014 .open
= mgslpc_open
,
3015 .close
= mgslpc_close
,
3016 .write
= mgslpc_write
,
3017 .put_char
= mgslpc_put_char
,
3018 .flush_chars
= mgslpc_flush_chars
,
3019 .write_room
= mgslpc_write_room
,
3020 .chars_in_buffer
= mgslpc_chars_in_buffer
,
3021 .flush_buffer
= mgslpc_flush_buffer
,
3022 .ioctl
= mgslpc_ioctl
,
3023 .throttle
= mgslpc_throttle
,
3024 .unthrottle
= mgslpc_unthrottle
,
3025 .send_xchar
= mgslpc_send_xchar
,
3026 .break_ctl
= mgslpc_break
,
3027 .wait_until_sent
= mgslpc_wait_until_sent
,
3028 .read_proc
= mgslpc_read_proc
,
3029 .set_termios
= mgslpc_set_termios
,
3031 .start
= tx_release
,
3032 .hangup
= mgslpc_hangup
,
3033 .tiocmget
= tiocmget
,
3034 .tiocmset
= tiocmset
,
3037 static void synclink_cs_cleanup(void)
3041 printk("Unloading %s: version %s\n", driver_name
, driver_version
);
3043 while(mgslpc_device_list
)
3044 mgslpc_remove_device(mgslpc_device_list
);
3046 if (serial_driver
) {
3047 if ((rc
= tty_unregister_driver(serial_driver
)))
3048 printk("%s(%d) failed to unregister tty driver err=%d\n",
3049 __FILE__
,__LINE__
,rc
);
3050 put_tty_driver(serial_driver
);
3053 pcmcia_unregister_driver(&mgslpc_driver
);
3056 static int __init
synclink_cs_init(void)
3060 if (break_on_load
) {
3061 mgslpc_get_text_ptr();
3065 printk("%s %s\n", driver_name
, driver_version
);
3067 if ((rc
= pcmcia_register_driver(&mgslpc_driver
)) < 0)
3070 serial_driver
= alloc_tty_driver(MAX_DEVICE_COUNT
);
3071 if (!serial_driver
) {
3076 /* Initialize the tty_driver structure */
3078 serial_driver
->owner
= THIS_MODULE
;
3079 serial_driver
->driver_name
= "synclink_cs";
3080 serial_driver
->name
= "ttySLP";
3081 serial_driver
->major
= ttymajor
;
3082 serial_driver
->minor_start
= 64;
3083 serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
3084 serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
3085 serial_driver
->init_termios
= tty_std_termios
;
3086 serial_driver
->init_termios
.c_cflag
=
3087 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
3088 serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
3089 tty_set_operations(serial_driver
, &mgslpc_ops
);
3091 if ((rc
= tty_register_driver(serial_driver
)) < 0) {
3092 printk("%s(%d):Couldn't register serial driver\n",
3094 put_tty_driver(serial_driver
);
3095 serial_driver
= NULL
;
3099 printk("%s %s, tty major#%d\n",
3100 driver_name
, driver_version
,
3101 serial_driver
->major
);
3106 synclink_cs_cleanup();
3110 static void __exit
synclink_cs_exit(void)
3112 synclink_cs_cleanup();
3115 module_init(synclink_cs_init
);
3116 module_exit(synclink_cs_exit
);
3118 static void mgslpc_set_rate(MGSLPC_INFO
*info
, unsigned char channel
, unsigned int rate
)
3123 /* note:standard BRG mode is broken in V3.2 chip
3124 * so enhanced mode is always used
3132 for (M
= 1; N
> 64 && M
< 16; M
++)
3138 * BGR[7..0] contained in BGR register
3139 * BGR[9..8] contained in CCR2[7..6]
3140 * divisor = (N+1)*2^M
3142 * Note: M *must* not be zero (causes asymetric duty cycle)
3144 write_reg(info
, (unsigned char) (channel
+ BGR
),
3145 (unsigned char) ((M
<< 6) + N
));
3146 val
= read_reg(info
, (unsigned char) (channel
+ CCR2
)) & 0x3f;
3147 val
|= ((M
<< 4) & 0xc0);
3148 write_reg(info
, (unsigned char) (channel
+ CCR2
), val
);
3152 /* Enabled the AUX clock output at the specified frequency.
3154 static void enable_auxclk(MGSLPC_INFO
*info
)
3160 * 07..06 MDS[1..0] 10 = transparent HDLC mode
3161 * 05 ADM Address Mode, 0 = no addr recognition
3162 * 04 TMD Timer Mode, 0 = external
3163 * 03 RAC Receiver Active, 0 = inactive
3164 * 02 RTS 0=RTS active during xmit, 1=RTS always active
3165 * 01 TRS Timer Resolution, 1=512
3166 * 00 TLP Test Loop, 0 = no loop
3172 /* channel B RTS is used to enable AUXCLK driver on SP505 */
3173 if (info
->params
.mode
== MGSL_MODE_HDLC
&& info
->params
.clock_speed
)
3175 write_reg(info
, CHB
+ MODE
, val
);
3179 * 07 PU Power Up, 1=active, 0=power down
3180 * 06 MCE Master Clock Enable, 1=enabled
3182 * 04..02 SC[2..0] Encoding
3183 * 01..00 SM[1..0] Serial Mode, 00=HDLC
3187 write_reg(info
, CHB
+ CCR0
, 0xc0);
3191 * 07 SFLG Shared Flag, 0 = disable shared flags
3192 * 06 GALP Go Active On Loop, 0 = not used
3193 * 05 GLP Go On Loop, 0 = not used
3194 * 04 ODS Output Driver Select, 1=TxD is push-pull output
3195 * 03 ITF Interframe Time Fill, 0=mark, 1=flag
3196 * 02..00 CM[2..0] Clock Mode
3200 write_reg(info
, CHB
+ CCR1
, 0x17);
3204 * 07..06 BGR[9..8] Baud rate bits 9..8
3205 * 05 BDF Baud rate divisor factor, 0=1, 1=BGR value
3206 * 04 SSEL Clock source select, 1=submode b
3207 * 03 TOE 0=TxCLK is input, 1=TxCLK is output
3208 * 02 RWX Read/Write Exchange 0=disabled
3209 * 01 C32, CRC select, 0=CRC-16, 1=CRC-32
3210 * 00 DIV, data inversion 0=disabled, 1=enabled
3214 if (info
->params
.mode
== MGSL_MODE_HDLC
&& info
->params
.clock_speed
)
3215 write_reg(info
, CHB
+ CCR2
, 0x38);
3217 write_reg(info
, CHB
+ CCR2
, 0x30);
3221 * 07 MCK4 Master Clock Divide by 4, 1=enabled
3222 * 06 EBRG Enhanced Baud Rate Generator Mode, 1=enabled
3223 * 05 TST1 Test Pin, 0=normal operation
3224 * 04 ICD Ivert Carrier Detect, 1=enabled (active low)
3225 * 03..02 Reserved, must be 0
3226 * 01..00 RFT[1..0] RxFIFO Threshold 00=32 bytes
3230 write_reg(info
, CHB
+ CCR4
, 0x50);
3232 /* if auxclk not enabled, set internal BRG so
3233 * CTS transitions can be detected (requires TxC)
3235 if (info
->params
.mode
== MGSL_MODE_HDLC
&& info
->params
.clock_speed
)
3236 mgslpc_set_rate(info
, CHB
, info
->params
.clock_speed
);
3238 mgslpc_set_rate(info
, CHB
, 921600);
3241 static void loopback_enable(MGSLPC_INFO
*info
)
3245 /* CCR1:02..00 CM[2..0] Clock Mode = 111 (clock mode 7) */
3246 val
= read_reg(info
, CHA
+ CCR1
) | (BIT2
+ BIT1
+ BIT0
);
3247 write_reg(info
, CHA
+ CCR1
, val
);
3249 /* CCR2:04 SSEL Clock source select, 1=submode b */
3250 val
= read_reg(info
, CHA
+ CCR2
) | (BIT4
+ BIT5
);
3251 write_reg(info
, CHA
+ CCR2
, val
);
3253 /* set LinkSpeed if available, otherwise default to 2Mbps */
3254 if (info
->params
.clock_speed
)
3255 mgslpc_set_rate(info
, CHA
, info
->params
.clock_speed
);
3257 mgslpc_set_rate(info
, CHA
, 1843200);
3259 /* MODE:00 TLP Test Loop, 1=loopback enabled */
3260 val
= read_reg(info
, CHA
+ MODE
) | BIT0
;
3261 write_reg(info
, CHA
+ MODE
, val
);
3264 static void hdlc_mode(MGSLPC_INFO
*info
)
3267 unsigned char clkmode
, clksubmode
;
3269 /* disable all interrupts */
3270 irq_disable(info
, CHA
, 0xffff);
3271 irq_disable(info
, CHB
, 0xffff);
3272 port_irq_disable(info
, 0xff);
3274 /* assume clock mode 0a, rcv=RxC xmt=TxC */
3275 clkmode
= clksubmode
= 0;
3276 if (info
->params
.flags
& HDLC_FLAG_RXC_DPLL
3277 && info
->params
.flags
& HDLC_FLAG_TXC_DPLL
) {
3278 /* clock mode 7a, rcv = DPLL, xmt = DPLL */
3280 } else if (info
->params
.flags
& HDLC_FLAG_RXC_BRG
3281 && info
->params
.flags
& HDLC_FLAG_TXC_BRG
) {
3282 /* clock mode 7b, rcv = BRG, xmt = BRG */
3285 } else if (info
->params
.flags
& HDLC_FLAG_RXC_DPLL
) {
3286 if (info
->params
.flags
& HDLC_FLAG_TXC_BRG
) {
3287 /* clock mode 6b, rcv = DPLL, xmt = BRG/16 */
3291 /* clock mode 6a, rcv = DPLL, xmt = TxC */
3294 } else if (info
->params
.flags
& HDLC_FLAG_TXC_BRG
) {
3295 /* clock mode 0b, rcv = RxC, xmt = BRG */
3301 * 07..06 MDS[1..0] 10 = transparent HDLC mode
3302 * 05 ADM Address Mode, 0 = no addr recognition
3303 * 04 TMD Timer Mode, 0 = external
3304 * 03 RAC Receiver Active, 0 = inactive
3305 * 02 RTS 0=RTS active during xmit, 1=RTS always active
3306 * 01 TRS Timer Resolution, 1=512
3307 * 00 TLP Test Loop, 0 = no loop
3312 if (info
->params
.loopback
)
3315 /* preserve RTS state */
3316 if (info
->serial_signals
& SerialSignal_RTS
)
3318 write_reg(info
, CHA
+ MODE
, val
);
3322 * 07 PU Power Up, 1=active, 0=power down
3323 * 06 MCE Master Clock Enable, 1=enabled
3325 * 04..02 SC[2..0] Encoding
3326 * 01..00 SM[1..0] Serial Mode, 00=HDLC
3331 switch (info
->params
.encoding
)
3333 case HDLC_ENCODING_NRZI
:
3336 case HDLC_ENCODING_BIPHASE_SPACE
:
3339 case HDLC_ENCODING_BIPHASE_MARK
:
3342 case HDLC_ENCODING_BIPHASE_LEVEL
:
3344 break; // Manchester
3346 write_reg(info
, CHA
+ CCR0
, val
);
3350 * 07 SFLG Shared Flag, 0 = disable shared flags
3351 * 06 GALP Go Active On Loop, 0 = not used
3352 * 05 GLP Go On Loop, 0 = not used
3353 * 04 ODS Output Driver Select, 1=TxD is push-pull output
3354 * 03 ITF Interframe Time Fill, 0=mark, 1=flag
3355 * 02..00 CM[2..0] Clock Mode
3359 val
= 0x10 + clkmode
;
3360 write_reg(info
, CHA
+ CCR1
, val
);
3364 * 07..06 BGR[9..8] Baud rate bits 9..8
3365 * 05 BDF Baud rate divisor factor, 0=1, 1=BGR value
3366 * 04 SSEL Clock source select, 1=submode b
3367 * 03 TOE 0=TxCLK is input, 0=TxCLK is input
3368 * 02 RWX Read/Write Exchange 0=disabled
3369 * 01 C32, CRC select, 0=CRC-16, 1=CRC-32
3370 * 00 DIV, data inversion 0=disabled, 1=enabled
3375 if (clkmode
== 2 || clkmode
== 3 || clkmode
== 6
3376 || clkmode
== 7 || (clkmode
== 0 && clksubmode
== 1))
3380 if (info
->params
.crc_type
== HDLC_CRC_32_CCITT
)
3382 if (info
->params
.encoding
== HDLC_ENCODING_NRZB
)
3384 write_reg(info
, CHA
+ CCR2
, val
);
3388 * 07..06 PRE[1..0] Preamble count 00=1, 01=2, 10=4, 11=8
3389 * 05 EPT Enable preamble transmission, 1=enabled
3390 * 04 RADD Receive address pushed to FIFO, 0=disabled
3391 * 03 CRL CRC Reset Level, 0=FFFF
3392 * 02 RCRC Rx CRC 0=On 1=Off
3393 * 01 TCRC Tx CRC 0=On 1=Off
3394 * 00 PSD DPLL Phase Shift Disable
3399 if (info
->params
.crc_type
== HDLC_CRC_NONE
)
3401 if (info
->params
.preamble
!= HDLC_PREAMBLE_PATTERN_NONE
)
3403 switch (info
->params
.preamble_length
)
3405 case HDLC_PREAMBLE_LENGTH_16BITS
:
3408 case HDLC_PREAMBLE_LENGTH_32BITS
:
3411 case HDLC_PREAMBLE_LENGTH_64BITS
:
3415 write_reg(info
, CHA
+ CCR3
, val
);
3417 /* PRE - Preamble pattern */
3419 switch (info
->params
.preamble
)
3421 case HDLC_PREAMBLE_PATTERN_FLAGS
: val
= 0x7e; break;
3422 case HDLC_PREAMBLE_PATTERN_10
: val
= 0xaa; break;
3423 case HDLC_PREAMBLE_PATTERN_01
: val
= 0x55; break;
3424 case HDLC_PREAMBLE_PATTERN_ONES
: val
= 0xff; break;
3426 write_reg(info
, CHA
+ PRE
, val
);
3430 * 07 MCK4 Master Clock Divide by 4, 1=enabled
3431 * 06 EBRG Enhanced Baud Rate Generator Mode, 1=enabled
3432 * 05 TST1 Test Pin, 0=normal operation
3433 * 04 ICD Ivert Carrier Detect, 1=enabled (active low)
3434 * 03..02 Reserved, must be 0
3435 * 01..00 RFT[1..0] RxFIFO Threshold 00=32 bytes
3440 write_reg(info
, CHA
+ CCR4
, val
);
3441 if (info
->params
.flags
& HDLC_FLAG_RXC_DPLL
)
3442 mgslpc_set_rate(info
, CHA
, info
->params
.clock_speed
* 16);
3444 mgslpc_set_rate(info
, CHA
, info
->params
.clock_speed
);
3446 /* RLCR Receive length check register
3448 * 7 1=enable receive length check
3449 * 6..0 Max frame length = (RL + 1) * 32
3451 write_reg(info
, CHA
+ RLCR
, 0);
3453 /* XBCH Transmit Byte Count High
3455 * 07 DMA mode, 0 = interrupt driven
3456 * 06 NRM, 0=ABM (ignored)
3457 * 05 CAS Carrier Auto Start
3458 * 04 XC Transmit Continuously (ignored)
3459 * 03..00 XBC[10..8] Transmit byte count bits 10..8
3464 if (info
->params
.flags
& HDLC_FLAG_AUTO_DCD
)
3466 write_reg(info
, CHA
+ XBCH
, val
);
3467 enable_auxclk(info
);
3468 if (info
->params
.loopback
|| info
->testing_irq
)
3469 loopback_enable(info
);
3470 if (info
->params
.flags
& HDLC_FLAG_AUTO_CTS
)
3472 irq_enable(info
, CHB
, IRQ_CTS
);
3473 /* PVR[3] 1=AUTO CTS active */
3474 set_reg_bits(info
, CHA
+ PVR
, BIT3
);
3476 clear_reg_bits(info
, CHA
+ PVR
, BIT3
);
3478 irq_enable(info
, CHA
,
3479 IRQ_RXEOM
+ IRQ_RXFIFO
+ IRQ_ALLSENT
+
3480 IRQ_UNDERRUN
+ IRQ_TXFIFO
);
3481 issue_command(info
, CHA
, CMD_TXRESET
+ CMD_RXRESET
);
3482 wait_command_complete(info
, CHA
);
3483 read_reg16(info
, CHA
+ ISR
); /* clear pending IRQs */
3485 /* Master clock mode enabled above to allow reset commands
3486 * to complete even if no data clocks are present.
3488 * Disable master clock mode for normal communications because
3489 * V3.2 of the ESCC2 has a bug that prevents the transmit all sent
3490 * IRQ when in master clock mode.
3492 * Leave master clock mode enabled for IRQ test because the
3493 * timer IRQ used by the test can only happen in master clock mode.
3495 if (!info
->testing_irq
)
3496 clear_reg_bits(info
, CHA
+ CCR0
, BIT6
);
3504 static void rx_stop(MGSLPC_INFO
*info
)
3506 if (debug_level
>= DEBUG_LEVEL_ISR
)
3507 printk("%s(%d):rx_stop(%s)\n",
3508 __FILE__
,__LINE__
, info
->device_name
);
3510 /* MODE:03 RAC Receiver Active, 0=inactive */
3511 clear_reg_bits(info
, CHA
+ MODE
, BIT3
);
3513 info
->rx_enabled
= 0;
3514 info
->rx_overflow
= 0;
3517 static void rx_start(MGSLPC_INFO
*info
)
3519 if (debug_level
>= DEBUG_LEVEL_ISR
)
3520 printk("%s(%d):rx_start(%s)\n",
3521 __FILE__
,__LINE__
, info
->device_name
);
3523 rx_reset_buffers(info
);
3524 info
->rx_enabled
= 0;
3525 info
->rx_overflow
= 0;
3527 /* MODE:03 RAC Receiver Active, 1=active */
3528 set_reg_bits(info
, CHA
+ MODE
, BIT3
);
3530 info
->rx_enabled
= 1;
3533 static void tx_start(MGSLPC_INFO
*info
)
3535 if (debug_level
>= DEBUG_LEVEL_ISR
)
3536 printk("%s(%d):tx_start(%s)\n",
3537 __FILE__
,__LINE__
, info
->device_name
);
3539 if (info
->tx_count
) {
3540 /* If auto RTS enabled and RTS is inactive, then assert */
3541 /* RTS and set a flag indicating that the driver should */
3542 /* negate RTS when the transmission completes. */
3543 info
->drop_rts_on_tx_done
= 0;
3545 if (info
->params
.flags
& HDLC_FLAG_AUTO_RTS
) {
3547 if (!(info
->serial_signals
& SerialSignal_RTS
)) {
3548 info
->serial_signals
|= SerialSignal_RTS
;
3550 info
->drop_rts_on_tx_done
= 1;
3554 if (info
->params
.mode
== MGSL_MODE_ASYNC
) {
3555 if (!info
->tx_active
) {
3556 info
->tx_active
= 1;
3560 info
->tx_active
= 1;
3562 info
->tx_timer
.expires
= jiffies
+ msecs_to_jiffies(5000);
3563 add_timer(&info
->tx_timer
);
3567 if (!info
->tx_enabled
)
3568 info
->tx_enabled
= 1;
3571 static void tx_stop(MGSLPC_INFO
*info
)
3573 if (debug_level
>= DEBUG_LEVEL_ISR
)
3574 printk("%s(%d):tx_stop(%s)\n",
3575 __FILE__
,__LINE__
, info
->device_name
);
3577 del_timer(&info
->tx_timer
);
3579 info
->tx_enabled
= 0;
3580 info
->tx_active
= 0;
3583 /* Reset the adapter to a known state and prepare it for further use.
3585 static void reset_device(MGSLPC_INFO
*info
)
3587 /* power up both channels (set BIT7) */
3588 write_reg(info
, CHA
+ CCR0
, 0x80);
3589 write_reg(info
, CHB
+ CCR0
, 0x80);
3590 write_reg(info
, CHA
+ MODE
, 0);
3591 write_reg(info
, CHB
+ MODE
, 0);
3593 /* disable all interrupts */
3594 irq_disable(info
, CHA
, 0xffff);
3595 irq_disable(info
, CHB
, 0xffff);
3596 port_irq_disable(info
, 0xff);
3598 /* PCR Port Configuration Register
3600 * 07..04 DEC[3..0] Serial I/F select outputs
3601 * 03 output, 1=AUTO CTS control enabled
3602 * 02 RI Ring Indicator input 0=active
3603 * 01 DSR input 0=active
3604 * 00 DTR output 0=active
3608 write_reg(info
, PCR
, 0x06);
3610 /* PVR Port Value Register
3612 * 07..04 DEC[3..0] Serial I/F select (0000=disabled)
3613 * 03 AUTO CTS output 1=enabled
3614 * 02 RI Ring Indicator input
3616 * 00 DTR output (1=inactive)
3620 // write_reg(info, PVR, PVR_DTR);
3622 /* IPC Interrupt Port Configuration
3624 * 07 VIS 1=Masked interrupts visible
3625 * 06..05 Reserved, 0
3626 * 04..03 SLA Slave address, 00 ignored
3627 * 02 CASM Cascading Mode, 1=daisy chain
3628 * 01..00 IC[1..0] Interrupt Config, 01=push-pull output, active low
3632 write_reg(info
, IPC
, 0x05);
3635 static void async_mode(MGSLPC_INFO
*info
)
3639 /* disable all interrupts */
3640 irq_disable(info
, CHA
, 0xffff);
3641 irq_disable(info
, CHB
, 0xffff);
3642 port_irq_disable(info
, 0xff);
3647 * 06 FRTS RTS State, 0=active
3648 * 05 FCTS Flow Control on CTS
3649 * 04 FLON Flow Control Enable
3650 * 03 RAC Receiver Active, 0 = inactive
3651 * 02 RTS 0=Auto RTS, 1=manual RTS
3652 * 01 TRS Timer Resolution, 1=512
3653 * 00 TLP Test Loop, 0 = no loop
3658 if (info
->params
.loopback
)
3661 /* preserve RTS state */
3662 if (!(info
->serial_signals
& SerialSignal_RTS
))
3664 write_reg(info
, CHA
+ MODE
, val
);
3668 * 07 PU Power Up, 1=active, 0=power down
3669 * 06 MCE Master Clock Enable, 1=enabled
3671 * 04..02 SC[2..0] Encoding, 000=NRZ
3672 * 01..00 SM[1..0] Serial Mode, 11=Async
3676 write_reg(info
, CHA
+ CCR0
, 0x83);
3680 * 07..05 Reserved, 0
3681 * 04 ODS Output Driver Select, 1=TxD is push-pull output
3682 * 03 BCR Bit Clock Rate, 1=16x
3683 * 02..00 CM[2..0] Clock Mode, 111=BRG
3687 write_reg(info
, CHA
+ CCR1
, 0x1f);
3691 * 07..06 BGR[9..8] Baud rate bits 9..8
3692 * 05 BDF Baud rate divisor factor, 0=1, 1=BGR value
3693 * 04 SSEL Clock source select, 1=submode b
3694 * 03 TOE 0=TxCLK is input, 0=TxCLK is input
3695 * 02 RWX Read/Write Exchange 0=disabled
3697 * 00 DIV, data inversion 0=disabled, 1=enabled
3701 write_reg(info
, CHA
+ CCR2
, 0x10);
3705 * 07..01 Reserved, 0
3706 * 00 PSD DPLL Phase Shift Disable
3710 write_reg(info
, CHA
+ CCR3
, 0);
3714 * 07 MCK4 Master Clock Divide by 4, 1=enabled
3715 * 06 EBRG Enhanced Baud Rate Generator Mode, 1=enabled
3716 * 05 TST1 Test Pin, 0=normal operation
3717 * 04 ICD Ivert Carrier Detect, 1=enabled (active low)
3718 * 03..00 Reserved, must be 0
3722 write_reg(info
, CHA
+ CCR4
, 0x50);
3723 mgslpc_set_rate(info
, CHA
, info
->params
.data_rate
* 16);
3728 * 06 XBRK transmit break, 0=normal operation
3729 * 05 Stop bits (0=1, 1=2)
3730 * 04..03 PAR[1..0] Parity (01=odd, 10=even)
3731 * 02 PAREN Parity Enable
3732 * 01..00 CHL[1..0] Character Length (00=8, 01=7)
3736 if (info
->params
.data_bits
!= 8)
3737 val
|= BIT0
; /* 7 bits */
3738 if (info
->params
.stop_bits
!= 1)
3740 if (info
->params
.parity
!= ASYNC_PARITY_NONE
)
3742 val
|= BIT2
; /* Parity enable */
3743 if (info
->params
.parity
== ASYNC_PARITY_ODD
)
3748 write_reg(info
, CHA
+ DAFO
, val
);
3750 /* RFC Rx FIFO Control
3753 * 06 DPS, 1=parity bit not stored in data byte
3754 * 05 DXS, 0=all data stored in FIFO (including XON/XOFF)
3755 * 04 RFDF Rx FIFO Data Format, 1=status byte stored in FIFO
3756 * 03..02 RFTH[1..0], rx threshold, 11=16 status + 16 data byte
3758 * 00 TCDE Terminate Char Detect Enable, 0=disabled
3762 write_reg(info
, CHA
+ RFC
, 0x5c);
3764 /* RLCR Receive length check register
3766 * Max frame length = (RL + 1) * 32
3768 write_reg(info
, CHA
+ RLCR
, 0);
3770 /* XBCH Transmit Byte Count High
3772 * 07 DMA mode, 0 = interrupt driven
3773 * 06 NRM, 0=ABM (ignored)
3774 * 05 CAS Carrier Auto Start
3775 * 04 XC Transmit Continuously (ignored)
3776 * 03..00 XBC[10..8] Transmit byte count bits 10..8
3781 if (info
->params
.flags
& HDLC_FLAG_AUTO_DCD
)
3783 write_reg(info
, CHA
+ XBCH
, val
);
3784 if (info
->params
.flags
& HDLC_FLAG_AUTO_CTS
)
3785 irq_enable(info
, CHA
, IRQ_CTS
);
3787 /* MODE:03 RAC Receiver Active, 1=active */
3788 set_reg_bits(info
, CHA
+ MODE
, BIT3
);
3789 enable_auxclk(info
);
3790 if (info
->params
.flags
& HDLC_FLAG_AUTO_CTS
) {
3791 irq_enable(info
, CHB
, IRQ_CTS
);
3792 /* PVR[3] 1=AUTO CTS active */
3793 set_reg_bits(info
, CHA
+ PVR
, BIT3
);
3795 clear_reg_bits(info
, CHA
+ PVR
, BIT3
);
3796 irq_enable(info
, CHA
,
3797 IRQ_RXEOM
+ IRQ_RXFIFO
+ IRQ_BREAK_ON
+ IRQ_RXTIME
+
3798 IRQ_ALLSENT
+ IRQ_TXFIFO
);
3799 issue_command(info
, CHA
, CMD_TXRESET
+ CMD_RXRESET
);
3800 wait_command_complete(info
, CHA
);
3801 read_reg16(info
, CHA
+ ISR
); /* clear pending IRQs */
3804 /* Set the HDLC idle mode for the transmitter.
3806 static void tx_set_idle(MGSLPC_INFO
*info
)
3808 /* Note: ESCC2 only supports flags and one idle modes */
3809 if (info
->idle_mode
== HDLC_TXIDLE_FLAGS
)
3810 set_reg_bits(info
, CHA
+ CCR1
, BIT3
);
3812 clear_reg_bits(info
, CHA
+ CCR1
, BIT3
);
3815 /* get state of the V24 status (input) signals.
3817 static void get_signals(MGSLPC_INFO
*info
)
3819 unsigned char status
= 0;
3821 /* preserve DTR and RTS */
3822 info
->serial_signals
&= SerialSignal_DTR
+ SerialSignal_RTS
;
3824 if (read_reg(info
, CHB
+ VSTR
) & BIT7
)
3825 info
->serial_signals
|= SerialSignal_DCD
;
3826 if (read_reg(info
, CHB
+ STAR
) & BIT1
)
3827 info
->serial_signals
|= SerialSignal_CTS
;
3829 status
= read_reg(info
, CHA
+ PVR
);
3830 if (!(status
& PVR_RI
))
3831 info
->serial_signals
|= SerialSignal_RI
;
3832 if (!(status
& PVR_DSR
))
3833 info
->serial_signals
|= SerialSignal_DSR
;
3836 /* Set the state of DTR and RTS based on contents of
3837 * serial_signals member of device extension.
3839 static void set_signals(MGSLPC_INFO
*info
)
3843 val
= read_reg(info
, CHA
+ MODE
);
3844 if (info
->params
.mode
== MGSL_MODE_ASYNC
) {
3845 if (info
->serial_signals
& SerialSignal_RTS
)
3850 if (info
->serial_signals
& SerialSignal_RTS
)
3855 write_reg(info
, CHA
+ MODE
, val
);
3857 if (info
->serial_signals
& SerialSignal_DTR
)
3858 clear_reg_bits(info
, CHA
+ PVR
, PVR_DTR
);
3860 set_reg_bits(info
, CHA
+ PVR
, PVR_DTR
);
3863 static void rx_reset_buffers(MGSLPC_INFO
*info
)
3870 info
->rx_frame_count
= 0;
3871 for (i
=0 ; i
< info
->rx_buf_count
; i
++) {
3872 buf
= (RXBUF
*)(info
->rx_buf
+ (i
* info
->rx_buf_size
));
3873 buf
->status
= buf
->count
= 0;
3877 /* Attempt to return a received HDLC frame
3878 * Only frames received without errors are returned.
3880 * Returns 1 if frame returned, otherwise 0
3882 static int rx_get_frame(MGSLPC_INFO
*info
)
3884 unsigned short status
;
3886 unsigned int framesize
= 0;
3887 unsigned long flags
;
3888 struct tty_struct
*tty
= info
->tty
;
3889 int return_frame
= 0;
3891 if (info
->rx_frame_count
== 0)
3894 buf
= (RXBUF
*)(info
->rx_buf
+ (info
->rx_get
* info
->rx_buf_size
));
3896 status
= buf
->status
;
3898 /* 07 VFR 1=valid frame
3899 * 06 RDO 1=data overrun
3900 * 05 CRC 1=OK, 0=error
3901 * 04 RAB 1=frame aborted
3903 if ((status
& 0xf0) != 0xA0) {
3904 if (!(status
& BIT7
) || (status
& BIT4
))
3905 info
->icount
.rxabort
++;
3906 else if (status
& BIT6
)
3907 info
->icount
.rxover
++;
3908 else if (!(status
& BIT5
)) {
3909 info
->icount
.rxcrc
++;
3910 if (info
->params
.crc_type
& HDLC_CRC_RETURN_EX
)
3916 struct net_device_stats
*stats
= hdlc_stats(info
->netdev
);
3918 stats
->rx_frame_errors
++;
3925 framesize
= buf
->count
;
3927 if (debug_level
>= DEBUG_LEVEL_BH
)
3928 printk("%s(%d):rx_get_frame(%s) status=%04X size=%d\n",
3929 __FILE__
,__LINE__
,info
->device_name
,status
,framesize
);
3931 if (debug_level
>= DEBUG_LEVEL_DATA
)
3932 trace_block(info
, buf
->data
, framesize
, 0);
3935 if ((info
->params
.crc_type
& HDLC_CRC_RETURN_EX
&&
3936 framesize
+1 > info
->max_frame_size
) ||
3937 framesize
> info
->max_frame_size
)
3938 info
->icount
.rxlong
++;
3941 info
->icount
.rxok
++;
3943 if (info
->params
.crc_type
& HDLC_CRC_RETURN_EX
) {
3944 *(buf
->data
+ framesize
) = status
& BIT5
? RX_OK
:RX_CRC_ERROR
;
3950 hdlcdev_rx(info
, buf
->data
, framesize
);
3953 ldisc_receive_buf(tty
, buf
->data
, info
->flag_buf
, framesize
);
3957 spin_lock_irqsave(&info
->lock
,flags
);
3958 buf
->status
= buf
->count
= 0;
3959 info
->rx_frame_count
--;
3961 if (info
->rx_get
>= info
->rx_buf_count
)
3963 spin_unlock_irqrestore(&info
->lock
,flags
);
3968 static BOOLEAN
register_test(MGSLPC_INFO
*info
)
3970 static unsigned char patterns
[] =
3971 { 0x00, 0xff, 0xaa, 0x55, 0x69, 0x96, 0x0f };
3972 static unsigned int count
= ARRAY_SIZE(patterns
);
3975 unsigned long flags
;
3977 spin_lock_irqsave(&info
->lock
,flags
);
3980 for (i
= 0; i
< count
; i
++) {
3981 write_reg(info
, XAD1
, patterns
[i
]);
3982 write_reg(info
, XAD2
, patterns
[(i
+ 1) % count
]);
3983 if ((read_reg(info
, XAD1
) != patterns
[i
]) ||
3984 (read_reg(info
, XAD2
) != patterns
[(i
+ 1) % count
])) {
3990 spin_unlock_irqrestore(&info
->lock
,flags
);
3994 static BOOLEAN
irq_test(MGSLPC_INFO
*info
)
3996 unsigned long end_time
;
3997 unsigned long flags
;
3999 spin_lock_irqsave(&info
->lock
,flags
);
4002 info
->testing_irq
= TRUE
;
4005 info
->irq_occurred
= FALSE
;
4007 /* init hdlc mode */
4009 irq_enable(info
, CHA
, IRQ_TIMER
);
4010 write_reg(info
, CHA
+ TIMR
, 0); /* 512 cycles */
4011 issue_command(info
, CHA
, CMD_START_TIMER
);
4013 spin_unlock_irqrestore(&info
->lock
,flags
);
4016 while(end_time
-- && !info
->irq_occurred
) {
4017 msleep_interruptible(10);
4020 info
->testing_irq
= FALSE
;
4022 spin_lock_irqsave(&info
->lock
,flags
);
4024 spin_unlock_irqrestore(&info
->lock
,flags
);
4026 return info
->irq_occurred
? TRUE
: FALSE
;
4029 static int adapter_test(MGSLPC_INFO
*info
)
4031 if (!register_test(info
)) {
4032 info
->init_error
= DiagStatus_AddressFailure
;
4033 printk( "%s(%d):Register test failure for device %s Addr=%04X\n",
4034 __FILE__
,__LINE__
,info
->device_name
, (unsigned short)(info
->io_base
) );
4038 if (!irq_test(info
)) {
4039 info
->init_error
= DiagStatus_IrqFailure
;
4040 printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
4041 __FILE__
,__LINE__
,info
->device_name
, (unsigned short)(info
->irq_level
) );
4045 if (debug_level
>= DEBUG_LEVEL_INFO
)
4046 printk("%s(%d):device %s passed diagnostics\n",
4047 __FILE__
,__LINE__
,info
->device_name
);
4051 static void trace_block(MGSLPC_INFO
*info
,const char* data
, int count
, int xmit
)
4056 printk("%s tx data:\n",info
->device_name
);
4058 printk("%s rx data:\n",info
->device_name
);
4066 for(i
=0;i
<linecount
;i
++)
4067 printk("%02X ",(unsigned char)data
[i
]);
4070 for(i
=0;i
<linecount
;i
++) {
4071 if (data
[i
]>=040 && data
[i
]<=0176)
4072 printk("%c",data
[i
]);
4083 /* HDLC frame time out
4084 * update stats and do tx completion processing
4086 static void tx_timeout(unsigned long context
)
4088 MGSLPC_INFO
*info
= (MGSLPC_INFO
*)context
;
4089 unsigned long flags
;
4091 if ( debug_level
>= DEBUG_LEVEL_INFO
)
4092 printk( "%s(%d):tx_timeout(%s)\n",
4093 __FILE__
,__LINE__
,info
->device_name
);
4094 if(info
->tx_active
&&
4095 info
->params
.mode
== MGSL_MODE_HDLC
) {
4096 info
->icount
.txtimeout
++;
4098 spin_lock_irqsave(&info
->lock
,flags
);
4099 info
->tx_active
= 0;
4100 info
->tx_count
= info
->tx_put
= info
->tx_get
= 0;
4102 spin_unlock_irqrestore(&info
->lock
,flags
);
4106 hdlcdev_tx_done(info
);
4115 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
4116 * set encoding and frame check sequence (FCS) options
4118 * dev pointer to network device structure
4119 * encoding serial encoding setting
4120 * parity FCS setting
4122 * returns 0 if success, otherwise error code
4124 static int hdlcdev_attach(struct net_device
*dev
, unsigned short encoding
,
4125 unsigned short parity
)
4127 MGSLPC_INFO
*info
= dev_to_port(dev
);
4128 unsigned char new_encoding
;
4129 unsigned short new_crctype
;
4131 /* return error if TTY interface open */
4137 case ENCODING_NRZ
: new_encoding
= HDLC_ENCODING_NRZ
; break;
4138 case ENCODING_NRZI
: new_encoding
= HDLC_ENCODING_NRZI_SPACE
; break;
4139 case ENCODING_FM_MARK
: new_encoding
= HDLC_ENCODING_BIPHASE_MARK
; break;
4140 case ENCODING_FM_SPACE
: new_encoding
= HDLC_ENCODING_BIPHASE_SPACE
; break;
4141 case ENCODING_MANCHESTER
: new_encoding
= HDLC_ENCODING_BIPHASE_LEVEL
; break;
4142 default: return -EINVAL
;
4147 case PARITY_NONE
: new_crctype
= HDLC_CRC_NONE
; break;
4148 case PARITY_CRC16_PR1_CCITT
: new_crctype
= HDLC_CRC_16_CCITT
; break;
4149 case PARITY_CRC32_PR1_CCITT
: new_crctype
= HDLC_CRC_32_CCITT
; break;
4150 default: return -EINVAL
;
4153 info
->params
.encoding
= new_encoding
;
4154 info
->params
.crc_type
= new_crctype
;
4156 /* if network interface up, reprogram hardware */
4158 mgslpc_program_hw(info
);
4164 * called by generic HDLC layer to send frame
4166 * skb socket buffer containing HDLC frame
4167 * dev pointer to network device structure
4169 * returns 0 if success, otherwise error code
4171 static int hdlcdev_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
4173 MGSLPC_INFO
*info
= dev_to_port(dev
);
4174 struct net_device_stats
*stats
= hdlc_stats(dev
);
4175 unsigned long flags
;
4177 if (debug_level
>= DEBUG_LEVEL_INFO
)
4178 printk(KERN_INFO
"%s:hdlc_xmit(%s)\n",__FILE__
,dev
->name
);
4180 /* stop sending until this frame completes */
4181 netif_stop_queue(dev
);
4183 /* copy data to device buffers */
4184 memcpy(info
->tx_buf
, skb
->data
, skb
->len
);
4186 info
->tx_put
= info
->tx_count
= skb
->len
;
4188 /* update network statistics */
4189 stats
->tx_packets
++;
4190 stats
->tx_bytes
+= skb
->len
;
4192 /* done with socket buffer, so free it */
4195 /* save start time for transmit timeout detection */
4196 dev
->trans_start
= jiffies
;
4198 /* start hardware transmitter if necessary */
4199 spin_lock_irqsave(&info
->lock
,flags
);
4200 if (!info
->tx_active
)
4202 spin_unlock_irqrestore(&info
->lock
,flags
);
4208 * called by network layer when interface enabled
4209 * claim resources and initialize hardware
4211 * dev pointer to network device structure
4213 * returns 0 if success, otherwise error code
4215 static int hdlcdev_open(struct net_device
*dev
)
4217 MGSLPC_INFO
*info
= dev_to_port(dev
);
4219 unsigned long flags
;
4221 if (debug_level
>= DEBUG_LEVEL_INFO
)
4222 printk("%s:hdlcdev_open(%s)\n",__FILE__
,dev
->name
);
4224 /* generic HDLC layer open processing */
4225 if ((rc
= hdlc_open(dev
)))
4228 /* arbitrate between network and tty opens */
4229 spin_lock_irqsave(&info
->netlock
, flags
);
4230 if (info
->count
!= 0 || info
->netcount
!= 0) {
4231 printk(KERN_WARNING
"%s: hdlc_open returning busy\n", dev
->name
);
4232 spin_unlock_irqrestore(&info
->netlock
, flags
);
4236 spin_unlock_irqrestore(&info
->netlock
, flags
);
4238 /* claim resources and init adapter */
4239 if ((rc
= startup(info
)) != 0) {
4240 spin_lock_irqsave(&info
->netlock
, flags
);
4242 spin_unlock_irqrestore(&info
->netlock
, flags
);
4246 /* assert DTR and RTS, apply hardware settings */
4247 info
->serial_signals
|= SerialSignal_RTS
+ SerialSignal_DTR
;
4248 mgslpc_program_hw(info
);
4250 /* enable network layer transmit */
4251 dev
->trans_start
= jiffies
;
4252 netif_start_queue(dev
);
4254 /* inform generic HDLC layer of current DCD status */
4255 spin_lock_irqsave(&info
->lock
, flags
);
4257 spin_unlock_irqrestore(&info
->lock
, flags
);
4258 if (info
->serial_signals
& SerialSignal_DCD
)
4259 netif_carrier_on(dev
);
4261 netif_carrier_off(dev
);
4266 * called by network layer when interface is disabled
4267 * shutdown hardware and release resources
4269 * dev pointer to network device structure
4271 * returns 0 if success, otherwise error code
4273 static int hdlcdev_close(struct net_device
*dev
)
4275 MGSLPC_INFO
*info
= dev_to_port(dev
);
4276 unsigned long flags
;
4278 if (debug_level
>= DEBUG_LEVEL_INFO
)
4279 printk("%s:hdlcdev_close(%s)\n",__FILE__
,dev
->name
);
4281 netif_stop_queue(dev
);
4283 /* shutdown adapter and release resources */
4288 spin_lock_irqsave(&info
->netlock
, flags
);
4290 spin_unlock_irqrestore(&info
->netlock
, flags
);
4296 * called by network layer to process IOCTL call to network device
4298 * dev pointer to network device structure
4299 * ifr pointer to network interface request structure
4300 * cmd IOCTL command code
4302 * returns 0 if success, otherwise error code
4304 static int hdlcdev_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
4306 const size_t size
= sizeof(sync_serial_settings
);
4307 sync_serial_settings new_line
;
4308 sync_serial_settings __user
*line
= ifr
->ifr_settings
.ifs_ifsu
.sync
;
4309 MGSLPC_INFO
*info
= dev_to_port(dev
);
4312 if (debug_level
>= DEBUG_LEVEL_INFO
)
4313 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__
,dev
->name
);
4315 /* return error if TTY interface open */
4319 if (cmd
!= SIOCWANDEV
)
4320 return hdlc_ioctl(dev
, ifr
, cmd
);
4322 switch(ifr
->ifr_settings
.type
) {
4323 case IF_GET_IFACE
: /* return current sync_serial_settings */
4325 ifr
->ifr_settings
.type
= IF_IFACE_SYNC_SERIAL
;
4326 if (ifr
->ifr_settings
.size
< size
) {
4327 ifr
->ifr_settings
.size
= size
; /* data size wanted */
4331 flags
= info
->params
.flags
& (HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_RXC_DPLL
|
4332 HDLC_FLAG_RXC_BRG
| HDLC_FLAG_RXC_TXCPIN
|
4333 HDLC_FLAG_TXC_TXCPIN
| HDLC_FLAG_TXC_DPLL
|
4334 HDLC_FLAG_TXC_BRG
| HDLC_FLAG_TXC_RXCPIN
);
4337 case (HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_TXC_TXCPIN
): new_line
.clock_type
= CLOCK_EXT
; break;
4338 case (HDLC_FLAG_RXC_BRG
| HDLC_FLAG_TXC_BRG
): new_line
.clock_type
= CLOCK_INT
; break;
4339 case (HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_TXC_BRG
): new_line
.clock_type
= CLOCK_TXINT
; break;
4340 case (HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_TXC_RXCPIN
): new_line
.clock_type
= CLOCK_TXFROMRX
; break;
4341 default: new_line
.clock_type
= CLOCK_DEFAULT
;
4344 new_line
.clock_rate
= info
->params
.clock_speed
;
4345 new_line
.loopback
= info
->params
.loopback
? 1:0;
4347 if (copy_to_user(line
, &new_line
, size
))
4351 case IF_IFACE_SYNC_SERIAL
: /* set sync_serial_settings */
4353 if(!capable(CAP_NET_ADMIN
))
4355 if (copy_from_user(&new_line
, line
, size
))
4358 switch (new_line
.clock_type
)
4360 case CLOCK_EXT
: flags
= HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_TXC_TXCPIN
; break;
4361 case CLOCK_TXFROMRX
: flags
= HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_TXC_RXCPIN
; break;
4362 case CLOCK_INT
: flags
= HDLC_FLAG_RXC_BRG
| HDLC_FLAG_TXC_BRG
; break;
4363 case CLOCK_TXINT
: flags
= HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_TXC_BRG
; break;
4364 case CLOCK_DEFAULT
: flags
= info
->params
.flags
&
4365 (HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_RXC_DPLL
|
4366 HDLC_FLAG_RXC_BRG
| HDLC_FLAG_RXC_TXCPIN
|
4367 HDLC_FLAG_TXC_TXCPIN
| HDLC_FLAG_TXC_DPLL
|
4368 HDLC_FLAG_TXC_BRG
| HDLC_FLAG_TXC_RXCPIN
); break;
4369 default: return -EINVAL
;
4372 if (new_line
.loopback
!= 0 && new_line
.loopback
!= 1)
4375 info
->params
.flags
&= ~(HDLC_FLAG_RXC_RXCPIN
| HDLC_FLAG_RXC_DPLL
|
4376 HDLC_FLAG_RXC_BRG
| HDLC_FLAG_RXC_TXCPIN
|
4377 HDLC_FLAG_TXC_TXCPIN
| HDLC_FLAG_TXC_DPLL
|
4378 HDLC_FLAG_TXC_BRG
| HDLC_FLAG_TXC_RXCPIN
);
4379 info
->params
.flags
|= flags
;
4381 info
->params
.loopback
= new_line
.loopback
;
4383 if (flags
& (HDLC_FLAG_RXC_BRG
| HDLC_FLAG_TXC_BRG
))
4384 info
->params
.clock_speed
= new_line
.clock_rate
;
4386 info
->params
.clock_speed
= 0;
4388 /* if network interface up, reprogram hardware */
4390 mgslpc_program_hw(info
);
4394 return hdlc_ioctl(dev
, ifr
, cmd
);
4399 * called by network layer when transmit timeout is detected
4401 * dev pointer to network device structure
4403 static void hdlcdev_tx_timeout(struct net_device
*dev
)
4405 MGSLPC_INFO
*info
= dev_to_port(dev
);
4406 struct net_device_stats
*stats
= hdlc_stats(dev
);
4407 unsigned long flags
;
4409 if (debug_level
>= DEBUG_LEVEL_INFO
)
4410 printk("hdlcdev_tx_timeout(%s)\n",dev
->name
);
4413 stats
->tx_aborted_errors
++;
4415 spin_lock_irqsave(&info
->lock
,flags
);
4417 spin_unlock_irqrestore(&info
->lock
,flags
);
4419 netif_wake_queue(dev
);
4423 * called by device driver when transmit completes
4424 * reenable network layer transmit if stopped
4426 * info pointer to device instance information
4428 static void hdlcdev_tx_done(MGSLPC_INFO
*info
)
4430 if (netif_queue_stopped(info
->netdev
))
4431 netif_wake_queue(info
->netdev
);
4435 * called by device driver when frame received
4436 * pass frame to network layer
4438 * info pointer to device instance information
4439 * buf pointer to buffer contianing frame data
4440 * size count of data bytes in buf
4442 static void hdlcdev_rx(MGSLPC_INFO
*info
, char *buf
, int size
)
4444 struct sk_buff
*skb
= dev_alloc_skb(size
);
4445 struct net_device
*dev
= info
->netdev
;
4446 struct net_device_stats
*stats
= hdlc_stats(dev
);
4448 if (debug_level
>= DEBUG_LEVEL_INFO
)
4449 printk("hdlcdev_rx(%s)\n",dev
->name
);
4452 printk(KERN_NOTICE
"%s: can't alloc skb, dropping packet\n", dev
->name
);
4453 stats
->rx_dropped
++;
4457 memcpy(skb_put(skb
, size
),buf
,size
);
4459 skb
->protocol
= hdlc_type_trans(skb
, info
->netdev
);
4461 stats
->rx_packets
++;
4462 stats
->rx_bytes
+= size
;
4466 info
->netdev
->last_rx
= jiffies
;
4470 * called by device driver when adding device instance
4471 * do generic HDLC initialization
4473 * info pointer to device instance information
4475 * returns 0 if success, otherwise error code
4477 static int hdlcdev_init(MGSLPC_INFO
*info
)
4480 struct net_device
*dev
;
4483 /* allocate and initialize network and HDLC layer objects */
4485 if (!(dev
= alloc_hdlcdev(info
))) {
4486 printk(KERN_ERR
"%s:hdlc device allocation failure\n",__FILE__
);
4490 /* for network layer reporting purposes only */
4491 dev
->base_addr
= info
->io_base
;
4492 dev
->irq
= info
->irq_level
;
4494 /* network layer callbacks and settings */
4495 dev
->do_ioctl
= hdlcdev_ioctl
;
4496 dev
->open
= hdlcdev_open
;
4497 dev
->stop
= hdlcdev_close
;
4498 dev
->tx_timeout
= hdlcdev_tx_timeout
;
4499 dev
->watchdog_timeo
= 10*HZ
;
4500 dev
->tx_queue_len
= 50;
4502 /* generic HDLC layer callbacks and settings */
4503 hdlc
= dev_to_hdlc(dev
);
4504 hdlc
->attach
= hdlcdev_attach
;
4505 hdlc
->xmit
= hdlcdev_xmit
;
4507 /* register objects with HDLC layer */
4508 if ((rc
= register_hdlc_device(dev
))) {
4509 printk(KERN_WARNING
"%s:unable to register hdlc device\n",__FILE__
);
4519 * called by device driver when removing device instance
4520 * do generic HDLC cleanup
4522 * info pointer to device instance information
4524 static void hdlcdev_exit(MGSLPC_INFO
*info
)
4526 unregister_hdlc_device(info
->netdev
);
4527 free_netdev(info
->netdev
);
4528 info
->netdev
= NULL
;
4531 #endif /* CONFIG_HDLC */