2017-11-07 01:11:51 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* moxa.c -- MOXA Intellio family multiport serial driver.
|
|
|
|
*
|
2008-04-30 15:53:48 +08:00
|
|
|
* Copyright (C) 1999-2000 Moxa Technologies (support@moxa.com).
|
|
|
|
* Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* This code is loosely based on the Linux serial driver, written by
|
|
|
|
* Linus Torvalds, Theodore T'so and others.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MOXA Intellio Series Driver
|
|
|
|
* for : LINUX
|
|
|
|
* date : 1999/1/7
|
|
|
|
* version : 5.1
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/errno.h>
|
2008-04-30 15:53:39 +08:00
|
|
|
#include <linux/firmware.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/signal.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/major.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/fcntl.h>
|
|
|
|
#include <linux/ptrace.h>
|
|
|
|
#include <linux/serial.h>
|
|
|
|
#include <linux/tty_driver.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/bitops.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-06-16 20:07:22 +08:00
|
|
|
#include <linux/ratelimit.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-09-14 17:08:23 +08:00
|
|
|
#define MOXA 0x400
|
|
|
|
#define MOXA_GET_IQUEUE (MOXA + 1) /* get input buffered count */
|
|
|
|
#define MOXA_GET_OQUEUE (MOXA + 2) /* get output buffered count */
|
|
|
|
#define MOXA_GETDATACOUNT (MOXA + 23)
|
|
|
|
#define MOXA_GET_IOQUEUE (MOXA + 27)
|
|
|
|
#define MOXA_FLUSH_QUEUE (MOXA + 28)
|
|
|
|
#define MOXA_GETMSTATUS (MOXA + 65)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System Configuration
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define Magic_code 0x404
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for C218 BIOS initialization
|
|
|
|
*/
|
|
|
|
#define C218_ConfBase 0x800
|
|
|
|
#define C218_status (C218_ConfBase + 0) /* BIOS running status */
|
|
|
|
#define C218_diag (C218_ConfBase + 2) /* diagnostic status */
|
|
|
|
#define C218_key (C218_ConfBase + 4) /* WORD (0x218 for C218) */
|
|
|
|
#define C218DLoad_len (C218_ConfBase + 6) /* WORD */
|
|
|
|
#define C218check_sum (C218_ConfBase + 8) /* BYTE */
|
|
|
|
#define C218chksum_ok (C218_ConfBase + 0x0a) /* BYTE (1:ok) */
|
|
|
|
#define C218_TestRx (C218_ConfBase + 0x10) /* 8 bytes for 8 ports */
|
|
|
|
#define C218_TestTx (C218_ConfBase + 0x18) /* 8 bytes for 8 ports */
|
|
|
|
#define C218_RXerr (C218_ConfBase + 0x20) /* 8 bytes for 8 ports */
|
|
|
|
#define C218_ErrFlag (C218_ConfBase + 0x28) /* 8 bytes for 8 ports */
|
|
|
|
|
|
|
|
#define C218_LoadBuf 0x0F00
|
|
|
|
#define C218_KeyCode 0x218
|
|
|
|
#define CP204J_KeyCode 0x204
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for C320 BIOS initialization
|
|
|
|
*/
|
|
|
|
#define C320_ConfBase 0x800
|
|
|
|
#define C320_LoadBuf 0x0f00
|
|
|
|
#define STS_init 0x05 /* for C320_status */
|
|
|
|
|
|
|
|
#define C320_status C320_ConfBase + 0 /* BIOS running status */
|
|
|
|
#define C320_diag C320_ConfBase + 2 /* diagnostic status */
|
|
|
|
#define C320_key C320_ConfBase + 4 /* WORD (0320H for C320) */
|
|
|
|
#define C320DLoad_len C320_ConfBase + 6 /* WORD */
|
|
|
|
#define C320check_sum C320_ConfBase + 8 /* WORD */
|
|
|
|
#define C320chksum_ok C320_ConfBase + 0x0a /* WORD (1:ok) */
|
|
|
|
#define C320bapi_len C320_ConfBase + 0x0c /* WORD */
|
|
|
|
#define C320UART_no C320_ConfBase + 0x0e /* WORD */
|
|
|
|
|
|
|
|
#define C320_KeyCode 0x320
|
|
|
|
|
|
|
|
#define FixPage_addr 0x0000 /* starting addr of static page */
|
|
|
|
#define DynPage_addr 0x2000 /* starting addr of dynamic page */
|
|
|
|
#define C218_start 0x3000 /* starting addr of C218 BIOS prg */
|
|
|
|
#define Control_reg 0x1ff0 /* select page and reset control */
|
|
|
|
#define HW_reset 0x80
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function Codes
|
|
|
|
*/
|
|
|
|
#define FC_CardReset 0x80
|
|
|
|
#define FC_ChannelReset 1 /* C320 firmware not supported */
|
|
|
|
#define FC_EnableCH 2
|
|
|
|
#define FC_DisableCH 3
|
|
|
|
#define FC_SetParam 4
|
|
|
|
#define FC_SetMode 5
|
|
|
|
#define FC_SetRate 6
|
|
|
|
#define FC_LineControl 7
|
|
|
|
#define FC_LineStatus 8
|
|
|
|
#define FC_XmitControl 9
|
|
|
|
#define FC_FlushQueue 10
|
|
|
|
#define FC_SendBreak 11
|
|
|
|
#define FC_StopBreak 12
|
|
|
|
#define FC_LoopbackON 13
|
|
|
|
#define FC_LoopbackOFF 14
|
|
|
|
#define FC_ClrIrqTable 15
|
|
|
|
#define FC_SendXon 16
|
|
|
|
#define FC_SetTermIrq 17 /* C320 firmware not supported */
|
|
|
|
#define FC_SetCntIrq 18 /* C320 firmware not supported */
|
|
|
|
#define FC_SetBreakIrq 19
|
|
|
|
#define FC_SetLineIrq 20
|
|
|
|
#define FC_SetFlowCtl 21
|
|
|
|
#define FC_GenIrq 22
|
|
|
|
#define FC_InCD180 23
|
|
|
|
#define FC_OutCD180 24
|
|
|
|
#define FC_InUARTreg 23
|
|
|
|
#define FC_OutUARTreg 24
|
|
|
|
#define FC_SetXonXoff 25
|
|
|
|
#define FC_OutCD180CCR 26
|
|
|
|
#define FC_ExtIQueue 27
|
|
|
|
#define FC_ExtOQueue 28
|
|
|
|
#define FC_ClrLineIrq 29
|
|
|
|
#define FC_HWFlowCtl 30
|
|
|
|
#define FC_GetClockRate 35
|
|
|
|
#define FC_SetBaud 36
|
|
|
|
#define FC_SetDataMode 41
|
|
|
|
#define FC_GetCCSR 43
|
|
|
|
#define FC_GetDataError 45
|
|
|
|
#define FC_RxControl 50
|
|
|
|
#define FC_ImmSend 51
|
|
|
|
#define FC_SetXonState 52
|
|
|
|
#define FC_SetXoffState 53
|
|
|
|
#define FC_SetRxFIFOTrig 54
|
|
|
|
#define FC_SetTxFIFOCnt 55
|
|
|
|
#define FC_UnixRate 56
|
|
|
|
#define FC_UnixResetTimer 57
|
|
|
|
|
|
|
|
#define RxFIFOTrig1 0
|
|
|
|
#define RxFIFOTrig4 1
|
|
|
|
#define RxFIFOTrig8 2
|
|
|
|
#define RxFIFOTrig14 3
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dual-Ported RAM
|
|
|
|
*/
|
|
|
|
#define DRAM_global 0
|
|
|
|
#define INT_data (DRAM_global + 0)
|
|
|
|
#define Config_base (DRAM_global + 0x108)
|
|
|
|
|
|
|
|
#define IRQindex (INT_data + 0)
|
|
|
|
#define IRQpending (INT_data + 4)
|
|
|
|
#define IRQtable (INT_data + 8)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupt Status
|
|
|
|
*/
|
|
|
|
#define IntrRx 0x01 /* receiver data O.K. */
|
|
|
|
#define IntrTx 0x02 /* transmit buffer empty */
|
|
|
|
#define IntrFunc 0x04 /* function complete */
|
|
|
|
#define IntrBreak 0x08 /* received break */
|
|
|
|
#define IntrLine 0x10 /* line status change
|
|
|
|
for transmitter */
|
|
|
|
#define IntrIntr 0x20 /* received INTR code */
|
|
|
|
#define IntrQuit 0x40 /* received QUIT code */
|
|
|
|
#define IntrEOF 0x80 /* received EOF code */
|
|
|
|
|
|
|
|
#define IntrRxTrigger 0x100 /* rx data count reach trigger value */
|
|
|
|
#define IntrTxTrigger 0x200 /* tx data count below trigger value */
|
|
|
|
|
|
|
|
#define Magic_no (Config_base + 0)
|
|
|
|
#define Card_model_no (Config_base + 2)
|
|
|
|
#define Total_ports (Config_base + 4)
|
|
|
|
#define Module_cnt (Config_base + 8)
|
|
|
|
#define Module_no (Config_base + 10)
|
|
|
|
#define Timer_10ms (Config_base + 14)
|
|
|
|
#define Disable_IRQ (Config_base + 20)
|
|
|
|
#define TMS320_PORT1 (Config_base + 22)
|
|
|
|
#define TMS320_PORT2 (Config_base + 24)
|
|
|
|
#define TMS320_CLOCK (Config_base + 26)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DATA BUFFER in DRAM
|
|
|
|
*/
|
|
|
|
#define Extern_table 0x400 /* Base address of the external table
|
|
|
|
(24 words * 64) total 3K bytes
|
|
|
|
(24 words * 128) total 6K bytes */
|
|
|
|
#define Extern_size 0x60 /* 96 bytes */
|
|
|
|
#define RXrptr 0x00 /* read pointer for RX buffer */
|
|
|
|
#define RXwptr 0x02 /* write pointer for RX buffer */
|
|
|
|
#define TXrptr 0x04 /* read pointer for TX buffer */
|
|
|
|
#define TXwptr 0x06 /* write pointer for TX buffer */
|
|
|
|
#define HostStat 0x08 /* IRQ flag and general flag */
|
|
|
|
#define FlagStat 0x0A
|
|
|
|
#define FlowControl 0x0C /* B7 B6 B5 B4 B3 B2 B1 B0 */
|
|
|
|
/* x x x x | | | | */
|
|
|
|
/* | | | + CTS flow */
|
|
|
|
/* | | +--- RTS flow */
|
|
|
|
/* | +------ TX Xon/Xoff */
|
|
|
|
/* +--------- RX Xon/Xoff */
|
|
|
|
#define Break_cnt 0x0E /* received break count */
|
|
|
|
#define CD180TXirq 0x10 /* if non-0: enable TX irq */
|
|
|
|
#define RX_mask 0x12
|
|
|
|
#define TX_mask 0x14
|
|
|
|
#define Ofs_rxb 0x16
|
|
|
|
#define Ofs_txb 0x18
|
|
|
|
#define Page_rxb 0x1A
|
|
|
|
#define Page_txb 0x1C
|
|
|
|
#define EndPage_rxb 0x1E
|
|
|
|
#define EndPage_txb 0x20
|
|
|
|
#define Data_error 0x22
|
|
|
|
#define RxTrigger 0x28
|
|
|
|
#define TxTrigger 0x2a
|
|
|
|
|
|
|
|
#define rRXwptr 0x34
|
|
|
|
#define Low_water 0x36
|
|
|
|
|
|
|
|
#define FuncCode 0x40
|
|
|
|
#define FuncArg 0x42
|
|
|
|
#define FuncArg1 0x44
|
|
|
|
|
|
|
|
#define C218rx_size 0x2000 /* 8K bytes */
|
|
|
|
#define C218tx_size 0x8000 /* 32K bytes */
|
|
|
|
|
|
|
|
#define C218rx_mask (C218rx_size - 1)
|
|
|
|
#define C218tx_mask (C218tx_size - 1)
|
|
|
|
|
|
|
|
#define C320p8rx_size 0x2000
|
|
|
|
#define C320p8tx_size 0x8000
|
|
|
|
#define C320p8rx_mask (C320p8rx_size - 1)
|
|
|
|
#define C320p8tx_mask (C320p8tx_size - 1)
|
|
|
|
|
|
|
|
#define C320p16rx_size 0x2000
|
|
|
|
#define C320p16tx_size 0x4000
|
|
|
|
#define C320p16rx_mask (C320p16rx_size - 1)
|
|
|
|
#define C320p16tx_mask (C320p16tx_size - 1)
|
|
|
|
|
|
|
|
#define C320p24rx_size 0x2000
|
|
|
|
#define C320p24tx_size 0x2000
|
|
|
|
#define C320p24rx_mask (C320p24rx_size - 1)
|
|
|
|
#define C320p24tx_mask (C320p24tx_size - 1)
|
|
|
|
|
|
|
|
#define C320p32rx_size 0x1000
|
|
|
|
#define C320p32tx_size 0x1000
|
|
|
|
#define C320p32rx_mask (C320p32rx_size - 1)
|
|
|
|
#define C320p32tx_mask (C320p32tx_size - 1)
|
|
|
|
|
|
|
|
#define Page_size 0x2000U
|
|
|
|
#define Page_mask (Page_size - 1)
|
|
|
|
#define C218rx_spage 3
|
|
|
|
#define C218tx_spage 4
|
|
|
|
#define C218rx_pageno 1
|
|
|
|
#define C218tx_pageno 4
|
|
|
|
#define C218buf_pageno 5
|
|
|
|
|
|
|
|
#define C320p8rx_spage 3
|
|
|
|
#define C320p8tx_spage 4
|
|
|
|
#define C320p8rx_pgno 1
|
|
|
|
#define C320p8tx_pgno 4
|
|
|
|
#define C320p8buf_pgno 5
|
|
|
|
|
|
|
|
#define C320p16rx_spage 3
|
|
|
|
#define C320p16tx_spage 4
|
|
|
|
#define C320p16rx_pgno 1
|
|
|
|
#define C320p16tx_pgno 2
|
|
|
|
#define C320p16buf_pgno 3
|
|
|
|
|
|
|
|
#define C320p24rx_spage 3
|
|
|
|
#define C320p24tx_spage 4
|
|
|
|
#define C320p24rx_pgno 1
|
|
|
|
#define C320p24tx_pgno 1
|
|
|
|
#define C320p24buf_pgno 2
|
|
|
|
|
|
|
|
#define C320p32rx_spage 3
|
|
|
|
#define C320p32tx_ofs C320p32rx_size
|
|
|
|
#define C320p32tx_spage 3
|
|
|
|
#define C320p32buf_pgno 1
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Host Status
|
|
|
|
*/
|
|
|
|
#define WakeupRx 0x01
|
|
|
|
#define WakeupTx 0x02
|
|
|
|
#define WakeupBreak 0x08
|
|
|
|
#define WakeupLine 0x10
|
|
|
|
#define WakeupIntr 0x20
|
|
|
|
#define WakeupQuit 0x40
|
|
|
|
#define WakeupEOF 0x80 /* used in VTIME control */
|
|
|
|
#define WakeupRxTrigger 0x100
|
|
|
|
#define WakeupTxTrigger 0x200
|
|
|
|
/*
|
|
|
|
* Flag status
|
|
|
|
*/
|
|
|
|
#define Rx_over 0x01
|
|
|
|
#define Xoff_state 0x02
|
|
|
|
#define Tx_flowOff 0x04
|
|
|
|
#define Tx_enable 0x08
|
|
|
|
#define CTS_state 0x10
|
|
|
|
#define DSR_state 0x20
|
|
|
|
#define DCD_state 0x80
|
|
|
|
/*
|
|
|
|
* FlowControl
|
|
|
|
*/
|
|
|
|
#define CTS_FlowCtl 1
|
|
|
|
#define RTS_FlowCtl 2
|
|
|
|
#define Tx_FlowCtl 4
|
|
|
|
#define Rx_FlowCtl 8
|
|
|
|
#define IXM_IXANY 0x10
|
|
|
|
|
|
|
|
#define LowWater 128
|
|
|
|
|
|
|
|
#define DTR_ON 1
|
|
|
|
#define RTS_ON 2
|
|
|
|
#define CTS_ON 1
|
|
|
|
#define DSR_ON 2
|
|
|
|
#define DCD_ON 8
|
|
|
|
|
|
|
|
/* mode definition */
|
|
|
|
#define MX_CS8 0x03
|
|
|
|
#define MX_CS7 0x02
|
|
|
|
#define MX_CS6 0x01
|
|
|
|
#define MX_CS5 0x00
|
|
|
|
|
|
|
|
#define MX_STOP1 0x00
|
|
|
|
#define MX_STOP15 0x04
|
|
|
|
#define MX_STOP2 0x08
|
|
|
|
|
|
|
|
#define MX_PARNONE 0x00
|
|
|
|
#define MX_PAREVEN 0x40
|
|
|
|
#define MX_PARODD 0xC0
|
|
|
|
#define MX_PARMARK 0xA0
|
|
|
|
#define MX_PARSPACE 0x20
|
2008-04-30 15:53:39 +08:00
|
|
|
|
2008-04-30 15:53:48 +08:00
|
|
|
#define MOXA_VERSION "6.0k"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
#define MOXA_FW_HDRLEN 32
|
|
|
|
|
2007-02-10 17:45:31 +08:00
|
|
|
#define MOXAMAJOR 172
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:45:31 +08:00
|
|
|
#define MAX_BOARDS 4 /* Don't change this value */
|
2005-04-17 06:20:36 +08:00
|
|
|
#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
|
2007-02-10 17:45:31 +08:00
|
|
|
#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:47 +08:00
|
|
|
#define MOXA_IS_320(brd) ((brd)->boardType == MOXA_BOARD_C320_ISA || \
|
|
|
|
(brd)->boardType == MOXA_BOARD_C320_PCI)
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Define the Moxa PCI vendor and device IDs.
|
|
|
|
*/
|
2007-02-10 17:45:31 +08:00
|
|
|
#define MOXA_BUS_TYPE_ISA 0
|
|
|
|
#define MOXA_BUS_TYPE_PCI 1
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
MOXA_BOARD_C218_PCI = 1,
|
|
|
|
MOXA_BOARD_C218_ISA,
|
|
|
|
MOXA_BOARD_C320_PCI,
|
|
|
|
MOXA_BOARD_C320_ISA,
|
|
|
|
MOXA_BOARD_CP204J,
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *moxa_brdname[] =
|
|
|
|
{
|
|
|
|
"C218 Turbo PCI series",
|
|
|
|
"C218 Turbo ISA series",
|
|
|
|
"C320 Turbo PCI series",
|
|
|
|
"C320 Turbo ISA series",
|
|
|
|
"CP-204J series",
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_PCI
|
2017-07-23 18:01:05 +08:00
|
|
|
static const struct pci_device_id moxa_pcibrds[] = {
|
2007-02-10 17:45:30 +08:00
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218),
|
|
|
|
.driver_data = MOXA_BOARD_C218_PCI },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C320),
|
|
|
|
.driver_data = MOXA_BOARD_C320_PCI },
|
|
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP204J),
|
|
|
|
.driver_data = MOXA_BOARD_CP204J },
|
2005-04-17 06:20:36 +08:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
|
|
|
|
#endif /* CONFIG_PCI */
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
struct moxa_port;
|
|
|
|
|
2007-02-10 17:45:33 +08:00
|
|
|
static struct moxa_board_conf {
|
2005-04-17 06:20:36 +08:00
|
|
|
int boardType;
|
|
|
|
int numPorts;
|
|
|
|
int busType;
|
2007-02-10 17:45:33 +08:00
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
unsigned int ready;
|
2007-02-10 17:45:33 +08:00
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
struct moxa_port *ports;
|
|
|
|
|
2007-02-10 17:45:33 +08:00
|
|
|
void __iomem *basemem;
|
|
|
|
void __iomem *intNdx;
|
|
|
|
void __iomem *intPend;
|
|
|
|
void __iomem *intTable;
|
|
|
|
} moxa_boards[MAX_BOARDS];
|
|
|
|
|
|
|
|
struct mxser_mstatus {
|
|
|
|
tcflag_t cflag;
|
|
|
|
int cts;
|
|
|
|
int dsr;
|
|
|
|
int ri;
|
|
|
|
int dcd;
|
2007-02-10 17:45:30 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:45:33 +08:00
|
|
|
struct moxaq_str {
|
|
|
|
int inq;
|
|
|
|
int outq;
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:45:33 +08:00
|
|
|
struct moxa_port {
|
2008-07-17 04:56:02 +08:00
|
|
|
struct tty_port port;
|
2008-04-30 15:53:40 +08:00
|
|
|
struct moxa_board_conf *board;
|
2008-04-30 15:53:43 +08:00
|
|
|
void __iomem *tableAddr;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int type;
|
|
|
|
int cflag;
|
2008-04-30 15:53:43 +08:00
|
|
|
unsigned long statusflags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-30 21:18:13 +08:00
|
|
|
u8 DCDState; /* Protected by the port lock */
|
2008-04-30 15:53:43 +08:00
|
|
|
u8 lineCtrl;
|
|
|
|
u8 lowChkFlag;
|
2007-02-10 17:45:33 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
struct mon_str {
|
|
|
|
int tick;
|
|
|
|
int rxcnt[MAX_PORTS];
|
|
|
|
int txcnt[MAX_PORTS];
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* statusflags */
|
2009-11-30 21:18:02 +08:00
|
|
|
#define TXSTOPPED 1
|
|
|
|
#define LOWWAIT 2
|
|
|
|
#define EMPTYWAIT 3
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
#define WAKEUP_CHARS 256
|
|
|
|
|
|
|
|
static int ttymajor = MOXAMAJOR;
|
2008-04-30 15:53:43 +08:00
|
|
|
static struct mon_str moxaLog;
|
|
|
|
static unsigned int moxaFuncTout = HZ / 2;
|
2008-04-30 15:53:43 +08:00
|
|
|
static unsigned int moxaLowWaterChk;
|
2008-04-30 15:53:45 +08:00
|
|
|
static DEFINE_MUTEX(moxa_openlock);
|
2009-11-30 21:18:24 +08:00
|
|
|
static DEFINE_SPINLOCK(moxa_lock);
|
2009-12-10 04:34:18 +08:00
|
|
|
|
2008-04-30 15:53:37 +08:00
|
|
|
static unsigned long baseaddr[MAX_BOARDS];
|
|
|
|
static unsigned int type[MAX_BOARDS];
|
|
|
|
static unsigned int numports[MAX_BOARDS];
|
2012-08-08 03:47:55 +08:00
|
|
|
static struct tty_port moxa_service_port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("William Chen");
|
|
|
|
MODULE_DESCRIPTION("MOXA Intellio Family Multiport Board Device Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2010-01-14 07:34:18 +08:00
|
|
|
MODULE_FIRMWARE("c218tunx.cod");
|
|
|
|
MODULE_FIRMWARE("cp204unx.cod");
|
|
|
|
MODULE_FIRMWARE("c320tunx.cod");
|
2009-12-10 04:34:18 +08:00
|
|
|
|
2008-04-30 15:53:37 +08:00
|
|
|
module_param_array(type, uint, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(type, "card type: C218=2, C320=4");
|
2017-04-04 23:54:29 +08:00
|
|
|
module_param_hw_array(baseaddr, ulong, ioport, NULL, 0);
|
2008-04-30 15:53:37 +08:00
|
|
|
MODULE_PARM_DESC(baseaddr, "base address");
|
|
|
|
module_param_array(numports, uint, NULL, 0);
|
|
|
|
MODULE_PARM_DESC(numports, "numports (ignored for C218)");
|
2009-12-10 04:34:18 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
module_param(ttymajor, int, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* static functions:
|
|
|
|
*/
|
|
|
|
static int moxa_open(struct tty_struct *, struct file *);
|
|
|
|
static void moxa_close(struct tty_struct *, struct file *);
|
2023-08-10 17:15:03 +08:00
|
|
|
static ssize_t moxa_write(struct tty_struct *, const u8 *, size_t);
|
2021-05-05 17:19:15 +08:00
|
|
|
static unsigned int moxa_write_room(struct tty_struct *);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void moxa_flush_buffer(struct tty_struct *);
|
2021-05-05 17:19:19 +08:00
|
|
|
static unsigned int moxa_chars_in_buffer(struct tty_struct *);
|
2022-08-16 19:57:39 +08:00
|
|
|
static void moxa_set_termios(struct tty_struct *, const struct ktermios *);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void moxa_stop(struct tty_struct *);
|
|
|
|
static void moxa_start(struct tty_struct *);
|
|
|
|
static void moxa_hangup(struct tty_struct *);
|
2011-02-15 00:26:14 +08:00
|
|
|
static int moxa_tiocmget(struct tty_struct *tty);
|
2011-02-15 00:26:50 +08:00
|
|
|
static int moxa_tiocmset(struct tty_struct *tty,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int set, unsigned int clear);
|
2017-08-29 02:28:21 +08:00
|
|
|
static void moxa_poll(struct timer_list *);
|
2022-08-16 19:57:39 +08:00
|
|
|
static void moxa_set_tty_param(struct tty_struct *, const struct ktermios *);
|
2009-11-30 21:17:51 +08:00
|
|
|
static void moxa_shutdown(struct tty_port *);
|
2023-01-17 17:03:52 +08:00
|
|
|
static bool moxa_carrier_raised(struct tty_port *);
|
2023-01-17 17:03:53 +08:00
|
|
|
static void moxa_dtr_rts(struct tty_port *, bool);
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* moxa board interface functions:
|
|
|
|
*/
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortEnable(struct moxa_port *);
|
|
|
|
static void MoxaPortDisable(struct moxa_port *);
|
|
|
|
static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t);
|
2023-01-17 17:03:53 +08:00
|
|
|
static int MoxaPortGetLineOut(struct moxa_port *, bool *, bool *);
|
|
|
|
static void MoxaPortLineCtrl(struct moxa_port *, bool, bool);
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
|
|
|
|
static int MoxaPortLineStatus(struct moxa_port *);
|
|
|
|
static void MoxaPortFlushData(struct moxa_port *, int);
|
2008-10-13 17:39:58 +08:00
|
|
|
static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
|
2008-04-30 15:53:43 +08:00
|
|
|
static int MoxaPortReadData(struct moxa_port *);
|
2021-05-05 17:19:19 +08:00
|
|
|
static unsigned int MoxaPortTxQueue(struct moxa_port *);
|
2008-04-30 15:53:40 +08:00
|
|
|
static int MoxaPortRxQueue(struct moxa_port *);
|
2021-05-05 17:19:15 +08:00
|
|
|
static unsigned int MoxaPortTxFree(struct moxa_port *);
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortTxDisable(struct moxa_port *);
|
|
|
|
static void MoxaPortTxEnable(struct moxa_port *);
|
2018-09-12 10:01:00 +08:00
|
|
|
static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
|
|
|
|
static int moxa_set_serial_info(struct tty_struct *, struct serial_struct *);
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaSetFifo(struct moxa_port *port, int enable);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
/*
|
|
|
|
* I/O functions
|
|
|
|
*/
|
|
|
|
|
2009-11-30 21:18:02 +08:00
|
|
|
static DEFINE_SPINLOCK(moxafunc_lock);
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
static void moxa_wait_finish(void __iomem *ofsAddr)
|
|
|
|
{
|
|
|
|
unsigned long end = jiffies + moxaFuncTout;
|
|
|
|
|
|
|
|
while (readw(ofsAddr + FuncCode) != 0)
|
|
|
|
if (time_after(jiffies, end))
|
|
|
|
return;
|
2011-06-16 20:07:22 +08:00
|
|
|
if (readw(ofsAddr + FuncCode) != 0)
|
|
|
|
printk_ratelimited(KERN_WARNING "moxa function expired\n");
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:46 +08:00
|
|
|
static void moxafunc(void __iomem *ofsAddr, u16 cmd, u16 arg)
|
2008-04-30 15:53:43 +08:00
|
|
|
{
|
2009-11-30 21:17:57 +08:00
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&moxafunc_lock, flags);
|
2008-04-30 15:53:43 +08:00
|
|
|
writew(arg, ofsAddr + FuncArg);
|
|
|
|
writew(cmd, ofsAddr + FuncCode);
|
|
|
|
moxa_wait_finish(ofsAddr);
|
2009-11-30 21:17:57 +08:00
|
|
|
spin_unlock_irqrestore(&moxafunc_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxafuncret(void __iomem *ofsAddr, u16 cmd, u16 arg)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
u16 ret;
|
|
|
|
spin_lock_irqsave(&moxafunc_lock, flags);
|
|
|
|
writew(arg, ofsAddr + FuncArg);
|
|
|
|
writew(cmd, ofsAddr + FuncCode);
|
|
|
|
moxa_wait_finish(ofsAddr);
|
|
|
|
ret = readw(ofsAddr + FuncArg);
|
|
|
|
spin_unlock_irqrestore(&moxafunc_lock, flags);
|
|
|
|
return ret;
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
static void moxa_low_water_check(void __iomem *ofsAddr)
|
|
|
|
{
|
|
|
|
u16 rptr, wptr, mask, len;
|
|
|
|
|
|
|
|
if (readb(ofsAddr + FlagStat) & Xoff_state) {
|
|
|
|
rptr = readw(ofsAddr + RXrptr);
|
|
|
|
wptr = readw(ofsAddr + RXwptr);
|
|
|
|
mask = readw(ofsAddr + RX_mask);
|
|
|
|
len = (wptr - rptr) & mask;
|
|
|
|
if (len <= Low_water)
|
|
|
|
moxafunc(ofsAddr, FC_SendXon, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
/*
|
|
|
|
* TTY operations
|
|
|
|
*/
|
|
|
|
|
2011-02-15 00:27:22 +08:00
|
|
|
static int moxa_ioctl(struct tty_struct *tty,
|
2008-04-30 15:53:43 +08:00
|
|
|
unsigned int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
struct moxa_port *ch = tty->driver_data;
|
|
|
|
void __user *argp = (void __user *)arg;
|
2008-04-30 15:53:45 +08:00
|
|
|
int status, ret = 0;
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
if (tty->index == MAX_PORTS) {
|
|
|
|
if (cmd != MOXA_GETDATACOUNT && cmd != MOXA_GET_IOQUEUE &&
|
|
|
|
cmd != MOXA_GETMSTATUS)
|
|
|
|
return -EINVAL;
|
|
|
|
} else if (!ch)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MOXA_GETDATACOUNT:
|
|
|
|
moxaLog.tick = jiffies;
|
2008-04-30 15:53:45 +08:00
|
|
|
if (copy_to_user(argp, &moxaLog, sizeof(moxaLog)))
|
|
|
|
ret = -EFAULT;
|
|
|
|
break;
|
2008-04-30 15:53:43 +08:00
|
|
|
case MOXA_FLUSH_QUEUE:
|
|
|
|
MoxaPortFlushData(ch, arg);
|
2008-04-30 15:53:45 +08:00
|
|
|
break;
|
2008-04-30 15:53:43 +08:00
|
|
|
case MOXA_GET_IOQUEUE: {
|
|
|
|
struct moxaq_str __user *argm = argp;
|
|
|
|
struct moxaq_str tmp;
|
|
|
|
struct moxa_port *p;
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_BOARDS; i++) {
|
|
|
|
p = moxa_boards[i].ports;
|
|
|
|
for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
|
|
|
|
memset(&tmp, 0, sizeof(tmp));
|
2009-11-30 21:18:24 +08:00
|
|
|
spin_lock_bh(&moxa_lock);
|
2008-04-30 15:53:43 +08:00
|
|
|
if (moxa_boards[i].ready) {
|
|
|
|
tmp.inq = MoxaPortRxQueue(p);
|
|
|
|
tmp.outq = MoxaPortTxQueue(p);
|
|
|
|
}
|
2009-11-30 21:18:24 +08:00
|
|
|
spin_unlock_bh(&moxa_lock);
|
|
|
|
if (copy_to_user(argm, &tmp, sizeof(tmp)))
|
2008-04-30 15:53:43 +08:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
2008-04-30 15:53:45 +08:00
|
|
|
break;
|
2008-04-30 15:53:43 +08:00
|
|
|
} case MOXA_GET_OQUEUE:
|
|
|
|
status = MoxaPortTxQueue(ch);
|
2008-04-30 15:53:45 +08:00
|
|
|
ret = put_user(status, (unsigned long __user *)argp);
|
|
|
|
break;
|
2008-04-30 15:53:43 +08:00
|
|
|
case MOXA_GET_IQUEUE:
|
|
|
|
status = MoxaPortRxQueue(ch);
|
2008-04-30 15:53:45 +08:00
|
|
|
ret = put_user(status, (unsigned long __user *)argp);
|
|
|
|
break;
|
2008-04-30 15:53:43 +08:00
|
|
|
case MOXA_GETMSTATUS: {
|
|
|
|
struct mxser_mstatus __user *argm = argp;
|
|
|
|
struct mxser_mstatus tmp;
|
|
|
|
struct moxa_port *p;
|
|
|
|
unsigned int i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_BOARDS; i++) {
|
|
|
|
p = moxa_boards[i].ports;
|
|
|
|
for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
|
2008-10-13 17:39:58 +08:00
|
|
|
struct tty_struct *ttyp;
|
2008-04-30 15:53:43 +08:00
|
|
|
memset(&tmp, 0, sizeof(tmp));
|
2009-11-30 21:18:24 +08:00
|
|
|
spin_lock_bh(&moxa_lock);
|
|
|
|
if (!moxa_boards[i].ready) {
|
|
|
|
spin_unlock_bh(&moxa_lock);
|
2008-04-30 15:53:43 +08:00
|
|
|
goto copy;
|
2009-11-30 21:18:24 +08:00
|
|
|
}
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
status = MoxaPortLineStatus(p);
|
2009-11-30 21:18:24 +08:00
|
|
|
spin_unlock_bh(&moxa_lock);
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
if (status & 1)
|
|
|
|
tmp.cts = 1;
|
|
|
|
if (status & 2)
|
|
|
|
tmp.dsr = 1;
|
|
|
|
if (status & 4)
|
|
|
|
tmp.dcd = 1;
|
|
|
|
|
2008-10-13 17:39:58 +08:00
|
|
|
ttyp = tty_port_tty_get(&p->port);
|
2012-07-14 22:31:47 +08:00
|
|
|
if (!ttyp)
|
2008-04-30 15:53:43 +08:00
|
|
|
tmp.cflag = p->cflag;
|
|
|
|
else
|
2012-07-14 22:31:47 +08:00
|
|
|
tmp.cflag = ttyp->termios.c_cflag;
|
2011-04-23 04:46:21 +08:00
|
|
|
tty_kref_put(ttyp);
|
2008-04-30 15:53:43 +08:00
|
|
|
copy:
|
2009-11-30 21:18:24 +08:00
|
|
|
if (copy_to_user(argm, &tmp, sizeof(tmp)))
|
2008-04-30 15:53:43 +08:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
2008-04-30 15:53:45 +08:00
|
|
|
break;
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
2008-04-30 15:53:45 +08:00
|
|
|
default:
|
|
|
|
ret = -ENOIOCTLCMD;
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
2008-04-30 15:53:45 +08:00
|
|
|
return ret;
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
|
|
|
|
2008-07-22 18:18:03 +08:00
|
|
|
static int moxa_break_ctl(struct tty_struct *tty, int state)
|
2008-04-30 15:53:43 +08:00
|
|
|
{
|
|
|
|
struct moxa_port *port = tty->driver_data;
|
|
|
|
|
|
|
|
moxafunc(port->tableAddr, state ? FC_SendBreak : FC_StopBreak,
|
|
|
|
Magic_code);
|
2008-07-22 18:18:03 +08:00
|
|
|
return 0;
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
|
|
|
|
2006-10-02 17:17:18 +08:00
|
|
|
static const struct tty_operations moxa_ops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = moxa_open,
|
|
|
|
.close = moxa_close,
|
|
|
|
.write = moxa_write,
|
|
|
|
.write_room = moxa_write_room,
|
|
|
|
.flush_buffer = moxa_flush_buffer,
|
|
|
|
.chars_in_buffer = moxa_chars_in_buffer,
|
|
|
|
.ioctl = moxa_ioctl,
|
|
|
|
.set_termios = moxa_set_termios,
|
|
|
|
.stop = moxa_stop,
|
|
|
|
.start = moxa_start,
|
|
|
|
.hangup = moxa_hangup,
|
2008-04-30 15:53:43 +08:00
|
|
|
.break_ctl = moxa_break_ctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
.tiocmget = moxa_tiocmget,
|
|
|
|
.tiocmset = moxa_tiocmset,
|
2018-09-12 10:01:00 +08:00
|
|
|
.set_serial = moxa_set_serial_info,
|
|
|
|
.get_serial = moxa_get_serial_info,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-01-02 21:45:05 +08:00
|
|
|
static const struct tty_port_operations moxa_port_ops = {
|
|
|
|
.carrier_raised = moxa_carrier_raised,
|
2009-11-30 21:17:51 +08:00
|
|
|
.dtr_rts = moxa_dtr_rts,
|
|
|
|
.shutdown = moxa_shutdown,
|
2009-01-02 21:45:05 +08:00
|
|
|
};
|
|
|
|
|
2007-02-10 17:45:27 +08:00
|
|
|
static struct tty_driver *moxaDriver;
|
2017-10-05 07:27:04 +08:00
|
|
|
static DEFINE_TIMER(moxaTimer, moxa_poll);
|
[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
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
/*
|
|
|
|
* HW init
|
|
|
|
*/
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
static int moxa_check_fw_model(struct moxa_board_conf *brd, u8 model)
|
|
|
|
{
|
|
|
|
switch (brd->boardType) {
|
|
|
|
case MOXA_BOARD_C218_ISA:
|
|
|
|
case MOXA_BOARD_C218_PCI:
|
|
|
|
if (model != 1)
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
case MOXA_BOARD_CP204J:
|
|
|
|
if (model != 3)
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (model != 2)
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxa_check_fw(const void *ptr)
|
|
|
|
{
|
|
|
|
const __le16 *lptr = ptr;
|
|
|
|
|
|
|
|
if (*lptr != cpu_to_le16(0x7980))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxa_load_bios(struct moxa_board_conf *brd, const u8 *buf,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
void __iomem *baseAddr = brd->basemem;
|
|
|
|
u16 tmp;
|
|
|
|
|
|
|
|
writeb(HW_reset, baseAddr + Control_reg); /* reset */
|
|
|
|
msleep(10);
|
|
|
|
memset_io(baseAddr, 0, 4096);
|
|
|
|
memcpy_toio(baseAddr, buf, len); /* download BIOS */
|
|
|
|
writeb(0, baseAddr + Control_reg); /* restart */
|
|
|
|
|
|
|
|
msleep(2000);
|
|
|
|
|
|
|
|
switch (brd->boardType) {
|
|
|
|
case MOXA_BOARD_C218_ISA:
|
|
|
|
case MOXA_BOARD_C218_PCI:
|
|
|
|
tmp = readw(baseAddr + C218_key);
|
|
|
|
if (tmp != C218_KeyCode)
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
case MOXA_BOARD_CP204J:
|
|
|
|
tmp = readw(baseAddr + C218_key);
|
|
|
|
if (tmp != CP204J_KeyCode)
|
|
|
|
goto err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tmp = readw(baseAddr + C320_key);
|
|
|
|
if (tmp != C320_KeyCode)
|
|
|
|
goto err;
|
|
|
|
tmp = readw(baseAddr + C320_status);
|
|
|
|
if (tmp != STS_init) {
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "MOXA: bios upload failed -- CPU/Basic "
|
2008-04-30 15:53:39 +08:00
|
|
|
"module not found\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "MOXA: bios upload failed -- board not found\n");
|
2008-04-30 15:53:39 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxa_load_320b(struct moxa_board_conf *brd, const u8 *ptr,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
void __iomem *baseAddr = brd->basemem;
|
|
|
|
|
|
|
|
if (len < 7168) {
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "MOXA: invalid 320 bios -- too short\n");
|
2008-04-30 15:53:39 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
writew(len - 7168 - 2, baseAddr + C320bapi_len);
|
|
|
|
writeb(1, baseAddr + Control_reg); /* Select Page 1 */
|
|
|
|
memcpy_toio(baseAddr + DynPage_addr, ptr, 7168);
|
|
|
|
writeb(2, baseAddr + Control_reg); /* Select Page 2 */
|
|
|
|
memcpy_toio(baseAddr + DynPage_addr, ptr + 7168, len - 7168);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
|
2008-04-30 15:53:39 +08:00
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
void __iomem *baseAddr = brd->basemem;
|
2008-10-16 13:04:19 +08:00
|
|
|
const __le16 *uptr = ptr;
|
2008-04-30 15:53:39 +08:00
|
|
|
size_t wlen, len2, j;
|
2008-04-30 15:53:39 +08:00
|
|
|
unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
|
2008-04-30 15:53:47 +08:00
|
|
|
unsigned int i, retry;
|
2008-04-30 15:53:39 +08:00
|
|
|
u16 usum, keycode;
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
keycode = (brd->boardType == MOXA_BOARD_CP204J) ? CP204J_KeyCode :
|
|
|
|
C218_KeyCode;
|
2008-04-30 15:53:39 +08:00
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
switch (brd->boardType) {
|
|
|
|
case MOXA_BOARD_CP204J:
|
|
|
|
case MOXA_BOARD_C218_ISA:
|
|
|
|
case MOXA_BOARD_C218_PCI:
|
|
|
|
key = C218_key;
|
|
|
|
loadbuf = C218_LoadBuf;
|
|
|
|
loadlen = C218DLoad_len;
|
|
|
|
checksum = C218check_sum;
|
|
|
|
checksum_ok = C218chksum_ok;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
key = C320_key;
|
|
|
|
keycode = C320_KeyCode;
|
|
|
|
loadbuf = C320_LoadBuf;
|
|
|
|
loadlen = C320DLoad_len;
|
|
|
|
checksum = C320check_sum;
|
|
|
|
checksum_ok = C320chksum_ok;
|
|
|
|
break;
|
2008-04-30 15:53:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
usum = 0;
|
|
|
|
wlen = len >> 1;
|
|
|
|
for (i = 0; i < wlen; i++)
|
|
|
|
usum += le16_to_cpu(uptr[i]);
|
|
|
|
retry = 0;
|
|
|
|
do {
|
|
|
|
wlen = len >> 1;
|
|
|
|
j = 0;
|
|
|
|
while (wlen) {
|
|
|
|
len2 = (wlen > 2048) ? 2048 : wlen;
|
|
|
|
wlen -= len2;
|
2008-04-30 15:53:39 +08:00
|
|
|
memcpy_toio(baseAddr + loadbuf, ptr + j, len2 << 1);
|
2008-04-30 15:53:39 +08:00
|
|
|
j += len2 << 1;
|
2008-04-30 15:53:39 +08:00
|
|
|
|
|
|
|
writew(len2, baseAddr + loadlen);
|
|
|
|
writew(0, baseAddr + key);
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
if (readw(baseAddr + key) == keycode)
|
2008-04-30 15:53:39 +08:00
|
|
|
break;
|
|
|
|
msleep(10);
|
|
|
|
}
|
2008-04-30 15:53:39 +08:00
|
|
|
if (readw(baseAddr + key) != keycode)
|
2008-04-30 15:53:39 +08:00
|
|
|
return -EIO;
|
|
|
|
}
|
2008-04-30 15:53:39 +08:00
|
|
|
writew(0, baseAddr + loadlen);
|
|
|
|
writew(usum, baseAddr + checksum);
|
|
|
|
writew(0, baseAddr + key);
|
|
|
|
for (i = 0; i < 100; i++) {
|
|
|
|
if (readw(baseAddr + key) == keycode)
|
2008-04-30 15:53:39 +08:00
|
|
|
break;
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
retry++;
|
2008-04-30 15:53:39 +08:00
|
|
|
} while ((readb(baseAddr + checksum_ok) != 1) && (retry < 3));
|
|
|
|
if (readb(baseAddr + checksum_ok) != 1)
|
2008-04-30 15:53:39 +08:00
|
|
|
return -EIO;
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
writew(0, baseAddr + key);
|
2008-04-30 15:53:39 +08:00
|
|
|
for (i = 0; i < 600; i++) {
|
|
|
|
if (readw(baseAddr + Magic_no) == Magic_code)
|
|
|
|
break;
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
if (readw(baseAddr + Magic_no) != Magic_code)
|
|
|
|
return -EIO;
|
|
|
|
|
2008-04-30 15:53:47 +08:00
|
|
|
if (MOXA_IS_320(brd)) {
|
2008-04-30 15:53:39 +08:00
|
|
|
if (brd->busType == MOXA_BUS_TYPE_PCI) { /* ASIC board */
|
|
|
|
writew(0x3800, baseAddr + TMS320_PORT1);
|
|
|
|
writew(0x3900, baseAddr + TMS320_PORT2);
|
|
|
|
writew(28499, baseAddr + TMS320_CLOCK);
|
|
|
|
} else {
|
|
|
|
writew(0x3200, baseAddr + TMS320_PORT1);
|
|
|
|
writew(0x3400, baseAddr + TMS320_PORT2);
|
|
|
|
writew(19999, baseAddr + TMS320_CLOCK);
|
|
|
|
}
|
2008-04-30 15:53:39 +08:00
|
|
|
}
|
|
|
|
writew(1, baseAddr + Disable_IRQ);
|
|
|
|
writew(0, baseAddr + Magic_no);
|
|
|
|
for (i = 0; i < 500; i++) {
|
|
|
|
if (readw(baseAddr + Magic_no) == Magic_code)
|
|
|
|
break;
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
if (readw(baseAddr + Magic_no) != Magic_code)
|
|
|
|
return -EIO;
|
|
|
|
|
2008-04-30 15:53:47 +08:00
|
|
|
if (MOXA_IS_320(brd)) {
|
2008-04-30 15:53:39 +08:00
|
|
|
j = readw(baseAddr + Module_cnt);
|
|
|
|
if (j <= 0)
|
|
|
|
return -EIO;
|
|
|
|
brd->numPorts = j * 8;
|
|
|
|
writew(j, baseAddr + Module_no);
|
|
|
|
writew(0, baseAddr + Magic_no);
|
|
|
|
for (i = 0; i < 600; i++) {
|
|
|
|
if (readw(baseAddr + Magic_no) == Magic_code)
|
|
|
|
break;
|
|
|
|
msleep(10);
|
|
|
|
}
|
|
|
|
if (readw(baseAddr + Magic_no) != Magic_code)
|
|
|
|
return -EIO;
|
2008-04-30 15:53:39 +08:00
|
|
|
}
|
|
|
|
brd->intNdx = baseAddr + IRQindex;
|
|
|
|
brd->intPend = baseAddr + IRQpending;
|
|
|
|
brd->intTable = baseAddr + IRQtable;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxa_load_code(struct moxa_board_conf *brd, const void *ptr,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
void __iomem *ofsAddr, *baseAddr = brd->basemem;
|
|
|
|
struct moxa_port *port;
|
|
|
|
int retval, i;
|
|
|
|
|
|
|
|
if (len % 2) {
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "MOXA: bios length is not even\n");
|
2008-04-30 15:53:39 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
retval = moxa_real_load_code(brd, ptr, len); /* may change numPorts */
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
switch (brd->boardType) {
|
|
|
|
case MOXA_BOARD_C218_ISA:
|
|
|
|
case MOXA_BOARD_C218_PCI:
|
|
|
|
case MOXA_BOARD_CP204J:
|
|
|
|
port = brd->ports;
|
|
|
|
for (i = 0; i < brd->numPorts; i++, port++) {
|
2008-04-30 15:53:40 +08:00
|
|
|
port->board = brd;
|
2008-04-30 15:53:39 +08:00
|
|
|
port->DCDState = 0;
|
|
|
|
port->tableAddr = baseAddr + Extern_table +
|
|
|
|
Extern_size * i;
|
|
|
|
ofsAddr = port->tableAddr;
|
|
|
|
writew(C218rx_mask, ofsAddr + RX_mask);
|
|
|
|
writew(C218tx_mask, ofsAddr + TX_mask);
|
|
|
|
writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
|
|
|
|
writew(readw(ofsAddr + Page_rxb) + C218rx_pageno, ofsAddr + EndPage_rxb);
|
|
|
|
|
|
|
|
writew(C218tx_spage + i * C218buf_pageno, ofsAddr + Page_txb);
|
|
|
|
writew(readw(ofsAddr + Page_txb) + C218tx_pageno, ofsAddr + EndPage_txb);
|
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
port = brd->ports;
|
|
|
|
for (i = 0; i < brd->numPorts; i++, port++) {
|
2008-04-30 15:53:40 +08:00
|
|
|
port->board = brd;
|
2008-04-30 15:53:39 +08:00
|
|
|
port->DCDState = 0;
|
|
|
|
port->tableAddr = baseAddr + Extern_table +
|
|
|
|
Extern_size * i;
|
|
|
|
ofsAddr = port->tableAddr;
|
|
|
|
switch (brd->numPorts) {
|
|
|
|
case 8:
|
|
|
|
writew(C320p8rx_mask, ofsAddr + RX_mask);
|
|
|
|
writew(C320p8tx_mask, ofsAddr + TX_mask);
|
|
|
|
writew(C320p8rx_spage + i * C320p8buf_pgno, ofsAddr + Page_rxb);
|
|
|
|
writew(readw(ofsAddr + Page_rxb) + C320p8rx_pgno, ofsAddr + EndPage_rxb);
|
|
|
|
writew(C320p8tx_spage + i * C320p8buf_pgno, ofsAddr + Page_txb);
|
|
|
|
writew(readw(ofsAddr + Page_txb) + C320p8tx_pgno, ofsAddr + EndPage_txb);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
writew(C320p16rx_mask, ofsAddr + RX_mask);
|
|
|
|
writew(C320p16tx_mask, ofsAddr + TX_mask);
|
|
|
|
writew(C320p16rx_spage + i * C320p16buf_pgno, ofsAddr + Page_rxb);
|
|
|
|
writew(readw(ofsAddr + Page_rxb) + C320p16rx_pgno, ofsAddr + EndPage_rxb);
|
|
|
|
writew(C320p16tx_spage + i * C320p16buf_pgno, ofsAddr + Page_txb);
|
|
|
|
writew(readw(ofsAddr + Page_txb) + C320p16tx_pgno, ofsAddr + EndPage_txb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
writew(C320p24rx_mask, ofsAddr + RX_mask);
|
|
|
|
writew(C320p24tx_mask, ofsAddr + TX_mask);
|
|
|
|
writew(C320p24rx_spage + i * C320p24buf_pgno, ofsAddr + Page_rxb);
|
|
|
|
writew(readw(ofsAddr + Page_rxb) + C320p24rx_pgno, ofsAddr + EndPage_rxb);
|
|
|
|
writew(C320p24tx_spage + i * C320p24buf_pgno, ofsAddr + Page_txb);
|
|
|
|
writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
writew(C320p32rx_mask, ofsAddr + RX_mask);
|
|
|
|
writew(C320p32tx_mask, ofsAddr + TX_mask);
|
|
|
|
writew(C320p32tx_ofs, ofsAddr + Ofs_txb);
|
|
|
|
writew(C320p32rx_spage + i * C320p32buf_pgno, ofsAddr + Page_rxb);
|
|
|
|
writew(readb(ofsAddr + Page_rxb), ofsAddr + EndPage_rxb);
|
|
|
|
writew(C320p32tx_spage + i * C320p32buf_pgno, ofsAddr + Page_txb);
|
|
|
|
writew(readw(ofsAddr + Page_txb), ofsAddr + EndPage_txb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxa_load_fw(struct moxa_board_conf *brd, const struct firmware *fw)
|
|
|
|
{
|
2008-07-09 00:37:15 +08:00
|
|
|
const void *ptr = fw->data;
|
2008-04-30 15:53:39 +08:00
|
|
|
char rsn[64];
|
|
|
|
u16 lens[5];
|
|
|
|
size_t len;
|
|
|
|
unsigned int a, lenp, lencnt;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
struct {
|
|
|
|
__le32 magic; /* 0x34303430 */
|
|
|
|
u8 reserved1[2];
|
|
|
|
u8 type; /* UNIX = 3 */
|
|
|
|
u8 model; /* C218T=1, C320T=2, CP204=3 */
|
|
|
|
u8 reserved2[8];
|
|
|
|
__le16 len[5];
|
2008-07-09 00:37:15 +08:00
|
|
|
} const *hdr = ptr;
|
2008-04-30 15:53:39 +08:00
|
|
|
|
|
|
|
BUILD_BUG_ON(ARRAY_SIZE(hdr->len) != ARRAY_SIZE(lens));
|
|
|
|
|
|
|
|
if (fw->size < MOXA_FW_HDRLEN) {
|
|
|
|
strcpy(rsn, "too short (even header won't fit)");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (hdr->magic != cpu_to_le32(0x30343034)) {
|
|
|
|
sprintf(rsn, "bad magic: %.8x", le32_to_cpu(hdr->magic));
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (hdr->type != 3) {
|
|
|
|
sprintf(rsn, "not for linux, type is %u", hdr->type);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (moxa_check_fw_model(brd, hdr->model)) {
|
|
|
|
sprintf(rsn, "not for this card, model is %u", hdr->model);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = MOXA_FW_HDRLEN;
|
|
|
|
lencnt = hdr->model == 2 ? 5 : 3;
|
|
|
|
for (a = 0; a < ARRAY_SIZE(lens); a++) {
|
|
|
|
lens[a] = le16_to_cpu(hdr->len[a]);
|
|
|
|
if (lens[a] && len + lens[a] <= fw->size &&
|
|
|
|
moxa_check_fw(&fw->data[len]))
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_WARNING "MOXA firmware: unexpected input "
|
2008-04-30 15:53:39 +08:00
|
|
|
"at offset %u, but going on\n", (u32)len);
|
|
|
|
if (!lens[a] && a < lencnt) {
|
|
|
|
sprintf(rsn, "too few entries in fw file");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
len += lens[a];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len != fw->size) {
|
|
|
|
sprintf(rsn, "bad length: %u (should be %u)", (u32)fw->size,
|
|
|
|
(u32)len);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr += MOXA_FW_HDRLEN;
|
|
|
|
lenp = 0; /* bios */
|
|
|
|
|
|
|
|
strcpy(rsn, "read above");
|
|
|
|
|
|
|
|
ret = moxa_load_bios(brd, ptr, lens[lenp]);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* we skip the tty section (lens[1]), since we don't need it */
|
|
|
|
ptr += lens[lenp] + lens[lenp + 1];
|
|
|
|
lenp += 2; /* comm */
|
|
|
|
|
|
|
|
if (hdr->model == 2) {
|
|
|
|
ret = moxa_load_320b(brd, ptr, lens[lenp]);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
/* skip another tty */
|
|
|
|
ptr += lens[lenp] + lens[lenp + 1];
|
|
|
|
lenp += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = moxa_load_code(brd, ptr, lens[lenp]);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
printk(KERN_ERR "firmware failed to load, reason: %s\n", rsn);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int moxa_init_board(struct moxa_board_conf *brd, struct device *dev)
|
|
|
|
{
|
|
|
|
const struct firmware *fw;
|
|
|
|
const char *file;
|
2008-04-30 15:53:41 +08:00
|
|
|
struct moxa_port *p;
|
2012-08-08 03:47:55 +08:00
|
|
|
unsigned int i, first_idx;
|
2008-04-30 15:53:39 +08:00
|
|
|
int ret;
|
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
brd->ports = kcalloc(MAX_PORTS_PER_BOARD, sizeof(*brd->ports),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (brd->ports == NULL) {
|
|
|
|
printk(KERN_ERR "cannot allocate memory for ports\n");
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0, p = brd->ports; i < MAX_PORTS_PER_BOARD; i++, p++) {
|
2008-07-17 04:57:18 +08:00
|
|
|
tty_port_init(&p->port);
|
2009-01-02 21:45:05 +08:00
|
|
|
p->port.ops = &moxa_port_ops;
|
2008-04-30 15:53:41 +08:00
|
|
|
p->type = PORT_16550A;
|
|
|
|
p->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
switch (brd->boardType) {
|
|
|
|
case MOXA_BOARD_C218_ISA:
|
|
|
|
case MOXA_BOARD_C218_PCI:
|
|
|
|
file = "c218tunx.cod";
|
|
|
|
break;
|
|
|
|
case MOXA_BOARD_CP204J:
|
|
|
|
file = "cp204unx.cod";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
file = "c320tunx.cod";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = request_firmware(&fw, file, dev);
|
|
|
|
if (ret) {
|
2008-04-30 15:53:49 +08:00
|
|
|
printk(KERN_ERR "MOXA: request_firmware failed. Make sure "
|
|
|
|
"you've placed '%s' file into your firmware "
|
|
|
|
"loader directory (e.g. /lib/firmware)\n",
|
|
|
|
file);
|
2008-04-30 15:53:41 +08:00
|
|
|
goto err_free;
|
2008-04-30 15:53:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = moxa_load_fw(brd, fw);
|
|
|
|
|
|
|
|
release_firmware(fw);
|
2008-04-30 15:53:41 +08:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
goto err_free;
|
|
|
|
|
2008-04-30 15:53:45 +08:00
|
|
|
spin_lock_bh(&moxa_lock);
|
2008-04-30 15:53:41 +08:00
|
|
|
brd->ready = 1;
|
2008-04-30 15:53:42 +08:00
|
|
|
if (!timer_pending(&moxaTimer))
|
|
|
|
mod_timer(&moxaTimer, jiffies + HZ / 50);
|
2008-04-30 15:53:45 +08:00
|
|
|
spin_unlock_bh(&moxa_lock);
|
2008-04-30 15:53:42 +08:00
|
|
|
|
2012-08-08 03:47:55 +08:00
|
|
|
first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD;
|
|
|
|
for (i = 0; i < brd->numPorts; i++)
|
|
|
|
tty_port_register_device(&brd->ports[i].port, moxaDriver,
|
|
|
|
first_idx + i, dev);
|
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
return 0;
|
|
|
|
err_free:
|
2012-11-15 16:49:56 +08:00
|
|
|
for (i = 0; i < MAX_PORTS_PER_BOARD; i++)
|
|
|
|
tty_port_destroy(&brd->ports[i].port);
|
2008-04-30 15:53:41 +08:00
|
|
|
kfree(brd->ports);
|
|
|
|
err:
|
2008-04-30 15:53:39 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
static void moxa_board_deinit(struct moxa_board_conf *brd)
|
|
|
|
{
|
2012-08-08 03:47:55 +08:00
|
|
|
unsigned int a, opened, first_idx;
|
2008-04-30 15:53:45 +08:00
|
|
|
|
|
|
|
mutex_lock(&moxa_openlock);
|
2008-04-30 15:53:43 +08:00
|
|
|
spin_lock_bh(&moxa_lock);
|
2008-04-30 15:53:41 +08:00
|
|
|
brd->ready = 0;
|
2008-04-30 15:53:43 +08:00
|
|
|
spin_unlock_bh(&moxa_lock);
|
2008-04-30 15:53:45 +08:00
|
|
|
|
|
|
|
/* pci hot-un-plug support */
|
|
|
|
for (a = 0; a < brd->numPorts; a++)
|
2016-04-10 08:53:25 +08:00
|
|
|
if (tty_port_initialized(&brd->ports[a].port))
|
2013-03-07 20:12:30 +08:00
|
|
|
tty_port_tty_hangup(&brd->ports[a].port, false);
|
|
|
|
|
2012-11-15 16:49:56 +08:00
|
|
|
for (a = 0; a < MAX_PORTS_PER_BOARD; a++)
|
|
|
|
tty_port_destroy(&brd->ports[a].port);
|
2013-03-07 20:12:30 +08:00
|
|
|
|
2008-04-30 15:53:45 +08:00
|
|
|
while (1) {
|
|
|
|
opened = 0;
|
|
|
|
for (a = 0; a < brd->numPorts; a++)
|
2016-04-10 08:53:25 +08:00
|
|
|
if (tty_port_initialized(&brd->ports[a].port))
|
2008-04-30 15:53:45 +08:00
|
|
|
opened++;
|
|
|
|
mutex_unlock(&moxa_openlock);
|
|
|
|
if (!opened)
|
|
|
|
break;
|
|
|
|
msleep(50);
|
|
|
|
mutex_lock(&moxa_openlock);
|
|
|
|
}
|
|
|
|
|
2012-08-08 03:47:55 +08:00
|
|
|
first_idx = (brd - moxa_boards) * MAX_PORTS_PER_BOARD;
|
|
|
|
for (a = 0; a < brd->numPorts; a++)
|
|
|
|
tty_unregister_device(moxaDriver, first_idx + a);
|
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
iounmap(brd->basemem);
|
|
|
|
brd->basemem = NULL;
|
|
|
|
kfree(brd->ports);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2012-11-20 02:21:50 +08:00
|
|
|
static int moxa_pci_probe(struct pci_dev *pdev,
|
2007-02-10 17:45:35 +08:00
|
|
|
const struct pci_device_id *ent)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-10 17:45:35 +08:00
|
|
|
struct moxa_board_conf *board;
|
|
|
|
unsigned int i;
|
|
|
|
int board_type = ent->driver_data;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = pci_enable_device(pdev);
|
2007-10-18 18:06:24 +08:00
|
|
|
if (retval) {
|
|
|
|
dev_err(&pdev->dev, "can't enable pci device\n");
|
2007-02-10 17:45:35 +08:00
|
|
|
goto err;
|
2007-10-18 18:06:24 +08:00
|
|
|
}
|
2007-02-10 17:45:35 +08:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_BOARDS; i++)
|
|
|
|
if (moxa_boards[i].basemem == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
retval = -ENODEV;
|
|
|
|
if (i >= MAX_BOARDS) {
|
2007-10-18 18:06:24 +08:00
|
|
|
dev_warn(&pdev->dev, "more than %u MOXA Intellio family boards "
|
2007-02-10 17:45:35 +08:00
|
|
|
"found. Board is ignored.\n", MAX_BOARDS);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
board = &moxa_boards[i];
|
2008-04-30 15:53:37 +08:00
|
|
|
|
|
|
|
retval = pci_request_region(pdev, 2, "moxa-base");
|
|
|
|
if (retval) {
|
|
|
|
dev_err(&pdev->dev, "can't request pci region 2\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2020-01-06 16:43:50 +08:00
|
|
|
board->basemem = ioremap(pci_resource_start(pdev, 2), 0x4000);
|
2007-10-18 18:06:24 +08:00
|
|
|
if (board->basemem == NULL) {
|
|
|
|
dev_err(&pdev->dev, "can't remap io space 2\n");
|
2012-08-14 14:47:35 +08:00
|
|
|
retval = -ENOMEM;
|
2008-04-30 15:53:37 +08:00
|
|
|
goto err_reg;
|
2007-10-18 18:06:24 +08:00
|
|
|
}
|
2007-02-10 17:45:35 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
board->boardType = board_type;
|
|
|
|
switch (board_type) {
|
|
|
|
case MOXA_BOARD_C218_ISA:
|
|
|
|
case MOXA_BOARD_C218_PCI:
|
|
|
|
board->numPorts = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MOXA_BOARD_CP204J:
|
|
|
|
board->numPorts = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
board->numPorts = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
board->busType = MOXA_BUS_TYPE_PCI;
|
2007-02-10 17:45:36 +08:00
|
|
|
|
2008-04-30 15:53:39 +08:00
|
|
|
retval = moxa_init_board(board, &pdev->dev);
|
|
|
|
if (retval)
|
|
|
|
goto err_base;
|
|
|
|
|
2007-02-10 17:45:35 +08:00
|
|
|
pci_set_drvdata(pdev, board);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:48 +08:00
|
|
|
dev_info(&pdev->dev, "board '%s' ready (%u ports, firmware loaded)\n",
|
|
|
|
moxa_brdname[board_type - 1], board->numPorts);
|
|
|
|
|
2008-04-30 15:53:46 +08:00
|
|
|
return 0;
|
2008-04-30 15:53:39 +08:00
|
|
|
err_base:
|
|
|
|
iounmap(board->basemem);
|
|
|
|
board->basemem = NULL;
|
2008-04-30 15:53:37 +08:00
|
|
|
err_reg:
|
|
|
|
pci_release_region(pdev, 2);
|
2007-02-10 17:45:35 +08:00
|
|
|
err:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:26:18 +08:00
|
|
|
static void moxa_pci_remove(struct pci_dev *pdev)
|
2007-02-10 17:45:35 +08:00
|
|
|
{
|
|
|
|
struct moxa_board_conf *brd = pci_get_drvdata(pdev);
|
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
moxa_board_deinit(brd);
|
|
|
|
|
2008-04-30 15:53:37 +08:00
|
|
|
pci_release_region(pdev, 2);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-10 17:45:36 +08:00
|
|
|
|
|
|
|
static struct pci_driver moxa_pci_driver = {
|
|
|
|
.name = "moxa",
|
|
|
|
.id_table = moxa_pcibrds,
|
|
|
|
.probe = moxa_pci_probe,
|
2012-11-20 02:21:06 +08:00
|
|
|
.remove = moxa_pci_remove
|
2007-02-10 17:45:36 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_PCI */
|
|
|
|
|
|
|
|
static int __init moxa_init(void)
|
|
|
|
{
|
2008-04-30 15:53:41 +08:00
|
|
|
unsigned int isabrds = 0;
|
2008-04-30 15:53:37 +08:00
|
|
|
int retval = 0;
|
2009-12-10 04:34:18 +08:00
|
|
|
struct moxa_board_conf *brd = moxa_boards;
|
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-10-18 18:06:24 +08:00
|
|
|
printk(KERN_INFO "MOXA Intellio family driver version %s\n",
|
|
|
|
MOXA_VERSION);
|
2012-08-08 03:47:55 +08:00
|
|
|
|
|
|
|
tty_port_init(&moxa_service_port);
|
|
|
|
|
|
|
|
moxaDriver = tty_alloc_driver(MAX_PORTS + 1,
|
|
|
|
TTY_DRIVER_REAL_RAW |
|
|
|
|
TTY_DRIVER_DYNAMIC_DEV);
|
2012-08-16 21:16:56 +08:00
|
|
|
if (IS_ERR(moxaDriver))
|
|
|
|
return PTR_ERR(moxaDriver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-03 23:26:49 +08:00
|
|
|
moxaDriver->name = "ttyMX";
|
2005-04-17 06:20:36 +08:00
|
|
|
moxaDriver->major = ttymajor;
|
|
|
|
moxaDriver->minor_start = 0;
|
|
|
|
moxaDriver->type = TTY_DRIVER_TYPE_SERIAL;
|
|
|
|
moxaDriver->subtype = SERIAL_TYPE_NORMAL;
|
|
|
|
moxaDriver->init_termios = tty_std_termios;
|
|
|
|
moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
|
2006-12-08 18:38:45 +08:00
|
|
|
moxaDriver->init_termios.c_ispeed = 9600;
|
|
|
|
moxaDriver->init_termios.c_ospeed = 9600;
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_set_operations(moxaDriver, &moxa_ops);
|
2012-08-08 03:47:55 +08:00
|
|
|
/* Having one more port only for ioctls is ugly */
|
|
|
|
tty_port_link_device(&moxa_service_port, moxaDriver, MAX_PORTS);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (tty_register_driver(moxaDriver)) {
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "can't register MOXA Smartio tty driver!\n");
|
2021-07-23 15:43:16 +08:00
|
|
|
tty_driver_kref_put(moxaDriver);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:37 +08:00
|
|
|
/* Find the boards defined from module args. */
|
2009-12-10 04:34:18 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
for (i = 0; i < MAX_BOARDS; i++) {
|
2008-04-30 15:53:37 +08:00
|
|
|
if (!baseaddr[i])
|
|
|
|
break;
|
|
|
|
if (type[i] == MOXA_BOARD_C218_ISA ||
|
|
|
|
type[i] == MOXA_BOARD_C320_ISA) {
|
2007-10-18 18:06:24 +08:00
|
|
|
pr_debug("Moxa board %2d: %s board(baseAddr=%lx)\n",
|
2008-04-30 15:53:37 +08:00
|
|
|
isabrds + 1, moxa_brdname[type[i] - 1],
|
|
|
|
baseaddr[i]);
|
|
|
|
brd->boardType = type[i];
|
|
|
|
brd->numPorts = type[i] == MOXA_BOARD_C218_ISA ? 8 :
|
|
|
|
numports[i];
|
|
|
|
brd->busType = MOXA_BUS_TYPE_ISA;
|
2020-01-06 16:43:50 +08:00
|
|
|
brd->basemem = ioremap(baseaddr[i], 0x4000);
|
2008-04-30 15:53:37 +08:00
|
|
|
if (!brd->basemem) {
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "MOXA: can't remap %lx\n",
|
2008-04-30 15:53:37 +08:00
|
|
|
baseaddr[i]);
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-04-30 15:53:39 +08:00
|
|
|
if (moxa_init_board(brd, NULL)) {
|
|
|
|
iounmap(brd->basemem);
|
|
|
|
brd->basemem = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
2008-04-30 15:53:37 +08:00
|
|
|
|
2014-08-06 12:43:42 +08:00
|
|
|
printk(KERN_INFO "MOXA isa board found at 0x%.8lx and "
|
2008-04-30 15:53:48 +08:00
|
|
|
"ready (%u ports, firmware loaded)\n",
|
|
|
|
baseaddr[i], brd->numPorts);
|
|
|
|
|
2008-04-30 15:53:37 +08:00
|
|
|
brd++;
|
|
|
|
isabrds++;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2007-02-10 17:45:36 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2007-02-10 17:45:36 +08:00
|
|
|
retval = pci_register_driver(&moxa_pci_driver);
|
|
|
|
if (retval) {
|
2008-04-30 15:53:46 +08:00
|
|
|
printk(KERN_ERR "Can't register MOXA pci driver!\n");
|
2008-04-30 15:53:37 +08:00
|
|
|
if (isabrds)
|
2007-02-10 17:45:36 +08:00
|
|
|
retval = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
#endif
|
2007-02-10 17:45:36 +08:00
|
|
|
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit moxa_exit(void)
|
|
|
|
{
|
2008-04-30 15:53:46 +08:00
|
|
|
unsigned int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-10 17:45:35 +08:00
|
|
|
#ifdef CONFIG_PCI
|
2007-02-10 17:45:36 +08:00
|
|
|
pci_unregister_driver(&moxa_pci_driver);
|
2007-02-10 17:45:35 +08:00
|
|
|
#endif
|
2007-02-10 17:45:36 +08:00
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
for (i = 0; i < MAX_BOARDS; i++) /* ISA boards */
|
|
|
|
if (moxa_boards[i].ready)
|
|
|
|
moxa_board_deinit(&moxa_boards[i]);
|
2008-04-30 15:53:45 +08:00
|
|
|
|
|
|
|
del_timer_sync(&moxaTimer);
|
|
|
|
|
2021-03-02 14:22:04 +08:00
|
|
|
tty_unregister_driver(moxaDriver);
|
2021-07-23 15:43:16 +08:00
|
|
|
tty_driver_kref_put(moxaDriver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(moxa_init);
|
|
|
|
module_exit(moxa_exit);
|
|
|
|
|
2009-11-30 21:17:51 +08:00
|
|
|
static void moxa_shutdown(struct tty_port *port)
|
2008-04-30 15:53:45 +08:00
|
|
|
{
|
2009-11-30 21:17:51 +08:00
|
|
|
struct moxa_port *ch = container_of(port, struct moxa_port, port);
|
|
|
|
MoxaPortDisable(ch);
|
2008-04-30 15:53:45 +08:00
|
|
|
MoxaPortFlushData(ch, 2);
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:03:52 +08:00
|
|
|
static bool moxa_carrier_raised(struct tty_port *port)
|
2009-01-02 21:45:05 +08:00
|
|
|
{
|
|
|
|
struct moxa_port *ch = container_of(port, struct moxa_port, port);
|
|
|
|
int dcd;
|
|
|
|
|
2009-11-30 21:18:13 +08:00
|
|
|
spin_lock_irq(&port->lock);
|
2009-01-02 21:45:05 +08:00
|
|
|
dcd = ch->DCDState;
|
2009-11-30 21:18:13 +08:00
|
|
|
spin_unlock_irq(&port->lock);
|
2009-01-02 21:45:05 +08:00
|
|
|
return dcd;
|
|
|
|
}
|
|
|
|
|
2023-01-17 17:03:58 +08:00
|
|
|
static void moxa_dtr_rts(struct tty_port *port, bool active)
|
2008-04-30 15:53:45 +08:00
|
|
|
{
|
2009-11-30 21:17:51 +08:00
|
|
|
struct moxa_port *ch = container_of(port, struct moxa_port, port);
|
2023-01-17 17:03:58 +08:00
|
|
|
MoxaPortLineCtrl(ch, active, active);
|
2008-04-30 15:53:45 +08:00
|
|
|
}
|
|
|
|
|
2009-11-30 21:17:51 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static int moxa_open(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
2008-04-30 15:53:41 +08:00
|
|
|
struct moxa_board_conf *brd;
|
2007-02-10 17:45:33 +08:00
|
|
|
struct moxa_port *ch;
|
2005-04-17 06:20:36 +08:00
|
|
|
int port;
|
|
|
|
|
2007-02-10 17:45:31 +08:00
|
|
|
port = tty->index;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (port == MAX_PORTS) {
|
2008-04-30 15:53:43 +08:00
|
|
|
return capable(CAP_SYS_ADMIN) ? 0 : -EPERM;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-30 15:53:45 +08:00
|
|
|
if (mutex_lock_interruptible(&moxa_openlock))
|
|
|
|
return -ERESTARTSYS;
|
2008-04-30 15:53:41 +08:00
|
|
|
brd = &moxa_boards[port / MAX_PORTS_PER_BOARD];
|
2008-04-30 15:53:45 +08:00
|
|
|
if (!brd->ready) {
|
|
|
|
mutex_unlock(&moxa_openlock);
|
2008-04-30 15:53:41 +08:00
|
|
|
return -ENODEV;
|
2008-04-30 15:53:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-11 21:56:44 +08:00
|
|
|
if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) {
|
|
|
|
mutex_unlock(&moxa_openlock);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:41 +08:00
|
|
|
ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
|
2008-07-17 04:56:02 +08:00
|
|
|
ch->port.count++;
|
2005-04-17 06:20:36 +08:00
|
|
|
tty->driver_data = ch;
|
2008-10-13 17:39:58 +08:00
|
|
|
tty_port_tty_set(&ch->port, tty);
|
2009-11-30 21:17:51 +08:00
|
|
|
mutex_lock(&ch->port.mutex);
|
2016-04-10 08:53:25 +08:00
|
|
|
if (!tty_port_initialized(&ch->port)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ch->statusflags = 0;
|
2012-07-14 22:31:47 +08:00
|
|
|
moxa_set_tty_param(tty, &tty->termios);
|
2023-01-17 17:03:53 +08:00
|
|
|
MoxaPortLineCtrl(ch, true, true);
|
2008-04-30 15:53:40 +08:00
|
|
|
MoxaPortEnable(ch);
|
2008-04-30 15:53:45 +08:00
|
|
|
MoxaSetFifo(ch, ch->type == PORT_16550A);
|
2023-01-17 17:03:47 +08:00
|
|
|
tty_port_set_initialized(&ch->port, true);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-11-30 21:17:51 +08:00
|
|
|
mutex_unlock(&ch->port.mutex);
|
2008-04-30 15:53:45 +08:00
|
|
|
mutex_unlock(&moxa_openlock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-03-30 05:23:41 +08:00
|
|
|
return tty_port_block_til_ready(&ch->port, tty, filp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void moxa_close(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
2009-11-30 21:17:51 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2012-07-14 22:31:47 +08:00
|
|
|
ch->cflag = tty->termios.c_cflag;
|
2009-11-30 21:17:51 +08:00
|
|
|
tty_port_close(&ch->port, tty, filp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-08-10 17:15:03 +08:00
|
|
|
static ssize_t moxa_write(struct tty_struct *tty, const u8 *buf, size_t count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2011-04-20 16:43:15 +08:00
|
|
|
unsigned long flags;
|
2008-04-30 15:53:40 +08:00
|
|
|
int len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ch == NULL)
|
2008-04-30 15:53:40 +08:00
|
|
|
return 0;
|
[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
|
|
|
|
2011-04-20 16:43:15 +08:00
|
|
|
spin_lock_irqsave(&moxa_lock, flags);
|
2008-10-13 17:39:58 +08:00
|
|
|
len = MoxaPortWriteData(tty, buf, count);
|
2011-04-20 16:43:15 +08:00
|
|
|
spin_unlock_irqrestore(&moxa_lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-30 21:18:02 +08:00
|
|
|
set_bit(LOWWAIT, &ch->statusflags);
|
2008-04-30 15:53:46 +08:00
|
|
|
return len;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2021-05-05 17:19:15 +08:00
|
|
|
static unsigned int moxa_write_room(struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-10 17:45:33 +08:00
|
|
|
struct moxa_port *ch;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-05-05 17:19:05 +08:00
|
|
|
if (tty->flow.stopped)
|
2008-04-30 15:53:46 +08:00
|
|
|
return 0;
|
2008-04-30 15:53:40 +08:00
|
|
|
ch = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ch == NULL)
|
2008-04-30 15:53:46 +08:00
|
|
|
return 0;
|
2008-04-30 15:53:40 +08:00
|
|
|
return MoxaPortTxFree(ch);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void moxa_flush_buffer(struct tty_struct *tty)
|
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return;
|
2008-04-30 15:53:40 +08:00
|
|
|
MoxaPortFlushData(ch, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
|
|
|
|
2021-05-05 17:19:19 +08:00
|
|
|
static unsigned int moxa_chars_in_buffer(struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2021-05-05 17:19:19 +08:00
|
|
|
unsigned int chars;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
chars = MoxaPortTxQueue(ch);
|
2009-11-30 21:18:18 +08:00
|
|
|
if (chars)
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Make it possible to wakeup anything waiting for output
|
|
|
|
* in tty_ioctl.c, etc.
|
|
|
|
*/
|
2009-11-30 21:18:18 +08:00
|
|
|
set_bit(EMPTYWAIT, &ch->statusflags);
|
2008-04-30 15:53:46 +08:00
|
|
|
return chars;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2011-02-15 00:26:14 +08:00
|
|
|
static int moxa_tiocmget(struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-30 21:18:13 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2023-01-17 17:03:58 +08:00
|
|
|
bool dtr_active, rts_active;
|
2023-01-17 17:03:53 +08:00
|
|
|
int flag = 0;
|
|
|
|
int status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-01-17 17:03:58 +08:00
|
|
|
MoxaPortGetLineOut(ch, &dtr_active, &rts_active);
|
|
|
|
if (dtr_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
flag |= TIOCM_DTR;
|
2023-01-17 17:03:58 +08:00
|
|
|
if (rts_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
flag |= TIOCM_RTS;
|
2023-01-17 17:03:53 +08:00
|
|
|
status = MoxaPortLineStatus(ch);
|
|
|
|
if (status & 1)
|
2005-04-17 06:20:36 +08:00
|
|
|
flag |= TIOCM_CTS;
|
2023-01-17 17:03:53 +08:00
|
|
|
if (status & 2)
|
2005-04-17 06:20:36 +08:00
|
|
|
flag |= TIOCM_DSR;
|
2023-01-17 17:03:53 +08:00
|
|
|
if (status & 4)
|
2005-04-17 06:20:36 +08:00
|
|
|
flag |= TIOCM_CD;
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
2011-02-15 00:26:50 +08:00
|
|
|
static int moxa_tiocmset(struct tty_struct *tty,
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int set, unsigned int clear)
|
|
|
|
{
|
2023-01-17 17:03:58 +08:00
|
|
|
bool dtr_active, rts_active;
|
2008-04-30 15:53:45 +08:00
|
|
|
struct moxa_port *ch;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:45 +08:00
|
|
|
mutex_lock(&moxa_openlock);
|
|
|
|
ch = tty->driver_data;
|
|
|
|
if (!ch) {
|
|
|
|
mutex_unlock(&moxa_openlock);
|
2008-04-30 15:53:43 +08:00
|
|
|
return -EINVAL;
|
2008-04-30 15:53:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-01-17 17:03:58 +08:00
|
|
|
MoxaPortGetLineOut(ch, &dtr_active, &rts_active);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (set & TIOCM_RTS)
|
2023-01-17 17:03:58 +08:00
|
|
|
rts_active = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (set & TIOCM_DTR)
|
2023-01-17 17:03:58 +08:00
|
|
|
dtr_active = true;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (clear & TIOCM_RTS)
|
2023-01-17 17:03:58 +08:00
|
|
|
rts_active = false;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (clear & TIOCM_DTR)
|
2023-01-17 17:03:58 +08:00
|
|
|
dtr_active = false;
|
|
|
|
MoxaPortLineCtrl(ch, dtr_active, rts_active);
|
2008-04-30 15:53:45 +08:00
|
|
|
mutex_unlock(&moxa_openlock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void moxa_set_termios(struct tty_struct *tty,
|
2022-08-16 19:57:39 +08:00
|
|
|
const struct ktermios *old_termios)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:46 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return;
|
2008-02-08 20:18:43 +08:00
|
|
|
moxa_set_tty_param(tty, old_termios);
|
2008-04-30 15:53:46 +08:00
|
|
|
if (!(old_termios->c_cflag & CLOCAL) && C_CLOCAL(tty))
|
2008-07-17 04:56:02 +08:00
|
|
|
wake_up_interruptible(&ch->port.open_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void moxa_stop(struct tty_struct *tty)
|
|
|
|
{
|
2008-04-30 15:53:46 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return;
|
2008-04-30 15:53:40 +08:00
|
|
|
MoxaPortTxDisable(ch);
|
2009-11-30 21:18:02 +08:00
|
|
|
set_bit(TXSTOPPED, &ch->statusflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void moxa_start(struct tty_struct *tty)
|
|
|
|
{
|
2008-04-30 15:53:46 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ch == NULL)
|
|
|
|
return;
|
|
|
|
|
2012-03-07 18:05:00 +08:00
|
|
|
if (!test_bit(TXSTOPPED, &ch->statusflags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
MoxaPortTxEnable(ch);
|
2009-11-30 21:18:02 +08:00
|
|
|
clear_bit(TXSTOPPED, &ch->statusflags);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void moxa_hangup(struct tty_struct *tty)
|
|
|
|
{
|
2009-11-30 21:18:02 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2009-11-30 21:17:51 +08:00
|
|
|
tty_port_hangup(&ch->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-11-30 21:18:13 +08:00
|
|
|
unsigned long flags;
|
2008-04-30 15:53:43 +08:00
|
|
|
dcd = !!dcd;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-11-30 21:18:13 +08:00
|
|
|
spin_lock_irqsave(&p->port.lock, flags);
|
2008-10-13 17:39:58 +08:00
|
|
|
if (dcd != p->DCDState) {
|
2009-11-30 21:18:13 +08:00
|
|
|
p->DCDState = dcd;
|
|
|
|
spin_unlock_irqrestore(&p->port.lock, flags);
|
2013-03-07 20:12:30 +08:00
|
|
|
if (!dcd)
|
|
|
|
tty_port_tty_hangup(&p->port, true);
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
2009-11-30 21:18:13 +08:00
|
|
|
else
|
|
|
|
spin_unlock_irqrestore(&p->port.lock, flags);
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
|
|
|
|
u16 __iomem *ip)
|
|
|
|
{
|
2008-10-13 17:39:58 +08:00
|
|
|
struct tty_struct *tty = tty_port_tty_get(&p->port);
|
2023-01-17 17:03:50 +08:00
|
|
|
bool inited = tty_port_initialized(&p->port);
|
2008-04-30 15:53:43 +08:00
|
|
|
void __iomem *ofsAddr;
|
|
|
|
u16 intr;
|
|
|
|
|
|
|
|
if (tty) {
|
2009-11-30 21:18:02 +08:00
|
|
|
if (test_bit(EMPTYWAIT, &p->statusflags) &&
|
2008-04-30 15:53:43 +08:00
|
|
|
MoxaPortTxQueue(p) == 0) {
|
2009-11-30 21:18:02 +08:00
|
|
|
clear_bit(EMPTYWAIT, &p->statusflags);
|
2008-04-30 15:53:43 +08:00
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
2021-05-05 17:19:05 +08:00
|
|
|
if (test_bit(LOWWAIT, &p->statusflags) && !tty->flow.stopped &&
|
2008-04-30 15:53:43 +08:00
|
|
|
MoxaPortTxQueue(p) <= WAKEUP_CHARS) {
|
2009-11-30 21:18:02 +08:00
|
|
|
clear_bit(LOWWAIT, &p->statusflags);
|
2008-04-30 15:53:43 +08:00
|
|
|
tty_wakeup(tty);
|
|
|
|
}
|
|
|
|
|
2016-04-10 08:11:36 +08:00
|
|
|
if (inited && !tty_throttled(tty) &&
|
2008-04-30 15:53:43 +08:00
|
|
|
MoxaPortRxQueue(p) > 0) { /* RX */
|
|
|
|
MoxaPortReadData(p);
|
2021-11-22 19:16:46 +08:00
|
|
|
tty_flip_buffer_push(&p->port);
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
|
|
|
} else {
|
2009-11-30 21:18:02 +08:00
|
|
|
clear_bit(EMPTYWAIT, &p->statusflags);
|
2008-04-30 15:53:43 +08:00
|
|
|
MoxaPortFlushData(p, 0); /* flush RX */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-30 15:53:42 +08:00
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
if (!handle) /* nothing else to do */
|
2009-04-07 00:34:04 +08:00
|
|
|
goto put;
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
intr = readw(ip); /* port irq status */
|
|
|
|
if (intr == 0)
|
2009-04-07 00:34:04 +08:00
|
|
|
goto put;
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
writew(0, ip); /* ACK port */
|
|
|
|
ofsAddr = p->tableAddr;
|
|
|
|
if (intr & IntrTx) /* disable tx intr */
|
|
|
|
writew(readw(ofsAddr + HostStat) & ~WakeupTx,
|
|
|
|
ofsAddr + HostStat);
|
|
|
|
|
|
|
|
if (!inited)
|
2009-04-07 00:34:04 +08:00
|
|
|
goto put;
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
if (tty && (intr & IntrBreak) && !I_IGNBRK(tty)) { /* BREAK */
|
2013-01-03 22:53:03 +08:00
|
|
|
tty_insert_flip_char(&p->port, 0, TTY_BREAK);
|
2021-11-22 19:16:46 +08:00
|
|
|
tty_flip_buffer_push(&p->port);
|
2008-04-30 15:53:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (intr & IntrLine)
|
|
|
|
moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state);
|
2009-04-07 00:34:04 +08:00
|
|
|
put:
|
|
|
|
tty_kref_put(tty);
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-29 02:28:21 +08:00
|
|
|
static void moxa_poll(struct timer_list *unused)
|
2008-04-30 15:53:43 +08:00
|
|
|
{
|
|
|
|
struct moxa_board_conf *brd;
|
|
|
|
u16 __iomem *ip;
|
2008-04-30 15:53:45 +08:00
|
|
|
unsigned int card, port, served = 0;
|
2008-04-30 15:53:43 +08:00
|
|
|
|
|
|
|
spin_lock(&moxa_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (card = 0; card < MAX_BOARDS; card++) {
|
2008-04-30 15:53:43 +08:00
|
|
|
brd = &moxa_boards[card];
|
|
|
|
if (!brd->ready)
|
2005-04-17 06:20:36 +08:00
|
|
|
continue;
|
2008-04-30 15:53:43 +08:00
|
|
|
|
2008-04-30 15:53:45 +08:00
|
|
|
served++;
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
ip = NULL;
|
|
|
|
if (readb(brd->intPend) == 0xff)
|
|
|
|
ip = brd->intTable + readb(brd->intNdx);
|
|
|
|
|
|
|
|
for (port = 0; port < brd->numPorts; port++)
|
|
|
|
moxa_poll_port(&brd->ports[port], !!ip, ip + port);
|
|
|
|
|
|
|
|
if (ip)
|
|
|
|
writeb(0, brd->intPend); /* ACK */
|
|
|
|
|
|
|
|
if (moxaLowWaterChk) {
|
|
|
|
struct moxa_port *p = brd->ports;
|
|
|
|
for (port = 0; port < brd->numPorts; port++, p++)
|
|
|
|
if (p->lowChkFlag) {
|
|
|
|
p->lowChkFlag = 0;
|
|
|
|
moxa_low_water_check(p->tableAddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-30 15:53:43 +08:00
|
|
|
moxaLowWaterChk = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:45 +08:00
|
|
|
if (served)
|
|
|
|
mod_timer(&moxaTimer, jiffies + HZ / 50);
|
|
|
|
spin_unlock(&moxa_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2022-08-16 19:57:39 +08:00
|
|
|
static void moxa_set_tty_param(struct tty_struct *tty,
|
|
|
|
const struct ktermios *old_termios)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-07-14 22:31:47 +08:00
|
|
|
register struct ktermios *ts = &tty->termios;
|
2008-04-30 15:53:46 +08:00
|
|
|
struct moxa_port *ch = tty->driver_data;
|
2008-02-08 20:18:43 +08:00
|
|
|
int rts, cts, txflow, rxflow, xany, baud;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rts = cts = txflow = rxflow = xany = 0;
|
|
|
|
if (ts->c_cflag & CRTSCTS)
|
|
|
|
rts = cts = 1;
|
|
|
|
if (ts->c_iflag & IXON)
|
|
|
|
txflow = 1;
|
|
|
|
if (ts->c_iflag & IXOFF)
|
|
|
|
rxflow = 1;
|
|
|
|
if (ts->c_iflag & IXANY)
|
|
|
|
xany = 1;
|
2008-02-08 20:18:43 +08:00
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
MoxaPortFlowCtrl(ch, rts, cts, txflow, rxflow, xany);
|
|
|
|
baud = MoxaPortSetTermio(ch, ts, tty_get_baud_rate(tty));
|
2008-02-08 20:18:43 +08:00
|
|
|
if (baud == -1)
|
|
|
|
baud = tty_termios_baud_rate(old_termios);
|
|
|
|
/* Not put the baud rate into the termios data */
|
|
|
|
tty_encode_baud_rate(tty, baud, baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Driver level functions: *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortFlushData(struct moxa_port *port, int mode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
void __iomem *ofsAddr;
|
2008-04-30 15:53:46 +08:00
|
|
|
if (mode < 0 || mode > 2)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2008-04-30 15:53:40 +08:00
|
|
|
ofsAddr = port->tableAddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
moxafunc(ofsAddr, FC_FlushQueue, mode);
|
|
|
|
if (mode != 1) {
|
2008-04-30 15:53:40 +08:00
|
|
|
port->lowChkFlag = 0;
|
2007-10-18 18:06:24 +08:00
|
|
|
moxa_low_water_check(ofsAddr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Moxa Port Number Description:
|
|
|
|
*
|
|
|
|
* MOXA serial driver supports up to 4 MOXA-C218/C320 boards. And,
|
|
|
|
* the port number using in MOXA driver functions will be 0 to 31 for
|
|
|
|
* first MOXA board, 32 to 63 for second, 64 to 95 for third and 96
|
|
|
|
* to 127 for fourth. For example, if you setup three MOXA boards,
|
|
|
|
* first board is C218, second board is C320-16 and third board is
|
|
|
|
* C320-32. The port number of first board (C218 - 8 ports) is from
|
|
|
|
* 0 to 7. The port number of second board (C320 - 16 ports) is form
|
|
|
|
* 32 to 47. The port number of third board (C320 - 32 ports) is from
|
|
|
|
* 64 to 95. And those port numbers form 8 to 31, 48 to 63 and 96 to
|
|
|
|
* 127 will be invalid.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Moxa Functions Description:
|
|
|
|
*
|
|
|
|
* Function 1: Driver initialization routine, this routine must be
|
|
|
|
* called when initialized driver.
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaDriverInit();
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 2: Moxa driver private IOCTL command processing.
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port);
|
|
|
|
*
|
|
|
|
* unsigned int cmd : IOCTL command
|
|
|
|
* unsigned long arg : IOCTL argument
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
* return: 0 (OK)
|
|
|
|
* -EINVAL
|
|
|
|
* -ENOIOCTLCMD
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 6: Enable this port to start Tx/Rx data.
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaPortEnable(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 7: Disable this port
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaPortDisable(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 10: Setting baud rate of this port.
|
|
|
|
* Syntax:
|
2008-04-30 15:53:47 +08:00
|
|
|
* speed_t MoxaPortSetBaud(int port, speed_t baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
* int port : port number (0 - 127)
|
|
|
|
* long baud : baud rate (50 - 115200)
|
|
|
|
*
|
|
|
|
* return: 0 : this port is invalid or baud < 50
|
|
|
|
* 50 - 115200 : the real baud rate set to the port, if
|
|
|
|
* the argument baud is large than maximun
|
|
|
|
* available baud rate, the real setting
|
|
|
|
* baud rate will be the maximun baud rate.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 12: Configure the port.
|
|
|
|
* Syntax:
|
2006-12-08 18:38:45 +08:00
|
|
|
* int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
* int port : port number (0 - 127)
|
2006-12-08 18:38:45 +08:00
|
|
|
* struct ktermios * termio : termio structure pointer
|
2006-10-01 14:27:24 +08:00
|
|
|
* speed_t baud : baud rate
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* return: -1 : this port is invalid or termio == NULL
|
|
|
|
* 0 : setting O.K.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 13: Get the DTR/RTS state of this port.
|
|
|
|
* Syntax:
|
2023-01-17 17:03:53 +08:00
|
|
|
* int MoxaPortGetLineOut(int port, bool *dtrState, bool *rtsState);
|
2005-04-17 06:20:36 +08:00
|
|
|
* int port : port number (0 - 127)
|
2023-01-17 17:03:58 +08:00
|
|
|
* bool * dtr_active : pointer to bool to receive the current DTR
|
2005-04-17 06:20:36 +08:00
|
|
|
* state. (if NULL, this function will not
|
|
|
|
* write to this address)
|
2023-01-17 17:03:58 +08:00
|
|
|
* bool * rts_active : pointer to bool to receive the current RTS
|
2005-04-17 06:20:36 +08:00
|
|
|
* state. (if NULL, this function will not
|
|
|
|
* write to this address)
|
|
|
|
*
|
|
|
|
* return: -1 : this port is invalid
|
|
|
|
* 0 : O.K.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 14: Setting the DTR/RTS output state of this port.
|
|
|
|
* Syntax:
|
2023-01-17 17:03:53 +08:00
|
|
|
* void MoxaPortLineCtrl(int port, bool dtrState, bool rtsState);
|
2005-04-17 06:20:36 +08:00
|
|
|
* int port : port number (0 - 127)
|
2023-01-17 17:03:58 +08:00
|
|
|
* bool dtr_active : DTR output state
|
|
|
|
* bool rts_active : RTS output state
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 15: Setting the flow control of this port.
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaPortFlowCtrl(int port, int rtsFlow, int ctsFlow, int rxFlow,
|
|
|
|
* int txFlow,int xany);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
* int rtsFlow : H/W RTS flow control (0: no, 1: yes)
|
|
|
|
* int ctsFlow : H/W CTS flow control (0: no, 1: yes)
|
|
|
|
* int rxFlow : S/W Rx XON/XOFF flow control (0: no, 1: yes)
|
|
|
|
* int txFlow : S/W Tx XON/XOFF flow control (0: no, 1: yes)
|
|
|
|
* int xany : S/W XANY flow control (0: no, 1: yes)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 16: Get ths line status of this port
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaPortLineStatus(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
* return: Bit 0 - CTS state (0: off, 1: on)
|
|
|
|
* Bit 1 - DSR state (0: off, 1: on)
|
|
|
|
* Bit 2 - DCD state (0: off, 1: on)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 19: Flush the Rx/Tx buffer data of this port.
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaPortFlushData(int port, int mode);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
* int mode
|
|
|
|
* 0 : flush the Rx buffer
|
|
|
|
* 1 : flush the Tx buffer
|
|
|
|
* 2 : flush the Rx and Tx buffer
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 20: Write data.
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaPortWriteData(int port, unsigned char * buffer, int length);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
* unsigned char * buffer : pointer to write data buffer.
|
|
|
|
* int length : write data length
|
|
|
|
*
|
|
|
|
* return: 0 - length : real write data length
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 21: Read data.
|
|
|
|
* Syntax:
|
[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 MoxaPortReadData(int port, struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
* int port : port number (0 - 127)
|
[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
|
|
|
* struct tty_struct *tty : tty for data
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* return: 0 - length : real read data length
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 24: Get the Tx buffer current queued data bytes
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaPortTxQueue(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
* return: .. : Tx buffer current queued data bytes
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 25: Get the Tx buffer current free space
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaPortTxFree(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
* return: .. : Tx buffer current free space
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 26: Get the Rx buffer current queued data bytes
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaPortRxQueue(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
* return: .. : Rx buffer current queued data bytes
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 28: Disable port data transmission.
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaPortTxDisable(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 29: Enable port data transmission.
|
|
|
|
* Syntax:
|
|
|
|
* void MoxaPortTxEnable(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Function 31: Get the received BREAK signal count and reset it.
|
|
|
|
* Syntax:
|
|
|
|
* int MoxaPortResetBrkCnt(int port);
|
|
|
|
* int port : port number (0 - 127)
|
|
|
|
*
|
|
|
|
* return: 0 - .. : BREAK signal count
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortEnable(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
void __iomem *ofsAddr;
|
2008-04-30 15:53:46 +08:00
|
|
|
u16 lowwater = 512;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
ofsAddr = port->tableAddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
writew(lowwater, ofsAddr + Low_water);
|
2008-04-30 15:53:47 +08:00
|
|
|
if (MOXA_IS_320(port->board))
|
2005-04-17 06:20:36 +08:00
|
|
|
moxafunc(ofsAddr, FC_SetBreakIrq, 0);
|
2008-04-30 15:53:46 +08:00
|
|
|
else
|
|
|
|
writew(readw(ofsAddr + HostStat) | WakeupBreak,
|
|
|
|
ofsAddr + HostStat);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
moxafunc(ofsAddr, FC_SetLineIrq, Magic_code);
|
|
|
|
moxafunc(ofsAddr, FC_FlushQueue, 2);
|
|
|
|
|
|
|
|
moxafunc(ofsAddr, FC_EnableCH, Magic_code);
|
|
|
|
MoxaPortLineStatus(port);
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortDisable(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
void __iomem *ofsAddr = port->tableAddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */
|
|
|
|
moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code);
|
|
|
|
writew(0, ofsAddr + HostStat);
|
|
|
|
moxafunc(ofsAddr, FC_DisableCH, Magic_code);
|
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:47 +08:00
|
|
|
static speed_t MoxaPortSetBaud(struct moxa_port *port, speed_t baud)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:47 +08:00
|
|
|
void __iomem *ofsAddr = port->tableAddr;
|
|
|
|
unsigned int clock, val;
|
|
|
|
speed_t max;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:47 +08:00
|
|
|
max = MOXA_IS_320(port->board) ? 460800 : 921600;
|
|
|
|
if (baud < 50)
|
2008-04-30 15:53:46 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (baud > max)
|
|
|
|
baud = max;
|
2008-04-30 15:53:47 +08:00
|
|
|
clock = 921600;
|
2005-04-17 06:20:36 +08:00
|
|
|
val = clock / baud;
|
|
|
|
moxafunc(ofsAddr, FC_SetBaud, val);
|
|
|
|
baud = clock / val;
|
2008-04-30 15:53:46 +08:00
|
|
|
return baud;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static int MoxaPortSetTermio(struct moxa_port *port, struct ktermios *termio,
|
|
|
|
speed_t baud)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
void __iomem *ofsAddr;
|
|
|
|
tcflag_t mode = 0;
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
ofsAddr = port->tableAddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
mode = termio->c_cflag & CSIZE;
|
|
|
|
if (mode == CS5)
|
|
|
|
mode = MX_CS5;
|
|
|
|
else if (mode == CS6)
|
|
|
|
mode = MX_CS6;
|
|
|
|
else if (mode == CS7)
|
|
|
|
mode = MX_CS7;
|
|
|
|
else if (mode == CS8)
|
|
|
|
mode = MX_CS8;
|
|
|
|
|
|
|
|
if (termio->c_cflag & CSTOPB) {
|
|
|
|
if (mode == MX_CS5)
|
|
|
|
mode |= MX_STOP15;
|
|
|
|
else
|
|
|
|
mode |= MX_STOP2;
|
|
|
|
} else
|
|
|
|
mode |= MX_STOP1;
|
|
|
|
|
|
|
|
if (termio->c_cflag & PARENB) {
|
2017-11-28 18:55:17 +08:00
|
|
|
if (termio->c_cflag & PARODD) {
|
|
|
|
if (termio->c_cflag & CMSPAR)
|
|
|
|
mode |= MX_PARMARK;
|
|
|
|
else
|
|
|
|
mode |= MX_PARODD;
|
|
|
|
} else {
|
|
|
|
if (termio->c_cflag & CMSPAR)
|
|
|
|
mode |= MX_PARSPACE;
|
|
|
|
else
|
|
|
|
mode |= MX_PAREVEN;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
} else
|
|
|
|
mode |= MX_PARNONE;
|
|
|
|
|
2008-04-30 15:53:46 +08:00
|
|
|
moxafunc(ofsAddr, FC_SetDataMode, (u16)mode);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:47 +08:00
|
|
|
if (MOXA_IS_320(port->board) && baud >= 921600)
|
|
|
|
return -1;
|
|
|
|
|
2008-02-08 20:18:43 +08:00
|
|
|
baud = MoxaPortSetBaud(port, baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (termio->c_iflag & (IXON | IXOFF | IXANY)) {
|
2009-11-30 21:17:57 +08:00
|
|
|
spin_lock_irq(&moxafunc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
writeb(termio->c_cc[VSTART], ofsAddr + FuncArg);
|
|
|
|
writeb(termio->c_cc[VSTOP], ofsAddr + FuncArg1);
|
|
|
|
writeb(FC_SetXonXoff, ofsAddr + FuncCode);
|
2007-10-18 18:06:24 +08:00
|
|
|
moxa_wait_finish(ofsAddr);
|
2009-11-30 21:18:02 +08:00
|
|
|
spin_unlock_irq(&moxafunc_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
}
|
2008-04-30 15:53:46 +08:00
|
|
|
return baud;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-01-17 17:03:58 +08:00
|
|
|
static int MoxaPortGetLineOut(struct moxa_port *port, bool *dtr_active,
|
|
|
|
bool *rts_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-01-17 17:03:58 +08:00
|
|
|
if (dtr_active)
|
|
|
|
*dtr_active = port->lineCtrl & DTR_ON;
|
|
|
|
if (rts_active)
|
|
|
|
*rts_active = port->lineCtrl & RTS_ON;
|
2008-04-30 15:53:40 +08:00
|
|
|
|
2008-04-30 15:53:46 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-01-17 17:03:58 +08:00
|
|
|
static void MoxaPortLineCtrl(struct moxa_port *port, bool dtr_active, bool rts_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:46 +08:00
|
|
|
u8 mode = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-01-17 17:03:58 +08:00
|
|
|
if (dtr_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
mode |= DTR_ON;
|
2023-01-17 17:03:58 +08:00
|
|
|
if (rts_active)
|
2005-04-17 06:20:36 +08:00
|
|
|
mode |= RTS_ON;
|
2008-04-30 15:53:40 +08:00
|
|
|
port->lineCtrl = mode;
|
|
|
|
moxafunc(port->tableAddr, FC_LineControl, mode);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortFlowCtrl(struct moxa_port *port, int rts, int cts,
|
|
|
|
int txflow, int rxflow, int txany)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
int mode = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (rts)
|
|
|
|
mode |= RTS_FlowCtl;
|
|
|
|
if (cts)
|
|
|
|
mode |= CTS_FlowCtl;
|
|
|
|
if (txflow)
|
|
|
|
mode |= Tx_FlowCtl;
|
|
|
|
if (rxflow)
|
|
|
|
mode |= Rx_FlowCtl;
|
|
|
|
if (txany)
|
|
|
|
mode |= IXM_IXANY;
|
2008-04-30 15:53:40 +08:00
|
|
|
moxafunc(port->tableAddr, FC_SetFlowCtl, mode);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static int MoxaPortLineStatus(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
void __iomem *ofsAddr;
|
|
|
|
int val;
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
ofsAddr = port->tableAddr;
|
2009-11-30 21:17:57 +08:00
|
|
|
if (MOXA_IS_320(port->board))
|
|
|
|
val = moxafuncret(ofsAddr, FC_LineStatus, 0);
|
|
|
|
else
|
2005-04-17 06:20:36 +08:00
|
|
|
val = readw(ofsAddr + FlagStat) >> 4;
|
|
|
|
val &= 0x0B;
|
2008-04-30 15:53:43 +08:00
|
|
|
if (val & 8)
|
2005-04-17 06:20:36 +08:00
|
|
|
val |= 4;
|
2008-04-30 15:53:43 +08:00
|
|
|
moxa_new_dcdstate(port, val & 8);
|
2005-04-17 06:20:36 +08:00
|
|
|
val &= 7;
|
2008-04-30 15:53:43 +08:00
|
|
|
return val;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-08-10 17:15:01 +08:00
|
|
|
static int MoxaPortWriteData(struct tty_struct *tty, const u8 *buffer, int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-10-13 17:39:58 +08:00
|
|
|
struct moxa_port *port = tty->driver_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
void __iomem *baseAddr, *ofsAddr, *ofs;
|
2008-04-30 15:53:44 +08:00
|
|
|
unsigned int c, total;
|
|
|
|
u16 head, tail, tx_mask, spage, epage;
|
|
|
|
u16 pageno, pageofs, bufhead;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
ofsAddr = port->tableAddr;
|
|
|
|
baseAddr = port->board->basemem;
|
2005-04-17 06:20:36 +08:00
|
|
|
tx_mask = readw(ofsAddr + TX_mask);
|
|
|
|
spage = readw(ofsAddr + Page_txb);
|
|
|
|
epage = readw(ofsAddr + EndPage_txb);
|
|
|
|
tail = readw(ofsAddr + TXwptr);
|
|
|
|
head = readw(ofsAddr + TXrptr);
|
2008-04-30 15:53:44 +08:00
|
|
|
c = (head > tail) ? (head - tail - 1) : (head - tail + tx_mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (c > len)
|
|
|
|
c = len;
|
2008-07-17 04:56:02 +08:00
|
|
|
moxaLog.txcnt[port->port.tty->index] += c;
|
2005-04-17 06:20:36 +08:00
|
|
|
total = c;
|
|
|
|
if (spage == epage) {
|
|
|
|
bufhead = readw(ofsAddr + Ofs_txb);
|
|
|
|
writew(spage, baseAddr + Control_reg);
|
|
|
|
while (c > 0) {
|
|
|
|
if (head > tail)
|
|
|
|
len = head - tail - 1;
|
|
|
|
else
|
|
|
|
len = tx_mask + 1 - tail;
|
|
|
|
len = (c > len) ? len : c;
|
|
|
|
ofs = baseAddr + DynPage_addr + bufhead + tail;
|
2008-04-30 15:53:44 +08:00
|
|
|
memcpy_toio(ofs, buffer, len);
|
|
|
|
buffer += len;
|
2005-04-17 06:20:36 +08:00
|
|
|
tail = (tail + len) & tx_mask;
|
|
|
|
c -= len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pageno = spage + (tail >> 13);
|
|
|
|
pageofs = tail & Page_mask;
|
2008-04-30 15:53:44 +08:00
|
|
|
while (c > 0) {
|
|
|
|
len = Page_size - pageofs;
|
|
|
|
if (len > c)
|
|
|
|
len = c;
|
2005-04-17 06:20:36 +08:00
|
|
|
writeb(pageno, baseAddr + Control_reg);
|
|
|
|
ofs = baseAddr + DynPage_addr + pageofs;
|
2008-04-30 15:53:44 +08:00
|
|
|
memcpy_toio(ofs, buffer, len);
|
|
|
|
buffer += len;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (++pageno == epage)
|
|
|
|
pageno = spage;
|
|
|
|
pageofs = 0;
|
2008-04-30 15:53:44 +08:00
|
|
|
c -= len;
|
|
|
|
}
|
|
|
|
tail = (tail + total) & tx_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-30 15:53:44 +08:00
|
|
|
writew(tail, ofsAddr + TXwptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
writeb(1, ofsAddr + CD180TXirq); /* start to send */
|
2008-04-30 15:53:44 +08:00
|
|
|
return total;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:43 +08:00
|
|
|
static int MoxaPortReadData(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-07-17 04:56:02 +08:00
|
|
|
struct tty_struct *tty = port->port.tty;
|
2008-04-30 15:53:44 +08:00
|
|
|
unsigned char *dst;
|
2005-04-17 06:20:36 +08:00
|
|
|
void __iomem *baseAddr, *ofsAddr, *ofs;
|
2008-04-30 15:53:44 +08:00
|
|
|
unsigned int count, len, total;
|
|
|
|
u16 tail, rx_mask, spage, epage;
|
|
|
|
u16 pageno, pageofs, bufhead, head;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
ofsAddr = port->tableAddr;
|
|
|
|
baseAddr = port->board->basemem;
|
2005-04-17 06:20:36 +08:00
|
|
|
head = readw(ofsAddr + RXrptr);
|
|
|
|
tail = readw(ofsAddr + RXwptr);
|
|
|
|
rx_mask = readw(ofsAddr + RX_mask);
|
|
|
|
spage = readw(ofsAddr + Page_rxb);
|
|
|
|
epage = readw(ofsAddr + EndPage_rxb);
|
2008-04-30 15:53:44 +08:00
|
|
|
count = (tail >= head) ? (tail - head) : (tail - head + rx_mask + 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (count == 0)
|
[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
|
|
|
return 0;
|
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
|
|
|
total = count;
|
2008-04-30 15:53:43 +08:00
|
|
|
moxaLog.rxcnt[tty->index] += total;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (spage == epage) {
|
|
|
|
bufhead = readw(ofsAddr + Ofs_rxb);
|
|
|
|
writew(spage, baseAddr + Control_reg);
|
|
|
|
while (count > 0) {
|
|
|
|
ofs = baseAddr + DynPage_addr + bufhead + head;
|
2008-04-30 15:53:44 +08:00
|
|
|
len = (tail >= head) ? (tail - head) :
|
|
|
|
(rx_mask + 1 - head);
|
2013-01-03 22:53:02 +08:00
|
|
|
len = tty_prepare_flip_string(&port->port, &dst,
|
2008-04-30 15:53:44 +08:00
|
|
|
min(len, count));
|
|
|
|
memcpy_fromio(dst, ofs, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
head = (head + len) & rx_mask;
|
|
|
|
count -= len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pageno = spage + (head >> 13);
|
|
|
|
pageofs = head & Page_mask;
|
2008-04-30 15:53:44 +08:00
|
|
|
while (count > 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
writew(pageno, baseAddr + Control_reg);
|
|
|
|
ofs = baseAddr + DynPage_addr + pageofs;
|
2013-01-03 22:53:02 +08:00
|
|
|
len = tty_prepare_flip_string(&port->port, &dst,
|
2008-04-30 15:53:44 +08:00
|
|
|
min(Page_size - pageofs, count));
|
|
|
|
memcpy_fromio(dst, ofs, len);
|
|
|
|
|
|
|
|
count -= len;
|
|
|
|
pageofs = (pageofs + len) & Page_mask;
|
|
|
|
if (pageofs == 0 && ++pageno == epage)
|
2005-04-17 06:20:36 +08:00
|
|
|
pageno = spage;
|
2008-04-30 15:53:44 +08:00
|
|
|
}
|
|
|
|
head = (head + total) & rx_mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-30 15:53:44 +08:00
|
|
|
writew(head, ofsAddr + RXrptr);
|
|
|
|
if (readb(ofsAddr + FlagStat) & Xoff_state) {
|
2005-04-17 06:20:36 +08:00
|
|
|
moxaLowWaterChk = 1;
|
2008-04-30 15:53:40 +08:00
|
|
|
port->lowChkFlag = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-04-30 15:53:44 +08:00
|
|
|
return total;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-05 17:19:19 +08:00
|
|
|
static unsigned int MoxaPortTxQueue(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
void __iomem *ofsAddr = port->tableAddr;
|
2008-04-30 15:53:44 +08:00
|
|
|
u16 rptr, wptr, mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rptr = readw(ofsAddr + TXrptr);
|
|
|
|
wptr = readw(ofsAddr + TXwptr);
|
|
|
|
mask = readw(ofsAddr + TX_mask);
|
2008-04-30 15:53:44 +08:00
|
|
|
return (wptr - rptr) & mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2021-05-05 17:19:15 +08:00
|
|
|
static unsigned int MoxaPortTxFree(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
void __iomem *ofsAddr = port->tableAddr;
|
2008-04-30 15:53:44 +08:00
|
|
|
u16 rptr, wptr, mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rptr = readw(ofsAddr + TXrptr);
|
|
|
|
wptr = readw(ofsAddr + TXwptr);
|
|
|
|
mask = readw(ofsAddr + TX_mask);
|
2008-04-30 15:53:44 +08:00
|
|
|
return mask - ((wptr - rptr) & mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static int MoxaPortRxQueue(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
void __iomem *ofsAddr = port->tableAddr;
|
2008-04-30 15:53:44 +08:00
|
|
|
u16 rptr, wptr, mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
rptr = readw(ofsAddr + RXrptr);
|
|
|
|
wptr = readw(ofsAddr + RXwptr);
|
|
|
|
mask = readw(ofsAddr + RX_mask);
|
2008-04-30 15:53:44 +08:00
|
|
|
return (wptr - rptr) & mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortTxDisable(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
moxafunc(port->tableAddr, FC_SetXoffState, Magic_code);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaPortTxEnable(struct moxa_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-09-12 10:01:00 +08:00
|
|
|
static int moxa_get_serial_info(struct tty_struct *tty,
|
|
|
|
struct serial_struct *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-12 10:01:00 +08:00
|
|
|
struct moxa_port *info = tty->driver_data;
|
|
|
|
|
|
|
|
if (tty->index == MAX_PORTS)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!info)
|
|
|
|
return -ENODEV;
|
|
|
|
mutex_lock(&info->port.mutex);
|
2021-08-25 15:24:05 +08:00
|
|
|
ss->type = info->type;
|
|
|
|
ss->line = info->port.tty->index;
|
|
|
|
ss->flags = info->port.flags;
|
|
|
|
ss->baud_base = 921600;
|
2021-04-07 18:23:28 +08:00
|
|
|
ss->close_delay = jiffies_to_msecs(info->port.close_delay) / 10;
|
2018-09-12 10:01:00 +08:00
|
|
|
mutex_unlock(&info->port.mutex);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-09-12 10:01:00 +08:00
|
|
|
static int moxa_set_serial_info(struct tty_struct *tty,
|
|
|
|
struct serial_struct *ss)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-12 10:01:00 +08:00
|
|
|
struct moxa_port *info = tty->driver_data;
|
2021-04-07 18:23:29 +08:00
|
|
|
unsigned int close_delay;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-12 10:01:00 +08:00
|
|
|
if (tty->index == MAX_PORTS)
|
|
|
|
return -EINVAL;
|
|
|
|
if (!info)
|
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-04-07 18:23:29 +08:00
|
|
|
close_delay = msecs_to_jiffies(ss->close_delay * 10);
|
|
|
|
|
2018-09-12 10:01:00 +08:00
|
|
|
mutex_lock(&info->port.mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!capable(CAP_SYS_ADMIN)) {
|
2021-04-07 18:23:29 +08:00
|
|
|
if (close_delay != info->port.close_delay ||
|
|
|
|
ss->type != info->type ||
|
|
|
|
((ss->flags & ~ASYNC_USR_MASK) !=
|
2018-09-12 10:01:00 +08:00
|
|
|
(info->port.flags & ~ASYNC_USR_MASK))) {
|
|
|
|
mutex_unlock(&info->port.mutex);
|
2008-04-30 15:53:46 +08:00
|
|
|
return -EPERM;
|
2018-09-12 10:01:00 +08:00
|
|
|
}
|
2021-04-07 18:23:29 +08:00
|
|
|
} else {
|
|
|
|
info->port.close_delay = close_delay;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-04-07 18:23:29 +08:00
|
|
|
MoxaSetFifo(info, ss->type == PORT_16550A);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2021-04-07 18:23:29 +08:00
|
|
|
info->type = ss->type;
|
|
|
|
}
|
2018-09-12 10:01:00 +08:00
|
|
|
mutex_unlock(&info->port.mutex);
|
2008-04-30 15:53:46 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Static local functions: *
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-04-30 15:53:40 +08:00
|
|
|
static void MoxaSetFifo(struct moxa_port *port, int enable)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-30 15:53:40 +08:00
|
|
|
void __iomem *ofsAddr = port->tableAddr;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!enable) {
|
|
|
|
moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0);
|
|
|
|
moxafunc(ofsAddr, FC_SetTxFIFOCnt, 1);
|
|
|
|
} else {
|
|
|
|
moxafunc(ofsAddr, FC_SetRxFIFOTrig, 3);
|
|
|
|
moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16);
|
|
|
|
}
|
|
|
|
}
|