All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arthur Simchaev <Arthur.Simchaev@wdc.com>
To: "James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: alim.akhtar@samsung.com, Bean Huo <beanhuo@micron.com>,
	Arthur Simchaev <Arthur.Simchaev@wdc.com>
Subject: [PATCH v2] scsi: ufs: sysfs: Print string descriptors as raw data
Date: Mon, 15 Feb 2021 19:40:46 +0200	[thread overview]
Message-ID: <1613410846-16883-1-git-send-email-Arthur.Simchaev@wdc.com> (raw)

Currently the string descriptors sysfs entries are printing in ascii
format. According to Jedec UFS spec the string descriptors data is
Unicode and need-not be ascii convertible. Therefore in case the device
string descriptor contains non ascii convertible characters, it will
produce a wrong output. In order to fix this issue, the new
string descriptors entries will added to sysfs directory.
Those entries will show the string descriptors in raw format

Signed-off-by: Arthur Simchaev <Arthur.Simchaev@wdc.com>
---
 Documentation/ABI/testing/sysfs-driver-ufs | 44 ++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufs-sysfs.c               | 34 +++++++++++++++++------
 2 files changed, 70 insertions(+), 8 deletions(-)

diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs
index d1bc23c..f6d6a46 100644
--- a/Documentation/ABI/testing/sysfs-driver-ufs
+++ b/Documentation/ABI/testing/sysfs-driver-ufs
@@ -561,6 +561,50 @@ Description:	This file contains a product revision string. The full
 
 		The file is read only.
 
+What:		/sys/bus/platform/drivers/ufshcd/*/string_descriptors/manufacturer_name_raw
+Date:		February 2021
+Contact:	Arthur Simchaev <arthur.simchaev@wdc.com>
+Description:	This file contains a device manufactureer name string
+		as raw data. The full information about the descriptor
+		could be found at UFS specifications 2.1.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/string_descriptors/product_name_raw
+Date:		February 2021
+Contact:	Arthur Simchaev <arthur.simchaev@wdc.com>
+Description:	This file contains a product name string as raw data.
+		The full information about the descriptor could be found at
+		UFS specifications 2.1.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/string_descriptors/oem_id_raw
+Date:		February 2021
+Contact:	Arthur Simchaev <arthur.simchaev@wdc.com>
+Description:	This file contains a OEM ID string as raw data.
+		The full information about the descriptor could be found at
+		UFS specifications 2.1.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/string_descriptors/serial_number_raw
+Date:		February 2021
+Contact:	Arthur Simchaev <arthur.simchaev@wdc.com>
+Description:	This file contains a device serial number string
+		as raw data. The full information about the descriptor could be
+		found at UFS specifications 2.1.
+
+		The file is read only.
+
+What:		/sys/bus/platform/drivers/ufshcd/*/string_descriptors/product_revision_raw
+Date:		February 2021
+Contact:	Arthur Simchaev <arthur.simchaev@wdc.com>
+Description:	This file contains a product revision string as raw data.
+		The full information about the descriptor could be found at
+		UFS specifications 2.1.
+
+		The file is read only.
 
 What:		/sys/class/scsi_device/*/device/unit_descriptor/boot_lun_id
 Date:		February 2018
diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c
index acc54f5..f1407ff 100644
--- a/drivers/scsi/ufs/ufs-sysfs.c
+++ b/drivers/scsi/ufs/ufs-sysfs.c
@@ -658,7 +658,7 @@ static const struct attribute_group ufs_sysfs_power_descriptor_group = {
 	.attrs = ufs_sysfs_power_descriptor,
 };
 
-#define UFS_STRING_DESCRIPTOR(_name, _pname)				\
+#define UFS_STRING_DESCRIPTOR(_name, _pname, _is_ascii)		\
 static ssize_t _name##_show(struct device *dev,				\
 	struct device_attribute *attr, char *buf)			\
 {									\
@@ -690,10 +690,18 @@ static ssize_t _name##_show(struct device *dev,				\
 	kfree(desc_buf);						\
 	desc_buf = NULL;						\
 	ret = ufshcd_read_string_desc(hba, index, &desc_buf,		\
-				      SD_ASCII_STD);			\
+				      _is_ascii);			\
 	if (ret < 0)							\
 		goto out;						\
-	ret = sysfs_emit(buf, "%s\n", desc_buf);			\
+	if (_is_ascii) {						\
+		ret = sysfs_emit(buf, "%s\n", desc_buf);		\
+	} else {							\
+		int i;							\
+									\
+		for (i = 0; i < desc_buf[0]; i++)			\
+			hex_byte_pack(buf + i * 2, desc_buf[i]);	\
+		ret = sysfs_emit(buf, "%s\n", buf);			\
+	}			\
 out:									\
 	pm_runtime_put_sync(hba->dev);					\
 	kfree(desc_buf);						\
@@ -702,11 +710,16 @@ out:									\
 }									\
 static DEVICE_ATTR_RO(_name)
 
-UFS_STRING_DESCRIPTOR(manufacturer_name, _MANF_NAME);
-UFS_STRING_DESCRIPTOR(product_name, _PRDCT_NAME);
-UFS_STRING_DESCRIPTOR(oem_id, _OEM_ID);
-UFS_STRING_DESCRIPTOR(serial_number, _SN);
-UFS_STRING_DESCRIPTOR(product_revision, _PRDCT_REV);
+UFS_STRING_DESCRIPTOR(manufacturer_name, _MANF_NAME, 1);
+UFS_STRING_DESCRIPTOR(product_name, _PRDCT_NAME, 1);
+UFS_STRING_DESCRIPTOR(oem_id, _OEM_ID, 1);
+UFS_STRING_DESCRIPTOR(serial_number, _SN, 1);
+UFS_STRING_DESCRIPTOR(product_revision, _PRDCT_REV, 1);
+UFS_STRING_DESCRIPTOR(manufacturer_name_raw, _MANF_NAME, 0);
+UFS_STRING_DESCRIPTOR(product_name_raw, _PRDCT_NAME, 0);
+UFS_STRING_DESCRIPTOR(oem_id_raw, _OEM_ID, 0);
+UFS_STRING_DESCRIPTOR(serial_number_raw, _SN, 0);
+UFS_STRING_DESCRIPTOR(product_revision_raw, _PRDCT_REV, 0);
 
 static struct attribute *ufs_sysfs_string_descriptors[] = {
 	&dev_attr_manufacturer_name.attr,
@@ -714,6 +727,11 @@ static struct attribute *ufs_sysfs_string_descriptors[] = {
 	&dev_attr_oem_id.attr,
 	&dev_attr_serial_number.attr,
 	&dev_attr_product_revision.attr,
+	&dev_attr_manufacturer_name_raw.attr,
+	&dev_attr_product_name_raw.attr,
+	&dev_attr_oem_id_raw.attr,
+	&dev_attr_serial_number_raw.attr,
+	&dev_attr_product_revision_raw.attr,
 	NULL,
 };
 
-- 
2.7.4


             reply	other threads:[~2021-02-15 17:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-15 17:40 Arthur Simchaev [this message]
2021-03-16 11:27 ` [PATCH v2] scsi: ufs: sysfs: Print string descriptors as raw data Arthur Simchaev
2021-03-17  2:59   ` Martin K. Petersen
2021-03-17  3:31 ` Bart Van Assche
2021-04-08 10:25   ` Arthur Simchaev

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=1613410846-16883-1-git-send-email-Arthur.Simchaev@wdc.com \
    --to=arthur.simchaev@wdc.com \
    --cc=alim.akhtar@samsung.com \
    --cc=beanhuo@micron.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.