V4L/DVB (8438): gspca: Lack of matrix for zc3xx - tas5130c (vf0250).
[safe/jmp/linux-2.6] / drivers / scsi / sd.c
index b044dcf..0c63947 100644 (file)
@@ -58,8 +58,8 @@
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_ioctl.h>
 #include <scsi/scsicam.h>
-#include <scsi/sd.h>
 
+#include "sd.h"
 #include "scsi_logging.h"
 
 MODULE_AUTHOR("Eric Youngdale");
@@ -82,6 +82,22 @@ MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK12_MAJOR);
 MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK13_MAJOR);
 MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK14_MAJOR);
 MODULE_ALIAS_BLOCKDEV_MAJOR(SCSI_DISK15_MAJOR);
+MODULE_ALIAS_SCSI_DEVICE(TYPE_DISK);
+MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD);
+MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
+
+static int  sd_revalidate_disk(struct gendisk *);
+static int  sd_probe(struct device *);
+static int  sd_remove(struct device *);
+static void sd_shutdown(struct device *);
+static int sd_suspend(struct device *, pm_message_t state);
+static int sd_resume(struct device *);
+static void sd_rescan(struct device *);
+static int sd_done(struct scsi_cmnd *);
+static void sd_read_capacity(struct scsi_disk *sdkp, unsigned char *buffer);
+static void scsi_disk_release(struct device *cdev);
+static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *);
+static void sd_print_result(struct scsi_disk *, int);
 
 static DEFINE_IDR(sd_index_idr);
 static DEFINE_SPINLOCK(sd_index_lock);
@@ -96,11 +112,12 @@ static const char *sd_cache_types[] = {
        "write back, no read (daft)"
 };
 
-static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
-                                  size_t count)
+static ssize_t
+sd_store_cache_type(struct device *dev, struct device_attribute *attr,
+                   const char *buf, size_t count)
 {
        int i, ct = -1, rcd, wce, sp;
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
        struct scsi_device *sdp = sdkp->device;
        char buffer[64];
        char *buffer_data;
@@ -147,10 +164,11 @@ static ssize_t sd_store_cache_type(struct class_device *cdev, const char *buf,
        return count;
 }
 
-static ssize_t sd_store_manage_start_stop(struct class_device *cdev,
-                                         const char *buf, size_t count)
+static ssize_t
+sd_store_manage_start_stop(struct device *dev, struct device_attribute *attr,
+                          const char *buf, size_t count)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
        struct scsi_device *sdp = sdkp->device;
 
        if (!capable(CAP_SYS_ADMIN))
@@ -161,10 +179,11 @@ static ssize_t sd_store_manage_start_stop(struct class_device *cdev,
        return count;
 }
 
-static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf,
-                                     size_t count)
+static ssize_t
+sd_store_allow_restart(struct device *dev, struct device_attribute *attr,
+                      const char *buf, size_t count)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
        struct scsi_device *sdp = sdkp->device;
 
        if (!capable(CAP_SYS_ADMIN))
@@ -178,37 +197,44 @@ static ssize_t sd_store_allow_restart(struct class_device *cdev, const char *buf
        return count;
 }
 
-static ssize_t sd_show_cache_type(struct class_device *cdev, char *buf)
+static ssize_t
+sd_show_cache_type(struct device *dev, struct device_attribute *attr,
+                  char *buf)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
        int ct = sdkp->RCD + 2*sdkp->WCE;
 
        return snprintf(buf, 40, "%s\n", sd_cache_types[ct]);
 }
 
-static ssize_t sd_show_fua(struct class_device *cdev, char *buf)
+static ssize_t
+sd_show_fua(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
 
        return snprintf(buf, 20, "%u\n", sdkp->DPOFUA);
 }
 
-static ssize_t sd_show_manage_start_stop(struct class_device *cdev, char *buf)
+static ssize_t
+sd_show_manage_start_stop(struct device *dev, struct device_attribute *attr,
+                         char *buf)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
        struct scsi_device *sdp = sdkp->device;
 
        return snprintf(buf, 20, "%u\n", sdp->manage_start_stop);
 }
 
-static ssize_t sd_show_allow_restart(struct class_device *cdev, char *buf)
+static ssize_t
+sd_show_allow_restart(struct device *dev, struct device_attribute *attr,
+                     char *buf)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
 
        return snprintf(buf, 40, "%d\n", sdkp->device->allow_restart);
 }
 
