Skip to content

Commit

Permalink
libata: update ->data_xfer hook for ATAPI
Browse files Browse the repository at this point in the history
Depending on how many bytes are transferred as a unit, PIO data
transfer may consume more bytes than requested.  Knowing how much
data is consumed is necessary to determine how much is left for
draining.  This patch update ->data_xfer such that it returns the
number of consumed bytes.

While at it, it also makes the following changes.

* s/adev/dev/
* use READ/WRITE constants for rw indication
* misc clean ups

Signed-off-by: Tejun Heo <htejun@gmail.com>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
  • Loading branch information
Tejun Heo authored and Jeff Garzik committed Jan 23, 2008
1 parent ceb0c64 commit 55dba31
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 102 deletions.
46 changes: 30 additions & 16 deletions drivers/ata/libata-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4994,7 +4994,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)

/**
* ata_data_xfer - Transfer data by PIO
* @adev: device to target
* @dev: device to target
* @buf: data buffer
* @buflen: buffer length
* @write_data: read/write
Expand All @@ -5003,37 +5003,44 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
*
* LOCKING:
* Inherited from caller.
*
* RETURNS:
* Bytes consumed.
*/
void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
unsigned int buflen, int write_data)
unsigned int ata_data_xfer(struct ata_device *dev, unsigned char *buf,
unsigned int buflen, int rw)
{
struct ata_port *ap = adev->link->ap;
struct ata_port *ap = dev->link->ap;
void __iomem *data_addr = ap->ioaddr.data_addr;
unsigned int words = buflen >> 1;

/* Transfer multiple of 2 bytes */
if (write_data)
iowrite16_rep(ap->ioaddr.data_addr, buf, words);
if (rw == READ)
ioread16_rep(data_addr, buf, words);
else
ioread16_rep(ap->ioaddr.data_addr, buf, words);
iowrite16_rep(data_addr, buf, words);

/* Transfer trailing 1 byte, if any. */
if (unlikely(buflen & 0x01)) {
u16 align_buf[1] = { 0 };
unsigned char *trailing_buf = buf + buflen - 1;

if (write_data) {
memcpy(align_buf, trailing_buf, 1);
iowrite16(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr);
} else {
align_buf[0] = cpu_to_le16(ioread16(ap->ioaddr.data_addr));
if (rw == READ) {
align_buf[0] = cpu_to_le16(ioread16(data_addr));
memcpy(trailing_buf, align_buf, 1);
} else {
memcpy(align_buf, trailing_buf, 1);
iowrite16(le16_to_cpu(align_buf[0]), data_addr);
}
words++;
}

return words << 1;
}

/**
* ata_data_xfer_noirq - Transfer data by PIO
* @adev: device to target
* @dev: device to target
* @buf: data buffer
* @buflen: buffer length
* @write_data: read/write
Expand All @@ -5043,14 +5050,21 @@ void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
*
* LOCKING:
* Inherited from caller.
*
* RETURNS:
* Bytes consumed.
*/
void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
unsigned int buflen, int write_data)
unsigned int ata_data_xfer_noirq(struct ata_device *dev, unsigned char *buf,
unsigned int buflen, int rw)
{
unsigned long flags;
unsigned int consumed;

local_irq_save(flags);
ata_data_xfer(adev, buf, buflen, write_data);
consumed = ata_data_xfer(dev, buf, buflen, rw);
local_irq_restore(flags);

return consumed;
}


Expand Down
28 changes: 15 additions & 13 deletions drivers/ata/pata_bf54x.c
Original file line number Diff line number Diff line change
Expand Up @@ -1167,34 +1167,36 @@ static unsigned char bfin_bmdma_status(struct ata_port *ap)
* Note: Original code is ata_data_xfer().
*/

