Add Support for UFS subsystem for TI's J721e
Subsystems (2)
v2 cover Add Support for UFS subsystem for TI's J721e
The following patches add support for the Universal Flash Storage (UFS) subsystem and its implementation on TI's J721e platform.
The UFS Application Layer (UAP) uses SCSI SAM-4 command set for communication with the device. Therefore, the first 4 patches prepare the scsi layer for compatibility with UFS. Patch 9 also adds support for initializing and configuring the device from the U-boot command line.
The UFS Transport Protocol Layer (UTP) and UFS Interconnect Layer (UIC) are implemented with patch 5. This series only adds support for detect and read/write operations to the LUNs present in the remote device. Task Management operations and configuration of LUNs will be added in a future series.
Patches 6 through 10 add platform driver, device tree and config support for TI's J721E devices.
Log: https://pastebin.ubuntu.com/p/65JZXGT3Z6/
Tested on top of Lokesh's tree:
https://github.com/lokeshvutla/u-boot
Branch: j721e-full-boot
Changes in v2:
1. Added environment variables such that its easy to boot kernel from UFS.
2. Introduced an API to probe UFS devices individually.
3. Changed ti-j721e-ufs wrapper driver to UCLASS_MISC because its not really a UFS device driver.
References:
[1] JESD220D UFS 3.0:
https://www.jedec.org/standards-documents/docs/jesd220c
[2] JESD223D UFS Host Controller Interface (UFSHCI) version 3.0:
https://www.jedec.org/standards-documents/docs/jesd223c
Faiz Abbas (11):
scsi: Simplify scsi_read()/_write()
scsi: Add max_bytes_per_req to scsi_platdata
scsi: Retry inquiry 3 times to overcome Unit Attention condition
scsi: Add dma direction member to command structure
ufs: Add Initial Support for UFS subsystem
ufs: Add Support for Cadence platform UFS driver
ufs: Add glue layer driver for TI J721E devices
arm: dts: k3-j721e-main: Add UFS nodes
cmd: Add Support for UFS commands
env: ti: Add environment variables to boot from UFS
configs: j721e_evm_a72: Enable configs for UFS
MAINTAINERS | 5 + arch/arm/dts/k3-j721e-main.dtsi | 24 + cmd/Kconfig | 7 + cmd/Makefile | 2 +- cmd/ufs.c | 37 + configs/j721e_evm_a72_defconfig | 8 +- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/scsi/scsi.c | 83 +- drivers/ufs/Kconfig | 23 + drivers/ufs/Makefile | 8 + drivers/ufs/cdns-platform.c | 122 ++ drivers/ufs/ti-j721e-ufs.c | 71 ++ drivers/ufs/ufs-uclass.c | 16 + drivers/ufs/ufs.c | 1968 +++++++++++++++++++++++++++++++ drivers/ufs/ufs.h | 918 ++++++++++++++ drivers/ufs/unipro.h | 270 +++++ include/configs/j721e_evm.h | 4 +- include/dm/uclass-id.h | 1 + include/environment/ti/ufs.h | 33 + include/scsi.h | 5 + include/ufs.h | 29 + 22 files changed, 3590 insertions(+), 47 deletions(-) create mode 100644 cmd/ufs.c create mode 100644 drivers/ufs/Kconfig create mode 100644 drivers/ufs/Makefile create mode 100644 drivers/ufs/cdns-platform.c create mode 100644 drivers/ufs/ti-j721e-ufs.c create mode 100644 drivers/ufs/ufs-uclass.c create mode 100644 drivers/ufs/ufs.c create mode 100644 drivers/ufs/ufs.h create mode 100644 drivers/ufs/unipro.h create mode 100644 include/environment/ti/ufs.h create mode 100644 include/ufs.h
Signature · 1 line
2.19.2
PATCH v2 1/11 scsi: Simplify scsi_read()/_write()
With no non-DM driver using scsi_read()/_write() APIs, remove the legacy implementations.
--- drivers/scsi/scsi.c | 22 ---------------------- 1 file changed, 22 deletions(-)
drivers/scsi/scsi.c +0 -22
@@ -141,20 +141,11 @@ static void scsi_setup_inquiry(struct scsi_cmd *pccb) pccb->msgout[0 ] =SCSI_IDENTIFY ;/* NOT USED */ } -#ifdef CONFIG_BLK static ulong scsi_read (struct udevice *dev,lbaint_t blknr,lbaint_t blkcnt,void *buffer) -#else -static ulong scsi_read (struct blk_desc *block_dev,lbaint_t blknr, - lbaint_t blkcnt, void *buffer) -#endif { -#ifdef CONFIG_BLK struct blk_desc *block_dev =dev_get_uclass_platdata (dev);struct udevice *bdev = dev->parent; -#else -struct udevice *bdev =NULL ; -#endif lbaint_t start, blks;uintptr_t buf_addr;unsigned short smallblks =0 ;
@@ -217,20 +208,11 @@ static ulong scsi_read(struct blk_desc *block_dev, lbaint_t blknr,/* Almost the maximum amount of the scsi_ext command.. */ #define SCSI_MAX_WRITE_BLK 0xFFFF -#ifdef CONFIG_BLK static ulong scsi_write (struct udevice *dev,lbaint_t blknr,lbaint_t blkcnt,const void *buffer) -#else -static ulong scsi_write (struct blk_desc *block_dev,lbaint_t blknr, - lbaint_t blkcnt, const void *buffer) -#endif { -#ifdef CONFIG_BLK struct blk_desc *block_dev =dev_get_uclass_platdata (dev);struct udevice *bdev = dev->parent; -#else -struct udevice *bdev =NULL ; -#endif lbaint_t start, blks;uintptr_t buf_addr;unsigned short smallblks;
@@ -450,10 +432,6 @@ static void scsi_init_dev_desc_priv(struct blk_desc *dev_desc) dev_desc->product[0 ] =0 ; dev_desc->revision[0 ] =0 ; dev_desc->removable = false; -#if !CONFIG_IS_ENABLED (BLK ) - dev_desc->block_read = scsi_read; - dev_desc->block_write = scsi_write; -#endif }#if !defined(CONFIG_DM_SCSI )
Signature · 1 line
2.19.2
PATCH v2 1/11 scsi: Simplify scsi_read()/_write()
Quoted 4 lines · Faiz Abbas
With no non-DM driver using scsi_read()/_write() APIs, remove the legacy implementations.
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/bc4899c4/attachment.sig>
PATCH v2 2/11 scsi: Add max_bytes_per_req to scsi_platdata
In reply to Faiz AbbasAdd max_bytes_per_req to scsi_platdata to enable the host driver to limit the number of bytes that can be read/written per request.
--- drivers/scsi/scsi.c | 45 ++++++++++++++++++++++++++------------------- include/scsi.h | 2 ++ 2 files changed, 28 insertions(+), 19 deletions(-)
drivers/scsi/scsi.c +26 -19
@@ -45,7 +45,7 @@ static struct blk_desc scsi_dev_desc[CONFIG_SYS_SCSI_MAX_DEVICE];#endif /* almost the maximum amount of the scsi_ext command.. */ -#define SCSI_MAX_READ_BLK 0xFFFF +#define SCSI_MAX_BLK 0xFFFF#define SCSI_LBA48_READ 0xFFFFFFFstatic void scsi_print_error (struct scsi_cmd *pccb)
@@ -146,7 +146,8 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, {struct blk_desc *block_dev =dev_get_uclass_platdata (dev);struct udevice *bdev = dev->parent; -lbaint_t start, blks; +struct scsi_platdata *uc_plat =dev_get_uclass_platdata (bdev); +lbaint_t start, blks, max_blks;uintptr_t buf_addr;unsigned short smallblks =0 ;struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
@@ -157,6 +158,11 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, buf_addr = (unsigned long )buffer; start = blknr; blks = blkcnt; +if (uc_plat->max_bytes_per_req) + max_blks = uc_plat->max_bytes_per_req / block_dev->blksz; +else + max_blks =SCSI_MAX_BLK ; +debug ("\nscsi_read: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n" , block_dev->devnum, start, blks, (unsigned long )buffer);
@@ -165,20 +171,19 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,#ifdef CONFIG_SYS_64BIT_LBA if (start >SCSI_LBA48_READ ) {unsigned long blocks; - blocks =min_t (lbaint_t, blks,SCSI_MAX_READ_BLK ); + blocks =min_t (lbaint_t, blks, max_blks); pccb->datalen = block_dev->blksz * blocks;scsi_setup_read16 (pccb, start, blocks); start += blocks; blks -= blocks; } else#endif -if (blks >SCSI_MAX_READ_BLK ) { - pccb->datalen = block_dev->blksz * -SCSI_MAX_READ_BLK ; - smallblks =SCSI_MAX_READ_BLK ; +if (blks > max_blks) { + pccb->datalen = block_dev->blksz * max_blks; + smallblks = max_blks;scsi_setup_read_ext (pccb, start, smallblks); - start +=SCSI_MAX_READ_BLK ; - blks -=SCSI_MAX_READ_BLK ; + start += max_blks; + blks -= max_blks; }else { pccb->datalen = block_dev->blksz * blks; smallblks = (unsigned short )blks;
@@ -205,15 +210,13 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,* scsi_write */ -/* Almost the maximum amount of the scsi_ext command.. */ -#define SCSI_MAX_WRITE_BLK 0xFFFF -static ulong scsi_write (struct udevice *dev,lbaint_t blknr,lbaint_t blkcnt,const void *buffer) {struct blk_desc *block_dev =dev_get_uclass_platdata (dev);struct udevice *bdev = dev->parent; -lbaint_t start, blks; +struct scsi_platdata *uc_plat =dev_get_uclass_platdata (bdev); +lbaint_t start, blks, max_blks;uintptr_t buf_addr;unsigned short smallblks;struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb;
@@ -224,17 +227,21 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, buf_addr = (unsigned long )buffer; start = blknr; blks = blkcnt; +if (uc_plat->max_bytes_per_req) + max_blks = uc_plat->max_bytes_per_req / block_dev->blksz; +else + max_blks =SCSI_MAX_BLK ; +debug ("\n%s: dev %d startblk " LBAF ", blccnt " LBAF " buffer %lx\n" , __func__, block_dev->devnum, start, blks, (unsigned long )buffer); do { pccb->pdata = (unsigned char *)buf_addr; - if (blks > SCSI_MAX_WRITE_BLK) { - pccb->datalen = (block_dev->blksz * - SCSI_MAX_WRITE_BLK); - smallblks = SCSI_MAX_WRITE_BLK; + if (blks > max_blks) { + pccb->datalen = block_dev->blksz * max_blks; + smallblks = max_blks; scsi_setup_write_ext(pccb, start, smallblks); - start += SCSI_MAX_WRITE_BLK; - blks -= SCSI_MAX_WRITE_BLK; + start += max_blks; + blks -= max_blks; } else { pccb->datalen = block_dev->blksz * blks; smallblks = (unsigned short)blks;
include/scsi.h +2 -0
@@ -163,11 +163,13 @@ struct scsi_cmd {* @base: Controller base address * @max_lun: Maximum number of logical units * @max_id: Maximum number of target ids +* @max_bytes_per_req: Maximum number of bytes per read/write request */ struct scsi_platdata {unsigned long base;unsigned long max_lun;unsigned long max_id; +unsigned long max_bytes_per_req; };/* Operations for SCSI */
Signature · 1 line
2.19.2
PATCH v2 2/11 scsi: Add max_bytes_per_req to scsi_platdata
Quoted 4 lines · Faiz Abbas
Add
max_bytes_per_reqtoscsi_platdatato enable the host driver to limit the number of bytes that can be read/written per request.Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/863afd3c/attachment.sig>
PATCH v2 3/11 scsi: Retry inquiry 3 times to overcome Unit Attention condition
In reply to Faiz AbbasThe UFS SCSI device LUNs are observed to return failure the first time a unit ready inquiry is sent and pass on the second try. Send this inquiry 3 times to make sure device is ready.
--- drivers/scsi/scsi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/scsi/scsi.c +9 -3
@@ -479,6 +479,7 @@ static int scsi_detect_dev(struct udevice *dev, int target, int lun,lbaint_t capacity;unsigned long blksz;struct scsi_cmd *pccb = (struct scsi_cmd *)&tempccb; +int count, err; pccb->target = target; pccb->lun = lun;
@@ -514,9 +515,14 @@ static int scsi_detect_dev(struct udevice *dev, int target, int lun, dev_desc->target = pccb->target; dev_desc->lun = pccb->lun; - pccb->datalen =0 ; -scsi_setup_test_unit_ready (pccb); -if (scsi_exec (dev, pccb)) { +for (count =0 ; count <3 ; count++) { + pccb->datalen =0 ; +scsi_setup_test_unit_ready (pccb); + err =scsi_exec (dev, pccb); +if (!err) +break ; + } +if (err) {if (dev_desc->removable) { dev_desc->type = perq; goto removable;
Signature · 1 line
2.19.2
PATCH v2 3/11 scsi: Retry inquiry 3 times to overcome Unit Attention condition
Quoted 5 lines · Faiz Abbas
The UFS SCSI device LUNs are observed to return failure the first time a unit ready inquiry is sent and pass on the second try. Send this inquiry 3 times to make sure device is ready.
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/61a3e633/attachment.sig>
PATCH v2 4/11 scsi: Add dma direction member to command structure
In reply to Faiz AbbasSome SCSI devices like UFS use DMA for executing scsi commands and hence need to know the direction of transfer of the dma. Add a dma_dir element to the command structure to facilitate this.
--- drivers/scsi/scsi.c | 4 ++++ include/scsi.h | 3 +++ 2 files changed, 7 insertions(+)
drivers/scsi/scsi.c +4 -0
@@ -168,6 +168,7 @@ static ulong scsi_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, block_dev->devnum, start, blks, (unsigned long)buffer); do { pccb->pdata = (unsigned char *)buf_addr; + pccb->dma_dir = DMA_FROM_DEVICE; #ifdef CONFIG_SYS_64BIT_LBA if (start > SCSI_LBA48_READ) { unsigned long blocks;
@@ -236,6 +237,7 @@ static ulong scsi_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, __func__, block_dev->devnum, start, blks, (unsigned long)buffer); do { pccb->pdata = (unsigned char *)buf_addr; + pccb->dma_dir = DMA_TO_DEVICE; if (blks > max_blks) { pccb->datalen = block_dev->blksz * max_blks; smallblks = max_blks;
@@ -383,6 +385,7 @@ static int scsi_read_capacity(struct udevice *dev, struct scsi_cmd *pccb, pccb->msgout[0 ] =SCSI_IDENTIFY ;/* NOT USED */ pccb->datalen =16 ; + pccb->dma_dir =DMA_FROM_DEVICE ;if (scsi_exec (dev, pccb))return 1 ;
@@ -485,6 +488,7 @@ static int scsi_detect_dev(struct udevice *dev, int target, int lun, pccb->lun = lun; pccb->pdata = (unsigned char *)&tempbuff; pccb->datalen =512 ; + pccb->dma_dir =DMA_FROM_DEVICE ;scsi_setup_inquiry (pccb);if (scsi_exec (dev, pccb)) {if (pccb->contr_stat ==SCSI_SEL_TIME_OUT ) {
include/scsi.h +3 -0
@@ -6,6 +6,8 @@ #ifndef _SCSI_H #define _SCSI_H +#include <linux/dma-direction.h> + struct scsi_cmd { unsigned char cmd[16]; /* command */ /* for request sense */
@@ -26,6 +28,7 @@ struct scsi_cmd {unsigned long trans_bytes;/* tranfered bytes */ unsigned int priv; +enum dma_data_direction dma_dir; };/*-----------------------------------------------------------
Signature · 1 line
2.19.2
PATCH v2 4/11 scsi: Add dma direction member to command structure
Quoted 5 lines · Faiz Abbas
Some SCSI devices like UFS use DMA for executing scsi commands and hence need to know the direction of transfer of the dma. Add a
dma_direlement to the command structure to facilitate this.Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/95e6f4cc/attachment.sig>
PATCH v2 5/11 ufs: Add Initial Support for UFS subsystem
In reply to Faiz AbbasAdd Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:
- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requests
Also register this host controller as a SCSI host controller.
Taken from Linux Kernel v5.2 (drivers/scsi/ufs/ufshcd.c) and ported to U-boot.
--- MAINTAINERS | 5 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ufs/Kconfig | 9 + drivers/ufs/Makefile | 6 + drivers/ufs/ufs-uclass.c | 16 + drivers/ufs/ufs.c | 1968 ++++++++++++++++++++++++++++++++++++++ drivers/ufs/ufs.h | 918 ++++++++++++++++++ drivers/ufs/unipro.h | 270 ++++++ include/dm/uclass-id.h | 1 + include/ufs.h | 29 + 11 files changed, 3225 insertions(+) create mode 100644 drivers/ufs/Kconfig create mode 100644 drivers/ufs/Makefile create mode 100644 drivers/ufs/ufs-uclass.c create mode 100644 drivers/ufs/ufs.c create mode 100644 drivers/ufs/ufs.h create mode 100644 drivers/ufs/unipro.h create mode 100644 include/ufs.h
MAINTAINERS +5 -0
@@ -839,6 +839,11 @@ S: Maintained T: git https://gitlab.denx.de/u-boot/custodians/u-boot-ubi.git F: drivers/mtd/ubi/ +UFS +M: Faiz Abbas <[email protected]> +S: Maintained +F: drivers/ufs/ + USB M: Marek Vasut <[email protected]> S: Maintained
drivers/Kconfig +2 -0
@@ -118,6 +118,8 @@ source "drivers/tpm/Kconfig" source "drivers/usb/Kconfig" +source "drivers/ufs/Kconfig" + source "drivers/video/Kconfig" source "drivers/virtio/Kconfig"
drivers/Makefile +1 -0
@@ -111,6 +111,7 @@ obj-y += soc/ obj-y += thermal/ obj-$(CONFIG_TEE) += tee/ obj-y += axi/ +obj-y += ufs/ obj-$(CONFIG_W1) += w1/ obj-$(CONFIG_W1_EEPROM) += w1-eeprom/
drivers/ufs/Kconfig new file +9 -0
@@ -0,0 +1,9 @@ +menu "UFS Host Controller Support" + +config UFS + bool "Support UFS controllers" + depends on DM_SCSI + help + This selects support for Universal Flash Subsystem (UFS). + Say Y here if you want UFS Support. +endmenu
drivers/ufs/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com +# + +obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o
drivers/ufs/ufs-uclass.c new file +16 -0
@@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/** +* ufs-uclass.c - Universal Flash Subsystem (UFS) Uclass driver +* +* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com +*/ + +#include <common.h> +#include "ufs.h" +#include <dm.h> + +UCLASS_DRIVER (ufs) = { + .id =UCLASS_UFS , + .name ="ufs" , + .per_device_auto_alloc_size =sizeof (struct ufs_hba ), +};
drivers/ufs/ufs.c new file +1968 -0
1,968 lines not on this page · raw message
drivers/ufs/ufs.h new file +918 -0
918 lines not on this page · raw message
drivers/ufs/unipro.h new file +270 -0
57 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.19.2
Part of the diff is not shown here. View the raw message.
PATCH v2 5/11 ufs: Add Initial Support for UFS subsystem
+Simon
Quoted 13 lines · Faiz Abbas
Add Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:
- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requests
Quoted 4 lines
Also register this host controller as a SCSI host controller.
Taken from Linux Kernel v5.2 (
drivers/scsi/ufs/ufshcd.c) and ported to U-boot.
nits: U-Boot
Quoted 14 lines
Signed-off-by Faiz Abbas <[email protected]>--- MAINTAINERS | 5 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ufs/Kconfig | 9 + drivers/ufs/Makefile | 6 + drivers/ufs/ufs-uclass.c | 16 + drivers/ufs/ufs.c | 1968 ++++++++++++++++++++++++++++++++++++++ drivers/ufs/ufs.h | 918 ++++++++++++++++++ drivers/ufs/unipro.h | 270 ++++++ include/dm/uclass-id.h | 1 + include/ufs.h | 29 +
Quoted 9 lines
11 files changed, 3225 insertions(+) create mode 100644 drivers/ufs/Kconfig create mode 100644 drivers/ufs/Makefile create mode 100644 drivers/ufs/ufs-uclass.c create mode 100644 drivers/ufs/ufs.c create mode 100644 drivers/ufs/ufs.h create mode 100644 drivers/ufs/unipro.h create mode 100644 include/ufs.h
I think we will need a sandbox ufs driver and test cases for testing dm ufs.
Regards,
Bin
PATCH v2 5/11 ufs: Add Initial Support for UFS subsystem
Quoted 47 lines · Bin Meng
+Simon
Quoted 13 lines · Faiz Abbas
Add Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:
- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requestsQuoted 4 lines
Also register this host controller as a SCSI host controller.
Taken from Linux Kernel v5.2 (
drivers/scsi/ufs/ufshcd.c) and ported to U-boot.nits: U-Boot
Quoted 14 lines
Signed-off-by Faiz Abbas <[email protected]>--- MAINTAINERS | 5 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/ufs/Kconfig | 9 + drivers/ufs/Makefile | 6 + drivers/ufs/ufs-uclass.c | 16 + drivers/ufs/ufs.c | 1968 ++++++++++++++++++++++++++++++++++++++ drivers/ufs/ufs.h | 918 ++++++++++++++++++ drivers/ufs/unipro.h | 270 ++++++ include/dm/uclass-id.h | 1 + include/ufs.h | 29 +Quoted 9 lines
11 files changed, 3225 insertions(+) create mode 100644 drivers/ufs/Kconfig create mode 100644 drivers/ufs/Makefile create mode 100644 drivers/ufs/ufs-uclass.c create mode 100644 drivers/ufs/ufs.c create mode 100644 drivers/ufs/ufs.h create mode 100644 drivers/ufs/unipro.h create mode 100644 include/ufs.h
Quoted 1 line
I think we will need a sandbox ufs driver and test cases for testing dm ufs.
I would also like to see that, but think we can do that in a follow-up.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/47665fdc/attachment.sig>
PATCH v2 5/11 ufs: Add Initial Support for UFS subsystem
In reply to Faiz AbbasQuoted 12 lines · Faiz Abbas
Add Support for UFS Host Controller Interface (UFSHCI) for communicating with Universal Flash Storage (UFS) devices. The steps to initialize the host controller interface are the following:
- Initiate the Host Controller Initialization process by writing to the Host controller enable register.
- Configure the Host Controller base address registers by allocating a host memory space and related data structures.
- Unipro link startup procedure
- Check for connected device
- Configure UFS host controller to process requests
Quoted 6 lines
Also register this host controller as a SCSI host controller.
Taken from Linux Kernel v5.2 (
drivers/scsi/ufs/ufshcd.c) and ported to U-boot.Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/2e3b5876/attachment.sig>
PATCH v2 6/11 ufs: Add Support for Cadence platform UFS driver
In reply to Faiz AbbasAdd Support for the platform driver for the Cadence device present on TI's J721e device.
--- drivers/ufs/Kconfig | 8 +++ drivers/ufs/Makefile | 1 + drivers/ufs/cdns-platform.c | 122 ++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 drivers/ufs/cdns-platform.c
drivers/ufs/Kconfig +8 -0
@@ -6,4 +6,12 @@ config UFS help This selects support for Universal Flash Subsystem (UFS). Say Y here if you want UFS Support. + +config CADENCE_UFS + bool "Cadence platform driver for UFS" + depends on UFS + help + This selects the platform driver for the Cadence UFS host + controller present on present TI's J721e devices. + endmenu
drivers/ufs/Makefile +1 -0
@@ -4,3 +4,4 @@ # obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o +obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o
drivers/ufs/cdns-platform.c new file +122 -0
122 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH v2 6/11 ufs: Add Support for Cadence platform UFS driver
Quoted 4 lines · Faiz Abbas
Add Support for the platform driver for the Cadence device present on TI's J721e device.
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/a2ceaee1/attachment.sig>
PATCH v2 7/11 ufs: Add glue layer driver for TI J721E devices
In reply to Faiz AbbasAdd glue layer driver for the controller present on TI's J721E devices.
--- drivers/ufs/Kconfig | 6 ++++ drivers/ufs/Makefile | 1 + drivers/ufs/ti-j721e-ufs.c | 71 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 drivers/ufs/ti-j721e-ufs.c
drivers/ufs/Kconfig +6 -0
@@ -14,4 +14,10 @@ config CADENCE_UFS This selects the platform driver for the Cadence UFS host controller present on present TI's J721e devices. +config TI_J721E_UFS + bool "Glue Layer driver for UFS on TI J721E devices" + help + This selects the glue layer driver for Cadence controller + present on TI's J721E devices. + endmenu
drivers/ufs/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_UFS) += ufs.o ufs-uclass.o obj-$(CONFIG_CADENCE_UFS) += cdns-platform.o +obj-$(CONFIG_TI_J721E_UFS) += ti-j721e-ufs.o
drivers/ufs/ti-j721e-ufs.c new file +71 -0
71 lines not on this page · raw message
Signature · 1 line
2.19.2
PATCH v2 7/11 ufs: Add glue layer driver for TI J721E devices
Quoted 3 lines · Faiz Abbas
Add glue layer driver for the controller present on TI's J721E devices.
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/cdca2ad0/attachment.sig>
PATCH v2 8/11 arm: dts: k3-j721e-main: Add UFS nodes
In reply to Faiz AbbasAdd TI UFS glue layer and Cadence UFS Host controller DT nodes.
--- arch/arm/dts/k3-j721e-main.dtsi | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
arch/arm/dts/k3-j721e-main.dtsi +24 -0
@@ -339,4 +339,28 @@ ti,sci-proc-ids = <0x30 0xFF>; resets = <&k3_reset 15 1>; }; + + ufs_wrapper: ufs-wrapper at 4e80000 { + compatible = "ti,j721e-ufs"; + reg = <0x0 0x4e80000 0x0 0x100>; + power-domains = <&k3_pds 277 TI_SCI_PD_EXCLUSIVE>; + clocks = <&k3_clks 277 1>; + assigned-clocks = <&k3_clks 277 1>; + assigned-clock-parents = <&k3_clks 277 4>; + ranges; + #address-cells = <2>; + #size-cells = <2>; + + ufs at 4e84000 { + compatible = "cdns,ufshc-m31-16nm", "jedec,ufs-2.0"; + reg = <0x0 0x4e84000 0x0 0x10000>; + interrupts = <GIC_SPI 17 IRQ_TYPE_LEVEL_HIGH>; + freq-table-hz = <0 0>, <0 0>; + clocks = <&k3_clks 277 0>, <&k3_clks 277 1>; + clock-names = "core_clk", "phy_clk"; + assigned-clocks = <&k3_clks 277 1>; + assigned-clock-parents = <&k3_clks 277 4>; + dma-coherent; + }; + }; };
Signature · 1 line
2.19.2
PATCH v2 8/11 arm: dts: k3-j721e-main: Add UFS nodes
Quoted 3 lines · Faiz Abbas
Add TI UFS glue layer and Cadence UFS Host controller DT nodes.
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/95e73de3/attachment.sig>
PATCH v2 9/11 cmd: Add Support for UFS commands
In reply to Faiz AbbasAdd Support for commands to initialize and configure UFS devices.
TODO: Add Support for commands to resize and reconfigure LUNs
--- cmd/Kconfig | 7 +++++++ cmd/Makefile | 2 +- cmd/ufs.c | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 cmd/ufs.c
cmd/Kconfig +7 -0
@@ -1205,6 +1205,13 @@ config CMD_TSI148 This provides various sub-commands to initialise and configure the Turndra tsi148 device. See the command help for full details. +config CMD_UFS + bool "Enable UFS - Universal Flash Subsystem commands" + depends on UFS + help + "This provides commands to initialise and configure universal flash + subsystem devices" + config CMD_UNIVERSE bool "universe - Command to set up the Turndra Universe controller" help
cmd/Makefile +1 -1
@@ -144,7 +144,7 @@ obj-$(CONFIG_CMD_UNZIP) += unzip.o obj-$(CONFIG_CMD_VIRTIO) += virtio.o obj-$(CONFIG_CMD_WDT) += wdt.o obj-$(CONFIG_CMD_LZMADEC) += lzmadec.o - +obj-$(CONFIG_CMD_UFS) += ufs.o obj-$(CONFIG_CMD_USB) += usb.o disk.o obj-$(CONFIG_CMD_FASTBOOT) += fastboot.o obj-$(CONFIG_CMD_FS_UUID) += fs_uuid.o
cmd/ufs.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ +/** +* ufs.c - UFS specific U-boot commands +* +* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com +* +*/ +#include <common.h> +#include <command.h> +#include <ufs.h> + +static int do_ufs (cmd_tbl_t *cmdtp,int flag,int argc,char *const argv[]) +{ +int dev, ret; + +if (argc >=2 ) { +if (!strcmp (argv[1 ],"init" )) { +if (argc ==3 ) { + dev =simple_strtoul (argv[2 ],NULL ,10 ); + ret =ufs_probe_dev (dev); +if (ret) +return CMD_RET_FAILURE ; + }else { +ufs_probe (); + } + +return CMD_RET_SUCCESS ; + } + } + +return CMD_RET_USAGE ; +} + +U_BOOT_CMD (ufs,3 ,1 , do_ufs, +"UFS sub system" , +"init [dev] - init UFS subsystem\n" +);
Signature · 1 line
2.19.2
PATCH v2 9/11 cmd: Add Support for UFS commands
Quoted 4 lines · Faiz Abbas
Add Support for commands to initialize and configure UFS devices.
TODO: Add Support for commands to resize and reconfigure LUNs
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/634c58cd/attachment.sig>
PATCH v2 10/11 env: ti: Add environment variables to boot from UFS
In reply to Faiz AbbasAdd environment variables to boot kernel from a filesystem contained in the 2nd UFS LUN. The user can boot from a ufs filesystem just by entering the following commands.
=> setenv boot ufs
=> boot
--- include/configs/j721e_evm.h | 4 +++- include/environment/ti/ufs.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 include/environment/ti/ufs.h
include/configs/j721e_evm.h +3 -1
@@ -13,6 +13,7 @@#include <config_distro_bootcmd.h> #include <environment/ti/mmc.h> #include <environment/ti/k3_rproc.h> +#include <environment/ti/ufs.h> #define CONFIG_ENV_SIZE (128 << 10)
@@ -103,7 +104,8 @@DEFAULT_MMC_TI_ARGS \ EXTRA_ENV_J721E_BOARD_SETTINGS \EXTRA_ENV_J721E_BOARD_SETTINGS_MMC \ -EXTRA_ENV_RPROC_SETTINGS + EXTRA_ENV_RPROC_SETTINGS \ +DEFAULT_UFS_TI_ARGS /* Now for the remaining common defines */#include <configs/ti_armv7_common.h>
include/environment/ti/ufs.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com +* +* Environment variable definitions for UFS on TI boards. +*/ + +#ifndef __TI_UFS_H +#define __TI_UFS_H + +#define DEFAULT_UFS_TI_ARGS \ + "scsirootfstype=ext4 rootwait\0" \ + "ufs_finduuid=part uuid scsi ${bootpart} uuid\0" \ + "args_ufs=setenv devtype scsi;setenv bootpart 1:1;" \ + "run ufs_finduuid;setenv bootargs console = ${console} " \ + "${optargs}" \ + "root=PARTUUID=${uuid} rw " \ + "rootfstype=${scsirootfstype};" \ + "setenv devtype scsi;" \ + "setenv bootpart 1:1\0" \ + "init_ufs=ufs init; scsi scan; run args_ufs\0" \ + "get_kern_ufs=load ${devtype} ${bootpart} ${loadaddr} ${bootdir}/${name_kern}\0" \ + "get_fdt_ufs=load ${devtype} ${bootpart} ${fdtaddr} ${bootdir}/${fdtfile}\0" \ + "get_overlay_ufs=" \ + "fdt address ${fdtaddr};" \ + "fdt resize 0x100000;" \ + "for overlay in $name_overlays;" \ + "do;" \ + "load scsi ${bootpart} ${overlayaddr} ${bootdir}/${overlay} && " \ + "fdt apply ${overlayaddr};" \ + "done;\0" + +#endif
Signature · 1 line
2.19.2
PATCH v2 10/11 env: ti: Add environment variables to boot from UFS
Quoted 8 lines · Faiz Abbas
Add environment variables to boot kernel from a filesystem contained in the 2nd UFS LUN. The user can boot from a ufs filesystem just by entering the following commands.
=> setenv boot ufs
=> bootSigned-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/a5972b73/attachment.sig>
PATCH v2 11/11 configs: j721e_evm_a72: Enable configs for UFS
In reply to Faiz AbbasEnable SCSI and UFS related configs.
--- configs/j721e_evm_a72_defconfig | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
configs/j721e_evm_a72_defconfig +7 -1
@@ -36,11 +36,12 @@ CONFIG_CMD_ASKENV=y CONFIG_CMD_MMC=y CONFIG_CMD_REMOTEPROC=y CONFIG_CMD_SF=y +CONFIG_CMD_UFS=y # CONFIG_CMD_SETEXPR is not set CONFIG_CMD_TIME=y CONFIG_CMD_EXT4_WRITE=y # CONFIG_ISO_PARTITION is not set -# CONFIG_EFI_PARTITION is not set +# CONFIG_SPL_EFI_PARTITION is not set CONFIG_OF_CONTROL=y CONFIG_SPL_OF_CONTROL=y CONFIG_DEFAULT_DEVICE_TREE="k3-j721e-common-proc-board"
@@ -77,6 +78,8 @@ CONFIG_REMOTEPROC_TI_K3_DSP=y CONFIG_REMOTEPROC_TI_K3_R5F=y CONFIG_DM_RESET=y CONFIG_RESET_TI_SCI=y +CONFIG_SCSI=y +CONFIG_DM_SCSI=y CONFIG_DM_SERIAL=y CONFIG_SPI=y CONFIG_DM_SPI=y
@@ -84,4 +87,7 @@ CONFIG_CADENCE_QSPI=y CONFIG_SYSRESET=y CONFIG_SPL_SYSRESET=y CONFIG_SYSRESET_TI_SCI=y +CONFIG_UFS=y +CONFIG_CADENCE_UFS=y +CONFIG_TI_J721E_UFS=y CONFIG_OF_LIBFDT_OVERLAY=y
Signature · 1 line
2.19.2
PATCH v2 11/11 configs: j721e_evm_a72: Enable configs for UFS
Quoted 3 lines · Faiz Abbas
Enable SCSI and UFS related configs.
Signed-off-by Faiz Abbas <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20191024/b84d2474/attachment.sig>
v2 cover Add Support for UFS subsystem for TI's J721e
In reply to Faiz AbbasTom,
Quoted 76 lines · Faiz Abbas
The following patches add support for the Universal Flash Storage (UFS) subsystem and its implementation on TI's J721e platform.
The UFS Application Layer (UAP) uses SCSI SAM-4 command set for communication with the device. Therefore, the first 4 patches prepare the scsi layer for compatibility with UFS. Patch 9 also adds support for initializing and configuring the device from the U-boot command line.
The UFS Transport Protocol Layer (UTP) and UFS Interconnect Layer (UIC) are implemented with patch 5. This series only adds support for detect and read/write operations to the LUNs present in the remote device. Task Management operations and configuration of LUNs will be added in a future series.
Patches 6 through 10 add platform driver, device tree and config support for TI's J721E devices.
Log: https://pastebin.ubuntu.com/p/65JZXGT3Z6/
Tested on top of Lokesh's tree:
https://github.com/lokeshvutla/u-boot
Branch: j721e-full-bootChanges in v2:
1. Added environment variables such that its easy to boot kernel from UFS.
2. Introduced an API to probe UFS devices individually.
3. Changed ti-j721e-ufs wrapper driver toUCLASS_MISCbecause its not really a UFS device driver.References:
[1] JESD220D UFS 3.0:
https://www.jedec.org/standards-documents/docs/jesd220c
[2] JESD223D UFS Host Controller Interface (UFSHCI) version 3.0:
https://www.jedec.org/standards-documents/docs/jesd223cFaiz Abbas (11):
scsi: Simplify scsi_read()/_write()
scsi: Addmax_bytes_per_reqtoscsi_platdata
scsi: Retry inquiry 3 times to overcome Unit Attention condition
scsi: Add dma direction member to command structure
ufs: Add Initial Support for UFS subsystem
ufs: Add Support for Cadence platform UFS driver
ufs: Add glue layer driver for TI J721E devices
arm: dts: k3-j721e-main: Add UFS nodes
cmd: Add Support for UFS commands
env: ti: Add environment variables to boot from UFS
configs:j721e_evm_a72: Enable configs for UFSMAINTAINERS | 5 + arch/arm/dts/k3-j721e-main.dtsi | 24 + cmd/Kconfig | 7 + cmd/Makefile | 2 +- cmd/ufs.c | 37 + configs/j721e_evm_a72_defconfig | 8 +- drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/scsi/scsi.c | 83 +- drivers/ufs/Kconfig | 23 + drivers/ufs/Makefile | 8 + drivers/ufs/cdns-platform.c | 122 ++ drivers/ufs/ti-j721e-ufs.c | 71 ++ drivers/ufs/ufs-uclass.c | 16 + drivers/ufs/ufs.c | 1968 +++++++++++++++++++++++++++++++ drivers/ufs/ufs.h | 918 ++++++++++++++ drivers/ufs/unipro.h | 270 +++++ include/configs/j721e_evm.h | 4 +- include/dm/uclass-id.h | 1 + include/environment/ti/ufs.h | 33 + include/scsi.h | 5 + include/ufs.h | 29 + 22 files changed, 3590 insertions(+), 47 deletions(-) create mode 100644 cmd/ufs.c create mode 100644 drivers/ufs/Kconfig create mode 100644 drivers/ufs/Makefile
Quoted 9 lines
create mode 100644 drivers/ufs/cdns-platform.c create mode 100644 drivers/ufs/ti-j721e-ufs.c create mode 100644 drivers/ufs/ufs-uclass.c create mode 100644 drivers/ufs/ufs.c create mode 100644 drivers/ufs/ufs.h create mode 100644 drivers/ufs/unipro.h create mode 100644 include/environment/ti/ufs.h create mode 100644 include/ufs.h
Were you able to pick this up for the merge window?
Thanks,
Faiz