Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1211544pxb; Wed, 10 Feb 2021 03:00:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwYiCAUaVyOGyqZvFZS7HzwbTBcUn4x1vlWVRqwPFKDkIq7ND6YNvzCTgguFQidn9u52Cvr X-Received: by 2002:a17:906:30c4:: with SMTP id b4mr2354057ejb.456.1612954858739; Wed, 10 Feb 2021 03:00:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612954858; cv=none; d=google.com; s=arc-20160816; b=B0w/Nsg8DtZIYizlLN2NkM7S79Fy2jUmnCLvpIUCRg92nqdE92P7B9RPlyX4Eg6OA8 WZacQ16Huph05RfO40bTocQNS2e/0Rgv8ttZl0QxJiEViox2ghAowyv75MpvZxubyfi2 efD18/dkfa8VaOu2zm4ukWG0Inr1zRMBQVAyqypNBjwMRjJfw/jw3M4cjkkFnMa8k1bn tgAQZP/b3oixhD1IMS2tHPyMIdBygyvgPZfEecB73ptWc30+GQFnT3TTTh8Lt36GG4yy jaf2ZlvQIyvO6yD664jwJtNLfBQRD9gFRd1TDvhx1jcFYOAc4675UjfGknr2EUwyzbkm 5qZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=glpWBA0zLBUT89u/FVuGznUCrQ6fXgvnZHG49spXARw=; b=PkR+E193trILJPgdSrsmrMTAWcAUtJblJVLvNfido/bV6j6YoVlKkCnAeCmufpYg6Y 4fBl1AvLU3SuyKdhP773ZXWYzPD+D2hR2vh3dRJTl14IIUqIMXdBLBzV4cowTxSb7G42 rn0XmstDm7YhMbCX53arwKiO5Z6nhz2Oh9YDDvZDj1HFS4PTc448PhdPtgp2t9WXv/So 5Ov1RywJE+TJNtojk1sGC3402jyQEVxKiFxntFg+IA0Bm1yw9ZW13QotuthWnZIT2OBU 7FpdWmH8+QG92k0gmpBJxKUC/S1WAn14QugEXFXsYRmijicyyI78658eCERiKHgyEe21 9G1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sandisk.com header.s=dkim.sandisk.com header.b="16/QuUsO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si1202885edj.219.2021.02.10.03.00.34; Wed, 10 Feb 2021 03:00:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@sandisk.com header.s=dkim.sandisk.com header.b="16/QuUsO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229636AbhBJK6o (ORCPT + 99 others); Wed, 10 Feb 2021 05:58:44 -0500 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:33841 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231511AbhBJKzJ (ORCPT ); Wed, 10 Feb 2021 05:55:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=sandisk.com; i=@sandisk.com; q=dns/txt; s=dkim.sandisk.com; t=1612954509; x=1644490509; h=from:to:cc:subject:date:message-id; bh=QUxTHn86SkMNd/9RtbLZhC4AogfF7Hfr2MyKmgOWQ8o=; b=16/QuUsORQl95qKp853Fs1kQVl/yn312vjFZmjtnYCG2B/MEl2BjTmCg Nb5hSPDEwNGs6vpje1V46GewtXwgWn3KimZ1i6+rWOUlTE2FZDJmHIoHw UafalgNz5xihiu8/mmatZ7SVmAuhNJFCYi3pE//dyoFlH/yGVzabnQ+gx 3gjX2umFmDyRLhHtWuCALJDR6XUaNvEM+0RANoMtFcDWumPrSmnXVxC2/ kvlvia9REH5vBZciTIf/aBAT6sw6OHwLsbMiEhS4b2pH4OD/H0FwCJG5o KRW9Ga9UeyOXqyCCdmMQPPQYpq0tr/XzEBLVUKpzZ2PbmKJgyk7ElVajF g==; IronPort-SDR: Mz07YtmEThSCYZNLySvyJERs6SB/VropMK5Qv6pcy20IhFzK5F1UFsQ2iKldXF5bgGrMfZTtXB CnKb2IFNl0FT1cVCIEtGnanJko1esLeNObv+1BZLNkeoZurEuXSOfTHFyrFcxEJD8A+jwsfXq6 thP5zNXR9k9gppFlRCenwoZR/EEcmNqOYSPLoEe3hrS9IYIqRILCqRNxENVDXiFIJ9ifhcwbo7 lk95fUWNr0jrZc25HNmbEGtwaeKmPF/w7tS41sNBAu0hDlB4/8KTc/xp5t5PCSMzcxJ4u4pJy6 lsI= X-IronPort-AV: E=Sophos;i="5.81,168,1610380800"; d="scan'208";a="270102607" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Feb 2021 18:53:51 +0800 IronPort-SDR: k76807AJXGa4mp8wOvFLcGIaUAVjtOBLww/iScqD+793Olv34U8ImucbHwgH+J5g1Z+eIi08VW ebwVqi3Fzt52pAbMfzgxB8QKxzN1hF/intRa75S3m50ln8F9+1V6RjNURal6zIqy//bBsvVqXk QkRc2tQ2dbxUTEpkmkCdsSlcpccChwtEvpnIREhw2T+/Rw91GJKwreLj8dEcDfzZYPwdMTIYrL OUzSx98DnWN8JY+L2Lk4tBUSL0yOaGXDA+LJPSRV+dLVzcIQNJ//2ZIq8nKnYoIodrTXFbntap IdX6BbzN6H3HTMQSgDojdq2h Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Feb 2021 02:37:35 -0800 IronPort-SDR: fMBKU3qIGmFehGUw1iQec26lbAGlShd6t1OWDxqFQyESmkYHRJOT1XSa/AqQM2hosPxnL4GwiL QcRzmDYG1nI0qI0KmI8szk/2SR46+aFKEd02j9ZAWJ+EoxpZI90FWWYrAURH84v71aVapqqa0i dqdlBHKwgASurc12zeeFGb8uw1GX+AVMS2XUAoLt7IE8JdB+yPJs3QQmXbk99GNMWUOQeQJ7Zm /fYPB4ZNJ4F8pgUWiaSuKTxjBF6zRyy9xwAiFCvvnaKQzqWjxSSFYJWGAspUSIoam3Vi9VMyif pzo= WDCIronportException: Internal Received: from cnf008142.ad.shared (HELO ilb001078.hgst.com) ([10.86.63.178]) by uls-op-cesaip02.wdc.com with ESMTP; 10 Feb 2021 02:53:50 -0800 From: Arthur Simchaev To: "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: alim.akhtar@samsung.com, Bean Huo , Arthur Simchaev , Arthur Simchaev Subject: [PATCH] scsi: ufs: sysfs: add is_ascii_output entry Date: Wed, 10 Feb 2021 12:53:45 +0200 Message-Id: <1612954425-6705-1-git-send-email-Arthur.Simchaev@sandisk.com> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arthur Simchaev Currently the string descriptors sysfs entries are printing in ascii format. According to Jedec UFS spec the string descriptors data is Unicode and may 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 "is_ascii_output" entry will be added to string descriptor's sysfs directory. According to the entry value, the user will receive the string descriptor output in raw or ascii data Signed-off-by: Arthur Simchaev --- Documentation/ABI/testing/sysfs-driver-ufs | 9 +++++++++ drivers/scsi/ufs/ufs-sysfs.c | 32 ++++++++++++++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index d1bc23c..c7d8d8d 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -561,6 +561,15 @@ Description: This file contains a product revision string. The full The file is read only. +What: /sys/bus/platform/drivers/ufshcd/*/string_descriptors/is_ascii_output +Date: February 2021 +Contact: Arthur Simchaev +Description: This entry could be used to set the string descriptor + output format: + 0 will print raw string descriptor data as defined in + UFS JEDEC spec. + 1 will convert the string descriptor data to ascii string + and print it. 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..83c8104 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -9,6 +9,8 @@ #include "ufs.h" #include "ufs-sysfs.h" +static bool is_ascii_output = true; + static const char *ufschd_uic_link_state_to_string( enum uic_link_state state) { @@ -693,7 +695,15 @@ static ssize_t _name##_show(struct device *dev, \ SD_ASCII_STD); \ if (ret < 0) \ goto out; \ - ret = sysfs_emit(buf, "%s\n", desc_buf); \ + if (is_ascii_output) { \ + 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); \ @@ -708,13 +718,31 @@ UFS_STRING_DESCRIPTOR(oem_id, _OEM_ID); UFS_STRING_DESCRIPTOR(serial_number, _SN); UFS_STRING_DESCRIPTOR(product_revision, _PRDCT_REV); +static ssize_t is_ascii_output_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + return scnprintf(buf, PAGE_SIZE, "%d\n", is_ascii_output); +} + +static ssize_t is_ascii_output_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + if (kstrtobool(buf, &is_ascii_output)) + return -EINVAL; + return count; +} + +static DEVICE_ATTR_RW(is_ascii_output); + static struct attribute *ufs_sysfs_string_descriptors[] = { &dev_attr_manufacturer_name.attr, &dev_attr_product_name.attr, &dev_attr_oem_id.attr, &dev_attr_serial_number.attr, &dev_attr_product_revision.attr, - NULL, + &dev_attr_is_ascii_output.attr, + NULL }; static const struct attribute_group ufs_sysfs_string_descriptors_group = { -- 2.7.4