x86: PAT use reserve free memtype in mmap of /dev/mem
[safe/jmp/linux-2.6] / drivers / char / synclinkmp.c
index f185724..c96062e 100644 (file)
@@ -34,7 +34,6 @@
 
 #define MAX_DEVICES 12
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
 #include <linux/termios.h>
 #include <linux/workqueue.h>
 #include <linux/hdlc.h>
+#include <linux/synclink.h>
 
-#ifdef CONFIG_HDLC_MODULE
-#define CONFIG_HDLC 1
+#if defined(CONFIG_HDLC) || (defined(CONFIG_HDLC_MODULE) && defined(CONFIG_SYNCLINKMP_MODULE))
+#define SYNCLINK_GENERIC_HDLC 1
+#else
+#define SYNCLINK_GENERIC_HDLC 0
 #endif
 
 #define GET_USER(error,value,addr) error = get_user(value,addr)
@@ -79,8 +81,6 @@
 
 #include <asm/uaccess.h>
 
-#include "linux/synclink.h"
-
 static MGSL_PARAMS default_params = {
        MGSL_MODE_HDLC,                 /* unsigned long mode */
        0,                              /* unsigned char loopback; */
@@ -134,8 +134,6 @@ typedef struct _SCADESC_EX
 
 #define IO_PIN_SHUTDOWN_LIMIT 100
 
-#define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
-
 struct _input_signal_events {
        int     ri_up;
        int     ri_down;
@@ -281,7 +279,7 @@ typedef struct _synclinkmp_info {
        int dosyncppp;
        spinlock_t netlock;
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        struct net_device *netdev;
 #endif
 
@@ -500,7 +498,6 @@ MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
 MODULE_LICENSE("GPL");
 
 static struct pci_driver synclinkmp_pci_driver = {
-       .owner          = THIS_MODULE,
        .name           = "synclinkmp",
        .id_table       = synclinkmp_pci_tbl,
        .probe          = synclinkmp_init_one,
@@ -519,7 +516,7 @@ static struct tty_driver *serial_driver;
 static int  open(struct tty_struct *tty, struct file * filp);
 static void close(struct tty_struct *tty, struct file * filp);
 static void hangup(struct tty_struct *tty);
-static void set_termios(struct tty_struct *tty, struct termios *old_termios);
+static void set_termios(struct tty_struct *tty, struct ktermios *old_termios);
 
 static int  write(struct tty_struct *tty, const unsigned char *buf, int count);
 static void put_char(struct tty_struct *tty, unsigned char ch);
@@ -538,7 +535,7 @@ static void throttle(struct tty_struct * tty);
 static void unthrottle(struct tty_struct * tty);
 static void set_break(struct tty_struct *tty, int break_state);
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
 #define dev_to_port(D) (dev_to_hdlc(D)->priv)
 static void hdlcdev_tx_done(SLMP_INFO *info);
 static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size);
@@ -604,7 +601,7 @@ static void enable_loopback(SLMP_INFO *info, int enable);
 static void set_rate(SLMP_INFO *info, u32 data_rate);
 
 static int  bh_action(SLMP_INFO *info);
-static void bh_handler(void* Context);
+static void bh_handler(struct work_struct *work);
 static void bh_receive(SLMP_INFO *info);
 static void bh_transmit(SLMP_INFO *info);
 static void bh_status(SLMP_INFO *info);
@@ -918,7 +915,7 @@ static void hangup(struct tty_struct *tty)
 
 /* Set new termios settings
  */
-static void set_termios(struct tty_struct *tty, struct termios *old_termios)
+static void set_termios(struct tty_struct *tty, struct ktermios *old_termios)
 {
        SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
        unsigned long flags;
@@ -927,12 +924,6 @@ static void set_termios(struct tty_struct *tty, struct termios *old_termios)
                printk("%s(%d):%s set_termios()\n", __FILE__,__LINE__,
                        tty->driver->name );
 
-       /* just return if nothing has changed */
-       if ((tty->termios->c_cflag == old_termios->c_cflag)
-           && (RELEVANT_IFLAG(tty->termios->c_iflag)
-               == RELEVANT_IFLAG(old_termios->c_iflag)))
-         return;
-
        change_params(info);
 
        /* Handle transition to B0 status */
@@ -989,7 +980,7 @@ static int write(struct tty_struct *tty,
        if (sanity_check(info, tty->name, "write"))
                goto cleanup;
 
-       if (!tty || !info->tx_buf)
+       if (!info->tx_buf)
                goto cleanup;
 
        if (info->params.mode == MGSL_MODE_HDLC) {
@@ -1068,7 +1059,7 @@ static void put_char(struct tty_struct *tty, unsigned char ch)
        if (sanity_check(info, tty->name, "put_char"))
                return;
 
-       if (!tty || !info->tx_buf)
+       if (!info->tx_buf)
                return;
 
        spin_lock_irqsave(&info->lock,flags);
@@ -1258,7 +1249,6 @@ static void flush_buffer(struct tty_struct *tty)
        del_timer(&info->tx_timer);
        spin_unlock_irqrestore(&info->lock,flags);
 
-       wake_up_interruptible(&tty->write_wait);
        tty_wakeup(tty);
 }
 
@@ -1609,7 +1599,7 @@ static void set_break(struct tty_struct *tty, int break_state)
        spin_unlock_irqrestore(&info->lock,flags);
 }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
 
 /**
  * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
@@ -1651,7 +1641,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
        }
 
        info->params.encoding = new_encoding;
-       info->params.crc_type = new_crctype;;
+       info->params.crc_type = new_crctype;
 
        /* if network interface up, reprogram hardware */
        if (info->netcount)
@@ -1754,8 +1744,10 @@ static int hdlcdev_open(struct net_device *dev)
        spin_lock_irqsave(&info->lock, flags);
        get_signals(info);
        spin_unlock_irqrestore(&info->lock, flags);
-       hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev);
-
+       if (info->serial_signals & SerialSignal_DCD)
+               netif_carrier_on(dev);
+       else
+               netif_carrier_off(dev);
        return 0;
 }
 
@@ -2063,9 +2055,9 @@ int bh_action(SLMP_INFO *info)
 
 /* Perform bottom half processing of work items queued by ISR.
  */
-void bh_handler(void* Context)
+void bh_handler(struct work_struct *work)
 {
-       SLMP_INFO *info = (SLMP_INFO*)Context;
+       SLMP_INFO *info = container_of(work, SLMP_INFO, task);
        int action;
 
        if (!info)
@@ -2125,10 +2117,8 @@ void bh_transmit(SLMP_INFO *info)
                printk( "%s(%d):%s bh_transmit() entry\n",
                        __FILE__,__LINE__,info->device_name);
 
-       if (tty) {
+       if (tty)
                tty_wakeup(tty);
-               wake_up_interruptible(&tty->write_wait);
-       }
 }
 
 void bh_status(SLMP_INFO *info)
@@ -2197,7 +2187,7 @@ void isr_rxint(SLMP_INFO * info)
                        if ( tty ) {
                                if (!(status & info->ignore_status_mask1)) {
                                        if (info->read_status_mask1 & BRKD) {
-                                               *tty->flip.flag_buf_ptr = TTY_BREAK;
+                                               tty_insert_flip_char(tty, 0, TTY_BREAK);
                                                if (info->flags & ASYNC_SAK)
                                                        do_SAK(tty);
                                        }
@@ -2241,16 +2231,10 @@ void isr_rxrdy(SLMP_INFO * info)
 
        while((status = read_reg(info,CST0)) & BIT0)
        {
+               int flag = 0;
+               int over = 0;
                DataByte = read_reg(info,TRB);
 
-               if ( tty ) {
-                       if (tty->flip.count >= TTY_FLIPBUF_SIZE)
-                               continue;
-
-                       *tty->flip.char_buf_ptr = DataByte;
-                       *tty->flip.flag_buf_ptr = 0;
-               }
-
                icount->rx++;
 
                if ( status & (PE + FRME + OVRN) ) {
@@ -2273,42 +2257,34 @@ void isr_rxrdy(SLMP_INFO * info)
 
                        if ( tty ) {
                                if (status & PE)
-                                       *tty->flip.flag_buf_ptr = TTY_PARITY;
+                                       flag = TTY_PARITY;
                                else if (status & FRME)
-                                       *tty->flip.flag_buf_ptr = TTY_FRAME;
+                                       flag = TTY_FRAME;
                                if (status & OVRN) {
                                        /* Overrun is special, since it's
                                         * reported immediately, and doesn't
                                         * affect the current character
                                         */
-                                       if (tty->flip.count < TTY_FLIPBUF_SIZE) {
-                                               tty->flip.count++;
-                                               tty->flip.flag_buf_ptr++;
-                                               tty->flip.char_buf_ptr++;
-                                               *tty->flip.flag_buf_ptr = TTY_OVERRUN;
-                                       }
+                                       over = 1;
                                }
                        }
                }       /* end of if (error) */
 
                if ( tty ) {
-                       tty->flip.flag_buf_ptr++;
-                       tty->flip.char_buf_ptr++;
-                       tty->flip.count++;
+                       tty_insert_flip_char(tty, DataByte, flag);
+                       if (over)
+                               tty_insert_flip_char(tty, 0, TTY_OVERRUN);
                }
        }
 
        if ( debug_level >= DEBUG_LEVEL_ISR ) {
-               printk("%s(%d):%s isr_rxrdy() flip count=%d\n",
-                       __FILE__,__LINE__,info->device_name,
-                       tty ? tty->flip.count : 0);
                printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
                        __FILE__,__LINE__,info->device_name,
                        icount->rx,icount->brk,icount->parity,
                        icount->frame,icount->overrun);
        }
 
-       if ( tty && tty->flip.count )
+       if ( tty )
                tty_flip_buffer_push(tty);
 }
 
@@ -2353,7 +2329,7 @@ static void isr_txeom(SLMP_INFO * info, unsigned char status)
                        set_signals(info);
                }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                if (info->netcount)
                        hdlcdev_tx_done(info);
                else
@@ -2537,9 +2513,13 @@ void isr_io_pin( SLMP_INFO *info, u16 status )
                                info->input_signal_events.dcd_up++;
                        } else
                                info->input_signal_events.dcd_down++;
