From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Elson Roy Serrao <quic_eserrao@quicinc.com>
Cc: "gregkh@linuxfoundation.org" <gregkh@linuxfoundation.org>,
Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"quic_wcheng@quicinc.com" <quic_wcheng@quicinc.com>,
"quic_jackp@quicinc.com" <quic_jackp@quicinc.com>
Subject: Re: [PATCH v13 5/6] usb: gadget: Handle function suspend feature selector
Date: Fri, 24 Mar 2023 23:09:58 +0000 [thread overview]
Message-ID: <20230324230947.cvs37umprqiswr6b@synopsys.com> (raw)
In-Reply-To: <1679694482-16430-6-git-send-email-quic_eserrao@quicinc.com>
On Fri, Mar 24, 2023, Elson Roy Serrao wrote:
> When host sends function suspend feature selector to the device,
> inspect the received packet and trigger function suspend or
> function resume accordingly. Inspect the remote wakeup bit and
> arm the function for remote wakeup if it is wakeup capable. Also
> host queries the function wakeup capability through a get status
> request before sending function resume. Handle such requests in
> composite layer.
>
> Signed-off-by: Elson Roy Serrao <quic_eserrao@quicinc.com>
> ---
> drivers/usb/gadget/composite.c | 65 ++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 60 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
> index 2111732..d1d7f89 100644
> --- a/drivers/usb/gadget/composite.c
> +++ b/drivers/usb/gadget/composite.c
> @@ -941,6 +941,9 @@ static void reset_config(struct usb_composite_dev *cdev)
> if (f->disable)
> f->disable(f);
>
> + /* Section 9.1.1.6, disable remote wakeup when device is reset */
> + f->func_wakeup_armed = false;
> +
> bitmap_zero(f->endpoints, 32);
> }
> cdev->config = NULL;
> @@ -2006,9 +2009,20 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
> f = cdev->config->interface[intf];
> if (!f)
> break;
> - status = f->get_status ? f->get_status(f) : 0;
> - if (status < 0)
> - break;
> +
> + if (f->get_status) {
> + status = f->get_status(f);
> + if (status < 0)
> + break;
> + } else {
> + /* Set D0 and D1 bits based on func wakeup capability */
> + if (f->config->bmAttributes & USB_CONFIG_ATT_WAKEUP) {
> + status |= USB_INTRF_STAT_FUNC_RW_CAP;
> + if (f->func_wakeup_armed)
> + status |= USB_INTRF_STAT_FUNC_RW;
> + }
> + }
> +
> put_unaligned_le16(status & 0x0000ffff, req->buf);
> break;
> /*
> @@ -2030,8 +2044,44 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
> if (!f)
> break;
> value = 0;
> - if (f->func_suspend)
> + if (f->func_suspend) {
> value = f->func_suspend(f, w_index >> 8);
> + /* SetFeature(FUNCTION_SUSPEND) */
> + } else if (ctrl->bRequest == USB_REQ_SET_FEATURE) {
> + if (!(f->config->bmAttributes &
> + USB_CONFIG_ATT_WAKEUP) &&
> + (w_index & USB_INTRF_FUNC_SUSPEND_RW))
> + break;
> +
> + f->func_wakeup_armed = !!(w_index &
> + USB_INTRF_FUNC_SUSPEND_RW);
> +
> + if (w_index & USB_INTRF_FUNC_SUSPEND_LP) {
> + if (f->suspend && !f->func_suspended) {
> + f->suspend(f);
> + f->func_suspended = true;
> + }
> + /*
> + * Handle cases where host sends function resume
> + * through SetFeature(FUNCTION_SUSPEND) but low power
> + * bit reset
> + */
> + } else {
> + if (f->resume && f->func_suspended) {
> + f->resume(f);
> + f->func_suspended = false;
> + }
> + }
> + /* ClearFeature(FUNCTION_SUSPEND) */
> + } else if (ctrl->bRequest == USB_REQ_CLEAR_FEATURE) {
> + f->func_wakeup_armed = false;
> +
> + if (f->resume && f->func_suspended) {
> + f->resume(f);
> + f->func_suspended = false;
> + }
> + }
> +
> if (value < 0) {
> ERROR(cdev,
> "func_suspend() returned error %d\n",
> @@ -2574,7 +2624,12 @@ void composite_resume(struct usb_gadget *gadget)
> cdev->driver->resume(cdev);
> if (cdev->config) {
> list_for_each_entry(f, &cdev->config->functions, list) {
> - if (f->resume)
> + /*
> + * Check for func_suspended flag to see if the function is
> + * in USB3 FUNCTION_SUSPEND state. In this case resume is
> + * done via FUNCTION_SUSPEND feature selector.
> + */
> + if (f->resume && !f->func_suspended)
> f->resume(f);
> }
>
> --
> 2.7.4
>
Reviewed-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Thanks,
Thinh
next prev parent reply other threads:[~2023-03-24 23:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 21:47 [PATCH v13 0/6] Add function suspend/resume and remote wakeup support Elson Roy Serrao
2023-03-24 21:47 ` [PATCH v13 1/6] usb: gadget: Properly configure the device for remote wakeup Elson Roy Serrao
2023-03-24 21:47 ` [PATCH v13 2/6] usb: dwc3: Add remote wakeup handling Elson Roy Serrao
2023-03-24 21:47 ` [PATCH v13 3/6] usb: gadget: Add function wakeup support Elson Roy Serrao
2023-03-24 21:48 ` [PATCH v13 4/6] usb: dwc3: Add function suspend and " Elson Roy Serrao
2023-03-24 21:48 ` [PATCH v13 5/6] usb: gadget: Handle function suspend feature selector Elson Roy Serrao
2023-03-24 23:09 ` Thinh Nguyen [this message]
2023-03-24 21:48 ` [PATCH v13 6/6] usb: gadget: f_ecm: Add suspend/resume and remote wakeup support Elson Roy Serrao
2023-03-24 23:22 ` Thinh Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230324230947.cvs37umprqiswr6b@synopsys.com \
--to=thinh.nguyen@synopsys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=quic_eserrao@quicinc.com \
--cc=quic_jackp@quicinc.com \
--cc=quic_wcheng@quicinc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®