#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
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;
}
count = min(pc->sg->length - pc->b_count, bcount);
buf = page_address(pc->sg->page) + pc->sg->offset;
- atapi_input_bytes (drive, buf + pc->b_count, count);
+ drive->hwif->atapi_input_bytes(drive, buf + pc->b_count, count);
bcount -= count; pc->b_count += count;
if (pc->b_count == pc->sg->length) {
pc->sg++;
}
count = min(pc->sg->length - pc->b_count, bcount);
buf = page_address(pc->sg->page) + pc->sg->offset;
- atapi_output_bytes (drive, buf + pc->b_count, count);
+ drive->hwif->atapi_output_bytes(drive, buf + pc->b_count, count);
bcount -= count; pc->b_count += count;
if (pc->b_count == pc->sg->length) {
pc->sg++;
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;
return ide_do_drive_cmd(drive, rq, ide_preempt);
}
-ide_startstop_t idescsi_atapi_error (ide_drive_t *drive, const char *msg, byte stat)
+static ide_startstop_t
+idescsi_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
{
- struct request *rq;
- byte err;
-
- err = ide_dump_atapi_status(drive, msg, stat);
-
- if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
- return ide_stopped;
-
- /* retry only "normal" I/O: */
- if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK | REQ_DRIVE_TASKFILE)) {
- rq->errors = 1;
- ide_end_drive_cmd(drive, stat, err);
- return ide_stopped;
- }
-
if (HWIF(drive)->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
/* force an abort */
HWIF(drive)->OUTB(WIN_IDLEIMMEDIATE,IDE_COMMAND_REG);
return ide_stopped;
}
-ide_startstop_t idescsi_atapi_abort (ide_drive_t *drive, const char *msg)
+static ide_startstop_t
+idescsi_atapi_abort(ide_drive_t *drive, struct request *rq)
{
- struct request *rq;
-
- if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
- return ide_stopped;
-
- /* retry only "normal" I/O: */
- if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK | REQ_DRIVE_TASKFILE)) {
- rq->errors = 1;
- ide_end_drive_cmd(drive, BUSY_STAT, 0);
- return ide_stopped;
- }
-
#if IDESCSI_DEBUG_LOG
printk(KERN_WARNING "idescsi_atapi_abort called for %lu\n",
((idescsi_pc_t *) rq->special)->scsi_cmd->serial_number);
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;
if (pc->sg)
idescsi_input_buffers(drive, pc, temp);
else
- atapi_input_bytes(drive, pc->current_position, temp);
+ drive->hwif->atapi_input_bytes(drive, pc->current_position, temp);
printk(KERN_ERR "ide-scsi: transferred %d of %d bytes\n", temp, bcount.all);
}
pc->actually_transferred += temp;
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;
/* Set the interrupt routine */
ide_set_handler(drive, &idescsi_pc_intr, get_timeout(pc), idescsi_expiry);
/* Send the actual packet */
- atapi_output_bytes(drive, scsi->pc->c, 12);
+ drive->hwif->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->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 */
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->dma_setup(drive);
+ hwif->sg_mapped = 0;
}
SELECT_DRIVE(drive);
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);
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);
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);
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);
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);
if (rq) kfree (rq);
cmd->result = DID_ERROR << 16;
done(cmd);
- return 1;
+ 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;
*/
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);
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);
/* 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);
return 0;
}
-static Scsi_Host_Template idescsi_template = {
+static struct scsi_host_template idescsi_template = {
.module = THIS_MODULE,
.name = "idescsi",
.info = idescsi_info,