return ret;
}
+static void call_retire_callback(struct snd_usb_endpoint *ep,
+ struct urb *urb)
+{
+ struct snd_usb_substream *data_subs;
+
+ data_subs = READ_ONCE(ep->data_subs);
+ if (data_subs && ep->retire_data_urb)
+ ep->retire_data_urb(data_subs, urb);
+}
+
static void retire_outbound_urb(struct snd_usb_endpoint *ep,
struct snd_urb_ctx *urb_ctx)
{
- if (ep->retire_data_urb)
- ep->retire_data_urb(ep->data_subs, urb_ctx->urb);
+ call_retire_callback(ep, urb_ctx->urb);
}
static void retire_inbound_urb(struct snd_usb_endpoint *ep,
if (ep->sync_slave)
snd_usb_handle_sync_urb(ep->sync_slave, ep, urb);
- if (ep->retire_data_urb)
- ep->retire_data_urb(ep->data_subs, urb);
+ call_retire_callback(ep, urb);
}
static void prepare_silent_urb(struct snd_usb_endpoint *ep,
{
struct urb *urb = ctx->urb;
unsigned char *cp = urb->transfer_buffer;
+ struct snd_usb_substream *data_subs;
urb->dev = ep->chip->dev; /* we need to set this at each time */
switch (ep->type) {
case SND_USB_ENDPOINT_TYPE_DATA:
- if (ep->prepare_data_urb) {
- ep->prepare_data_urb(ep->data_subs, urb);
- } else {
- /* no data provider, so send silence */
+ data_subs = READ_ONCE(ep->data_subs);
+ if (data_subs && ep->prepare_data_urb)
+ ep->prepare_data_urb(data_subs, urb);
+ else /* no data provider, so send silence */
prepare_silent_urb(ep, ctx);
- }
break;
case SND_USB_ENDPOINT_TYPE_SYNC:
{
struct snd_urb_ctx *ctx = urb->context;
struct snd_usb_endpoint *ep = ctx->ep;
- struct snd_pcm_substream *substream;
+ struct snd_usb_substream *data_subs;
unsigned long flags;
int err;
return;
usb_audio_err(ep->chip, "cannot submit urb (err = %d)\n", err);
- if (ep->data_subs && ep->data_subs->pcm_substream) {
- substream = ep->data_subs->pcm_substream;
- snd_pcm_stop_xrun(substream);
- }
+ data_subs = READ_ONCE(ep->data_subs);
+ if (data_subs && data_subs->pcm_substream)
+ snd_pcm_stop_xrun(data_subs->pcm_substream);
exit_clear:
clear_bit(ctx->index, &ep->active_mask);
}
}
+/*
+ * Set data endpoint callbacks and the assigned data stream
+ *
+ * Called at PCM trigger and cleanups.
+ * Pass NULL to deactivate each callback.
+ */
+void snd_usb_endpoint_set_callback(struct snd_usb_endpoint *ep,
+ void (*prepare)(struct snd_usb_substream *subs,
+ struct urb *urb),
+ void (*retire)(struct snd_usb_substream *subs,
+ struct urb *urb),
+ struct snd_usb_substream *data_subs)
+{
+ ep->prepare_data_urb = prepare;
+ ep->retire_data_urb = retire;
+ WRITE_ONCE(ep->data_subs, data_subs);
+}
+
/*
* wait until all urbs are processed.
*/
alive, ep->ep_num);
clear_bit(EP_FLAG_STOPPING, &ep->flags);
- ep->data_subs = NULL;
ep->sync_slave = NULL;
- ep->retire_data_urb = NULL;
- ep->prepare_data_urb = NULL;
+ snd_usb_endpoint_set_callback(ep, NULL, NULL, NULL);
return 0;
}
int i;
/* route incoming urbs to nirvana */
- ep->retire_data_urb = NULL;
- ep->prepare_data_urb = NULL;
+ snd_usb_endpoint_set_callback(ep, NULL, NULL, NULL);
/* stop urbs */
deactivate_urbs(ep, force);
if (!test_and_set_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags)) {
struct snd_usb_endpoint *ep = subs->data_endpoint;
- ep->data_subs = subs;
err = snd_usb_endpoint_start(ep);
if (err < 0) {
clear_bit(SUBSTREAM_FLAG_DATA_EP_STARTED, &subs->flags);
subs->trigger_tstamp_pending_update = true;
fallthrough;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- subs->data_endpoint->prepare_data_urb = prepare_playback_urb;
- subs->data_endpoint->retire_data_urb = retire_playback_urb;
+ snd_usb_endpoint_set_callback(subs->data_endpoint,
+ prepare_playback_urb,
+ retire_playback_urb,
+ subs);
subs->running = 1;
return 0;
case SNDRV_PCM_TRIGGER_STOP:
stop_endpoints(subs);
+ snd_usb_endpoint_set_callback(subs->data_endpoint,
+ NULL, NULL, NULL);
subs->running = 0;
return 0;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- subs->data_endpoint->prepare_data_urb = NULL;
/* keep retire_data_urb for delay calculation */
- subs->data_endpoint->retire_data_urb = retire_playback_urb;
+ snd_usb_endpoint_set_callback(subs->data_endpoint,
+ NULL,
+ retire_playback_urb,
+ subs);
subs->running = 0;
return 0;
case SNDRV_PCM_TRIGGER_SUSPEND:
err = start_endpoints(subs);
if (err < 0)
return err;
-
- subs->data_endpoint->retire_data_urb = retire_capture_urb;
+ fallthrough;
+ case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+ snd_usb_endpoint_set_callback(subs->data_endpoint,
+ NULL, retire_capture_urb,
+ subs);
subs->running = 1;
return 0;
case SNDRV_PCM_TRIGGER_STOP:
stop_endpoints(subs);
- subs->data_endpoint->retire_data_urb = NULL;
- subs->running = 0;
- return 0;
+ fallthrough;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
- subs->data_endpoint->retire_data_urb = NULL;
+ snd_usb_endpoint_set_callback(subs->data_endpoint,
+ NULL, NULL, NULL);
subs->running = 0;
return 0;
- case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
- subs->data_endpoint->retire_data_urb = retire_capture_urb;
- subs->running = 1;
- return 0;
case SNDRV_PCM_TRIGGER_SUSPEND:
if (subs->stream->chip->setup_fmt_after_resume_quirk) {
stop_endpoints(subs);