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. Changes since V13: 1)scsi: ufs: set the device reference clock setting Removed extra comment. 2)scsi: ufs: Add configfs support for UFS provisioning Used snprintf for limiting configfs item name length to 20 and thus avoid overrun. Changes since V12: 1)scsi: ufs: set the device reference clock setting No update. 2)scsi: ufs: Add configfs support for UFS provisioning Minor fixes related to return statement, updated indentation as per checkpatch script and added logic to first read config descriptor before updating with user provied buffer so that old configuration can be retained in case user buffer length is less than expected config descriptor length. Changes since V11: 1)scsi: ufs: set the device reference clock setting No update. 2)scsi: ufs: Add configfs support for UFS provisioning Minor fixes related to missing kfree(), return statement and indentation. Changes since V10: 1)scsi: ufs: set the device reference clock setting No update. 2)scsi: ufs: Add configfs support for UFS provisioning Added support for all config descriptors (namely with index 0,1,2,3). Updated config descriptor length to reflect actual length of each descriptor instead of hard coded macro. Updated documentation as per new added fields (for each config descriptor). Added support for multiple ufs hba's. Changes since V9: 1)scsi: ufs: set the device reference clock setting Minor fixes related to naming format, if check conditions. 2)scsi: ufs: Add configfs support for UFS provisioning Minor fixes related to naming format, function return type. Changes since V8: 1)scsi: ufs: set the device reference clock setting Updated one common enum for both ref_clk_freq in Hz and bref_attr and used same in parsing api. Moved call to parse api to ufshcd_alloc_host() instead of calling from pltfrm_init(), so that it can be called via other paths(which dont use pltfrm_init) and hba->dev_ref_clk can get intialized to either valid/invalid value. 2)scsi: ufs: Add configfs support for UFS provisioning Updated error returns and removed few unnecessary sanity check as per comments. Changes since V7: 1)scsi: ufs: set the device reference clock setting Updated return statements and condition checks as per comments. Added struct ufs_ref_clk_freqs which holds both bref_clk_attr val and respective ref clk frequency in Hz and used same while parsing ref_clk. 2)scsi: ufs: Add configfs support for UFS provisioning Updated return statements and conditional check as per comments. Changes since V6: 1)scsi: ufs: set the device reference clock setting Re-introduced this patch to provisioning patch set(as per comments from Evan). Used of_clk_get_by_name() and clk_get_rate() to set ref_clk frequency instead of passing freq via DT. 2)scsi: ufs: Add configfs support for UFS provisioning Updated error handling in case if kstrtoint fails while parsing input configuration buffer. Changes since V5: 1)scsi: ufs: set the device reference clock setting Removed this patch from provisioning patch set(as its not required to be set as dependent changes). This will be uploaded as a separate patch later. 2)scsi: ufs: Add configfs support for UFS provisioning Removed few extra debug prints. Updated permission of ufs_provision attribute from 0666 to 0644. Pass UFS device name as part of ufshcd_configfs_init() to support multiple UFS controller for embedded and removable UFS card. Changes since V4: 1)scsi: ufs: set the device reference clock setting Used "assigned-clock-rates" DT property to pass required ref clk frequency. 2)scsi: ufs: Add configfs support for ufs provisioning Combined previous patch(2) and patch(3) into single patch which adds configfs provisioning support in driver. Removed extra sw provisioning related fields (like lun_to_grow, commit) and its related code. Updated Documentation to match configuration descriptor buffer parameters to be passed as per specs. Removed global ufs_hba ptr added in ufs-configfs file and instead passed *hba in ufs configfs init()/store()/show() api's. This is to support embedded as well as removable ufs card provisioning via configfs. Changes since V3: 1)scsi: ufs: set the device reference clock setting Updated logic to retain default ref_clk frequency setting programmed in device in case if invalid value is passed via devicetree setting. Replaced of_property_read_u32() with device_property_read_u32(). Removed invalid checks. 2)scsi: ufs: Add ufs provisioning support Added pm_runtime_get/put_sync and scsi_block/unblock_request in runtime provisioning for stable operation. 3)scsi: ufs: Add configfs support for ufs provisioning Updated Documentation with missing buffer entries required for runtime provisioning. Used config option to support conditional compilation for configfs api's. Changes since V2: Added configfs support for ufs provisioning and removed sysfs support. Changes since V1: Added device tree entry to parse reference clock frequency instead of hardcoding 19.2 MHz, as it can vary for different vendors. Also removed setting ref_clk again during runtime provisioning as it will be already set during probe. Used get_unaligned_be*/put_unaligned_be* where applicable. Changes since RFC: Added check to avoid ufs runtime provisioning if Configuration decriptor lock attribute is set to one. Instead of parsing ref_clk frequency via device tree, used correct enum ref_clk_freq value(19.2 Mhz for proviosioning). Added config_descriptor sysfs entry to provision ufs and also updated documentation for its correct usage. Added more protection against bad data handling in sysfs code. Sayali Lokhande (1): scsi: ufs: Add configfs support for UFS provisioning Subhash Jadavani (1): scsi: ufs: set the device reference clock setting Documentation/ABI/testing/configfs-driver-ufs | 12 ++ drivers/scsi/ufs/Kconfig | 10 ++ drivers/scsi/ufs/Makefile | 1 + drivers/scsi/ufs/ufs-configfs.c | 237 ++++++++++++++++++++++++++ drivers/scsi/ufs/ufs.h | 14 ++ drivers/scsi/ufs/ufshcd-pltfrm.c | 2 + drivers/scsi/ufs/ufshcd.c | 90 +++++++++- drivers/scsi/ufs/ufshcd.h | 20 +++ 8 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/configfs-driver-ufs create mode 100644 drivers/scsi/ufs/ufs-configfs.c -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project