Skip to contentSkip to conversation

scsi: ufs: set the device reference clock setting

RFC PATCH In review Sayali Lokhande 2 participants 5 messages May 22, 2018 – May 25, 2018 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#1 lore raw

RFC PATCH 1/3 scsi: ufs: set the device reference clock setting

In reply to a message not in the archive

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.

---
 .../devicetree/bindings/ufs/ufshcd-pltfrm.txt      |  8 +++
 drivers/scsi/ufs/ufs.h                             |  9 ++++
 drivers/scsi/ufs/ufshcd-pltfrm.c                   | 20 ++++++++
 drivers/scsi/ufs/ufshcd.c                          | 60 ++++++++++++++++++++++
 drivers/scsi/ufs/ufshcd.h                          |  2 +
 5 files changed, 99 insertions(+)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +8 -0
index c39dfef..ac94220 100644
@@ -41,6 +41,12 @@ Optional properties:
 -lanes-per-direction	: number of lanes available per direction - either 1 or 2.
 			  Note that it is assume same number of lanes is used both
 			  directions at once. If not specified, default is 2 lanes per direction.
+- dev-ref-clk-freq	: Specify the device reference clock frequency, must be one of the following:
+			  0: 19.2 MHz
+			  1: 26 MHz
+			  2: 38.4 MHz
+			  3: 52 MHz
+			  Defaults to 26 MHz if not specified.
 
 Note: If above properties are not defined it can be assumed that the supply
 regulators or clocks are always on.
@@ -66,4 +72,6 @@ Example:
 		freq-table-hz = <100000000 200000000>, <0 0>, <0 0>;
 		phys = <&ufsphy1>;
 		phy-names = "ufsphy";
+		dev-ref-clk-freq = <0>; /* reference clock freq: 19.2 MHz */
 	};
+
drivers/scsi/ufs/ufs.h +9 -0
index 14e5bf7..e15deb0 100644
@@ -378,6 +378,15 @@ enum query_opcode {
 	UPIU_QUERY_OPCODE_TOGGLE_FLAG	= 0x8,
 };
 
+/* bRefClkFreq attribute values */
+enum ref_clk_freq {
+	REF_CLK_FREQ_19_2_MHZ	= 0x0,
+	REF_CLK_FREQ_26_MHZ	= 0x1,
+	REF_CLK_FREQ_38_4_MHZ	= 0x2,
+	REF_CLK_FREQ_52_MHZ	= 0x3,
+	REF_CLK_FREQ_MAX	= REF_CLK_FREQ_52_MHZ,
+};
+
 /* Query response result code */
 enum {
 	QUERY_RESULT_SUCCESS                    = 0x00,
drivers/scsi/ufs/ufshcd-pltfrm.c +20 -0
index e82bde0..b70838b 100644
@@ -221,6 +221,24 @@ static int ufshcd_parse_regulator_info(struct ufs_hba *hba)
 	return err;
 }
 
+static void ufshcd_parse_dev_ref_clk_freq(struct ufs_hba *hba)
+{
+	struct device *dev = hba->dev;
+	struct device_node *np = dev->of_node;
+	int ret;
+
+	if (!np)
+		return;
+
+	ret = of_property_read_u32(np, "dev-ref-clk-freq",
+				   &hba->dev_ref_clk_freq);
+	if (ret ||
+	    (hba->dev_ref_clk_freq < 0) ||
+	    (hba->dev_ref_clk_freq > REF_CLK_FREQ_52_MHZ))
+		/* default setting */
+		hba->dev_ref_clk_freq = REF_CLK_FREQ_26_MHZ;
+}
+
 #ifdef CONFIG_PM
 /**
  * ufshcd_pltfrm_suspend - suspend power management function
@@ -343,6 +361,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 +60 -0

72 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.h +2 -0
index 8110dcd..0dcf113 100644
@@ -549,6 +549,8 @@ struct ufs_hba {
 	unsigned int irq;
 	bool is_irq_enabled;
 
+	u32 dev_ref_clk_freq;
+
 	/* Interrupt aggregation support is broken */
 	#define UFSHCD_QUIRK_BROKEN_INTR_AGGR			0x1
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#4 lore raw

RFC PATCH 2/3 scsi: ufs: Add ufs provisioning support

In reply to a message not in the archive

A new api ufshcd_do_config_device() is added in driver to suppoet UFS provisioning at runtime. Sysfs support is added to trigger provisioning.
Device configuration descriptors or parameters are parsed from vendor specific provisioning data and passed via sysfs at runtime to provision ufs device.

