Merge branch 'for-linus' of git://neil.brown.name/md
[safe/jmp/linux-2.6] / drivers / serial / icom.c
index 79f8df4..a461b3b 100644 (file)
   */
 #define SERIAL_DO_RESTART
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/signal.h>
-#include <linux/sched.h>
 #include <linux/timer.h>
 #include <linux/interrupt.h>
 #include <linux/tty.h>
 #include <linux/pci.h>
 #include <linux/vmalloc.h>
 #include <linux/smp.h>
-#include <linux/smp_lock.h>
 #include <linux/spinlock.h>
-#include <linux/kobject.h>
+#include <linux/kref.h>
 #include <linux/firmware.h>
 #include <linux/bitops.h>
 
 #include <asm/system.h>
-#include <asm/segment.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 #include <asm/uaccess.h>
 #define ICOM_VERSION_STR "1.3.1"
 #define NR_PORTS              128
 #define ICOM_PORT ((struct icom_port *)port)
-#define to_icom_adapter(d) container_of(d, struct icom_adapter, kobj)
+#define to_icom_adapter(d) container_of(d, struct icom_adapter, kref)
 
 static const struct pci_device_id icom_pci_table[] = {
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
-             .subvendor = PCI_ANY_ID,
-             .subdevice = PCI_ANY_ID,
-             .driver_data = ADAPTER_V1,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
+               .subvendor = PCI_ANY_ID,
+               .subdevice = PCI_ANY_ID,
+               .driver_data = ADAPTER_V1,
+       },
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
-             .subvendor = PCI_VENDOR_ID_IBM,
-             .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
-             .driver_data = ADAPTER_V2,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
+               .driver_data = ADAPTER_V2,
+       },
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
-             .subvendor = PCI_VENDOR_ID_IBM,
-             .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
-             .driver_data = ADAPTER_V2,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
+               .driver_data = ADAPTER_V2,
+       },
        {
-             .vendor = PCI_VENDOR_ID_IBM,
-             .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
-             .subvendor = PCI_VENDOR_ID_IBM,
-             .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
-             .driver_data = ADAPTER_V2,
-        },
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
+               .driver_data = ADAPTER_V2,
+       },
+       {
+               .vendor = PCI_VENDOR_ID_IBM,
+               .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
+               .subvendor = PCI_VENDOR_ID_IBM,
+               .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM_PCIE,
+               .driver_data = ADAPTER_V2,
+       },
        {}
 };
 
@@ -138,6 +141,7 @@ static inline void trace(struct icom_port *, char *, unsigned long) {};
 #else
 static inline void trace(struct icom_port *icom_port, char *trace_pt, unsigned long trace_data) {};
 #endif
+static void icom_kref_release(struct kref *kref);
 
 static void free_port_memory(struct icom_port *icom_port)
 {
@@ -167,7 +171,7 @@ static void free_port_memory(struct icom_port *icom_port)
        }
 }
 
