Message ID | 20240507195116.9464-1-quic_wcheng@quicinc.com |
---|---|
Headers | show |
Series | Introduce QC USB SND audio offloading support | expand |
> +const char *snd_soc_usb_get_components_tag(bool playback) > +{ > + if (playback) > + return "usbplaybackoffload: 1"; > + else > + return "usbcaptureoffload : 1"; why are there different spaces and do we need spaces in the first place? > +int snd_soc_usb_add_port(struct snd_soc_usb *usb) > +{ > + mutex_lock(&ctx_mutex); > + list_add_tail(&usb->list, &usb_ctx_list); > + mutex_unlock(&ctx_mutex); > + > + return 0; make the function return void? > +int snd_soc_usb_remove_port(struct snd_soc_usb *usb) > +{ > + struct snd_soc_usb *ctx, *tmp; > + > + mutex_lock(&ctx_mutex); > + list_for_each_entry_safe(ctx, tmp, &usb_ctx_list, list) { > + if (ctx == usb) { > + list_del(&ctx->list); > + break; > + } > + } > + mutex_unlock(&ctx_mutex); > + > + return 0; make this return void?
> static struct snd_soc_dai_driver q6dsp_audio_fe_dais[] = { > + { > + .playback = { > + .stream_name = "USB Playback", > + .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | > + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | > + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | > + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | > + SNDRV_PCM_RATE_192000, > + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | > + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | > + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | > + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, > + .channels_min = 1, > + .channels_max = 2, > + .rate_min = 8000, > + .rate_max = 192000, > + }, > + .id = USB_RX, > + .name = "USB_RX", > + }, Wait, is this saying you will have exactly one PCM device/FE DAI connected to the USB BE DAI exposed in patch 11? > + SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, > + usb_mixer_controls, > + ARRAY_SIZE(usb_mixer_controls)), > + And then what is the role of the USB mixer if you only have one input? I must be missing something.
> +config SND_SOC_QDSP6_USB > + tristate "SoC ALSA USB offloading backing for QDSP6" > + depends on SND_SOC_USB > + help > + Adds support for USB offloading for QDSP6 ASoC > + based platform sound cards. This will enable the > + Q6USB DPCM backend DAI link, which will interact > + with the SoC USB framework to initialize a session > + with active USB SND devices. If this is set to 'n', don't you have a risk of the FE DAIs exposed in patch 9 not being connected to anything?
> If a PCM device is already in use, the check will return an error to > userspace notifying that the stream is currently busy. This ensures that > only one path is using the USB substream. What was the point of having a "USB Mixer" then?
> @@ -113,6 +120,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, > if (connected) { > /* We only track the latest USB headset plugged in */ > data->active_usb_chip_idx = sdev->card_idx; > + > + set_bit(sdev->card_idx, &data->available_card_slot); > + data->status[sdev->card_idx].sdev = sdev; Not following the 'only track the latest USB headset plugged in', I don't see anything that discard the previously latest headset... If you plug headset1, then headset2, how is headset1 marked as not available for USB offload? > + } else { > + clear_bit(sdev->card_idx, &data->available_card_slot); > + data->status[sdev->card_idx].sdev = NULL; > } > > return 0;
On 5/7/24 14:51, Wesley Cheng wrote: > Add SND kcontrol to SOC USB, which will allow for userpsace to determine > which USB card number and PCM device to offload. This allows for userspace > to potentially tag an alternate path for a specific USB SND card and PCM > device. Previously, control was absent, and the offload path would be > enabled on the last USB SND device which was connected. This logic will > continue to be applicable if no mixer input is received for specific device > selection. > > An example to configure the offload device using tinymix: > tinymix -D 0 set 'USB Offload Playback Route Select' 1 0 > > The above command will configure the offload path to utilize card#1 and PCM > stream#0. I don't know how this is usable in practice. Using card indices is really hard to do, it depends on the order in which devices are plugged-in...
> +/** > + * snd_soc_usb_device_offload_available() - Fetch BE DAI link sound card > + * @dev: the device to find in SOC USB > + * > + * Finds the component linked to a specific SOC USB instance, and returns > + * the sound card number for the platform card supporting offloading. > + * > + */ > +int snd_soc_usb_device_offload_available(struct device *dev) > +{ > + struct snd_soc_usb *ctx; > + > + ctx = snd_soc_find_usb_ctx(dev); > + if (!ctx) > + return -ENODEV; > + > + return ctx->component->card->snd_card->number; > +} Presumably there's a notification to help applications discard this information on removal?
On 5/7/24 14:51, Wesley Cheng wrote: > In order to allow userspace/applications know about USB offloading status, > expose a sound kcontrol that fetches information about which sound card > index is associated with the ASoC platform card supporting offloading. In > the USB audio offloading framework, the ASoC BE DAI link is the entity > responsible for registering to the SOC USB layer. SOC USB will expose more > details about the current offloading status, which includes the USB sound > card and USB PCM device indexes currently being used. > > It is expected for the USB offloading driver to add the kcontrol to the > sound card associated with the USB audio device. An example output would > look like: > > tinymix -D 1 get 'USB Offload Playback Capable Card' > 0 (range -1->32) You already gave the following examples in patch 29: " USB offloading idle: tinymix -D 0 get 'USB Offload Playback Route Status' -->-1, -1 (range -1->32) USB offloading active(USB card#1 pcm#0): tinymix -D 0 get 'USB Offload Playback Route Status' -->1, 0 (range -1->32) " Can you clarify how many controls there would be in the end? Also isn't tinymix -D N going to give you the controls for card N?
On 5/7/24 14:51, Wesley Cheng wrote: > For userspace to know about certain capabilities of the current platform > card, add tags to the components string that it can use to enable support > for that audio path. In case of USB offloading, the "usboffldplybk: 1" tag usboffloadplayback? same question as before, do we need spaces? And if we have controls, why do we need component strings? The component string is not dynamic to the best of my knowledge, this could be problematic if the card is no longer capable of supporting this stream, while a control can be updated at will.
Hi Pierre, On 5/7/2024 2:37 PM, Pierre-Louis Bossart wrote: > > > On 5/7/24 14:51, Wesley Cheng wrote: >> In order to allow userspace/applications know about USB offloading status, >> expose a sound kcontrol that fetches information about which sound card >> index is associated with the ASoC platform card supporting offloading. In >> the USB audio offloading framework, the ASoC BE DAI link is the entity >> responsible for registering to the SOC USB layer. SOC USB will expose more >> details about the current offloading status, which includes the USB sound >> card and USB PCM device indexes currently being used. >> >> It is expected for the USB offloading driver to add the kcontrol to the >> sound card associated with the USB audio device. An example output would >> look like: >> >> tinymix -D 1 get 'USB Offload Playback Capable Card' >> 0 (range -1->32) > > You already gave the following examples in patch 29: > > " > USB offloading idle: > tinymix -D 0 get 'USB Offload Playback Route Status' > -->-1, -1 (range -1->32) > > USB offloading active(USB card#1 pcm#0): > tinymix -D 0 get 'USB Offload Playback Route Status' > -->1, 0 (range -1->32) > " > > Can you clarify how many controls there would be in the end? For USB offload situations, there will be a set of controls for playback status and playback select. The offload jack will also be there to tell us if there is an offload path available for the platform ASoC sound card. > Also isn't tinymix -D N going to give you the controls for card N? > Yes, since the offload portion is handled as a DPCM DAI link to the platform ASoC card, it will be included as a kcontrol for that. Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 2:40 PM, Pierre-Louis Bossart wrote: > > > On 5/7/24 14:51, Wesley Cheng wrote: >> For userspace to know about certain capabilities of the current platform >> card, add tags to the components string that it can use to enable support >> for that audio path. In case of USB offloading, the "usboffldplybk: 1" tag > > usboffloadplayback? > > same question as before, do we need spaces? > I think spaces are currently used as a delimiter, so I'll remove the spaces. > And if we have controls, why do we need component strings? The component > string is not dynamic to the best of my knowledge, this could be > problematic if the card is no longer capable of supporting this stream, > while a control can be updated at will. > Maybe I misunderstood your comment here: https://lore.kernel.org/linux-usb/925d7c03-c288-49a4-8bcd-395b32810d75@linux.intel.com/ At the time, I didn't include the kcontrols on the USB SND portion of it, which was added after this series. My interpretation was that there were userspace entities that could query for general information about what the card supports based on the components string, or sound card name. I treated this as an independent identifier, since the change to add the offload capable jack was present. Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 1:26 PM, Pierre-Louis Bossart wrote: > >> +const char *snd_soc_usb_get_components_tag(bool playback) >> +{ >> + if (playback) >> + return "usbplaybackoffload: 1"; >> + else >> + return "usbcaptureoffload : 1"; > > why are there different spaces and do we need spaces in the first place? > Will remove these spaces once we clarify if this is still needed. >> +int snd_soc_usb_add_port(struct snd_soc_usb *usb) >> +{ >> + mutex_lock(&ctx_mutex); >> + list_add_tail(&usb->list, &usb_ctx_list); >> + mutex_unlock(&ctx_mutex); >> + >> + return 0; > > make the function return void? > Ack. >> +int snd_soc_usb_remove_port(struct snd_soc_usb *usb) >> +{ >> + struct snd_soc_usb *ctx, *tmp; >> + >> + mutex_lock(&ctx_mutex); >> + list_for_each_entry_safe(ctx, tmp, &usb_ctx_list, list) { >> + if (ctx == usb) { >> + list_del(&ctx->list); >> + break; >> + } >> + } >> + mutex_unlock(&ctx_mutex); >> + >> + return 0; > > make this return void? > > Ack. Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 1:37 PM, Pierre-Louis Bossart wrote: > >> static struct snd_soc_dai_driver q6dsp_audio_fe_dais[] = { >> + { >> + .playback = { >> + .stream_name = "USB Playback", >> + .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | >> + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | >> + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | >> + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | >> + SNDRV_PCM_RATE_192000, >> + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | >> + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | >> + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | >> + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, >> + .channels_min = 1, >> + .channels_max = 2, >> + .rate_min = 8000, >> + .rate_max = 192000, >> + }, >> + .id = USB_RX, >> + .name = "USB_RX", >> + }, > > Wait, is this saying you will have exactly one PCM device/FE DAI > connected to the USB BE DAI exposed in patch 11? > >> + SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, >> + usb_mixer_controls, >> + ARRAY_SIZE(usb_mixer_controls)), >> + > > And then what is the role of the USB mixer if you only have one input? > > I must be missing something. > Not sure if this is a QCOM specific implementation, but the way the DT is defined for the USB offload path is as follows: usb-dai-link { link-name = "USB Playback"; cpu { sound-dai = <&q6afedai USB_RX>; }; codec { sound-dai = <&usbdai USB_RX>; }; platform { sound-dai = <&q6routing>; }; }; Based on our DT parser helper API (qcom_snd_parse_of()) this isn't going to create a PCM device. The PCM devices are created for nodes that don't have a codec and platform defined: mm1-dai-link { link-name = "MultiMedia1"; cpu { sound-dai = <&q6asmdai MSM_FRONTEND_DAI_MULTIMEDIA1>; }; }; The ASM path is the entity that defines the number of PCM devices that is created for the QC ASoC platform card, and is where the actual PCM data is sent over to the DSP. So there could be several PCM devices that can use the USB BE DAI. Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 2:20 PM, Pierre-Louis Bossart wrote: > >> If a PCM device is already in use, the check will return an error to >> userspace notifying that the stream is currently busy. This ensures that >> only one path is using the USB substream. > > What was the point of having a "USB Mixer" then? The USB mixer is intended to enable/route the USB offloading path to the audio DSP, and is for controlling the ASoC specific entities. This change is needed to resolve any contention between the USB SND PCM device (non offload path) and the ASoC USB BE DAI (offload path). Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 2:23 PM, Pierre-Louis Bossart wrote: > >> @@ -113,6 +120,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, >> if (connected) { >> /* We only track the latest USB headset plugged in */ >> data->active_usb_chip_idx = sdev->card_idx; >> + >> + set_bit(sdev->card_idx, &data->available_card_slot); >> + data->status[sdev->card_idx].sdev = sdev; > > Not following the 'only track the latest USB headset plugged in', I > don't see anything that discard the previously latest headset... > > If you plug headset1, then headset2, how is headset1 marked as not > available for USB offload? > It won't mark headset1 as not available for offload, because offload could happen on either depending on what is selected (from the kcontrol as well). Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 2:26 PM, Pierre-Louis Bossart wrote: > > > On 5/7/24 14:51, Wesley Cheng wrote: >> Add SND kcontrol to SOC USB, which will allow for userpsace to determine >> which USB card number and PCM device to offload. This allows for userspace >> to potentially tag an alternate path for a specific USB SND card and PCM >> device. Previously, control was absent, and the offload path would be >> enabled on the last USB SND device which was connected. This logic will >> continue to be applicable if no mixer input is received for specific device >> selection. >> >> An example to configure the offload device using tinymix: >> tinymix -D 0 set 'USB Offload Playback Route Select' 1 0 >> >> The above command will configure the offload path to utilize card#1 and PCM >> stream#0. > > I don't know how this is usable in practice. Using card indices is > really hard to do, it depends on the order in which devices are > plugged-in... How are the existing mechanisms handling USB audio devices, or what is the identifier being used? Thanks Wesley Cheng
Hi Pierre, On 5/7/2024 2:33 PM, Pierre-Louis Bossart wrote: > >> +/** >> + * snd_soc_usb_device_offload_available() - Fetch BE DAI link sound card >> + * @dev: the device to find in SOC USB >> + * >> + * Finds the component linked to a specific SOC USB instance, and returns >> + * the sound card number for the platform card supporting offloading. >> + * >> + */ >> +int snd_soc_usb_device_offload_available(struct device *dev) >> +{ >> + struct snd_soc_usb *ctx; >> + >> + ctx = snd_soc_find_usb_ctx(dev); >> + if (!ctx) >> + return -ENODEV; >> + >> + return ctx->component->card->snd_card->number; >> +} > > Presumably there's a notification to help applications discard this > information on removal? If the platform/ASoC sound card is removed then the USB BE DAI is going to be unregistered from SOC USB. This would lead to the snd_soc_find_usb_ctx() to return with -ENODEV to the USB SND offload kcontrol call. Thanks Wesley Cheng
Hi Pierre, On 5/8/2024 12:41 PM, Wesley Cheng wrote: > Hi Pierre, > > On 5/7/2024 2:37 PM, Pierre-Louis Bossart wrote: >> >> >> On 5/7/24 14:51, Wesley Cheng wrote: >>> In order to allow userspace/applications know about USB offloading >>> status, >>> expose a sound kcontrol that fetches information about which sound card >>> index is associated with the ASoC platform card supporting >>> offloading. In >>> the USB audio offloading framework, the ASoC BE DAI link is the entity >>> responsible for registering to the SOC USB layer. SOC USB will >>> expose more >>> details about the current offloading status, which includes the USB >>> sound >>> card and USB PCM device indexes currently being used. >>> >>> It is expected for the USB offloading driver to add the kcontrol to the >>> sound card associated with the USB audio device. An example output >>> would >>> look like: >>> >>> tinymix -D 1 get 'USB Offload Playback Capable Card' >>> 0 (range -1->32) >> >> You already gave the following examples in patch 29: >> >> " >> USB offloading idle: >> tinymix -D 0 get 'USB Offload Playback Route Status' >> -->-1, -1 (range -1->32) >> >> USB offloading active(USB card#1 pcm#0): >> tinymix -D 0 get 'USB Offload Playback Route Status' >> -->1, 0 (range -1->32) >> " >> >> Can you clarify how many controls there would be in the end? > > For USB offload situations, there will be a set of controls for playback > status and playback select. The offload jack will also be there to tell > us if there is an offload path available for the platform ASoC sound card. > >> Also isn't tinymix -D N going to give you the controls for card N? >> > > Yes, since the offload portion is handled as a DPCM DAI link to the > platform ASoC card, it will be included as a kcontrol for that. > > Thanks > Wesley Cheng > > Sorry for responding again. I read your email again, and wanted to also add that aside from the above, which are all within the ASoC layer, as we discussed previously, we should have a kcontrol in the USB SND card to determine if there is an ASoC platform card capable of offloading. This is also available from the SND card created by the USB audio device. Thanks Wesley Cheng
>> Wait, is this saying you will have exactly one PCM device/FE DAI >> connected to the USB BE DAI exposed in patch 11? >> >>> + SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, >>> + usb_mixer_controls, >>> + ARRAY_SIZE(usb_mixer_controls)), >>> + >> >> And then what is the role of the USB mixer if you only have one input? >> >> I must be missing something. >> > > Not sure if this is a QCOM specific implementation, but the way the DT > is defined for the USB offload path is as follows: > > usb-dai-link { > link-name = "USB Playback"; > > cpu { > sound-dai = <&q6afedai USB_RX>; > }; > > codec { > sound-dai = <&usbdai USB_RX>; > }; > > platform { > sound-dai = <&q6routing>; > }; > }; > > Based on our DT parser helper API (qcom_snd_parse_of()) this isn't going > to create a PCM device. The PCM devices are created for nodes that > don't have a codec and platform defined: > > mm1-dai-link { > link-name = "MultiMedia1"; > cpu { > sound-dai = <&q6asmdai MSM_FRONTEND_DAI_MULTIMEDIA1>; > }; > }; > > The ASM path is the entity that defines the number of PCM devices that > is created for the QC ASoC platform card, and is where the actual PCM > data is sent over to the DSP. So there could be several PCM devices > that can use the USB BE DAI. ok, but then how would this work with the ALSA controls reporting which PCM device can be used? I didn't see a mechanism allowing for more than one offloaded device, IIRC the control reported just ONE PCM device number.
On 5/8/24 18:40, Wesley Cheng wrote: > Hi Pierre, > > On 5/7/2024 2:20 PM, Pierre-Louis Bossart wrote: >> >>> If a PCM device is already in use, the check will return an error to >>> userspace notifying that the stream is currently busy. This ensures >>> that >>> only one path is using the USB substream. >> >> What was the point of having a "USB Mixer" then? > > The USB mixer is intended to enable/route the USB offloading path to the > audio DSP, and is for controlling the ASoC specific entities. This > change is needed to resolve any contention between the USB SND PCM > device (non offload path) and the ASoC USB BE DAI (offload path). Not following, sorry. Is the "USB Mixer" some sort of hardware entity related to USB offload or just a pure DAPM processing widget handling volume and actual mixing between streams? I was trying to get clarity on whether there can be multiple streams mixed before going to the USB endpoint. The commit message "only one path is using the USB substream" is ambiguous, not sure if you are referring to mutual exclusion between offloaded and non-offloaded paths, or number of streams when offloaded is supported. Different concepts/levels.
On 5/8/24 18:57, Wesley Cheng wrote: > Hi Pierre, > > On 5/7/2024 2:23 PM, Pierre-Louis Bossart wrote: >> >>> @@ -113,6 +120,12 @@ static int q6usb_alsa_connection_cb(struct >>> snd_soc_usb *usb, >>> if (connected) { >>> /* We only track the latest USB headset plugged in */ >>> data->active_usb_chip_idx = sdev->card_idx; >>> + >>> + set_bit(sdev->card_idx, &data->available_card_slot); >>> + data->status[sdev->card_idx].sdev = sdev; >> >> Not following the 'only track the latest USB headset plugged in', I >> don't see anything that discard the previously latest headset... >> >> If you plug headset1, then headset2, how is headset1 marked as not >> available for USB offload? >> > > It won't mark headset1 as not available for offload, because offload > could happen on either depending on what is selected (from the kcontrol > as well). Right, so the wording 'only track the latest USB headset plugged in' is incorrect or obsolete, isn't it?
On 5/8/24 19:10, Wesley Cheng wrote: > Hi Pierre, > > On 5/7/2024 2:26 PM, Pierre-Louis Bossart wrote: >> >> >> On 5/7/24 14:51, Wesley Cheng wrote: >>> Add SND kcontrol to SOC USB, which will allow for userpsace to determine >>> which USB card number and PCM device to offload. This allows for >>> userspace >>> to potentially tag an alternate path for a specific USB SND card and PCM >>> device. Previously, control was absent, and the offload path would be >>> enabled on the last USB SND device which was connected. This logic will >>> continue to be applicable if no mixer input is received for specific >>> device >>> selection. >>> >>> An example to configure the offload device using tinymix: >>> tinymix -D 0 set 'USB Offload Playback Route Select' 1 0 >>> >>> The above command will configure the offload path to utilize card#1 >>> and PCM >>> stream#0. >> >> I don't know how this is usable in practice. Using card indices is >> really hard to do, it depends on the order in which devices are >> plugged-in... > > How are the existing mechanisms handling USB audio devices, or what is > the identifier being used? Well it's a mess, that's why I asked. There are configuration work-arounds to make sure that 'local' accessories are handled first and get repeatable card indices. But between USB devices I guess the rule is 'anything goes'. Even if there are two devices connected at boot, the index allocation will depend on probe order. The card names are not necessarily super-useful either, i.e. yesterday I was confused by an USB card named "CODEC" without any details.
>>>> It is expected for the USB offloading driver to add the kcontrol to the >>>> sound card associated with the USB audio device. An example output >>>> would >>>> look like: >>>> >>>> tinymix -D 1 get 'USB Offload Playback Capable Card' >>>> 0 (range -1->32) >>> >>> You already gave the following examples in patch 29: >>> >>> " >>> USB offloading idle: >>> tinymix -D 0 get 'USB Offload Playback Route Status' >>> -->-1, -1 (range -1->32) >>> >>> USB offloading active(USB card#1 pcm#0): >>> tinymix -D 0 get 'USB Offload Playback Route Status' >>> -->1, 0 (range -1->32) >>> " >>> >>> Can you clarify how many controls there would be in the end? >> >> For USB offload situations, there will be a set of controls for >> playback status and playback select. The offload jack will also be >> there to tell us if there is an offload path available for the >> platform ASoC sound card. >> >>> Also isn't tinymix -D N going to give you the controls for card N? >>> >> >> Yes, since the offload portion is handled as a DPCM DAI link to the >> platform ASoC card, it will be included as a kcontrol for that. >> >> Thanks >> Wesley Cheng >> >> > > Sorry for responding again. I read your email again, and wanted to also > add that aside from the above, which are all within the ASoC layer, as > we discussed previously, we should have a kcontrol in the USB SND card > to determine if there is an ASoC platform card capable of offloading. > This is also available from the SND card created by the USB audio device. That makes sense: if the application wanted to use a given endpoint, it could check if there is a 'better' path exposed by another card. It'd be a lot easier than reading controls from random cards. Was this part of this patchset or more of an idea for a future addition?
On 5/8/24 15:06, Wesley Cheng wrote: > Hi Pierre, > > On 5/7/2024 2:40 PM, Pierre-Louis Bossart wrote: >> >> >> On 5/7/24 14:51, Wesley Cheng wrote: >>> For userspace to know about certain capabilities of the current platform >>> card, add tags to the components string that it can use to enable >>> support >>> for that audio path. In case of USB offloading, the "usboffldplybk: >>> 1" tag >> >> usboffloadplayback? >> >> same question as before, do we need spaces? >> > > I think spaces are currently used as a delimiter, so I'll remove the > spaces. > >> And if we have controls, why do we need component strings? The component >> string is not dynamic to the best of my knowledge, this could be >> problematic if the card is no longer capable of supporting this stream, >> while a control can be updated at will. >> > > Maybe I misunderstood your comment here: > > https://lore.kernel.org/linux-usb/925d7c03-c288-49a4-8bcd-395b32810d75@linux.intel.com/ > > At the time, I didn't include the kcontrols on the USB SND portion of > it, which was added after this series. My interpretation was that there > were userspace entities that could query for general information about > what the card supports based on the components string, or sound card > name. I treated this as an independent identifier, since the change to > add the offload capable jack was present. My comment at the time stands: it's very hard to figure out that a random card supports USB and is connected to a given endpoint. It'd be much easier as you wrote in the comments on patch 34 to have a control in the "regular" USB card to point to the 'better' offloaded path exposed by another card. Applications wouldn't need to know what this other card is, they would then use the card:device information directly.
Hi Pierre, On 5/9/2024 5:54 AM, Pierre-Louis Bossart wrote: > > > >>> Wait, is this saying you will have exactly one PCM device/FE DAI >>> connected to the USB BE DAI exposed in patch 11? >>> >>>> + SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, >>>> + usb_mixer_controls, >>>> + ARRAY_SIZE(usb_mixer_controls)), >>>> + >>> >>> And then what is the role of the USB mixer if you only have one input? >>> >>> I must be missing something. >>> >> >> Not sure if this is a QCOM specific implementation, but the way the DT >> is defined for the USB offload path is as follows: >> >> usb-dai-link { >> link-name = "USB Playback"; >> >> cpu { >> sound-dai = <&q6afedai USB_RX>; >> }; >> >> codec { >> sound-dai = <&usbdai USB_RX>; >> }; >> >> platform { >> sound-dai = <&q6routing>; >> }; >> }; >> >> Based on our DT parser helper API (qcom_snd_parse_of()) this isn't going >> to create a PCM device. The PCM devices are created for nodes that >> don't have a codec and platform defined: >> >> mm1-dai-link { >> link-name = "MultiMedia1"; >> cpu { >> sound-dai = <&q6asmdai MSM_FRONTEND_DAI_MULTIMEDIA1>; >> }; >> }; >> >> The ASM path is the entity that defines the number of PCM devices that >> is created for the QC ASoC platform card, and is where the actual PCM >> data is sent over to the DSP. So there could be several PCM devices >> that can use the USB BE DAI. > > ok, but then how would this work with the ALSA controls reporting which > PCM device can be used? I didn't see a mechanism allowing for more than > one offloaded device, IIRC the control reported just ONE PCM device number. With respects to the PCM devices exposed by the ASoC card, the USB Mixer controls which "Multimedia" (ASM) path can be routed to the USB BE DAI. The kcontrols you are mentioning are controlling which USB card and USB PCM device to execute the offloading on. As of now, at least for the QCOM implementation, we support only offloading on one path/USB interface. I can't comment on how other offloading solutions look like, but we pass the USB PCM and card index as part of our AFE port open command (done from USB BE DAI). This will result in a USB QMI message back (from ADSP) to our USB SND offload driver, which carries all the information about the selected card and PCM index to execute offloading on. One thing I can do is to actually make the kcontrols for selecting the PCM and card devices to look at the num_supported_streams. This would at least allow for vendors that have support for more potential offloading streams to select more than one. Thanks Wesley Cheng
Hi Pierre, On 5/9/2024 6:01 AM, Pierre-Louis Bossart wrote: > > > On 5/8/24 18:40, Wesley Cheng wrote: >> Hi Pierre, >> >> On 5/7/2024 2:20 PM, Pierre-Louis Bossart wrote: >>> >>>> If a PCM device is already in use, the check will return an error to >>>> userspace notifying that the stream is currently busy. This ensures >>>> that >>>> only one path is using the USB substream. >>> >>> What was the point of having a "USB Mixer" then? >> >> The USB mixer is intended to enable/route the USB offloading path to the >> audio DSP, and is for controlling the ASoC specific entities. This >> change is needed to resolve any contention between the USB SND PCM >> device (non offload path) and the ASoC USB BE DAI (offload path). > > Not following, sorry. Is the "USB Mixer" some sort of hardware entity > related to USB offload or just a pure DAPM processing widget handling > volume and actual mixing between streams? > It controls which Multimedia (ASM) stream can be routed to the USB BE DAI. > I was trying to get clarity on whether there can be multiple streams > mixed before going to the USB endpoint. The commit message "only one > path is using the USB substream" is ambiguous, not sure if you are > referring to mutual exclusion between offloaded and non-offloaded paths, > or number of streams when offloaded is supported. Different concepts/levels. Ideally we shouldn't. Only one ASM stream should be allowed to open the USB AFE port at a time. Thanks Wesley Cheng
Hi Pierre, On 5/9/2024 6:02 AM, Pierre-Louis Bossart wrote: > > > On 5/8/24 18:57, Wesley Cheng wrote: >> Hi Pierre, >> >> On 5/7/2024 2:23 PM, Pierre-Louis Bossart wrote: >>> >>>> @@ -113,6 +120,12 @@ static int q6usb_alsa_connection_cb(struct >>>> snd_soc_usb *usb, >>>> if (connected) { >>>> /* We only track the latest USB headset plugged in */ >>>> data->active_usb_chip_idx = sdev->card_idx; >>>> + >>>> + set_bit(sdev->card_idx, &data->available_card_slot); >>>> + data->status[sdev->card_idx].sdev = sdev; >>> >>> Not following the 'only track the latest USB headset plugged in', I >>> don't see anything that discard the previously latest headset... >>> >>> If you plug headset1, then headset2, how is headset1 marked as not >>> available for USB offload? >>> >> >> It won't mark headset1 as not available for offload, because offload >> could happen on either depending on what is selected (from the kcontrol >> as well). > > Right, so the wording 'only track the latest USB headset plugged in' is > incorrect or obsolete, isn't it? Sure, I can reword it. Will specify that it "selects the latest USB headset plugged in for offloading" Thanks Wesley Cheng
Hi Pierre, On 5/9/2024 6:11 AM, Pierre-Louis Bossart wrote: > >>>>> It is expected for the USB offloading driver to add the kcontrol to the >>>>> sound card associated with the USB audio device. An example output >>>>> would >>>>> look like: >>>>> >>>>> tinymix -D 1 get 'USB Offload Playback Capable Card' >>>>> 0 (range -1->32) >>>> >>>> You already gave the following examples in patch 29: >>>> >>>> " >>>> USB offloading idle: >>>> tinymix -D 0 get 'USB Offload Playback Route Status' >>>> -->-1, -1 (range -1->32) >>>> >>>> USB offloading active(USB card#1 pcm#0): >>>> tinymix -D 0 get 'USB Offload Playback Route Status' >>>> -->1, 0 (range -1->32) >>>> " >>>> >>>> Can you clarify how many controls there would be in the end? >>> >>> For USB offload situations, there will be a set of controls for >>> playback status and playback select. The offload jack will also be >>> there to tell us if there is an offload path available for the >>> platform ASoC sound card. >>> >>>> Also isn't tinymix -D N going to give you the controls for card N? >>>> >>> >>> Yes, since the offload portion is handled as a DPCM DAI link to the >>> platform ASoC card, it will be included as a kcontrol for that. >>> >>> Thanks >>> Wesley Cheng >>> >>> >> >> Sorry for responding again. I read your email again, and wanted to also >> add that aside from the above, which are all within the ASoC layer, as >> we discussed previously, we should have a kcontrol in the USB SND card >> to determine if there is an ASoC platform card capable of offloading. >> This is also available from the SND card created by the USB audio device. > > That makes sense: if the application wanted to use a given endpoint, it > could check if there is a 'better' path exposed by another card. It'd be > a lot easier than reading controls from random cards. > > Was this part of this patchset or more of an idea for a future addition? Its part of this patchset. Please refer to patch#34. The mixer_usb_offload is initialized by the offload entity residing in USB SND (qc_usb_audio_offload), and will add it to the sound card associated with the USB device. Thanks Wesley Cheng
Hi Pierre, On 5/9/2024 6:17 AM, Pierre-Louis Bossart wrote: > > > On 5/8/24 15:06, Wesley Cheng wrote: >> Hi Pierre, >> >> On 5/7/2024 2:40 PM, Pierre-Louis Bossart wrote: >>> >>> >>> On 5/7/24 14:51, Wesley Cheng wrote: >>>> For userspace to know about certain capabilities of the current platform >>>> card, add tags to the components string that it can use to enable >>>> support >>>> for that audio path. In case of USB offloading, the "usboffldplybk: >>>> 1" tag >>> >>> usboffloadplayback? >>> >>> same question as before, do we need spaces? >>> >> >> I think spaces are currently used as a delimiter, so I'll remove the >> spaces. >> >>> And if we have controls, why do we need component strings? The component >>> string is not dynamic to the best of my knowledge, this could be >>> problematic if the card is no longer capable of supporting this stream, >>> while a control can be updated at will. >>> >> >> Maybe I misunderstood your comment here: >> >> https://lore.kernel.org/linux-usb/925d7c03-c288-49a4-8bcd-395b32810d75@linux.intel.com/ >> >> At the time, I didn't include the kcontrols on the USB SND portion of >> it, which was added after this series. My interpretation was that there >> were userspace entities that could query for general information about >> what the card supports based on the components string, or sound card >> name. I treated this as an independent identifier, since the change to >> add the offload capable jack was present. > > My comment at the time stands: it's very hard to figure out that a > random card supports USB and is connected to a given endpoint. > > It'd be much easier as you wrote in the comments on patch 34 to have a > control in the "regular" USB card to point to the 'better' offloaded > path exposed by another card. Applications wouldn't need to know what > this other card is, they would then use the card:device information > directly. OK, then it might be fine to remove the components tag if patch#34 is there. That kcontrol is exposed as part of the sound card created for the USB device, so if applications queried, it would signify that there is an offload path available. For this kcontrol, it will return the ASoC platform card index, would that be sufficient? Thanks Wesley Cheng
Hi Pierre, On 5/9/2024 6:07 AM, Pierre-Louis Bossart wrote: > > > On 5/8/24 19:10, Wesley Cheng wrote: >> Hi Pierre, >> >> On 5/7/2024 2:26 PM, Pierre-Louis Bossart wrote: >>> >>> >>> On 5/7/24 14:51, Wesley Cheng wrote: >>>> Add SND kcontrol to SOC USB, which will allow for userpsace to determine >>>> which USB card number and PCM device to offload. This allows for >>>> userspace >>>> to potentially tag an alternate path for a specific USB SND card and PCM >>>> device. Previously, control was absent, and the offload path would be >>>> enabled on the last USB SND device which was connected. This logic will >>>> continue to be applicable if no mixer input is received for specific >>>> device >>>> selection. >>>> >>>> An example to configure the offload device using tinymix: >>>> tinymix -D 0 set 'USB Offload Playback Route Select' 1 0 >>>> >>>> The above command will configure the offload path to utilize card#1 >>>> and PCM >>>> stream#0. >>> >>> I don't know how this is usable in practice. Using card indices is >>> really hard to do, it depends on the order in which devices are >>> plugged-in... >> >> How are the existing mechanisms handling USB audio devices, or what is >> the identifier being used? > > Well it's a mess, that's why I asked. > > There are configuration work-arounds to make sure that 'local' > accessories are handled first and get repeatable card indices. > So is the intention of the configuration aspect you're thinking of to have an entry that maps a USB device based on some identifier, which will take the offload path by default? IMO, the concept of this selection of card and PCM device should happen after the application discovers a USB device that is offload capable. For example, maybe the application will use the USB VID/PID to lookup an entry within the configuration. If some offload tag is present, it can further determine which card and PCM devices are associated w/ the USB device? Although this is under the assumption the application has insight to the USB sysfs. > But between USB devices I guess the rule is 'anything goes'. Even if > there are two devices connected at boot, the index allocation will > depend on probe order. The card names are not necessarily super-useful > either, i.e. yesterday I was confused by an USB card named "CODEC" > without any details. That device is very informative :D Thanks Wesley Cheng