---
 drivers/scsi/ufs/ufs.h    |  28 +++++++
 drivers/scsi/ufs/ufshcd.c | 200 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufshcd.h |   1 +
 3 files changed, 229 insertions(+)
drivers/scsi/ufs/ufs.h +28 -0
index e15deb0..1f99904 100644
@@ -333,6 +333,7 @@ enum {
 	UFSHCD_AMP		= 3,
 };
 
+#define UFS_BLOCK_SIZE	4096
 #define POWER_DESC_MAX_SIZE			0x62
 #define POWER_DESC_MAX_ACTV_ICC_LVLS		16
 
@@ -425,6 +426,33 @@ enum {
 	MASK_TM_SERVICE_RESP		= 0xFF,
 };
 
+struct ufs_unit_desc {
+	u8     bLUEnable;              /* 1 for enabled LU */
+	u8     bBootLunID;             /* 0 for using this LU for boot */
+	u8     bLUWriteProtect;        /* 1 = power on WP, 2 = permanent WP */
+	u8     bMemoryType;            /* 0 for enhanced memory type */
+	u32    dNumAllocUnits;         /* Number of alloc unit for this LU */
+	u8     bDataReliability;       /* 0 for reliable write support */
+	u8     bLogicalBlockSize;      /* See section 13.2.3 of UFS standard */
+	u8     bProvisioningType;      /* 0 for thin provisioning */
+	u16    wContextCapabilities;   /* refer Unit Descriptor Description */
+};
+
+struct ufs_config_descr {
+	u8     bNumberLU;              /* Total number of active LUs */
+	u8     bBootEnable;            /* enabling device for partial init */
+	u8     bDescrAccessEn;         /* desc access during partial init */
+	u8     bInitPowerMode;         /* Initial device power mode */
+	u8     bHighPriorityLUN;       /* LUN of the high priority LU */
+	u8     bSecureRemovalType;     /* Erase config for data removal */
+	u8     bInitActiveICCLevel;    /* ICC level after reset */
+	u16    wPeriodicRTCUpdate;     /* 0 to set a priodic RTC update rate */
+	u32     bConfigDescrLock;      /* 1 to lock Configation Descriptor */
+	u32    qVendorConfigCode;      /* Vendor specific configuration code */
+	struct ufs_unit_desc unit[8];
+	u8	lun_to_grow;
+};
+
 /* Task management service response */
 enum {
 	UPIU_TASK_MANAGEMENT_FUNC_COMPL		= 0x00,
drivers/scsi/ufs/ufshcd.c +200 -0

218 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.h +1 -0
index 0dcf113..0c4b683 100644
@@ -550,6 +550,7 @@ struct ufs_hba {
 	bool is_irq_enabled;
 
 	u32 dev_ref_clk_freq;
+	struct ufs_config_descr cfgs;
 
 	/* Interrupt aggregation support is broken */
 	#define UFSHCD_QUIRK_BROKEN_INTR_AGGR			0x1
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#5 lore raw

RFC PATCH 3/3 scsi: ufs: Add sysfs support for ufs provision

In reply to a message not in the archive

Add sysfs support to trigger ufs provisioning at runtime. Usage :
echo <desc_buf> > /sys/bus/platform/devices/1d84000.ufshcd/ufs_provision To check provisioning status:
cat /sys/bus/platform/devices/1d84000.ufshc/ufs_provision
1 -> Success (Reboot device to check updated provisioning)

---
 drivers/scsi/ufs/ufs.h    |   2 +
 drivers/scsi/ufs/ufshcd.c | 125 +++++++++++++++++++++++++++++++++++++++++++++-
 drivers/scsi/ufs/ufshcd.h |   6 +++
 3 files changed, 132 insertions(+), 1 deletion(-)
drivers/scsi/ufs/ufs.h +2 -0
index 1f99904..0b497fc 100644
@@ -427,6 +427,7 @@ enum {
 };
 
 struct ufs_unit_desc {
+	u8	   LUNum;
 	u8     bLUEnable;              /* 1 for enabled LU */
 	u8     bBootLunID;             /* 0 for using this LU for boot */
 	u8     bLUWriteProtect;        /* 1 = power on WP, 2 = permanent WP */
@@ -451,6 +452,7 @@ struct ufs_config_descr {
 	u32    qVendorConfigCode;      /* Vendor specific configuration code */
 	struct ufs_unit_desc unit[8];
 	u8	lun_to_grow;
+	u8 num_luns;
 };
 
 /* Task management service response */
drivers/scsi/ufs/ufshcd.c +124 -1

167 lines not on this page · raw message

drivers/scsi/ufs/ufshcd.h +6 -0
index 0c4b683..3580631 100644
@@ -364,6 +364,11 @@ struct ufs_clk_gating {
 	int active_reqs;
 };
 
+struct ufs_provisioning {
+	struct device_attribute enable_attr;
+	bool is_enabled;
+};
+
 struct ufs_saved_pwr_info {
 	struct ufs_pa_layer_attr info;
 	bool is_valid;
@@ -652,6 +657,7 @@ struct ufs_hba {
 	struct ufs_pwr_mode_info max_pwr_info;
 
 	struct ufs_clk_gating clk_gating;
+	struct ufs_provisioning ufs_provision;
 	/* Control to enable/disable host capabilities */
 	u32 caps;
 	/* Allow dynamic clk gating */
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#2 lore raw
In reply to Sayali Lokhande
Quoted 25 lines · Sayali Lokhande

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.

---
 .../devicetree/bindings/ufs/ufshcd-pltfrm.txt      |  8 +++
 drivers/scsi/ufs/ufs.h                             |  9 ++++
 drivers/scsi/ufs/ufshcd-pltfrm.c                   | 20 ++++++++
 drivers/scsi/ufs/ufshcd.c                          | 60 ++++++++++++++++++++++
 drivers/scsi/ufs/ufshcd.h                          |  2 +
 5 files changed, 99 insertions(+)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +0 -0
index c39dfef..ac94220 100644

Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt Optional properties: · line 49

Quoted 9 lines
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +6 -0
@@ -41,6 +41,12 @@ Optional properties:
 -lanes-per-direction	: number of lanes available per direction - either 1 or 2.
 			  Note that it is assume same number of lanes is used both
 			  directions at once. If not specified, default is 2 lanes per direction.
+- dev-ref-clk-freq	: Specify the device reference clock frequency, must be one of the following:
+			  0: 19.2 MHz
+			  1: 26 MHz
+			  2: 38.4 MHz
+			  3: 52 MHz
+			  Defaults to 26 MHz if not specified.

You already have "ref_clk", can't you just read its frequency?

Rob

author
#3 lore raw

Hi Rob,

For UFS provisioning, all we need is ref_clk to be set to 19.2MHz before actual descriptor write happens.
So I can actually avoid parsing it via DT and use REF_CLK_FREQ_19_2_MHZ from enum ref_clk_freq (which is already added in my current implementation).

Thanks,
Sayali
-----Original Message-----
From: Rob Herring [mailto:[email protected]]
Sent: Thursday, May 24, 2018 12:19 AM
To: Sayali Lokhande <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Mark Rutland <[email protected]>; Mathieu Malaterre <[email protected]>; open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS <[email protected]>; open list <[email protected]>
Subject: Re: [PATCH RFC 1/3] scsi: ufs: set the device reference clock setting

Quoted 13 lines · Sayali Lokhande

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.

Quoted 5 lines
---
 .../devicetree/bindings/ufs/ufshcd-pltfrm.txt      |  8 +++
 drivers/scsi/ufs/ufs.h                             |  9 ++++
 drivers/scsi/ufs/ufshcd-pltfrm.c                   | 20 ++++++++
 drivers/scsi/ufs/ufshcd.c                          | 60

++++++++++++++++++++++

Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt Optional properties: · line 41

Quoted 10 lines
 drivers/scsi/ufs/ufshcd.h                          |  2 +
 5 files changed, 99 insertions(+)
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +0 -0
index c39dfef..ac94220 100644
@@ -41,6 +41,12 @@ Optional properties:
 -lanes-per-direction	: number of lanes available per direction - either 1

or 2.

Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt Optional properties: · line 42

Quoted 1 line
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +0 -0
 			  Note that it is assume same number of lanes is

used both

Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt Optional properties: · line 43

Quoted 1 line
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +0 -0
 			  directions at once. If not specified, default is 2

lanes per direction.

Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt Optional properties: · line 44

Quoted 1 line
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +1 -0
+- dev-ref-clk-freq	: Specify the device reference clock frequency, must

be one of the following:

Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt Optional properties: · line 49

Quoted 5 lines
Documentation/devicetree/bindings/ufs/ufshcd-pltfrm.txt +5 -0
+			  0: 19.2 MHz
+			  1: 26 MHz
+			  2: 38.4 MHz
+			  3: 52 MHz
+			  Defaults to 26 MHz if not specified.

You already have "ref_clk", can't you just read its frequency?

Rob