-static struct class_device_attribute sd_disk_attrs[] = {
+static struct device_attribute sd_disk_attrs[] = {
        __ATTR(cache_type, S_IRUGO|S_IWUSR, sd_show_cache_type,
               sd_store_cache_type),
        __ATTR(FUA, S_IRUGO, sd_show_fua, NULL),
@@ -222,8 +248,8 @@ static struct class_device_attribute sd_disk_attrs[] = {
 static struct class sd_disk_class = {
        .name           = "scsi_disk",
        .owner          = THIS_MODULE,
-       .release        = scsi_disk_release,
-       .class_dev_attrs = sd_disk_attrs,
+       .dev_release    = scsi_disk_release,
+       .dev_attrs      = sd_disk_attrs,
 };
 
 static struct scsi_driver sd_template = {
@@ -237,8 +263,7 @@ static struct scsi_driver sd_template = {
                .shutdown       = sd_shutdown,
        },
        .rescan                 = sd_rescan,
-       .init_command           = sd_init_command,
-       .issue_flush            = sd_issue_flush,
+       .done                   = sd_done,
 };
 
 /*
@@ -270,11 +295,6 @@ static int sd_major(int major_idx)
        }
 }
 
-static inline struct scsi_disk *scsi_disk(struct gendisk *disk)
-{
-       return container_of(disk->private_data, struct scsi_disk, driver);
-}
-
 static struct scsi_disk *__scsi_disk_get(struct gendisk *disk)
 {
        struct scsi_disk *sdkp = NULL;
@@ -282,7 +302,7 @@ static struct scsi_disk *__scsi_disk_get(struct gendisk *disk)
        if (disk->private_data) {
                sdkp = scsi_disk(disk);
                if (scsi_device_get(sdkp->device) == 0)
-                       class_device_get(&sdkp->cdev);
+                       get_device(&sdkp->dev);
                else
                        sdkp = NULL;
        }
@@ -316,7 +336,7 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
        struct scsi_device *sdev = sdkp->device;
 
        mutex_lock(&sd_ref_mutex);
-       class_device_put(&sdkp->cdev);
+       put_device(&sdkp->dev);
        scsi_device_put(sdev);
        mutex_unlock(&sd_ref_mutex);
 }
@@ -329,14 +349,31 @@ static void scsi_disk_put(struct scsi_disk *sdkp)
  *
  *     Returns 1 if successful and 0 if error (or cannot be done now).
  **/
-static int sd_init_command(struct scsi_cmnd * SCpnt)
+static int sd_prep_fn(struct request_queue *q, struct request *rq)
 {
-       struct scsi_device *sdp = SCpnt->device;
-       struct request *rq = SCpnt->request;
+       struct scsi_cmnd *SCpnt;
+       struct scsi_device *sdp = q->queuedata;
        struct gendisk *disk = rq->rq_disk;
        sector_t block = rq->sector;
-       unsigned int this_count = SCpnt->request_bufflen >> 9;
+       unsigned int this_count = rq->nr_sectors;
        unsigned int timeout = sdp->timeout;
+       int ret;
+
+       if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
+               ret = scsi_setup_blk_pc_cmnd(sdp, rq);
+               goto out;
+       } else if (rq->cmd_type != REQ_TYPE_FS) {
+               ret = BLKPREP_KILL;
+               goto out;
+       }
+       ret = scsi_setup_fs_cmnd(sdp, rq);
+       if (ret != BLKPREP_OK)
+               goto out;
+       SCpnt = rq->special;
+
+       /* from here on until we're complete, any goto out
+        * is used for a killable error condition */
+       ret = BLKPREP_KILL;
 
        SCSI_LOG_HLQUEUE(1, scmd_printk(KERN_INFO, SCpnt,
                                        "sd_init_command: block=%llu, "
@@ -351,7 +388,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                                                rq->nr_sectors));
                SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
                                                "Retry with 0x%p\n", SCpnt));
-               return 0;
+               goto out;
        }
 
        if (sdp->changed) {
@@ -360,8 +397,18 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                 * the changed bit has been reset
                 */
                /* printk("SCSI disk has been changed. Prohibiting further I/O.\n"); */
-               return 0;
+               goto out;
        }
