ALSA: firewire-lib: replace pointer callback to flush isoc contexts in AMDTP domain
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Fri, 18 Oct 2019 06:19:07 +0000 (15:19 +0900)
committerTakashi Iwai <tiwai@suse.de>
Sat, 19 Oct 2019 07:18:20 +0000 (09:18 +0200)
An isoc context for AMDTP stream is flushed to queue packet
by a call of pcm.pointer. This commit extends this for AMDTP
domain.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Link: https://lore.kernel.org/r/20191018061911.24909-3-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/firewire/amdtp-stream.c
sound/firewire/amdtp-stream.h
sound/firewire/bebob/bebob_pcm.c
sound/firewire/dice/dice-pcm.c
sound/firewire/digi00x/digi00x-pcm.c
sound/firewire/fireface/ff-pcm.c
sound/firewire/fireworks/fireworks_pcm.c
sound/firewire/motu/motu-pcm.c
sound/firewire/oxfw/oxfw-pcm.c
sound/firewire/tascam/tascam-pcm.c

index 7486eec4d9584dd38e7cb96bcf6020d5c5bf7faa..23677b805b055354981d707e9f78518af7acade7 100644 (file)
@@ -1099,35 +1099,44 @@ err_unlock:
 }
 
 /**
- * amdtp_stream_pcm_pointer - get the PCM buffer position
+ * amdtp_domain_stream_pcm_pointer - get the PCM buffer position
+ * @d: the AMDTP domain.
  * @s: the AMDTP stream that transports the PCM data
  *
  * Returns the current buffer position, in frames.
  */
-unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s)
+unsigned long amdtp_domain_stream_pcm_pointer(struct amdtp_domain *d,
+                                             struct amdtp_stream *s)
 {
-       /*
-        * This function is called in software IRQ context of period_tasklet or
-        * process context.
-        *
-        * When the software IRQ context was scheduled by software IRQ context
-        * of IR/IT contexts, queued packets were already handled. Therefore,
-        * no need to flush the queue in buffer anymore.
-        *
-        * When the process context reach here, some packets will be already
-        * queued in the buffer. These packets should be handled immediately
-        * to keep better granularity of PCM pointer.
-        *
-        * Later, the process context will sometimes schedules software IRQ
-        * context of the period_tasklet. Then, no need to flush the queue by
-        * the same reason as described for IR/IT contexts.
-        */
-       if (!in_interrupt() && amdtp_stream_running(s))
-               fw_iso_context_flush_completions(s->context);
+       struct amdtp_stream *irq_target = d->irq_target;
+
+       if (irq_target && amdtp_stream_running(irq_target)) {
+               // This function is called in software IRQ context of
+               // period_tasklet or process context.
+               //
+               // When the software IRQ context was scheduled by software IRQ
+               // context of IT contexts, queued packets were already handled.
+               // Therefore, no need to flush the queue in buffer furthermore.
+               //
+               // When the process context reach here, some packets will be
+               // already queued in the buffer. These packets should be handled
+               // immediately to keep better granularity of PCM pointer.
+               //
+               // Later, the process context will sometimes schedules software
+               // IRQ context of the period_tasklet. Then, no need to flush the
+               // queue by the same reason as described in the above
+               if (!in_interrupt()) {
+                       // Queued packet should be processed without any kernel
+                       // preemption to keep latency against bus cycle.
+                       preempt_disable();
+                       fw_iso_context_flush_completions(irq_target->context);
+                       preempt_enable();
+               }
+       }
 
        return READ_ONCE(s->pcm_buffer_pointer);
 }
