@@ -172,6 +172,9 @@ struct iso_context {
172172 struct context context ;
173173 void * header ;
174174 size_t header_length ;
175+ unsigned long flushing_completions ;
176+ u32 mc_buffer_bus ;
177+ u16 mc_completed ;
175178 u16 last_timestamp ;
176179 u8 sync ;
177180 u8 tags ;
@@ -2749,28 +2752,51 @@ static int handle_ir_buffer_fill(struct context *context,
27492752{
27502753 struct iso_context * ctx =
27512754 container_of (context , struct iso_context , context );
2755+ unsigned int req_count , res_count , completed ;
27522756 u32 buffer_dma ;
27532757
2754- if (last -> res_count != 0 )
2758+ req_count = le16_to_cpu (last -> req_count );
2759+ res_count = le16_to_cpu (ACCESS_ONCE (last -> res_count ));
2760+ completed = req_count - res_count ;
2761+ buffer_dma = le32_to_cpu (last -> data_address );
2762+
2763+ if (completed > 0 ) {
2764+ ctx -> mc_buffer_bus = buffer_dma ;
2765+ ctx -> mc_completed = completed ;
2766+ }
2767+
2768+ if (res_count != 0 )
27552769 /* Descriptor(s) not done yet, stop iteration */
27562770 return 0 ;
27572771
2758- buffer_dma = le32_to_cpu (last -> data_address );
27592772 dma_sync_single_range_for_cpu (context -> ohci -> card .device ,
27602773 buffer_dma & PAGE_MASK ,
27612774 buffer_dma & ~PAGE_MASK ,
2762- le16_to_cpu (last -> req_count ),
2763- DMA_FROM_DEVICE );
2775+ completed , DMA_FROM_DEVICE );
27642776
2765- if (last -> control & cpu_to_le16 (DESCRIPTOR_IRQ_ALWAYS ))
2777+ if (last -> control & cpu_to_le16 (DESCRIPTOR_IRQ_ALWAYS )) {
27662778 ctx -> base .callback .mc (& ctx -> base ,
2767- le32_to_cpu (last -> data_address ) +
2768- le16_to_cpu (last -> req_count ),
2779+ buffer_dma + completed ,
27692780 ctx -> base .callback_data );
2781+ ctx -> mc_completed = 0 ;
2782+ }
27702783
27712784 return 1 ;
27722785}
27732786
2787+ static void flush_ir_buffer_fill (struct iso_context * ctx )
2788+ {
2789+ dma_sync_single_range_for_cpu (ctx -> context .ohci -> card .device ,
2790+ ctx -> mc_buffer_bus & PAGE_MASK ,
2791+ ctx -> mc_buffer_bus & ~PAGE_MASK ,
2792+ ctx -> mc_completed , DMA_FROM_DEVICE );
2793+
2794+ ctx -> base .callback .mc (& ctx -> base ,
2795+ ctx -> mc_buffer_bus + ctx -> mc_completed ,
2796+ ctx -> base .callback_data );
2797+ ctx -> mc_completed = 0 ;
2798+ }
2799+
27742800static inline void sync_it_packet_for_cpu (struct context * context ,
27752801 struct descriptor * pd )
27762802{
@@ -2925,8 +2951,10 @@ static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card,
29252951 if (ret < 0 )
29262952 goto out_with_header ;
29272953
2928- if (type == FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL )
2954+ if (type == FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL ) {
29292955 set_multichannel_mask (ohci , 0 );
2956+ ctx -> mc_completed = 0 ;
2957+ }
29302958
29312959 return & ctx -> base ;
29322960
@@ -3388,6 +3416,39 @@ static void ohci_flush_queue_iso(struct fw_iso_context *base)
33883416 reg_write (ctx -> ohci , CONTROL_SET (ctx -> regs ), CONTEXT_WAKE );
33893417}
33903418
3419+ static int ohci_flush_iso_completions (struct fw_iso_context * base )
3420+ {
3421+ struct iso_context * ctx = container_of (base , struct iso_context , base );
3422+ int ret = 0 ;
3423+
3424+ tasklet_disable (& ctx -> context .tasklet );
3425+
3426+ if (!test_and_set_bit_lock (0 , & ctx -> flushing_completions )) {
3427+ context_tasklet ((unsigned long )& ctx -> context );
3428+
3429+ switch (base -> type ) {
3430+ case FW_ISO_CONTEXT_TRANSMIT :
3431+ case FW_ISO_CONTEXT_RECEIVE :
3432+ if (ctx -> header_length != 0 )
3433+ flush_iso_completions (ctx );
3434+ break ;
3435+ case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL :
3436+ if (ctx -> mc_completed != 0 )
3437+ flush_ir_buffer_fill (ctx );
3438+ break ;
3439+ default :
3440+ ret = - ENOSYS ;
3441+ }
3442+
3443+ clear_bit_unlock (0 , & ctx -> flushing_completions );
3444+ smp_mb__after_clear_bit ();
3445+ }
3446+
3447+ tasklet_enable (& ctx -> context .tasklet );
3448+
3449+ return ret ;
3450+ }
3451+
33913452static const struct fw_card_driver ohci_driver = {
33923453 .enable = ohci_enable ,
33933454 .read_phy_reg = ohci_read_phy_reg ,
@@ -3405,6 +3466,7 @@ static const struct fw_card_driver ohci_driver = {
34053466 .set_iso_channels = ohci_set_iso_channels ,
34063467 .queue_iso = ohci_queue_iso ,
34073468 .flush_queue_iso = ohci_flush_queue_iso ,
3469+ .flush_iso_completions = ohci_flush_iso_completions ,
34083470 .start_iso = ohci_start_iso ,
34093471 .stop_iso = ohci_stop_iso ,
34103472};
0 commit comments