pcmcia: do not use io_req_t after call to pcmcia_request_io()
[linux-2.6.git] / drivers / scsi / pcmcia / sym53c500_cs.c
index 1ef3109..d99c0cb 100644 (file)
@@ -54,7 +54,6 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/ioport.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_host.h>
 
-#include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 #include <pcmcia/ciscode.h>
 
-/* ================================================================== */
-
-#ifdef PCMCIA_DEBUG
-static int pc_debug = PCMCIA_DEBUG;
-module_param(pc_debug, int, 0);
-#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
-static char *version =
-"sym53c500_cs.c 0.9c 2004/10/27 (Bob Tracy)";
-#else
-#define DEBUG(n, args...)
-#endif
 
 /* ================================================================== */
 
@@ -203,7 +190,6 @@ static char *version =
 
 struct scsi_info_t {
        struct pcmcia_device    *p_dev;
-       dev_node_t node;
        struct Scsi_Host *host;
        unsigned short manf_id;
 };
@@ -363,7 +349,7 @@ SYM53C500_pio_write(int fast_pio, int base, unsigned char *request, unsigned int
 }
 
 static irqreturn_t
-SYM53C500_intr(int irq, void *dev_id, struct pt_regs *regs)
+SYM53C500_intr(int irq, void *dev_id)
 {
        unsigned long flags;
        struct Scsi_Host *dev = dev_id;
@@ -371,8 +357,6 @@ SYM53C500_intr(int irq, void *dev_id, struct pt_regs *regs)
        DEB(unsigned char seq_reg;)
        unsigned char status, int_reg;
        unsigned char pio_status;
-       struct scatterlist *sglist;
-       unsigned int sgcount;
        int port_base = dev->io_port;
        struct sym53c500_data *data =
            (struct sym53c500_data *)dev->hostdata;
@@ -435,20 +419,18 @@ SYM53C500_intr(int irq, void *dev_id, struct pt_regs *regs)
        switch (status & 0x07) {        /* scsi phase */
        case 0x00:                      /* DATA-OUT */
                if (int_reg & 0x10) {   /* Target requesting info transfer */
+                       struct scatterlist *sg;
+                       int i;
+
                        curSC->SCp.phase = data_out;
                        VDEB(printk("SYM53C500: Data-Out phase\n"));
                        outb(FLUSH_FIFO, port_base + CMD_REG);
-                       LOAD_DMA_COUNT(port_base, curSC->request_bufflen);      /* Max transfer size */
+                       LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */
                        outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG);
-                       if (!curSC->use_sg)     /* Don't use scatter-gather */
-                               SYM53C500_pio_write(fast_pio, port_base, curSC->request_buffer, curSC->request_bufflen);
-                       else {  /* use scatter-gather */
-                               sgcount = curSC->use_sg;
-                               sglist = curSC->request_buffer;
-                               while (sgcount--) {
-                                       SYM53C500_pio_write(fast_pio, port_base, page_address(sglist->page) + sglist->offset, sglist->length);
-                                       sglist++;
-                               }
+
+                       scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
+                               SYM53C500_pio_write(fast_pio, port_base,
+                                   sg_virt(sg), sg->length);
                        }
                        REG0(port_base);
                }
@@ -456,20 +438,18 @@ SYM53C500_intr(int irq, void *dev_id, struct pt_regs *regs)
 
        case 0x01:              /* DATA-IN */
                if (int_reg & 0x10) {   /* Target requesting info transfer */
+                       struct scatterlist *sg;
+                       int i;
+
                        curSC->SCp.phase = data_in;
                        VDEB(printk("SYM53C500: Data-In phase\n"));
                        outb(FLUSH_FIFO, port_base + CMD_REG);
-                       LOAD_DMA_COUNT(port_base, curSC->request_bufflen);      /* Max transfer size */
+                       LOAD_DMA_COUNT(port_base, scsi_bufflen(curSC)); /* Max transfer size */
                        outb(TRANSFER_INFO | DMA_OP, port_base + CMD_REG);
-                       if (!curSC->use_sg)     /* Don't use scatter-gather */
-                               SYM53C500_pio_read(fast_pio, port_base, curSC->request_buffer, curSC->request_bufflen);
-                       else {  /* Use scatter-gather */
-                               sgcount = curSC->use_sg;
-                               sglist = curSC->request_buffer;
-                               while (sgcount--) {
-                                       SYM53C500_pio_read(fast_pio, port_base, page_address(sglist->page) + sglist->offset, sglist->length);
-                                       sglist++;
-                               }
+
+                       scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
+                               SYM53C500_pio_read(fast_pio, port_base,
+                                       sg_virt(sg), sg->length);
                        }
                        REG0(port_base);
                }
@@ -527,12 +507,12 @@ idle_out:
 }
 
 static void
