Commit 726f0785 authored by Tejun Heo's avatar Tejun Heo Committed by Jeff Garzik

libata: kill qc->nsect and cursect

libata used two separate sets of variables to record request size and
current offset for ATA and ATAPI.  This is confusing and fragile.
This patch replaces qc->nsect/cursect with qc->nbytes/curbytes and
kills them.  Also, ata_pio_sector() is updated to use bytes for
qc->cursg_ofs instead of sectors.  The field used to be used in bytes
for ATAPI and in sectors for ATA.
Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Signed-off-by: default avatarJeff Garzik <jeff@garzik.org>
parent 16454445
...@@ -1249,7 +1249,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, ...@@ -1249,7 +1249,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
buflen += sg[i].length; buflen += sg[i].length;
ata_sg_init(qc, sg, n_elem); ata_sg_init(qc, sg, n_elem);
qc->nsect = buflen / ATA_SECT_SIZE;
qc->nbytes = buflen; qc->nbytes = buflen;
} }
...@@ -4006,11 +4005,11 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) ...@@ -4006,11 +4005,11 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
unsigned int offset; unsigned int offset;
unsigned char *buf; unsigned char *buf;
if (qc->cursect == (qc->nsect - 1)) if (qc->curbytes == qc->nbytes - ATA_SECT_SIZE)
ap->hsm_task_state = HSM_ST_LAST; ap->hsm_task_state = HSM_ST_LAST;
page = sg[qc->cursg].page; page = sg[qc->cursg].page;
offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; offset = sg[qc->cursg].offset + qc->cursg_ofs;
/* get the current page and offset */ /* get the current page and offset */
page = nth_page(page, (offset >> PAGE_SHIFT)); page = nth_page(page, (offset >> PAGE_SHIFT));
...@@ -4035,10 +4034,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) ...@@ -4035,10 +4034,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write); ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write);
} }
qc->cursect++; qc->curbytes += ATA_SECT_SIZE;
qc->cursg_ofs++; qc->cursg_ofs += ATA_SECT_SIZE;
if ((qc->cursg_ofs * ATA_SECT_SIZE) == (&sg[qc->cursg])->length) { if (qc->cursg_ofs == (&sg[qc->cursg])->length) {
qc->cursg++; qc->cursg++;
qc->cursg_ofs = 0; qc->cursg_ofs = 0;
} }
...@@ -4063,7 +4062,8 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc) ...@@ -4063,7 +4062,8 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
WARN_ON(qc->dev->multi_count == 0); WARN_ON(qc->dev->multi_count == 0);
nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count); nsect = min((qc->nbytes - qc->curbytes) / ATA_SECT_SIZE,
qc->dev->multi_count);
while (nsect--) while (nsect--)
ata_pio_sector(qc); ata_pio_sector(qc);
} else } else
......
...@@ -1443,15 +1443,10 @@ static void ata_eh_report(struct ata_port *ap) ...@@ -1443,15 +1443,10 @@ static void ata_eh_report(struct ata_port *ap)
}; };
struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
unsigned int nbytes;
if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask) if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask)
continue; continue;
nbytes = qc->nbytes;
if (!nbytes)
nbytes = qc->nsect << 9;
ata_dev_printk(qc->dev, KERN_ERR, ata_dev_printk(qc->dev, KERN_ERR,
"cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
"tag %d cdb 0x%x data %u %s\n " "tag %d cdb 0x%x data %u %s\n "
...@@ -1461,7 +1456,7 @@ static void ata_eh_report(struct ata_port *ap) ...@@ -1461,7 +1456,7 @@ static void ata_eh_report(struct ata_port *ap)
cmd->lbal, cmd->lbam, cmd->lbah, cmd->lbal, cmd->lbam, cmd->lbah,
cmd->hob_feature, cmd->hob_nsect, cmd->hob_feature, cmd->hob_nsect,
cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah,
cmd->device, qc->tag, qc->cdb[0], nbytes, cmd->device, qc->tag, qc->cdb[0], qc->nbytes,
dma_str[qc->dma_dir], dma_str[qc->dma_dir],
res->command, res->feature, res->nsect, res->command, res->feature, res->nsect,
res->lbal, res->lbam, res->lbah, res->lbal, res->lbam, res->lbah,
......
...@@ -1359,7 +1359,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) ...@@ -1359,7 +1359,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
goto nothing_to_do; goto nothing_to_do;
qc->flags |= ATA_QCFLAG_IO; qc->flags |= ATA_QCFLAG_IO;
qc->nsect = n_block; qc->nbytes = n_block * ATA_SECT_SIZE;
rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags,
qc->tag); qc->tag);
...@@ -2660,7 +2660,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) ...@@ -2660,7 +2660,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
* TODO: find out if we need to do more here to * TODO: find out if we need to do more here to
* cover scatter/gather case. * cover scatter/gather case.
*/ */
qc->nsect = scmd->request_bufflen / ATA_SECT_SIZE; qc->nbytes = scmd->request_bufflen;
/* request result TF */ /* request result TF */
qc->flags |= ATA_QCFLAG_RESULT_TF; qc->flags |= ATA_QCFLAG_RESULT_TF;
......
...@@ -189,10 +189,7 @@ static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc) ...@@ -189,10 +189,7 @@ static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
/* Cases the state machine will not complete correctly without help */ /* Cases the state machine will not complete correctly without help */
if ((tf->flags & ATA_TFLAG_LBA48) || tf->protocol == ATA_PROT_ATAPI_DMA) if ((tf->flags & ATA_TFLAG_LBA48) || tf->protocol == ATA_PROT_ATAPI_DMA)
{ {
if (tf->flags & ATA_TFLAG_LBA48) len = qc->nbytes;
len = qc->nsect * 512;
else
len = qc->nbytes;
if (tf->flags & ATA_TFLAG_WRITE) if (tf->flags & ATA_TFLAG_WRITE)
len |= 0x06000000; len |= 0x06000000;
......
...@@ -325,7 +325,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc) ...@@ -325,7 +325,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
/* host control block (HCB) */ /* host control block (HCB) */
buf[ 0] = QS_HCB_HDR; buf[ 0] = QS_HCB_HDR;
buf[ 1] = hflags; buf[ 1] = hflags;
*(__le32 *)(&buf[ 4]) = cpu_to_le32(qc->nsect * ATA_SECT_SIZE); *(__le32 *)(&buf[ 4]) = cpu_to_le32(qc->nbytes);
*(__le32 *)(&buf[ 8]) = cpu_to_le32(nelem); *(__le32 *)(&buf[ 8]) = cpu_to_le32(nelem);
addr = ((u64)pp->pkt_dma) + QS_CPB_BYTES; addr = ((u64)pp->pkt_dma) + QS_CPB_BYTES;
*(__le64 *)(&buf[16]) = cpu_to_le64(addr); *(__le64 *)(&buf[16]) = cpu_to_le64(addr);
......
...@@ -427,9 +427,6 @@ struct ata_queued_cmd { ...@@ -427,9 +427,6 @@ struct ata_queued_cmd {
unsigned int pad_len; unsigned int pad_len;
unsigned int nsect;
unsigned int cursect;
unsigned int nbytes; unsigned int nbytes;
unsigned int curbytes; unsigned int curbytes;
...@@ -1145,8 +1142,7 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc) ...@@ -1145,8 +1142,7 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
qc->dma_dir = DMA_NONE; qc->dma_dir = DMA_NONE;
qc->__sg = NULL; qc->__sg = NULL;
qc->flags = 0; qc->flags = 0;
qc->cursect = qc->cursg = qc->cursg_ofs = 0; qc->cursg = qc->cursg_ofs = 0;
qc->nsect = 0;
qc->nbytes = qc->curbytes = 0; qc->nbytes = qc->curbytes = 0;
qc->n_elem = 0; qc->n_elem = 0;
qc->err_mask = 0; qc->err_mask = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment