synclink.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:232k
- *
- * info pointer to device instance data
- * BufferList pointer to list of buffer entries
- * Buffercount count of buffer entries in buffer list
- *
- * Return Value: None
- */
- void mgsl_free_frame_memory(struct mgsl_struct *info, DMABUFFERENTRY *BufferList, int Buffercount)
- {
- int i;
- if ( BufferList ) {
- for ( i = 0 ; i < Buffercount ; i++ ) {
- if ( BufferList[i].virt_addr ) {
- if ( info->bus_type != MGSL_BUS_TYPE_PCI )
- kfree(BufferList[i].virt_addr);
- BufferList[i].virt_addr = NULL;
- }
- }
- }
- } /* end of mgsl_free_frame_memory() */
- /* mgsl_free_dma_buffers()
- *
- * Free DMA buffers
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void mgsl_free_dma_buffers( struct mgsl_struct *info )
- {
- mgsl_free_frame_memory( info, info->rx_buffer_list, info->rx_buffer_count );
- mgsl_free_frame_memory( info, info->tx_buffer_list, info->tx_buffer_count );
- mgsl_free_buffer_list_memory( info );
- } /* end of mgsl_free_dma_buffers() */
- /*
- * mgsl_alloc_intermediate_rxbuffer_memory()
- *
- * Allocate a buffer large enough to hold max_frame_size. This buffer
- * is used to pass an assembled frame to the line discipline.
- *
- * Arguments:
- *
- * info pointer to device instance data
- *
- * Return Value: 0 if success, otherwise -ENOMEM
- */
- int mgsl_alloc_intermediate_rxbuffer_memory(struct mgsl_struct *info)
- {
- info->intermediate_rxbuffer = kmalloc(info->max_frame_size, GFP_KERNEL | GFP_DMA);
- if ( info->intermediate_rxbuffer == NULL )
- return -ENOMEM;
- return 0;
- } /* end of mgsl_alloc_intermediate_rxbuffer_memory() */
- /*
- * mgsl_free_intermediate_rxbuffer_memory()
- *
- *
- * Arguments:
- *
- * info pointer to device instance data
- *
- * Return Value: None
- */
- void mgsl_free_intermediate_rxbuffer_memory(struct mgsl_struct *info)
- {
- if ( info->intermediate_rxbuffer )
- kfree(info->intermediate_rxbuffer);
- info->intermediate_rxbuffer = NULL;
- } /* end of mgsl_free_intermediate_rxbuffer_memory() */
- /*
- * mgsl_alloc_intermediate_txbuffer_memory()
- *
- * Allocate intermdiate transmit buffer(s) large enough to hold max_frame_size.
- * This buffer is used to load transmit frames into the adapter's dma transfer
- * buffers when there is sufficient space.
- *
- * Arguments:
- *
- * info pointer to device instance data
- *
- * Return Value: 0 if success, otherwise -ENOMEM
- */
- int mgsl_alloc_intermediate_txbuffer_memory(struct mgsl_struct *info)
- {
- int i;
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk("%s %s(%d) allocating %d tx holding buffersn",
- info->device_name, __FILE__,__LINE__,info->num_tx_holding_buffers);
- memset(info->tx_holding_buffers,0,sizeof(info->tx_holding_buffers));
- for ( i=0; i<info->num_tx_holding_buffers; ++i) {
- info->tx_holding_buffers[i].buffer =
- kmalloc(info->max_frame_size, GFP_KERNEL);
- if ( info->tx_holding_buffers[i].buffer == NULL )
- return -ENOMEM;
- }
- return 0;
- } /* end of mgsl_alloc_intermediate_txbuffer_memory() */
- /*
- * mgsl_free_intermediate_txbuffer_memory()
- *
- *
- * Arguments:
- *
- * info pointer to device instance data
- *
- * Return Value: None
- */
- void mgsl_free_intermediate_txbuffer_memory(struct mgsl_struct *info)
- {
- int i;
- for ( i=0; i<info->num_tx_holding_buffers; ++i ) {
- if ( info->tx_holding_buffers[i].buffer ) {
- kfree(info->tx_holding_buffers[i].buffer);
- info->tx_holding_buffers[i].buffer=NULL;
- }
- }
- info->get_tx_holding_index = 0;
- info->put_tx_holding_index = 0;
- info->tx_holding_count = 0;
- } /* end of mgsl_free_intermediate_txbuffer_memory() */
- /*
- * load_next_tx_holding_buffer()
- *
- * attempts to load the next buffered tx request into the
- * tx dma buffers
- *
- * Arguments:
- *
- * info pointer to device instance data
- *
- * Return Value: 1 if next buffered tx request loaded
- * into adapter's tx dma buffer,
- * 0 otherwise
- */
- int load_next_tx_holding_buffer(struct mgsl_struct *info)
- {
- int ret = 0;
- if ( info->tx_holding_count ) {
- /* determine if we have enough tx dma buffers
- * to accomodate the next tx frame
- */
- struct tx_holding_buffer *ptx =
- &info->tx_holding_buffers[info->get_tx_holding_index];
- int num_free = num_free_tx_dma_buffers(info);
- int num_needed = ptx->buffer_size / DMABUFFERSIZE;
- if ( ptx->buffer_size % DMABUFFERSIZE )
- ++num_needed;
- if (num_needed <= num_free) {
- info->xmit_cnt = ptx->buffer_size;
- mgsl_load_tx_dma_buffer(info,ptx->buffer,ptx->buffer_size);
- --info->tx_holding_count;
- if ( ++info->get_tx_holding_index >= info->num_tx_holding_buffers)
- info->get_tx_holding_index=0;
- /* restart transmit timer */
- del_timer(&info->tx_timer);
- info->tx_timer.expires = jiffies + jiffies_from_ms(5000);
- add_timer(&info->tx_timer);
- ret = 1;
- }
- }
- return ret;
- }
- /*
- * save_tx_buffer_request()
- *
- * attempt to store transmit frame request for later transmission
- *
- * Arguments:
- *
- * info pointer to device instance data
- * Buffer pointer to buffer containing frame to load
- * BufferSize size in bytes of frame in Buffer
- *
- * Return Value: 1 if able to store, 0 otherwise
- */
- int save_tx_buffer_request(struct mgsl_struct *info,const char *Buffer, unsigned int BufferSize)
- {
- struct tx_holding_buffer *ptx;
- if ( info->tx_holding_count >= info->num_tx_holding_buffers ) {
- return 0; /* all buffers in use */
- }
- ptx = &info->tx_holding_buffers[info->put_tx_holding_index];
- ptx->buffer_size = BufferSize;
- memcpy( ptx->buffer, Buffer, BufferSize);
- ++info->tx_holding_count;
- if ( ++info->put_tx_holding_index >= info->num_tx_holding_buffers)
- info->put_tx_holding_index=0;
- return 1;
- }
- int mgsl_claim_resources(struct mgsl_struct *info)
- {
- if (request_region(info->io_base,info->io_addr_size,"synclink") == NULL) {
- printk( "%s(%d):I/O address conflict on device %s Addr=%08Xn",
- __FILE__,__LINE__,info->device_name, info->io_base);
- return -ENODEV;
- }
- info->io_addr_requested = 1;
-
- if ( request_irq(info->irq_level,mgsl_interrupt,info->irq_flags,
- info->device_name, info ) < 0 ) {
- printk( "%s(%d):Cant request interrupt on device %s IRQ=%dn",
- __FILE__,__LINE__,info->device_name, info->irq_level );
- goto errout;
- }
- info->irq_requested = 1;
-
- if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
- if (request_mem_region(info->phys_memory_base,0x40000,"synclink") == NULL) {
- printk( "%s(%d):mem addr conflict device %s Addr=%08Xn",
- __FILE__,__LINE__,info->device_name, info->phys_memory_base);
- goto errout;
- }
- info->shared_mem_requested = 1;
- if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclink") == NULL) {
- printk( "%s(%d):lcr mem addr conflict device %s Addr=%08Xn",
- __FILE__,__LINE__,info->device_name, info->phys_lcr_base + info->lcr_offset);
- goto errout;
- }
- info->lcr_mem_requested = 1;
- info->memory_base = ioremap(info->phys_memory_base,0x40000);
- if (!info->memory_base) {
- printk( "%s(%d):Cant map shared memory on device %s MemAddr=%08Xn",
- __FILE__,__LINE__,info->device_name, info->phys_memory_base );
- goto errout;
- }
-
- if ( !mgsl_memory_test(info) ) {
- printk( "%s(%d):Failed shared memory test %s MemAddr=%08Xn",
- __FILE__,__LINE__,info->device_name, info->phys_memory_base );
- goto errout;
- }
-
- info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE) + info->lcr_offset;
- if (!info->lcr_base) {
- printk( "%s(%d):Cant map LCR memory on device %s MemAddr=%08Xn",
- __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
- goto errout;
- }
-
- } else {
- /* claim DMA channel */
-
- if (request_dma(info->dma_level,info->device_name) < 0){
- printk( "%s(%d):Cant request DMA channel on device %s DMA=%dn",
- __FILE__,__LINE__,info->device_name, info->dma_level );
- mgsl_release_resources( info );
- return -ENODEV;
- }
- info->dma_requested = 1;
- /* ISA adapter uses bus master DMA */
- set_dma_mode(info->dma_level,DMA_MODE_CASCADE);
- enable_dma(info->dma_level);
- }
-
- if ( mgsl_allocate_dma_buffers(info) < 0 ) {
- printk( "%s(%d):Cant allocate DMA buffers on device %s DMA=%dn",
- __FILE__,__LINE__,info->device_name, info->dma_level );
- goto errout;
- }
-
- return 0;
- errout:
- mgsl_release_resources(info);
- return -ENODEV;
- } /* end of mgsl_claim_resources() */
- void mgsl_release_resources(struct mgsl_struct *info)
- {
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk( "%s(%d):mgsl_release_resources(%s) entryn",
- __FILE__,__LINE__,info->device_name );
-
- if ( info->irq_requested ) {
- free_irq(info->irq_level, info);
- info->irq_requested = 0;
- }
- if ( info->dma_requested ) {
- disable_dma(info->dma_level);
- free_dma(info->dma_level);
- info->dma_requested = 0;
- }
- mgsl_free_dma_buffers(info);
- mgsl_free_intermediate_rxbuffer_memory(info);
- mgsl_free_intermediate_txbuffer_memory(info);
-
- if ( info->io_addr_requested ) {
- release_region(info->io_base,info->io_addr_size);
- info->io_addr_requested = 0;
- }
- if ( info->shared_mem_requested ) {
- release_mem_region(info->phys_memory_base,0x40000);
- info->shared_mem_requested = 0;
- }
- if ( info->lcr_mem_requested ) {
- release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
- info->lcr_mem_requested = 0;
- }
- if (info->memory_base){
- iounmap(info->memory_base);
- info->memory_base = 0;
- }
- if (info->lcr_base){
- iounmap(info->lcr_base - info->lcr_offset);
- info->lcr_base = 0;
- }
-
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk( "%s(%d):mgsl_release_resources(%s) exitn",
- __FILE__,__LINE__,info->device_name );
-
- } /* end of mgsl_release_resources() */
- /* mgsl_add_device()
- *
- * Add the specified device instance data structure to the
- * global linked list of devices and increment the device count.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void mgsl_add_device( struct mgsl_struct *info )
- {
- info->next_device = NULL;
- info->line = mgsl_device_count;
- sprintf(info->device_name,"ttySL%d",info->line);
-
- if (info->line < MAX_TOTAL_DEVICES) {
- if (maxframe[info->line])
- info->max_frame_size = maxframe[info->line];
- info->dosyncppp = dosyncppp[info->line];
- if (txdmabufs[info->line]) {
- info->num_tx_dma_buffers = txdmabufs[info->line];
- if (info->num_tx_dma_buffers < 1)
- info->num_tx_dma_buffers = 1;
- }
- if (txholdbufs[info->line]) {
- info->num_tx_holding_buffers = txholdbufs[info->line];
- if (info->num_tx_holding_buffers < 1)
- info->num_tx_holding_buffers = 1;
- else if (info->num_tx_holding_buffers > MAX_TX_HOLDING_BUFFERS)
- info->num_tx_holding_buffers = MAX_TX_HOLDING_BUFFERS;
- }
- }
- mgsl_device_count++;
-
- if ( !mgsl_device_list )
- mgsl_device_list = info;
- else {
- struct mgsl_struct *current_dev = mgsl_device_list;
- while( current_dev->next_device )
- current_dev = current_dev->next_device;
- current_dev->next_device = info;
- }
-
- if ( info->max_frame_size < 4096 )
- info->max_frame_size = 4096;
- else if ( info->max_frame_size > 65535 )
- info->max_frame_size = 65535;
-
- if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
- printk( "SyncLink device %s added:PCI bus IO=%04X IRQ=%d Mem=%08X LCR=%08X MaxFrameSize=%un",
- info->device_name, info->io_base, info->irq_level,
- info->phys_memory_base, info->phys_lcr_base,
- info->max_frame_size );
- } else {
- printk( "SyncLink device %s added:ISA bus IO=%04X IRQ=%d DMA=%d MaxFrameSize=%un",
- info->device_name, info->io_base, info->irq_level, info->dma_level,
- info->max_frame_size );
- }
- #ifdef CONFIG_SYNCLINK_SYNCPPP
- #ifdef MODULE
- if (info->dosyncppp)
- #endif
- mgsl_sppp_init(info);
- #endif
- } /* end of mgsl_add_device() */
- /* mgsl_allocate_device()
- *
- * Allocate and initialize a device instance structure
- *
- * Arguments: none
- * Return Value: pointer to mgsl_struct if success, otherwise NULL
- */
- struct mgsl_struct* mgsl_allocate_device()
- {
- struct mgsl_struct *info;
-
- info = (struct mgsl_struct *)kmalloc(sizeof(struct mgsl_struct),
- GFP_KERNEL);
-
- if (!info) {
- printk("Error can't allocate device instance datan");
- } else {
- memset(info, 0, sizeof(struct mgsl_struct));
- info->magic = MGSL_MAGIC;
- info->task.sync = 0;
- info->task.routine = mgsl_bh_handler;
- info->task.data = info;
- info->max_frame_size = 4096;
- info->close_delay = 5*HZ/10;
- info->closing_wait = 30*HZ;
- init_waitqueue_head(&info->open_wait);
- init_waitqueue_head(&info->close_wait);
- init_waitqueue_head(&info->status_event_wait_q);
- init_waitqueue_head(&info->event_wait_q);
- spin_lock_init(&info->irq_spinlock);
- spin_lock_init(&info->netlock);
- memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
- info->idle_mode = HDLC_TXIDLE_FLAGS;
- info->num_tx_dma_buffers = 1;
- info->num_tx_holding_buffers = 0;
- }
-
- return info;
- } /* end of mgsl_allocate_device()*/
- /*
- * perform tty device initialization
- */
- int mgsl_init_tty(void);
- int mgsl_init_tty()
- {
- struct mgsl_struct *info;
- memset(serial_table,0,sizeof(struct tty_struct*)*MAX_TOTAL_DEVICES);
- memset(serial_termios,0,sizeof(struct termios*)*MAX_TOTAL_DEVICES);
- memset(serial_termios_locked,0,sizeof(struct termios*)*MAX_TOTAL_DEVICES);
- /* Initialize the tty_driver structure */
-
- memset(&serial_driver, 0, sizeof(struct tty_driver));
- serial_driver.magic = TTY_DRIVER_MAGIC;
- serial_driver.driver_name = "synclink";
- serial_driver.name = "ttySL";
- serial_driver.major = ttymajor;
- serial_driver.minor_start = 64;
- serial_driver.num = mgsl_device_count;
- serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
- serial_driver.subtype = SERIAL_TYPE_NORMAL;
- serial_driver.init_termios = tty_std_termios;
- serial_driver.init_termios.c_cflag =
- B9600 | CS8 | CREAD | HUPCL | CLOCAL;
- serial_driver.flags = TTY_DRIVER_REAL_RAW;
- serial_driver.refcount = &serial_refcount;
- serial_driver.table = serial_table;
- serial_driver.termios = serial_termios;
- serial_driver.termios_locked = serial_termios_locked;
- serial_driver.open = mgsl_open;
- serial_driver.close = mgsl_close;
- serial_driver.write = mgsl_write;
- serial_driver.put_char = mgsl_put_char;
- serial_driver.flush_chars = mgsl_flush_chars;
- serial_driver.write_room = mgsl_write_room;
- serial_driver.chars_in_buffer = mgsl_chars_in_buffer;
- serial_driver.flush_buffer = mgsl_flush_buffer;
- serial_driver.ioctl = mgsl_ioctl;
- serial_driver.throttle = mgsl_throttle;
- serial_driver.unthrottle = mgsl_unthrottle;
- serial_driver.send_xchar = mgsl_send_xchar;
- serial_driver.break_ctl = mgsl_break;
- serial_driver.wait_until_sent = mgsl_wait_until_sent;
- serial_driver.read_proc = mgsl_read_proc;
- serial_driver.set_termios = mgsl_set_termios;
- serial_driver.stop = mgsl_stop;
- serial_driver.start = mgsl_start;
- serial_driver.hangup = mgsl_hangup;
-
- /*
- * The callout device is just like normal device except for
- * major number and the subtype code.
- */
- callout_driver = serial_driver;
- callout_driver.name = "cuaSL";
- callout_driver.major = cuamajor;
- callout_driver.subtype = SERIAL_TYPE_CALLOUT;
- callout_driver.read_proc = 0;
- callout_driver.proc_entry = 0;
- if (tty_register_driver(&serial_driver) < 0)
- printk("%s(%d):Couldn't register serial drivern",
- __FILE__,__LINE__);
-
- if (tty_register_driver(&callout_driver) < 0)
- printk("%s(%d):Couldn't register callout drivern",
- __FILE__,__LINE__);
- printk("%s %s, tty major#%d callout major#%dn",
- driver_name, driver_version,
- serial_driver.major, callout_driver.major);
-
- /* Propagate these values to all device instances */
-
- info = mgsl_device_list;
- while(info){
- info->callout_termios = callout_driver.init_termios;
- info->normal_termios = serial_driver.init_termios;
- info = info->next_device;
- }
- return 0;
- }
- /* enumerate user specified ISA adapters
- */
- int mgsl_enum_isa_devices()
- {
- struct mgsl_struct *info;
- int i;
-
- /* Check for user specified ISA devices */
-
- for (i=0 ;(i < MAX_ISA_DEVICES) && io[i] && irq[i]; i++){
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk("ISA device specified io=%04X,irq=%d,dma=%dn",
- io[i], irq[i], dma[i] );
-
- info = mgsl_allocate_device();
- if ( !info ) {
- /* error allocating device instance data */
- if ( debug_level >= DEBUG_LEVEL_ERROR )
- printk( "can't allocate device instance data.n");
- continue;
- }
-
- /* Copy user configuration info to device instance data */
- info->io_base = (unsigned int)io[i];
- info->irq_level = (unsigned int)irq[i];
- info->irq_level = irq_cannonicalize(info->irq_level);
- info->dma_level = (unsigned int)dma[i];
- info->bus_type = MGSL_BUS_TYPE_ISA;
- info->io_addr_size = 16;
- info->irq_flags = 0;
-
- mgsl_add_device( info );
- }
-
- return 0;
- }
- /* mgsl_init()
- *
- * Driver initialization entry point.
- *
- * Arguments: None
- * Return Value: 0 if success, otherwise error code
- */
- int __init mgsl_init(void)
- {
- int rc;
- EXPORT_NO_SYMBOLS;
-
- printk("%s %sn", driver_name, driver_version);
-
- mgsl_enum_isa_devices();
- pci_register_driver(&synclink_pci_driver);
- if ( !mgsl_device_list ) {
- printk("%s(%d):No SyncLink devices found.n",__FILE__,__LINE__);
- return -ENODEV;
- }
- if ((rc = mgsl_init_tty()))
- return rc;
-
- return 0;
- }
- static int __init synclink_init(void)
- {
- /* Uncomment this to kernel debug module.
- * mgsl_get_text_ptr() leaves the .text address in eax
- * which can be used with add-symbol-file with gdb.
- */
- if (break_on_load) {
- mgsl_get_text_ptr();
- BREAKPOINT();
- }
-
- return mgsl_init();
- }
- static void __exit synclink_exit(void)
- {
- unsigned long flags;
- int rc;
- struct mgsl_struct *info;
- struct mgsl_struct *tmp;
- printk("Unloading %s: %sn", driver_name, driver_version);
- save_flags(flags);
- cli();
- if ((rc = tty_unregister_driver(&serial_driver)))
- printk("%s(%d) failed to unregister tty driver err=%dn",
- __FILE__,__LINE__,rc);
- if ((rc = tty_unregister_driver(&callout_driver)))
- printk("%s(%d) failed to unregister callout driver err=%dn",
- __FILE__,__LINE__,rc);
- restore_flags(flags);
- info = mgsl_device_list;
- while(info) {
- #ifdef CONFIG_SYNCLINK_SYNCPPP
- if (info->dosyncppp)
- mgsl_sppp_delete(info);
- #endif
- mgsl_release_resources(info);
- tmp = info;
- info = info->next_device;
- kfree(tmp);
- }
-
- if (tmp_buf) {
- free_page((unsigned long) tmp_buf);
- tmp_buf = NULL;
- }
-
- pci_unregister_driver(&synclink_pci_driver);
- }
- module_init(synclink_init);
- module_exit(synclink_exit);
- /*
- * usc_RTCmd()
- *
- * Issue a USC Receive/Transmit command to the
- * Channel Command/Address Register (CCAR).
- *
- * Notes:
- *
- * The command is encoded in the most significant 5 bits <15..11>
- * of the CCAR value. Bits <10..7> of the CCAR must be preserved
- * and Bits <6..0> must be written as zeros.
- *
- * Arguments:
- *
- * info pointer to device information structure
- * Cmd command mask (use symbolic macros)
- *
- * Return Value:
- *
- * None
- */
- void usc_RTCmd( struct mgsl_struct *info, u16 Cmd )
- {
- /* output command to CCAR in bits <15..11> */
- /* preserve bits <10..7>, bits <6..0> must be zero */
- outw( Cmd + info->loopback_bits, info->io_base + CCAR );
- /* Read to flush write to CCAR */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- inw( info->io_base + CCAR );
- } /* end of usc_RTCmd() */
- /*
- * usc_DmaCmd()
- *
- * Issue a DMA command to the DMA Command/Address Register (DCAR).
- *
- * Arguments:
- *
- * info pointer to device information structure
- * Cmd DMA command mask (usc_DmaCmd_XX Macros)
- *
- * Return Value:
- *
- * None
- */
- void usc_DmaCmd( struct mgsl_struct *info, u16 Cmd )
- {
- /* write command mask to DCAR */
- outw( Cmd + info->mbre_bit, info->io_base );
- /* Read to flush write to DCAR */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- inw( info->io_base );
- } /* end of usc_DmaCmd() */
- /*
- * usc_OutDmaReg()
- *
- * Write a 16-bit value to a USC DMA register
- *
- * Arguments:
- *
- * info pointer to device info structure
- * RegAddr register address (number) for write
- * RegValue 16-bit value to write to register
- *
- * Return Value:
- *
- * None
- *
- */
- void usc_OutDmaReg( struct mgsl_struct *info, u16 RegAddr, u16 RegValue )
- {
- /* Note: The DCAR is located at the adapter base address */
- /* Note: must preserve state of BIT8 in DCAR */
- outw( RegAddr + info->mbre_bit, info->io_base );
- outw( RegValue, info->io_base );
- /* Read to flush write to DCAR */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- inw( info->io_base );
- } /* end of usc_OutDmaReg() */
-
- /*
- * usc_InDmaReg()
- *
- * Read a 16-bit value from a DMA register
- *
- * Arguments:
- *
- * info pointer to device info structure
- * RegAddr register address (number) to read from
- *
- * Return Value:
- *
- * The 16-bit value read from register
- *
- */
- u16 usc_InDmaReg( struct mgsl_struct *info, u16 RegAddr )
- {
- /* Note: The DCAR is located at the adapter base address */
- /* Note: must preserve state of BIT8 in DCAR */
- outw( RegAddr + info->mbre_bit, info->io_base );
- return inw( info->io_base );
- } /* end of usc_InDmaReg() */
- /*
- *
- * usc_OutReg()
- *
- * Write a 16-bit value to a USC serial channel register
- *
- * Arguments:
- *
- * info pointer to device info structure
- * RegAddr register address (number) to write to
- * RegValue 16-bit value to write to register
- *
- * Return Value:
- *
- * None
- *
- */
- void usc_OutReg( struct mgsl_struct *info, u16 RegAddr, u16 RegValue )
- {
- outw( RegAddr + info->loopback_bits, info->io_base + CCAR );
- outw( RegValue, info->io_base + CCAR );
- /* Read to flush write to CCAR */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- inw( info->io_base + CCAR );
- } /* end of usc_OutReg() */
- /*
- * usc_InReg()
- *
- * Reads a 16-bit value from a USC serial channel register
- *
- * Arguments:
- *
- * info pointer to device extension
- * RegAddr register address (number) to read from
- *
- * Return Value:
- *
- * 16-bit value read from register
- */
- u16 usc_InReg( struct mgsl_struct *info, u16 RegAddr )
- {
- outw( RegAddr + info->loopback_bits, info->io_base + CCAR );
- return inw( info->io_base + CCAR );
- } /* end of usc_InReg() */
- /* usc_set_sdlc_mode()
- *
- * Set up the adapter for SDLC DMA communications.
- *
- * Arguments: info pointer to device instance data
- * Return Value: NONE
- */
- void usc_set_sdlc_mode( struct mgsl_struct *info )
- {
- u16 RegValue;
- int PreSL1660;
-
- /*
- * determine if the IUSC on the adapter is pre-SL1660. If
- * not, take advantage of the UnderWait feature of more
- * modern chips. If an underrun occurs and this bit is set,
- * the transmitter will idle the programmed idle pattern
- * until the driver has time to service the underrun. Otherwise,
- * the dma controller may get the cycles previously requested
- * and begin transmitting queued tx data.
- */
- usc_OutReg(info,TMCR,0x1f);
- RegValue=usc_InReg(info,TMDR);
- if ( RegValue == IUSC_PRE_SL1660 )
- PreSL1660 = 1;
- else
- PreSL1660 = 0;
-
- if ( info->params.flags & HDLC_FLAG_HDLC_LOOPMODE )
- {
- /*
- ** Channel Mode Register (CMR)
- **
- ** <15..14> 10 Tx Sub Modes, Send Flag on Underrun
- ** <13> 0 0 = Transmit Disabled (initially)
- ** <12> 0 1 = Consecutive Idles share common 0
- ** <11..8> 1110 Transmitter Mode = HDLC/SDLC Loop
- ** <7..4> 0000 Rx Sub Modes, addr/ctrl field handling
- ** <3..0> 0110 Receiver Mode = HDLC/SDLC
- **
- ** 1000 1110 0000 0110 = 0x8e06
- */
- RegValue = 0x8e06;
-
- /*--------------------------------------------------
- * ignore user options for UnderRun Actions and
- * preambles
- *--------------------------------------------------*/
- }
- else
- {
- /* Channel mode Register (CMR)
- *
- * <15..14> 00 Tx Sub modes, Underrun Action
- * <13> 0 1 = Send Preamble before opening flag
- * <12> 0 1 = Consecutive Idles share common 0
- * <11..8> 0110 Transmitter mode = HDLC/SDLC
- * <7..4> 0000 Rx Sub modes, addr/ctrl field handling
- * <3..0> 0110 Receiver mode = HDLC/SDLC
- *
- * 0000 0110 0000 0110 = 0x0606
- */
- if (info->params.mode == MGSL_MODE_RAW) {
- RegValue = 0x0001; /* Set Receive mode = external sync */
- usc_OutReg( info, IOCR, /* Set IOCR DCD is RxSync Detect Input */
- (unsigned short)((usc_InReg(info, IOCR) & ~(BIT13|BIT12)) | BIT12));
- /*
- * TxSubMode:
- * CMR <15> 0 Don't send CRC on Tx Underrun
- * CMR <14> x undefined
- * CMR <13> 0 Send preamble before openning sync
- * CMR <12> 0 Send 8-bit syncs, 1=send Syncs per TxLength
- *
- * TxMode:
- * CMR <11-8) 0100 MonoSync
- *
- * 0x00 0100 xxxx xxxx 04xx
- */
- RegValue |= 0x0400;
- }
- else {
- RegValue = 0x0606;
- if ( info->params.flags & HDLC_FLAG_UNDERRUN_ABORT15 )
- RegValue |= BIT14;
- else if ( info->params.flags & HDLC_FLAG_UNDERRUN_FLAG )
- RegValue |= BIT15;
- else if ( info->params.flags & HDLC_FLAG_UNDERRUN_CRC )
- RegValue |= BIT15 + BIT14;
- }
- if ( info->params.preamble != HDLC_PREAMBLE_PATTERN_NONE )
- RegValue |= BIT13;
- }
- if ( info->params.mode == MGSL_MODE_HDLC &&
- (info->params.flags & HDLC_FLAG_SHARE_ZERO) )
- RegValue |= BIT12;
- if ( info->params.addr_filter != 0xff )
- {
- /* set up receive address filtering */
- usc_OutReg( info, RSR, info->params.addr_filter );
- RegValue |= BIT4;
- }
- usc_OutReg( info, CMR, RegValue );
- info->cmr_value = RegValue;
- /* Receiver mode Register (RMR)
- *
- * <15..13> 000 encoding
- * <12..11> 00 FCS = 16bit CRC CCITT (x15 + x12 + x5 + 1)
- * <10> 1 1 = Set CRC to all 1s (use for SDLC/HDLC)
- * <9> 0 1 = Include Receive chars in CRC
- * <8> 1 1 = Use Abort/PE bit as abort indicator
- * <7..6> 00 Even parity
- * <5> 0 parity disabled
- * <4..2> 000 Receive Char Length = 8 bits
- * <1..0> 00 Disable Receiver
- *
- * 0000 0101 0000 0000 = 0x0500
- */
- RegValue = 0x0500;
- switch ( info->params.encoding ) {
- case HDLC_ENCODING_NRZB: RegValue |= BIT13; break;
- case HDLC_ENCODING_NRZI_MARK: RegValue |= BIT14; break;
- case HDLC_ENCODING_NRZI_SPACE: RegValue |= BIT14 + BIT13; break;
- case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT15; break;
- case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT15 + BIT13; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14 + BIT13; break;
- }
- if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_16_CCITT )
- RegValue |= BIT9;
- else if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_32_CCITT )
- RegValue |= ( BIT12 | BIT10 | BIT9 );
- usc_OutReg( info, RMR, RegValue );
- /* Set the Receive count Limit Register (RCLR) to 0xffff. */
- /* When an opening flag of an SDLC frame is recognized the */
- /* Receive Character count (RCC) is loaded with the value in */
- /* RCLR. The RCC is decremented for each received byte. The */
- /* value of RCC is stored after the closing flag of the frame */
- /* allowing the frame size to be computed. */
- usc_OutReg( info, RCLR, RCLRVALUE );
- usc_RCmd( info, RCmd_SelectRicrdma_level );
- /* Receive Interrupt Control Register (RICR)
- *
- * <15..8> ? RxFIFO DMA Request Level
- * <7> 0 Exited Hunt IA (Interrupt Arm)
- * <6> 0 Idle Received IA
- * <5> 0 Break/Abort IA
- * <4> 0 Rx Bound IA
- * <3> 1 Queued status reflects oldest 2 bytes in FIFO
- * <2> 0 Abort/PE IA
- * <1> 1 Rx Overrun IA
- * <0> 0 Select TC0 value for readback
- *
- * 0000 0000 0000 1000 = 0x000a
- */
- /* Carry over the Exit Hunt and Idle Received bits */
- /* in case they have been armed by usc_ArmEvents. */
- RegValue = usc_InReg( info, RICR ) & 0xc0;
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- usc_OutReg( info, RICR, (u16)(0x030a | RegValue) );
- else
- usc_OutReg( info, RICR, (u16)(0x140a | RegValue) );
- /* Unlatch all Rx status bits and clear Rx status IRQ Pending */
- usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, RECEIVE_STATUS );
- /* Transmit mode Register (TMR)
- *
- * <15..13> 000 encoding
- * <12..11> 00 FCS = 16bit CRC CCITT (x15 + x12 + x5 + 1)
- * <10> 1 1 = Start CRC as all 1s (use for SDLC/HDLC)
- * <9> 0 1 = Tx CRC Enabled
- * <8> 0 1 = Append CRC to end of transmit frame
- * <7..6> 00 Transmit parity Even
- * <5> 0 Transmit parity Disabled
- * <4..2> 000 Tx Char Length = 8 bits
- * <1..0> 00 Disable Transmitter
- *
- * 0000 0100 0000 0000 = 0x0400
- */
- RegValue = 0x0400;
- switch ( info->params.encoding ) {
- case HDLC_ENCODING_NRZB: RegValue |= BIT13; break;
- case HDLC_ENCODING_NRZI_MARK: RegValue |= BIT14; break;
- case HDLC_ENCODING_NRZI_SPACE: RegValue |= BIT14 + BIT13; break;
- case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT15; break;
- case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT15 + BIT13; break;
- case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14; break;
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: RegValue |= BIT15 + BIT14 + BIT13; break;
- }
- if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_16_CCITT )
- RegValue |= BIT9 + BIT8;
- else if ( (info->params.crc_type & HDLC_CRC_MASK) == HDLC_CRC_32_CCITT )
- RegValue |= ( BIT12 | BIT10 | BIT9 | BIT8);
- usc_OutReg( info, TMR, RegValue );
- usc_set_txidle( info );
- usc_TCmd( info, TCmd_SelectTicrdma_level );
- /* Transmit Interrupt Control Register (TICR)
- *
- * <15..8> ? Transmit FIFO DMA Level
- * <7> 0 Present IA (Interrupt Arm)
- * <6> 0 Idle Sent IA
- * <5> 1 Abort Sent IA
- * <4> 1 EOF/EOM Sent IA
- * <3> 0 CRC Sent IA
- * <2> 1 1 = Wait for SW Trigger to Start Frame
- * <1> 1 Tx Underrun IA
- * <0> 0 TC0 constant on read back
- *
- * 0000 0000 0011 0110 = 0x0036
- */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- usc_OutReg( info, TICR, 0x0736 );
- else
- usc_OutReg( info, TICR, 0x1436 );
- usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
- /*
- ** Transmit Command/Status Register (TCSR)
- **
- ** <15..12> 0000 TCmd
- ** <11> 0/1 UnderWait
- ** <10..08> 000 TxIdle
- ** <7> x PreSent
- ** <6> x IdleSent
- ** <5> x AbortSent
- ** <4> x EOF/EOM Sent
- ** <3> x CRC Sent
- ** <2> x All Sent
- ** <1> x TxUnder
- ** <0> x TxEmpty
- **
- ** 0000 0000 0000 0000 = 0x0000
- */
- info->tcsr_value = 0;
- if ( !PreSL1660 )
- info->tcsr_value |= TCSR_UNDERWAIT;
-
- usc_OutReg( info, TCSR, info->tcsr_value );
- /* Clock mode Control Register (CMCR)
- *
- * <15..14> 00 counter 1 Source = Disabled
- * <13..12> 00 counter 0 Source = Disabled
- * <11..10> 11 BRG1 Input is TxC Pin
- * <9..8> 11 BRG0 Input is TxC Pin
- * <7..6> 01 DPLL Input is BRG1 Output
- * <5..3> XXX TxCLK comes from Port 0
- * <2..0> XXX RxCLK comes from Port 1
- *
- * 0000 1111 0111 0111 = 0x0f77
- */
- RegValue = 0x0f40;
- if ( info->params.flags & HDLC_FLAG_RXC_DPLL )
- RegValue |= 0x0003; /* RxCLK from DPLL */
- else if ( info->params.flags & HDLC_FLAG_RXC_BRG )
- RegValue |= 0x0004; /* RxCLK from BRG0 */
- else if ( info->params.flags & HDLC_FLAG_RXC_TXCPIN)
- RegValue |= 0x0006; /* RxCLK from TXC Input */
- else
- RegValue |= 0x0007; /* RxCLK from Port1 */
- if ( info->params.flags & HDLC_FLAG_TXC_DPLL )
- RegValue |= 0x0018; /* TxCLK from DPLL */
- else if ( info->params.flags & HDLC_FLAG_TXC_BRG )
- RegValue |= 0x0020; /* TxCLK from BRG0 */
- else if ( info->params.flags & HDLC_FLAG_TXC_RXCPIN)
- RegValue |= 0x0038; /* RxCLK from TXC Input */
- else
- RegValue |= 0x0030; /* TxCLK from Port0 */
- usc_OutReg( info, CMCR, RegValue );
- /* Hardware Configuration Register (HCR)
- *
- * <15..14> 00 CTR0 Divisor:00=32,01=16,10=8,11=4
- * <13> 0 CTR1DSel:0=CTR0Div determines CTR0Div
- * <12> 0 CVOK:0=report code violation in biphase
- * <11..10> 00 DPLL Divisor:00=32,01=16,10=8,11=4
- * <9..8> XX DPLL mode:00=disable,01=NRZ,10=Biphase,11=Biphase Level
- * <7..6> 00 reserved
- * <5> 0 BRG1 mode:0=continuous,1=single cycle
- * <4> X BRG1 Enable
- * <3..2> 00 reserved
- * <1> 0 BRG0 mode:0=continuous,1=single cycle
- * <0> 0 BRG0 Enable
- */
- RegValue = 0x0000;
- if ( info->params.flags & (HDLC_FLAG_RXC_DPLL + HDLC_FLAG_TXC_DPLL) ) {
- u32 XtalSpeed;
- u32 DpllDivisor;
- u16 Tc;
- /* DPLL is enabled. Use BRG1 to provide continuous reference clock */
- /* for DPLL. DPLL mode in HCR is dependent on the encoding used. */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- XtalSpeed = 11059200;
- else
- XtalSpeed = 14745600;
- if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
- DpllDivisor = 16;
- RegValue |= BIT10;
- }
- else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
- DpllDivisor = 8;
- RegValue |= BIT11;
- }
- else
- DpllDivisor = 32;
- /* Tc = (Xtal/Speed) - 1 */
- /* If twice the remainder of (Xtal/Speed) is greater than Speed */
- /* then rounding up gives a more precise time constant. Instead */
- /* of rounding up and then subtracting 1 we just don't subtract */
- /* the one in this case. */
- /*--------------------------------------------------
- * ejz: for DPLL mode, application should use the
- * same clock speed as the partner system, even
- * though clocking is derived from the input RxData.
- * In case the user uses a 0 for the clock speed,
- * default to 0xffffffff and don't try to divide by
- * zero
- *--------------------------------------------------*/
- if ( info->params.clock_speed )
- {
- Tc = (u16)((XtalSpeed/DpllDivisor)/info->params.clock_speed);
- if ( !((((XtalSpeed/DpllDivisor) % info->params.clock_speed) * 2)
- / info->params.clock_speed) )
- Tc--;
- }
- else
- Tc = -1;
-
- /* Write 16-bit Time Constant for BRG1 */
- usc_OutReg( info, TC1R, Tc );
- RegValue |= BIT4; /* enable BRG1 */
- switch ( info->params.encoding ) {
- case HDLC_ENCODING_NRZ:
- case HDLC_ENCODING_NRZB:
- case HDLC_ENCODING_NRZI_MARK:
- case HDLC_ENCODING_NRZI_SPACE: RegValue |= BIT8; break;
- case HDLC_ENCODING_BIPHASE_MARK:
- case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT9; break;
- case HDLC_ENCODING_BIPHASE_LEVEL:
- case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: RegValue |= BIT9 + BIT8; break;
- }
- }
- usc_OutReg( info, HCR, RegValue );
- /* Channel Control/status Register (CCSR)
- *
- * <15> X RCC FIFO Overflow status (RO)
- * <14> X RCC FIFO Not Empty status (RO)
- * <13> 0 1 = Clear RCC FIFO (WO)
- * <12> X DPLL Sync (RW)
- * <11> X DPLL 2 Missed Clocks status (RO)
- * <10> X DPLL 1 Missed Clock status (RO)
- * <9..8> 00 DPLL Resync on rising and falling edges (RW)
- * <7> X SDLC Loop On status (RO)
- * <6> X SDLC Loop Send status (RO)
- * <5> 1 Bypass counters for TxClk and RxClk (RW)
- * <4..2> 000 Last Char of SDLC frame has 8 bits (RW)
- * <1..0> 00 reserved
- *
- * 0000 0000 0010 0000 = 0x0020
- */
- usc_OutReg( info, CCSR, 0x1020 );
- if ( info->params.flags & HDLC_FLAG_AUTO_CTS ) {
- usc_OutReg( info, SICR,
- (u16)(usc_InReg(info,SICR) | SICR_CTS_INACTIVE) );
- }
-
- /* enable Master Interrupt Enable bit (MIE) */
- usc_EnableMasterIrqBit( info );
- usc_ClearIrqPendingBits( info, RECEIVE_STATUS + RECEIVE_DATA +
- TRANSMIT_STATUS + TRANSMIT_DATA );
- info->mbre_bit = 0;
- outw( 0, info->io_base ); /* clear Master Bus Enable (DCAR) */
- usc_DmaCmd( info, DmaCmd_ResetAllChannels ); /* disable both DMA channels */
- info->mbre_bit = BIT8;
- outw( BIT8, info->io_base ); /* set Master Bus Enable (DCAR) */
- /* Enable DMAEN (Port 7, Bit 14) */
- /* This connects the DMA request signal to the ISA bus */
- /* on the ISA adapter. This has no effect for the PCI adapter */
- usc_OutReg( info, PCR, (u16)((usc_InReg(info, PCR) | BIT15) & ~BIT14) );
- /* DMA Control Register (DCR)
- *
- * <15..14> 10 Priority mode = Alternating Tx/Rx
- * 01 Rx has priority
- * 00 Tx has priority
- *
- * <13> 1 Enable Priority Preempt per DCR<15..14>
- * (WARNING DCR<11..10> must be 00 when this is 1)
- * 0 Choose activate channel per DCR<11..10>
- *
- * <12> 0 Little Endian for Array/List
- * <11..10> 00 Both Channels can use each bus grant
- * <9..6> 0000 reserved
- * <5> 0 7 CLK - Minimum Bus Re-request Interval
- * <4> 0 1 = drive D/C and S/D pins
- * <3> 1 1 = Add one wait state to all DMA cycles.
- * <2> 0 1 = Strobe /UAS on every transfer.
- * <1..0> 11 Addr incrementing only affects LS24 bits
- *
- * 0110 0000 0000 1011 = 0x600b
- */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
- /* PCI adapter does not need DMA wait state */
- usc_OutDmaReg( info, DCR, 0xa00b );
- }
- else
- usc_OutDmaReg( info, DCR, 0x800b );
- /* Receive DMA mode Register (RDMR)
- *
- * <15..14> 11 DMA mode = Linked List Buffer mode
- * <13> 1 RSBinA/L = store Rx status Block in Arrary/List entry
- * <12> 1 Clear count of List Entry after fetching
- * <11..10> 00 Address mode = Increment
- * <9> 1 Terminate Buffer on RxBound
- * <8> 0 Bus Width = 16bits
- * <7..0> ? status Bits (write as 0s)
- *
- * 1111 0010 0000 0000 = 0xf200
- */
- usc_OutDmaReg( info, RDMR, 0xf200 );
- /* Transmit DMA mode Register (TDMR)
- *
- * <15..14> 11 DMA mode = Linked List Buffer mode
- * <13> 1 TCBinA/L = fetch Tx Control Block from List entry
- * <12> 1 Clear count of List Entry after fetching
- * <11..10> 00 Address mode = Increment
- * <9> 1 Terminate Buffer on end of frame
- * <8> 0 Bus Width = 16bits
- * <7..0> ? status Bits (Read Only so write as 0)
- *
- * 1111 0010 0000 0000 = 0xf200
- */
- usc_OutDmaReg( info, TDMR, 0xf200 );
- /* DMA Interrupt Control Register (DICR)
- *
- * <15> 1 DMA Interrupt Enable
- * <14> 0 1 = Disable IEO from USC
- * <13> 0 1 = Don't provide vector during IntAck
- * <12> 1 1 = Include status in Vector
- * <10..2> 0 reserved, Must be 0s
- * <1> 0 1 = Rx DMA Interrupt Enabled
- * <0> 0 1 = Tx DMA Interrupt Enabled
- *
- * 1001 0000 0000 0000 = 0x9000
- */
- usc_OutDmaReg( info, DICR, 0x9000 );
- usc_InDmaReg( info, RDMR ); /* clear pending receive DMA IRQ bits */
- usc_InDmaReg( info, TDMR ); /* clear pending transmit DMA IRQ bits */
- usc_OutDmaReg( info, CDIR, 0x0303 ); /* clear IUS and Pending for Tx and Rx */
- /* Channel Control Register (CCR)
- *
- * <15..14> 10 Use 32-bit Tx Control Blocks (TCBs)
- * <13> 0 Trigger Tx on SW Command Disabled
- * <12> 0 Flag Preamble Disabled
- * <11..10> 00 Preamble Length
- * <9..8> 00 Preamble Pattern
- * <7..6> 10 Use 32-bit Rx status Blocks (RSBs)
- * <5> 0 Trigger Rx on SW Command Disabled
- * <4..0> 0 reserved
- *
- * 1000 0000 1000 0000 = 0x8080
- */
- RegValue = 0x8080;
- switch ( info->params.preamble_length ) {
- case HDLC_PREAMBLE_LENGTH_16BITS: RegValue |= BIT10; break;
- case HDLC_PREAMBLE_LENGTH_32BITS: RegValue |= BIT11; break;
- case HDLC_PREAMBLE_LENGTH_64BITS: RegValue |= BIT11 + BIT10; break;
- }
- switch ( info->params.preamble ) {
- case HDLC_PREAMBLE_PATTERN_FLAGS: RegValue |= BIT8 + BIT12; break;
- case HDLC_PREAMBLE_PATTERN_ONES: RegValue |= BIT8; break;
- case HDLC_PREAMBLE_PATTERN_10: RegValue |= BIT9; break;
- case HDLC_PREAMBLE_PATTERN_01: RegValue |= BIT9 + BIT8; break;
- }
- usc_OutReg( info, CCR, RegValue );
- /*
- * Burst/Dwell Control Register
- *
- * <15..8> 0x20 Maximum number of transfers per bus grant
- * <7..0> 0x00 Maximum number of clock cycles per bus grant
- */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
- /* don't limit bus occupancy on PCI adapter */
- usc_OutDmaReg( info, BDCR, 0x0000 );
- }
- else
- usc_OutDmaReg( info, BDCR, 0x2000 );
- usc_stop_transmitter(info);
- usc_stop_receiver(info);
-
- } /* end of usc_set_sdlc_mode() */
- /* usc_enable_loopback()
- *
- * Set the 16C32 for internal loopback mode.
- * The TxCLK and RxCLK signals are generated from the BRG0 and
- * the TxD is looped back to the RxD internally.
- *
- * Arguments: info pointer to device instance data
- * enable 1 = enable loopback, 0 = disable
- * Return Value: None
- */
- void usc_enable_loopback(struct mgsl_struct *info, int enable)
- {
- if (enable) {
- /* blank external TXD output */
- usc_OutReg(info,IOCR,usc_InReg(info,IOCR) | (BIT7+BIT6));
-
- /* Clock mode Control Register (CMCR)
- *
- * <15..14> 00 counter 1 Disabled
- * <13..12> 00 counter 0 Disabled
- * <11..10> 11 BRG1 Input is TxC Pin
- * <9..8> 11 BRG0 Input is TxC Pin
- * <7..6> 01 DPLL Input is BRG1 Output
- * <5..3> 100 TxCLK comes from BRG0
- * <2..0> 100 RxCLK comes from BRG0
- *
- * 0000 1111 0110 0100 = 0x0f64
- */
- usc_OutReg( info, CMCR, 0x0f64 );
- /* Write 16-bit Time Constant for BRG0 */
- /* use clock speed if available, otherwise use 8 for diagnostics */
- if (info->params.clock_speed) {
- if (info->bus_type == MGSL_BUS_TYPE_PCI)
- usc_OutReg(info, TC0R, (u16)((11059200/info->params.clock_speed)-1));
- else
- usc_OutReg(info, TC0R, (u16)((14745600/info->params.clock_speed)-1));
- } else
- usc_OutReg(info, TC0R, (u16)8);
- /* Hardware Configuration Register (HCR) Clear Bit 1, BRG0
- mode = Continuous Set Bit 0 to enable BRG0. */
- usc_OutReg( info, HCR, (u16)((usc_InReg( info, HCR ) & ~BIT1) | BIT0) );
- /* Input/Output Control Reg, <2..0> = 100, Drive RxC pin with BRG0 */
- usc_OutReg(info, IOCR, (u16)((usc_InReg(info, IOCR) & 0xfff8) | 0x0004));
- /* set Internal Data loopback mode */
- info->loopback_bits = 0x300;
- outw( 0x0300, info->io_base + CCAR );
- } else {
- /* enable external TXD output */
- usc_OutReg(info,IOCR,usc_InReg(info,IOCR) & ~(BIT7+BIT6));
-
- /* clear Internal Data loopback mode */
- info->loopback_bits = 0;
- outw( 0,info->io_base + CCAR );
- }
-
- } /* end of usc_enable_loopback() */
- /* usc_enable_aux_clock()
- *
- * Enabled the AUX clock output at the specified frequency.
- *
- * Arguments:
- *
- * info pointer to device extension
- * data_rate data rate of clock in bits per second
- * A data rate of 0 disables the AUX clock.
- *
- * Return Value: None
- */
- void usc_enable_aux_clock( struct mgsl_struct *info, u32 data_rate )
- {
- u32 XtalSpeed;
- u16 Tc;
- if ( data_rate ) {
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- XtalSpeed = 11059200;
- else
- XtalSpeed = 14745600;
- /* Tc = (Xtal/Speed) - 1 */
- /* If twice the remainder of (Xtal/Speed) is greater than Speed */
- /* then rounding up gives a more precise time constant. Instead */
- /* of rounding up and then subtracting 1 we just don't subtract */
- /* the one in this case. */
- Tc = (u16)(XtalSpeed/data_rate);
- if ( !(((XtalSpeed % data_rate) * 2) / data_rate) )
- Tc--;
- /* Write 16-bit Time Constant for BRG0 */
- usc_OutReg( info, TC0R, Tc );
- /*
- * Hardware Configuration Register (HCR)
- * Clear Bit 1, BRG0 mode = Continuous
- * Set Bit 0 to enable BRG0.
- */
- usc_OutReg( info, HCR, (u16)((usc_InReg( info, HCR ) & ~BIT1) | BIT0) );
- /* Input/Output Control Reg, <2..0> = 100, Drive RxC pin with BRG0 */
- usc_OutReg( info, IOCR, (u16)((usc_InReg(info, IOCR) & 0xfff8) | 0x0004) );
- } else {
- /* data rate == 0 so turn off BRG0 */
- usc_OutReg( info, HCR, (u16)(usc_InReg( info, HCR ) & ~BIT0) );
- }
- } /* end of usc_enable_aux_clock() */
- /*
- *
- * usc_process_rxoverrun_sync()
- *
- * This function processes a receive overrun by resetting the
- * receive DMA buffers and issuing a Purge Rx FIFO command
- * to allow the receiver to continue receiving.
- *
- * Arguments:
- *
- * info pointer to device extension
- *
- * Return Value: None
- */
- void usc_process_rxoverrun_sync( struct mgsl_struct *info )
- {
- int start_index;
- int end_index;
- int frame_start_index;
- int start_of_frame_found = FALSE;
- int end_of_frame_found = FALSE;
- int reprogram_dma = FALSE;
- DMABUFFERENTRY *buffer_list = info->rx_buffer_list;
- u32 phys_addr;
- usc_DmaCmd( info, DmaCmd_PauseRxChannel );
- usc_RCmd( info, RCmd_EnterHuntmode );
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- /* CurrentRxBuffer points to the 1st buffer of the next */
- /* possibly available receive frame. */
-
- frame_start_index = start_index = end_index = info->current_rx_buffer;
- /* Search for an unfinished string of buffers. This means */
- /* that a receive frame started (at least one buffer with */
- /* count set to zero) but there is no terminiting buffer */
- /* (status set to non-zero). */
- while( !buffer_list[end_index].count )
- {
- /* Count field has been reset to zero by 16C32. */
- /* This buffer is currently in use. */
- if ( !start_of_frame_found )
- {
- start_of_frame_found = TRUE;
- frame_start_index = end_index;
- end_of_frame_found = FALSE;
- }
- if ( buffer_list[end_index].status )
- {
- /* Status field has been set by 16C32. */
- /* This is the last buffer of a received frame. */
- /* We want to leave the buffers for this frame intact. */
- /* Move on to next possible frame. */
- start_of_frame_found = FALSE;
- end_of_frame_found = TRUE;
- }
- /* advance to next buffer entry in linked list */
- end_index++;
- if ( end_index == info->rx_buffer_count )
- end_index = 0;
- if ( start_index == end_index )
- {
- /* The entire list has been searched with all Counts == 0 and */
- /* all Status == 0. The receive buffers are */
- /* completely screwed, reset all receive buffers! */
- mgsl_reset_rx_dma_buffers( info );
- frame_start_index = 0;
- start_of_frame_found = FALSE;
- reprogram_dma = TRUE;
- break;
- }
- }
- if ( start_of_frame_found && !end_of_frame_found )
- {
- /* There is an unfinished string of receive DMA buffers */
- /* as a result of the receiver overrun. */
- /* Reset the buffers for the unfinished frame */
- /* and reprogram the receive DMA controller to start */
- /* at the 1st buffer of unfinished frame. */
- start_index = frame_start_index;
- do
- {
- *((unsigned long *)&(info->rx_buffer_list[start_index++].count)) = DMABUFFERSIZE;
- /* Adjust index for wrap around. */
- if ( start_index == info->rx_buffer_count )
- start_index = 0;
- } while( start_index != end_index );
- reprogram_dma = TRUE;
- }
- if ( reprogram_dma )
- {
- usc_UnlatchRxstatusBits(info,RXSTATUS_ALL);
- usc_ClearIrqPendingBits(info, RECEIVE_DATA|RECEIVE_STATUS);
- usc_UnlatchRxstatusBits(info, RECEIVE_DATA|RECEIVE_STATUS);
-
- usc_EnableReceiver(info,DISABLE_UNCONDITIONAL);
-
- /* This empties the receive FIFO and loads the RCC with RCLR */
- usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
- /* program 16C32 with physical address of 1st DMA buffer entry */
- phys_addr = info->rx_buffer_list[frame_start_index].phys_entry;
- usc_OutDmaReg( info, NRARL, (u16)phys_addr );
- usc_OutDmaReg( info, NRARU, (u16)(phys_addr >> 16) );
- usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, RECEIVE_DATA + RECEIVE_STATUS );
- usc_EnableInterrupts( info, RECEIVE_STATUS );
- /* 1. Arm End of Buffer (EOB) Receive DMA Interrupt (BIT2 of RDIAR) */
- /* 2. Enable Receive DMA Interrupts (BIT1 of DICR) */
- usc_OutDmaReg( info, RDIAR, BIT3 + BIT2 );
- usc_OutDmaReg( info, DICR, (u16)(usc_InDmaReg(info,DICR) | BIT1) );
- usc_DmaCmd( info, DmaCmd_InitRxChannel );
- if ( info->params.flags & HDLC_FLAG_AUTO_DCD )
- usc_EnableReceiver(info,ENABLE_AUTO_DCD);
- else
- usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
- }
- else
- {
- /* This empties the receive FIFO and loads the RCC with RCLR */
- usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- }
- } /* end of usc_process_rxoverrun_sync() */
- /* usc_stop_receiver()
- *
- * Disable USC receiver
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_stop_receiver( struct mgsl_struct *info )
- {
- if (debug_level >= DEBUG_LEVEL_ISR)
- printk("%s(%d):usc_stop_receiver(%s)n",
- __FILE__,__LINE__, info->device_name );
-
- /* Disable receive DMA channel. */
- /* This also disables receive DMA channel interrupts */
- usc_DmaCmd( info, DmaCmd_ResetRxChannel );
- usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, RECEIVE_DATA + RECEIVE_STATUS );
- usc_DisableInterrupts( info, RECEIVE_DATA + RECEIVE_STATUS );
- usc_EnableReceiver(info,DISABLE_UNCONDITIONAL);
- /* This empties the receive FIFO and loads the RCC with RCLR */
- usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- info->rx_enabled = 0;
- info->rx_overflow = 0;
-
- } /* end of stop_receiver() */
- /* usc_start_receiver()
- *
- * Enable the USC receiver
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_start_receiver( struct mgsl_struct *info )
- {
- u32 phys_addr;
-
- if (debug_level >= DEBUG_LEVEL_ISR)
- printk("%s(%d):usc_start_receiver(%s)n",
- __FILE__,__LINE__, info->device_name );
- mgsl_reset_rx_dma_buffers( info );
- usc_stop_receiver( info );
- usc_OutReg( info, CCSR, (u16)(usc_InReg(info,CCSR) | BIT13) );
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- if ( info->params.mode == MGSL_MODE_HDLC ||
- info->params.mode == MGSL_MODE_RAW ) {
- /* DMA mode Transfers */
- /* Program the DMA controller. */
- /* Enable the DMA controller end of buffer interrupt. */
- /* program 16C32 with physical address of 1st DMA buffer entry */
- phys_addr = info->rx_buffer_list[0].phys_entry;
- usc_OutDmaReg( info, NRARL, (u16)phys_addr );
- usc_OutDmaReg( info, NRARU, (u16)(phys_addr >> 16) );
- usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, RECEIVE_DATA + RECEIVE_STATUS );
- usc_EnableInterrupts( info, RECEIVE_STATUS );
- /* 1. Arm End of Buffer (EOB) Receive DMA Interrupt (BIT2 of RDIAR) */
- /* 2. Enable Receive DMA Interrupts (BIT1 of DICR) */
- usc_OutDmaReg( info, RDIAR, BIT3 + BIT2 );
- usc_OutDmaReg( info, DICR, (u16)(usc_InDmaReg(info,DICR) | BIT1) );
- usc_DmaCmd( info, DmaCmd_InitRxChannel );
- if ( info->params.flags & HDLC_FLAG_AUTO_DCD )
- usc_EnableReceiver(info,ENABLE_AUTO_DCD);
- else
- usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
- } else {
- usc_UnlatchRxstatusBits(info, RXSTATUS_ALL);
- usc_ClearIrqPendingBits(info, RECEIVE_DATA + RECEIVE_STATUS);
- usc_EnableInterrupts(info, RECEIVE_DATA);
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- usc_RCmd( info, RCmd_EnterHuntmode );
- usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
- }
- usc_OutReg( info, CCSR, 0x1020 );
- info->rx_enabled = 1;
- } /* end of usc_start_receiver() */
- /* usc_start_transmitter()
- *
- * Enable the USC transmitter and send a transmit frame if
- * one is loaded in the DMA buffers.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_start_transmitter( struct mgsl_struct *info )
- {
- u32 phys_addr;
- unsigned int FrameSize;
- if (debug_level >= DEBUG_LEVEL_ISR)
- printk("%s(%d):usc_start_transmitter(%s)n",
- __FILE__,__LINE__, info->device_name );
-
- if ( info->xmit_cnt ) {
- /* If auto RTS enabled and RTS is inactive, then assert */
- /* RTS and set a flag indicating that the driver should */
- /* negate RTS when the transmission completes. */
- info->drop_rts_on_tx_done = 0;
- if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
- usc_get_serial_signals( info );
- if ( !(info->serial_signals & SerialSignal_RTS) ) {
- info->serial_signals |= SerialSignal_RTS;
- usc_set_serial_signals( info );
- info->drop_rts_on_tx_done = 1;
- }
- }
- if ( info->params.mode == MGSL_MODE_ASYNC ) {
- if ( !info->tx_active ) {
- usc_UnlatchTxstatusBits(info, TXSTATUS_ALL);
- usc_ClearIrqPendingBits(info, TRANSMIT_STATUS + TRANSMIT_DATA);
- usc_EnableInterrupts(info, TRANSMIT_DATA);
- usc_load_txfifo(info);
- }
- } else {
- /* Disable transmit DMA controller while programming. */
- usc_DmaCmd( info, DmaCmd_ResetTxChannel );
-
- /* Transmit DMA buffer is loaded, so program USC */
- /* to send the frame contained in the buffers. */
- FrameSize = info->tx_buffer_list[info->start_tx_dma_buffer].rcc;
- /* if operating in Raw sync mode, reset the rcc component
- * of the tx dma buffer entry, otherwise, the serial controller
- * will send a closing sync char after this count.
- */
- if ( info->params.mode == MGSL_MODE_RAW )
- info->tx_buffer_list[info->start_tx_dma_buffer].rcc = 0;
- /* Program the Transmit Character Length Register (TCLR) */
- /* and clear FIFO (TCC is loaded with TCLR on FIFO clear) */
- usc_OutReg( info, TCLR, (u16)FrameSize );
- usc_RTCmd( info, RTCmd_PurgeTxFifo );
- /* Program the address of the 1st DMA Buffer Entry in linked list */
- phys_addr = info->tx_buffer_list[info->start_tx_dma_buffer].phys_entry;
- usc_OutDmaReg( info, NTARL, (u16)phys_addr );
- usc_OutDmaReg( info, NTARU, (u16)(phys_addr >> 16) );
- usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
- usc_EnableInterrupts( info, TRANSMIT_STATUS );
- if ( info->params.mode == MGSL_MODE_RAW &&
- info->num_tx_dma_buffers > 1 ) {
- /* When running external sync mode, attempt to 'stream' transmit */
- /* by filling tx dma buffers as they become available. To do this */
- /* we need to enable Tx DMA EOB Status interrupts : */
- /* */
- /* 1. Arm End of Buffer (EOB) Transmit DMA Interrupt (BIT2 of TDIAR) */
- /* 2. Enable Transmit DMA Interrupts (BIT0 of DICR) */
- usc_OutDmaReg( info, TDIAR, BIT2|BIT3 );
- usc_OutDmaReg( info, DICR, (u16)(usc_InDmaReg(info,DICR) | BIT0) );
- }
- /* Initialize Transmit DMA Channel */
- usc_DmaCmd( info, DmaCmd_InitTxChannel );
-
- usc_TCmd( info, TCmd_SendFrame );
-
- info->tx_timer.expires = jiffies + jiffies_from_ms(5000);
- add_timer(&info->tx_timer);
- }
- info->tx_active = 1;
- }
- if ( !info->tx_enabled ) {
- info->tx_enabled = 1;
- if ( info->params.flags & HDLC_FLAG_AUTO_CTS )
- usc_EnableTransmitter(info,ENABLE_AUTO_CTS);
- else
- usc_EnableTransmitter(info,ENABLE_UNCONDITIONAL);
- }
- } /* end of usc_start_transmitter() */
- /* usc_stop_transmitter()
- *
- * Stops the transmitter and DMA
- *
- * Arguments: info pointer to device isntance data
- * Return Value: None
- */
- void usc_stop_transmitter( struct mgsl_struct *info )
- {
- if (debug_level >= DEBUG_LEVEL_ISR)
- printk("%s(%d):usc_stop_transmitter(%s)n",
- __FILE__,__LINE__, info->device_name );
-
- del_timer(&info->tx_timer);
-
- usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, TRANSMIT_STATUS + TRANSMIT_DATA );
- usc_DisableInterrupts( info, TRANSMIT_STATUS + TRANSMIT_DATA );
- usc_EnableTransmitter(info,DISABLE_UNCONDITIONAL);
- usc_DmaCmd( info, DmaCmd_ResetTxChannel );
- usc_RTCmd( info, RTCmd_PurgeTxFifo );
- info->tx_enabled = 0;
- info->tx_active = 0;
- } /* end of usc_stop_transmitter() */
- /* usc_load_txfifo()
- *
- * Fill the transmit FIFO until the FIFO is full or
- * there is no more data to load.
- *
- * Arguments: info pointer to device extension (instance data)
- * Return Value: None
- */
- void usc_load_txfifo( struct mgsl_struct *info )
- {
- int Fifocount;
- u8 TwoBytes[2];
-
- if ( !info->xmit_cnt && !info->x_char )
- return;
-
- /* Select transmit FIFO status readback in TICR */
- usc_TCmd( info, TCmd_SelectTicrTxFifostatus );
- /* load the Transmit FIFO until FIFOs full or all data sent */
- while( (Fifocount = usc_InReg(info, TICR) >> 8) && info->xmit_cnt ) {
- /* there is more space in the transmit FIFO and */
- /* there is more data in transmit buffer */
- if ( (info->xmit_cnt > 1) && (Fifocount > 1) && !info->x_char ) {
- /* write a 16-bit word from transmit buffer to 16C32 */
-
- TwoBytes[0] = info->xmit_buf[info->xmit_tail++];
- info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
- TwoBytes[1] = info->xmit_buf[info->xmit_tail++];
- info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
-
- outw( *((u16 *)TwoBytes), info->io_base + DATAREG);
-
- info->xmit_cnt -= 2;
- info->icount.tx += 2;
- } else {
- /* only 1 byte left to transmit or 1 FIFO slot left */
-
- outw( (inw( info->io_base + CCAR) & 0x0780) | (TDR+LSBONLY),
- info->io_base + CCAR );
-
- if (info->x_char) {
- /* transmit pending high priority char */
- outw( info->x_char,info->io_base + CCAR );
- info->x_char = 0;
- } else {
- outw( info->xmit_buf[info->xmit_tail++],info->io_base + CCAR );
- info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
- info->xmit_cnt--;
- }
- info->icount.tx++;
- }
- }
- } /* end of usc_load_txfifo() */
- /* usc_reset()
- *
- * Reset the adapter to a known state and prepare it for further use.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_reset( struct mgsl_struct *info )
- {
- if ( info->bus_type == MGSL_BUS_TYPE_PCI ) {
- int i;
- u32 readval;
- /* Set BIT30 of Misc Control Register */
- /* (Local Control Register 0x50) to force reset of USC. */
- volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
- u32 *LCR0BRDR = (u32 *)(info->lcr_base + 0x28);
- info->misc_ctrl_value |= BIT30;
- *MiscCtrl = info->misc_ctrl_value;
- /*
- * Force at least 170ns delay before clearing
- * reset bit. Each read from LCR takes at least
- * 30ns so 10 times for 300ns to be safe.
- */
- for(i=0;i<10;i++)
- readval = *MiscCtrl;
- info->misc_ctrl_value &= ~BIT30;
- *MiscCtrl = info->misc_ctrl_value;
- *LCR0BRDR = BUS_DESCRIPTOR(
- 1, // Write Strobe Hold (0-3)
- 2, // Write Strobe Delay (0-3)
- 2, // Read Strobe Delay (0-3)
- 0, // NWDD (Write data-data) (0-3)
- 4, // NWAD (Write Addr-data) (0-31)
- 0, // NXDA (Read/Write Data-Addr) (0-3)
- 0, // NRDD (Read Data-Data) (0-3)
- 5 // NRAD (Read Addr-Data) (0-31)
- );
- } else {
- /* do HW reset */
- outb( 0,info->io_base + 8 );
- }
- info->mbre_bit = 0;
- info->loopback_bits = 0;
- info->usc_idle_mode = 0;
- /*
- * Program the Bus Configuration Register (BCR)
- *
- * <15> 0 Don't use seperate address
- * <14..6> 0 reserved
- * <5..4> 00 IAckmode = Default, don't care
- * <3> 1 Bus Request Totem Pole output
- * <2> 1 Use 16 Bit data bus
- * <1> 0 IRQ Totem Pole output
- * <0> 0 Don't Shift Right Addr
- *
- * 0000 0000 0000 1100 = 0x000c
- *
- * By writing to io_base + SDPIN the Wait/Ack pin is
- * programmed to work as a Wait pin.
- */
-
- outw( 0x000c,info->io_base + SDPIN );
- outw( 0,info->io_base );
- outw( 0,info->io_base + CCAR );
- /* select little endian byte ordering */
- usc_RTCmd( info, RTCmd_SelectLittleEndian );
- /* Port Control Register (PCR)
- *
- * <15..14> 11 Port 7 is Output (~DMAEN, Bit 14 : 0 = Enabled)
- * <13..12> 11 Port 6 is Output (~INTEN, Bit 12 : 0 = Enabled)
- * <11..10> 00 Port 5 is Input (No Connect, Don't Care)
- * <9..8> 00 Port 4 is Input (No Connect, Don't Care)
- * <7..6> 11 Port 3 is Output (~RTS, Bit 6 : 0 = Enabled )
- * <5..4> 11 Port 2 is Output (~DTR, Bit 4 : 0 = Enabled )
- * <3..2> 01 Port 1 is Input (Dedicated RxC)
- * <1..0> 01 Port 0 is Input (Dedicated TxC)
- *
- * 1111 0000 1111 0101 = 0xf0f5
- */
- usc_OutReg( info, PCR, 0xf0f5 );
- /*
- * Input/Output Control Register
- *
- * <15..14> 00 CTS is active low input
- * <13..12> 00 DCD is active low input
- * <11..10> 00 TxREQ pin is input (DSR)
- * <9..8> 00 RxREQ pin is input (RI)
- * <7..6> 00 TxD is output (Transmit Data)
- * <5..3> 000 TxC Pin in Input (14.7456MHz Clock)
- * <2..0> 100 RxC is Output (drive with BRG0)
- *
- * 0000 0000 0000 0100 = 0x0004
- */
- usc_OutReg( info, IOCR, 0x0004 );
- } /* end of usc_reset() */
- /* usc_set_async_mode()
- *
- * Program adapter for asynchronous communications.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_set_async_mode( struct mgsl_struct *info )
- {
- u16 RegValue;
- /* disable interrupts while programming USC */
- usc_DisableMasterIrqBit( info );
- outw( 0, info->io_base ); /* clear Master Bus Enable (DCAR) */
- usc_DmaCmd( info, DmaCmd_ResetAllChannels ); /* disable both DMA channels */
- usc_loopback_frame( info );
- /* Channel mode Register (CMR)
- *
- * <15..14> 00 Tx Sub modes, 00 = 1 Stop Bit
- * <13..12> 00 00 = 16X Clock
- * <11..8> 0000 Transmitter mode = Asynchronous
- * <7..6> 00 reserved?
- * <5..4> 00 Rx Sub modes, 00 = 16X Clock
- * <3..0> 0000 Receiver mode = Asynchronous
- *
- * 0000 0000 0000 0000 = 0x0
- */
- RegValue = 0;
- if ( info->params.stop_bits != 1 )
- RegValue |= BIT14;
- usc_OutReg( info, CMR, RegValue );
-
- /* Receiver mode Register (RMR)
- *
- * <15..13> 000 encoding = None
- * <12..08> 00000 reserved (Sync Only)
- * <7..6> 00 Even parity
- * <5> 0 parity disabled
- * <4..2> 000 Receive Char Length = 8 bits
- * <1..0> 00 Disable Receiver
- *
- * 0000 0000 0000 0000 = 0x0
- */
- RegValue = 0;
- if ( info->params.data_bits != 8 )
- RegValue |= BIT4+BIT3+BIT2;
- if ( info->params.parity != ASYNC_PARITY_NONE ) {
- RegValue |= BIT5;
- if ( info->params.parity != ASYNC_PARITY_ODD )
- RegValue |= BIT6;
- }
- usc_OutReg( info, RMR, RegValue );
- /* Set IRQ trigger level */
- usc_RCmd( info, RCmd_SelectRicrIntLevel );
-
- /* Receive Interrupt Control Register (RICR)
- *
- * <15..8> ? RxFIFO IRQ Request Level
- *
- * Note: For async mode the receive FIFO level must be set
- * to 0 to aviod the situation where the FIFO contains fewer bytes
- * than the trigger level and no more data is expected.
- *
- * <7> 0 Exited Hunt IA (Interrupt Arm)
- * <6> 0 Idle Received IA
- * <5> 0 Break/Abort IA
- * <4> 0 Rx Bound IA
- * <3> 0 Queued status reflects oldest byte in FIFO
- * <2> 0 Abort/PE IA
- * <1> 0 Rx Overrun IA
- * <0> 0 Select TC0 value for readback
- *
- * 0000 0000 0100 0000 = 0x0000 + (FIFOLEVEL in MSB)
- */
-
- usc_OutReg( info, RICR, 0x0000 );
- usc_UnlatchRxstatusBits( info, RXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, RECEIVE_STATUS );
-
- /* Transmit mode Register (TMR)
- *
- * <15..13> 000 encoding = None
- * <12..08> 00000 reserved (Sync Only)
- * <7..6> 00 Transmit parity Even
- * <5> 0 Transmit parity Disabled
- * <4..2> 000 Tx Char Length = 8 bits
- * <1..0> 00 Disable Transmitter
- *
- * 0000 0000 0000 0000 = 0x0
- */
- RegValue = 0;
- if ( info->params.data_bits != 8 )
- RegValue |= BIT4+BIT3+BIT2;
- if ( info->params.parity != ASYNC_PARITY_NONE ) {
- RegValue |= BIT5;
- if ( info->params.parity != ASYNC_PARITY_ODD )
- RegValue |= BIT6;
- }
- usc_OutReg( info, TMR, RegValue );
- usc_set_txidle( info );
- /* Set IRQ trigger level */
- usc_TCmd( info, TCmd_SelectTicrIntLevel );
-
- /* Transmit Interrupt Control Register (TICR)
- *
- * <15..8> ? Transmit FIFO IRQ Level
- * <7> 0 Present IA (Interrupt Arm)
- * <6> 1 Idle Sent IA
- * <5> 0 Abort Sent IA
- * <4> 0 EOF/EOM Sent IA
- * <3> 0 CRC Sent IA
- * <2> 0 1 = Wait for SW Trigger to Start Frame
- * <1> 0 Tx Underrun IA
- * <0> 0 TC0 constant on read back
- *
- * 0000 0000 0100 0000 = 0x0040
- */
- usc_OutReg( info, TICR, 0x1f40 );
- usc_UnlatchTxstatusBits( info, TXSTATUS_ALL );
- usc_ClearIrqPendingBits( info, TRANSMIT_STATUS );
- usc_enable_async_clock( info, info->params.data_rate );
-
- /* Channel Control/status Register (CCSR)
- *
- * <15> X RCC FIFO Overflow status (RO)
- * <14> X RCC FIFO Not Empty status (RO)
- * <13> 0 1 = Clear RCC FIFO (WO)
- * <12> X DPLL in Sync status (RO)
- * <11> X DPLL 2 Missed Clocks status (RO)
- * <10> X DPLL 1 Missed Clock status (RO)
- * <9..8> 00 DPLL Resync on rising and falling edges (RW)
- * <7> X SDLC Loop On status (RO)
- * <6> X SDLC Loop Send status (RO)
- * <5> 1 Bypass counters for TxClk and RxClk (RW)
- * <4..2> 000 Last Char of SDLC frame has 8 bits (RW)
- * <1..0> 00 reserved
- *
- * 0000 0000 0010 0000 = 0x0020
- */
-
- usc_OutReg( info, CCSR, 0x0020 );
- usc_DisableInterrupts( info, TRANSMIT_STATUS + TRANSMIT_DATA +
- RECEIVE_DATA + RECEIVE_STATUS );
- usc_ClearIrqPendingBits( info, TRANSMIT_STATUS + TRANSMIT_DATA +
- RECEIVE_DATA + RECEIVE_STATUS );
- usc_EnableMasterIrqBit( info );
- /* Enable INTEN (Port 6, Bit12) */
- /* This connects the IRQ request signal to the ISA bus */
- /* on the ISA adapter. This has no effect for the PCI adapter */
- usc_OutReg( info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) & ~BIT12) );
- } /* end of usc_set_async_mode() */
- /* usc_loopback_frame()
- *
- * Loop back a small (2 byte) dummy SDLC frame.
- * Interrupts and DMA are NOT used. The purpose of this is to
- * clear any 'stale' status info left over from running in async mode.
- *
- * The 16C32 shows the strange behaviour of marking the 1st
- * received SDLC frame with a CRC error even when there is no
- * CRC error. To get around this a small dummy from of 2 bytes
- * is looped back when switching from async to sync mode.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_loopback_frame( struct mgsl_struct *info )
- {
- int i;
- unsigned long oldmode = info->params.mode;
- info->params.mode = MGSL_MODE_HDLC;
-
- usc_DisableMasterIrqBit( info );
- usc_set_sdlc_mode( info );
- usc_enable_loopback( info, 1 );
- /* Write 16-bit Time Constant for BRG0 */
- usc_OutReg( info, TC0R, 0 );
-
- /* Channel Control Register (CCR)
- *
- * <15..14> 00 Don't use 32-bit Tx Control Blocks (TCBs)
- * <13> 0 Trigger Tx on SW Command Disabled
- * <12> 0 Flag Preamble Disabled
- * <11..10> 00 Preamble Length = 8-Bits
- * <9..8> 01 Preamble Pattern = flags
- * <7..6> 10 Don't use 32-bit Rx status Blocks (RSBs)
- * <5> 0 Trigger Rx on SW Command Disabled
- * <4..0> 0 reserved
- *
- * 0000 0001 0000 0000 = 0x0100
- */
- usc_OutReg( info, CCR, 0x0100 );
- /* SETUP RECEIVER */
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- usc_EnableReceiver(info,ENABLE_UNCONDITIONAL);
- /* SETUP TRANSMITTER */
- /* Program the Transmit Character Length Register (TCLR) */
- /* and clear FIFO (TCC is loaded with TCLR on FIFO clear) */
- usc_OutReg( info, TCLR, 2 );
- usc_RTCmd( info, RTCmd_PurgeTxFifo );
- /* unlatch Tx status bits, and start transmit channel. */
- usc_UnlatchTxstatusBits(info,TXSTATUS_ALL);
- outw(0,info->io_base + DATAREG);
- /* ENABLE TRANSMITTER */
- usc_TCmd( info, TCmd_SendFrame );
- usc_EnableTransmitter(info,ENABLE_UNCONDITIONAL);
-
- /* WAIT FOR RECEIVE COMPLETE */
- for (i=0 ; i<1000 ; i++)
- if (usc_InReg( info, RCSR ) & (BIT8 + BIT4 + BIT3 + BIT1))
- break;
- /* clear Internal Data loopback mode */
- usc_enable_loopback(info, 0);
- usc_EnableMasterIrqBit(info);
- info->params.mode = oldmode;
- } /* end of usc_loopback_frame() */
- /* usc_set_sync_mode() Programs the USC for SDLC communications.
- *
- * Arguments: info pointer to adapter info structure
- * Return Value: None
- */
- void usc_set_sync_mode( struct mgsl_struct *info )
- {
- usc_loopback_frame( info );
- usc_set_sdlc_mode( info );
- /* Enable INTEN (Port 6, Bit12) */
- /* This connects the IRQ request signal to the ISA bus */
- /* on the ISA adapter. This has no effect for the PCI adapter */
- usc_OutReg(info, PCR, (u16)((usc_InReg(info, PCR) | BIT13) & ~BIT12));
- usc_enable_aux_clock(info, info->params.clock_speed);
- if (info->params.loopback)
- usc_enable_loopback(info,1);
- } /* end of mgsl_set_sync_mode() */
- /* usc_set_txidle() Set the HDLC idle mode for the transmitter.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_set_txidle( struct mgsl_struct *info )
- {
- u16 usc_idle_mode = IDLEMODE_FLAGS;
- /* Map API idle mode to USC register bits */
- switch( info->idle_mode ){
- case HDLC_TXIDLE_FLAGS: usc_idle_mode = IDLEMODE_FLAGS; break;
- case HDLC_TXIDLE_ALT_ZEROS_ONES: usc_idle_mode = IDLEMODE_ALT_ONE_ZERO; break;
- case HDLC_TXIDLE_ZEROS: usc_idle_mode = IDLEMODE_ZERO; break;
- case HDLC_TXIDLE_ONES: usc_idle_mode = IDLEMODE_ONE; break;
- case HDLC_TXIDLE_ALT_MARK_SPACE: usc_idle_mode = IDLEMODE_ALT_MARK_SPACE; break;
- case HDLC_TXIDLE_SPACE: usc_idle_mode = IDLEMODE_SPACE; break;
- case HDLC_TXIDLE_MARK: usc_idle_mode = IDLEMODE_MARK; break;
- }
- info->usc_idle_mode = usc_idle_mode;
- //usc_OutReg(info, TCSR, usc_idle_mode);
- info->tcsr_value &= ~IDLEMODE_MASK; /* clear idle mode bits */
- info->tcsr_value += usc_idle_mode;
- usc_OutReg(info, TCSR, info->tcsr_value);
- /*
- * if SyncLink WAN adapter is running in external sync mode, the
- * transmitter has been set to Monosync in order to try to mimic
- * a true raw outbound bit stream. Monosync still sends an open/close
- * sync char at the start/end of a frame. Try to match those sync
- * patterns to the idle mode set here
- */
- if ( info->params.mode == MGSL_MODE_RAW ) {
- unsigned char syncpat = 0;
- switch( info->idle_mode ) {
- case HDLC_TXIDLE_FLAGS:
- syncpat = 0x7e;
- break;
- case HDLC_TXIDLE_ALT_ZEROS_ONES:
- syncpat = 0x55;
- break;
- case HDLC_TXIDLE_ZEROS:
- case HDLC_TXIDLE_SPACE:
- syncpat = 0x00;
- break;
- case HDLC_TXIDLE_ONES:
- case HDLC_TXIDLE_MARK:
- syncpat = 0xff;
- break;
- case HDLC_TXIDLE_ALT_MARK_SPACE:
- syncpat = 0xaa;
- break;
- }
- usc_SetTransmitSyncChars(info,syncpat,syncpat);
- }
- } /* end of usc_set_txidle() */
- /* usc_get_serial_signals()
- *
- * Query the adapter for the state of the V24 status (input) signals.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_get_serial_signals( struct mgsl_struct *info )
- {
- u16 status;
- /* clear all serial signals except DTR and RTS */
- info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
- /* Read the Misc Interrupt status Register (MISR) to get */
- /* the V24 status signals. */
- status = usc_InReg( info, MISR );
- /* set serial signal bits to reflect MISR */
- if ( status & MISCSTATUS_CTS )
- info->serial_signals |= SerialSignal_CTS;
- if ( status & MISCSTATUS_DCD )
- info->serial_signals |= SerialSignal_DCD;
- if ( status & MISCSTATUS_RI )
- info->serial_signals |= SerialSignal_RI;
- if ( status & MISCSTATUS_DSR )
- info->serial_signals |= SerialSignal_DSR;
- } /* end of usc_get_serial_signals() */
- /* usc_set_serial_signals()
- *
- * Set the state of DTR and RTS based on contents of
- * serial_signals member of device extension.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void usc_set_serial_signals( struct mgsl_struct *info )
- {
- u16 Control;
- unsigned char V24Out = info->serial_signals;
- /* get the current value of the Port Control Register (PCR) */
- Control = usc_InReg( info, PCR );
- if ( V24Out & SerialSignal_RTS )
- Control &= ~(BIT6);
- else
- Control |= BIT6;
- if ( V24Out & SerialSignal_DTR )
- Control &= ~(BIT4);
- else
- Control |= BIT4;
- usc_OutReg( info, PCR, Control );
- } /* end of usc_set_serial_signals() */
- /* usc_enable_async_clock()
- *
- * Enable the async clock at the specified frequency.
- *
- * Arguments: info pointer to device instance data
- * data_rate data rate of clock in bps
- * 0 disables the AUX clock.
- * Return Value: None
- */
- void usc_enable_async_clock( struct mgsl_struct *info, u32 data_rate )
- {
- if ( data_rate ) {
- /*
- * Clock mode Control Register (CMCR)
- *
- * <15..14> 00 counter 1 Disabled
- * <13..12> 00 counter 0 Disabled
- * <11..10> 11 BRG1 Input is TxC Pin
- * <9..8> 11 BRG0 Input is TxC Pin
- * <7..6> 01 DPLL Input is BRG1 Output
- * <5..3> 100 TxCLK comes from BRG0
- * <2..0> 100 RxCLK comes from BRG0
- *
- * 0000 1111 0110 0100 = 0x0f64
- */
-
- usc_OutReg( info, CMCR, 0x0f64 );
- /*
- * Write 16-bit Time Constant for BRG0
- * Time Constant = (ClkSpeed / data_rate) - 1
- * ClkSpeed = 921600 (ISA), 691200 (PCI)
- */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- usc_OutReg( info, TC0R, (u16)((691200/data_rate) - 1) );
- else
- usc_OutReg( info, TC0R, (u16)((921600/data_rate) - 1) );
-
- /*
- * Hardware Configuration Register (HCR)
- * Clear Bit 1, BRG0 mode = Continuous
- * Set Bit 0 to enable BRG0.
- */
- usc_OutReg( info, HCR,
- (u16)((usc_InReg( info, HCR ) & ~BIT1) | BIT0) );
- /* Input/Output Control Reg, <2..0> = 100, Drive RxC pin with BRG0 */
- usc_OutReg( info, IOCR,
- (u16)((usc_InReg(info, IOCR) & 0xfff8) | 0x0004) );
- } else {
- /* data rate == 0 so turn off BRG0 */
- usc_OutReg( info, HCR, (u16)(usc_InReg( info, HCR ) & ~BIT0) );
- }
- } /* end of usc_enable_async_clock() */
- /*
- * Buffer Structures:
- *
- * Normal memory access uses virtual addresses that can make discontiguous
- * physical memory pages appear to be contiguous in the virtual address
- * space (the processors memory mapping handles the conversions).
- *
- * DMA transfers require physically contiguous memory. This is because
- * the DMA system controller and DMA bus masters deal with memory using
- * only physical addresses.
- *
- * This causes a problem under Windows NT when large DMA buffers are
- * needed. Fragmentation of the nonpaged pool prevents allocations of
- * physically contiguous buffers larger than the PAGE_SIZE.
- *
- * However the 16C32 supports Bus Master Scatter/Gather DMA which
- * allows DMA transfers to physically discontiguous buffers. Information
- * about each data transfer buffer is contained in a memory structure
- * called a 'buffer entry'. A list of buffer entries is maintained
- * to track and control the use of the data transfer buffers.
- *
- * To support this strategy we will allocate sufficient PAGE_SIZE
- * contiguous memory buffers to allow for the total required buffer
- * space.
- *
- * The 16C32 accesses the list of buffer entries using Bus Master
- * DMA. Control information is read from the buffer entries by the
- * 16C32 to control data transfers. status information is written to
- * the buffer entries by the 16C32 to indicate the status of completed
- * transfers.
- *
- * The CPU writes control information to the buffer entries to control
- * the 16C32 and reads status information from the buffer entries to
- * determine information about received and transmitted frames.
- *
- * Because the CPU and 16C32 (adapter) both need simultaneous access
- * to the buffer entries, the buffer entry memory is allocated with
- * HalAllocateCommonBuffer(). This restricts the size of the buffer
- * entry list to PAGE_SIZE.
- *
- * The actual data buffers on the other hand will only be accessed
- * by the CPU or the adapter but not by both simultaneously. This allows
- * Scatter/Gather packet based DMA procedures for using physically
- * discontiguous pages.
- */
- /*
- * mgsl_reset_tx_dma_buffers()
- *
- * Set the count for all transmit buffers to 0 to indicate the
- * buffer is available for use and set the current buffer to the
- * first buffer. This effectively makes all buffers free and
- * discards any data in buffers.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void mgsl_reset_tx_dma_buffers( struct mgsl_struct *info )
- {
- unsigned int i;
- for ( i = 0; i < info->tx_buffer_count; i++ ) {
- *((unsigned long *)&(info->tx_buffer_list[i].count)) = 0;
- }
- info->current_tx_buffer = 0;
- info->start_tx_dma_buffer = 0;
- info->tx_dma_buffers_used = 0;
- info->get_tx_holding_index = 0;
- info->put_tx_holding_index = 0;
- info->tx_holding_count = 0;
- } /* end of mgsl_reset_tx_dma_buffers() */
- /*
- * num_free_tx_dma_buffers()
- *
- * returns the number of free tx dma buffers available
- *
- * Arguments: info pointer to device instance data
- * Return Value: number of free tx dma buffers
- */
- int num_free_tx_dma_buffers(struct mgsl_struct *info)
- {
- return info->tx_buffer_count - info->tx_dma_buffers_used;
- }
- /*
- * mgsl_reset_rx_dma_buffers()
- *
- * Set the count for all receive buffers to DMABUFFERSIZE
- * and set the current buffer to the first buffer. This effectively
- * makes all buffers free and discards any data in buffers.
- *
- * Arguments: info pointer to device instance data
- * Return Value: None
- */
- void mgsl_reset_rx_dma_buffers( struct mgsl_struct *info )
- {
- unsigned int i;
- for ( i = 0; i < info->rx_buffer_count; i++ ) {
- *((unsigned long *)&(info->rx_buffer_list[i].count)) = DMABUFFERSIZE;
- // info->rx_buffer_list[i].count = DMABUFFERSIZE;
- // info->rx_buffer_list[i].status = 0;
- }
- info->current_rx_buffer = 0;
- } /* end of mgsl_reset_rx_dma_buffers() */
- /*
- * mgsl_free_rx_frame_buffers()
- *
- * Free the receive buffers used by a received SDLC
- * frame such that the buffers can be reused.
- *
- * Arguments:
- *
- * info pointer to device instance data
- * StartIndex index of 1st receive buffer of frame
- * EndIndex index of last receive buffer of frame
- *
- * Return Value: None
- */
- void mgsl_free_rx_frame_buffers( struct mgsl_struct *info, unsigned int StartIndex, unsigned int EndIndex )
- {
- int Done = 0;
- DMABUFFERENTRY *pBufEntry;
- unsigned int Index;
- /* Starting with 1st buffer entry of the frame clear the status */
- /* field and set the count field to DMA Buffer Size. */
- Index = StartIndex;
- while( !Done ) {
- pBufEntry = &(info->rx_buffer_list[Index]);
- if ( Index == EndIndex ) {
- /* This is the last buffer of the frame! */
- Done = 1;
- }
- /* reset current buffer for reuse */
- // pBufEntry->status = 0;
- // pBufEntry->count = DMABUFFERSIZE;
- *((unsigned long *)&(pBufEntry->count)) = DMABUFFERSIZE;
- /* advance to next buffer entry in linked list */
- Index++;
- if ( Index == info->rx_buffer_count )
- Index = 0;
- }
- /* set current buffer to next buffer after last buffer of frame */
- info->current_rx_buffer = Index;
- } /* end of free_rx_frame_buffers() */
- /* mgsl_get_rx_frame()
- *
- * This function attempts to return a received SDLC frame from the
- * receive DMA buffers. Only frames received without errors are returned.
- *
- * Arguments: info pointer to device extension
- * Return Value: 1 if frame returned, otherwise 0
- */
- int mgsl_get_rx_frame(struct mgsl_struct *info)
- {
- unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
- unsigned short status;
- DMABUFFERENTRY *pBufEntry;
- unsigned int framesize = 0;
- int ReturnCode = 0;
- unsigned long flags;
- struct tty_struct *tty = info->tty;
- int return_frame = 0;
-
- /*
- * current_rx_buffer points to the 1st buffer of the next available
- * receive frame. To find the last buffer of the frame look for
- * a non-zero status field in the buffer entries. (The status
- * field is set by the 16C32 after completing a receive frame.
- */
- StartIndex = EndIndex = info->current_rx_buffer;
- while( !info->rx_buffer_list[EndIndex].status ) {
- /*
- * If the count field of the buffer entry is non-zero then
- * this buffer has not been used. (The 16C32 clears the count
- * field when it starts using the buffer.) If an unused buffer
- * is encountered then there are no frames available.
- */
- if ( info->rx_buffer_list[EndIndex].count )
- goto Cleanup;
- /* advance to next buffer entry in linked list */
- EndIndex++;
- if ( EndIndex == info->rx_buffer_count )
- EndIndex = 0;
- /* if entire list searched then no frame available */
- if ( EndIndex == StartIndex ) {
- /* If this occurs then something bad happened,
- * all buffers have been 'used' but none mark
- * the end of a frame. Reset buffers and receiver.
- */
- if ( info->rx_enabled ){
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_start_receiver(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- }
- goto Cleanup;
- }
- }
- /* check status of receive frame */
-
- status = info->rx_buffer_list[EndIndex].status;
- if ( status & (RXSTATUS_SHORT_FRAME + RXSTATUS_OVERRUN +
- RXSTATUS_CRC_ERROR + RXSTATUS_ABORT) ) {
- if ( status & RXSTATUS_SHORT_FRAME )
- info->icount.rxshort++;
- else if ( status & RXSTATUS_ABORT )
- info->icount.rxabort++;
- else if ( status & RXSTATUS_OVERRUN )
- info->icount.rxover++;
- else {
- info->icount.rxcrc++;
- if ( info->params.crc_type & HDLC_CRC_RETURN_EX )
- return_frame = 1;
- }
- framesize = 0;
- #ifdef CONFIG_SYNCLINK_SYNCPPP
- info->netstats.rx_errors++;
- info->netstats.rx_frame_errors++;
- #endif
- } else
- return_frame = 1;
- if ( return_frame ) {
- /* receive frame has no errors, get frame size.
- * The frame size is the starting value of the RCC (which was
- * set to 0xffff) minus the ending value of the RCC (decremented
- * once for each receive character) minus 2 for the 16-bit CRC.
- */
- framesize = RCLRVALUE - info->rx_buffer_list[EndIndex].rcc;
- /* adjust frame size for CRC if any */
- if ( info->params.crc_type == HDLC_CRC_16_CCITT )
- framesize -= 2;
- else if ( info->params.crc_type == HDLC_CRC_32_CCITT )
- framesize -= 4;
- }
- if ( debug_level >= DEBUG_LEVEL_BH )
- printk("%s(%d):mgsl_get_rx_frame(%s) status=%04X size=%dn",
- __FILE__,__LINE__,info->device_name,status,framesize);
-
- if ( debug_level >= DEBUG_LEVEL_DATA )
- mgsl_trace_block(info,info->rx_buffer_list[StartIndex].virt_addr,
- MIN(framesize,DMABUFFERSIZE),0);
-
- if (framesize) {
- if ( ( (info->params.crc_type & HDLC_CRC_RETURN_EX) &&
- ((framesize+1) > info->max_frame_size) ) ||
- (framesize > info->max_frame_size) )
- info->icount.rxlong++;
- else {
- /* copy dma buffer(s) to contiguous intermediate buffer */
- int copy_count = framesize;
- int index = StartIndex;
- unsigned char *ptmp = info->intermediate_rxbuffer;
- if ( !(status & RXSTATUS_CRC_ERROR))
- info->icount.rxok++;
-
- while(copy_count) {
- int partial_count;
- if ( copy_count > DMABUFFERSIZE )
- partial_count = DMABUFFERSIZE;
- else
- partial_count = copy_count;
-
- pBufEntry = &(info->rx_buffer_list[index]);
- memcpy( ptmp, pBufEntry->virt_addr, partial_count );
- ptmp += partial_count;
- copy_count -= partial_count;
-
- if ( ++index == info->rx_buffer_count )
- index = 0;
- }
- if ( info->params.crc_type & HDLC_CRC_RETURN_EX ) {
- ++framesize;
- *ptmp = (status & RXSTATUS_CRC_ERROR ?
- RX_CRC_ERROR :
- RX_OK);
- if ( debug_level >= DEBUG_LEVEL_DATA )
- printk("%s(%d):mgsl_get_rx_frame(%s) rx frame status=%dn",
- __FILE__,__LINE__,info->device_name,
- *ptmp);
- }
- #ifdef CONFIG_SYNCLINK_SYNCPPP
- if (info->netcount) {
- /* pass frame to syncppp device */
- mgsl_sppp_rx_done(info,info->intermediate_rxbuffer,framesize);
- }
- else
- #endif
- {
- /* Call the line discipline receive callback directly. */
- if ( tty && tty->ldisc.receive_buf )
- tty->ldisc.receive_buf(tty, info->intermediate_rxbuffer, info->flag_buf, framesize);
- }
- }
- }
- /* Free the buffers used by this frame. */
- mgsl_free_rx_frame_buffers( info, StartIndex, EndIndex );
- ReturnCode = 1;
- Cleanup:
- if ( info->rx_enabled && info->rx_overflow ) {
- /* The receiver needs to restarted because of
- * a receive overflow (buffer or FIFO). If the
- * receive buffers are now empty, then restart receiver.
- */
- if ( !info->rx_buffer_list[EndIndex].status &&
- info->rx_buffer_list[EndIndex].count ) {
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_start_receiver(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- }
- }
- return ReturnCode;
- } /* end of mgsl_get_rx_frame() */
- /* mgsl_get_raw_rx_frame()
- *
- * This function attempts to return a received frame from the
- * receive DMA buffers when running in external loop mode. In this mode,
- * we will return at most one DMABUFFERSIZE frame to the application.
- * The USC receiver is triggering off of DCD going active to start a new
- * frame, and DCD going inactive to terminate the frame (similar to
- * processing a closing flag character).
- *
- * In this routine, we will return DMABUFFERSIZE "chunks" at a time.
- * If DCD goes inactive, the last Rx DMA Buffer will have a non-zero
- * status field and the RCC field will indicate the length of the
- * entire received frame. We take this RCC field and get the modulus
- * of RCC and DMABUFFERSIZE to determine if number of bytes in the
- * last Rx DMA buffer and return that last portion of the frame.
- *
- * Arguments: info pointer to device extension
- * Return Value: 1 if frame returned, otherwise 0
- */
- int mgsl_get_raw_rx_frame(struct mgsl_struct *info)
- {
- unsigned int CurrentIndex, NextIndex;
- unsigned short status;
- DMABUFFERENTRY *pBufEntry;
- unsigned int framesize = 0;
- int ReturnCode = 0;
- unsigned long flags;
- struct tty_struct *tty = info->tty;
- /*
- * current_rx_buffer points to the 1st buffer of the next available
- * receive frame. The status field is set by the 16C32 after
- * completing a receive frame. If the status field of this buffer
- * is zero, either the USC is still filling this buffer or this
- * is one of a series of buffers making up a received frame.
- *
- * If the count field of this buffer is zero, the USC is either
- * using this buffer or has used this buffer. Look at the count
- * field of the next buffer. If that next buffer's count is
- * non-zero, the USC is still actively using the current buffer.
- * Otherwise, if the next buffer's count field is zero, the
- * current buffer is complete and the USC is using the next
- * buffer.
- */
- CurrentIndex = NextIndex = info->current_rx_buffer;
- ++NextIndex;
- if ( NextIndex == info->rx_buffer_count )
- NextIndex = 0;
- if ( info->rx_buffer_list[CurrentIndex].status != 0 ||
- (info->rx_buffer_list[CurrentIndex].count == 0 &&
- info->rx_buffer_list[NextIndex].count == 0)) {
- /*
- * Either the status field of this dma buffer is non-zero
- * (indicating the last buffer of a receive frame) or the next
- * buffer is marked as in use -- implying this buffer is complete
- * and an intermediate buffer for this received frame.
- */
- status = info->rx_buffer_list[CurrentIndex].status;
- if ( status & (RXSTATUS_SHORT_FRAME + RXSTATUS_OVERRUN +
- RXSTATUS_CRC_ERROR + RXSTATUS_ABORT) ) {
- if ( status & RXSTATUS_SHORT_FRAME )
- info->icount.rxshort++;
- else if ( status & RXSTATUS_ABORT )
- info->icount.rxabort++;
- else if ( status & RXSTATUS_OVERRUN )
- info->icount.rxover++;
- else
- info->icount.rxcrc++;
- framesize = 0;
- } else {
- /*
- * A receive frame is available, get frame size and status.
- *
- * The frame size is the starting value of the RCC (which was
- * set to 0xffff) minus the ending value of the RCC (decremented
- * once for each receive character) minus 2 or 4 for the 16-bit
- * or 32-bit CRC.
- *
- * If the status field is zero, this is an intermediate buffer.
- * It's size is 4K.
- *
- * If the DMA Buffer Entry's Status field is non-zero, the
- * receive operation completed normally (ie: DCD dropped). The
- * RCC field is valid and holds the received frame size.
- * It is possible that the RCC field will be zero on a DMA buffer
- * entry with a non-zero status. This can occur if the total
- * frame size (number of bytes between the time DCD goes active
- * to the time DCD goes inactive) exceeds 65535 bytes. In this
- * case the 16C32 has underrun on the RCC count and appears to
- * stop updating this counter to let us know the actual received
- * frame size. If this happens (non-zero status and zero RCC),
- * simply return the entire RxDMA Buffer
- */
- if ( status ) {
- /*
- * In the event that the final RxDMA Buffer is
- * terminated with a non-zero status and the RCC
- * field is zero, we interpret this as the RCC
- * having underflowed (received frame > 65535 bytes).
- *
- * Signal the event to the user by passing back
- * a status of RxStatus_CrcError returning the full
- * buffer and let the app figure out what data is
- * actually valid
- */
- if ( info->rx_buffer_list[CurrentIndex].rcc )
- framesize = RCLRVALUE - info->rx_buffer_list[CurrentIndex].rcc;
- else
- framesize = DMABUFFERSIZE;
- }
- else
- framesize = DMABUFFERSIZE;
- }
- if ( framesize > DMABUFFERSIZE ) {
- /*
- * if running in raw sync mode, ISR handler for
- * End Of Buffer events terminates all buffers at 4K.
- * If this frame size is said to be >4K, get the
- * actual number of bytes of the frame in this buffer.
- */
- framesize = framesize % DMABUFFERSIZE;
- }
- if ( debug_level >= DEBUG_LEVEL_BH )
- printk("%s(%d):mgsl_get_raw_rx_frame(%s) status=%04X size=%dn",
- __FILE__,__LINE__,info->device_name,status,framesize);
- if ( debug_level >= DEBUG_LEVEL_DATA )
- mgsl_trace_block(info,info->rx_buffer_list[CurrentIndex].virt_addr,
- MIN(framesize,DMABUFFERSIZE),0);
- if (framesize) {
- /* copy dma buffer(s) to contiguous intermediate buffer */
- /* NOTE: we never copy more than DMABUFFERSIZE bytes */
- pBufEntry = &(info->rx_buffer_list[CurrentIndex]);
- memcpy( info->intermediate_rxbuffer, pBufEntry->virt_addr, framesize);
- info->icount.rxok++;
- /* Call the line discipline receive callback directly. */
- if ( tty && tty->ldisc.receive_buf )
- tty->ldisc.receive_buf(tty, info->intermediate_rxbuffer, info->flag_buf, framesize);
- }
- /* Free the buffers used by this frame. */
- mgsl_free_rx_frame_buffers( info, CurrentIndex, CurrentIndex );
- ReturnCode = 1;
- }
- if ( info->rx_enabled && info->rx_overflow ) {
- /* The receiver needs to restarted because of
- * a receive overflow (buffer or FIFO). If the
- * receive buffers are now empty, then restart receiver.
- */
- if ( !info->rx_buffer_list[CurrentIndex].status &&
- info->rx_buffer_list[CurrentIndex].count ) {
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_start_receiver(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- }
- }
- return ReturnCode;
- } /* end of mgsl_get_raw_rx_frame() */
- /* mgsl_load_tx_dma_buffer()
- *
- * Load the transmit DMA buffer with the specified data.
- *
- * Arguments:
- *
- * info pointer to device extension
- * Buffer pointer to buffer containing frame to load
- * BufferSize size in bytes of frame in Buffer
- *
- * Return Value: None
- */
- void mgsl_load_tx_dma_buffer(struct mgsl_struct *info, const char *Buffer,
- unsigned int BufferSize)
- {
- unsigned short Copycount;
- unsigned int i = 0;
- DMABUFFERENTRY *pBufEntry;
-
- if ( debug_level >= DEBUG_LEVEL_DATA )
- mgsl_trace_block(info,Buffer, MIN(BufferSize,DMABUFFERSIZE), 1);
- if (info->params.flags & HDLC_FLAG_HDLC_LOOPMODE) {
- /* set CMR:13 to start transmit when
- * next GoAhead (abort) is received
- */
- info->cmr_value |= BIT13;
- }
-
- /* begin loading the frame in the next available tx dma
- * buffer, remember it's starting location for setting
- * up tx dma operation
- */
- i = info->current_tx_buffer;
- info->start_tx_dma_buffer = i;
- /* Setup the status and RCC (Frame Size) fields of the 1st */
- /* buffer entry in the transmit DMA buffer list. */
- info->tx_buffer_list[i].status = info->cmr_value & 0xf000;
- info->tx_buffer_list[i].rcc = BufferSize;
- info->tx_buffer_list[i].count = BufferSize;
- /* Copy frame data from 1st source buffer to the DMA buffers. */
- /* The frame data may span multiple DMA buffers. */
- while( BufferSize ){
- /* Get a pointer to next DMA buffer entry. */
- pBufEntry = &info->tx_buffer_list[i++];
-
- if ( i == info->tx_buffer_count )
- i=0;
- /* Calculate the number of bytes that can be copied from */
- /* the source buffer to this DMA buffer. */
- if ( BufferSize > DMABUFFERSIZE )
- Copycount = DMABUFFERSIZE;
- else
- Copycount = BufferSize;
- /* Actually copy data from source buffer to DMA buffer. */
- /* Also set the data count for this individual DMA buffer. */
- if ( info->bus_type == MGSL_BUS_TYPE_PCI )
- mgsl_load_pci_memory(pBufEntry->virt_addr, Buffer,Copycount);
- else
- memcpy(pBufEntry->virt_addr, Buffer, Copycount);
- pBufEntry->count = Copycount;
- /* Advance source pointer and reduce remaining data count. */
- Buffer += Copycount;
- BufferSize -= Copycount;
- ++info->tx_dma_buffers_used;
- }
- /* remember next available tx dma buffer */
- info->current_tx_buffer = i;
- } /* end of mgsl_load_tx_dma_buffer() */
- /*
- * mgsl_register_test()
- *
- * Performs a register test of the 16C32.
- *
- * Arguments: info pointer to device instance data
- * Return Value: TRUE if test passed, otherwise FALSE
- */
- BOOLEAN mgsl_register_test( struct mgsl_struct *info )
- {
- static unsigned short BitPatterns[] =
- { 0x0000, 0xffff, 0xaaaa, 0x5555, 0x1234, 0x6969, 0x9696, 0x0f0f };
- static unsigned int Patterncount = sizeof(BitPatterns)/sizeof(unsigned short);
- unsigned int i;
- BOOLEAN rc = TRUE;
- unsigned long flags;
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_reset(info);
- /* Verify the reset state of some registers. */
- if ( (usc_InReg( info, SICR ) != 0) ||
- (usc_InReg( info, IVR ) != 0) ||
- (usc_InDmaReg( info, DIVR ) != 0) ){
- rc = FALSE;
- }
- if ( rc == TRUE ){
- /* Write bit patterns to various registers but do it out of */
- /* sync, then read back and verify values. */
- for ( i = 0 ; i < Patterncount ; i++ ) {
- usc_OutReg( info, TC0R, BitPatterns[i] );
- usc_OutReg( info, TC1R, BitPatterns[(i+1)%Patterncount] );
- usc_OutReg( info, TCLR, BitPatterns[(i+2)%Patterncount] );
- usc_OutReg( info, RCLR, BitPatterns[(i+3)%Patterncount] );
- usc_OutReg( info, RSR, BitPatterns[(i+4)%Patterncount] );
- usc_OutDmaReg( info, TBCR, BitPatterns[(i+5)%Patterncount] );
- if ( (usc_InReg( info, TC0R ) != BitPatterns[i]) ||
- (usc_InReg( info, TC1R ) != BitPatterns[(i+1)%Patterncount]) ||
- (usc_InReg( info, TCLR ) != BitPatterns[(i+2)%Patterncount]) ||
- (usc_InReg( info, RCLR ) != BitPatterns[(i+3)%Patterncount]) ||
- (usc_InReg( info, RSR ) != BitPatterns[(i+4)%Patterncount]) ||
- (usc_InDmaReg( info, TBCR ) != BitPatterns[(i+5)%Patterncount]) ){
- rc = FALSE;
- break;
- }
- }
- }
- usc_reset(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- return rc;
- } /* end of mgsl_register_test() */
- /* mgsl_irq_test() Perform interrupt test of the 16C32.
- *
- * Arguments: info pointer to device instance data
- * Return Value: TRUE if test passed, otherwise FALSE
- */
- BOOLEAN mgsl_irq_test( struct mgsl_struct *info )
- {
- unsigned long EndTime;
- unsigned long flags;
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_reset(info);
- /*
- * Setup 16C32 to interrupt on TxC pin (14MHz clock) transition.
- * The ISR sets irq_occurred to 1.
- */
- info->irq_occurred = FALSE;
- /* Enable INTEN gate for ISA adapter (Port 6, Bit12) */
- /* Enable INTEN (Port 6, Bit12) */
- /* This connects the IRQ request signal to the ISA bus */
- /* on the ISA adapter. This has no effect for the PCI adapter */
- usc_OutReg( info, PCR, (unsigned short)((usc_InReg(info, PCR) | BIT13) & ~BIT12) );
- usc_EnableMasterIrqBit(info);
- usc_EnableInterrupts(info, IO_PIN);
- usc_ClearIrqPendingBits(info, IO_PIN);
-
- usc_UnlatchIostatusBits(info, MISCSTATUS_TXC_LATCHED);
- usc_EnableStatusIrqs(info, SICR_TXC_ACTIVE + SICR_TXC_INACTIVE);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- EndTime=100;
- while( EndTime-- && !info->irq_occurred ) {
- set_current_state(TASK_INTERRUPTIBLE);
- schedule_timeout(jiffies_from_ms(10));
- }
-
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_reset(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
-
- if ( !info->irq_occurred )
- return FALSE;
- else
- return TRUE;
- } /* end of mgsl_irq_test() */
- /* mgsl_dma_test()
- *
- * Perform a DMA test of the 16C32. A small frame is
- * transmitted via DMA from a transmit buffer to a receive buffer
- * using single buffer DMA mode.
- *
- * Arguments: info pointer to device instance data
- * Return Value: TRUE if test passed, otherwise FALSE
- */
- BOOLEAN mgsl_dma_test( struct mgsl_struct *info )
- {
- unsigned short FifoLevel;
- unsigned long phys_addr;
- unsigned int FrameSize;
- unsigned int i;
- char *TmpPtr;
- BOOLEAN rc = TRUE;
- unsigned short status=0;
- unsigned long EndTime;
- unsigned long flags;
- MGSL_PARAMS tmp_params;
- /* save current port options */
- memcpy(&tmp_params,&info->params,sizeof(MGSL_PARAMS));
- /* load default port options */
- memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
-
- #define TESTFRAMESIZE 40
- spin_lock_irqsave(&info->irq_spinlock,flags);
-
- /* setup 16C32 for SDLC DMA transfer mode */
- usc_reset(info);
- usc_set_sdlc_mode(info);
- usc_enable_loopback(info,1);
-
- /* Reprogram the RDMR so that the 16C32 does NOT clear the count
- * field of the buffer entry after fetching buffer address. This
- * way we can detect a DMA failure for a DMA read (which should be
- * non-destructive to system memory) before we try and write to
- * memory (where a failure could corrupt system memory).
- */
- /* Receive DMA mode Register (RDMR)
- *
- * <15..14> 11 DMA mode = Linked List Buffer mode
- * <13> 1 RSBinA/L = store Rx status Block in List entry
- * <12> 0 1 = Clear count of List Entry after fetching
- * <11..10> 00 Address mode = Increment
- * <9> 1 Terminate Buffer on RxBound
- * <8> 0 Bus Width = 16bits
- * <7..0> ? status Bits (write as 0s)
- *
- * 1110 0010 0000 0000 = 0xe200
- */
- usc_OutDmaReg( info, RDMR, 0xe200 );
-
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- /* SETUP TRANSMIT AND RECEIVE DMA BUFFERS */
- FrameSize = TESTFRAMESIZE;
- /* setup 1st transmit buffer entry: */
- /* with frame size and transmit control word */
- info->tx_buffer_list[0].count = FrameSize;
- info->tx_buffer_list[0].rcc = FrameSize;
- info->tx_buffer_list[0].status = 0x4000;
- /* build a transmit frame in 1st transmit DMA buffer */
- TmpPtr = info->tx_buffer_list[0].virt_addr;
- for (i = 0; i < FrameSize; i++ )
- *TmpPtr++ = i;
- /* setup 1st receive buffer entry: */
- /* clear status, set max receive buffer size */
- info->rx_buffer_list[0].status = 0;
- info->rx_buffer_list[0].count = FrameSize + 4;
- /* zero out the 1st receive buffer */
- memset( info->rx_buffer_list[0].virt_addr, 0, FrameSize + 4 );
- /* Set count field of next buffer entries to prevent */
- /* 16C32 from using buffers after the 1st one. */
- info->tx_buffer_list[1].count = 0;
- info->rx_buffer_list[1].count = 0;
-
- /***************************/
- /* Program 16C32 receiver. */
- /***************************/
-
- spin_lock_irqsave(&info->irq_spinlock,flags);
- /* setup DMA transfers */
- usc_RTCmd( info, RTCmd_PurgeRxFifo );
- /* program 16C32 receiver with physical address of 1st DMA buffer entry */
- phys_addr = info->rx_buffer_list[0].phys_entry;
- usc_OutDmaReg( info, NRARL, (unsigned short)phys_addr );
- usc_OutDmaReg( info, NRARU, (unsigned short)(phys_addr >> 16) );
- /* Clear the Rx DMA status bits (read RDMR) and start channel */
- usc_InDmaReg( info, RDMR );
- usc_DmaCmd( info, DmaCmd_InitRxChannel );
- /* Enable Receiver (RMR <1..0> = 10) */
- usc_OutReg( info, RMR, (unsigned short)((usc_InReg(info, RMR) & 0xfffc) | 0x0002) );
-
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- /*************************************************************/
- /* WAIT FOR RECEIVER TO DMA ALL PARAMETERS FROM BUFFER ENTRY */
- /*************************************************************/
- /* Wait 100ms for interrupt. */
- EndTime = jiffies + jiffies_from_ms(100);
- for(;;) {
- if ( jiffies > EndTime ) {
- rc = FALSE;
- break;
- }
- spin_lock_irqsave(&info->irq_spinlock,flags);
- status = usc_InDmaReg( info, RDMR );
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- if ( !(status & BIT4) && (status & BIT5) ) {
- /* INITG (BIT 4) is inactive (no entry read in progress) AND */
- /* BUSY (BIT 5) is active (channel still active). */
- /* This means the buffer entry read has completed. */
- break;
- }
- }
- /******************************/
- /* Program 16C32 transmitter. */
- /******************************/
-
- spin_lock_irqsave(&info->irq_spinlock,flags);
- /* Program the Transmit Character Length Register (TCLR) */
- /* and clear FIFO (TCC is loaded with TCLR on FIFO clear) */
- usc_OutReg( info, TCLR, (unsigned short)info->tx_buffer_list[0].count );
- usc_RTCmd( info, RTCmd_PurgeTxFifo );
- /* Program the address of the 1st DMA Buffer Entry in linked list */
- phys_addr = info->tx_buffer_list[0].phys_entry;
- usc_OutDmaReg( info, NTARL, (unsigned short)phys_addr );
- usc_OutDmaReg( info, NTARU, (unsigned short)(phys_addr >> 16) );
- /* unlatch Tx status bits, and start transmit channel. */
- usc_OutReg( info, TCSR, (unsigned short)(( usc_InReg(info, TCSR) & 0x0f00) | 0xfa) );
- usc_DmaCmd( info, DmaCmd_InitTxChannel );
- /* wait for DMA controller to fill transmit FIFO */
- usc_TCmd( info, TCmd_SelectTicrTxFifostatus );
-
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- /**********************************/
- /* WAIT FOR TRANSMIT FIFO TO FILL */
- /**********************************/
-
- /* Wait 100ms */
- EndTime = jiffies + jiffies_from_ms(100);
- for(;;) {
- if ( jiffies > EndTime ) {
- rc = FALSE;
- break;
- }
- spin_lock_irqsave(&info->irq_spinlock,flags);
- FifoLevel = usc_InReg(info, TICR) >> 8;
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
-
- if ( FifoLevel < 16 )
- break;
- else
- if ( FrameSize < 32 ) {
- /* This frame is smaller than the entire transmit FIFO */
- /* so wait for the entire frame to be loaded. */
- if ( FifoLevel <= (32 - FrameSize) )
- break;
- }
- }
- if ( rc == TRUE )
- {
- /* Enable 16C32 transmitter. */
- spin_lock_irqsave(&info->irq_spinlock,flags);
-
- /* Transmit mode Register (TMR), <1..0> = 10, Enable Transmitter */
- usc_TCmd( info, TCmd_SendFrame );
- usc_OutReg( info, TMR, (unsigned short)((usc_InReg(info, TMR) & 0xfffc) | 0x0002) );
-
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
-
- /******************************/
- /* WAIT FOR TRANSMIT COMPLETE */
- /******************************/
- /* Wait 100ms */
- EndTime = jiffies + jiffies_from_ms(100);
- /* While timer not expired wait for transmit complete */
- spin_lock_irqsave(&info->irq_spinlock,flags);
- status = usc_InReg( info, TCSR );
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- while ( !(status & (BIT6+BIT5+BIT4+BIT2+BIT1)) ) {
- if ( jiffies > EndTime ) {
- rc = FALSE;
- break;
- }
- spin_lock_irqsave(&info->irq_spinlock,flags);
- status = usc_InReg( info, TCSR );
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- }
- }
- if ( rc == TRUE ){
- /* CHECK FOR TRANSMIT ERRORS */
- if ( status & (BIT5 + BIT1) )
- rc = FALSE;
- }
- if ( rc == TRUE ) {
- /* WAIT FOR RECEIVE COMPLETE */
- /* Wait 100ms */
- EndTime = jiffies + jiffies_from_ms(100);
- /* Wait for 16C32 to write receive status to buffer entry. */
- status=info->rx_buffer_list[0].status;
- while ( status == 0 ) {
- if ( jiffies > EndTime ) {
- printk(KERN_ERR"mark 4n");
- rc = FALSE;
- break;
- }
- status=info->rx_buffer_list[0].status;
- }
- }
- if ( rc == TRUE ) {
- /* CHECK FOR RECEIVE ERRORS */
- status = info->rx_buffer_list[0].status;
- if ( status & (BIT8 + BIT3 + BIT1) ) {
- /* receive error has occured */
- rc = FALSE;
- } else {
- if ( memcmp( info->tx_buffer_list[0].virt_addr ,
- info->rx_buffer_list[0].virt_addr, FrameSize ) ){
- rc = FALSE;
- }
- }
- }
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_reset( info );
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- /* restore current port options */
- memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
-
- return rc;
- } /* end of mgsl_dma_test() */
- /* mgsl_adapter_test()
- *
- * Perform the register, IRQ, and DMA tests for the 16C32.
- *
- * Arguments: info pointer to device instance data
- * Return Value: 0 if success, otherwise -ENODEV
- */
- int mgsl_adapter_test( struct mgsl_struct *info )
- {
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk( "%s(%d):Testing device %sn",
- __FILE__,__LINE__,info->device_name );
-
- if ( !mgsl_register_test( info ) ) {
- info->init_error = DiagStatus_AddressFailure;
- printk( "%s(%d):Register test failure for device %s Addr=%04Xn",
- __FILE__,__LINE__,info->device_name, (unsigned short)(info->io_base) );
- return -ENODEV;
- }
- if ( !mgsl_irq_test( info ) ) {
- info->init_error = DiagStatus_IrqFailure;
- printk( "%s(%d):Interrupt test failure for device %s IRQ=%dn",
- __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
- return -ENODEV;
- }
- if ( !mgsl_dma_test( info ) ) {
- info->init_error = DiagStatus_DmaFailure;
- printk( "%s(%d):DMA test failure for device %s DMA=%dn",
- __FILE__,__LINE__,info->device_name, (unsigned short)(info->dma_level) );
- return -ENODEV;
- }
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk( "%s(%d):device %s passed diagnosticsn",
- __FILE__,__LINE__,info->device_name );
-
- return 0;
- } /* end of mgsl_adapter_test() */
- /* mgsl_memory_test()
- *
- * Test the shared memory on a PCI adapter.
- *
- * Arguments: info pointer to device instance data
- * Return Value: TRUE if test passed, otherwise FALSE
- */
- BOOLEAN mgsl_memory_test( struct mgsl_struct *info )
- {
- static unsigned long BitPatterns[] = { 0x0, 0x55555555, 0xaaaaaaaa,
- 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
- unsigned long Patterncount = sizeof(BitPatterns)/sizeof(unsigned long);
- unsigned long i;
- unsigned long TestLimit = SHARED_MEM_ADDRESS_SIZE/sizeof(unsigned long);
- unsigned long * TestAddr;
- if ( info->bus_type != MGSL_BUS_TYPE_PCI )
- return TRUE;
- TestAddr = (unsigned long *)info->memory_base;
- /* Test data lines with test pattern at one location. */
- for ( i = 0 ; i < Patterncount ; i++ ) {
- *TestAddr = BitPatterns[i];
- if ( *TestAddr != BitPatterns[i] )
- return FALSE;
- }
- /* Test address lines with incrementing pattern over */
- /* entire address range. */
- for ( i = 0 ; i < TestLimit ; i++ ) {
- *TestAddr = i * 4;
- TestAddr++;
- }
- TestAddr = (unsigned long *)info->memory_base;
- for ( i = 0 ; i < TestLimit ; i++ ) {
- if ( *TestAddr != i * 4 )
- return FALSE;
- TestAddr++;
- }
- memset( info->memory_base, 0, SHARED_MEM_ADDRESS_SIZE );
- return TRUE;
- } /* End Of mgsl_memory_test() */
- /* mgsl_load_pci_memory()
- *
- * Load a large block of data into the PCI shared memory.
- * Use this instead of memcpy() or memmove() to move data
- * into the PCI shared memory.
- *
- * Notes:
- *
- * This function prevents the PCI9050 interface chip from hogging
- * the adapter local bus, which can starve the 16C32 by preventing
- * 16C32 bus master cycles.
- *
- * The PCI9050 documentation says that the 9050 will always release
- * control of the local bus after completing the current read
- * or write operation.
- *
- * It appears that as long as the PCI9050 write FIFO is full, the
- * PCI9050 treats all of the writes as a single burst transaction
- * and will not release the bus. This causes DMA latency problems
- * at high speeds when copying large data blocks to the shared
- * memory.
- *
- * This function in effect, breaks the a large shared memory write
- * into multiple transations by interleaving a shared memory read
- * which will flush the write FIFO and 'complete' the write
- * transation. This allows any pending DMA request to gain control
- * of the local bus in a timely fasion.
- *
- * Arguments:
- *
- * TargetPtr pointer to target address in PCI shared memory
- * SourcePtr pointer to source buffer for data
- * count count in bytes of data to copy
- *
- * Return Value: None
- */
- void mgsl_load_pci_memory( char* TargetPtr, const char* SourcePtr,
- unsigned short count )
- {
- /* 16 32-bit writes @ 60ns each = 960ns max latency on local bus */
- #define PCI_LOAD_INTERVAL 64
- unsigned short Intervalcount = count / PCI_LOAD_INTERVAL;
- unsigned short Index;
- unsigned long Dummy;
- for ( Index = 0 ; Index < Intervalcount ; Index++ )
- {
- memcpy(TargetPtr, SourcePtr, PCI_LOAD_INTERVAL);
- Dummy = *((volatile unsigned long *)TargetPtr);
- TargetPtr += PCI_LOAD_INTERVAL;
- SourcePtr += PCI_LOAD_INTERVAL;
- }
- memcpy( TargetPtr, SourcePtr, count % PCI_LOAD_INTERVAL );
- } /* End Of mgsl_load_pci_memory() */
- void mgsl_trace_block(struct mgsl_struct *info,const char* data, int count, int xmit)
- {
- int i;
- int linecount;
- if (xmit)
- printk("%s tx data:n",info->device_name);
- else
- printk("%s rx data:n",info->device_name);
-
- while(count) {
- if (count > 16)
- linecount = 16;
- else
- linecount = count;
-
- for(i=0;i<linecount;i++)
- printk("%02X ",(unsigned char)data[i]);
- for(;i<17;i++)
- printk(" ");
- for(i=0;i<linecount;i++) {
- if (data[i]>=040 && data[i]<=0176)
- printk("%c",data[i]);
- else
- printk(".");
- }
- printk("n");
-
- data += linecount;
- count -= linecount;
- }
- } /* end of mgsl_trace_block() */
- /* mgsl_tx_timeout()
- *
- * called when HDLC frame times out
- * update stats and do tx completion processing
- *
- * Arguments: context pointer to device instance data
- * Return Value: None
- */
- void mgsl_tx_timeout(unsigned long context)
- {
- struct mgsl_struct *info = (struct mgsl_struct*)context;
- unsigned long flags;
-
- if ( debug_level >= DEBUG_LEVEL_INFO )
- printk( "%s(%d):mgsl_tx_timeout(%s)n",
- __FILE__,__LINE__,info->device_name);
- if(info->tx_active &&
- (info->params.mode == MGSL_MODE_HDLC ||
- info->params.mode == MGSL_MODE_RAW) ) {
- info->icount.txtimeout++;
- }
- spin_lock_irqsave(&info->irq_spinlock,flags);
- info->tx_active = 0;
- info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
- if ( info->params.flags & HDLC_FLAG_HDLC_LOOPMODE )
- usc_loopmode_cancel_transmit( info );
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
-
- #ifdef CONFIG_SYNCLINK_SYNCPPP
- if (info->netcount)
- mgsl_sppp_tx_done(info);
- else
- #endif
- mgsl_bh_transmit(info);
-
- } /* end of mgsl_tx_timeout() */
- /* signal that there are no more frames to send, so that
- * line is 'released' by echoing RxD to TxD when current
- * transmission is complete (or immediately if no tx in progress).
- */
- static int mgsl_loopmode_send_done( struct mgsl_struct * info )
- {
- unsigned long flags;
-
- spin_lock_irqsave(&info->irq_spinlock,flags);
- if (info->params.flags & HDLC_FLAG_HDLC_LOOPMODE) {
- if (info->tx_active)
- info->loopmode_send_done_requested = TRUE;
- else
- usc_loopmode_send_done(info);
- }
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- return 0;
- }
- /* release the line by echoing RxD to TxD
- * upon completion of a transmit frame
- */
- void usc_loopmode_send_done( struct mgsl_struct * info )
- {
- info->loopmode_send_done_requested = FALSE;
- /* clear CMR:13 to 0 to start echoing RxData to TxData */
- info->cmr_value &= ~BIT13;
- usc_OutReg(info, CMR, info->cmr_value);
- }
- /* abort a transmit in progress while in HDLC LoopMode
- */
- void usc_loopmode_cancel_transmit( struct mgsl_struct * info )
- {
- /* reset tx dma channel and purge TxFifo */
- usc_RTCmd( info, RTCmd_PurgeTxFifo );
- usc_DmaCmd( info, DmaCmd_ResetTxChannel );
- usc_loopmode_send_done( info );
- }
- /* for HDLC/SDLC LoopMode, setting CMR:13 after the transmitter is enabled
- * is an Insert Into Loop action. Upon receipt of a GoAhead sequence (RxAbort)
- * we must clear CMR:13 to begin repeating TxData to RxData
- */
- void usc_loopmode_insert_request( struct mgsl_struct * info )
- {
- info->loopmode_insert_requested = TRUE;
-
- /* enable RxAbort irq. On next RxAbort, clear CMR:13 to
- * begin repeating TxData on RxData (complete insertion)
- */
- usc_OutReg( info, RICR,
- (usc_InReg( info, RICR ) | RXSTATUS_ABORT_RECEIVED ) );
-
- /* set CMR:13 to insert into loop on next GoAhead (RxAbort) */
- info->cmr_value |= BIT13;
- usc_OutReg(info, CMR, info->cmr_value);
- }
- /* return 1 if station is inserted into the loop, otherwise 0
- */
- int usc_loopmode_active( struct mgsl_struct * info)
- {
- return usc_InReg( info, CCSR ) & BIT7 ? 1 : 0 ;
- }
- /* return 1 if USC is in loop send mode, otherwise 0
- */
- int usc_loopmode_send_active( struct mgsl_struct * info )
- {
- return usc_InReg( info, CCSR ) & BIT6 ? 1 : 0 ;
- }
- #ifdef CONFIG_SYNCLINK_SYNCPPP
- /* syncppp net device routines
- */
- void mgsl_sppp_init(struct mgsl_struct *info)
- {
- struct net_device *d;
- sprintf(info->netname,"mgsl%d",info->line);
- info->if_ptr = &info->pppdev;
- info->netdev = info->pppdev.dev = &info->netdevice;
- sppp_attach(&info->pppdev);
- d = info->netdev;
- strcpy(d->name,info->netname);
- d->base_addr = info->io_base;
- d->irq = info->irq_level;
- d->dma = info->dma_level;
- d->priv = info;
- d->init = NULL;
- d->open = mgsl_sppp_open;
- d->stop = mgsl_sppp_close;
- d->hard_start_xmit = mgsl_sppp_tx;
- d->do_ioctl = mgsl_sppp_ioctl;
- d->get_stats = mgsl_net_stats;
- d->tx_timeout = mgsl_sppp_tx_timeout;
- d->watchdog_timeo = 10*HZ;
- #if LINUX_VERSION_CODE < VERSION(2,4,4)
- dev_init_buffers(d);
- #endif
- if (register_netdev(d) == -1) {
- printk(KERN_WARNING "%s: register_netdev failed.n", d->name);
- sppp_detach(info->netdev);
- return;
- }
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_init()n");
- }
- void mgsl_sppp_delete(struct mgsl_struct *info)
- {
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_delete(%s)n",info->netname);
- sppp_detach(info->netdev);
- unregister_netdev(info->netdev);
- }
- int mgsl_sppp_open(struct net_device *d)
- {
- struct mgsl_struct *info = d->priv;
- int err;
- unsigned long flags;
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_open(%s)n",info->netname);
- spin_lock_irqsave(&info->netlock, flags);
- if (info->count != 0 || info->netcount != 0) {
- printk(KERN_WARNING "%s: sppp_open returning busyn", info->netname);
- spin_unlock_irqrestore(&info->netlock, flags);
- return -EBUSY;
- }
- info->netcount=1;
- MOD_INC_USE_COUNT;
- spin_unlock_irqrestore(&info->netlock, flags);
- /* claim resources and init adapter */
- if ((err = startup(info)) != 0)
- goto open_fail;
- /* allow syncppp module to do open processing */
- if ((err = sppp_open(d)) != 0) {
- shutdown(info);
- goto open_fail;
- }
- info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
- mgsl_program_hw(info);
- d->trans_start = jiffies;
- netif_start_queue(d);
- return 0;
- open_fail:
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- MOD_DEC_USE_COUNT;
- spin_unlock_irqrestore(&info->netlock, flags);
- return err;
- }
- void mgsl_sppp_tx_timeout(struct net_device *dev)
- {
- struct mgsl_struct *info = dev->priv;
- unsigned long flags;
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_tx_timeout(%s)n",info->netname);
- info->netstats.tx_errors++;
- info->netstats.tx_aborted_errors++;
- spin_lock_irqsave(&info->irq_spinlock,flags);
- usc_stop_transmitter(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- netif_wake_queue(dev);
- }
- int mgsl_sppp_tx(struct sk_buff *skb, struct net_device *dev)
- {
- struct mgsl_struct *info = dev->priv;
- unsigned long flags;
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_tx(%s)n",info->netname);
- netif_stop_queue(dev);
- info->xmit_cnt = skb->len;
- mgsl_load_tx_dma_buffer(info, skb->data, skb->len);
- info->netstats.tx_packets++;
- info->netstats.tx_bytes += skb->len;
- dev_kfree_skb(skb);
- dev->trans_start = jiffies;
- spin_lock_irqsave(&info->irq_spinlock,flags);
- if (!info->tx_active)
- usc_start_transmitter(info);
- spin_unlock_irqrestore(&info->irq_spinlock,flags);
- return 0;
- }
- int mgsl_sppp_close(struct net_device *d)
- {
- struct mgsl_struct *info = d->priv;
- unsigned long flags;
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_close(%s)n",info->netname);
- /* shutdown adapter and release resources */
- shutdown(info);
- /* allow syncppp to do close processing */
- sppp_close(d);
- netif_stop_queue(d);
- spin_lock_irqsave(&info->netlock, flags);
- info->netcount=0;
- MOD_DEC_USE_COUNT;
- spin_unlock_irqrestore(&info->netlock, flags);
- return 0;
- }
- void mgsl_sppp_rx_done(struct mgsl_struct *info, char *buf, int size)
- {
- struct sk_buff *skb = dev_alloc_skb(size);
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_sppp_rx_done(%s)n",info->netname);
- if (skb == NULL) {
- printk(KERN_NOTICE "%s: cant alloc skb, dropping packetn",
- info->netname);
- info->netstats.rx_dropped++;
- return;
- }
- memcpy(skb_put(skb, size),buf,size);
- skb->protocol = htons(ETH_P_WAN_PPP);
- skb->dev = info->netdev;
- skb->mac.raw = skb->data;
- info->netstats.rx_packets++;
- info->netstats.rx_bytes += size;
- netif_rx(skb);
- info->netdev->trans_start = jiffies;
- }
- void mgsl_sppp_tx_done(struct mgsl_struct *info)
- {
- if (netif_queue_stopped(info->netdev))
- netif_wake_queue(info->netdev);
- }
- struct net_device_stats *mgsl_net_stats(struct net_device *dev)
- {
- struct mgsl_struct *info = dev->priv;
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("mgsl_net_stats(%s)n",info->netname);
- return &info->netstats;
- }
- int mgsl_sppp_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
- {
- struct mgsl_struct *info = (struct mgsl_struct *)dev->priv;
- if (debug_level >= DEBUG_LEVEL_INFO)
- printk("%s(%d):mgsl_ioctl %s cmd=%08Xn", __FILE__,__LINE__,
- info->netname, cmd );
- return sppp_do_ioctl(dev, ifr, cmd);
- }
- #endif /* ifdef CONFIG_SYNCLINK_SYNCPPP */
- static int __init synclink_init_one (struct pci_dev *dev,
- const struct pci_device_id *ent)
- {
- struct mgsl_struct *info;
- if (pci_enable_device(dev)) {
- printk("error enabling pci device %pn", dev);
- return -EIO;
- }
- if (!(info = mgsl_allocate_device())) {
- printk("can't allocate device instance data.n");
- return -EIO;
- }
- /* Copy user configuration info to device instance data */
-
- info->io_base = pci_resource_start(dev, 2);
- info->irq_level = dev->irq;
- info->phys_memory_base = pci_resource_start(dev, 3);
-
- /* Because veremap only works on page boundaries we must map
- * a larger area than is actually implemented for the LCR
- * memory range. We map a full page starting at the page boundary.
- */
- info->phys_lcr_base = pci_resource_start(dev, 0);
- info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
- info->phys_lcr_base &= ~(PAGE_SIZE-1);
-
- info->bus_type = MGSL_BUS_TYPE_PCI;
- info->io_addr_size = 8;
- info->irq_flags = SA_SHIRQ;
-
- /* Store the PCI9050 misc control register value because a flaw
- * in the PCI9050 prevents LCR registers from being read if
- * BIOS assigns an LCR base address with bit 7 set.
- *
- * Only the misc control register is accessed for which only
- * write access is needed, so set an initial value and change
- * bits to the device instance data as we write the value
- * to the actual misc control register.
- */
- info->misc_ctrl_value = 0x087e4546;
-
- mgsl_add_device(info);
- return 0;
- }
- static void __devexit synclink_remove_one (struct pci_dev *dev)
- {
- }