ufs: Add a PCI UFS controller support
cover ufs: Add a PCI UFS controller support
This adds a PCI UFS controller support and enables the support on QEMU RISC-V for testing.
Requiring QEMU v8.2+.
This series is avaiable at u-boot-x86/ufs for testing.
Bin Meng (9):
ufs: Correct the UFS terminlogy
ufs: Add a line feed to the end of some dev_xxx() messages
cmd: kconfig: Make ufs prompt look similar to other commands
cmd: ufs: Correct the help text
pci_ids: Add Red Hat vendor and device IDs
ufs: Allow mmio registers on the PCI bus
ufs: Add a PCI based UFS controller driver
ufs: Handle UFS 3.1 controllers
qemu: riscv: Enable UFS support
board/emulation/qemu-riscv/Kconfig | 2 ++ cmd/Kconfig | 2 +- cmd/ufs.c | 2 +- doc/board/emulation/qemu-riscv.rst | 8 +++++- drivers/ufs/Kconfig | 11 ++++++++ drivers/ufs/Makefile | 1 + drivers/ufs/ufs-pci.c | 45 ++++++++++++++++++++++++++++++ drivers/ufs/ufs-uclass.c | 2 +- drivers/ufs/ufs.c | 31 ++++++++++++-------- drivers/ufs/ufs.h | 1 + include/pci_ids.h | 7 +++++ 11 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 drivers/ufs/ufs-pci.c
Signature · 1 line
2.34.1
PATCH 1/9 ufs: Correct the UFS terminlogy
UFS stands for Universal Flash Storage, not Subsytem.
---
cmd/Kconfig | 2 +- drivers/ufs/ufs-uclass.c | 2 +- drivers/ufs/ufs.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
cmd/Kconfig +1 -1
@@ -1536,7 +1536,7 @@ config CMD_TSI148 Turndra tsi148 device. See the command help for full details. config CMD_UFS - bool "Enable UFS - Universal Flash Subsystem commands" + bool "Enable UFS - Universal Flash Storage commands" depends on UFS help "This provides commands to initialise and configure universal flash
drivers/ufs/ufs-uclass.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0 /** -* ufs-uclass.c - Universal Flash Subsystem (UFS) Uclass driver +* ufs-uclass.c - Universal Flash Storage (UFS) Uclass driver * * Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com */
drivers/ufs/ufs.c +1 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0+ /** -* ufs.c - Universal Flash Subsystem (UFS) driver +* ufs.c - Universal Flash Storage (UFS) driver * * Taken from Linux Kernel v5.2 (drivers/scsi/ufs/ufshcd.c) and ported * to u-boot.
Signature · 1 line
2.34.1
Re: [PATCH 1/9] ufs: Correct the UFS terminlogy
Quoted 10 lines · Bin Meng
UFS stands for Universal Flash Storage, not Subsytem.
Signed-off-by Bin Meng <[email protected]>---
cmd/Kconfig | 2 +- drivers/ufs/ufs-uclass.c | 2 +- drivers/ufs/ufs.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
PATCH 2/9 ufs: Add a line feed to the end of some dev_xxx() messages
In reply to Bin MengAdd a line feed to improve readability of some dev_xxx() messages.
---
drivers/ufs/ufs.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/ufs/ufs.c +8 -8
@@ -320,7 +320,7 @@ static int ufshcd_disable_tx_lcc(struct ufs_hba *hba, bool peer) UIC_ARG_MPHY_TX_GEN_SEL_INDEX(i)), 0);if (err) { -dev_err (hba->dev,"%s: TX LCC Disable failed, peer = %d, lane = %d, err = %d" , +dev_err (hba->dev,"%s: TX LCC Disable failed, peer = %d, lane = %d, err = %d\n" , __func__, peer, i, err);break ; }
@@ -441,7 +441,7 @@ static int ufshcd_make_hba_operational(struct ufs_hba *hba)ufshcd_enable_run_stop_reg (hba); }else {dev_err (hba->dev, -"Host controller not ready to process requests" ); +"Host controller not ready to process requests\n" ); err = -EIO ; goto out; }
@@ -930,7 +930,7 @@ static int ufshcd_copy_query_response(struct ufs_hba *hba)memcpy (hba->dev_cmd.query.descriptor, descp, resp_len); }else {dev_warn (hba->dev, -"%s: Response size is bigger than buffer" , +"%s: Response size is bigger than buffer\n" , __func__);return -EINVAL ; }
@@ -1179,11 +1179,11 @@ static int ufshcd_read_desc_length(struct ufs_hba *hba, enum desc_idn desc_id, &header_len);if (ret) { -dev_err (hba->dev,"%s: Failed to get descriptor header id %d" , +dev_err (hba->dev,"%s: Failed to get descriptor header id %d\n" , __func__, desc_id);return ret; }else if (desc_id != header[QUERY_DESC_DESC_TYPE_OFFSET ]) { -dev_warn (hba->dev,"%s: descriptor header id %d and desc_id %d mismatch" , +dev_warn (hba->dev,"%s: descriptor header id %d and desc_id %d mismatch\n" , __func__, header[QUERY_DESC_DESC_TYPE_OFFSET ], desc_id); ret = -EINVAL ;
@@ -1302,7 +1302,7 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id,/* Sanity checks */ if (ret || !buff_len) { -dev_err (hba->dev,"%s: Failed to get full descriptor length" , +dev_err (hba->dev,"%s: Failed to get full descriptor length\n" , __func__);return ret; }
@@ -1323,14 +1323,14 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id, &buff_len);if (ret) { -dev_err (hba->dev,"%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d" , +dev_err (hba->dev,"%s: Failed reading descriptor. desc_id %d, desc_index %d, param_offset %d, ret %d\n" , __func__, desc_id, desc_index, param_offset, ret); goto out; }/* Sanity check */ if (desc_buf[QUERY_DESC_DESC_TYPE_OFFSET ] != desc_id) { -dev_err (hba->dev,"%s: invalid desc_id %d in descriptor header" , +dev_err (hba->dev,"%s: invalid desc_id %d in descriptor header\n" , __func__, desc_buf[QUERY_DESC_DESC_TYPE_OFFSET ]); ret = -EINVAL ; goto out;
Signature · 1 line
2.34.1
PATCH 3/9 cmd: kconfig: Make ufs prompt look similar to other commands
In reply to Bin MengAt present the 'ufs' command prompt does not look similar like other commands. Update it.
---
cmd/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/Kconfig +1 -1
@@ -1536,7 +1536,7 @@ config CMD_TSI148 Turndra tsi148 device. See the command help for full details. config CMD_UFS - bool "Enable UFS - Universal Flash Storage commands" + bool "ufs - Universal Flash Storage commands" depends on UFS help "This provides commands to initialise and configure universal flash
Signature · 1 line
2.34.1
PATCH 4/9 cmd: ufs: Correct the help text
In reply to Bin MengRemove the additional space and use "sub-system" for consistency with other commands like "scsi" and "usb".
---
cmd/ufs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/ufs.c +1 -1
@@ -32,6 +32,6 @@ static int do_ufs(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) }U_BOOT_CMD (ufs,3 ,1 , do_ufs, -"UFS sub system" , +"UFS sub-system" ,"init [dev] - init UFS subsystem\n" );
Signature · 1 line
2.34.1
PATCH 5/9 pci_ids: Add Red Hat vendor and device IDs
In reply to Bin MengRed Hat, Inc. donates a part of its device ID range [1] to QEMU, to be used for virtual devices. This commit adds several typical devices that are useful in U-Boot.
[1] https://www.qemu.org/docs/master/specs/pci-ids.html
---
include/pci_ids.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/pci_ids.h +7 -0
@@ -1363,6 +1363,13 @@#define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP 0x3fc5#define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI 0x3fc6 +/* Per https://www.qemu.org/docs/master/specs/pci-ids.html */ +#define PCI_VENDOR_ID_REDHAT 0x1b36 +#define PCI_DEVICE_ID_REDHAT_SDHCI 0x0007 +#define PCI_DEVICE_ID_REDHAT_XHCI 0x000d +#define PCI_DEVICE_ID_REDHAT_NVME 0x0010 +#define PCI_DEVICE_ID_REDHAT_UFS 0x0013 +#define PCI_VENDOR_ID_INIT 0x1101#define PCI_VENDOR_ID_CREATIVE 0x1102/* duplicate: ECTIVA */
Signature · 1 line
2.34.1
PATCH 6/9 ufs: Allow mmio registers on the PCI bus
In reply to Bin MengCheck if the UFS controller is on the PCI bus, and get its register base address accordingly.
---
drivers/ufs/ufs.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/ufs/ufs.c +9 -1
@@ -1914,6 +1914,7 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops)struct ufs_hba *hba =dev_get_uclass_priv (ufs_dev);struct scsi_plat *scsi_plat;struct udevice *scsi_dev; +void __iomem *mmio_base;int err;device_find_first_child (ufs_dev, &scsi_dev);
@@ -1927,7 +1928,14 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops) hba->dev = ufs_dev; hba->ops = hba_ops; - hba->mmio_base =dev_read_addr_ptr (ufs_dev); + +if (device_is_on_pci_bus (ufs_dev)) { + mmio_base =dm_pci_map_bar (ufs_dev,PCI_BASE_ADDRESS_0 ,0 ,0 , +PCI_REGION_TYPE ,PCI_REGION_MEM ); + }else { + mmio_base =dev_read_addr_ptr (ufs_dev); + } + hba->mmio_base = mmio_base;/* Set descriptor lengths to specification defaults */ ufshcd_def_desc_sizes (hba);
Signature · 1 line
2.34.1
PATCH 7/9 ufs: Add a PCI based UFS controller driver
In reply to Bin MengThis adds a simple PCI based UFS controller driver with a QEMU emulated UFS controller on the PCI bus.
Requiring QEMU v8.2+.
---
drivers/ufs/Kconfig | 11 +++++++++++ drivers/ufs/Makefile | 1 + drivers/ufs/ufs-pci.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 drivers/ufs/ufs-pci.c
drivers/ufs/Kconfig +11 -0
@@ -15,6 +15,17 @@ config CADENCE_UFS This selects the platform driver for the Cadence UFS host controller present on present TI's J721e devices. +config UFS_PCI + bool "PCI bus based UFS Controller support" + depends on PCI && UFS + help + This selects the PCI UFS Host Controller Interface. Select this if + you have UFS Host Controller with PCI Interface. + + If you have a controller with this interface, say Y here. + + If unsure, say N. + config TI_J721E_UFS bool "Glue Layer driver for UFS on TI J721E devices" help
drivers/ufs/Makefile +1 -0
@@ -6,4 +6,5 @@ obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o obj-$(CONFIG_TI_J721E_UFS) += ti-j721e-ufs.o +obj-$(CONFIG_UFS_PCI) += ufs-pci.o obj-$(CONFIG_UFS_RENESAS) += ufs-renesas.o
drivers/ufs/ufs-pci.c new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH 8/9 ufs: Handle UFS 3.1 controllers
In reply to Bin MengExtend the version check to handle UFS 3.1 controllers as well. Tested on QEMU emulated UFS 3.1 controller.
---
drivers/ufs/ufs.c | 3 ++- drivers/ufs/ufs.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/ufs/ufs.c +2 -1
@@ -1953,7 +1953,8 @@ int ufshcd_probe(struct udevice *ufs_dev, struct ufs_hba_ops *hba_ops) hba->version != UFSHCI_VERSION_11 && hba->version != UFSHCI_VERSION_20 && hba->version != UFSHCI_VERSION_21 && - hba->version != UFSHCI_VERSION_30) + hba->version != UFSHCI_VERSION_30 && + hba->version != UFSHCI_VERSION_31)dev_err (hba->dev,"invalid UFS version 0x%x\n" , hba->version);
drivers/ufs/ufs.h +1 -0
@@ -782,6 +782,7 @@ enum {UFSHCI_VERSION_20 =0x00000200 ,/* 2.0 */ UFSHCI_VERSION_21 =0x00000210 ,/* 2.1 */ UFSHCI_VERSION_30 =0x00000300 ,/* 3.0 */ + UFSHCI_VERSION_31 = 0x00000310, /* 3.1 */ };/* Interrupt disable masks */
Signature · 1 line
2.34.1
PATCH 9/9 qemu: riscv: Enable UFS support
In reply to Bin MengThis enables UFS support for QEMU RISC-V 'virt' machine.
---
board/emulation/qemu-riscv/Kconfig | 2 ++ doc/board/emulation/qemu-riscv.rst | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-)
board/emulation/qemu-riscv/Kconfig +2 -0
@@ -82,5 +82,7 @@ config BOARD_SPECIFIC_OPTIONS # dummy imply USB_XHCI_PCI imply USB_KEYBOARD imply CMD_USB + imply UFS + imply UFS_PCI endif
doc/board/emulation/qemu-riscv.rst +7 -1
@@ -131,7 +131,13 @@ An attached disk can be emulated in RISC-V virt machine by adding:: -drive if=none,file=riscv64.img,format=raw,id=mydisk \ -device ide-hd,drive=mydisk,bus=ahci.0 -You will have to run 'scsi scan' to use it. +or alternatively attach an emulated UFS:: + + -device ufs,id=ufs0 \ + -drive if=none,file=test.img,format=raw,id=lun0 \ + -device ufs-lu,drive=lun0,bus=ufs0 + +You will have to run 'scsi scan' to use them. A video console can be emulated in RISC-V virt machine by removing "-nographic" and adding::
Signature · 1 line
2.34.1