-static int __init get_port_memory(struct icom_port *icom_port)
+static int __devinit get_port_memory(struct icom_port *icom_port)
 {
        int index;
        unsigned long stgAddr;
@@ -726,23 +730,24 @@ static void xmit_interrupt(u16 port_int_reg, struct icom_port *icom_port)
 static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
 {
        short int count, rcv_buff;
-       struct tty_struct *tty = icom_port->uart_port.info->tty;
+       struct tty_struct *tty = icom_port->uart_port.info->port.tty;
        unsigned short int status;
        struct uart_icount *icount;
        unsigned long offset;
+       unsigned char flag;
 
        trace(icom_port, "RCV_COMPLETE", 0);
        rcv_buff = icom_port->next_rcv;
 
        status = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].flags);
        while (status & SA_FL_RCV_DONE) {
+               int first = -1;
 
                trace(icom_port, "FID_STATUS", status);
                count = cpu_to_le16(icom_port->statStg->rcv[rcv_buff].leLength);
 
+                count = tty_buffer_request_room(tty, count);
                trace(icom_port, "RCV_COUNT", count);
-               if (count > (TTY_FLIPBUF_SIZE - tty->flip.count))
-                       count = TTY_FLIPBUF_SIZE - tty->flip.count;
 
                trace(icom_port, "REAL_COUNT", count);
 
@@ -750,15 +755,10 @@ static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
                        cpu_to_le32(icom_port->statStg->rcv[rcv_buff].leBuffer) -
                        icom_port->recv_buf_pci;
 
-               memcpy(tty->flip.char_buf_ptr,(unsigned char *)
-                      ((unsigned long)icom_port->recv_buf + offset), count);
-
+               /* Block copy all but the last byte as this may have status */
                if (count > 0) {
-                       tty->flip.count += count - 1;
-                       tty->flip.char_buf_ptr += count - 1;
-
-                       memset(tty->flip.flag_buf_ptr, 0, count);
-                       tty->flip.flag_buf_ptr += count - 1;
+                       first = icom_port->recv_buf[offset];
+                       tty_insert_flip_string(tty, icom_port->recv_buf + offset, count - 1);
                }
 
                icount = &icom_port->uart_port.icount;
@@ -766,12 +766,14 @@ static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
 
                /* Break detect logic */
                if ((status & SA_FLAGS_FRAME_ERROR)
-                   && (tty->flip.char_buf_ptr[0] == 0x00)) {
+                   && first == 0) {
                        status &= ~SA_FLAGS_FRAME_ERROR;
                        status |= SA_FLAGS_BREAK_DET;
                        trace(icom_port, "BREAK_DET", 0);
                }
 
+               flag = TTY_NORMAL;
+
                if (status &
                    (SA_FLAGS_BREAK_DET | SA_FLAGS_PARITY_ERROR |
                     SA_FLAGS_FRAME_ERROR | SA_FLAGS_OVERRUN)) {
@@ -798,33 +800,26 @@ static void recv_interrupt(u16 port_int_reg, struct icom_port *icom_port)
                        status &= icom_port->read_status_mask;
 
                        if (status & SA_FLAGS_BREAK_DET) {
-                               *tty->flip.flag_buf_ptr = TTY_BREAK;
+                               flag = TTY_BREAK;
                        } else if (status & SA_FLAGS_PARITY_ERROR) {
                                trace(icom_port, "PARITY_ERROR", 0);
-                               *tty->flip.flag_buf_ptr = TTY_PARITY;
+                               flag = TTY_PARITY;
                        } else if (status & SA_FLAGS_FRAME_ERROR)
-                               *tty->flip.flag_buf_ptr = TTY_FRAME;
-
-                       if (status & SA_FLAGS_OVERRUN) {
-                               /*
-                                * 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;
-                               }
-                       }
+                               flag = TTY_FRAME;
+
                }
 
-               tty->flip.flag_buf_ptr++;
-               tty->flip.char_buf_ptr++;
-               tty->flip.count++;
-               ignore_char:
-                       icom_port->statStg->rcv[rcv_buff].flags = 0;
+               tty_insert_flip_char(tty, *(icom_port->recv_buf + offset + count - 1), flag);
+
+               if (status & SA_FLAGS_OVERRUN)
+                       /*
+                        * Overrun is special, since it's
+                        * reported immediately, and doesn't
+                        * affect the current character
+                        */
+                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+ignore_char:
+               icom_port->statStg->rcv[rcv_buff].flags = 0;
                icom_port->statStg->rcv[rcv_buff].leLength = 0;
                icom_port->statStg->rcv[rcv_buff].WorkingLength =
                        (unsigned short int) cpu_to_le16(RCV_BUFF_SZ);
@@ -855,8 +850,7 @@ static void process_interrupt(u16 port_int_reg,
        spin_unlock(&icom_port->uart_port.lock);
 }
 
-static irqreturn_t icom_interrupt(int irq, void *dev_id,
-                                 struct pt_regs *regs)
+static irqreturn_t icom_interrupt(int irq, void *dev_id)
 {
        void __iomem * int_reg;
        u32 adapter_interrupts;
@@ -1070,11 +1064,11 @@ static int icom_open(struct uart_port *port)
 {
        int retval;
 
-       kobject_get(&ICOM_PORT->adapter->kobj);
+       kref_get(&ICOM_PORT->adapter->kref);
        retval = startup(ICOM_PORT);
 
        if (retval) {
-               kobject_put(&ICOM_PORT->adapter->kobj);
+               kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
                trace(ICOM_PORT, "STARTUP_ERROR", 0);
                return retval;
        }
@@ -1095,16 +1089,15 @@ static void icom_close(struct uart_port *port)
 
        shutdown(ICOM_PORT);
 
-       kobject_put(&ICOM_PORT->adapter->kobj);
+       kref_put(&ICOM_PORT->adapter->kref, icom_kref_release);
 }
 
 static void icom_set_termios(struct uart_port *port,
-                            struct termios *termios,
-                            struct termios *old_termios)
+                            struct ktermios *termios,
+                            struct ktermios *old_termios)
 {
        int baud;
        unsigned cflag, iflag;
-       int bits;
        char new_config2;
        char new_config3 = 0;
        char tmp_byte;
@@ -1125,34 +1118,27 @@ static void icom_set_termios(struct uart_port *port,
        switch (cflag & CSIZE) {
        case CS5:               /* 5 bits/char */
                new_config2 |= ICOM_ACFG_5BPC;
-               bits = 7;
                break;
        case CS6:               /* 6 bits/char */
                new_config2 |= ICOM_ACFG_6BPC;
-               bits = 8;
                break;
        case CS7:               /* 7 bits/char */
                new_config2 |= ICOM_ACFG_7BPC;
-               bits = 9;
                break;
        case CS8:               /* 8 bits/char */
                new_config2 |= ICOM_ACFG_8BPC;
-               bits = 10;
                break;
        default:
-               bits = 10;
                break;
        }
        if (cflag & CSTOPB) {
                /* 2 stop bits */
                new_config2 |= ICOM_ACFG_2STOP_BIT;
-               bits++;
        }
        if (cflag & PARENB) {
                /* parity bit enabled */
                new_config2 |= ICOM_ACFG_PARITY_ENAB;
                trace(ICOM_PORT, "PARENB", 0);
-               bits++;
        }
        if (cflag & PARODD) {
                /* odd parity */
@@ -1328,7 +1314,6 @@ static struct uart_driver icom_uart_driver = {
 static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
 {
        u32 subsystem_id = icom_adapter->subsystem_id;
-       int retval = 0;
        int i;
        struct icom_port *icom_port;
 
@@ -1374,7 +1359,7 @@ static int __devinit icom_init_ports(struct icom_adapter *icom_adapter)
                }
        }
 
-       return retval;
+       return 0;
 }
 
 static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *icom_adapter, int port_num)
@@ -1393,11 +1378,10 @@ static void icom_port_active(struct icom_port *icom_port, struct icom_adapter *i
                            0x8024 + 2 - 2 * (icom_port->port - 2);
        }
 }
-static int __init icom_load_ports(struct icom_adapter *icom_adapter)
+static int __devinit icom_load_ports(struct icom_adapter *icom_adapter)
 {
        struct icom_port *icom_port;
        int port_num;
-       int retval;
 
        for (port_num = 0; port_num < icom_adapter->numb_ports; port_num++) {
 
@@ -1411,7 +1395,7 @@ static int __init icom_load_ports(struct icom_adapter *icom_adapter)
                        icom_port->adapter = icom_adapter;
 
                        /* get port memory */
-                       if ((retval = get_port_memory(icom_port)) != 0) {
+                       if (get_port_memory(icom_port) != 0) {
                                dev_err(&icom_port->adapter->pci_dev->dev,
                                        "Memory allocation for port FAILED\n");
                        }
@@ -1429,14 +1413,12 @@ static int __devinit icom_alloc_adapter(struct icom_adapter
        struct list_head *tmp;
 
        icom_adapter = (struct icom_adapter *)
-           kmalloc(sizeof(struct icom_adapter), GFP_KERNEL);
+           kzalloc(sizeof(struct icom_adapter), GFP_KERNEL);
 
        if (!icom_adapter) {
                return -ENOMEM;
        }
 
-       memset(icom_adapter, 0, sizeof(struct icom_adapter));
-
        list_for_each(tmp, &icom_adapter_head) {
                cur_adapter_entry =
                    list_entry(tmp, struct icom_adapter,
@@ -1488,24 +1470,20 @@ static void icom_remove_adapter(struct icom_adapter *icom_adapter)
                }
        }
 
-       free_irq(icom_adapter->irq_number, (void *) icom_adapter);
+       free_irq(icom_adapter->pci_dev->irq, (void *) icom_adapter);
        iounmap(icom_adapter->base_addr);
-       icom_free_adapter(icom_adapter);
        pci_release_regions(icom_adapter->pci_dev);
+       icom_free_adapter(icom_adapter);
 }
 
-static void icom_kobj_release(struct kobject *kobj)
+static void icom_kref_release(struct kref *kref)
 {
        struct icom_adapter *icom_adapter;
 
-       icom_adapter = to_icom_adapter(kobj);
+       icom_adapter = to_icom_adapter(kref);
        icom_remove_adapter(icom_adapter);
 }
 
-static struct kobj_type icom_kobj_type = {
-       .release = icom_kobj_release,
-};
-
 static int __devinit icom_probe(struct pci_dev *dev,
                                const struct pci_device_id *ent)
 {
@@ -1522,7 +1500,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
        }
 
        if ( (retval = pci_request_regions(dev, "icom"))) {
-                dev_err(&dev->dev, "pci_request_region FAILED\n");
+                dev_err(&dev->dev, "pci_request_regions FAILED\n");
                 pci_disable_device(dev);
                 return retval;
         }
@@ -1554,7 +1532,6 @@ static int __devinit icom_probe(struct pci_dev *dev,
        }
 
         icom_adapter->base_addr_pci = pci_resource_start(dev, 0);
-        icom_adapter->irq_number = dev->irq;
         icom_adapter->pci_dev = dev;
         icom_adapter->version = ent->driver_data;
         icom_adapter->subsystem_id = ent->subdevice;
@@ -1574,7 +1551,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
 
         /* save off irq and request irq line */
         if ( (retval = request_irq(dev->irq, icom_interrupt,
-                                  SA_INTERRUPT | SA_SHIRQ, ICOM_DRIVER_NAME,
+                                  IRQF_DISABLED | IRQF_SHARED, ICOM_DRIVER_NAME,
                                   (void *) icom_adapter))) {
                  goto probe_exit2;
         }
@@ -1585,7 +1562,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
                icom_port = &icom_adapter->port_info[index];
 
                if (icom_port->status == ICOM_PORT_ACTIVE) {
-                       icom_port->uart_port.irq = icom_port->adapter->irq_number;
+                       icom_port->uart_port.irq = icom_port->adapter->pci_dev->irq;
                        icom_port->uart_port.type = PORT_ICOM;
                        icom_port->uart_port.iotype = UPIO_MEM;
                        icom_port->uart_port.membase =
@@ -1602,8 +1579,7 @@ static int __devinit icom_probe(struct pci_dev *dev,
                }
        }
 
-       kobject_init(&icom_adapter->kobj);
-       icom_adapter->kobj.ktype = &icom_kobj_type;
+       kref_init(&icom_adapter->kref);
        return 0;
 
 probe_exit2:
@@ -1629,7 +1605,7 @@ static void __devexit icom_remove(struct pci_dev *dev)
                icom_adapter = list_entry(tmp, struct icom_adapter,
                                          icom_adapter_entry);
                if (icom_adapter->pci_dev == dev) {
-                       kobject_put(&icom_adapter->kobj);
+                       kref_put(&icom_adapter->kref, icom_kref_release);
                        return;
                }
        }