From 565c473a7575febb0684835b9a254bd3104c604b Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Tue, 5 Oct 2021 19:16:16 +0200 Subject: [PATCH] Raspberry Pi U-Boot fixes (#1572) * Add NVMe and XHCI USB driver fix for Raspberry Pi Add patch which fixes NVMe read reliability and allows to compile the XHCI USB driver (for Compute Module 4). * Enable Broadcom XHCI driver for Compute Module 4 The BCM2711 has two USB 2.0 IPs: A Broadcom XHCI USB 2.0 controller and a Synopsys DWC2 USB 2.0 Host/Device controller. When USB boot is used the former is active. Make sure U-Boot has the driver built-in for that IP. --- ...FIG_OF_BOARD-instead-of-CONFIG_EMBED.patch | 6 +- ...usb-xhci-reset-endpoint-on-USB-stall.patch | 10 ++-- .../0003-rpi-add-NVMe-to-boot-order.patch | 10 ++-- ...ect-the-prps-per-page-calculation-me.patch | 10 ++-- ...prove-readability-of-nvme_setup_prps.patch | 10 ++-- ...se-pointer-for-CPU-addressed-buffers.patch | 10 ++-- ...irtual-addresses-into-the-bus-s-addr.patch | 10 ++-- ...date-correct-memory-range-after-read.patch | 57 +++++++++++++++++++ ...-Include-header-file-needed-for-dev_.patch | 32 +++++++++++ .../board/raspberrypi/uboot.config | 2 + 10 files changed, 124 insertions(+), 33 deletions(-) create mode 100644 buildroot-external/board/raspberrypi/patches/uboot/0008-nvme-invalidate-correct-memory-range-after-read.patch create mode 100644 buildroot-external/board/raspberrypi/patches/uboot/0009-drivers-usb-host-Include-header-file-needed-for-dev_.patch diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0001-rpi-Use-CONFIG_OF_BOARD-instead-of-CONFIG_EMBED.patch b/buildroot-external/board/raspberrypi/patches/uboot/0001-rpi-Use-CONFIG_OF_BOARD-instead-of-CONFIG_EMBED.patch index 3135e0d39..b82d5069f 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0001-rpi-Use-CONFIG_OF_BOARD-instead-of-CONFIG_EMBED.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0001-rpi-Use-CONFIG_OF_BOARD-instead-of-CONFIG_EMBED.patch @@ -1,8 +1,8 @@ -From cb3001355d465fa4a2f80cd186700a7bd27ca354 Mon Sep 17 00:00:00 2001 -Message-Id: +From d7ec084799b394cc02395829dc97019c8834e944 Mon Sep 17 00:00:00 2001 +Message-Id: From: Pascal Vizeli Date: Tue, 10 Dec 2019 09:48:46 +0000 -Subject: [PATCH 1/8] rpi: Use CONFIG_OF_BOARD instead of CONFIG_EMBED +Subject: [PATCH 1/9] rpi: Use CONFIG_OF_BOARD instead of CONFIG_EMBED Signed-off-by: Pascal Vizeli --- diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0002-usb-xhci-reset-endpoint-on-USB-stall.patch b/buildroot-external/board/raspberrypi/patches/uboot/0002-usb-xhci-reset-endpoint-on-USB-stall.patch index 08d8759a0..d8e5a0fd4 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0002-usb-xhci-reset-endpoint-on-USB-stall.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0002-usb-xhci-reset-endpoint-on-USB-stall.patch @@ -1,10 +1,10 @@ -From e89cc9ab5b404645bc19f149401b6ac97b35069d Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: +From 3d471d3be58ccd899d29bf57ad669e7a51d0b47d Mon Sep 17 00:00:00 2001 +Message-Id: <3d471d3be58ccd899d29bf57ad669e7a51d0b47d.1633447374.git.stefan@agner.ch> +In-Reply-To: +References: From: Stefan Agner Date: Mon, 27 Sep 2021 12:28:04 +0200 -Subject: [PATCH 2/8] usb: xhci: reset endpoint on USB stall +Subject: [PATCH 2/9] usb: xhci: reset endpoint on USB stall There are devices which cause a USB stall when trying to read strings. Specifically Arduino Mega R3 stalls when trying to read the product diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0003-rpi-add-NVMe-to-boot-order.patch b/buildroot-external/board/raspberrypi/patches/uboot/0003-rpi-add-NVMe-to-boot-order.patch index ece870431..7f3cec7ee 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0003-rpi-add-NVMe-to-boot-order.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0003-rpi-add-NVMe-to-boot-order.patch @@ -1,10 +1,10 @@ -From 130b939a3176abdd483bd30cbed9783d96e68819 Mon Sep 17 00:00:00 2001 -Message-Id: <130b939a3176abdd483bd30cbed9783d96e68819.1632816160.git.stefan@agner.ch> -In-Reply-To: -References: +From 698fc7c39fb3265ccb9cc7f3bb08432b76f3cdf5 Mon Sep 17 00:00:00 2001 +Message-Id: <698fc7c39fb3265ccb9cc7f3bb08432b76f3cdf5.1633447374.git.stefan@agner.ch> +In-Reply-To: +References: From: Stefan Agner Date: Tue, 29 Dec 2020 23:34:52 +0100 -Subject: [PATCH 3/8] rpi: add NVMe to boot order +Subject: [PATCH 3/9] rpi: add NVMe to boot order The Compute Module 4 I/O Board can support a NVMe. Add NVMe to the boot order. diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0004-Revert-nvme-Correct-the-prps-per-page-calculation-me.patch b/buildroot-external/board/raspberrypi/patches/uboot/0004-Revert-nvme-Correct-the-prps-per-page-calculation-me.patch index 60b97a34e..8e4581409 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0004-Revert-nvme-Correct-the-prps-per-page-calculation-me.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0004-Revert-nvme-Correct-the-prps-per-page-calculation-me.patch @@ -1,10 +1,10 @@ -From bb7d531f80d676a26f85982fc2bbb2a0939fd3bf Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: +From fdacde2c24e052938cbb54d15dabc541304d8f40 Mon Sep 17 00:00:00 2001 +Message-Id: +In-Reply-To: +References: From: Stefan Agner Date: Thu, 23 Sep 2021 23:43:31 +0200 -Subject: [PATCH 4/8] Revert "nvme: Correct the prps per page calculation +Subject: [PATCH 4/9] Revert "nvme: Correct the prps per page calculation method" This reverts commit 859b33c948945f7904f60a2c12a3792d356d51ad. diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0005-nvme-improve-readability-of-nvme_setup_prps.patch b/buildroot-external/board/raspberrypi/patches/uboot/0005-nvme-improve-readability-of-nvme_setup_prps.patch index 730f1368a..c07af0b27 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0005-nvme-improve-readability-of-nvme_setup_prps.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0005-nvme-improve-readability-of-nvme_setup_prps.patch @@ -1,10 +1,10 @@ -From a09d03397cad903a7a5925d5a0e9e5262ab9b13e Mon Sep 17 00:00:00 2001 -Message-Id: -In-Reply-To: -References: +From d7a7036c90d0f65c8345b9f75ac1e817c48c998f Mon Sep 17 00:00:00 2001 +Message-Id: +In-Reply-To: +References: From: Stefan Agner Date: Thu, 23 Sep 2021 23:52:44 +0200 -Subject: [PATCH 5/8] nvme: improve readability of nvme_setup_prps() +Subject: [PATCH 5/9] nvme: improve readability of nvme_setup_prps() Improve readability by introducing consts, reuse consts where appropriate and adding variables with discriptive name. diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0006-nvme-Use-pointer-for-CPU-addressed-buffers.patch b/buildroot-external/board/raspberrypi/patches/uboot/0006-nvme-Use-pointer-for-CPU-addressed-buffers.patch index b1993033e..8757b3897 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0006-nvme-Use-pointer-for-CPU-addressed-buffers.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0006-nvme-Use-pointer-for-CPU-addressed-buffers.patch @@ -1,10 +1,10 @@ -From 7e71ddff9abedfda11fa6c8cc1ba2b5729af9a95 Mon Sep 17 00:00:00 2001 -Message-Id: <7e71ddff9abedfda11fa6c8cc1ba2b5729af9a95.1632816160.git.stefan@agner.ch> -In-Reply-To: -References: +From 27a4d59876323a0e13807ac3614b01700b8cfe83 Mon Sep 17 00:00:00 2001 +Message-Id: <27a4d59876323a0e13807ac3614b01700b8cfe83.1633447374.git.stefan@agner.ch> +In-Reply-To: +References: From: Stefan Agner Date: Thu, 23 Sep 2021 23:58:35 +0200 -Subject: [PATCH 6/8] nvme: Use pointer for CPU addressed buffers +Subject: [PATCH 6/9] nvme: Use pointer for CPU addressed buffers Pass buffers which use CPU addressing as void pointers. This aligns with DMA APIs which use void pointers as argument. It will avoid unnecessary diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0007-nvme-translate-virtual-addresses-into-the-bus-s-addr.patch b/buildroot-external/board/raspberrypi/patches/uboot/0007-nvme-translate-virtual-addresses-into-the-bus-s-addr.patch index 7e022659e..3e974bc7c 100644 --- a/buildroot-external/board/raspberrypi/patches/uboot/0007-nvme-translate-virtual-addresses-into-the-bus-s-addr.patch +++ b/buildroot-external/board/raspberrypi/patches/uboot/0007-nvme-translate-virtual-addresses-into-the-bus-s-addr.patch @@ -1,10 +1,10 @@ -From 9e8a4fc39549069ff5a81119755586efe9002cab Mon Sep 17 00:00:00 2001 -Message-Id: <9e8a4fc39549069ff5a81119755586efe9002cab.1632816160.git.stefan@agner.ch> -In-Reply-To: -References: +From bdaf8f67fd33ae1d38011a2b6f9da4884ec11dd2 Mon Sep 17 00:00:00 2001 +Message-Id: +In-Reply-To: +References: From: Stefan Agner Date: Fri, 24 Sep 2021 00:27:39 +0200 -Subject: [PATCH 7/8] nvme: translate virtual addresses into the bus's address +Subject: [PATCH 7/9] nvme: translate virtual addresses into the bus's address space So far we've been content with passing physical/CPU addresses when diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0008-nvme-invalidate-correct-memory-range-after-read.patch b/buildroot-external/board/raspberrypi/patches/uboot/0008-nvme-invalidate-correct-memory-range-after-read.patch new file mode 100644 index 000000000..30301b7ad --- /dev/null +++ b/buildroot-external/board/raspberrypi/patches/uboot/0008-nvme-invalidate-correct-memory-range-after-read.patch @@ -0,0 +1,57 @@ +From e55ccb4af869726b9579596ad37f3e7f33b5332d Mon Sep 17 00:00:00 2001 +Message-Id: +In-Reply-To: +References: +From: Stefan Agner +Date: Tue, 28 Sep 2021 00:52:51 +0200 +Subject: [PATCH 8/9] nvme: invalidate correct memory range after read + +The current code invalidates the range after the read buffer since the +buffer pointer gets incremented in the read loop. Use a temporary +pointer to make sure we have a pristine pointer to invalidate the +correct memory range after read. + +Fixes: 704e040a51d2 ("nvme: Apply cache operations on the DMA buffers") +Signed-off-by: Stefan Agner +--- + drivers/nvme/nvme.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/drivers/nvme/nvme.c b/drivers/nvme/nvme.c +index 0b7082d71b..dd190bd654 100644 +--- a/drivers/nvme/nvme.c ++++ b/drivers/nvme/nvme.c +@@ -746,6 +746,7 @@ static ulong nvme_blk_rw(struct udevice *udev, lbaint_t blknr, + u64 prp2; + u64 total_len = blkcnt << desc->log2blksz; + u64 temp_len = total_len; ++ void *temp_buffer = buffer; + + u64 slba = blknr; + u16 lbas = 1 << (dev->max_transfer_shift - ns->lba_shift); +@@ -773,19 +774,19 @@ static ulong nvme_blk_rw(struct udevice *udev, lbaint_t blknr, + } + + if (nvme_setup_prps(dev, &prp2, +- lbas << ns->lba_shift, buffer)) ++ lbas << ns->lba_shift, temp_buffer)) + return -EIO; + c.rw.slba = cpu_to_le64(slba); + slba += lbas; + c.rw.length = cpu_to_le16(lbas - 1); +- c.rw.prp1 = cpu_to_le64(nvme_virt_to_bus(dev, buffer)); ++ c.rw.prp1 = cpu_to_le64(nvme_virt_to_bus(dev, temp_buffer)); + c.rw.prp2 = cpu_to_le64(prp2); + status = nvme_submit_sync_cmd(dev->queues[NVME_IO_Q], + &c, NULL, IO_TIMEOUT); + if (status) + break; + temp_len -= (u32)lbas << ns->lba_shift; +- buffer += lbas << ns->lba_shift; ++ temp_buffer += lbas << ns->lba_shift; + } + + if (read) +-- +2.33.0 + diff --git a/buildroot-external/board/raspberrypi/patches/uboot/0009-drivers-usb-host-Include-header-file-needed-for-dev_.patch b/buildroot-external/board/raspberrypi/patches/uboot/0009-drivers-usb-host-Include-header-file-needed-for-dev_.patch new file mode 100644 index 000000000..3bb639753 --- /dev/null +++ b/buildroot-external/board/raspberrypi/patches/uboot/0009-drivers-usb-host-Include-header-file-needed-for-dev_.patch @@ -0,0 +1,32 @@ +From 6fc60c237cedf06cb5a1db087e2408a528870e3f Mon Sep 17 00:00:00 2001 +Message-Id: <6fc60c237cedf06cb5a1db087e2408a528870e3f.1633447374.git.stefan@agner.ch> +In-Reply-To: +References: +From: Stefan Agner +Date: Tue, 5 Oct 2021 17:07:22 +0200 +Subject: [PATCH 9/9] drivers: usb: host: Include header file needed for + dev_err + +dev_err seems to be moved to different header file. Include +dm/device_compat.h file to compile properly. + +Signed-off-by: Stefan Agner +--- + drivers/usb/host/xhci-brcm.c | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/drivers/usb/host/xhci-brcm.c b/drivers/usb/host/xhci-brcm.c +index 27c4bbfcba..ee3b55242e 100644 +--- a/drivers/usb/host/xhci-brcm.c ++++ b/drivers/usb/host/xhci-brcm.c +@@ -5,6 +5,7 @@ + + #include + #include ++#include + #include + #include + #include +-- +2.33.0 + diff --git a/buildroot-external/board/raspberrypi/uboot.config b/buildroot-external/board/raspberrypi/uboot.config index d003a8df7..4612beb59 100644 --- a/buildroot-external/board/raspberrypi/uboot.config +++ b/buildroot-external/board/raspberrypi/uboot.config @@ -4,3 +4,5 @@ CONFIG_USB_FUNCTION_MASS_STORAGE=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_EHCI_GENERIC=y CONFIG_USB_OHCI_HCD=y + +CONFIG_USB_XHCI_BRCM=y