-SYM53C500_release(dev_link_t *link)
+SYM53C500_release(struct pcmcia_device *link)
 {
        struct scsi_info_t *info = link->priv;
        struct Scsi_Host *shost = info->host;
 
-       DEBUG(0, "SYM53C500_release(0x%p)\n", link);
+       dev_dbg(&link->dev, "SYM53C500_release\n");
 
        /*
        *  Do this before releasing/freeing resources.
@@ -545,12 +525,10 @@ SYM53C500_release(dev_link_t *link)
        */
        if (shost->irq)
                free_irq(shost->irq, shost);
-       if (shost->dma_channel != 0xff)
-               free_dma(shost->dma_channel);
        if (shost->io_port && shost->n_io_port)
                release_region(shost->io_port, shost->n_io_port);
 
-       pcmcia_disable_device(link->handle);
+       pcmcia_disable_device(link);
 
        scsi_host_put(shost);
 } /* SYM53C500_release */
@@ -581,7 +559,7 @@ SYM53C500_queue(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
 
        DEB(printk("cmd=%02x, cmd_len=%02x, target=%02x, lun=%02x, bufflen=%d\n", 
            SCpnt->cmnd[0], SCpnt->cmd_len, SCpnt->device->id, 
-           SCpnt->device->lun,  SCpnt->request_bufflen));
+           SCpnt->device->lun,  scsi_bufflen(SCpnt)));
 
        VDEB(for (i = 0; i < SCpnt->cmd_len; i++)
            printk("cmd[%d]=%02x  ", i, SCpnt->cmnd[i]));
@@ -641,9 +619,10 @@ SYM53C500_biosparm(struct scsi_device *disk,
 }
 
 static ssize_t
-SYM53C500_show_pio(struct class_device *cdev, char *buf)
+SYM53C500_show_pio(struct device *dev, struct device_attribute *attr,
+                  char *buf)
 {
-       struct Scsi_Host *SHp = class_to_shost(cdev);
+       struct Scsi_Host *SHp = class_to_shost(dev);
        struct sym53c500_data *data =
            (struct sym53c500_data *)SHp->hostdata;
 
@@ -651,10 +630,11 @@ SYM53C500_show_pio(struct class_device *cdev, char *buf)
 }
 
 static ssize_t
