scsi: ufs: set the device reference clock setting
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v10 1/2 scsi: ufs: set the device reference clock setting
From: Subhash Jadavani <[email protected]>
UFS host supplies the reference clock to UFS device and UFS device specification allows host to provide one of the 4 frequencies (19.2 MHz, 26 MHz, 38.4 MHz, 52 MHz) for reference clock. Host should set the device reference clock frequency setting in the device based on what frequency it is supplying to UFS device.
--- drivers/scsi/ufs/ufs.h | 14 +++++++ drivers/scsi/ufs/ufshcd-pltfrm.c | 2 + drivers/scsi/ufs/ufshcd.c | 90 ++++++++++++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 2 + 4 files changed, 108 insertions(+)
drivers/scsi/ufs/ufs.h +14 -0
@@ -378,6 +378,20 @@ enum query_opcode { UPIU_QUERY_OPCODE_TOGGLE_FLAG = 0x8, }; +/* bRefClkFreq attribute values */ +enum ufs_ref_clk_freq { +REF_CLK_FREQ_19_2_MHZ =0 , +REF_CLK_FREQ_26_MHZ =1 , +REF_CLK_FREQ_38_4_MHZ =2 , +REF_CLK_FREQ_52_MHZ =3 , +REF_CLK_FREQ_INVAL =-1 , +}; + +struct ufs_ref_clk { +u32 freq_hz; +enum ufs_ref_clk_freq val; +}; +/* Query response result code */ enum {QUERY_RESULT_SUCCESS =0x00 ,
drivers/scsi/ufs/ufshcd-pltfrm.c +2 -0
@@ -343,6 +343,8 @@ int ufshcd_pltfrm_init(struct platform_device *pdev,pm_runtime_set_active (&pdev->dev);pm_runtime_enable (&pdev->dev); +ufshcd_parse_dev_ref_clk_freq (hba); +ufshcd_init_lanes_per_dir (hba); err =ufshcd_init (hba, mmio_base, irq);
drivers/scsi/ufs/ufshcd.c +90 -0
108 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.h +2 -0
@@ -548,6 +548,7 @@ struct ufs_hba {void *priv;unsigned int irq;bool is_irq_enabled; +enum ufs_ref_clk_freq dev_ref_clk_freq;/* Interrupt aggregation support is broken */ #define UFSHCD_QUIRK_BROKEN_INTR_AGGR 0x1
@@ -746,6 +747,7 @@ static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)int ufshcd_wait_for_register (struct ufs_hba *hba,u32 reg,u32 mask,u32 val,unsigned long interval_us,unsigned long timeout_ms,bool can_sleep); +void ufshcd_parse_dev_ref_clk_freq (struct ufs_hba *hba);static inline void check_upiu_size (void ) {
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v10 2/2 scsi: ufs: Add configfs support for UFS provisioning
In reply to a message not in the archiveThis 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 :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provision
--- Documentation/ABI/testing/configfs-driver-ufs | 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155 ++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++ 6 files changed, 203 insertions(+), 1 deletion(-) 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 +18 -0
@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provision +Date: Jun 2018 +KernelVersion: 4.14 +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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated + format specificied as below: + 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
@@ -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
@@ -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 +155 -0
155 lines not on this page · raw message
drivers/scsi/ufs/ufshcd.c +2 -1
@@ -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 +17 -0
@@ -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,9 @@ struct ufs_hba {struct Scsi_Host *host;struct device *dev; +#ifdef CONFIG_UFS_PROVISION +struct configfs_subsystem subsys; +#endif /* * This field is to keep a reference to "scsi_device" corresponding to * "UFS device" W-LU.
@@ -868,6 +872,19 @@ 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); +/* 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
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
Quoted 37 lines · Sayali Lokhande
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>--- Documentation/ABI/testing/configfs-driver-ufs | 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155 ++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++ 6 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/configfs-driver-ufs create mode 100644 drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0
Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provision
You are using the device name as the config subsystem name, so this is really:
What: /config/*/ufs_provision
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.14
4.19 maybe
Documentation/ABI/testing/configfs-driver-ufs line 5
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set in device.
It is only the first config descriptor though isn't it? There is no support for the other 3. Shouldn't we support config descriptors fully?
Documentation/ABI/testing/configfs-driver-ufs line 11
Quoted 6 lines
Documentation/ABI/testing/configfs-driver-ufs new file +6
-0+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated + format specificied as below:
specificied -> specified
Documentation/ABI/testing/configfs-driver-ufs line 17
Quoted 6 lines
Documentation/ABI/testing/configfs-driver-ufs new file +6
-0+ 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>
This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Quoted 48 lines
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0+ > /config/XXXX.ufshc/ufs_provisiondrivers/scsi/ufs/Kconfig +10
-0@@ -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@@ -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.odrivers/scsi/ufs/ufs-configfs.c new file +12
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba (struct config_item *item) +{
drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 10 lines
drivers/scsi/ufs/ufs-configfs.c new file +10
-0+struct config_group *group =to_config_group (item); +struct configfs_subsystem *subsys =to_configfs_subsystem (group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys); + +return subsys ? hba :NULL ; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ +u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE ] = {0 };
Is it really ok to hard-code the descriptor size?
Quoted 60 lines
drivers/scsi/ufs/ufs-configfs.c new file +60
-0+int desc_buf_len =QUERY_DESC_CONFIGURATION_DEF_SIZE ; +int i, ret, curr_len =0 ; +struct ufs_hba *hba =config_item_to_hba (item); + + ret =ufshcd_query_descriptor_retry (hba,UPIU_QUERY_OPCODE_READ_DESC , +QUERY_DESC_IDN_CONFIGURATION ,0 ,0 , desc_buf, &desc_buf_len); + +if (ret) +return ret; + +for (i =0 ; i < desc_buf_len; i++) + curr_len +=snprintf ((buf + curr_len), (PAGE_SIZE - curr_len), +"0x%x " , desc_buf[i]); + +return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, +const char *buf,size_t count) +{ +char *strbuf; +char *strbuf_copy; +u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE ] = {0 }; +int desc_buf_len =QUERY_DESC_CONFIGURATION_DEF_SIZE ; +char *token; +int i, ret, value; +u32 config_desc_lock =0 ; + +/* reserve one byte for null termination */ + strbuf =kmalloc (count +1 ,GFP_KERNEL ); +if (!strbuf) +return -ENOMEM ; + + strbuf_copy = strbuf; +strlcpy (strbuf, buf, count +1 ); + +/* Just return if bConfigDescrLock is already set */ + ret =ufshcd_query_attr (hba,UPIU_QUERY_OPCODE_READ_ATTR , +QUERY_ATTR_IDN_CONF_DESC_LOCK ,0 ,0 , &config_desc_lock); +if (ret) + goto out; + +if (config_desc_lock) { +dev_err (hba->dev,"%s: bConfigDescrLock already set to %u, cannot re-provision device!\n" , + __func__, config_desc_lock); + ret = -EINVAL ; + goto out; + } + +for (i =0 ; i <QUERY_DESC_CONFIGURATION_DEF_SIZE ; i++) { + token =strsep (&strbuf," " ); +if (!token && i) +break ; + + ret =kstrtoint (token,0 , &value); +if (ret) { +dev_err (hba->dev,"%s: kstrtoint failed %d %s\n" , + __func__, ret, token); + ret = -EINVAL ; + goto out;
drivers/scsi/ufs/ufs-configfs.c line 92
Quoted 10 lines
drivers/scsi/ufs/ufs-configfs.c new file +10
-0+ } + desc_buf[i] = (u8 )value; + } + +/* Write configuration descriptor to provision ufs */ + ret =ufshcd_query_descriptor_retry (hba,UPIU_QUERY_OPCODE_WRITE_DESC , +QUERY_DESC_IDN_CONFIGURATION ,0 ,0 , desc_buf, &desc_buf_len); + +if (!ret) + dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",
That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Quoted 40 lines
drivers/scsi/ufs/ufs-configfs.c new file +40
-0+ __func__); + +out: +kfree (strbuf_copy); +if (ret) +return ret; +return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, +const char *buf,size_t count) +{ +struct ufs_hba *hba =config_item_to_hba (item); + +return ufshcd_desc_configfs_store (hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name ="ufs_provision" , + .ca_mode =0644 , + .ca_owner =THIS_MODULE , + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, +NULL , +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner =THIS_MODULE , +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + },
drivers/scsi/ufs/ufs-configfs.c line 142
Quoted 10 lines
drivers/scsi/ufs/ufs-configfs.c new file +10
-0+ }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name) +{ +int ret; +struct configfs_subsystem *subsys = &hba->subsys; + +strncpy (ufscfg_subsys.su_group.cg_item.ci_namebuf, name,strlen (name)); + subsys->su_group = ufscfg_subsys.su_group;
configfs_subsystem cannot share su_group with other configfs_subsystem i.e you are not allowing for there being more than 1 hba
Quoted 77 lines
drivers/scsi/ufs/ufs-configfs.c new file +13
-0+config_group_init (&subsys->su_group); +mutex_init (&subsys->su_mutex); + ret =configfs_register_subsystem (subsys); +if (ret) +pr_err ("Error %d while registering subsystem %s\n" , + ret, + subsys->su_group.cg_item.ci_namebuf); +} + +void ufshcd_configfs_exit (void ) +{ +configfs_unregister_subsystem (&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +17
-0@@ -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,9 @@ struct ufs_hba {struct Scsi_Host *host;struct device *dev; +#ifdef CONFIG_UFS_PROVISION +struct configfs_subsystem subsys; +#endif /* * This field is to keep a reference to "scsi_device" corresponding to * "UFS device" W-LU. @@ -868,6 +872,19 @@ 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); +/* 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);
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
Hi Adrian,
Quoted 41 lines · Adrian Hunter
Quoted 37 lines · Sayali Lokhande
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>--- Documentation/ABI/testing/configfs-driver-ufs | 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155 ++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++ 6 files changed, 203 insertions(+), 1 deletion(-)create mode 100644
Documentation/ABI/testing/configfs-driver-ufscreate mode 100644drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provisionYou are using the device name as the config subsystem name, so this is really:
Quoted 1 line
What: /config/*/ufs_provision
Agree. Will update.
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.144.19 maybe
Done.
Quoted 4 lines
Documentation/ABI/testing/configfs-driver-ufs line 5
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set in device.It is only the first config descriptor though isn't it? There is no support for the other 3. Shouldn't we support config descriptors fully?
Yes, we should support config descriptors fully. My current implementation only supports config desc (index = 00h). I m thinking I can add separate "index" field along with "ufs_provision" field and can use this index (instead of hard coding to 0) to write repective config_desc. In this way, we should first set the "index" and then read/write to "ufs_provision". Let me know if you have any concern with this approach ?
Quoted 7 lines
Documentation/ABI/testing/configfs-driver-ufs line 11
Quoted 6 lines
Documentation/ABI/testing/configfs-driver-ufs new file +6
-0+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated + format specificied as below:specificied -> specified
Done
Quoted 9 lines
Documentation/ABI/testing/configfs-driver-ufs line 17
Quoted 6 lines
Documentation/ABI/testing/configfs-driver-ufs new file +6
-0+ 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>This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Agree. Will update to just refer to UFS spec (for Config_desc format).
Quoted 51 lines
Quoted 51 lines
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0+ > /config/XXXX.ufshc/ufs_provisiondrivers/scsi/ufs/Kconfig +10
-0@@ -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@@ -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.odrivers/scsi/ufs/ufs-configfs.c new file +15
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba (struct config_item *item) +{ +struct config_group *group =to_config_group (item); +struct configfs_subsystem *subsys =to_configfs_subsystem (group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys);
Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 7 lines
drivers/scsi/ufs/ufs-configfs.c new file +7
-0+ +return subsys ? hba :NULL ; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ +u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE ] = {0 };Is it really ok to hard-code the descriptor size?
I will use ufshcd_read_desc_length() api for each index as required. Will remove this hard-code.
Quoted 65 lines
Quoted 65 lines
drivers/scsi/ufs/ufs-configfs.c new file +65
-0+int desc_buf_len =QUERY_DESC_CONFIGURATION_DEF_SIZE ; +int i, ret, curr_len =0 ; +struct ufs_hba *hba =config_item_to_hba (item); + + ret =ufshcd_query_descriptor_retry (hba,UPIU_QUERY_OPCODE_READ_DESC , +QUERY_DESC_IDN_CONFIGURATION ,0 ,0 , desc_buf, &desc_buf_len); + +if (ret) +return ret; + +for (i =0 ; i < desc_buf_len; i++) + curr_len +=snprintf ((buf + curr_len), (PAGE_SIZE - curr_len), +"0x%x " , desc_buf[i]); + +return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, +const char *buf,size_t count) +{ +char *strbuf; +char *strbuf_copy; +u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE ] = {0 }; +int desc_buf_len =QUERY_DESC_CONFIGURATION_DEF_SIZE ; +char *token; +int i, ret, value; +u32 config_desc_lock =0 ; + +/* reserve one byte for null termination */ + strbuf =kmalloc (count +1 ,GFP_KERNEL ); +if (!strbuf) +return -ENOMEM ; + + strbuf_copy = strbuf; +strlcpy (strbuf, buf, count +1 ); + +/* Just return if bConfigDescrLock is already set */ + ret =ufshcd_query_attr (hba,UPIU_QUERY_OPCODE_READ_ATTR , +QUERY_ATTR_IDN_CONF_DESC_LOCK ,0 ,0 , &config_desc_lock); +if (ret) + goto out; + +if (config_desc_lock) { +dev_err (hba->dev,"%s: bConfigDescrLock already set to %u, cannot re-provision device!\n" , + __func__, config_desc_lock); + ret = -EINVAL ; + goto out; + } + +for (i =0 ; i <QUERY_DESC_CONFIGURATION_DEF_SIZE ; i++) { + token =strsep (&strbuf," " ); +if (!token && i) +break ; + + ret =kstrtoint (token,0 , &value); +if (ret) { +dev_err (hba->dev,"%s: kstrtoint failed %d %s\n" , + __func__, ret, token); + ret = -EINVAL ; + goto out; + } + desc_buf[i] = (u8 )value; + } + +/* Write configuration descriptor to provision ufs */
Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 92
Quoted 5 lines
drivers/scsi/ufs/ufs-configfs.c new file +5
-0+ ret =ufshcd_query_descriptor_retry (hba,UPIU_QUERY_OPCODE_WRITE_DESC , +QUERY_DESC_IDN_CONFIGURATION ,0 ,0 , desc_buf, &desc_buf_len); + +if (!ret) + dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Agree. Will update.
Quoted 45 lines
Quoted 45 lines
drivers/scsi/ufs/ufs-configfs.c new file +44
-0+ __func__); + +out: +kfree (strbuf_copy); +if (ret) +return ret; +return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, +const char *buf,size_t count) +{ +struct ufs_hba *hba =config_item_to_hba (item); + +return ufshcd_desc_configfs_store (hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name ="ufs_provision" , + .ca_mode =0644 , + .ca_owner =THIS_MODULE , + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, +NULL , +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner =THIS_MODULE , +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + }, + }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name)
Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 142
Quoted 6 lines
drivers/scsi/ufs/ufs-configfs.c new file +6
-0+{ +int ret; +struct configfs_subsystem *subsys = &hba->subsys; + +strncpy (ufscfg_subsys.su_group.cg_item.ci_namebuf, name,strlen (name)); + subsys->su_group = ufscfg_subsys.su_group;
configfs_subsystemcannot sharesu_groupwith otherconfigfs_subsystemi.e you are not allowing for there being more than 1 hba
Agree. I think I will have to move above declarations(ufscfg_subsys/ufscfg_type/ufshcd_attrs) in driver .c/.h file (to make it per ufs hba/probe). Will check and update.
Quoted 77 lines
Quoted 77 lines
drivers/scsi/ufs/ufs-configfs.c new file +13
-0+config_group_init (&subsys->su_group); +mutex_init (&subsys->su_mutex); + ret =configfs_register_subsystem (subsys); +if (ret) +pr_err ("Error %d while registering subsystem %s\n" , + ret, + subsys->su_group.cg_item.ci_namebuf); +} + +void ufshcd_configfs_exit (void ) +{ +configfs_unregister_subsystem (&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +17
-0@@ -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,9 @@ struct ufs_hba {struct Scsi_Host *host;struct device *dev; +#ifdef CONFIG_UFS_PROVISION +struct configfs_subsystem subsys; +#endif /* * This field is to keep a reference to "scsi_device" corresponding to * "UFS device" W-LU. @@ -868,6 +872,19 @@ 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); +/* 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);
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
Quoted 1 line · Sayali Lokhande
Hi Adrian,
Hi Sayali
I see you sent version V10.1. Should I look at that or are you about to make a V11
Quoted 358 lines · Adrian Hunter
Quoted 44 lines · Sayali Lokhande
Quoted 39 lines
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>---
Documentation/ABI/testing/configfs-driver-ufs| 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155
++++++++++++++++++++++++++
drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++6 files changed, 203 insertions(+), 1 deletion(-)create mode 100644
Documentation/ABI/testing/configfs-driver-ufscreate mode 100644drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provisionYou are using the device name as the config subsystem name, so this is really:
Quoted 1 line
What: /config/*/ufs_provision
Agree. Will update.
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.144.19 maybe
Done.
Quoted 5 lines
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set indevice.
It is only the first config descriptor though isn't it? There is no support for the other 3. Shouldn't we support config descriptors fully?
Yes, we should support config descriptors fully. My current implementation only supports config desc (index = 00h).
I m thinking I can add separate "index" field along with "ufs_provision" field and can use this index (instead of hard coding to 0)
to write repectiveconfig_desc. In this way, we should first set the "index" and then read/write to "ufs_provision".
Let me know if you have any concern with this approach ?Quoted 9 lines
Quoted 8 lines
+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated
+ format specificied as below:specificied -> specified
Done
Quoted 10 lines
Quoted 7 lines
+ 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>This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Agree. Will update to just refer to UFS spec (for
Config_descformat).Quoted 52 lines
Quoted 52 lines
+ > /config/XXXX.ufshc/ufs_provision
drivers/scsi/ufs/Kconfig +0
-0@@ -100,3 +100,13 @@ config SCSI_UFS_QCOMSelect this if you have UFS controller on QCOM chipset. If unsure, say N.
drivers/scsi/ufs/Kconfig +10
-0+ +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 +0
-0@@ -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 +15
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba (struct config_item *item) +{ + struct config_group *group = to_config_group(item); + struct configfs_subsystem *subsys = to_configfs_subsystem(group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys);Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 7 lines
drivers/scsi/ufs/ufs-configfs.c new file +7
-0+ + return subsys ? hba : NULL; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0};Is it really ok to hard-code the descriptor size?
I will use
ufshcd_read_desc_length()api for each index as required. Will remove this hard-code.Quoted 66 lines
Quoted 66 lines
drivers/scsi/ufs/ufs-configfs.c new file +44
-0+ int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + int i, ret, curr_len = 0; + struct ufs_hba *hba = config_item_to_hba(item); + + ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, + QUERY_DESC_IDN_CONFIGURATION, 0, 0, desc_buf, &desc_buf_len); + + if (ret) + return ret; + + for (i = 0; i < desc_buf_len; i++) + curr_len += snprintf((buf + curr_len), (PAGE_SIZE - curr_len), + "0x%x ", desc_buf[i]); + + return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, + const char *buf, size_t count) +{ + char *strbuf; + char *strbuf_copy; + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0}; + int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + char *token; + int i, ret, value; + u32 config_desc_lock = 0; + + /* reserve one byte for null termination */ + strbuf = kmalloc(count + 1, GFP_KERNEL); + if (!strbuf) + return -ENOMEM; + + strbuf_copy = strbuf; + strlcpy(strbuf, buf, count + 1); + + /* Just return if bConfigDescrLock is already set */ + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_CONF_DESC_LOCK, 0, 0, &config_desc_lock); + if (ret) + goto out; + + if (config_desc_lock) { + dev_err(hba->dev, "%s: bConfigDescrLock already set to %u,cannot re-provision device!\n",
+__func__,config_desc_lock);
+ ret =-EINVAL;
+ goto out;
+ }drivers/scsi/ufs/ufs-configfs.c new file +17
-0+ + for (i = 0; i < QUERY_DESC_CONFIGURATION_DEF_SIZE; i++) { + token = strsep(&strbuf, " "); + if (!token && i) + break; + + ret = kstrtoint(token, 0, &value); + if (ret) { + dev_err(hba->dev, "%s: kstrtoint failed %d %s\n", + __func__, ret, token); + ret = -EINVAL; + goto out; + } + desc_buf[i] = (u8)value; + } + + /* Write configuration descriptor to provision ufs */Quoted 8 lines
Quoted 5 lines
+ ret = ufshcd_query_descriptor_retry(hba,
UPIU_QUERY_OPCODE_WRITE_DESC, +QUERY_DESC_IDN_CONFIGURATION, 0, 0,desc_buf,&desc_buf_len); +
+ if (!ret)
+ dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Agree. Will update.
Quoted 45 lines
Quoted 45 lines
+
__func__);drivers/scsi/ufs/ufs-configfs.c new file +43
-0+ +out: + kfree(strbuf_copy); + if (ret) + return ret; + return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, + const char *buf, size_t count) +{ + struct ufs_hba *hba = config_item_to_hba(item); + + return ufshcd_desc_configfs_store(hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name = "ufs_provision", + .ca_mode = 0644, + .ca_owner = THIS_MODULE, + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, + NULL, +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + }, + }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name)Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 142
Quoted 6 lines
drivers/scsi/ufs/ufs-configfs.c new file +6
-0+{ + int ret; + struct configfs_subsystem *subsys = &hba->subsys; + + strncpy(ufscfg_subsys.su_group.cg_item.ci_namebuf, name, strlen(name)); + subsys->su_group = ufscfg_subsys.su_group;
configfs_subsystemcannot sharesu_groupwith otherconfigfs_subsystemi.e you are not allowing for there being more than 1 hbaAgree. I think I will have to move above
declarations(ufscfg_subsys/ufscfg_type/ufshcd_attrs)in driver .c/.h file (to make it per ufs hba/probe).
Will check and update.Quoted 75 lines
Quoted 75 lines
+
config_group_init(&subsys->su_group);
+mutex_init(&subsys->su_mutex);
+ ret =configfs_register_subsystem(subsys);
+ if (ret)
+ pr_err("Error %d while registering subsystem %s\n", + ret,
+subsys->su_group.cg_item.ci_namebuf);drivers/scsi/ufs/ufs-configfs.c new file +6
-0+} + +void ufshcd_configfs_exit (void ) +{ + configfs_unregister_subsystem(&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +0
-0@@ -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>drivers/scsi/ufs/ufshcd.h +3
-0@@ -515,6 +516,9 @@ struct ufs_hba { struct Scsi_Host *host; struct device *dev; +#ifdef CONFIG_UFS_PROVISION + struct configfs_subsystem subsys; +#endif /** This field is to keep a reference to "scsi_device" corresponding to * "UFS device" W-LU. @@ -868,6 +872,19 @@ 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);+/* Expose UFS configfs API's */
drivers/scsi/ufs/ufshcd.h +2
-0+#ifndef CONFIG_UFS_PROVISION +static inline void ufshcd_configfs_init(struct ufs_hba *hba, const char*name)
drivers/scsi/ufs/ufshcd.h +10
-0+{ +} +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, enumdesc_idndesc_id,
int*desc_length);
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
In reply to Sayali LokhandeQuoted 58 lines · Sayali Lokhande
Hi Adrian,
Quoted 44 lines · Adrian Hunter
Quoted 39 lines · Sayali Lokhande
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>---
Documentation/ABI/testing/configfs-driver-ufs| 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155
++++++++++++++++++++++++++
drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++6 files changed, 203 insertions(+), 1 deletion(-)create mode 100644
Documentation/ABI/testing/configfs-driver-ufscreate mode 100644drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provisionYou are using the device name as the config subsystem name, so this is really:
Quoted 1 line
What: /config/*/ufs_provision
Agree. Will update.
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.144.19 maybe
Done.
Quoted 5 lines
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set indevice.
It is only the first config descriptor though isn't it? There is no support for the other 3. Shouldn't we support config descriptors fully?
Quoted 7 lines
Yes, we should support config descriptors fully. My current implementation only supports config desc (index = 00h).
I m thinking I can add separate "index" field along with "ufs_provision" field and can use this index (instead of hard coding to 0)
to write repectiveconfig_desc. In this way, we should first set the "index" and then read/write to "ufs_provision".
Let me know if you have any concern with this approach ?
One file for each config descriptor would seem more normal.
Quoted 83 lines
Quoted 10 lines
Quoted 9 lines
+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated
+ format specificied as below:specificied -> specified
Done
Quoted 10 lines
Quoted 7 lines
+ 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>This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Agree. Will update to just refer to UFS spec (for
Config_descformat).Quoted 52 lines
Quoted 52 lines
+ > /config/XXXX.ufshc/ufs_provision
drivers/scsi/ufs/Kconfig +0
-0@@ -100,3 +100,13 @@ config SCSI_UFS_QCOMSelect this if you have UFS controller on QCOM chipset. If unsure, say N.
drivers/scsi/ufs/Kconfig +10
-0+ +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 +0
-0@@ -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 +15
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba (struct config_item *item) +{ + struct config_group *group = to_config_group(item); + struct configfs_subsystem *subsys = to_configfs_subsystem(group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys);Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 7 lines
drivers/scsi/ufs/ufs-configfs.c new file +7
-0+ + return subsys ? hba : NULL; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0};Is it really ok to hard-code the descriptor size?
Quoted 2 lines
I will use
ufshcd_read_desc_length()api for each index as required. Will remove this hard-code.
Alternatively, I see there is already hba->desc_size.conf_desc
Quoted 209 lines
Quoted 66 lines
Quoted 66 lines
drivers/scsi/ufs/ufs-configfs.c new file +44
-0+ int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + int i, ret, curr_len = 0; + struct ufs_hba *hba = config_item_to_hba(item); + + ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, + QUERY_DESC_IDN_CONFIGURATION, 0, 0, desc_buf, &desc_buf_len); + + if (ret) + return ret; + + for (i = 0; i < desc_buf_len; i++) + curr_len += snprintf((buf + curr_len), (PAGE_SIZE - curr_len), + "0x%x ", desc_buf[i]); + + return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, + const char *buf, size_t count) +{ + char *strbuf; + char *strbuf_copy; + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0}; + int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + char *token; + int i, ret, value; + u32 config_desc_lock = 0; + + /* reserve one byte for null termination */ + strbuf = kmalloc(count + 1, GFP_KERNEL); + if (!strbuf) + return -ENOMEM; + + strbuf_copy = strbuf; + strlcpy(strbuf, buf, count + 1); + + /* Just return if bConfigDescrLock is already set */ + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_CONF_DESC_LOCK, 0, 0, &config_desc_lock); + if (ret) + goto out; + + if (config_desc_lock) { + dev_err(hba->dev, "%s: bConfigDescrLock already set to %u,cannot re-provision device!\n",
+__func__,config_desc_lock);
+ ret =-EINVAL;
+ goto out;
+ }drivers/scsi/ufs/ufs-configfs.c new file +17
-0+ + for (i = 0; i < QUERY_DESC_CONFIGURATION_DEF_SIZE; i++) { + token = strsep(&strbuf, " "); + if (!token && i) + break; + + ret = kstrtoint(token, 0, &value); + if (ret) { + dev_err(hba->dev, "%s: kstrtoint failed %d %s\n", + __func__, ret, token); + ret = -EINVAL; + goto out; + } + desc_buf[i] = (u8)value; + } + + /* Write configuration descriptor to provision ufs */Quoted 8 lines
Quoted 5 lines
+ ret = ufshcd_query_descriptor_retry(hba,
UPIU_QUERY_OPCODE_WRITE_DESC, +QUERY_DESC_IDN_CONFIGURATION, 0, 0,desc_buf,&desc_buf_len); +
+ if (!ret)
+ dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Agree. Will update.
Quoted 45 lines
Quoted 45 lines
+
__func__);drivers/scsi/ufs/ufs-configfs.c new file +43
-0+ +out: + kfree(strbuf_copy); + if (ret) + return ret; + return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, + const char *buf, size_t count) +{ + struct ufs_hba *hba = config_item_to_hba(item); + + return ufshcd_desc_configfs_store(hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name = "ufs_provision", + .ca_mode = 0644, + .ca_owner = THIS_MODULE, + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, + NULL, +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + }, + }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name)Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 142
Quoted 6 lines
drivers/scsi/ufs/ufs-configfs.c new file +6
-0+{ + int ret; + struct configfs_subsystem *subsys = &hba->subsys; + + strncpy(ufscfg_subsys.su_group.cg_item.ci_namebuf, name, strlen(name)); + subsys->su_group = ufscfg_subsys.su_group;
configfs_subsystemcannot sharesu_groupwith otherconfigfs_subsystemi.e you are not allowing for there being more than 1 hbaAgree. I think I will have to move above
declarations(ufscfg_subsys/ufscfg_type/ufshcd_attrs)in driver .c/.h file (to make it per ufs hba/probe).
Will check and update.Quoted 75 lines
Quoted 75 lines
+
config_group_init(&subsys->su_group);
+mutex_init(&subsys->su_mutex);
+ ret =configfs_register_subsystem(subsys);
+ if (ret)
+ pr_err("Error %d while registering subsystem %s\n", + ret,
+subsys->su_group.cg_item.ci_namebuf);drivers/scsi/ufs/ufs-configfs.c new file +6
-0+} + +void ufshcd_configfs_exit (void ) +{ + configfs_unregister_subsystem(&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +0
-0@@ -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>drivers/scsi/ufs/ufshcd.h +3
-0@@ -515,6 +516,9 @@ struct ufs_hba { struct Scsi_Host *host; struct device *dev; +#ifdef CONFIG_UFS_PROVISION + struct configfs_subsystem subsys; +#endif /** This field is to keep a reference to "scsi_device" corresponding to * "UFS device" W-LU. @@ -868,6 +872,19 @@ 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);+/* Expose UFS configfs API's */
drivers/scsi/ufs/ufshcd.h +2
-0+#ifndef CONFIG_UFS_PROVISION +static inline void ufshcd_configfs_init(struct ufs_hba *hba, const char*name)
drivers/scsi/ufs/ufshcd.h +10
-0+{ +} +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, enumdesc_idndesc_id,
int*desc_length);
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
Quoted 59 lines · Adrian Hunter
Quoted 58 lines · Sayali Lokhande
Hi Adrian,
Quoted 44 lines · Adrian Hunter
Quoted 39 lines · Sayali Lokhande
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>--- Documentation/ABI/testing/configfs-driver-ufs | 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155 ++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++ 6 files changed, 203 insertions(+), 1 deletion(-)create mode 100644
Documentation/ABI/testing/configfs-driver-ufscreate mode 100644drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provisionYou are using the device name as the config subsystem name, so this is really:
Quoted 1 line
What: /config/*/ufs_provision
Agree. Will update.
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.144.19 maybe
Done.
Quoted 5 lines
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set indevice.
It is only the first config descriptor though isn't it? There is no support for the other 3. Shouldn't we support config descriptors fully?
Quoted 8 lines
Quoted 7 lines
Yes, we should support config descriptors fully. My current implementation only supports config desc (index = 00h).
I m thinking I can add separate "index" field along with "ufs_provision" field and can use this index (instead of hard coding to 0)
to write repectiveconfig_desc. In this way, we should first set the "index" and then read/write to "ufs_provision".
Let me know if you have any concern with this approach ?One file for each config descriptor would seem more normal.
I can make separate file for each config descriptor index(say ufs_provision_0/1/2/3), but still show() and store() api's can remain common. Will try it out and update.
Quoted 82 lines
Quoted 82 lines
Quoted 9 lines
Quoted 8 lines
+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated
+ format specificied as below:specificied -> specified
Done
Quoted 10 lines
Quoted 7 lines
+ 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>This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Agree. Will update to just refer to UFS spec (for
Config_descformat).Quoted 60 lines
Quoted 49 lines
+ > /config/XXXX.ufshc/ufs_provision
drivers/scsi/ufs/Kconfig +10
-0@@ -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 +0
-0@@ -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.odrivers/scsi/ufs/Makefile +1
-0+obj-$(CONFIG_UFS_PROVISION) += ufs-configfs.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.odrivers/scsi/ufs/ufs-configfs.c new file +12
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba (struct config_item *item) +{drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 10 lines
drivers/scsi/ufs/ufs-configfs.c new file +10
-0+ struct config_group *group = to_config_group(item); + struct configfs_subsystem *subsys = to_configfs_subsystem(group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys); + + return subsys ? hba : NULL; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0};Is it really ok to hard-code the descriptor size?
Quoted 3 lines
Quoted 2 lines
I will use
ufshcd_read_desc_length()api for each index as required. Will remove this hard-code.Alternatively, I see there is already
hba->desc_size.conf_desc
hba->desc_size.conf_desc is actually size for index 0. I thought what if desc size various per index. So better to read for each index. What say ?
Quoted 208 lines
Quoted 208 lines
Quoted 67 lines
Quoted 67 lines
drivers/scsi/ufs/ufs-configfs.c new file +44
-0+ int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + int i, ret, curr_len = 0; + struct ufs_hba *hba = config_item_to_hba(item); + + ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, + QUERY_DESC_IDN_CONFIGURATION, 0, 0, desc_buf, &desc_buf_len); + + if (ret) + return ret; + + for (i = 0; i < desc_buf_len; i++) + curr_len += snprintf((buf + curr_len), (PAGE_SIZE - curr_len), + "0x%x ", desc_buf[i]); + + return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, + const char *buf, size_t count) +{ + char *strbuf; + char *strbuf_copy; + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0}; + int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + char *token; + int i, ret, value; + u32 config_desc_lock = 0; + + /* reserve one byte for null termination */ + strbuf = kmalloc(count + 1, GFP_KERNEL); + if (!strbuf) + return -ENOMEM; + + strbuf_copy = strbuf; + strlcpy(strbuf, buf, count + 1); + + /* Just return if bConfigDescrLock is already set */ + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_CONF_DESC_LOCK, 0, 0, &config_desc_lock); + if (ret) + goto out; + + if (config_desc_lock) { + dev_err(hba->dev, "%s: bConfigDescrLock already set to %u,cannot re-provision device!\n",
+__func__,config_desc_lock);
+ ret =-EINVAL;
+ goto out;
+ }drivers/scsi/ufs/ufs-configfs.c new file +17
-0+ + for (i = 0; i < QUERY_DESC_CONFIGURATION_DEF_SIZE; i++) { + token = strsep(&strbuf, " "); + if (!token && i) + break; + + ret = kstrtoint(token, 0, &value); + if (ret) { + dev_err(hba->dev, "%s: kstrtoint failed %d %s\n", + __func__, ret, token); + ret = -EINVAL; + goto out; + } + desc_buf[i] = (u8)value; + } + + /* Write configuration descriptor to provision ufs */Quoted 8 lines
Quoted 5 lines
+ ret = ufshcd_query_descriptor_retry(hba,
UPIU_QUERY_OPCODE_WRITE_DESC, +QUERY_DESC_IDN_CONFIGURATION, 0, 0,desc_buf,&desc_buf_len); +
+ if (!ret)
+ dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Agree. Will update.
Quoted 44 lines
Quoted 44 lines
+
__func__);drivers/scsi/ufs/ufs-configfs.c new file +43
-0+ +out: + kfree(strbuf_copy); + if (ret) + return ret; + return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, + const char *buf, size_t count) +{ + struct ufs_hba *hba = config_item_to_hba(item); + + return ufshcd_desc_configfs_store(hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name = "ufs_provision", + .ca_mode = 0644, + .ca_owner = THIS_MODULE, + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, + NULL, +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + }, + }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name)Quoted 8 lines
drivers/scsi/ufs/ufs-configfs.c line 142
Quoted 6 lines
drivers/scsi/ufs/ufs-configfs.c new file +6
-0+{ + int ret; + struct configfs_subsystem *subsys = &hba->subsys; + + strncpy(ufscfg_subsys.su_group.cg_item.ci_namebuf, name, strlen(name)); + subsys->su_group = ufscfg_subsys.su_group;
configfs_subsystemcannot sharesu_groupwith otherconfigfs_subsystemi.e you are not allowing for there being more than 1 hbaAgree. I think I will have to move above
declarations(ufscfg_subsys/ufscfg_type/ufshcd_attrs)in driver .c/.h file (to make it per ufs hba/probe).
Will check and update.Quoted 75 lines
Quoted 75 lines
+
config_group_init(&subsys->su_group);
+mutex_init(&subsys->su_mutex);
+ ret =configfs_register_subsystem(subsys);
+ if (ret)
+ pr_err("Error %d while registering subsystem %s\n", + ret,
+subsys->su_group.cg_item.ci_namebuf);drivers/scsi/ufs/ufs-configfs.c new file +6
-0+} + +void ufshcd_configfs_exit (void ) +{ + configfs_unregister_subsystem(&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +15
-0@@ -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,9 @@ struct ufs_hba { struct Scsi_Host *host; struct device *dev; +#ifdef CONFIG_UFS_PROVISION + struct configfs_subsystem subsys; +#endif /** This field is to keep a reference to "scsi_device" corresponding to * "UFS device" W-LU. @@ -868,6 +872,19 @@ 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); +/* 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);
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
Quoted 157 lines · Sayali Lokhande
Quoted 60 lines · Adrian Hunter
Quoted 59 lines · Sayali Lokhande
Hi Adrian,
Quoted 44 lines · Adrian Hunter
Quoted 39 lines · Sayali Lokhande
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>---
Documentation/ABI/testing/configfs-driver-ufs| 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155
++++++++++++++++++++++++++
drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++6 files changed, 203 insertions(+), 1 deletion(-)create mode 100644
Documentation/ABI/testing/configfs-driver-ufscreate mode 100644drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provisionYou are using the device name as the config subsystem name, so this is really:
Quoted 1 line
What: /config/*/ufs_provision
Agree. Will update.
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.144.19 maybe
Done.
Quoted 6 lines
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set indevice.
It is only the first config descriptor though isn't it? There is no support
for the other 3. Shouldn't we support config descriptors fully?Quoted 8 lines
Quoted 7 lines
Yes, we should support config descriptors fully. My current implementation only supports config desc (index = 00h).
I m thinking I can add separate "index" field along with "ufs_provision" field and can use this index (instead of hard coding to 0)
to write repectiveconfig_desc. In this way, we should first set the "index" and then read/write to "ufs_provision".
Let me know if you have any concern with this approach ?One file for each config descriptor would seem more normal.
I can make separate file for each config descriptor
index(say ufs_provision_0/1/2/3), but stillshow()andstore()api's can remain common. Will try it out and update.Quoted 84 lines
Quoted 84 lines
Quoted 10 lines
Quoted 9 lines
+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated
+ format specificied as below:specificied -> specified
Done
Quoted 10 lines
Quoted 7 lines
+ 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>This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Agree. Will update to just refer to UFS spec (for
Config_descformat).Quoted 61 lines
Quoted 50 lines
+ > /config/XXXX.ufshc/ufs_provision
drivers/scsi/ufs/Kconfig +0
-0@@ -100,3 +100,13 @@ config SCSI_UFS_QCOMSelect this if you have UFS controller on QCOM chipset. If unsure, say N.
drivers/scsi/ufs/Kconfig +10
-0+ +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 +0
-0@@ -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 +11
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba(struct config_item*item)
drivers/scsi/ufs/ufs-configfs.c new file +1
-0+{drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 10 lines
drivers/scsi/ufs/ufs-configfs.c new file +10
-0+ struct config_group *group = to_config_group(item); + struct configfs_subsystem *subsys = to_configfs_subsystem(group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys); + + return subsys ? hba : NULL; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0};Is it really ok to hard-code the descriptor size?
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
I will use
ufshcd_read_desc_length()api for each index as required. Will remove this hard-code.Alternatively, I see there is already
hba->desc_size.conf_desc
hba->desc_size.conf_descis actually size for index 0. I thought what if desc size various per index.
So better to read for each index. What say ?
Based on the 'B' and 'L' values defined in the spec., all configuration descriptors have the same length.
Quoted 213 lines
Quoted 211 lines
Quoted 211 lines
Quoted 68 lines
Quoted 68 lines
+ int
desc_buf_len=QUERY_DESC_CONFIGURATION_DEF_SIZE; + int i, ret,curr_len= 0;
+ structufs_hba*hba =config_item_to_hba(item);drivers/scsi/ufs/ufs-configfs.c new file +41
-0+ + ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, + QUERY_DESC_IDN_CONFIGURATION, 0, 0, desc_buf, &desc_buf_len); + + if (ret) + return ret; + + for (i = 0; i < desc_buf_len; i++) + curr_len += snprintf((buf + curr_len), (PAGE_SIZE - curr_len), + "0x%x ", desc_buf[i]); + + return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, + const char *buf, size_t count) +{ + char *strbuf; + char *strbuf_copy; + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0}; + int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + char *token; + int i, ret, value; + u32 config_desc_lock = 0; + + /* reserve one byte for null termination */ + strbuf = kmalloc(count + 1, GFP_KERNEL); + if (!strbuf) + return -ENOMEM; + + strbuf_copy = strbuf; + strlcpy(strbuf, buf, count + 1); + + /* Just return if bConfigDescrLock is already set */ + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_CONF_DESC_LOCK, 0, 0, &config_desc_lock); + if (ret) + goto out; + + if (config_desc_lock) { + dev_err(hba->dev, "%s: bConfigDescrLock already set to %u,cannot re-provision device!\n",
+__func__,config_desc_lock);
+ ret =-EINVAL;
+ goto out;
+ }drivers/scsi/ufs/ufs-configfs.c new file +18
-0+ + for (i = 0; i < QUERY_DESC_CONFIGURATION_DEF_SIZE; i++) { + token = strsep(&strbuf, " "); + if (!token && i) + break; + + ret = kstrtoint(token, 0, &value); + if (ret) { + dev_err(hba->dev, "%s: kstrtoint failed %d %s\n", + __func__, ret, token); + ret = -EINVAL; + goto out; + } + desc_buf[i] = (u8)value; + } + + /* Write configuration descriptor to provision ufs */ + ret = ufshcd_query_descriptor_retry(hba,Quoted 8 lines
Quoted 5 lines
UPIU_QUERY_OPCODE_WRITE_DESC,
+QUERY_DESC_IDN_CONFIGURATION, 0, 0,desc_buf,&desc_buf_len); +
+ if (!ret)
+ dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Agree. Will update.
Quoted 45 lines
Quoted 45 lines
+
__func__);drivers/scsi/ufs/ufs-configfs.c new file +44
-0+ +out: + kfree(strbuf_copy); + if (ret) + return ret; + return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, + const char *buf, size_t count) +{ + struct ufs_hba *hba = config_item_to_hba(item); + + return ufshcd_desc_configfs_store(hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name = "ufs_provision", + .ca_mode = 0644, + .ca_owner = THIS_MODULE, + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, + NULL, +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + }, + }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name) +{Quoted 8 lines
Quoted 6 lines
+ int ret;
+ structconfigfs_subsystem*subsys =&hba->subsys; +
+strncpy(ufscfg_subsys.su_group.cg_item.ci_namebuf, name, strlen(name));
+subsys->su_group= ufscfg_subsys.su_group;
configfs_subsystemcannot sharesu_groupwith otherconfigfs_subsystemi.e you are not allowing for there being more than 1 hbaAgree. I think I will have to move above
declarations(ufscfg_subsys/ufscfg_type/ufshcd_attrs)in driver .c/.h file (to make it per ufs hba/probe).
Will check and update.Quoted 76 lines
Quoted 76 lines
+
config_group_init(&subsys->su_group);
+mutex_init(&subsys->su_mutex);
+ ret =configfs_register_subsystem(subsys);
+ if (ret)
+ pr_err("Error %d while registering subsystem %s\n", + ret,
+subsys->su_group.cg_item.ci_namebuf);drivers/scsi/ufs/ufs-configfs.c new file +6
-0+} + +void ufshcd_configfs_exit (void ) +{ + configfs_unregister_subsystem(&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +0
-0@@ -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>drivers/scsi/ufs/ufshcd.h +3
-0@@ -515,6 +516,9 @@ struct ufs_hba { struct Scsi_Host *host; struct device *dev; +#ifdef CONFIG_UFS_PROVISION + struct configfs_subsystem subsys; +#endif /** This field is to keep a reference to "scsi_device" corresponding to
* "UFS device" W-LU.drivers/scsi/ufs/ufshcd.h +0
-0@@ -868,6 +872,19 @@ 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);+/* Expose UFS configfs API's */
drivers/scsi/ufs/ufshcd.h +2
-0+#ifndef CONFIG_UFS_PROVISION +static inline void ufshcd_configfs_init(struct ufs_hba *hba, const char*name)
drivers/scsi/ufs/ufshcd.h +10
-0+{ +} +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, enumdesc_idndesc_id,
int*desc_length);
Re: [PATCH V10 2/2] scsi: ufs: Add configfs support for UFS provisioning
Quoted 157 lines · Adrian Hunter
Quoted 156 lines · Sayali Lokhande
Quoted 60 lines · Adrian Hunter
Quoted 59 lines · Sayali Lokhande
Hi Adrian,
Quoted 44 lines · Adrian Hunter
Quoted 39 lines · Sayali Lokhande
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_FSneeds to be enabled for using this feature.Usage:
1) To read current configuration descriptor :
cat /config/XXXX.ufshc/ufs_provision
2) To provision ufs device:
echo <config_desc_buf> > /config/XXXX.ufshc/ufs_provisionSigned-off-by Sayali Lokhande <[email protected]>--- Documentation/ABI/testing/configfs-driver-ufs | 18 +++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 155 ++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 3 +- drivers/scsi/ufs/ufshcd.h | 17 +++ 6 files changed, 203 insertions(+), 1 deletion(-)create mode 100644
Documentation/ABI/testing/configfs-driver-ufscreate mode 100644drivers/scsi/ufs/ufs-configfs.cDocumentation/ABI/testing/configfs-driver-ufs new file +0
-0Documentation/ABI/testing/configfs-driver-ufs line 1
Quoted 1 line
Documentation/ABI/testing/configfs-driver-ufs new file +1
-0@@ -0,0 +1,18 @@ +What: /config/ufshcd/ufs_provisionYou are using the device name as the config subsystem name, so this is really:
Quoted 1 line
What: /config/*/ufs_provision
Agree. Will update.
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs line 3
Quoted 2 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Date: Jun 2018 +KernelVersion: 4.144.19 maybe
Done.
Quoted 6 lines
Quoted 3 lines
Documentation/ABI/testing/configfs-driver-ufs new file +2
-0+Description: + This file shows the current ufs configuration descriptor set indevice.
It is only the first config descriptor though isn't it? There is no support
for the other 3. Shouldn't we support config descriptors fully?Quoted 8 lines
Quoted 7 lines
Yes, we should support config descriptors fully. My current implementation only supports config desc (index = 00h).
I m thinking I can add separate "index" field along with "ufs_provision" field and can use this index (instead of hard coding to 0)
to write repectiveconfig_desc. In this way, we should first set the "index" and then read/write to "ufs_provision".
Let me know if you have any concern with this approach ?One file for each config descriptor would seem more normal.
I can make separate file for each config descriptor
index(say ufs_provision_0/1/2/3), but stillshow()andstore()api's can remain common. Will try it out and update.Quoted 84 lines
Quoted 84 lines
Quoted 10 lines
Quoted 9 lines
+ 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 of each configuration descriptor parameter. + Configuration descriptor buffer needs to be passed in space separated
+ format specificied as below:specificied -> specified
Done
Quoted 10 lines
Quoted 7 lines
+ 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>This format is not exactly correct anymore because each byte has to be represented separately. Also theoretically it can be change, so maybe better just to refer the user to the UFS specification.
Agree. Will update to just refer to UFS spec (for
Config_descformat).Quoted 61 lines
Quoted 50 lines
+ > /config/XXXX.ufshc/ufs_provision
drivers/scsi/ufs/Kconfig +10
-0@@ -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 +0
-0@@ -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.odrivers/scsi/ufs/Makefile +1
-0+obj-$(CONFIG_UFS_PROVISION) += ufs-configfs.o obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.odrivers/scsi/ufs/ufs-configfs.c new file +11
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0+ +// Copyright (c) 2018, Linux Foundation. + +#include <linux/configfs.h> +#include <linux/err.h> +#include <linux/string.h> + +#include "ufs.h" +#include "ufshcd.h" + +static inline struct ufs_hba *config_item_to_hba(struct config_item*item)
drivers/scsi/ufs/ufs-configfs.c new file +1
-0+{drivers/scsi/ufs/ufs-configfs.c line 22
Quoted 10 lines
drivers/scsi/ufs/ufs-configfs.c new file +10
-0+ struct config_group *group = to_config_group(item); + struct configfs_subsystem *subsys = to_configfs_subsystem(group); + struct ufs_hba *hba = container_of(subsys, struct ufs_hba, subsys); + + return subsys ? hba : NULL; +} + +static ssize_t ufs_provision_show (struct config_item *item,char *buf) +{ + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0};Is it really ok to hard-code the descriptor size?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
I will use
ufshcd_read_desc_length()api for each index as required. Will remove this hard-code.Alternatively, I see there is already
hba->desc_size.conf_desc
hba->desc_size.conf_descis actually size for index 0. I thought what if desc size various per index.
So better to read for each index. What say ?Based on the 'B' and 'L' values defined in the spec., all configuration descriptors have the same length.
Ok. Got it. Then I will just use "hba->desc_size.conf_desc" as desc length.
Quoted 210 lines
Quoted 210 lines
Quoted 209 lines
Quoted 209 lines
Quoted 67 lines
Quoted 67 lines
+ int
desc_buf_len=QUERY_DESC_CONFIGURATION_DEF_SIZE; + int i, ret,curr_len= 0;
+ structufs_hba*hba =config_item_to_hba(item);drivers/scsi/ufs/ufs-configfs.c new file +41
-0+ + ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_READ_DESC, + QUERY_DESC_IDN_CONFIGURATION, 0, 0, desc_buf, &desc_buf_len); + + if (ret) + return ret; + + for (i = 0; i < desc_buf_len; i++) + curr_len += snprintf((buf + curr_len), (PAGE_SIZE - curr_len), + "0x%x ", desc_buf[i]); + + return curr_len; +} + +ssize_t ufshcd_desc_configfs_store (struct ufs_hba *hba, + const char *buf, size_t count) +{ + char *strbuf; + char *strbuf_copy; + u8 desc_buf[QUERY_DESC_CONFIGURATION_DEF_SIZE] = {0}; + int desc_buf_len = QUERY_DESC_CONFIGURATION_DEF_SIZE; + char *token; + int i, ret, value; + u32 config_desc_lock = 0; + + /* reserve one byte for null termination */ + strbuf = kmalloc(count + 1, GFP_KERNEL); + if (!strbuf) + return -ENOMEM; + + strbuf_copy = strbuf; + strlcpy(strbuf, buf, count + 1); + + /* Just return if bConfigDescrLock is already set */ + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_CONF_DESC_LOCK, 0, 0, &config_desc_lock); + if (ret) + goto out; + + if (config_desc_lock) { + dev_err(hba->dev, "%s: bConfigDescrLock already set to %u,cannot re-provision device!\n",
+__func__,config_desc_lock);
+ ret =-EINVAL;
+ goto out;
+ }drivers/scsi/ufs/ufs-configfs.c new file +18
-0+ + for (i = 0; i < QUERY_DESC_CONFIGURATION_DEF_SIZE; i++) { + token = strsep(&strbuf, " "); + if (!token && i) + break; + + ret = kstrtoint(token, 0, &value); + if (ret) { + dev_err(hba->dev, "%s: kstrtoint failed %d %s\n", + __func__, ret, token); + ret = -EINVAL; + goto out; + } + desc_buf[i] = (u8)value; + } + + /* Write configuration descriptor to provision ufs */ + ret = ufshcd_query_descriptor_retry(hba,Quoted 8 lines
Quoted 5 lines
UPIU_QUERY_OPCODE_WRITE_DESC,
+QUERY_DESC_IDN_CONFIGURATION, 0, 0,desc_buf,&desc_buf_len); +
+ if (!ret)
+ dev_info(hba->dev, "%s: UFS Provisioning done, reboot now!\n",That is not necessarily true - bConfDescContinue might have been used or bConfigDescrLock might need to be set. Better just to say that configuration descriptor 0 was written.
Agree. Will update.
Quoted 45 lines
Quoted 45 lines
+
__func__);drivers/scsi/ufs/ufs-configfs.c new file +44
-0+ +out: + kfree(strbuf_copy); + if (ret) + return ret; + return count; +} + +static ssize_t ufs_provision_store (struct config_item *item, + const char *buf, size_t count) +{ + struct ufs_hba *hba = config_item_to_hba(item); + + return ufshcd_desc_configfs_store(hba, buf, count); +} + +static struct configfs_attribute ufshcd_attr_provision = { + .ca_name = "ufs_provision", + .ca_mode = 0644, + .ca_owner = THIS_MODULE, + .show = ufs_provision_show, + .store = ufs_provision_store, +}; + +static struct configfs_attribute *ufshcd_attrs[] = { + &ufshcd_attr_provision, + NULL, +}; + +static struct config_item_type ufscfg_type = { + .ct_attrs = ufshcd_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem ufscfg_subsys = { + .su_group = { + .cg_item = { + .ci_type = &ufscfg_type, + }, + }, +}; + +void ufshcd_configfs_init (struct ufs_hba *hba,const char *name) +{Quoted 8 lines
Quoted 6 lines
+ int ret;
+ structconfigfs_subsystem*subsys =&hba->subsys; +
+strncpy(ufscfg_subsys.su_group.cg_item.ci_namebuf, name, strlen(name));
+subsys->su_group= ufscfg_subsys.su_group;
configfs_subsystemcannot sharesu_groupwith otherconfigfs_subsystemi.e you are not allowing for there being more than 1 hbaAgree. I think I will have to move above
declarations(ufscfg_subsys/ufscfg_type/ufshcd_attrs)in driver .c/.h file (to make it per ufs hba/probe).
Will check and update.Quoted 76 lines
Quoted 76 lines
+
config_group_init(&subsys->su_group);
+mutex_init(&subsys->su_mutex);
+ ret =configfs_register_subsystem(subsys);
+ if (ret)
+ pr_err("Error %d while registering subsystem %s\n", + ret,
+subsys->su_group.cg_item.ci_namebuf);drivers/scsi/ufs/ufs-configfs.c new file +6
-0+} + +void ufshcd_configfs_exit (void ) +{ + configfs_unregister_subsystem(&ufscfg_subsys); +}drivers/scsi/ufs/ufshcd.c +2
-1@@ -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 +3
-0@@ -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,9 @@ struct ufs_hba { struct Scsi_Host *host; struct device *dev; +#ifdef CONFIG_UFS_PROVISION + struct configfs_subsystem subsys; +#endif /** This field is to keep a reference to "scsi_device" corresponding to
* "UFS device" W-LU.drivers/scsi/ufs/ufshcd.h +12
-0@@ -868,6 +872,19 @@ 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); +/* 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);