-#ifdef CONFIG_HDLC
-                       if (info->netcount)
-                               hdlc_set_carrier(status & SerialSignal_DCD, info->netdev);
+#if SYNCLINK_GENERIC_HDLC
+                       if (info->netcount) {
+                               if (status & SerialSignal_DCD)
+                                       netif_carrier_on(info->netdev);
+                               else
+                                       netif_carrier_off(info->netdev);
+                       }
 #endif
                }
                if (status & MISCSTATUS_CTS_LATCHED)
@@ -2606,10 +2586,9 @@ void isr_io_pin( SLMP_INFO *info, u16 status )
  *     dev_id          device ID supplied during interrupt registration
  *     regs            interrupted processor context
  */
-static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
-                                       struct pt_regs *regs)
+static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
 {
-       SLMP_INFO * info;
+       SLMP_INFO *info = dev_id;
        unsigned char status, status0, status1=0;
        unsigned char dmastatus, dmastatus0, dmastatus1=0;
        unsigned char timerstatus0, timerstatus1=0;
@@ -2618,12 +2597,8 @@ static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
        unsigned short tmp;
 
        if ( debug_level >= DEBUG_LEVEL_ISR )
-               printk("%s(%d): synclinkmp_interrupt(%d)entry.\n",
-                       __FILE__,__LINE__,irq);
-
-       info = (SLMP_INFO *)dev_id;
-       if (!info)
-               return IRQ_NONE;
+               printk(KERN_DEBUG "%s(%d): synclinkmp_interrupt(%d)entry.\n",
+                       __FILE__, __LINE__, info->irq_level);
 
        spin_lock(&info->lock);
 
@@ -2636,9 +2611,9 @@ static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
                timerstatus0 = read_reg(info, ISR2);
 
                if ( debug_level >= DEBUG_LEVEL_ISR )
-                       printk("%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
-                               __FILE__,__LINE__,info->device_name,
-                               status0,dmastatus0,timerstatus0);
+                       printk(KERN_DEBUG "%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
+                               __FILE__, __LINE__, info->device_name,
+                               status0, dmastatus0, timerstatus0);
 
                if (info->port_count == 4) {
                        /* get status for SCA1 (ports 2-3) */
@@ -2723,8 +2698,8 @@ static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
        spin_unlock(&info->lock);
 
        if ( debug_level >= DEBUG_LEVEL_ISR )
-               printk("%s(%d):synclinkmp_interrupt(%d)exit.\n",
-                       __FILE__,__LINE__,irq);
+               printk(KERN_DEBUG "%s(%d):synclinkmp_interrupt(%d)exit.\n",
+                       __FILE__, __LINE__, info->irq_level);
        return IRQ_HANDLED;
 }
 
@@ -2739,7 +2714,7 @@ static int startup(SLMP_INFO * info)
                return 0;
 
        if (!info->tx_buf) {
-               info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL);
+               info->tx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
                if (!info->tx_buf) {
                        printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
                                __FILE__,__LINE__,info->device_name);
@@ -2756,8 +2731,7 @@ static int startup(SLMP_INFO * info)
 
        change_params(info);
 
-       info->status_timer.expires = jiffies + msecs_to_jiffies(10);
-       add_timer(&info->status_timer);
+       mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
 
        if (info->tty)
                clear_bit(TTY_IO_ERROR, &info->tty->flags);
@@ -2788,10 +2762,8 @@ static void shutdown(SLMP_INFO * info)
        del_timer(&info->tx_timer);
        del_timer(&info->status_timer);
 
-       if (info->tx_buf) {
-               kfree(info->tx_buf);
-               info->tx_buf = NULL;
-       }
+       kfree(info->tx_buf);
+       info->tx_buf = NULL;
 
        spin_lock_irqsave(&info->lock,flags);
 
@@ -3611,8 +3583,7 @@ int alloc_tmp_rx_buf(SLMP_INFO *info)
 
 void free_tmp_rx_buf(SLMP_INFO *info)
 {
-       if (info->tmp_rx_buf)
-               kfree(info->tmp_rx_buf);
+       kfree(info->tmp_rx_buf);
        info->tmp_rx_buf = NULL;
 }
 
@@ -3797,7 +3768,7 @@ void add_device(SLMP_INFO *info)
                info->irq_level,
                info->max_frame_size );
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        hdlcdev_init(info);
 #endif
 }