-SYM53C500_store_pio(struct class_device *cdev, const char *buf, size_t count)
+SYM53C500_store_pio(struct device *dev, struct device_attribute *attr,
+                   const char *buf, size_t count)
 {
        int pio;
-       struct Scsi_Host *SHp = class_to_shost(cdev);
+       struct Scsi_Host *SHp = class_to_shost(dev);
        struct sym53c500_data *data =
            (struct sym53c500_data *)SHp->hostdata;
 
@@ -671,7 +651,7 @@ SYM53C500_store_pio(struct class_device *cdev, const char *buf, size_t count)
 *  SCSI HBA device attributes we want to
 *  make available via sysfs.
 */
-static struct class_device_attribute SYM53C500_pio_attr = {
+static struct device_attribute SYM53C500_pio_attr = {
        .attr = {
                .name = "fast_pio",
                .mode = (S_IRUGO | S_IWUSR),
@@ -680,7 +660,7 @@ static struct class_device_attribute SYM53C500_pio_attr = {
        .store = SYM53C500_store_pio,
 };
 
-static struct class_device_attribute *SYM53C500_shost_attrs[] = {
+static struct device_attribute *SYM53C500_shost_attrs[] = {
        &SYM53C500_pio_attr,
        NULL,
 };
@@ -704,63 +684,45 @@ static struct scsi_host_template sym53c500_driver_template = {
      .shost_attrs              = SYM53C500_shost_attrs
 };
 
-#define CS_CHECK(fn, ret) \
-do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
+static int SYM53C500_config_check(struct pcmcia_device *p_dev,
+                                 cistpl_cftable_entry_t *cfg,
+                                 cistpl_cftable_entry_t *dflt,
+                                 unsigned int vcc,
+                                 void *priv_data)
+{
+       p_dev->io.BasePort1 = cfg->io.win[0].base;
+       p_dev->io.NumPorts1 = cfg->io.win[0].len;
+
+       if (p_dev->io.BasePort1 == 0)
+               return -ENODEV;
 
-static void
-SYM53C500_config(dev_link_t *link)
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
+static int
+SYM53C500_config(struct pcmcia_device *link)
 {
-       client_handle_t handle = link->handle;
        struct scsi_info_t *info = link->priv;
-       tuple_t tuple;
-       cisparse_t parse;
-       int i, last_ret, last_fn;
+       int ret;
        int irq_level, port_base;
-       unsigned short tuple_data[32];
        struct Scsi_Host *host;
        struct scsi_host_template *tpnt = &sym53c500_driver_template;
        struct sym53c500_data *data;
 
-       DEBUG(0, "SYM53C500_config(0x%p)\n", link);
-
-       tuple.TupleData = (cisdata_t *)tuple_data;
-       tuple.TupleDataMax = 64;
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = CISTPL_CONFIG;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
-       CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse));
-       link->conf.ConfigBase = parse.config.base;
-
-       tuple.DesiredTuple = CISTPL_MANFID;
-       if ((pcmcia_get_first_tuple(handle, &tuple) == CS_SUCCESS) &&
-           (pcmcia_get_tuple_data(handle, &tuple) == CS_SUCCESS))
-               info->manf_id = le16_to_cpu(tuple.TupleData[0]);
-
-       /* Configure card */
-       link->state |= DEV_CONFIG;
-
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple));
-       while (1) {
-               if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
-                   pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
-                       goto next_entry;
-               link->conf.ConfigIndex = parse.cftable_entry.index;
-               link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-               link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
-
-               if (link->io.BasePort1 != 0) {
-                       i = pcmcia_request_io(handle, &link->io);
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
-       }
+       dev_dbg(&link->dev, "SYM53C500_config\n");
+
+       info->manf_id = link->manf_id;
+
+       ret = pcmcia_loop_config(link, SYM53C500_config_check, NULL);
+       if (ret)
+               goto failed;
+
+       if (!link->irq)
+               goto failed;
 
-       CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
+       ret = pcmcia_request_configuration(link, &link->conf);
+       if (ret)
+               goto failed;
 
        /*
        *  That's the trouble with copying liberally from another driver.
@@ -771,9 +733,9 @@ next_entry:
            (info->manf_id == MANFID_PIONEER) ||
            (info->manf_id == 0x0098)) {
                /* set ATAcmd */
-               outb(0xb4, link->io.BasePort1 + 0xd);
-               outb(0x24, link->io.BasePort1 + 0x9);
-               outb(0x04, link->io.BasePort1 + 0xd);
+               outb(0xb4, link->resource[0]->start + 0xd);
+               outb(0x24, link->resource[0]->start + 0x9);
+               outb(0x04, link->resource[0]->start + 0xd);
        }
 
        /*
@@ -786,8 +748,8 @@ next_entry:
        *       0x130, 0x230, 0x280, 0x290,
        *       0x320, 0x330, 0x340, 0x350
        */
-       port_base = link->io.BasePort1;
-       irq_level = link->irq.AssignedIRQ;
+       port_base = link->resource[0]->start;
+       irq_level = link->irq;
 
        DEB(printk("SYM53C500: port_base=0x%x, irq=%d, fast_pio=%d\n",
            port_base, irq_level, USE_FAST_PIO);)
@@ -803,7 +765,7 @@ next_entry:
        data = (struct sym53c500_data *)host->hostdata;
 
        if (irq_level > 0) {
-               if (request_irq(irq_level, SYM53C500_intr, SA_SHIRQ, "SYM53C500", host)) {
+               if (request_irq(irq_level, SYM53C500_intr, IRQF_SHARED, "SYM53C500", host)) {
                        printk("SYM53C500: unable to allocate IRQ %d\n", irq_level);
                        goto err_free_scsi;
                }
@@ -828,8 +790,6 @@ next_entry:
        */
        data->fast_pio = USE_FAST_PIO;
 
-       sprintf(info->node.dev_name, "scsi%d", host->host_no);
-       link->dev_node = &info->node;
        info->host = host;
 
        if (scsi_add_host(host, NULL))
@@ -837,7 +797,7 @@ next_entry:
 
        scsi_scan_host(host);
 
-       goto out;       /* SUCCESS */
+       return 0;
 
 err_free_irq:
        free_irq(irq_level, host);
@@ -846,83 +806,65 @@ err_free_scsi:
 err_release:
        release_region(port_base, 0x10);
        printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n");
+       return -ENODEV;
 
-out:
-       link->state &= ~DEV_CONFIG_PENDING;
-       return;
-
-cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
+failed:
        SYM53C500_release(link);
-       return;
+       return -ENODEV;
 } /* SYM53C500_config */
 
-static int sym53c500_resume(struct pcmcia_device *dev)
+static int sym53c500_resume(struct pcmcia_device *link)
 {
-       dev_link_t *link = dev_to_instance(dev);
        struct scsi_info_t *info = link->priv;
 
-       if (link->state & DEV_CONFIG) {
-               /* See earlier comment about manufacturer IDs. */
-               if ((info->manf_id == MANFID_MACNICA) ||
-                   (info->manf_id == MANFID_PIONEER) ||
-                   (info->manf_id == 0x0098)) {
-                       outb(0x80, link->io.BasePort1 + 0xd);
-                       outb(0x24, link->io.BasePort1 + 0x9);
-                       outb(0x04, link->io.BasePort1 + 0xd);
-               }
-               /*
-                *  If things don't work after a "resume",
-                *  this is a good place to start looking.
-                */
-               SYM53C500_int_host_reset(link->io.BasePort1);
+       /* See earlier comment about manufacturer IDs. */
+       if ((info->manf_id == MANFID_MACNICA) ||
+           (info->manf_id == MANFID_PIONEER) ||
+           (info->manf_id == 0x0098)) {
+               outb(0x80, link->resource[0]->start + 0xd);
+               outb(0x24, link->resource[0]->start + 0x9);
+               outb(0x04, link->resource[0]->start + 0xd);
        }
+       /*
+        *  If things don't work after a "resume",
+        *  this is a good place to start looking.
+        */
+       SYM53C500_int_host_reset(link->resource[0]->start);
 
        return 0;
 }
 
 static void
-SYM53C500_detach(struct pcmcia_device *p_dev)
+SYM53C500_detach(struct pcmcia_device *link)
 {
-       dev_link_t *link = dev_to_instance(p_dev);
+       dev_dbg(&link->dev, "SYM53C500_detach\n");
 
-       DEBUG(0, "SYM53C500_detach(0x%p)\n", link);
-
-       if (link->state & DEV_CONFIG)
-               SYM53C500_release(link);
+       SYM53C500_release(link);
 
        kfree(link->priv);
        link->priv = NULL;
 } /* SYM53C500_detach */
 
 static int
-SYM53C500_attach(struct pcmcia_device *p_dev)
+SYM53C500_probe(struct pcmcia_device *link)
 {
        struct scsi_info_t *info;
-       dev_link_t *link = dev_to_instance(p_dev);
 
-       DEBUG(0, "SYM53C500_attach()\n");
+       dev_dbg(&link->dev, "SYM53C500_attach()\n");
 
        /* Create new SCSI device */
-       info = kmalloc(sizeof(*info), GFP_KERNEL);
+       info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
                return -ENOMEM;
-       memset(info, 0, sizeof(*info));
-       info->p_dev = p_dev;
+       info->p_dev = link;
        link->priv = info;
        link->io.NumPorts1 = 16;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
        link->io.IOAddrLines = 10;
-       link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
-       link->irq.IRQInfo1 = IRQ_LEVEL_ID;
        link->conf.Attributes = CONF_ENABLE_IRQ;
        link->conf.IntType = INT_MEMORY_AND_IO;
-       link->conf.Present = PRESENT_OPTION;
 
-       link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-       SYM53C500_config(link);
-
-       return 0;
+       return SYM53C500_config(link);
 } /* SYM53C500_attach */
 
 MODULE_AUTHOR("Bob Tracy <rct@frus.com>");
@@ -942,7 +884,7 @@ static struct pcmcia_driver sym53c500_cs_driver = {
        .drv            = {
                .name   = "sym53c500_cs",
        },
-       .probe          = SYM53C500_attach,
+       .probe          = SYM53C500_probe,
        .remove         = SYM53C500_detach,
        .id_table       = sym53c500_ids,
        .resume         = sym53c500_resume,