From: "Lu, Baolu" <baolu.lu@linux.intel.com>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Mathias Nyman <mathias.nyman@intel.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC][PATCH 1/3] usb: add a hcd notify entry in hc_driver
Date: Tue, 05 May 2015 09:05:48 +0800 [thread overview]
Message-ID: <5548176C.7040502@linux.intel.com> (raw)
In-Reply-To: <Pine.LNX.4.44L0.1505041023580.1450-100000@iolanthe.rowland.org>
Hi Alan,
Thanks for your review comments. Below has my response inline.
On 05/04/2015 10:28 PM, Alan Stern wrote:
> On Mon, 4 May 2015, Lu Baolu wrote:
>
>> This patch adds a new entry pointer in hc_driver. With this new entry,
>> USB core can notify host driver when something happens and host driver
>> is willing to be notified. One use case of this interface comes from
>> xHCI compatible host controller driver.
> "Notify" is too generic. It's better to make the callback routine
> specific to the activity in question. So this patch series should add
> "device_suspend" and "device_resume" callbacks, not a general "notify"
> callback.
Fair enough. I will make this change in v2 if there is no objection.
>
>> The xHCI spec is designed to allow an xHC implementation to cache the
>> endpoint state. Caching endpoint state allows an xHC to reduce latency
>> when handling ERDYs and other USB asynchronous events. However holding
>> this state in xHC consumes resources and power. The xHCI spec designs
>> some methods through which host controller driver can hint xHC about
>> how to optimize its operation, e.g. to determine when it holds state
>> internally or pushes it out to memory, when to power down logic, etc.
>>
>> When a USB device is going to suspend, states of all endpoints cached
>> in the xHC should be pushed out to memory to save power and resources.
>> Vice versa, when a USB device resumes, those states should be brought
>> back to the cache. USB core suspends or resumes a USB device by sending
>> set/clear port feature requests to the parent hub where the USB device
>> is connected. Unfortunately, these operations are transparent to xHCI
>> driver unless the USB device is plugged in a root port. This patch
>> utilizes the notify interface to notify xHCI driver whenever a USB
>> device's power state is changed.
>>
>> It is harmless if a USB devices under USB 3.0 host controller suspends
>> or resumes without a notification to hcd driver. However there may be
>> less opportunities for power savings and there may be increased latency
>> for restarting an endpoint. The precise impact will be different for
>> each xHC implementation. It all depends on what an implementation does
>> with the hints.
>>
>> Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
>> ---
>> drivers/usb/core/generic.c | 10 ++++++++--
>> drivers/usb/core/hcd.c | 23 +++++++++++++++++++++++
>> include/linux/usb/hcd.h | 11 ++++++++++-
>> 3 files changed, 41 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/core/generic.c b/drivers/usb/core/generic.c
>> index 358ca8d..92bee33 100644
>> --- a/drivers/usb/core/generic.c
>> +++ b/drivers/usb/core/generic.c
>> @@ -211,8 +211,12 @@ static int generic_suspend(struct usb_device *udev, pm_message_t msg)
>> /* Non-root devices don't need to do anything for FREEZE or PRETHAW */
>> else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
>> rc = 0;
>> - else
>> + else {
>> + hcd_notify(udev, HCD_MSG_DEV_SUSPEND, &msg);
>> rc = usb_port_suspend(udev, msg);
>> + if (rc)
>> + hcd_notify(udev, HCD_MSG_DEV_RESUME, &msg);
>> + }
>>
>> return rc;
>> }
>> @@ -228,8 +232,10 @@ static int generic_resume(struct usb_device *udev, pm_message_t msg)
>> */
>> if (!udev->parent)
>> rc = hcd_bus_resume(udev, msg);
>> - else
>> + else {
>> rc = usb_port_resume(udev, msg);
>> + hcd_notify(udev, HCD_MSG_DEV_RESUME, &msg);
>> + }
> Don't you want to tell the HCD about the resume _before_ it happens?
> After all, the devices endpoint will be used as soon as the resume
> takes place.
The order that software should do during device suspend/resume is
defined in 4.15.1.1 of xHCI spec 1.1.
Spec 4.15.1.1:
Software shall stop all endpoints of a device using the Stop Endpoint
Command and setting the Suspend
(SP) flag to ‘1’ prior to selectively suspending a device. After the
device is resumed software shall ring an
endpoint’s doorbell to restart it.
--end--
So the order looks like:
tell hcd device suspend
usb_port_suspend()
usb_port_resume()
tell hcd device resume
>
> And besides, this should be symmetrical with the code above, where you
> tell the HCD about a suspend _after_ it happens.
This was done in above change in generic_suspend():
@@ -211,8 +211,12 @@ static int generic_suspend(struct usb_device *udev, pm_message_t msg)
/* Non-root devices don't need to do anything for FREEZE or PRETHAW */
else if (msg.event == PM_EVENT_FREEZE || msg.event == PM_EVENT_PRETHAW)
rc = 0;
- else
+ else {
+ hcd_notify(udev, HCD_MSG_DEV_SUSPEND, &msg);
rc = usb_port_suspend(udev, msg);
+ if (rc)
+ hcd_notify(udev, HCD_MSG_DEV_RESUME, &msg);
+ }
return rc;
}
If usb_port_suspend() returns error, we should roll back HCD to the previous state.
>
> Alan Stern
Thanks again,
Baolu
next prev parent reply other threads:[~2015-05-05 1:05 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-04 3:15 [RFC][PATCH 0/3] usb: add a hcd notify entry in hc_driver Lu Baolu
2015-05-04 3:15 ` [RFC][PATCH 1/3] " Lu Baolu
2015-05-04 8:14 ` Greg Kroah-Hartman
2015-05-05 22:36 ` Lu, Baolu
2015-05-04 14:28 ` Alan Stern
2015-05-05 1:05 ` Lu, Baolu [this message]
2015-05-05 14:50 ` Alan Stern
2015-05-06 1:07 ` Lu, Baolu
2015-05-04 3:15 ` [RFC][PATCH 2/3] usb: xhci: implement hc_driver notify entry Lu Baolu
2015-05-04 3:15 ` [RFC][PATCH 3/3] usb: xhci: cleanup unnecessary stop device and ring doorbell operations 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=5548176C.7040502@linux.intel.com \
--to=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=stern@rowland.harvard.edu \
/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