static void bfin_data_xfer(struct ata_device *adev, unsigned char *buf,
unsigned int buflen, int write_data)
static unsigned int bfin_data_xfer(struct ata_device *dev, unsigned char *buf,
unsigned int buflen, int rw)
{
struct ata_port *ap = adev->link->ap;
unsigned int words = buflen >> 1;
unsigned short *buf16 = (u16 *) buf;
struct ata_port *ap = dev->link->ap;
void __iomem *base = (void __iomem *)ap->ioaddr.ctl_addr;
unsigned int words = buflen >> 1;
unsigned short *buf16 = (u16 *)buf;

/* Transfer multiple of 2 bytes */
if (write_data) {
write_atapi_data(base, words, buf16);
} else {
if (rw == READ)
read_atapi_data(base, words, buf16);
}
else
write_atapi_data(base, words, buf16);

/* Transfer trailing 1 byte, if any. */
if (unlikely(buflen & 0x01)) {
unsigned short align_buf[1] = { 0 };
unsigned char *trailing_buf = buf + buflen - 1;

if (write_data) {
memcpy(align_buf, trailing_buf, 1);
write_atapi_data(base, 1, align_buf);
} else {
if (rw == READ) {
read_atapi_data(base, 1, align_buf);
memcpy(trailing_buf, align_buf, 1);
} else {
memcpy(align_buf, trailing_buf, 1);
write_atapi_data(base, 1, align_buf);
}
words++;
}

return words << 1;
}

/**
Expand Down
26 changes: 14 additions & 12 deletions drivers/ata/pata_ixp4xx_cf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ static int ixp4xx_set_mode(struct ata_link *link, struct ata_device **error)
return 0;
}

static void ixp4xx_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
unsigned int buflen, int write_data)
static unsigned int ixp4xx_mmio_data_xfer(struct ata_device *dev,
unsigned char *buf, unsigned int buflen, int rw)
{
unsigned int i;
unsigned int words = buflen >> 1;
u16 *buf16 = (u16 *) buf;
struct ata_port *ap = adev->link->ap;
struct ata_port *ap = dev->link->ap;
void __iomem *mmio = ap->ioaddr.data_addr;
struct ixp4xx_pata_data *data = ap->host->dev->platform_data;

Expand All @@ -59,30 +59,32 @@ static void ixp4xx_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
udelay(100);

/* Transfer multiple of 2 bytes */
if (write_data) {
for (i = 0; i < words; i++)
writew(buf16[i], mmio);
} else {
if (rw == READ)
for (i = 0; i < words; i++)
buf16[i] = readw(mmio);
}
else
for (i = 0; i < words; i++)
writew(buf16[i], mmio);

/* Transfer trailing 1 byte, if any. */
if (unlikely(buflen & 0x01)) {
u16 align_buf[1] = { 0 };
unsigned char *trailing_buf = buf + buflen - 1;

if (write_data) {
memcpy(align_buf, trailing_buf, 1);
writew(align_buf[0], mmio);
} else {
if (rw == READ) {
align_buf[0] = readw(mmio);
memcpy(trailing_buf, align_buf, 1);
} else {
memcpy(align_buf, trailing_buf, 1);
writew(align_buf[0], mmio);
}
words++;
}

udelay(100);
*data->cs0_cfg |= 0x01;

return words << 1;
}

static struct scsi_host_template ixp4xx_sht = {
Expand Down
36 changes: 19 additions & 17 deletions drivers/ata/pata_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,14 @@ static void pdc20230_set_piomode(struct ata_port *ap, struct ata_device *adev)

}

static void pdc_data_xfer_vlb(struct ata_device *adev, unsigned char *buf, unsigned int buflen, int write_data)
static unsigned int pdc_data_xfer_vlb(struct ata_device *dev,
unsigned char *buf, unsigned int buflen, int rw)
{
struct ata_port *ap = adev->link->ap;
int slop = buflen & 3;
unsigned long flags;

if (ata_id_has_dword_io(adev->id)) {
struct ata_port *ap = dev->link->ap;
int slop = buflen & 3;
unsigned long flags;

local_irq_save(flags);

/* Perform the 32bit I/O synchronization sequence */
Expand All @@ -264,26 +265,27 @@ static void pdc_data_xfer_vlb(struct ata_device *adev, unsigned char *buf, unsig
ioread8(ap->ioaddr.nsect_addr);

/* Now the data */

if (write_data)
iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
else
if (rw == READ)
ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
else
iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);

if (unlikely(slop)) {
__le32 pad = 0;
if (write_data) {
memcpy(&pad, buf + buflen - slop, slop);
iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
} else {
u32 pad;
if (rw == READ) {
pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
memcpy(buf + buflen - slop, &pad, slop);
} else {
memcpy(&pad, buf + buflen - slop, slop);
iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
}
buflen += 4 - slop;
}
local_irq_restore(flags);
}
else
ata_data_xfer_noirq(adev, buf, buflen, write_data);
} else
buflen = ata_data_xfer_noirq(dev, buf, buflen, rw);

return buflen;
}

static struct ata_port_operations pdc20230_port_ops = {
Expand Down
30 changes: 17 additions & 13 deletions drivers/ata/pata_qdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,33 @@ static unsigned int qdi_qc_issue_prot(struct ata_queued_cmd *qc)
return ata_qc_issue_prot(qc);
}

static void qdi_data_xfer(struct ata_device *adev, unsigned char *buf, unsigned int buflen, int write_data)
static unsigned int qdi_data_xfer(struct ata_device *dev, unsigned char *buf,
unsigned int buflen, int rw)
{
struct ata_port *ap = adev->link->ap;
int slop = buflen & 3;
if (ata_id_has_dword_io(dev->id)) {
struct ata_port *ap = dev->link->ap;
int slop = buflen & 3;

if (ata_id_has_dword_io(adev->id)) {
if (write_data)
iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
else
if (rw == READ)
ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
else
iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);

if (unlikely(slop)) {
__le32 pad = 0;
if (write_data) {
memcpy(&pad, buf + buflen - slop, slop);
iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
} else {
u32 pad;
if (rw == READ) {
pad = cpu_to_le32(ioread32(ap->ioaddr.data_addr));
memcpy(buf + buflen - slop, &pad, slop);
} else {
memcpy(&pad, buf + buflen - slop, slop);
iowrite32(le32_to_cpu(pad), ap->ioaddr.data_addr);
}
buflen += 4 - slop;
}
} else
ata_data_xfer(adev, buf, buflen, write_data);
buflen = ata_data_xfer(dev, buf, buflen, rw);

return buflen;
}

static struct scsi_host_template qdi_sht = {
Expand Down
30 changes: 16 additions & 14 deletions drivers/ata/pata_scc.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,45 +768,47 @@ static u8 scc_bmdma_status (struct ata_port *ap)

/**
* scc_data_xfer - Transfer data by PIO
* @adev: device for this I/O
* @dev: device for this I/O
* @buf: data buffer
* @buflen: buffer length
* @write_data: read/write
* @rw: read/write
*
* Note: Original code is ata_data_xfer().
*/

static void scc_data_xfer (struct ata_device *adev, unsigned char *buf,
unsigned int buflen, int write_data)
static unsigned int scc_data_xfer (struct ata_device *dev, unsigned char *buf,
unsigned int buflen, int rw)
{
struct ata_port *ap = adev->link->ap;
struct ata_port *ap = dev->link->ap;
unsigned int words = buflen >> 1;
unsigned int i;
u16 *buf16 = (u16 *) buf;
void __iomem *mmio = ap->ioaddr.data_addr;

/* Transfer multiple of 2 bytes */
if (write_data) {
for (i = 0; i < words; i++)
out_be32(mmio, cpu_to_le16(buf16[i]));
} else {
if (rw == READ)
for (i = 0; i < words; i++)
buf16[i] = le16_to_cpu(in_be32(mmio));
}
else
for (i = 0; i < words; i++)
out_be32(mmio, cpu_to_le16(buf16[i]));

/* Transfer trailing 1 byte, if any. */
if (unlikely(buflen & 0x01)) {
u16 align_buf[1] = { 0 };
unsigned char *trailing_buf = buf + buflen - 1;

if (write_data) {
memcpy(align_buf, trailing_buf, 1);
out_be32(mmio, cpu_to_le16(align_buf[0]));
} else {
if (rw == READ) {
align_buf[0] = le16_to_cpu(in_be32(mmio));
memcpy(trailing_buf, align_buf, 1);
} else {
memcpy(align_buf, trailing_buf, 1);
out_be32(mmio, cpu_to_le16(align_buf[0]));
}
words++;
}

return words << 1;
}

/**
Expand Down
Loading

0 comments on commit 55dba31

Please sign in to comment.