diff options
author | Jens Axboe <jens.axboe@oracle.com> | 2007-10-16 05:14:12 -0400 |
---|---|---|
committer | Jens Axboe <jens.axboe@oracle.com> | 2007-10-16 05:14:12 -0400 |
commit | 8726021626780a73e795c9b939e1ee49ac8c9136 (patch) | |
tree | 7f42d69578ab8f286a4b66180c95864a60e95690 /drivers | |
parent | a8474ce23a73185dd2bae4c884b1716474032d31 (diff) |
libata: convert to using sg helpers
This converts libata to using the sg helpers for looking up sg
elements, instead of doing it manually.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ata/libata-core.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c index 68699b3e7998..e52c33180e42 100644 --- a/drivers/ata/libata-core.c +++ b/drivers/ata/libata-core.c | |||
@@ -1410,7 +1410,7 @@ static void ata_qc_complete_internal(struct ata_queued_cmd *qc) | |||
1410 | */ | 1410 | */ |
1411 | unsigned ata_exec_internal_sg(struct ata_device *dev, | 1411 | unsigned ata_exec_internal_sg(struct ata_device *dev, |
1412 | struct ata_taskfile *tf, const u8 *cdb, | 1412 | struct ata_taskfile *tf, const u8 *cdb, |
1413 | int dma_dir, struct scatterlist *sg, | 1413 | int dma_dir, struct scatterlist *sgl, |
1414 | unsigned int n_elem, unsigned long timeout) | 1414 | unsigned int n_elem, unsigned long timeout) |
1415 | { | 1415 | { |
1416 | struct ata_link *link = dev->link; | 1416 | struct ata_link *link = dev->link; |
@@ -1472,11 +1472,12 @@ unsigned ata_exec_internal_sg(struct ata_device *dev, | |||
1472 | qc->dma_dir = dma_dir; | 1472 | qc->dma_dir = dma_dir; |
1473 | if (dma_dir != DMA_NONE) { | 1473 | if (dma_dir != DMA_NONE) { |
1474 | unsigned int i, buflen = 0; | 1474 | unsigned int i, buflen = 0; |
1475 | struct scatterlist *sg; | ||
1475 | 1476 | ||
1476 | for (i = 0; i < n_elem; i++) | 1477 | for_each_sg(sgl, sg, n_elem, i) |
1477 | buflen += sg[i].length; | 1478 | buflen += sg->length; |
1478 | 1479 | ||
1479 | ata_sg_init(qc, sg, n_elem); | 1480 | ata_sg_init(qc, sgl, n_elem); |
1480 | qc->nbytes = buflen; | 1481 | qc->nbytes = buflen; |
1481 | } | 1482 | } |
1482 | 1483 | ||
@@ -4292,7 +4293,7 @@ void ata_sg_clean(struct ata_queued_cmd *qc) | |||
4292 | if (qc->n_elem) | 4293 | if (qc->n_elem) |
4293 | dma_unmap_sg(ap->dev, sg, qc->n_elem, dir); | 4294 | dma_unmap_sg(ap->dev, sg, qc->n_elem, dir); |
4294 | /* restore last sg */ | 4295 | /* restore last sg */ |
4295 | sg[qc->orig_n_elem - 1].length += qc->pad_len; | 4296 | sg_last(sg, qc->orig_n_elem)->length += qc->pad_len; |
4296 | if (pad_buf) { | 4297 | if (pad_buf) { |
4297 | struct scatterlist *psg = &qc->pad_sgent; | 4298 | struct scatterlist *psg = &qc->pad_sgent; |
4298 | void *addr = kmap_atomic(psg->page, KM_IRQ0); | 4299 | void *addr = kmap_atomic(psg->page, KM_IRQ0); |
@@ -4547,6 +4548,7 @@ void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, unsigned int buflen) | |||
4547 | qc->orig_n_elem = 1; | 4548 | qc->orig_n_elem = 1; |
4548 | qc->buf_virt = buf; | 4549 | qc->buf_virt = buf; |
4549 | qc->nbytes = buflen; | 4550 | qc->nbytes = buflen; |
4551 | qc->cursg = qc->__sg; | ||
4550 | 4552 | ||
4551 | sg_init_one(&qc->sgent, buf, buflen); | 4553 | sg_init_one(&qc->sgent, buf, buflen); |
4552 | } | 4554 | } |
@@ -4572,6 +4574,7 @@ void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, | |||
4572 | qc->__sg = sg; | 4574 | qc->__sg = sg; |
4573 | qc->n_elem = n_elem; | 4575 | qc->n_elem = n_elem; |
4574 | qc->orig_n_elem = n_elem; | 4576 | qc->orig_n_elem = n_elem; |
4577 | qc->cursg = qc->__sg; | ||
4575 | } | 4578 | } |
4576 | 4579 | ||
4577 | /** | 4580 | /** |
@@ -4661,7 +4664,7 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) | |||
4661 | { | 4664 | { |
4662 | struct ata_port *ap = qc->ap; | 4665 | struct ata_port *ap = qc->ap; |
4663 | struct scatterlist *sg = qc->__sg; | 4666 | struct scatterlist *sg = qc->__sg; |
4664 | struct scatterlist *lsg = &sg[qc->n_elem - 1]; | 4667 | struct scatterlist *lsg = sg_last(qc->__sg, qc->n_elem); |
4665 | int n_elem, pre_n_elem, dir, trim_sg = 0; | 4668 | int n_elem, pre_n_elem, dir, trim_sg = 0; |
4666 | 4669 | ||
4667 | VPRINTK("ENTER, ata%u\n", ap->print_id); | 4670 | VPRINTK("ENTER, ata%u\n", ap->print_id); |
@@ -4825,7 +4828,6 @@ void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf, | |||
4825 | static void ata_pio_sector(struct ata_queued_cmd *qc) | 4828 | static void ata_pio_sector(struct ata_queued_cmd *qc) |
4826 | { | 4829 | { |
4827 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); | 4830 | int do_write = (qc->tf.flags & ATA_TFLAG_WRITE); |
4828 | struct scatterlist *sg = qc->__sg; | ||
4829 | struct ata_port *ap = qc->ap; | 4831 | struct ata_port *ap = qc->ap; |
4830 | struct page *page; | 4832 | struct page *page; |
4831 | unsigned int offset; | 4833 | unsigned int offset; |
@@ -4834,8 +4836,8 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) | |||
4834 | if (qc->curbytes == qc->nbytes - qc->sect_size) | 4836 | if (qc->curbytes == qc->nbytes - qc->sect_size) |
4835 | ap->hsm_task_state = HSM_ST_LAST; | 4837 | ap->hsm_task_state = HSM_ST_LAST; |
4836 | 4838 | ||
4837 | page = sg[qc->cursg].page; | 4839 | page = qc->cursg->page; |
4838 | offset = sg[qc->cursg].offset + qc->cursg_ofs; | 4840 | offset = qc->cursg->offset + qc->cursg_ofs; |
4839 | 4841 | ||
4840 | /* get the current page and offset */ | 4842 | /* get the current page and offset */ |
4841 | page = nth_page(page, (offset >> PAGE_SHIFT)); | 4843 | page = nth_page(page, (offset >> PAGE_SHIFT)); |
@@ -4863,8 +4865,8 @@ static void ata_pio_sector(struct ata_queued_cmd *qc) | |||
4863 | qc->curbytes += qc->sect_size; | 4865 | qc->curbytes += qc->sect_size; |
4864 | qc->cursg_ofs += qc->sect_size; | 4866 | qc->cursg_ofs += qc->sect_size; |
4865 | 4867 | ||
4866 | if (qc->cursg_ofs == (&sg[qc->cursg])->length) { | 4868 | if (qc->cursg_ofs == qc->cursg->length) { |
4867 | qc->cursg++; | 4869 | qc->cursg = sg_next(qc->cursg); |
4868 | qc->cursg_ofs = 0; | 4870 | qc->cursg_ofs = 0; |
4869 | } | 4871 | } |
4870 | } | 4872 | } |
@@ -4959,7 +4961,7 @@ static void __atapi_pio_bytes(struct ata_queued_cmd *qc, unsigned int bytes) | |||
4959 | ap->hsm_task_state = HSM_ST_LAST; | 4961 | ap->hsm_task_state = HSM_ST_LAST; |
4960 | 4962 | ||
4961 | next_sg: | 4963 | next_sg: |
4962 | if (unlikely(qc->cursg >= qc->n_elem)) { | 4964 | if (unlikely(qc->cursg == sg_last(qc->__sg, qc->n_elem))) { |
4963 | /* | 4965 | /* |
4964 | * The end of qc->sg is reached and the device expects | 4966 | * The end of qc->sg is reached and the device expects |
4965 | * more data to transfer. In order not to overrun qc->sg | 4967 | * more data to transfer. In order not to overrun qc->sg |
@@ -4982,7 +4984,7 @@ next_sg: | |||
4982 | return; | 4984 | return; |
4983 | } | 4985 | } |
4984 | 4986 | ||
4985 | sg = &qc->__sg[qc->cursg]; | 4987 | sg = qc->cursg; |
4986 | 4988 | ||
4987 | page = sg->page; | 4989 | page = sg->page; |
4988 | offset = sg->offset + qc->cursg_ofs; | 4990 | offset = sg->offset + qc->cursg_ofs; |
@@ -5021,7 +5023,7 @@ next_sg: | |||
5021 | qc->cursg_ofs += count; | 5023 | qc->cursg_ofs += count; |
5022 | 5024 | ||
5023 | if (qc->cursg_ofs == sg->length) { | 5025 | if (qc->cursg_ofs == sg->length) { |
5024 | qc->cursg++; | 5026 | qc->cursg = sg_next(qc->cursg); |
5025 | qc->cursg_ofs = 0; | 5027 | qc->cursg_ofs = 0; |
5026 | } | 5028 | } |
5027 | 5029 | ||