+
+       /*
+        * Some devices (some sdcards for one) don't like it if the
+        * last sector gets read in a larger then 1 sector read.
+        */
+       if (unlikely(sdp->last_sector_bug &&
+           rq->nr_sectors > sdp->sector_size / 512 &&
+           block + this_count == get_capacity(disk)))
+               this_count -= sdp->sector_size / 512;
+
        SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt, "block=%llu\n",
                                        (unsigned long long)block));
 
@@ -380,7 +427,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                if ((block & 1) || (rq->nr_sectors & 1)) {
                        scmd_printk(KERN_ERR, SCpnt,
                                    "Bad block number requested\n");
-                       return 0;
+                       goto out;
                } else {
                        block = block >> 1;
                        this_count = this_count >> 1;
@@ -390,7 +437,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                if ((block & 3) || (rq->nr_sectors & 3)) {
                        scmd_printk(KERN_ERR, SCpnt,
                                    "Bad block number requested\n");
-                       return 0;
+                       goto out;
                } else {
                        block = block >> 2;
                        this_count = this_count >> 2;
@@ -400,7 +447,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                if ((block & 7) || (rq->nr_sectors & 7)) {
                        scmd_printk(KERN_ERR, SCpnt,
                                    "Bad block number requested\n");
-                       return 0;
+                       goto out;
                } else {
                        block = block >> 3;
                        this_count = this_count >> 3;
@@ -408,7 +455,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
        }
        if (rq_data_dir(rq) == WRITE) {
                if (!sdp->writeable) {
-                       return 0;
+                       goto out;
                }
                SCpnt->cmnd[0] = WRITE_6;
                SCpnt->sc_data_direction = DMA_TO_DEVICE;
@@ -417,7 +464,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                SCpnt->sc_data_direction = DMA_FROM_DEVICE;
        } else {
                scmd_printk(KERN_ERR, SCpnt, "Unknown command %x\n", rq->cmd_flags);
-               return 0;
+               goto out;
        }
 
        SCSI_LOG_HLQUEUE(2, scmd_printk(KERN_INFO, SCpnt,
@@ -468,7 +515,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                         */
                        scmd_printk(KERN_ERR, SCpnt,
                                    "FUA write on READ/WRITE(6) drive\n");
-                       return 0;
+                       goto out;
                }
 
                SCpnt->cmnd[1] |= (unsigned char) ((block >> 16) & 0x1f);
@@ -477,7 +524,7 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
                SCpnt->cmnd[4] = (unsigned char) this_count;
                SCpnt->cmnd[5] = 0;
        }
-       SCpnt->request_bufflen = this_count * sdp->sector_size;
+       SCpnt->sdb.length = this_count * sdp->sector_size;
 
        /*
         * We shouldn't disconnect in the middle of a sector, so with a dumb
@@ -490,16 +537,12 @@ static int sd_init_command(struct scsi_cmnd * SCpnt)
        SCpnt->timeout_per_command = timeout;
 
        /*
-        * This is the completion routine we use.  This is matched in terms
-        * of capability to this function.
-        */
-       SCpnt->done = sd_rw_intr;
-
-       /*
         * This indicates that the command is ready from our end to be
         * queued.
         */
-       return 1;
+       ret = BLKPREP_OK;
+ out:
+       return scsi_prep_return(q, rq, ret);
 }
 
 /**
@@ -647,7 +690,7 @@ static int sd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
  *     success as well). Returns a negated errno value in case of error.
  *
  *     Note: most ioctls are forward onto the block subsystem or further
- *     down in the scsi subsytem.
+ *     down in the scsi subsystem.
  **/
 static int sd_ioctl(struct inode * inode, struct file * filp, 
                    unsigned int cmd, unsigned long arg)
@@ -681,7 +724,7 @@ static int sd_ioctl(struct inode * inode, struct file * filp,
                case SCSI_IOCTL_GET_BUS_NUMBER:
                        return scsi_ioctl(sdp, cmd, p);
                default:
-                       error = scsi_cmd_ioctl(filp, disk, cmd, p);
+                       error = scsi_cmd_ioctl(filp, disk->queue, disk, cmd, p);
                        if (error != -ENOTTY)
                                return error;
        }
@@ -707,6 +750,7 @@ static int sd_media_changed(struct gendisk *disk)
 {
        struct scsi_disk *sdkp = scsi_disk(disk);
        struct scsi_device *sdp = sdkp->device;
+       struct scsi_sense_hdr *sshdr = NULL;
        int retval;
 
        SCSI_LOG_HLQUEUE(3, sd_printk(KERN_INFO, sdkp, "sd_media_changed\n"));
@@ -720,8 +764,11 @@ static int sd_media_changed(struct gendisk *disk)
         * can deal with it then.  It is only because of unrecoverable errors
         * that we would ever take a device offline in the first place.
         */
-       if (!scsi_device_online(sdp))
-               goto not_present;
+       if (!scsi_device_online(sdp)) {
+               set_media_not_present(sdkp);
+               retval = 1;
+               goto out;
+       }
 
        /*
         * Using TEST_UNIT_READY enables differentiation between drive with
@@ -733,8 +780,12 @@ static int sd_media_changed(struct gendisk *disk)
         * sd_revalidate() is called.
         */
        retval = -ENODEV;
-       if (scsi_block_when_processing_errors(sdp))
-               retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES);
+
+       if (scsi_block_when_processing_errors(sdp)) {
+               sshdr  = kzalloc(sizeof(*sshdr), GFP_KERNEL);
+               retval = scsi_test_unit_ready(sdp, SD_TIMEOUT, SD_MAX_RETRIES,
+                                             sshdr);
+       }
 
        /*
         * Unable to test, unit probably not ready.   This usually
@@ -742,8 +793,13 @@ static int sd_media_changed(struct gendisk *disk)
         * and we will figure it out later once the drive is
         * available again.
         */
-       if (retval)
-                goto not_present;
+       if (retval || (scsi_sense_valid(sshdr) &&
+                      /* 0x3a is medium not present */
+                      sshdr->asc == 0x3a)) {
+               set_media_not_present(sdkp);
+               retval = 1;
+               goto out;
+       }
 
        /*
         * For removable scsi disk we have to recognise the presence
@@ -754,12 +810,12 @@ static int sd_media_changed(struct gendisk *disk)
 
        retval = sdp->changed;
        sdp->changed = 0;
-
+out:
+       if (retval != sdkp->previous_state)
+               sdev_evt_send_simple(sdp, SDEV_EVT_MEDIA_CHANGE, GFP_KERNEL);
+       sdkp->previous_state = retval;
+       kfree(sshdr);
        return retval;
-
-not_present:
-       set_media_not_present(sdkp);
-       return 1;
 }
 
 static int sd_sync_cache(struct scsi_disk *sdkp)
@@ -797,23 +853,8 @@ static int sd_sync_cache(struct scsi_disk *sdkp)
        return 0;
 }
 
-static int sd_issue_flush(struct device *dev, sector_t *error_sector)
-{
-       int ret = 0;
-       struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
-
-       if (!sdkp)
-               return -ENODEV;
-
-       if (sdkp->WCE)
-               ret = sd_sync_cache(sdkp);
-       scsi_disk_put(sdkp);
-       return ret;
-}
-
-static void sd_prepare_flush(request_queue_t *q, struct request *rq)
+static void sd_prepare_flush(struct request_queue *q, struct request *rq)
 {
-       memset(rq->cmd, 0, sizeof(rq->cmd));
        rq->cmd_type = REQ_TYPE_BLOCK_PC;
        rq->timeout = SD_TIMEOUT;
        rq->cmd[0] = SYNCHRONIZE_CACHE;
@@ -880,18 +921,19 @@ static struct block_device_operations sd_fops = {
 };
 
 /**
- *     sd_rw_intr - bottom half handler: called when the lower level
+ *     sd_done - bottom half handler: called when the lower level
  *     driver has completed (successfully or otherwise) a scsi command.
  *     @SCpnt: mid-level's per command structure.
  *
  *     Note: potentially run from within an ISR. Must not block.
  **/
-static void sd_rw_intr(struct scsi_cmnd * SCpnt)
+static int sd_done(struct scsi_cmnd *SCpnt)
 {
        int result = SCpnt->result;
-       unsigned int xfer_size = SCpnt->request_bufflen;
+       unsigned int xfer_size = scsi_bufflen(SCpnt);
        unsigned int good_bytes = result ? 0 : xfer_size;
        u64 start_lba = SCpnt->request->sector;
+       u64 end_lba = SCpnt->request->sector + (xfer_size / 512);
        u64 bad_lba;
        struct scsi_sense_hdr sshdr;
        int sense_valid = 0;
@@ -907,7 +949,7 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt)
        SCSI_LOG_HLCOMPLETE(1, scsi_print_result(SCpnt));
        if (sense_valid) {
                SCSI_LOG_HLCOMPLETE(1, scmd_printk(KERN_INFO, SCpnt,
-                                                  "sd_rw_intr: sb[respc,sk,asc,"
+                                                  "sd_done: sb[respc,sk,asc,"
                                                   "ascq]=%x,%x,%x,%x\n",
                                                   sshdr.response_code,
                                                   sshdr.sense_key, sshdr.asc,
@@ -930,26 +972,23 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt)
                        goto out;
                if (xfer_size <= SCpnt->device->sector_size)
                        goto out;
-               switch (SCpnt->device->sector_size) {
-               case 256:
+               if (SCpnt->device->sector_size < 512) {
+                       /* only legitimate sector_size here is 256 */
                        start_lba <<= 1;
-                       break;
-               case 512:
-                       break;
-               case 1024:
-                       start_lba >>= 1;
-                       break;
-               case 2048:
-                       start_lba >>= 2;
-                       break;
-               case 4096:
-                       start_lba >>= 3;
-                       break;
-               default:
-                       /* Print something here with limiting frequency. */
-                       goto out;
-                       break;
+                       end_lba <<= 1;
+               } else {
+                       /* be careful ... don't want any overflows */
+                       u64 factor = SCpnt->device->sector_size / 512;
+                       do_div(start_lba, factor);
+                       do_div(end_lba, factor);
                }
+
+               if (bad_lba < start_lba  || bad_lba >= end_lba)
+                       /* the bad lba was reported incorrectly, we have
+                        * no idea where the error is
+                        */
+                       goto out;
+
                /* This computation should always be done in terms of
                 * the resolution of the device's medium.
                 */
@@ -979,7 +1018,7 @@ static void sd_rw_intr(struct scsi_cmnd * SCpnt)
                break;
        }
  out:
-       scsi_io_completion(SCpnt, good_bytes);
+       return good_bytes;
 }
 
 static int media_not_present(struct scsi_disk *sdkp,
@@ -1080,6 +1119,8 @@ sd_spinup_disk(struct scsi_disk *sdkp)
                                cmd[1] = 1;     /* Return immediately */
                                memset((void *) &cmd[2], 0, 8);
                                cmd[4] = 1;     /* Start spin cycle */
+                               if (sdkp->device->start_stop_pwr_cond)
+                                       cmd[4] |= 1 << 4;
                                scsi_execute_req(sdkp->device, cmd, DMA_NONE,
                                                 NULL, 0, &sshdr,
                                                 SD_TIMEOUT, SD_MAX_RETRIES);
@@ -1282,7 +1323,7 @@ got_data:
                 */
                int hard_sector = sector_size;
                sector_t sz = (sdkp->capacity/2) * (hard_sector/256);
-               request_queue_t *queue = sdp->request_queue;
+               struct request_queue *queue = sdp->request_queue;
                sector_t mb = sz;
 
                blk_queue_hardsect_size(queue, hard_sector);
@@ -1512,7 +1553,7 @@ static int sd_revalidate_disk(struct gendisk *disk)
        if (!scsi_device_online(sdp))
                goto out;
 
-       buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL | __GFP_DMA);
+       buffer = kmalloc(SD_BUF_SIZE, GFP_KERNEL);
        if (!buffer) {
                sd_printk(KERN_WARNING, sdkp, "sd_revalidate_disk: Memory "
                          "allocation failure.\n");
@@ -1619,6 +1660,7 @@ static int sd_probe(struct device *dev)
        sdkp->disk = gd;
        sdkp->index = index;
        sdkp->openers = 0;
+       sdkp->previous_state = 1;
 
        if (!sdp->timeout) {
                if (sdp->type != TYPE_MOD)
@@ -1627,12 +1669,12 @@ static int sd_probe(struct device *dev)
                        sdp->timeout = SD_MOD_TIMEOUT;
        }
 
-       class_device_initialize(&sdkp->cdev);
-       sdkp->cdev.dev = &sdp->sdev_gendev;
-       sdkp->cdev.class = &sd_disk_class;
-       strncpy(sdkp->cdev.class_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
+       device_initialize(&sdkp->dev);
+       sdkp->dev.parent = &sdp->sdev_gendev;
+       sdkp->dev.class = &sd_disk_class;
+       strncpy(sdkp->dev.bus_id, sdp->sdev_gendev.bus_id, BUS_ID_SIZE);
 
-       if (class_device_add(&sdkp->cdev))
+       if (device_add(&sdkp->dev))
                goto out_put;
 
        get_device(&sdp->sdev_gendev);
@@ -1660,6 +1702,8 @@ static int sd_probe(struct device *dev)
 
        sd_revalidate_disk(gd);
 
+       blk_queue_prep_rq(sdp->request_queue, sd_prep_fn);
+
        gd->driverfs_dev = &sdp->sdev_gendev;
        gd->flags = GENHD_FL_DRIVERFS;
        if (sdp->removable)
@@ -1696,13 +1740,13 @@ static int sd_remove(struct device *dev)
 {
        struct scsi_disk *sdkp = dev_get_drvdata(dev);
 
-       class_device_del(&sdkp->cdev);
+       device_del(&sdkp->dev);
        del_gendisk(sdkp->disk);
        sd_shutdown(dev);
 
        mutex_lock(&sd_ref_mutex);
        dev_set_drvdata(dev, NULL);
-       class_device_put(&sdkp->cdev);
+       put_device(&sdkp->dev);
        mutex_unlock(&sd_ref_mutex);
 
        return 0;
@@ -1710,16 +1754,16 @@ static int sd_remove(struct device *dev)
 
 /**
  *     scsi_disk_release - Called to free the scsi_disk structure
- *     @cdev: pointer to embedded class device
+ *     @dev: pointer to embedded class device
  *
  *     sd_ref_mutex must be held entering this routine.  Because it is
  *     called on last put, you should always use the scsi_disk_get()
  *     scsi_disk_put() helpers which manipulate the semaphore directly
- *     and never do a direct class_device_put().
+ *     and never do a direct put_device.
  **/
-static void scsi_disk_release(struct class_device *cdev)
+static void scsi_disk_release(struct device *dev)
 {
-       struct scsi_disk *sdkp = to_scsi_disk(cdev);
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
        struct gendisk *disk = sdkp->disk;
        
        spin_lock(&sd_index_lock);
@@ -1743,6 +1787,9 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start)
        if (start)
                cmd[4] |= 1;    /* START */
 
+       if (sdp->start_stop_pwr_cond)
+               cmd[4] |= start ? 1 << 4 : 3 << 4;      /* Active or Standby */
+
        if (!scsi_device_online(sdp))
                return -ENODEV;
 
@@ -1786,7 +1833,7 @@ static void sd_shutdown(struct device *dev)
 static int sd_suspend(struct device *dev, pm_message_t mesg)
 {
        struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
-       int ret;
+       int ret = 0;
 
        if (!sdkp)
                return 0;       /* this can happen */
@@ -1795,30 +1842,33 @@ static int sd_suspend(struct device *dev, pm_message_t mesg)
                sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n");
                ret = sd_sync_cache(sdkp);
                if (ret)
-                       return ret;
+                       goto done;
        }
 
-       if (mesg.event == PM_EVENT_SUSPEND &&
-           sdkp->device->manage_start_stop) {
+       if ((mesg.event & PM_EVENT_SLEEP) && sdkp->device->manage_start_stop) {
                sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
                ret = sd_start_stop_device(sdkp, 0);
-               if (ret)
-                       return ret;
        }
 
-       return 0;
+done:
+       scsi_disk_put(sdkp);
+       return ret;
 }
 
 static int sd_resume(struct device *dev)
 {
        struct scsi_disk *sdkp = scsi_disk_get_from_dev(dev);
+       int ret = 0;
 
        if (!sdkp->device->manage_start_stop)
-               return 0;
+               goto done;
 
        sd_printk(KERN_NOTICE, sdkp, "Starting disk\n");
+       ret = sd_start_stop_device(sdkp, 1);
 
-       return sd_start_stop_device(sdkp, 1);
+done:
+       scsi_disk_put(sdkp);
+       return ret;
 }
 
 /**