From: Ray Chi <raychi@google.com>
To: gregkh@linuxfoundation.org, mathias.nyman@intel.com,
stern@rowland.harvard.edu
Cc: badhri@google.com, albertccwang@google.com,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Ray Chi <raychi@google.com>
Subject: [PATCH 1/2] usb: core: add a hook to check port init status
Date: Tue, 16 Aug 2022 16:38:53 +0800 [thread overview]
Message-ID: <20220816083854.1491886-2-raychi@google.com> (raw)
In-Reply-To: <20220816083854.1491886-1-raychi@google.com>
This patch add a hook to check the port init status. Currently, only
usbcore knows port init status even if the result is bad. It will cause
a USB host keep doing USB enumeration for a long time when the USB host
connects to a broken USB accessory.
The hc_driver could use the hook to know port init status and do possible
error handling according to platform requirements or limitations.
Signed-off-by: Ray Chi <raychi@google.com>
---
drivers/usb/core/hub.c | 14 ++++++++++++++
include/linux/usb/hcd.h | 8 ++++++++
2 files changed, 22 insertions(+)
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index 2633acde7ac1..6ce6092816cb 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -4659,6 +4659,16 @@ static int hub_enable_device(struct usb_device *udev)
return hcd->driver->enable_device(hcd, udev);
}
+static int hub_port_check_init_status(struct usb_device *udev, int r)
+{
+ struct usb_hcd *hcd = bus_to_hcd(udev->bus);
+
+ if (!hcd->driver->check_init_status)
+ return 0;
+
+ return hcd->driver->check_init_status(hcd, udev, r);
+}
+
/* Reset device, (re)assign address, get device descriptor.
* Device connection must be stable, no more debouncing needed.
* Returns device in USB_STATE_ADDRESS, except on error.
@@ -4855,6 +4865,10 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
buf->bMaxPacketSize0;
kfree(buf);
+ retval = hub_port_check_init_status(udev, r);
+ if (retval < 0)
+ goto fail;
+
retval = hub_port_reset(hub, port1, udev, delay, false);
if (retval < 0) /* error or disconnect */
goto fail;
diff --git a/include/linux/usb/hcd.h b/include/linux/usb/hcd.h
index 67f8713d3fa3..8fa30b4a6b7d 100644
--- a/include/linux/usb/hcd.h
+++ b/include/linux/usb/hcd.h
@@ -297,6 +297,14 @@ struct hc_driver {
gfp_t mem_flags);
void (*unmap_urb_for_dma)(struct usb_hcd *hcd, struct urb *urb);
+ /*
+ * (optional) HCD could get the information of GET_DESCRIPTOR by this hook.
+ * In general, it is not necessary unless the enumeration takes long
+ * time to do. The host controller could know the enumeration status by
+ * this hook and do some error handlings.
+ */
+ int (*check_init_status)(struct usb_hcd *hcd, struct usb_device *udev, int r);
+
/* hw synch, freeing endpoint resources that urb_dequeue can't */
void (*endpoint_disable)(struct usb_hcd *hcd,
struct usb_host_endpoint *ep);
--
2.37.1.595.g718a3a8f04-goog
next prev parent reply other threads:[~2022-08-16 9:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 8:38 [PATCH 0/2] Provide a hook to check port init status Ray Chi
2022-08-16 8:38 ` Ray Chi [this message]
2022-08-16 13:53 ` [PATCH 1/2] usb: core: add " Alan Stern
2022-08-16 8:38 ` [PATCH 2/2] usb: xhci: add check_init_status hook support Ray Chi
2022-08-16 8:57 ` Greg KH
2022-08-22 15:42 ` Ray Chi
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=20220816083854.1491886-2-raychi@google.com \
--to=raychi@google.com \
--cc=albertccwang@google.com \
--cc=badhri@google.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