2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/drivers/char/pcmcia/synclink_cs.c
|
|
|
|
*
|
2005-09-10 15:26:07 +08:00
|
|
|
* $Id: synclink_cs.c,v 4.34 2005/09/08 13:20:54 paulkf Exp $
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* Device driver for Microgate SyncLink PC Card
|
|
|
|
* multiprotocol serial adapter.
|
|
|
|
*
|
|
|
|
* written by Paul Fulghum for Microgate Corporation
|
|
|
|
* paulkf@microgate.com
|
|
|
|
*
|
|
|
|
* Microgate and SyncLink are trademarks of Microgate Corporation
|
|
|
|
*
|
|
|
|
* This code is released under the GNU General Public License (GPL)
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
|
|
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
|
|
|
|
#if defined(__i386__)
|
|
|
|
# define BREAKPOINT() asm(" int $3");
|
|
|
|
#else
|
|
|
|
# define BREAKPOINT() { }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define MAX_DEVICE_COUNT 4
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/mm.h>
|
2009-04-01 06:19:17 +08:00
|
|
|
#include <linux/seq_file.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/ioctl.h>
|
2008-02-06 17:37:17 +08:00
|
|
|
#include <linux/synclink.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/system.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/irq.h>
|
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <asm/types.h>
|
|
|
|
#include <linux/termios.h>
|
|
|
|
#include <linux/workqueue.h>
|
|
|
|
#include <linux/hdlc.h>
|
|
|
|
|
|
|
|
#include <pcmcia/cs_types.h>
|
|
|
|
#include <pcmcia/cs.h>
|
|
|
|
#include <pcmcia/cistpl.h>
|
|
|
|
#include <pcmcia/cisreg.h>
|
|
|
|
#include <pcmcia/ds.h>
|
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_CS_MODULE))
|
|
|
|
#define SYNCLINK_GENERIC_HDLC 1
|
|
|
|
#else
|
|
|
|
#define SYNCLINK_GENERIC_HDLC 0
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define GET_USER(error,value,addr) error = get_user(value,addr)
|
|
|
|
#define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
|
|
|
|
#define PUT_USER(error,value,addr) error = put_user(value,addr)
|
|
|
|
#define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
|
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
static MGSL_PARAMS default_params = {
|
|
|
|
MGSL_MODE_HDLC, /* unsigned long mode */
|
|
|
|
0, /* unsigned char loopback; */
|
|
|
|
HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
|
|
|
|
HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
|
|
|
|
0, /* unsigned long clock_speed; */
|
|
|
|
0xff, /* unsigned char addr_filter; */
|
|
|
|
HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
|
|
|
|
HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
|
|
|
|
HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
|
|
|
|
9600, /* unsigned long data_rate; */
|
|
|
|
8, /* unsigned char data_bits; */
|
|
|
|
1, /* unsigned char stop_bits; */
|
|
|
|
ASYNC_PARITY_NONE /* unsigned char parity; */
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
unsigned char status;
|
|
|
|
char data[1];
|
|
|
|
} RXBUF;
|
|
|
|
|
|
|
|
/* The queue of BH actions to be performed */
|
|
|
|
|
|
|
|
#define BH_RECEIVE 1
|
|
|
|
#define BH_TRANSMIT 2
|
|
|
|
#define BH_STATUS 4
|
|
|
|
|
|
|
|
#define IO_PIN_SHUTDOWN_LIMIT 100
|
|
|
|
|
|
|
|
#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
|
|
|
|
|
|
|
|
struct _input_signal_events {
|
2007-10-20 03:45:35 +08:00
|
|
|
int ri_up;
|
2005-04-17 06:20:36 +08:00
|
|
|
int ri_down;
|
|
|
|
int dsr_up;
|
|
|
|
int dsr_down;
|
|
|
|
int dcd_up;
|
|
|
|
int dcd_down;
|
|
|
|
int cts_up;
|
|
|
|
int cts_down;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Device instance data structure
|
|
|
|
*/
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
typedef struct _mgslpc_info {
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_port port;
|
2005-04-17 06:20:36 +08:00
|
|
|
void *if_ptr; /* General purpose pointer (used by SPPP) */
|
|
|
|
int magic;
|
|
|
|
int line;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct mgsl_icount icount;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int timeout;
|
|
|
|
int x_char; /* xon/xoff character */
|
|
|
|
unsigned char read_status_mask;
|
2007-10-20 03:45:35 +08:00
|
|
|
unsigned char ignore_status_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
unsigned char *tx_buf;
|
|
|
|
int tx_put;
|
|
|
|
int tx_get;
|
|
|
|
int tx_count;
|
|
|
|
|
|
|
|
/* circular list of fixed length rx buffers */
|
|
|
|
|
|
|
|
unsigned char *rx_buf; /* memory allocated for all rx buffers */
|
|
|
|
int rx_buf_total_size; /* size of memory allocated for rx buffers */
|
|
|
|
int rx_put; /* index of next empty rx buffer */
|
|
|
|
int rx_get; /* index of next full rx buffer */
|
|
|
|
int rx_buf_size; /* size in bytes of single rx buffer */
|
|
|
|
int rx_buf_count; /* total number of rx buffers */
|
|
|
|
int rx_frame_count; /* number of full rx buffers */
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
wait_queue_head_t status_event_wait_q;
|
|
|
|
wait_queue_head_t event_wait_q;
|
|
|
|
struct timer_list tx_timer; /* HDLC transmit timeout timer */
|
|
|
|
struct _mgslpc_info *next_device; /* device list link */
|
|
|
|
|
|
|
|
unsigned short imra_value;
|
|
|
|
unsigned short imrb_value;
|
|
|
|
unsigned char pim_value;
|
|
|
|
|
|
|
|
spinlock_t lock;
|
|
|
|
struct work_struct task; /* task structure for scheduling bh */
|
|
|
|
|
|
|
|
u32 max_frame_size;
|
|
|
|
|
|
|
|
u32 pending_bh;
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
bool bh_running;
|
|
|
|
bool bh_requested;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int dcd_chkcount; /* check counts to prevent */
|
|
|
|
int cts_chkcount; /* too many IRQs if a signal */
|
|
|
|
int dsr_chkcount; /* is floating */
|
|
|
|
int ri_chkcount;
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
bool rx_enabled;
|
|
|
|
bool rx_overflow;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
bool tx_enabled;
|
|
|
|
bool tx_active;
|
|
|
|
bool tx_aborting;
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 idle_mode;
|
|
|
|
|
|
|
|
int if_mode; /* serial interface selection (RS-232, v.35 etc) */
|
|
|
|
|
|
|
|
char device_name[25]; /* device instance name */
|
|
|
|
|
|
|
|
unsigned int io_base; /* base I/O address of adapter */
|
|
|
|
unsigned int irq_level;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
MGSL_PARAMS params; /* communications parameters */
|
|
|
|
|
|
|
|
unsigned char serial_signals; /* current serial signal states */
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
bool irq_occurred; /* for diagnostics use */
|
2005-04-17 06:20:36 +08:00
|
|
|
char testing_irq;
|
|
|
|
unsigned int init_error; /* startup error (DIAGS) */
|
|
|
|
|
|
|
|
char flag_buf[MAX_ASYNC_BUFFER_SIZE];
|
2008-04-28 17:14:02 +08:00
|
|
|
bool drop_rts_on_tx_done;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
struct _input_signal_events input_signal_events;
|
|
|
|
|
|
|
|
/* PCMCIA support */
|
2006-03-05 17:45:09 +08:00
|
|
|
struct pcmcia_device *p_dev;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev_node_t node;
|
|
|
|
int stop;
|
|
|
|
|
|
|
|
/* SPPP/Cisco HDLC device parts */
|
|
|
|
int netcount;
|
|
|
|
spinlock_t netlock;
|
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
struct net_device *netdev;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} MGSLPC_INFO;
|
|
|
|
|
|
|
|
#define MGSLPC_MAGIC 0x5402
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The size of the serial xmit buffer is 1 page, or 4096 bytes
|
|
|
|
*/
|
|
|
|
#define TXBUFSIZE 4096
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define CHA 0x00 /* channel A offset */
|
|
|
|
#define CHB 0x40 /* channel B offset */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: PPC has PVR defined in asm/reg.h. For now we just undef it.
|
|
|
|
*/
|
|
|
|
#undef PVR
|
|
|
|
|
|
|
|
#define RXFIFO 0
|
|
|
|
#define TXFIFO 0
|
|
|
|
#define STAR 0x20
|
|
|
|
#define CMDR 0x20
|
|
|
|
#define RSTA 0x21
|
|
|
|
#define PRE 0x21
|
|
|
|
#define MODE 0x22
|
|
|
|
#define TIMR 0x23
|
|
|
|
#define XAD1 0x24
|
|
|
|
#define XAD2 0x25
|
|
|
|
#define RAH1 0x26
|
|
|
|
#define RAH2 0x27
|
|
|
|
#define DAFO 0x27
|
|
|
|
#define RAL1 0x28
|
|
|
|
#define RFC 0x28
|
|
|
|
#define RHCR 0x29
|
|
|
|
#define RAL2 0x29
|
|
|
|
#define RBCL 0x2a
|
|
|
|
#define XBCL 0x2a
|
|
|
|
#define RBCH 0x2b
|
|
|
|
#define XBCH 0x2b
|
|
|
|
#define CCR0 0x2c
|
|
|
|
#define CCR1 0x2d
|
|
|
|
#define CCR2 0x2e
|
|
|
|
#define CCR3 0x2f
|
|
|
|
#define VSTR 0x34
|
|
|
|
#define BGR 0x34
|
|
|
|
#define RLCR 0x35
|
|
|
|
#define AML 0x36
|
|
|
|
#define AMH 0x37
|
|
|
|
#define GIS 0x38
|
|
|
|
#define IVA 0x38
|
|
|
|
#define IPC 0x39
|
|
|
|
#define ISR 0x3a
|
|
|
|
#define IMR 0x3a
|
|
|
|
#define PVR 0x3c
|
|
|
|
#define PIS 0x3d
|
|
|
|
#define PIM 0x3d
|
|
|
|
#define PCR 0x3e
|
|
|
|
#define CCR4 0x3f
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
// IMR/ISR
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define IRQ_BREAK_ON BIT15 // rx break detected
|
|
|
|
#define IRQ_DATAOVERRUN BIT14 // receive data overflow
|
|
|
|
#define IRQ_ALLSENT BIT13 // all sent
|
|
|
|
#define IRQ_UNDERRUN BIT12 // transmit data underrun
|
|
|
|
#define IRQ_TIMER BIT11 // timer interrupt
|
|
|
|
#define IRQ_CTS BIT10 // CTS status change
|
|
|
|
#define IRQ_TXREPEAT BIT9 // tx message repeat
|
|
|
|
#define IRQ_TXFIFO BIT8 // transmit pool ready
|
|
|
|
#define IRQ_RXEOM BIT7 // receive message end
|
|
|
|
#define IRQ_EXITHUNT BIT6 // receive frame start
|
|
|
|
#define IRQ_RXTIME BIT6 // rx char timeout
|
|
|
|
#define IRQ_DCD BIT2 // carrier detect status change
|
|
|
|
#define IRQ_OVERRUN BIT1 // receive frame overflow
|
|
|
|
#define IRQ_RXFIFO BIT0 // receive pool full
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
// STAR
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define XFW BIT6 // transmit FIFO write enable
|
|
|
|
#define CEC BIT2 // command executing
|
|
|
|
#define CTS BIT1 // CTS state
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define PVR_DTR BIT0
|
|
|
|
#define PVR_DSR BIT1
|
|
|
|
#define PVR_RI BIT2
|
|
|
|
#define PVR_AUTOCTS BIT3
|
|
|
|
#define PVR_RS232 0x20 /* 0010b */
|
|
|
|
#define PVR_V35 0xe0 /* 1110b */
|
|
|
|
#define PVR_RS422 0x40 /* 0100b */
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* Register access functions */
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define write_reg(info, reg, val) outb((val),(info)->io_base + (reg))
|
|
|
|
#define read_reg(info, reg) inb((info)->io_base + (reg))
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
#define read_reg16(info, reg) inw((info)->io_base + (reg))
|
2005-04-17 06:20:36 +08:00
|
|
|
#define write_reg16(info, reg, val) outw((val), (info)->io_base + (reg))
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#define set_reg_bits(info, reg, mask) \
|
|
|
|
write_reg(info, (reg), \
|
2007-10-20 03:45:35 +08:00
|
|
|
(unsigned char) (read_reg(info, (reg)) | (mask)))
|
2005-04-17 06:20:36 +08:00
|
|
|
#define clear_reg_bits(info, reg, mask) \
|
|
|
|
write_reg(info, (reg), \
|
2007-10-20 03:45:35 +08:00
|
|
|
(unsigned char) (read_reg(info, (reg)) & ~(mask)))
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* interrupt enable/disable routines
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
|
|
|
static void irq_disable(MGSLPC_INFO *info, unsigned char channel, unsigned short mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (channel == CHA) {
|
|
|
|
info->imra_value |= mask;
|
|
|
|
write_reg16(info, CHA + IMR, info->imra_value);
|
|
|
|
} else {
|
|
|
|
info->imrb_value |= mask;
|
|
|
|
write_reg16(info, CHB + IMR, info->imrb_value);
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
static void irq_enable(MGSLPC_INFO *info, unsigned char channel, unsigned short mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (channel == CHA) {
|
|
|
|
info->imra_value &= ~mask;
|
|
|
|
write_reg16(info, CHA + IMR, info->imra_value);
|
|
|
|
} else {
|
|
|
|
info->imrb_value &= ~mask;
|
|
|
|
write_reg16(info, CHB + IMR, info->imrb_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define port_irq_disable(info, mask) \
|
|
|
|
{ info->pim_value |= (mask); write_reg(info, PIM, info->pim_value); }
|
|
|
|
|
|
|
|
#define port_irq_enable(info, mask) \
|
|
|
|
{ info->pim_value &= ~(mask); write_reg(info, PIM, info->pim_value); }
|
|
|
|
|
|
|
|
static void rx_start(MGSLPC_INFO *info);
|
|
|
|
static void rx_stop(MGSLPC_INFO *info);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void tx_stop(MGSLPC_INFO *info);
|
|
|
|
static void tx_set_idle(MGSLPC_INFO *info);
|
|
|
|
|
|
|
|
static void get_signals(MGSLPC_INFO *info);
|
|
|
|
static void set_signals(MGSLPC_INFO *info);
|
|
|
|
|
|
|
|
static void reset_device(MGSLPC_INFO *info);
|
|
|
|
|
|
|
|
static void hdlc_mode(MGSLPC_INFO *info);
|
|
|
|
static void async_mode(MGSLPC_INFO *info);
|
|
|
|
|
|
|
|
static void tx_timeout(unsigned long context);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static int carrier_raised(struct tty_port *port);
|
2009-06-11 19:24:17 +08:00
|
|
|
static void dtr_rts(struct tty_port *port, int onoff);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
#define dev_to_port(D) (dev_to_hdlc(D)->priv)
|
|
|
|
static void hdlcdev_tx_done(MGSLPC_INFO *info);
|
|
|
|
static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size);
|
|
|
|
static int hdlcdev_init(MGSLPC_INFO *info);
|
|
|
|
static void hdlcdev_exit(MGSLPC_INFO *info);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit);
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
static bool register_test(MGSLPC_INFO *info);
|
|
|
|
static bool irq_test(MGSLPC_INFO *info);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int adapter_test(MGSLPC_INFO *info);
|
|
|
|
|
|
|
|
static int claim_resources(MGSLPC_INFO *info);
|
|
|
|
static void release_resources(MGSLPC_INFO *info);
|
|
|
|
static void mgslpc_add_device(MGSLPC_INFO *info);
|
|
|
|
static void mgslpc_remove_device(MGSLPC_INFO *info);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void rx_reset_buffers(MGSLPC_INFO *info);
|
|
|
|
static int rx_alloc_buffers(MGSLPC_INFO *info);
|
|
|
|
static void rx_free_buffers(MGSLPC_INFO *info);
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static irqreturn_t mgslpc_isr(int irq, void *dev_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Bottom half interrupt handlers
|
|
|
|
*/
|
2006-11-22 22:57:56 +08:00
|
|
|
static void bh_handler(struct work_struct *work);
|
2009-01-02 21:48:47 +08:00
|
|
|
static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void bh_status(MGSLPC_INFO *info);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ioctl handlers
|
|
|
|
*/
|
|
|
|
static int tiocmget(struct tty_struct *tty, struct file *file);
|
|
|
|
static int tiocmset(struct tty_struct *tty, struct file *file,
|
|
|
|
unsigned int set, unsigned int clear);
|
|
|
|
static int get_stats(MGSLPC_INFO *info, struct mgsl_icount __user *user_icount);
|
|
|
|
static int get_params(MGSLPC_INFO *info, MGSL_PARAMS __user *user_params);
|
2009-01-02 21:48:47 +08:00
|
|
|
static int set_params(MGSLPC_INFO *info, MGSL_PARAMS __user *new_params, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int get_txidle(MGSLPC_INFO *info, int __user *idle_mode);
|
|
|
|
static int set_txidle(MGSLPC_INFO *info, int idle_mode);
|
2009-01-02 21:48:47 +08:00
|
|
|
static int set_txenable(MGSLPC_INFO *info, int enable, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int tx_abort(MGSLPC_INFO *info);
|
|
|
|
static int set_rxenable(MGSLPC_INFO *info, int enable);
|
|
|
|
static int wait_events(MGSLPC_INFO *info, int __user *mask);
|
|
|
|
|
|
|
|
static MGSLPC_INFO *mgslpc_device_list = NULL;
|
|
|
|
static int mgslpc_device_count = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set this param to non-zero to load eax with the
|
|
|
|
* .text section address and breakpoint on module load.
|
|
|
|
* This is useful for use with gdb and add-symbol-file command.
|
|
|
|
*/
|
|
|
|
static int break_on_load=0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Driver major number, defaults to zero to get auto
|
|
|
|
* assigned major number. May be forced as module parameter.
|
|
|
|
*/
|
|
|
|
static int ttymajor=0;
|
|
|
|
|
|
|
|
static int debug_level = 0;
|
|
|
|
static int maxframe[MAX_DEVICE_COUNT] = {0,};
|
|
|
|
|
|
|
|
module_param(break_on_load, bool, 0);
|
|
|
|
module_param(ttymajor, int, 0);
|
|
|
|
module_param(debug_level, int, 0);
|
|
|
|
module_param_array(maxframe, int, NULL, 0);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static char *driver_name = "SyncLink PC Card driver";
|
2005-09-10 15:26:07 +08:00
|
|
|
static char *driver_version = "$Revision: 4.34 $";
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct tty_driver *serial_driver;
|
|
|
|
|
|
|
|
/* number of characters left in xmit buffer before we ask for more */
|
|
|
|
#define WAKEUP_CHARS 256
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout);
|
|
|
|
|
|
|
|
/* PCMCIA prototypes */
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int mgslpc_config(struct pcmcia_device *link);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void mgslpc_release(u_long arg);
|
2005-11-15 04:23:14 +08:00
|
|
|
static void mgslpc_detach(struct pcmcia_device *p_dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 1st function defined in .text section. Calling this function in
|
|
|
|
* init_module() followed by a breakpoint allows a remote debugger
|
|
|
|
* (gdb) to get the .text address for the add-symbol-file command.
|
|
|
|
* This allows remote debugging of dynamically loadable modules.
|
|
|
|
*/
|
|
|
|
static void* mgslpc_get_text_ptr(void)
|
|
|
|
{
|
|
|
|
return mgslpc_get_text_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* line discipline callback wrappers
|
|
|
|
*
|
|
|
|
* The wrappers maintain line discipline references
|
|
|
|
* while calling into the line discipline.
|
|
|
|
*
|
|
|
|
* ldisc_receive_buf - pass receive data to line discipline
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ldisc_receive_buf(struct tty_struct *tty,
|
|
|
|
const __u8 *data, char *flags, int count)
|
|
|
|
{
|
|
|
|
struct tty_ldisc *ld;
|
|
|
|
if (!tty)
|
|
|
|
return;
|
|
|
|
ld = tty_ldisc_ref(tty);
|
|
|
|
if (ld) {
|
2008-07-17 04:53:12 +08:00
|
|
|
if (ld->ops->receive_buf)
|
|
|
|
ld->ops->receive_buf(tty, data, flags, count);
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_ldisc_deref(ld);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static const struct tty_port_operations mgslpc_port_ops = {
|
|
|
|
.carrier_raised = carrier_raised,
|
2009-06-11 19:24:17 +08:00
|
|
|
.dtr_rts = dtr_rts
|
2009-01-02 21:48:47 +08:00
|
|
|
};
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int mgslpc_probe(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info;
|
2006-03-31 23:26:06 +08:00
|
|
|
int ret;
|
2006-03-05 17:45:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("mgslpc_attach\n");
|
2006-03-05 17:45:09 +08:00
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 16:49:03 +08:00
|
|
|
info = kzalloc(sizeof(MGSLPC_INFO), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!info) {
|
|
|
|
printk("Error can't allocate device instance data\n");
|
2005-11-15 04:25:51 +08:00
|
|
|
return -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
info->magic = MGSLPC_MAGIC;
|
2009-01-02 21:48:47 +08:00
|
|
|
tty_port_init(&info->port);
|
|
|
|
info->port.ops = &mgslpc_port_ops;
|
2006-11-22 22:57:56 +08:00
|
|
|
INIT_WORK(&info->task, bh_handler);
|
2005-04-17 06:20:36 +08:00
|
|
|
info->max_frame_size = 4096;
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.close_delay = 5*HZ/10;
|
|
|
|
info->port.closing_wait = 30*HZ;
|
2005-04-17 06:20:36 +08:00
|
|
|
init_waitqueue_head(&info->status_event_wait_q);
|
|
|
|
init_waitqueue_head(&info->event_wait_q);
|
|
|
|
spin_lock_init(&info->lock);
|
|
|
|
spin_lock_init(&info->netlock);
|
|
|
|
memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
|
2007-10-20 03:45:35 +08:00
|
|
|
info->idle_mode = HDLC_TXIDLE_FLAGS;
|
2005-04-17 06:20:36 +08:00
|
|
|
info->imra_value = 0xffff;
|
|
|
|
info->imrb_value = 0xffff;
|
|
|
|
info->pim_value = 0xff;
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
info->p_dev = link;
|
2005-04-17 06:20:36 +08:00
|
|
|
link->priv = info;
|
2006-03-05 17:45:09 +08:00
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
/* Initialize the struct pcmcia_device structure */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Interrupt setup */
|
2008-10-06 00:35:41 +08:00
|
|
|
link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
|
2005-06-28 07:28:56 +08:00
|
|
|
link->irq.IRQInfo1 = IRQ_LEVEL_ID;
|
2005-04-17 06:20:36 +08:00
|
|
|
link->irq.Handler = NULL;
|
2006-03-05 17:45:09 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
link->conf.Attributes = 0;
|
|
|
|
link->conf.IntType = INT_MEMORY_AND_IO;
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
ret = mgslpc_config(link);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
mgslpc_add_device(info);
|
|
|
|
|
2005-11-15 04:25:51 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Card has been inserted.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CS_CHECK(fn, ret) \
|
|
|
|
do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
|
|
|
|
|
2006-03-31 23:26:06 +08:00
|
|
|
static int mgslpc_config(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = link->priv;
|
|
|
|
tuple_t tuple;
|
|
|
|
cisparse_t parse;
|
|
|
|
int last_fn, last_ret;
|
|
|
|
u_char buf[64];
|
|
|
|
cistpl_cftable_entry_t dflt = { 0 };
|
|
|
|
cistpl_cftable_entry_t *cfg;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("mgslpc_config(0x%p)\n", link);
|
|
|
|
|
|
|
|
tuple.Attributes = 0;
|
|
|
|
tuple.TupleData = buf;
|
|
|
|
tuple.TupleDataMax = sizeof(buf);
|
|
|
|
tuple.TupleOffset = 0;
|
|
|
|
|
|
|
|
/* get CIS configuration entry */
|
|
|
|
|
|
|
|
tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
|
2006-03-31 23:21:06 +08:00
|
|
|
CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cfg = &(parse.cftable_entry);
|
2006-03-31 23:21:06 +08:00
|
|
|
CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
|
2008-08-31 21:50:33 +08:00
|
|
|
CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
|
|
|
|
if (cfg->index == 0)
|
|
|
|
goto cs_failed;
|
|
|
|
|
|
|
|
link->conf.ConfigIndex = cfg->index;
|
|
|
|
link->conf.Attributes |= CONF_ENABLE_IRQ;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* IO window settings */
|
|
|
|
link->io.NumPorts1 = 0;
|
|
|
|
if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
|
|
|
|
cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
|
|
|
|
link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
|
|
|
|
if (!(io->flags & CISTPL_IO_8BIT))
|
|
|
|
link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
|
|
|
|
if (!(io->flags & CISTPL_IO_16BIT))
|
|
|
|
link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
|
|
|
|
link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
|
|
|
|
link->io.BasePort1 = io->win[0].base;
|
|
|
|
link->io.NumPorts1 = io->win[0].len;
|
2006-03-31 23:21:06 +08:00
|
|
|
CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
link->conf.Attributes = CONF_ENABLE_IRQ;
|
|
|
|
link->conf.IntType = INT_MEMORY_AND_IO;
|
|
|
|
link->conf.ConfigIndex = 8;
|
|
|
|
link->conf.Present = PRESENT_OPTION;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
link->irq.Attributes |= IRQ_HANDLE_PRESENT;
|
|
|
|
link->irq.Handler = mgslpc_isr;
|
|
|
|
link->irq.Instance = info;
|
2006-03-31 23:21:06 +08:00
|
|
|
CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
info->io_base = link->io.BasePort1;
|
|
|
|
info->irq_level = link->irq.AssignedIRQ;
|
|
|
|
|
|
|
|
/* add to linked list of devices */
|
|
|
|
sprintf(info->node.dev_name, "mgslpc0");
|
|
|
|
info->node.major = info->node.minor = 0;
|
2006-03-05 17:45:09 +08:00
|
|
|
link->dev_node = &info->node;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
printk(KERN_INFO "%s: index 0x%02x:",
|
|
|
|
info->node.dev_name, link->conf.ConfigIndex);
|
|
|
|
if (link->conf.Attributes & CONF_ENABLE_IRQ)
|
|
|
|
printk(", irq %d", link->irq.AssignedIRQ);
|
|
|
|
if (link->io.NumPorts1)
|
|
|
|
printk(", io 0x%04x-0x%04x", link->io.BasePort1,
|
|
|
|
link->io.BasePort1+link->io.NumPorts1-1);
|
|
|
|
printk("\n");
|
2006-03-31 23:26:06 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
cs_failed:
|
2006-03-31 23:21:06 +08:00
|
|
|
cs_error(link, last_fn, last_ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
mgslpc_release((u_long)link);
|
2006-03-31 23:26:06 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Card has been removed.
|
|
|
|
* Unregister device and release PCMCIA configuration.
|
|
|
|
* If device is open, postpone until it is closed.
|
|
|
|
*/
|
|
|
|
static void mgslpc_release(u_long arg)
|
|
|
|
{
|
2006-03-02 07:09:29 +08:00
|
|
|
struct pcmcia_device *link = (struct pcmcia_device *)arg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("mgslpc_release(0x%p)\n", link);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
pcmcia_disable_device(link);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static void mgslpc_detach(struct pcmcia_device *link)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-03-02 07:09:29 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("mgslpc_detach(0x%p)\n", link);
|
2005-11-15 04:23:14 +08:00
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
((MGSLPC_INFO *)link->priv)->stop = 1;
|
|
|
|
mgslpc_release((u_long)link);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
mgslpc_remove_device((MGSLPC_INFO *)link->priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static int mgslpc_suspend(struct pcmcia_device *link)
|
2005-11-15 04:21:18 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = link->priv;
|
|
|
|
|
|
|
|
info->stop = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-31 23:21:06 +08:00
|
|
|
static int mgslpc_resume(struct pcmcia_device *link)
|
2005-11-15 04:21:18 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = link->priv;
|
|
|
|
|
|
|
|
info->stop = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
static inline bool mgslpc_paranoia_check(MGSLPC_INFO *info,
|
2005-04-17 06:20:36 +08:00
|
|
|
char *name, const char *routine)
|
|
|
|
{
|
|
|
|
#ifdef MGSLPC_PARANOIA_CHECK
|
|
|
|
static const char *badmagic =
|
|
|
|
"Warning: bad magic number for mgsl struct (%s) in %s\n";
|
|
|
|
static const char *badinfo =
|
|
|
|
"Warning: null mgslpc_info for (%s) in %s\n";
|
|
|
|
|
|
|
|
if (!info) {
|
|
|
|
printk(badinfo, name, routine);
|
2008-04-28 17:14:02 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (info->magic != MGSLPC_MAGIC) {
|
|
|
|
printk(badmagic, name, routine);
|
2008-04-28 17:14:02 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (!info)
|
2008-04-28 17:14:02 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
2008-04-28 17:14:02 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define CMD_RXFIFO BIT7 // release current rx FIFO
|
|
|
|
#define CMD_RXRESET BIT6 // receiver reset
|
|
|
|
#define CMD_RXFIFO_READ BIT5
|
|
|
|
#define CMD_START_TIMER BIT4
|
|
|
|
#define CMD_TXFIFO BIT3 // release current tx FIFO
|
|
|
|
#define CMD_TXEOM BIT1 // transmit end message
|
|
|
|
#define CMD_TXRESET BIT0 // transmit reset
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
static bool wait_command_complete(MGSLPC_INFO *info, unsigned char channel)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
/* wait for command completion */
|
2005-04-17 06:20:36 +08:00
|
|
|
while (read_reg(info, (unsigned char)(channel+STAR)) & BIT2) {
|
|
|
|
udelay(1);
|
|
|
|
if (i++ == 1000)
|
2008-04-28 17:14:02 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-28 17:14:02 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
static void issue_command(MGSLPC_INFO *info, unsigned char channel, unsigned char cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
wait_command_complete(info, channel);
|
|
|
|
write_reg(info, (unsigned char) (channel + CMDR), cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tx_pause(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "tx_pause"))
|
|
|
|
return;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
2007-10-20 03:45:35 +08:00
|
|
|
printk("tx_pause(%s)\n",info->device_name);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (info->tx_enabled)
|
|
|
|
tx_stop(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tx_release(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "tx_release"))
|
|
|
|
return;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
2007-10-20 03:45:35 +08:00
|
|
|
printk("tx_release(%s)\n",info->device_name);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (!info->tx_enabled)
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_start(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return next bottom half action to perform.
|
|
|
|
* or 0 if nothing to do.
|
|
|
|
*/
|
|
|
|
static int bh_action(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int rc = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
|
|
|
|
if (info->pending_bh & BH_RECEIVE) {
|
|
|
|
info->pending_bh &= ~BH_RECEIVE;
|
|
|
|
rc = BH_RECEIVE;
|
|
|
|
} else if (info->pending_bh & BH_TRANSMIT) {
|
|
|
|
info->pending_bh &= ~BH_TRANSMIT;
|
|
|
|
rc = BH_TRANSMIT;
|
|
|
|
} else if (info->pending_bh & BH_STATUS) {
|
|
|
|
info->pending_bh &= ~BH_STATUS;
|
|
|
|
rc = BH_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rc) {
|
|
|
|
/* Mark BH routine as complete */
|
2008-04-28 17:14:02 +08:00
|
|
|
info->bh_running = false;
|
|
|
|
info->bh_requested = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static void bh_handler(struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-11-22 22:57:56 +08:00
|
|
|
MGSLPC_INFO *info = container_of(work, MGSLPC_INFO, task);
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_struct *tty;
|
2005-04-17 06:20:36 +08:00
|
|
|
int action;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_BH)
|
|
|
|
printk( "%s(%d):bh_handler(%s) entry\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->bh_running = true;
|
2009-01-02 21:48:47 +08:00
|
|
|
tty = tty_port_tty_get(&info->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
while((action = bh_action(info)) != 0) {
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Process work item */
|
|
|
|
if ( debug_level >= DEBUG_LEVEL_BH )
|
|
|
|
printk( "%s(%d):bh_handler() work item action=%d\n",
|
|
|
|
__FILE__,__LINE__,action);
|
|
|
|
|
|
|
|
switch (action) {
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
case BH_RECEIVE:
|
2009-01-02 21:48:47 +08:00
|
|
|
while(rx_get_frame(info, tty));
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case BH_TRANSMIT:
|
2009-01-02 21:48:47 +08:00
|
|
|
bh_transmit(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
case BH_STATUS:
|
|
|
|
bh_status(info);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unknown work item ID */
|
|
|
|
printk("Unknown work item ID=%08X!\n", action);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_BH)
|
|
|
|
printk( "%s(%d):bh_handler(%s) exit\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void bh_transmit(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (debug_level >= DEBUG_LEVEL_BH)
|
|
|
|
printk("bh_transmit() entry on %s\n", info->device_name);
|
|
|
|
|
2007-02-10 17:44:55 +08:00
|
|
|
if (tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void bh_status(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
info->ri_chkcount = 0;
|
|
|
|
info->dsr_chkcount = 0;
|
|
|
|
info->dcd_chkcount = 0;
|
|
|
|
info->cts_chkcount = 0;
|
|
|
|
}
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* eom: non-zero = end of frame */
|
2005-04-17 06:20:36 +08:00
|
|
|
static void rx_ready_hdlc(MGSLPC_INFO *info, int eom)
|
|
|
|
{
|
|
|
|
unsigned char data[2];
|
|
|
|
unsigned char fifo_count, read_count, i;
|
|
|
|
RXBUF *buf = (RXBUF*)(info->rx_buf + (info->rx_put * info->rx_buf_size));
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s(%d):rx_ready_hdlc(eom=%d)\n",__FILE__,__LINE__,eom);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!info->rx_enabled)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info->rx_frame_count >= info->rx_buf_count) {
|
|
|
|
/* no more free buffers */
|
|
|
|
issue_command(info, CHA, CMD_RXRESET);
|
|
|
|
info->pending_bh |= BH_RECEIVE;
|
2008-04-28 17:14:02 +08:00
|
|
|
info->rx_overflow = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
info->icount.buf_overrun++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eom) {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* end of frame, get FIFO count from RBCL register */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(fifo_count = (unsigned char)(read_reg(info, CHA+RBCL) & 0x1f)))
|
|
|
|
fifo_count = 32;
|
|
|
|
} else
|
|
|
|
fifo_count = 32;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
do {
|
|
|
|
if (fifo_count == 1) {
|
|
|
|
read_count = 1;
|
|
|
|
data[0] = read_reg(info, CHA + RXFIFO);
|
|
|
|
} else {
|
|
|
|
read_count = 2;
|
|
|
|
*((unsigned short *) data) = read_reg16(info, CHA + RXFIFO);
|
|
|
|
}
|
|
|
|
fifo_count -= read_count;
|
|
|
|
if (!fifo_count && eom)
|
|
|
|
buf->status = data[--read_count];
|
|
|
|
|
|
|
|
for (i = 0; i < read_count; i++) {
|
|
|
|
if (buf->count >= info->max_frame_size) {
|
|
|
|
/* frame too large, reset receiver and reset current buffer */
|
|
|
|
issue_command(info, CHA, CMD_RXRESET);
|
|
|
|
buf->count = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*(buf->data + buf->count) = data[i];
|
|
|
|
buf->count++;
|
|
|
|
}
|
|
|
|
} while (fifo_count);
|
|
|
|
|
|
|
|
if (eom) {
|
|
|
|
info->pending_bh |= BH_RECEIVE;
|
|
|
|
info->rx_frame_count++;
|
|
|
|
info->rx_put++;
|
|
|
|
if (info->rx_put >= info->rx_buf_count)
|
|
|
|
info->rx_put = 0;
|
|
|
|
}
|
|
|
|
issue_command(info, CHA, CMD_RXFIFO);
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void rx_ready_async(MGSLPC_INFO *info, int tcd, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
unsigned char data, status, flag;
|
2005-04-17 06:20:36 +08:00
|
|
|
int fifo_count;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
int work = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct mgsl_icount *icount = &info->icount;
|
|
|
|
|
|
|
|
if (tcd) {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* early termination, get FIFO count from RBCL register */
|
2005-04-17 06:20:36 +08:00
|
|
|
fifo_count = (unsigned char)(read_reg(info, CHA+RBCL) & 0x1f);
|
|
|
|
|
|
|
|
/* Zero fifo count could mean 0 or 32 bytes available.
|
|
|
|
* If BIT5 of STAR is set then at least 1 byte is available.
|
|
|
|
*/
|
|
|
|
if (!fifo_count && (read_reg(info,CHA+STAR) & BIT5))
|
|
|
|
fifo_count = 32;
|
|
|
|
} else
|
|
|
|
fifo_count = 32;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
|
|
|
|
tty_buffer_request_room(tty, fifo_count);
|
2007-10-20 03:45:35 +08:00
|
|
|
/* Flush received async data to receive data buffer. */
|
2005-04-17 06:20:36 +08:00
|
|
|
while (fifo_count) {
|
|
|
|
data = read_reg(info, CHA + RXFIFO);
|
|
|
|
status = read_reg(info, CHA + RXFIFO);
|
|
|
|
fifo_count -= 2;
|
|
|
|
|
|
|
|
icount->rx++;
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_NORMAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
// if no frameing/crc error then save data
|
|
|
|
// BIT7:parity error
|
|
|
|
// BIT6:framing error
|
|
|
|
|
|
|
|
if (status & (BIT7 + BIT6)) {
|
2007-10-20 03:45:35 +08:00
|
|
|
if (status & BIT7)
|
2005-04-17 06:20:36 +08:00
|
|
|
icount->parity++;
|
|
|
|
else
|
|
|
|
icount->frame++;
|
|
|
|
|
|
|
|
/* discard char if tty control flags say so */
|
|
|
|
if (status & info->ignore_status_mask)
|
|
|
|
continue;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
status &= info->read_status_mask;
|
|
|
|
|
|
|
|
if (status & BIT7)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_PARITY;
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (status & BIT6)
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
flag = TTY_FRAME;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
work += tty_insert_flip_char(tty, data, flag);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
issue_command(info, CHA, CMD_RXFIFO);
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR) {
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
printk("%s(%d):rx_ready_async",
|
|
|
|
__FILE__,__LINE__);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
|
|
|
|
__FILE__,__LINE__,icount->rx,icount->brk,
|
|
|
|
icount->parity,icount->frame,icount->overrun);
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
if (work)
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void tx_done(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (!info->tx_active)
|
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_active = false;
|
|
|
|
info->tx_aborting = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_ASYNC)
|
|
|
|
return;
|
|
|
|
|
|
|
|
info->tx_count = info->tx_put = info->tx_get = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
del_timer(&info->tx_timer);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->drop_rts_on_tx_done) {
|
|
|
|
get_signals(info);
|
|
|
|
if (info->serial_signals & SerialSignal_RTS) {
|
|
|
|
info->serial_signals &= ~SerialSignal_RTS;
|
|
|
|
set_signals(info);
|
|
|
|
}
|
2008-04-28 17:14:02 +08:00
|
|
|
info->drop_rts_on_tx_done = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->netcount)
|
|
|
|
hdlcdev_tx_done(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
{
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty->stopped || tty->hw_stopped) {
|
2005-04-17 06:20:36 +08:00
|
|
|
tx_stop(info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
info->pending_bh |= BH_TRANSMIT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void tx_ready(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char fifo_count = 32;
|
|
|
|
int c;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s(%d):tx_ready(%s)\n", __FILE__,__LINE__,info->device_name);
|
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_HDLC) {
|
|
|
|
if (!info->tx_active)
|
|
|
|
return;
|
|
|
|
} else {
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty->stopped || tty->hw_stopped) {
|
2005-04-17 06:20:36 +08:00
|
|
|
tx_stop(info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!info->tx_count)
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_active = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!info->tx_count)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (info->tx_count && fifo_count) {
|
|
|
|
c = min(2, min_t(int, fifo_count, min(info->tx_count, TXBUFSIZE - info->tx_get)));
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (c == 1) {
|
|
|
|
write_reg(info, CHA + TXFIFO, *(info->tx_buf + info->tx_get));
|
|
|
|
} else {
|
|
|
|
write_reg16(info, CHA + TXFIFO,
|
|
|
|
*((unsigned short*)(info->tx_buf + info->tx_get)));
|
|
|
|
}
|
|
|
|
info->tx_count -= c;
|
|
|
|
info->tx_get = (info->tx_get + c) & (TXBUFSIZE - 1);
|
|
|
|
fifo_count -= c;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_ASYNC) {
|
|
|
|
if (info->tx_count < WAKEUP_CHARS)
|
|
|
|
info->pending_bh |= BH_TRANSMIT;
|
|
|
|
issue_command(info, CHA, CMD_TXFIFO);
|
|
|
|
} else {
|
|
|
|
if (info->tx_count)
|
|
|
|
issue_command(info, CHA, CMD_TXFIFO);
|
|
|
|
else
|
|
|
|
issue_command(info, CHA, CMD_TXFIFO + CMD_TXEOM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void cts_change(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
get_signals(info);
|
|
|
|
if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
|
|
|
|
irq_disable(info, CHB, IRQ_CTS);
|
|
|
|
info->icount.cts++;
|
|
|
|
if (info->serial_signals & SerialSignal_CTS)
|
|
|
|
info->input_signal_events.cts_up++;
|
|
|
|
else
|
|
|
|
info->input_signal_events.cts_down++;
|
|
|
|
wake_up_interruptible(&info->status_event_wait_q);
|
|
|
|
wake_up_interruptible(&info->event_wait_q);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.flags & ASYNC_CTS_FLOW) {
|
|
|
|
if (tty->hw_stopped) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->serial_signals & SerialSignal_CTS) {
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("CTS tx start...");
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty)
|
|
|
|
tty->hw_stopped = 0;
|
|
|
|
tx_start(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
info->pending_bh |= BH_TRANSMIT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(info->serial_signals & SerialSignal_CTS)) {
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("CTS tx stop...");
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty)
|
|
|
|
tty->hw_stopped = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
tx_stop(info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info->pending_bh |= BH_STATUS;
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void dcd_change(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
get_signals(info);
|
|
|
|
if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
|
|
|
|
irq_disable(info, CHB, IRQ_DCD);
|
|
|
|
info->icount.dcd++;
|
|
|
|
if (info->serial_signals & SerialSignal_DCD) {
|
|
|
|
info->input_signal_events.dcd_up++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
info->input_signal_events.dcd_down++;
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2006-07-22 05:44:55 +08:00
|
|
|
if (info->netcount) {
|
|
|
|
if (info->serial_signals & SerialSignal_DCD)
|
|
|
|
netif_carrier_on(info->netdev);
|
|
|
|
else
|
|
|
|
netif_carrier_off(info->netdev);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
wake_up_interruptible(&info->status_event_wait_q);
|
|
|
|
wake_up_interruptible(&info->event_wait_q);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.flags & ASYNC_CHECK_CD) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s CD now %s...", info->device_name,
|
|
|
|
(info->serial_signals & SerialSignal_DCD) ? "on" : "off");
|
|
|
|
if (info->serial_signals & SerialSignal_DCD)
|
2009-01-02 21:48:47 +08:00
|
|
|
wake_up_interruptible(&info->port.open_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("doing serial hangup...");
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty)
|
|
|
|
tty_hangup(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
info->pending_bh |= BH_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dsr_change(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
get_signals(info);
|
|
|
|
if ((info->dsr_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
|
|
|
|
port_irq_disable(info, PVR_DSR);
|
|
|
|
info->icount.dsr++;
|
|
|
|
if (info->serial_signals & SerialSignal_DSR)
|
|
|
|
info->input_signal_events.dsr_up++;
|
|
|
|
else
|
|
|
|
info->input_signal_events.dsr_down++;
|
|
|
|
wake_up_interruptible(&info->status_event_wait_q);
|
|
|
|
wake_up_interruptible(&info->event_wait_q);
|
|
|
|
info->pending_bh |= BH_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ri_change(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
get_signals(info);
|
|
|
|
if ((info->ri_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
|
|
|
|
port_irq_disable(info, PVR_RI);
|
|
|
|
info->icount.rng++;
|
|
|
|
if (info->serial_signals & SerialSignal_RI)
|
|
|
|
info->input_signal_events.ri_up++;
|
|
|
|
else
|
|
|
|
info->input_signal_events.ri_down++;
|
|
|
|
wake_up_interruptible(&info->status_event_wait_q);
|
|
|
|
wake_up_interruptible(&info->event_wait_q);
|
|
|
|
info->pending_bh |= BH_STATUS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt service routine entry point.
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* irq interrupt number that caused interrupt
|
|
|
|
* dev_id device ID supplied during interrupt registration
|
|
|
|
*/
|
2007-10-31 17:20:49 +08:00
|
|
|
static irqreturn_t mgslpc_isr(int dummy, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-31 17:20:49 +08:00
|
|
|
MGSLPC_INFO *info = dev_id;
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_struct *tty;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned short isr;
|
|
|
|
unsigned char gis, pis;
|
|
|
|
int count=0;
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
2007-10-31 17:20:49 +08:00
|
|
|
printk("mgslpc_isr(%d) entry.\n", info->irq_level);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2006-03-02 07:09:29 +08:00
|
|
|
if (!(info->p_dev->_locked))
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
tty = tty_port_tty_get(&info->port);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&info->lock);
|
|
|
|
|
|
|
|
while ((gis = read_reg(info, CHA + GIS))) {
|
2007-10-20 03:45:35 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("mgslpc_isr %s gis=%04X\n", info->device_name,gis);
|
|
|
|
|
|
|
|
if ((gis & 0x70) || count > 1000) {
|
|
|
|
printk("synclink_cs:hardware failed or ejected\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if (gis & (BIT1 + BIT0)) {
|
|
|
|
isr = read_reg16(info, CHB + ISR);
|
|
|
|
if (isr & IRQ_DCD)
|
2009-01-02 21:48:47 +08:00
|
|
|
dcd_change(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (isr & IRQ_CTS)
|
2009-01-02 21:48:47 +08:00
|
|
|
cts_change(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (gis & (BIT3 + BIT2))
|
|
|
|
{
|
|
|
|
isr = read_reg16(info, CHA + ISR);
|
|
|
|
if (isr & IRQ_TIMER) {
|
2008-04-28 17:14:02 +08:00
|
|
|
info->irq_occurred = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
irq_disable(info, CHA, IRQ_TIMER);
|
|
|
|
}
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* receive IRQs */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (isr & IRQ_EXITHUNT) {
|
|
|
|
info->icount.exithunt++;
|
|
|
|
wake_up_interruptible(&info->event_wait_q);
|
|
|
|
}
|
|
|
|
if (isr & IRQ_BREAK_ON) {
|
|
|
|
info->icount.brk++;
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.flags & ASYNC_SAK)
|
|
|
|
do_SAK(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (isr & IRQ_RXTIME) {
|
|
|
|
issue_command(info, CHA, CMD_RXFIFO_READ);
|
|
|
|
}
|
|
|
|
if (isr & (IRQ_RXEOM + IRQ_RXFIFO)) {
|
|
|
|
if (info->params.mode == MGSL_MODE_HDLC)
|
2007-10-20 03:45:35 +08:00
|
|
|
rx_ready_hdlc(info, isr & IRQ_RXEOM);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2009-01-02 21:48:47 +08:00
|
|
|
rx_ready_async(info, isr & IRQ_RXEOM, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* transmit IRQs */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (isr & IRQ_UNDERRUN) {
|
|
|
|
if (info->tx_aborting)
|
|
|
|
info->icount.txabort++;
|
|
|
|
else
|
|
|
|
info->icount.txunder++;
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_done(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
else if (isr & IRQ_ALLSENT) {
|
|
|
|
info->icount.txok++;
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_done(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
else if (isr & IRQ_TXFIFO)
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_ready(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
if (gis & BIT7) {
|
|
|
|
pis = read_reg(info, CHA + PIS);
|
|
|
|
if (pis & BIT1)
|
|
|
|
dsr_change(info);
|
|
|
|
if (pis & BIT2)
|
|
|
|
ri_change(info);
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* Request bottom half processing if there's something
|
2005-04-17 06:20:36 +08:00
|
|
|
* for it to do and the bh is not already running
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (info->pending_bh && !info->bh_running && !info->bh_requested) {
|
2007-10-20 03:45:35 +08:00
|
|
|
if ( debug_level >= DEBUG_LEVEL_ISR )
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("%s(%d):%s queueing bh task.\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
schedule_work(&info->task);
|
2008-04-28 17:14:02 +08:00
|
|
|
info->bh_requested = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&info->lock);
|
2009-01-02 21:48:47 +08:00
|
|
|
tty_kref_put(tty);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("%s(%d):mgslpc_isr(%d)exit.\n",
|
2007-10-31 17:20:49 +08:00
|
|
|
__FILE__, __LINE__, info->irq_level);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize and start device.
|
|
|
|
*/
|
2009-01-02 21:48:47 +08:00
|
|
|
static int startup(MGSLPC_INFO * info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int retval = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):startup(%s)\n",__FILE__,__LINE__,info->device_name);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.flags & ASYNC_INITIALIZED)
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!info->tx_buf) {
|
|
|
|
/* allocate a page of memory for a transmit buffer */
|
|
|
|
info->tx_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
|
|
|
|
if (!info->tx_buf) {
|
|
|
|
printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
info->pending_bh = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-09-10 15:26:07 +08:00
|
|
|
memset(&info->icount, 0, sizeof(info->icount));
|
|
|
|
|
2007-02-12 16:52:31 +08:00
|
|
|
setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Allocate and claim adapter resources */
|
|
|
|
retval = claim_resources(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* perform existance check and diagnostics */
|
|
|
|
if ( !retval )
|
|
|
|
retval = adapter_test(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ( retval ) {
|
2009-01-02 21:48:47 +08:00
|
|
|
if (capable(CAP_SYS_ADMIN) && tty)
|
|
|
|
set_bit(TTY_IO_ERROR, &tty->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
release_resources(info);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* program hardware for current parameters */
|
2009-01-02 21:48:47 +08:00
|
|
|
mgslpc_change_params(info, tty);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty)
|
|
|
|
clear_bit(TTY_IO_ERROR, &tty->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.flags |= ASYNC_INITIALIZED;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by mgslpc_close() and mgslpc_hangup() to shutdown hardware
|
|
|
|
*/
|
2009-01-02 21:48:47 +08:00
|
|
|
static void shutdown(MGSLPC_INFO * info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (!(info->port.flags & ASYNC_INITIALIZED))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_shutdown(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
|
|
|
|
|
|
|
/* clear status wait queue because status changes */
|
|
|
|
/* can't happen after shutting down the hardware */
|
|
|
|
wake_up_interruptible(&info->status_event_wait_q);
|
|
|
|
wake_up_interruptible(&info->event_wait_q);
|
|
|
|
|
2007-02-12 16:52:31 +08:00
|
|
|
del_timer_sync(&info->tx_timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (info->tx_buf) {
|
|
|
|
free_page((unsigned long) info->tx_buf);
|
|
|
|
info->tx_buf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
|
|
|
|
rx_stop(info);
|
|
|
|
tx_stop(info);
|
|
|
|
|
|
|
|
/* TODO:disable interrupts instead of reset to preserve signal states */
|
|
|
|
reset_device(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (!tty || tty->termios->c_cflag & HUPCL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
|
|
|
|
set_signals(info);
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
release_resources(info);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty)
|
|
|
|
set_bit(TTY_IO_ERROR, &tty->flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.flags &= ~ASYNC_INITIALIZED;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void mgslpc_program_hw(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
rx_stop(info);
|
|
|
|
tx_stop(info);
|
|
|
|
info->tx_count = info->tx_put = info->tx_get = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
|
|
|
|
hdlc_mode(info);
|
|
|
|
else
|
|
|
|
async_mode(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
set_signals(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
info->dcd_chkcount = 0;
|
|
|
|
info->cts_chkcount = 0;
|
|
|
|
info->ri_chkcount = 0;
|
|
|
|
info->dsr_chkcount = 0;
|
|
|
|
|
|
|
|
irq_enable(info, CHB, IRQ_DCD | IRQ_CTS);
|
|
|
|
port_irq_enable(info, (unsigned char) PVR_DSR | PVR_RI);
|
|
|
|
get_signals(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->netcount || (tty && (tty->termios->c_cflag & CREAD)))
|
2005-04-17 06:20:36 +08:00
|
|
|
rx_start(info);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reconfigure adapter based on new parameters
|
|
|
|
*/
|
2009-01-02 21:48:47 +08:00
|
|
|
static void mgslpc_change_params(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned cflag;
|
|
|
|
int bits_per_char;
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (!tty || !tty->termios)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_change_params(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
cflag = tty->termios->c_cflag;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* if B0 rate (hangup) specified then negate DTR and RTS */
|
|
|
|
/* otherwise assert DTR and RTS */
|
|
|
|
if (cflag & CBAUD)
|
|
|
|
info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
|
|
|
|
else
|
|
|
|
info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* byte size and parity */
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
switch (cflag & CSIZE) {
|
|
|
|
case CS5: info->params.data_bits = 5; break;
|
|
|
|
case CS6: info->params.data_bits = 6; break;
|
|
|
|
case CS7: info->params.data_bits = 7; break;
|
|
|
|
case CS8: info->params.data_bits = 8; break;
|
|
|
|
default: info->params.data_bits = 7; break;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cflag & CSTOPB)
|
|
|
|
info->params.stop_bits = 2;
|
|
|
|
else
|
|
|
|
info->params.stop_bits = 1;
|
|
|
|
|
|
|
|
info->params.parity = ASYNC_PARITY_NONE;
|
|
|
|
if (cflag & PARENB) {
|
|
|
|
if (cflag & PARODD)
|
|
|
|
info->params.parity = ASYNC_PARITY_ODD;
|
|
|
|
else
|
|
|
|
info->params.parity = ASYNC_PARITY_EVEN;
|
|
|
|
#ifdef CMSPAR
|
|
|
|
if (cflag & CMSPAR)
|
|
|
|
info->params.parity = ASYNC_PARITY_SPACE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate number of jiffies to transmit a full
|
|
|
|
* FIFO (32 bytes) at specified data rate
|
|
|
|
*/
|
2007-10-20 03:45:35 +08:00
|
|
|
bits_per_char = info->params.data_bits +
|
2005-04-17 06:20:36 +08:00
|
|
|
info->params.stop_bits + 1;
|
|
|
|
|
|
|
|
/* if port data rate is set to 460800 or less then
|
|
|
|
* allow tty settings to override, otherwise keep the
|
|
|
|
* current data rate.
|
|
|
|
*/
|
|
|
|
if (info->params.data_rate <= 460800) {
|
2009-01-02 21:48:47 +08:00
|
|
|
info->params.data_rate = tty_get_baud_rate(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ( info->params.data_rate ) {
|
2007-10-20 03:45:35 +08:00
|
|
|
info->timeout = (32*HZ*bits_per_char) /
|
2005-04-17 06:20:36 +08:00
|
|
|
info->params.data_rate;
|
|
|
|
}
|
|
|
|
info->timeout += HZ/50; /* Add .02 seconds of slop */
|
|
|
|
|
|
|
|
if (cflag & CRTSCTS)
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.flags |= ASYNC_CTS_FLOW;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.flags &= ~ASYNC_CTS_FLOW;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cflag & CLOCAL)
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.flags &= ~ASYNC_CHECK_CD;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2009-01-02 21:48:47 +08:00
|
|
|
info->port.flags |= ASYNC_CHECK_CD;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* process tty input control flags */
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
info->read_status_mask = 0;
|
2009-01-02 21:48:47 +08:00
|
|
|
if (I_INPCK(tty))
|
2005-04-17 06:20:36 +08:00
|
|
|
info->read_status_mask |= BIT7 | BIT6;
|
2009-01-02 21:48:47 +08:00
|
|
|
if (I_IGNPAR(tty))
|
2005-04-17 06:20:36 +08:00
|
|
|
info->ignore_status_mask |= BIT7 | BIT6;
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
mgslpc_program_hw(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a character to the transmit buffer
|
|
|
|
*/
|
2008-04-30 15:54:04 +08:00
|
|
|
static int mgslpc_put_char(struct tty_struct *tty, unsigned char ch)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO) {
|
|
|
|
printk( "%s(%d):mgslpc_put_char(%d) on %s\n",
|
|
|
|
__FILE__,__LINE__,ch,info->device_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_put_char"))
|
2008-04-30 15:54:04 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-06-25 20:48:48 +08:00
|
|
|
if (!info->tx_buf)
|
2008-04-30 15:54:04 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_ASYNC || !info->tx_active) {
|
|
|
|
if (info->tx_count < TXBUFSIZE - 1) {
|
|
|
|
info->tx_buf[info->tx_put++] = ch;
|
|
|
|
info->tx_put &= TXBUFSIZE-1;
|
|
|
|
info->tx_count++;
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2008-04-30 15:54:04 +08:00
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable transmitter so remaining characters in the
|
|
|
|
* transmit buffer are sent.
|
|
|
|
*/
|
|
|
|
static void mgslpc_flush_chars(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk( "%s(%d):mgslpc_flush_chars() entry on %s tx_count=%d\n",
|
|
|
|
__FILE__,__LINE__,info->device_name,info->tx_count);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_chars"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (info->tx_count <= 0 || tty->stopped ||
|
|
|
|
tty->hw_stopped || !info->tx_buf)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk( "%s(%d):mgslpc_flush_chars() entry on %s starting transmitter\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (!info->tx_active)
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_start(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send a block of data
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* tty pointer to tty information structure
|
|
|
|
* buf pointer to buffer containing send data
|
|
|
|
* count size of send data in bytes
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Returns: number of characters written
|
|
|
|
*/
|
|
|
|
static int mgslpc_write(struct tty_struct * tty,
|
|
|
|
const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
int c, ret = 0;
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk( "%s(%d):mgslpc_write(%s) count=%d\n",
|
|
|
|
__FILE__,__LINE__,info->device_name,count);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_write") ||
|
2006-06-25 20:48:48 +08:00
|
|
|
!info->tx_buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_HDLC) {
|
|
|
|
if (count > TXBUFSIZE) {
|
|
|
|
ret = -EIO;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
if (info->tx_active)
|
|
|
|
goto cleanup;
|
|
|
|
else if (info->tx_count)
|
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
c = min(count,
|
|
|
|
min(TXBUFSIZE - info->tx_count - 1,
|
|
|
|
TXBUFSIZE - info->tx_put));
|
|
|
|
if (c <= 0)
|
|
|
|
break;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
memcpy(info->tx_buf + info->tx_put, buf, c);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
info->tx_put = (info->tx_put + c) & (TXBUFSIZE-1);
|
|
|
|
info->tx_count += c;
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
buf += c;
|
|
|
|
count -= c;
|
|
|
|
ret += c;
|
|
|
|
}
|
|
|
|
start:
|
|
|
|
if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (!info->tx_active)
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_start(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
cleanup:
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk( "%s(%d):mgslpc_write(%s) returning=%d\n",
|
|
|
|
__FILE__,__LINE__,info->device_name,ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the count of free bytes in transmit buffer
|
|
|
|
*/
|
|
|
|
static int mgslpc_write_room(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
int ret;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_write_room"))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_HDLC) {
|
|
|
|
/* HDLC (frame oriented) mode */
|
|
|
|
if (info->tx_active)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return HDLC_MAX_FRAME_SIZE;
|
|
|
|
} else {
|
|
|
|
ret = TXBUFSIZE - info->tx_count - 1;
|
|
|
|
if (ret < 0)
|
|
|
|
ret = 0;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_write_room(%s)=%d\n",
|
|
|
|
__FILE__,__LINE__, info->device_name, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the count of bytes in transmit buffer
|
|
|
|
*/
|
|
|
|
static int mgslpc_chars_in_buffer(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
int rc;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_chars_in_buffer(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_chars_in_buffer"))
|
|
|
|
return 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_HDLC)
|
|
|
|
rc = info->tx_active ? info->max_frame_size : 0;
|
|
|
|
else
|
|
|
|
rc = info->tx_count;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_chars_in_buffer(%s)=%d\n",
|
|
|
|
__FILE__,__LINE__, info->device_name, rc);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Discard all data in the send buffer
|
|
|
|
*/
|
|
|
|
static void mgslpc_flush_buffer(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_flush_buffer(%s) entry\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_flush_buffer"))
|
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
info->tx_count = info->tx_put = info->tx_get = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
del_timer(&info->tx_timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
wake_up_interruptible(&tty->write_wait);
|
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send a high-priority XON/XOFF character
|
|
|
|
*/
|
|
|
|
static void mgslpc_send_xchar(struct tty_struct *tty, char ch)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_send_xchar(%s,%d)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name, ch );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_send_xchar"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
info->x_char = ch;
|
|
|
|
if (ch) {
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (!info->tx_enabled)
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_start(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal remote device to throttle send data (our receive data)
|
|
|
|
*/
|
|
|
|
static void mgslpc_throttle(struct tty_struct * tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_throttle(%s) entry\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
|
|
|
|
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_throttle"))
|
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (I_IXOFF(tty))
|
|
|
|
mgslpc_send_xchar(tty, STOP_CHAR(tty));
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tty->termios->c_cflag & CRTSCTS) {
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
info->serial_signals &= ~SerialSignal_RTS;
|
|
|
|
set_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal remote device to stop throttling send data (our receive data)
|
|
|
|
*/
|
|
|
|
static void mgslpc_unthrottle(struct tty_struct * tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_unthrottle(%s) entry\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
|
|
|
|
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_unthrottle"))
|
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
if (info->x_char)
|
|
|
|
info->x_char = 0;
|
|
|
|
else
|
|
|
|
mgslpc_send_xchar(tty, START_CHAR(tty));
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tty->termios->c_cflag & CRTSCTS) {
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
info->serial_signals |= SerialSignal_RTS;
|
|
|
|
set_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the current serial statistics
|
|
|
|
*/
|
|
|
|
static int get_stats(MGSLPC_INFO * info, struct mgsl_icount __user *user_icount)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("get_params(%s)\n", info->device_name);
|
2005-09-10 15:26:07 +08:00
|
|
|
if (!user_icount) {
|
|
|
|
memset(&info->icount, 0, sizeof(info->icount));
|
|
|
|
} else {
|
|
|
|
COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
|
|
|
|
if (err)
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the current serial parameters
|
|
|
|
*/
|
|
|
|
static int get_params(MGSLPC_INFO * info, MGSL_PARAMS __user *user_params)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("get_params(%s)\n", info->device_name);
|
|
|
|
COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
|
|
|
|
if (err)
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set the serial parameters
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* info pointer to device instance data
|
|
|
|
* new_params user buffer containing new serial params
|
|
|
|
*
|
|
|
|
* Returns: 0 if success, otherwise error code
|
|
|
|
*/
|
2009-01-02 21:48:47 +08:00
|
|
|
static int set_params(MGSLPC_INFO * info, MGSL_PARAMS __user *new_params, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
MGSL_PARAMS tmp_params;
|
|
|
|
int err;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):set_params %s\n", __FILE__,__LINE__,
|
|
|
|
info->device_name );
|
|
|
|
COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
|
|
|
|
if (err) {
|
|
|
|
if ( debug_level >= DEBUG_LEVEL_INFO )
|
|
|
|
printk( "%s(%d):set_params(%s) user buffer copy failed\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
mgslpc_change_params(info, tty);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_txidle(MGSLPC_INFO * info, int __user *idle_mode)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("get_txidle(%s)=%d\n", info->device_name, info->idle_mode);
|
|
|
|
COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
|
|
|
|
if (err)
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_txidle(MGSLPC_INFO * info, int idle_mode)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("set_txidle(%s,%d)\n", info->device_name, idle_mode);
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
info->idle_mode = idle_mode;
|
|
|
|
tx_set_idle(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_interface(MGSLPC_INFO * info, int __user *if_mode)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("get_interface(%s)=%d\n", info->device_name, info->if_mode);
|
|
|
|
COPY_TO_USER(err,if_mode, &info->if_mode, sizeof(int));
|
|
|
|
if (err)
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_interface(MGSLPC_INFO * info, int if_mode)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char val;
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("set_interface(%s,%d)\n", info->device_name, if_mode);
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
info->if_mode = if_mode;
|
|
|
|
|
|
|
|
val = read_reg(info, PVR) & 0x0f;
|
|
|
|
switch (info->if_mode)
|
|
|
|
{
|
|
|
|
case MGSL_INTERFACE_RS232: val |= PVR_RS232; break;
|
|
|
|
case MGSL_INTERFACE_V35: val |= PVR_V35; break;
|
|
|
|
case MGSL_INTERFACE_RS422: val |= PVR_RS422; break;
|
|
|
|
}
|
|
|
|
write_reg(info, PVR, val);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static int set_txenable(MGSLPC_INFO * info, int enable, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("set_txenable(%s,%d)\n", info->device_name, enable);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (enable) {
|
|
|
|
if (!info->tx_enabled)
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_start(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
if (info->tx_enabled)
|
|
|
|
tx_stop(info);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tx_abort(MGSLPC_INFO * info)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("tx_abort(%s)\n", info->device_name);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (info->tx_active && info->tx_count &&
|
|
|
|
info->params.mode == MGSL_MODE_HDLC) {
|
|
|
|
/* clear data count so FIFO is not filled on next IRQ.
|
|
|
|
* This results in underrun and abort transmission.
|
|
|
|
*/
|
|
|
|
info->tx_count = info->tx_put = info->tx_get = 0;
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_aborting = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int set_rxenable(MGSLPC_INFO * info, int enable)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("set_rxenable(%s,%d)\n", info->device_name, enable);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (enable) {
|
|
|
|
if (!info->rx_enabled)
|
|
|
|
rx_start(info);
|
|
|
|
} else {
|
|
|
|
if (info->rx_enabled)
|
|
|
|
rx_stop(info);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for specified event to occur
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments: info pointer to device instance data
|
|
|
|
* mask pointer to bitmask of events to wait for
|
|
|
|
* Return Value: 0 if successful and bit mask updated with
|
|
|
|
* of events triggerred,
|
|
|
|
* otherwise error code
|
|
|
|
*/
|
|
|
|
static int wait_events(MGSLPC_INFO * info, int __user *mask_ptr)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int s;
|
|
|
|
int rc=0;
|
|
|
|
struct mgsl_icount cprev, cnow;
|
|
|
|
int events;
|
|
|
|
int mask;
|
|
|
|
struct _input_signal_events oldsigs, newsigs;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
|
|
|
|
if (rc)
|
|
|
|
return -EFAULT;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("wait_events(%s,%d)\n", info->device_name, mask);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
|
|
|
|
/* return immediately if state matches requested events */
|
|
|
|
get_signals(info);
|
|
|
|
s = info->serial_signals;
|
|
|
|
events = mask &
|
|
|
|
( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
|
|
|
|
((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
|
|
|
|
((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
|
|
|
|
((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
|
|
|
|
if (events) {
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* save current irq counts */
|
|
|
|
cprev = info->icount;
|
|
|
|
oldsigs = info->input_signal_events;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((info->params.mode == MGSL_MODE_HDLC) &&
|
|
|
|
(mask & MgslEvent_ExitHuntMode))
|
|
|
|
irq_enable(info, CHA, IRQ_EXITHUNT);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
add_wait_queue(&info->event_wait_q, &wait);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for(;;) {
|
|
|
|
schedule();
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
rc = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* get current irq counts */
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
cnow = info->icount;
|
|
|
|
newsigs = info->input_signal_events;
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
/* if no change, wait aborted for some reason */
|
|
|
|
if (newsigs.dsr_up == oldsigs.dsr_up &&
|
|
|
|
newsigs.dsr_down == oldsigs.dsr_down &&
|
|
|
|
newsigs.dcd_up == oldsigs.dcd_up &&
|
|
|
|
newsigs.dcd_down == oldsigs.dcd_down &&
|
|
|
|
newsigs.cts_up == oldsigs.cts_up &&
|
|
|
|
newsigs.cts_down == oldsigs.cts_down &&
|
|
|
|
newsigs.ri_up == oldsigs.ri_up &&
|
|
|
|
newsigs.ri_down == oldsigs.ri_down &&
|
|
|
|
cnow.exithunt == cprev.exithunt &&
|
|
|
|
cnow.rxidle == cprev.rxidle) {
|
|
|
|
rc = -EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
events = mask &
|
|
|
|
( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
|
|
|
|
(newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
|
|
|
|
(newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
|
|
|
|
(newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
|
|
|
|
(newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
|
|
|
|
(newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
|
|
|
|
(newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
|
|
|
|
(newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
|
|
|
|
(cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
|
|
|
|
(cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
|
|
|
|
if (events)
|
|
|
|
break;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
cprev = cnow;
|
|
|
|
oldsigs = newsigs;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
remove_wait_queue(&info->event_wait_q, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
|
|
|
|
if (mask & MgslEvent_ExitHuntMode) {
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (!waitqueue_active(&info->event_wait_q))
|
|
|
|
irq_disable(info, CHA, IRQ_EXITHUNT);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
if (rc == 0)
|
|
|
|
PUT_USER(rc, events, mask_ptr);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int modem_input_wait(MGSLPC_INFO *info,int arg)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int rc;
|
|
|
|
struct mgsl_icount cprev, cnow;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
/* save current irq counts */
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
cprev = info->icount;
|
|
|
|
add_wait_queue(&info->status_event_wait_q, &wait);
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
schedule();
|
|
|
|
if (signal_pending(current)) {
|
|
|
|
rc = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get new irq counts */
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
cnow = info->icount;
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
/* if no change, wait aborted for some reason */
|
|
|
|
if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
|
|
|
|
cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
|
|
|
|
rc = -EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for change in caller specified modem input */
|
|
|
|
if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
|
|
|
|
(arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
|
|
|
|
(arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
|
|
|
|
(arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
|
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cprev = cnow;
|
|
|
|
}
|
|
|
|
remove_wait_queue(&info->status_event_wait_q, &wait);
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return the state of the serial control and status signals
|
|
|
|
*/
|
|
|
|
static int tiocmget(struct tty_struct *tty, struct file *file)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned int result;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
get_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
|
|
|
|
((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
|
|
|
|
((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
|
|
|
|
((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
|
|
|
|
((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
|
|
|
|
((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):%s tiocmget() value=%08X\n",
|
|
|
|
__FILE__,__LINE__, info->device_name, result );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* set modem control signals (DTR/RTS)
|
|
|
|
*/
|
|
|
|
static int tiocmset(struct tty_struct *tty, struct file *file,
|
|
|
|
unsigned int set, unsigned int clear)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):%s tiocmset(%x,%x)\n",
|
|
|
|
__FILE__,__LINE__,info->device_name, set, clear);
|
|
|
|
|
|
|
|
if (set & TIOCM_RTS)
|
|
|
|
info->serial_signals |= SerialSignal_RTS;
|
|
|
|
if (set & TIOCM_DTR)
|
|
|
|
info->serial_signals |= SerialSignal_DTR;
|
|
|
|
if (clear & TIOCM_RTS)
|
|
|
|
info->serial_signals &= ~SerialSignal_RTS;
|
|
|
|
if (clear & TIOCM_DTR)
|
|
|
|
info->serial_signals &= ~SerialSignal_DTR;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
set_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set or clear transmit break condition
|
|
|
|
*
|
|
|
|
* Arguments: tty pointer to tty instance data
|
|
|
|
* break_state -1=set break condition, 0=clear
|
|
|
|
*/
|
2008-07-22 18:18:03 +08:00
|
|
|
static int mgslpc_break(struct tty_struct *tty, int break_state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_break(%s,%d)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name, break_state);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_break"))
|
2008-07-22 18:18:03 +08:00
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
if (break_state == -1)
|
|
|
|
set_reg_bits(info, CHA+DAFO, BIT6);
|
2007-10-20 03:45:35 +08:00
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_reg_bits(info, CHA+DAFO, BIT6);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2008-07-22 18:18:03 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Service an IOCTL request
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* tty pointer to tty instance data
|
|
|
|
* file pointer to associated file object for device
|
|
|
|
* cmd IOCTL command code
|
|
|
|
* arg command argument/context
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Return Value: 0 if success, otherwise error code
|
|
|
|
*/
|
|
|
|
static int mgslpc_ioctl(struct tty_struct *tty, struct file * file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
|
2009-01-02 21:48:47 +08:00
|
|
|
int error;
|
|
|
|
struct mgsl_icount cnow; /* kernel counter temps */
|
|
|
|
struct serial_icounter_struct __user *p_cuser; /* user space */
|
|
|
|
void __user *argp = (void __user *)arg;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
|
|
|
|
info->device_name, cmd );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_ioctl"))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
|
|
|
|
(cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
|
|
|
|
if (tty->flags & (1 << TTY_IO_ERROR))
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MGSL_IOCGPARAMS:
|
|
|
|
return get_params(info, argp);
|
|
|
|
case MGSL_IOCSPARAMS:
|
2009-01-02 21:48:47 +08:00
|
|
|
return set_params(info, argp, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
case MGSL_IOCGTXIDLE:
|
|
|
|
return get_txidle(info, argp);
|
|
|
|
case MGSL_IOCSTXIDLE:
|
|
|
|
return set_txidle(info, (int)arg);
|
|
|
|
case MGSL_IOCGIF:
|
|
|
|
return get_interface(info, argp);
|
|
|
|
case MGSL_IOCSIF:
|
|
|
|
return set_interface(info,(int)arg);
|
|
|
|
case MGSL_IOCTXENABLE:
|
2009-01-02 21:48:47 +08:00
|
|
|
return set_txenable(info,(int)arg, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
case MGSL_IOCRXENABLE:
|
|
|
|
return set_rxenable(info,(int)arg);
|
|
|
|
case MGSL_IOCTXABORT:
|
|
|
|
return tx_abort(info);
|
|
|
|
case MGSL_IOCGSTATS:
|
|
|
|
return get_stats(info, argp);
|
|
|
|
case MGSL_IOCWAITEVENT:
|
|
|
|
return wait_events(info, argp);
|
|
|
|
case TIOCMIWAIT:
|
|
|
|
return modem_input_wait(info,(int)arg);
|
|
|
|
case TIOCGICOUNT:
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
cnow = info->icount;
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
p_cuser = argp;
|
|
|
|
PUT_USER(error,cnow.cts, &p_cuser->cts);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.dsr, &p_cuser->dsr);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.rng, &p_cuser->rng);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.dcd, &p_cuser->dcd);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.rx, &p_cuser->rx);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.tx, &p_cuser->tx);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.frame, &p_cuser->frame);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.overrun, &p_cuser->overrun);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.parity, &p_cuser->parity);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.brk, &p_cuser->brk);
|
|
|
|
if (error) return error;
|
|
|
|
PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
|
|
|
|
if (error) return error;
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set new termios settings
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments:
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* tty pointer to tty structure
|
|
|
|
* termios pointer to buffer to hold returned old termios
|
|
|
|
*/
|
2006-12-08 18:38:45 +08:00
|
|
|
static void mgslpc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_set_termios %s\n", __FILE__,__LINE__,
|
|
|
|
tty->driver->name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* just return if nothing has changed */
|
|
|
|
if ((tty->termios->c_cflag == old_termios->c_cflag)
|
2007-10-20 03:45:35 +08:00
|
|
|
&& (RELEVANT_IFLAG(tty->termios->c_iflag)
|
2005-04-17 06:20:36 +08:00
|
|
|
== RELEVANT_IFLAG(old_termios->c_iflag)))
|
|
|
|
return;
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
mgslpc_change_params(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Handle transition to B0 status */
|
|
|
|
if (old_termios->c_cflag & CBAUD &&
|
|
|
|
!(tty->termios->c_cflag & CBAUD)) {
|
|
|
|
info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
set_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Handle transition away from B0 status */
|
|
|
|
if (!(old_termios->c_cflag & CBAUD) &&
|
|
|
|
tty->termios->c_cflag & CBAUD) {
|
|
|
|
info->serial_signals |= SerialSignal_DTR;
|
2007-10-20 03:45:35 +08:00
|
|
|
if (!(tty->termios->c_cflag & CRTSCTS) ||
|
2005-04-17 06:20:36 +08:00
|
|
|
!test_bit(TTY_THROTTLED, &tty->flags)) {
|
|
|
|
info->serial_signals |= SerialSignal_RTS;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
set_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Handle turning off CRTSCTS */
|
|
|
|
if (old_termios->c_cflag & CRTSCTS &&
|
|
|
|
!(tty->termios->c_cflag & CRTSCTS)) {
|
|
|
|
tty->hw_stopped = 0;
|
|
|
|
tx_release(tty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mgslpc_close(struct tty_struct *tty, struct file * filp)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_port *port = &info->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_close"))
|
|
|
|
return;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
|
2009-01-02 21:48:47 +08:00
|
|
|
__FILE__,__LINE__, info->device_name, port->count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
WARN_ON(!port->count);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty_port_close_start(port, tty, filp) == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
goto cleanup;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (port->flags & ASYNC_INITIALIZED)
|
2005-04-17 06:20:36 +08:00
|
|
|
mgslpc_wait_until_sent(tty, info->timeout);
|
|
|
|
|
2008-04-30 15:53:59 +08:00
|
|
|
mgslpc_flush_buffer(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:59 +08:00
|
|
|
tty_ldisc_flush(tty);
|
2009-01-02 21:48:47 +08:00
|
|
|
shutdown(info, tty);
|
|
|
|
|
|
|
|
tty_port_close_end(port, tty);
|
|
|
|
tty_port_tty_set(port, NULL);
|
2007-10-20 03:45:35 +08:00
|
|
|
cleanup:
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
|
2009-01-02 21:48:47 +08:00
|
|
|
tty->driver->name, port->count);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait until the transmitter is empty.
|
|
|
|
*/
|
|
|
|
static void mgslpc_wait_until_sent(struct tty_struct *tty, int timeout)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
|
|
|
|
unsigned long orig_jiffies, char_time;
|
|
|
|
|
|
|
|
if (!info )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_wait_until_sent(%s) entry\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_wait_until_sent"))
|
|
|
|
return;
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (!(info->port.flags & ASYNC_INITIALIZED))
|
2005-04-17 06:20:36 +08:00
|
|
|
goto exit;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
orig_jiffies = jiffies;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Set check interval to 1/5 of estimated time to
|
|
|
|
* send a character, and make it at least 1. The check
|
|
|
|
* interval should also be less than the timeout.
|
|
|
|
* Note: use tight timings here to satisfy the NIST-PCTS.
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ( info->params.data_rate ) {
|
|
|
|
char_time = info->timeout/(32 * 5);
|
|
|
|
if (!char_time)
|
|
|
|
char_time++;
|
|
|
|
} else
|
|
|
|
char_time = 1;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (timeout)
|
|
|
|
char_time = min_t(unsigned long, char_time, timeout);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_HDLC) {
|
|
|
|
while (info->tx_active) {
|
|
|
|
msleep_interruptible(jiffies_to_msecs(char_time));
|
|
|
|
if (signal_pending(current))
|
|
|
|
break;
|
|
|
|
if (timeout && time_after(jiffies, orig_jiffies + timeout))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while ((info->tx_count || info->tx_active) &&
|
|
|
|
info->tx_enabled) {
|
|
|
|
msleep_interruptible(jiffies_to_msecs(char_time));
|
|
|
|
if (signal_pending(current))
|
|
|
|
break;
|
|
|
|
if (timeout && time_after(jiffies, orig_jiffies + timeout))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
exit:
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_wait_until_sent(%s) exit\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called by tty_hangup() when a hangup is signaled.
|
|
|
|
* This is the same as closing all open files for the port.
|
|
|
|
*/
|
|
|
|
static void mgslpc_hangup(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO * info = (MGSLPC_INFO *)tty->driver_data;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_hangup(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_hangup"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
mgslpc_flush_buffer(tty);
|
2009-01-02 21:48:47 +08:00
|
|
|
shutdown(info, tty);
|
|
|
|
tty_port_hangup(&info->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static int carrier_raised(struct tty_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-01-02 21:48:47 +08:00
|
|
|
MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
get_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->serial_signals & SerialSignal_DCD)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-06-11 19:24:17 +08:00
|
|
|
static void dtr_rts(struct tty_port *port, int onoff)
|
2009-01-02 21:48:47 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = container_of(port, MGSLPC_INFO, port);
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
2009-06-11 19:24:17 +08:00
|
|
|
if (onoff)
|
|
|
|
info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
|
|
|
|
else
|
|
|
|
info->serial_signals &= ~SerialSignal_RTS + SerialSignal_DTR;
|
2009-01-02 21:48:47 +08:00
|
|
|
set_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int mgslpc_open(struct tty_struct *tty, struct file * filp)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info;
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_port *port;
|
2005-04-17 06:20:36 +08:00
|
|
|
int retval, line;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* verify range of specified line number */
|
2005-04-17 06:20:36 +08:00
|
|
|
line = tty->index;
|
|
|
|
if ((line < 0) || (line >= mgslpc_device_count)) {
|
|
|
|
printk("%s(%d):mgslpc_open with invalid line #%d.\n",
|
|
|
|
__FILE__,__LINE__,line);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* find the info structure for the specified line */
|
|
|
|
info = mgslpc_device_list;
|
|
|
|
while(info && info->line != line)
|
|
|
|
info = info->next_device;
|
|
|
|
if (mgslpc_paranoia_check(info, tty->name, "mgslpc_open"))
|
|
|
|
return -ENODEV;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
port = &info->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
tty->driver_data = info;
|
2009-01-02 21:48:47 +08:00
|
|
|
tty_port_tty_set(port, tty);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
|
2009-01-02 21:48:47 +08:00
|
|
|
__FILE__,__LINE__,tty->driver->name, port->count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* If port is closing, signal caller to try again */
|
2009-01-02 21:48:47 +08:00
|
|
|
if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
|
|
|
|
if (port->flags & ASYNC_CLOSING)
|
|
|
|
interruptible_sleep_on(&port->close_wait);
|
|
|
|
retval = ((port->flags & ASYNC_HUP_NOTIFY) ?
|
2005-04-17 06:20:36 +08:00
|
|
|
-EAGAIN : -ERESTARTSYS);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
tty->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->netlock, flags);
|
|
|
|
if (info->netcount) {
|
|
|
|
retval = -EBUSY;
|
|
|
|
spin_unlock_irqrestore(&info->netlock, flags);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2009-01-02 21:48:47 +08:00
|
|
|
spin_lock(&port->lock);
|
|
|
|
port->count++;
|
|
|
|
spin_unlock(&port->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->netlock, flags);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
if (port->count == 1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* 1st open on this device, init hardware */
|
2009-01-02 21:48:47 +08:00
|
|
|
retval = startup(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval < 0)
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
retval = tty_port_block_til_ready(&info->port, tty, filp);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (retval) {
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):block_til_ready(%s) returned %d\n",
|
|
|
|
__FILE__,__LINE__, info->device_name, retval);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):mgslpc_open(%s) success\n",
|
|
|
|
__FILE__,__LINE__, info->device_name);
|
|
|
|
retval = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
cleanup:
|
2005-04-17 06:20:36 +08:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* /proc fs routines....
|
|
|
|
*/
|
|
|
|
|
2009-04-01 06:19:17 +08:00
|
|
|
static inline void line_info(struct seq_file *m, MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char stat_buf[30];
|
|
|
|
unsigned long flags;
|
|
|
|
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, "%s:io:%04X irq:%d",
|
2005-04-17 06:20:36 +08:00
|
|
|
info->device_name, info->io_base, info->irq_level);
|
|
|
|
|
|
|
|
/* output current serial signal states */
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
get_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
stat_buf[0] = 0;
|
|
|
|
stat_buf[1] = 0;
|
|
|
|
if (info->serial_signals & SerialSignal_RTS)
|
|
|
|
strcat(stat_buf, "|RTS");
|
|
|
|
if (info->serial_signals & SerialSignal_CTS)
|
|
|
|
strcat(stat_buf, "|CTS");
|
|
|
|
if (info->serial_signals & SerialSignal_DTR)
|
|
|
|
strcat(stat_buf, "|DTR");
|
|
|
|
if (info->serial_signals & SerialSignal_DSR)
|
|
|
|
strcat(stat_buf, "|DSR");
|
|
|
|
if (info->serial_signals & SerialSignal_DCD)
|
|
|
|
strcat(stat_buf, "|CD");
|
|
|
|
if (info->serial_signals & SerialSignal_RI)
|
|
|
|
strcat(stat_buf, "|RI");
|
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_HDLC) {
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " HDLC txok:%d rxok:%d",
|
2005-04-17 06:20:36 +08:00
|
|
|
info->icount.txok, info->icount.rxok);
|
|
|
|
if (info->icount.txunder)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " txunder:%d", info->icount.txunder);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.txabort)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " txabort:%d", info->icount.txabort);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.rxshort)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " rxshort:%d", info->icount.rxshort);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.rxlong)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " rxlong:%d", info->icount.rxlong);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.rxover)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " rxover:%d", info->icount.rxover);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.rxcrc)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " rxcrc:%d", info->icount.rxcrc);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " ASYNC tx:%d rx:%d",
|
2005-04-17 06:20:36 +08:00
|
|
|
info->icount.tx, info->icount.rx);
|
|
|
|
if (info->icount.frame)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " fe:%d", info->icount.frame);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.parity)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " pe:%d", info->icount.parity);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.brk)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " brk:%d", info->icount.brk);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->icount.overrun)
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " oe:%d", info->icount.overrun);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Append serial signal status to end */
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, " %s\n", stat_buf+1);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, "txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
info->tx_active,info->bh_requested,info->bh_running,
|
|
|
|
info->pending_bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called to print information about devices
|
|
|
|
*/
|
2009-04-01 06:19:17 +08:00
|
|
|
static int mgslpc_proc_show(struct seq_file *m, void *v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2009-04-01 06:19:17 +08:00
|
|
|
seq_printf(m, "synclink driver:%s\n", driver_version);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
info = mgslpc_device_list;
|
|
|
|
while( info ) {
|
2009-04-01 06:19:17 +08:00
|
|
|
line_info(m, info);
|
2005-04-17 06:20:36 +08:00
|
|
|
info = info->next_device;
|
|
|
|
}
|
2009-04-01 06:19:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-01 06:19:17 +08:00
|
|
|
static int mgslpc_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, mgslpc_proc_show, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 06:19:17 +08:00
|
|
|
static const struct file_operations mgslpc_proc_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = mgslpc_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static int rx_alloc_buffers(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* each buffer has header and data */
|
|
|
|
info->rx_buf_size = sizeof(RXBUF) + info->max_frame_size;
|
|
|
|
|
|
|
|
/* calculate total allocation size for 8 buffers */
|
|
|
|
info->rx_buf_total_size = info->rx_buf_size * 8;
|
|
|
|
|
|
|
|
/* limit total allocated memory */
|
|
|
|
if (info->rx_buf_total_size > 0x10000)
|
|
|
|
info->rx_buf_total_size = 0x10000;
|
|
|
|
|
|
|
|
/* calculate number of buffers */
|
|
|
|
info->rx_buf_count = info->rx_buf_total_size / info->rx_buf_size;
|
|
|
|
|
|
|
|
info->rx_buf = kmalloc(info->rx_buf_total_size, GFP_KERNEL);
|
|
|
|
if (info->rx_buf == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rx_reset_buffers(info);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void rx_free_buffers(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-11-07 17:01:29 +08:00
|
|
|
kfree(info->rx_buf);
|
2005-04-17 06:20:36 +08:00
|
|
|
info->rx_buf = NULL;
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static int claim_resources(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (rx_alloc_buffers(info) < 0 ) {
|
|
|
|
printk( "Cant allocate rx buffer %s\n", info->device_name);
|
|
|
|
release_resources(info);
|
|
|
|
return -ENODEV;
|
2007-10-20 03:45:35 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void release_resources(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("release_resources(%s)\n", info->device_name);
|
|
|
|
rx_free_buffers(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the specified device instance data structure to the
|
|
|
|
* global linked list of devices and increment the device count.
|
2007-10-20 03:45:35 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Arguments: info pointer to device instance data
|
|
|
|
*/
|
2006-06-23 17:06:04 +08:00
|
|
|
static void mgslpc_add_device(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
info->next_device = NULL;
|
|
|
|
info->line = mgslpc_device_count;
|
|
|
|
sprintf(info->device_name,"ttySLP%d",info->line);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->line < MAX_DEVICE_COUNT) {
|
|
|
|
if (maxframe[info->line])
|
|
|
|
info->max_frame_size = maxframe[info->line];
|
|
|
|
}
|
|
|
|
|
|
|
|
mgslpc_device_count++;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!mgslpc_device_list)
|
|
|
|
mgslpc_device_list = info;
|
2007-10-20 03:45:35 +08:00
|
|
|
else {
|
2005-04-17 06:20:36 +08:00
|
|
|
MGSLPC_INFO *current_dev = mgslpc_device_list;
|
|
|
|
while( current_dev->next_device )
|
|
|
|
current_dev = current_dev->next_device;
|
|
|
|
current_dev->next_device = info;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->max_frame_size < 4096)
|
|
|
|
info->max_frame_size = 4096;
|
|
|
|
else if (info->max_frame_size > 65535)
|
|
|
|
info->max_frame_size = 65535;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk( "SyncLink PC Card %s:IO=%04X IRQ=%d\n",
|
|
|
|
info->device_name, info->io_base, info->irq_level);
|
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
hdlcdev_init(info);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void mgslpc_remove_device(MGSLPC_INFO *remove_info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = mgslpc_device_list;
|
|
|
|
MGSLPC_INFO *last = NULL;
|
|
|
|
|
|
|
|
while(info) {
|
|
|
|
if (info == remove_info) {
|
|
|
|
if (last)
|
|
|
|
last->next_device = info->next_device;
|
|
|
|
else
|
|
|
|
mgslpc_device_list = info->next_device;
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
hdlcdev_exit(info);
|
|
|
|
#endif
|
|
|
|
release_resources(info);
|
|
|
|
kfree(info);
|
|
|
|
mgslpc_device_count--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
last = info;
|
|
|
|
info = info->next_device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-28 07:28:42 +08:00
|
|
|
static struct pcmcia_device_id mgslpc_ids[] = {
|
|
|
|
PCMCIA_DEVICE_MANF_CARD(0x02c5, 0x0050),
|
|
|
|
PCMCIA_DEVICE_NULL
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pcmcia, mgslpc_ids);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct pcmcia_driver mgslpc_driver = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.drv = {
|
|
|
|
.name = "synclink_cs",
|
|
|
|
},
|
2006-03-31 23:26:06 +08:00
|
|
|
.probe = mgslpc_probe,
|
2005-11-15 04:23:14 +08:00
|
|
|
.remove = mgslpc_detach,
|
2005-06-28 07:28:42 +08:00
|
|
|
.id_table = mgslpc_ids,
|
2005-11-15 04:21:18 +08:00
|
|
|
.suspend = mgslpc_suspend,
|
|
|
|
.resume = mgslpc_resume,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2006-10-02 17:17:18 +08:00
|
|
|
static const struct tty_operations mgslpc_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = mgslpc_open,
|
|
|
|
.close = mgslpc_close,
|
|
|
|
.write = mgslpc_write,
|
|
|
|
.put_char = mgslpc_put_char,
|
|
|
|
.flush_chars = mgslpc_flush_chars,
|
|
|
|
.write_room = mgslpc_write_room,
|
|
|
|
.chars_in_buffer = mgslpc_chars_in_buffer,
|
|
|
|
.flush_buffer = mgslpc_flush_buffer,
|
|
|
|
.ioctl = mgslpc_ioctl,
|
|
|
|
.throttle = mgslpc_throttle,
|
|
|
|
.unthrottle = mgslpc_unthrottle,
|
|
|
|
.send_xchar = mgslpc_send_xchar,
|
|
|
|
.break_ctl = mgslpc_break,
|
|
|
|
.wait_until_sent = mgslpc_wait_until_sent,
|
|
|
|
.set_termios = mgslpc_set_termios,
|
|
|
|
.stop = tx_pause,
|
|
|
|
.start = tx_release,
|
|
|
|
.hangup = mgslpc_hangup,
|
|
|
|
.tiocmget = tiocmget,
|
|
|
|
.tiocmset = tiocmset,
|
2009-04-01 06:19:17 +08:00
|
|
|
.proc_fops = &mgslpc_proc_fops,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void synclink_cs_cleanup(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
printk("Unloading %s: version %s\n", driver_name, driver_version);
|
|
|
|
|
|
|
|
while(mgslpc_device_list)
|
|
|
|
mgslpc_remove_device(mgslpc_device_list);
|
|
|
|
|
|
|
|
if (serial_driver) {
|
|
|
|
if ((rc = tty_unregister_driver(serial_driver)))
|
|
|
|
printk("%s(%d) failed to unregister tty driver err=%d\n",
|
|
|
|
__FILE__,__LINE__,rc);
|
|
|
|
put_tty_driver(serial_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
pcmcia_unregister_driver(&mgslpc_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init synclink_cs_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (break_on_load) {
|
|
|
|
mgslpc_get_text_ptr();
|
|
|
|
BREAKPOINT();
|
|
|
|
}
|
|
|
|
|
|
|
|
printk("%s %s\n", driver_name, driver_version);
|
|
|
|
|
|
|
|
if ((rc = pcmcia_register_driver(&mgslpc_driver)) < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
serial_driver = alloc_tty_driver(MAX_DEVICE_COUNT);
|
|
|
|
if (!serial_driver) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the tty_driver structure */
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
serial_driver->owner = THIS_MODULE;
|
|
|
|
serial_driver->driver_name = "synclink_cs";
|
|
|
|
serial_driver->name = "ttySLP";
|
|
|
|
serial_driver->major = ttymajor;
|
|
|
|
serial_driver->minor_start = 64;
|
|
|
|
serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
|
|
|
|
serial_driver->subtype = SERIAL_TYPE_NORMAL;
|
|
|
|
serial_driver->init_termios = tty_std_termios;
|
|
|
|
serial_driver->init_termios.c_cflag =
|
|
|
|
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
|
|
|
|
serial_driver->flags = TTY_DRIVER_REAL_RAW;
|
|
|
|
tty_set_operations(serial_driver, &mgslpc_ops);
|
|
|
|
|
|
|
|
if ((rc = tty_register_driver(serial_driver)) < 0) {
|
|
|
|
printk("%s(%d):Couldn't register serial driver\n",
|
|
|
|
__FILE__,__LINE__);
|
|
|
|
put_tty_driver(serial_driver);
|
|
|
|
serial_driver = NULL;
|
|
|
|
goto error;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
printk("%s %s, tty major#%d\n",
|
|
|
|
driver_name, driver_version,
|
|
|
|
serial_driver->major);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
synclink_cs_cleanup();
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
static void __exit synclink_cs_exit(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
synclink_cs_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(synclink_cs_init);
|
|
|
|
module_exit(synclink_cs_exit);
|
|
|
|
|
|
|
|
static void mgslpc_set_rate(MGSLPC_INFO *info, unsigned char channel, unsigned int rate)
|
|
|
|
{
|
|
|
|
unsigned int M, N;
|
|
|
|
unsigned char val;
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* note:standard BRG mode is broken in V3.2 chip
|
|
|
|
* so enhanced mode is always used
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (rate) {
|
|
|
|
N = 3686400 / rate;
|
|
|
|
if (!N)
|
|
|
|
N = 1;
|
|
|
|
N >>= 1;
|
|
|
|
for (M = 1; N > 64 && M < 16; M++)
|
|
|
|
N >>= 1;
|
|
|
|
N--;
|
|
|
|
|
|
|
|
/* BGR[5..0] = N
|
|
|
|
* BGR[9..6] = M
|
|
|
|
* BGR[7..0] contained in BGR register
|
|
|
|
* BGR[9..8] contained in CCR2[7..6]
|
|
|
|
* divisor = (N+1)*2^M
|
|
|
|
*
|
|
|
|
* Note: M *must* not be zero (causes asymetric duty cycle)
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, (unsigned char) (channel + BGR),
|
|
|
|
(unsigned char) ((M << 6) + N));
|
|
|
|
val = read_reg(info, (unsigned char) (channel + CCR2)) & 0x3f;
|
|
|
|
val |= ((M << 4) & 0xc0);
|
|
|
|
write_reg(info, (unsigned char) (channel + CCR2), val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enabled the AUX clock output at the specified frequency.
|
|
|
|
*/
|
|
|
|
static void enable_auxclk(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
unsigned char val;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* MODE
|
|
|
|
*
|
|
|
|
* 07..06 MDS[1..0] 10 = transparent HDLC mode
|
|
|
|
* 05 ADM Address Mode, 0 = no addr recognition
|
|
|
|
* 04 TMD Timer Mode, 0 = external
|
|
|
|
* 03 RAC Receiver Active, 0 = inactive
|
|
|
|
* 02 RTS 0=RTS active during xmit, 1=RTS always active
|
|
|
|
* 01 TRS Timer Resolution, 1=512
|
|
|
|
* 00 TLP Test Loop, 0 = no loop
|
|
|
|
*
|
|
|
|
* 1000 0010
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x82;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* channel B RTS is used to enable AUXCLK driver on SP505 */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_HDLC && info->params.clock_speed)
|
|
|
|
val |= BIT2;
|
|
|
|
write_reg(info, CHB + MODE, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR0
|
|
|
|
*
|
|
|
|
* 07 PU Power Up, 1=active, 0=power down
|
|
|
|
* 06 MCE Master Clock Enable, 1=enabled
|
|
|
|
* 05 Reserved, 0
|
|
|
|
* 04..02 SC[2..0] Encoding
|
|
|
|
* 01..00 SM[1..0] Serial Mode, 00=HDLC
|
|
|
|
*
|
|
|
|
* 11000000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHB + CCR0, 0xc0);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR1
|
|
|
|
*
|
|
|
|
* 07 SFLG Shared Flag, 0 = disable shared flags
|
|
|
|
* 06 GALP Go Active On Loop, 0 = not used
|
|
|
|
* 05 GLP Go On Loop, 0 = not used
|
|
|
|
* 04 ODS Output Driver Select, 1=TxD is push-pull output
|
|
|
|
* 03 ITF Interframe Time Fill, 0=mark, 1=flag
|
|
|
|
* 02..00 CM[2..0] Clock Mode
|
|
|
|
*
|
|
|
|
* 0001 0111
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHB + CCR1, 0x17);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR2 (Channel B)
|
|
|
|
*
|
|
|
|
* 07..06 BGR[9..8] Baud rate bits 9..8
|
|
|
|
* 05 BDF Baud rate divisor factor, 0=1, 1=BGR value
|
|
|
|
* 04 SSEL Clock source select, 1=submode b
|
|
|
|
* 03 TOE 0=TxCLK is input, 1=TxCLK is output
|
|
|
|
* 02 RWX Read/Write Exchange 0=disabled
|
|
|
|
* 01 C32, CRC select, 0=CRC-16, 1=CRC-32
|
|
|
|
* 00 DIV, data inversion 0=disabled, 1=enabled
|
|
|
|
*
|
|
|
|
* 0011 1000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_HDLC && info->params.clock_speed)
|
|
|
|
write_reg(info, CHB + CCR2, 0x38);
|
|
|
|
else
|
|
|
|
write_reg(info, CHB + CCR2, 0x30);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR4
|
|
|
|
*
|
|
|
|
* 07 MCK4 Master Clock Divide by 4, 1=enabled
|
|
|
|
* 06 EBRG Enhanced Baud Rate Generator Mode, 1=enabled
|
|
|
|
* 05 TST1 Test Pin, 0=normal operation
|
|
|
|
* 04 ICD Ivert Carrier Detect, 1=enabled (active low)
|
|
|
|
* 03..02 Reserved, must be 0
|
|
|
|
* 01..00 RFT[1..0] RxFIFO Threshold 00=32 bytes
|
|
|
|
*
|
|
|
|
* 0101 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHB + CCR4, 0x50);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* if auxclk not enabled, set internal BRG so
|
|
|
|
* CTS transitions can be detected (requires TxC)
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.mode == MGSL_MODE_HDLC && info->params.clock_speed)
|
|
|
|
mgslpc_set_rate(info, CHB, info->params.clock_speed);
|
|
|
|
else
|
|
|
|
mgslpc_set_rate(info, CHB, 921600);
|
|
|
|
}
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
static void loopback_enable(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* CCR1:02..00 CM[2..0] Clock Mode = 111 (clock mode 7) */
|
2005-04-17 06:20:36 +08:00
|
|
|
val = read_reg(info, CHA + CCR1) | (BIT2 + BIT1 + BIT0);
|
|
|
|
write_reg(info, CHA + CCR1, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* CCR2:04 SSEL Clock source select, 1=submode b */
|
2005-04-17 06:20:36 +08:00
|
|
|
val = read_reg(info, CHA + CCR2) | (BIT4 + BIT5);
|
|
|
|
write_reg(info, CHA + CCR2, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* set LinkSpeed if available, otherwise default to 2Mbps */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->params.clock_speed)
|
|
|
|
mgslpc_set_rate(info, CHA, info->params.clock_speed);
|
|
|
|
else
|
|
|
|
mgslpc_set_rate(info, CHA, 1843200);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* MODE:00 TLP Test Loop, 1=loopback enabled */
|
2005-04-17 06:20:36 +08:00
|
|
|
val = read_reg(info, CHA + MODE) | BIT0;
|
|
|
|
write_reg(info, CHA + MODE, val);
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void hdlc_mode(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
unsigned char clkmode, clksubmode;
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* disable all interrupts */
|
2005-04-17 06:20:36 +08:00
|
|
|
irq_disable(info, CHA, 0xffff);
|
|
|
|
irq_disable(info, CHB, 0xffff);
|
|
|
|
port_irq_disable(info, 0xff);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* assume clock mode 0a, rcv=RxC xmt=TxC */
|
2005-04-17 06:20:36 +08:00
|
|
|
clkmode = clksubmode = 0;
|
|
|
|
if (info->params.flags & HDLC_FLAG_RXC_DPLL
|
|
|
|
&& info->params.flags & HDLC_FLAG_TXC_DPLL) {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* clock mode 7a, rcv = DPLL, xmt = DPLL */
|
2005-04-17 06:20:36 +08:00
|
|
|
clkmode = 7;
|
|
|
|
} else if (info->params.flags & HDLC_FLAG_RXC_BRG
|
|
|
|
&& info->params.flags & HDLC_FLAG_TXC_BRG) {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* clock mode 7b, rcv = BRG, xmt = BRG */
|
2005-04-17 06:20:36 +08:00
|
|
|
clkmode = 7;
|
|
|
|
clksubmode = 1;
|
|
|
|
} else if (info->params.flags & HDLC_FLAG_RXC_DPLL) {
|
|
|
|
if (info->params.flags & HDLC_FLAG_TXC_BRG) {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* clock mode 6b, rcv = DPLL, xmt = BRG/16 */
|
2005-04-17 06:20:36 +08:00
|
|
|
clkmode = 6;
|
|
|
|
clksubmode = 1;
|
|
|
|
} else {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* clock mode 6a, rcv = DPLL, xmt = TxC */
|
2005-04-17 06:20:36 +08:00
|
|
|
clkmode = 6;
|
|
|
|
}
|
|
|
|
} else if (info->params.flags & HDLC_FLAG_TXC_BRG) {
|
2007-10-20 03:45:35 +08:00
|
|
|
/* clock mode 0b, rcv = RxC, xmt = BRG */
|
2005-04-17 06:20:36 +08:00
|
|
|
clksubmode = 1;
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* MODE
|
|
|
|
*
|
|
|
|
* 07..06 MDS[1..0] 10 = transparent HDLC mode
|
|
|
|
* 05 ADM Address Mode, 0 = no addr recognition
|
|
|
|
* 04 TMD Timer Mode, 0 = external
|
|
|
|
* 03 RAC Receiver Active, 0 = inactive
|
|
|
|
* 02 RTS 0=RTS active during xmit, 1=RTS always active
|
|
|
|
* 01 TRS Timer Resolution, 1=512
|
|
|
|
* 00 TLP Test Loop, 0 = no loop
|
|
|
|
*
|
|
|
|
* 1000 0010
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x82;
|
|
|
|
if (info->params.loopback)
|
|
|
|
val |= BIT0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* preserve RTS state */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->serial_signals & SerialSignal_RTS)
|
|
|
|
val |= BIT2;
|
|
|
|
write_reg(info, CHA + MODE, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR0
|
|
|
|
*
|
|
|
|
* 07 PU Power Up, 1=active, 0=power down
|
|
|
|
* 06 MCE Master Clock Enable, 1=enabled
|
|
|
|
* 05 Reserved, 0
|
|
|
|
* 04..02 SC[2..0] Encoding
|
|
|
|
* 01..00 SM[1..0] Serial Mode, 00=HDLC
|
|
|
|
*
|
|
|
|
* 11000000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0xc0;
|
|
|
|
switch (info->params.encoding)
|
|
|
|
{
|
|
|
|
case HDLC_ENCODING_NRZI:
|
|
|
|
val |= BIT3;
|
|
|
|
break;
|
|
|
|
case HDLC_ENCODING_BIPHASE_SPACE:
|
|
|
|
val |= BIT4;
|
|
|
|
break; // FM0
|
|
|
|
case HDLC_ENCODING_BIPHASE_MARK:
|
|
|
|
val |= BIT4 + BIT2;
|
|
|
|
break; // FM1
|
|
|
|
case HDLC_ENCODING_BIPHASE_LEVEL:
|
|
|
|
val |= BIT4 + BIT3;
|
|
|
|
break; // Manchester
|
|
|
|
}
|
|
|
|
write_reg(info, CHA + CCR0, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR1
|
|
|
|
*
|
|
|
|
* 07 SFLG Shared Flag, 0 = disable shared flags
|
|
|
|
* 06 GALP Go Active On Loop, 0 = not used
|
|
|
|
* 05 GLP Go On Loop, 0 = not used
|
|
|
|
* 04 ODS Output Driver Select, 1=TxD is push-pull output
|
|
|
|
* 03 ITF Interframe Time Fill, 0=mark, 1=flag
|
|
|
|
* 02..00 CM[2..0] Clock Mode
|
|
|
|
*
|
|
|
|
* 0001 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x10 + clkmode;
|
|
|
|
write_reg(info, CHA + CCR1, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR2
|
|
|
|
*
|
|
|
|
* 07..06 BGR[9..8] Baud rate bits 9..8
|
|
|
|
* 05 BDF Baud rate divisor factor, 0=1, 1=BGR value
|
|
|
|
* 04 SSEL Clock source select, 1=submode b
|
|
|
|
* 03 TOE 0=TxCLK is input, 0=TxCLK is input
|
|
|
|
* 02 RWX Read/Write Exchange 0=disabled
|
|
|
|
* 01 C32, CRC select, 0=CRC-16, 1=CRC-32
|
|
|
|
* 00 DIV, data inversion 0=disabled, 1=enabled
|
|
|
|
*
|
|
|
|
* 0000 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x00;
|
|
|
|
if (clkmode == 2 || clkmode == 3 || clkmode == 6
|
|
|
|
|| clkmode == 7 || (clkmode == 0 && clksubmode == 1))
|
|
|
|
val |= BIT5;
|
|
|
|
if (clksubmode)
|
|
|
|
val |= BIT4;
|
|
|
|
if (info->params.crc_type == HDLC_CRC_32_CCITT)
|
|
|
|
val |= BIT1;
|
|
|
|
if (info->params.encoding == HDLC_ENCODING_NRZB)
|
|
|
|
val |= BIT0;
|
|
|
|
write_reg(info, CHA + CCR2, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR3
|
|
|
|
*
|
|
|
|
* 07..06 PRE[1..0] Preamble count 00=1, 01=2, 10=4, 11=8
|
|
|
|
* 05 EPT Enable preamble transmission, 1=enabled
|
|
|
|
* 04 RADD Receive address pushed to FIFO, 0=disabled
|
|
|
|
* 03 CRL CRC Reset Level, 0=FFFF
|
|
|
|
* 02 RCRC Rx CRC 0=On 1=Off
|
|
|
|
* 01 TCRC Tx CRC 0=On 1=Off
|
|
|
|
* 00 PSD DPLL Phase Shift Disable
|
|
|
|
*
|
|
|
|
* 0000 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x00;
|
|
|
|
if (info->params.crc_type == HDLC_CRC_NONE)
|
|
|
|
val |= BIT2 + BIT1;
|
|
|
|
if (info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE)
|
|
|
|
val |= BIT5;
|
|
|
|
switch (info->params.preamble_length)
|
|
|
|
{
|
|
|
|
case HDLC_PREAMBLE_LENGTH_16BITS:
|
|
|
|
val |= BIT6;
|
|
|
|
break;
|
|
|
|
case HDLC_PREAMBLE_LENGTH_32BITS:
|
|
|
|
val |= BIT6;
|
|
|
|
break;
|
|
|
|
case HDLC_PREAMBLE_LENGTH_64BITS:
|
|
|
|
val |= BIT7 + BIT6;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
write_reg(info, CHA + CCR3, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* PRE - Preamble pattern */
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0;
|
|
|
|
switch (info->params.preamble)
|
|
|
|
{
|
|
|
|
case HDLC_PREAMBLE_PATTERN_FLAGS: val = 0x7e; break;
|
|
|
|
case HDLC_PREAMBLE_PATTERN_10: val = 0xaa; break;
|
|
|
|
case HDLC_PREAMBLE_PATTERN_01: val = 0x55; break;
|
|
|
|
case HDLC_PREAMBLE_PATTERN_ONES: val = 0xff; break;
|
|
|
|
}
|
|
|
|
write_reg(info, CHA + PRE, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR4
|
|
|
|
*
|
|
|
|
* 07 MCK4 Master Clock Divide by 4, 1=enabled
|
|
|
|
* 06 EBRG Enhanced Baud Rate Generator Mode, 1=enabled
|
|
|
|
* 05 TST1 Test Pin, 0=normal operation
|
|
|
|
* 04 ICD Ivert Carrier Detect, 1=enabled (active low)
|
|
|
|
* 03..02 Reserved, must be 0
|
|
|
|
* 01..00 RFT[1..0] RxFIFO Threshold 00=32 bytes
|
|
|
|
*
|
|
|
|
* 0101 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x50;
|
|
|
|
write_reg(info, CHA + CCR4, val);
|
|
|
|
if (info->params.flags & HDLC_FLAG_RXC_DPLL)
|
|
|
|
mgslpc_set_rate(info, CHA, info->params.clock_speed * 16);
|
|
|
|
else
|
|
|
|
mgslpc_set_rate(info, CHA, info->params.clock_speed);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* RLCR Receive length check register
|
|
|
|
*
|
|
|
|
* 7 1=enable receive length check
|
|
|
|
* 6..0 Max frame length = (RL + 1) * 32
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + RLCR, 0);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* XBCH Transmit Byte Count High
|
|
|
|
*
|
|
|
|
* 07 DMA mode, 0 = interrupt driven
|
|
|
|
* 06 NRM, 0=ABM (ignored)
|
|
|
|
* 05 CAS Carrier Auto Start
|
|
|
|
* 04 XC Transmit Continuously (ignored)
|
|
|
|
* 03..00 XBC[10..8] Transmit byte count bits 10..8
|
|
|
|
*
|
|
|
|
* 0000 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x00;
|
|
|
|
if (info->params.flags & HDLC_FLAG_AUTO_DCD)
|
|
|
|
val |= BIT5;
|
|
|
|
write_reg(info, CHA + XBCH, val);
|
|
|
|
enable_auxclk(info);
|
|
|
|
if (info->params.loopback || info->testing_irq)
|
|
|
|
loopback_enable(info);
|
|
|
|
if (info->params.flags & HDLC_FLAG_AUTO_CTS)
|
|
|
|
{
|
|
|
|
irq_enable(info, CHB, IRQ_CTS);
|
2007-10-20 03:45:35 +08:00
|
|
|
/* PVR[3] 1=AUTO CTS active */
|
2005-04-17 06:20:36 +08:00
|
|
|
set_reg_bits(info, CHA + PVR, BIT3);
|
|
|
|
} else
|
|
|
|
clear_reg_bits(info, CHA + PVR, BIT3);
|
|
|
|
|
|
|
|
irq_enable(info, CHA,
|
|
|
|
IRQ_RXEOM + IRQ_RXFIFO + IRQ_ALLSENT +
|
|
|
|
IRQ_UNDERRUN + IRQ_TXFIFO);
|
|
|
|
issue_command(info, CHA, CMD_TXRESET + CMD_RXRESET);
|
|
|
|
wait_command_complete(info, CHA);
|
|
|
|
read_reg16(info, CHA + ISR); /* clear pending IRQs */
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Master clock mode enabled above to allow reset commands
|
|
|
|
* to complete even if no data clocks are present.
|
|
|
|
*
|
|
|
|
* Disable master clock mode for normal communications because
|
|
|
|
* V3.2 of the ESCC2 has a bug that prevents the transmit all sent
|
|
|
|
* IRQ when in master clock mode.
|
|
|
|
*
|
|
|
|
* Leave master clock mode enabled for IRQ test because the
|
|
|
|
* timer IRQ used by the test can only happen in master clock mode.
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!info->testing_irq)
|
|
|
|
clear_reg_bits(info, CHA + CCR0, BIT6);
|
|
|
|
|
|
|
|
tx_set_idle(info);
|
|
|
|
|
|
|
|
tx_stop(info);
|
|
|
|
rx_stop(info);
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void rx_stop(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s(%d):rx_stop(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* MODE:03 RAC Receiver Active, 0=inactive */
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_reg_bits(info, CHA + MODE, BIT3);
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->rx_enabled = false;
|
|
|
|
info->rx_overflow = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void rx_start(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s(%d):rx_start(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
|
|
|
|
|
|
|
rx_reset_buffers(info);
|
2008-04-28 17:14:02 +08:00
|
|
|
info->rx_enabled = false;
|
|
|
|
info->rx_overflow = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* MODE:03 RAC Receiver Active, 1=active */
|
2005-04-17 06:20:36 +08:00
|
|
|
set_reg_bits(info, CHA + MODE, BIT3);
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->rx_enabled = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
static void tx_start(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s(%d):tx_start(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->tx_count) {
|
|
|
|
/* If auto RTS enabled and RTS is inactive, then assert */
|
|
|
|
/* RTS and set a flag indicating that the driver should */
|
|
|
|
/* negate RTS when the transmission completes. */
|
2008-04-28 17:14:02 +08:00
|
|
|
info->drop_rts_on_tx_done = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (info->params.flags & HDLC_FLAG_AUTO_RTS) {
|
|
|
|
get_signals(info);
|
|
|
|
if (!(info->serial_signals & SerialSignal_RTS)) {
|
|
|
|
info->serial_signals |= SerialSignal_RTS;
|
|
|
|
set_signals(info);
|
2008-04-28 17:14:02 +08:00
|
|
|
info->drop_rts_on_tx_done = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (info->params.mode == MGSL_MODE_ASYNC) {
|
|
|
|
if (!info->tx_active) {
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_active = true;
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_ready(info, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_active = true;
|
2009-01-02 21:48:47 +08:00
|
|
|
tx_ready(info, tty);
|
2007-02-12 16:52:31 +08:00
|
|
|
mod_timer(&info->tx_timer, jiffies +
|
|
|
|
msecs_to_jiffies(5000));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!info->tx_enabled)
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_enabled = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void tx_stop(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (debug_level >= DEBUG_LEVEL_ISR)
|
|
|
|
printk("%s(%d):tx_stop(%s)\n",
|
|
|
|
__FILE__,__LINE__, info->device_name );
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
del_timer(&info->tx_timer);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_enabled = false;
|
|
|
|
info->tx_active = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Reset the adapter to a known state and prepare it for further use.
|
|
|
|
*/
|
2006-06-23 17:06:04 +08:00
|
|
|
static void reset_device(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-20 03:45:35 +08:00
|
|
|
/* power up both channels (set BIT7) */
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + CCR0, 0x80);
|
|
|
|
write_reg(info, CHB + CCR0, 0x80);
|
|
|
|
write_reg(info, CHA + MODE, 0);
|
|
|
|
write_reg(info, CHB + MODE, 0);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* disable all interrupts */
|
2005-04-17 06:20:36 +08:00
|
|
|
irq_disable(info, CHA, 0xffff);
|
|
|
|
irq_disable(info, CHB, 0xffff);
|
|
|
|
port_irq_disable(info, 0xff);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* PCR Port Configuration Register
|
|
|
|
*
|
|
|
|
* 07..04 DEC[3..0] Serial I/F select outputs
|
|
|
|
* 03 output, 1=AUTO CTS control enabled
|
|
|
|
* 02 RI Ring Indicator input 0=active
|
|
|
|
* 01 DSR input 0=active
|
|
|
|
* 00 DTR output 0=active
|
|
|
|
*
|
|
|
|
* 0000 0110
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, PCR, 0x06);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* PVR Port Value Register
|
|
|
|
*
|
|
|
|
* 07..04 DEC[3..0] Serial I/F select (0000=disabled)
|
|
|
|
* 03 AUTO CTS output 1=enabled
|
|
|
|
* 02 RI Ring Indicator input
|
|
|
|
* 01 DSR input
|
|
|
|
* 00 DTR output (1=inactive)
|
|
|
|
*
|
|
|
|
* 0000 0001
|
|
|
|
*/
|
|
|
|
// write_reg(info, PVR, PVR_DTR);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* IPC Interrupt Port Configuration
|
|
|
|
*
|
|
|
|
* 07 VIS 1=Masked interrupts visible
|
|
|
|
* 06..05 Reserved, 0
|
|
|
|
* 04..03 SLA Slave address, 00 ignored
|
|
|
|
* 02 CASM Cascading Mode, 1=daisy chain
|
|
|
|
* 01..00 IC[1..0] Interrupt Config, 01=push-pull output, active low
|
|
|
|
*
|
|
|
|
* 0000 0101
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, IPC, 0x05);
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void async_mode(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
|
2007-10-20 03:45:35 +08:00
|
|
|
/* disable all interrupts */
|
2005-04-17 06:20:36 +08:00
|
|
|
irq_disable(info, CHA, 0xffff);
|
|
|
|
irq_disable(info, CHB, 0xffff);
|
|
|
|
port_irq_disable(info, 0xff);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* MODE
|
|
|
|
*
|
|
|
|
* 07 Reserved, 0
|
|
|
|
* 06 FRTS RTS State, 0=active
|
|
|
|
* 05 FCTS Flow Control on CTS
|
|
|
|
* 04 FLON Flow Control Enable
|
|
|
|
* 03 RAC Receiver Active, 0 = inactive
|
|
|
|
* 02 RTS 0=Auto RTS, 1=manual RTS
|
|
|
|
* 01 TRS Timer Resolution, 1=512
|
|
|
|
* 00 TLP Test Loop, 0 = no loop
|
|
|
|
*
|
|
|
|
* 0000 0110
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x06;
|
|
|
|
if (info->params.loopback)
|
|
|
|
val |= BIT0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* preserve RTS state */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!(info->serial_signals & SerialSignal_RTS))
|
|
|
|
val |= BIT6;
|
|
|
|
write_reg(info, CHA + MODE, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR0
|
|
|
|
*
|
|
|
|
* 07 PU Power Up, 1=active, 0=power down
|
|
|
|
* 06 MCE Master Clock Enable, 1=enabled
|
|
|
|
* 05 Reserved, 0
|
|
|
|
* 04..02 SC[2..0] Encoding, 000=NRZ
|
|
|
|
* 01..00 SM[1..0] Serial Mode, 11=Async
|
|
|
|
*
|
|
|
|
* 1000 0011
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + CCR0, 0x83);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR1
|
|
|
|
*
|
|
|
|
* 07..05 Reserved, 0
|
|
|
|
* 04 ODS Output Driver Select, 1=TxD is push-pull output
|
|
|
|
* 03 BCR Bit Clock Rate, 1=16x
|
|
|
|
* 02..00 CM[2..0] Clock Mode, 111=BRG
|
|
|
|
*
|
|
|
|
* 0001 1111
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + CCR1, 0x1f);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR2 (channel A)
|
|
|
|
*
|
|
|
|
* 07..06 BGR[9..8] Baud rate bits 9..8
|
|
|
|
* 05 BDF Baud rate divisor factor, 0=1, 1=BGR value
|
|
|
|
* 04 SSEL Clock source select, 1=submode b
|
|
|
|
* 03 TOE 0=TxCLK is input, 0=TxCLK is input
|
|
|
|
* 02 RWX Read/Write Exchange 0=disabled
|
|
|
|
* 01 Reserved, 0
|
|
|
|
* 00 DIV, data inversion 0=disabled, 1=enabled
|
|
|
|
*
|
|
|
|
* 0001 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + CCR2, 0x10);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR3
|
|
|
|
*
|
|
|
|
* 07..01 Reserved, 0
|
|
|
|
* 00 PSD DPLL Phase Shift Disable
|
|
|
|
*
|
|
|
|
* 0000 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + CCR3, 0);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* CCR4
|
|
|
|
*
|
|
|
|
* 07 MCK4 Master Clock Divide by 4, 1=enabled
|
|
|
|
* 06 EBRG Enhanced Baud Rate Generator Mode, 1=enabled
|
|
|
|
* 05 TST1 Test Pin, 0=normal operation
|
|
|
|
* 04 ICD Ivert Carrier Detect, 1=enabled (active low)
|
|
|
|
* 03..00 Reserved, must be 0
|
|
|
|
*
|
|
|
|
* 0101 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + CCR4, 0x50);
|
|
|
|
mgslpc_set_rate(info, CHA, info->params.data_rate * 16);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* DAFO Data Format
|
|
|
|
*
|
|
|
|
* 07 Reserved, 0
|
|
|
|
* 06 XBRK transmit break, 0=normal operation
|
|
|
|
* 05 Stop bits (0=1, 1=2)
|
|
|
|
* 04..03 PAR[1..0] Parity (01=odd, 10=even)
|
|
|
|
* 02 PAREN Parity Enable
|
|
|
|
* 01..00 CHL[1..0] Character Length (00=8, 01=7)
|
|
|
|
*
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x00;
|
|
|
|
if (info->params.data_bits != 8)
|
|
|
|
val |= BIT0; /* 7 bits */
|
|
|
|
if (info->params.stop_bits != 1)
|
|
|
|
val |= BIT5;
|
|
|
|
if (info->params.parity != ASYNC_PARITY_NONE)
|
|
|
|
{
|
|
|
|
val |= BIT2; /* Parity enable */
|
|
|
|
if (info->params.parity == ASYNC_PARITY_ODD)
|
|
|
|
val |= BIT3;
|
|
|
|
else
|
|
|
|
val |= BIT4;
|
|
|
|
}
|
|
|
|
write_reg(info, CHA + DAFO, val);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* RFC Rx FIFO Control
|
|
|
|
*
|
|
|
|
* 07 Reserved, 0
|
|
|
|
* 06 DPS, 1=parity bit not stored in data byte
|
|
|
|
* 05 DXS, 0=all data stored in FIFO (including XON/XOFF)
|
|
|
|
* 04 RFDF Rx FIFO Data Format, 1=status byte stored in FIFO
|
|
|
|
* 03..02 RFTH[1..0], rx threshold, 11=16 status + 16 data byte
|
|
|
|
* 01 Reserved, 0
|
|
|
|
* 00 TCDE Terminate Char Detect Enable, 0=disabled
|
|
|
|
*
|
|
|
|
* 0101 1100
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + RFC, 0x5c);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* RLCR Receive length check register
|
|
|
|
*
|
|
|
|
* Max frame length = (RL + 1) * 32
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
write_reg(info, CHA + RLCR, 0);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* XBCH Transmit Byte Count High
|
|
|
|
*
|
|
|
|
* 07 DMA mode, 0 = interrupt driven
|
|
|
|
* 06 NRM, 0=ABM (ignored)
|
|
|
|
* 05 CAS Carrier Auto Start
|
|
|
|
* 04 XC Transmit Continuously (ignored)
|
|
|
|
* 03..00 XBC[10..8] Transmit byte count bits 10..8
|
|
|
|
*
|
|
|
|
* 0000 0000
|
2007-10-20 03:45:35 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
val = 0x00;
|
|
|
|
if (info->params.flags & HDLC_FLAG_AUTO_DCD)
|
|
|
|
val |= BIT5;
|
|
|
|
write_reg(info, CHA + XBCH, val);
|
|
|
|
if (info->params.flags & HDLC_FLAG_AUTO_CTS)
|
|
|
|
irq_enable(info, CHA, IRQ_CTS);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* MODE:03 RAC Receiver Active, 1=active */
|
2005-04-17 06:20:36 +08:00
|
|
|
set_reg_bits(info, CHA + MODE, BIT3);
|
|
|
|
enable_auxclk(info);
|
|
|
|
if (info->params.flags & HDLC_FLAG_AUTO_CTS) {
|
|
|
|
irq_enable(info, CHB, IRQ_CTS);
|
2007-10-20 03:45:35 +08:00
|
|
|
/* PVR[3] 1=AUTO CTS active */
|
2005-04-17 06:20:36 +08:00
|
|
|
set_reg_bits(info, CHA + PVR, BIT3);
|
|
|
|
} else
|
|
|
|
clear_reg_bits(info, CHA + PVR, BIT3);
|
|
|
|
irq_enable(info, CHA,
|
|
|
|
IRQ_RXEOM + IRQ_RXFIFO + IRQ_BREAK_ON + IRQ_RXTIME +
|
|
|
|
IRQ_ALLSENT + IRQ_TXFIFO);
|
|
|
|
issue_command(info, CHA, CMD_TXRESET + CMD_RXRESET);
|
|
|
|
wait_command_complete(info, CHA);
|
|
|
|
read_reg16(info, CHA + ISR); /* clear pending IRQs */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the HDLC idle mode for the transmitter.
|
|
|
|
*/
|
2006-06-23 17:06:04 +08:00
|
|
|
static void tx_set_idle(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-20 03:45:35 +08:00
|
|
|
/* Note: ESCC2 only supports flags and one idle modes */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->idle_mode == HDLC_TXIDLE_FLAGS)
|
|
|
|
set_reg_bits(info, CHA + CCR1, BIT3);
|
|
|
|
else
|
|
|
|
clear_reg_bits(info, CHA + CCR1, BIT3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get state of the V24 status (input) signals.
|
|
|
|
*/
|
2006-06-23 17:06:04 +08:00
|
|
|
static void get_signals(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char status = 0;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
|
|
|
/* preserve DTR and RTS */
|
2005-04-17 06:20:36 +08:00
|
|
|
info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
|
|
|
|
|
|
|
|
if (read_reg(info, CHB + VSTR) & BIT7)
|
|
|
|
info->serial_signals |= SerialSignal_DCD;
|
|
|
|
if (read_reg(info, CHB + STAR) & BIT1)
|
|
|
|
info->serial_signals |= SerialSignal_CTS;
|
|
|
|
|
|
|
|
status = read_reg(info, CHA + PVR);
|
|
|
|
if (!(status & PVR_RI))
|
|
|
|
info->serial_signals |= SerialSignal_RI;
|
|
|
|
if (!(status & PVR_DSR))
|
|
|
|
info->serial_signals |= SerialSignal_DSR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the state of DTR and RTS based on contents of
|
|
|
|
* serial_signals member of device extension.
|
|
|
|
*/
|
2006-06-23 17:06:04 +08:00
|
|
|
static void set_signals(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
val = read_reg(info, CHA + MODE);
|
|
|
|
if (info->params.mode == MGSL_MODE_ASYNC) {
|
|
|
|
if (info->serial_signals & SerialSignal_RTS)
|
|
|
|
val &= ~BIT6;
|
|
|
|
else
|
|
|
|
val |= BIT6;
|
|
|
|
} else {
|
|
|
|
if (info->serial_signals & SerialSignal_RTS)
|
|
|
|
val |= BIT2;
|
|
|
|
else
|
|
|
|
val &= ~BIT2;
|
|
|
|
}
|
|
|
|
write_reg(info, CHA + MODE, val);
|
|
|
|
|
|
|
|
if (info->serial_signals & SerialSignal_DTR)
|
|
|
|
clear_reg_bits(info, CHA + PVR, PVR_DTR);
|
|
|
|
else
|
|
|
|
set_reg_bits(info, CHA + PVR, PVR_DTR);
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void rx_reset_buffers(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
RXBUF *buf;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
info->rx_put = 0;
|
|
|
|
info->rx_get = 0;
|
|
|
|
info->rx_frame_count = 0;
|
|
|
|
for (i=0 ; i < info->rx_buf_count ; i++) {
|
|
|
|
buf = (RXBUF*)(info->rx_buf + (i * info->rx_buf_size));
|
|
|
|
buf->status = buf->count = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Attempt to return a received HDLC frame
|
|
|
|
* Only frames received without errors are returned.
|
|
|
|
*
|
2008-04-28 17:14:02 +08:00
|
|
|
* Returns true if frame returned, otherwise false
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2009-01-02 21:48:47 +08:00
|
|
|
static bool rx_get_frame(MGSLPC_INFO *info, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned short status;
|
|
|
|
RXBUF *buf;
|
|
|
|
unsigned int framesize = 0;
|
|
|
|
unsigned long flags;
|
2008-04-28 17:14:02 +08:00
|
|
|
bool return_frame = false;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->rx_frame_count == 0)
|
2008-04-28 17:14:02 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
buf = (RXBUF*)(info->rx_buf + (info->rx_get * info->rx_buf_size));
|
|
|
|
|
|
|
|
status = buf->status;
|
|
|
|
|
|
|
|
/* 07 VFR 1=valid frame
|
|
|
|
* 06 RDO 1=data overrun
|
|
|
|
* 05 CRC 1=OK, 0=error
|
|
|
|
* 04 RAB 1=frame aborted
|
|
|
|
*/
|
|
|
|
if ((status & 0xf0) != 0xA0) {
|
|
|
|
if (!(status & BIT7) || (status & BIT4))
|
|
|
|
info->icount.rxabort++;
|
|
|
|
else if (status & BIT6)
|
|
|
|
info->icount.rxover++;
|
|
|
|
else if (!(status & BIT5)) {
|
|
|
|
info->icount.rxcrc++;
|
|
|
|
if (info->params.crc_type & HDLC_CRC_RETURN_EX)
|
2008-04-28 17:14:02 +08:00
|
|
|
return_frame = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
framesize = 0;
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-07-01 05:26:53 +08:00
|
|
|
info->netdev->stats.rx_errors++;
|
|
|
|
info->netdev->stats.rx_frame_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} else
|
2008-04-28 17:14:02 +08:00
|
|
|
return_frame = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (return_frame)
|
|
|
|
framesize = buf->count;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_BH)
|
|
|
|
printk("%s(%d):rx_get_frame(%s) status=%04X size=%d\n",
|
|
|
|
__FILE__,__LINE__,info->device_name,status,framesize);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (debug_level >= DEBUG_LEVEL_DATA)
|
2007-10-20 03:45:35 +08:00
|
|
|
trace_block(info, buf->data, framesize, 0);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (framesize) {
|
|
|
|
if ((info->params.crc_type & HDLC_CRC_RETURN_EX &&
|
|
|
|
framesize+1 > info->max_frame_size) ||
|
|
|
|
framesize > info->max_frame_size)
|
|
|
|
info->icount.rxlong++;
|
|
|
|
else {
|
|
|
|
if (status & BIT5)
|
|
|
|
info->icount.rxok++;
|
|
|
|
|
|
|
|
if (info->params.crc_type & HDLC_CRC_RETURN_EX) {
|
|
|
|
*(buf->data + framesize) = status & BIT5 ? RX_OK:RX_CRC_ERROR;
|
|
|
|
++framesize;
|
|
|
|
}
|
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->netcount)
|
|
|
|
hdlcdev_rx(info, buf->data, framesize);
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
ldisc_receive_buf(tty, buf->data, info->flag_buf, framesize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
buf->status = buf->count = 0;
|
|
|
|
info->rx_frame_count--;
|
|
|
|
info->rx_get++;
|
|
|
|
if (info->rx_get >= info->rx_buf_count)
|
|
|
|
info->rx_get = 0;
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
static bool register_test(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-10-20 03:45:35 +08:00
|
|
|
static unsigned char patterns[] =
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0x00, 0xff, 0xaa, 0x55, 0x69, 0x96, 0x0f };
|
2006-01-10 12:54:02 +08:00
|
|
|
static unsigned int count = ARRAY_SIZE(patterns);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int i;
|
2008-04-28 17:14:02 +08:00
|
|
|
bool rc = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
reset_device(info);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
write_reg(info, XAD1, patterns[i]);
|
|
|
|
write_reg(info, XAD2, patterns[(i + 1) % count]);
|
2006-01-10 12:54:02 +08:00
|
|
|
if ((read_reg(info, XAD1) != patterns[i]) ||
|
2005-04-17 06:20:36 +08:00
|
|
|
(read_reg(info, XAD2) != patterns[(i + 1) % count])) {
|
2008-04-28 17:14:02 +08:00
|
|
|
rc = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
static bool irq_test(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned long end_time;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
reset_device(info);
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->testing_irq = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
hdlc_mode(info);
|
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->irq_occurred = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* init hdlc mode */
|
|
|
|
|
|
|
|
irq_enable(info, CHA, IRQ_TIMER);
|
|
|
|
write_reg(info, CHA + TIMR, 0); /* 512 cycles */
|
|
|
|
issue_command(info, CHA, CMD_START_TIMER);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
end_time=100;
|
|
|
|
while(end_time-- && !info->irq_occurred) {
|
|
|
|
msleep_interruptible(10);
|
|
|
|
}
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
info->testing_irq = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
reset_device(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2008-04-28 17:14:02 +08:00
|
|
|
return info->irq_occurred;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static int adapter_test(MGSLPC_INFO *info)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
if (!register_test(info)) {
|
|
|
|
info->init_error = DiagStatus_AddressFailure;
|
|
|
|
printk( "%s(%d):Register test failure for device %s Addr=%04X\n",
|
|
|
|
__FILE__,__LINE__,info->device_name, (unsigned short)(info->io_base) );
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!irq_test(info)) {
|
|
|
|
info->init_error = DiagStatus_IrqFailure;
|
|
|
|
printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
|
|
|
|
__FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s(%d):device %s passed diagnostics\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:06:04 +08:00
|
|
|
static void trace_block(MGSLPC_INFO *info,const char* data, int count, int xmit)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int linecount;
|
|
|
|
if (xmit)
|
|
|
|
printk("%s tx data:\n",info->device_name);
|
|
|
|
else
|
|
|
|
printk("%s rx data:\n",info->device_name);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
while(count) {
|
|
|
|
if (count > 16)
|
|
|
|
linecount = 16;
|
|
|
|
else
|
|
|
|
linecount = count;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for(i=0;i<linecount;i++)
|
|
|
|
printk("%02X ",(unsigned char)data[i]);
|
|
|
|
for(;i<17;i++)
|
|
|
|
printk(" ");
|
|
|
|
for(i=0;i<linecount;i++) {
|
|
|
|
if (data[i]>=040 && data[i]<=0176)
|
|
|
|
printk("%c",data[i]);
|
|
|
|
else
|
|
|
|
printk(".");
|
|
|
|
}
|
|
|
|
printk("\n");
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
data += linecount;
|
|
|
|
count -= linecount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* HDLC frame time out
|
|
|
|
* update stats and do tx completion processing
|
|
|
|
*/
|
2006-06-23 17:06:04 +08:00
|
|
|
static void tx_timeout(unsigned long context)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = (MGSLPC_INFO*)context;
|
|
|
|
unsigned long flags;
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if ( debug_level >= DEBUG_LEVEL_INFO )
|
|
|
|
printk( "%s(%d):tx_timeout(%s)\n",
|
|
|
|
__FILE__,__LINE__,info->device_name);
|
|
|
|
if(info->tx_active &&
|
|
|
|
info->params.mode == MGSL_MODE_HDLC) {
|
|
|
|
info->icount.txtimeout++;
|
|
|
|
}
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
2008-04-28 17:14:02 +08:00
|
|
|
info->tx_active = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
info->tx_count = info->tx_put = info->tx_get = 0;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
2007-10-20 03:45:35 +08:00
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
if (info->netcount)
|
|
|
|
hdlcdev_tx_done(info);
|
|
|
|
else
|
|
|
|
#endif
|
2009-01-02 21:48:47 +08:00
|
|
|
{
|
|
|
|
struct tty_struct *tty = tty_port_tty_get(&info->port);
|
|
|
|
bh_transmit(info, tty);
|
|
|
|
tty_kref_put(tty);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-12-07 12:40:24 +08:00
|
|
|
#if SYNCLINK_GENERIC_HDLC
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
|
|
|
|
* set encoding and frame check sequence (FCS) options
|
|
|
|
*
|
|
|
|
* dev pointer to network device structure
|
|
|
|
* encoding serial encoding setting
|
|
|
|
* parity FCS setting
|
|
|
|
*
|
|
|
|
* returns 0 if success, otherwise error code
|
|
|
|
*/
|
|
|
|
static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
|
|
|
|
unsigned short parity)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = dev_to_port(dev);
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_struct *tty;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned char new_encoding;
|
|
|
|
unsigned short new_crctype;
|
|
|
|
|
|
|
|
/* return error if TTY interface open */
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.count)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
switch (encoding)
|
|
|
|
{
|
|
|
|
case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
|
|
|
|
case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
|
|
|
|
case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
|
|
|
|
case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
|
|
|
|
case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
|
|
|
|
default: return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (parity)
|
|
|
|
{
|
|
|
|
case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
|
|
|
|
case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
|
|
|
|
case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
|
|
|
|
default: return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->params.encoding = new_encoding;
|
2006-03-24 19:16:13 +08:00
|
|
|
info->params.crc_type = new_crctype;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* if network interface up, reprogram hardware */
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->netcount) {
|
|
|
|
tty = tty_port_tty_get(&info->port);
|
|
|
|
mgslpc_program_hw(info, tty);
|
|
|
|
tty_kref_put(tty);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by generic HDLC layer to send frame
|
|
|
|
*
|
|
|
|
* skb socket buffer containing HDLC frame
|
|
|
|
* dev pointer to network device structure
|
|
|
|
*/
|
2009-09-01 03:50:48 +08:00
|
|
|
static netdev_tx_t hdlcdev_xmit(struct sk_buff *skb,
|
|
|
|
struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = dev_to_port(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk(KERN_INFO "%s:hdlc_xmit(%s)\n",__FILE__,dev->name);
|
|
|
|
|
|
|
|
/* stop sending until this frame completes */
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
/* copy data to device buffers */
|
2007-03-28 05:55:52 +08:00
|
|
|
skb_copy_from_linear_data(skb, info->tx_buf, skb->len);
|
2005-04-17 06:20:36 +08:00
|
|
|
info->tx_get = 0;
|
|
|
|
info->tx_put = info->tx_count = skb->len;
|
|
|
|
|
|
|
|
/* update network statistics */
|
2008-07-01 05:26:53 +08:00
|
|
|
dev->stats.tx_packets++;
|
|
|
|
dev->stats.tx_bytes += skb->len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* done with socket buffer, so free it */
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
|
|
|
|
/* save start time for transmit timeout detection */
|
|
|
|
dev->trans_start = jiffies;
|
|
|
|
|
|
|
|
/* start hardware transmitter if necessary */
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
2009-01-02 21:48:47 +08:00
|
|
|
if (!info->tx_active) {
|
|
|
|
struct tty_struct *tty = tty_port_tty_get(&info->port);
|
|
|
|
tx_start(info, tty);
|
|
|
|
tty_kref_put(tty);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
2009-09-01 03:50:48 +08:00
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by network layer when interface enabled
|
|
|
|
* claim resources and initialize hardware
|
|
|
|
*
|
|
|
|
* dev pointer to network device structure
|
|
|
|
*
|
|
|
|
* returns 0 if success, otherwise error code
|
|
|
|
*/
|
|
|
|
static int hdlcdev_open(struct net_device *dev)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = dev_to_port(dev);
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_struct *tty;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s:hdlcdev_open(%s)\n",__FILE__,dev->name);
|
|
|
|
|
|
|
|
/* generic HDLC layer open processing */
|
|
|
|
if ((rc = hdlc_open(dev)))
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* arbitrate between network and tty opens */
|
|
|
|
spin_lock_irqsave(&info->netlock, flags);
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.count != 0 || info->netcount != 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
|
|
|
|
spin_unlock_irqrestore(&info->netlock, flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
info->netcount=1;
|
|
|
|
spin_unlock_irqrestore(&info->netlock, flags);
|
|
|
|
|
2009-01-02 21:48:47 +08:00
|
|
|
tty = tty_port_tty_get(&info->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* claim resources and init adapter */
|
2009-01-02 21:48:47 +08:00
|
|
|
if ((rc = startup(info, tty)) != 0) {
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&info->netlock, flags);
|
|
|
|
info->netcount=0;
|
|
|
|
spin_unlock_irqrestore(&info->netlock, flags);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
/* assert DTR and RTS, apply hardware settings */
|
|
|
|
info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
|
2009-01-02 21:48:47 +08:00
|
|
|
mgslpc_program_hw(info, tty);
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* enable network layer transmit */
|
|
|
|
dev->trans_start = jiffies;
|
|
|
|
netif_start_queue(dev);
|
|
|
|
|
|
|
|
/* inform generic HDLC layer of current DCD status */
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
get_signals(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
2006-07-22 05:44:55 +08:00
|
|
|
if (info->serial_signals & SerialSignal_DCD)
|
|
|
|
netif_carrier_on(dev);
|
|
|
|
else
|
|
|
|
netif_carrier_off(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by network layer when interface is disabled
|
|
|
|
* shutdown hardware and release resources
|
|
|
|
*
|
|
|
|
* dev pointer to network device structure
|
|
|
|
*
|
|
|
|
* returns 0 if success, otherwise error code
|
|
|
|
*/
|
|
|
|
static int hdlcdev_close(struct net_device *dev)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = dev_to_port(dev);
|
2009-01-02 21:48:47 +08:00
|
|
|
struct tty_struct *tty = tty_port_tty_get(&info->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s:hdlcdev_close(%s)\n",__FILE__,dev->name);
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
/* shutdown adapter and release resources */
|
2009-01-02 21:48:47 +08:00
|
|
|
shutdown(info, tty);
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
hdlc_close(dev);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->netlock, flags);
|
|
|
|
info->netcount=0;
|
|
|
|
spin_unlock_irqrestore(&info->netlock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by network layer to process IOCTL call to network device
|
|
|
|
*
|
|
|
|
* dev pointer to network device structure
|
|
|
|
* ifr pointer to network interface request structure
|
|
|
|
* cmd IOCTL command code
|
|
|
|
*
|
|
|
|
* returns 0 if success, otherwise error code
|
|
|
|
*/
|
|
|
|
static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
|
|
|
|
{
|
|
|
|
const size_t size = sizeof(sync_serial_settings);
|
|
|
|
sync_serial_settings new_line;
|
|
|
|
sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
|
|
|
|
MGSLPC_INFO *info = dev_to_port(dev);
|
|
|
|
unsigned int flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
|
|
|
|
|
|
|
|
/* return error if TTY interface open */
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->port.count)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
if (cmd != SIOCWANDEV)
|
|
|
|
return hdlc_ioctl(dev, ifr, cmd);
|
|
|
|
|
|
|
|
switch(ifr->ifr_settings.type) {
|
|
|
|
case IF_GET_IFACE: /* return current sync_serial_settings */
|
|
|
|
|
|
|
|
ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL;
|
|
|
|
if (ifr->ifr_settings.size < size) {
|
|
|
|
ifr->ifr_settings.size = size; /* data size wanted */
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
|
|
|
|
flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
|
|
|
|
HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
|
|
|
|
HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
|
|
|
|
HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
|
|
|
|
|
|
|
|
switch (flags){
|
|
|
|
case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
|
|
|
|
case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
|
|
|
|
case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
|
|
|
|
case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
|
|
|
|
default: new_line.clock_type = CLOCK_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
new_line.clock_rate = info->params.clock_speed;
|
|
|
|
new_line.loopback = info->params.loopback ? 1:0;
|
|
|
|
|
|
|
|
if (copy_to_user(line, &new_line, size))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
|
|
|
|
|
|
|
|
if(!capable(CAP_NET_ADMIN))
|
|
|
|
return -EPERM;
|
|
|
|
if (copy_from_user(&new_line, line, size))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
switch (new_line.clock_type)
|
|
|
|
{
|
|
|
|
case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
|
|
|
|
case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
|
|
|
|
case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
|
|
|
|
case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
|
|
|
|
case CLOCK_DEFAULT: flags = info->params.flags &
|
|
|
|
(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
|
|
|
|
HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
|
|
|
|
HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
|
|
|
|
HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
|
|
|
|
default: return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_line.loopback != 0 && new_line.loopback != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
|
|
|
|
HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
|
|
|
|
HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
|
|
|
|
HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
|
|
|
|
info->params.flags |= flags;
|
|
|
|
|
|
|
|
info->params.loopback = new_line.loopback;
|
|
|
|
|
|
|
|
if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
|
|
|
|
info->params.clock_speed = new_line.clock_rate;
|
|
|
|
else
|
|
|
|
info->params.clock_speed = 0;
|
|
|
|
|
|
|
|
/* if network interface up, reprogram hardware */
|
2009-01-02 21:48:47 +08:00
|
|
|
if (info->netcount) {
|
|
|
|
struct tty_struct *tty = tty_port_tty_get(&info->port);
|
|
|
|
mgslpc_program_hw(info, tty);
|
|
|
|
tty_kref_put(tty);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return hdlc_ioctl(dev, ifr, cmd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by network layer when transmit timeout is detected
|
|
|
|
*
|
|
|
|
* dev pointer to network device structure
|
|
|
|
*/
|
|
|
|
static void hdlcdev_tx_timeout(struct net_device *dev)
|
|
|
|
{
|
|
|
|
MGSLPC_INFO *info = dev_to_port(dev);
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("hdlcdev_tx_timeout(%s)\n",dev->name);
|
|
|
|
|
2008-07-01 05:26:53 +08:00
|
|
|
dev->stats.tx_errors++;
|
|
|
|
dev->stats.tx_aborted_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock,flags);
|
|
|
|
tx_stop(info);
|
|
|
|
spin_unlock_irqrestore(&info->lock,flags);
|
|
|
|
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by device driver when transmit completes
|
|
|
|
* reenable network layer transmit if stopped
|
|
|
|
*
|
|
|
|
* info pointer to device instance information
|
|
|
|
*/
|
|
|
|
static void hdlcdev_tx_done(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
if (netif_queue_stopped(info->netdev))
|
|
|
|
netif_wake_queue(info->netdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by device driver when frame received
|
|
|
|
* pass frame to network layer
|
|
|
|
*
|
|
|
|
* info pointer to device instance information
|
|
|
|
* buf pointer to buffer contianing frame data
|
|
|
|
* size count of data bytes in buf
|
|
|
|
*/
|
|
|
|
static void hdlcdev_rx(MGSLPC_INFO *info, char *buf, int size)
|
|
|
|
{
|
|
|
|
struct sk_buff *skb = dev_alloc_skb(size);
|
|
|
|
struct net_device *dev = info->netdev;
|
|
|
|
|
|
|
|
if (debug_level >= DEBUG_LEVEL_INFO)
|
|
|
|
printk("hdlcdev_rx(%s)\n",dev->name);
|
|
|
|
|
|
|
|
if (skb == NULL) {
|
|
|
|
printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n", dev->name);
|
2008-07-01 05:26:53 +08:00
|
|
|
dev->stats.rx_dropped++;
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-01 05:26:53 +08:00
|
|
|
memcpy(skb_put(skb, size), buf, size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-01 05:26:53 +08:00
|
|
|
skb->protocol = hdlc_type_trans(skb, dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-01 05:26:53 +08:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
netif_rx(skb);
|
|
|
|
}
|
|
|
|
|
2009-01-09 05:52:11 +08:00
|
|
|
static const struct net_device_ops hdlcdev_ops = {
|
|
|
|
.ndo_open = hdlcdev_open,
|
|
|
|
.ndo_stop = hdlcdev_close,
|
|
|
|
.ndo_change_mtu = hdlc_change_mtu,
|
|
|
|
.ndo_start_xmit = hdlc_start_xmit,
|
|
|
|
.ndo_do_ioctl = hdlcdev_ioctl,
|
|
|
|
.ndo_tx_timeout = hdlcdev_tx_timeout,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/**
|
|
|
|
* called by device driver when adding device instance
|
|
|
|
* do generic HDLC initialization
|
|
|
|
*
|
|
|
|
* info pointer to device instance information
|
|
|
|
*
|
|
|
|
* returns 0 if success, otherwise error code
|
|
|
|
*/
|
|
|
|
static int hdlcdev_init(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct net_device *dev;
|
|
|
|
hdlc_device *hdlc;
|
|
|
|
|
|
|
|
/* allocate and initialize network and HDLC layer objects */
|
|
|
|
|
|
|
|
if (!(dev = alloc_hdlcdev(info))) {
|
|
|
|
printk(KERN_ERR "%s:hdlc device allocation failure\n",__FILE__);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for network layer reporting purposes only */
|
|
|
|
dev->base_addr = info->io_base;
|
|
|
|
dev->irq = info->irq_level;
|
|
|
|
|
|
|
|
/* network layer callbacks and settings */
|
2009-01-09 05:52:11 +08:00
|
|
|
dev->netdev_ops = &hdlcdev_ops;
|
|
|
|
dev->watchdog_timeo = 10 * HZ;
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->tx_queue_len = 50;
|
|
|
|
|
|
|
|
/* generic HDLC layer callbacks and settings */
|
|
|
|
hdlc = dev_to_hdlc(dev);
|
|
|
|
hdlc->attach = hdlcdev_attach;
|
|
|
|
hdlc->xmit = hdlcdev_xmit;
|
|
|
|
|
|
|
|
/* register objects with HDLC layer */
|
|
|
|
if ((rc = register_hdlc_device(dev))) {
|
|
|
|
printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
|
|
|
|
free_netdev(dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
info->netdev = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by device driver when removing device instance
|
|
|
|
* do generic HDLC cleanup
|
|
|
|
*
|
|
|
|
* info pointer to device instance information
|
|
|
|
*/
|
|
|
|
static void hdlcdev_exit(MGSLPC_INFO *info)
|
|
|
|
{
|
|
|
|
unregister_hdlc_device(info->netdev);
|
|
|
|
free_netdev(info->netdev);
|
|
|
|
info->netdev = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_HDLC */
|
|
|
|
|