All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alan Stern <stern@rowland.harvard.edu>
To: "Lu, Baolu" <baolu.lu@linux.intel.com>
Cc: Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	<linux-usb@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH v2 1/3] usb: core: lpm: fix usb3_hardware_lpm sysfs node
Date: Fri, 13 Nov 2015 10:28:47 -0500 (EST)	[thread overview]
Message-ID: <Pine.LNX.4.44L0.1511131024250.1719-100000@iolanthe.rowland.org> (raw)
In-Reply-To: <56457B35.6000205@linux.intel.com>

On Fri, 13 Nov 2015, Lu, Baolu wrote:

> On 11/13/2015 12:20 AM, Alan Stern wrote:
> > On Thu, 12 Nov 2015, Lu Baolu wrote:
> >
> >> Commit 655fe4effe0f ("usbcore: add sysfs support to xHCI usb3
> >> hardware LPM") introduced usb3_hardware_lpm sysfs node. This
> >> doesn't show the correct status of USB3 U1 and U2 LPM status.
> >>
> >> This patch fixes this by replacing usb3_hardware_lpm with two
> >> nodes, usb3_hardware_lpm_u1 (for U1) and usb3_hardware_lpm_u2
> >> (for U2), and recording the U1/U2 LPM status in right places.
> >>
> >> This patch should be back-ported to kernels as old as 4.3,
> >> that contains Commit 655fe4effe0f ("usbcore: add sysfs support
> >> to xHCI usb3 hardware LPM").
> >>
> >> Cc: stable@vger.kernel.org
> >> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
> > ...
> >
> >> --- a/drivers/usb/core/hub.c
> >> +++ b/drivers/usb/core/hub.c
> >> @@ -3875,17 +3875,23 @@ static void usb_enable_link_state(struct usb_hcd *hcd, struct usb_device *udev,
> >>   		return;
> >>   	}
> >>   
> >> -	if (usb_set_lpm_timeout(udev, state, timeout))
> >> +	ret = usb_set_lpm_timeout(udev, state, timeout);
> >> +	if (ret)
> >>   		/* If we can't set the parent hub U1/U2 timeout,
> >>   		 * device-initiated LPM won't be allowed either, so let the xHCI
> >>   		 * host know that this link state won't be enabled.
> >>   		 */
> >>   		hcd->driver->disable_usb3_lpm_timeout(hcd, udev, state);
> >> -
> >>   	/* Only a configured device will accept the Set Feature U1/U2_ENABLE */
> >>   	else if (udev->actconfig)
> >>   		usb_set_device_initiated_lpm(udev, state, true);
> >>   
> >> +	if (!ret) {
> >> +		if (state == USB3_LPM_U1)
> >> +			udev->usb3_lpm_u1_enabled = 1;
> >> +		else if (state == USB3_LPM_U2)
> >> +			udev->usb3_lpm_u2_enabled = 1;
> >> +	}
> > This doesn't look right at all.  What happens if ret is 0 but the
> > device isn't configured?  You'll set the usb3_lpm_u*_enabled flag even
> > though LPM isn't really enabled.
> >
> > Don't you want to set these flags inside the
> > usb_set_device_initiated_lpm() function, where you know whether the
> > action succeeded?  And leave this routine unchanged?
> 
> My understand is that both hub and device can initiate LPM.
> As soon as usb_set_lpm_timeout(valid_timeout_value)
> returns 0, the hub-initiated LPM is enabled. Thus, LPM is
> enabled no matter the result of usb_set_device_initiated_lpm().
> The only difference is whether device is able to initiate LPM.
> 
> On disable side, as soon as usb_set_lpm_timeout(0) return 0,
> hub initiated LPM is disabled. Hub will disallows link to enter
> U1/U2 as well, even device is initiating LPM. Hence LPM
> is disabled as soon as hub LPM timeout set to 0, no matter
> device-initiated LPM is disabled or not.

Then maybe you can add a comment explaining this.

The patch still looks strange, though.  Your new code does this:

	ret = usb_set_lpm_timeout(...);
	if (ret)
		...
	else if (udev->actconfig)
		...
	if (!ret) {
		if (state == USB3_LPM_U1)
		...
	}

It would be better to do this:

	if (usb_set_lpm_timeout(...)) {
		...
	} else {
		if (udev->actconfig)
			...
		if (state == USB3_LPM_U1)
		...
	}

Alan Stern


  reply	other threads:[~2015-11-13 15:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-12  2:19 [PATCH v2 0/3] usb: core: lpm: add sysfs node for usb3 lpm permit Lu Baolu
2015-11-12  2:19 ` [PATCH v2 1/3] usb: core: lpm: fix usb3_hardware_lpm sysfs node Lu Baolu
2015-11-12 16:20   ` Alan Stern
2015-11-13  5:55     ` Lu, Baolu
2015-11-13 15:28       ` Alan Stern [this message]
2015-11-14  7:18         ` Lu Baolu
2015-11-12  2:19 ` [PATCH v2 2/3] usb: core: lpm: add sysfs node for usb3 lpm permit Lu Baolu
2015-11-12  2:19 ` [PATCH v2 3/3] usb: core: lpm: remove usb3_lpm_enabled in usb_device Lu Baolu
2015-11-12 16:20   ` Alan Stern
2015-11-13  1:31     ` Lu, Baolu

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=Pine.LNX.4.44L0.1511131024250.1719-100000@iolanthe.rowland.org \
    --to=stern@rowland.harvard.edu \
    --cc=baolu.lu@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=stable@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.