upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / drivers / scsi / ide-scsi.c
index 5f07bbf..d30b99b 100644 (file)
 #include <linux/hdreg.h>
 #include <linux/slab.h>
 #include <linux/ide.h>
+#include <linux/scatterlist.h>
 
 #include <asm/io.h>
 #include <asm/bitops.h>
 #include <asm/uaccess.h>
 
-#include "scsi.h"
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
 #include <scsi/scsi_host.h>
+#include <scsi/scsi_tcq.h>
 #include <scsi/sg.h>
 
 #define IDESCSI_DEBUG_LOG              0
@@ -66,8 +70,8 @@ typedef struct idescsi_pc_s {
        u8 *current_position;                   /* Pointer into the above buffer */
        struct scatterlist *sg;                 /* Scatter gather table */
        int b_count;                            /* Bytes transferred from current entry */
-       Scsi_Cmnd *scsi_cmd;                    /* SCSI command */
-       void (*done)(Scsi_Cmnd *);              /* Scsi completion routine */
+       struct scsi_cmnd *scsi_cmd;             /* SCSI command */
+       void (*done)(struct scsi_cmnd *);       /* Scsi completion routine */
        unsigned long flags;                    /* Status/Action flags */
        unsigned long timeout;                  /* Command timeout */
 } idescsi_pc_t;
@@ -250,17 +254,6 @@ static inline void idescsi_transform_pc2 (ide_drive_t *drive, idescsi_pc_t *pc)
                kfree(atapi_buf);
 }
 
