X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Fchar%2Fsynclink_gt.c;h=f3d8d72e5ea47d74e97d1f60a6b68d44b491a01d;hb=0fab6de09c71a976e5d765e1ff548b14be385153;hp=372a37e256208b30711e2ee1e3809f120c5b25cc;hpb=dd00cc486ab1c17049a535413d1751ef3482141c;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c index 372a37e..f3d8d72 100644 --- a/drivers/char/synclink_gt.c +++ b/drivers/char/synclink_gt.c @@ -1,5 +1,5 @@ /* - * $Id: synclink_gt.c,v 4.36 2006/08/28 20:47:14 paulkf Exp $ + * $Id: synclink_gt.c,v 4.50 2007/07/25 19:29:25 paulkf Exp $ * * Device driver for Microgate SyncLink GT serial adapters. * @@ -73,6 +73,7 @@ #include #include #include +#include #include #include @@ -81,8 +82,6 @@ #include #include -#include "linux/synclink.h" - #if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINK_GT_MODULE)) #define SYNCLINK_GENERIC_HDLC 1 #else @@ -93,7 +92,7 @@ * module identification */ static char *driver_name = "SyncLink GT"; -static char *driver_version = "$Revision: 4.36 $"; +static char *driver_version = "$Revision: 4.50 $"; static char *tty_driver_name = "synclink_gt"; static char *tty_dev_prefix = "ttySLG"; MODULE_LICENSE("GPL"); @@ -118,7 +117,7 @@ static struct pci_driver pci_driver = { .remove = __devexit_p(remove_one), }; -static int pci_registered; +static bool pci_registered; /* * module configuration and status @@ -206,10 +205,10 @@ static void flush_cond_wait(struct cond_wait **head); */ struct slgt_desc { - unsigned short count; - unsigned short status; - unsigned int pbuf; /* physical address of data buffer */ - unsigned int next; /* physical address of next descriptor */ + __le16 count; + __le16 status; + __le32 pbuf; /* physical address of data buffer */ + __le32 next; /* physical address of next descriptor */ /* driver book keeping */ char *buf; /* virtual address of data buffer */ @@ -290,12 +289,12 @@ struct slgt_info { struct work_struct task; u32 pending_bh; - int bh_requested; - int bh_running; + bool bh_requested; + bool bh_running; int isr_overflow; - int irq_requested; /* nonzero if IRQ requested */ - int irq_occurred; /* for diagnostics use */ + bool irq_requested; /* true if IRQ requested */ + bool irq_occurred; /* for diagnostics use */ /* device configuration */ @@ -305,7 +304,7 @@ struct slgt_info { unsigned char __iomem * reg_addr; /* memory mapped registers address */ u32 phys_reg_addr; - int reg_addr_requested; + bool reg_addr_requested; MGSL_PARAMS params; /* communications parameters */ u32 idle_mode; @@ -316,11 +315,11 @@ struct slgt_info { /* device status */ - int rx_enabled; - int rx_restart; + bool rx_enabled; + bool rx_restart; - int tx_enabled; - int tx_active; + bool tx_enabled; + bool tx_active; unsigned char signals; /* serial signal states */ int init_error; /* initialization error */ @@ -330,7 +329,7 @@ struct slgt_info { char flag_buf[MAX_ASYNC_BUFFER_SIZE]; char char_buf[MAX_ASYNC_BUFFER_SIZE]; - BOOLEAN drop_rts_on_tx_done; + bool drop_rts_on_tx_done; struct _input_signal_events input_signal_events; int dcd_chkcount; /* check counts to prevent */ @@ -468,8 +467,8 @@ static void rx_start(struct slgt_info *info); static void reset_rbufs(struct slgt_info *info); static void free_rbufs(struct slgt_info *info, unsigned int first, unsigned int last); static void rdma_reset(struct slgt_info *info); -static int rx_get_frame(struct slgt_info *info); -static int rx_get_buf(struct slgt_info *info); +static bool rx_get_frame(struct slgt_info *info); +static bool rx_get_buf(struct slgt_info *info); static void tx_start(struct slgt_info *info); static void tx_stop(struct slgt_info *info); @@ -477,6 +476,7 @@ static void tx_set_idle(struct slgt_info *info); static unsigned int free_tbuf_count(struct slgt_info *info); static void reset_tbufs(struct slgt_info *info); static void tdma_reset(struct slgt_info *info); +static void tdma_start(struct slgt_info *info); static void tx_load(struct slgt_info *info, const char *buf, unsigned int count); static void get_signals(struct slgt_info *info); @@ -491,7 +491,6 @@ static void isr_serial(struct slgt_info *info); static void isr_rdma(struct slgt_info *info); static void isr_txeom(struct slgt_info *info, unsigned short status); static void isr_tdma(struct slgt_info *info); -static irqreturn_t slgt_interrupt(int irq, void *dev_id); static int alloc_dma_bufs(struct slgt_info *info); static void free_dma_bufs(struct slgt_info *info); @@ -904,6 +903,8 @@ start: spin_lock_irqsave(&info->lock,flags); if (!info->tx_active) tx_start(info); + else + tdma_start(info); spin_unlock_irqrestore(&info->lock,flags); } @@ -1562,6 +1563,9 @@ static int hdlcdev_open(struct net_device *dev) int rc; unsigned long flags; + if (!try_module_get(THIS_MODULE)) + return -EBUSY; + DBGINFO(("%s hdlcdev_open\n", dev->name)); /* generic HDLC layer open processing */ @@ -1631,6 +1635,7 @@ static int hdlcdev_close(struct net_device *dev) info->netcount=0; spin_unlock_irqrestore(&info->netlock, flags); + module_put(THIS_MODULE); return 0; } @@ -1963,8 +1968,8 @@ static int bh_action(struct slgt_info *info) rc = BH_STATUS; } else { /* Mark BH routine as complete */ - info->bh_running = 0; - info->bh_requested = 0; + info->bh_running = false; + info->bh_requested = false; rc = 0; } @@ -1983,7 +1988,7 @@ static void bh_handler(struct work_struct *work) if (!info) return; - info->bh_running = 1; + info->bh_running = true; while((action = bh_action(info))) { switch (action) { @@ -2033,37 +2038,41 @@ static void bh_transmit(struct slgt_info *info) tty_wakeup(tty); } -static void dsr_change(struct slgt_info *info) +static void dsr_change(struct slgt_info *info, unsigned short status) { - get_signals(info); + if (status & BIT3) { + info->signals |= SerialSignal_DSR; + info->input_signal_events.dsr_up++; + } else { + info->signals &= ~SerialSignal_DSR; + info->input_signal_events.dsr_down++; + } DBGISR(("dsr_change %s signals=%04X\n", info->device_name, info->signals)); if ((info->dsr_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { slgt_irq_off(info, IRQ_DSR); return; } info->icount.dsr++; - if (info->signals & SerialSignal_DSR) - info->input_signal_events.dsr_up++; - else - info->input_signal_events.dsr_down++; wake_up_interruptible(&info->status_event_wait_q); wake_up_interruptible(&info->event_wait_q); info->pending_bh |= BH_STATUS; } -static void cts_change(struct slgt_info *info) +static void cts_change(struct slgt_info *info, unsigned short status) { - get_signals(info); + if (status & BIT2) { + info->signals |= SerialSignal_CTS; + info->input_signal_events.cts_up++; + } else { + info->signals &= ~SerialSignal_CTS; + info->input_signal_events.cts_down++; + } DBGISR(("cts_change %s signals=%04X\n", info->device_name, info->signals)); if ((info->cts_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { slgt_irq_off(info, IRQ_CTS); return; } info->icount.cts++; - if (info->signals & SerialSignal_CTS) - info->input_signal_events.cts_up++; - else - info->input_signal_events.cts_down++; wake_up_interruptible(&info->status_event_wait_q); wake_up_interruptible(&info->event_wait_q); info->pending_bh |= BH_STATUS; @@ -2084,20 +2093,21 @@ static void cts_change(struct slgt_info *info) } } -static void dcd_change(struct slgt_info *info) +static void dcd_change(struct slgt_info *info, unsigned short status) { - get_signals(info); + if (status & BIT1) { + info->signals |= SerialSignal_DCD; + info->input_signal_events.dcd_up++; + } else { + info->signals &= ~SerialSignal_DCD; + info->input_signal_events.dcd_down++; + } DBGISR(("dcd_change %s signals=%04X\n", info->device_name, info->signals)); if ((info->dcd_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { slgt_irq_off(info, IRQ_DCD); return; } info->icount.dcd++; - if (info->signals & SerialSignal_DCD) { - info->input_signal_events.dcd_up++; - } else { - info->input_signal_events.dcd_down++; - } #if SYNCLINK_GENERIC_HDLC if (info->netcount) { if (info->signals & SerialSignal_DCD) @@ -2120,20 +2130,21 @@ static void dcd_change(struct slgt_info *info) } } -static void ri_change(struct slgt_info *info) +static void ri_change(struct slgt_info *info, unsigned short status) { - get_signals(info); + if (status & BIT0) { + info->signals |= SerialSignal_RI; + info->input_signal_events.ri_up++; + } else { + info->signals &= ~SerialSignal_RI; + info->input_signal_events.ri_down++; + } DBGISR(("ri_change %s signals=%04X\n", info->device_name, info->signals)); if ((info->ri_chkcount)++ == IO_PIN_SHUTDOWN_LIMIT) { slgt_irq_off(info, IRQ_RI); return; } - info->icount.dcd++; - if (info->signals & SerialSignal_RI) { - info->input_signal_events.ri_up++; - } else { - info->input_signal_events.ri_down++; - } + info->icount.rng++; wake_up_interruptible(&info->status_event_wait_q); wake_up_interruptible(&info->event_wait_q); info->pending_bh |= BH_STATUS; @@ -2147,7 +2158,7 @@ static void isr_serial(struct slgt_info *info) wr_reg16(info, SSR, status); /* clear pending */ - info->irq_occurred = 1; + info->irq_occurred = true; if (info->params.mode == MGSL_MODE_ASYNC) { if (status & IRQ_TXIDLE) { @@ -2184,13 +2195,13 @@ static void isr_serial(struct slgt_info *info) } if (status & IRQ_DSR) - dsr_change(info); + dsr_change(info, status); if (status & IRQ_CTS) - cts_change(info); + cts_change(info, status); if (status & IRQ_DCD) - dcd_change(info); + dcd_change(info, status); if (status & IRQ_RI) - ri_change(info); + ri_change(info, status); } static void isr_rdma(struct slgt_info *info) @@ -2214,7 +2225,7 @@ static void isr_rdma(struct slgt_info *info) if (status & (BIT5 + BIT4)) { DBGISR(("%s isr_rdma rx_restart=1\n", info->device_name)); - info->rx_restart = 1; + info->rx_restart = true; } info->pending_bh |= BH_RECEIVE; } @@ -2265,14 +2276,14 @@ static void isr_txeom(struct slgt_info *info, unsigned short status) info->icount.txok++; } - info->tx_active = 0; + info->tx_active = false; info->tx_count = 0; del_timer(&info->tx_timer); if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done) { info->signals &= ~SerialSignal_RTS; - info->drop_rts_on_tx_done = 0; + info->drop_rts_on_tx_done = false; set_signals(info); } @@ -2314,23 +2325,19 @@ static void isr_gpio(struct slgt_info *info, unsigned int changed, unsigned int * irq interrupt number * dev_id device ID supplied during interrupt registration */ -static irqreturn_t slgt_interrupt(int irq, void *dev_id) +static irqreturn_t slgt_interrupt(int dummy, void *dev_id) { - struct slgt_info *info; + struct slgt_info *info = dev_id; unsigned int gsr; unsigned int i; - DBGISR(("slgt_interrupt irq=%d entry\n", irq)); - - info = dev_id; - if (!info) - return IRQ_NONE; + DBGISR(("slgt_interrupt irq=%d entry\n", info->irq_level)); spin_lock(&info->lock); while((gsr = rd_reg32(info, GSR) & 0xffffff00)) { DBGISR(("%s gsr=%08x\n", info->device_name, gsr)); - info->irq_occurred = 1; + info->irq_occurred = true; for(i=0; i < info->port_count ; i++) { if (info->port_array[i] == NULL) continue; @@ -2367,13 +2374,13 @@ static irqreturn_t slgt_interrupt(int irq, void *dev_id) !port->bh_requested) { DBGISR(("%s bh queued\n", port->device_name)); schedule_work(&port->task); - port->bh_requested = 1; + port->bh_requested = true; } } spin_unlock(&info->lock); - DBGISR(("slgt_interrupt irq=%d exit\n", irq)); + DBGISR(("slgt_interrupt irq=%d exit\n", info->irq_level)); return IRQ_HANDLED; } @@ -3103,7 +3110,8 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, { DECLARE_WAITQUEUE(wait, current); int retval; - int do_clocal = 0, extra_count = 0; + bool do_clocal = false; + bool extra_count = false; unsigned long flags; DBGINFO(("%s block_til_ready\n", tty->driver->name)); @@ -3115,7 +3123,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, } if (tty->termios->c_cflag & CLOCAL) - do_clocal = 1; + do_clocal = true; /* Wait for carrier detect and the line to become * free (i.e., not in use by the callout). While we are in @@ -3129,7 +3137,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp, spin_lock_irqsave(&info->lock, flags); if (!tty_hung_up_p(filp)) { - extra_count = 1; + extra_count = true; info->count--; } spin_unlock_irqrestore(&info->lock, flags); @@ -3314,7 +3322,7 @@ static int claim_resources(struct slgt_info *info) goto errout; } else - info->reg_addr_requested = 1; + info->reg_addr_requested = true; info->reg_addr = ioremap(info->phys_reg_addr, SLGT_REG_SIZE); if (!info->reg_addr) { @@ -3334,12 +3342,12 @@ static void release_resources(struct slgt_info *info) { if (info->irq_requested) { free_irq(info->irq_level, info); - info->irq_requested = 0; + info->irq_requested = false; } if (info->reg_addr_requested) { release_mem_region(info->phys_reg_addr, SLGT_REG_SIZE); - info->reg_addr_requested = 0; + info->reg_addr_requested = false; } if (info->reg_addr) { @@ -3504,7 +3512,7 @@ static void device_init(int adapter_num, struct pci_dev *pdev) port_array[0]->device_name, port_array[0]->irq_level)); } else { - port_array[0]->irq_requested = 1; + port_array[0]->irq_requested = true; adapter_test(port_array[0]); for (i=1 ; i < port_count ; i++) { port_array[i]->init_error = port_array[0]->init_error; @@ -3647,7 +3655,7 @@ static int __init slgt_init(void) printk("%s pci_register_driver error=%d\n", driver_name, rc); goto error; } - pci_registered = 1; + pci_registered = true; if (!slgt_device_list) printk("%s no devices found\n",driver_name); @@ -3805,8 +3813,8 @@ static void rx_stop(struct slgt_info *info) rdma_reset(info); - info->rx_enabled = 0; - info->rx_restart = 0; + info->rx_enabled = false; + info->rx_restart = false; } static void rx_start(struct slgt_info *info) @@ -3842,8 +3850,8 @@ static void rx_start(struct slgt_info *info) /* enable receiver */ wr_reg16(info, RCR, (unsigned short)(rd_reg16(info, RCR) | BIT1)); - info->rx_restart = 0; - info->rx_enabled = 1; + info->rx_restart = false; + info->rx_enabled = true; } static void tx_start(struct slgt_info *info) @@ -3851,11 +3859,11 @@ static void tx_start(struct slgt_info *info) if (!info->tx_enabled) { wr_reg16(info, TCR, (unsigned short)((rd_reg16(info, TCR) | BIT1) & ~BIT2)); - info->tx_enabled = TRUE; + info->tx_enabled = true; } if (info->tx_count) { - info->drop_rts_on_tx_done = 0; + info->drop_rts_on_tx_done = false; if (info->params.mode != MGSL_MODE_ASYNC) { if (info->params.flags & HDLC_FLAG_AUTO_RTS) { @@ -3863,7 +3871,7 @@ static void tx_start(struct slgt_info *info) if (!(info->signals & SerialSignal_RTS)) { info->signals |= SerialSignal_RTS; set_signals(info); - info->drop_rts_on_tx_done = 1; + info->drop_rts_on_tx_done = true; } } @@ -3871,41 +3879,55 @@ static void tx_start(struct slgt_info *info) slgt_irq_on(info, IRQ_TXUNDER + IRQ_TXIDLE); /* clear tx idle and underrun status bits */ wr_reg16(info, SSR, (unsigned short)(IRQ_TXIDLE + IRQ_TXUNDER)); - - if (!(rd_reg32(info, TDCSR) & BIT0)) { - /* tx DMA stopped, restart tx DMA */ - tdma_reset(info); - /* set 1st descriptor address */ - wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); - switch(info->params.mode) { - case MGSL_MODE_RAW: - case MGSL_MODE_MONOSYNC: - case MGSL_MODE_BISYNC: - wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */ - break; - default: - wr_reg32(info, TDCSR, BIT0); /* DMA enable */ - } - } - if (info->params.mode == MGSL_MODE_HDLC) mod_timer(&info->tx_timer, jiffies + msecs_to_jiffies(5000)); } else { - tdma_reset(info); - /* set 1st descriptor address */ - wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); - slgt_irq_off(info, IRQ_TXDATA); slgt_irq_on(info, IRQ_TXIDLE); /* clear tx idle status bit */ wr_reg16(info, SSR, IRQ_TXIDLE); - - /* enable tx DMA */ - wr_reg32(info, TDCSR, BIT0); } + tdma_start(info); + info->tx_active = true; + } +} + +/* + * start transmit DMA if inactive and there are unsent buffers + */ +static void tdma_start(struct slgt_info *info) +{ + unsigned int i; - info->tx_active = 1; + if (rd_reg32(info, TDCSR) & BIT0) + return; + + /* transmit DMA inactive, check for unsent buffers */ + i = info->tbuf_start; + while (!desc_count(info->tbufs[i])) { + if (++i == info->tbuf_count) + i = 0; + if (i == info->tbuf_current) + return; + } + info->tbuf_start = i; + + /* there are unsent buffers, start transmit DMA */ + + /* reset needed if previous error condition */ + tdma_reset(info); + + /* set 1st descriptor address */ + wr_reg32(info, TDDAR, info->tbufs[info->tbuf_start].pdesc); + switch(info->params.mode) { + case MGSL_MODE_RAW: + case MGSL_MODE_MONOSYNC: + case MGSL_MODE_BISYNC: + wr_reg32(info, TDCSR, BIT2 + BIT0); /* IRQ + DMA enable */ + break; + default: + wr_reg32(info, TDCSR, BIT0); /* DMA enable */ } } @@ -3928,8 +3950,8 @@ static void tx_stop(struct slgt_info *info) reset_tbufs(info); - info->tx_enabled = 0; - info->tx_active = 0; + info->tx_enabled = false; + info->tx_active = false; } static void reset_port(struct slgt_info *info) @@ -4449,14 +4471,13 @@ static void reset_rbufs(struct slgt_info *info) /* * pass receive HDLC frame to upper layer * - * return 1 if frame available, otherwise 0 + * return true if frame available, otherwise false */ -static int rx_get_frame(struct slgt_info *info) +static bool rx_get_frame(struct slgt_info *info) { unsigned int start, end; unsigned short status; unsigned int framesize = 0; - int rc = 0; unsigned long flags; struct tty_struct *tty = info->tty; unsigned char addr_field = 0xff; @@ -4580,23 +4601,23 @@ check_again: } } free_rbufs(info, start, end); - rc = 1; + return true; cleanup: - return rc; + return false; } /* * pass receive buffer (RAW synchronous mode) to tty layer - * return 1 if buffer available, otherwise 0 + * return true if buffer available, otherwise false */ -static int rx_get_buf(struct slgt_info *info) +static bool rx_get_buf(struct slgt_info *info) { unsigned int i = info->rbuf_current; unsigned int count; if (!desc_complete(info->rbufs[i])) - return 0; + return false; count = desc_count(info->rbufs[i]); switch(info->params.mode) { case MGSL_MODE_MONOSYNC: @@ -4612,7 +4633,7 @@ static int rx_get_buf(struct slgt_info *info) ldisc_receive_buf(info->tty, info->rbufs[i].buf, info->flag_buf, count); free_rbufs(info, i, i); - return 1; + return true; } static void reset_tbufs(struct slgt_info *info) @@ -4642,8 +4663,8 @@ static unsigned int free_tbuf_count(struct slgt_info *info) i=0; } while (i != info->tbuf_current); - /* last buffer with zero count may be in use, assume it is */ - if (count) + /* if tx DMA active, last zero count buffer is in use */ + if (count && (rd_reg32(info, TDCSR) & BIT0)) --count; return count; @@ -4737,7 +4758,7 @@ static int irq_test(struct slgt_info *info) /* assume failure */ info->init_error = DiagStatus_IrqFailure; - info->irq_occurred = FALSE; + info->irq_occurred = false; spin_unlock_irqrestore(&info->lock, flags); @@ -4870,7 +4891,7 @@ static void tx_timeout(unsigned long context) info->icount.txtimeout++; } spin_lock_irqsave(&info->lock,flags); - info->tx_active = 0; + info->tx_active = false; info->tx_count = 0; spin_unlock_irqrestore(&info->lock,flags);