Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752666AbbEDDQb (ORCPT ); Sun, 3 May 2015 23:16:31 -0400 Received: from mga02.intel.com ([134.134.136.20]:33683 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752563AbbEDDPh (ORCPT ); Sun, 3 May 2015 23:15:37 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,363,1427785200"; d="scan'208";a="565694307" From: Lu Baolu To: Greg Kroah-Hartman , Mathias Nyman , Alan Stern Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [RFC][PATCH 1/3] usb: add a hcd notify entry in hc_driver Date: Mon, 4 May 2015 11:15:30 +0800 Message-Id: <1430709332-18814-2-git-send-email-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1430709332-18814-1-git-send-email-baolu.lu@linux.intel.com> References: <1430709332-18814-1-git-send-email-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5264 Lines: 145 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. 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 --- 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); + } return rc; } diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c index 45a915c..725d611 100644 --- a/drivers/usb/core/hcd.c +++ b/drivers/usb/core/hcd.c @@ -2289,6 +2289,29 @@ void usb_hcd_resume_root_hub (struct usb_hcd *hcd) } EXPORT_SYMBOL_GPL(usb_hcd_resume_root_hub); +/** + * hcd_notify - notify hcd driver with a message + * @udev: USB device + * @type: message type of this notification + * @data: message type specific data + * + * Call back to hcd driver to notify an event. + */ +void hcd_notify(struct usb_device *udev, + enum hcd_notification_type type, void *data) +{ + struct usb_hcd *hcd; + + if (!udev) + return; + + hcd = bus_to_hcd(udev->bus); + + if (hcd->driver->notify) + hcd->driver->notify(hcd, udev, type, data); +} +EXPORT_SYMBOL_GPL(hcd_notify); + #endif /* CONFIG_PM */ /*-------------------------------------------------------------------------*/ diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h index 68b1e83..bdb422c 100644 --- a/include/linux/usb/hcd.h +++ b/include/linux/usb/hcd.h @@ -76,6 +76,11 @@ struct giveback_urb_bh { struct usb_host_endpoint *completing_ep; }; +enum hcd_notification_type { + HCD_MSG_DEV_SUSPEND = 0, /* USB device suspend */ + HCD_MSG_DEV_RESUME, /* USB device resume */ +}; + struct usb_hcd { /* @@ -383,7 +388,9 @@ struct hc_driver { int (*find_raw_port_number)(struct usb_hcd *, int); /* Call for power on/off the port if necessary */ int (*port_power)(struct usb_hcd *hcd, int portnum, bool enable); - + /* Call to notify hcd when it is necessary. */ + void (*notify)(struct usb_hcd *, struct usb_device *, + enum hcd_notification_type, void *); }; static inline int hcd_giveback_urb_in_bh(struct usb_hcd *hcd) @@ -632,6 +639,8 @@ extern void usb_root_hub_lost_power(struct usb_device *rhdev); extern int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg); extern int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg); extern void usb_hcd_resume_root_hub(struct usb_hcd *hcd); +extern void hcd_notify(struct usb_device *udev, + enum hcd_notification_type type, void *data); #else static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) { -- 2.1.0 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/