pcmcia: do not use io_req_t after call to pcmcia_request_io()
[linux-2.6.git] / drivers / scsi / pcmcia / sym53c500_cs.c
index 190e2a7..d99c0cb 100644 (file)
 #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
 
 /* ================================================================== */
 
@@ -202,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;
 };
@@ -443,8 +430,7 @@ SYM53C500_intr(int irq, void *dev_id)
 
                        scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
                                SYM53C500_pio_write(fast_pio, port_base,
-                                                   page_address(sg->page) + sg->offset,
-                                                   sg->length);
+                                   sg_virt(sg), sg->length);
                        }
                        REG0(port_base);
                }
@@ -463,8 +449,7 @@ SYM53C500_intr(int irq, void *dev_id)
 
                        scsi_for_each_sg(curSC, sg, scsi_sg_count(curSC), i) {
                                SYM53C500_pio_read(fast_pio, port_base,
-                                                  page_address(sg->page) + sg->offset,
-                                                  sg->length);
+                                       sg_virt(sg), sg->length);
                        }
                        REG0(port_base);
                }
@@ -527,7 +512,7 @@ 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.
@@ -634,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;
 
@@ -644,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;
 
@@ -664,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),
@@ -673,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,
 };
@@ -694,55 +681,48 @@ static struct scsi_host_template sym53c500_driver_template = {
      .sg_tablesize             = 32,
      .cmd_per_lun              = 1,
      .use_clustering           = ENABLE_CLUSTERING,
-     .use_sg_chaining          = ENABLE_SG_CHAINING,
      .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;
+
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
 
 static int
 SYM53C500_config(struct pcmcia_device *link)
 {
        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);
+       dev_dbg(&link->dev, "SYM53C500_config\n");
 
        info->manf_id = link->manf_id;
 
-       tuple.TupleData = (cisdata_t *)tuple_data;
-       tuple.TupleDataMax = 64;
-       tuple.TupleOffset = 0;
-
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                   pcmcia_parse_tuple(link, &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(link, &link->io);
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       }
+       ret = pcmcia_loop_config(link, SYM53C500_config_check, NULL);
+       if (ret)
+               goto failed;
+
+       if (!link->irq)
+               goto failed;
 
-       CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
+       ret = pcmcia_request_configuration(link, &link->conf);
+       if (ret)
+               goto failed;
 
        /*
        *  That's the trouble with copying liberally from another driver.
@@ -753,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);
        }
 
        /*
@@ -768,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);)
@@ -810,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))
@@ -830,8 +808,7 @@ err_release:
        printk(KERN_INFO "sym53c500_cs: no SCSI devices found\n");
        return -ENODEV;
 
-cs_failed:
-       cs_error(link, last_fn, last_ret);
+failed:
        SYM53C500_release(link);
        return -ENODEV;
 } /* SYM53C500_config */
@@ -844,15 +821,15 @@ static int sym53c500_resume(struct pcmcia_device *link)
        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);
+               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->io.BasePort1);
+       SYM53C500_int_host_reset(link->resource[0]->start);
 
        return 0;
 }
@@ -860,7 +837,7 @@ static int sym53c500_resume(struct pcmcia_device *link)
 static void
 SYM53C500_detach(struct pcmcia_device *link)
 {
-       DEBUG(0, "SYM53C500_detach(0x%p)\n", link);
+       dev_dbg(&link->dev, "SYM53C500_detach\n");
 
        SYM53C500_release(link);
 
@@ -873,7 +850,7 @@ SYM53C500_probe(struct pcmcia_device *link)
 {
        struct scsi_info_t *info;
 
-       DEBUG(0, "SYM53C500_attach()\n");
+       dev_dbg(&link->dev, "SYM53C500_attach()\n");
 
        /* Create new SCSI device */
        info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -884,8 +861,6 @@ SYM53C500_probe(struct pcmcia_device *link)
        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;