Message ID | 20240228013619.29758-1-quic_wcheng@quicinc.com |
---|---|
Headers | show |
Series | Introduce QC USB SND audio offloading support | expand |
+/** + * qc_usb_audio_offload_suspend() - USB offload PM suspend handler + * @intf: USB interface + * @message: suspend type + * + * PM suspend handler to ensure that the USB offloading driver is able to stop + * any pending traffic, so that the bus can be suspended. + * + */ +static void qc_usb_audio_offload_suspend(struct usb_interface *intf, + pm_message_t message) +{ + struct qmi_uaudio_stream_ind_msg_v01 disconnect_ind = {0}; + struct snd_usb_audio *chip = usb_get_intfdata(intf); + struct uaudio_qmi_svc *svc = uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num = chip->card->number; + if (card_num >= SNDRV_CARDS) + return; + + + mutex_lock(&chip->mutex); + dev = &uadev[card_num]; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + dev_dbg(uaudio_qdev->data->dev, "sending qmi indication suspend\n"); + disconnect_ind.dev_event = USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id = dev->udev->slot_id; + disconnect_ind.controller_num = dev->usb_core_id; + disconnect_ind.controller_num_valid = 1; + ret = qmi_send_indication(svc->uaudio_svc_hdl, &svc->client_sq, + QMI_UAUDIO_STREAM_IND_V01, + QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_ind_msg_v01_ei, + &disconnect_ind); + if (ret < 0) + dev_err(uaudio_qdev->data->dev, + "qmi send failed with err: %d\n", ret); + + ret = wait_event_interruptible_timeout(dev->disconnect_wq, + !atomic_read(&dev->in_use), + msecs_to_jiffies(DEV_RELEASE_WAIT_TIMEOUT)); + if (!ret) { + dev_err(uaudio_qdev->data->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->data->dev, + "failed with ret %d\n", ret); + atomic_set(&dev->in_use, 0); + } + mutex_lock(&chip->mutex); + } + mutex_unlock(&chip->mutex); +} + Hi Wesley, The suspend function `qc_usb_audio_offload_suspend()` looks to stop the traffic on the bus, so that the bus can be suspended. That allows the application processor(AP) to enter suspend. There is a subtle difference with our feature, which is to allow AP suspend with the Host and USB controller active to continue the audio offloading. We call this feature `allow AP suspend in playback`. So, I have some points to clarify with you: 1. Will the suspend flow `usb_audio_suspend() --> platform_ops->suspend_cb() --> qc_usb_audio_offload_suspend()` be called when offloading is active? 2. As my understanding, the suspend function is to allow AP suspend when the offloading is IDLE, but it won't allow AP suspend when in playback or capture. Please correct me if anything is wrong. 3. We would like to integrate the `allow AP suspend in playback` feature with your framework to become one upstream offload solution. Here is the patch: https://patchwork.kernel.org/project/linux-pm/patch/20240223143833.1509961-1-guanyulin@google.com/ . Thanks, Albert
Hi Albert, On 3/13/2024 1:03 AM, Albert Wang wrote: > +/** > + * qc_usb_audio_offload_suspend() - USB offload PM suspend handler > + * @intf: USB interface > + * @message: suspend type > + * > + * PM suspend handler to ensure that the USB offloading driver is able to stop > + * any pending traffic, so that the bus can be suspended. > + * > + */ > +static void qc_usb_audio_offload_suspend(struct usb_interface *intf, > + pm_message_t message) > +{ > + struct qmi_uaudio_stream_ind_msg_v01 disconnect_ind = {0}; > + struct snd_usb_audio *chip = usb_get_intfdata(intf); > + struct uaudio_qmi_svc *svc = uaudio_svc; > + struct uaudio_dev *dev; > + int card_num; > + int ret; > + > + if (!chip) > + return; > + > + card_num = chip->card->number; > + if (card_num >= SNDRV_CARDS) > + return; > + > + > + mutex_lock(&chip->mutex); > + dev = &uadev[card_num]; > + > + if (atomic_read(&dev->in_use)) { > + mutex_unlock(&chip->mutex); > + dev_dbg(uaudio_qdev->data->dev, "sending qmi > indication suspend\n"); > + disconnect_ind.dev_event = USB_QMI_DEV_DISCONNECT_V01; > + disconnect_ind.slot_id = dev->udev->slot_id; > + disconnect_ind.controller_num = dev->usb_core_id; > + disconnect_ind.controller_num_valid = 1; > + ret = qmi_send_indication(svc->uaudio_svc_hdl, &svc->client_sq, > + QMI_UAUDIO_STREAM_IND_V01, > + QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN, > + qmi_uaudio_stream_ind_msg_v01_ei, > + &disconnect_ind); > + if (ret < 0) > + dev_err(uaudio_qdev->data->dev, > + "qmi send failed with err: %d\n", ret); > + > + ret = wait_event_interruptible_timeout(dev->disconnect_wq, > + !atomic_read(&dev->in_use), > + msecs_to_jiffies(DEV_RELEASE_WAIT_TIMEOUT)); > + if (!ret) { > + dev_err(uaudio_qdev->data->dev, > + "timeout while waiting for dev_release\n"); > + atomic_set(&dev->in_use, 0); > + } else if (ret < 0) { > + dev_err(uaudio_qdev->data->dev, > + "failed with ret %d\n", ret); > + atomic_set(&dev->in_use, 0); > + } > + mutex_lock(&chip->mutex); > + } > + mutex_unlock(&chip->mutex); > +} > + > > Hi Wesley, > > The suspend function `qc_usb_audio_offload_suspend()` looks to stop > the traffic on the bus, so that the bus can be suspended. That allows > the application processor(AP) to enter suspend. There is a subtle > difference with our feature, which is to allow AP suspend with the > Host and USB controller active to continue the audio offloading. We > call this feature `allow AP suspend in playback`. So, I have some > points to clarify with you: Yes, I'm aware of that feature also. > 1. Will the suspend flow `usb_audio_suspend() --> > platform_ops->suspend_cb() --> qc_usb_audio_offload_suspend()` be > called when offloading is active? It can be. This is why in our case, we are going to issue the disconnect event to the audio DSP to stop the session if it is currently in one. > 2. As my understanding, the suspend function is to allow AP suspend > when the offloading is IDLE, but it won't allow AP suspend when in > playback or capture. Please correct me if anything is wrong. As mentioned above, it will let apps go into PM suspend after forcing the audio stream to be idle. We won't block PM suspend entry. > 3. We would like to integrate the `allow AP suspend in playback` > feature with your framework to become one upstream offload solution. > Here is the patch: > https://patchwork.kernel.org/project/linux-pm/patch/20240223143833.1509961-1-guanyulin@google.com/ > . Yes, I saw that patch as well. I'll take a look once this series lands upstream. Thanks Wesley Cheng
On Thu, Mar 14, 2024 at 3:18 AM Wesley Cheng <quic_wcheng@quicinc.com> wrote: > > Hi Albert, > > On 3/13/2024 1:03 AM, Albert Wang wrote: > > Hi Wesley, > > > > The suspend function `qc_usb_audio_offload_suspend()` looks to stop > > the traffic on the bus, so that the bus can be suspended. That allows > > the application processor(AP) to enter suspend. There is a subtle > > difference with our feature, which is to allow AP suspend with the > > Host and USB controller active to continue the audio offloading. We > > call this feature `allow AP suspend in playback`. So, I have some > > points to clarify with you: > > Yes, I'm aware of that feature also. > > > 1. Will the suspend flow `usb_audio_suspend() --> > > platform_ops->suspend_cb() --> qc_usb_audio_offload_suspend()` be > > called when offloading is active? > > It can be. This is why in our case, we are going to issue the > disconnect event to the audio DSP to stop the session if it is currently > in one. > > > 2. As my understanding, the suspend function is to allow AP suspend > > when the offloading is IDLE, but it won't allow AP suspend when in > > playback or capture. Please correct me if anything is wrong. > > As mentioned above, it will let apps go into PM suspend after forcing > the audio stream to be idle. We won't block PM suspend entry. > Right. Your design is to force the audio stream idle, or say, inform the audio DSP to stop the current offloading session first, then AP can go into PM suspend as usual. Then I can say the current design did not support the `allow AP suspend in playback` feature, right? > Yes, I saw that patch as well. I'll take a look once this series lands > upstream. That patch is rejected and archived now. So we need to find another approach to do that, even based on your framework. Thanks, Albert > > 3. We would like to integrate the `allow AP suspend in playback` > > feature with your framework to become one upstream offload solution. > > Here is the patch: > > https://patchwork.kernel.org/project/linux-pm/patch/20240223143833.1509961-1-guanyulin@google.com/ > > . > > Yes, I saw that patch as well. I'll take a look once this series lands > upstream. > > Thanks > Wesley Cheng
Hi Albert On 3/14/2024 3:29 AM, Albert Wang wrote: > On Thu, Mar 14, 2024 at 3:18 AM Wesley Cheng <quic_wcheng@quicinc.com> wrote: >> >> Hi Albert, >> >> On 3/13/2024 1:03 AM, Albert Wang wrote: >>> Hi Wesley, >>> >>> The suspend function `qc_usb_audio_offload_suspend()` looks to stop >>> the traffic on the bus, so that the bus can be suspended. That allows >>> the application processor(AP) to enter suspend. There is a subtle >>> difference with our feature, which is to allow AP suspend with the >>> Host and USB controller active to continue the audio offloading. We >>> call this feature `allow AP suspend in playback`. So, I have some >>> points to clarify with you: >> >> Yes, I'm aware of that feature also. >> >>> 1. Will the suspend flow `usb_audio_suspend() --> >>> platform_ops->suspend_cb() --> qc_usb_audio_offload_suspend()` be >>> called when offloading is active? >> >> It can be. This is why in our case, we are going to issue the >> disconnect event to the audio DSP to stop the session if it is currently >> in one. >> >>> 2. As my understanding, the suspend function is to allow AP suspend >>> when the offloading is IDLE, but it won't allow AP suspend when in >>> playback or capture. Please correct me if anything is wrong. >> >> As mentioned above, it will let apps go into PM suspend after forcing >> the audio stream to be idle. We won't block PM suspend entry. >> > Right. Your design is to force the audio stream idle, or say, inform > the audio DSP > to stop the current offloading session first, then AP can go into PM > suspend as usual. > Then I can say the current design did not support the `allow AP > suspend in playback` > feature, right? > Correct, this series does not cover this mechanism. >> Yes, I saw that patch as well. I'll take a look once this series lands >> upstream. > > That patch is rejected and archived now. So we need to find another > approach to do > that, even based on your framework. > We can discuss that offline and come up with an approach that is reviewable by maintainers and the community. Thanks Wesley Cheng > Thanks, > Albert > > >>> 3. We would like to integrate the `allow AP suspend in playback` >>> feature with your framework to become one upstream offload solution. >>> Here is the patch: >>> https://patchwork.kernel.org/project/linux-pm/patch/20240223143833.1509961-1-guanyulin@google.com/ >>> . >> >> Yes, I saw that patch as well. I'll take a look once this series lands >> upstream. >> >> Thanks >> Wesley Cheng
> We can discuss that offline and come up with an approach that is > reviewable by maintainers and the community. Sure, looking forward to working together with you! Thanks, Albert Wang On Fri, Mar 15, 2024 at 4:57 AM Wesley Cheng <quic_wcheng@quicinc.com> wrote: > > Hi Albert > > On 3/14/2024 3:29 AM, Albert Wang wrote: > > On Thu, Mar 14, 2024 at 3:18 AM Wesley Cheng <quic_wcheng@quicinc.com> wrote: > >> > >> Hi Albert, > >> > >> On 3/13/2024 1:03 AM, Albert Wang wrote: > >>> Hi Wesley, > >>> > >>> The suspend function `qc_usb_audio_offload_suspend()` looks to stop > >>> the traffic on the bus, so that the bus can be suspended. That allows > >>> the application processor(AP) to enter suspend. There is a subtle > >>> difference with our feature, which is to allow AP suspend with the > >>> Host and USB controller active to continue the audio offloading. We > >>> call this feature `allow AP suspend in playback`. So, I have some > >>> points to clarify with you: > >> > >> Yes, I'm aware of that feature also. > >> > >>> 1. Will the suspend flow `usb_audio_suspend() --> > >>> platform_ops->suspend_cb() --> qc_usb_audio_offload_suspend()` be > >>> called when offloading is active? > >> > >> It can be. This is why in our case, we are going to issue the > >> disconnect event to the audio DSP to stop the session if it is currently > >> in one. > >> > >>> 2. As my understanding, the suspend function is to allow AP suspend > >>> when the offloading is IDLE, but it won't allow AP suspend when in > >>> playback or capture. Please correct me if anything is wrong. > >> > >> As mentioned above, it will let apps go into PM suspend after forcing > >> the audio stream to be idle. We won't block PM suspend entry. > >> > > Right. Your design is to force the audio stream idle, or say, inform > > the audio DSP > > to stop the current offloading session first, then AP can go into PM > > suspend as usual. > > Then I can say the current design did not support the `allow AP > > suspend in playback` > > feature, right? > > > > Correct, this series does not cover this mechanism. > > >> Yes, I saw that patch as well. I'll take a look once this series lands > >> upstream. > > > > That patch is rejected and archived now. So we need to find another > > approach to do > > that, even based on your framework. > > > > We can discuss that offline and come up with an approach that is > reviewable by maintainers and the community. > > Thanks > Wesley Cheng > > > Thanks, > > Albert > > > > > >>> 3. We would like to integrate the `allow AP suspend in playback` > >>> feature with your framework to become one upstream offload solution. > >>> Here is the patch: > >>> https://patchwork.kernel.org/project/linux-pm/patch/20240223143833.1509961-1-guanyulin@google.com/ > >>> . > >> > >> Yes, I saw that patch as well. I'll take a look once this series lands > >> upstream. > >> > >> Thanks > >> Wesley Cheng
Hi, On 2/27/2024 5:35 PM, Wesley Cheng wrote: > Several Qualcomm based chipsets can support USB audio offloading to a > dedicated audio DSP, which can take over issuing transfers to the USB > host controller. The intention is to reduce the load on the main > processors in the SoC, and allow them to be placed into lower power modes. > There are several parts to this design: > 1. Adding ASoC binding layer > 2. Create a USB backend for Q6DSP > 3. Introduce XHCI interrupter support > 4. Create vendor ops for the USB SND driver > > USB | ASoC > -------------------------------------------------------------------- > | _________________________ > | |sm8250 platform card | > | |_________________________| > | | | > | ___V____ ____V____ > | |Q6USB | |Q6AFE | > | |"codec" | |"cpu" | > | |________| |_________| > | ^ ^ ^ > | | |________| > | ___V____ | > | |SOC-USB | | > ________ ________ | | | > |USB SND |<--->|QC offld|<------------>|________| | > |(card.c)| | |<---------- | > |________| |________|___ | | | > ^ ^ | | | ____________V_________ > | | | | | |APR/GLINK | > __ V_______________V_____ | | | |______________________| > |USB SND (endpoint.c) | | | | ^ > |_________________________| | | | | > ^ | | | ___________V___________ > | | | |->|audio DSP | > ___________V_____________ | | |_______________________| > |XHCI HCD |<- | > |_________________________| | > > > Adding ASoC binding layer: > soc-usb: Intention is to treat a USB port similar to a headphone jack. > The port is always present on the device, but cable/pin status can be > enabled/disabled. Expose mechanisms for USB backend ASoC drivers to > communicate with USB SND. > > Create a USB backend for Q6DSP: > q6usb: Basic backend driver that will be responsible for maintaining the > resources needed to initiate a playback stream using the Q6DSP. Will > be the entity that checks to make sure the connected USB audio device > supports the requested PCM format. If it does not, the PCM open call will > fail, and userpsace ALSA can take action accordingly. > > Introduce XHCI interrupter support: > XHCI HCD supports multiple interrupters, which allows for events to be routed > to different event rings. This is determined by "Interrupter Target" field > specified in Section "6.4.1.1 Normal TRB" of the XHCI specification. > > Events in the offloading case will be routed to an event ring that is assigned > to the audio DSP. > > Create vendor ops for the USB SND driver: > qc_audio_offload: This particular driver has several components associated > with it: > - QMI stream request handler > - XHCI interrupter and resource management > - audio DSP memory management > > When the audio DSP wants to enable a playback stream, the request is first > received by the ASoC platform sound card. Depending on the selected route, > ASoC will bring up the individual DAIs in the path. The Q6USB backend DAI > will send an AFE port start command (with enabling the USB playback path), and > the audio DSP will handle the request accordingly. > > Part of the AFE USB port start handling will have an exchange of control > messages using the QMI protocol. The qc_audio_offload driver will populate the > buffer information: > - Event ring base address > - EP transfer ring base address > > and pass it along to the audio DSP. All endpoint management will now be handed > over to the DSP, and the main processor is not involved in transfers. > > Overall, implementing this feature will still expose separate sound card and PCM > devices for both the platorm card and USB audio device: > 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D > SM8250-MTP-WCD9380-WSA8810-VA-DMIC > 1 [Audio ]: USB-Audio - USB Audio > Generic USB Audio at usb-xhci-hcd.1.auto-1.4, high speed > > This is to ensure that userspace ALSA entities can decide which route to take > when executing the audio playback. In the above, if card#1 is selected, then > USB audio data will take the legacy path over the USB PCM drivers, etc... > > This feature was validated using: > - tinymix: set/enable the multimedia path to route to USB backend > - tinyplay: issue playback on platform card > > Changelog > -------------------------------------------- > Changes in v18: > - Rebased to usb-next, which merged in part of the series. Removed these patches. > - Reworked Kconfigs for the ASoC USB related components from QCOM Q6DSP drivers > to keep dependencies in place for SoC USB and USB SND. > - Removed the repurposing of the stop ep sync API into existing XHCI operations. > This will be solely used by the XHCI sideband for now. > Wanted to give a friendly ping to see if there were any more concerns/feedback about this series before I submit a new revision that rebases to the latest kernel codebase? Thanks Wesley Cheng