55 # define BREAKPOINT() asm(" int $3");
57 # define BREAKPOINT() { }
60 #define MAX_ISA_DEVICES 10
61 #define MAX_PCI_DEVICES 10
62 #define MAX_TOTAL_DEVICES 20
64 #include <linux/module.h>
65 #include <linux/errno.h>
66 #include <linux/signal.h>
67 #include <linux/sched.h>
70 #include <linux/pci.h>
71 #include <linux/tty.h>
73 #include <linux/serial.h>
75 #include <linux/string.h>
76 #include <linux/fcntl.h>
77 #include <linux/ptrace.h>
81 #include <linux/slab.h>
83 #include <linux/netdevice.h>
87 #include <linux/synclink.h>
92 #include <linux/bitops.h>
93 #include <asm/types.h>
96 #include <linux/hdlc.h>
99 #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_MODULE))
100 #define SYNCLINK_GENERIC_HDLC 1
102 #define SYNCLINK_GENERIC_HDLC 0
105 #define GET_USER(error,value,addr) error = get_user(value,addr)
106 #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
107 #define PUT_USER(error,value,addr) error = put_user(value,addr)
108 #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
110 #include <asm/uaccess.h>
112 #define RCLRVALUE 0xffff
130 #define SHARED_MEM_ADDRESS_SIZE 0x40000
131 #define BUFFERLISTSIZE 4096
132 #define DMABUFFERSIZE 4096
133 #define MAXRXFRAMES 7
151 #define BH_TRANSMIT 2
154 #define IO_PIN_SHUTDOWN_LIMIT 100
168 #define MAX_TX_HOLDING_BUFFERS 5
258 unsigned char function;
307 #if SYNCLINK_GENERIC_HDLC
312 #define MGSL_MAGIC 0x5401
317 #ifndef SERIAL_XMIT_SIZE
318 #define SERIAL_XMIT_SIZE 4096
332 #define DATAREG DCPIN + SDPIN
409 #define MODEMSTATUS_DTR 0x80
410 #define MODEMSTATUS_DSR 0x40
411 #define MODEMSTATUS_RTS 0x20
412 #define MODEMSTATUS_CTS 0x10
413 #define MODEMSTATUS_RI 0x04
414 #define MODEMSTATUS_DCD 0x01
421 #define RTCmd_Null 0x0000
422 #define RTCmd_ResetHighestIus 0x1000
423 #define RTCmd_TriggerChannelLoadDma 0x2000
424 #define RTCmd_TriggerRxDma 0x2800
425 #define RTCmd_TriggerTxDma 0x3000
426 #define RTCmd_TriggerRxAndTxDma 0x3800
427 #define RTCmd_PurgeRxFifo 0x4800
428 #define RTCmd_PurgeTxFifo 0x5000
429 #define RTCmd_PurgeRxAndTxFifo 0x5800
430 #define RTCmd_LoadRcc 0x6800
431 #define RTCmd_LoadTcc 0x7000
432 #define RTCmd_LoadRccAndTcc 0x7800
433 #define RTCmd_LoadTC0 0x8800
434 #define RTCmd_LoadTC1 0x9000
435 #define RTCmd_LoadTC0AndTC1 0x9800
436 #define RTCmd_SerialDataLSBFirst 0xa000
437 #define RTCmd_SerialDataMSBFirst 0xa800
438 #define RTCmd_SelectBigEndian 0xb000
439 #define RTCmd_SelectLittleEndian 0xb800
446 #define DmaCmd_Null 0x0000
447 #define DmaCmd_ResetTxChannel 0x1000
448 #define DmaCmd_ResetRxChannel 0x1200
449 #define DmaCmd_StartTxChannel 0x2000
450 #define DmaCmd_StartRxChannel 0x2200
451 #define DmaCmd_ContinueTxChannel 0x3000
452 #define DmaCmd_ContinueRxChannel 0x3200
453 #define DmaCmd_PauseTxChannel 0x4000
454 #define DmaCmd_PauseRxChannel 0x4200
455 #define DmaCmd_AbortTxChannel 0x5000
456 #define DmaCmd_AbortRxChannel 0x5200
457 #define DmaCmd_InitTxChannel 0x7000
458 #define DmaCmd_InitRxChannel 0x7200
459 #define DmaCmd_ResetHighestDmaIus 0x8000
460 #define DmaCmd_ResetAllChannels 0x9000
461 #define DmaCmd_StartAllChannels 0xa000
462 #define DmaCmd_ContinueAllChannels 0xb000
463 #define DmaCmd_PauseAllChannels 0xc000
464 #define DmaCmd_AbortAllChannels 0xd000
465 #define DmaCmd_InitAllChannels 0xf000
467 #define TCmd_Null 0x0000
468 #define TCmd_ClearTxCRC 0x2000
469 #define TCmd_SelectTicrTtsaData 0x4000
470 #define TCmd_SelectTicrTxFifostatus 0x5000
471 #define TCmd_SelectTicrIntLevel 0x6000
472 #define TCmd_SelectTicrdma_level 0x7000
473 #define TCmd_SendFrame 0x8000
474 #define TCmd_SendAbort 0x9000
475 #define TCmd_EnableDleInsertion 0xc000
476 #define TCmd_DisableDleInsertion 0xd000
477 #define TCmd_ClearEofEom 0xe000
478 #define TCmd_SetEofEom 0xf000
480 #define RCmd_Null 0x0000
481 #define RCmd_ClearRxCRC 0x2000
482 #define RCmd_EnterHuntmode 0x3000
483 #define RCmd_SelectRicrRtsaData 0x4000
484 #define RCmd_SelectRicrRxFifostatus 0x5000
485 #define RCmd_SelectRicrIntLevel 0x6000
486 #define RCmd_SelectRicrdma_level 0x7000
492 #define RECEIVE_STATUS BIT5
493 #define RECEIVE_DATA BIT4
494 #define TRANSMIT_STATUS BIT3
495 #define TRANSMIT_DATA BIT2
504 #define RXSTATUS_SHORT_FRAME BIT8
505 #define RXSTATUS_CODE_VIOLATION BIT8
506 #define RXSTATUS_EXITED_HUNT BIT7
507 #define RXSTATUS_IDLE_RECEIVED BIT6
508 #define RXSTATUS_BREAK_RECEIVED BIT5
509 #define RXSTATUS_ABORT_RECEIVED BIT5
510 #define RXSTATUS_RXBOUND BIT4
511 #define RXSTATUS_CRC_ERROR BIT3
512 #define RXSTATUS_FRAMING_ERROR BIT3
513 #define RXSTATUS_ABORT BIT2
514 #define RXSTATUS_PARITY_ERROR BIT2
515 #define RXSTATUS_OVERRUN BIT1
516 #define RXSTATUS_DATA_AVAILABLE BIT0
517 #define RXSTATUS_ALL 0x01f6
518 #define usc_UnlatchRxstatusBits(a,b) usc_OutReg( (a), RCSR, (u16)((b) & RXSTATUS_ALL) )
524 #define IDLEMODE_FLAGS 0x0000
525 #define IDLEMODE_ALT_ONE_ZERO 0x0100
526 #define IDLEMODE_ZERO 0x0200
527 #define IDLEMODE_ONE 0x0300
528 #define IDLEMODE_ALT_MARK_SPACE 0x0500
529 #define IDLEMODE_SPACE 0x0600
530 #define IDLEMODE_MARK 0x0700
531 #define IDLEMODE_MASK 0x0700
536 #define IUSC_SL1660 0x4d44
537 #define IUSC_PRE_SL1660 0x4553
543 #define TCSR_PRESERVE 0x0F00
545 #define TCSR_UNDERWAIT BIT11
546 #define TXSTATUS_PREAMBLE_SENT BIT7
547 #define TXSTATUS_IDLE_SENT BIT6
548 #define TXSTATUS_ABORT_SENT BIT5
549 #define TXSTATUS_EOF_SENT BIT4
550 #define TXSTATUS_EOM_SENT BIT4
551 #define TXSTATUS_CRC_SENT BIT3
552 #define TXSTATUS_ALL_SENT BIT2
553 #define TXSTATUS_UNDERRUN BIT1
554 #define TXSTATUS_FIFO_EMPTY BIT0
555 #define TXSTATUS_ALL 0x00fa
556 #define usc_UnlatchTxstatusBits(a,b) usc_OutReg( (a), TCSR, (u16)((a)->tcsr_value + ((b) & 0x00FF)) )
559 #define MISCSTATUS_RXC_LATCHED BIT15
560 #define MISCSTATUS_RXC BIT14
561 #define MISCSTATUS_TXC_LATCHED BIT13
562 #define MISCSTATUS_TXC BIT12
563 #define MISCSTATUS_RI_LATCHED BIT11
564 #define MISCSTATUS_RI BIT10
565 #define MISCSTATUS_DSR_LATCHED BIT9
566 #define MISCSTATUS_DSR BIT8
567 #define MISCSTATUS_DCD_LATCHED BIT7
568 #define MISCSTATUS_DCD BIT6
569 #define MISCSTATUS_CTS_LATCHED BIT5
570 #define MISCSTATUS_CTS BIT4
571 #define MISCSTATUS_RCC_UNDERRUN BIT3
572 #define MISCSTATUS_DPLL_NO_SYNC BIT2
573 #define MISCSTATUS_BRG1_ZERO BIT1
574 #define MISCSTATUS_BRG0_ZERO BIT0
576 #define usc_UnlatchIostatusBits(a,b) usc_OutReg((a),MISR,(u16)((b) & 0xaaa0))
577 #define usc_UnlatchMiscstatusBits(a,b) usc_OutReg((a),MISR,(u16)((b) & 0x000f))
579 #define SICR_RXC_ACTIVE BIT15
580 #define SICR_RXC_INACTIVE BIT14
581 #define SICR_RXC (BIT15+BIT14)
582 #define SICR_TXC_ACTIVE BIT13
583 #define SICR_TXC_INACTIVE BIT12
584 #define SICR_TXC (BIT13+BIT12)
585 #define SICR_RI_ACTIVE BIT11
586 #define SICR_RI_INACTIVE BIT10
587 #define SICR_RI (BIT11+BIT10)
588 #define SICR_DSR_ACTIVE BIT9
589 #define SICR_DSR_INACTIVE BIT8
590 #define SICR_DSR (BIT9+BIT8)
591 #define SICR_DCD_ACTIVE BIT7
592 #define SICR_DCD_INACTIVE BIT6
593 #define SICR_DCD (BIT7+BIT6)
594 #define SICR_CTS_ACTIVE BIT5
595 #define SICR_CTS_INACTIVE BIT4
596 #define SICR_CTS (BIT5+BIT4)
597 #define SICR_RCC_UNDERFLOW BIT3
598 #define SICR_DPLL_NO_SYNC BIT2
599 #define SICR_BRG1_ZERO BIT1
600 #define SICR_BRG0_ZERO BIT0
608 #define usc_EnableInterrupts( a, b ) \
609 usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0xff00) + 0xc0 + (b)) )
611 #define usc_DisableInterrupts( a, b ) \
612 usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0xff00) + 0x80 + (b)) )
614 #define usc_EnableMasterIrqBit(a) \
615 usc_OutReg( (a), ICR, (u16)((usc_InReg((a),ICR) & 0x0f00) + 0xb000) )
617 #define usc_DisableMasterIrqBit(a) \
618 usc_OutReg( (a), ICR, (u16)(usc_InReg((a),ICR) & 0x7f00) )
620 #define usc_ClearIrqPendingBits( a, b ) usc_OutReg( (a), DCCR, 0x40 + (b) )
627 #define TXSTATUS_PREAMBLE_SENT BIT7
628 #define TXSTATUS_IDLE_SENT BIT6
629 #define TXSTATUS_ABORT_SENT BIT5
630 #define TXSTATUS_EOF BIT4
631 #define TXSTATUS_CRC_SENT BIT3
632 #define TXSTATUS_ALL_SENT BIT2
633 #define TXSTATUS_UNDERRUN BIT1
634 #define TXSTATUS_FIFO_EMPTY BIT0
636 #define DICR_MASTER BIT15
637 #define DICR_TRANSMIT BIT0
638 #define DICR_RECEIVE BIT1
640 #define usc_EnableDmaInterrupts(a,b) \
641 usc_OutDmaReg( (a), DICR, (u16)(usc_InDmaReg((a),DICR) | (b)) )
643 #define usc_DisableDmaInterrupts(a,b) \
644 usc_OutDmaReg( (a), DICR, (u16)(usc_InDmaReg((a),DICR) & ~(b)) )
646 #define usc_EnableStatusIrqs(a,b) \
647 usc_OutReg( (a), SICR, (u16)(usc_InReg((a),SICR) | (b)) )
649 #define usc_DisablestatusIrqs(a,b) \
650 usc_OutReg( (a), SICR, (u16)(usc_InReg((a),SICR) & ~(b)) )
656 #define DISABLE_UNCONDITIONAL 0
657 #define DISABLE_END_OF_FRAME 1
658 #define ENABLE_UNCONDITIONAL 2
659 #define ENABLE_AUTO_CTS 3
660 #define ENABLE_AUTO_DCD 3
661 #define usc_EnableTransmitter(a,b) \
662 usc_OutReg( (a), TMR, (u16)((usc_InReg((a),TMR) & 0xfffc) | (b)) )
663 #define usc_EnableReceiver(a,b) \
664 usc_OutReg( (a), RMR, (u16)((usc_InReg((a),RMR) & 0xfffc) | (b)) )
676 #define usc_TCmd(a,b) usc_OutReg((a), TCSR, (u16)((a)->tcsr_value + (b)))
677 #define usc_RCmd(a,b) usc_OutReg((a), RCSR, (b))
679 #define usc_SetTransmitSyncChars(a,s0,s1) usc_OutReg((a), TSR, (u16)(((u16)s0<<8)|(u16)s1))
705 static void mgsl_tx_timeout(
unsigned long context);
715 #if SYNCLINK_GENERIC_HDLC
716 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
728 #define BUS_DESCRIPTOR( WrHold, WrDly, RdDly, Nwdd, Nwad, Nxda, Nrdd, Nrad ) \
756 static struct mgsl_struct* mgsl_allocate_device(
void);
761 static void mgsl_free_rx_frame_buffers(
struct mgsl_struct *
info,
unsigned int StartIndex,
unsigned int EndIndex );
768 static void mgsl_load_pci_memory(
char* TargetPtr,
const char* SourcePtr,
unsigned short count);
779 static int mgsl_alloc_intermediate_rxbuffer_memory(
struct mgsl_struct *
info);
780 static void mgsl_free_intermediate_rxbuffer_memory(
struct mgsl_struct *
info);
781 static int mgsl_alloc_intermediate_txbuffer_memory(
struct mgsl_struct *
info);
782 static void mgsl_free_intermediate_txbuffer_memory(
struct mgsl_struct *
info);
814 mgsl_isr_transmit_data,
815 mgsl_isr_transmit_status,
816 mgsl_isr_receive_data,
817 mgsl_isr_receive_status
825 unsigned int set,
unsigned int clear);
827 __user *user_icount);
839 static bool pci_registered;
845 static int mgsl_device_count;
852 static bool break_on_load;
866 static int debug_level;
881 static char *
driver_name =
"SyncLink serial driver";
884 static int synclink_init_one (
struct pci_dev *
dev,
886 static void synclink_remove_one (
struct pci_dev *
dev);
897 static struct pci_driver synclink_pci_driver = {
899 .id_table = synclink_pci_tbl,
900 .probe = synclink_init_one,
907 #define WAKEUP_CHARS 256
911 static void mgsl_wait_until_sent(
struct tty_struct *tty,
int timeout);
919 static void* mgsl_get_text_ptr(
void)
921 return mgsl_get_text_ptr;
927 #ifdef MGSL_PARANOIA_CHECK
928 static const char *badmagic =
929 "Warning: bad magic number for mgsl struct (%s) in %s\n";
930 static const char *badinfo =
931 "Warning: null mgsl_struct for (%s) in %s\n";
934 printk(badinfo, name, routine);
938 printk(badmagic, name, routine);
957 static void ldisc_receive_buf(
struct tty_struct *tty,
965 if (ld->
ops->receive_buf)
966 ld->
ops->receive_buf(tty, data, flags, count);
981 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_stop"))
989 usc_stop_transmitter(info);
999 static void mgsl_start(
struct tty_struct *tty)
1002 unsigned long flags;
1004 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_start"))
1012 usc_start_transmitter(info);
1024 static int mgsl_bh_action(
struct mgsl_struct *info)
1026 unsigned long flags;
1066 printk(
"%s(%d):mgsl_bh_handler(%s) entry\n",
1071 while((action = mgsl_bh_action(info)) != 0) {
1075 printk(
"%s(%d):mgsl_bh_handler() work item action=%d\n",
1076 __FILE__,__LINE__,action);
1081 mgsl_bh_receive(info);
1084 mgsl_bh_transmit(info);
1087 mgsl_bh_status(info);
1091 printk(
"Unknown work item ID=%08X!\n", action);
1097 printk(
"%s(%d):mgsl_bh_handler(%s) exit\n",
1101 static void mgsl_bh_receive(
struct mgsl_struct *info)
1107 printk(
"%s(%d):mgsl_bh_receive(%s)\n",
1113 unsigned long flags;
1115 usc_start_receiver(info);
1119 }
while(get_rx_frame(info));
1122 static void mgsl_bh_transmit(
struct mgsl_struct *info)
1125 unsigned long flags;
1128 printk(
"%s(%d):mgsl_bh_transmit() entry on %s\n",
1139 usc_loopmode_send_done( info );
1143 static void mgsl_bh_status(
struct mgsl_struct *info)
1146 printk(
"%s(%d):mgsl_bh_status() entry on %s\n",
1164 static void mgsl_isr_receive_status(
struct mgsl_struct *info )
1169 printk(
"%s(%d):mgsl_isr_receive_status status=%04X\n",
1170 __FILE__,__LINE__,status);
1174 usc_loopmode_active(info) )
1184 usc_OutReg(info,
RICR,
1185 (usc_InReg(info,
RICR) & ~RXSTATUS_ABORT_RECEIVED));
1198 usc_process_rxoverrun_sync( info );
1216 static void mgsl_isr_transmit_status(
struct mgsl_struct *info )
1218 u16 status = usc_InReg( info,
TCSR );
1221 printk(
"%s(%d):mgsl_isr_transmit_status status=%04X\n",
1222 __FILE__,__LINE__,status);
1252 usc_get_serial_signals( info );
1255 usc_set_serial_signals( info );
1260 #if SYNCLINK_GENERIC_HDLC
1262 hdlcdev_tx_done(info);
1266 if (info->
port.tty->stopped || info->
port.tty->hw_stopped) {
1267 usc_stop_transmitter(info);
1283 static void mgsl_isr_io_pin(
struct mgsl_struct *info )
1286 u16 status = usc_InReg( info,
MISR );
1289 printk(
"%s(%d):mgsl_isr_io_pin status=%04X\n",
1290 __FILE__,__LINE__,status);
1325 #if SYNCLINK_GENERIC_HDLC
1327 if (status & MISCSTATUS_DCD)
1348 (status & MISCSTATUS_DCD_LATCHED) ) {
1351 (status & MISCSTATUS_DCD) ?
"on" :
"off");
1352 if (status & MISCSTATUS_DCD)
1356 printk(
"doing serial hangup...");
1362 if (tty_port_cts_enabled(&info->
port) &&
1363 (status & MISCSTATUS_CTS_LATCHED) ) {
1364 if (info->
port.tty->hw_stopped) {
1367 printk(
"CTS tx start...");
1369 info->
port.tty->hw_stopped = 0;
1370 usc_start_transmitter(info);
1375 if (!(status & MISCSTATUS_CTS)) {
1377 printk(
"CTS tx stop...");
1379 info->
port.tty->hw_stopped = 1;
1380 usc_stop_transmitter(info);
1390 usc_OutReg( info,
SICR,
1405 static void mgsl_isr_transmit_data(
struct mgsl_struct *info )
1408 printk(
"%s(%d):mgsl_isr_transmit_data xmit_cnt=%d\n",
1413 if (info->
port.tty->stopped || info->
port.tty->hw_stopped) {
1414 usc_stop_transmitter(info);
1419 usc_load_txfifo( info );
1437 static void mgsl_isr_receive_data(
struct mgsl_struct *info )
1442 unsigned char DataByte;
1447 printk(
"%s(%d):mgsl_isr_receive_data\n",
1461 while( (Fifocount = (usc_InReg(info,
RICR) >> 8)) ) {
1470 status = usc_InReg(info,
RCSR);
1480 printk(
"rxerr=%04X\n",status);
1502 if (status & RXSTATUS_BREAK_RECEIVED) {
1506 }
else if (status & RXSTATUS_PARITY_ERROR)
1508 else if (status & RXSTATUS_FRAMING_ERROR)
1511 tty_insert_flip_char(tty, DataByte, flag);
1512 if (status & RXSTATUS_OVERRUN) {
1517 work += tty_insert_flip_char(tty, 0,
TTY_OVERRUN);
1522 printk(
"%s(%d):rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
1523 __FILE__,__LINE__,icount->
rx,icount->
brk,
1538 static void mgsl_isr_misc(
struct mgsl_struct *info )
1540 u16 status = usc_InReg( info,
MISR );
1543 printk(
"%s(%d):mgsl_isr_misc status=%04X\n",
1544 __FILE__,__LINE__,status);
1574 static void mgsl_isr_null(
struct mgsl_struct *info )
1598 static void mgsl_isr_receive_dma(
struct mgsl_struct *info )
1607 status = usc_InDmaReg( info,
RDMR );
1610 printk(
"%s(%d):mgsl_isr_receive_dma(%s) status=%04X\n",
1615 if ( status &
BIT3 ) {
1617 info->
icount.buf_overrun++;
1642 static void mgsl_isr_transmit_dma(
struct mgsl_struct *info )
1652 status = usc_InDmaReg( info,
TDMR );
1655 printk(
"%s(%d):mgsl_isr_transmit_dma(%s) status=%04X\n",
1658 if ( status &
BIT2 ) {
1664 if ( load_next_tx_holding_buffer(info) ) {
1699 UscVector = usc_InReg(info,
IVR) >> 9;
1700 DmaVector = usc_InDmaReg(info,
DIVR);
1703 printk(
"%s(%d):%s UscVector=%08X DmaVector=%08X\n",
1704 __FILE__,__LINE__,info->
device_name,UscVector,DmaVector);
1706 if ( !UscVector && !DmaVector )
1711 (*UscIsrTable[UscVector])(info);
1713 mgsl_isr_transmit_dma(info);
1715 mgsl_isr_receive_dma(info);
1732 printk(
"%s(%d):%s queueing bh task.\n",
1781 retval = mgsl_claim_resources(info);
1785 retval = mgsl_adapter_test(info);
1790 mgsl_release_resources(info);
1795 mgsl_change_params(info);
1815 unsigned long flags;
1821 printk(
"%s(%d):mgsl_shutdown(%s)\n",
1838 usc_stop_receiver(info);
1839 usc_stop_transmitter(info);
1854 if (!info->
port.tty || info->
port.tty->termios.c_cflag &
HUPCL) {
1856 usc_set_serial_signals(info);
1861 mgsl_release_resources(info);
1870 static void mgsl_program_hw(
struct mgsl_struct *info)
1872 unsigned long flags;
1876 usc_stop_receiver(info);
1877 usc_stop_transmitter(info);
1883 usc_set_sync_mode(info);
1885 usc_set_async_mode(info);
1887 usc_set_serial_signals(info);
1896 usc_get_serial_signals(info);
1899 usc_start_receiver(info);
1906 static void mgsl_change_params(
struct mgsl_struct *info)
1911 if (!info->
port.tty)
1915 printk(
"%s(%d):mgsl_change_params(%s)\n",
1918 cflag = info->
port.tty->termios.c_cflag;
1929 switch (cflag &
CSIZE) {
2003 mgsl_program_hw(info);
2016 static int mgsl_put_char(
struct tty_struct *tty,
unsigned char ch)
2019 unsigned long flags;
2027 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_put_char"))
2056 static void mgsl_flush_chars(
struct tty_struct *tty)
2059 unsigned long flags;
2062 printk(
"%s(%d):mgsl_flush_chars() entry on %s xmit_cnt=%d\n",
2065 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_flush_chars"))
2073 printk(
"%s(%d):mgsl_flush_chars() entry on %s starting transmitter\n",
2084 mgsl_load_tx_dma_buffer(info,
2087 usc_start_transmitter(info);
2106 static int mgsl_write(
struct tty_struct * tty,
2107 const unsigned char *
buf,
int count)
2111 unsigned long flags;
2114 printk(
"%s(%d):mgsl_write(%s) count=%d\n",
2117 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_write"))
2145 save_tx_buffer_request(info,buf,count);
2151 load_next_tx_holding_buffer(info);
2161 !usc_loopmode_active(info) )
2174 mgsl_load_tx_dma_buffer(info,
2177 printk(
"%s(%d):mgsl_write(%s) sync xmit_cnt flushing\n",
2181 printk(
"%s(%d):mgsl_write(%s) sync transmit accepted\n",
2185 mgsl_load_tx_dma_buffer(info,buf,count);
2190 c =
min_t(
int, count,
2211 usc_start_transmitter(info);
2216 printk(
"%s(%d):mgsl_write(%s) returning=%d\n",
2230 static int mgsl_write_room(
struct tty_struct *tty)
2235 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_write_room"))
2242 printk(
"%s(%d):mgsl_write_room(%s)=%d\n",
2265 static int mgsl_chars_in_buffer(
struct tty_struct *tty)
2270 printk(
"%s(%d):mgsl_chars_in_buffer(%s)\n",
2273 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_chars_in_buffer"))
2277 printk(
"%s(%d):mgsl_chars_in_buffer(%s)=%d\n",
2299 static void mgsl_flush_buffer(
struct tty_struct *tty)
2302 unsigned long flags;
2305 printk(
"%s(%d):mgsl_flush_buffer(%s) entry\n",
2308 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_flush_buffer"))
2327 static void mgsl_send_xchar(
struct tty_struct *tty,
char ch)
2330 unsigned long flags;
2333 printk(
"%s(%d):mgsl_send_xchar(%s,%d)\n",
2336 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_send_xchar"))
2344 usc_start_transmitter(info);
2356 static void mgsl_throttle(
struct tty_struct * tty)
2359 unsigned long flags;
2362 printk(
"%s(%d):mgsl_throttle(%s) entry\n",
2365 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_throttle"))
2371 if (tty->termios.c_cflag & CRTSCTS) {
2374 usc_set_serial_signals(info);
2386 static void mgsl_unthrottle(
struct tty_struct * tty)
2389 unsigned long flags;
2392 printk(
"%s(%d):mgsl_unthrottle(%s) entry\n",
2395 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_unthrottle"))
2405 if (tty->termios.c_cflag & CRTSCTS) {
2408 usc_set_serial_signals(info);
2428 printk(
"%s(%d):mgsl_get_params(%s)\n",
2458 printk(
"%s(%d):mgsl_get_params(%s)\n",
2466 printk(
"%s(%d):mgsl_get_params(%s) user buffer copy failed\n",
2488 unsigned long flags;
2493 printk(
"%s(%d):mgsl_set_params %s\n", __FILE__,__LINE__,
2498 printk(
"%s(%d):mgsl_set_params(%s) user buffer copy failed\n",
2508 mgsl_change_params(info);
2529 printk(
"%s(%d):mgsl_get_txidle(%s)=%d\n",
2535 printk(
"%s(%d):mgsl_get_txidle(%s) user buffer copy failed\n",
2551 static int mgsl_set_txidle(
struct mgsl_struct * info,
int idle_mode)
2553 unsigned long flags;
2556 printk(
"%s(%d):mgsl_set_txidle(%s,%d)\n", __FILE__,__LINE__,
2561 usc_set_txidle( info );
2580 unsigned long flags;
2583 printk(
"%s(%d):mgsl_txenable(%s,%d)\n", __FILE__,__LINE__,
2590 usc_start_transmitter(info);
2599 usc_loopmode_insert_request( info );
2603 usc_stop_transmitter(info);
2615 static int mgsl_txabort(
struct mgsl_struct * info)
2617 unsigned long flags;
2620 printk(
"%s(%d):mgsl_txabort(%s)\n", __FILE__,__LINE__,
2627 usc_loopmode_cancel_transmit( info );
2642 static int mgsl_rxenable(
struct mgsl_struct * info,
int enable)
2644 unsigned long flags;
2647 printk(
"%s(%d):mgsl_rxenable(%s,%d)\n", __FILE__,__LINE__,
2653 usc_start_receiver(info);
2656 usc_stop_receiver(info);
2671 static int mgsl_wait_event(
struct mgsl_struct * info,
int __user * mask_ptr)
2673 unsigned long flags;
2688 printk(
"%s(%d):mgsl_wait_event(%s,%d)\n", __FILE__,__LINE__,
2694 usc_get_serial_signals(info);
2712 u16 oldreg = usc_InReg(info,
RICR);
2713 u16 newreg = oldreg +
2716 if (oldreg != newreg)
2717 usc_OutReg(info,
RICR, newreg);
2728 if (signal_pending(
current)) {
2741 if (newsigs.dsr_up == oldsigs.dsr_up &&
2742 newsigs.dsr_down == oldsigs.dsr_down &&
2743 newsigs.dcd_up == oldsigs.dcd_up &&
2744 newsigs.dcd_down == oldsigs.dcd_down &&
2745 newsigs.cts_up == oldsigs.cts_up &&
2746 newsigs.cts_down == oldsigs.cts_down &&
2747 newsigs.ri_up == oldsigs.ri_up &&
2748 newsigs.ri_down == oldsigs.ri_down &&
2749 cnow.exithunt == cprev.exithunt &&
2750 cnow.rxidle == cprev.rxidle) {
2759 (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
2761 (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
2763 (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
2780 usc_OutReg(info,
RICR, usc_InReg(info,
RICR) &
2795 unsigned long flags;
2809 if (signal_pending(
current)) {
2821 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
2822 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
2828 if ((arg &
TIOCM_RNG && cnow.rng != cprev.rng) ||
2829 (arg &
TIOCM_DSR && cnow.dsr != cprev.dsr) ||
2830 (arg &
TIOCM_CD && cnow.dcd != cprev.dcd) ||
2831 (arg &
TIOCM_CTS && cnow.cts != cprev.cts)) {
2849 unsigned long flags;
2852 usc_get_serial_signals(info);
2863 printk(
"%s(%d):%s tiocmget() value=%08X\n",
2871 unsigned int set,
unsigned int clear)
2874 unsigned long flags;
2877 printk(
"%s(%d):%s tiocmset(%x,%x)\n",
2882 if (
set & TIOCM_DTR)
2886 if (clear & TIOCM_DTR)
2890 usc_set_serial_signals(info);
2902 static int mgsl_break(
struct tty_struct *tty,
int break_state)
2905 unsigned long flags;
2908 printk(
"%s(%d):mgsl_break(%s,%d)\n",
2909 __FILE__,__LINE__, info->
device_name, break_state);
2911 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_break"))
2915 if (break_state == -1)
2930 static int msgl_get_icount(
struct tty_struct *tty,
2936 unsigned long flags;
2942 icount->
cts = cnow.cts;
2943 icount->
dsr = cnow.dsr;
2944 icount->
rng = cnow.rng;
2945 icount->
dcd = cnow.dcd;
2946 icount->
rx = cnow.rx;
2947 icount->
tx = cnow.tx;
2948 icount->
frame = cnow.frame;
2949 icount->
overrun = cnow.overrun;
2950 icount->
parity = cnow.parity;
2951 icount->
brk = cnow.brk;
2966 static int mgsl_ioctl(
struct tty_struct *tty,
2967 unsigned int cmd,
unsigned long arg)
2972 printk(
"%s(%d):mgsl_ioctl %s cmd=%08X\n", __FILE__,__LINE__,
2975 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_ioctl"))
2984 return mgsl_ioctl_common(info, cmd, arg);
2987 static int mgsl_ioctl_common(
struct mgsl_struct *info,
unsigned int cmd,
unsigned long arg)
2993 return mgsl_get_params(info, argp);
2995 return mgsl_set_params(info, argp);
2997 return mgsl_get_txidle(info, argp);
2999 return mgsl_set_txidle(info,(
int)arg);
3001 return mgsl_txenable(info,(
int)arg);
3003 return mgsl_rxenable(info,(
int)arg);
3005 return mgsl_txabort(info);
3007 return mgsl_get_stats(info, argp);
3009 return mgsl_wait_event(info, argp);
3011 return mgsl_loopmode_send_done(info);
3016 return modem_input_wait(info,(
int)arg);
3038 unsigned long flags;
3041 printk(
"%s(%d):mgsl_set_termios %s\n", __FILE__,__LINE__,
3044 mgsl_change_params(info);
3047 if (old_termios->
c_cflag & CBAUD &&
3048 !(tty->termios.c_cflag & CBAUD)) {
3051 usc_set_serial_signals(info);
3056 if (!(old_termios->
c_cflag & CBAUD) &&
3057 tty->termios.c_cflag & CBAUD) {
3059 if (!(tty->termios.c_cflag & CRTSCTS) ||
3064 usc_set_serial_signals(info);
3069 if (old_termios->
c_cflag & CRTSCTS &&
3070 !(tty->termios.c_cflag & CRTSCTS)) {
3089 static void mgsl_close(
struct tty_struct *tty,
struct file * filp)
3093 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_close"))
3097 printk(
"%s(%d):mgsl_close(%s) entry, count=%d\n",
3105 mgsl_wait_until_sent(tty, info->
timeout);
3106 mgsl_flush_buffer(tty);
3115 printk(
"%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
3134 unsigned long orig_jiffies, char_time;
3140 printk(
"%s(%d):mgsl_wait_until_sent(%s) entry\n",
3143 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_wait_until_sent"))
3158 char_time = info->
timeout/(32 * 5);
3165 char_time =
min_t(
unsigned long, char_time, timeout);
3173 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
3182 if (timeout &&
time_after(jiffies, orig_jiffies + timeout))
3189 printk(
"%s(%d):mgsl_wait_until_sent(%s) exit\n",
3202 static void mgsl_hangup(
struct tty_struct *tty)
3207 printk(
"%s(%d):mgsl_hangup(%s)\n",
3210 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_hangup"))
3213 mgsl_flush_buffer(tty);
3216 info->
port.count = 0;
3232 unsigned long flags;
3236 usc_get_serial_signals(info);
3241 static void dtr_rts(
struct tty_port *port,
int on)
3244 unsigned long flags;
3251 usc_set_serial_signals(info);
3269 static int block_til_ready(
struct tty_struct *tty,
struct file * filp,
3274 bool do_clocal =
false;
3275 bool extra_count =
false;
3276 unsigned long flags;
3281 printk(
"%s(%d):block_til_ready on %s\n",
3282 __FILE__,__LINE__, tty->
driver->name );
3290 if (tty->termios.c_cflag & CLOCAL)
3304 printk(
"%s(%d):block_til_ready before block on %s count=%d\n",
3305 __FILE__,__LINE__, tty->
driver->name, port->
count );
3316 if (tty->termios.c_cflag & CBAUD)
3332 if (signal_pending(
current)) {
3338 printk(
"%s(%d):block_til_ready blocking on %s count=%d\n",
3339 __FILE__,__LINE__, tty->
driver->name, port->
count );
3355 printk(
"%s(%d):block_til_ready after blocking on %s count=%d\n",
3356 __FILE__,__LINE__, tty->
driver->name, port->
count );
3371 if (line >= mgsl_device_count) {
3372 printk(
"%s(%d):mgsl_open with invalid line #%d.\n",
3373 __FILE__, __LINE__, line);
3378 info = mgsl_device_list;
3379 while (info && info->
line != line)
3381 if (mgsl_paranoia_check(info, tty->
name,
"mgsl_open"))
3401 unsigned long flags;
3404 info->
port.tty = tty;
3407 printk(
"%s(%d):mgsl_open(%s), old ref count = %d\n",
3408 __FILE__,__LINE__,tty->
driver->name, info->
port.count);
3424 spin_unlock_irqrestore(&info->
netlock, flags);
3428 spin_unlock_irqrestore(&info->
netlock, flags);
3430 if (info->
port.count == 1) {
3432 retval = startup(info);
3437 retval = block_til_ready(tty, filp, info);
3440 printk(
"%s(%d):block_til_ready(%s) returned %d\n",
3446 printk(
"%s(%d):mgsl_open(%s) success\n",
3452 if (tty->
count == 1)
3454 if(info->
port.count)
3469 unsigned long flags;
3472 seq_printf(m,
"%s:PCI io:%04X irq:%d mem:%08X lcr:%08X",
3476 seq_printf(m,
"%s:(E)ISA io:%04X irq:%d dma:%d",
3483 usc_get_serial_signals(info);
3489 strcat(stat_buf,
"|RTS");
3491 strcat(stat_buf,
"|CTS");
3493 strcat(stat_buf,
"|DTR");
3495 strcat(stat_buf,
"|DSR");
3505 if (info->
icount.txunder)
3507 if (info->
icount.txabort)
3509 if (info->
icount.rxshort)
3526 if (info->
icount.overrun)
3533 seq_printf(m,
"txactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
3539 u16 Tcsr = usc_InReg( info,
TCSR );
3540 u16 Tdmr = usc_InDmaReg( info,
TDMR );
3541 u16 Ticr = usc_InReg( info,
TICR );
3542 u16 Rscr = usc_InReg( info,
RCSR );
3543 u16 Rdmr = usc_InDmaReg( info,
RDMR );
3544 u16 Ricr = usc_InReg( info,
RICR );
3545 u16 Icr = usc_InReg( info,
ICR );
3546 u16 Dccr = usc_InReg( info,
DCCR );
3547 u16 Tmr = usc_InReg( info,
TMR );
3548 u16 Tccr = usc_InReg( info,
TCCR );
3550 seq_printf(m,
"tcsr=%04X tdmr=%04X ticr=%04X rcsr=%04X rdmr=%04X\n"
3551 "ricr=%04X icr =%04X dccr=%04X tmr=%04X tccr=%04X ccar=%04X\n",
3552 Tcsr,Tdmr,Ticr,Rscr,Rdmr,Ricr,Icr,Dccr,Tmr,Tccr,Ccar );
3558 static int mgsl_proc_show(
struct seq_file *m,
void *
v)
3562 seq_printf(m,
"synclink driver:%s\n", driver_version);
3564 info = mgsl_device_list;
3579 .open = mgsl_proc_open,
3593 static int mgsl_allocate_dma_buffers(
struct mgsl_struct *info)
3595 unsigned short BuffersPerFrame;
3658 printk(
"%s(%d):Allocating %d TX and %d RX DMA buffers.\n",
3661 if ( mgsl_alloc_buffer_list_memory( info ) < 0 ||
3664 mgsl_alloc_intermediate_rxbuffer_memory(info) < 0 ||
3665 mgsl_alloc_intermediate_txbuffer_memory(info) < 0 ) {
3666 printk(
"%s(%d):Can't allocate DMA buffer memory\n",__FILE__,__LINE__);
3670 mgsl_reset_rx_dma_buffers( info );
3671 mgsl_reset_tx_dma_buffers( info );
3700 static int mgsl_alloc_buffer_list_memory(
struct mgsl_struct *info )
3752 if ( i < info->rx_buffer_count - 1 )
3767 if ( i < info->tx_buffer_count - 1 )
3784 static void mgsl_free_buffer_list_memory(
struct mgsl_struct *info )
3818 for ( i = 0; i < Buffercount; i++ ) {
3827 if (BufferList[i].virt_addr ==
NULL)
3857 for ( i = 0 ; i < Buffercount ; i++ ) {
3858 if ( BufferList[i].virt_addr ) {
3875 static void mgsl_free_dma_buffers(
struct mgsl_struct *info )
3879 mgsl_free_buffer_list_memory( info );
3896 static int mgsl_alloc_intermediate_rxbuffer_memory(
struct mgsl_struct *info)
3916 static void mgsl_free_intermediate_rxbuffer_memory(
struct mgsl_struct *info)
3936 static int mgsl_alloc_intermediate_txbuffer_memory(
struct mgsl_struct *info)
3941 printk(
"%s %s(%d) allocating %d tx holding buffers\n",
3950 for (--i; i >= 0; i--) {
3972 static void mgsl_free_intermediate_txbuffer_memory(
struct mgsl_struct *info)
4002 static bool load_next_tx_holding_buffer(
struct mgsl_struct *info)
4012 int num_free = num_free_tx_dma_buffers(info);
4017 if (num_needed <= num_free) {
4048 static int save_tx_buffer_request(
struct mgsl_struct *info,
const char *Buffer,
unsigned int BufferSize)
4067 static int mgsl_claim_resources(
struct mgsl_struct *info)
4070 printk(
"%s(%d):I/O address conflict on device %s Addr=%08X\n",
4078 printk(
"%s(%d):Can't request interrupt on device %s IRQ=%d\n",
4086 printk(
"%s(%d):mem addr conflict device %s Addr=%08X\n",
4092 printk(
"%s(%d):lcr mem addr conflict device %s Addr=%08X\n",
4101 printk(
"%s(%d):Can't map shared memory on device %s MemAddr=%08X\n",
4106 if ( !mgsl_memory_test(info) ) {
4107 printk(
"%s(%d):Failed shared memory test %s MemAddr=%08X\n",
4115 printk(
"%s(%d):Can't map LCR memory on device %s MemAddr=%08X\n",
4125 printk(
"%s(%d):Can't request DMA channel on device %s DMA=%d\n",
4127 mgsl_release_resources( info );
4137 if ( mgsl_allocate_dma_buffers(info) < 0 ) {
4138 printk(
"%s(%d):Can't allocate DMA buffers on device %s DMA=%d\n",
4145 mgsl_release_resources(info);
4150 static void mgsl_release_resources(
struct mgsl_struct *info)
4153 printk(
"%s(%d):mgsl_release_resources(%s) entry\n",
4165 mgsl_free_dma_buffers(info);
4166 mgsl_free_intermediate_rxbuffer_memory(info);
4167 mgsl_free_intermediate_txbuffer_memory(info);
4191 printk(
"%s(%d):mgsl_release_resources(%s) exit\n",
4204 static void mgsl_add_device(
struct mgsl_struct *info )
4207 info->
line = mgsl_device_count;
4211 if (maxframe[info->
line])
4214 if (txdmabufs[info->
line]) {
4220 if (txholdbufs[info->
line]) {
4229 mgsl_device_count++;
4231 if ( !mgsl_device_list )
4232 mgsl_device_list =
info;
4234 struct mgsl_struct *current_dev = mgsl_device_list;
4246 printk(
"SyncLink PCI v%d %s: IO=%04X IRQ=%d Mem=%08X,%08X MaxFrameSize=%u\n",
4251 printk(
"SyncLink ISA %s: IO=%04X IRQ=%d DMA=%d MaxFrameSize=%u\n",
4256 #if SYNCLINK_GENERIC_HDLC
4275 static struct mgsl_struct* mgsl_allocate_device(
void)
4283 printk(
"Error can't allocate device instance data\n");
4286 info->
port.ops = &mgsl_port_ops;
4290 info->
port.close_delay = 5*
HZ/10;
4291 info->
port.closing_wait = 30*
HZ;
4307 .install = mgsl_install,
4309 .close = mgsl_close,
4310 .write = mgsl_write,
4311 .put_char = mgsl_put_char,
4312 .flush_chars = mgsl_flush_chars,
4313 .write_room = mgsl_write_room,
4314 .chars_in_buffer = mgsl_chars_in_buffer,
4315 .flush_buffer = mgsl_flush_buffer,
4316 .ioctl = mgsl_ioctl,
4317 .throttle = mgsl_throttle,
4318 .unthrottle = mgsl_unthrottle,
4319 .send_xchar = mgsl_send_xchar,
4320 .break_ctl = mgsl_break,
4321 .wait_until_sent = mgsl_wait_until_sent,
4322 .set_termios = mgsl_set_termios,
4324 .start = mgsl_start,
4325 .hangup = mgsl_hangup,
4328 .get_icount = msgl_get_icount,
4329 .proc_fops = &mgsl_proc_fops,
4335 static int mgsl_init_tty(
void)
4339 serial_driver = alloc_tty_driver(128);
4344 serial_driver->
name =
"ttySL";
4345 serial_driver->
major = ttymajor;
4357 printk(
"%s(%d):Couldn't register serial driver\n",
4360 serial_driver =
NULL;
4364 printk(
"%s %s, tty major#%d\n",
4366 serial_driver->
major);
4372 static void mgsl_enum_isa_devices(
void)
4381 printk(
"ISA device specified io=%04X,irq=%d,dma=%d\n",
4382 io[i], irq[i],
dma[i] );
4384 info = mgsl_allocate_device();
4388 printk(
"can't allocate device instance data.\n");
4401 mgsl_add_device( info );
4405 static void synclink_cleanup(
void)
4413 if (serial_driver) {
4415 printk(
"%s(%d) failed to unregister tty driver err=%d\n",
4416 __FILE__,__LINE__,rc);
4420 info = mgsl_device_list;
4422 #if SYNCLINK_GENERIC_HDLC
4425 mgsl_release_resources(info);
4435 static int __init synclink_init(
void)
4439 if (break_on_load) {
4440 mgsl_get_text_ptr();
4446 mgsl_enum_isa_devices();
4447 if ((rc = pci_register_driver(&synclink_pci_driver)) < 0)
4448 printk(
"%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
4450 pci_registered =
true;
4452 if ((rc = mgsl_init_tty()) < 0)
4462 static void __exit synclink_exit(
void)
4545 static void usc_OutDmaReg(
struct mgsl_struct *info,
u16 RegAddr,
u16 RegValue )
4640 static void usc_set_sdlc_mode(
struct mgsl_struct *info )
4654 usc_OutReg(info,
TMCR,0x1f);
4655 RegValue=usc_InReg(info,
TMDR);
4695 usc_OutReg( info,
IOCR,
4739 usc_OutReg( info,
CMR, RegValue );
4774 usc_OutReg( info,
RMR, RegValue );
4805 RegValue = usc_InReg( info,
RICR ) & 0xc0;
4808 usc_OutReg( info,
RICR, (
u16)(0x030a | RegValue) );
4810 usc_OutReg( info,
RICR, (
u16)(0x140a | RegValue) );
4849 usc_OutReg( info,
TMR, RegValue );
4851 usc_set_txidle( info );
4872 usc_OutReg( info,
TICR, 0x0736 );
4874 usc_OutReg( info,
TICR, 0x1436 );
4936 usc_OutReg( info,
CMCR, RegValue );
4965 XtalSpeed = 11059200;
4967 XtalSpeed = 14745600;
5006 usc_OutReg( info,
TC1R, Tc );
5022 usc_OutReg( info,
HCR, RegValue );
5043 usc_OutReg( info,
CCSR, 0x1020 );
5047 usc_OutReg( info,
SICR,
5098 usc_OutDmaReg( info,
DCR, 0xa00b );
5101 usc_OutDmaReg( info,
DCR, 0x800b );
5117 usc_OutDmaReg( info,
RDMR, 0xf200 );
5133 usc_OutDmaReg( info,
TDMR, 0xf200 );
5149 usc_OutDmaReg( info,
DICR, 0x9000 );
5151 usc_InDmaReg( info,
RDMR );
5152 usc_InDmaReg( info,
TDMR );
5153 usc_OutDmaReg( info,
CDIR, 0x0303 );
5184 usc_OutReg( info,
CCR, RegValue );
5196 usc_OutDmaReg( info,
BDCR, 0x0000 );
5199 usc_OutDmaReg( info,
BDCR, 0x2000 );
5201 usc_stop_transmitter(info);
5202 usc_stop_receiver(info);
5216 static void usc_enable_loopback(
struct mgsl_struct *info,
int enable)
5235 usc_OutReg( info,
CMCR, 0x0f64 );
5245 usc_OutReg(info,
TC0R, (
u16)8);
5252 usc_OutReg(info,
IOCR, (
u16)((usc_InReg(info,
IOCR) & 0xfff8) | 0x0004));
5280 static void usc_enable_aux_clock(
struct mgsl_struct *info,
u32 data_rate )
5287 XtalSpeed = 11059200;
5289 XtalSpeed = 14745600;
5299 Tc = (
u16)(XtalSpeed/data_rate);
5300 if ( !(((XtalSpeed % data_rate) * 2) / data_rate) )
5304 usc_OutReg( info,
TC0R, Tc );
5315 usc_OutReg( info,
IOCR, (
u16)((usc_InReg(info,
IOCR) & 0xfff8) | 0x0004) );
5318 usc_OutReg( info,
HCR, (
u16)(usc_InReg( info,
HCR ) & ~
BIT0) );
5337 static void usc_process_rxoverrun_sync(
struct mgsl_struct *info )
5341 int frame_start_index;
5342 bool start_of_frame_found =
false;
5343 bool end_of_frame_found =
false;
5344 bool reprogram_dma =
false;
5363 while( !buffer_list[end_index].count )
5368 if ( !start_of_frame_found )
5370 start_of_frame_found =
true;
5371 frame_start_index = end_index;
5372 end_of_frame_found =
false;
5375 if ( buffer_list[end_index].status )
5383 start_of_frame_found =
false;
5384 end_of_frame_found =
true;
5392 if ( start_index == end_index )
5397 mgsl_reset_rx_dma_buffers( info );
5398 frame_start_index = 0;
5399 start_of_frame_found =
false;
5400 reprogram_dma =
true;
5405 if ( start_of_frame_found && !end_of_frame_found )
5414 start_index = frame_start_index;
5424 }
while( start_index != end_index );
5426 reprogram_dma =
true;
5429 if ( reprogram_dma )
5442 usc_OutDmaReg( info,
NRARL, (
u16)phys_addr );
5443 usc_OutDmaReg( info,
NRARU, (
u16)(phys_addr >> 16) );
5452 usc_OutDmaReg( info,
RDIAR,
BIT3 + BIT2 );
5476 static void usc_stop_receiver(
struct mgsl_struct *info )
5479 printk(
"%s(%d):usc_stop_receiver(%s)\n",
5509 static void usc_start_receiver(
struct mgsl_struct *info )
5514 printk(
"%s(%d):usc_start_receiver(%s)\n",
5517 mgsl_reset_rx_dma_buffers( info );
5518 usc_stop_receiver( info );
5531 usc_OutDmaReg( info,
NRARL, (
u16)phys_addr );
5532 usc_OutDmaReg( info,
NRARU, (
u16)(phys_addr >> 16) );
5541 usc_OutDmaReg( info,
RDIAR,
BIT3 + BIT2 );
5559 usc_OutReg( info,
CCSR, 0x1020 );
5573 static void usc_start_transmitter(
struct mgsl_struct *info )
5576 unsigned int FrameSize;
5579 printk(
"%s(%d):usc_start_transmitter(%s)\n",
5591 usc_get_serial_signals( info );
5594 usc_set_serial_signals( info );
5605 usc_load_txfifo(info);
5625 usc_OutReg( info,
TCLR, (
u16)FrameSize );
5631 usc_OutDmaReg( info,
NTARL, (
u16)phys_addr );
5632 usc_OutDmaReg( info,
NTARU, (
u16)(phys_addr >> 16) );
5647 usc_OutDmaReg( info,
TDIAR, BIT2|
BIT3 );
5679 static void usc_stop_transmitter(
struct mgsl_struct *info )
5682 printk(
"%s(%d):usc_stop_transmitter(%s)\n",
5708 static void usc_load_txfifo(
struct mgsl_struct *info )
5721 while( (Fifocount = usc_InReg(info,
TICR) >> 8) && info->
xmit_cnt ) {
5725 if ( (info->
xmit_cnt > 1) && (Fifocount > 1) && !info->
x_char ) {
5786 readval = *MiscCtrl;
5851 usc_OutReg( info,
PCR, 0xf0f5 );
5868 usc_OutReg( info,
IOCR, 0x0004 );
5879 static void usc_set_async_mode(
struct mgsl_struct *info )
5889 usc_loopback_frame( info );
5906 usc_OutReg( info,
CMR, RegValue );
5932 usc_OutReg( info,
RMR, RegValue );
5960 usc_OutReg( info,
RICR, 0x0000 );
5989 usc_OutReg( info,
TMR, RegValue );
5991 usc_set_txidle( info );
6014 usc_OutReg( info,
TICR, 0x1f40 );
6040 usc_OutReg( info,
CCSR, 0x0020 );
6077 static void usc_loopback_frame(
struct mgsl_struct *info )
6086 usc_set_sdlc_mode( info );
6087 usc_enable_loopback( info, 1 );
6090 usc_OutReg( info,
TC0R, 0 );
6106 usc_OutReg( info,
CCR, 0x0100 );
6115 usc_OutReg( info,
TCLR, 2 );
6127 for (i=0 ; i<1000 ; i++)
6132 usc_enable_loopback(info, 0);
6145 static void usc_set_sync_mode(
struct mgsl_struct *info )
6147 usc_loopback_frame( info );
6148 usc_set_sdlc_mode( info );
6159 usc_enable_loopback(info,1);
6168 static void usc_set_txidle(
struct mgsl_struct *info )
6198 unsigned char syncpat = 0;
6231 static void usc_get_serial_signals(
struct mgsl_struct *info )
6241 status = usc_InReg( info,
MISR );
6245 if ( status & MISCSTATUS_CTS )
6248 if ( status & MISCSTATUS_DCD )
6267 static void usc_set_serial_signals(
struct mgsl_struct *info )
6274 Control = usc_InReg( info,
PCR );
6276 if ( V24Out & SerialSignal_RTS )
6281 if ( V24Out & SerialSignal_DTR )
6286 usc_OutReg( info,
PCR, Control );
6299 static void usc_enable_async_clock(
struct mgsl_struct *info,
u32 data_rate )
6316 usc_OutReg( info,
CMCR, 0x0f64 );
6326 usc_OutReg( info,
TC0R, (
u16)((691200/data_rate) - 1) );
6328 usc_OutReg( info,
TC0R, (
u16)((921600/data_rate) - 1) );
6337 usc_OutReg( info,
HCR,
6343 usc_OutReg( info,
IOCR,
6344 (
u16)((usc_InReg(info,
IOCR) & 0xfff8) | 0x0004) );
6347 usc_OutReg( info,
HCR, (
u16)(usc_InReg( info,
HCR ) & ~
BIT0) );
6409 static void mgsl_reset_tx_dma_buffers(
struct mgsl_struct *info )
6435 static int num_free_tx_dma_buffers(
struct mgsl_struct *info)
6450 static void mgsl_reset_rx_dma_buffers(
struct mgsl_struct *info )
6478 static void mgsl_free_rx_frame_buffers(
struct mgsl_struct *info,
unsigned int StartIndex,
unsigned int EndIndex )
6492 if ( Index == EndIndex ) {
6521 static bool mgsl_get_rx_frame(
struct mgsl_struct *info)
6523 unsigned int StartIndex, EndIndex;
6526 unsigned int framesize = 0;
6527 bool ReturnCode =
false;
6528 unsigned long flags;
6530 bool return_frame =
false;
6558 if ( EndIndex == StartIndex ) {
6566 usc_start_receiver(info);
6584 else if ( status & RXSTATUS_OVERRUN )
6589 return_frame =
true;
6592 #if SYNCLINK_GENERIC_HDLC
6594 info->netdev->stats.rx_errors++;
6595 info->netdev->stats.rx_frame_errors++;
6599 return_frame =
true;
6601 if ( return_frame ) {
6618 printk(
"%s(%d):mgsl_get_rx_frame(%s) status=%04X size=%d\n",
6619 __FILE__,__LINE__,info->
device_name,status,framesize);
6632 int copy_count = framesize;
6633 int index = StartIndex;
6644 partial_count = copy_count;
6648 ptmp += partial_count;
6649 copy_count -= partial_count;
6657 *ptmp = (status & RXSTATUS_CRC_ERROR ?
6662 printk(
"%s(%d):mgsl_get_rx_frame(%s) rx frame status=%d\n",
6667 #if SYNCLINK_GENERIC_HDLC
6676 mgsl_free_rx_frame_buffers( info, StartIndex, EndIndex );
6691 usc_start_receiver(info);
6719 static bool mgsl_get_raw_rx_frame(
struct mgsl_struct *info)
6721 unsigned int CurrentIndex, NextIndex;
6724 unsigned int framesize = 0;
6725 bool ReturnCode =
false;
6726 unsigned long flags;
6761 if ( status & (RXSTATUS_SHORT_FRAME + RXSTATUS_OVERRUN +
6762 RXSTATUS_CRC_ERROR + RXSTATUS_ABORT) ) {
6763 if ( status & RXSTATUS_SHORT_FRAME )
6765 else if ( status & RXSTATUS_ABORT )
6767 else if ( status & RXSTATUS_OVERRUN )
6829 printk(
"%s(%d):mgsl_get_raw_rx_frame(%s) status=%04X size=%d\n",
6830 __FILE__,__LINE__,info->
device_name,status,framesize);
6848 mgsl_free_rx_frame_buffers( info, CurrentIndex, CurrentIndex );
6863 usc_start_receiver(info);
6884 static void mgsl_load_tx_dma_buffer(
struct mgsl_struct *info,
6885 const char *Buffer,
unsigned int BufferSize)
6887 unsigned short Copycount;
6918 while( BufferSize ){
6935 mgsl_load_pci_memory(pBufEntry->
virt_addr, Buffer,Copycount);
6939 pBufEntry->
count = Copycount;
6942 Buffer += Copycount;
6943 BufferSize -= Copycount;
6961 static bool mgsl_register_test(
struct mgsl_struct *info )
6963 static unsigned short BitPatterns[] =
6964 { 0x0000, 0xffff, 0xaaaa, 0x5555, 0x1234, 0x6969, 0x9696, 0x0f0f };
6965 static unsigned int Patterncount =
ARRAY_SIZE(BitPatterns);
6968 unsigned long flags;
6975 if ( (usc_InReg( info,
SICR ) != 0) ||
6976 (usc_InReg( info,
IVR ) != 0) ||
6977 (usc_InDmaReg( info,
DIVR ) != 0) ){
6985 for ( i = 0 ; i < Patterncount ; i++ ) {
6986 usc_OutReg( info,
TC0R, BitPatterns[i] );
6987 usc_OutReg( info,
TC1R, BitPatterns[(i+1)%Patterncount] );
6988 usc_OutReg( info,
TCLR, BitPatterns[(i+2)%Patterncount] );
6989 usc_OutReg( info,
RCLR, BitPatterns[(i+3)%Patterncount] );
6990 usc_OutReg( info,
RSR, BitPatterns[(i+4)%Patterncount] );
6991 usc_OutDmaReg( info,
TBCR, BitPatterns[(i+5)%Patterncount] );
6993 if ( (usc_InReg( info,
TC0R ) != BitPatterns[i]) ||
6994 (usc_InReg( info,
TC1R ) != BitPatterns[(i+1)%Patterncount]) ||
6995 (usc_InReg( info,
TCLR ) != BitPatterns[(i+2)%Patterncount]) ||
6996 (usc_InReg( info,
RCLR ) != BitPatterns[(i+3)%Patterncount]) ||
6997 (usc_InReg( info,
RSR ) != BitPatterns[(i+4)%Patterncount]) ||
6998 (usc_InDmaReg( info,
TBCR ) != BitPatterns[(i+5)%Patterncount]) ){
7017 static bool mgsl_irq_test(
struct mgsl_struct *info )
7019 unsigned long EndTime;
7020 unsigned long flags;
7036 usc_OutReg( info,
PCR, (
unsigned short)((usc_InReg(info,
PCR) |
BIT13) & ~
BIT12) );
7069 static bool mgsl_dma_test(
struct mgsl_struct *info )
7071 unsigned short FifoLevel;
7073 unsigned int FrameSize;
7077 unsigned short status=0;
7078 unsigned long EndTime;
7079 unsigned long flags;
7087 #define TESTFRAMESIZE 40
7094 usc_set_sdlc_mode(info);
7095 usc_enable_loopback(info,1);
7117 usc_OutDmaReg( info,
RDMR, 0xe200 );
7136 for (i = 0; i < FrameSize; i++ )
7167 usc_OutDmaReg( info,
NRARL, (
unsigned short)phys_addr );
7168 usc_OutDmaReg( info,
NRARU, (
unsigned short)(phys_addr >> 16) );
7171 usc_InDmaReg( info,
RDMR );
7175 usc_OutReg( info,
RMR, (
unsigned short)((usc_InReg(info,
RMR) & 0xfffc) | 0x0002) );
7194 status = usc_InDmaReg( info,
RDMR );
7197 if ( !(status &
BIT4) && (status &
BIT5) ) {
7221 usc_OutDmaReg( info,
NTARL, (
unsigned short)phys_addr );
7222 usc_OutDmaReg( info,
NTARU, (
unsigned short)(phys_addr >> 16) );
7226 usc_OutReg( info,
TCSR, (
unsigned short)(( usc_InReg(info,
TCSR) & 0x0f00) | 0xfa) );
7250 FifoLevel = usc_InReg(info,
TICR) >> 8;
7253 if ( FifoLevel < 16 )
7256 if ( FrameSize < 32 ) {
7259 if ( FifoLevel <= (32 - FrameSize) )
7273 usc_OutReg( info,
TMR, (
unsigned short)((usc_InReg(info,
TMR) & 0xfffc) | 0x0002) );
7288 status = usc_InReg( info,
TCSR );
7298 status = usc_InReg( info,
TCSR );
7318 while ( status == 0 ) {
7332 if ( status & (BIT8 +
BIT3 +
BIT1) ) {
7361 static int mgsl_adapter_test(
struct mgsl_struct *info )
7364 printk(
"%s(%d):Testing device %s\n",
7367 if ( !mgsl_register_test( info ) ) {
7369 printk(
"%s(%d):Register test failure for device %s Addr=%04X\n",
7374 if ( !mgsl_irq_test( info ) ) {
7376 printk(
"%s(%d):Interrupt test failure for device %s IRQ=%d\n",
7381 if ( !mgsl_dma_test( info ) ) {
7383 printk(
"%s(%d):DMA test failure for device %s DMA=%d\n",
7389 printk(
"%s(%d):device %s passed diagnostics\n",
7403 static bool mgsl_memory_test(
struct mgsl_struct *info )
7405 static unsigned long BitPatterns[] =
7406 { 0x0, 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
7407 unsigned long Patterncount =
ARRAY_SIZE(BitPatterns);
7410 unsigned long * TestAddr;
7419 for ( i = 0 ; i < Patterncount ; i++ ) {
7420 *TestAddr = BitPatterns[
i];
7421 if ( *TestAddr != BitPatterns[i] )
7428 for ( i = 0 ; i < TestLimit ; i++ ) {
7435 for ( i = 0 ; i < TestLimit ; i++ ) {
7436 if ( *TestAddr != i * 4 )
7484 static void mgsl_load_pci_memory(
char* TargetPtr,
const char* SourcePtr,
7485 unsigned short count )
7488 #define PCI_LOAD_INTERVAL 64
7491 unsigned short Index;
7492 unsigned long Dummy;
7494 for ( Index = 0 ; Index < Intervalcount ; Index++ )
7496 memcpy(TargetPtr, SourcePtr, PCI_LOAD_INTERVAL);
7497 Dummy = *((
volatile unsigned long *)TargetPtr);
7502 memcpy( TargetPtr, SourcePtr, count % PCI_LOAD_INTERVAL );
7506 static void mgsl_trace_block(
struct mgsl_struct *info,
const char* data,
int count,
int xmit)
7521 for(i=0;i<linecount;i++)
7522 printk(
"%02X ",(
unsigned char)data[i]);
7525 for(i=0;i<linecount;i++) {
7526 if (data[i]>=040 && data[i]<=0176)
7546 static void mgsl_tx_timeout(
unsigned long context)
7549 unsigned long flags;
7552 printk(
"%s(%d):mgsl_tx_timeout(%s)\n",
7557 info->
icount.txtimeout++;
7564 usc_loopmode_cancel_transmit( info );
7568 #if SYNCLINK_GENERIC_HDLC
7570 hdlcdev_tx_done(info);
7573 mgsl_bh_transmit(info);
7581 static int mgsl_loopmode_send_done(
struct mgsl_struct * info )
7583 unsigned long flags;
7590 usc_loopmode_send_done(info);
7600 static void usc_loopmode_send_done(
struct mgsl_struct * info )
7610 static void usc_loopmode_cancel_transmit(
struct mgsl_struct * info )
7615 usc_loopmode_send_done( info );
7622 static void usc_loopmode_insert_request(
struct mgsl_struct * info )
7629 usc_OutReg( info,
RICR,
7630 (usc_InReg( info,
RICR ) | RXSTATUS_ABORT_RECEIVED ) );
7639 static int usc_loopmode_active(
struct mgsl_struct * info)
7641 return usc_InReg( info,
CCSR ) &
BIT7 ? 1 : 0 ;
7644 #if SYNCLINK_GENERIC_HDLC
7656 static int hdlcdev_attach(
struct net_device *
dev,
unsigned short encoding,
7657 unsigned short parity)
7660 unsigned char new_encoding;
7661 unsigned short new_crctype;
7664 if (info->
port.count)
7690 mgsl_program_hw(info);
7705 unsigned long flags;
7711 netif_stop_queue(dev);
7715 mgsl_load_tx_dma_buffer(info, skb->
data, skb->
len);
7718 dev->
stats.tx_packets++;
7730 usc_start_transmitter(info);
7744 static int hdlcdev_open(
struct net_device *dev)
7748 unsigned long flags;
7751 printk(
"%s:hdlcdev_open(%s)\n",__FILE__,dev->
name);
7761 spin_unlock_irqrestore(&info->
netlock, flags);
7765 spin_unlock_irqrestore(&info->
netlock, flags);
7768 if ((rc = startup(info)) != 0) {
7771 spin_unlock_irqrestore(&info->
netlock, flags);
7777 mgsl_program_hw(info);
7781 netif_start_queue(dev);
7785 usc_get_serial_signals(info);
7802 static int hdlcdev_close(
struct net_device *dev)
7805 unsigned long flags;
7808 printk(
"%s:hdlcdev_close(%s)\n",__FILE__,dev->
name);
7810 netif_stop_queue(dev);
7819 spin_unlock_irqrestore(&info->
netlock, flags);
7833 static int hdlcdev_ioctl(
struct net_device *dev,
struct ifreq *ifr,
int cmd)
7842 printk(
"%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->
name);
7845 if (info->
port.count)
7851 switch(ifr->ifr_settings.type) {
7855 if (ifr->ifr_settings.size < size) {
7856 ifr->ifr_settings.size =
size;
7919 mgsl_program_hw(info);
7932 static void hdlcdev_tx_timeout(
struct net_device *dev)
7935 unsigned long flags;
7938 printk(
"hdlcdev_tx_timeout(%s)\n",dev->
name);
7940 dev->
stats.tx_errors++;
7941 dev->
stats.tx_aborted_errors++;
7944 usc_stop_transmitter(info);
7947 netif_wake_queue(dev);
7956 static void hdlcdev_tx_done(
struct mgsl_struct *info)
7958 if (netif_queue_stopped(info->netdev))
7959 netif_wake_queue(info->netdev);
7970 static void hdlcdev_rx(
struct mgsl_struct *info,
char *buf,
int size)
7972 struct sk_buff *skb = dev_alloc_skb(size);
7981 dev->
stats.rx_dropped++;
7987 skb->
protocol = hdlc_type_trans(skb, dev);
7989 dev->
stats.rx_packets++;
7997 .ndo_stop = hdlcdev_close,
8000 .ndo_do_ioctl = hdlcdev_ioctl,
8001 .ndo_tx_timeout = hdlcdev_tx_timeout,
8036 hdlc = dev_to_hdlc(dev);
8037 hdlc->
attach = hdlcdev_attach;
8038 hdlc->
xmit = hdlcdev_xmit;
8057 static void hdlcdev_exit(
struct mgsl_struct *info)
8061 info->netdev =
NULL;
8073 printk(
"error enabling pci device %p\n", dev);
8077 if (!(info = mgsl_allocate_device())) {
8078 printk(
"can't allocate device instance data.\n");
8100 if (dev->
device == 0x0210) {
8114 mgsl_add_device(info);