dw_dmac: fill len field of the descriptor
PATCH 1/2 dw_dmac: fill len field of the descriptor
It will be useful to have the length of the transfer in the descriptor. The cyclic transfer functions remained untouched.
--- drivers/dma/dw_dmac.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/dma/dw_dmac.c +3 -0
@@ -754,6 +754,7 @@ dwc_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src, first = desc; }else { prev->lli.llp = desc->txd.phys; + desc->len = xfer_count << src_width;list_add_tail (&desc->desc_node, &first->tx_list); }
@@ -852,6 +853,7 @@ slave_sg_todev_fill_desc: first = desc; }else { prev->lli.llp = desc->txd.phys; + desc->len = dlen;list_add_tail (&desc->desc_node, &first->tx_list); }
@@ -910,6 +912,7 @@ slave_sg_fromdev_fill_desc: first = desc; }else { prev->lli.llp = desc->txd.phys; + desc->len = dlen;list_add_tail (&desc->desc_node, &first->tx_list); }
Signature · 1 line
1.7.10.4
PATCH 2/2 dw_dmac: return proper residue value
Currently the driver returns full length of the active descriptor which is wrong. We have to go throught the active descriptor and sum up the length of unsent children in the chain along with the actual data in the DMA channel registers.
The cyclic case is not handled by this patch due to len field in the descriptor structure is left untouched by the original code.
--- drivers/dma/dw_dmac.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)
drivers/dma/dw_dmac.c +92 -1
@@ -941,6 +941,97 @@ err_desc_get:return NULL ; } +/* --------------------- Calculate residue ---------------------------- */ + +static inline size_t dwc_get_rest (struct dw_dma_chan *dwc,struct dw_desc *desc) +{ +enum dma_transfer_direction direction = dwc->direction; + +if (direction ==DMA_MEM_TO_DEV || direction ==DMA_MEM_TO_MEM ) +return desc->len - (channel_readl (dwc,SAR ) - desc->lli.sar); +else if (direction ==DMA_DEV_TO_MEM ) +return desc->len - (channel_readl (dwc,DAR ) - desc->lli.dar); + +return 0 ; +} + +static inline size_t dwc_get_residue_in_llp (struct dw_dma_chan *dwc, +struct list_head *active, +struct list_head *head) +{ +size_t residue =dwc_get_rest (dwc,to_dw_desc (active)); + +do { + active = active->next; +if (active == head) +break ; + residue +=to_dw_desc (active)->len; + }while (true); + +return residue; +} + +static size_t dwc_calc_residue_llp_hw (struct dw_dma_chan *dwc) +{ +struct dw_desc *desc =dwc_first_active (dwc); +struct list_head *head = &desc->tx_list, *active; +dma_addr_t llp =channel_readl (dwc,LLP ); + +/* The transfer didn't start yet */ +if (unlikely (desc->txd.phys == llp)) +return desc->len; + +/* First descriptor is active */ +if (desc->lli.llp == llp) +return dwc_get_rest (dwc, desc); + +/* Somewhere in the middle */ +list_for_each (active, head) +if (to_dw_desc (active)->lli.llp == llp) +return dwc_get_residue_in_llp (dwc, active, head); + +return 0 ; +} + +static size_t dwc_calc_residue_llp_sw (struct dw_dma_chan *dwc) +{ +struct dw_desc *desc =dwc_first_active (dwc); +struct list_head *head = dwc->tx_list, *active; + + active = dwc->tx_node_active; + +/* First node is active */ +if (active == head->next) +return dwc_get_rest (dwc, desc); + +/* Last node is active */ +if (active == head) +return dwc_get_rest (dwc,to_dw_desc (active->prev)); + +/* Somewhere in the middle */ +return dwc_get_residue_in_llp (dwc, active, head); +} + +static size_t dwc_get_residue (struct dw_dma_chan *dwc) +{ +unsigned long flags; +size_t residue =0 ; + +spin_lock_irqsave (&dwc->lock, flags); +if (list_empty (&dwc->active_list)) { +spin_unlock_irqrestore (&dwc->lock, flags); +return 0 ; + } + +if (test_bit (DW_DMA_IS_SOFT_LLP , &dwc->flags)) + residue =dwc_calc_residue_llp_sw (dwc); +else if (!test_bit (DW_DMA_IS_CYCLIC , &dwc->flags)) + residue =dwc_calc_residue_llp_hw (dwc); + +spin_unlock_irqrestore (&dwc->lock, flags); +return residue; +} +/* * Fix sconfig's burst size according to dw_dmac. We need to convert them as: * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
@@ -1062,7 +1153,7 @@ dwc_tx_status(struct dma_chan *chan, }if (ret !=DMA_SUCCESS ) -dma_set_residue (txstate,dwc_first_active (dwc)->len); +dma_set_residue (txstate,dwc_get_residue (dwc));if (dwc->paused)return DMA_PAUSED ;
Signature · 1 line
1.7.10.4
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 3 lines · Andy Shevchenko
Currently the driver returns full length of the active descriptor which is wrong. We have to go throught the active descriptor and sum up the length of unsent children in the chain along with the actual data in the DMA channel
why do you mean by children here?
Quoted 20 lines
registers.
The cyclic case is not handled by this patch due to len field in the descriptor structure is left untouched by the original code.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/dma/dw_dmac.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)drivers/dma/dw_dmac.c +2
-0@@ -941,6 +941,97 @@ err_desc_get:return NULL ; } +/* --------------------- Calculate residue ---------------------------- */ +
drivers/dma/dw_dmac.c err_desc_get: · line 955
Quoted 10 lines
drivers/dma/dw_dmac.c +10
-0+static inline size_t dwc_get_rest (struct dw_dma_chan *dwc,struct dw_desc *desc) +{ +enum dma_transfer_direction direction = dwc->direction; + +if (direction ==DMA_MEM_TO_DEV || direction ==DMA_MEM_TO_MEM ) +return desc->len - (channel_readl (dwc,SAR ) - desc->lli.sar); +else if (direction ==DMA_DEV_TO_MEM ) +return desc->len - (channel_readl (dwc,DAR ) - desc->lli.dar); + +return 0 ;
hmmm, why not use BLOCK_TS value. That way you dont need to look at direction and along with burst can easily calculate residue...
--
~Vinod
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 5 lines · Vinod Koul
Quoted 3 lines · Andy Shevchenko
Currently the driver returns full length of the active descriptor which is wrong. We have to go throught the active descriptor and sum up the length of unsent children in the chain along with the actual data in the DMA channel
why do you mean by children here?
The list nodes chained under (active) &desc->tx_list.
Quoted 18 lines
Quoted 18 lines
registers.
The cyclic case is not handled by this patch due to len field in the descriptor structure is left untouched by the original code.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/dma/dw_dmac.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)drivers/dma/dw_dmac.c +0
-0@@ -941,6 +941,97 @@ err_desc_get:return NULL ; }
Quoted 14 lines
drivers/dma/dw_dmac.c err_desc_get: · line 955
Quoted 12 lines
drivers/dma/dw_dmac.c +12
-0+/* --------------------- Calculate residue ---------------------------- */ + +static inline size_t dwc_get_rest (struct dw_dma_chan *dwc,struct dw_desc *desc) +{ +enum dma_transfer_direction direction = dwc->direction; + +if (direction ==DMA_MEM_TO_DEV || direction ==DMA_MEM_TO_MEM ) +return desc->len - (channel_readl (dwc,SAR ) - desc->lli.sar); +else if (direction ==DMA_DEV_TO_MEM ) +return desc->len - (channel_readl (dwc,DAR ) - desc->lli.dar); + +return 0 ;hmmm, why not use
BLOCK_TSvalue. That way you dont need to look at direction and along with burst can easily calculate residue...
Do you mean to read CTL hi/lo and do
desc->len - ctlhi.block_ts * ctllo.src_tr_width?
I think it could be not precise when memory-to-peripheral transfer is going on. In that case you probably will have src_tr_width like 32 bits, meanwhile peripheral may receive only byte stream.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;hmmm, why not use
BLOCK_TSvalue. That way you dont need to look at direction and along with burst can easily calculate residue...Do you mean to read CTL hi/lo and do
desc->len- ctlhi.block_ts * ctllo.src_tr_width?
Yes
Quoted 3 lines
I think it could be not precise when memory-to-peripheral transfer is going on. In that case you probably will have
src_tr_widthlike 32 bits, meanwhile peripheral may receive only byte stream.
Nope that is not the case.
SAR/DAR is always incremented in src/dstn_tr_width granularity. For example if you are using MEM to DMA, then SAR will always increment in case of x86 in 4byte granularity as we will read bursts not singles.
Also if check the spec, it says "Once the transfer starts, the read-back value is the total number of data items already read from the source peripheral, regardless of what is the flow controller"
So basically you get what is read from buffer in case of MEM->PER and get what is read from FIFO in case of PER->MEM which IMO gives you better or equal results than your calulation.
--
~Vinod
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 18 lines · Vinod Koul
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ return 0;hmmm, why not use
BLOCK_TSvalue. That way you dont need to look at direction and along with burst can easily calculate residue...Do you mean to read CTL hi/lo and do
desc->len- ctlhi.block_ts * ctllo.src_tr_width?Yes
Quoted 3 lines
I think it could be not precise when memory-to-peripheral transfer is going on. In that case you probably will have
src_tr_widthlike 32 bits, meanwhile peripheral may receive only byte stream.Nope that is not the case.
SAR/DAR is always incremented in src/dstn_tr_width granularity. For example if you are using MEM to DMA, then SAR will always increment in case of x86 in 4byte granularity as we will read bursts not singles.
Quoted 7 lines
Also if check the spec, it says "Once the transfer starts, the read-back value is the total number of data items already read from the source peripheral, regardless of what is the flow controller"
So basically you get what is read from buffer in case of
MEM->PERand get what is read from FIFO in case ofPER->MEMwhich IMO gives you better or equal results than your calulation.
I will try this. Indeed I don't like usage of direction as well, and your solution seems much clear in that sense.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH 2/2] dw_dmac: return proper residue value
In reply to Andy ShevchenkoQuoted 24 lines · Andy Shevchenko
Currently the driver returns full length of the active descriptor which is wrong. We have to go throught the active descriptor and sum up the length of unsent children in the chain along with the actual data in the DMA channel registers.
The cyclic case is not handled by this patch due to len field in the descriptor structure is left untouched by the original code.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/dma/dw_dmac.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)drivers/dma/dw_dmac.c +3
-0@@ -941,6 +941,97 @@ err_desc_get:return NULL ; } +/* --------------------- Calculate residue ---------------------------- */ + +static inline size_t dwc_get_rest (struct dw_dma_chan *dwc,struct dw_desc *desc)
drivers/dma/dw_dmac.c err_desc_get: · line 956
Quoted 10 lines
drivers/dma/dw_dmac.c +10
-0+{ +enum dma_transfer_direction direction = dwc->direction; + +if (direction ==DMA_MEM_TO_DEV || direction ==DMA_MEM_TO_MEM ) +return desc->len - (channel_readl (dwc,SAR ) - desc->lli.sar); +else if (direction ==DMA_DEV_TO_MEM ) +return desc->len - (channel_readl (dwc,DAR ) - desc->lli.dar); + +return 0 ; +}
I agree with Vinod on this routine.
Quoted 48 lines
drivers/dma/dw_dmac.c +48
-0+static inline size_t dwc_get_residue_in_llp (struct dw_dma_chan *dwc, +struct list_head *active, +struct list_head *head) +{ +size_t residue =dwc_get_rest (dwc,to_dw_desc (active)); + +do { + active = active->next; +if (active == head) +break ; + residue +=to_dw_desc (active)->len; + }while (true); + +return residue; +} + +static size_t dwc_calc_residue_llp_hw (struct dw_dma_chan *dwc) +{ +struct dw_desc *desc =dwc_first_active (dwc); +struct list_head *head = &desc->tx_list, *active; +dma_addr_t llp =channel_readl (dwc,LLP ); + +/* The transfer didn't start yet */ +if (unlikely (desc->txd.phys == llp)) +return desc->len; + +/* First descriptor is active */ +if (desc->lli.llp == llp) +return dwc_get_rest (dwc, desc); + +/* Somewhere in the middle */ +list_for_each (active, head) +if (to_dw_desc (active)->lli.llp == llp) +return dwc_get_residue_in_llp (dwc, active, head); + +return 0 ; +} + +static size_t dwc_calc_residue_llp_sw (struct dw_dma_chan *dwc) +{ +struct dw_desc *desc =dwc_first_active (dwc); +struct list_head *head = dwc->tx_list, *active; + + active = dwc->tx_node_active; + +/* First node is active */ +if (active == head->next) +return dwc_get_rest (dwc, desc);
drivers/dma/dw_dmac.c err_desc_get: · line 1015
Quoted 10 lines
drivers/dma/dw_dmac.c +10
-0+ +/* Last node is active */ +if (active == head) +return dwc_get_rest (dwc,to_dw_desc (active->prev)); + +/* Somewhere in the middle */ +return dwc_get_residue_in_llp (dwc, active, head); +} + +static size_t dwc_get_residue (struct dw_dma_chan *dwc)
return u32, that's the type of residue field.
drivers/dma/dw_dmac.c err_desc_get: · line 1018
Quoted 3 lines
drivers/dma/dw_dmac.c +3
-0+{ +unsigned long flags; +size_t residue =0 ;
ditto.
drivers/dma/dw_dmac.c err_desc_get: · line 1021
Quoted 3 lines
drivers/dma/dw_dmac.c +3
-0+ +spin_lock_irqsave (&dwc->lock, flags); +if (list_empty (&dwc->active_list)) {
can this every happen?
drivers/dma/dw_dmac.c err_desc_get: · line 1029
Quoted 8 lines
drivers/dma/dw_dmac.c +8
-0+spin_unlock_irqrestore (&dwc->lock, flags); +return 0 ; + } + +if (test_bit (DW_DMA_IS_SOFT_LLP , &dwc->flags)) + residue =dwc_calc_residue_llp_sw (dwc); +else if (!test_bit (DW_DMA_IS_CYCLIC , &dwc->flags)) + residue =dwc_calc_residue_llp_hw (dwc);
Hmm. you return zero for cyclic transfers, shouldn't that be the total length instead?
Over that, cyclic case can be handled before taking any locks.
Quoted 9 lines
drivers/dma/dw_dmac.c +5
-0+ +spin_unlock_irqrestore (&dwc->lock, flags); +return residue; +} +/* * Fix sconfig's burst size according to dw_dmac. We need to convert them as: * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3.
drivers/dma/dw_dmac.c dwc_tx_status(struct dma_chan *chan, · line 1156
Quoted 5 lines
drivers/dma/dw_dmac.c +1
-1@@ -1062,7 +1153,7 @@ dwc_tx_status(struct dma_chan *chan, }if (ret !=DMA_SUCCESS ) -dma_set_residue (txstate,dwc_first_active (dwc)->len); +dma_set_residue (txstate,dwc_get_residue (dwc));
Hmm.. After thinking a bit more on this, i am not sure if what u have done is the best way of doing it :(
Just before above line got executed, we called dwc_scan_descriptors(), which also scans through the llis to see where we are.. What about updating first->residue
there, so that we don't traverse it twice?
Quoted 6 lines
drivers/dma/dw_dmac.c +0
-1if (dwc->paused)return DMA_PAUSED ; --1.7.10.4
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 23 lines · Viresh Kumar
Quoted 21 lines · Andy Shevchenko
Currently the driver returns full length of the active descriptor which is wrong. We have to go throught the active descriptor and sum up the length of unsent children in the chain along with the actual data in the DMA channel registers.
The cyclic case is not handled by this patch due to len field in the descriptor structure is left untouched by the original code.
Signed-off-by Andy Shevchenko <[email protected]>--- drivers/dma/dw_dmac.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-)drivers/dma/dw_dmac.c +0
-0@@ -941,6 +941,97 @@ err_desc_get:return NULL ; }
Quoted 15 lines
drivers/dma/dw_dmac.c err_desc_get: · line 956
Quoted 13 lines
drivers/dma/dw_dmac.c +13
-0+/* --------------------- Calculate residue ---------------------------- */ + +static inline size_t dwc_get_rest (struct dw_dma_chan *dwc,struct dw_desc *desc) +{ +enum dma_transfer_direction direction = dwc->direction; + +if (direction ==DMA_MEM_TO_DEV || direction ==DMA_MEM_TO_MEM ) +return desc->len - (channel_readl (dwc,SAR ) - desc->lli.sar); +else if (direction ==DMA_DEV_TO_MEM ) +return desc->len - (channel_readl (dwc,DAR ) - desc->lli.dar); + +return 0 ; +}I agree with Vinod on this routine.
I'm checking this now. But on first glance his proposal is quite better.
Quoted 52 lines
Quoted 52 lines
drivers/dma/dw_dmac.c +52
-0+static inline size_t dwc_get_residue_in_llp (struct dw_dma_chan *dwc, +struct list_head *active, +struct list_head *head) +{ +size_t residue =dwc_get_rest (dwc,to_dw_desc (active)); + +do { + active = active->next; +if (active == head) +break ; + residue +=to_dw_desc (active)->len; + }while (true); + +return residue; +} + +static size_t dwc_calc_residue_llp_hw (struct dw_dma_chan *dwc) +{ +struct dw_desc *desc =dwc_first_active (dwc); +struct list_head *head = &desc->tx_list, *active; +dma_addr_t llp =channel_readl (dwc,LLP ); + +/* The transfer didn't start yet */ +if (unlikely (desc->txd.phys == llp)) +return desc->len; + +/* First descriptor is active */ +if (desc->lli.llp == llp) +return dwc_get_rest (dwc, desc); + +/* Somewhere in the middle */ +list_for_each (active, head) +if (to_dw_desc (active)->lli.llp == llp) +return dwc_get_residue_in_llp (dwc, active, head); + +return 0 ; +} + +static size_t dwc_calc_residue_llp_sw (struct dw_dma_chan *dwc) +{ +struct dw_desc *desc =dwc_first_active (dwc); +struct list_head *head = dwc->tx_list, *active; + + active = dwc->tx_node_active; + +/* First node is active */ +if (active == head->next) +return dwc_get_rest (dwc, desc); + +/* Last node is active */ +if (active == head) +return dwc_get_rest (dwc,to_dw_desc (active->prev));
Quoted 8 lines
drivers/dma/dw_dmac.c err_desc_get: · line 1015
Quoted 6 lines
drivers/dma/dw_dmac.c +6
-0+ +/* Somewhere in the middle */ +return dwc_get_residue_in_llp (dwc, active, head); +} + +static size_t dwc_get_residue (struct dw_dma_chan *dwc)return u32, that's the type of residue field.
Hmm... I didn't remember where I got size_t for that, but you are right. I'll fix that across the code.
Quoted 5 lines
drivers/dma/dw_dmac.c err_desc_get: · line 1018
Quoted 4 lines
drivers/dma/dw_dmac.c +3
-0+{ +unsigned long flags; +size_t residue =0 ;
Quoted 7 lines
ditto.
drivers/dma/dw_dmac.c err_desc_get: · line 1021
Quoted 3 lines
drivers/dma/dw_dmac.c +3
-0+ +spin_lock_irqsave (&dwc->lock, flags); +if (list_empty (&dwc->active_list)) {can this every happen?
In the same way as in dwc_scan_descriptors().
For example when transfer is done.
Quoted 11 lines
drivers/dma/dw_dmac.c err_desc_get: · line 1029
Quoted 8 lines
drivers/dma/dw_dmac.c +8
-0+spin_unlock_irqrestore (&dwc->lock, flags); +return 0 ; + } + +if (test_bit (DW_DMA_IS_SOFT_LLP , &dwc->flags)) + residue =dwc_calc_residue_llp_sw (dwc); +else if (!test_bit (DW_DMA_IS_CYCLIC , &dwc->flags)) + residue =dwc_calc_residue_llp_hw (dwc);Hmm. you return zero for cyclic transfers, shouldn't that be the total length instead?
Total length is zero as I mentioned in commit message. The cyclic API should be fixed separately if someone wants to have such functionality of it.
Quoted 1 line
Over that, cyclic case can be handled before taking any locks.
Does the user is responsible to follow specific workflow for cyclic API? However, it isn't related to current topic. I will move it out of spinlock.
Quoted 11 lines
Quoted 11 lines
drivers/dma/dw_dmac.c +5
-0+ +spin_unlock_irqrestore (&dwc->lock, flags); +return residue; +} +/* * Fix sconfig's burst size according to dw_dmac. We need to convert them as: * 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3. @@ -1062,7 +1153,7 @@ dwc_tx_status(struct dma_chan *chan, }
Quoted 6 lines
drivers/dma/dw_dmac.c dwc_tx_status(struct dma_chan *chan, · line 1156
Quoted 3 lines
drivers/dma/dw_dmac.c +1
-1if (ret !=DMA_SUCCESS ) -dma_set_residue (txstate,dwc_first_active (dwc)->len); +dma_set_residue (txstate,dwc_get_residue (dwc));Hmm.. After thinking a bit more on this, i am not sure if what u have done is the best way of doing it :(
At least it works for us :-)
Quoted 5 lines
Just before above line got executed, we called
dwc_scan_descriptors(), which also scans through the llis to see where we are.. What about updatingfirst->residue
there, so that we don't traverse it twice?
The dwc_scan_descriptors traverses the chain and returns immediately if it found a match. But to calculate residue we have to traverse from that point to the end of the chain along with current DMA register check.
Quoted 3 lines
Quoted 3 lines
drivers/dma/dw_dmac.c +0
-0if (dwc->paused)return DMA_PAUSED ;
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 8 lines · Andy Shevchenko
Quoted 4 lines · Viresh Kumar
drivers/dma/dw_dmac.c err_desc_get: · line 1021
Quoted 2 lines
drivers/dma/dw_dmac.c +2
-0+spin_lock_irqsave (&dwc->lock, flags); +if (list_empty (&dwc->active_list)) {can this every happen?
In the same way as in
dwc_scan_descriptors().
For example when transfer is done.
My point was, because scan_descriptor() is just called, if the transfer is over by now, we must have returned back, else we reach this place and so this may never be true.
Quoted 3 lines
Quoted 1 line
Over that, cyclic case can be handled before taking any locks.
Does the user is responsible to follow specific workflow for cyclic API?
not sure.
Quoted 8 lines
Quoted 4 lines
Just before above line got executed, we called
dwc_scan_descriptors(), which also scans through the llis to see where we are.. What about updatingfirst->residue
there, so that we don't traverse it twice?The
dwc_scan_descriptorstraverses the chain and returns immediately if it found a match. But to calculate residue we have to traverse from that point to the end of the chain along with current DMA register check.
Hey, you can start subtracting individual lengths of descriptors from total length
in scan descriptors() and that should give you what you want.
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 6 lines · Viresh Kumar
Quoted 4 lines · Andy Shevchenko
Quoted 3 lines · Viresh Kumar
Quoted 2 lines
drivers/dma/dw_dmac.c +2
-0+spin_lock_irqsave (&dwc->lock, flags); +if (list_empty (&dwc->active_list)) {
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
can this every happen?
In the same way as in
dwc_scan_descriptors().
For example when transfer is done.My point was, because
scan_descriptor()is just called, if the transfer is over by now, we must have returned back, else we reach this place and so this may never be true.
Ah, you mean the dma_cookie_status returns DMA_SUCCESS in case active_list is empty, don't you?
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Over that, cyclic case can be handled before taking any locks.
Does the user is responsible to follow specific workflow for cyclic API?
not sure.
I have no test cases against cyclic API, so I may assume that it doesn't require locking for that bit.
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Just before above line got executed, we called
dwc_scan_descriptors(), which also scans through the llis to see where we are.. What about updatingfirst->residue
there, so that we don't traverse it twice?
Quoted 7 lines
Quoted 3 lines
The
dwc_scan_descriptorstraverses the chain and returns immediately if it found a match. But to calculate residue we have to traverse from that point to the end of the chain along with current DMA register check.Hey, you can start subtracting individual lengths of descriptors from total length
in scandescriptors()and that should give you what you want.
Yesterday I spent in testing of different approaches. First of all, the calculation of the sent amount is nicer when ctlhi/ctllo is used and it works fine. But the approach, when we substract length of sent descriptors, is losing data. Namely, we have no information how big is the master descriptor (it has total length of the entire chain). So, I'm thinking how to solve this one. Otherwise it seems simpler than mine first idea.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 2 lines · Andy Shevchenko
Ah, you mean the
dma_cookie_statusreturnsDMA_SUCCESSin caseactive_listis empty, don't you?
Bingo!!
Quoted 7 lines
Yesterday I spent in testing of different approaches. First of all, the calculation of the sent amount is nicer when ctlhi/ctllo is used and it works fine. But the approach, when we substract length of sent descriptors, is losing data. Namely, we have no information how big is the master descriptor (it has total length of the entire chain). So, I'm thinking how to solve this one. Otherwise it seems simpler than mine first idea.
I was planning to give you another review comment which i thought i will give later :)
It looks to be a bit wrong to have individual lengths in all descriptors leaving the first one :)
This is the descriptor struct:
struct dw_desc {
/* FIRST values the hardware uses */
struct dw_lli lli;
/* THEN values for driver housekeeping */
struct list_head desc_node;
struct list_head tx_list;
struct dma_async_tx_descriptor txd;
size_t len;
};Firstly i believe we can have a union of both list_heads as only one is used at any time. Can you patch it down?
Second to solve your problem, you can add another field here: total_len. I know it will consume 4 bytes per desc but i think that's the drawback we need to accept.
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 30 lines · Viresh Kumar
Quoted 7 lines · Andy Shevchenko
Yesterday I spent in testing of different approaches. First of all, the calculation of the sent amount is nicer when ctlhi/ctllo is used and it works fine. But the approach, when we substract length of sent descriptors, is losing data. Namely, we have no information how big is the master descriptor (it has total length of the entire chain). So, I'm thinking how to solve this one. Otherwise it seems simpler than mine first idea.
I was planning to give you another review comment which i thought i will give later :)
It looks to be a bit wrong to have individual lengths in all descriptors leaving the first one :)
This is the descriptor struct:
struct dw_desc { /* FIRST values the hardware uses */ struct dw_lli lli; /* THEN values for driver housekeeping */ struct list_head desc_node; struct list_head tx_list; struct dma_async_tx_descriptor txd; size_t len; };
Quoted 2 lines
Firstly i believe we can have a union of both
list_headsas only one is used at any time. Can you patch it down?
Okay, separately and later to avoid additional testing. Will it work for you?
Quoted 4 lines
Second to solve your problem, you can add another field here:
total_len. I know it will consume 4 bytes per desc but i think that's the drawback we need to accept.
I found already better solution I guess.
I introduced two functions to get amount of sent bytes like
u32 calc_sent(u32 ctlhi, u32 ctllo)
{
return f1(ctlhi) * f2(ctllo);
}
u32 get_sent(dwc)
{
return calc_sent(read(CTL_HI), read(CTL_LO));
}
And usage like
/* initial residue */desc->len - calc_sent(desc->lli.ctlhi, desc->lli.ctllo).
What do you think?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · Viresh Kumar
Firstly i believe we can have a union of both
list_headsas only one is used at any time. Can you patch it down?Okay, separately and later to avoid additional testing. Will it work for you?
Yes.
Quoted 5 lines
Quoted 3 lines
Second to solve your problem, you can add another field here:
total_len. I know it will consume 4 bytes per desc but i think that's the drawback we need to accept.I found already better solution I guess.
Wow!!
Quoted 12 lines
I introduced two functions to get amount of sent bytes like
u32
calc_sent(u32 ctlhi, u32 ctllo)
{
return f1(ctlhi) * f2(ctllo);
}u32
get_sent(dwc)
{
returncalc_sent(read(CTL_HI), read(CTL_LO));
}
Quoted 6 lines
And usage like
/* initial residue */
desc->len-calc_sent(desc->lli.ctlhi, desc->lli.ctllo).What do you think?
You plan to use it for
- the first descriptor in a list as others already have length embedded in them?
- And the descriptor currently getting used, by reading its ctlhi/lo from registers
instead of lli.*** ?
Looks good. but still keeping len of individual descriptors in all descriptors leaving
the first one is not the code i would like to keep :)
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 28 lines · Viresh Kumar
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Viresh Kumar
Second to solve your problem, you can add another field here:
total_len. I know it will consume 4 bytes per desc but i think that's the drawback we need to accept.I found already better solution I guess.
Wow!!
Quoted 17 lines
I introduced two functions to get amount of sent bytes like
u32
calc_sent(u32 ctlhi, u32 ctllo)
{
return f1(ctlhi) * f2(ctllo);
}u32
get_sent(dwc)
{
returncalc_sent(read(CTL_HI), read(CTL_LO));
}And usage like
/* initial residue */
desc->len-calc_sent(desc->lli.ctlhi, desc->lli.ctllo).
Quoted 7 lines
Quoted 1 line
What do you think?
You plan to use it for
- the first descriptor in a list as others already have length embedded in them?
- And the descriptor currently getting used, by reading its ctlhi/lo from registers
instead of lli.*** ?
Roughly, yes.
Quoted 3 lines
Looks good. but still keeping len of individual descriptors in all descriptors leaving
the first one is not the code i would like to keep :)
What about to calc len every time from lli.* instead of keeping it in the len field of the descriptor?
It's logically looks better, but requires more resources.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 2 lines · Andy Shevchenko
What about to calc len every time from lli.* instead of keeping it in the len field of the descriptor?
That's even bad.. we spend time on something for no good reason. :) I would still suggest you to add len and total_len in descriptor :)
Re: [PATCH 2/2] dw_dmac: return proper residue value
Quoted 6 lines · Viresh Kumar
Quoted 2 lines · Andy Shevchenko
What about to calc len every time from lli.* instead of keeping it in the len field of the descriptor?
That's even bad.. we spend time on something for no good reason. :) I would still suggest you to add len and
total_lenin descriptor :)
Okay, let's stick to this one for now.
I will come with patch v2 soon.
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy