Skip to contentSkip to conversation

scsi: ufs: Add configfs support for UFS provisioning

PATCH New Sayali Lokhande 1 participant 1 message Aug 28, 2018 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 scsi: ufs: Add configfs support for UFS provisioning

This patch adds configfs support to provision UFS device at runtime. This feature can be primarily useful in factory or assembly line as some devices may be required to be configured multiple times during initial system development phase. Configuration Descriptors can be written multiple times until bConfigDescrLock attribute is zero.

Configuration descriptor buffer consists of Device and Unit descriptor configurable parameters which are parsed from vendor specific provisioning file and then passed via configfs node at runtime to provision ufs device.
CONFIG_CONFIGFS_FS needs to be enabled for using this feature.

Usage:
1) To read current configuration descriptor with index X :
echo X > /config/XXXX.ufshc/ufs_config_desc_index cat /config/XXXX.ufshc/ufs_provision
2) To write configuration descriptor with index X :
echo X > /config/XXXX.ufshc/ufs_config_desc_index echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provision

---
 Documentation/ABI/testing/configfs-driver-ufs |  35 +++++
 drivers/scsi/ufs/Kconfig                      |  10 ++
 drivers/scsi/ufs/Makefile                     |   1 +
 drivers/scsi/ufs/ufs-configfs.c               | 208 ++++++++++++++++++++++++++
 drivers/scsi/ufs/ufshcd.c                     |   5 +-
 drivers/scsi/ufs/ufshcd.h                     |  22 +++
 6 files changed, 279 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/ABI/testing/configfs-driver-ufs
 create mode 100644 drivers/scsi/ufs/ufs-configfs.c
Documentation/ABI/testing/configfs-driver-ufs new file +35 -0
new file mode 100644
index 0000000..71df18e
@@ -0,0 +1,35 @@
+What:		/config/*/ufs_config_desc_index
+Date:		Jun 2018
+KernelVersion:	4.19
+Description:
+		This file shows the current ufs configuration descriptor index.
+		For more details, refer 14.1.6.3 Configuration Descriptor.
+		Once index is set, respective Configuration Descriptor can be written
+		using ufs_provision entry (refer /config/*/ufs_provision below).
+		Usage:
+		echo <Index> > /config/XXXX.ufshc/ufs_config_desc_index
+
+What:		/config/*/ufs_provision
+Date:		Jun 2018
+KernelVersion:	4.19
+Description:
+		This file shows the current ufs configuration descriptor set in device.
+		This can be used to provision ufs device if bConfigDescrLock is 0.
+		For more details, refer 14.1.6.3 Configuration Descriptor and
+		Table 14-12 - Unit Descriptor configurable parameters from specs for
+		description and format to be passed for respective index of configuration
+		descriptor. Please note each parameter must be passed in space separated
+		format.
+		Usage:
+		echo <Configuration_Descriptor_for_Index> /config/XXXX.ufshc/ufs_provision
+
+		For example: To write Configuration Descriptor with Index 0
+		echo 0 > /config/XXXX.ufshc/ufs_config_desc_index
+
+		echo <bLength> <bDescriptorIDN> <bConfDescContinue> <bBootEnable>
+		<bDescrAccessEn> <bInitPowerMode> <bHighPriorityLUN>
+		<bSecureRemovalType> <bInitActiveICCLevel> <wPeriodicRTCUpdate>
+		<0Bh:0Fh_ReservedAs_0> <bLUEnable> <bBootLunID> <bLUWriteProtect>
+		<bMemoryType> <dNumAllocUnits> <bDataReliability> <bLogicalBlockSize>
+		<bProvisioningType> <wContextCapabilities> <0Dh:0Fh_ReservedAs_0>
+		> /config/XXXX.ufshc/ufs_provision
drivers/scsi/ufs/Kconfig +10 -0
index e27b4d4..a9a0a58 100644
@@ -100,3 +100,13 @@ config SCSI_UFS_QCOM
 
 	  Select this if you have UFS controller on QCOM chipset.
 	  If unsure, say N.
+
+config UFS_PROVISION
+	tristate "Runtime UFS Provisioning support"
+	depends on SCSI_UFSHCD && CONFIGFS_FS
+	help
+	  This enables runtime UFS provisioning support. This can be used
+	  primarily during assembly line as some devices may be required to
+	  be configured multiple times during initial development phase.
+
+	  If unsure, say N.
drivers/scsi/ufs/Makefile +1 -0
index 918f579..00110ea 100644
@@ -5,5 +5,6 @@ obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o ufshcd-dwc.o tc-d
 obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
 ufshcd-core-objs := ufshcd.o ufs-sysfs.o
+obj-$(CONFIG_UFS_PROVISION) += ufs-configfs.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
 obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
drivers/scsi/ufs/ufs-configfs.c new file +208 -0

208 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.c +3 -2
index e01cdc0..6be98bc 100644
@@ -2887,7 +2887,7 @@ int ufshcd_query_descriptor_retry(struct ufs_hba *hba,
  *
  * Return 0 in case of success, non-zero otherwise
  */
-static int ufshcd_read_desc_length(struct ufs_hba *hba,
+int ufshcd_read_desc_length(struct ufs_hba *hba,
 	enum desc_idn desc_id,
 	int desc_index,
 	int *desc_length)
@@ -7711,6 +7711,7 @@ int ufshcd_shutdown(struct ufs_hba *hba)
 void ufshcd_remove(struct ufs_hba *hba)
 {
 	ufs_sysfs_remove_nodes(hba->dev);
+	ufshcd_configfs_exit();
 	scsi_remove_host(hba->host);
 	/* disable interrupts */
 	ufshcd_disable_intr(hba, hba->intr_mask);
@@ -7965,7 +7966,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 
 	async_schedule(ufshcd_async_scan, hba);
 	ufs_sysfs_add_nodes(hba->dev);
-
+	ufshcd_configfs_init(hba, dev_name(hba->dev));
 	return 0;
 
 out_remove_scsi_host:
drivers/scsi/ufs/ufshcd.h +22 -0
index 45013b6..b14d900 100644
@@ -37,6 +37,7 @@
 #ifndef _UFSHCD_H
 #define _UFSHCD_H
 
+#include <linux/configfs.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -515,6 +516,10 @@ struct ufs_hba {
 
 	struct Scsi_Host *host;
 	struct device *dev;
+#ifdef CONFIG_UFS_PROVISION
+	struct configfs_subsystem subsys;
+	u8 config_desc_index;
+#endif
 	/*
 	 * This field is to keep a reference to "scsi_device" corresponding to
 	 * "UFS device" W-LU.
@@ -867,6 +872,23 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index,
 
 int ufshcd_hold(struct ufs_hba *hba, bool async);
 void ufshcd_release(struct ufs_hba *hba);
+int ufshcd_read_desc_length(struct ufs_hba *hba,
+	enum desc_idn desc_id,
+	int desc_index,
+	int *desc_length);
+
+/* Expose UFS configfs API's */
+#ifndef CONFIG_UFS_PROVISION
+static inline void ufshcd_configfs_init(struct ufs_hba *hba, const char *name)
+{
+}
+static inline void ufshcd_configfs_exit(void)
+{
+}
+#else
+void ufshcd_configfs_init(struct ufs_hba *hba, const char *name);
+void ufshcd_configfs_exit(void);
+#endif
 
 int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id,
 	int *desc_length);
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project