some kmalloc/memset ->kzalloc (tree wide)
[linux-2.6.git] / drivers / scsi / pcmcia / qlogic_stub.c
index 0dcf411..67c5a58 100644 (file)
@@ -34,7 +34,6 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/ioport.h>
@@ -49,7 +48,6 @@
 #include <scsi/scsi_host.h>
 #include "../qlogicfas408.h"
 
-#include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
 #include <pcmcia/cistpl.h>
@@ -73,7 +71,7 @@ static char *version = "qlogic_cs.c 1.79-ac 2002/10/26 (David Hinds)";
 #define DEBUG(n, args...)
 #endif
 
-static Scsi_Host_Template qlogicfas_driver_template = {
+static struct scsi_host_template qlogicfas_driver_template = {
        .module                 = THIS_MODULE,
        .name                   = qlogic_name,
        .proc_name              = qlogic_name,
@@ -92,25 +90,18 @@ static Scsi_Host_Template qlogicfas_driver_template = {
 /*====================================================================*/
 
 typedef struct scsi_info_t {
-       dev_link_t link;
+       struct pcmcia_device    *p_dev;
        dev_node_t node;
        struct Scsi_Host *host;
        unsigned short manf_id;
 } scsi_info_t;
 
-static void qlogic_release(dev_link_t *link);
-static int qlogic_event(event_t event, int priority, event_callback_args_t * args);
+static void qlogic_release(struct pcmcia_device *link);
+static void qlogic_detach(struct pcmcia_device *p_dev);
+static int qlogic_config(struct pcmcia_device * link);
 
-static dev_link_t *qlogic_attach(void);
-static void qlogic_detach(dev_link_t *);
-
-
-static dev_link_t *dev_list = NULL;
-
-static dev_info_t dev_info = "qlogic_cs";
-
-static struct Scsi_Host *qlogic_detect(Scsi_Host_Template *host,
-                               dev_link_t *link, int qbase, int qlirq)
+static struct Scsi_Host *qlogic_detect(struct scsi_host_template *host,
+                               struct pcmcia_device *link, int qbase, int qlirq)
 {
        int qltyp;              /* type of chip */
        int qinitid;
@@ -164,21 +155,17 @@ free_scsi_host:
 err:
        return NULL;
 }
-static dev_link_t *qlogic_attach(void)
+static int qlogic_probe(struct pcmcia_device *link)
 {
        scsi_info_t *info;
-       client_reg_t client_reg;
-       dev_link_t *link;
-       int ret;
 
        DEBUG(0, "qlogic_attach()\n");
 
        /* Create new SCSI device */
-       info = kmalloc(sizeof(*info), GFP_KERNEL);
+       info = kzalloc(sizeof(*info), GFP_KERNEL);
        if (!info)
-               return NULL;
-       memset(info, 0, sizeof(*info));
-       link = &info->link;
+               return -ENOMEM;
+       info->p_dev = link;
        link->priv = info;
        link->io.NumPorts1 = 16;
        link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
@@ -186,51 +173,19 @@ static dev_link_t *qlogic_attach(void)
        link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
        link->irq.IRQInfo1 = IRQ_LEVEL_ID;
        link->conf.Attributes = CONF_ENABLE_IRQ;
-       link->conf.Vcc = 50;
        link->conf.IntType = INT_MEMORY_AND_IO;
        link->conf.Present = PRESENT_OPTION;
 
-       /* Register with Card Services */
-       link->next = dev_list;
-       dev_list = link;
-       client_reg.dev_info = &dev_info;
-       client_reg.event_handler = &qlogic_event;
-       client_reg.EventMask = CS_EVENT_RESET_REQUEST | CS_EVENT_CARD_RESET | CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
-       client_reg.Version = 0x0210;
-       client_reg.event_callback_args.client_data = link;
-       ret = pcmcia_register_client(&link->handle, &client_reg);
-       if (ret != 0) {
-               cs_error(link->handle, RegisterClient, ret);
-               qlogic_detach(link);
-               return NULL;
-       }
-
-       return link;
+       return qlogic_config(link);
 }                              /* qlogic_attach */
 
 /*====================================================================*/
 
-static void qlogic_detach(dev_link_t * link)
+static void qlogic_detach(struct pcmcia_device *link)
 {
-       dev_link_t **linkp;
-
        DEBUG(0, "qlogic_detach(0x%p)\n", link);
 
-       /* Locate device structure */
-       for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
-               if (*linkp == link)
-                       break;
-       if (*linkp == NULL)
-               return;
-
-       if (link->state & DEV_CONFIG)
-               qlogic_release(link);
-
-       if (link->handle)
-               pcmcia_deregister_client(link->handle);
-
-       /* Unlink device structure, free bits */
-       *linkp = link->next;
+       qlogic_release(link);
        kfree(link->priv);
 
 }                              /* qlogic_detach */
@@ -240,9 +195,8 @@ static void qlogic_detach(dev_link_t * link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
-static void qlogic_config(dev_link_t * link)
+static int qlogic_config(struct pcmcia_device * link)
 {
-       client_handle_t handle = link->handle;
        scsi_info_t *info = link->priv;
        tuple_t tuple;
        cisparse_t parse;
@@ -252,42 +206,32 @@ static void qlogic_config(dev_link_t * link)
 
        DEBUG(0, "qlogic_config(0x%p)\n", link);
 
+       info->manf_id = link->manf_id;
+
        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));
+       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
        while (1) {
-               if (pcmcia_get_tuple_data(handle, &tuple) != 0 ||
-                               pcmcia_parse_tuple(handle, &tuple, &parse) != 0)
+               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(handle, &link->io);
+                       i = pcmcia_request_io(link, &link->io);
                        if (i == CS_SUCCESS)
                                break;
                }
              next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple));
+               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
        }
 
