mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 02:50:43 +00:00
dmaengine: dw: move residue to a descriptor
Residue is a property of any active descriptor. So, any descriptor may be in different state but residue is a feature of active descriptor. Check if the asked descriptor is active and return proper residue value for it. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
This commit is contained in:
parent
423f9cbf2d
commit
b68fd09762
2 changed files with 41 additions and 21 deletions
|
@ -242,7 +242,7 @@ static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first)
|
||||||
|
|
||||||
dwc_initialize(dwc);
|
dwc_initialize(dwc);
|
||||||
|
|
||||||
dwc->residue = first->total_len;
|
first->residue = first->total_len;
|
||||||
dwc->tx_node_active = &first->tx_list;
|
dwc->tx_node_active = &first->tx_list;
|
||||||
|
|
||||||
/* Submit first block */
|
/* Submit first block */
|
||||||
|
@ -372,11 +372,11 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
|
||||||
|
|
||||||
head = &desc->tx_list;
|
head = &desc->tx_list;
|
||||||
if (active != head) {
|
if (active != head) {
|
||||||
/* Update desc to reflect last sent one */
|
/* Update residue to reflect last sent descriptor */
|
||||||
if (active != head->next)
|
if (active == head->next)
|
||||||
desc = to_dw_desc(active->prev);
|
desc->residue -= desc->len;
|
||||||
|
else
|
||||||
dwc->residue -= desc->len;
|
desc->residue -= to_dw_desc(active->prev)->len;
|
||||||
|
|
||||||
child = to_dw_desc(active);
|
child = to_dw_desc(active);
|
||||||
|
|
||||||
|
@ -391,8 +391,6 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
|
||||||
clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
|
clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
dwc->residue = 0;
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dwc->lock, flags);
|
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||||
|
|
||||||
dwc_complete_all(dw, dwc);
|
dwc_complete_all(dw, dwc);
|
||||||
|
@ -400,7 +398,6 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list_empty(&dwc->active_list)) {
|
if (list_empty(&dwc->active_list)) {
|
||||||
dwc->residue = 0;
|
|
||||||
spin_unlock_irqrestore(&dwc->lock, flags);
|
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -415,7 +412,7 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
|
||||||
|
|
||||||
list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
|
list_for_each_entry_safe(desc, _desc, &dwc->active_list, desc_node) {
|
||||||
/* Initial residue value */
|
/* Initial residue value */
|
||||||
dwc->residue = desc->total_len;
|
desc->residue = desc->total_len;
|
||||||
|
|
||||||
/* Check first descriptors addr */
|
/* Check first descriptors addr */
|
||||||
if (desc->txd.phys == DWC_LLP_LOC(llp)) {
|
if (desc->txd.phys == DWC_LLP_LOC(llp)) {
|
||||||
|
@ -426,20 +423,20 @@ static void dwc_scan_descriptors(struct dw_dma *dw, struct dw_dma_chan *dwc)
|
||||||
/* Check first descriptors llp */
|
/* Check first descriptors llp */
|
||||||
if (lli_read(desc, llp) == llp) {
|
if (lli_read(desc, llp) == llp) {
|
||||||
/* This one is currently in progress */
|
/* This one is currently in progress */
|
||||||
dwc->residue -= dwc_get_sent(dwc);
|
desc->residue -= dwc_get_sent(dwc);
|
||||||
spin_unlock_irqrestore(&dwc->lock, flags);
|
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dwc->residue -= desc->len;
|
desc->residue -= desc->len;
|
||||||
list_for_each_entry(child, &desc->tx_list, desc_node) {
|
list_for_each_entry(child, &desc->tx_list, desc_node) {
|
||||||
if (lli_read(child, llp) == llp) {
|
if (lli_read(child, llp) == llp) {
|
||||||
/* Currently in progress */
|
/* Currently in progress */
|
||||||
dwc->residue -= dwc_get_sent(dwc);
|
desc->residue -= dwc_get_sent(dwc);
|
||||||
spin_unlock_irqrestore(&dwc->lock, flags);
|
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
dwc->residue -= child->len;
|
desc->residue -= child->len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1059,16 +1056,37 @@ static int dwc_terminate_all(struct dma_chan *chan)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline u32 dwc_get_residue(struct dw_dma_chan *dwc)
|
static struct dw_desc *dwc_find_desc(struct dw_dma_chan *dwc, dma_cookie_t c)
|
||||||
{
|
{
|
||||||
|
struct dw_desc *desc;
|
||||||
|
|
||||||
|
list_for_each_entry(desc, &dwc->active_list, desc_node)
|
||||||
|
if (desc->txd.cookie == c)
|
||||||
|
return desc;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static u32 dwc_get_residue(struct dw_dma_chan *dwc, dma_cookie_t cookie)
|
||||||
|
{
|
||||||
|
struct dw_desc *desc;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
u32 residue;
|
u32 residue;
|
||||||
|
|
||||||
spin_lock_irqsave(&dwc->lock, flags);
|
spin_lock_irqsave(&dwc->lock, flags);
|
||||||
|
|
||||||
residue = dwc->residue;
|
desc = dwc_find_desc(dwc, cookie);
|
||||||
if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue)
|
if (desc) {
|
||||||
residue -= dwc_get_sent(dwc);
|
if (desc == dwc_first_active(dwc)) {
|
||||||
|
residue = desc->residue;
|
||||||
|
if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags) && residue)
|
||||||
|
residue -= dwc_get_sent(dwc);
|
||||||
|
} else {
|
||||||
|
residue = desc->total_len;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
residue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&dwc->lock, flags);
|
spin_unlock_irqrestore(&dwc->lock, flags);
|
||||||
return residue;
|
return residue;
|
||||||
|
@ -1089,8 +1107,10 @@ dwc_tx_status(struct dma_chan *chan,
|
||||||
dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
|
dwc_scan_descriptors(to_dw_dma(chan->device), dwc);
|
||||||
|
|
||||||
ret = dma_cookie_status(chan, cookie, txstate);
|
ret = dma_cookie_status(chan, cookie, txstate);
|
||||||
if (ret != DMA_COMPLETE)
|
if (ret == DMA_COMPLETE)
|
||||||
dma_set_residue(txstate, dwc_get_residue(dwc));
|
return ret;
|
||||||
|
|
||||||
|
dma_set_residue(txstate, dwc_get_residue(dwc, cookie));
|
||||||
|
|
||||||
if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags) && ret == DMA_IN_PROGRESS)
|
if (test_bit(DW_DMA_IS_PAUSED, &dwc->flags) && ret == DMA_IN_PROGRESS)
|
||||||
return DMA_PAUSED;
|
return DMA_PAUSED;
|
||||||
|
|
|
@ -237,7 +237,6 @@ struct dw_dma_chan {
|
||||||
struct list_head active_list;
|
struct list_head active_list;
|
||||||
struct list_head queue;
|
struct list_head queue;
|
||||||
struct list_head free_list;
|
struct list_head free_list;
|
||||||
u32 residue;
|
|
||||||
struct dw_cyclic_desc *cdesc;
|
struct dw_cyclic_desc *cdesc;
|
||||||
|
|
||||||
unsigned int descs_allocated;
|
unsigned int descs_allocated;
|
||||||
|
@ -352,6 +351,7 @@ struct dw_desc {
|
||||||
struct dma_async_tx_descriptor txd;
|
struct dma_async_tx_descriptor txd;
|
||||||
size_t len;
|
size_t len;
|
||||||
size_t total_len;
|
size_t total_len;
|
||||||
|
u32 residue;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node)
|
#define to_dw_desc(h) list_entry(h, struct dw_desc, desc_node)
|
||||||
|
|
Loading…
Reference in a new issue