From patchwork Wed Mar 29 03:04:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marek_Marczykowski-G=C3=B3recki?= X-Patchwork-Id: 13191840 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3325DC76196 for ; Wed, 29 Mar 2023 03:05:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229733AbjC2DFP (ORCPT ); Tue, 28 Mar 2023 23:05:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjC2DFM (ORCPT ); Tue, 28 Mar 2023 23:05:12 -0400 Received: from wout3-smtp.messagingengine.com (wout3-smtp.messagingengine.com [64.147.123.19]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 675DA1FCA for ; Tue, 28 Mar 2023 20:05:07 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 8A514320090F for ; Tue, 28 Mar 2023 23:05:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Tue, 28 Mar 2023 23:05:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= invisiblethingslab.com; h=cc:content-type:content-type:date:date :from:from:in-reply-to:message-id:mime-version:reply-to:sender :subject:subject:to:to; s=fm2; t=1680059104; x=1680145504; bh=/o 2/9xrnfJysVp8kA9cnc6R2XdFxnEEL+xZZLUzc8HU=; b=gUFk8vWYnDV79yHf6Y D02PQZUUMQMpuv62TGN8tTyy10YwkzCgVSyHnYro8+OEapW7aka41PqF+eVTUl6i CXEXxebE9W8LyZ0+6WYqW9FBsKqzJ2LbA3nU42/LalmFuEZK3qyIvCgNGsZ7II4l nyIT1phhWa5AQsOa0XGEG/GF/xe1kpPRgYOvyV0zh/ybuhFIzzwd3Ed3rTGzaiWV 35i4Xqgrm48FE5P8B89z5omtqENAVo3yOfQn7fhTjCg0Z5JyFOMf0uJKQaXQ7fNL fC09jtTerEbpPXYK+M1n1SjxFdtefZDgwSBAz+VK8K2viXSjV6oPqrwLKPnsE/tM AkSQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1680059104; x=1680145504; bh=/o2/9xrnfJysVp8kA9cnc6R2XdFxnEEL+xZ ZLUzc8HU=; b=q9m9yQ6iB3iB6CCrJHBxukkNf6gxee1RsM2Tz1JYgCFRo1GdWmM uwPiljGW5dXg0fOalGJkxVqfNQRAwB4+/riA8HfMh/Q+Kpwygn8ssPpeBox7Kc+p OUpBX1KRR3qKaqDhB7DC5xB/rD+ZtlhvrurY0SDpp8uReo1Z5uu6+fY24qgB1VL0 rsj2BwAvwhIs5ZqDV80jRf4O8Jqd+caOHXLzXeBrAibzh3nAYXCzlO9wxqr4uNCd 0sOZpZTHBpKs28e6tuByDs03ay2WPka8e8jV41vsdwFWt83WMhhHx17f+Rha+54n xtKCkIz2A4T/cKoGtxLRIAH1yAJHZZIGm0Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehhedgieeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugesghdtreertd dtjeenucfhrhhomhepofgrrhgvkhcuofgrrhgtiiihkhhofihskhhiqdfikphrvggtkhhi uceomhgrrhhmrghrvghksehinhhvihhsihgslhgvthhhihhnghhslhgrsgdrtghomheqne cuggftrfgrthhtvghrnhepgffffeetvddtjeekjefhudduudekffekjefhuefgffetfefg tdektdeiveeitefgnecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmrghrmhgrrhgvkhesihhn vhhishhisghlvghthhhinhhgshhlrggsrdgtohhm X-ME-Proxy: Feedback-ID: i1568416f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Tue, 28 Mar 2023 23:05:03 -0400 (EDT) Date: Wed, 29 Mar 2023 05:04:58 +0200 From: Marek =?utf-8?q?Marczykowski-G=C3=B3recki?= To: linux-usb@vger.kernel.org Subject: earlyprintk=xdbc doesn't work on AMD Renoir Message-ID: MIME-Version: 1.0 Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Hello, I'm trying to get early console working via USB3 debug capability[*]. It works fine on Intel, but on AMD it does not. First issue is that the BAR0 is 1MB and it's too big for early_ioremap(). Since all the DbC-related registers are quite early (first page), this hack kinda works: ---8<--- ---8<--- but it did not helped. I've checked DbC registers in those two situations: When it works: control: 0x820f003, status: 0x06000000, portsc: 0x00001003 When it doesn't: control: 0x800f002, status: 0x00000000, portsc: 0x000000a0 Any ideas? Specific hardware is: AMD Ryzen 5 4500U, HP Probook 445 G7/8730 Full dmesg attached. The related controller is 04:00.3. PS I added `#define xdbc_trace printk`, as I couldn't figure out how to use tracing API. How to do that properly? [*] In fact, I'm trying to get it working in Xen, but I figured it will be easier to debug it in Linux first and only then do the same in Xen. Details: https://lore.kernel.org/xen-devel/cover.932f486c1b08268190342f8918b09fa6a7c3f149.1670724490.git-series.marmarek@invisiblethingslab.com/ diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c index 341408410ed9..bfd41098fd83 100644 --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -83,6 +84,7 @@ static void __iomem * __init xdbc_map_pci_mmio(u32 bus, u32 dev, u32 func) write_pci_config_byte(bus, dev, func, PCI_COMMAND, byte); } + sz64 = min(sz64, 64ULL * 1024); xdbc.xhci_start = val64; xdbc.xhci_length = sz64; base = early_ioremap(val64, sz64); ---8<--- Then, it fails with: waiting for connection timed out xhci_dbc:early_xdbc_setup_hardware: failed to setup the connection to host On the other hand, enabling it later via sysfs works: [root@test-1 ~]# cat /sys/bus/pci/devices/0000\:04\:00.3/dbc disabled [root@test-1 ~]# echo enable > /sys/bus/pci/devices/0000\:04\:00.3/dbc [root@test-1 ~]# cat /sys/bus/pci/devices/0000\:04\:00.3/dbc configured [root@test-1 ~]# dmesg|tail [ 365.992308] usb usb3-port2: config error [ 370.042302] usb usb3-port2: Cannot enable. Maybe the USB cable is bad? [ 370.042333] usb usb3-port2: config error [ 370.837429] usb usb3-port2: config error [ 371.667309] usb usb3-port2: config error [ 372.499309] usb usb3-port2: config error [ 373.331309] usb usb3-port2: config error [ 374.315309] usb usb3-port2: config error [ 375.003453] xhci_hcd 0000:04:00.3: DbC connected [ 375.459336] xhci_hcd 0000:04:00.3: DbC configured The obvious difference is that later the full xhci driver is loaded and the main controller is initialized. I've tried the simple thing: setting Run/Stop bit to 1 with this hacky patch: ---8<--- diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c index 341408410ed9..03c6a815e3e2 100644 --- a/drivers/usb/early/xhci-dbc.c +++ b/drivers/usb/early/xhci-dbc.c @@ -420,6 +422,22 @@ static int xdbc_start(void) u32 ctrl, status; int ret; + if (xdbc.vendor == PCI_VENDOR_ID_AMD) { + u8 caplen = readb(xdbc.xhci_base); + u32 usbcmd = readl(xdbc.xhci_base + caplen); + xdbc_trace("USBCMD before: %#x\n", usbcmd); + xdbc_trace("USBSTS before: %#x\n", readl(xdbc.xhci_base + caplen + 4)); + writel(usbcmd | 1, xdbc.xhci_base + caplen); + /* wait for HCH to clear */ + ret = handshake(xdbc.xhci_base + caplen + 4, 1, 0, 100000, 100); + if (ret) { + xdbc_trace("failed to enable XHCI\n"); + return ret; + } + xdbc_trace("USBCMD after: %#x\n", readl(xdbc.xhci_base + caplen)); + xdbc_trace("USBSTS after: %#x\n", readl(xdbc.xhci_base + caplen + 4)); + } + ctrl = readl(&xdbc.xdbc_reg->control); writel(ctrl | CTRL_DBC_ENABLE | CTRL_PORT_ENABLE, &xdbc.xdbc_reg->control); ret = handshake(&xdbc.xdbc_reg->control, CTRL_DBC_ENABLE, CTRL_DBC_ENABLE, 100000, 100);