-       CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq));
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf));
+       CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
+       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
 
        if ((info->manf_id == MANFID_MACNICA) || (info->manf_id == MANFID_PIONEER) || (info->manf_id == 0x0098)) {
                /* set ATAcmd */
@@ -306,94 +250,57 @@ static void qlogic_config(dev_link_t * link)
        
        if (!host) {
                printk(KERN_INFO "%s: no SCSI devices found\n", qlogic_name);
-               goto out;
+               goto cs_failed;
        }
 
        sprintf(info->node.dev_name, "scsi%d", host->host_no);
-       link->dev = &info->node;
+       link->dev_node = &info->node;
        info->host = host;
 
-out:
-       link->state &= ~DEV_CONFIG_PENDING;
-       return;
+       return 0;
 
 cs_failed:
-       cs_error(link->handle, last_fn, last_ret);
-       link->dev = NULL;
-       pcmcia_release_configuration(link->handle);
-       pcmcia_release_io(link->handle, &link->io);
-       pcmcia_release_irq(link->handle, &link->irq);
-       link->state &= ~DEV_CONFIG;
-       return;
+       cs_error(link, last_fn, last_ret);
+       pcmcia_disable_device(link);
+       return -ENODEV;
 
 }                              /* qlogic_config */
 
 /*====================================================================*/
 
-static void qlogic_release(dev_link_t *link)
+static void qlogic_release(struct pcmcia_device *link)
 {
        scsi_info_t *info = link->priv;
 
        DEBUG(0, "qlogic_release(0x%p)\n", link);
 
        scsi_remove_host(info->host);
-       link->dev = NULL;
 
        free_irq(link->irq.AssignedIRQ, info->host);
-
-       pcmcia_release_configuration(link->handle);
-       pcmcia_release_io(link->handle, &link->io);
-       pcmcia_release_irq(link->handle, &link->irq);
+       pcmcia_disable_device(link);
 
        scsi_host_put(info->host);
-
-       link->state &= ~DEV_CONFIG;
 }
 
 /*====================================================================*/
 
-static int qlogic_event(event_t event, int priority, event_callback_args_t * args)
+static int qlogic_resume(struct pcmcia_device *link)
 {
-       dev_link_t *link = args->client_data;
-
-       DEBUG(1, "qlogic_event(0x%06x)\n", event);
-
-       switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG)
-                       qlogic_release(link);
-               break;
-       case CS_EVENT_CARD_INSERTION:
-               link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
-               qlogic_config(link);
-               break;
-       case CS_EVENT_PM_SUSPEND:
-               link->state |= DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               if (link->state & DEV_CONFIG)
-                       pcmcia_release_configuration(link->handle);
-               break;
-       case CS_EVENT_PM_RESUME:
-               link->state &= ~DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               if (link->state & DEV_CONFIG) {
-                       scsi_info_t *info = link->priv;
-                       pcmcia_request_configuration(link->handle, &link->conf);
-                       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);
-                       }
-                       /* Ugggglllyyyy!!! */
-                       qlogicfas408_bus_reset(NULL);
-               }
-               break;
+       scsi_info_t *info = link->priv;
+
+       pcmcia_request_configuration(link, &link->conf);
+       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);
        }
+       /* Ugggglllyyyy!!! */
+       qlogicfas408_bus_reset(NULL);
+
        return 0;
-}                              /* qlogic_event */
+}
 
 static struct pcmcia_device_id qlogic_ids[] = {
        PCMCIA_DEVICE_PROD_ID12("EIger Labs", "PCMCIA-to-SCSI Adapter", 0x88395fa7, 0x33b7a5e6),
@@ -422,9 +329,10 @@ static struct pcmcia_driver qlogic_cs_driver = {
        .drv            = {
        .name           = "qlogic_cs",
        },
-       .attach         = qlogic_attach,
-       .detach         = qlogic_detach,
+       .probe          = qlogic_probe,
+       .remove         = qlogic_detach,
        .id_table       = qlogic_ids,
+       .resume         = qlogic_resume,
 };
 
 static int __init init_qlogic_cs(void)
@@ -435,7 +343,6 @@ static int __init init_qlogic_cs(void)
 static void __exit exit_qlogic_cs(void)
 {
        pcmcia_unregister_driver(&qlogic_cs_driver);
-       BUG_ON(dev_list != NULL);
 }
 
 MODULE_AUTHOR("Tom Zerucha, Michael Griffith");