From: Evan Green <evgreen@chromium.org>
To: Vinayak Holikatti <vinholikatti@gmail.com>,
"James E.J. Bottomley" <jejb@linux.vnet.ibm.com>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Stanislav Nijnikov <stanislav.nijnikov@wdc.com>,
linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org
Cc: Gwendal Grignou <gwendal@chromium.org>,
Evan Green <evgreen@chromium.org>
Subject: [PATCH 6/7] scsi: ufs: Enable writing config descriptor
Date: Tue, 29 May 2018 11:17:39 -0700 [thread overview]
Message-ID: <20180529181740.195362-7-evgreen@chromium.org> (raw)
In-Reply-To: <20180529181740.195362-1-evgreen@chromium.org>
This change enables writing to fields of the config descriptor
via sysfs. It can be used to provision an unprovisioned UFS
device, or reprovision an unlocked device.
Signed-off-by: Evan Green <evgreen@chromium.org>
---
drivers/scsi/ufs/ufs-sysfs.c | 64 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 61 insertions(+), 3 deletions(-)
diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c
index 623c56074572..54e9f3bca9db 100644
--- a/drivers/scsi/ufs/ufs-sysfs.c
+++ b/drivers/scsi/ufs/ufs-sysfs.c
@@ -252,6 +252,31 @@ static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
return ret;
}
+static ssize_t ufs_sysfs_write_desc_param(struct ufs_hba *hba,
+ enum desc_idn desc_id,
+ u8 desc_index,
+ u8 param_offset,
+ const char *buf,
+ ssize_t buf_size,
+ u8 width)
+{
+ int ret;
+ unsigned long long value;
+
+ if (kstrtoull(buf, 0, &value))
+ return -EINVAL;
+
+ /* Convert to big endian, and send only the appropriate width. */
+ value = cpu_to_be64(value);
+ ret = ufshcd_rw_desc_param(hba, UPIU_QUERY_OPCODE_WRITE_DESC, desc_id,
+ desc_index, param_offset,
+ (u8 *)&value + 8 - width, width);
+ if (ret)
+ return -EINVAL;
+
+ return buf_size;
+}
+
#define UFS_DESC_PARAM(_name, _puname, _duname, _size) \
static ssize_t _name##_show(struct device *dev, \
struct device_attribute *attr, char *buf) \
@@ -357,8 +382,25 @@ static ssize_t cfg_unit_store(struct device *dev,
return count;
}
-#define UFS_CONFIG_DESC_PARAM(_name, _uname, _size) \
- UFS_DESC_PARAM(cfg_##_name, _uname, CONFIGURATION, _size)
+#define UFS_CONFIG_DESC_PARAM(_name, _puname, _size) \
+static ssize_t cfg_##_name##_show(struct device *dev, \
+ struct device_attribute *attr, char *buf) \
+{ \
+ struct ufs_hba *hba = dev_get_drvdata(dev); \
+ return ufs_sysfs_read_desc_param(hba, \
+ QUERY_DESC_IDN_CONFIGURATION, 0, \
+ CONFIGURATION_DESC_PARAM##_puname, buf, _size); \
+} \
+static ssize_t cfg_##_name##_store(struct device *dev, \
+ struct device_attribute *attr, const char *buf, \
+ size_t count) \
+{ \
+ struct ufs_hba *hba = dev_get_drvdata(dev); \
+ return ufs_sysfs_write_desc_param(hba, \
+ QUERY_DESC_IDN_CONFIGURATION, 0, \
+ CONFIGURATION_DESC_PARAM##_puname, buf, count, _size); \
+} \
+static DEVICE_ATTR_RW(cfg_##_name)
#define UFS_CONFIG_UNIT_DESC_PARAM(_name, _uname, _size) \
static ssize_t unit_##_name##_show(struct device *dev, \
@@ -375,7 +417,23 @@ static ssize_t unit_##_name##_show(struct device *dev, \
return ufs_sysfs_read_desc_param(hba, \
QUERY_DESC_IDN_CONFIGURATION, 0, offset, buf, _size); \
} \
-static DEVICE_ATTR_RO(unit_##_name)
+static ssize_t unit_##_name##_store(struct device *dev, \
+ struct device_attribute *attr, const char *buf, \
+ size_t count) \
+{ \
+ struct ufs_hba *hba = dev_get_drvdata(dev); \
+ size_t offset = CONFIGURATION_DESC_PARAM_UNIT0 + \
+ (hba->sysfs_config_unit * \
+ CONFIGURATION_UNIT_DESC_SIZE) + \
+ CONFIGURATION_UNIT_DESC_PARAM_##_uname; \
+ if (offset + _size > hba->desc_size.conf_desc) { \
+ return -EINVAL; \
+ } \
+ return ufs_sysfs_write_desc_param(hba, \
+ QUERY_DESC_IDN_CONFIGURATION, 0, offset, buf, count, \
+ _size); \
+} \
+static DEVICE_ATTR_RW(unit_##_name)
UFS_CONFIG_DESC_PARAM(number_of_luns, _NUM_LU, 1);
UFS_CONFIG_DESC_PARAM(boot_enable, _BOOT_ENBL, 1);
--
2.13.5
next prev parent reply other threads:[~2018-05-29 18:17 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-29 18:17 [PATCH 0/7] Enable UFS provisioning via Linux Evan Green
2018-05-29 18:17 ` [PATCH 1/7] scsi: ufs: Add Configuration Descriptor to sysfs Evan Green
2018-06-04 8:31 ` Bart Van Assche
2018-06-04 15:39 ` Evan Green
2018-05-29 18:17 ` [PATCH 2/7] scsi: ufs: Add config descriptor documentation Evan Green
2018-06-04 8:34 ` Bart Van Assche
2018-06-04 15:39 ` Evan Green
2018-05-29 18:17 ` [PATCH 3/7] scsi: ufs: Make sysfs attributes writable Evan Green
2018-06-04 8:33 ` Bart Van Assche
2018-06-04 15:39 ` Evan Green
2018-05-29 18:17 ` [PATCH 4/7] scsi: ufs: sysfs: Document attribute writability Evan Green
2018-06-04 8:35 ` Bart Van Assche
2018-06-04 15:39 ` Evan Green
2018-05-29 18:17 ` [PATCH 5/7] scsi: ufs: Refactor descriptor read for write Evan Green
2018-05-30 17:21 ` Evan Green
2018-06-04 8:40 ` Bart Van Assche
2018-06-04 15:40 ` Evan Green
2018-05-29 18:17 ` Evan Green [this message]
2018-06-04 8:46 ` [PATCH 6/7] scsi: ufs: Enable writing config descriptor Bart Van Assche
2018-05-29 18:17 ` [PATCH 7/7] scsi: ufs: Update config descriptor documentation Evan Green
2018-05-31 10:04 ` [PATCH 0/7] Enable UFS provisioning via Linux Stanislav Nijnikov
2018-06-01 14:44 ` Evan Green
2018-06-03 10:21 ` Stanislav Nijnikov
2018-06-04 14:59 ` Evan Green
2018-06-08 12:30 ` Adrian Hunter
2018-06-10 9:31 ` Stanislav Nijnikov
2018-06-12 19:42 ` Evan Green
2018-06-12 20:11 ` Bart Van Assche
2018-06-13 10:12 ` Stanislav Nijnikov
2018-06-15 21:19 ` Evan Green
2018-06-04 11:11 ` Kyuho Choi
2018-06-04 15:03 ` Evan Green
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180529181740.195362-7-evgreen@chromium.org \
--to=evgreen@chromium.org \
--cc=gwendal@chromium.org \
--cc=jejb@linux.vnet.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stanislav.nijnikov@wdc.com \
--cc=vinholikatti@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox