2 * linux/drivers/char/synclink.c
4 * $Id: synclink.c,v 4.38 2005/11/07 16:30:34 paulkf Exp $
6 * Device driver for Microgate SyncLink ISA and PCI
7 * high speed multiprotocol serial adapters.
9 * written by Paul Fulghum for Microgate Corporation
10 * paulkf@microgate.com
12 * Microgate and SyncLink are trademarks of Microgate Corporation
14 * Derived from serial.c written by Theodore Ts'o and Linus Torvalds
16 * Original release 01/11/99
18 * This code is released under the GNU General Public License (GPL)
20 * This driver is primarily intended for use in synchronous
21 * HDLC mode. Asynchronous mode is also provided.
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.
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.
33 * This driver has been tested with a slightly modified ppp.c driver
34 * for synchronous PPP.
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.
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.
57 # define BREAKPOINT() asm(" int $3");
59 # define BREAKPOINT() { }
62 #define MAX_ISA_DEVICES 10
63 #define MAX_PCI_DEVICES 10
64 #define MAX_TOTAL_DEVICES 20
66 #include <linux/module.h>
67 #include <linux/errno.h>
68 #include <linux/signal.h>
69 #include <linux/sched.h>
70 #include <linux/timer.h>
71 #include <linux/interrupt.h>
72 #include <linux/pci.h>
73 #include <linux/tty.h>
74 #include <linux/tty_flip.h>
75 #include <linux/serial.h>
76 #include <linux/major.h>
77 #include <linux/string.h>
78 #include <linux/fcntl.h>
79 #include <linux/ptrace.h>
80 #include <linux/ioport.h>
82 #include <linux/slab.h>
83 #include <linux/delay.h>
85 #include <linux/netdevice.h>
87 #include <linux/vmalloc.h>
88 #include <linux/init.h>
90 #include <linux/delay.h>
91 #include <linux/ioctl.h>
93 #include <asm/system.h>
97 #include <linux/bitops.h>
98 #include <asm/types.h>
99 #include <linux/termios.h>
100 #include <linux/workqueue.h>
101 #include <linux/hdlc.h>
102 #include <linux/dma-mapping.h>
104 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_MODULE))
105 #define SYNCLINK_GENERIC_HDLC 1
107 #define SYNCLINK_GENERIC_HDLC 0
110 #define GET_USER(error,value,addr) error = get_user(value,addr)
111 #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
112 #define PUT_USER(error,value,addr) error = put_user(value,addr)
113 #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
115 #include <asm/uaccess.h>
117 #include "linux/synclink.h"
119 #define RCLRVALUE 0xffff
121 static MGSL_PARAMS default_params = {
122 MGSL_MODE_HDLC, /* unsigned long mode */
123 0, /* unsigned char loopback; */
124 HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
125 HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
126 0, /* unsigned long clock_speed; */
127 0xff, /* unsigned char addr_filter; */
128 HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
129 HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
130 HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
131 9600, /* unsigned long data_rate; */
132 8, /* unsigned char data_bits; */
133 1, /* unsigned char stop_bits; */
134 ASYNC_PARITY_NONE /* unsigned char parity; */
137 #define SHARED_MEM_ADDRESS_SIZE 0x40000
138 #define BUFFERLISTSIZE 4096
139 #define DMABUFFERSIZE 4096
140 #define MAXRXFRAMES 7
142 typedef struct _DMABUFFERENTRY
144 u32 phys_addr; /* 32-bit flat physical address of data buffer */
145 volatile u16 count; /* buffer size/data count */
146 volatile u16 status; /* Control/status field */
147 volatile u16 rcc; /* character count field */
148 u16 reserved; /* padding required by 16C32 */
149 u32 link; /* 32-bit flat link to next buffer entry */
150 char *virt_addr; /* virtual address of data buffer */
151 u32 phys_entry; /* physical address of this buffer entry */
153 } DMABUFFERENTRY, *DMAPBUFFERENTRY;
155 /* The queue of BH actions to be performed */
158 #define BH_TRANSMIT 2
161 #define IO_PIN_SHUTDOWN_LIMIT 100
163 struct _input_signal_events {
174 /* transmit holding buffer definitions*/
175 #define MAX_TX_HOLDING_BUFFERS 5
176 struct tx_holding_buffer {
178 unsigned char * buffer;
183 * Device instance data structure
189 int count; /* count of opens */
192 unsigned short close_delay;
193 unsigned short closing_wait; /* time to wait before closing */
195 struct mgsl_icount icount;
197 struct tty_struct *tty;
199 int x_char; /* xon/xoff character */
200 int blocked_open; /* # of blocked opens */
201 u16 read_status_mask;
202 u16 ignore_status_mask;
203 unsigned char *xmit_buf;
208 wait_queue_head_t open_wait;
209 wait_queue_head_t close_wait;
211 wait_queue_head_t status_event_wait_q;
212 wait_queue_head_t event_wait_q;
213 struct timer_list tx_timer; /* HDLC transmit timeout timer */
214 struct mgsl_struct *next_device; /* device list link */
216 spinlock_t irq_spinlock; /* spinlock for synchronizing with ISR */
217 struct work_struct task; /* task structure for scheduling bh */
219 u32 EventMask; /* event trigger mask */
220 u32 RecordedEvents; /* pending events */
222 u32 max_frame_size; /* as set by device config */
226 int bh_running; /* Protection from multiple */
230 int dcd_chkcount; /* check counts to prevent */
231 int cts_chkcount; /* too many IRQs if a signal */
232 int dsr_chkcount; /* is floating */
235 char *buffer_list; /* virtual address of Rx & Tx buffer lists */
236 u32 buffer_list_phys;
237 dma_addr_t buffer_list_dma_addr;
239 unsigned int rx_buffer_count; /* count of total allocated Rx buffers */
240 DMABUFFERENTRY *rx_buffer_list; /* list of receive buffer entries */
241 unsigned int current_rx_buffer;
243 int num_tx_dma_buffers; /* number of tx dma frames required */
244 int tx_dma_buffers_used;
245 unsigned int tx_buffer_count; /* count of total allocated Tx buffers */
246 DMABUFFERENTRY *tx_buffer_list; /* list of transmit buffer entries */
247 int start_tx_dma_buffer; /* tx dma buffer to start tx dma operation */
248 int current_tx_buffer; /* next tx dma buffer to be loaded */
250 unsigned char *intermediate_rxbuffer;
252 int num_tx_holding_buffers; /* number of tx holding buffer allocated */
253 int get_tx_holding_index; /* next tx holding buffer for adapter to load */
254 int put_tx_holding_index; /* next tx holding buffer to store user request */
255 int tx_holding_count; /* number of tx holding buffers waiting */
256 struct tx_holding_buffer tx_holding_buffers[MAX_TX_HOLDING_BUFFERS];
269 char device_name[25]; /* device instance name */
271 unsigned int bus_type; /* expansion bus type (ISA,EISA,PCI) */
272 unsigned char bus; /* expansion bus number (zero based) */
273 unsigned char function; /* PCI device number */
275 unsigned int io_base; /* base I/O address of adapter */
276 unsigned int io_addr_size; /* size of the I/O address range */
277 int io_addr_requested; /* nonzero if I/O address requested */
279 unsigned int irq_level; /* interrupt level */
280 unsigned long irq_flags;
281 int irq_requested; /* nonzero if IRQ requested */
283 unsigned int dma_level; /* DMA channel */
284 int dma_requested; /* nonzero if dma channel requested */
290 MGSL_PARAMS params; /* communications parameters */
292 unsigned char serial_signals; /* current serial signal states */
294 int irq_occurred; /* for diagnostics use */
295 unsigned int init_error; /* Initialization startup error (DIAGS) */
296 int fDiagnosticsmode; /* Driver in Diagnostic mode? (DIAGS) */
299 unsigned char* memory_base; /* shared memory address (PCI only) */
300 u32 phys_memory_base;
301 int shared_mem_requested;
303 unsigned char* lcr_base; /* local config registers (PCI only) */
306 int lcr_mem_requested;
309 char flag_buf[MAX_ASYNC_BUFFER_SIZE];
310 char char_buf[MAX_ASYNC_BUFFER_SIZE];
311 BOOLEAN drop_rts_on_tx_done;
313 BOOLEAN loopmode_insert_requested;
314 BOOLEAN loopmode_send_done_requested;
316 struct _input_signal_events input_signal_events;
318 /* generic HDLC device parts */
323 #if SYNCLINK_GENERIC_HDLC
324 struct net_device *netdev;
328 #define MGSL_MAGIC 0x5401
331 * The size of the serial xmit buffer is 1 page, or 4096 bytes
333 #ifndef SERIAL_XMIT_SIZE
334 #define SERIAL_XMIT_SIZE 4096
338 * These macros define the offsets used in calculating the
339 * I/O address of the specified USC registers.
343 #define DCPIN 2 /* Bit 1 of I/O address */
344 #define SDPIN 4 /* Bit 2 of I/O address */
346 #define DCAR 0 /* DMA command/address register */
347 #define CCAR SDPIN /* channel command/address register */
348 #define DATAREG DCPIN + SDPIN /* serial data register */
353 * These macros define the register address (ordinal number)
354 * used for writing address/value pairs to the USC.
357 #define CMR 0x02 /* Channel mode Register */
358 #define CCSR 0x04 /* Channel Command/status Register */
359 #define CCR 0x06 /* Channel Control Register */
360 #define PSR 0x08 /* Port status Register */
361 #define PCR 0x0a /* Port Control Register */
362 #define TMDR 0x0c /* Test mode Data Register */
363 #define TMCR 0x0e /* Test mode Control Register */
364 #define CMCR 0x10 /* Clock mode Control Register */
365 #define HCR 0x12 /* Hardware Configuration Register */
366 #define IVR 0x14 /* Interrupt Vector Register */
367 #define IOCR 0x16 /* Input/Output Control Register */
368 #define ICR 0x18 /* Interrupt Control Register */
369 #define DCCR 0x1a /* Daisy Chain Control Register */
370 #define MISR 0x1c /* Misc Interrupt status Register */
371 #define SICR 0x1e /* status Interrupt Control Register */
372 #define RDR 0x20 /* Receive Data Register */
373 #define RMR 0x22 /* Receive mode Register */
374 #define RCSR 0x24 /* Receive Command/status Register */
375 #define RICR 0x26 /* Receive Interrupt Control Register */
376 #define RSR 0x28 /* Receive Sync Register */
377 #define RCLR 0x2a /* Receive count Limit Register */
378 #define RCCR 0x2c /* Receive Character count Register */
379 #define TC0R 0x2e /* Time Constant 0 Register */
380 #define TDR 0x30 /* Transmit Data Register */
381 #define TMR 0x32 /* Transmit mode Register */
382 #define TCSR 0x34 /* Transmit Command/status Register */
383 #define TICR 0x36 /* Transmit Interrupt Control Register */
384 #define TSR 0x38 /* Transmit Sync Register */
385 #define TCLR 0x3a /* Transmit count Limit Register */
386 #define TCCR 0x3c /* Transmit Character count Register */
387 #define TC1R 0x3e /* Time Constant 1 Register */
391 * MACRO DEFINITIONS FOR DMA REGISTERS
394 #define DCR 0x06 /* DMA Control Register (shared) */
395 #define DACR 0x08 /* DMA Array count Register (shared) */
396 #define BDCR 0x12 /* Burst/Dwell Control Register (shared) */
397 #define DIVR 0x14 /* DMA Interrupt Vector Register (shared) */
398 #define DICR 0x18 /* DMA Interrupt Control Register (shared) */
399 #define CDIR 0x1a /* Clear DMA Interrupt Register (shared) */
400 #define SDIR 0x1c /* Set DMA Interrupt Register (shared) */
402 #define TDMR 0x02 /* Transmit DMA mode Register */
403 #define TDIAR 0x1e /* Transmit DMA Interrupt Arm Register */
404 #define TBCR 0x2a /* Transmit Byte count Register */
405 #define TARL 0x2c /* Transmit Address Register (low) */
406 #define TARU 0x2e /* Transmit Address Register (high) */
407 #define NTBCR 0x3a /* Next Transmit Byte count Register */
408 #define NTARL 0x3c /* Next Transmit Address Register (low) */
409 #define NTARU 0x3e /* Next Transmit Address Register (high) */
411 #define RDMR 0x82 /* Receive DMA mode Register (non-shared) */
412 #define RDIAR 0x9e /* Receive DMA Interrupt Arm Register */
413 #define RBCR 0xaa /* Receive Byte count Register */
414 #define RARL 0xac /* Receive Address Register (low) */
415 #define RARU 0xae /* Receive Address Register (high) */
416 #define NRBCR 0xba /* Next Receive Byte count Register */
417 #define NRARL 0xbc /* Next Receive Address Register (low) */
418 #define NRARU 0xbe /* Next Receive Address Register (high) */
422 * MACRO DEFINITIONS FOR MODEM STATUS BITS
425 #define MODEMSTATUS_DTR 0x80
426 #define MODEMSTATUS_DSR 0x40
427 #define MODEMSTATUS_RTS 0x20
428 #define MODEMSTATUS_CTS 0x10
429 #define MODEMSTATUS_RI 0x04
430 #define MODEMSTATUS_DCD 0x01
434 * Channel Command/Address Register (CCAR) Command Codes
437 #define RTCmd_Null 0x0000
438 #define RTCmd_ResetHighestIus 0x1000
439 #define RTCmd_TriggerChannelLoadDma 0x2000
440 #define RTCmd_TriggerRxDma 0x2800
441 #define RTCmd_TriggerTxDma 0x3000
442 #define RTCmd_TriggerRxAndTxDma 0x3800
443 #define RTCmd_PurgeRxFifo 0x4800
444 #define RTCmd_PurgeTxFifo 0x5000
445 #define RTCmd_PurgeRxAndTxFifo 0x5800
446 #define RTCmd_LoadRcc 0x6800
447 #define RTCmd_LoadTcc 0x7000
448 #define RTCmd_LoadRccAndTcc 0x7800
449 #define RTCmd_LoadTC0 0x8800
450 #define RTCmd_LoadTC1 0x9000
451 #define RTCmd_LoadTC0AndTC1 0x9800
452 #define RTCmd_SerialDataLSBFirst 0xa000
453 #define RTCmd_SerialDataMSBFirst 0xa800
454 #define RTCmd_SelectBigEndian 0xb000
455 #define RTCmd_SelectLittleEndian 0xb800
459 * DMA Command/Address Register (DCAR) Command Codes
462 #define DmaCmd_Null 0x0000
463 #define DmaCmd_ResetTxChannel 0x1000
464 #define DmaCmd_ResetRxChannel 0x1200
465 #define DmaCmd_StartTxChannel 0x2000
466 #define DmaCmd_StartRxChannel 0x2200
467 #define DmaCmd_ContinueTxChannel 0x3000
468 #define DmaCmd_ContinueRxChannel 0x3200
469 #define DmaCmd_PauseTxChannel 0x4000
470 #define DmaCmd_PauseRxChannel 0x4200
471 #define DmaCmd_AbortTxChannel 0x5000
472 #define DmaCmd_AbortRxChannel 0x5200
473 #define DmaCmd_InitTxChannel 0x7000
474 #define DmaCmd_InitRxChannel 0x7200
475 #define DmaCmd_ResetHighestDmaIus 0x8000
476 #define DmaCmd_ResetAllChannels 0x9000
477 #define DmaCmd_StartAllChannels 0xa000
478 #define DmaCmd_ContinueAllChannels 0xb000
479 #define DmaCmd_PauseAllChannels 0xc000
480 #define DmaCmd_AbortAllChannels 0xd000
481 #define DmaCmd_InitAllChannels 0xf000
483 #define TCmd_Null 0x0000
484 #define TCmd_ClearTxCRC 0x2000
485 #define TCmd_SelectTicrTtsaData 0x4000
486 #define TCmd_SelectTicrTxFifostatus 0x5000
487 #define TCmd_SelectTicrIntLevel 0x6000
488 #define TCmd_SelectTicrdma_level 0x7000
489 #define TCmd_SendFrame 0x8000
490 #define TCmd_SendAbort 0x9000
491 #define TCmd_EnableDleInsertion 0xc000
492 #define TCmd_DisableDleInsertion 0xd000
493 #define TCmd_ClearEofEom 0xe000
494 #define TCmd_SetEofEom 0xf000
496 #define RCmd_Null 0x0000
497 #define RCmd_ClearRxCRC 0x2000
498 #define RCmd_EnterHuntmode 0x3000
499 #define RCmd_SelectRicrRtsaData 0x4000
500 #define RCmd_SelectRicrRxFifostatus 0x5000
501 #define RCmd_SelectRicrIntLevel 0x6000
502 #define RCmd_SelectRicrdma_level 0x7000
505 * Bits for enabling and disabling IRQs in Interrupt Control Register (ICR)
508 #define RECEIVE_STATUS BIT5
509 #define RECEIVE_DATA BIT4
510 #define TRANSMIT_STATUS BIT3
511 #define TRANSMIT_DATA BIT2
517 * Receive status Bits in Receive Command/status Register RCSR
520 #define RXSTATUS_SHORT_FRAME BIT8
521 #define RXSTATUS_CODE_VIOLATION BIT8
522 #define RXSTATUS_EXITED_HUNT BIT7
523 #define RXSTATUS_IDLE_RECEIVED BIT6
524 #define RXSTATUS_BREAK_RECEIVED BIT5
525 #define RXSTATUS_ABORT_RECEIVED BIT5
526 #define RXSTATUS_RXBOUND BIT4
527 #define RXSTATUS_CRC_ERROR BIT3
528 #define RXSTATUS_FRAMING_ERROR BIT3
529 #define RXSTATUS_ABORT BIT2
530 #define RXSTATUS_PARITY_ERROR BIT2
531 #define RXSTATUS_OVERRUN BIT1
532 #define RXSTATUS_DATA_AVAILABLE BIT0
533 #define RXSTATUS_ALL 0x01f6
534 #define usc_UnlatchRxstatusBits(a,b) usc_OutReg( (a), RCSR, (u16)((b) & RXSTATUS_ALL) )
537 * Values for setting transmit idle mode in
538 * Transmit Control/status Register (TCSR)
540 #define IDLEMODE_FLAGS 0x0000
541 #define IDLEMODE_ALT_ONE_ZERO 0x0100
542 #define IDLEMODE_ZERO 0x0200
543 #define IDLEMODE_ONE 0x0300
544 #define IDLEMODE_ALT_MARK_SPACE 0x0500
545 #define IDLEMODE_SPACE 0x0600
546 #define IDLEMODE_MARK 0x0700
547 #define IDLEMODE_MASK 0x0700
550 * IUSC revision identifiers
552 #define IUSC_SL1660 0x4d44
553 #define IUSC_PRE_SL1660 0x4553
556 * Transmit status Bits in Transmit Command/status Register (TCSR)
559 #define TCSR_PRESERVE 0x0F00
561 #define TCSR_UNDERWAIT BIT11
562 #define TXSTATUS_PREAMBLE_SENT BIT7
563 #define TXSTATUS_IDLE_SENT BIT6
564 #define TXSTATUS_ABORT_SENT BIT5
565 #define TXSTATUS_EOF_SENT BIT4
566 #define TXSTATUS_EOM_SENT BIT4
567 #define TXSTATUS_CRC_SENT BIT3
568 #define TXSTATUS_ALL_SENT BIT2
569 #define TXSTATUS_UNDERRUN BIT1
570 #define TXSTATUS_FIFO_EMPTY BIT0
571 #define TXSTATUS_ALL 0x00fa
572 #define usc_UnlatchTxstatusBits(a,b) usc_OutReg( (a), TCSR, (u16)((a)->tcsr_value + ((b) & 0x00FF)) )
575 #define MISCSTATUS_RXC_LATCHED BIT15
576 #define MISCSTATUS_RXC BIT14
577 #define MISCSTATUS_TXC_LATCHED BIT13
578 #define MISCSTATUS_TXC BIT12
579 #define MISCSTATUS_RI_LATCHED BIT11
580 #define MISCSTATUS_RI BIT10
581 #define MISCSTATUS_DSR_LATCHED BIT9
582 #define MISCSTATUS_DSR BIT8
583 #define MISCSTATUS_DCD_LATCHED BIT7
584 #define MISCSTATUS_DCD BIT6
585 #define MISCSTATUS_CTS_LATCHED BIT5
586 #define MISCSTATUS_CTS BIT4
587 #define MISCSTATUS_RCC_UNDERRUN BIT3
588 #define MISCSTATUS_DPLL_NO_SYNC BIT2
589 #define MISCSTATUS_BRG1_ZERO BIT1
590 #define MISCSTATUS_BRG0_ZERO BIT0
592 #define usc_UnlatchIostatusBits(a,b) usc_OutReg((a),MISR,(u16)((b) & 0xaaa0))
593 #define usc_UnlatchMiscstatusBits(a,b) usc_OutReg((a),MISR,(u16)((b) & 0x000f))
595 #define SICR_RXC_ACTIVE BIT15
596 #define SICR_RXC_INACTIVE BIT14
597 #define SICR_RXC (BIT15+BIT14)
598 #define SICR_TXC_ACTIVE BIT13
599 #define SICR_TXC_INACTIVE BIT12
600 #define SICR_TXC (BIT13+BIT12)
601 #define SICR_RI_ACTIVE BIT11
602 #define SICR_RI_INACTIVE BIT10
603 #define SICR_RI (BIT11+BIT10)
604 #define SICR_DSR_ACTIVE BIT9
605 #define SICR_DSR_INACTIVE BIT8
606 #define SICR_DSR (BIT9+BIT8)
607 #define SICR_DCD_ACTIVE BIT7
608 #define SICR_DCD_INACTIVE BIT6
609 #define SICR_DCD (BIT7+BIT6)
610 #define SICR_CTS_ACTIVE BIT5
611 #define SICR_CTS_INACTIVE BIT4
612 #define SICR_CTS (BIT5+BIT4)
613 #define SICR_RCC_UNDERFLOW BIT3
614 #define SICR_DPLL_NO_SYNC BIT2
615 #define SICR_BRG1_ZERO BIT1
616 #define SICR_BRG0_ZERO BIT0
618 void usc_DisableMasterIrqBit( struct mgsl_struct *info );
619 void usc_EnableMasterIrqBit( struct mgsl_struct *info );
620 void usc_EnableInterrupts( struct mgsl_struct *info, u16 IrqMask );
621 void usc_DisableInterrupts( struct mgsl_struct *info, u16 IrqMask );
622 void usc_ClearIrqPendingBits( struct mgsl_struct *info, u16 IrqMask );
624 #define usc_EnableInterrupts( a, b ) \
625 usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0xff00) + 0xc0 + (b)) )
627 #define usc_DisableInterrupts( a, b ) \
628 usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0xff00) + 0x80 + (b)) )
630 #define usc_EnableMasterIrqBit(a) \
631 usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0x0f00) + 0xb000) )
633 #define usc_DisableMasterIrqBit(a) \
634 usc_OutReg( (a), ICR, (u16)(usc_InReg((a),ICR) & 0x7f00) )
636 #define usc_ClearIrqPendingBits( a, b ) usc_OutReg( (a), DCCR, 0x40 + (b) )
639 * Transmit status Bits in Transmit Control status Register (TCSR)
640 * and Transmit Interrupt Control Register (TICR) (except BIT2, BIT0)
643 #define TXSTATUS_PREAMBLE_SENT BIT7
644 #define TXSTATUS_IDLE_SENT BIT6
645 #define TXSTATUS_ABORT_SENT BIT5
646 #define TXSTATUS_EOF BIT4
647 #define TXSTATUS_CRC_SENT BIT3
648 #define TXSTATUS_ALL_SENT BIT2
649 #define TXSTATUS_UNDERRUN BIT1
650 #define TXSTATUS_FIFO_EMPTY BIT0
652 #define DICR_MASTER BIT15
653 #define DICR_TRANSMIT BIT0
654 #define DICR_RECEIVE BIT1
656 #define usc_EnableDmaInterrupts(a,b) \
657 usc_OutDmaReg( (a), DICR, (u16)(usc_InDmaReg((a),DICR) | (b)) )
659 #define usc_DisableDmaInterrupts(a,b) \
660 usc_OutDmaReg( (a), DICR, (u16)(usc_InDmaReg((a),DICR) & ~(b)) )
662 #define usc_EnableStatusIrqs(a,b) \
663 usc_OutReg( (a), SICR, (u16)(usc_InReg((a),SICR) | (b)) )
665 #define usc_DisablestatusIrqs(a,b) \
666 usc_OutReg( (a), SICR, (u16)(usc_InReg((a),SICR) & ~(b)) )
668 /* Transmit status Bits in Transmit Control status Register (TCSR) */
669 /* and Transmit Interrupt Control Register (TICR) (except BIT2, BIT0) */
672 #define DISABLE_UNCONDITIONAL 0
673 #define DISABLE_END_OF_FRAME 1
674 #define ENABLE_UNCONDITIONAL 2
675 #define ENABLE_AUTO_CTS 3
676 #define ENABLE_AUTO_DCD 3
677 #define usc_EnableTransmitter(a,b) \
678 usc_OutReg( (a), TMR, (u16)((usc_InReg((a),TMR) & 0xfffc) | (b)) )
679 #define usc_EnableReceiver(a,b) \
680 usc_OutReg( (a), RMR, (u16)((usc_InReg((a),RMR) & 0xfffc) | (b)) )
682 static u16 usc_InDmaReg( struct mgsl_struct *info, u16 Port );
683 static void usc_OutDmaReg( struct mgsl_struct *info, u16 Port, u16 Value );
684 static void usc_DmaCmd( struct mgsl_struct *info, u16 Cmd );
686 static u16 usc_InReg( struct mgsl_struct *info, u16 Port );
687 static void usc_OutReg( struct mgsl_struct *info, u16 Port, u16 Value );
688 static void usc_RTCmd( struct mgsl_struct *info, u16 Cmd );
689 void usc_RCmd( struct mgsl_struct *info, u16 Cmd );
690 void usc_TCmd( struct mgsl_struct *info, u16 Cmd );
692 #define usc_TCmd(a,b) usc_OutReg((a), TCSR, (u16)((a)->tcsr_value + (b)))
693 #define usc_RCmd(a,b) usc_OutReg((a), RCSR, (b))
695 #define usc_SetTransmitSyncChars(a,s0,s1) usc_OutReg((a), TSR, (u16)(((u16)s0<<8)|(u16)s1))
697 static void usc_process_rxoverrun_sync( struct mgsl_struct *info );
698 static void usc_start_receiver( struct mgsl_struct *info );
699 static void usc_stop_receiver( struct mgsl_struct *info );
701 static void usc_start_transmitter( struct mgsl_struct *info );
702 static void usc_stop_transmitter( struct mgsl_struct *info );
703 static void usc_set_txidle( struct mgsl_struct *info );
704 static void usc_load_txfifo( struct mgsl_struct *info );
706 static void usc_enable_aux_clock( struct mgsl_struct *info, u32 DataRate );
707 static void usc_enable_loopback( struct mgsl_struct *info, int enable );
709 static void usc_get_serial_signals( struct mgsl_struct *info );
710 static void usc_set_serial_signals( struct mgsl_struct *info );
712 static void usc_reset( struct mgsl_struct *info );
714 static void usc_set_sync_mode( struct mgsl_struct *info );
715 static void usc_set_sdlc_mode( struct mgsl_struct *info );
716 static void usc_set_async_mode( struct mgsl_struct *info );
717 static void usc_enable_async_clock( struct mgsl_struct *info, u32 DataRate );
719 static void usc_loopback_frame( struct mgsl_struct *info );
721 static void mgsl_tx_timeout(unsigned long context);
724 static void usc_loopmode_cancel_transmit( struct mgsl_struct * info );
725 static void usc_loopmode_insert_request( struct mgsl_struct * info );
726 static int usc_loopmode_active( struct mgsl_struct * info);
727 static void usc_loopmode_send_done( struct mgsl_struct * info );
729 static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg);
731 #if SYNCLINK_GENERIC_HDLC
732 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
733 static void hdlcdev_tx_done(struct mgsl_struct *info);
734 static void hdlcdev_rx(struct mgsl_struct *info, char *buf, int size);
735 static int hdlcdev_init(struct mgsl_struct *info);
736 static void hdlcdev_exit(struct mgsl_struct *info);
740 * Defines a BUS descriptor value for the PCI adapter
741 * local bus address ranges.
744 #define BUS_DESCRIPTOR( WrHold, WrDly, RdDly, Nwdd, Nwad, Nxda, Nrdd, Nrad ) \
755 static void mgsl_trace_block(struct mgsl_struct *info,const char* data, int count, int xmit);
758 * Adapter diagnostic routines
760 static BOOLEAN mgsl_register_test( struct mgsl_struct *info );
761 static BOOLEAN mgsl_irq_test( struct mgsl_struct *info );
762 static BOOLEAN mgsl_dma_test( struct mgsl_struct *info );
763 static BOOLEAN mgsl_memory_test( struct mgsl_struct *info );
764 static int mgsl_adapter_test( struct mgsl_struct *info );
767 * device and resource management routines
769 static int mgsl_claim_resources(struct mgsl_struct *info);
770 static void mgsl_release_resources(struct mgsl_struct *info);
771 static void mgsl_add_device(struct mgsl_struct *info);
772 static struct mgsl_struct* mgsl_allocate_device(void);
775 * DMA buffer manupulation functions.
777 static void mgsl_free_rx_frame_buffers( struct mgsl_struct *info, unsigned int StartIndex, unsigned int EndIndex );
778 static int mgsl_get_rx_frame( struct mgsl_struct *info );
779 static int mgsl_get_raw_rx_frame( struct mgsl_struct *info );
780 static void mgsl_reset_rx_dma_buffers( struct mgsl_struct *info );
781 static void mgsl_reset_tx_dma_buffers( struct mgsl_struct *info );
782 static int num_free_tx_dma_buffers(struct mgsl_struct *info);
783 static void mgsl_load_tx_dma_buffer( struct mgsl_struct *info, const char *Buffer, unsigned int BufferSize);
784 static void mgsl_load_pci_memory(char* TargetPtr, const char* SourcePtr, unsigned short count);
787 * DMA and Shared Memory buffer allocation and formatting
789 static int mgsl_allocate_dma_buffers(struct mgsl_struct *info);
790 static void mgsl_free_dma_buffers(struct mgsl_struct *info);
791 static int mgsl_alloc_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *BufferList,int Buffercount);
792 static void mgsl_free_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *BufferList,int Buffercount);
793 static int mgsl_alloc_buffer_list_memory(struct mgsl_struct *info);
794 static void mgsl_free_buffer_list_memory(struct mgsl_struct *info);
795 static int mgsl_alloc_intermediate_rxbuffer_memory(struct mgsl_struct *info);
796 static void mgsl_free_intermediate_rxbuffer_memory(struct mgsl_struct *info);
797 static int mgsl_alloc_intermediate_txbuffer_memory(struct mgsl_struct *info);
798 static void mgsl_free_intermediate_txbuffer_memory(struct mgsl_struct *info);
799 static int load_next_tx_holding_buffer(struct mgsl_struct *info);
800 static int save_tx_buffer_request(struct mgsl_struct *info,const char *Buffer, unsigned int BufferSize);
803 * Bottom half interrupt handlers
805 static void mgsl_bh_handler(struct work_struct *work);
806 static void mgsl_bh_receive(struct mgsl_struct *info);
807 static void mgsl_bh_transmit(struct mgsl_struct *info);
808 static void mgsl_bh_status(struct mgsl_struct *info);
811 * Interrupt handler routines and dispatch table.
813 static void mgsl_isr_null( struct mgsl_struct *info );
814 static void mgsl_isr_transmit_data( struct mgsl_struct *info );
815 static void mgsl_isr_receive_data( struct mgsl_struct *info );
816 static void mgsl_isr_receive_status( struct mgsl_struct *info );
817 static void mgsl_isr_transmit_status( struct mgsl_struct *info );
818 static void mgsl_isr_io_pin( struct mgsl_struct *info );
819 static void mgsl_isr_misc( struct mgsl_struct *info );
820 static void mgsl_isr_receive_dma( struct mgsl_struct *info );
821 static void mgsl_isr_transmit_dma( struct mgsl_struct *info );
823 typedef void (*isr_dispatch_func)(struct mgsl_struct *);
825 static isr_dispatch_func UscIsrTable[7] =
830 mgsl_isr_transmit_data,
831 mgsl_isr_transmit_status,
832 mgsl_isr_receive_data,
833 mgsl_isr_receive_status
837 * ioctl call handlers
839 static int tiocmget(struct tty_struct *tty, struct file *file);
840 static int tiocmset(struct tty_struct *tty, struct file *file,
841 unsigned int set, unsigned int clear);
842 static int mgsl_get_stats(struct mgsl_struct * info, struct mgsl_icount
843 __user *user_icount);
844 static int mgsl_get_params(struct mgsl_struct * info, MGSL_PARAMS __user *user_params);
845 static int mgsl_set_params(struct mgsl_struct * info, MGSL_PARAMS __user *new_params);
846 static int mgsl_get_txidle(struct mgsl_struct * info, int __user *idle_mode);
847 static int mgsl_set_txidle(struct mgsl_struct * info, int idle_mode);
848 static int mgsl_txenable(struct mgsl_struct * info, int enable);
849 static int mgsl_txabort(struct mgsl_struct * info);
850 static int mgsl_rxenable(struct mgsl_struct * info, int enable);
851 static int mgsl_wait_event(struct mgsl_struct * info, int __user *mask);
852 static int mgsl_loopmode_send_done( struct mgsl_struct * info );
854 /* set non-zero on successful registration with PCI subsystem */
855 static int pci_registered;
858 * Global linked list of SyncLink devices
860 static struct mgsl_struct *mgsl_device_list;
861 static int mgsl_device_count;
864 * Set this param to non-zero to load eax with the
865 * .text section address and breakpoint on module load.
866 * This is useful for use with gdb and add-symbol-file command.
868 static int break_on_load;
871 * Driver major number, defaults to zero to get auto
872 * assigned major number. May be forced as module parameter.
877 * Array of user specified options for ISA adapters.
879 static int io[MAX_ISA_DEVICES];
880 static int irq[MAX_ISA_DEVICES];
881 static int dma[MAX_ISA_DEVICES];
882 static int debug_level;
883 static int maxframe[MAX_TOTAL_DEVICES];
884 static int dosyncppp[MAX_TOTAL_DEVICES];
885 static int txdmabufs[MAX_TOTAL_DEVICES];
886 static int txholdbufs[MAX_TOTAL_DEVICES];
888 module_param(break_on_load, bool, 0);
889 module_param(ttymajor, int, 0);
890 module_param_array(io, int, NULL, 0);
891 module_param_array(irq, int, NULL, 0);
892 module_param_array(dma, int, NULL, 0);
893 module_param(debug_level, int, 0);
894 module_param_array(maxframe, int, NULL, 0);
895 module_param_array(dosyncppp, int, NULL, 0);
896 module_param_array(txdmabufs, int, NULL, 0);
897 module_param_array(txholdbufs, int, NULL, 0);
899 static char *driver_name = "SyncLink serial driver";
900 static char *driver_version = "$Revision: 4.38 $";
902 static int synclink_init_one (struct pci_dev *dev,
903 const struct pci_device_id *ent);
904 static void synclink_remove_one (struct pci_dev *dev);
906 static struct pci_device_id synclink_pci_tbl[] = {
907 { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_USC, PCI_ANY_ID, PCI_ANY_ID, },
908 { PCI_VENDOR_ID_MICROGATE, 0x0210, PCI_ANY_ID, PCI_ANY_ID, },
909 { 0, }, /* terminate list */
911 MODULE_DEVICE_TABLE(pci, synclink_pci_tbl);
913 MODULE_LICENSE("GPL");
915 static struct pci_driver synclink_pci_driver = {
917 .id_table = synclink_pci_tbl,
918 .probe = synclink_init_one,
919 .remove = __devexit_p(synclink_remove_one),
922 static struct tty_driver *serial_driver;
924 /* number of characters left in xmit buffer before we ask for more */
925 #define WAKEUP_CHARS 256
928 static void mgsl_change_params(struct mgsl_struct *info);
929 static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout);
932 * 1st function defined in .text section. Calling this function in
933 * init_module() followed by a breakpoint allows a remote debugger
934 * (gdb) to get the .text address for the add-symbol-file command.
935 * This allows remote debugging of dynamically loadable modules.
937 static void* mgsl_get_text_ptr(void)
939 return mgsl_get_text_ptr;
942 static inline int mgsl_paranoia_check(struct mgsl_struct *info,
943 char *name, const char *routine)
945 #ifdef MGSL_PARANOIA_CHECK
946 static const char *badmagic =
947 "Warning: bad magic number for mgsl struct (%s) in %s\n";
948 static const char *badinfo =
949 "Warning: null mgsl_struct for (%s) in %s\n";
952 printk(badinfo, name, routine);
955 if (info->magic != MGSL_MAGIC) {
956 printk(badmagic, name, routine);
967 * line discipline callback wrappers
969 * The wrappers maintain line discipline references
970 * while calling into the line discipline.
972 * ldisc_receive_buf - pass receive data to line discipline
975 static void ldisc_receive_buf(struct tty_struct *tty,
976 const __u8 *data, char *flags, int count)
978 struct tty_ldisc *ld;
981 ld = tty_ldisc_ref(tty);
984 ld->receive_buf(tty, data, flags, count);
989 /* mgsl_stop() throttle (stop) transmitter
991 * Arguments: tty pointer to tty info structure
994 static void mgsl_stop(struct tty_struct *tty)
996 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
999 if (mgsl_paranoia_check(info, tty->name, "mgsl_stop"))
1002 if ( debug_level >= DEBUG_LEVEL_INFO )
1003 printk("mgsl_stop(%s)\n",info->device_name);
1005 spin_lock_irqsave(&info->irq_spinlock,flags);
1006 if (info->tx_enabled)
1007 usc_stop_transmitter(info);
1008 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1010 } /* end of mgsl_stop() */
1012 /* mgsl_start() release (start) transmitter
1014 * Arguments: tty pointer to tty info structure
1015 * Return Value: None
1017 static void mgsl_start(struct tty_struct *tty)
1019 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
1020 unsigned long flags;
1022 if (mgsl_paranoia_check(info, tty->name, "mgsl_start"))
1025 if ( debug_level >= DEBUG_LEVEL_INFO )
1026 printk("mgsl_start(%s)\n",info->device_name);
1028 spin_lock_irqsave(&info->irq_spinlock,flags);
1029 if (!info->tx_enabled)
1030 usc_start_transmitter(info);
1031 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1033 } /* end of mgsl_start() */
1036 * Bottom half work queue access functions
1039 /* mgsl_bh_action() Return next bottom half action to perform.
1040 * Return Value: BH action code or 0 if nothing to do.
1042 static int mgsl_bh_action(struct mgsl_struct *info)
1044 unsigned long flags;
1047 spin_lock_irqsave(&info->irq_spinlock,flags);
1049 if (info->pending_bh & BH_RECEIVE) {
1050 info->pending_bh &= ~BH_RECEIVE;
1052 } else if (info->pending_bh & BH_TRANSMIT) {
1053 info->pending_bh &= ~BH_TRANSMIT;
1055 } else if (info->pending_bh & BH_STATUS) {
1056 info->pending_bh &= ~BH_STATUS;
1061 /* Mark BH routine as complete */
1062 info->bh_running = 0;
1063 info->bh_requested = 0;
1066 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1072 * Perform bottom half processing of work items queued by ISR.
1074 static void mgsl_bh_handler(struct work_struct *work)
1076 struct mgsl_struct *info =
1077 container_of(work, struct mgsl_struct, task);
1083 if ( debug_level >= DEBUG_LEVEL_BH )
1084 printk( "%s(%d):mgsl_bh_handler(%s) entry\n",
1085 __FILE__,__LINE__,info->device_name);
1087 info->bh_running = 1;
1089 while((action = mgsl_bh_action(info)) != 0) {
1091 /* Process work item */
1092 if ( debug_level >= DEBUG_LEVEL_BH )
1093 printk( "%s(%d):mgsl_bh_handler() work item action=%d\n",
1094 __FILE__,__LINE__,action);
1099 mgsl_bh_receive(info);
1102 mgsl_bh_transmit(info);
1105 mgsl_bh_status(info);
1108 /* unknown work item ID */
1109 printk("Unknown work item ID=%08X!\n", action);
1114 if ( debug_level >= DEBUG_LEVEL_BH )
1115 printk( "%s(%d):mgsl_bh_handler(%s) exit\n",
1116 __FILE__,__LINE__,info->device_name);
1119 static void mgsl_bh_receive(struct mgsl_struct *info)
1121 int (*get_rx_frame)(struct mgsl_struct *info) =
1122 (info->params.mode == MGSL_MODE_HDLC ? mgsl_get_rx_frame : mgsl_get_raw_rx_frame);
1124 if ( debug_level >= DEBUG_LEVEL_BH )
1125 printk( "%s(%d):mgsl_bh_receive(%s)\n",
1126 __FILE__,__LINE__,info->device_name);
1130 if (info->rx_rcc_underrun) {
1131 unsigned long flags;
1132 spin_lock_irqsave(&info->irq_spinlock,flags);
1133 usc_start_receiver(info);
1134 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1137 } while(get_rx_frame(info));
1140 static void mgsl_bh_transmit(struct mgsl_struct *info)
1142 struct tty_struct *tty = info->tty;
1143 unsigned long flags;
1145 if ( debug_level >= DEBUG_LEVEL_BH )
1146 printk( "%s(%d):mgsl_bh_transmit() entry on %s\n",
1147 __FILE__,__LINE__,info->device_name);
1152 /* if transmitter idle and loopmode_send_done_requested
1153 * then start echoing RxD to TxD
1155 spin_lock_irqsave(&info->irq_spinlock,flags);
1156 if ( !info->tx_active && info->loopmode_send_done_requested )
1157 usc_loopmode_send_done( info );
1158 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1161 static void mgsl_bh_status(struct mgsl_struct *info)
1163 if ( debug_level >= DEBUG_LEVEL_BH )
1164 printk( "%s(%d):mgsl_bh_status() entry on %s\n",
1165 __FILE__,__LINE__,info->device_name);
1167 info->ri_chkcount = 0;
1168 info->dsr_chkcount = 0;
1169 info->dcd_chkcount = 0;
1170 info->cts_chkcount = 0;
1173 /* mgsl_isr_receive_status()
1175 * Service a receive status interrupt. The type of status
1176 * interrupt is indicated by the state of the RCSR.
1177 * This is only used for HDLC mode.
1179 * Arguments: info pointer to device instance data
1180 * Return Value: None
1182 static void mgsl_isr_receive_status( struct mgsl_struct *info )
1184 u16 status = usc_InReg( info, RCSR );
1186 if ( debug_level >= DEBUG_LEVEL_ISR )
1187 printk("%s(%d):mgsl_isr_receive_status status=%04X\n",
1188 __FILE__,__LINE__,status);
1190 if ( (status & RXSTATUS_ABORT_RECEIVED) &&
1191 info->loopmode_insert_requested &&
1192 usc_loopmode_active(info) )
1194 ++info->icount.rxabort;
1195 info->loopmode_insert_requested = FALSE;
1197 /* clear CMR:13 to start echoing RxD to TxD */
1198 info->cmr_value &= ~BIT13;
1199 usc_OutReg(info, CMR, info->cmr_value);
1201 /* disable received abort irq (no longer required) */
1202 usc_OutReg(info, RICR,
1203 (usc_InReg(info, RICR) & ~RXSTATUS_ABORT_RECEIVED));
1206 if (status & (RXSTATUS_EXITED_HUNT + RXSTATUS_IDLE_RECEIVED)) {
1207 if (status & RXSTATUS_EXITED_HUNT)
1208 info->icount.exithunt++;
1209 if (status & RXSTATUS_IDLE_RECEIVED)
1210 info->icount.rxidle++;
1211 wake_up_interruptible(&info->event_wait_q);
1214 if (status & RXSTATUS_OVERRUN){
1215 info->icount.rxover++;
1216 usc_process_rxoverrun_sync( info );
1219 usc_ClearIrqPendingBits( info, RECEIVE_STATUS );
1220 usc_UnlatchRxstatusBits( info, status );
1222 } /* end of mgsl_isr_receive_status() */
1224 /* mgsl_isr_transmit_status()
1226 * Service a transmit status interrupt
1227 * HDLC mode :end of transmit frame
1228 * Async mode:all data is sent
1229 * transmit status is indicated by bits in the TCSR.
1231 * Arguments: info pointer to device instance data
1232 * Return Value: None
1234 static void mgsl_isr_transmit_status( struct mgsl_struct *info )
1236 u16 status = usc_InReg( info, TCSR );
1238 if ( debug_level >= DEBUG_LEVEL_ISR )
1239 printk("%s(%d):mgsl_isr_transmit_status status=%04X\n",
1240 __FILE__,__LINE__,status);
1242 usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
1243 usc_UnlatchTxstatusBits( info, status );
1245 if ( status & (TXSTATUS_UNDERRUN | TXSTATUS_ABORT_SENT) )
1247 /* finished sending HDLC abort. This may leave */
1248 /* the TxFifo with data from the aborted frame */
1249 /* so purge the TxFifo. Also shutdown the DMA */
1250 /* channel in case there is data remaining in */
1251 /* the DMA buffer */
1252 usc_DmaCmd( info, DmaCmd_ResetTxChannel );
1253 usc_RTCmd( info, RTCmd_PurgeTxFifo );
1256 if ( status & TXSTATUS_EOF_SENT )
1257 info->icount.txok++;
1258 else if ( status & TXSTATUS_UNDERRUN )
1259 info->icount.txunder++;
1260 else if ( status & TXSTATUS_ABORT_SENT )
1261 info->icount.txabort++;
1263 info->icount.txunder++;
1265 info->tx_active = 0;
1266 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1267 del_timer(&info->tx_timer);
1269 if ( info->drop_rts_on_tx_done ) {
1270 usc_get_serial_signals( info );
1271 if ( info->serial_signals & SerialSignal_RTS ) {
1272 info->serial_signals &= ~SerialSignal_RTS;
1273 usc_set_serial_signals( info );
1275 info->drop_rts_on_tx_done = 0;
1278 #if SYNCLINK_GENERIC_HDLC
1280 hdlcdev_tx_done(info);
1284 if (info->tty->stopped || info->tty->hw_stopped) {
1285 usc_stop_transmitter(info);
1288 info->pending_bh |= BH_TRANSMIT;
1291 } /* end of mgsl_isr_transmit_status() */
1293 /* mgsl_isr_io_pin()
1295 * Service an Input/Output pin interrupt. The type of
1296 * interrupt is indicated by bits in the MISR
1298 * Arguments: info pointer to device instance data
1299 * Return Value: None
1301 static void mgsl_isr_io_pin( struct mgsl_struct *info )
1303 struct mgsl_icount *icount;
1304 u16 status = usc_InReg( info, MISR );
1306 if ( debug_level >= DEBUG_LEVEL_ISR )
1307 printk("%s(%d):mgsl_isr_io_pin status=%04X\n",
1308 __FILE__,__LINE__,status);
1310 usc_ClearIrqPendingBits( info, IO_PIN );
1311 usc_UnlatchIostatusBits( info, status );
1313 if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
1314 MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
1315 icount = &info->icount;
1316 /* update input line counters */
1317 if (status & MISCSTATUS_RI_LATCHED) {
1318 if ((info->ri_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
1319 usc_DisablestatusIrqs(info,SICR_RI);
1321 if ( status & MISCSTATUS_RI )
1322 info->input_signal_events.ri_up++;
1324 info->input_signal_events.ri_down++;
1326 if (status & MISCSTATUS_DSR_LATCHED) {
1327 if ((info->dsr_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
1328 usc_DisablestatusIrqs(info,SICR_DSR);
1330 if ( status & MISCSTATUS_DSR )
1331 info->input_signal_events.dsr_up++;
1333 info->input_signal_events.dsr_down++;
1335 if (status & MISCSTATUS_DCD_LATCHED) {
1336 if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
1337 usc_DisablestatusIrqs(info,SICR_DCD);
1339 if (status & MISCSTATUS_DCD) {
1340 info->input_signal_events.dcd_up++;
1342 info->input_signal_events.dcd_down++;
1343 #if SYNCLINK_GENERIC_HDLC
1344 if (info->netcount) {
1345 if (status & MISCSTATUS_DCD)
1346 netif_carrier_on(info->netdev);
1348 netif_carrier_off(info->netdev);
1352 if (status & MISCSTATUS_CTS_LATCHED)
1354 if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT)
1355 usc_DisablestatusIrqs(info,SICR_CTS);
1357 if ( status & MISCSTATUS_CTS )
1358 info->input_signal_events.cts_up++;
1360 info->input_signal_events.cts_down++;
1362 wake_up_interruptible(&info->status_event_wait_q);
1363 wake_up_interruptible(&info->event_wait_q);
1365 if ( (info->flags & ASYNC_CHECK_CD) &&
1366 (status & MISCSTATUS_DCD_LATCHED) ) {
1367 if ( debug_level >= DEBUG_LEVEL_ISR )
1368 printk("%s CD now %s...", info->device_name,
1369 (status & MISCSTATUS_DCD) ? "on" : "off");
1370 if (status & MISCSTATUS_DCD)
1371 wake_up_interruptible(&info->open_wait);
1373 if ( debug_level >= DEBUG_LEVEL_ISR )
1374 printk("doing serial hangup...");
1376 tty_hangup(info->tty);
1380 if ( (info->flags & ASYNC_CTS_FLOW) &&
1381 (status & MISCSTATUS_CTS_LATCHED) ) {
1382 if (info->tty->hw_stopped) {
1383 if (status & MISCSTATUS_CTS) {
1384 if ( debug_level >= DEBUG_LEVEL_ISR )
1385 printk("CTS tx start...");
1387 info->tty->hw_stopped = 0;
1388 usc_start_transmitter(info);
1389 info->pending_bh |= BH_TRANSMIT;
1393 if (!(status & MISCSTATUS_CTS)) {
1394 if ( debug_level >= DEBUG_LEVEL_ISR )
1395 printk("CTS tx stop...");
1397 info->tty->hw_stopped = 1;
1398 usc_stop_transmitter(info);
1404 info->pending_bh |= BH_STATUS;
1406 /* for diagnostics set IRQ flag */
1407 if ( status & MISCSTATUS_TXC_LATCHED ){
1408 usc_OutReg( info, SICR,
1409 (unsigned short)(usc_InReg(info,SICR) & ~(SICR_TXC_ACTIVE+SICR_TXC_INACTIVE)) );
1410 usc_UnlatchIostatusBits( info, MISCSTATUS_TXC_LATCHED );
1411 info->irq_occurred = 1;
1414 } /* end of mgsl_isr_io_pin() */
1416 /* mgsl_isr_transmit_data()
1418 * Service a transmit data interrupt (async mode only).
1420 * Arguments: info pointer to device instance data
1421 * Return Value: None
1423 static void mgsl_isr_transmit_data( struct mgsl_struct *info )
1425 if ( debug_level >= DEBUG_LEVEL_ISR )
1426 printk("%s(%d):mgsl_isr_transmit_data xmit_cnt=%d\n",
1427 __FILE__,__LINE__,info->xmit_cnt);
1429 usc_ClearIrqPendingBits( info, TRANSMIT_DATA );
1431 if (info->tty->stopped || info->tty->hw_stopped) {
1432 usc_stop_transmitter(info);
1436 if ( info->xmit_cnt )
1437 usc_load_txfifo( info );
1439 info->tx_active = 0;
1441 if (info->xmit_cnt < WAKEUP_CHARS)
1442 info->pending_bh |= BH_TRANSMIT;
1444 } /* end of mgsl_isr_transmit_data() */
1446 /* mgsl_isr_receive_data()
1448 * Service a receive data interrupt. This occurs
1449 * when operating in asynchronous interrupt transfer mode.
1450 * The receive data FIFO is flushed to the receive data buffers.
1452 * Arguments: info pointer to device instance data
1453 * Return Value: None
1455 static void mgsl_isr_receive_data( struct mgsl_struct *info )
1460 unsigned char DataByte;
1461 struct tty_struct *tty = info->tty;
1462 struct mgsl_icount *icount = &info->icount;
1464 if ( debug_level >= DEBUG_LEVEL_ISR )
1465 printk("%s(%d):mgsl_isr_receive_data\n",
1468 usc_ClearIrqPendingBits( info, RECEIVE_DATA );
1470 /* select FIFO status for RICR readback */
1471 usc_RCmd( info, RCmd_SelectRicrRxFifostatus );
1473 /* clear the Wordstatus bit so that status readback */
1474 /* only reflects the status of this byte */
1475 usc_OutReg( info, RICR+LSBONLY, (u16)(usc_InReg(info, RICR+LSBONLY) & ~BIT3 ));
1477 /* flush the receive FIFO */
1479 while( (Fifocount = (usc_InReg(info,RICR) >> 8)) ) {
1482 /* read one byte from RxFIFO */
1483 outw( (inw(info->io_base + CCAR) & 0x0780) | (RDR+LSBONLY),
1484 info->io_base + CCAR );
1485 DataByte = inb( info->io_base + CCAR );
1487 /* get the status of the received byte */
1488 status = usc_InReg(info, RCSR);
1489 if ( status & (RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR +
1490 RXSTATUS_OVERRUN + RXSTATUS_BREAK_RECEIVED) )
1491 usc_UnlatchRxstatusBits(info,RXSTATUS_ALL);
1496 if ( status & (RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR +
1497 RXSTATUS_OVERRUN + RXSTATUS_BREAK_RECEIVED) ) {
1498 printk("rxerr=%04X\n",status);
1499 /* update error statistics */
1500 if ( status & RXSTATUS_BREAK_RECEIVED ) {
1501 status &= ~(RXSTATUS_FRAMING_ERROR + RXSTATUS_PARITY_ERROR);
1503 } else if (status & RXSTATUS_PARITY_ERROR)
1505 else if (status & RXSTATUS_FRAMING_ERROR)
1507 else if (status & RXSTATUS_OVERRUN) {
1508 /* must issue purge fifo cmd before */
1509 /* 16C32 accepts more receive chars */
1510 usc_RTCmd(info,RTCmd_PurgeRxFifo);
1514 /* discard char if tty control flags say so */
1515 if (status & info->ignore_status_mask)
1518 status &= info->read_status_mask;
1520 if (status & RXSTATUS_BREAK_RECEIVED) {
1522 if (info->flags & ASYNC_SAK)
1524 } else if (status & RXSTATUS_PARITY_ERROR)
1526 else if (status & RXSTATUS_FRAMING_ERROR)
1528 } /* end of if (error) */
1529 tty_insert_flip_char(tty, DataByte, flag);
1530 if (status & RXSTATUS_OVERRUN) {
1531 /* Overrun is special, since it's
1532 * reported immediately, and doesn't
1533 * affect the current character
1535 work += tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1539 if ( debug_level >= DEBUG_LEVEL_ISR ) {
1540 printk("%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
1541 __FILE__,__LINE__,icount->rx,icount->brk,
1542 icount->parity,icount->frame,icount->overrun);
1546 tty_flip_buffer_push(tty);
1551 * Service a miscellaneos interrupt source.
1553 * Arguments: info pointer to device extension (instance data)
1554 * Return Value: None
1556 static void mgsl_isr_misc( struct mgsl_struct *info )
1558 u16 status = usc_InReg( info, MISR );
1560 if ( debug_level >= DEBUG_LEVEL_ISR )
1561 printk("%s(%d):mgsl_isr_misc status=%04X\n",
1562 __FILE__,__LINE__,status);
1564 if ((status & MISCSTATUS_RCC_UNDERRUN) &&
1565 (info->params.mode == MGSL_MODE_HDLC)) {
1567 /* turn off receiver and rx DMA */
1568 usc_EnableReceiver(info,DISABLE_UNCONDITIONAL);
1569 usc_DmaCmd(info, DmaCmd_ResetRxChannel);
1570 usc_UnlatchRxstatusBits(info, RXSTATUS_ALL);
1571 usc_ClearIrqPendingBits(info, RECEIVE_DATA + RECEIVE_STATUS);
1572 usc_DisableInterrupts(info, RECEIVE_DATA + RECEIVE_STATUS);
1574 /* schedule BH handler to restart receiver */
1575 info->pending_bh |= BH_RECEIVE;
1576 info->rx_rcc_underrun = 1;
1579 usc_ClearIrqPendingBits( info, MISC );
1580 usc_UnlatchMiscstatusBits( info, status );
1582 } /* end of mgsl_isr_misc() */
1586 * Services undefined interrupt vectors from the
1587 * USC. (hence this function SHOULD never be called)
1589 * Arguments: info pointer to device extension (instance data)
1590 * Return Value: None
1592 static void mgsl_isr_null( struct mgsl_struct *info )
1595 } /* end of mgsl_isr_null() */
1597 /* mgsl_isr_receive_dma()
1599 * Service a receive DMA channel interrupt.
1600 * For this driver there are two sources of receive DMA interrupts
1601 * as identified in the Receive DMA mode Register (RDMR):
1603 * BIT3 EOA/EOL End of List, all receive buffers in receive
1604 * buffer list have been filled (no more free buffers
1605 * available). The DMA controller has shut down.
1607 * BIT2 EOB End of Buffer. This interrupt occurs when a receive
1608 * DMA buffer is terminated in response to completion
1609 * of a good frame or a frame with errors. The status
1610 * of the frame is stored in the buffer entry in the
1611 * list of receive buffer entries.
1613 * Arguments: info pointer to device instance data
1614 * Return Value: None
1616 static void mgsl_isr_receive_dma( struct mgsl_struct *info )
1620 /* clear interrupt pending and IUS bit for Rx DMA IRQ */
1621 usc_OutDmaReg( info, CDIR, BIT9+BIT1 );
1623 /* Read the receive DMA status to identify interrupt type. */
1624 /* This also clears the status bits. */
1625 status = usc_InDmaReg( info, RDMR );
1627 if ( debug_level >= DEBUG_LEVEL_ISR )
1628 printk("%s(%d):mgsl_isr_receive_dma(%s) status=%04X\n",
1629 __FILE__,__LINE__,info->device_name,status);
1631 info->pending_bh |= BH_RECEIVE;
1633 if ( status & BIT3 ) {
1634 info->rx_overflow = 1;
1635 info->icount.buf_overrun++;
1638 } /* end of mgsl_isr_receive_dma() */
1640 /* mgsl_isr_transmit_dma()
1642 * This function services a transmit DMA channel interrupt.
1644 * For this driver there is one source of transmit DMA interrupts
1645 * as identified in the Transmit DMA Mode Register (TDMR):
1647 * BIT2 EOB End of Buffer. This interrupt occurs when a
1648 * transmit DMA buffer has been emptied.
1650 * The driver maintains enough transmit DMA buffers to hold at least
1651 * one max frame size transmit frame. When operating in a buffered
1652 * transmit mode, there may be enough transmit DMA buffers to hold at
1653 * least two or more max frame size frames. On an EOB condition,
1654 * determine if there are any queued transmit buffers and copy into
1655 * transmit DMA buffers if we have room.
1657 * Arguments: info pointer to device instance data
1658 * Return Value: None
1660 static void mgsl_isr_transmit_dma( struct mgsl_struct *info )
1664 /* clear interrupt pending and IUS bit for Tx DMA IRQ */
1665 usc_OutDmaReg(info, CDIR, BIT8+BIT0 );
1667 /* Read the transmit DMA status to identify interrupt type. */
1668 /* This also clears the status bits. */
1670 status = usc_InDmaReg( info, TDMR );
1672 if ( debug_level >= DEBUG_LEVEL_ISR )
1673 printk("%s(%d):mgsl_isr_transmit_dma(%s) status=%04X\n",
1674 __FILE__,__LINE__,info->device_name,status);
1676 if ( status & BIT2 ) {
1677 --info->tx_dma_buffers_used;
1679 /* if there are transmit frames queued,
1680 * try to load the next one
1682 if ( load_next_tx_holding_buffer(info) ) {
1683 /* if call returns non-zero value, we have
1684 * at least one free tx holding buffer
1686 info->pending_bh |= BH_TRANSMIT;
1690 } /* end of mgsl_isr_transmit_dma() */
1694 * Interrupt service routine entry point.
1698 * irq interrupt number that caused interrupt
1699 * dev_id device ID supplied during interrupt registration
1701 * Return Value: None
1703 static irqreturn_t mgsl_interrupt(int irq, void *dev_id)
1705 struct mgsl_struct * info;
1709 if ( debug_level >= DEBUG_LEVEL_ISR )
1710 printk("%s(%d):mgsl_interrupt(%d)entry.\n",
1711 __FILE__,__LINE__,irq);
1713 info = (struct mgsl_struct *)dev_id;
1717 spin_lock(&info->irq_spinlock);
1720 /* Read the interrupt vectors from hardware. */
1721 UscVector = usc_InReg(info, IVR) >> 9;
1722 DmaVector = usc_InDmaReg(info, DIVR);
1724 if ( debug_level >= DEBUG_LEVEL_ISR )
1725 printk("%s(%d):%s UscVector=%08X DmaVector=%08X\n",
1726 __FILE__,__LINE__,info->device_name,UscVector,DmaVector);
1728 if ( !UscVector && !DmaVector )
1731 /* Dispatch interrupt vector */
1733 (*UscIsrTable[UscVector])(info);
1734 else if ( (DmaVector&(BIT10|BIT9)) == BIT10)
1735 mgsl_isr_transmit_dma(info);
1737 mgsl_isr_receive_dma(info);
1739 if ( info->isr_overflow ) {
1740 printk(KERN_ERR"%s(%d):%s isr overflow irq=%d\n",
1741 __FILE__,__LINE__,info->device_name, irq);
1742 usc_DisableMasterIrqBit(info);
1743 usc_DisableDmaInterrupts(info,DICR_MASTER);
1748 /* Request bottom half processing if there's something
1749 * for it to do and the bh is not already running
1752 if ( info->pending_bh && !info->bh_running && !info->bh_requested ) {
1753 if ( debug_level >= DEBUG_LEVEL_ISR )
1754 printk("%s(%d):%s queueing bh task.\n",
1755 __FILE__,__LINE__,info->device_name);
1756 schedule_work(&info->task);
1757 info->bh_requested = 1;
1760 spin_unlock(&info->irq_spinlock);
1762 if ( debug_level >= DEBUG_LEVEL_ISR )
1763 printk("%s(%d):mgsl_interrupt(%d)exit.\n",
1764 __FILE__,__LINE__,irq);
1766 } /* end of mgsl_interrupt() */
1770 * Initialize and start device.
1772 * Arguments: info pointer to device instance data
1773 * Return Value: 0 if success, otherwise error code
1775 static int startup(struct mgsl_struct * info)
1779 if ( debug_level >= DEBUG_LEVEL_INFO )
1780 printk("%s(%d):mgsl_startup(%s)\n",__FILE__,__LINE__,info->device_name);
1782 if (info->flags & ASYNC_INITIALIZED)
1785 if (!info->xmit_buf) {
1786 /* allocate a page of memory for a transmit buffer */
1787 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
1788 if (!info->xmit_buf) {
1789 printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
1790 __FILE__,__LINE__,info->device_name);
1795 info->pending_bh = 0;
1797 memset(&info->icount, 0, sizeof(info->icount));
1799 setup_timer(&info->tx_timer, mgsl_tx_timeout, (unsigned long)info);
1801 /* Allocate and claim adapter resources */
1802 retval = mgsl_claim_resources(info);
1804 /* perform existence check and diagnostics */
1806 retval = mgsl_adapter_test(info);
1809 if (capable(CAP_SYS_ADMIN) && info->tty)
1810 set_bit(TTY_IO_ERROR, &info->tty->flags);
1811 mgsl_release_resources(info);
1815 /* program hardware for current parameters */
1816 mgsl_change_params(info);
1819 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1821 info->flags |= ASYNC_INITIALIZED;
1825 } /* end of startup() */
1829 * Called by mgsl_close() and mgsl_hangup() to shutdown hardware
1831 * Arguments: info pointer to device instance data
1832 * Return Value: None
1834 static void shutdown(struct mgsl_struct * info)
1836 unsigned long flags;
1838 if (!(info->flags & ASYNC_INITIALIZED))
1841 if (debug_level >= DEBUG_LEVEL_INFO)
1842 printk("%s(%d):mgsl_shutdown(%s)\n",
1843 __FILE__,__LINE__, info->device_name );
1845 /* clear status wait queue because status changes */
1846 /* can't happen after shutting down the hardware */
1847 wake_up_interruptible(&info->status_event_wait_q);
1848 wake_up_interruptible(&info->event_wait_q);
1850 del_timer_sync(&info->tx_timer);
1852 if (info->xmit_buf) {
1853 free_page((unsigned long) info->xmit_buf);
1854 info->xmit_buf = NULL;
1857 spin_lock_irqsave(&info->irq_spinlock,flags);
1858 usc_DisableMasterIrqBit(info);
1859 usc_stop_receiver(info);
1860 usc_stop_transmitter(info);
1861 usc_DisableInterrupts(info,RECEIVE_DATA + RECEIVE_STATUS +
1862 TRANSMIT_DATA + TRANSMIT_STATUS + IO_PIN + MISC );
1863 usc_DisableDmaInterrupts(info,DICR_MASTER + DICR_TRANSMIT + DICR_RECEIVE);
1865 /* Disable DMAEN (Port 7, Bit 14) */
1866 /* This disconnects the DMA request signal from the ISA bus */
1867 /* on the ISA adapter. This has no effect for the PCI adapter */
1868 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT15) | BIT14));
1870 /* Disable INTEN (Port 6, Bit12) */
1871 /* This disconnects the IRQ request signal to the ISA bus */
1872 /* on the ISA adapter. This has no effect for the PCI adapter */
1873 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) | BIT12));
1875 if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
1876 info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
1877 usc_set_serial_signals(info);
1880 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1882 mgsl_release_resources(info);
1885 set_bit(TTY_IO_ERROR, &info->tty->flags);
1887 info->flags &= ~ASYNC_INITIALIZED;
1889 } /* end of shutdown() */
1891 static void mgsl_program_hw(struct mgsl_struct *info)
1893 unsigned long flags;
1895 spin_lock_irqsave(&info->irq_spinlock,flags);
1897 usc_stop_receiver(info);
1898 usc_stop_transmitter(info);
1899 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1901 if (info->params.mode == MGSL_MODE_HDLC ||
1902 info->params.mode == MGSL_MODE_RAW ||
1904 usc_set_sync_mode(info);
1906 usc_set_async_mode(info);
1908 usc_set_serial_signals(info);
1910 info->dcd_chkcount = 0;
1911 info->cts_chkcount = 0;
1912 info->ri_chkcount = 0;
1913 info->dsr_chkcount = 0;
1915 usc_EnableStatusIrqs(info,SICR_CTS+SICR_DSR+SICR_DCD+SICR_RI);
1916 usc_EnableInterrupts(info, IO_PIN);
1917 usc_get_serial_signals(info);
1919 if (info->netcount || info->tty->termios->c_cflag & CREAD)
1920 usc_start_receiver(info);
1922 spin_unlock_irqrestore(&info->irq_spinlock,flags);
1925 /* Reconfigure adapter based on new parameters
1927 static void mgsl_change_params(struct mgsl_struct *info)
1932 if (!info->tty || !info->tty->termios)
1935 if (debug_level >= DEBUG_LEVEL_INFO)
1936 printk("%s(%d):mgsl_change_params(%s)\n",
1937 __FILE__,__LINE__, info->device_name );
1939 cflag = info->tty->termios->c_cflag;
1941 /* if B0 rate (hangup) specified then negate DTR and RTS */
1942 /* otherwise assert DTR and RTS */
1944 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
1946 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
1948 /* byte size and parity */
1950 switch (cflag & CSIZE) {
1951 case CS5: info->params.data_bits = 5; break;
1952 case CS6: info->params.data_bits = 6; break;
1953 case CS7: info->params.data_bits = 7; break;
1954 case CS8: info->params.data_bits = 8; break;
1955 /* Never happens, but GCC is too dumb to figure it out */
1956 default: info->params.data_bits = 7; break;
1960 info->params.stop_bits = 2;
1962 info->params.stop_bits = 1;
1964 info->params.parity = ASYNC_PARITY_NONE;
1965 if (cflag & PARENB) {
1967 info->params.parity = ASYNC_PARITY_ODD;
1969 info->params.parity = ASYNC_PARITY_EVEN;
1972 info->params.parity = ASYNC_PARITY_SPACE;
1976 /* calculate number of jiffies to transmit a full
1977 * FIFO (32 bytes) at specified data rate
1979 bits_per_char = info->params.data_bits +
1980 info->params.stop_bits + 1;
1982 /* if port data rate is set to 460800 or less then
1983 * allow tty settings to override, otherwise keep the
1984 * current data rate.
1986 if (info->params.data_rate <= 460800)
1987 info->params.data_rate = tty_get_baud_rate(info->tty);
1989 if ( info->params.data_rate ) {
1990 info->timeout = (32*HZ*bits_per_char) /
1991 info->params.data_rate;
1993 info->timeout += HZ/50; /* Add .02 seconds of slop */
1995 if (cflag & CRTSCTS)
1996 info->flags |= ASYNC_CTS_FLOW;
1998 info->flags &= ~ASYNC_CTS_FLOW;
2001 info->flags &= ~ASYNC_CHECK_CD;
2003 info->flags |= ASYNC_CHECK_CD;
2005 /* process tty input control flags */
2007 info->read_status_mask = RXSTATUS_OVERRUN;
2008 if (I_INPCK(info->tty))
2009 info->read_status_mask |= RXSTATUS_PARITY_ERROR | RXSTATUS_FRAMING_ERROR;
2010 if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
2011 info->read_status_mask |= RXSTATUS_BREAK_RECEIVED;
2013 if (I_IGNPAR(info->tty))
2014 info->ignore_status_mask |= RXSTATUS_PARITY_ERROR | RXSTATUS_FRAMING_ERROR;
2015 if (I_IGNBRK(info->tty)) {
2016 info->ignore_status_mask |= RXSTATUS_BREAK_RECEIVED;
2017 /* If ignoring parity and break indicators, ignore
2018 * overruns too. (For real raw support).
2020 if (I_IGNPAR(info->tty))
2021 info->ignore_status_mask |= RXSTATUS_OVERRUN;
2024 mgsl_program_hw(info);
2026 } /* end of mgsl_change_params() */
2030 * Add a character to the transmit buffer.
2032 * Arguments: tty pointer to tty information structure
2033 * ch character to add to transmit buffer
2035 * Return Value: None
2037 static void mgsl_put_char(struct tty_struct *tty, unsigned char ch)
2039 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2040 unsigned long flags;
2042 if ( debug_level >= DEBUG_LEVEL_INFO ) {
2043 printk( "%s(%d):mgsl_put_char(%d) on %s\n",
2044 __FILE__,__LINE__,ch,info->device_name);
2047 if (mgsl_paranoia_check(info, tty->name, "mgsl_put_char"))
2050 if (!tty || !info->xmit_buf)
2053 spin_lock_irqsave(&info->irq_spinlock,flags);
2055 if ( (info->params.mode == MGSL_MODE_ASYNC ) || !info->tx_active ) {
2057 if (info->xmit_cnt < SERIAL_XMIT_SIZE - 1) {
2058 info->xmit_buf[info->xmit_head++] = ch;
2059 info->xmit_head &= SERIAL_XMIT_SIZE-1;
2064 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2066 } /* end of mgsl_put_char() */
2068 /* mgsl_flush_chars()
2070 * Enable transmitter so remaining characters in the
2071 * transmit buffer are sent.
2073 * Arguments: tty pointer to tty information structure
2074 * Return Value: None
2076 static void mgsl_flush_chars(struct tty_struct *tty)
2078 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2079 unsigned long flags;
2081 if ( debug_level >= DEBUG_LEVEL_INFO )
2082 printk( "%s(%d):mgsl_flush_chars() entry on %s xmit_cnt=%d\n",
2083 __FILE__,__LINE__,info->device_name,info->xmit_cnt);
2085 if (mgsl_paranoia_check(info, tty->name, "mgsl_flush_chars"))
2088 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
2092 if ( debug_level >= DEBUG_LEVEL_INFO )
2093 printk( "%s(%d):mgsl_flush_chars() entry on %s starting transmitter\n",
2094 __FILE__,__LINE__,info->device_name );
2096 spin_lock_irqsave(&info->irq_spinlock,flags);
2098 if (!info->tx_active) {
2099 if ( (info->params.mode == MGSL_MODE_HDLC ||
2100 info->params.mode == MGSL_MODE_RAW) && info->xmit_cnt ) {
2101 /* operating in synchronous (frame oriented) mode */
2102 /* copy data from circular xmit_buf to */
2103 /* transmit DMA buffer. */
2104 mgsl_load_tx_dma_buffer(info,
2105 info->xmit_buf,info->xmit_cnt);
2107 usc_start_transmitter(info);
2110 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2112 } /* end of mgsl_flush_chars() */
2116 * Send a block of data
2120 * tty pointer to tty information structure
2121 * buf pointer to buffer containing send data
2122 * count size of send data in bytes
2124 * Return Value: number of characters written
2126 static int mgsl_write(struct tty_struct * tty,
2127 const unsigned char *buf, int count)
2130 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2131 unsigned long flags;
2133 if ( debug_level >= DEBUG_LEVEL_INFO )
2134 printk( "%s(%d):mgsl_write(%s) count=%d\n",
2135 __FILE__,__LINE__,info->device_name,count);
2137 if (mgsl_paranoia_check(info, tty->name, "mgsl_write"))
2140 if (!tty || !info->xmit_buf)
2143 if ( info->params.mode == MGSL_MODE_HDLC ||
2144 info->params.mode == MGSL_MODE_RAW ) {
2145 /* operating in synchronous (frame oriented) mode */
2146 /* operating in synchronous (frame oriented) mode */
2147 if (info->tx_active) {
2149 if ( info->params.mode == MGSL_MODE_HDLC ) {
2153 /* transmitter is actively sending data -
2154 * if we have multiple transmit dma and
2155 * holding buffers, attempt to queue this
2156 * frame for transmission at a later time.
2158 if (info->tx_holding_count >= info->num_tx_holding_buffers ) {
2159 /* no tx holding buffers available */
2164 /* queue transmit frame request */
2166 save_tx_buffer_request(info,buf,count);
2168 /* if we have sufficient tx dma buffers,
2169 * load the next buffered tx request
2171 spin_lock_irqsave(&info->irq_spinlock,flags);
2172 load_next_tx_holding_buffer(info);
2173 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2177 /* if operating in HDLC LoopMode and the adapter */
2178 /* has yet to be inserted into the loop, we can't */
2181 if ( (info->params.flags & HDLC_FLAG_HDLC_LOOPMODE) &&
2182 !usc_loopmode_active(info) )
2188 if ( info->xmit_cnt ) {
2189 /* Send accumulated from send_char() calls */
2190 /* as frame and wait before accepting more data. */
2193 /* copy data from circular xmit_buf to */
2194 /* transmit DMA buffer. */
2195 mgsl_load_tx_dma_buffer(info,
2196 info->xmit_buf,info->xmit_cnt);
2197 if ( debug_level >= DEBUG_LEVEL_INFO )
2198 printk( "%s(%d):mgsl_write(%s) sync xmit_cnt flushing\n",
2199 __FILE__,__LINE__,info->device_name);
2201 if ( debug_level >= DEBUG_LEVEL_INFO )
2202 printk( "%s(%d):mgsl_write(%s) sync transmit accepted\n",
2203 __FILE__,__LINE__,info->device_name);
2205 info->xmit_cnt = count;
2206 mgsl_load_tx_dma_buffer(info,buf,count);
2210 spin_lock_irqsave(&info->irq_spinlock,flags);
2211 c = min_t(int, count,
2212 min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
2213 SERIAL_XMIT_SIZE - info->xmit_head));
2215 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2218 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2219 info->xmit_head = ((info->xmit_head + c) &
2220 (SERIAL_XMIT_SIZE-1));
2221 info->xmit_cnt += c;
2222 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2229 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2230 spin_lock_irqsave(&info->irq_spinlock,flags);
2231 if (!info->tx_active)
2232 usc_start_transmitter(info);
2233 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2236 if ( debug_level >= DEBUG_LEVEL_INFO )
2237 printk( "%s(%d):mgsl_write(%s) returning=%d\n",
2238 __FILE__,__LINE__,info->device_name,ret);
2242 } /* end of mgsl_write() */
2244 /* mgsl_write_room()
2246 * Return the count of free bytes in transmit buffer
2248 * Arguments: tty pointer to tty info structure
2249 * Return Value: None
2251 static int mgsl_write_room(struct tty_struct *tty)
2253 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2256 if (mgsl_paranoia_check(info, tty->name, "mgsl_write_room"))
2258 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
2262 if (debug_level >= DEBUG_LEVEL_INFO)
2263 printk("%s(%d):mgsl_write_room(%s)=%d\n",
2264 __FILE__,__LINE__, info->device_name,ret );
2266 if ( info->params.mode == MGSL_MODE_HDLC ||
2267 info->params.mode == MGSL_MODE_RAW ) {
2268 /* operating in synchronous (frame oriented) mode */
2269 if ( info->tx_active )
2272 return HDLC_MAX_FRAME_SIZE;
2277 } /* end of mgsl_write_room() */
2279 /* mgsl_chars_in_buffer()
2281 * Return the count of bytes in transmit buffer
2283 * Arguments: tty pointer to tty info structure
2284 * Return Value: None
2286 static int mgsl_chars_in_buffer(struct tty_struct *tty)
2288 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2290 if (debug_level >= DEBUG_LEVEL_INFO)
2291 printk("%s(%d):mgsl_chars_in_buffer(%s)\n",
2292 __FILE__,__LINE__, info->device_name );
2294 if (mgsl_paranoia_check(info, tty->name, "mgsl_chars_in_buffer"))
2297 if (debug_level >= DEBUG_LEVEL_INFO)
2298 printk("%s(%d):mgsl_chars_in_buffer(%s)=%d\n",
2299 __FILE__,__LINE__, info->device_name,info->xmit_cnt );
2301 if ( info->params.mode == MGSL_MODE_HDLC ||
2302 info->params.mode == MGSL_MODE_RAW ) {
2303 /* operating in synchronous (frame oriented) mode */
2304 if ( info->tx_active )
2305 return info->max_frame_size;
2310 return info->xmit_cnt;
2311 } /* end of mgsl_chars_in_buffer() */
2313 /* mgsl_flush_buffer()
2315 * Discard all data in the send buffer
2317 * Arguments: tty pointer to tty info structure
2318 * Return Value: None
2320 static void mgsl_flush_buffer(struct tty_struct *tty)
2322 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2323 unsigned long flags;
2325 if (debug_level >= DEBUG_LEVEL_INFO)
2326 printk("%s(%d):mgsl_flush_buffer(%s) entry\n",
2327 __FILE__,__LINE__, info->device_name );
2329 if (mgsl_paranoia_check(info, tty->name, "mgsl_flush_buffer"))
2332 spin_lock_irqsave(&info->irq_spinlock,flags);
2333 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2334 del_timer(&info->tx_timer);
2335 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2340 /* mgsl_send_xchar()
2342 * Send a high-priority XON/XOFF character
2344 * Arguments: tty pointer to tty info structure
2345 * ch character to send
2346 * Return Value: None
2348 static void mgsl_send_xchar(struct tty_struct *tty, char ch)
2350 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2351 unsigned long flags;
2353 if (debug_level >= DEBUG_LEVEL_INFO)
2354 printk("%s(%d):mgsl_send_xchar(%s,%d)\n",
2355 __FILE__,__LINE__, info->device_name, ch );
2357 if (mgsl_paranoia_check(info, tty->name, "mgsl_send_xchar"))
2362 /* Make sure transmit interrupts are on */
2363 spin_lock_irqsave(&info->irq_spinlock,flags);
2364 if (!info->tx_enabled)
2365 usc_start_transmitter(info);
2366 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2368 } /* end of mgsl_send_xchar() */
2372 * Signal remote device to throttle send data (our receive data)
2374 * Arguments: tty pointer to tty info structure
2375 * Return Value: None
2377 static void mgsl_throttle(struct tty_struct * tty)
2379 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2380 unsigned long flags;
2382 if (debug_level >= DEBUG_LEVEL_INFO)
2383 printk("%s(%d):mgsl_throttle(%s) entry\n",
2384 __FILE__,__LINE__, info->device_name );
2386 if (mgsl_paranoia_check(info, tty->name, "mgsl_throttle"))
2390 mgsl_send_xchar(tty, STOP_CHAR(tty));
2392 if (tty->termios->c_cflag & CRTSCTS) {
2393 spin_lock_irqsave(&info->irq_spinlock,flags);
2394 info->serial_signals &= ~SerialSignal_RTS;
2395 usc_set_serial_signals(info);
2396 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2398 } /* end of mgsl_throttle() */
2400 /* mgsl_unthrottle()
2402 * Signal remote device to stop throttling send data (our receive data)
2404 * Arguments: tty pointer to tty info structure
2405 * Return Value: None
2407 static void mgsl_unthrottle(struct tty_struct * tty)
2409 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2410 unsigned long flags;
2412 if (debug_level >= DEBUG_LEVEL_INFO)
2413 printk("%s(%d):mgsl_unthrottle(%s) entry\n",
2414 __FILE__,__LINE__, info->device_name );
2416 if (mgsl_paranoia_check(info, tty->name, "mgsl_unthrottle"))
2423 mgsl_send_xchar(tty, START_CHAR(tty));
2426 if (tty->termios->c_cflag & CRTSCTS) {
2427 spin_lock_irqsave(&info->irq_spinlock,flags);
2428 info->serial_signals |= SerialSignal_RTS;
2429 usc_set_serial_signals(info);
2430 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2433 } /* end of mgsl_unthrottle() */
2437 * get the current serial parameters information
2439 * Arguments: info pointer to device instance data
2440 * user_icount pointer to buffer to hold returned stats
2442 * Return Value: 0 if success, otherwise error code
2444 static int mgsl_get_stats(struct mgsl_struct * info, struct mgsl_icount __user *user_icount)
2448 if (debug_level >= DEBUG_LEVEL_INFO)
2449 printk("%s(%d):mgsl_get_params(%s)\n",
2450 __FILE__,__LINE__, info->device_name);
2453 memset(&info->icount, 0, sizeof(info->icount));
2455 COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
2462 } /* end of mgsl_get_stats() */
2464 /* mgsl_get_params()
2466 * get the current serial parameters information
2468 * Arguments: info pointer to device instance data
2469 * user_params pointer to buffer to hold returned params
2471 * Return Value: 0 if success, otherwise error code
2473 static int mgsl_get_params(struct mgsl_struct * info, MGSL_PARAMS __user *user_params)
2476 if (debug_level >= DEBUG_LEVEL_INFO)
2477 printk("%s(%d):mgsl_get_params(%s)\n",
2478 __FILE__,__LINE__, info->device_name);
2480 COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
2482 if ( debug_level >= DEBUG_LEVEL_INFO )
2483 printk( "%s(%d):mgsl_get_params(%s) user buffer copy failed\n",
2484 __FILE__,__LINE__,info->device_name);
2490 } /* end of mgsl_get_params() */
2492 /* mgsl_set_params()
2494 * set the serial parameters
2498 * info pointer to device instance data
2499 * new_params user buffer containing new serial params
2501 * Return Value: 0 if success, otherwise error code
2503 static int mgsl_set_params(struct mgsl_struct * info, MGSL_PARAMS __user *new_params)
2505 unsigned long flags;
2506 MGSL_PARAMS tmp_params;
2509 if (debug_level >= DEBUG_LEVEL_INFO)
2510 printk("%s(%d):mgsl_set_params %s\n", __FILE__,__LINE__,
2511 info->device_name );
2512 COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
2514 if ( debug_level >= DEBUG_LEVEL_INFO )
2515 printk( "%s(%d):mgsl_set_params(%s) user buffer copy failed\n",
2516 __FILE__,__LINE__,info->device_name);
2520 spin_lock_irqsave(&info->irq_spinlock,flags);
2521 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
2522 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2524 mgsl_change_params(info);
2528 } /* end of mgsl_set_params() */
2530 /* mgsl_get_txidle()
2532 * get the current transmit idle mode
2534 * Arguments: info pointer to device instance data
2535 * idle_mode pointer to buffer to hold returned idle mode
2537 * Return Value: 0 if success, otherwise error code
2539 static int mgsl_get_txidle(struct mgsl_struct * info, int __user *idle_mode)
2543 if (debug_level >= DEBUG_LEVEL_INFO)
2544 printk("%s(%d):mgsl_get_txidle(%s)=%d\n",
2545 __FILE__,__LINE__, info->device_name, info->idle_mode);
2547 COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
2549 if ( debug_level >= DEBUG_LEVEL_INFO )
2550 printk( "%s(%d):mgsl_get_txidle(%s) user buffer copy failed\n",
2551 __FILE__,__LINE__,info->device_name);
2557 } /* end of mgsl_get_txidle() */
2559 /* mgsl_set_txidle() service ioctl to set transmit idle mode
2561 * Arguments: info pointer to device instance data
2562 * idle_mode new idle mode
2564 * Return Value: 0 if success, otherwise error code
2566 static int mgsl_set_txidle(struct mgsl_struct * info, int idle_mode)
2568 unsigned long flags;
2570 if (debug_level >= DEBUG_LEVEL_INFO)
2571 printk("%s(%d):mgsl_set_txidle(%s,%d)\n", __FILE__,__LINE__,
2572 info->device_name, idle_mode );
2574 spin_lock_irqsave(&info->irq_spinlock,flags);
2575 info->idle_mode = idle_mode;
2576 usc_set_txidle( info );
2577 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2580 } /* end of mgsl_set_txidle() */
2584 * enable or disable the transmitter
2588 * info pointer to device instance data
2589 * enable 1 = enable, 0 = disable
2591 * Return Value: 0 if success, otherwise error code
2593 static int mgsl_txenable(struct mgsl_struct * info, int enable)
2595 unsigned long flags;
2597 if (debug_level >= DEBUG_LEVEL_INFO)
2598 printk("%s(%d):mgsl_txenable(%s,%d)\n", __FILE__,__LINE__,
2599 info->device_name, enable);
2601 spin_lock_irqsave(&info->irq_spinlock,flags);
2603 if ( !info->tx_enabled ) {
2605 usc_start_transmitter(info);
2606 /*--------------------------------------------------
2607 * if HDLC/SDLC Loop mode, attempt to insert the
2608 * station in the 'loop' by setting CMR:13. Upon
2609 * receipt of the next GoAhead (RxAbort) sequence,
2610 * the OnLoop indicator (CCSR:7) should go active
2611 * to indicate that we are on the loop
2612 *--------------------------------------------------*/
2613 if ( info->params.flags & HDLC_FLAG_HDLC_LOOPMODE )
2614 usc_loopmode_insert_request( info );
2617 if ( info->tx_enabled )
2618 usc_stop_transmitter(info);
2620 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2623 } /* end of mgsl_txenable() */
2625 /* mgsl_txabort() abort send HDLC frame
2627 * Arguments: info pointer to device instance data
2628 * Return Value: 0 if success, otherwise error code
2630 static int mgsl_txabort(struct mgsl_struct * info)
2632 unsigned long flags;
2634 if (debug_level >= DEBUG_LEVEL_INFO)
2635 printk("%s(%d):mgsl_txabort(%s)\n", __FILE__,__LINE__,
2638 spin_lock_irqsave(&info->irq_spinlock,flags);
2639 if ( info->tx_active && info->params.mode == MGSL_MODE_HDLC )
2641 if ( info->params.flags & HDLC_FLAG_HDLC_LOOPMODE )
2642 usc_loopmode_cancel_transmit( info );
2644 usc_TCmd(info,TCmd_SendAbort);
2646 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2649 } /* end of mgsl_txabort() */
2651 /* mgsl_rxenable() enable or disable the receiver
2653 * Arguments: info pointer to device instance data
2654 * enable 1 = enable, 0 = disable
2655 * Return Value: 0 if success, otherwise error code
2657 static int mgsl_rxenable(struct mgsl_struct * info, int enable)
2659 unsigned long flags;
2661 if (debug_level >= DEBUG_LEVEL_INFO)
2662 printk("%s(%d):mgsl_rxenable(%s,%d)\n", __FILE__,__LINE__,
2663 info->device_name, enable);
2665 spin_lock_irqsave(&info->irq_spinlock,flags);
2667 if ( !info->rx_enabled )
2668 usc_start_receiver(info);
2670 if ( info->rx_enabled )
2671 usc_stop_receiver(info);
2673 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2676 } /* end of mgsl_rxenable() */
2678 /* mgsl_wait_event() wait for specified event to occur
2680 * Arguments: info pointer to device instance data
2681 * mask pointer to bitmask of events to wait for
2682 * Return Value: 0 if successful and bit mask updated with
2683 * of events triggerred,
2684 * otherwise error code
2686 static int mgsl_wait_event(struct mgsl_struct * info, int __user * mask_ptr)
2688 unsigned long flags;
2691 struct mgsl_icount cprev, cnow;
2694 struct _input_signal_events oldsigs, newsigs;
2695 DECLARE_WAITQUEUE(wait, current);
2697 COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
2702 if (debug_level >= DEBUG_LEVEL_INFO)
2703 printk("%s(%d):mgsl_wait_event(%s,%d)\n", __FILE__,__LINE__,
2704 info->device_name, mask);
2706 spin_lock_irqsave(&info->irq_spinlock,flags);
2708 /* return immediately if state matches requested events */
2709 usc_get_serial_signals(info);
2710 s = info->serial_signals;
2712 ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
2713 ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
2714 ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
2715 ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
2717 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2721 /* save current irq counts */
2722 cprev = info->icount;
2723 oldsigs = info->input_signal_events;
2725 /* enable hunt and idle irqs if needed */
2726 if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
2727 u16 oldreg = usc_InReg(info,RICR);
2728 u16 newreg = oldreg +
2729 (mask & MgslEvent_ExitHuntMode ? RXSTATUS_EXITED_HUNT:0) +
2730 (mask & MgslEvent_IdleReceived ? RXSTATUS_IDLE_RECEIVED:0);
2731 if (oldreg != newreg)
2732 usc_OutReg(info, RICR, newreg);
2735 set_current_state(TASK_INTERRUPTIBLE);
2736 add_wait_queue(&info->event_wait_q, &wait);
2738 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2743 if (signal_pending(current)) {
2748 /* get current irq counts */
2749 spin_lock_irqsave(&info->irq_spinlock,flags);
2750 cnow = info->icount;
2751 newsigs = info->input_signal_events;
2752 set_current_state(TASK_INTERRUPTIBLE);
2753 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2755 /* if no change, wait aborted for some reason */
2756 if (newsigs.dsr_up == oldsigs.dsr_up &&
2757 newsigs.dsr_down == oldsigs.dsr_down &&
2758 newsigs.dcd_up == oldsigs.dcd_up &&
2759 newsigs.dcd_down == oldsigs.dcd_down &&
2760 newsigs.cts_up == oldsigs.cts_up &&
2761 newsigs.cts_down == oldsigs.cts_down &&
2762 newsigs.ri_up == oldsigs.ri_up &&
2763 newsigs.ri_down == oldsigs.ri_down &&
2764 cnow.exithunt == cprev.exithunt &&
2765 cnow.rxidle == cprev.rxidle) {
2771 ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
2772 (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
2773 (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
2774 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
2775 (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
2776 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
2777 (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
2778 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
2779 (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
2780 (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
2788 remove_wait_queue(&info->event_wait_q, &wait);
2789 set_current_state(TASK_RUNNING);
2791 if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
2792 spin_lock_irqsave(&info->irq_spinlock,flags);
2793 if (!waitqueue_active(&info->event_wait_q)) {
2794 /* disable enable exit hunt mode/idle rcvd IRQs */
2795 usc_OutReg(info, RICR, usc_InReg(info,RICR) &
2796 ~(RXSTATUS_EXITED_HUNT + RXSTATUS_IDLE_RECEIVED));
2798 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2802 PUT_USER(rc, events, mask_ptr);
2806 } /* end of mgsl_wait_event() */
2808 static int modem_input_wait(struct mgsl_struct *info,int arg)
2810 unsigned long flags;
2812 struct mgsl_icount cprev, cnow;
2813 DECLARE_WAITQUEUE(wait, current);
2815 /* save current irq counts */
2816 spin_lock_irqsave(&info->irq_spinlock,flags);
2817 cprev = info->icount;
2818 add_wait_queue(&info->status_event_wait_q, &wait);
2819 set_current_state(TASK_INTERRUPTIBLE);
2820 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2824 if (signal_pending(current)) {
2829 /* get new irq counts */
2830 spin_lock_irqsave(&info->irq_spinlock,flags);
2831 cnow = info->icount;
2832 set_current_state(TASK_INTERRUPTIBLE);
2833 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2835 /* if no change, wait aborted for some reason */
2836 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2837 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2842 /* check for change in caller specified modem input */
2843 if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
2844 (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
2845 (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
2846 (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
2853 remove_wait_queue(&info->status_event_wait_q, &wait);
2854 set_current_state(TASK_RUNNING);
2858 /* return the state of the serial control and status signals
2860 static int tiocmget(struct tty_struct *tty, struct file *file)
2862 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2863 unsigned int result;
2864 unsigned long flags;
2866 spin_lock_irqsave(&info->irq_spinlock,flags);
2867 usc_get_serial_signals(info);
2868 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2870 result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
2871 ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
2872 ((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
2873 ((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
2874 ((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
2875 ((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
2877 if (debug_level >= DEBUG_LEVEL_INFO)
2878 printk("%s(%d):%s tiocmget() value=%08X\n",
2879 __FILE__,__LINE__, info->device_name, result );
2883 /* set modem control signals (DTR/RTS)
2885 static int tiocmset(struct tty_struct *tty, struct file *file,
2886 unsigned int set, unsigned int clear)
2888 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
2889 unsigned long flags;
2891 if (debug_level >= DEBUG_LEVEL_INFO)
2892 printk("%s(%d):%s tiocmset(%x,%x)\n",
2893 __FILE__,__LINE__,info->device_name, set, clear);
2895 if (set & TIOCM_RTS)
2896 info->serial_signals |= SerialSignal_RTS;
2897 if (set & TIOCM_DTR)
2898 info->serial_signals |= SerialSignal_DTR;
2899 if (clear & TIOCM_RTS)
2900 info->serial_signals &= ~SerialSignal_RTS;
2901 if (clear & TIOCM_DTR)
2902 info->serial_signals &= ~SerialSignal_DTR;
2904 spin_lock_irqsave(&info->irq_spinlock,flags);
2905 usc_set_serial_signals(info);
2906 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2911 /* mgsl_break() Set or clear transmit break condition
2913 * Arguments: tty pointer to tty instance data
2914 * break_state -1=set break condition, 0=clear
2915 * Return Value: None
2917 static void mgsl_break(struct tty_struct *tty, int break_state)
2919 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
2920 unsigned long flags;
2922 if (debug_level >= DEBUG_LEVEL_INFO)
2923 printk("%s(%d):mgsl_break(%s,%d)\n",
2924 __FILE__,__LINE__, info->device_name, break_state);
2926 if (mgsl_paranoia_check(info, tty->name, "mgsl_break"))
2929 spin_lock_irqsave(&info->irq_spinlock,flags);
2930 if (break_state == -1)
2931 usc_OutReg(info,IOCR,(u16)(usc_InReg(info,IOCR) | BIT7));
2933 usc_OutReg(info,IOCR,(u16)(usc_InReg(info,IOCR) & ~BIT7));
2934 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2936 } /* end of mgsl_break() */
2938 /* mgsl_ioctl() Service an IOCTL request
2942 * tty pointer to tty instance data
2943 * file pointer to associated file object for device
2944 * cmd IOCTL command code
2945 * arg command argument/context
2947 * Return Value: 0 if success, otherwise error code
2949 static int mgsl_ioctl(struct tty_struct *tty, struct file * file,
2950 unsigned int cmd, unsigned long arg)
2952 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
2954 if (debug_level >= DEBUG_LEVEL_INFO)
2955 printk("%s(%d):mgsl_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
2956 info->device_name, cmd );
2958 if (mgsl_paranoia_check(info, tty->name, "mgsl_ioctl"))
2961 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
2962 (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
2963 if (tty->flags & (1 << TTY_IO_ERROR))
2967 return mgsl_ioctl_common(info, cmd, arg);
2970 static int mgsl_ioctl_common(struct mgsl_struct *info, unsigned int cmd, unsigned long arg)
2973 struct mgsl_icount cnow; /* kernel counter temps */
2974 void __user *argp = (void __user *)arg;
2975 struct serial_icounter_struct __user *p_cuser; /* user space */
2976 unsigned long flags;
2979 case MGSL_IOCGPARAMS:
2980 return mgsl_get_params(info, argp);
2981 case MGSL_IOCSPARAMS:
2982 return mgsl_set_params(info, argp);
2983 case MGSL_IOCGTXIDLE:
2984 return mgsl_get_txidle(info, argp);
2985 case MGSL_IOCSTXIDLE:
2986 return mgsl_set_txidle(info,(int)arg);
2987 case MGSL_IOCTXENABLE:
2988 return mgsl_txenable(info,(int)arg);
2989 case MGSL_IOCRXENABLE:
2990 return mgsl_rxenable(info,(int)arg);
2991 case MGSL_IOCTXABORT:
2992 return mgsl_txabort(info);
2993 case MGSL_IOCGSTATS:
2994 return mgsl_get_stats(info, argp);
2995 case MGSL_IOCWAITEVENT:
2996 return mgsl_wait_event(info, argp);
2997 case MGSL_IOCLOOPTXDONE:
2998 return mgsl_loopmode_send_done(info);
2999 /* Wait for modem input (DCD,RI,DSR,CTS) change
3000 * as specified by mask in arg (TIOCM_RNG/DSR/CD/CTS)
3003 return modem_input_wait(info,(int)arg);
3006 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
3007 * Return: write counters to the user passed counter struct
3008 * NB: both 1->0 and 0->1 transitions are counted except for
3009 * RI where only 0->1 is counted.
3012 spin_lock_irqsave(&info->irq_spinlock,flags);
3013 cnow = info->icount;
3014 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3016 PUT_USER(error,cnow.cts, &p_cuser->cts);
3017 if (error) return error;
3018 PUT_USER(error,cnow.dsr, &p_cuser->dsr);
3019 if (error) return error;
3020 PUT_USER(error,cnow.rng, &p_cuser->rng);
3021 if (error) return error;
3022 PUT_USER(error,cnow.dcd, &p_cuser->dcd);
3023 if (error) return error;
3024 PUT_USER(error,cnow.rx, &p_cuser->rx);
3025 if (error) return error;
3026 PUT_USER(error,cnow.tx, &p_cuser->tx);
3027 if (error) return error;
3028 PUT_USER(error,cnow.frame, &p_cuser->frame);
3029 if (error) return error;
3030 PUT_USER(error,cnow.overrun, &p_cuser->overrun);
3031 if (error) return error;
3032 PUT_USER(error,cnow.parity, &p_cuser->parity);
3033 if (error) return error;
3034 PUT_USER(error,cnow.brk, &p_cuser->brk);
3035 if (error) return error;
3036 PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
3037 if (error) return error;
3040 return -ENOIOCTLCMD;
3045 /* mgsl_set_termios()
3047 * Set new termios settings
3051 * tty pointer to tty structure
3052 * termios pointer to buffer to hold returned old termios
3054 * Return Value: None
3056 static void mgsl_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
3058 struct mgsl_struct *info = (struct mgsl_struct *)tty->driver_data;
3059 unsigned long flags;
3061 if (debug_level >= DEBUG_LEVEL_INFO)
3062 printk("%s(%d):mgsl_set_termios %s\n", __FILE__,__LINE__,
3063 tty->driver->name );
3065 mgsl_change_params(info);
3067 /* Handle transition to B0 status */
3068 if (old_termios->c_cflag & CBAUD &&
3069 !(tty->termios->c_cflag & CBAUD)) {
3070 info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
3071 spin_lock_irqsave(&info->irq_spinlock,flags);
3072 usc_set_serial_signals(info);
3073 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3076 /* Handle transition away from B0 status */
3077 if (!(old_termios->c_cflag & CBAUD) &&
3078 tty->termios->c_cflag & CBAUD) {
3079 info->serial_signals |= SerialSignal_DTR;
3080 if (!(tty->termios->c_cflag & CRTSCTS) ||
3081 !test_bit(TTY_THROTTLED, &tty->flags)) {
3082 info->serial_signals |= SerialSignal_RTS;
3084 spin_lock_irqsave(&info->irq_spinlock,flags);
3085 usc_set_serial_signals(info);
3086 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3089 /* Handle turning off CRTSCTS */
3090 if (old_termios->c_cflag & CRTSCTS &&
3091 !(tty->termios->c_cflag & CRTSCTS)) {
3092 tty->hw_stopped = 0;
3096 } /* end of mgsl_set_termios() */
3100 * Called when port is closed. Wait for remaining data to be
3101 * sent. Disable port and free resources.
3105 * tty pointer to open tty structure
3106 * filp pointer to open file object
3108 * Return Value: None
3110 static void mgsl_close(struct tty_struct *tty, struct file * filp)
3112 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
3114 if (mgsl_paranoia_check(info, tty->name, "mgsl_close"))
3117 if (debug_level >= DEBUG_LEVEL_INFO)
3118 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
3119 __FILE__,__LINE__, info->device_name, info->count);
3124 if (tty_hung_up_p(filp))
3127 if ((tty->count == 1) && (info->count != 1)) {
3129 * tty->count is 1 and the tty structure will be freed.
3130 * info->count should be one in this case.
3131 * if it's not, correct it so that the port is shutdown.
3133 printk("mgsl_close: bad refcount; tty->count is 1, "
3134 "info->count is %d\n", info->count);
3140 /* if at least one open remaining, leave hardware active */
3144 info->flags |= ASYNC_CLOSING;
3146 /* set tty->closing to notify line discipline to
3147 * only process XON/XOFF characters. Only the N_TTY
3148 * discipline appears to use this (ppp does not).
3152 /* wait for transmit data to clear all layers */
3154 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
3155 if (debug_level >= DEBUG_LEVEL_INFO)
3156 printk("%s(%d):mgsl_close(%s) calling tty_wait_until_sent\n",
3157 __FILE__,__LINE__, info->device_name );
3158 tty_wait_until_sent(tty, info->closing_wait);
3161 if (info->flags & ASYNC_INITIALIZED)
3162 mgsl_wait_until_sent(tty, info->timeout);
3164 if (tty->driver->flush_buffer)
3165 tty->driver->flush_buffer(tty);
3167 tty_ldisc_flush(tty);
3174 if (info->blocked_open) {
3175 if (info->close_delay) {
3176 msleep_interruptible(jiffies_to_msecs(info->close_delay));
3178 wake_up_interruptible(&info->open_wait);
3181 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
3183 wake_up_interruptible(&info->close_wait);
3186 if (debug_level >= DEBUG_LEVEL_INFO)
3187 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
3188 tty->driver->name, info->count);
3190 } /* end of mgsl_close() */
3192 /* mgsl_wait_until_sent()
3194 * Wait until the transmitter is empty.
3198 * tty pointer to tty info structure
3199 * timeout time to wait for send completion
3201 * Return Value: None
3203 static void mgsl_wait_until_sent(struct tty_struct *tty, int timeout)
3205 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
3206 unsigned long orig_jiffies, char_time;
3211 if (debug_level >= DEBUG_LEVEL_INFO)
3212 printk("%s(%d):mgsl_wait_until_sent(%s) entry\n",
3213 __FILE__,__LINE__, info->device_name );
3215 if (mgsl_paranoia_check(info, tty->name, "mgsl_wait_until_sent"))
3218 if (!(info->flags & ASYNC_INITIALIZED))
3221 orig_jiffies = jiffies;
3223 /* Set check interval to 1/5 of estimated time to
3224 * send a character, and make it at least 1. The check
3225 * interval should also be less than the timeout.
3226 * Note: use tight timings here to satisfy the NIST-PCTS.
3229 if ( info->params.data_rate ) {
3230 char_time = info->timeout/(32 * 5);
3237 char_time = min_t(unsigned long, char_time, timeout);
3239 if ( info->params.mode == MGSL_MODE_HDLC ||
3240 info->params.mode == MGSL_MODE_RAW ) {
3241 while (info->tx_active) {
3242 msleep_interruptible(jiffies_to_msecs(char_time));
3243 if (signal_pending(current))
3245 if (timeout && time_after(jiffies, orig_jiffies + timeout))
3249 while (!(usc_InReg(info,TCSR) & TXSTATUS_ALL_SENT) &&
3251 msleep_interruptible(jiffies_to_msecs(char_time));
3252 if (signal_pending(current))
3254 if (timeout && time_after(jiffies, orig_jiffies + timeout))
3260 if (debug_level >= DEBUG_LEVEL_INFO)
3261 printk("%s(%d):mgsl_wait_until_sent(%s) exit\n",
3262 __FILE__,__LINE__, info->device_name );
3264 } /* end of mgsl_wait_until_sent() */
3268 * Called by tty_hangup() when a hangup is signaled.
3269 * This is the same as to closing all open files for the port.
3271 * Arguments: tty pointer to associated tty object
3272 * Return Value: None
3274 static void mgsl_hangup(struct tty_struct *tty)
3276 struct mgsl_struct * info = (struct mgsl_struct *)tty->driver_data;
3278 if (debug_level >= DEBUG_LEVEL_INFO)
3279 printk("%s(%d):mgsl_hangup(%s)\n",
3280 __FILE__,__LINE__, info->device_name );
3282 if (mgsl_paranoia_check(info, tty->name, "mgsl_hangup"))
3285 mgsl_flush_buffer(tty);
3289 info->flags &= ~ASYNC_NORMAL_ACTIVE;
3292 wake_up_interruptible(&info->open_wait);
3294 } /* end of mgsl_hangup() */
3296 /* block_til_ready()
3298 * Block the current process until the specified port
3299 * is ready to be opened.
3303 * tty pointer to tty info structure
3304 * filp pointer to open file object
3305 * info pointer to device instance data
3307 * Return Value: 0 if success, otherwise error code
3309 static int block_til_ready(struct tty_struct *tty, struct file * filp,
3310 struct mgsl_struct *info)
3312 DECLARE_WAITQUEUE(wait, current);
3314 int do_clocal = 0, extra_count = 0;
3315 unsigned long flags;
3317 if (debug_level >= DEBUG_LEVEL_INFO)
3318 printk("%s(%d):block_til_ready on %s\n",
3319 __FILE__,__LINE__, tty->driver->name );
3321 if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
3322 /* nonblock mode is set or port is not enabled */
3323 info->flags |= ASYNC_NORMAL_ACTIVE;
3327 if (tty->termios->c_cflag & CLOCAL)
3330 /* Wait for carrier detect and the line to become
3331 * free (i.e., not in use by the callout). While we are in
3332 * this loop, info->count is dropped by one, so that
3333 * mgsl_close() knows when to free things. We restore it upon
3334 * exit, either normal or abnormal.
3338 add_wait_queue(&info->open_wait, &wait);
3340 if (debug_level >= DEBUG_LEVEL_INFO)
3341 printk("%s(%d):block_til_ready before block on %s count=%d\n",
3342 __FILE__,__LINE__, tty->driver->name, info->count );
3344 spin_lock_irqsave(&info->irq_spinlock, flags);
3345 if (!tty_hung_up_p(filp)) {
3349 spin_unlock_irqrestore(&info->irq_spinlock, flags);
3350 info->blocked_open++;
3353 if (tty->termios->c_cflag & CBAUD) {
3354 spin_lock_irqsave(&info->irq_spinlock,flags);
3355 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
3356 usc_set_serial_signals(info);
3357 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3360 set_current_state(TASK_INTERRUPTIBLE);
3362 if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
3363 retval = (info->flags & ASYNC_HUP_NOTIFY) ?
3364 -EAGAIN : -ERESTARTSYS;
3368 spin_lock_irqsave(&info->irq_spinlock,flags);
3369 usc_get_serial_signals(info);
3370 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3372 if (!(info->flags & ASYNC_CLOSING) &&
3373 (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
3377 if (signal_pending(current)) {
3378 retval = -ERESTARTSYS;
3382 if (debug_level >= DEBUG_LEVEL_INFO)
3383 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
3384 __FILE__,__LINE__, tty->driver->name, info->count );
3389 set_current_state(TASK_RUNNING);
3390 remove_wait_queue(&info->open_wait, &wait);
3394 info->blocked_open--;
3396 if (debug_level >= DEBUG_LEVEL_INFO)
3397 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
3398 __FILE__,__LINE__, tty->driver->name, info->count );
3401 info->flags |= ASYNC_NORMAL_ACTIVE;
3405 } /* end of block_til_ready() */
3409 * Called when a port is opened. Init and enable port.
3410 * Perform serial-specific initialization for the tty structure.
3412 * Arguments: tty pointer to tty info structure
3413 * filp associated file pointer
3415 * Return Value: 0 if success, otherwise error code
3417 static int mgsl_open(struct tty_struct *tty, struct file * filp)
3419 struct mgsl_struct *info;
3421 unsigned long flags;
3423 /* verify range of specified line number */
3425 if ((line < 0) || (line >= mgsl_device_count)) {
3426 printk("%s(%d):mgsl_open with invalid line #%d.\n",
3427 __FILE__,__LINE__,line);
3431 /* find the info structure for the specified line */
3432 info = mgsl_device_list;
3433 while(info && info->line != line)
3434 info = info->next_device;
3435 if (mgsl_paranoia_check(info, tty->name, "mgsl_open"))
3438 tty->driver_data = info;
3441 if (debug_level >= DEBUG_LEVEL_INFO)
3442 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
3443 __FILE__,__LINE__,tty->driver->name, info->count);
3445 /* If port is closing, signal caller to try again */
3446 if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
3447 if (info->flags & ASYNC_CLOSING)
3448 interruptible_sleep_on(&info->close_wait);
3449 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
3450 -EAGAIN : -ERESTARTSYS);
3454 info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
3456 spin_lock_irqsave(&info->netlock, flags);
3457 if (info->netcount) {
3459 spin_unlock_irqrestore(&info->netlock, flags);
3463 spin_unlock_irqrestore(&info->netlock, flags);
3465 if (info->count == 1) {
3466 /* 1st open on this device, init hardware */
3467 retval = startup(info);
3472 retval = block_til_ready(tty, filp, info);
3474 if (debug_level >= DEBUG_LEVEL_INFO)
3475 printk("%s(%d):block_til_ready(%s) returned %d\n",
3476 __FILE__,__LINE__, info->device_name, retval);
3480 if (debug_level >= DEBUG_LEVEL_INFO)
3481 printk("%s(%d):mgsl_open(%s) success\n",
3482 __FILE__,__LINE__, info->device_name);
3487 if (tty->count == 1)
3488 info->tty = NULL; /* tty layer will release tty struct */
3495 } /* end of mgsl_open() */
3498 * /proc fs routines....
3501 static inline int line_info(char *buf, struct mgsl_struct *info)
3505 unsigned long flags;
3507 if (info->bus_type == MGSL_BUS_TYPE_PCI) {
3508 ret = sprintf(buf, "%s:PCI io:%04X irq:%d mem:%08X lcr:%08X",
3509 info->device_name, info->io_base, info->irq_level,
3510 info->phys_memory_base, info->phys_lcr_base);
3512 ret = sprintf(buf, "%s:(E)ISA io:%04X irq:%d dma:%d",
3513 info->device_name, info->io_base,
3514 info->irq_level, info->dma_level);
3517 /* output current serial signal states */
3518 spin_lock_irqsave(&info->irq_spinlock,flags);
3519 usc_get_serial_signals(info);
3520 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3524 if (info->serial_signals & SerialSignal_RTS)
3525 strcat(stat_buf, "|RTS");
3526 if (info->serial_signals & SerialSignal_CTS)
3527 strcat(stat_buf, "|CTS");
3528 if (info->serial_signals & SerialSignal_DTR)
3529 strcat(stat_buf, "|DTR");
3530 if (info->serial_signals & SerialSignal_DSR)
3531 strcat(stat_buf, "|DSR");
3532 if (info->serial_signals & SerialSignal_DCD)
3533 strcat(stat_buf, "|CD");
3534 if (info->serial_signals & SerialSignal_RI)
3535 strcat(stat_buf, "|RI");
3537 if (info->params.mode == MGSL_MODE_HDLC ||
3538 info->params.mode == MGSL_MODE_RAW ) {
3539 ret += sprintf(buf+ret, " HDLC txok:%d rxok:%d",
3540 info->icount.txok, info->icount.rxok);
3541 if (info->icount.txunder)
3542 ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
3543 if (info->icount.txabort)
3544 ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
3545 if (info->icount.rxshort)
3546 ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);
3547 if (info->icount.rxlong)
3548 ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
3549 if (info->icount.rxover)
3550 ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
3551 if (info->icount.rxcrc)
3552 ret += sprintf(buf+ret, " rxcrc:%d", info->icount.rxcrc);
3554 ret += sprintf(buf+ret, " ASYNC tx:%d rx:%d",
3555 info->icount.tx, info->icount.rx);
3556 if (info->icount.frame)
3557 ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
3558 if (info->icount.parity)
3559 ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
3560 if (info->icount.brk)
3561 ret += sprintf(buf+ret, " brk:%d", info->icount.brk);
3562 if (info->icount.overrun)
3563 ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
3566 /* Append serial signal status to end */
3567 ret += sprintf(buf+ret, " %s\n", stat_buf+1);
3569 ret += sprintf(buf+ret, "txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
3570 info->tx_active,info->bh_requested,info->bh_running,
3573 spin_lock_irqsave(&info->irq_spinlock,flags);
3575 u16 Tcsr = usc_InReg( info, TCSR );
3576 u16 Tdmr = usc_InDmaReg( info, TDMR );
3577 u16 Ticr = usc_InReg( info, TICR );
3578 u16 Rscr = usc_InReg( info, RCSR );
3579 u16 Rdmr = usc_InDmaReg( info, RDMR );
3580 u16 Ricr = usc_InReg( info, RICR );
3581 u16 Icr = usc_InReg( info, ICR );
3582 u16 Dccr = usc_InReg( info, DCCR );
3583 u16 Tmr = usc_InReg( info, TMR );
3584 u16 Tccr = usc_InReg( info, TCCR );
3585 u16 Ccar = inw( info->io_base + CCAR );
3586 ret += sprintf(buf+ret, "tcsr=%04X tdmr=%04X ticr=%04X rcsr=%04X rdmr=%04X\n"
3587 "ricr=%04X icr =%04X dccr=%04X tmr=%04X tccr=%04X ccar=%04X\n",
3588 Tcsr,Tdmr,Ticr,Rscr,Rdmr,Ricr,Icr,Dccr,Tmr,Tccr,Ccar );
3590 spin_unlock_irqrestore(&info->irq_spinlock,flags);
3594 } /* end of line_info() */
3598 * Called to print information about devices
3601 * page page of memory to hold returned info
3610 static int mgsl_read_proc(char *page, char **start, off_t off, int count,
3611 int *eof, void *data)
3615 struct mgsl_struct *info;
3617 len += sprintf(page, "synclink driver:%s\n", driver_version);
3619 info = mgsl_device_list;
3621 l = line_info(page + len, info);
3623 if (len+begin > off+count)
3625 if (len+begin < off) {
3629 info = info->next_device;
3634 if (off >= len+begin)
3636 *start = page + (off-begin);
3637 return ((count < begin+len-off) ? count : begin+len-off);
3639 } /* end of mgsl_read_proc() */
3641 /* mgsl_allocate_dma_buffers()
3643 * Allocate and format DMA buffers (ISA adapter)
3644 * or format shared memory buffers (PCI adapter).
3646 * Arguments: info pointer to device instance data
3647 * Return Value: 0 if success, otherwise error
3649 static int mgsl_allocate_dma_buffers(struct mgsl_struct *info)
3651 unsigned short BuffersPerFrame;
3653 info->last_mem_alloc = 0;
3655 /* Calculate the number of DMA buffers necessary to hold the */
3656 /* largest allowable frame size. Note: If the max frame size is */
3657 /* not an even multiple of the DMA buffer size then we need to */
3658 /* round the buffer count per frame up one. */
3660 BuffersPerFrame = (unsigned short)(info->max_frame_size/DMABUFFERSIZE);
3661 if ( info->max_frame_size % DMABUFFERSIZE )
3664 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
3666 * The PCI adapter has 256KBytes of shared memory to use.
3667 * This is 64 PAGE_SIZE buffers.
3669 * The first page is used for padding at this time so the
3670 * buffer list does not begin at offset 0 of the PCI
3671 * adapter's shared memory.
3673 * The 2nd page is used for the buffer list. A 4K buffer
3674 * list can hold 128 DMA_BUFFER structures at 32 bytes
3677 * This leaves 62 4K pages.
3679 * The next N pages are used for transmit frame(s). We
3680 * reserve enough 4K page blocks to hold the required
3681 * number of transmit dma buffers (num_tx_dma_buffers),
3682 * each of MaxFrameSize size.
3684 * Of the remaining pages (62-N), determine how many can
3685 * be used to receive full MaxFrameSize inbound frames
3687 info->tx_buffer_count = info->num_tx_dma_buffers * BuffersPerFrame;
3688 info->rx_buffer_count = 62 - info->tx_buffer_count;
3690 /* Calculate the number of PAGE_SIZE buffers needed for */
3691 /* receive and transmit DMA buffers. */
3694 /* Calculate the number of DMA buffers necessary to */
3695 /* hold 7 max size receive frames and one max size transmit frame. */
3696 /* The receive buffer count is bumped by one so we avoid an */
3697 /* End of List condition if all receive buffers are used when */
3698 /* using linked list DMA buffers. */
3700 info->tx_buffer_count = info->num_tx_dma_buffers * BuffersPerFrame;
3701 info->rx_buffer_count = (BuffersPerFrame * MAXRXFRAMES) + 6;
3704 * limit total TxBuffers & RxBuffers to 62 4K total
3705 * (ala PCI Allocation)
3708 if ( (info->tx_buffer_count + info->rx_buffer_count) > 62 )
3709 info->rx_buffer_count = 62 - info->tx_buffer_count;
3713 if ( debug_level >= DEBUG_LEVEL_INFO )
3714 printk("%s(%d):Allocating %d TX and %d RX DMA buffers.\n",
3715 __FILE__,__LINE__, info->tx_buffer_count,info->rx_buffer_count);
3717 if ( mgsl_alloc_buffer_list_memory( info ) < 0 ||
3718 mgsl_alloc_frame_memory(info, info->rx_buffer_list, info->rx_buffer_count) < 0 ||
3719 mgsl_alloc_frame_memory(info, info->tx_buffer_list, info->tx_buffer_count) < 0 ||
3720 mgsl_alloc_intermediate_rxbuffer_memory(info) < 0 ||
3721 mgsl_alloc_intermediate_txbuffer_memory(info) < 0 ) {
3722 printk("%s(%d):Can't allocate DMA buffer memory\n",__FILE__,__LINE__);
3726 mgsl_reset_rx_dma_buffers( info );
3727 mgsl_reset_tx_dma_buffers( info );
3731 } /* end of mgsl_allocate_dma_buffers() */
3734 * mgsl_alloc_buffer_list_memory()
3736 * Allocate a common DMA buffer for use as the
3737 * receive and transmit buffer lists.
3739 * A buffer list is a set of buffer entries where each entry contains
3740 * a pointer to an actual buffer and a pointer to the next buffer entry
3741 * (plus some other info about the buffer).
3743 * The buffer entries for a list are built to form a circular list so
3744 * that when the entire list has been traversed you start back at the
3747 * This function allocates memory for just the buffer entries.
3748 * The links (pointer to next entry) are filled in with the physical
3749 * address of the next entry so the adapter can navigate the list
3750 * using bus master DMA. The pointers to the actual buffers are filled
3751 * out later when the actual buffers are allocated.
3753 * Arguments: info pointer to device instance data
3754 * Return Value: 0 if success, otherwise error
3756 static int mgsl_alloc_buffer_list_memory( struct mgsl_struct *info )
3760 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
3761 /* PCI adapter uses shared memory. */
3762 info->buffer_list = info->memory_base + info->last_mem_alloc;
3763 info->buffer_list_phys = info->last_mem_alloc;
3764 info->last_mem_alloc += BUFFERLISTSIZE;
3766 /* ISA adapter uses system memory. */
3767 /* The buffer lists are allocated as a common buffer that both */
3768 /* the processor and adapter can access. This allows the driver to */
3769 /* inspect portions of the buffer while other portions are being */
3770 /* updated by the adapter using Bus Master DMA. */
3772 info->buffer_list = dma_alloc_coherent(NULL, BUFFERLISTSIZE, &info->buffer_list_dma_addr, GFP_KERNEL);
3773 if (info->buffer_list == NULL)
3775 info->buffer_list_phys = (u32)(info->buffer_list_dma_addr);
3778 /* We got the memory for the buffer entry lists. */
3779 /* Initialize the memory block to all zeros. */
3780 memset( info->buffer_list, 0, BUFFERLISTSIZE );
3782 /* Save virtual address pointers to the receive and */
3783 /* transmit buffer lists. (Receive 1st). These pointers will */
3784 /* be used by the processor to access the lists. */
3785 info->rx_buffer_list = (DMABUFFERENTRY *)info->buffer_list;
3786 info->tx_buffer_list = (DMABUFFERENTRY *)info->buffer_list;
3787 info->tx_buffer_list += info->rx_buffer_count;
3790 * Build the links for the buffer entry lists such that
3791 * two circular lists are built. (Transmit and Receive).
3793 * Note: the links are physical addresses
3794 * which are read by the adapter to determine the next
3795 * buffer entry to use.
3798 for ( i = 0; i < info->rx_buffer_count; i++ ) {
3799 /* calculate and store physical address of this buffer entry */
3800 info->rx_buffer_list[i].phys_entry =
3801 info->buffer_list_phys + (i * sizeof(DMABUFFERENTRY));
3803 /* calculate and store physical address of */
3804 /* next entry in cirular list of entries */
3806 info->rx_buffer_list[i].link = info->buffer_list_phys;
3808 if ( i < info->rx_buffer_count - 1 )
3809 info->rx_buffer_list[i].link += (i + 1) * sizeof(DMABUFFERENTRY);
3812 for ( i = 0; i < info->tx_buffer_count; i++ ) {
3813 /* calculate and store physical address of this buffer entry */
3814 info->tx_buffer_list[i].phys_entry = info->buffer_list_phys +
3815 ((info->rx_buffer_count + i) * sizeof(DMABUFFERENTRY));
3817 /* calculate and store physical address of */
3818 /* next entry in cirular list of entries */
3820 info->tx_buffer_list[i].link = info->buffer_list_phys +
3821 info->rx_buffer_count * sizeof(DMABUFFERENTRY);
3823 if ( i < info->tx_buffer_count - 1 )
3824 info->tx_buffer_list[i].link += (i + 1) * sizeof(DMABUFFERENTRY);
3829 } /* end of mgsl_alloc_buffer_list_memory() */
3831 /* Free DMA buffers allocated for use as the
3832 * receive and transmit buffer lists.
3835 * The data transfer buffers associated with the buffer list
3836 * MUST be freed before freeing the buffer list itself because
3837 * the buffer list contains the information necessary to free
3838 * the individual buffers!
3840 static void mgsl_free_buffer_list_memory( struct mgsl_struct *info )
3842 if (info->buffer_list && info->bus_type != MGSL_BUS_TYPE_PCI)
3843 dma_free_coherent(NULL, BUFFERLISTSIZE, info->buffer_list, info->buffer_list_dma_addr);
3845 info->buffer_list = NULL;
3846 info->rx_buffer_list = NULL;
3847 info->tx_buffer_list = NULL;
3849 } /* end of mgsl_free_buffer_list_memory() */
3852 * mgsl_alloc_frame_memory()
3854 * Allocate the frame DMA buffers used by the specified buffer list.
3855 * Each DMA buffer will be one memory page in size. This is necessary
3856 * because memory can fragment enough that it may be impossible
3861 * info pointer to device instance data
3862 * BufferList pointer to list of buffer entries
3863 * Buffercount count of buffer entries in buffer list
3865 * Return Value: 0 if success, otherwise -ENOMEM
3867 static int mgsl_alloc_frame_memory(struct mgsl_struct *info,DMABUFFERENTRY *BufferList,int Buffercount)
3872 /* Allocate page sized buffers for the receive buffer list */
3874 for ( i = 0; i < Buffercount; i++ ) {
3875 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
3876 /* PCI adapter uses shared memory buffers. */
3877 BufferList[i].virt_addr = info->memory_base + info->last_mem_alloc;
3878 phys_addr = info->last_mem_alloc;
3879 info->last_mem_alloc += DMABUFFERSIZE;
3881 /* ISA adapter uses system memory. */
3882 BufferList[i].virt_addr = dma_alloc_coherent(NULL, DMABUFFERSIZE, &BufferList[i].dma_addr, GFP_KERNEL);
3883 if (BufferList[i].virt_addr == NULL)
3885 phys_addr = (u32)(BufferList[i].dma_addr);
3887 BufferList[i].phys_addr = phys_addr;
3892 } /* end of mgsl_alloc_frame_memory() */
3895 * mgsl_free_frame_memory()
3897 * Free the buffers associated with
3898 * each buffer entry of a buffer list.
3902 * info pointer to device instance data
3903 * BufferList pointer to list of buffer entries
3904 * Buffercount count of buffer entries in buffer list
3906 * Return Value: None
3908 static void mgsl_free_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *BufferList, int Buffercount)
3913 for ( i = 0 ; i < Buffercount ; i++ ) {
3914 if ( BufferList[i].virt_addr ) {
3915 if ( info->bus_type != MGSL_BUS_TYPE_PCI )
3916 dma_free_coherent(NULL, DMABUFFERSIZE, BufferList[i].virt_addr, BufferList[i].dma_addr);
3917 BufferList[i].virt_addr = NULL;
3922 } /* end of mgsl_free_frame_memory() */
3924 /* mgsl_free_dma_buffers()
3928 * Arguments: info pointer to device instance data
3929 * Return Value: None
3931 static void mgsl_free_dma_buffers( struct mgsl_struct *info )
3933 mgsl_free_frame_memory( info, info->rx_buffer_list, info->rx_buffer_count );
3934 mgsl_free_frame_memory( info, info->tx_buffer_list, info->tx_buffer_count );
3935 mgsl_free_buffer_list_memory( info );
3937 } /* end of mgsl_free_dma_buffers() */
3941 * mgsl_alloc_intermediate_rxbuffer_memory()
3943 * Allocate a buffer large enough to hold max_frame_size. This buffer
3944 * is used to pass an assembled frame to the line discipline.
3948 * info pointer to device instance data
3950 * Return Value: 0 if success, otherwise -ENOMEM
3952 static int mgsl_alloc_intermediate_rxbuffer_memory(struct mgsl_struct *info)
3954 info->intermediate_rxbuffer = kmalloc(info->max_frame_size, GFP_KERNEL | GFP_DMA);
3955 if ( info->intermediate_rxbuffer == NULL )
3960 } /* end of mgsl_alloc_intermediate_rxbuffer_memory() */
3963 * mgsl_free_intermediate_rxbuffer_memory()
3968 * info pointer to device instance data
3970 * Return Value: None
3972 static void mgsl_free_intermediate_rxbuffer_memory(struct mgsl_struct *info)
3974 kfree(info->intermediate_rxbuffer);
3975 info->intermediate_rxbuffer = NULL;
3977 } /* end of mgsl_free_intermediate_rxbuffer_memory() */
3980 * mgsl_alloc_intermediate_txbuffer_memory()
3982 * Allocate intermdiate transmit buffer(s) large enough to hold max_frame_size.
3983 * This buffer is used to load transmit frames into the adapter's dma transfer
3984 * buffers when there is sufficient space.
3988 * info pointer to device instance data
3990 * Return Value: 0 if success, otherwise -ENOMEM
3992 static int mgsl_alloc_intermediate_txbuffer_memory(struct mgsl_struct *info)
3996 if ( debug_level >= DEBUG_LEVEL_INFO )
3997 printk("%s %s(%d) allocating %d tx holding buffers\n",
3998 info->device_name, __FILE__,__LINE__,info->num_tx_holding_buffers);
4000 memset(info->tx_holding_buffers,0,sizeof(info->tx_holding_buffers));
4002 for ( i=0; i<info->num_tx_holding_buffers; ++i) {
4003 info->tx_holding_buffers[i].buffer =
4004 kmalloc(info->max_frame_size, GFP_KERNEL);
4005 if (info->tx_holding_buffers[i].buffer == NULL) {
4006 for (--i; i >= 0; i--) {
4007 kfree(info->tx_holding_buffers[i].buffer);
4008 info->tx_holding_buffers[i].buffer = NULL;
4016 } /* end of mgsl_alloc_intermediate_txbuffer_memory() */
4019 * mgsl_free_intermediate_txbuffer_memory()
4024 * info pointer to device instance data
4026 * Return Value: None
4028 static void mgsl_free_intermediate_txbuffer_memory(struct mgsl_struct *info)
4032 for ( i=0; i<info->num_tx_holding_buffers; ++i ) {
4033 kfree(info->tx_holding_buffers[i].buffer);
4034 info->tx_holding_buffers[i].buffer = NULL;
4037 info->get_tx_holding_index = 0;
4038 info->put_tx_holding_index = 0;
4039 info->tx_holding_count = 0;
4041 } /* end of mgsl_free_intermediate_txbuffer_memory() */
4045 * load_next_tx_holding_buffer()
4047 * attempts to load the next buffered tx request into the
4052 * info pointer to device instance data
4054 * Return Value: 1 if next buffered tx request loaded
4055 * into adapter's tx dma buffer,
4058 static int load_next_tx_holding_buffer(struct mgsl_struct *info)
4062 if ( info->tx_holding_count ) {
4063 /* determine if we have enough tx dma buffers
4064 * to accommodate the next tx frame
4066 struct tx_holding_buffer *ptx =
4067 &info->tx_holding_buffers[info->get_tx_holding_index];
4068 int num_free = num_free_tx_dma_buffers(info);
4069 int num_needed = ptx->buffer_size / DMABUFFERSIZE;
4070 if ( ptx->buffer_size % DMABUFFERSIZE )
4073 if (num_needed <= num_free) {
4074 info->xmit_cnt = ptx->buffer_size;
4075 mgsl_load_tx_dma_buffer(info,ptx->buffer,ptx->buffer_size);
4077 --info->tx_holding_count;
4078 if ( ++info->get_tx_holding_index >= info->num_tx_holding_buffers)
4079 info->get_tx_holding_index=0;
4081 /* restart transmit timer */
4082 mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(5000));
4092 * save_tx_buffer_request()
4094 * attempt to store transmit frame request for later transmission
4098 * info pointer to device instance data
4099 * Buffer pointer to buffer containing frame to load
4100 * BufferSize size in bytes of frame in Buffer
4102 * Return Value: 1 if able to store, 0 otherwise
4104 static int save_tx_buffer_request(struct mgsl_struct *info,const char *Buffer, unsigned int BufferSize)
4106 struct tx_holding_buffer *ptx;
4108 if ( info->tx_holding_count >= info->num_tx_holding_buffers ) {
4109 return 0; /* all buffers in use */
4112 ptx = &info->tx_holding_buffers[info->put_tx_holding_index];
4113 ptx->buffer_size = BufferSize;
4114 memcpy( ptx->buffer, Buffer, BufferSize);
4116 ++info->tx_holding_count;
4117 if ( ++info->put_tx_holding_index >= info->num_tx_holding_buffers)
4118 info->put_tx_holding_index=0;
4123 static int mgsl_claim_resources(struct mgsl_struct *info)
4125 if (request_region(info->io_base,info->io_addr_size,"synclink") == NULL) {
4126 printk( "%s(%d):I/O address conflict on device %s Addr=%08X\n",
4127 __FILE__,__LINE__,info->device_name, info->io_base);
4130 info->io_addr_requested = 1;
4132 if ( request_irq(info->irq_level,mgsl_interrupt,info->irq_flags,
4133 info->device_name, info ) < 0 ) {
4134 printk( "%s(%d):Cant request interrupt on device %s IRQ=%d\n",
4135 __FILE__,__LINE__,info->device_name, info->irq_level );
4138 info->irq_requested = 1;
4140 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
4141 if (request_mem_region(info->phys_memory_base,0x40000,"synclink") == NULL) {
4142 printk( "%s(%d):mem addr conflict device %s Addr=%08X\n",
4143 __FILE__,__LINE__,info->device_name, info->phys_memory_base);
4146 info->shared_mem_requested = 1;
4147 if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclink") == NULL) {
4148 printk( "%s(%d):lcr mem addr conflict device %s Addr=%08X\n",
4149 __FILE__,__LINE__,info->device_name, info->phys_lcr_base + info->lcr_offset);
4152 info->lcr_mem_requested = 1;
4154 info->memory_base = ioremap(info->phys_memory_base,0x40000);
4155 if (!info->memory_base) {
4156 printk( "%s(%d):Cant map shared memory on device %s MemAddr=%08X\n",
4157 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
4161 if ( !mgsl_memory_test(info) ) {
4162 printk( "%s(%d):Failed shared memory test %s MemAddr=%08X\n",
4163 __FILE__,__LINE__,info->device_name, info->phys_memory_base );
4167 info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE) + info->lcr_offset;
4168 if (!info->lcr_base) {
4169 printk( "%s(%d):Cant map LCR memory on device %s MemAddr=%08X\n",
4170 __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
4175 /* claim DMA channel */
4177 if (request_dma(info->dma_level,info->device_name) < 0){
4178 printk( "%s(%d):Cant request DMA channel on device %s DMA=%d\n",
4179 __FILE__,__LINE__,info->device_name, info->dma_level );
4180 mgsl_release_resources( info );
4183 info->dma_requested = 1;
4185 /* ISA adapter uses bus master DMA */
4186 set_dma_mode(info->dma_level,DMA_MODE_CASCADE);
4187 enable_dma(info->dma_level);
4190 if ( mgsl_allocate_dma_buffers(info) < 0 ) {
4191 printk( "%s(%d):Cant allocate DMA buffers on device %s DMA=%d\n",
4192 __FILE__,__LINE__,info->device_name, info->dma_level );
4198 mgsl_release_resources(info);
4201 } /* end of mgsl_claim_resources() */
4203 static void mgsl_release_resources(struct mgsl_struct *info)
4205 if ( debug_level >= DEBUG_LEVEL_INFO )
4206 printk( "%s(%d):mgsl_release_resources(%s) entry\n",
4207 __FILE__,__LINE__,info->device_name );
4209 if ( info->irq_requested ) {
4210 free_irq(info->irq_level, info);
4211 info->irq_requested = 0;
4213 if ( info->dma_requested ) {
4214 disable_dma(info->dma_level);
4215 free_dma(info->dma_level);
4216 info->dma_requested = 0;
4218 mgsl_free_dma_buffers(info);
4219 mgsl_free_intermediate_rxbuffer_memory(info);
4220 mgsl_free_intermediate_txbuffer_memory(info);
4222 if ( info->io_addr_requested ) {
4223 release_region(info->io_base,info->io_addr_size);
4224 info->io_addr_requested = 0;
4226 if ( info->shared_mem_requested ) {
4227 release_mem_region(info->phys_memory_base,0x40000);
4228 info->shared_mem_requested = 0;
4230 if ( info->lcr_mem_requested ) {
4231 release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
4232 info->lcr_mem_requested = 0;
4234 if (info->memory_base){
4235 iounmap(info->memory_base);
4236 info->memory_base = NULL;
4238 if (info->lcr_base){
4239 iounmap(info->lcr_base - info->lcr_offset);
4240 info->lcr_base = NULL;
4243 if ( debug_level >= DEBUG_LEVEL_INFO )
4244 printk( "%s(%d):mgsl_release_resources(%s) exit\n",
4245 __FILE__,__LINE__,info->device_name );
4247 } /* end of mgsl_release_resources() */
4249 /* mgsl_add_device()
4251 * Add the specified device instance data structure to the
4252 * global linked list of devices and increment the device count.
4254 * Arguments: info pointer to device instance data
4255 * Return Value: None
4257 static void mgsl_add_device( struct mgsl_struct *info )
4259 info->next_device = NULL;
4260 info->line = mgsl_device_count;
4261 sprintf(info->device_name,"ttySL%d",info->line);
4263 if (info->line < MAX_TOTAL_DEVICES) {
4264 if (maxframe[info->line])
4265 info->max_frame_size = maxframe[info->line];
4266 info->dosyncppp = dosyncppp[info->line];
4268 if (txdmabufs[info->line]) {
4269 info->num_tx_dma_buffers = txdmabufs[info->line];
4270 if (info->num_tx_dma_buffers < 1)
4271 info->num_tx_dma_buffers = 1;
4274 if (txholdbufs[info->line]) {
4275 info->num_tx_holding_buffers = txholdbufs[info->line];
4276 if (info->num_tx_holding_buffers < 1)
4277 info->num_tx_holding_buffers = 1;
4278 else if (info->num_tx_holding_buffers > MAX_TX_HOLDING_BUFFERS)
4279 info->num_tx_holding_buffers = MAX_TX_HOLDING_BUFFERS;
4283 mgsl_device_count++;
4285 if ( !mgsl_device_list )
4286 mgsl_device_list = info;
4288 struct mgsl_struct *current_dev = mgsl_device_list;
4289 while( current_dev->next_device )
4290 current_dev = current_dev->next_device;
4291 current_dev->next_device = info;
4294 if ( info->max_frame_size < 4096 )
4295 info->max_frame_size = 4096;
4296 else if ( info->max_frame_size > 65535 )
4297 info->max_frame_size = 65535;
4299 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
4300 printk( "SyncLink PCI v%d %s: IO=%04X IRQ=%d Mem=%08X,%08X MaxFrameSize=%u\n",
4301 info->hw_version + 1, info->device_name, info->io_base, info->irq_level,
4302 info->phys_memory_base, info->phys_lcr_base,
4303 info->max_frame_size );
4305 printk( "SyncLink ISA %s: IO=%04X IRQ=%d DMA=%d MaxFrameSize=%u\n",
4306 info->device_name, info->io_base, info->irq_level, info->dma_level,
4307 info->max_frame_size );
4310 #if SYNCLINK_GENERIC_HDLC
4314 } /* end of mgsl_add_device() */
4316 /* mgsl_allocate_device()
4318 * Allocate and initialize a device instance structure
4321 * Return Value: pointer to mgsl_struct if success, otherwise NULL
4323 static struct mgsl_struct* mgsl_allocate_device(void)
4325 struct mgsl_struct *info;
4327 info = kmalloc(sizeof(struct mgsl_struct),
4331 printk("Error can't allocate device instance data\n");
4333 memset(info, 0, sizeof(struct mgsl_struct));
4334 info->magic = MGSL_MAGIC;
4335 INIT_WORK(&info->task, mgsl_bh_handler);
4336 info->max_frame_size = 4096;
4337 info->close_delay = 5*HZ/10;
4338 info->closing_wait = 30*HZ;
4339 init_waitqueue_head(&info->open_wait);
4340 init_waitqueue_head(&info->close_wait);
4341 init_waitqueue_head(&info->status_event_wait_q);
4342 init_waitqueue_head(&info->event_wait_q);
4343 spin_lock_init(&info->irq_spinlock);
4344 spin_lock_init(&info->netlock);
4345 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
4346 info->idle_mode = HDLC_TXIDLE_FLAGS;
4347 info->num_tx_dma_buffers = 1;
4348 info->num_tx_holding_buffers = 0;
4353 } /* end of mgsl_allocate_device()*/
4355 static const struct tty_operations mgsl_ops = {
4357 .close = mgsl_close,
4358 .write = mgsl_write,
4359 .put_char = mgsl_put_char,
4360 .flush_chars = mgsl_flush_chars,
4361 .write_room = mgsl_write_room,
4362 .chars_in_buffer = mgsl_chars_in_buffer,
4363 .flush_buffer = mgsl_flush_buffer,
4364 .ioctl = mgsl_ioctl,
4365 .throttle = mgsl_throttle,
4366 .unthrottle = mgsl_unthrottle,
4367 .send_xchar = mgsl_send_xchar,
4368 .break_ctl = mgsl_break,
4369 .wait_until_sent = mgsl_wait_until_sent,
4370 .read_proc = mgsl_read_proc,
4371 .set_termios = mgsl_set_termios,
4373 .start = mgsl_start,
4374 .hangup = mgsl_hangup,
4375 .tiocmget = tiocmget,
4376 .tiocmset = tiocmset,
4380 * perform tty device initialization
4382 static int mgsl_init_tty(void)
4386 serial_driver = alloc_tty_driver(128);
4390 serial_driver->owner = THIS_MODULE;
4391 serial_driver->driver_name = "synclink";
4392 serial_driver->name = "ttySL";
4393 serial_driver->major = ttymajor;
4394 serial_driver->minor_start = 64;
4395 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
4396 serial_driver->subtype = SERIAL_TYPE_NORMAL;
4397 serial_driver->init_termios = tty_std_termios;
4398 serial_driver->init_termios.c_cflag =
4399 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
4400 serial_driver->init_termios.c_ispeed = 9600;
4401 serial_driver->init_termios.c_ospeed = 9600;
4402 serial_driver->flags = TTY_DRIVER_REAL_RAW;
4403 tty_set_operations(serial_driver, &mgsl_ops);
4404 if ((rc = tty_register_driver(serial_driver)) < 0) {
4405 printk("%s(%d):Couldn't register serial driver\n",
4407 put_tty_driver(serial_driver);
4408 serial_driver = NULL;
4412 printk("%s %s, tty major#%d\n",
4413 driver_name, driver_version,
4414 serial_driver->major);
4418 /* enumerate user specified ISA adapters
4420 static void mgsl_enum_isa_devices(void)
4422 struct mgsl_struct *info;
4425 /* Check for user specified ISA devices */
4427 for (i=0 ;(i < MAX_ISA_DEVICES) && io[i] && irq[i]; i++){
4428 if ( debug_level >= DEBUG_LEVEL_INFO )
4429 printk("ISA device specified io=%04X,irq=%d,dma=%d\n",
4430 io[i], irq[i], dma[i] );
4432 info = mgsl_allocate_device();
4434 /* error allocating device instance data */
4435 if ( debug_level >= DEBUG_LEVEL_ERROR )
4436 printk( "can't allocate device instance data.\n");
4440 /* Copy user configuration info to device instance data */
4441 info->io_base = (unsigned int)io[i];
4442 info->irq_level = (unsigned int)irq[i];
4443 info->irq_level = irq_canonicalize(info->irq_level);
4444 info->dma_level = (unsigned int)dma[i];
4445 info->bus_type = MGSL_BUS_TYPE_ISA;
4446 info->io_addr_size = 16;
4447 info->irq_flags = 0;
4449 mgsl_add_device( info );
4453 static void synclink_cleanup(void)
4456 struct mgsl_struct *info;
4457 struct mgsl_struct *tmp;
4459 printk("Unloading %s: %s\n", driver_name, driver_version);
4461 if (serial_driver) {
4462 if ((rc = tty_unregister_driver(serial_driver)))
4463 printk("%s(%d) failed to unregister tty driver err=%d\n",
4464 __FILE__,__LINE__,rc);
4465 put_tty_driver(serial_driver);
4468 info = mgsl_device_list;
4470 #if SYNCLINK_GENERIC_HDLC
4473 mgsl_release_resources(info);
4475 info = info->next_device;
4480 pci_unregister_driver(&synclink_pci_driver);
4483 static int __init synclink_init(void)
4487 if (break_on_load) {
4488 mgsl_get_text_ptr();
4492 printk("%s %s\n", driver_name, driver_version);
4494 mgsl_enum_isa_devices();
4495 if ((rc = pci_register_driver(&synclink_pci_driver)) < 0)
4496 printk("%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
4500 if ((rc = mgsl_init_tty()) < 0)
4510 static void __exit synclink_exit(void)
4515 module_init(synclink_init);
4516 module_exit(synclink_exit);
4521 * Issue a USC Receive/Transmit command to the
4522 * Channel Command/Address Register (CCAR).
4526 * The command is encoded in the most significant 5 bits <15..11>
4527 * of the CCAR value. Bits <10..7> of the CCAR must be preserved
4528 * and Bits <6..0> must be written as zeros.
4532 * info pointer to device information structure
4533 * Cmd command mask (use symbolic macros)
4539 static void usc_RTCmd( struct mgsl_struct *info, u16 Cmd )
4541 /* output command to CCAR in bits <15..11> */
4542 /* preserve bits <10..7>, bits <6..0> must be zero */
4544 outw( Cmd + info->loopback_bits, info->io_base + CCAR );
4546 /* Read to flush write to CCAR */
4547 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
4548 inw( info->io_base + CCAR );
4550 } /* end of usc_RTCmd() */
4555 * Issue a DMA command to the DMA Command/Address Register (DCAR).
4559 * info pointer to device information structure
4560 * Cmd DMA command mask (usc_DmaCmd_XX Macros)
4566 static void usc_DmaCmd( struct mgsl_struct *info, u16 Cmd )
4568 /* write command mask to DCAR */
4569 outw( Cmd + info->mbre_bit, info->io_base );
4571 /* Read to flush write to DCAR */
4572 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
4573 inw( info->io_base );
4575 } /* end of usc_DmaCmd() */
4580 * Write a 16-bit value to a USC DMA register
4584 * info pointer to device info structure
4585 * RegAddr register address (number) for write
4586 * RegValue 16-bit value to write to register
4593 static void usc_OutDmaReg( struct mgsl_struct *info, u16 RegAddr, u16 RegValue )
4595 /* Note: The DCAR is located at the adapter base address */
4596 /* Note: must preserve state of BIT8 in DCAR */
4598 outw( RegAddr + info->mbre_bit, info->io_base );
4599 outw( RegValue, info->io_base );
4601 /* Read to flush write to DCAR */
4602 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
4603 inw( info->io_base );
4605 } /* end of usc_OutDmaReg() */
4610 * Read a 16-bit value from a DMA register
4614 * info pointer to device info structure
4615 * RegAddr register address (number) to read from
4619 * The 16-bit value read from register
4622 static u16 usc_InDmaReg( struct mgsl_struct *info, u16 RegAddr )
4624 /* Note: The DCAR is located at the adapter base address */
4625 /* Note: must preserve state of BIT8 in DCAR */
4627 outw( RegAddr + info->mbre_bit, info->io_base );
4628 return inw( info->io_base );
4630 } /* end of usc_InDmaReg() */
4636 * Write a 16-bit value to a USC serial channel register
4640 * info pointer to device info structure
4641 * RegAddr register address (number) to write to
4642 * RegValue 16-bit value to write to register
4649 static void usc_OutReg( struct mgsl_struct *info, u16 RegAddr, u16 RegValue )
4651 outw( RegAddr + info->loopback_bits, info->io_base + CCAR );
4652 outw( RegValue, info->io_base + CCAR );
4654 /* Read to flush write to CCAR */
4655 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
4656 inw( info->io_base + CCAR );
4658 } /* end of usc_OutReg() */
4663 * Reads a 16-bit value from a USC serial channel register
4667 * info pointer to device extension
4668 * RegAddr register address (number) to read from
4672 * 16-bit value read from register
4674 static u16 usc_InReg( struct mgsl_struct *info, u16 RegAddr )
4676 outw( RegAddr + info->loopback_bits, info->io_base + CCAR );
4677 return inw( info->io_base + CCAR );
4679 } /* end of usc_InReg() */
4681 /* usc_set_sdlc_mode()
4683 * Set up the adapter for SDLC DMA communications.
4685 * Arguments: info pointer to device instance data
4686 * Return Value: NONE
4688 static void usc_set_sdlc_mode( struct mgsl_struct *info )
4694 * determine if the IUSC on the adapter is pre-SL1660. If
4695 * not, take advantage of the UnderWait feature of more
4696 * modern chips. If an underrun occurs and this bit is set,
4697 * the transmitter will idle the programmed idle pattern
4698 * until the driver has time to service the underrun. Otherwise,
4699 * the dma controller may get the cycles previously requested
4700 * and begin transmitting queued tx data.
4702 usc_OutReg(info,TMCR,0x1f);
4703 RegValue=usc_InReg(info,TMDR);
4704 if ( RegValue == IUSC_PRE_SL1660 )
4710 if ( info->params.flags & HDLC_FLAG_HDLC_LOOPMODE )
4713 ** Channel Mode Register (CMR)
4715 ** <15..14> 10 Tx Sub Modes, Send Flag on Underrun
4716 ** <13> 0 0 = Transmit Disabled (initially)
4717 ** <12> 0 1 = Consecutive Idles share common 0
4718 ** <11..8> 1110 Transmitter Mode = HDLC/SDLC Loop
4719 ** <7..4> 0000 Rx Sub Modes, addr/ctrl field handling
4720 ** <3..0> 0110 Receiver Mode = HDLC/SDLC
4722 ** 1000 1110 0000 0110 = 0x8e06
4726 /*--------------------------------------------------
4727 * ignore user options for UnderRun Actions and
4729 *--------------------------------------------------*/
4733 /* Channel mode Register (CMR)
4735 * <15..14> 00 Tx Sub modes, Underrun Action
4736 * <13> 0 1 = Send Preamble before opening flag
4737 * <12> 0 1 = Consecutive Idles share common 0
4738 * <11..8> 0110 Transmitter mode = HDLC/SDLC
4739 * <7..4> 0000 Rx Sub modes, addr/ctrl field handling
4740 * <3..0> 0110 Receiver mode = HDLC/SDLC
4742 * 0000 0110 0000 0110 = 0x0606
4744 if (info->params.mode == MGSL_MODE_RAW) {
4745 RegValue = 0x0001; /* Set Receive mode = external sync */
4747 usc_OutReg( info, IOCR, /* Set IOCR DCD is RxSync Detect Input */
4748 (unsigned short)((usc_InReg(info, IOCR) & ~(BIT13|BIT12)) | BIT12));
4752 * CMR <15> 0 Don't send CRC on Tx Underrun
4753 * CMR <14> x undefined
4754 * CMR <13> 0 Send preamble before openning sync
4755 * CMR <12> 0 Send 8-bit syncs, 1=send Syncs per TxLength
4758 * CMR <11-8) 0100 MonoSync
4760 * 0x00 0100 xxxx xxxx 04xx
4768 if ( info->params.flags & HDLC_FLAG_UNDERRUN_ABORT15 )
4770 else if ( info->params.flags & HDLC_FLAG_UNDERRUN_FLAG )
4772 else if ( info->params.flags & HDLC_FLAG_UNDERRUN_CRC )
4773 RegValue |= BIT15 + BIT14;
4776 if ( info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE )
4780 if ( info->params.mode == MGSL_MODE_HDLC &&
4781 (info->params.flags & HDLC_FLAG_SHARE_ZERO) )
4784 if ( info->params.addr_filter != 0xff )
4786 /* set up receive address filtering */
4787 usc_OutReg( info, RSR, info->params.addr_filter );
4791 usc_OutReg( info, CMR, RegValue );
4792 info->cmr_value = RegValue;
4794 /* Receiver mode Register (RMR)
4796 * <15..13> 000 encoding
4797 * <12..11> 00 FCS = 16bit CRC CCITT (x15 + x12 + x5 + 1)
4798 * <10> 1 1 = Set CRC to all 1s (use for SDLC/HDLC)
4799 * <9> 0 1 = Include Receive chars in CRC
4800 * <8> 1 1 = Use Abort/PE bit as abort indicator
4801 * <7..6> 00 Even parity
4802 * <5> 0 parity disabled
4803 * <4..2> 000 Receive Char Length = 8 bits
4804 * <1..0> 00 Disable Receiver
4806 * 0000 0101 0000 0000 = 0x0500
4811 switch ( info->params.encoding ) {
4812 case HDLC_ENCODING_NRZB: RegValue |= BIT13; break;
4813 case HDLC_ENCODING_NRZI_MARK: RegValue |= BIT14; break;
4814 case HDLC_ENCODING_NRZI_SPACE: RegValue |= BIT14 + BIT13; break;
4815 case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT15; break;
4816 case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT15 + BIT13; break;
4817 case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14; break;
4818 case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14 + BIT13; break;
4821 if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_16_CCITT )
4823 else if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_32_CCITT )
4824 RegValue |= ( BIT12 | BIT10 | BIT9 );
4826 usc_OutReg( info, RMR, RegValue );
4828 /* Set the Receive count Limit Register (RCLR) to 0xffff. */
4829 /* When an opening flag of an SDLC frame is recognized the */
4830 /* Receive Character count (RCC) is loaded with the value in */
4831 /* RCLR. The RCC is decremented for each received byte. The */
4832 /* value of RCC is stored after the closing flag of the frame */
4833 /* allowing the frame size to be computed. */
4835 usc_OutReg( info, RCLR, RCLRVALUE );
4837 usc_RCmd( info, RCmd_SelectRicrdma_level );
4839 /* Receive Interrupt Control Register (RICR)
4841 * <15..8> ? RxFIFO DMA Request Level
4842 * <7> 0 Exited Hunt IA (Interrupt Arm)
4843 * <6> 0 Idle Received IA
4844 * <5> 0 Break/Abort IA
4846 * <3> 1 Queued status reflects oldest 2 bytes in FIFO
4848 * <1> 1 Rx Overrun IA
4849 * <0> 0 Select TC0 value for readback
4851 * 0000 0000 0000 1000 = 0x000a
4854 /* Carry over the Exit Hunt and Idle Received bits */
4855 /* in case they have been armed by usc_ArmEvents. */
4857 RegValue = usc_InReg( info, RICR ) & 0xc0;
4859 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
4860 usc_OutReg( info, RICR, (u16)(0x030a | RegValue) );
4862 usc_OutReg( info, RICR, (u16)(0x140a | RegValue) );
4864 /* Unlatch all Rx status bits and clear Rx status IRQ Pending */
4866 usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
4867 usc_ClearIrqPendingBits( info, RECEIVE_STATUS );
4869 /* Transmit mode Register (TMR)
4871 * <15..13> 000 encoding
4872 * <12..11> 00 FCS = 16bit CRC CCITT (x15 + x12 + x5 + 1)
4873 * <10> 1 1 = Start CRC as all 1s (use for SDLC/HDLC)
4874 * <9> 0 1 = Tx CRC Enabled
4875 * <8> 0 1 = Append CRC to end of transmit frame
4876 * <7..6> 00 Transmit parity Even
4877 * <5> 0 Transmit parity Disabled
4878 * <4..2> 000 Tx Char Length = 8 bits
4879 * <1..0> 00 Disable Transmitter
4881 * 0000 0100 0000 0000 = 0x0400
4886 switch ( info->params.encoding ) {
4887 case HDLC_ENCODING_NRZB: RegValue |= BIT13; break;
4888 case HDLC_ENCODING_NRZI_MARK: RegValue |= BIT14; break;
4889 case HDLC_ENCODING_NRZI_SPACE: RegValue |= BIT14 + BIT13; break;
4890 case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT15; break;
4891 case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT15 + BIT13; break;
4892 case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14; break;
4893 case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14 + BIT13; break;
4896 if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_16_CCITT )
4897 RegValue |= BIT9 + BIT8;
4898 else if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_32_CCITT )
4899 RegValue |= ( BIT12 | BIT10 | BIT9 | BIT8);
4901 usc_OutReg( info, TMR, RegValue );
4903 usc_set_txidle( info );
4906 usc_TCmd( info, TCmd_SelectTicrdma_level );
4908 /* Transmit Interrupt Control Register (TICR)
4910 * <15..8> ? Transmit FIFO DMA Level
4911 * <7> 0 Present IA (Interrupt Arm)
4912 * <6> 0 Idle Sent IA
4913 * <5> 1 Abort Sent IA
4914 * <4> 1 EOF/EOM Sent IA
4916 * <2> 1 1 = Wait for SW Trigger to Start Frame
4917 * <1> 1 Tx Underrun IA
4918 * <0> 0 TC0 constant on read back
4920 * 0000 0000 0011 0110 = 0x0036
4923 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
4924 usc_OutReg( info, TICR, 0x0736 );
4926 usc_OutReg( info, TICR, 0x1436 );
4928 usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
4929 usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
4932 ** Transmit Command/Status Register (TCSR)
4934 ** <15..12> 0000 TCmd
4935 ** <11> 0/1 UnderWait
4936 ** <10..08> 000 TxIdle
4940 ** <4> x EOF/EOM Sent
4946 ** 0000 0000 0000 0000 = 0x0000
4948 info->tcsr_value = 0;
4951 info->tcsr_value |= TCSR_UNDERWAIT;
4953 usc_OutReg( info, TCSR, info->tcsr_value );
4955 /* Clock mode Control Register (CMCR)
4957 * <15..14> 00 counter 1 Source = Disabled
4958 * <13..12> 00 counter 0 Source = Disabled
4959 * <11..10> 11 BRG1 Input is TxC Pin
4960 * <9..8> 11 BRG0 Input is TxC Pin
4961 * <7..6> 01 DPLL Input is BRG1 Output
4962 * <5..3> XXX TxCLK comes from Port 0
4963 * <2..0> XXX RxCLK comes from Port 1
4965 * 0000 1111 0111 0111 = 0x0f77
4970 if ( info->params.flags & HDLC_FLAG_RXC_DPLL )
4971 RegValue |= 0x0003; /* RxCLK from DPLL */
4972 else if ( info->params.flags & HDLC_FLAG_RXC_BRG )
4973 RegValue |= 0x0004; /* RxCLK from BRG0 */
4974 else if ( info->params.flags & HDLC_FLAG_RXC_TXCPIN)
4975 RegValue |= 0x0006; /* RxCLK from TXC Input */
4977 RegValue |= 0x0007; /* RxCLK from Port1 */
4979 if ( info->params.flags & HDLC_FLAG_TXC_DPLL )
4980 RegValue |= 0x0018; /* TxCLK from DPLL */
4981 else if ( info->params.flags & HDLC_FLAG_TXC_BRG )
4982 RegValue |= 0x0020; /* TxCLK from BRG0 */
4983 else if ( info->params.flags & HDLC_FLAG_TXC_RXCPIN)
4984 RegValue |= 0x0038; /* RxCLK from TXC Input */
4986 RegValue |= 0x0030; /* TxCLK from Port0 */
4988 usc_OutReg( info, CMCR, RegValue );
4991 /* Hardware Configuration Register (HCR)
4993 * <15..14> 00 CTR0 Divisor:00=32,01=16,10=8,11=4
4994 * <13> 0 CTR1DSel:0=CTR0Div determines CTR0Div
4995 * <12> 0 CVOK:0=report code violation in biphase
4996 * <11..10> 00 DPLL Divisor:00=32,01=16,10=8,11=4
4997 * <9..8> XX DPLL mode:00=disable,01=NRZ,10=Biphase,11=Biphase Level
4998 * <7..6> 00 reserved
4999 * <5> 0 BRG1 mode:0=continuous,1=single cycle
5001 * <3..2> 00 reserved
5002 * <1> 0 BRG0 mode:0=continuous,1=single cycle
5008 if ( info->params.flags & (HDLC_FLAG_RXC_DPLL + HDLC_FLAG_TXC_DPLL) ) {
5013 /* DPLL is enabled. Use BRG1 to provide continuous reference clock */
5014 /* for DPLL. DPLL mode in HCR is dependent on the encoding used. */
5016 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
5017 XtalSpeed = 11059200;
5019 XtalSpeed = 14745600;
5021 if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
5025 else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
5032 /* Tc = (Xtal/Speed) - 1 */
5033 /* If twice the remainder of (Xtal/Speed) is greater than Speed */
5034 /* then rounding up gives a more precise time constant. Instead */
5035 /* of rounding up and then subtracting 1 we just don't subtract */
5036 /* the one in this case. */
5038 /*--------------------------------------------------
5039 * ejz: for DPLL mode, application should use the
5040 * same clock speed as the partner system, even
5041 * though clocking is derived from the input RxData.
5042 * In case the user uses a 0 for the clock speed,
5043 * default to 0xffffffff and don't try to divide by
5045 *--------------------------------------------------*/
5046 if ( info->params.clock_speed )
5048 Tc = (u16)((XtalSpeed/DpllDivisor)/info->params.clock_speed);
5049 if ( !((((XtalSpeed/DpllDivisor) % info->params.clock_speed) * 2)
5050 / info->params.clock_speed) )
5057 /* Write 16-bit Time Constant for BRG1 */
5058 usc_OutReg( info, TC1R, Tc );
5060 RegValue |= BIT4; /* enable BRG1 */
5062 switch ( info->params.encoding ) {
5063 case HDLC_ENCODING_NRZ:
5064 case HDLC_ENCODING_NRZB:
5065 case HDLC_ENCODING_NRZI_MARK:
5066 case HDLC_ENCODING_NRZI_SPACE: RegValue |= BIT8; break;
5067 case HDLC_ENCODING_BIPHASE_MARK:
5068 case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT9; break;
5069 case HDLC_ENCODING_BIPHASE_LEVEL:
5070 case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: RegValue |= BIT9 + BIT8; break;
5074 usc_OutReg( info, HCR, RegValue );
5077 /* Channel Control/status Register (CCSR)
5079 * <15> X RCC FIFO Overflow status (RO)
5080 * <14> X RCC FIFO Not Empty status (RO)
5081 * <13> 0 1 = Clear RCC FIFO (WO)
5082 * <12> X DPLL Sync (RW)
5083 * <11> X DPLL 2 Missed Clocks status (RO)
5084 * <10> X DPLL 1 Missed Clock status (RO)
5085 * <9..8> 00 DPLL Resync on rising and falling edges (RW)
5086 * <7> X SDLC Loop On status (RO)
5087 * <6> X SDLC Loop Send status (RO)
5088 * <5> 1 Bypass counters for TxClk and RxClk (RW)
5089 * <4..2> 000 Last Char of SDLC frame has 8 bits (RW)
5090 * <1..0> 00 reserved
5092 * 0000 0000 0010 0000 = 0x0020
5095 usc_OutReg( info, CCSR, 0x1020 );
5098 if ( info->params.flags & HDLC_FLAG_AUTO_CTS ) {
5099 usc_OutReg( info, SICR,
5100 (u16)(usc_InReg(info,SICR) | SICR_CTS_INACTIVE) );
5104 /* enable Master Interrupt Enable bit (MIE) */
5105 usc_EnableMasterIrqBit( info );
5107 usc_ClearIrqPendingBits( info, RECEIVE_STATUS + RECEIVE_DATA +
5108 TRANSMIT_STATUS + TRANSMIT_DATA + MISC);
5110 /* arm RCC underflow interrupt */
5111 usc_OutReg(info, SICR, (u16)(usc_InReg(info,SICR) | BIT3));
5112 usc_EnableInterrupts(info, MISC);
5115 outw( 0, info->io_base ); /* clear Master Bus Enable (DCAR) */
5116 usc_DmaCmd( info, DmaCmd_ResetAllChannels ); /* disable both DMA channels */
5117 info->mbre_bit = BIT8;
5118 outw( BIT8, info->io_base ); /* set Master Bus Enable (DCAR) */
5120 if (info->bus_type == MGSL_BUS_TYPE_ISA) {
5121 /* Enable DMAEN (Port 7, Bit 14) */
5122 /* This connects the DMA request signal to the ISA bus */
5123 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT15) & ~BIT14));
5126 /* DMA Control Register (DCR)
5128 * <15..14> 10 Priority mode = Alternating Tx/Rx
5129 * 01 Rx has priority
5130 * 00 Tx has priority
5132 * <13> 1 Enable Priority Preempt per DCR<15..14>
5133 * (WARNING DCR<11..10> must be 00 when this is 1)
5134 * 0 Choose activate channel per DCR<11..10>
5136 * <12> 0 Little Endian for Array/List
5137 * <11..10> 00 Both Channels can use each bus grant
5138 * <9..6> 0000 reserved
5139 * <5> 0 7 CLK - Minimum Bus Re-request Interval
5140 * <4> 0 1 = drive D/C and S/D pins
5141 * <3> 1 1 = Add one wait state to all DMA cycles.
5142 * <2> 0 1 = Strobe /UAS on every transfer.
5143 * <1..0> 11 Addr incrementing only affects LS24 bits
5145 * 0110 0000 0000 1011 = 0x600b
5148 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
5149 /* PCI adapter does not need DMA wait state */
5150 usc_OutDmaReg( info, DCR, 0xa00b );
5153 usc_OutDmaReg( info, DCR, 0x800b );
5156 /* Receive DMA mode Register (RDMR)
5158 * <15..14> 11 DMA mode = Linked List Buffer mode
5159 * <13> 1 RSBinA/L = store Rx status Block in Arrary/List entry
5160 * <12> 1 Clear count of List Entry after fetching
5161 * <11..10> 00 Address mode = Increment
5162 * <9> 1 Terminate Buffer on RxBound
5163 * <8> 0 Bus Width = 16bits
5164 * <7..0> ? status Bits (write as 0s)
5166 * 1111 0010 0000 0000 = 0xf200
5169 usc_OutDmaReg( info, RDMR, 0xf200 );
5172 /* Transmit DMA mode Register (TDMR)
5174 * <15..14> 11 DMA mode = Linked List Buffer mode
5175 * <13> 1 TCBinA/L = fetch Tx Control Block from List entry
5176 * <12> 1 Clear count of List Entry after fetching
5177 * <11..10> 00 Address mode = Increment
5178 * <9> 1 Terminate Buffer on end of frame
5179 * <8> 0 Bus Width = 16bits
5180 * <7..0> ? status Bits (Read Only so write as 0)
5182 * 1111 0010 0000 0000 = 0xf200
5185 usc_OutDmaReg( info, TDMR, 0xf200 );
5188 /* DMA Interrupt Control Register (DICR)
5190 * <15> 1 DMA Interrupt Enable
5191 * <14> 0 1 = Disable IEO from USC
5192 * <13> 0 1 = Don't provide vector during IntAck
5193 * <12> 1 1 = Include status in Vector
5194 * <10..2> 0 reserved, Must be 0s
5195 * <1> 0 1 = Rx DMA Interrupt Enabled
5196 * <0> 0 1 = Tx DMA Interrupt Enabled
5198 * 1001 0000 0000 0000 = 0x9000
5201 usc_OutDmaReg( info, DICR, 0x9000 );
5203 usc_InDmaReg( info, RDMR ); /* clear pending receive DMA IRQ bits */
5204 usc_InDmaReg( info, TDMR ); /* clear pending transmit DMA IRQ bits */
5205 usc_OutDmaReg( info, CDIR, 0x0303 ); /* clear IUS and Pending for Tx and Rx */
5207 /* Channel Control Register (CCR)
5209 * <15..14> 10 Use 32-bit Tx Control Blocks (TCBs)
5210 * <13> 0 Trigger Tx on SW Command Disabled
5211 * <12> 0 Flag Preamble Disabled
5212 * <11..10> 00 Preamble Length
5213 * <9..8> 00 Preamble Pattern
5214 * <7..6> 10 Use 32-bit Rx status Blocks (RSBs)
5215 * <5> 0 Trigger Rx on SW Command Disabled
5218 * 1000 0000 1000 0000 = 0x8080
5223 switch ( info->params.preamble_length ) {
5224 case HDLC_PREAMBLE_LENGTH_16BITS: RegValue |= BIT10; break;
5225 case HDLC_PREAMBLE_LENGTH_32BITS: RegValue |= BIT11; break;
5226 case HDLC_PREAMBLE_LENGTH_64BITS: RegValue |= BIT11 + BIT10; break;
5229 switch ( info->params.preamble ) {
5230 case HDLC_PREAMBLE_PATTERN_FLAGS: RegValue |= BIT8 + BIT12; break;
5231 case HDLC_PREAMBLE_PATTERN_ONES: RegValue |= BIT8; break;
5232 case HDLC_PREAMBLE_PATTERN_10: RegValue |= BIT9; break;
5233 case HDLC_PREAMBLE_PATTERN_01: RegValue |= BIT9 + BIT8; break;
5236 usc_OutReg( info, CCR, RegValue );
5240 * Burst/Dwell Control Register
5242 * <15..8> 0x20 Maximum number of transfers per bus grant
5243 * <7..0> 0x00 Maximum number of clock cycles per bus grant
5246 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
5247 /* don't limit bus occupancy on PCI adapter */
5248 usc_OutDmaReg( info, BDCR, 0x0000 );
5251 usc_OutDmaReg( info, BDCR, 0x2000 );
5253 usc_stop_transmitter(info);
5254 usc_stop_receiver(info);
5256 } /* end of usc_set_sdlc_mode() */
5258 /* usc_enable_loopback()
5260 * Set the 16C32 for internal loopback mode.
5261 * The TxCLK and RxCLK signals are generated from the BRG0 and
5262 * the TxD is looped back to the RxD internally.
5264 * Arguments: info pointer to device instance data
5265 * enable 1 = enable loopback, 0 = disable
5266 * Return Value: None
5268 static void usc_enable_loopback(struct mgsl_struct *info, int enable)
5271 /* blank external TXD output */
5272 usc_OutReg(info,IOCR,usc_InReg(info,IOCR) | (BIT7+BIT6));
5274 /* Clock mode Control Register (CMCR)
5276 * <15..14> 00 counter 1 Disabled
5277 * <13..12> 00 counter 0 Disabled
5278 * <11..10> 11 BRG1 Input is TxC Pin
5279 * <9..8> 11 BRG0 Input is TxC Pin
5280 * <7..6> 01 DPLL Input is BRG1 Output
5281 * <5..3> 100 TxCLK comes from BRG0
5282 * <2..0> 100 RxCLK comes from BRG0
5284 * 0000 1111 0110 0100 = 0x0f64
5287 usc_OutReg( info, CMCR, 0x0f64 );
5289 /* Write 16-bit Time Constant for BRG0 */
5290 /* use clock speed if available, otherwise use 8 for diagnostics */
5291 if (info->params.clock_speed) {
5292 if (info->bus_type == MGSL_BUS_TYPE_PCI)
5293 usc_OutReg(info, TC0R, (u16)((11059200/info->params.clock_speed)-1));
5295 usc_OutReg(info, TC0R, (u16)((14745600/info->params.clock_speed)-1));
5297 usc_OutReg(info, TC0R, (u16)8);
5299 /* Hardware Configuration Register (HCR) Clear Bit 1, BRG0
5300 mode = Continuous Set Bit 0 to enable BRG0. */
5301 usc_OutReg( info, HCR, (u16)((usc_InReg( info, HCR ) & ~BIT1) | BIT0) );
5303 /* Input/Output Control Reg, <2..0> = 100, Drive RxC pin with BRG0 */
5304 usc_OutReg(info, IOCR, (u16)((usc_InReg(info, IOCR) & 0xfff8) | 0x0004));
5306 /* set Internal Data loopback mode */
5307 info->loopback_bits = 0x300;
5308 outw( 0x0300, info->io_base + CCAR );
5310 /* enable external TXD output */
5311 usc_OutReg(info,IOCR,usc_InReg(info,IOCR) & ~(BIT7+BIT6));
5313 /* clear Internal Data loopback mode */
5314 info->loopback_bits = 0;
5315 outw( 0,info->io_base + CCAR );
5318 } /* end of usc_enable_loopback() */
5320 /* usc_enable_aux_clock()
5322 * Enabled the AUX clock output at the specified frequency.
5326 * info pointer to device extension
5327 * data_rate data rate of clock in bits per second
5328 * A data rate of 0 disables the AUX clock.
5330 * Return Value: None
5332 static void usc_enable_aux_clock( struct mgsl_struct *info, u32 data_rate )
5338 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
5339 XtalSpeed = 11059200;
5341 XtalSpeed = 14745600;
5344 /* Tc = (Xtal/Speed) - 1 */
5345 /* If twice the remainder of (Xtal/Speed) is greater than Speed */
5346 /* then rounding up gives a more precise time constant. Instead */
5347 /* of rounding up and then subtracting 1 we just don't subtract */
5348 /* the one in this case. */
5351 Tc = (u16)(XtalSpeed/data_rate);
5352 if ( !(((XtalSpeed % data_rate) * 2) / data_rate) )
5355 /* Write 16-bit Time Constant for BRG0 */
5356 usc_OutReg( info, TC0R, Tc );
5359 * Hardware Configuration Register (HCR)
5360 * Clear Bit 1, BRG0 mode = Continuous
5361 * Set Bit 0 to enable BRG0.
5364 usc_OutReg( info, HCR, (u16)((usc_InReg( info, HCR ) & ~BIT1) | BIT0) );
5366 /* Input/Output Control Reg, <2..0> = 100, Drive RxC pin with BRG0 */
5367 usc_OutReg( info, IOCR, (u16)((usc_InReg(info, IOCR) & 0xfff8) | 0x0004) );
5369 /* data rate == 0 so turn off BRG0 */
5370 usc_OutReg( info, HCR, (u16)(usc_InReg( info, HCR ) & ~BIT0) );
5373 } /* end of usc_enable_aux_clock() */
5377 * usc_process_rxoverrun_sync()
5379 * This function processes a receive overrun by resetting the
5380 * receive DMA buffers and issuing a Purge Rx FIFO command
5381 * to allow the receiver to continue receiving.
5385 * info pointer to device extension
5387 * Return Value: None
5389 static void usc_process_rxoverrun_sync( struct mgsl_struct *info )
5393 int frame_start_index;
5394 int start_of_frame_found = FALSE;
5395 int end_of_frame_found = FALSE;
5396 int reprogram_dma = FALSE;
5398 DMABUFFERENTRY *buffer_list = info->rx_buffer_list;
5401 usc_DmaCmd( info, DmaCmd_PauseRxChannel );
5402 usc_RCmd( info, RCmd_EnterHuntmode );
5403 usc_RTCmd( info, RTCmd_PurgeRxFifo );
5405 /* CurrentRxBuffer points to the 1st buffer of the next */
5406 /* possibly available receive frame. */
5408 frame_start_index = start_index = end_index = info->current_rx_buffer;
5410 /* Search for an unfinished string of buffers. This means */
5411 /* that a receive frame started (at least one buffer with */
5412 /* count set to zero) but there is no terminiting buffer */
5413 /* (status set to non-zero). */
5415 while( !buffer_list[end_index].count )
5417 /* Count field has been reset to zero by 16C32. */
5418 /* This buffer is currently in use. */
5420 if ( !start_of_frame_found )
5422 start_of_frame_found = TRUE;
5423 frame_start_index = end_index;
5424 end_of_frame_found = FALSE;
5427 if ( buffer_list[end_index].status )
5429 /* Status field has been set by 16C32. */
5430 /* This is the last buffer of a received frame. */
5432 /* We want to leave the buffers for this frame intact. */
5433 /* Move on to next possible frame. */
5435 start_of_frame_found = FALSE;
5436 end_of_frame_found = TRUE;
5439 /* advance to next buffer entry in linked list */
5441 if ( end_index == info->rx_buffer_count )
5444 if ( start_index == end_index )
5446 /* The entire list has been searched with all Counts == 0 and */
5447 /* all Status == 0. The receive buffers are */
5448 /* completely screwed, reset all receive buffers! */
5449 mgsl_reset_rx_dma_buffers( info );
5450 frame_start_index = 0;
5451 start_of_frame_found = FALSE;
5452 reprogram_dma = TRUE;
5457 if ( start_of_frame_found && !end_of_frame_found )
5459 /* There is an unfinished string of receive DMA buffers */
5460 /* as a result of the receiver overrun. */
5462 /* Reset the buffers for the unfinished frame */
5463 /* and reprogram the receive DMA controller to start */
5464 /* at the 1st buffer of unfinished frame. */
5466 start_index = frame_start_index;
5470 *((unsigned long *)&(info->rx_buffer_list[start_index++].count)) = DMABUFFERSIZE;
5472 /* Adjust index for wrap around. */
5473 if ( start_index == info->rx_buffer_count )
5476 } while( start_index != end_index );
5478 reprogram_dma = TRUE;
5481 if ( reprogram_dma )
5483 usc_UnlatchRxstatusBits(info,RXSTATUS_ALL);
5484 usc_ClearIrqPendingBits(info, RECEIVE_DATA|RECEIVE_STATUS);
5485 usc_UnlatchRxstatusBits(info, RECEIVE_DATA|RECEIVE_STATUS);
5487 usc_EnableReceiver(info,DISABLE_UNCONDITIONAL);
5489 /* This empties the receive FIFO and loads the RCC with RCLR */
5490 usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
5492 /* program 16C32 with physical address of 1st DMA buffer entry */
5493 phys_addr = info->rx_buffer_list[frame_start_index].phys_entry;
5494 usc_OutDmaReg( info, NRARL, (u16)phys_addr );
5495 usc_OutDmaReg( info, NRARU, (u16)(phys_addr >> 16) );
5497 usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
5498 usc_ClearIrqPendingBits( info, RECEIVE_DATA + RECEIVE_STATUS );
5499 usc_EnableInterrupts( info, RECEIVE_STATUS );
5501 /* 1. Arm End of Buffer (EOB) Receive DMA Interrupt (BIT2 of RDIAR) */
5502 /* 2. Enable Receive DMA Interrupts (BIT1 of DICR) */
5504 usc_OutDmaReg( info, RDIAR, BIT3 + BIT2 );
5505 usc_OutDmaReg( info, DICR, (u16)(usc_InDmaReg(info,DICR) | BIT1) );
5506 usc_DmaCmd( info, DmaCmd_InitRxChannel );
5507 if ( info->params.flags & HDLC_FLAG_AUTO_DCD )
5508 usc_EnableReceiver(info,ENABLE_AUTO_DCD);
5510 usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
5514 /* This empties the receive FIFO and loads the RCC with RCLR */
5515 usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
5516 usc_RTCmd( info, RTCmd_PurgeRxFifo );
5519 } /* end of usc_process_rxoverrun_sync() */
5521 /* usc_stop_receiver()
5523 * Disable USC receiver
5525 * Arguments: info pointer to device instance data
5526 * Return Value: None
5528 static void usc_stop_receiver( struct mgsl_struct *info )
5530 if (debug_level >= DEBUG_LEVEL_ISR)
5531 printk("%s(%d):usc_stop_receiver(%s)\n",
5532 __FILE__,__LINE__, info->device_name );
5534 /* Disable receive DMA channel. */
5535 /* This also disables receive DMA channel interrupts */
5536 usc_DmaCmd( info, DmaCmd_ResetRxChannel );
5538 usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
5539 usc_ClearIrqPendingBits( info, RECEIVE_DATA + RECEIVE_STATUS );
5540 usc_DisableInterrupts( info, RECEIVE_DATA + RECEIVE_STATUS );
5542 usc_EnableReceiver(info,DISABLE_UNCONDITIONAL);
5544 /* This empties the receive FIFO and loads the RCC with RCLR */
5545 usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
5546 usc_RTCmd( info, RTCmd_PurgeRxFifo );
5548 info->rx_enabled = 0;
5549 info->rx_overflow = 0;
5550 info->rx_rcc_underrun = 0;
5552 } /* end of stop_receiver() */
5554 /* usc_start_receiver()
5556 * Enable the USC receiver
5558 * Arguments: info pointer to device instance data
5559 * Return Value: None
5561 static void usc_start_receiver( struct mgsl_struct *info )
5565 if (debug_level >= DEBUG_LEVEL_ISR)
5566 printk("%s(%d):usc_start_receiver(%s)\n",
5567 __FILE__,__LINE__, info->device_name );
5569 mgsl_reset_rx_dma_buffers( info );
5570 usc_stop_receiver( info );
5572 usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
5573 usc_RTCmd( info, RTCmd_PurgeRxFifo );
5575 if ( info->params.mode == MGSL_MODE_HDLC ||
5576 info->params.mode == MGSL_MODE_RAW ) {
5577 /* DMA mode Transfers */
5578 /* Program the DMA controller. */
5579 /* Enable the DMA controller end of buffer interrupt. */
5581 /* program 16C32 with physical address of 1st DMA buffer entry */
5582 phys_addr = info->rx_buffer_list[0].phys_entry;
5583 usc_OutDmaReg( info, NRARL, (u16)phys_addr );
5584 usc_OutDmaReg( info, NRARU, (u16)(phys_addr >> 16) );
5586 usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
5587 usc_ClearIrqPendingBits( info, RECEIVE_DATA + RECEIVE_STATUS );
5588 usc_EnableInterrupts( info, RECEIVE_STATUS );
5590 /* 1. Arm End of Buffer (EOB) Receive DMA Interrupt (BIT2 of RDIAR) */
5591 /* 2. Enable Receive DMA Interrupts (BIT1 of DICR) */
5593 usc_OutDmaReg( info, RDIAR, BIT3 + BIT2 );
5594 usc_OutDmaReg( info, DICR, (u16)(usc_InDmaReg(info,DICR) | BIT1) );
5595 usc_DmaCmd( info, DmaCmd_InitRxChannel );
5596 if ( info->params.flags & HDLC_FLAG_AUTO_DCD )
5597 usc_EnableReceiver(info,ENABLE_AUTO_DCD);
5599 usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
5601 usc_UnlatchRxstatusBits(info, RXSTATUS_ALL);
5602 usc_ClearIrqPendingBits(info, RECEIVE_DATA + RECEIVE_STATUS);
5603 usc_EnableInterrupts(info, RECEIVE_DATA);
5605 usc_RTCmd( info, RTCmd_PurgeRxFifo );
5606 usc_RCmd( info, RCmd_EnterHuntmode );
5608 usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
5611 usc_OutReg( info, CCSR, 0x1020 );
5613 info->rx_enabled = 1;
5615 } /* end of usc_start_receiver() */
5617 /* usc_start_transmitter()
5619 * Enable the USC transmitter and send a transmit frame if
5620 * one is loaded in the DMA buffers.
5622 * Arguments: info pointer to device instance data
5623 * Return Value: None
5625 static void usc_start_transmitter( struct mgsl_struct *info )
5628 unsigned int FrameSize;
5630 if (debug_level >= DEBUG_LEVEL_ISR)
5631 printk("%s(%d):usc_start_transmitter(%s)\n",
5632 __FILE__,__LINE__, info->device_name );
5634 if ( info->xmit_cnt ) {
5636 /* If auto RTS enabled and RTS is inactive, then assert */
5637 /* RTS and set a flag indicating that the driver should */
5638 /* negate RTS when the transmission completes. */
5640 info->drop_rts_on_tx_done = 0;
5642 if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
5643 usc_get_serial_signals( info );
5644 if ( !(info->serial_signals & SerialSignal_RTS) ) {
5645 info->serial_signals |= SerialSignal_RTS;
5646 usc_set_serial_signals( info );
5647 info->drop_rts_on_tx_done = 1;
5652 if ( info->params.mode == MGSL_MODE_ASYNC ) {
5653 if ( !info->tx_active ) {
5654 usc_UnlatchTxstatusBits(info, TXSTATUS_ALL);
5655 usc_ClearIrqPendingBits(info, TRANSMIT_STATUS + TRANSMIT_DATA);
5656 usc_EnableInterrupts(info, TRANSMIT_DATA);
5657 usc_load_txfifo(info);
5660 /* Disable transmit DMA controller while programming. */
5661 usc_DmaCmd( info, DmaCmd_ResetTxChannel );
5663 /* Transmit DMA buffer is loaded, so program USC */
5664 /* to send the frame contained in the buffers. */
5666 FrameSize = info->tx_buffer_list[info->start_tx_dma_buffer].rcc;
5668 /* if operating in Raw sync mode, reset the rcc component
5669 * of the tx dma buffer entry, otherwise, the serial controller
5670 * will send a closing sync char after this count.
5672 if ( info->params.mode == MGSL_MODE_RAW )
5673 info->tx_buffer_list[info->start_tx_dma_buffer].rcc = 0;
5675 /* Program the Transmit Character Length Register (TCLR) */
5676 /* and clear FIFO (TCC is loaded with TCLR on FIFO clear) */
5677 usc_OutReg( info, TCLR, (u16)FrameSize );
5679 usc_RTCmd( info, RTCmd_PurgeTxFifo );
5681 /* Program the address of the 1st DMA Buffer Entry in linked list */
5682 phys_addr = info->tx_buffer_list[info->start_tx_dma_buffer].phys_entry;
5683 usc_OutDmaReg( info, NTARL, (u16)phys_addr );
5684 usc_OutDmaReg( info, NTARU, (u16)(phys_addr >> 16) );
5686 usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
5687 usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
5688 usc_EnableInterrupts( info, TRANSMIT_STATUS );
5690 if ( info->params.mode == MGSL_MODE_RAW &&
5691 info->num_tx_dma_buffers > 1 ) {
5692 /* When running external sync mode, attempt to 'stream' transmit */
5693 /* by filling tx dma buffers as they become available. To do this */
5694 /* we need to enable Tx DMA EOB Status interrupts : */
5696 /* 1. Arm End of Buffer (EOB) Transmit DMA Interrupt (BIT2 of TDIAR) */
5697 /* 2. Enable Transmit DMA Interrupts (BIT0 of DICR) */
5699 usc_OutDmaReg( info, TDIAR, BIT2|BIT3 );
5700 usc_OutDmaReg( info, DICR, (u16)(usc_InDmaReg(info,DICR) | BIT0) );
5703 /* Initialize Transmit DMA Channel */
5704 usc_DmaCmd( info, DmaCmd_InitTxChannel );
5706 usc_TCmd( info, TCmd_SendFrame );
5708 mod_timer(&info->tx_timer, jiffies +
5709 msecs_to_jiffies(5000));
5711 info->tx_active = 1;
5714 if ( !info->tx_enabled ) {
5715 info->tx_enabled = 1;
5716 if ( info->params.flags & HDLC_FLAG_AUTO_CTS )
5717 usc_EnableTransmitter(info,ENABLE_AUTO_CTS);
5719 usc_EnableTransmitter(info,ENABLE_UNCONDITIONAL);
5722 } /* end of usc_start_transmitter() */
5724 /* usc_stop_transmitter()
5726 * Stops the transmitter and DMA
5728 * Arguments: info pointer to device isntance data
5729 * Return Value: None
5731 static void usc_stop_transmitter( struct mgsl_struct *info )
5733 if (debug_level >= DEBUG_LEVEL_ISR)
5734 printk("%s(%d):usc_stop_transmitter(%s)\n",
5735 __FILE__,__LINE__, info->device_name );
5737 del_timer(&info->tx_timer);
5739 usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
5740 usc_ClearIrqPendingBits( info, TRANSMIT_STATUS + TRANSMIT_DATA );
5741 usc_DisableInterrupts( info, TRANSMIT_STATUS + TRANSMIT_DATA );
5743 usc_EnableTransmitter(info,DISABLE_UNCONDITIONAL);
5744 usc_DmaCmd( info, DmaCmd_ResetTxChannel );
5745 usc_RTCmd( info, RTCmd_PurgeTxFifo );
5747 info->tx_enabled = 0;
5748 info->tx_active = 0;
5750 } /* end of usc_stop_transmitter() */
5752 /* usc_load_txfifo()
5754 * Fill the transmit FIFO until the FIFO is full or
5755 * there is no more data to load.
5757 * Arguments: info pointer to device extension (instance data)
5758 * Return Value: None
5760 static void usc_load_txfifo( struct mgsl_struct *info )
5765 if ( !info->xmit_cnt && !info->x_char )
5768 /* Select transmit FIFO status readback in TICR */
5769 usc_TCmd( info, TCmd_SelectTicrTxFifostatus );
5771 /* load the Transmit FIFO until FIFOs full or all data sent */
5773 while( (Fifocount = usc_InReg(info, TICR) >> 8) && info->xmit_cnt ) {
5774 /* there is more space in the transmit FIFO and */
5775 /* there is more data in transmit buffer */
5777 if ( (info->xmit_cnt > 1) && (Fifocount > 1) && !info->x_char ) {
5778 /* write a 16-bit word from transmit buffer to 16C32 */
5780 TwoBytes[0] = info->xmit_buf[info->xmit_tail++];
5781 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
5782 TwoBytes[1] = info->xmit_buf[info->xmit_tail++];
5783 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
5785 outw( *((u16 *)TwoBytes), info->io_base + DATAREG);
5787 info->xmit_cnt -= 2;
5788 info->icount.tx += 2;
5790 /* only 1 byte left to transmit or 1 FIFO slot left */
5792 outw( (inw( info->io_base + CCAR) & 0x0780) | (TDR+LSBONLY),
5793 info->io_base + CCAR );
5796 /* transmit pending high priority char */
5797 outw( info->x_char,info->io_base + CCAR );
5800 outw( info->xmit_buf[info->xmit_tail++],info->io_base + CCAR );
5801 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
5808 } /* end of usc_load_txfifo() */
5812 * Reset the adapter to a known state and prepare it for further use.
5814 * Arguments: info pointer to device instance data
5815 * Return Value: None
5817 static void usc_reset( struct mgsl_struct *info )
5819 if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
5823 /* Set BIT30 of Misc Control Register */
5824 /* (Local Control Register 0x50) to force reset of USC. */
5826 volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
5827 u32 *LCR0BRDR = (u32 *)(info->lcr_base + 0x28);
5829 info->misc_ctrl_value |= BIT30;
5830 *MiscCtrl = info->misc_ctrl_value;
5833 * Force at least 170ns delay before clearing
5834 * reset bit. Each read from LCR takes at least
5835 * 30ns so 10 times for 300ns to be safe.
5838 readval = *MiscCtrl;
5840 info->misc_ctrl_value &= ~BIT30;
5841 *MiscCtrl = info->misc_ctrl_value;
5843 *LCR0BRDR = BUS_DESCRIPTOR(
5844 1, // Write Strobe Hold (0-3)
5845 2, // Write Strobe Delay (0-3)
5846 2, // Read Strobe Delay (0-3)
5847 0, // NWDD (Write data-data) (0-3)
5848 4, // NWAD (Write Addr-data) (0-31)
5849 0, // NXDA (Read/Write Data-Addr) (0-3)
5850 0, // NRDD (Read Data-Data) (0-3)
5851 5 // NRAD (Read Addr-Data) (0-31)
5855 outb( 0,info->io_base + 8 );
5859 info->loopback_bits = 0;
5860 info->usc_idle_mode = 0;
5863 * Program the Bus Configuration Register (BCR)
5865 * <15> 0 Don't use separate address
5866 * <14..6> 0 reserved
5867 * <5..4> 00 IAckmode = Default, don't care
5868 * <3> 1 Bus Request Totem Pole output
5869 * <2> 1 Use 16 Bit data bus
5870 * <1> 0 IRQ Totem Pole output
5871 * <0> 0 Don't Shift Right Addr
5873 * 0000 0000 0000 1100 = 0x000c
5875 * By writing to io_base + SDPIN the Wait/Ack pin is
5876 * programmed to work as a Wait pin.
5879 outw( 0x000c,info->io_base + SDPIN );
5882 outw( 0,info->io_base );
5883 outw( 0,info->io_base + CCAR );
5885 /* select little endian byte ordering */
5886 usc_RTCmd( info, RTCmd_SelectLittleEndian );
5889 /* Port Control Register (PCR)
5891 * <15..14> 11 Port 7 is Output (~DMAEN, Bit 14 : 0 = Enabled)
5892 * <13..12> 11 Port 6 is Output (~INTEN, Bit 12 : 0 = Enabled)
5893 * <11..10> 00 Port 5 is Input (No Connect, Don't Care)
5894 * <9..8> 00 Port 4 is Input (No Connect, Don't Care)
5895 * <7..6> 11 Port 3 is Output (~RTS, Bit 6 : 0 = Enabled )
5896 * <5..4> 11 Port 2 is Output (~DTR, Bit 4 : 0 = Enabled )
5897 * <3..2> 01 Port 1 is Input (Dedicated RxC)
5898 * <1..0> 01 Port 0 is Input (Dedicated TxC)
5900 * 1111 0000 1111 0101 = 0xf0f5
5903 usc_OutReg( info, PCR, 0xf0f5 );
5907 * Input/Output Control Register
5909 * <15..14> 00 CTS is active low input
5910 * <13..12> 00 DCD is active low input
5911 * <11..10> 00 TxREQ pin is input (DSR)
5912 * <9..8> 00 RxREQ pin is input (RI)
5913 * <7..6> 00 TxD is output (Transmit Data)
5914 * <5..3> 000 TxC Pin in Input (14.7456MHz Clock)
5915 * <2..0> 100 RxC is Output (drive with BRG0)
5917 * 0000 0000 0000 0100 = 0x0004
5920 usc_OutReg( info, IOCR, 0x0004 );
5922 } /* end of usc_reset() */
5924 /* usc_set_async_mode()
5926 * Program adapter for asynchronous communications.
5928 * Arguments: info pointer to device instance data
5929 * Return Value: None
5931 static void usc_set_async_mode( struct mgsl_struct *info )
5935 /* disable interrupts while programming USC */
5936 usc_DisableMasterIrqBit( info );
5938 outw( 0, info->io_base ); /* clear Master Bus Enable (DCAR) */
5939 usc_DmaCmd( info, DmaCmd_ResetAllChannels ); /* disable both DMA channels */
5941 usc_loopback_frame( info );
5943 /* Channel mode Register (CMR)
5945 * <15..14> 00 Tx Sub modes, 00 = 1 Stop Bit
5946 * <13..12> 00 00 = 16X Clock
5947 * <11..8> 0000 Transmitter mode = Asynchronous
5948 * <7..6> 00 reserved?
5949 * <5..4> 00 Rx Sub modes, 00 = 16X Clock
5950 * <3..0> 0000 Receiver mode = Asynchronous
5952 * 0000 0000 0000 0000 = 0x0
5956 if ( info->params.stop_bits != 1 )
5958 usc_OutReg( info, CMR, RegValue );
5961 /* Receiver mode Register (RMR)
5963 * <15..13> 000 encoding = None
5964 * <12..08> 00000 reserved (Sync Only)
5965 * <7..6> 00 Even parity
5966 * <5> 0 parity disabled
5967 * <4..2> 000 Receive Char Length = 8 bits
5968 * <1..0> 00 Disable Receiver
5970 * 0000 0000 0000 0000 = 0x0
5975 if ( info->params.data_bits != 8 )
5976 RegValue |= BIT4+BIT3+BIT2;
5978 if ( info->params.parity != ASYNC_PARITY_NONE ) {
5980 if ( info->params.parity != ASYNC_PARITY_ODD )
5984 usc_OutReg( info, RMR, RegValue );
5987 /* Set IRQ trigger level */
5989 usc_RCmd( info, RCmd_SelectRicrIntLevel );
5992 /* Receive Interrupt Control Register (RICR)
5994 * <15..8> ? RxFIFO IRQ Request Level
5996 * Note: For async mode the receive FIFO level must be set
5997 * to 0 to avoid the situation where the FIFO contains fewer bytes
5998 * than the trigger level and no more data is expected.
6000 * <7> 0 Exited Hunt IA (Interrupt Arm)
6001 * <6> 0 Idle Received IA
6002 * <5> 0 Break/Abort IA
6004 * <3> 0 Queued status reflects oldest byte in FIFO
6006 * <1> 0 Rx Overrun IA
6007 * <0> 0 Select TC0 value for readback
6009 * 0000 0000 0100 0000 = 0x0000 + (FIFOLEVEL in MSB)
6012 usc_OutReg( info, RICR, 0x0000 );
6014 usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
6015 usc_ClearIrqPendingBits( info, RECEIVE_STATUS );
6018 /* Transmit mode Register (TMR)
6020 * <15..13> 000 encoding = None
6021 * <12..08> 00000 reserved (Sync Only)
6022 * <7..6> 00 Transmit parity Even
6023 * <5> 0 Transmit parity Disabled
6024 * <4..2> 000 Tx Char Length = 8 bits
6025 * <1..0> 00 Disable Transmitter
6027 * 0000 0000 0000 0000 = 0x0
6032 if ( info->params.data_bits != 8 )
6033 RegValue |= BIT4+BIT3+BIT2;
6035 if ( info->params.parity != ASYNC_PARITY_NONE ) {
6037 if ( info->params.parity != ASYNC_PARITY_ODD )
6041 usc_OutReg( info, TMR, RegValue );
6043 usc_set_txidle( info );
6046 /* Set IRQ trigger level */
6048 usc_TCmd( info, TCmd_SelectTicrIntLevel );
6051 /* Transmit Interrupt Control Register (TICR)
6053 * <15..8> ? Transmit FIFO IRQ Level
6054 * <7> 0 Present IA (Interrupt Arm)
6055 * <6> 1 Idle Sent IA
6056 * <5> 0 Abort Sent IA
6057 * <4> 0 EOF/EOM Sent IA
6059 * <2> 0 1 = Wait for SW Trigger to Start Frame
6060 * <1> 0 Tx Underrun IA
6061 * <0> 0 TC0 constant on read back
6063 * 0000 0000 0100 0000 = 0x0040
6066 usc_OutReg( info, TICR, 0x1f40 );
6068 usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
6069 usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
6071 usc_enable_async_clock( info, info->params.data_rate );
6074 /* Channel Control/status Register (CCSR)
6076 * <15> X RCC FIFO Overflow status (RO)
6077 * <14> X RCC FIFO Not Empty status (RO)
6078 * <13> 0 1 = Clear RCC FIFO (WO)
6079 * <12> X DPLL in Sync status (RO)
6080 * <11> X DPLL 2 Missed Clocks status (RO)
6081 * <10> X DPLL 1 Missed Clock status (RO)
6082 * <9..8> 00 DPLL Resync on rising and falling edges (RW)
6083 * <7> X SDLC Loop On status (RO)
6084 * <6> X SDLC Loop Send status (RO)
6085 * <5> 1 Bypass counters for TxClk and RxClk (RW)
6086 * <4..2> 000 Last Char of SDLC frame has 8 bits (RW)
6087 * <1..0> 00 reserved
6089 * 0000 0000 0010 0000 = 0x0020
6092 usc_OutReg( info, CCSR, 0x0020 );
6094 usc_DisableInterrupts( info, TRANSMIT_STATUS + TRANSMIT_DATA +
6095 RECEIVE_DATA + RECEIVE_STATUS );
6097 usc_ClearIrqPendingBits( info, TRANSMIT_STATUS + TRANSMIT_DATA +
6098 RECEIVE_DATA + RECEIVE_STATUS );
6100 usc_EnableMasterIrqBit( info );
6102 if (info->bus_type == MGSL_BUS_TYPE_ISA) {
6103 /* Enable INTEN (Port 6, Bit12) */
6104 /* This connects the IRQ request signal to the ISA bus */
6105 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) & ~BIT12));
6108 if (info->params.loopback) {
6109 info->loopback_bits = 0x300;
6110 outw(0x0300, info->io_base + CCAR);
6113 } /* end of usc_set_async_mode() */
6115 /* usc_loopback_frame()
6117 * Loop back a small (2 byte) dummy SDLC frame.
6118 * Interrupts and DMA are NOT used. The purpose of this is to
6119 * clear any 'stale' status info left over from running in async mode.
6121 * The 16C32 shows the strange behaviour of marking the 1st
6122 * received SDLC frame with a CRC error even when there is no
6123 * CRC error. To get around this a small dummy from of 2 bytes
6124 * is looped back when switching from async to sync mode.
6126 * Arguments: info pointer to device instance data
6127 * Return Value: None
6129 static void usc_loopback_frame( struct mgsl_struct *info )
6132 unsigned long oldmode = info->params.mode;
6134 info->params.mode = MGSL_MODE_HDLC;
6136 usc_DisableMasterIrqBit( info );
6138 usc_set_sdlc_mode( info );
6139 usc_enable_loopback( info, 1 );
6141 /* Write 16-bit Time Constant for BRG0 */
6142 usc_OutReg( info, TC0R, 0 );
6144 /* Channel Control Register (CCR)
6146 * <15..14> 00 Don't use 32-bit Tx Control Blocks (TCBs)
6147 * <13> 0 Trigger Tx on SW Command Disabled
6148 * <12> 0 Flag Preamble Disabled
6149 * <11..10> 00 Preamble Length = 8-Bits
6150 * <9..8> 01 Preamble Pattern = flags
6151 * <7..6> 10 Don't use 32-bit Rx status Blocks (RSBs)
6152 * <5> 0 Trigger Rx on SW Command Disabled
6155 * 0000 0001 0000 0000 = 0x0100
6158 usc_OutReg( info, CCR, 0x0100 );
6160 /* SETUP RECEIVER */
6161 usc_RTCmd( info, RTCmd_PurgeRxFifo );
6162 usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
6164 /* SETUP TRANSMITTER */
6165 /* Program the Transmit Character Length Register (TCLR) */
6166 /* and clear FIFO (TCC is loaded with TCLR on FIFO clear) */
6167 usc_OutReg( info, TCLR, 2 );
6168 usc_RTCmd( info, RTCmd_PurgeTxFifo );
6170 /* unlatch Tx status bits, and start transmit channel. */
6171 usc_UnlatchTxstatusBits(info,TXSTATUS_ALL);
6172 outw(0,info->io_base + DATAREG);
6174 /* ENABLE TRANSMITTER */
6175 usc_TCmd( info, TCmd_SendFrame );
6176 usc_EnableTransmitter(info,ENABLE_UNCONDITIONAL);
6178 /* WAIT FOR RECEIVE COMPLETE */
6179 for (i=0 ; i<1000 ; i++)
6180 if (usc_InReg( info, RCSR ) & (BIT8 + BIT4 + BIT3 + BIT1))
6183 /* clear Internal Data loopback mode */
6184 usc_enable_loopback(info, 0);
6186 usc_EnableMasterIrqBit(info);
6188 info->params.mode = oldmode;
6190 } /* end of usc_loopback_frame() */
6192 /* usc_set_sync_mode() Programs the USC for SDLC communications.
6194 * Arguments: info pointer to adapter info structure
6195 * Return Value: None
6197 static void usc_set_sync_mode( struct mgsl_struct *info )
6199 usc_loopback_frame( info );
6200 usc_set_sdlc_mode( info );
6202 if (info->bus_type == MGSL_BUS_TYPE_ISA) {
6203 /* Enable INTEN (Port 6, Bit12) */
6204 /* This connects the IRQ request signal to the ISA bus */
6205 usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) & ~BIT12));
6208 usc_enable_aux_clock(info, info->params.clock_speed);
6210 if (info->params.loopback)
6211 usc_enable_loopback(info,1);
6213 } /* end of mgsl_set_sync_mode() */
6215 /* usc_set_txidle() Set the HDLC idle mode for the transmitter.
6217 * Arguments: info pointer to device instance data
6218 * Return Value: None
6220 static void usc_set_txidle( struct mgsl_struct *info )
6222 u16 usc_idle_mode = IDLEMODE_FLAGS;
6224 /* Map API idle mode to USC register bits */
6226 switch( info->idle_mode ){
6227 case HDLC_TXIDLE_FLAGS: usc_idle_mode = IDLEMODE_FLAGS; break;
6228 case HDLC_TXIDLE_ALT_ZEROS_ONES: usc_idle_mode = IDLEMODE_ALT_ONE_ZERO; break;
6229 case HDLC_TXIDLE_ZEROS: usc_idle_mode = IDLEMODE_ZERO; break;
6230 case HDLC_TXIDLE_ONES: usc_idle_mode = IDLEMODE_ONE; break;
6231 case HDLC_TXIDLE_ALT_MARK_SPACE: usc_idle_mode = IDLEMODE_ALT_MARK_SPACE; break;
6232 case HDLC_TXIDLE_SPACE: usc_idle_mode = IDLEMODE_SPACE; break;
6233 case HDLC_TXIDLE_MARK: usc_idle_mode = IDLEMODE_MARK; break;
6236 info->usc_idle_mode = usc_idle_mode;
6237 //usc_OutReg(info, TCSR, usc_idle_mode);
6238 info->tcsr_value &= ~IDLEMODE_MASK; /* clear idle mode bits */
6239 info->tcsr_value += usc_idle_mode;
6240 usc_OutReg(info, TCSR, info->tcsr_value);
6243 * if SyncLink WAN adapter is running in external sync mode, the
6244 * transmitter has been set to Monosync in order to try to mimic
6245 * a true raw outbound bit stream. Monosync still sends an open/close
6246 * sync char at the start/end of a frame. Try to match those sync
6247 * patterns to the idle mode set here
6249 if ( info->params.mode == MGSL_MODE_RAW ) {
6250 unsigned char syncpat = 0;
6251 switch( info->idle_mode ) {
6252 case HDLC_TXIDLE_FLAGS:
6255 case HDLC_TXIDLE_ALT_ZEROS_ONES:
6258 case HDLC_TXIDLE_ZEROS:
6259 case HDLC_TXIDLE_SPACE:
6262 case HDLC_TXIDLE_ONES:
6263 case HDLC_TXIDLE_MARK:
6266 case HDLC_TXIDLE_ALT_MARK_SPACE:
6271 usc_SetTransmitSyncChars(info,syncpat,syncpat);
6274 } /* end of usc_set_txidle() */
6276 /* usc_get_serial_signals()
6278 * Query the adapter for the state of the V24 status (input) signals.
6280 * Arguments: info pointer to device instance data
6281 * Return Value: None
6283 static void usc_get_serial_signals( struct mgsl_struct *info )
6287 /* clear all serial signals except DTR and RTS */
6288 info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
6290 /* Read the Misc Interrupt status Register (MISR) to get */
6291 /* the V24 status signals. */
6293 status = usc_InReg( info, MISR );
6295 /* set serial signal bits to reflect MISR */
6297 if ( status & MISCSTATUS_CTS )
6298 info->serial_signals |= SerialSignal_CTS;
6300 if ( status & MISCSTATUS_DCD )
6301 info->serial_signals |= SerialSignal_DCD;
6303 if ( status & MISCSTATUS_RI )
6304 info->serial_signals |= SerialSignal_RI;
6306 if ( status & MISCSTATUS_DSR )
6307 info->serial_signals |= SerialSignal_DSR;
6309 } /* end of usc_get_serial_signals() */
6311 /* usc_set_serial_signals()
6313 * Set the state of DTR and RTS based on contents of
6314 * serial_signals member of device extension.
6316 * Arguments: info pointer to device instance data
6317 * Return Value: None
6319 static void usc_set_serial_signals( struct mgsl_struct *info )
6322 unsigned char V24Out = info->serial_signals;
6324 /* get the current value of the Port Control Register (PCR) */
6326 Control = usc_InReg( info, PCR );
6328 if ( V24Out & SerialSignal_RTS )
6333 if ( V24Out & SerialSignal_DTR )
6338 usc_OutReg( info, PCR, Control );
6340 } /* end of usc_set_serial_signals() */
6342 /* usc_enable_async_clock()
6344 * Enable the async clock at the specified frequency.
6346 * Arguments: info pointer to device instance data
6347 * data_rate data rate of clock in bps
6348 * 0 disables the AUX clock.
6349 * Return Value: None
6351 static void usc_enable_async_clock( struct mgsl_struct *info, u32 data_rate )
6355 * Clock mode Control Register (CMCR)
6357 * <15..14> 00 counter 1 Disabled
6358 * <13..12> 00 counter 0 Disabled
6359 * <11..10> 11 BRG1 Input is TxC Pin
6360 * <9..8> 11 BRG0 Input is TxC Pin
6361 * <7..6> 01 DPLL Input is BRG1 Output
6362 * <5..3> 100 TxCLK comes from BRG0
6363 * <2..0> 100 RxCLK comes from BRG0
6365 * 0000 1111 0110 0100 = 0x0f64
6368 usc_OutReg( info, CMCR, 0x0f64 );
6372 * Write 16-bit Time Constant for BRG0
6373 * Time Constant = (ClkSpeed / data_rate) - 1
6374 * ClkSpeed = 921600 (ISA), 691200 (PCI)
6377 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
6378 usc_OutReg( info, TC0R, (u16)((691200/data_rate) - 1) );
6380 usc_OutReg( info, TC0R, (u16)((921600/data_rate) - 1) );
6384 * Hardware Configuration Register (HCR)
6385 * Clear Bit 1, BRG0 mode = Continuous
6386 * Set Bit 0 to enable BRG0.
6389 usc_OutReg( info, HCR,
6390 (u16)((usc_InReg( info, HCR ) & ~BIT1) | BIT0) );
6393 /* Input/Output Control Reg, <2..0> = 100, Drive RxC pin with BRG0 */
6395 usc_OutReg( info, IOCR,
6396 (u16)((usc_InReg(info, IOCR) & 0xfff8) | 0x0004) );
6398 /* data rate == 0 so turn off BRG0 */
6399 usc_OutReg( info, HCR, (u16)(usc_InReg( info, HCR ) & ~BIT0) );
6402 } /* end of usc_enable_async_clock() */
6405 * Buffer Structures:
6407 * Normal memory access uses virtual addresses that can make discontiguous
6408 * physical memory pages appear to be contiguous in the virtual address
6409 * space (the processors memory mapping handles the conversions).
6411 * DMA transfers require physically contiguous memory. This is because
6412 * the DMA system controller and DMA bus masters deal with memory using
6413 * only physical addresses.
6415 * This causes a problem under Windows NT when large DMA buffers are
6416 * needed. Fragmentation of the nonpaged pool prevents allocations of
6417 * physically contiguous buffers larger than the PAGE_SIZE.
6419 * However the 16C32 supports Bus Master Scatter/Gather DMA which
6420 * allows DMA transfers to physically discontiguous buffers. Information
6421 * about each data transfer buffer is contained in a memory structure
6422 * called a 'buffer entry'. A list of buffer entries is maintained
6423 * to track and control the use of the data transfer buffers.
6425 * To support this strategy we will allocate sufficient PAGE_SIZE
6426 * contiguous memory buffers to allow for the total required buffer
6429 * The 16C32 accesses the list of buffer entries using Bus Master
6430 * DMA. Control information is read from the buffer entries by the
6431 * 16C32 to control data transfers. status information is written to
6432 * the buffer entries by the 16C32 to indicate the status of completed
6435 * The CPU writes control information to the buffer entries to control
6436 * the 16C32 and reads status information from the buffer entries to
6437 * determine information about received and transmitted frames.
6439 * Because the CPU and 16C32 (adapter) both need simultaneous access
6440 * to the buffer entries, the buffer entry memory is allocated with
6441 * HalAllocateCommonBuffer(). This restricts the size of the buffer
6442 * entry list to PAGE_SIZE.
6444 * The actual data buffers on the other hand will only be accessed
6445 * by the CPU or the adapter but not by both simultaneously. This allows
6446 * Scatter/Gather packet based DMA procedures for using physically
6447 * discontiguous pages.
6451 * mgsl_reset_tx_dma_buffers()
6453 * Set the count for all transmit buffers to 0 to indicate the
6454 * buffer is available for use and set the current buffer to the
6455 * first buffer. This effectively makes all buffers free and
6456 * discards any data in buffers.
6458 * Arguments: info pointer to device instance data
6459 * Return Value: None
6461 static void mgsl_reset_tx_dma_buffers( struct mgsl_struct *info )
6465 for ( i = 0; i < info->tx_buffer_count; i++ ) {
6466 *((unsigned long *)&(info->tx_buffer_list[i].count)) = 0;
6469 info->current_tx_buffer = 0;
6470 info->start_tx_dma_buffer = 0;
6471 info->tx_dma_buffers_used = 0;
6473 info->get_tx_holding_index = 0;
6474 info->put_tx_holding_index = 0;
6475 info->tx_holding_count = 0;
6477 } /* end of mgsl_reset_tx_dma_buffers() */
6480 * num_free_tx_dma_buffers()
6482 * returns the number of free tx dma buffers available
6484 * Arguments: info pointer to device instance data
6485 * Return Value: number of free tx dma buffers
6487 static int num_free_tx_dma_buffers(struct mgsl_struct *info)
6489 return info->tx_buffer_count - info->tx_dma_buffers_used;
6493 * mgsl_reset_rx_dma_buffers()
6495 * Set the count for all receive buffers to DMABUFFERSIZE
6496 * and set the current buffer to the first buffer. This effectively
6497 * makes all buffers free and discards any data in buffers.
6499 * Arguments: info pointer to device instance data
6500 * Return Value: None
6502 static void mgsl_reset_rx_dma_buffers( struct mgsl_struct *info )
6506 for ( i = 0; i < info->rx_buffer_count; i++ ) {
6507 *((unsigned long *)&(info->rx_buffer_list[i].count)) = DMABUFFERSIZE;
6508 // info->rx_buffer_list[i].count = DMABUFFERSIZE;
6509 // info->rx_buffer_list[i].status = 0;
6512 info->current_rx_buffer = 0;
6514 } /* end of mgsl_reset_rx_dma_buffers() */
6517 * mgsl_free_rx_frame_buffers()
6519 * Free the receive buffers used by a received SDLC
6520 * frame such that the buffers can be reused.
6524 * info pointer to device instance data
6525 * StartIndex index of 1st receive buffer of frame
6526 * EndIndex index of last receive buffer of frame
6528 * Return Value: None
6530 static void mgsl_free_rx_frame_buffers( struct mgsl_struct *info, unsigned int StartIndex, unsigned int EndIndex )
6533 DMABUFFERENTRY *pBufEntry;
6536 /* Starting with 1st buffer entry of the frame clear the status */
6537 /* field and set the count field to DMA Buffer Size. */
6542 pBufEntry = &(info->rx_buffer_list[Index]);
6544 if ( Index == EndIndex ) {
6545 /* This is the last buffer of the frame! */
6549 /* reset current buffer for reuse */
6550 // pBufEntry->status = 0;
6551 // pBufEntry->count = DMABUFFERSIZE;
6552 *((unsigned long *)&(pBufEntry->count)) = DMABUFFERSIZE;
6554 /* advance to next buffer entry in linked list */
6556 if ( Index == info->rx_buffer_count )
6560 /* set current buffer to next buffer after last buffer of frame */
6561 info->current_rx_buffer = Index;
6563 } /* end of free_rx_frame_buffers() */
6565 /* mgsl_get_rx_frame()
6567 * This function attempts to return a received SDLC frame from the
6568 * receive DMA buffers. Only frames received without errors are returned.
6570 * Arguments: info pointer to device extension
6571 * Return Value: 1 if frame returned, otherwise 0
6573 static int mgsl_get_rx_frame(struct mgsl_struct *info)
6575 unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
6576 unsigned short status;
6577 DMABUFFERENTRY *pBufEntry;
6578 unsigned int framesize = 0;
6580 unsigned long flags;
6581 struct tty_struct *tty = info->tty;
6582 int return_frame = 0;
6585 * current_rx_buffer points to the 1st buffer of the next available
6586 * receive frame. To find the last buffer of the frame look for
6587 * a non-zero status field in the buffer entries. (The status
6588 * field is set by the 16C32 after completing a receive frame.
6591 StartIndex = EndIndex = info->current_rx_buffer;
6593 while( !info->rx_buffer_list[EndIndex].status ) {
6595 * If the count field of the buffer entry is non-zero then
6596 * this buffer has not been used. (The 16C32 clears the count
6597 * field when it starts using the buffer.) If an unused buffer
6598 * is encountered then there are no frames available.
6601 if ( info->rx_buffer_list[EndIndex].count )
6604 /* advance to next buffer entry in linked list */
6606 if ( EndIndex == info->rx_buffer_count )
6609 /* if entire list searched then no frame available */
6610 if ( EndIndex == StartIndex ) {
6611 /* If this occurs then something bad happened,
6612 * all buffers have been 'used' but none mark
6613 * the end of a frame. Reset buffers and receiver.
6616 if ( info->rx_enabled ){
6617 spin_lock_irqsave(&info->irq_spinlock,flags);
6618 usc_start_receiver(info);
6619 spin_unlock_irqrestore(&info->irq_spinlock,flags);
6626 /* check status of receive frame */
6628 status = info->rx_buffer_list[EndIndex].status;
6630 if ( status & (RXSTATUS_SHORT_FRAME + RXSTATUS_OVERRUN +
6631 RXSTATUS_CRC_ERROR + RXSTATUS_ABORT) ) {
6632 if ( status & RXSTATUS_SHORT_FRAME )
6633 info->icount.rxshort++;
6634 else if ( status & RXSTATUS_ABORT )
6635 info->icount.rxabort++;
6636 else if ( status & RXSTATUS_OVERRUN )
6637 info->icount.rxover++;
6639 info->icount.rxcrc++;
6640 if ( info->params.crc_type & HDLC_CRC_RETURN_EX )
6644 #if SYNCLINK_GENERIC_HDLC
6646 struct net_device_stats *stats = hdlc_stats(info->netdev);
6648 stats->rx_frame_errors++;
6654 if ( return_frame ) {
6655 /* receive frame has no errors, get frame size.
6656 * The frame size is the starting value of the RCC (which was
6657 * set to 0xffff) minus the ending value of the RCC (decremented
6658 * once for each receive character) minus 2 for the 16-bit CRC.
6661 framesize = RCLRVALUE - info->rx_buffer_list[EndIndex].rcc;
6663 /* adjust frame size for CRC if any */
6664 if ( info->params.crc_type == HDLC_CRC_16_CCITT )
6666 else if ( info->params.crc_type == HDLC_CRC_32_CCITT )
6670 if ( debug_level >= DEBUG_LEVEL_BH )
6671 printk("%s(%d):mgsl_get_rx_frame(%s) status=%04X size=%d\n",
6672 __FILE__,__LINE__,info->device_name,status,framesize);
6674 if ( debug_level >= DEBUG_LEVEL_DATA )
6675 mgsl_trace_block(info,info->rx_buffer_list[StartIndex].virt_addr,
6676 min_t(int, framesize, DMABUFFERSIZE),0);
6679 if ( ( (info->params.crc_type & HDLC_CRC_RETURN_EX) &&
6680 ((framesize+1) > info->max_frame_size) ) ||
6681 (framesize > info->max_frame_size) )
6682 info->icount.rxlong++;
6684 /* copy dma buffer(s) to contiguous intermediate buffer */
6685 int copy_count = framesize;
6686 int index = StartIndex;
6687 unsigned char *ptmp = info->intermediate_rxbuffer;
6689 if ( !(status & RXSTATUS_CRC_ERROR))
6690 info->icount.rxok++;
6694 if ( copy_count > DMABUFFERSIZE )
6695 partial_count = DMABUFFERSIZE;
6697 partial_count = copy_count;
6699 pBufEntry = &(info->rx_buffer_list[index]);
6700 memcpy( ptmp, pBufEntry->virt_addr, partial_count );
6701 ptmp += partial_count;
6702 copy_count -= partial_count;
6704 if ( ++index == info->rx_buffer_count )
6708 if ( info->params.crc_type & HDLC_CRC_RETURN_EX ) {
6710 *ptmp = (status & RXSTATUS_CRC_ERROR ?
6714 if ( debug_level >= DEBUG_LEVEL_DATA )
6715 printk("%s(%d):mgsl_get_rx_frame(%s) rx frame status=%d\n",
6716 __FILE__,__LINE__,info->device_name,
6720 #if SYNCLINK_GENERIC_HDLC
6722 hdlcdev_rx(info,info->intermediate_rxbuffer,framesize);
6725 ldisc_receive_buf(tty, info->intermediate_rxbuffer, info->flag_buf, framesize);
6728 /* Free the buffers used by this frame. */
6729 mgsl_free_rx_frame_buffers( info, StartIndex, EndIndex );
6735 if ( info->rx_enabled && info->rx_overflow ) {
6736 /* The receiver needs to restarted because of
6737 * a receive overflow (buffer or FIFO). If the
6738 * receive buffers are now empty, then restart receiver.
6741 if ( !info->rx_buffer_list[EndIndex].status &&
6742 info->rx_buffer_list[EndIndex].count ) {
6743 spin_lock_irqsave(&info->irq_spinlock,flags);
6744 usc_start_receiver(info);
6745 spin_unlock_irqrestore(&info->irq_spinlock,flags);
6751 } /* end of mgsl_get_rx_frame() */
6753 /* mgsl_get_raw_rx_frame()
6755 * This function attempts to return a received frame from the
6756 * receive DMA buffers when running in external loop mode. In this mode,
6757 * we will return at most one DMABUFFERSIZE frame to the application.
6758 * The USC receiver is triggering off of DCD going active to start a new
6759 * frame, and DCD going inactive to terminate the frame (similar to
6760 * processing a closing flag character).
6762 * In this routine, we will return DMABUFFERSIZE "chunks" at a time.
6763 * If DCD goes inactive, the last Rx DMA Buffer will have a non-zero
6764 * status field and the RCC field will indicate the length of the
6765 * entire received frame. We take this RCC field and get the modulus
6766 * of RCC and DMABUFFERSIZE to determine if number of bytes in the
6767 * last Rx DMA buffer and return that last portion of the frame.
6769 * Arguments: info pointer to device extension
6770 * Return Value: 1 if frame returned, otherwise 0
6772 static int mgsl_get_raw_rx_frame(struct mgsl_struct *info)
6774 unsigned int CurrentIndex, NextIndex;
6775 unsigned short status;
6776 DMABUFFERENTRY *pBufEntry;
6777 unsigned int framesize = 0;
6779 unsigned long flags;
6780 struct tty_struct *tty = info->tty;
6783 * current_rx_buffer points to the 1st buffer of the next available
6784 * receive frame. The status field is set by the 16C32 after
6785 * completing a receive frame. If the status field of this buffer
6786 * is zero, either the USC is still filling this buffer or this
6787 * is one of a series of buffers making up a received frame.
6789 * If the count field of this buffer is zero, the USC is either
6790 * using this buffer or has used this buffer. Look at the count
6791 * field of the next buffer. If that next buffer's count is
6792 * non-zero, the USC is still actively using the current buffer.
6793 * Otherwise, if the next buffer's count field is zero, the
6794 * current buffer is complete and the USC is using the next
6797 CurrentIndex = NextIndex = info->current_rx_buffer;
6799 if ( NextIndex == info->rx_buffer_count )
6802 if ( info->rx_buffer_list[CurrentIndex].status != 0 ||
6803 (info->rx_buffer_list[CurrentIndex].count == 0 &&
6804 info->rx_buffer_list[NextIndex].count == 0)) {
6806 * Either the status field of this dma buffer is non-zero
6807 * (indicating the last buffer of a receive frame) or the next
6808 * buffer is marked as in use -- implying this buffer is complete
6809 * and an intermediate buffer for this received frame.
6812 status = info->rx_buffer_list[CurrentIndex].status;
6814 if ( status & (RXSTATUS_SHORT_FRAME + RXSTATUS_OVERRUN +
6815 RXSTATUS_CRC_ERROR + RXSTATUS_ABORT) ) {
6816 if ( status & RXSTATUS_SHORT_FRAME )
6817 info->icount.rxshort++;
6818 else if ( status & RXSTATUS_ABORT )
6819 info->icount.rxabort++;
6820 else if ( status & RXSTATUS_OVERRUN )
6821 info->icount.rxover++;
6823 info->icount.rxcrc++;
6827 * A receive frame is available, get frame size and status.
6829 * The frame size is the starting value of the RCC (which was
6830 * set to 0xffff) minus the ending value of the RCC (decremented
6831 * once for each receive character) minus 2 or 4 for the 16-bit
6834 * If the status field is zero, this is an intermediate buffer.
6837 * If the DMA Buffer Entry's Status field is non-zero, the
6838 * receive operation completed normally (ie: DCD dropped). The
6839 * RCC field is valid and holds the received frame size.
6840 * It is possible that the RCC field will be zero on a DMA buffer
6841 * entry with a non-zero status. This can occur if the total
6842 * frame size (number of bytes between the time DCD goes active
6843 * to the time DCD goes inactive) exceeds 65535 bytes. In this
6844 * case the 16C32 has underrun on the RCC count and appears to
6845 * stop updating this counter to let us know the actual received
6846 * frame size. If this happens (non-zero status and zero RCC),
6847 * simply return the entire RxDMA Buffer
6851 * In the event that the final RxDMA Buffer is
6852 * terminated with a non-zero status and the RCC
6853 * field is zero, we interpret this as the RCC
6854 * having underflowed (received frame > 65535 bytes).
6856 * Signal the event to the user by passing back
6857 * a status of RxStatus_CrcError returning the full
6858 * buffer and let the app figure out what data is
6861 if ( info->rx_buffer_list[CurrentIndex].rcc )
6862 framesize = RCLRVALUE - info->rx_buffer_list[CurrentIndex].rcc;
6864 framesize = DMABUFFERSIZE;
6867 framesize = DMABUFFERSIZE;
6870 if ( framesize > DMABUFFERSIZE ) {
6872 * if running in raw sync mode, ISR handler for
6873 * End Of Buffer events terminates all buffers at 4K.
6874 * If this frame size is said to be >4K, get the
6875 * actual number of bytes of the frame in this buffer.
6877 framesize = framesize % DMABUFFERSIZE;
6881 if ( debug_level >= DEBUG_LEVEL_BH )
6882 printk("%s(%d):mgsl_get_raw_rx_frame(%s) status=%04X size=%d\n",
6883 __FILE__,__LINE__,info->device_name,status,framesize);
6885 if ( debug_level >= DEBUG_LEVEL_DATA )
6886 mgsl_trace_block(info,info->rx_buffer_list[CurrentIndex].virt_addr,
6887 min_t(int, framesize, DMABUFFERSIZE),0);
6890 /* copy dma buffer(s) to contiguous intermediate buffer */
6891 /* NOTE: we never copy more than DMABUFFERSIZE bytes */
6893 pBufEntry = &(info->rx_buffer_list[CurrentIndex]);
6894 memcpy( info->intermediate_rxbuffer, pBufEntry->virt_addr, framesize);
6895 info->icount.rxok++;
6897 ldisc_receive_buf(tty, info->intermediate_rxbuffer, info->flag_buf, framesize);
6900 /* Free the buffers used by this frame. */
6901 mgsl_free_rx_frame_buffers( info, CurrentIndex, CurrentIndex );
6907 if ( info->rx_enabled && info->rx_overflow ) {
6908 /* The receiver needs to restarted because of
6909 * a receive overflow (buffer or FIFO). If the
6910 * receive buffers are now empty, then restart receiver.
6913 if ( !info->rx_buffer_list[CurrentIndex].status &&
6914 info->rx_buffer_list[CurrentIndex].count ) {
6915 spin_lock_irqsave(&info->irq_spinlock,flags);
6916 usc_start_receiver(info);
6917 spin_unlock_irqrestore(&info->irq_spinlock,flags);
6923 } /* end of mgsl_get_raw_rx_frame() */
6925 /* mgsl_load_tx_dma_buffer()
6927 * Load the transmit DMA buffer with the specified data.
6931 * info pointer to device extension
6932 * Buffer pointer to buffer containing frame to load
6933 * BufferSize size in bytes of frame in Buffer
6935 * Return Value: None
6937 static void mgsl_load_tx_dma_buffer(struct mgsl_struct *info,
6938 const char *Buffer, unsigned int BufferSize)
6940 unsigned short Copycount;
6942 DMABUFFERENTRY *pBufEntry;
6944 if ( debug_level >= DEBUG_LEVEL_DATA )
6945 mgsl_trace_block(info,Buffer, min_t(int, BufferSize, DMABUFFERSIZE), 1);
6947 if (info->params.flags & HDLC_FLAG_HDLC_LOOPMODE) {
6948 /* set CMR:13 to start transmit when
6949 * next GoAhead (abort) is received
6951 info->cmr_value |= BIT13;
6954 /* begin loading the frame in the next available tx dma
6955 * buffer, remember it's starting location for setting
6956 * up tx dma operation
6958 i = info->current_tx_buffer;
6959 info->start_tx_dma_buffer = i;
6961 /* Setup the status and RCC (Frame Size) fields of the 1st */
6962 /* buffer entry in the transmit DMA buffer list. */
6964 info->tx_buffer_list[i].status = info->cmr_value & 0xf000;
6965 info->tx_buffer_list[i].rcc = BufferSize;
6966 info->tx_buffer_list[i].count = BufferSize;
6968 /* Copy frame data from 1st source buffer to the DMA buffers. */
6969 /* The frame data may span multiple DMA buffers. */
6971 while( BufferSize ){
6972 /* Get a pointer to next DMA buffer entry. */
6973 pBufEntry = &info->tx_buffer_list[i++];
6975 if ( i == info->tx_buffer_count )
6978 /* Calculate the number of bytes that can be copied from */
6979 /* the source buffer to this DMA buffer. */
6980 if ( BufferSize > DMABUFFERSIZE )
6981 Copycount = DMABUFFERSIZE;
6983 Copycount = BufferSize;
6985 /* Actually copy data from source buffer to DMA buffer. */
6986 /* Also set the data count for this individual DMA buffer. */
6987 if ( info->bus_type == MGSL_BUS_TYPE_PCI )
6988 mgsl_load_pci_memory(pBufEntry->virt_addr, Buffer,Copycount);
6990 memcpy(pBufEntry->virt_addr, Buffer, Copycount);
6992 pBufEntry->count = Copycount;
6994 /* Advance source pointer and reduce remaining data count. */
6995 Buffer += Copycount;
6996 BufferSize -= Copycount;
6998 ++info->tx_dma_buffers_used;
7001 /* remember next available tx dma buffer */
7002 info->current_tx_buffer = i;
7004 } /* end of mgsl_load_tx_dma_buffer() */
7007 * mgsl_register_test()
7009 * Performs a register test of the 16C32.
7011 * Arguments: info pointer to device instance data
7012 * Return Value: TRUE if test passed, otherwise FALSE
7014 static BOOLEAN mgsl_register_test( struct mgsl_struct *info )
7016 static unsigned short BitPatterns[] =
7017 { 0x0000, 0xffff, 0xaaaa, 0x5555, 0x1234, 0x6969, 0x9696, 0x0f0f };
7018 static unsigned int Patterncount = ARRAY_SIZE(BitPatterns);
7021 unsigned long flags;
7023 spin_lock_irqsave(&info->irq_spinlock,flags);
7026 /* Verify the reset state of some registers. */
7028 if ( (usc_InReg( info, SICR ) != 0) ||
7029 (usc_InReg( info, IVR ) != 0) ||
7030 (usc_InDmaReg( info, DIVR ) != 0) ){
7035 /* Write bit patterns to various registers but do it out of */
7036 /* sync, then read back and verify values. */
7038 for ( i = 0 ; i < Patterncount ; i++ ) {
7039 usc_OutReg( info, TC0R, BitPatterns[i] );
7040 usc_OutReg( info, TC1R, BitPatterns[(i+1)%Patterncount] );
7041 usc_OutReg( info, TCLR, BitPatterns[(i+2)%Patterncount] );
7042 usc_OutReg( info, RCLR, BitPatterns[(i+3)%Patterncount] );
7043 usc_OutReg( info, RSR, BitPatterns[(i+4)%Patterncount] );
7044 usc_OutDmaReg( info, TBCR, BitPatterns[(i+5)%Patterncount] );
7046 if ( (usc_InReg( info, TC0R ) != BitPatterns[i]) ||
7047 (usc_InReg( info, TC1R ) != BitPatterns[(i+1)%Patterncount]) ||
7048 (usc_InReg( info, TCLR ) != BitPatterns[(i+2)%Patterncount]) ||
7049 (usc_InReg( info, RCLR ) != BitPatterns[(i+3)%Patterncount]) ||
7050 (usc_InReg( info, RSR ) != BitPatterns[(i+4)%Patterncount]) ||
7051 (usc_InDmaReg( info, TBCR ) != BitPatterns[(i+5)%Patterncount]) ){
7059 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7063 } /* end of mgsl_register_test() */
7065 /* mgsl_irq_test() Perform interrupt test of the 16C32.
7067 * Arguments: info pointer to device instance data
7068 * Return Value: TRUE if test passed, otherwise FALSE
7070 static BOOLEAN mgsl_irq_test( struct mgsl_struct *info )
7072 unsigned long EndTime;
7073 unsigned long flags;
7075 spin_lock_irqsave(&info->irq_spinlock,flags);
7079 * Setup 16C32 to interrupt on TxC pin (14MHz clock) transition.
7080 * The ISR sets irq_occurred to 1.
7083 info->irq_occurred = FALSE;
7085 /* Enable INTEN gate for ISA adapter (Port 6, Bit12) */
7086 /* Enable INTEN (Port 6, Bit12) */
7087 /* This connects the IRQ request signal to the ISA bus */
7088 /* on the ISA adapter. This has no effect for the PCI adapter */
7089 usc_OutReg( info, PCR, (unsigned short)((usc_InReg(info, PCR) | BIT13) & ~BIT12) );
7091 usc_EnableMasterIrqBit(info);
7092 usc_EnableInterrupts(info, IO_PIN);
7093 usc_ClearIrqPendingBits(info, IO_PIN);
7095 usc_UnlatchIostatusBits(info, MISCSTATUS_TXC_LATCHED);
7096 usc_EnableStatusIrqs(info, SICR_TXC_ACTIVE + SICR_TXC_INACTIVE);
7098 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7101 while( EndTime-- && !info->irq_occurred ) {
7102 msleep_interruptible(10);
7105 spin_lock_irqsave(&info->irq_spinlock,flags);
7107 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7109 if ( !info->irq_occurred )
7114 } /* end of mgsl_irq_test() */
7118 * Perform a DMA test of the 16C32. A small frame is
7119 * transmitted via DMA from a transmit buffer to a receive buffer
7120 * using single buffer DMA mode.
7122 * Arguments: info pointer to device instance data
7123 * Return Value: TRUE if test passed, otherwise FALSE
7125 static BOOLEAN mgsl_dma_test( struct mgsl_struct *info )
7127 unsigned short FifoLevel;
7128 unsigned long phys_addr;
7129 unsigned int FrameSize;
7133 unsigned short status=0;
7134 unsigned long EndTime;
7135 unsigned long flags;
7136 MGSL_PARAMS tmp_params;
7138 /* save current port options */
7139 memcpy(&tmp_params,&info->params,sizeof(MGSL_PARAMS));
7140 /* load default port options */
7141 memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
7143 #define TESTFRAMESIZE 40
7145 spin_lock_irqsave(&info->irq_spinlock,flags);
7147 /* setup 16C32 for SDLC DMA transfer mode */
7150 usc_set_sdlc_mode(info);
7151 usc_enable_loopback(info,1);
7153 /* Reprogram the RDMR so that the 16C32 does NOT clear the count
7154 * field of the buffer entry after fetching buffer address. This
7155 * way we can detect a DMA failure for a DMA read (which should be
7156 * non-destructive to system memory) before we try and write to
7157 * memory (where a failure could corrupt system memory).
7160 /* Receive DMA mode Register (RDMR)
7162 * <15..14> 11 DMA mode = Linked List Buffer mode
7163 * <13> 1 RSBinA/L = store Rx status Block in List entry
7164 * <12> 0 1 = Clear count of List Entry after fetching
7165 * <11..10> 00 Address mode = Increment
7166 * <9> 1 Terminate Buffer on RxBound
7167 * <8> 0 Bus Width = 16bits
7168 * <7..0> ? status Bits (write as 0s)
7170 * 1110 0010 0000 0000 = 0xe200
7173 usc_OutDmaReg( info, RDMR, 0xe200 );
7175 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7178 /* SETUP TRANSMIT AND RECEIVE DMA BUFFERS */
7180 FrameSize = TESTFRAMESIZE;
7182 /* setup 1st transmit buffer entry: */
7183 /* with frame size and transmit control word */
7185 info->tx_buffer_list[0].count = FrameSize;
7186 info->tx_buffer_list[0].rcc = FrameSize;
7187 info->tx_buffer_list[0].status = 0x4000;
7189 /* build a transmit frame in 1st transmit DMA buffer */
7191 TmpPtr = info->tx_buffer_list[0].virt_addr;
7192 for (i = 0; i < FrameSize; i++ )
7195 /* setup 1st receive buffer entry: */
7196 /* clear status, set max receive buffer size */
7198 info->rx_buffer_list[0].status = 0;
7199 info->rx_buffer_list[0].count = FrameSize + 4;
7201 /* zero out the 1st receive buffer */
7203 memset( info->rx_buffer_list[0].virt_addr, 0, FrameSize + 4 );
7205 /* Set count field of next buffer entries to prevent */
7206 /* 16C32 from using buffers after the 1st one. */
7208 info->tx_buffer_list[1].count = 0;
7209 info->rx_buffer_list[1].count = 0;
7212 /***************************/
7213 /* Program 16C32 receiver. */
7214 /***************************/
7216 spin_lock_irqsave(&info->irq_spinlock,flags);
7218 /* setup DMA transfers */
7219 usc_RTCmd( info, RTCmd_PurgeRxFifo );
7221 /* program 16C32 receiver with physical address of 1st DMA buffer entry */
7222 phys_addr = info->rx_buffer_list[0].phys_entry;
7223 usc_OutDmaReg( info, NRARL, (unsigned short)phys_addr );
7224 usc_OutDmaReg( info, NRARU, (unsigned short)(phys_addr >> 16) );
7226 /* Clear the Rx DMA status bits (read RDMR) and start channel */
7227 usc_InDmaReg( info, RDMR );
7228 usc_DmaCmd( info, DmaCmd_InitRxChannel );
7230 /* Enable Receiver (RMR <1..0> = 10) */
7231 usc_OutReg( info, RMR, (unsigned short)((usc_InReg(info, RMR) & 0xfffc) | 0x0002) );
7233 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7236 /*************************************************************/
7237 /* WAIT FOR RECEIVER TO DMA ALL PARAMETERS FROM BUFFER ENTRY */
7238 /*************************************************************/
7240 /* Wait 100ms for interrupt. */
7241 EndTime = jiffies + msecs_to_jiffies(100);
7244 if (time_after(jiffies, EndTime)) {
7249 spin_lock_irqsave(&info->irq_spinlock,flags);
7250 status = usc_InDmaReg( info, RDMR );
7251 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7253 if ( !(status & BIT4) && (status & BIT5) ) {
7254 /* INITG (BIT 4) is inactive (no entry read in progress) AND */
7255 /* BUSY (BIT 5) is active (channel still active). */
7256 /* This means the buffer entry read has completed. */
7262 /******************************/
7263 /* Program 16C32 transmitter. */
7264 /******************************/
7266 spin_lock_irqsave(&info->irq_spinlock,flags);
7268 /* Program the Transmit Character Length Register (TCLR) */
7269 /* and clear FIFO (TCC is loaded with TCLR on FIFO clear) */
7271 usc_OutReg( info, TCLR, (unsigned short)info->tx_buffer_list[0].count );
7272 usc_RTCmd( info, RTCmd_PurgeTxFifo );
7274 /* Program the address of the 1st DMA Buffer Entry in linked list */
7276 phys_addr = info->tx_buffer_list[0].phys_entry;
7277 usc_OutDmaReg( info, NTARL, (unsigned short)phys_addr );
7278 usc_OutDmaReg( info, NTARU, (unsigned short)(phys_addr >> 16) );
7280 /* unlatch Tx status bits, and start transmit channel. */
7282 usc_OutReg( info, TCSR, (unsigned short)(( usc_InReg(info, TCSR) & 0x0f00) | 0xfa) );
7283 usc_DmaCmd( info, DmaCmd_InitTxChannel );
7285 /* wait for DMA controller to fill transmit FIFO */
7287 usc_TCmd( info, TCmd_SelectTicrTxFifostatus );
7289 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7292 /**********************************/
7293 /* WAIT FOR TRANSMIT FIFO TO FILL */
7294 /**********************************/
7297 EndTime = jiffies + msecs_to_jiffies(100);
7300 if (time_after(jiffies, EndTime)) {
7305 spin_lock_irqsave(&info->irq_spinlock,flags);
7306 FifoLevel = usc_InReg(info, TICR) >> 8;
7307 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7309 if ( FifoLevel < 16 )
7312 if ( FrameSize < 32 ) {
7313 /* This frame is smaller than the entire transmit FIFO */
7314 /* so wait for the entire frame to be loaded. */
7315 if ( FifoLevel <= (32 - FrameSize) )
7323 /* Enable 16C32 transmitter. */
7325 spin_lock_irqsave(&info->irq_spinlock,flags);
7327 /* Transmit mode Register (TMR), <1..0> = 10, Enable Transmitter */
7328 usc_TCmd( info, TCmd_SendFrame );
7329 usc_OutReg( info, TMR, (unsigned short)((usc_InReg(info, TMR) & 0xfffc) | 0x0002) );
7331 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7334 /******************************/
7335 /* WAIT FOR TRANSMIT COMPLETE */
7336 /******************************/
7339 EndTime = jiffies + msecs_to_jiffies(100);
7341 /* While timer not expired wait for transmit complete */
7343 spin_lock_irqsave(&info->irq_spinlock,flags);
7344 status = usc_InReg( info, TCSR );
7345 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7347 while ( !(status & (BIT6+BIT5+BIT4+BIT2+BIT1)) ) {
7348 if (time_after(jiffies, EndTime)) {
7353 spin_lock_irqsave(&info->irq_spinlock,flags);
7354 status = usc_InReg( info, TCSR );
7355 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7361 /* CHECK FOR TRANSMIT ERRORS */
7362 if ( status & (BIT5 + BIT1) )
7367 /* WAIT FOR RECEIVE COMPLETE */
7370 EndTime = jiffies + msecs_to_jiffies(100);
7372 /* Wait for 16C32 to write receive status to buffer entry. */
7373 status=info->rx_buffer_list[0].status;
7374 while ( status == 0 ) {
7375 if (time_after(jiffies, EndTime)) {
7379 status=info->rx_buffer_list[0].status;
7385 /* CHECK FOR RECEIVE ERRORS */
7386 status = info->rx_buffer_list[0].status;
7388 if ( status & (BIT8 + BIT3 + BIT1) ) {
7389 /* receive error has occurred */
7392 if ( memcmp( info->tx_buffer_list[0].virt_addr ,
7393 info->rx_buffer_list[0].virt_addr, FrameSize ) ){
7399 spin_lock_irqsave(&info->irq_spinlock,flags);
7401 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7403 /* restore current port options */
7404 memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
7408 } /* end of mgsl_dma_test() */
7410 /* mgsl_adapter_test()
7412 * Perform the register, IRQ, and DMA tests for the 16C32.
7414 * Arguments: info pointer to device instance data
7415 * Return Value: 0 if success, otherwise -ENODEV
7417 static int mgsl_adapter_test( struct mgsl_struct *info )
7419 if ( debug_level >= DEBUG_LEVEL_INFO )
7420 printk( "%s(%d):Testing device %s\n",
7421 __FILE__,__LINE__,info->device_name );
7423 if ( !mgsl_register_test( info ) ) {
7424 info->init_error = DiagStatus_AddressFailure;
7425 printk( "%s(%d):Register test failure for device %s Addr=%04X\n",
7426 __FILE__,__LINE__,info->device_name, (unsigned short)(info->io_base) );
7430 if ( !mgsl_irq_test( info ) ) {
7431 info->init_error = DiagStatus_IrqFailure;
7432 printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
7433 __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
7437 if ( !mgsl_dma_test( info ) ) {
7438 info->init_error = DiagStatus_DmaFailure;
7439 printk( "%s(%d):DMA test failure for device %s DMA=%d\n",
7440 __FILE__,__LINE__,info->device_name, (unsigned short)(info->dma_level) );
7444 if ( debug_level >= DEBUG_LEVEL_INFO )
7445 printk( "%s(%d):device %s passed diagnostics\n",
7446 __FILE__,__LINE__,info->device_name );
7450 } /* end of mgsl_adapter_test() */
7452 /* mgsl_memory_test()
7454 * Test the shared memory on a PCI adapter.
7456 * Arguments: info pointer to device instance data
7457 * Return Value: TRUE if test passed, otherwise FALSE
7459 static BOOLEAN mgsl_memory_test( struct mgsl_struct *info )
7461 static unsigned long BitPatterns[] =
7462 { 0x0, 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
7463 unsigned long Patterncount = ARRAY_SIZE(BitPatterns);
7465 unsigned long TestLimit = SHARED_MEM_ADDRESS_SIZE/sizeof(unsigned long);
7466 unsigned long * TestAddr;
7468 if ( info->bus_type != MGSL_BUS_TYPE_PCI )
7471 TestAddr = (unsigned long *)info->memory_base;
7473 /* Test data lines with test pattern at one location. */
7475 for ( i = 0 ; i < Patterncount ; i++ ) {
7476 *TestAddr = BitPatterns[i];
7477 if ( *TestAddr != BitPatterns[i] )
7481 /* Test address lines with incrementing pattern over */
7482 /* entire address range. */
7484 for ( i = 0 ; i < TestLimit ; i++ ) {
7489 TestAddr = (unsigned long *)info->memory_base;
7491 for ( i = 0 ; i < TestLimit ; i++ ) {
7492 if ( *TestAddr != i * 4 )
7497 memset( info->memory_base, 0, SHARED_MEM_ADDRESS_SIZE );
7501 } /* End Of mgsl_memory_test() */
7504 /* mgsl_load_pci_memory()
7506 * Load a large block of data into the PCI shared memory.
7507 * Use this instead of memcpy() or memmove() to move data
7508 * into the PCI shared memory.
7512 * This function prevents the PCI9050 interface chip from hogging
7513 * the adapter local bus, which can starve the 16C32 by preventing
7514 * 16C32 bus master cycles.
7516 * The PCI9050 documentation says that the 9050 will always release
7517 * control of the local bus after completing the current read
7518 * or write operation.
7520 * It appears that as long as the PCI9050 write FIFO is full, the
7521 * PCI9050 treats all of the writes as a single burst transaction
7522 * and will not release the bus. This causes DMA latency problems
7523 * at high speeds when copying large data blocks to the shared
7526 * This function in effect, breaks the a large shared memory write
7527 * into multiple transations by interleaving a shared memory read
7528 * which will flush the write FIFO and 'complete' the write
7529 * transation. This allows any pending DMA request to gain control
7530 * of the local bus in a timely fasion.
7534 * TargetPtr pointer to target address in PCI shared memory
7535 * SourcePtr pointer to source buffer for data
7536 * count count in bytes of data to copy
7538 * Return Value: None
7540 static void mgsl_load_pci_memory( char* TargetPtr, const char* SourcePtr,
7541 unsigned short count )
7543 /* 16 32-bit writes @ 60ns each = 960ns max latency on local bus */
7544 #define PCI_LOAD_INTERVAL 64
7546 unsigned short Intervalcount = count / PCI_LOAD_INTERVAL;
7547 unsigned short Index;
7548 unsigned long Dummy;
7550 for ( Index = 0 ; Index < Intervalcount ; Index++ )
7552 memcpy(TargetPtr, SourcePtr, PCI_LOAD_INTERVAL);
7553 Dummy = *((volatile unsigned long *)TargetPtr);
7554 TargetPtr += PCI_LOAD_INTERVAL;
7555 SourcePtr += PCI_LOAD_INTERVAL;
7558 memcpy( TargetPtr, SourcePtr, count % PCI_LOAD_INTERVAL );
7560 } /* End Of mgsl_load_pci_memory() */
7562 static void mgsl_trace_block(struct mgsl_struct *info,const char* data, int count, int xmit)
7567 printk("%s tx data:\n",info->device_name);
7569 printk("%s rx data:\n",info->device_name);
7577 for(i=0;i<linecount;i++)
7578 printk("%02X ",(unsigned char)data[i]);
7581 for(i=0;i<linecount;i++) {
7582 if (data[i]>=040 && data[i]<=0176)
7583 printk("%c",data[i]);
7592 } /* end of mgsl_trace_block() */
7594 /* mgsl_tx_timeout()
7596 * called when HDLC frame times out
7597 * update stats and do tx completion processing
7599 * Arguments: context pointer to device instance data
7600 * Return Value: None
7602 static void mgsl_tx_timeout(unsigned long context)
7604 struct mgsl_struct *info = (struct mgsl_struct*)context;
7605 unsigned long flags;
7607 if ( debug_level >= DEBUG_LEVEL_INFO )
7608 printk( "%s(%d):mgsl_tx_timeout(%s)\n",
7609 __FILE__,__LINE__,info->device_name);
7610 if(info->tx_active &&
7611 (info->params.mode == MGSL_MODE_HDLC ||
7612 info->params.mode == MGSL_MODE_RAW) ) {
7613 info->icount.txtimeout++;
7615 spin_lock_irqsave(&info->irq_spinlock,flags);
7616 info->tx_active = 0;
7617 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
7619 if ( info->params.flags & HDLC_FLAG_HDLC_LOOPMODE )
7620 usc_loopmode_cancel_transmit( info );
7622 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7624 #if SYNCLINK_GENERIC_HDLC
7626 hdlcdev_tx_done(info);
7629 mgsl_bh_transmit(info);
7631 } /* end of mgsl_tx_timeout() */
7633 /* signal that there are no more frames to send, so that
7634 * line is 'released' by echoing RxD to TxD when current
7635 * transmission is complete (or immediately if no tx in progress).
7637 static int mgsl_loopmode_send_done( struct mgsl_struct * info )
7639 unsigned long flags;
7641 spin_lock_irqsave(&info->irq_spinlock,flags);
7642 if (info->params.flags & HDLC_FLAG_HDLC_LOOPMODE) {
7643 if (info->tx_active)
7644 info->loopmode_send_done_requested = TRUE;
7646 usc_loopmode_send_done(info);
7648 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7653 /* release the line by echoing RxD to TxD
7654 * upon completion of a transmit frame
7656 static void usc_loopmode_send_done( struct mgsl_struct * info )
7658 info->loopmode_send_done_requested = FALSE;
7659 /* clear CMR:13 to 0 to start echoing RxData to TxData */
7660 info->cmr_value &= ~BIT13;
7661 usc_OutReg(info, CMR, info->cmr_value);
7664 /* abort a transmit in progress while in HDLC LoopMode
7666 static void usc_loopmode_cancel_transmit( struct mgsl_struct * info )
7668 /* reset tx dma channel and purge TxFifo */
7669 usc_RTCmd( info, RTCmd_PurgeTxFifo );
7670 usc_DmaCmd( info, DmaCmd_ResetTxChannel );
7671 usc_loopmode_send_done( info );
7674 /* for HDLC/SDLC LoopMode, setting CMR:13 after the transmitter is enabled
7675 * is an Insert Into Loop action. Upon receipt of a GoAhead sequence (RxAbort)
7676 * we must clear CMR:13 to begin repeating TxData to RxData
7678 static void usc_loopmode_insert_request( struct mgsl_struct * info )
7680 info->loopmode_insert_requested = TRUE;
7682 /* enable RxAbort irq. On next RxAbort, clear CMR:13 to
7683 * begin repeating TxData on RxData (complete insertion)
7685 usc_OutReg( info, RICR,
7686 (usc_InReg( info, RICR ) | RXSTATUS_ABORT_RECEIVED ) );
7688 /* set CMR:13 to insert into loop on next GoAhead (RxAbort) */
7689 info->cmr_value |= BIT13;
7690 usc_OutReg(info, CMR, info->cmr_value);
7693 /* return 1 if station is inserted into the loop, otherwise 0
7695 static int usc_loopmode_active( struct mgsl_struct * info)
7697 return usc_InReg( info, CCSR ) & BIT7 ? 1 : 0 ;
7700 #if SYNCLINK_GENERIC_HDLC
7703 * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
7704 * set encoding and frame check sequence (FCS) options
7706 * dev pointer to network device structure
7707 * encoding serial encoding setting
7708 * parity FCS setting
7710 * returns 0 if success, otherwise error code
7712 static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
7713 unsigned short parity)
7715 struct mgsl_struct *info = dev_to_port(dev);
7716 unsigned char new_encoding;
7717 unsigned short new_crctype;
7719 /* return error if TTY interface open */
7725 case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
7726 case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
7727 case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
7728 case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
7729 case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
7730 default: return -EINVAL;
7735 case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
7736 case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
7737 case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
7738 default: return -EINVAL;
7741 info->params.encoding = new_encoding;
7742 info->params.crc_type = new_crctype;
7744 /* if network interface up, reprogram hardware */
7746 mgsl_program_hw(info);
7752 * called by generic HDLC layer to send frame
7754 * skb socket buffer containing HDLC frame
7755 * dev pointer to network device structure
7757 * returns 0 if success, otherwise error code
7759 static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
7761 struct mgsl_struct *info = dev_to_port(dev);
7762 struct net_device_stats *stats = hdlc_stats(dev);
7763 unsigned long flags;
7765 if (debug_level >= DEBUG_LEVEL_INFO)
7766 printk(KERN_INFO "%s:hdlc_xmit(%s)\n",__FILE__,dev->name);
7768 /* stop sending until this frame completes */
7769 netif_stop_queue(dev);
7771 /* copy data to device buffers */
7772 info->xmit_cnt = skb->len;
7773 mgsl_load_tx_dma_buffer(info, skb->data, skb->len);
7775 /* update network statistics */
7776 stats->tx_packets++;
7777 stats->tx_bytes += skb->len;
7779 /* done with socket buffer, so free it */
7782 /* save start time for transmit timeout detection */
7783 dev->trans_start = jiffies;
7785 /* start hardware transmitter if necessary */
7786 spin_lock_irqsave(&info->irq_spinlock,flags);
7787 if (!info->tx_active)
7788 usc_start_transmitter(info);
7789 spin_unlock_irqrestore(&info->irq_spinlock,flags);
7795 * called by network layer when interface enabled
7796 * claim resources and initialize hardware
7798 * dev pointer to network device structure
7800 * returns 0 if success, otherwise error code
7802 static int hdlcdev_open(struct net_device *dev)
7804 struct mgsl_struct *info = dev_to_port(dev);
7806 unsigned long flags;
7808 if (debug_level >= DEBUG_LEVEL_INFO)
7809 printk("%s:hdlcdev_open(%s)\n",__FILE__,dev->name);
7811 /* generic HDLC layer open processing */
7812 if ((rc = hdlc_open(dev)))
7815 /* arbitrate between network and tty opens */
7816 spin_lock_irqsave(&info->netlock, flags);
7817 if (info->count != 0 || info->netcount != 0) {
7818 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
7819 spin_unlock_irqrestore(&info->netlock, flags);
7823 spin_unlock_irqrestore(&info->netlock, flags);
7825 /* claim resources and init adapter */
7826 if ((rc = startup(info)) != 0) {
7827 spin_lock_irqsave(&info->netlock, flags);
7829 spin_unlock_irqrestore(&info->netlock, flags);
7833 /* assert DTR and RTS, apply hardware settings */
7834 info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
7835 mgsl_program_hw(info);
7837 /* enable network layer transmit */
7838 dev->trans_start = jiffies;
7839 netif_start_queue(dev);
7841 /* inform generic HDLC layer of current DCD status */
7842 spin_lock_irqsave(&info->irq_spinlock, flags);
7843 usc_get_serial_signals(info);
7844 spin_unlock_irqrestore(&info->irq_spinlock, flags);
7845 if (info->serial_signals & SerialSignal_DCD)
7846 netif_carrier_on(dev);
7848 netif_carrier_off(dev);
7853 * called by network layer when interface is disabled
7854 * shutdown hardware and release resources
7856 * dev pointer to network device structure
7858 * returns 0 if success, otherwise error code
7860 static int hdlcdev_close(struct net_device *dev)
7862 struct mgsl_struct *info = dev_to_port(dev);
7863 unsigned long flags;
7865 if (debug_level >= DEBUG_LEVEL_INFO)
7866 printk("%s:hdlcdev_close(%s)\n",__FILE__,dev->name);
7868 netif_stop_queue(dev);
7870 /* shutdown adapter and release resources */
7875 spin_lock_irqsave(&info->netlock, flags);
7877 spin_unlock_irqrestore(&info->netlock, flags);
7883 * called by network layer to process IOCTL call to network device
7885 * dev pointer to network device structure
7886 * ifr pointer to network interface request structure
7887 * cmd IOCTL command code
7889 * returns 0 if success, otherwise error code
7891 static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
7893 const size_t size = sizeof(sync_serial_settings);
7894 sync_serial_settings new_line;
7895 sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
7896 struct mgsl_struct *info = dev_to_port(dev);
7899 if (debug_level >= DEBUG_LEVEL_INFO)
7900 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
7902 /* return error if TTY interface open */
7906 if (cmd != SIOCWANDEV)
7907 return hdlc_ioctl(dev, ifr, cmd);
7909 switch(ifr->ifr_settings.type) {
7910 case IF_GET_IFACE: /* return current sync_serial_settings */
7912 ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL;
7913 if (ifr->ifr_settings.size < size) {
7914 ifr->ifr_settings.size = size; /* data size wanted */
7918 flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
7919 HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
7920 HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
7921 HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
7924 case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
7925 case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
7926 case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
7927 case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
7928 default: new_line.clock_type = CLOCK_DEFAULT;
7931 new_line.clock_rate = info->params.clock_speed;
7932 new_line.loopback = info->params.loopback ? 1:0;
7934 if (copy_to_user(line, &new_line, size))
7938 case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
7940 if(!capable(CAP_NET_ADMIN))
7942 if (copy_from_user(&new_line, line, size))
7945 switch (new_line.clock_type)
7947 case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
7948 case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
7949 case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
7950 case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
7951 case CLOCK_DEFAULT: flags = info->params.flags &
7952 (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
7953 HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
7954 HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
7955 HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
7956 default: return -EINVAL;
7959 if (new_line.loopback != 0 && new_line.loopback != 1)
7962 info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
7963 HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
7964 HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
7965 HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
7966 info->params.flags |= flags;
7968 info->params.loopback = new_line.loopback;
7970 if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
7971 info->params.clock_speed = new_line.clock_rate;
7973 info->params.clock_speed = 0;
7975 /* if network interface up, reprogram hardware */
7977 mgsl_program_hw(info);
7981 return hdlc_ioctl(dev, ifr, cmd);
7986 * called by network layer when transmit timeout is detected
7988 * dev pointer to network device structure
7990 static void hdlcdev_tx_timeout(struct net_device *dev)
7992 struct mgsl_struct *info = dev_to_port(dev);
7993 struct net_device_stats *stats = hdlc_stats(dev);
7994 unsigned long flags;
7996 if (debug_level >= DEBUG_LEVEL_INFO)
7997 printk("hdlcdev_tx_timeout(%s)\n",dev->name);
8000 stats->tx_aborted_errors++;
8002 spin_lock_irqsave(&info->irq_spinlock,flags);
8003 usc_stop_transmitter(info);
8004 spin_unlock_irqrestore(&info->irq_spinlock,flags);
8006 netif_wake_queue(dev);
8010 * called by device driver when transmit completes
8011 * reenable network layer transmit if stopped
8013 * info pointer to device instance information
8015 static void hdlcdev_tx_done(struct mgsl_struct *info)
8017 if (netif_queue_stopped(info->netdev))
8018 netif_wake_queue(info->netdev);
8022 * called by device driver when frame received
8023 * pass frame to network layer
8025 * info pointer to device instance information
8026 * buf pointer to buffer contianing frame data
8027 * size count of data bytes in buf
8029 static void hdlcdev_rx(struct mgsl_struct *info, char *buf, int size)
8031 struct sk_buff *skb = dev_alloc_skb(size);
8032 struct net_device *dev = info->netdev;
8033 struct net_device_stats *stats = hdlc_stats(dev);
8035 if (debug_level >= DEBUG_LEVEL_INFO)
8036 printk("hdlcdev_rx(%s)\n",dev->name);
8039 printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n", dev->name);
8040 stats->rx_dropped++;
8044 memcpy(skb_put(skb, size),buf,size);
8046 skb->protocol = hdlc_type_trans(skb, info->netdev);
8048 stats->rx_packets++;
8049 stats->rx_bytes += size;
8053 info->netdev->last_rx = jiffies;
8057 * called by device driver when adding device instance
8058 * do generic HDLC initialization
8060 * info pointer to device instance information
8062 * returns 0 if success, otherwise error code
8064 static int hdlcdev_init(struct mgsl_struct *info)
8067 struct net_device *dev;
8070 /* allocate and initialize network and HDLC layer objects */
8072 if (!(dev = alloc_hdlcdev(info))) {
8073 printk(KERN_ERR "%s:hdlc device allocation failure\n",__FILE__);
8077 /* for network layer reporting purposes only */
8078 dev->base_addr = info->io_base;
8079 dev->irq = info->irq_level;
8080 dev->dma = info->dma_level;
8082 /* network layer callbacks and settings */
8083 dev->do_ioctl = hdlcdev_ioctl;
8084 dev->open = hdlcdev_open;
8085 dev->stop = hdlcdev_close;
8086 dev->tx_timeout = hdlcdev_tx_timeout;
8087 dev->watchdog_timeo = 10*HZ;
8088 dev->tx_queue_len = 50;
8090 /* generic HDLC layer callbacks and settings */
8091 hdlc = dev_to_hdlc(dev);
8092 hdlc->attach = hdlcdev_attach;
8093 hdlc->xmit = hdlcdev_xmit;
8095 /* register objects with HDLC layer */
8096 if ((rc = register_hdlc_device(dev))) {
8097 printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
8107 * called by device driver when removing device instance
8108 * do generic HDLC cleanup
8110 * info pointer to device instance information
8112 static void hdlcdev_exit(struct mgsl_struct *info)
8114 unregister_hdlc_device(info->netdev);
8115 free_netdev(info->netdev);
8116 info->netdev = NULL;
8119 #endif /* CONFIG_HDLC */
8122 static int __devinit synclink_init_one (struct pci_dev *dev,
8123 const struct pci_device_id *ent)
8125 struct mgsl_struct *info;
8127 if (pci_enable_device(dev)) {
8128 printk("error enabling pci device %p\n", dev);
8132 if (!(info = mgsl_allocate_device())) {
8133 printk("can't allocate device instance data.\n");
8137 /* Copy user configuration info to device instance data */
8139 info->io_base = pci_resource_start(dev, 2);
8140 info->irq_level = dev->irq;
8141 info->phys_memory_base = pci_resource_start(dev, 3);
8143 /* Because veremap only works on page boundaries we must map
8144 * a larger area than is actually implemented for the LCR
8145 * memory range. We map a full page starting at the page boundary.
8147 info->phys_lcr_base = pci_resource_start(dev, 0);
8148 info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
8149 info->phys_lcr_base &= ~(PAGE_SIZE-1);
8151 info->bus_type = MGSL_BUS_TYPE_PCI;
8152 info->io_addr_size = 8;
8153 info->irq_flags = IRQF_SHARED;
8155 if (dev->device == 0x0210) {
8156 /* Version 1 PCI9030 based universal PCI adapter */
8157 info->misc_ctrl_value = 0x007c4080;
8158 info->hw_version = 1;
8160 /* Version 0 PCI9050 based 5V PCI adapter
8161 * A PCI9050 bug prevents reading LCR registers if
8162 * LCR base address bit 7 is set. Maintain shadow
8163 * value so we can write to LCR misc control reg.
8165 info->misc_ctrl_value = 0x087e4546;
8166 info->hw_version = 0;
8169 mgsl_add_device(info);
8174 static void __devexit synclink_remove_one (struct pci_dev *dev)