libata: kill qc->nsect and cursect
authorTejun Heo <htejun@gmail.com>
Wed, 3 Jan 2007 08:30:39 +0000 (17:30 +0900)
committerJeff Garzik <jeff@garzik.org>
Fri, 9 Feb 2007 22:39:31 +0000 (17:39 -0500)
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: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
drivers/ata/libata-core.c
drivers/ata/libata-eh.c
drivers/ata/libata-scsi.c
drivers/ata/pata_pdc202xx_old.c
drivers/ata/sata_qstor.c
include/linux/libata.h

index 89f3cf57b677ecc88778217c64a8712e67f6761f..c1444d8f92c69c36efade7c4858b989b5d0e637e 100644 (file)
@@ -1249,7 +1249,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
                        buflen += sg[i].length;
 
                ata_sg_init(qc, sg, n_elem);
-               qc->nsect = buflen / ATA_SECT_SIZE;
                qc->nbytes = buflen;
        }
 
@@ -4006,11 +4005,11 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
        unsigned int offset;
        unsigned char *buf;
 
-       if (qc->cursect == (qc->nsect - 1))
+       if (qc->curbytes == qc->nbytes - ATA_SECT_SIZE)
                ap->hsm_task_state = HSM_ST_LAST;
 
        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 */
        page = nth_page(page, (offset >> PAGE_SHIFT));
@@ -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);
        }
 
-       qc->cursect++;
-       qc->cursg_ofs++;
+       qc->curbytes += ATA_SECT_SIZE;
+       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_ofs = 0;
        }
@@ -4063,7 +4062,8 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
 
                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--)
                        ata_pio_sector(qc);
        } else
index 748435807d689cbc8ac3aa511576dc87e656b427..52c85af7fe9912492cd9353a4d92f78e3a600e9c 100644 (file)
@@ -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_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
-               unsigned int nbytes;
 
                if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask)
                        continue;
 
-               nbytes = qc->nbytes;
-               if (!nbytes)
-                       nbytes = qc->nsect << 9;
-
                ata_dev_printk(qc->dev, KERN_ERR,
                        "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
                        "tag %d cdb 0x%x data %u %s\n         "
@@ -1461,7 +1456,7 @@ static void ata_eh_report(struct ata_port *ap)
                        cmd->lbal, cmd->lbam, cmd->lbah,
                        cmd->hob_feature, cmd->hob_nsect,
                        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],
                        res->command, res->feature, res->nsect,
                        res->lbal, res->lbam, res->lbah,
index 6a99c0824751b191e83cf2c4b6740e845ce905e9..9b5088ab2742ca0c750be5a04807253903335c37 100644 (file)
@@ -1359,7 +1359,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
                goto nothing_to_do;
 
        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,
                             qc->tag);
@@ -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
         *       cover scatter/gather case.
         */
-       qc->nsect = scmd->request_bufflen / ATA_SECT_SIZE;
+       qc->nbytes = scmd->request_bufflen;
 
        /* request result TF */
        qc->flags |= ATA_QCFLAG_RESULT_TF;
index ad691b9e77434d94bc5491ec250304eb573e970a..ba982ba68ad5920c530c4c60545f00d7c0aca9de 100644 (file)
@@ -189,10 +189,7 @@ static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
        /* 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)
-                       len = qc->nsect * 512;
-               else
-                       len = qc->nbytes;
+               len = qc->nbytes;
 
                if (tf->flags & ATA_TFLAG_WRITE)
                        len |= 0x06000000;
index 710909df4eaf18a7e846d29f1f20d945318b7542..0292a79f9747ae082b28790af5290a967202b3d4 100644 (file)
@@ -325,7 +325,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
        /* host control block (HCB) */
        buf[ 0] = QS_HCB_HDR;
        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);
        addr = ((u64)pp->pkt_dma) + QS_CPB_BYTES;
        *(__le64 *)(&buf[16]) = cpu_to_le64(addr);
index a8ecaaad55fffdeeb47ef989e2e9e3fefbb79634..a2458dfefb17d3a45fd6372b7d7344190ae1a2c2 100644 (file)
@@ -427,9 +427,6 @@ struct ata_queued_cmd {
 
        unsigned int            pad_len;
 
-       unsigned int            nsect;
-       unsigned int            cursect;
-
        unsigned int            nbytes;
        unsigned int            curbytes;
 
@@ -1145,8 +1142,7 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
        qc->dma_dir = DMA_NONE;
        qc->__sg = NULL;
        qc->flags = 0;
-       qc->cursect = qc->cursg = qc->cursg_ofs = 0;
-       qc->nsect = 0;
+       qc->cursg = qc->cursg_ofs = 0;
        qc->nbytes = qc->curbytes = 0;
        qc->n_elem = 0;
        qc->err_mask = 0;