|
@@ -82,14 +82,12 @@ typedef struct idescsi_pc_s {
|
|
*/
|
|
*/
|
|
#define PC_DMA_IN_PROGRESS 0 /* 1 while DMA in progress */
|
|
#define PC_DMA_IN_PROGRESS 0 /* 1 while DMA in progress */
|
|
#define PC_WRITING 1 /* Data direction */
|
|
#define PC_WRITING 1 /* Data direction */
|
|
-#define PC_TRANSFORM 2 /* transform SCSI commands */
|
|
|
|
#define PC_TIMEDOUT 3 /* command timed out */
|
|
#define PC_TIMEDOUT 3 /* command timed out */
|
|
#define PC_DMA_OK 4 /* Use DMA */
|
|
#define PC_DMA_OK 4 /* Use DMA */
|
|
|
|
|
|
/*
|
|
/*
|
|
* SCSI command transformation layer
|
|
* SCSI command transformation layer
|
|
*/
|
|
*/
|
|
-#define IDESCSI_TRANSFORM 0 /* Enable/Disable transformation */
|
|
|
|
#define IDESCSI_SG_TRANSFORM 1 /* /dev/sg transformation */
|
|
#define IDESCSI_SG_TRANSFORM 1 /* /dev/sg transformation */
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -175,7 +173,8 @@ static void idescsi_input_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsigne
|
|
char *buf;
|
|
char *buf;
|
|
|
|
|
|
while (bcount) {
|
|
while (bcount) {
|
|
- if (pc->sg - (struct scatterlist *) pc->scsi_cmd->request_buffer > pc->scsi_cmd->use_sg) {
|
|
|
|
|
|
+ if (pc->sg - scsi_sglist(pc->scsi_cmd) >
|
|
|
|
+ scsi_sg_count(pc->scsi_cmd)) {
|
|
printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n");
|
|
printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n");
|
|
idescsi_discard_data (drive, bcount);
|
|
idescsi_discard_data (drive, bcount);
|
|
return;
|
|
return;
|
|
@@ -210,7 +209,8 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
|
|
char *buf;
|
|
char *buf;
|
|
|
|
|
|
while (bcount) {
|
|
while (bcount) {
|
|
- if (pc->sg - (struct scatterlist *) pc->scsi_cmd->request_buffer > pc->scsi_cmd->use_sg) {
|
|
|
|
|
|
+ if (pc->sg - scsi_sglist(pc->scsi_cmd) >
|
|
|
|
+ scsi_sg_count(pc->scsi_cmd)) {
|
|
printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n");
|
|
printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n");
|
|
idescsi_output_zeros (drive, bcount);
|
|
idescsi_output_zeros (drive, bcount);
|
|
return;
|
|
return;
|
|
@@ -239,77 +239,6 @@ static void idescsi_output_buffers (ide_drive_t *drive, idescsi_pc_t *pc, unsign
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
- * Most of the SCSI commands are supported directly by ATAPI devices.
|
|
|
|
- * idescsi_transform_pc handles the few exceptions.
|
|
|
|
- */
|
|
|
|
-static inline void idescsi_transform_pc1 (ide_drive_t *drive, idescsi_pc_t *pc)
|
|
|
|
-{
|
|
|
|
- u8 *c = pc->c, *scsi_buf = pc->buffer, *sc = pc->scsi_cmd->cmnd;
|
|
|
|
- char *atapi_buf;
|
|
|
|
-
|
|
|
|
- if (!test_bit(PC_TRANSFORM, &pc->flags))
|
|
|
|
- return;
|
|
|
|
- if (drive->media == ide_cdrom || drive->media == ide_optical) {
|
|
|
|
- if (c[0] == READ_6 || c[0] == WRITE_6) {
|
|
|
|
- c[8] = c[4]; c[5] = c[3]; c[4] = c[2];
|
|
|
|
- c[3] = c[1] & 0x1f; c[2] = 0; c[1] &= 0xe0;
|
|
|
|
- c[0] += (READ_10 - READ_6);
|
|
|
|
- }
|
|
|
|
- if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) {
|
|
|
|
- unsigned short new_len;
|
|
|
|
- if (!scsi_buf)
|
|
|
|
- return;
|
|
|
|
- if ((atapi_buf = kmalloc(pc->buffer_size + 4, GFP_ATOMIC)) == NULL)
|
|
|
|
- return;
|
|
|
|
- memset(atapi_buf, 0, pc->buffer_size + 4);
|
|
|
|
- memset (c, 0, 12);
|
|
|
|
- c[0] = sc[0] | 0x40;
|
|
|
|
- c[1] = sc[1];
|
|
|
|
- c[2] = sc[2];
|
|
|
|
- new_len = sc[4] + 4;
|
|
|
|
- c[8] = new_len;
|
|
|
|
- c[7] = new_len >> 8;
|
|
|
|
- c[9] = sc[5];
|
|
|
|
- if (c[0] == MODE_SELECT_10) {
|
|
|
|
- atapi_buf[1] = scsi_buf[0]; /* Mode data length */
|
|
|
|
- atapi_buf[2] = scsi_buf[1]; /* Medium type */
|
|
|
|
- atapi_buf[3] = scsi_buf[2]; /* Device specific parameter */
|
|
|
|
- atapi_buf[7] = scsi_buf[3]; /* Block descriptor length */
|
|
|
|
- memcpy(atapi_buf + 8, scsi_buf + 4, pc->buffer_size - 4);
|
|
|
|
- }
|
|
|
|
- pc->buffer = atapi_buf;
|
|
|
|
- pc->request_transfer += 4;
|
|
|
|
- pc->buffer_size += 4;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static inline void idescsi_transform_pc2 (ide_drive_t *drive, idescsi_pc_t *pc)
|
|
|
|
-{
|
|
|
|
- u8 *atapi_buf = pc->buffer;
|
|
|
|
- u8 *sc = pc->scsi_cmd->cmnd;
|
|
|
|
- u8 *scsi_buf = pc->scsi_cmd->request_buffer;
|
|
|
|
-
|
|
|
|
- if (!test_bit(PC_TRANSFORM, &pc->flags))
|
|
|
|
- return;
|
|
|
|
- if (drive->media == ide_cdrom || drive->media == ide_optical) {
|
|
|
|
- if (pc->c[0] == MODE_SENSE_10 && sc[0] == MODE_SENSE) {
|
|
|
|
- scsi_buf[0] = atapi_buf[1]; /* Mode data length */
|
|
|
|
- scsi_buf[1] = atapi_buf[2]; /* Medium type */
|
|
|
|
- scsi_buf[2] = atapi_buf[3]; /* Device specific parameter */
|
|
|
|
- scsi_buf[3] = atapi_buf[7]; /* Block descriptor length */
|
|
|
|
- memcpy(scsi_buf + 4, atapi_buf + 8, pc->request_transfer - 8);
|
|
|
|
- }
|
|
|
|
- if (pc->c[0] == INQUIRY) {
|
|
|
|
- scsi_buf[2] |= 2; /* ansi_revision */
|
|
|
|
- scsi_buf[3] = (scsi_buf[3] & 0xf0) | 2; /* response data format */
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if (atapi_buf && atapi_buf != scsi_buf)
|
|
|
|
- kfree(atapi_buf);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void hexdump(u8 *x, int len)
|
|
static void hexdump(u8 *x, int len)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
@@ -393,7 +322,6 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
|
|
idescsi_pc_t *pc = (idescsi_pc_t *) rq->special;
|
|
idescsi_pc_t *pc = (idescsi_pc_t *) rq->special;
|
|
int log = test_bit(IDESCSI_LOG_CMD, &scsi->log);
|
|
int log = test_bit(IDESCSI_LOG_CMD, &scsi->log);
|
|
struct Scsi_Host *host;
|
|
struct Scsi_Host *host;
|
|
- u8 *scsi_buf;
|
|
|
|
int errors = rq->errors;
|
|
int errors = rq->errors;
|
|
unsigned long flags;
|
|
unsigned long flags;
|
|
|
|
|
|
@@ -434,15 +362,6 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
|
|
pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16);
|
|
pc->scsi_cmd->result = (CHECK_CONDITION << 1) | (DID_OK << 16);
|
|
} else {
|
|
} else {
|
|
pc->scsi_cmd->result = DID_OK << 16;
|
|
pc->scsi_cmd->result = DID_OK << 16;
|
|
- idescsi_transform_pc2 (drive, pc);
|
|
|
|
- if (log) {
|
|
|
|
- printk ("ide-scsi: %s: suc %lu", drive->name, pc->scsi_cmd->serial_number);
|
|
|
|
- if (!test_bit(PC_WRITING, &pc->flags) && pc->actually_transferred && pc->actually_transferred <= 1024 && pc->buffer) {
|
|
|
|
- printk(", rst = ");
|
|
|
|
- scsi_buf = pc->scsi_cmd->request_buffer;
|
|
|
|
- hexdump(scsi_buf, min_t(unsigned, 16, pc->scsi_cmd->request_bufflen));
|
|
|
|
- } else printk("\n");
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
host = pc->scsi_cmd->device->host;
|
|
host = pc->scsi_cmd->device->host;
|
|
spin_lock_irqsave(host->host_lock, flags);
|
|
spin_lock_irqsave(host->host_lock, flags);
|
|
@@ -637,19 +556,14 @@ static int idescsi_map_sg(ide_drive_t *drive, idescsi_pc_t *pc)
|
|
return 1;
|
|
return 1;
|
|
|
|
|
|
sg = hwif->sg_table;
|
|
sg = hwif->sg_table;
|
|
- scsi_sg = pc->scsi_cmd->request_buffer;
|
|
|
|
- segments = pc->scsi_cmd->use_sg;
|
|
|
|
|
|
+ scsi_sg = scsi_sglist(pc->scsi_cmd);
|
|
|
|
+ segments = scsi_sg_count(pc->scsi_cmd);
|
|
|
|
|
|
if (segments > hwif->sg_max_nents)
|
|
if (segments > hwif->sg_max_nents)
|
|
return 1;
|
|
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);
|
|
|
|
- }
|
|
|
|
|
|
+ hwif->sg_nents = segments;
|
|
|
|
+ memcpy(sg, scsi_sg, sizeof(*sg) * segments);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -744,7 +658,6 @@ static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
|
|
{
|
|
{
|
|
if (drive->id && (drive->id->config & 0x0060) == 0x20)
|
|
if (drive->id && (drive->id->config & 0x0060) == 0x20)
|
|
set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags);
|
|
set_bit (IDESCSI_DRQ_INTERRUPT, &scsi->flags);
|
|
- set_bit(IDESCSI_TRANSFORM, &scsi->transform);
|
|
|
|
clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
|
|
clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
|
|
#if IDESCSI_DEBUG_LOG
|
|
#if IDESCSI_DEBUG_LOG
|
|
set_bit(IDESCSI_LOG_CMD, &scsi->log);
|
|
set_bit(IDESCSI_LOG_CMD, &scsi->log);
|
|
@@ -838,6 +751,8 @@ static struct block_device_operations idescsi_ops = {
|
|
static int idescsi_slave_configure(struct scsi_device * sdp)
|
|
static int idescsi_slave_configure(struct scsi_device * sdp)
|
|
{
|
|
{
|
|
/* Configure detected device */
|
|
/* Configure detected device */
|
|
|
|
+ sdp->use_10_for_rw = 1;
|
|
|
|
+ sdp->use_10_for_ms = 1;
|
|
scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, sdp->host->cmd_per_lun);
|
|
scsi_adjust_queue_depth(sdp, MSG_SIMPLE_TAG, sdp->host->cmd_per_lun);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -862,24 +777,6 @@ static int idescsi_ioctl (struct scsi_device *dev, int cmd, void __user *arg)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
}
|
|
}
|
|
|
|
|
|
-static inline int should_transform(ide_drive_t *drive, struct scsi_cmnd *cmd)
|
|
|
|
-{
|
|
|
|
- idescsi_scsi_t *scsi = drive_to_idescsi(drive);
|
|
|
|
-
|
|
|
|
- /* this was a layering violation and we can't support it
|
|
|
|
- anymore, sorry. */
|
|
|
|
-#if 0
|
|
|
|
- struct gendisk *disk = cmd->request->rq_disk;
|
|
|
|
-
|
|
|
|
- if (disk) {
|
|
|
|
- struct struct scsi_device_Template **p = disk->private_data;
|
|
|
|
- if (strcmp((*p)->scsi_driverfs_driver.name, "sg") == 0)
|
|
|
|
- return test_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
|
|
|
|
- }
|
|
|
|
-#endif
|
|
|
|
- return test_bit(IDESCSI_TRANSFORM, &scsi->transform);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static int idescsi_queue (struct scsi_cmnd *cmd,
|
|
static int idescsi_queue (struct scsi_cmnd *cmd,
|
|
void (*done)(struct scsi_cmnd *))
|
|
void (*done)(struct scsi_cmnd *))
|
|
{
|
|
{
|
|
@@ -905,23 +802,14 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
|
|
pc->flags = 0;
|
|
pc->flags = 0;
|
|
pc->rq = rq;
|
|
pc->rq = rq;
|
|
memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
|
|
memcpy (pc->c, cmd->cmnd, cmd->cmd_len);
|
|
- if (cmd->use_sg) {
|
|
|
|
- pc->buffer = NULL;
|
|
|
|
- pc->sg = cmd->request_buffer;
|
|
|
|
- } else {
|
|
|
|
- pc->buffer = cmd->request_buffer;
|
|
|
|
- pc->sg = NULL;
|
|
|
|
- }
|
|
|
|
|
|
+ pc->buffer = NULL;
|
|
|
|
+ pc->sg = scsi_sglist(cmd);
|
|
pc->b_count = 0;
|
|
pc->b_count = 0;
|
|
- pc->request_transfer = pc->buffer_size = cmd->request_bufflen;
|
|
|
|
|
|
+ pc->request_transfer = pc->buffer_size = scsi_bufflen(cmd);
|
|
pc->scsi_cmd = cmd;
|
|
pc->scsi_cmd = cmd;
|
|
pc->done = done;
|
|
pc->done = done;
|
|
pc->timeout = jiffies + cmd->timeout_per_command;
|
|
pc->timeout = jiffies + cmd->timeout_per_command;
|
|
|
|
|
|
- if (should_transform(drive, cmd))
|
|
|
|
- set_bit(PC_TRANSFORM, &pc->flags);
|
|
|
|
- idescsi_transform_pc1 (drive, pc);
|
|
|
|
-
|
|
|
|
if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
|
|
if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
|
|
printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
|
|
printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
|
|
hexdump(cmd->cmnd, cmd->cmd_len);
|
|
hexdump(cmd->cmnd, cmd->cmd_len);
|