@@ -3810,16 +3781,15 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
 {
        SLMP_INFO *info;
 
-       info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO),
+       info = kzalloc(sizeof(SLMP_INFO),
                 GFP_KERNEL);
 
        if (!info) {
                printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
                        __FILE__,__LINE__, adapter_num, port_num);
        } else {
-               memset(info, 0, sizeof(SLMP_INFO));
                info->magic = MGSL_MAGIC;
-               INIT_WORK(&info->task, bh_handler, info);
+               INIT_WORK(&info->task, bh_handler);
                info->max_frame_size = 4096;
                info->close_delay = 5*HZ/10;
                info->closing_wait = 30*HZ;
@@ -3854,15 +3824,11 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
                info->phys_statctrl_base &= ~(PAGE_SIZE-1);
 
                info->bus_type = MGSL_BUS_TYPE_PCI;
-               info->irq_flags = SA_SHIRQ;
-
-               init_timer(&info->tx_timer);
-               info->tx_timer.data = (unsigned long)info;
-               info->tx_timer.function = tx_timeout;
+               info->irq_flags = IRQF_SHARED;
 
-               init_timer(&info->status_timer);
-               info->status_timer.data = (unsigned long)info;
-               info->status_timer.function = status_timeout;
+               setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
+               setup_timer(&info->status_timer, status_timeout,
+                               (unsigned long)info);
 
                /* Store the PCI9050 misc control register value because a flaw
                 * in the PCI9050 prevents LCR registers from being read if
@@ -3942,7 +3908,7 @@ void device_init(int adapter_num, struct pci_dev *pdev)
        }
 }
 
-static struct tty_operations ops = {
+static const struct tty_operations ops = {
        .open = open,
        .close = close,
        .write = write,
@@ -3991,7 +3957,7 @@ static void synclinkmp_cleanup(void)
        /* release devices */
        info = synclinkmp_device_list;
        while(info) {
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                hdlcdev_exit(info);
 #endif
                free_dma_bufs(info);
@@ -4046,6 +4012,8 @@ static int __init synclinkmp_init(void)
        serial_driver->init_termios = tty_std_termios;
        serial_driver->init_termios.c_cflag =
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+       serial_driver->init_termios.c_ispeed = 9600;
+       serial_driver->init_termios.c_ospeed = 9600;
        serial_driver->flags = TTY_DRIVER_REAL_RAW;
        tty_set_operations(serial_driver, &ops);
        if ((rc = tty_register_driver(serial_driver)) < 0) {
@@ -4304,8 +4272,8 @@ void tx_start(SLMP_INFO *info)
                        write_reg(info, TXDMA + DIR, 0x40);             /* enable Tx DMA interrupts (EOM) */
                        write_reg(info, TXDMA + DSR, 0xf2);             /* clear Tx DMA IRQs, enable Tx DMA */
        
-                       info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
-                       add_timer(&info->tx_timer);
+                       mod_timer(&info->tx_timer, jiffies +
+                                       msecs_to_jiffies(5000));
                }
                else {
                        tx_load_fifo(info);
@@ -4993,7 +4961,7 @@ CheckAgain:
                        info->icount.rxcrc++;
 
                framesize = 0;
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                {
                        struct net_device_stats *stats = hdlc_stats(info->netdev);
                        stats->rx_errors++;
@@ -5034,7 +5002,7 @@ CheckAgain:
                                        index = 0;
                        }
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
                        if (info->netcount)
                                hdlcdev_rx(info,info->tmp_rx_buf,framesize);
                        else
@@ -5108,7 +5076,7 @@ void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count)
 int register_test(SLMP_INFO *info)
 {
        static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
-       static unsigned int count = sizeof(testval)/sizeof(unsigned char);
+       static unsigned int count = ARRAY_SIZE(testval);
        unsigned int i;
        int rc = TRUE;
        unsigned long flags;
@@ -5426,7 +5394,7 @@ int memory_test(SLMP_INFO *info)
 {
        static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
                0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
-       unsigned long count = sizeof(testval)/sizeof(unsigned long);
+       unsigned long count = ARRAY_SIZE(testval);
        unsigned long i;
        unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
        unsigned long * addr = (unsigned long *)info->memory_base;
@@ -5545,7 +5513,7 @@ void tx_timeout(unsigned long context)
 
        spin_unlock_irqrestore(&info->lock,flags);
 
-#ifdef CONFIG_HDLC
+#if SYNCLINK_GENERIC_HDLC
        if (info->netcount)
                hdlcdev_tx_done(info);
        else
@@ -5587,10 +5555,7 @@ void status_timeout(unsigned long context)
        if (status)
                isr_io_pin(info,status);
 
-       info->status_timer.data = (unsigned long)info;
-       info->status_timer.function = status_timeout;
-       info->status_timer.expires = jiffies + msecs_to_jiffies(10);
-       add_timer(&info->status_timer);
+       mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
 }