Commit 513e3486 authored by Jeff Garzik's avatar Jeff Garzik

[libata] split ATA_QCFLAG_SG into ATA_QCFLAG_{SG,SINGLE}

In part of the effort to remove SCSI specifics from the libata
internals, remove references to cmd->use_sg.  cmd->use_sg
becomes ATA_QCFLAG_SG, and !cmd->use_sg becomes ATA_QCFLAG_SINGLE.

Convenience constant ATA_QCFLAG_DMAMAP is created when the programmer
wishes to refer collectively to ATA_QCFLAG_{SG,SINGLE}.
parent 1ed9ed8f
...@@ -1750,26 +1750,24 @@ static void ata_dev_set_pio(struct ata_port *ap, unsigned int device) ...@@ -1750,26 +1750,24 @@ static void ata_dev_set_pio(struct ata_port *ap, unsigned int device)
static void ata_sg_clean(struct ata_queued_cmd *qc) static void ata_sg_clean(struct ata_queued_cmd *qc)
{ {
struct ata_port *ap = qc->ap; struct ata_port *ap = qc->ap;
struct scsi_cmnd *cmd = qc->scsicmd;
struct scatterlist *sg = qc->sg; struct scatterlist *sg = qc->sg;
int dir = scsi_to_pci_dma_dir(cmd->sc_data_direction); int dir = qc->pci_dma_dir;
assert(dir == SCSI_DATA_READ || dir == SCSI_DATA_WRITE); assert(qc->flags & ATA_QCFLAG_DMAMAP);
assert(qc->flags & ATA_QCFLAG_SG);
assert(sg != NULL); assert(sg != NULL);
if (!cmd->use_sg) if (qc->flags & ATA_QCFLAG_SINGLE)
assert(qc->n_elem == 1); assert(qc->n_elem == 1);
DPRINTK("unmapping %u sg elements\n", qc->n_elem); DPRINTK("unmapping %u sg elements\n", qc->n_elem);
if (cmd->use_sg) if (qc->flags & ATA_QCFLAG_SG)
pci_unmap_sg(ap->host_set->pdev, sg, qc->n_elem, dir); pci_unmap_sg(ap->host_set->pdev, sg, qc->n_elem, dir);
else else
pci_unmap_single(ap->host_set->pdev, sg_dma_address(&sg[0]), pci_unmap_single(ap->host_set->pdev, sg_dma_address(&sg[0]),
sg_dma_len(&sg[0]), dir); sg_dma_len(&sg[0]), dir);
qc->flags &= ~ATA_QCFLAG_SG; qc->flags &= ~ATA_QCFLAG_DMAMAP;
qc->sg = NULL; qc->sg = NULL;
} }
...@@ -1830,7 +1828,7 @@ static void ata_fill_sg(struct ata_queued_cmd *qc) ...@@ -1830,7 +1828,7 @@ static void ata_fill_sg(struct ata_queued_cmd *qc)
*/ */
void ata_qc_prep(struct ata_queued_cmd *qc) void ata_qc_prep(struct ata_queued_cmd *qc)
{ {
if (!(qc->flags & ATA_QCFLAG_SG)) if (!(qc->flags & ATA_QCFLAG_DMAMAP))
return; return;
ata_fill_sg(qc); ata_fill_sg(qc);
...@@ -1851,7 +1849,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc) ...@@ -1851,7 +1849,7 @@ static int ata_sg_setup_one(struct ata_queued_cmd *qc)
{ {
struct ata_port *ap = qc->ap; struct ata_port *ap = qc->ap;
struct scsi_cmnd *cmd = qc->scsicmd; struct scsi_cmnd *cmd = qc->scsicmd;
int dir = scsi_to_pci_dma_dir(cmd->sc_data_direction); int dir = qc->pci_dma_dir;
struct scatterlist *sg = qc->sg; struct scatterlist *sg = qc->sg;
dma_addr_t dma_address; dma_addr_t dma_address;
...@@ -1893,11 +1891,11 @@ static int ata_sg_setup(struct ata_queued_cmd *qc) ...@@ -1893,11 +1891,11 @@ static int ata_sg_setup(struct ata_queued_cmd *qc)
struct scatterlist *sg; struct scatterlist *sg;
int n_elem, dir; int n_elem, dir;
VPRINTK("ENTER, ata%u, use_sg %d\n", ap->id, cmd->use_sg); VPRINTK("ENTER, ata%u\n", ap->id);
assert(cmd->use_sg > 0); assert(qc->flags & ATA_QCFLAG_SG);
sg = (struct scatterlist *)cmd->request_buffer; sg = (struct scatterlist *)cmd->request_buffer;
dir = scsi_to_pci_dma_dir(cmd->sc_data_direction); dir = qc->pci_dma_dir;
n_elem = pci_map_sg(ap->host_set->pdev, sg, cmd->use_sg, dir); n_elem = pci_map_sg(ap->host_set->pdev, sg, cmd->use_sg, dir);
if (n_elem < 1) if (n_elem < 1)
return -1; return -1;
...@@ -2058,7 +2056,7 @@ static void ata_pio_sector(struct ata_port *ap) ...@@ -2058,7 +2056,7 @@ static void ata_pio_sector(struct ata_port *ap)
qc->cursect++; qc->cursect++;
qc->cursg_ofs++; qc->cursg_ofs++;
if (cmd->use_sg) if (qc->flags & ATA_QCFLAG_SG)
if ((qc->cursg_ofs * ATA_SECT_SIZE) == sg_dma_len(&sg[qc->cursg])) { if ((qc->cursg_ofs * ATA_SECT_SIZE) == sg_dma_len(&sg[qc->cursg])) {
qc->cursg++; qc->cursg++;
qc->cursg_ofs = 0; qc->cursg_ofs = 0;
...@@ -2299,7 +2297,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) ...@@ -2299,7 +2297,7 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */ assert(qc != NULL); /* ata_qc_from_tag _might_ return NULL */
assert(qc->flags & ATA_QCFLAG_ACTIVE); assert(qc->flags & ATA_QCFLAG_ACTIVE);
if (likely(qc->flags & ATA_QCFLAG_SG)) if (likely(qc->flags & ATA_QCFLAG_DMAMAP))
ata_sg_clean(qc); ata_sg_clean(qc);
/* call completion callback */ /* call completion callback */
...@@ -2346,18 +2344,14 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat) ...@@ -2346,18 +2344,14 @@ void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat)
int ata_qc_issue(struct ata_queued_cmd *qc) int ata_qc_issue(struct ata_queued_cmd *qc)
{ {
struct ata_port *ap = qc->ap; struct ata_port *ap = qc->ap;
struct scsi_cmnd *cmd = qc->scsicmd;
if (qc->flags & ATA_QCFLAG_SG) { if (qc->flags & ATA_QCFLAG_SG) {
/* set up SG table */
if (cmd->use_sg) {
if (ata_sg_setup(qc)) if (ata_sg_setup(qc))
goto err_out; goto err_out;
} else { } else if (qc->flags & ATA_QCFLAG_SINGLE) {
if (ata_sg_setup_one(qc)) if (ata_sg_setup_one(qc))
goto err_out; goto err_out;
} }
}
ap->ops->qc_prep(qc); ap->ops->qc_prep(qc);
......
...@@ -386,6 +386,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, ...@@ -386,6 +386,7 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
if (!qc) if (!qc)
return; return;
/* data is present; dma-map it */
if (cmd->sc_data_direction == SCSI_DATA_READ || if (cmd->sc_data_direction == SCSI_DATA_READ ||
cmd->sc_data_direction == SCSI_DATA_WRITE) { cmd->sc_data_direction == SCSI_DATA_WRITE) {
if (unlikely(cmd->request_bufflen < 1)) { if (unlikely(cmd->request_bufflen < 1)) {
...@@ -394,7 +395,12 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev, ...@@ -394,7 +395,12 @@ static void ata_scsi_translate(struct ata_port *ap, struct ata_device *dev,
goto err_out; goto err_out;
} }
qc->flags |= ATA_QCFLAG_SG; /* data is present; dma-map it */ if (cmd->use_sg)
qc->flags |= ATA_QCFLAG_SG;
else
qc->flags |= ATA_QCFLAG_SINGLE;
qc->pci_dma_dir = scsi_to_pci_dma_dir(cmd->sc_data_direction);
} }
qc->complete_fn = ata_scsi_qc_complete; qc->complete_fn = ata_scsi_qc_complete;
......
...@@ -449,7 +449,7 @@ static void pdc20621_qc_prep(struct ata_queued_cmd *qc) ...@@ -449,7 +449,7 @@ static void pdc20621_qc_prep(struct ata_queued_cmd *qc)
unsigned int i, last, idx, total_len = 0, sgt_len; unsigned int i, last, idx, total_len = 0, sgt_len;
u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ]; u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
if (!(qc->flags & ATA_QCFLAG_SG)) if (!(qc->flags & ATA_QCFLAG_DMAMAP))
return; return;
VPRINTK("ata%u: ENTER\n", ap->id); VPRINTK("ata%u: ENTER\n", ap->id);
......
...@@ -112,7 +112,9 @@ enum { ...@@ -112,7 +112,9 @@ enum {
ATA_QCFLAG_ACTIVE = (1 << 1), /* cmd not yet ack'd to scsi lyer */ ATA_QCFLAG_ACTIVE = (1 << 1), /* cmd not yet ack'd to scsi lyer */
ATA_QCFLAG_DMA = (1 << 2), /* data delivered via DMA */ ATA_QCFLAG_DMA = (1 << 2), /* data delivered via DMA */
ATA_QCFLAG_SG = (1 << 4), /* have s/g table? */ ATA_QCFLAG_SG = (1 << 3), /* have s/g table? */
ATA_QCFLAG_SINGLE = (1 << 4), /* no s/g, just a single buffer */
ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE,
/* various lengths of time */ /* various lengths of time */
ATA_TMOUT_EDD = 5 * HZ, /* hueristic */ ATA_TMOUT_EDD = 5 * HZ, /* hueristic */
...@@ -216,10 +218,14 @@ struct ata_queued_cmd { ...@@ -216,10 +218,14 @@ struct ata_queued_cmd {
unsigned long flags; /* ATA_QCFLAG_xxx */ unsigned long flags; /* ATA_QCFLAG_xxx */
unsigned int tag; unsigned int tag;
unsigned int n_elem; unsigned int n_elem;
int pci_dma_dir;
unsigned int nsect; unsigned int nsect;
unsigned int cursect; unsigned int cursect;
unsigned int cursg; unsigned int cursg;
unsigned int cursg_ofs; unsigned int cursg_ofs;
struct ata_taskfile tf; struct ata_taskfile tf;
struct scatterlist sgent; struct scatterlist sgent;
......
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