Commit e3923592 authored by Alexandru Ardelean's avatar Alexandru Ardelean Committed by Vinod Koul

dmaengine: axi-dmac: populate residue info for completed xfers

Starting with version 4.2.a, the AXI DMAC controller can report partial
transfers that have been issued.

This change implements computing DMA residue information for transfers,
based on that reported information.

The way this is done, is to dequeue the partial transfers from the FIFO of
partial transfers, store the partial length to the correct segment &
descriptor, and compute the residue before submitting the DMA cookie to the
DMA framework.
Signed-off-by: default avatarAlexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent 09d5b702
...@@ -63,6 +63,8 @@ ...@@ -63,6 +63,8 @@
#define AXI_DMAC_REG_STATUS 0x430 #define AXI_DMAC_REG_STATUS 0x430
#define AXI_DMAC_REG_CURRENT_SRC_ADDR 0x434 #define AXI_DMAC_REG_CURRENT_SRC_ADDR 0x434
#define AXI_DMAC_REG_CURRENT_DEST_ADDR 0x438 #define AXI_DMAC_REG_CURRENT_DEST_ADDR 0x438
#define AXI_DMAC_REG_PARTIAL_XFER_LEN 0x44c
#define AXI_DMAC_REG_PARTIAL_XFER_ID 0x450
#define AXI_DMAC_CTRL_ENABLE BIT(0) #define AXI_DMAC_CTRL_ENABLE BIT(0)
#define AXI_DMAC_CTRL_PAUSE BIT(1) #define AXI_DMAC_CTRL_PAUSE BIT(1)
...@@ -72,6 +74,9 @@ ...@@ -72,6 +74,9 @@
#define AXI_DMAC_FLAG_CYCLIC BIT(0) #define AXI_DMAC_FLAG_CYCLIC BIT(0)
#define AXI_DMAC_FLAG_LAST BIT(1) #define AXI_DMAC_FLAG_LAST BIT(1)
#define AXI_DMAC_FLAG_PARTIAL_REPORT BIT(2)
#define AXI_DMAC_FLAG_PARTIAL_XFER_DONE BIT(31)
/* The maximum ID allocated by the hardware is 31 */ /* The maximum ID allocated by the hardware is 31 */
#define AXI_DMAC_SG_UNUSED 32U #define AXI_DMAC_SG_UNUSED 32U
...@@ -84,6 +89,7 @@ struct axi_dmac_sg { ...@@ -84,6 +89,7 @@ struct axi_dmac_sg {
unsigned int dest_stride; unsigned int dest_stride;
unsigned int src_stride; unsigned int src_stride;
unsigned int id; unsigned int id;
unsigned int partial_len;
bool schedule_when_free; bool schedule_when_free;
}; };
...@@ -113,6 +119,7 @@ struct axi_dmac_chan { ...@@ -113,6 +119,7 @@ struct axi_dmac_chan {
unsigned int address_align_mask; unsigned int address_align_mask;
unsigned int length_align_mask; unsigned int length_align_mask;
bool hw_partial_xfer;
bool hw_cyclic; bool hw_cyclic;
bool hw_2d; bool hw_2d;
}; };
...@@ -244,6 +251,9 @@ static void axi_dmac_start_transfer(struct axi_dmac_chan *chan) ...@@ -244,6 +251,9 @@ static void axi_dmac_start_transfer(struct axi_dmac_chan *chan)
desc->num_sgs == 1) desc->num_sgs == 1)
flags |= AXI_DMAC_FLAG_CYCLIC; flags |= AXI_DMAC_FLAG_CYCLIC;
if (chan->hw_partial_xfer)
flags |= AXI_DMAC_FLAG_PARTIAL_REPORT;
axi_dmac_write(dmac, AXI_DMAC_REG_X_LENGTH, sg->x_len - 1); axi_dmac_write(dmac, AXI_DMAC_REG_X_LENGTH, sg->x_len - 1);
axi_dmac_write(dmac, AXI_DMAC_REG_Y_LENGTH, sg->y_len - 1); axi_dmac_write(dmac, AXI_DMAC_REG_Y_LENGTH, sg->y_len - 1);
axi_dmac_write(dmac, AXI_DMAC_REG_FLAGS, flags); axi_dmac_write(dmac, AXI_DMAC_REG_FLAGS, flags);
...@@ -256,6 +266,82 @@ static struct axi_dmac_desc *axi_dmac_active_desc(struct axi_dmac_chan *chan) ...@@ -256,6 +266,82 @@ static struct axi_dmac_desc *axi_dmac_active_desc(struct axi_dmac_chan *chan)
struct axi_dmac_desc, vdesc.node); struct axi_dmac_desc, vdesc.node);
} }
static inline unsigned int axi_dmac_total_sg_bytes(struct axi_dmac_chan *chan,
struct axi_dmac_sg *sg)
{
if (chan->hw_2d)
return sg->x_len * sg->y_len;
else
return sg->x_len;
}
static void axi_dmac_dequeue_partial_xfers(struct axi_dmac_chan *chan)
{
struct axi_dmac *dmac = chan_to_axi_dmac(chan);
struct axi_dmac_desc *desc;
struct axi_dmac_sg *sg;
u32 xfer_done, len, id, i;
bool found_sg;
do {
len = axi_dmac_read(dmac, AXI_DMAC_REG_PARTIAL_XFER_LEN);
id = axi_dmac_read(dmac, AXI_DMAC_REG_PARTIAL_XFER_ID);
found_sg = false;
list_for_each_entry(desc, &chan->active_descs, vdesc.node) {
for (i = 0; i < desc->num_sgs; i++) {
sg = &desc->sg[i];
if (sg->id == AXI_DMAC_SG_UNUSED)
continue;
if (sg->id == id) {
sg->partial_len = len;
found_sg = true;
break;
}
}
if (found_sg)
break;
}
if (found_sg) {
dev_dbg(dmac->dma_dev.dev,
"Found partial segment id=%u, len=%u\n",
id, len);
} else {
dev_warn(dmac->dma_dev.dev,
"Not found partial segment id=%u, len=%u\n",
id, len);
}
/* Check if we have any more partial transfers */
xfer_done = axi_dmac_read(dmac, AXI_DMAC_REG_TRANSFER_DONE);
xfer_done = !(xfer_done & AXI_DMAC_FLAG_PARTIAL_XFER_DONE);
} while (!xfer_done);
}
static void axi_dmac_compute_residue(struct axi_dmac_chan *chan,
struct axi_dmac_desc *active)
{
struct dmaengine_result *rslt = &active->vdesc.tx_result;
unsigned int start = active->num_completed - 1;
struct axi_dmac_sg *sg;
unsigned int i, total;
rslt->result = DMA_TRANS_NOERROR;
rslt->residue = 0;
/*
* We get here if the last completed segment is partial, which
* means we can compute the residue from that segment onwards
*/
for (i = start; i < active->num_sgs; i++) {
sg = &active->sg[i];
total = axi_dmac_total_sg_bytes(chan, sg);
rslt->residue += (total - sg->partial_len);
}
}
static bool axi_dmac_transfer_done(struct axi_dmac_chan *chan, static bool axi_dmac_transfer_done(struct axi_dmac_chan *chan,
unsigned int completed_transfers) unsigned int completed_transfers)
{ {
...@@ -267,6 +353,10 @@ static bool axi_dmac_transfer_done(struct axi_dmac_chan *chan, ...@@ -267,6 +353,10 @@ static bool axi_dmac_transfer_done(struct axi_dmac_chan *chan,
if (!active) if (!active)
return false; return false;
if (chan->hw_partial_xfer &&
(completed_transfers & AXI_DMAC_FLAG_PARTIAL_XFER_DONE))
axi_dmac_dequeue_partial_xfers(chan);
do { do {
sg = &active->sg[active->num_completed]; sg = &active->sg[active->num_completed];
if (sg->id == AXI_DMAC_SG_UNUSED) /* Not yet submitted */ if (sg->id == AXI_DMAC_SG_UNUSED) /* Not yet submitted */
...@@ -280,10 +370,14 @@ static bool axi_dmac_transfer_done(struct axi_dmac_chan *chan, ...@@ -280,10 +370,14 @@ static bool axi_dmac_transfer_done(struct axi_dmac_chan *chan,
start_next = true; start_next = true;
} }
if (sg->partial_len)
axi_dmac_compute_residue(chan, active);
if (active->cyclic) if (active->cyclic)
vchan_cyclic_callback(&active->vdesc); vchan_cyclic_callback(&active->vdesc);
if (active->num_completed == active->num_sgs) { if (active->num_completed == active->num_sgs ||
sg->partial_len) {
if (active->cyclic) { if (active->cyclic) {
active->num_completed = 0; /* wrap around */ active->num_completed = 0; /* wrap around */
} else { } else {
...@@ -674,6 +768,9 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac) ...@@ -674,6 +768,9 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac)
return -ENODEV; return -ENODEV;
} }
if (version >= ADI_AXI_PCORE_VER(4, 2, 'a'))
chan->hw_partial_xfer = true;
if (version >= ADI_AXI_PCORE_VER(4, 1, 'a')) { if (version >= ADI_AXI_PCORE_VER(4, 1, 'a')) {
axi_dmac_write(dmac, AXI_DMAC_REG_X_LENGTH, 0x00); axi_dmac_write(dmac, AXI_DMAC_REG_X_LENGTH, 0x00);
chan->length_align_mask = chan->length_align_mask =
......
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