-static inline void idescsi_free_bio (struct bio *bio)
-{
-       struct bio *bhp;
-
-       while (bio) {
-               bhp = bio;
-               bio = bio->bi_next;
-               bio_put(bhp);
-       }
-}
-
 static void hexdump(u8 *x, int len)
 {
        int i;
@@ -418,7 +411,6 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
        spin_lock_irqsave(host->host_lock, flags);
        pc->done(pc->scsi_cmd);
        spin_unlock_irqrestore(host->host_lock, flags);
-       idescsi_free_bio(rq->bio);
        kfree(pc);
        kfree(rq);
        scsi->pc = NULL;
@@ -552,6 +544,7 @@ static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
 
 static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
 {
+       ide_hwif_t *hwif = drive->hwif;
        idescsi_scsi_t *scsi = drive_to_idescsi(drive);
        idescsi_pc_t *pc = scsi->pc;
        atapi_ireason_t ireason;
@@ -576,20 +569,64 @@ static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
        atapi_output_bytes(drive, scsi->pc->c, 12);
        if (test_bit (PC_DMA_OK, &pc->flags)) {
                set_bit (PC_DMA_IN_PROGRESS, &pc->flags);
-               (void) (HWIF(drive)->ide_dma_begin(drive));
+               hwif->ide_dma_start(drive);
        }
        return ide_started;
 }
 
+static inline int idescsi_set_direction(idescsi_pc_t *pc)
+{
+       switch (pc->c[0]) {
+               case READ_6: case READ_10: case READ_12:
+                       clear_bit(PC_WRITING, &pc->flags);
+                       return 0;
+               case WRITE_6: case WRITE_10: case WRITE_12:
+                       set_bit(PC_WRITING, &pc->flags);
+                       return 0;
+               default:
+                       return 1;
+       }
+}
+
+static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       struct scatterlist *sg, *scsi_sg;
+       int segments;
+
+       if (!pc->request_transfer || pc->request_transfer % 1024)
+               return 1;
+
+       if (idescsi_set_direction(pc))
+               return 1;
+
+       sg = hwif->sg_table;
+       scsi_sg = pc->scsi_cmd->request_buffer;
+       segments = pc->scsi_cmd->use_sg;
+
+       if (segments > hwif->sg_max_nents)
+               return 1;
+
+       if (!segments) {
+               hwif->sg_nents = 1;
+               sg_init_one(sg, pc->scsi_cmd->request_buffer, pc->request_transfer);
+       } else {
+               hwif->sg_nents = segments;
+               memcpy(sg, scsi_sg, sizeof(*sg) * segments);
+       }
+
+       return 0;
+}
+
 /*
  *     Issue a packet command
  */
 static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
 {
        idescsi_scsi_t *scsi = drive_to_idescsi(drive);
+       ide_hwif_t *hwif = drive->hwif;
        atapi_feature_t feature;
        atapi_bcount_t bcount;
-       struct request *rq = pc->rq;
 
        scsi->pc=pc;                                                    /* Set the current packet command */
        pc->actually_transferred=0;                                     /* We haven't transferred any data yet */
@@ -597,11 +634,10 @@ static ide_startstop_t idescsi_issue_pc (ide_drive_t *drive, idescsi_pc_t *pc)
        bcount.all = min(pc->request_transfer, 63 * 1024);              /* Request to transfer the entire buffer at once */
 
        feature.all = 0;
-       if (drive->using_dma && rq->bio) {
-               if (test_bit(PC_WRITING, &pc->flags))
-                       feature.b.dma = !HWIF(drive)->ide_dma_write(drive);
-               else
-                       feature.b.dma = !HWIF(drive)->ide_dma_read(drive);
+       if (drive->using_dma && !idescsi_map_sg(drive, pc)) {
+               hwif->sg_mapped = 1;
+               feature.b.dma = !hwif->ide_dma_setup(drive);
+               hwif->sg_mapped = 0;
        }
 
        SELECT_DRIVE(drive);
@@ -753,7 +789,7 @@ static struct block_device_operations idescsi_ops = {
 
 static int idescsi_attach(ide_drive_t *drive);
 
-static int idescsi_slave_configure(Scsi_Device * sdp)
+static int idescsi_slave_configure(struct scsi_device * sdp)
 {
        /* Configure detected device */
        scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, sdp->host->cmd_per_lun);
@@ -765,7 +801,7 @@ static const char *idescsi_info (struct Scsi_Host *host)
        return "SCSI host adapter emulation for IDE ATAPI devices";
 }
 
-static int idescsi_ioctl (Scsi_Device *dev, int cmd, void __user *arg)
+static int idescsi_ioctl (struct scsi_device *dev, int cmd, void __user *arg)
 {
        idescsi_scsi_t *scsi = scsihost_to_idescsi(dev->host);
 
@@ -780,82 +816,7 @@ static int idescsi_ioctl (Scsi_Device *dev, int cmd, void __user *arg)
        return -EINVAL;
 }
 
-static inline struct bio *idescsi_kmalloc_bio (int count)
-{
-       struct bio *bh, *bhp, *first_bh;
-
-       if ((first_bh = bhp = bh = bio_alloc(GFP_ATOMIC, 1)) == NULL)
-               goto abort;
-       bio_init(bh);
-       bh->bi_vcnt = 1;
-       while (--count) {
-               if ((bh = bio_alloc(GFP_ATOMIC, 1)) == NULL)
-                       goto abort;
-               bio_init(bh);
-               bh->bi_vcnt = 1;
-               bhp->bi_next = bh;
-               bhp = bh;
-               bh->bi_next = NULL;
-       }
-       return first_bh;
-abort:
-       idescsi_free_bio (first_bh);
-       return NULL;
-}
-
-static inline int idescsi_set_direction (idescsi_pc_t *pc)
-{
-       switch (pc->c[0]) {
-               case READ_6: case READ_10: case READ_12:
-                       clear_bit (PC_WRITING, &pc->flags);
-                       return 0;
-               case WRITE_6: case WRITE_10: case WRITE_12:
-                       set_bit (PC_WRITING, &pc->flags);
-                       return 0;
-               default:
-                       return 1;
-       }
-}
-
-static inline struct bio *idescsi_dma_bio(ide_drive_t *drive, idescsi_pc_t *pc)
-{
-       struct bio *bh = NULL, *first_bh = NULL;
-       int segments = pc->scsi_cmd->use_sg;
-       struct scatterlist *sg = pc->scsi_cmd->request_buffer;
-
-       if (!drive->using_dma || !pc->request_transfer || pc->request_transfer % 1024)
-               return NULL;
-       if (idescsi_set_direction(pc))
-               return NULL;
-       if (segments) {
-               if ((first_bh = bh = idescsi_kmalloc_bio (segments)) == NULL)
-                       return NULL;
-#if IDESCSI_DEBUG_LOG
-               printk ("ide-scsi: %s: building DMA table, %d segments, %dkB total\n", drive->name, segments, pc->request_transfer >> 10);
-#endif /* IDESCSI_DEBUG_LOG */
-               while (segments--) {
-                       bh->bi_io_vec[0].bv_page = sg->page;
-                       bh->bi_io_vec[0].bv_len = sg->length;
-                       bh->bi_io_vec[0].bv_offset = sg->offset;
-                       bh->bi_size = sg->length;
-                       bh = bh->bi_next;
-                       sg++;
-               }
-       } else {
-               if ((first_bh = bh = idescsi_kmalloc_bio (1)) == NULL)
-                       return NULL;
-#if IDESCSI_DEBUG_LOG
-               printk ("ide-scsi: %s: building DMA table for a single buffer (%dkB)\n", drive->name, pc->request_transfer >> 10);
-#endif /* IDESCSI_DEBUG_LOG */
-               bh->bi_io_vec[0].bv_page = virt_to_page(pc->scsi_cmd->request_buffer);
-               bh->bi_io_vec[0].bv_offset = offset_in_page(pc->scsi_cmd->request_buffer);
-               bh->bi_io_vec[0].bv_len = pc->request_transfer;
-               bh->bi_size = pc->request_transfer;
-       }
-       return first_bh;
-}
-
-static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd)
+static inline int should_transform(ide_drive_t *drive, struct scsi_cmnd *cmd)
 {
        idescsi_scsi_t *scsi = drive_to_idescsi(drive);
 
@@ -873,7 +834,8 @@ static inline int should_transform(ide_drive_t *drive, Scsi_Cmnd *cmd)
        return test_bit(IDESCSI_TRANSFORM, &scsi->transform);
 }
 
-static int idescsi_queue (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
+static int idescsi_queue (struct scsi_cmnd *cmd,
+               void (*done)(struct scsi_cmnd *))
 {
        struct Scsi_Host *host = cmd->device->host;
        idescsi_scsi_t *scsi = scsihost_to_idescsi(host);
@@ -925,7 +887,6 @@ static int idescsi_queue (Scsi_Cmnd *cmd, void (*done)(Scsi_Cmnd *))
 
        ide_init_drive_cmd (rq);
        rq->special = (char *) pc;
-       rq->bio = idescsi_dma_bio (drive, pc);
        rq->flags = REQ_SPECIAL;
        spin_unlock_irq(host->host_lock);
        (void) ide_do_drive_cmd (drive, rq, ide_end);
@@ -939,7 +900,7 @@ abort:
        return 0;
 }
 
-static int idescsi_eh_abort (Scsi_Cmnd *cmd)
+static int idescsi_eh_abort (struct scsi_cmnd *cmd)
 {
        idescsi_scsi_t *scsi  = scsihost_to_idescsi(cmd->device->host);
        ide_drive_t    *drive = scsi->drive;
@@ -979,7 +940,6 @@ static int idescsi_eh_abort (Scsi_Cmnd *cmd)
                 */
                printk (KERN_ERR "ide-scsi: cmd aborted!\n");
 
-               idescsi_free_bio(scsi->pc->rq->bio);
                if (scsi->pc->rq->flags & REQ_SENSE)
                        kfree(scsi->pc->buffer);
                kfree(scsi->pc->rq);
@@ -998,7 +958,7 @@ no_drive:
        return ret;
 }
 
-static int idescsi_eh_reset (Scsi_Cmnd *cmd)
+static int idescsi_eh_reset (struct scsi_cmnd *cmd)
 {
        struct request *req;
        idescsi_scsi_t *scsi  = scsihost_to_idescsi(cmd->device->host);
@@ -1028,7 +988,6 @@ static int idescsi_eh_reset (Scsi_Cmnd *cmd)
        /* kill current request */
        blkdev_dequeue_request(req);
        end_that_request_last(req);
-       idescsi_free_bio(req->bio);
        if (req->flags & REQ_SENSE)
                kfree(scsi->pc->buffer);
        kfree(scsi->pc);
@@ -1081,7 +1040,7 @@ static int idescsi_bios(struct scsi_device *sdev, struct block_device *bdev,
        return 0;
 }
 
-static Scsi_Host_Template idescsi_template = {
+static struct scsi_host_template idescsi_template = {
        .module                 = THIS_MODULE,
        .name                   = "idescsi",
        .info                   = idescsi_info,