Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kmB9x-0004dN-Jl for mharc-grub-devel@gnu.org; Mon, 07 Dec 2020 02:42:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:54162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmB9u-0004Yx-Nc for grub-devel@gnu.org; Mon, 07 Dec 2020 02:42:10 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:55975) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kmB9r-0007n7-0q for grub-devel@gnu.org; Mon, 07 Dec 2020 02:42:10 -0500 Received: by mail-wm1-x343.google.com with SMTP id x22so10566960wmc.5 for ; Sun, 06 Dec 2020 23:42:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3YFVxkk3bRYVBkjxgMAKspzOWcGA1XKStAYuTHbX8o8=; b=KdY0zZNIi3A3YHjqweEfomsYozVyFZfN9P4HEX8QSIbrE4NMv7Y3PaiRJZe3ZW4dpf aIOTB+5ehY/TajYvKvO4zBDqrqnJAUFztc/qPR2PtGGwiPE9vV7pObrev5u/F1KeoHO1 Vns8ymfLotNfkEGU7m1kqfGBRHM0yH4dqlOPYg0QhME9nX4pv14+gqjUkVVHYuPs/DAm ClvVMIeDUtsRFFlai38A+lizcu9x9IvFPXSH0ZVvjGIfd4eL84AYAnENysYq7yQoTGpm OvekLLTiLxURqadhkqobFJ8dJY8r/nDo0es9YoQpwUev5EGgvCrmPysO6ZhxnJ3blFUU LQHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3YFVxkk3bRYVBkjxgMAKspzOWcGA1XKStAYuTHbX8o8=; b=W3CHD19AfAz6L9LybaydRaiXKkroC6hgGHfcl1erYq0RHaeNeN46aFkJBvun59ZqCs B1Yeatx4Zsw5QwbJXzlPv9I3imgDVnTotw10fG1qSOYJ0tq4EgyJ1a0n4aSkI7fVx5Iv Bwj9gJoa1maq6WNFOVmwSdYVqRSfjJ6ZvTxsFQmGHYDg2ZCbfjAVjlDrQ25rDBsQNkUb oh5pgULJmdVbuR2C907ctVpht7WpjA49YNKsD2yih3wu7YxvoQ/4drJdsYb5fvvFWPFu SmvsWAPStN9gzEbHVY+3U5e6Emkq37vjyxiYAZYcftlfz04W83riUsFt+ra5lWphidH7 xA8Q== X-Gm-Message-State: AOAM532HWFg/5s1p4X6FXU8PIPNtMdltEPENxbIpTKPow4pDW/ZFGfVs gUZ5SSHGKEO0+81+EcPdmk4DmLEPFJSqnel8 X-Google-Smtp-Source: ABdhPJysnudTUHJzu70kVSTizgnuvCjfo1U6wUwTk1wB0uaS4uDBJA6Li9RXnog6vNBdK2xrMiRw8Q== X-Received: by 2002:a1c:220a:: with SMTP id i10mr16738515wmi.93.1607326925347; Sun, 06 Dec 2020 23:42:05 -0800 (PST) Received: from rudolphp-notebook.9e.network (b2b-78-94-0-50.unitymedia.biz. [78.94.0.50]) by smtp.gmail.com with ESMTPSA id h83sm13979687wmf.9.2020.12.06.23.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Dec 2020 23:42:04 -0800 (PST) From: Patrick Rudolph To: grub-devel@gnu.org Cc: Patrick Rudolph Subject: [PATCH v2 7/7] grub-core/bus/usb/usbhub: Add xHCI non root hub support Date: Mon, 7 Dec 2020 08:41:27 +0100 Message-Id: <20201207074127.59286-8-patrick.rudolph@9elements.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201207074127.59286-1-patrick.rudolph@9elements.com> References: <20201207074127.59286-1-patrick.rudolph@9elements.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=patrick.rudolph@9elements.com; helo=mail-wm1-x343.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Dec 2020 07:42:11 -0000 Tested on Intel PCH C246, the USB3 hub can be configured by grub. Issues: * USB3 devices connected behind that hub are sometimes not detected. Signed-off-by: Patrick Rudolph --- grub-core/bus/usb/usbhub.c | 40 ++++++++++++++++++++++++++++++++------ include/grub/usbdesc.h | 1 + include/grub/usbtrans.h | 4 ++++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c index 63bee1d1a..841796f2f 100644 --- a/grub-core/bus/usb/usbhub.c +++ b/grub-core/bus/usb/usbhub.c @@ -148,19 +148,32 @@ grub_usb_hub_add_dev (grub_usb_controller_t controller, return dev; } - +static grub_usb_err_t +grub_usb_set_hub_depth(grub_usb_device_t dev, grub_uint8_t depth) +{ + return grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_OUT + | GRUB_USB_REQTYPE_CLASS + | GRUB_USB_REQTYPE_TARGET_DEV), + GRUB_USB_HUB_REQ_SET_HUB_DEPTH, depth, + 0, 0, NULL); +} + static grub_usb_err_t grub_usb_add_hub (grub_usb_device_t dev) { struct grub_usb_usb_hubdesc hubdesc; grub_usb_err_t err; + grub_uint16_t req; int i; - + + req = (dev->speed == GRUB_USB_SPEED_SUPER) ? GRUB_USB_DESCRIPTOR_SS_HUB : + GRUB_USB_DESCRIPTOR_HUB; + err = grub_usb_control_msg (dev, (GRUB_USB_REQTYPE_IN | GRUB_USB_REQTYPE_CLASS | GRUB_USB_REQTYPE_TARGET_DEV), - GRUB_USB_REQ_GET_DESCRIPTOR, - (GRUB_USB_DESCRIPTOR_HUB << 8) | 0, + GRUB_USB_REQ_GET_DESCRIPTOR, + (req << 8) | 0, 0, sizeof (hubdesc), (char *) &hubdesc); if (err) return err; @@ -183,6 +196,19 @@ grub_usb_add_hub (grub_usb_device_t dev) return GRUB_USB_ERR_INTERNAL; } + if (dev->speed == GRUB_USB_SPEED_SUPER) + { + grub_uint8_t depth; + grub_uint32_t route; + /* Depth maximum value is 5, but root hubs doesn't count */ + for (depth = 0, route = dev->route; (route & 0xf) > 0; route >>= 4) + depth++; + + err = grub_usb_set_hub_depth(dev, depth); + if (err) + return err; + } + /* Power on all Hub ports. */ for (i = 1; i <= hubdesc.portcnt; i++) { @@ -637,7 +663,9 @@ poll_nonroot_hub (grub_usb_device_t dev) int split_hubaddr = 0; /* Determine the device speed. */ - if (status & GRUB_USB_HUB_STATUS_PORT_LOWSPEED) + if (dev->speed == GRUB_USB_SPEED_SUPER) + speed = GRUB_USB_SPEED_SUPER; + else if (status & GRUB_USB_HUB_STATUS_PORT_LOWSPEED) speed = GRUB_USB_SPEED_LOW; else { @@ -651,7 +679,7 @@ poll_nonroot_hub (grub_usb_device_t dev) grub_millisleep (10); /* Find correct values for SPLIT hubport and hubaddr */ - if (speed == GRUB_USB_SPEED_HIGH) + if (speed == GRUB_USB_SPEED_HIGH || speed == GRUB_USB_SPEED_SUPER) { /* HIGH speed device needs not transaction translation */ split_hubport = 0; diff --git a/include/grub/usbdesc.h b/include/grub/usbdesc.h index bb2ab2e27..1697aa465 100644 --- a/include/grub/usbdesc.h +++ b/include/grub/usbdesc.h @@ -30,6 +30,7 @@ typedef enum { GRUB_USB_DESCRIPTOR_ENDPOINT, GRUB_USB_DESCRIPTOR_DEBUG = 10, GRUB_USB_DESCRIPTOR_HUB = 0x29, + GRUB_USB_DESCRIPTOR_SS_HUB = 0x2a, GRUB_USB_DESCRIPTOR_SS_ENDPOINT_COMPANION = 0x30 } grub_usb_descriptor_t; diff --git a/include/grub/usbtrans.h b/include/grub/usbtrans.h index aef482cb9..a5891e663 100644 --- a/include/grub/usbtrans.h +++ b/include/grub/usbtrans.h @@ -110,6 +110,10 @@ enum GRUB_USB_REQ_SET_INTERFACE = 0x0B, GRUB_USB_REQ_SYNC_FRAME = 0x0C }; +enum + { + GRUB_USB_HUB_REQ_SET_HUB_DEPTH = 0x0C, + }; #define GRUB_USB_FEATURE_ENDP_HALT 0x00 #define GRUB_USB_FEATURE_DEV_REMOTE_WU 0x01 -- 2.26.2