-EXPORT_SYMBOL(amdtp_stream_pcm_pointer);
+EXPORT_SYMBOL_GPL(amdtp_domain_stream_pcm_pointer);
 
 /**
  * amdtp_stream_pcm_ack - acknowledge queued PCM frames
index f92397a2f35fed77349594f9d1fa9c29f0a5f074..ba0bbeddfdcb5e293ceeb313b9b0453c9401f2fb 100644 (file)
@@ -198,7 +198,6 @@ int amdtp_stream_add_pcm_hw_constraints(struct amdtp_stream *s,
                                        struct snd_pcm_runtime *runtime);
 
 void amdtp_stream_pcm_prepare(struct amdtp_stream *s);
-unsigned long amdtp_stream_pcm_pointer(struct amdtp_stream *s);
 int amdtp_stream_pcm_ack(struct amdtp_stream *s);
 void amdtp_stream_pcm_abort(struct amdtp_stream *s);
 
@@ -302,4 +301,6 @@ static inline int amdtp_domain_set_events_per_period(struct amdtp_domain *d,
        return 0;
 }
 
+unsigned long amdtp_domain_stream_pcm_pointer(struct amdtp_domain *d,
+                                             struct amdtp_stream *s);
 #endif
index 8b2e0ceffe829d1aba217697017f6c7ce32b826a..dc15ea8d0dc58302b1f4bcd5c385e6ae78f74084 100644 (file)
@@ -313,17 +313,19 @@ pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd)
        return 0;
 }
 
-static snd_pcm_uframes_t
-pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
+static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_bebob *bebob = sbstrm->private_data;
-       return amdtp_stream_pcm_pointer(&bebob->tx_stream);
+
+       return amdtp_domain_stream_pcm_pointer(&bebob->domain,
+                                              &bebob->tx_stream);
 }
-static snd_pcm_uframes_t
-pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
+static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_bebob *bebob = sbstrm->private_data;
-       return amdtp_stream_pcm_pointer(&bebob->rx_stream);
+
+       return amdtp_domain_stream_pcm_pointer(&bebob->domain,
+                                              &bebob->rx_stream);
 }
 
 static int pcm_capture_ack(struct snd_pcm_substream *substream)
index 7c0c34c5bd4791371977f539f7984fb0aa6cfc9a..81b78e7d181dd7695d9420a052a5bef8376063f5 100644 (file)
@@ -379,14 +379,14 @@ static snd_pcm_uframes_t capture_pointer(struct snd_pcm_substream *substream)
        struct snd_dice *dice = substream->private_data;
        struct amdtp_stream *stream = &dice->tx_stream[substream->pcm->device];
 
-       return amdtp_stream_pcm_pointer(stream);
+       return amdtp_domain_stream_pcm_pointer(&dice->domain, stream);
 }
 static snd_pcm_uframes_t playback_pointer(struct snd_pcm_substream *substream)
 {
        struct snd_dice *dice = substream->private_data;
        struct amdtp_stream *stream = &dice->rx_stream[substream->pcm->device];
 
-       return amdtp_stream_pcm_pointer(stream);
+       return amdtp_domain_stream_pcm_pointer(&dice->domain, stream);
 }
 
 static int capture_ack(struct snd_pcm_substream *substream)
index c9a833dff20dd63ecea24e0ace3fcdee6ae7b0e8..f6a2053d5f10830def4e9753ea574e3913d6f50a 100644 (file)
@@ -301,14 +301,14 @@ static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_dg00x *dg00x = sbstrm->private_data;
 
-       return amdtp_stream_pcm_pointer(&dg00x->tx_stream);
+       return amdtp_domain_stream_pcm_pointer(&dg00x->domain, &dg00x->tx_stream);
 }
 
 static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_dg00x *dg00x = sbstrm->private_data;
 
-       return amdtp_stream_pcm_pointer(&dg00x->rx_stream);
+       return amdtp_domain_stream_pcm_pointer(&dg00x->domain, &dg00x->rx_stream);
 }
 
 static int pcm_capture_ack(struct snd_pcm_substream *substream)
index 005d959f86517fbf04e7151d60577e040601939b..5af1dce9092101416606db4eed4df847eb71c744 100644 (file)
@@ -341,14 +341,14 @@ static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_ff *ff = sbstrm->private_data;
 
-       return amdtp_stream_pcm_pointer(&ff->tx_stream);
+       return amdtp_domain_stream_pcm_pointer(&ff->domain, &ff->tx_stream);
 }
 
 static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_ff *ff = sbstrm->private_data;
 
-       return amdtp_stream_pcm_pointer(&ff->rx_stream);
+       return amdtp_domain_stream_pcm_pointer(&ff->domain, &ff->rx_stream);
 }
 
 static int pcm_capture_ack(struct snd_pcm_substream *substream)
index abcc53dac8a5a4c6ebd4b00d0492e1b8d756d5e9..71f5057caa0d930c72d8b7fcb99332bd22876e97 100644 (file)
@@ -348,12 +348,14 @@ static int pcm_playback_trigger(struct snd_pcm_substream *substream, int cmd)
 static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_efw *efw = sbstrm->private_data;
-       return amdtp_stream_pcm_pointer(&efw->tx_stream);
+
+       return amdtp_domain_stream_pcm_pointer(&efw->domain, &efw->tx_stream);
 }
 static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_efw *efw = sbstrm->private_data;
-       return amdtp_stream_pcm_pointer(&efw->rx_stream);
+
+       return amdtp_domain_stream_pcm_pointer(&efw->domain, &efw->rx_stream);
 }
 
 static int pcm_capture_ack(struct snd_pcm_substream *substream)
index 00e693da0cad1992be8de5bcbaa070e6e8218fb9..13e2577c2a076ffd0b06401804af912373d18515 100644 (file)
@@ -320,13 +320,13 @@ static snd_pcm_uframes_t capture_pointer(struct snd_pcm_substream *substream)
 {
        struct snd_motu *motu = substream->private_data;
 
-       return amdtp_stream_pcm_pointer(&motu->tx_stream);
+       return amdtp_domain_stream_pcm_pointer(&motu->domain, &motu->tx_stream);
 }
 static snd_pcm_uframes_t playback_pointer(struct snd_pcm_substream *substream)
 {
        struct snd_motu *motu = substream->private_data;
 
-       return amdtp_stream_pcm_pointer(&motu->rx_stream);
+       return amdtp_domain_stream_pcm_pointer(&motu->domain, &motu->rx_stream);
 }
 
 static int capture_ack(struct snd_pcm_substream *substream)
index ba586d1ac91d7b8a781a40f7be71d58ad894b9c7..3be35dfcf270bdd2b19bc3945258411c051be23e 100644 (file)
@@ -393,13 +393,13 @@ static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstm)
 {
        struct snd_oxfw *oxfw = sbstm->private_data;
 
-       return amdtp_stream_pcm_pointer(&oxfw->tx_stream);
+       return amdtp_domain_stream_pcm_pointer(&oxfw->domain, &oxfw->tx_stream);
 }
 static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstm)
 {
        struct snd_oxfw *oxfw = sbstm->private_data;
 
-       return amdtp_stream_pcm_pointer(&oxfw->rx_stream);
+       return amdtp_domain_stream_pcm_pointer(&oxfw->domain, &oxfw->rx_stream);
 }
 
 static int pcm_capture_ack(struct snd_pcm_substream *substream)
index b18664fdf9558b27db094f95fd0b4964b154608b..1f66c8be7528ae8df001f51970659f3f051c89e1 100644 (file)
@@ -230,14 +230,14 @@ static snd_pcm_uframes_t pcm_capture_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_tscm *tscm = sbstrm->private_data;
 
-       return amdtp_stream_pcm_pointer(&tscm->tx_stream);
+       return amdtp_domain_stream_pcm_pointer(&tscm->domain, &tscm->tx_stream);
 }
 
 static snd_pcm_uframes_t pcm_playback_pointer(struct snd_pcm_substream *sbstrm)
 {
        struct snd_tscm *tscm = sbstrm->private_data;
 
-       return amdtp_stream_pcm_pointer(&tscm->rx_stream);
+       return amdtp_domain_stream_pcm_pointer(&tscm->domain, &tscm->rx_stream);
 }
 
 static int pcm_capture_ack(struct snd_pcm_substream *substream)