aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libata-scsi.c
diff options
context:
space:
mode:
authorJeff Garzik <jgarzik@pobox.com>2005-11-14 14:50:05 -0500
committerJeff Garzik <jgarzik@pobox.com>2005-11-14 14:50:05 -0500
commitc6e6e666cbfe40f0d7fb1a293ff6332973acac37 (patch)
tree21609c228d8aaf1f9a2217f7fd08266ed669f5bc /drivers/scsi/libata-scsi.c
parent2c13b7cee045af689b36349c2bc6a9ed6e3d73fa (diff)
[libata] REQUEST SENSE handling fixes
- Move ATAPI check-condition handling out of the timeout handler - Use multi-qc-issue feature to issue REQUEST SENSE ATAPI PACKET command upon receiving an ATAPI check-condition. This cleans things up a lot, and eliminates a nasty recursion bug.
Diffstat (limited to 'drivers/scsi/libata-scsi.c')
-rw-r--r--drivers/scsi/libata-scsi.c77
1 files changed, 43 insertions, 34 deletions
diff --git a/drivers/scsi/libata-scsi.c b/drivers/scsi/libata-scsi.c
index 0df4b682965d..3b4ca55a3332 100644
--- a/drivers/scsi/libata-scsi.c
+++ b/drivers/scsi/libata-scsi.c
@@ -1955,22 +1955,44 @@ void ata_scsi_badcmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *), u8
1955 done(cmd); 1955 done(cmd);
1956} 1956}
1957 1957
1958void atapi_request_sense(struct ata_port *ap, struct ata_device *dev, 1958static int atapi_sense_complete(struct ata_queued_cmd *qc,unsigned int err_mask)
1959 struct scsi_cmnd *cmd)
1960{ 1959{
1961 DECLARE_COMPLETION(wait); 1960 if (err_mask && ((err_mask & AC_ERR_DEV) == 0))
1962 struct ata_queued_cmd *qc; 1961 /* FIXME: not quite right; we don't want the
1963 unsigned long flags; 1962 * translation of taskfile registers into
1964 int rc; 1963 * a sense descriptors, since that's only
1964 * correct for ATA, not ATAPI
1965 */
1966 ata_gen_ata_desc_sense(qc);
1965 1967
1966 DPRINTK("ATAPI request sense\n"); 1968 qc->scsidone(qc->scsicmd);
1969 return 0;
1970}
1967 1971
1968 qc = ata_qc_new_init(ap, dev); 1972/* is it pointless to prefer PIO for "safety reasons"? */
1969 BUG_ON(qc == NULL); 1973static inline int ata_pio_use_silly(struct ata_port *ap)
1974{
1975 return (ap->flags & ATA_FLAG_PIO_DMA);
1976}
1977
1978static void atapi_request_sense(struct ata_queued_cmd *qc)
1979{
1980 struct ata_port *ap = qc->ap;
1981 struct scsi_cmnd *cmd = qc->scsicmd;
1982
1983 DPRINTK("ATAPI request sense\n");
1970 1984
1971 /* FIXME: is this needed? */ 1985 /* FIXME: is this needed? */
1972 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer)); 1986 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
1973 1987
1988 ap->ops->tf_read(ap, &qc->tf);
1989
1990 /* fill these in, for the case where they are -not- overwritten */
1991 cmd->sense_buffer[0] = 0x70;
1992 cmd->sense_buffer[2] = qc->tf.feature >> 4;
1993
1994 ata_qc_reinit(qc);
1995
1974 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer)); 1996 ata_sg_init_one(qc, cmd->sense_buffer, sizeof(cmd->sense_buffer));
1975 qc->dma_dir = DMA_FROM_DEVICE; 1997 qc->dma_dir = DMA_FROM_DEVICE;
1976 1998
@@ -1981,22 +2003,20 @@ void atapi_request_sense(struct ata_port *ap, struct ata_device *dev,
1981 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; 2003 qc->tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE;
1982 qc->tf.command = ATA_CMD_PACKET; 2004 qc->tf.command = ATA_CMD_PACKET;
1983 2005
1984 qc->tf.protocol = ATA_PROT_ATAPI; 2006 if (ata_pio_use_silly(ap)) {
1985 qc->tf.lbam = (8 * 1024) & 0xff; 2007 qc->tf.protocol = ATA_PROT_ATAPI_DMA;
1986 qc->tf.lbah = (8 * 1024) >> 8; 2008 qc->tf.feature |= ATAPI_PKT_DMA;
2009 } else {
2010 qc->tf.protocol = ATA_PROT_ATAPI;
2011 qc->tf.lbam = (8 * 1024) & 0xff;
2012 qc->tf.lbah = (8 * 1024) >> 8;
2013 }
1987 qc->nbytes = SCSI_SENSE_BUFFERSIZE; 2014 qc->nbytes = SCSI_SENSE_BUFFERSIZE;
1988 2015
1989 qc->waiting = &wait; 2016 qc->complete_fn = atapi_sense_complete;
1990 qc->complete_fn = ata_qc_complete_noop;
1991 2017
1992 spin_lock_irqsave(&ap->host_set->lock, flags); 2018 if (ata_qc_issue(qc))
1993 rc = ata_qc_issue(qc); 2019 ata_qc_complete(qc, AC_ERR_OTHER);
1994 spin_unlock_irqrestore(&ap->host_set->lock, flags);
1995
1996 if (rc)
1997 ata_port_disable(ap);
1998 else
1999 wait_for_completion(&wait);
2000 2020
2001 DPRINTK("EXIT\n"); 2021 DPRINTK("EXIT\n");
2002} 2022}
@@ -2008,19 +2028,8 @@ static int atapi_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask)
2008 VPRINTK("ENTER, err_mask 0x%X\n", err_mask); 2028 VPRINTK("ENTER, err_mask 0x%X\n", err_mask);
2009 2029
2010 if (unlikely(err_mask & AC_ERR_DEV)) { 2030 if (unlikely(err_mask & AC_ERR_DEV)) {
2011 DPRINTK("request check condition\n");
2012
2013 /* FIXME: command completion with check condition
2014 * but no sense causes the error handler to run,
2015 * which then issues REQUEST SENSE, fills in the sense
2016 * buffer, and completes the command (for the second
2017 * time). We need to issue REQUEST SENSE some other
2018 * way, to avoid completing the command twice.
2019 */
2020 cmd->result = SAM_STAT_CHECK_CONDITION; 2031 cmd->result = SAM_STAT_CHECK_CONDITION;
2021 2032 atapi_request_sense(qc);
2022 qc->scsidone(cmd);
2023
2024 return 1; 2033 return 1;
2025 } 2034 }
2026 2035