/drivers/char/synclink.c

https://bitbucket.org/evzijst/gittest · C · 8214 lines · 4490 code · 1386 blank · 2338 comment · 948 complexity · c6885025eab792ef4139b80b7ffa6901 MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. * linux/drivers/char/synclink.c
  3. *
  4. * $Id: synclink.c,v 4.28 2004/08/11 19:30:01 paulkf Exp $
  5. *
  6. * Device driver for Microgate SyncLink ISA and PCI
  7. * high speed multiprotocol serial adapters.
  8. *
  9. * written by Paul Fulghum for Microgate Corporation
  10. * paulkf@microgate.com
  11. *
  12. * Microgate and SyncLink are trademarks of Microgate Corporation
  13. *
  14. * Derived from serial.c written by Theodore Ts'o and Linus Torvalds
  15. *
  16. * Original release 01/11/99
  17. *
  18. * This code is released under the GNU General Public License (GPL)
  19. *
  20. * This driver is primarily intended for use in synchronous
  21. * HDLC mode. Asynchronous mode is also provided.
  22. *
  23. * When operating in synchronous mode, each call to mgsl_write()
  24. * contains exactly one complete HDLC frame. Calling mgsl_put_char
  25. * will start assembling an HDLC frame that will not be sent until
  26. * mgsl_flush_chars or mgsl_write is called.
  27. *
  28. * Synchronous receive data is reported as complete frames. To accomplish
  29. * this, the TTY flip buffer is bypassed (too small to hold largest
  30. * frame and may fragment frames) and the line discipline
  31. * receive entry point is called directly.
  32. *
  33. * This driver has been tested with a slightly modified ppp.c driver
  34. * for synchronous PPP.
  35. *
  36. * 2000/02/16
  37. * Added interface for syncppp.c driver (an alternate synchronous PPP
  38. * implementation that also supports Cisco HDLC). Each device instance
  39. * registers as a tty device AND a network device (if dosyncppp option
  40. * is set for the device). The functionality is determined by which
  41. * device interface is opened.
  42. *
  43. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  44. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  45. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  47. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  48. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  49. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  50. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  51. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  52. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  53. * OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55. #if defined(__i386__)
  56. # define BREAKPOINT() asm(" int $3");
  57. #else
  58. # define BREAKPOINT() { }
  59. #endif
  60. #define MAX_ISA_DEVICES 10
  61. #define MAX_PCI_DEVICES 10
  62. #define MAX_TOTAL_DEVICES 20
  63. #include <linux/config.h>
  64. #include <linux/module.h>
  65. #include <linux/errno.h>
  66. #include <linux/signal.h>
  67. #include <linux/sched.h>
  68. #include <linux/timer.h>
  69. #include <linux/interrupt.h>
  70. #include <linux/pci.h>
  71. #include <linux/tty.h>
  72. #include <linux/tty_flip.h>
  73. #include <linux/serial.h>
  74. #include <linux/major.h>
  75. #include <linux/string.h>
  76. #include <linux/fcntl.h>
  77. #include <linux/ptrace.h>
  78. #include <linux/ioport.h>
  79. #include <linux/mm.h>
  80. #include <linux/slab.h>
  81. #include <linux/delay.h>
  82. #include <linux/netdevice.h>
  83. #include <linux/vmalloc.h>
  84. #include <linux/init.h>
  85. #include <asm/serial.h>
  86. #include <linux/delay.h>
  87. #include <linux/ioctl.h>
  88. #include <asm/system.h>
  89. #include <asm/io.h>
  90. #include <asm/irq.h>
  91. #include <asm/dma.h>
  92. #include <linux/bitops.h>
  93. #include <asm/types.h>
  94. #include <linux/termios.h>
  95. #include <linux/workqueue.h>
  96. #include <linux/hdlc.h>
  97. #ifdef CONFIG_HDLC_MODULE
  98. #define CONFIG_HDLC 1
  99. #endif
  100. #define GET_USER(error,value,addr) error = get_user(value,addr)
  101. #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
  102. #define PUT_USER(error,value,addr) error = put_user(value,addr)
  103. #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
  104. #include <asm/uaccess.h>
  105. #include "linux/synclink.h"
  106. #define RCLRVALUE 0xffff
  107. static MGSL_PARAMS default_params = {
  108. MGSL_MODE_HDLC, /* unsigned long mode */
  109. 0, /* unsigned char loopback; */
  110. HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
  111. HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
  112. 0, /* unsigned long clock_speed; */
  113. 0xff, /* unsigned char addr_filter; */
  114. HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
  115. HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
  116. HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
  117. 9600, /* unsigned long data_rate; */
  118. 8, /* unsigned char data_bits; */
  119. 1, /* unsigned char stop_bits; */
  120. ASYNC_PARITY_NONE /* unsigned char parity; */
  121. };
  122. #define SHARED_MEM_ADDRESS_SIZE 0x40000
  123. #define BUFFERLISTSIZE (PAGE_SIZE)
  124. #define DMABUFFERSIZE (PAGE_SIZE)
  125. #define MAXRXFRAMES 7
  126. typedef struct _DMABUFFERENTRY
  127. {
  128. u32 phys_addr; /* 32-bit flat physical address of data buffer */
  129. u16 count; /* buffer size/data count */
  130. u16 status; /* Control/status field */
  131. u16 rcc; /* character count field */
  132. u16 reserved; /* padding required by 16C32 */
  133. u32 link; /* 32-bit flat link to next buffer entry */
  134. char *virt_addr; /* virtual address of data buffer */
  135. u32 phys_entry; /* physical address of this buffer entry */
  136. } DMABUFFERENTRY, *DMAPBUFFERENTRY;
  137. /* The queue of BH actions to be performed */
  138. #define BH_RECEIVE 1
  139. #define BH_TRANSMIT 2
  140. #define BH_STATUS 4
  141. #define IO_PIN_SHUTDOWN_LIMIT 100
  142. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  143. struct _input_signal_events {
  144. int ri_up;
  145. int ri_down;
  146. int dsr_up;
  147. int dsr_down;
  148. int dcd_up;
  149. int dcd_down;
  150. int cts_up;
  151. int cts_down;
  152. };
  153. /* transmit holding buffer definitions*/
  154. #define MAX_TX_HOLDING_BUFFERS 5
  155. struct tx_holding_buffer {
  156. int buffer_size;
  157. unsigned char * buffer;
  158. };
  159. /*
  160. * Device instance data structure
  161. */
  162. struct mgsl_struct {
  163. int magic;
  164. int flags;
  165. int count; /* count of opens */
  166. int line;
  167. int hw_version;
  168. unsigned short close_delay;
  169. unsigned short closing_wait; /* time to wait before closing */
  170. struct mgsl_icount icount;
  171. struct tty_struct *tty;
  172. int timeout;
  173. int x_char; /* xon/xoff character */
  174. int blocked_open; /* # of blocked opens */
  175. u16 read_status_mask;
  176. u16 ignore_status_mask;
  177. unsigned char *xmit_buf;
  178. int xmit_head;
  179. int xmit_tail;
  180. int xmit_cnt;
  181. wait_queue_head_t open_wait;
  182. wait_queue_head_t close_wait;
  183. wait_queue_head_t status_event_wait_q;
  184. wait_queue_head_t event_wait_q;
  185. struct timer_list tx_timer; /* HDLC transmit timeout timer */
  186. struct mgsl_struct *next_device; /* device list link */
  187. spinlock_t irq_spinlock; /* spinlock for synchronizing with ISR */
  188. struct work_struct task; /* task structure for scheduling bh */
  189. u32 EventMask; /* event trigger mask */
  190. u32 RecordedEvents; /* pending events */
  191. u32 max_frame_size; /* as set by device config */
  192. u32 pending_bh;
  193. int bh_running; /* Protection from multiple */
  194. int isr_overflow;
  195. int bh_requested;
  196. int dcd_chkcount; /* check counts to prevent */
  197. int cts_chkcount; /* too many IRQs if a signal */
  198. int dsr_chkcount; /* is floating */
  199. int ri_chkcount;
  200. char *buffer_list; /* virtual address of Rx & Tx buffer lists */
  201. unsigned long buffer_list_phys;
  202. unsigned int rx_buffer_count; /* count of total allocated Rx buffers */
  203. DMABUFFERENTRY *rx_buffer_list; /* list of receive buffer entries */
  204. unsigned int current_rx_buffer;
  205. int num_tx_dma_buffers; /* number of tx dma frames required */
  206. int tx_dma_buffers_used;
  207. unsigned int tx_buffer_count; /* count of total allocated Tx buffers */
  208. DMABUFFERENTRY *tx_buffer_list; /* list of transmit buffer entries */
  209. int start_tx_dma_buffer; /* tx dma buffer to start tx dma operation */
  210. int current_tx_buffer; /* next tx dma buffer to be loaded */
  211. unsigned char *intermediate_rxbuffer;
  212. int num_tx_holding_buffers; /* number of tx holding buffer allocated */
  213. int get_tx_holding_index; /* next tx holding buffer for adapter to load */
  214. int put_tx_holding_index; /* next tx holding buffer to store user request */
  215. int tx_holding_count; /* number of tx holding buffers waiting */
  216. struct tx_holding_buffer tx_holding_buffers[MAX_TX_HOLDING_BUFFERS];
  217. int rx_enabled;
  218. int rx_overflow;
  219. int rx_rcc_underrun;
  220. int tx_enabled;
  221. int tx_active;
  222. u32 idle_mode;
  223. u16 cmr_value;
  224. u16 tcsr_value;
  225. char device_name[25]; /* device instance name */
  226. unsigned int bus_type; /* expansion bus type (ISA,EISA,PCI) */
  227. unsigned char bus; /* expansion bus number (zero based) */
  228. unsigned char function; /* PCI device number */
  229. unsigned int io_base; /* base I/O address of adapter */
  230. unsigned int io_addr_size; /* size of the I/O address range */
  231. int io_addr_requested; /* nonzero if I/O address requested */
  232. unsigned int irq_level; /* interrupt level */
  233. unsigned long irq_flags;
  234. int irq_requested; /* nonzero if IRQ requested */
  235. unsigned int dma_level; /* DMA channel */
  236. int dma_requested; /* nonzero if dma channel requested */
  237. u16 mbre_bit;
  238. u16 loopback_bits;
  239. u16 usc_idle_mode;
  240. MGSL_PARAMS params; /* communications parameters */
  241. unsigned char serial_signals; /* current serial signal states */
  242. int irq_occurred; /* for diagnostics use */
  243. unsigned int init_error; /* Initialization startup error (DIAGS) */
  244. int fDiagnosticsmode; /* Driver in Diagnostic mode? (DIAGS) */
  245. u32 last_mem_alloc;
  246. unsigned char* memory_base; /* shared memory address (PCI only) */
  247. u32 phys_memory_base;
  248. int shared_mem_requested;
  249. unsigned char* lcr_base; /* local config registers (PCI only) */
  250. u32 phys_lcr_base;
  251. u32 lcr_offset;
  252. int lcr_mem_requested;
  253. u32 misc_ctrl_value;
  254. char flag_buf[MAX_ASYNC_BUFFER_SIZE];
  255. char char_buf[MAX_ASYNC_BUFFER_SIZE];
  256. BOOLEAN drop_rts_on_tx_done;
  257. BOOLEAN loopmode_insert_requested;
  258. BOOLEAN loopmode_send_done_requested;
  259. struct _input_signal_events input_signal_events;
  260. /* generic HDLC device parts */
  261. int netcount;
  262. int dosyncppp;
  263. spinlock_t netlock;
  264. #ifdef CONFIG_HDLC
  265. struct net_device *netdev;
  266. #endif
  267. };
  268. #define MGSL_MAGIC 0x5401
  269. /*
  270. * The size of the serial xmit buffer is 1 page, or 4096 bytes
  271. */
  272. #ifndef SERIAL_XMIT_SIZE
  273. #define SERIAL_XMIT_SIZE 4096
  274. #endif
  275. /*
  276. * These macros define the offsets used in calculating the
  277. * I/O address of the specified USC registers.
  278. */
  279. #define DCPIN 2 /* Bit 1 of I/O address */
  280. #define SDPIN 4 /* Bit 2 of I/O address */
  281. #define DCAR 0 /* DMA command/address register */
  282. #define CCAR SDPIN /* channel command/address register */
  283. #define DATAREG DCPIN + SDPIN /* serial data register */
  284. #define MSBONLY 0x41
  285. #define LSBONLY 0x40
  286. /*
  287. * These macros define the register address (ordinal number)
  288. * used for writing address/value pairs to the USC.
  289. */
  290. #define CMR 0x02 /* Channel mode Register */
  291. #define CCSR 0x04 /* Channel Command/status Register */
  292. #define CCR 0x06 /* Channel Control Register */
  293. #define PSR 0x08 /* Port status Register */
  294. #define PCR 0x0a /* Port Control Register */
  295. #define TMDR 0x0c /* Test mode Data Register */
  296. #define TMCR 0x0e /* Test mode Control Register */
  297. #define CMCR 0x10 /* Clock mode Control Register */
  298. #define HCR 0x12 /* Hardware Configuration Register */
  299. #define IVR 0x14 /* Interrupt Vector Register */
  300. #define IOCR 0x16 /* Input/Output Control Register */
  301. #define ICR 0x18 /* Interrupt Control Register */
  302. #define DCCR 0x1a /* Daisy Chain Control Register */
  303. #define MISR 0x1c /* Misc Interrupt status Register */
  304. #define SICR 0x1e /* status Interrupt Control Register */
  305. #define RDR 0x20 /* Receive Data Register */
  306. #define RMR 0x22 /* Receive mode Register */
  307. #define RCSR 0x24 /* Receive Command/status Register */
  308. #define RICR 0x26 /* Receive Interrupt Control Register */
  309. #define RSR 0x28 /* Receive Sync Register */
  310. #define RCLR 0x2a /* Receive count Limit Register */
  311. #define RCCR 0x2c /* Receive Character count Register */
  312. #define TC0R 0x2e /* Time Constant 0 Register */
  313. #define TDR 0x30 /* Transmit Data Register */
  314. #define TMR 0x32 /* Transmit mode Register */
  315. #define TCSR 0x34 /* Transmit Command/status Register */
  316. #define TICR 0x36 /* Transmit Interrupt Control Register */
  317. #define TSR 0x38 /* Transmit Sync Register */
  318. #define TCLR 0x3a /* Transmit count Limit Register */
  319. #define TCCR 0x3c /* Transmit Character count Register */
  320. #define TC1R 0x3e /* Time Constant 1 Register */
  321. /*
  322. * MACRO DEFINITIONS FOR DMA REGISTERS
  323. */
  324. #define DCR 0x06 /* DMA Control Register (shared) */
  325. #define DACR 0x08 /* DMA Array count Register (shared) */
  326. #define BDCR 0x12 /* Burst/Dwell Control Register (shared) */
  327. #define DIVR 0x14 /* DMA Interrupt Vector Register (shared) */
  328. #define DICR 0x18 /* DMA Interrupt Control Register (shared) */
  329. #define CDIR 0x1a /* Clear DMA Interrupt Register (shared) */
  330. #define SDIR 0x1c /* Set DMA Interrupt Register (shared) */
  331. #define TDMR 0x02 /* Transmit DMA mode Register */
  332. #define TDIAR 0x1e /* Transmit DMA Interrupt Arm Register */
  333. #define TBCR 0x2a /* Transmit Byte count Register */
  334. #define TARL 0x2c /* Transmit Address Register (low) */
  335. #define TARU 0x2e /* Transmit Address Register (high) */
  336. #define NTBCR 0x3a /* Next Transmit Byte count Register */
  337. #define NTARL 0x3c /* Next Transmit Address Register (low) */
  338. #define NTARU 0x3e /* Next Transmit Address Register (high) */
  339. #define RDMR 0x82 /* Receive DMA mode Register (non-shared) */
  340. #define RDIAR 0x9e /* Receive DMA Interrupt Arm Register */
  341. #define RBCR 0xaa /* Receive Byte count Register */
  342. #define RARL 0xac /* Receive Address Register (low) */
  343. #define RARU 0xae /* Receive Address Register (high) */
  344. #define NRBCR 0xba /* Next Receive Byte count Register */
  345. #define NRARL 0xbc /* Next Receive Address Register (low) */
  346. #define NRARU 0xbe /* Next Receive Address Register (high) */
  347. /*
  348. * MACRO DEFINITIONS FOR MODEM STATUS BITS
  349. */
  350. #define MODEMSTATUS_DTR 0x80
  351. #define MODEMSTATUS_DSR 0x40
  352. #define MODEMSTATUS_RTS 0x20
  353. #define MODEMSTATUS_CTS 0x10
  354. #define MODEMSTATUS_RI 0x04
  355. #define MODEMSTATUS_DCD 0x01
  356. /*
  357. * Channel Command/Address Register (CCAR) Command Codes
  358. */
  359. #define RTCmd_Null 0x0000
  360. #define RTCmd_ResetHighestIus 0x1000
  361. #define RTCmd_TriggerChannelLoadDma 0x2000
  362. #define RTCmd_TriggerRxDma 0x2800
  363. #define RTCmd_TriggerTxDma 0x3000
  364. #define RTCmd_TriggerRxAndTxDma 0x3800
  365. #define RTCmd_PurgeRxFifo 0x4800
  366. #define RTCmd_PurgeTxFifo 0x5000
  367. #define RTCmd_PurgeRxAndTxFifo 0x5800
  368. #define RTCmd_LoadRcc 0x6800
  369. #define RTCmd_LoadTcc 0x7000
  370. #define RTCmd_LoadRccAndTcc 0x7800
  371. #define RTCmd_LoadTC0 0x8800
  372. #define RTCmd_LoadTC1 0x9000
  373. #define RTCmd_LoadTC0AndTC1 0x9800
  374. #define RTCmd_SerialDataLSBFirst 0xa000
  375. #define RTCmd_SerialDataMSBFirst 0xa800
  376. #define RTCmd_SelectBigEndian 0xb000
  377. #define RTCmd_SelectLittleEndian 0xb800
  378. /*
  379. * DMA Command/Address Register (DCAR) Command Codes
  380. */
  381. #define DmaCmd_Null 0x0000
  382. #define DmaCmd_ResetTxChannel 0x1000
  383. #define DmaCmd_ResetRxChannel 0x1200
  384. #define DmaCmd_StartTxChannel 0x2000
  385. #define DmaCmd_StartRxChannel 0x2200
  386. #define DmaCmd_ContinueTxChannel 0x3000
  387. #define DmaCmd_ContinueRxChannel 0x3200
  388. #define DmaCmd_PauseTxChannel 0x4000
  389. #define DmaCmd_PauseRxChannel 0x4200
  390. #define DmaCmd_AbortTxChannel 0x5000
  391. #define DmaCmd_AbortRxChannel 0x5200
  392. #define DmaCmd_InitTxChannel 0x7000
  393. #define DmaCmd_InitRxChannel 0x7200
  394. #define DmaCmd_ResetHighestDmaIus 0x8000
  395. #define DmaCmd_ResetAllChannels 0x9000
  396. #define DmaCmd_StartAllChannels 0xa000
  397. #define DmaCmd_ContinueAllChannels 0xb000
  398. #define DmaCmd_PauseAllChannels 0xc000
  399. #define DmaCmd_AbortAllChannels 0xd000
  400. #define DmaCmd_InitAllChannels 0xf000
  401. #define TCmd_Null 0x0000
  402. #define TCmd_ClearTxCRC 0x2000
  403. #define TCmd_SelectTicrTtsaData 0x4000
  404. #define TCmd_SelectTicrTxFifostatus 0x5000
  405. #define TCmd_SelectTicrIntLevel 0x6000
  406. #define TCmd_SelectTicrdma_level 0x7000
  407. #define TCmd_SendFrame 0x8000
  408. #define TCmd_SendAbort 0x9000
  409. #define TCmd_EnableDleInsertion 0xc000
  410. #define TCmd_DisableDleInsertion 0xd000
  411. #define TCmd_ClearEofEom 0xe000
  412. #define TCmd_SetEofEom 0xf000
  413. #define RCmd_Null 0x0000
  414. #define RCmd_ClearRxCRC 0x2000
  415. #define RCmd_EnterHuntmode 0x3000
  416. #define RCmd_SelectRicrRtsaData 0x4000
  417. #define RCmd_SelectRicrRxFifostatus 0x5000
  418. #define RCmd_SelectRicrIntLevel 0x6000
  419. #define RCmd_SelectRicrdma_level 0x7000
  420. /*
  421. * Bits for enabling and disabling IRQs in Interrupt Control Register (ICR)
  422. */
  423. #define RECEIVE_STATUS BIT5
  424. #define RECEIVE_DATA BIT4
  425. #define TRANSMIT_STATUS BIT3
  426. #define TRANSMIT_DATA BIT2
  427. #define IO_PIN BIT1
  428. #define MISC BIT0
  429. /*
  430. * Receive status Bits in Receive Command/status Register RCSR
  431. */
  432. #define RXSTATUS_SHORT_FRAME BIT8
  433. #define RXSTATUS_CODE_VIOLATION BIT8
  434. #define RXSTATUS_EXITED_HUNT BIT7
  435. #define RXSTATUS_IDLE_RECEIVED BIT6
  436. #define RXSTATUS_BREAK_RECEIVED BIT5
  437. #define RXSTATUS_ABORT_RECEIVED BIT5
  438. #define RXSTATUS_RXBOUND BIT4
  439. #define RXSTATUS_CRC_ERROR BIT3
  440. #define RXSTATUS_FRAMING_ERROR BIT3
  441. #define RXSTATUS_ABORT BIT2
  442. #define RXSTATUS_PARITY_ERROR BIT2
  443. #define RXSTATUS_OVERRUN BIT1
  444. #define RXSTATUS_DATA_AVAILABLE BIT0
  445. #define RXSTATUS_ALL 0x01f6
  446. #define usc_UnlatchRxstatusBits(a,b) usc_OutReg( (a), RCSR, (u16)((b) & RXSTATUS_ALL) )
  447. /*
  448. * Values for setting transmit idle mode in
  449. * Transmit Control/status Register (TCSR)
  450. */
  451. #define IDLEMODE_FLAGS 0x0000
  452. #define IDLEMODE_ALT_ONE_ZERO 0x0100
  453. #define IDLEMODE_ZERO 0x0200
  454. #define IDLEMODE_ONE 0x0300
  455. #define IDLEMODE_ALT_MARK_SPACE 0x0500
  456. #define IDLEMODE_SPACE 0x0600
  457. #define IDLEMODE_MARK 0x0700
  458. #define IDLEMODE_MASK 0x0700
  459. /*
  460. * IUSC revision identifiers
  461. */
  462. #define IUSC_SL1660 0x4d44
  463. #define IUSC_PRE_SL1660 0x4553
  464. /*
  465. * Transmit status Bits in Transmit Command/status Register (TCSR)
  466. */
  467. #define TCSR_PRESERVE 0x0F00
  468. #define TCSR_UNDERWAIT BIT11
  469. #define TXSTATUS_PREAMBLE_SENT BIT7
  470. #define TXSTATUS_IDLE_SENT BIT6
  471. #define TXSTATUS_ABORT_SENT BIT5
  472. #define TXSTATUS_EOF_SENT BIT4
  473. #define TXSTATUS_EOM_SENT BIT4
  474. #define TXSTATUS_CRC_SENT BIT3
  475. #define TXSTATUS_ALL_SENT BIT2
  476. #define TXSTATUS_UNDERRUN BIT1
  477. #define TXSTATUS_FIFO_EMPTY BIT0
  478. #define TXSTATUS_ALL 0x00fa
  479. #define usc_UnlatchTxstatusBits(a,b) usc_OutReg( (a), TCSR, (u16)((a)->tcsr_value + ((b) & 0x00FF)) )
  480. #define MISCSTATUS_RXC_LATCHED BIT15
  481. #define MISCSTATUS_RXC BIT14
  482. #define MISCSTATUS_TXC_LATCHED BIT13
  483. #define MISCSTATUS_TXC BIT12
  484. #define MISCSTATUS_RI_LATCHED BIT11
  485. #define MISCSTATUS_RI BIT10
  486. #define MISCSTATUS_DSR_LATCHED BIT9
  487. #define MISCSTATUS_DSR BIT8
  488. #define MISCSTATUS_DCD_LATCHED BIT7
  489. #define MISCSTATUS_DCD BIT6
  490. #define MISCSTATUS_CTS_LATCHED BIT5
  491. #define MISCSTATUS_CTS BIT4
  492. #define MISCSTATUS_RCC_UNDERRUN BIT3
  493. #define MISCSTATUS_DPLL_NO_SYNC BIT2
  494. #define MISCSTATUS_BRG1_ZERO BIT1
  495. #define MISCSTATUS_BRG0_ZERO BIT0
  496. #define usc_UnlatchIostatusBits(a,b) usc_OutReg((a),MISR,(u16)((b) & 0xaaa0))
  497. #define usc_UnlatchMiscstatusBits(a,b) usc_OutReg((a),MISR,(u16)((b) & 0x000f))
  498. #define SICR_RXC_ACTIVE BIT15
  499. #define SICR_RXC_INACTIVE BIT14
  500. #define SICR_RXC (BIT15+BIT14)
  501. #define SICR_TXC_ACTIVE BIT13
  502. #define SICR_TXC_INACTIVE BIT12
  503. #define SICR_TXC (BIT13+BIT12)
  504. #define SICR_RI_ACTIVE BIT11
  505. #define SICR_RI_INACTIVE BIT10
  506. #define SICR_RI (BIT11+BIT10)
  507. #define SICR_DSR_ACTIVE BIT9
  508. #define SICR_DSR_INACTIVE BIT8
  509. #define SICR_DSR (BIT9+BIT8)
  510. #define SICR_DCD_ACTIVE BIT7
  511. #define SICR_DCD_INACTIVE BIT6
  512. #define SICR_DCD (BIT7+BIT6)
  513. #define SICR_CTS_ACTIVE BIT5
  514. #define SICR_CTS_INACTIVE BIT4
  515. #define SICR_CTS (BIT5+BIT4)
  516. #define SICR_RCC_UNDERFLOW BIT3
  517. #define SICR_DPLL_NO_SYNC BIT2
  518. #define SICR_BRG1_ZERO BIT1
  519. #define SICR_BRG0_ZERO BIT0
  520. void usc_DisableMasterIrqBit( struct mgsl_struct *info );
  521. void usc_EnableMasterIrqBit( struct mgsl_struct *info );
  522. void usc_EnableInterrupts( struct mgsl_struct *info, u16 IrqMask );
  523. void usc_DisableInterrupts( struct mgsl_struct *info, u16 IrqMask );
  524. void usc_ClearIrqPendingBits( struct mgsl_struct *info, u16 IrqMask );
  525. #define usc_EnableInterrupts( a, b ) \
  526. usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0xff00) + 0xc0 + (b)) )
  527. #define usc_DisableInterrupts( a, b ) \
  528. usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0xff00) + 0x80 + (b)) )
  529. #define usc_EnableMasterIrqBit(a) \
  530. usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0x0f00) + 0xb000) )
  531. #define usc_DisableMasterIrqBit(a) \
  532. usc_OutReg( (a), ICR, (u16)(usc_InReg((a),ICR) & 0x7f00) )
  533. #define usc_ClearIrqPendingBits( a, b ) usc_OutReg( (a), DCCR, 0x40 + (b) )
  534. /*
  535. * Transmit status Bits in Transmit Control status Register (TCSR)
  536. * and Transmit Interrupt Control Register (TICR) (except BIT2, BIT0)
  537. */
  538. #define TXSTATUS_PREAMBLE_SENT BIT7
  539. #define TXSTATUS_IDLE_SENT BIT6
  540. #define TXSTATUS_ABORT_SENT BIT5
  541. #define TXSTATUS_EOF BIT4
  542. #define TXSTATUS_CRC_SENT BIT3
  543. #define TXSTATUS_ALL_SENT BIT2
  544. #define TXSTATUS_UNDERRUN BIT1
  545. #define TXSTATUS_FIFO_EMPTY BIT0
  546. #define DICR_MASTER BIT15
  547. #define DICR_TRANSMIT BIT0
  548. #define DICR_RECEIVE BIT1
  549. #define usc_EnableDmaInterrupts(a,b) \
  550. usc_OutDmaReg( (a), DICR, (u16)(usc_InDmaReg((a),DICR) | (b)) )
  551. #define usc_DisableDmaInterrupts(a,b) \
  552. usc_OutDmaReg( (a), DICR, (u16)(usc_InDmaReg((a),DICR) & ~(b)) )
  553. #define usc_EnableStatusIrqs(a,b) \
  554. usc_OutReg( (a), SICR, (u16)(usc_InReg((a),SICR) | (b)) )
  555. #define usc_DisablestatusIrqs(a,b) \
  556. usc_OutReg( (a), SICR, (u16)(usc_InReg((a),SICR) & ~(b)) )
  557. /* Transmit status Bits in Transmit Control status Register (TCSR) */
  558. /* and Transmit Interrupt Control Register (TICR) (except BIT2, BIT0) */
  559. #define DISABLE_UNCONDITIONAL 0
  560. #define DISABLE_END_OF_FRAME 1
  561. #define ENABLE_UNCONDITIONAL 2
  562. #define ENABLE_AUTO_CTS 3
  563. #define ENABLE_AUTO_DCD 3
  564. #define usc_EnableTransmitter(a,b) \
  565. usc_OutReg( (a), TMR, (u16)((usc_InReg((a),TMR) & 0xfffc) | (b)) )
  566. #define usc_EnableReceiver(a,b) \
  567. usc_OutReg( (a), RMR, (u16)((usc_InReg((a),RMR) & 0xfffc) | (b)) )
  568. static u16 usc_InDmaReg( struct mgsl_struct *info, u16 Port );
  569. static void usc_OutDmaReg( struct mgsl_struct *info, u16 Port, u16 Value );
  570. static void usc_DmaCmd( struct mgsl_struct *info, u16 Cmd );
  571. static u16 usc_InReg( struct mgsl_struct *info, u16 Port );
  572. static void usc_OutReg( struct mgsl_struct *info, u16 Port, u16 Value );
  573. static void usc_RTCmd( struct mgsl_struct *info, u16 Cmd );
  574. void usc_RCmd( struct mgsl_struct *info, u16 Cmd );
  575. void usc_TCmd( struct mgsl_struct *info, u16 Cmd );
  576. #define usc_TCmd(a,b) usc_OutReg((a), TCSR, (u16)((a)->tcsr_value + (b)))
  577. #define usc_RCmd(a,b) usc_OutReg((a), RCSR, (b))
  578. #define usc_SetTransmitSyncChars(a,s0,s1) usc_OutReg((a), TSR, (u16)(((u16)s0<<8)|(u16)s1))
  579. static void usc_process_rxoverrun_sync( struct mgsl_struct *info );
  580. static void usc_start_receiver( struct mgsl_struct *info );
  581. static void usc_stop_receiver( struct mgsl_struct *info );
  582. static void usc_start_transmitter( struct mgsl_struct *info );
  583. static void usc_stop_transmitter( struct mgsl_struct *info );
  584. static void usc_set_txidle( struct mgsl_struct *info );
  585. static void usc_load_txfifo( struct mgsl_struct *info );
  586. static void usc_enable_aux_clock( struct mgsl_struct *info, u32 DataRate );
  587. static void usc_enable_loopback( struct mgsl_struct *info, int enable );
  588. static void usc_get_serial_signals( struct mgsl_struct *info );
  589. static void usc_set_serial_signals( struct mgsl_struct *info );
  590. static void usc_reset( struct mgsl_struct *info );
  591. static void usc_set_sync_mode( struct mgsl_struct *info );
  592. static void usc_set_sdlc_mode( struct mgsl_struct *info );
  593. static void usc_set_async_mode( struct mgsl_struct *info );
  594. static void usc_enable_async_clock( struct mgsl_struct *info, u32 DataRate );
  595. static void usc_loopback_frame( struct mgsl_struct *info );
  596. static void mgsl_tx_timeout(unsigned long context);
  597. static void usc_loopmode_cancel_transmit( struct mgsl_struct * info );
  598. static void usc_loopmode_insert_request( struct mgsl_struct * info );
  599. static int usc_loopmode_active( struct mgsl_struct * info);
  600. static void usc_loopmode_send_done( struct mgsl_struct * info );
  601. static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg);
  602. #ifdef CONFIG_HDLC
  603. #define dev_to_port(D) (dev_to_hdlc(D)->priv)
  604. static void hdlcdev_tx_done(struct mgsl_struct *info);
  605. static void hdlcdev_rx(struct mgsl_struct *info, char *buf, int size);
  606. static int hdlcdev_init(struct mgsl_struct *info);
  607. static void hdlcdev_exit(struct mgsl_struct *info);
  608. #endif
  609. /*
  610. * Defines a BUS descriptor value for the PCI adapter
  611. * local bus address ranges.
  612. */
  613. #define BUS_DESCRIPTOR( WrHold, WrDly, RdDly, Nwdd, Nwad, Nxda, Nrdd, Nrad ) \
  614. (0x00400020 + \
  615. ((WrHold) << 30) + \
  616. ((WrDly) << 28) + \
  617. ((RdDly) << 26) + \
  618. ((Nwdd) << 20) + \
  619. ((Nwad) << 15) + \
  620. ((Nxda) << 13) + \
  621. ((Nrdd) << 11) + \
  622. ((Nrad) << 6) )
  623. static void mgsl_trace_block(struct mgsl_struct *info,const char* data, int count, int xmit);
  624. /*
  625. * Adapter diagnostic routines
  626. */
  627. static BOOLEAN mgsl_register_test( struct mgsl_struct *info );
  628. static BOOLEAN mgsl_irq_test( struct mgsl_struct *info );
  629. static BOOLEAN mgsl_dma_test( struct mgsl_struct *info );
  630. static BOOLEAN mgsl_memory_test( struct mgsl_struct *info );
  631. static int mgsl_adapter_test( struct mgsl_struct *info );
  632. /*
  633. * device and resource management routines
  634. */
  635. static int mgsl_claim_resources(struct mgsl_struct *info);
  636. static void mgsl_release_resources(struct mgsl_struct *info);
  637. static void mgsl_add_device(struct mgsl_struct *info);
  638. static struct mgsl_struct* mgsl_allocate_device(void);
  639. /*
  640. * DMA buffer manupulation functions.
  641. */
  642. static void mgsl_free_rx_frame_buffers( struct mgsl_struct *info, unsigned int StartIndex, unsigned int EndIndex );
  643. static int mgsl_get_rx_frame( struct mgsl_struct *info );
  644. static int mgsl_get_raw_rx_frame( struct mgsl_struct *info );
  645. static void mgsl_reset_rx_dma_buffers( struct mgsl_struct *info );
  646. static void mgsl_reset_tx_dma_buffers( struct mgsl_struct *info );
  647. static int num_free_tx_dma_buffers(struct mgsl_struct *info);
  648. static void mgsl_load_tx_dma_buffer( struct mgsl_struct *info, const char *Buffer, unsigned int BufferSize);
  649. static void mgsl_load_pci_memory(char* TargetPtr, const char* SourcePtr, unsigned short count);
  650. /*
  651. * DMA and Shared Memory buffer allocation and formatting
  652. */
  653. static int mgsl_allocate_dma_buffers(struct mgsl_struct *info);
  654. static void mgsl_free_dma_buffers(struct mgsl_struct *info);
  655. static int mgsl_alloc_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *BufferList,int Buffercount);
  656. static void mgsl_free_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *BufferList,int Buffercount);
  657. static int mgsl_alloc_buffer_list_memory(struct mgsl_struct *info);
  658. static void mgsl_free_buffer_list_memory(struct mgsl_struct *info);
  659. static int mgsl_alloc_intermediate_rxbuffer_memory(struct mgsl_struct *info);
  660. static void mgsl_free_intermediate_rxbuffer_memory(struct mgsl_struct *info);
  661. static int mgsl_alloc_intermediate_txbuffer_memory(struct mgsl_struct *info);
  662. static void mgsl_free_intermediate_txbuffer_memory(struct mgsl_struct *info);
  663. static int load_next_tx_holding_buffer(struct mgsl_struct *info);
  664. static int save_tx_buffer_request(struct mgsl_struct *info,const char *Buffer, unsigned int BufferSize);
  665. /*
  666. * Bottom half interrupt handlers
  667. */
  668. static void mgsl_bh_handler(void* Context);
  669. static void mgsl_bh_receive(struct mgsl_struct *info);
  670. static void mgsl_bh_transmit(struct mgsl_struct *info);
  671. static void mgsl_bh_status(struct mgsl_struct *info);
  672. /*
  673. * Interrupt handler routines and dispatch table.
  674. */
  675. static void mgsl_isr_null( struct mgsl_struct *info );
  676. static void mgsl_isr_transmit_data( struct mgsl_struct *info );
  677. static void mgsl_isr_receive_data( struct mgsl_struct *info );
  678. static void mgsl_isr_receive_status( struct mgsl_struct *info );
  679. static void mgsl_isr_transmit_status( struct mgsl_struct *info );
  680. static void mgsl_isr_io_pin( struct mgsl_struct *info );
  681. static void mgsl_isr_misc( struct mgsl_struct *info );
  682. static void mgsl_isr_receive_dma( struct mgsl_struct *info );
  683. static void mgsl_isr_transmit_dma( struct mgsl_struct *info );
  684. typedef void (*isr_dispatch_func)(struct mgsl_struct *);
  685. static isr_dispatch_func UscIsrTable[7] =
  686. {
  687. mgsl_isr_null,
  688. mgsl_isr_misc,
  689. mgsl_isr_io_pin,
  690. mgsl_isr_transmit_data,
  691. mgsl_isr_transmit_status,
  692. mgsl_isr_receive_data,
  693. mgsl_isr_receive_status
  694. };
  695. /*
  696. * ioctl call handlers
  697. */
  698. static int tiocmget(struct tty_struct *tty, struct file *file);
  699. static int tiocmset(struct tty_struct *tty, struct file *file,
  700. unsigned int set, unsigned int clear);
  701. static int mgsl_get_stats(struct mgsl_struct * info, struct mgsl_icount
  702. __user *user_icount);
  703. static int mgsl_get_params(struct mgsl_struct * info, MGSL_PARAMS __user *user_params);
  704. static int mgsl_set_params(struct mgsl_struct * info, MGSL_PARAMS __user *new_params);
  705. static int mgsl_get_txidle(struct mgsl_struct * info, int __user *idle_mode);
  706. static int mgsl_set_txidle(struct mgsl_struct * info, int idle_mode);
  707. static int mgsl_txenable(struct mgsl_struct * info, int enable);
  708. static int mgsl_txabort(struct mgsl_struct * info);
  709. static int mgsl_rxenable(struct mgsl_struct * info, int enable);
  710. static int mgsl_wait_event(struct mgsl_struct * info, int __user *mask);
  711. static int mgsl_loopmode_send_done( struct mgsl_struct * info );
  712. /* set non-zero on successful registration with PCI subsystem */
  713. static int pci_registered;
  714. /*
  715. * Global linked list of SyncLink devices
  716. */
  717. static struct mgsl_struct *mgsl_device_list;
  718. static int mgsl_device_count;
  719. /*
  720. * Set this param to non-zero to load eax with the
  721. * .text section address and breakpoint on module load.
  722. * This is useful for use with gdb and add-symbol-file command.
  723. */
  724. static int break_on_load;
  725. /*
  726. * Driver major number, defaults to zero to get auto
  727. * assigned major number. May be forced as module parameter.
  728. */
  729. static int ttymajor;
  730. /*
  731. * Array of user specified options for ISA adapters.
  732. */
  733. static int io[MAX_ISA_DEVICES];
  734. static int irq[MAX_ISA_DEVICES];
  735. static int dma[MAX_ISA_DEVICES];
  736. static int debug_level;
  737. static int maxframe[MAX_TOTAL_DEVICES];
  738. static int dosyncppp[MAX_TOTAL_DEVICES];
  739. static int txdmabufs[MAX_TOTAL_DEVICES];
  740. static int txholdbufs[MAX_TOTAL_DEVICES];
  741. module_param(break_on_load, bool, 0);
  742. module_param(ttymajor, int, 0);
  743. module_param_array(io, int, NULL, 0);
  744. module_param_array(irq, int, NULL, 0);
  745. module_param_array(dma, int, NULL, 0);
  746. module_param(debug_level, int, 0);
  747. module_param_array(maxframe, int, NULL, 0);
  748. module_param_array(dosyncppp, int, NULL, 0);
  749. module_param_array(txdmabufs, int, NULL, 0);
  750. module_param_array(txholdbufs, int, NULL, 0);
  751. static char *driver_name = "SyncLink serial driver";
  752. static char *driver_version = "$Revision: 4.28 $";
  753. static int synclink_init_one (struct pci_dev *dev,
  754. const struct pci_device_id *ent);
  755. static void synclink_remove_one (struct pci_dev *dev);
  756. static struct pci_device_id synclink_pci_tbl[] = {
  757. { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_USC, PCI_ANY_ID, PCI_ANY_ID, },
  758. { PCI_VENDOR_ID_MICROGATE, 0x0210, PCI_ANY_ID, PCI_ANY_ID, },
  759. { 0, }, /* terminate list */
  760. };
  761. MODULE_DEVICE_TABLE(pci, synclink_pci_tbl);
  762. MODULE_LICENSE("GPL");
  763. static struct pci_driver synclink_pci_driver = {
  764. .name = "synclink",
  765. .id_table = synclink_pci_tbl,
  766. .probe = synclink_init_one,
  767. .remove = __devexit_p(synclink_remove_one),
  768. };
  769. static struct tty_driver *serial_driver;
  770. /* number of characters left in xmit buffer before we ask for more */
  771. #define WAKEUP_CHARS 256
  772. static void mgsl_change_params(struct mgsl_struct *info);
  773. static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout);
  774. /*
  775. * 1st function defined in .text section. Calling this function in
  776. * init_module() followed by a breakpoint allows a remote debugger
  777. * (gdb) to get the .text address for the add-symbol-file command.
  778. * This allows remote debugging of dynamically loadable modules.
  779. */
  780. static void* mgsl_get_text_ptr(void)
  781. {
  782. return mgsl_get_text_ptr;
  783. }
  784. /*
  785. * tmp_buf is used as a temporary buffer by mgsl_write. We need to
  786. * lock it in case the COPY_FROM_USER blocks while swapping in a page,
  787. * and some other program tries to do a serial write at the same time.
  788. * Since the lock will only come under contention when the system is
  789. * swapping and available memory is low, it makes sense to share one
  790. * buffer across all the serial ioports, since it significantly saves
  791. * memory if large numbers of serial ports are open.
  792. */
  793. static unsigned char *tmp_buf;
  794. static DECLARE_MUTEX(tmp_buf_sem);
  795. static inline int mgsl_paranoia_check(struct mgsl_struct *info,
  796. char *name, const char *routine)
  797. {
  798. #ifdef MGSL_PARANOIA_CHECK
  799. static const char *badmagic =
  800. "Warning: bad magic number for mgsl struct (%s) in %s\n";
  801. static const char *badinfo =
  802. "Warning: null mgsl_struct for (%s) in %s\n";
  803. if (!info) {
  804. printk(badinfo, name, routine);
  805. return 1;
  806. }
  807. if (info->magic != MGSL_MAGIC) {
  808. printk(badmagic, name, routine);
  809. return 1;
  810. }
  811. #else
  812. if (!info)
  813. return 1;
  814. #endif
  815. return 0;
  816. }
  817. /**
  818. * line discipline callback wrappers
  819. *
  820. * The wrappers maintain line discipline references
  821. * while calling into the line discipline.
  822. *
  823. * ldisc_receive_buf - pass receive data to line discipline
  824. */
  825. static void ldisc_receive_buf(struct tty_struct *tty,
  826. const __u8 *data, char *flags, int count)
  827. {
  828. struct tty_ldisc *ld;
  829. if (!tty)
  830. return;
  831. ld = tty_ldisc_ref(tty);
  832. if (ld) {
  833. if (ld->receive_buf)
  834. ld->receive_buf(tty, data, flags, count);
  835. tty_ldisc_deref(ld);
  836. }
  837. }
  838. /* mgsl_stop() throttle (stop) transmitter
  839. *
  840. * Arguments: tty pointer to tty info structure
  841. * Return Value: None
  842. */
  843. static void mgsl_stop(struct tty_struct *tty)
  844. {
  845. struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
  846. unsigned long flags;
  847. if (mgsl_paranoia_check(info, tty->name, "mgsl_stop"))
  848. return;
  849. if ( debug_level >= DEBUG_LEVEL_INFO )
  850. printk("mgsl_stop(%s)\n",info->device_name);
  851. spin_lock_irqsave(&info->irq_spinlock,flags);
  852. if (info->tx_enabled)
  853. usc_stop_transmitter(info);
  854. spin_unlock_irqrestore(&info->irq_spinlock,flags);
  855. } /* end of mgsl_stop() */
  856. /* mgsl_start() release (start) transmitter
  857. *
  858. * Arguments: tty pointer to tty info structure
  859. * Return Value: None
  860. */
  861. static void mgsl_start(struct tty_struct *tty)
  862. {
  863. struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
  864. unsigned long flags;
  865. if (mgsl_paranoia_check(info, tty->name, "mgsl_start"))
  866. return;
  867. if ( debug_level >= DEBUG_LEVEL_INFO )
  868. printk("mgsl_start(%s)\n",info->device_name);
  869. spin_lock_irqsave(&info->irq_spinlock,flags);
  870. if (!info->tx_enabled)
  871. usc_start_transmitter(info);
  872. spin_unlock_irqrestore(&info->irq_spinlock,flags);
  873. } /* end of mgsl_start() */
  874. /*
  875. * Bottom half work queue access functions
  876. */
  877. /* mgsl_bh_action() Return next bottom half action to perform.
  878. * Return Value: BH action code or 0 if nothing to do.
  879. */
  880. static int mgsl_bh_action(struct mgsl_struct *info)
  881. {
  882. unsigned long flags;
  883. int rc = 0;
  884. spin_lock_irqsave(&info->irq_spinlock,flags);
  885. if (info->pending_bh & BH_RECEIVE) {
  886. info->pending_bh &= ~BH_RECEIVE;
  887. rc = BH_RECEIVE;
  888. } else if (info->pending_bh & BH_TRANSMIT) {
  889. info->pending_bh &= ~BH_TRANSMIT;
  890. rc = BH_TRANSMIT;
  891. } else if (info->pending_bh & BH_STATUS) {
  892. info->pending_bh &= ~BH_STATUS;
  893. rc = BH_STATUS;
  894. }
  895. if (!rc) {
  896. /* Mark BH routine as complete */
  897. info->bh_running = 0;
  898. info->bh_requested = 0;
  899. }
  900. spin_unlock_irqrestore(&info->irq_spinlock,flags);
  901. return rc;
  902. }
  903. /*
  904. * Perform bottom half processing of work items queued by ISR.
  905. */
  906. static void mgsl_bh_handler(void* Context)
  907. {
  908. struct mgsl_struct *info = (struct mgsl_struct*)Context;
  909. int action;
  910. if (!info)
  911. return;
  912. if ( debug_level >= DEBUG_LEVEL_BH )
  913. printk( "%s(%d):mgsl_bh_handler(%s) entry\n",
  914. __FILE__,__LINE__,info->device_name);
  915. info->bh_running = 1;
  916. while((action = mgsl_bh_action(info)) != 0) {
  917. /* Process work item */
  918. if ( debug_level >= DEBUG_LEVEL_BH )
  919. printk( "%s(%d):mgsl_bh_handler() work item action=%d\n",
  920. __FILE__,__LINE__,action);
  921. switch (action) {
  922. case BH_RECEIVE:
  923. mgsl_bh_receive(info);
  924. break;
  925. case BH_TRANSMIT:
  926. mgsl_bh_transmit(info);
  927. break;
  928. case BH_STATUS:
  929. mgsl_bh_status(info);
  930. break;
  931. default:
  932. /* unknown work item ID */
  933. printk("Unknown work item ID=%08X!\n", action);
  934. break;
  935. }
  936. }
  937. if ( debug_level >= DEBUG_LEVEL_BH )
  938. printk( "%s(%d):mgsl_bh_handler(%s) exit\n",
  939. __FILE__,__LINE__,info->device_name);
  940. }
  941. static void mgsl_bh_receive(struct mgsl_struct *info)
  942. {
  943. int (*get_rx_frame)(struct mgsl_struct *info) =
  944. (info->params.mode == MGSL_MODE_HDLC ? mgsl_get_rx_frame : mgsl_get_raw_rx_frame);
  945. if ( debug_level >= DEBUG_LEVEL_BH )
  946. printk( "%s(%d):mgsl_bh_receive(%s)\n",
  947. __FILE__,__LINE__,info->device_name);
  948. do
  949. {
  950. if (info->rx_rcc_underrun) {
  951. unsigned long flags;
  952. spin_lock_irqsave(&info->irq_spinlock,flags);
  953. usc_start_receiver(info);
  954. spin_unlock_irqrestore(&info->irq_spinlock,flags);
  955. return;
  956. }
  957. } while(get_rx_frame(info));
  958. }
  959. static void mgsl_bh_transmit(struct mgsl_struct *info)
  960. {
  961. struct tty_struct *tty = info->tty;
  962. unsigned long flags;
  963. if ( debug_level >= DEBUG_LEVEL_BH )
  964. printk( "%s(%d):mgsl_bh_transmit() entry on %s\n",
  965. __FILE__,__LINE__,info->device_name);
  966. if (tty) {
  967. tty_wakeup(tty);
  968. wake_up_interruptible(&tty->write_wait);
  969. }
  970. /* if transmitter idle and loopmode_send_done_requested
  971. * then start echoing RxD to TxD
  972. */
  973. spin_lock_irqsave(&info->irq_spinlock,flags);
  974. if ( !info->tx_active && info->loopmode_send_done_requested )
  975. usc_loopmode_send_done( info );
  976. spin_unlock_irqrestore(&info->irq_spinlock,flags);
  977. }
  978. static void mgsl_bh_status(struct mgsl_struct *info)
  979. {
  980. if ( debug_level >= DEBUG_LEVEL_BH )
  981. printk( "%s(%d):mgsl_bh_status() entry on %s\n",
  982. __FILE__,__LINE__,info->device_name);
  983. info->ri_chkcount = 0;
  984. info->dsr_chkcount = 0;
  985. info->dcd_chkcount = 0;
  986. info->cts_chkcount = 0;
  987. }
  988. /* mgsl_isr_receive_status()
  989. *
  990. * Service a receive status interrupt. The type of status
  991. * interrupt is indicated by the state of the RCSR.
  992. * This is only used for HDLC mode.
  993. *
  994. * Arguments: info pointer to device instance data
  995. * Return Value: None
  996. */
  997. static void mgsl_isr_receive_status( struct mgsl_struct *info )
  998. {
  999. u16 status = usc_InReg( info, RCSR );
  1000. if ( debug_level >= DEBUG_LEVEL_ISR )
  1001. printk("%s(%d):mgsl_isr_receive_status status=%04X\n",
  1002. __FILE__,__LINE__,status);
  1003. if ( (status & RXSTATUS_ABORT_RECEIVED) &&
  1004. info->loopmode_insert_requested &&
  1005. usc_loopmode_active(info) )
  1006. {
  1007. ++info->icount.rxabort;
  1008. info->loopmode_insert_requested = FALSE;
  1009. /* clear CMR:13 to start echoing RxD to TxD */
  1010. info->cmr_value &= ~BIT13;
  1011. usc_OutReg(info, CMR, info->cmr_value);
  1012. /* disable received abort irq (no longer required) */
  1013. usc_OutReg(info, RICR,
  1014. (usc_InReg(info, RICR) & ~RXSTATUS_ABORT_RECEIVED));
  1015. }
  1016. if (status & (RXSTATUS_EXITED_HUNT + RXSTATUS_IDLE_RECEIVED)) {
  1017. if (status & RXSTATUS_EXITED_HUNT)
  1018. info->icount.exithunt++;
  1019. if (status & RXSTATUS_IDLE_RECEIVED)
  1020. info->icount.rxidle++;
  1021. wake_up_interruptible(&info->event_wait_q);
  1022. }
  1023. if (status & RXSTATUS_OVERRUN){
  1024. info->icount.rxover++;
  1025. usc_process_rxoverrun_sync( info );
  1026. }
  1027. usc_ClearIrqPendingBits( info, RECEIVE_STATUS );
  1028. usc_UnlatchRxstatusBits( info, status );
  1029. } /* end of mgsl_isr_receive_status() */
  1030. /* mgsl_isr_transmit_status()
  1031. *
  1032. * Service a transmit status interrupt
  1033. * HDLC mode :end of transmit frame
  1034. * Async mode:all data is sent
  1035. * transmit status is indicated by bits in the TCSR.
  1036. *
  1037. * Arguments: info pointer to device instance data
  1038. * Return Value: None
  1039. */
  1040. static void mgsl_isr_transmit_status( struct mgsl_struct *info )
  1041. {
  1042. u16 status = usc_InReg( info, TCSR );
  1043. if ( debug_level >= DEBUG_LEVEL_ISR )
  1044. printk("%s(%d):mgsl_isr_transmit_status status=%04X\n",
  1045. __FILE__,__LINE__,status);
  1046. usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
  1047. usc_UnlatchTxstatusBits( info, status );
  1048. if ( status & (TXSTATUS_UNDERRUN | TXSTATUS_ABORT_SENT) )
  1049. {
  1050. /* finished sending HDLC abort. This may leave */
  1051. /* the TxFifo with data from the aborted frame */
  1052. /* so purge the TxFifo. Also shutdown the DMA */
  1053. /* channel in case there is data remaining in */
  1054. /* the DMA buffer */
  1055. usc_DmaCmd( info, DmaCmd_ResetTxChannel );
  1056. usc_RTCmd( info, RTCmd_PurgeTxFifo );
  1057. }
  1058. if ( status & TXSTATUS_EOF_SENT )
  1059. info->icount.txok++;
  1060. else if ( status & TXSTATUS_UNDERRUN )
  1061. info->icount.txunder++;
  1062. else if ( status & TXSTATUS_ABORT_SENT )
  1063. info->icount.txabort++;
  1064. else
  1065. info->icount.txunder++;
  1066. info->tx_active = 0;
  1067. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1068. del_timer(&info->tx_timer);
  1069. if ( info->drop_rts_on_tx_done ) {
  1070. usc_get_serial_signals( info );
  1071. if ( info->serial_signals & SerialSignal_RTS ) {
  1072. info->serial_signals &= ~SerialSignal_RTS;
  1073. usc_set_serial_signals( info );
  1074. }
  1075. info->drop_rts_on_tx_done = 0;
  1076. }
  1077. #ifdef CONFIG_HDLC
  1078. if (info->netcount)
  1079. hdlcdev_tx_done(info);
  1080. else
  1081. #endif
  1082. {
  1083. if (info->tty->stopped || info->tty->hw_stopped) {
  1084. usc_stop_transmitter(info);
  1085. return;
  1086. }
  1087. info->pending_bh |= BH_TRANSMIT;
  1088. }
  1089. } /* end of mgsl_isr_transmit_status() */
  1090. /* mgsl_isr_io_pin()
  1091. *
  1092. * Service an Input/Output pin interrupt. The type of
  1093. * interrupt is indicated by bits in the MISR
  1094. *
  1095. * Arguments: info pointer to device instance data
  1096. * Return Value: None
  1097. */
  1098. static void mgsl_isr_io_pin( struct mgsl_struct *info )
  1099. {
  1100. struct mgsl_icount *icount;
  1101. u16 status = usc_InReg( info, MISR );
  1102. if ( debug_level >= DEBUG_LEVEL_ISR )
  1103. printk("%s(%d):mgsl_isr_io_pin status=%04X\n",
  1104. __FILE__,__LINE__,status);
  1105. usc_ClearIrqPendingBits( info, IO_PIN );
  1106. usc_UnlatchIostatusBits( info, status );
  1107. if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
  1108. MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
  1109. icount = &info->icount;
  1110. /* update input line counters */
  1111. if (status & MISCSTATUS_RI_LATCHED) {
  1112. if ((info->ri_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
  1113. usc_DisablestatusIrqs(info,SICR_RI);
  1114. icount->rng++;
  1115. if ( status & MISCSTATUS_RI )
  1116. info->input_signal_events.ri_up++;
  1117. else
  1118. info->input_signal_events.ri_down++;
  1119. }
  1120. if (status & MISCSTATUS_DSR_LATCHED) {
  1121. if ((info->dsr_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
  1122. usc_DisablestatusIrqs(info,SICR_DSR);
  1123. icount->dsr++;
  1124. if ( status & MISCSTATUS_DSR )
  1125. info->input_signal_events.dsr_up++;
  1126. else
  1127. info->input_signal_events.dsr_down++;
  1128. }
  1129. if (status & MISCSTATUS_DCD_LATCHED) {
  1130. if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
  1131. usc_DisablestatusIrqs(info,SICR_DCD);
  1132. icount->dcd++;
  1133. if (status & MISCSTATUS_DCD) {
  1134. info->input_signal_events.dcd_up++;
  1135. } else
  1136. info->input_signal_events.dcd_down++;
  1137. #ifdef CONFIG_HDLC
  1138. if (info->netcount)
  1139. hdlc_set_carrier(status & MISCSTATUS_DCD, info->netdev);
  1140. #endif
  1141. }
  1142. if (status & MISCSTATUS_CTS_LATCHED)
  1143. {
  1144. if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
  1145. usc_DisablestatusIrqs(info,SICR_CTS);
  1146. icount->cts++;
  1147. if ( status & MISCSTATUS_CTS )
  1148. info->input_signal_events.cts_up++;
  1149. else
  1150. info->input_signal_events.cts_down++;
  1151. }
  1152. wake_up_interruptible(&info->status_event_wait_q);
  1153. wake_up_interruptible(&info->event_wait_q);
  1154. if ( (info->flags & ASYNC_CHECK_CD) &&
  1155. (status & MISCSTATUS_DCD_LATCHED) ) {
  1156. if ( debug_level >= DEBUG_LEVEL_ISR )
  1157. printk("%s CD now %s...", info->device_name,
  1158. (status & MISCSTATUS_DCD) ? "on" : "off");
  1159. if (status & MISCSTATUS_DCD)
  1160. wake_up_interruptible(&info->open_wait);
  1161. else {
  1162. if ( debug_level >= DEBUG_LEVEL_ISR )
  1163. printk("doing serial hangup...");
  1164. if (info->tty)
  1165. tty_hangup(info->tty);
  1166. }
  1167. }
  1168. if ( (info->flags & ASYNC_CTS_FLOW) &&
  1169. (status & MISCSTATUS_CTS_LATCHED) ) {
  1170. if (info->tty->hw_stopped) {
  1171. if (status & MISCSTATUS_CTS) {
  1172. if ( debug_level >= DEBUG_LEVEL_ISR )
  1173. printk("CTS tx start...");
  1174. if (info->tty)
  1175. info->tty->hw_stopped = 0;
  1176. usc_start_transmitter(info);
  1177. info->pending_bh |= BH_TRANSMIT;
  1178. return;
  1179. }
  1180. } else {
  1181. if (!(status & MISCSTATUS_CTS)) {
  1182. if ( debug_level >= DEBUG_LEVEL_ISR )
  1183. printk("CTS tx stop...");
  1184. if (info->tty)
  1185. info->tty->hw_stopped = 1;
  1186. usc_stop_transmitter(info);
  1187. }
  1188. }
  1189. }
  1190. }
  1191. info->pending_bh |= BH_STATUS;
  1192. /* for diagnostics set IRQ flag */
  1193. if ( status & MISCSTATUS_TXC_LATCHED ){
  1194. usc_OutReg( info, SICR,
  1195. (unsigned short)(usc_InReg(info,SICR) & ~(SICR_TXC_ACTIVE+SICR_TXC_INACTIVE)) );
  1196. usc_UnlatchIostatusBits( info, MISCSTATUS_TXC_LATCHED );
  1197. info->irq_occurred = 1;
  1198. }
  1199. } /* end of mgsl_isr_io_pin() */
  1200. /* mgsl_isr_transmit_data()
  1201. *
  1202. * Service a transmit data interrupt (async mode only).
  1203. *
  1204. * Arguments: info pointer to device instance data
  1205. * Return Value: None
  1206. */
  1207. static void mgsl_isr_transmit_data( struct mgsl_struct *info )
  1208. {
  1209. if ( debug_level >= DEBUG_LEVEL_ISR )
  1210. printk("%s(%d):mgsl_isr_transmit_data xmit_cnt=%d\n",
  1211. __FILE__,__LINE__,info->xmit_cnt);
  1212. usc_ClearIrqPendingBits( info, TRANSMIT_DATA );
  1213. if (info->tty->stopped || info->tty->hw_stopped) {
  1214. usc_stop_transmitter(info);
  1215. return;
  1216. }
  1217. if ( info->xmit_cnt )
  1218. usc_load_txfifo( info );
  1219. else
  1220. info->tx_active = 0;
  1221. if (info->xmit_cnt < WAKEUP_CHARS)
  1222. info->pending_bh |= BH_TRANSMIT;
  1223. } /* end of mgsl_isr_transmit_data() */
  1224. /* mgsl_isr_receive_data()
  1225. *
  1226. * Service a receive data interrupt. This occurs
  1227. * when operating in asynchronous interrupt transfer mode.
  1228. * The receive data FIFO is flushed to the receive data buffers.
  1229. *
  1230. * Arguments: info pointer to device instance data
  1231. * Return Value: None
  1232. */
  1233. static void mgsl_isr_receive_data( struct mgsl_struct *info )
  1234. {
  1235. int Fifocount;
  1236. u16 status;
  1237. unsigned char DataByte;
  1238. struct tty_struct *tty = info->tty;
  1239. struct mgsl_icount *icount = &info->icount;
  1240. if ( debug_level >= DEBUG_LEVEL_ISR )
  1241. printk("%s(%d):mgsl_isr_receive_data\n",
  1242. __FILE__,__LINE__);
  1243. usc_ClearIrqPendingBits( info, RECEIVE_DATA );
  1244. /* select FIFO status for RICR readback */
  1245. usc_RCmd( info, RCmd_SelectRicrRxFifostatus );
  1246. /* clear the Wordstatus bit so that status readback */
  1247. /* only reflects the status of this byte */
  1248. usc_OutReg( info, RICR+LSBONLY, (u16)(usc_InReg(info, RICR+LSBONLY) & ~BIT3 ));
  1249. /* flush the receive FIFO */
  1250. while( (Fifocount = (usc_InReg(info,RICR) >> 8)) ) {
  1251. /* read one byte from RxFIFO */
  1252. outw( (inw(info->io_base + CCAR) & 0x0780) | (RDR+LSBONLY),
  1253. info->io_base + CCAR );
  1254. DataByte = inb( info->io_base + CCAR );
  1255. /* get the status of the received byte */
  1256. status = usc_InReg(info, RCSR);
  1257. if ( status & (RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR +
  1258. RXSTATUS_OVERRUN + RXSTATUS_BREAK_RECEIVED) )
  1259. usc_UnlatchRxstatusBits(info,RXSTATUS_ALL);
  1260. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  1261. continue;
  1262. *tty->flip.char_buf_ptr = DataByte;
  1263. icount->rx++;
  1264. *tty->flip.flag_buf_ptr = 0;
  1265. if ( status & (RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR +
  1266. RXSTATUS_OVERRUN + RXSTATUS_BREAK_RECEIVED) ) {
  1267. printk("rxerr=%04X\n",status);
  1268. /* update error statistics */
  1269. if ( status & RXSTATUS_BREAK_RECEIVED ) {
  1270. status &= ~(RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR);
  1271. icount->brk++;
  1272. } else if (status & RXSTATUS_PARITY_ERROR)
  1273. icount->parity++;
  1274. else if (status & RXSTATUS_FRAMING_ERROR)
  1275. icount->frame++;
  1276. else if (status & RXSTATUS_OVERRUN) {
  1277. /* must issue purge fifo cmd before */
  1278. /* 16C32 accepts more receive chars */
  1279. usc_RTCmd(info,RTCmd_PurgeRxFifo);
  1280. icount->overrun++;
  1281. }
  1282. /* discard char if tty control flags say so */
  1283. if (status & info->ignore_status_mask)
  1284. continue;
  1285. status &= info->read_status_mask;
  1286. if (status & RXSTATUS_BREAK_RECEIVED) {
  1287. *tty->flip.flag_buf_ptr = TTY_BREAK;
  1288. if (info->flags & ASYNC_SAK)
  1289. do_SAK(tty);
  1290. } else if (status & RXSTATUS_PARITY_ERROR)
  1291. *tty->flip.flag_buf_ptr = TTY_PARITY;
  1292. else if (status & RXSTATUS_FRAMING_ERROR)
  1293. *tty->flip.flag_buf_ptr = TTY_FRAME;
  1294. if (status & RXSTATUS_OVERRUN) {
  1295. /* Overrun is special, since it's
  1296. * reported immediately, and doesn't
  1297. * affect the current character
  1298. */
  1299. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  1300. tty->flip.count++;
  1301. tty->flip.flag_buf_ptr++;
  1302. tty->flip.char_buf_ptr++;
  1303. *tty->flip.flag_buf_ptr = TTY_OVERRUN;
  1304. }
  1305. }
  1306. } /* end of if (error) */
  1307. tty->flip.flag_buf_ptr++;
  1308. tty->flip.char_buf_ptr++;
  1309. tty->flip.count++;
  1310. }
  1311. if ( debug_level >= DEBUG_LEVEL_ISR ) {
  1312. printk("%s(%d):mgsl_isr_receive_data flip count=%d\n",
  1313. __FILE__,__LINE__,tty->flip.count);
  1314. printk("%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
  1315. __FILE__,__LINE__,icount->rx,icount->brk,
  1316. icount->parity,icount->frame,icount->overrun);
  1317. }
  1318. if ( tty->flip.count )
  1319. tty_flip_buffer_push(tty);
  1320. }
  1321. /* mgsl_isr_misc()
  1322. *
  1323. * Service a miscellaneos interrupt source.
  1324. *
  1325. * Arguments: info pointer to device extension (instance data)
  1326. * Return Value: None
  1327. */
  1328. static void mgsl_isr_misc( struct mgsl_struct *info )
  1329. {
  1330. u16 status = usc_InReg( info, MISR );
  1331. if ( debug_level >= DEBUG_LEVEL_ISR )
  1332. printk("%s(%d):mgsl_isr_misc status=%04X\n",
  1333. __FILE__,__LINE__,status);
  1334. if ((status & MISCSTATUS_RCC_UNDERRUN) &&
  1335. (info->params.mode == MGSL_MODE_HDLC)) {
  1336. /* turn off receiver and rx DMA */
  1337. usc_EnableReceiver(info,DISABLE_UNCONDITIONAL);
  1338. usc_DmaCmd(info, DmaCmd_ResetRxChannel);
  1339. usc_UnlatchRxstatusBits(info, RXSTATUS_ALL);
  1340. usc_ClearIrqPendingBits(info, RECEIVE_DATA + RECEIVE_STATUS);
  1341. usc_DisableInterrupts(info, RECEIVE_DATA + RECEIVE_STATUS);
  1342. /* schedule BH handler to restart receiver */
  1343. info->pending_bh |= BH_RECEIVE;
  1344. info->rx_rcc_underrun = 1;
  1345. }
  1346. usc_ClearIrqPendingBits( info, MISC );
  1347. usc_UnlatchMiscstatusBits( info, status );
  1348. } /* end of mgsl_isr_misc() */
  1349. /* mgsl_isr_null()
  1350. *
  1351. * Services undefined interrupt vectors from the
  1352. * USC. (hence this function SHOULD never be called)
  1353. *
  1354. * Arguments: info pointer to device extension (instance data)
  1355. * Return Value: None
  1356. */
  1357. static void mgsl_isr_null( struct mgsl_struct *info )
  1358. {
  1359. } /* end of mgsl_isr_null() */
  1360. /* mgsl_isr_receive_dma()
  1361. *
  1362. * Service a rec…