[PATCH] pcmcia: remove dev_list from drivers
[safe/jmp/linux-2.6] / drivers / scsi / pcmcia / nsp_cs.c
index 3d2f710..e48e9fb 100644 (file)
@@ -81,7 +81,7 @@ module_param(free_ports, bool, 0);
 MODULE_PARM_DESC(free_ports, "Release IO ports after configuration? (default: 0 (=no))");
 
 /* /usr/src/linux/drivers/scsi/hosts.h */
-static Scsi_Host_Template nsp_driver_template = {
+static struct scsi_host_template nsp_driver_template = {
        .proc_name               = "nsp_cs",
        .proc_info               = nsp_proc_info,
        .name                    = "WorkBit NinjaSCSI-3/32Bi(16bit)",
@@ -104,7 +104,6 @@ static Scsi_Host_Template nsp_driver_template = {
 #endif
 };
 
-static dev_link_t *dev_list = NULL;
 static dev_info_t dev_info  = {"nsp_cs"};
 
 static nsp_hw_data nsp_data_base; /* attach <-> detect glue */
@@ -1310,7 +1309,7 @@ timer_out:
 /*----------------------------------------------------------------*/
 /* look for ninja3 card and init if found                        */
 /*----------------------------------------------------------------*/
-static struct Scsi_Host *nsp_detect(Scsi_Host_Template *sht)
+static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht)
 {
        struct Scsi_Host *host; /* registered host structure */
        nsp_hw_data *data_b = &nsp_data_base, *data;
@@ -1358,7 +1357,7 @@ static struct Scsi_Host *nsp_detect(Scsi_Host_Template *sht)
 }
 
 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-static int nsp_detect_old(Scsi_Host_Template *sht)
+static int nsp_detect_old(struct scsi_host_template *sht)
 {
        if (nsp_detect(sht) == NULL) {
                return 0;
@@ -1638,15 +1637,14 @@ static dev_link_t *nsp_cs_attach(void)
 
 
        /* Register with Card Services */
-       link->next               = dev_list;
-       dev_list                 = link;
+       link->next               = NULL;
        client_reg.dev_info      = &dev_info;
        client_reg.Version       = 0x0210;
        client_reg.event_callback_args.client_data = link;
        ret = pcmcia_register_client(&link->handle, &client_reg);
        if (ret != CS_SUCCESS) {
                cs_error(link->handle, RegisterClient, ret);
-               nsp_cs_detach(link);
+               nsp_cs_detach(link->handle);
                return NULL;
        }
 
@@ -1662,35 +1660,19 @@ static dev_link_t *nsp_cs_attach(void)
     structures are freed.  Otherwise, the structures will be freed
     when the device is released.
 ======================================================================*/
-static void nsp_cs_detach(dev_link_t *link)
+static void nsp_cs_detach(struct pcmcia_device *p_dev)
 {
-       dev_link_t **linkp;
+       dev_link_t *link = dev_to_instance(p_dev);
 
        nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", 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)
+       if (link->state & DEV_CONFIG) {
+               ((scsi_info_t *)link->priv)->stop = 1;
                nsp_cs_release(link);
-
-       /* Break the link with Card Services */
-       if (link->handle) {
-               pcmcia_deregister_client(link->handle);
        }
 
-       /* Unlink device structure, free bits */
-       *linkp = link->next;
        kfree(link->priv);
        link->priv = NULL;
-
 } /* nsp_cs_detach */
 
 
@@ -1717,7 +1699,7 @@ static void nsp_cs_config(dev_link_t *link)
        struct Scsi_Host *host;
        nsp_hw_data      *data = &nsp_data_base;
 #if !(LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
-       Scsi_Device      *dev;
+       struct scsi_device       *dev;
        dev_node_t      **tail, *node;
 #endif
 
@@ -2021,6 +2003,59 @@ static void nsp_cs_release(dev_link_t *link)
 #endif
 } /* nsp_cs_release */
 
+static int nsp_cs_suspend(struct pcmcia_device *dev)
+{
+       dev_link_t *link = dev_to_instance(dev);
+       scsi_info_t *info = link->priv;
+       nsp_hw_data *data;
+
+       link->state |= DEV_SUSPEND;
+
+       nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
+
+       if (info->host != NULL) {
+               nsp_msg(KERN_INFO, "clear SDTR status");
+
+               data = (nsp_hw_data *)info->host->hostdata;
+
+               nsphw_init_sync(data);
+       }
+
+       info->stop = 1;
+
+       if (link->state & DEV_CONFIG)
+               pcmcia_release_configuration(link->handle);
+
+       return 0;
+}
+
+static int nsp_cs_resume(struct pcmcia_device *dev)
+{
+       dev_link_t *link = dev_to_instance(dev);
+       scsi_info_t *info = link->priv;
+       nsp_hw_data *data;
+
+       nsp_dbg(NSP_DEBUG_INIT, "event: resume");
+
+       link->state &= ~DEV_SUSPEND;
+
+       if (link->state & DEV_CONFIG)
+               pcmcia_request_configuration(link->handle, &link->conf);
+
+       info->stop = 0;
+
+       if (info->host != NULL) {
+               nsp_msg(KERN_INFO, "reset host and bus");
+
+               data = (nsp_hw_data *)info->host->hostdata;
+
+               nsphw_init   (data);
+               nsp_bus_reset(data);
+       }
+
+       return 0;
+}
+
 /*======================================================================
 
     The card status event handler.  Mostly, this schedules other
@@ -2039,21 +2074,10 @@ static int nsp_cs_event(event_t                event,
                        event_callback_args_t *args)
 {
        dev_link_t  *link = args->client_data;
-       scsi_info_t *info = link->priv;
-       nsp_hw_data *data;
 
        nsp_dbg(NSP_DEBUG_INIT, "in, event=0x%08x", event);
 
        switch (event) {
-       case CS_EVENT_CARD_REMOVAL:
-               nsp_dbg(NSP_DEBUG_INIT, "event: remove");
-               link->state &= ~DEV_PRESENT;
-               if (link->state & DEV_CONFIG) {
-                       ((scsi_info_t *)link->priv)->stop = 1;
-                       nsp_cs_release(link);
-               }
-               break;
-
        case CS_EVENT_CARD_INSERTION:
                nsp_dbg(NSP_DEBUG_INIT, "event: insert");
                link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
@@ -2062,51 +2086,6 @@ static int nsp_cs_event(event_t                 event,
 #endif
                nsp_cs_config(link);
                break;
-
-       case CS_EVENT_PM_SUSPEND:
-               nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
-               link->state |= DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_RESET_PHYSICAL:
-               /* Mark the device as stopped, to block IO until later */
-               nsp_dbg(NSP_DEBUG_INIT, "event: reset physical");
-
-               if (info->host != NULL) {
-                       nsp_msg(KERN_INFO, "clear SDTR status");
-
-                       data = (nsp_hw_data *)info->host->hostdata;
-
-                       nsphw_init_sync(data);
-               }
-
-               info->stop = 1;
-               if (link->state & DEV_CONFIG) {
-                       pcmcia_release_configuration(link->handle);
-               }
-               break;
-
-       case CS_EVENT_PM_RESUME:
-               nsp_dbg(NSP_DEBUG_INIT, "event: resume");
-               link->state &= ~DEV_SUSPEND;
-               /* Fall through... */
-       case CS_EVENT_CARD_RESET:
-               nsp_dbg(NSP_DEBUG_INIT, "event: reset");
-               if (link->state & DEV_CONFIG) {
-                       pcmcia_request_configuration(link->handle, &link->conf);
-               }
-               info->stop = 0;
-
-               if (info->host != NULL) {
-                       nsp_msg(KERN_INFO, "reset host and bus");
-
-                       data = (nsp_hw_data *)info->host->hostdata;
-
-                       nsphw_init   (data);
-                       nsp_bus_reset(data);
-               }
-
-               break;
-
        default:
                nsp_dbg(NSP_DEBUG_INIT, "event: unknown");
                break;
@@ -2138,8 +2117,10 @@ static struct pcmcia_driver nsp_driver = {
        },
        .attach         = nsp_cs_attach,
        .event          = nsp_cs_event,
-       .detach         = nsp_cs_detach,
+       .remove         = nsp_cs_detach,
        .id_table       = nsp_cs_ids,
+       .suspend        = nsp_cs_suspend,
+       .resume         = nsp_cs_resume,
 };
 #endif
 
@@ -2171,7 +2152,6 @@ static void __exit nsp_cs_exit(void)
 
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,68))
        pcmcia_unregister_driver(&nsp_driver);
-       BUG_ON(dev_list != NULL);
 #else
        unregister_pcmcia_driver(&dev_info);
        /* XXX: this really needs to move into generic code.. */