Received: by 10.223.185.116 with SMTP id b49csp1948238wrg; Thu, 15 Feb 2018 04:18:37 -0800 (PST) X-Google-Smtp-Source: AH8x226mOsEjDtfDJZ6yLzksRS/vxPEQv3fZ8w5zDyyMyh64T2hsGxiIAlDdSd5G9dAyCgwTMk4O X-Received: by 2002:a17:902:b43:: with SMTP id 61-v6mr2451504plq.270.1518697117518; Thu, 15 Feb 2018 04:18:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518697117; cv=none; d=google.com; s=arc-20160816; b=oAKw9NuRQVTsN+Sj2IAcnP4RyqhXJdbweeVgxyDW4jXsmXAqa+OmMRt7O8N0D/rpwb mCass9RUyiXRZlfWlpspx3vfXe+8kAMhMUw1zdg0o2wjECQod+Uhm58owQr+Zu1CY1zX 2CsuNJ5eUaR5lWKS85lBakwnnmrl3zJKG4iL4IxmhpECRxEqUlVSYHKDN5Yijjier8Pr P2GCT5whkb5KDSoQxalVF24DyaY2+rDjFZD9jQjdOKSxv53ntjb7VGXOPFaQO3HxOkPo 9zS7CLskU0WS9OcDyYqI+e43iOWufuEMKrF1SQKjPkRBKB+Wm0HuEnanhz/B0rzKkCuM 5pfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=Aiy0j4Ter7y3ZzLzzNPlzI8e1d7WDXNqtmXdxxD2iGA=; b=RiNP42cP2FfytU0H0Bbc8ERXKtIpWrQ3uD2+wXuQ8lMA7+fefMgYGnssl5YK/lS04b YEMwq66jxfVrTTUt3xWUYSW0sCjW4DdWYtWAJmQ2lAK03nr1vYCprckNUkpdPwixKg1y mbKfvQFl8cZFMd9kJ1BHRhE7JWoaNn1UecfjEWw8zgOu5xGJtSrm2oP+dMGzfjyQKelW 2byS6zLNbSJahah8woamoaTRhDsX/AIUFvAOgbGelB5haaoy6cHfh4Lo6sMfglsfw1ff B9cQOPXVfpeWnt52beudxZaZDiR+NFwzkdxlUOuZF7eyUCLvAzencnrqG8koLaoBCMMV ptmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=NGEqg5rn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b81si2991718pfj.331.2018.02.15.04.18.23; Thu, 15 Feb 2018 04:18:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=NGEqg5rn; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968114AbeBOMP6 (ORCPT + 99 others); Thu, 15 Feb 2018 07:15:58 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:56846 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968006AbeBOMOe (ORCPT ); Thu, 15 Feb 2018 07:14:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1518696875; x=1550232875; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=19OuwC1/yG3QTHWR8amatzmfuugD0aH8Gp+imWBsDjo=; b=NGEqg5rncvUEIQCNyQl1jJlbkJb7XsDPvzUU0fKBvTNips6x7YQy4gpG BpG+XJUOSgcS9Akun+jnVCdyyfK0/3CQnSSRZh4+xJavHlkBTZQ6O+Rz4 sJy0qzawD+QlUQoV7HHlquCyw3QqNeVnaOlCBIG9bOR7khBBNzFt1u/W1 2pp5EL3LnZiEAYK7BA8GATa+g3ppAHW1J0dgiVstSaKgJ2rbl+hklk0+/ UzSeSLZJc7beUd3c6Bga37ogTFdDwOfAWDy5rQafuWFONe1WTIRP5Q879 fqfRFJaDDQxrBvzSiXM7E8o9l/i+TvxC2qHpAE2bwar6KstY4Sv+FNoyd g==; X-IronPort-AV: E=Sophos;i="5.46,517,1511798400"; d="scan'208";a="71975464" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 15 Feb 2018 20:14:35 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP; 15 Feb 2018 04:08:36 -0800 Received: from ilb000042.sdcorp.global.sandisk.com ([10.0.231.79]) by uls-op-cesaip02.wdc.com with ESMTP; 15 Feb 2018 04:14:32 -0800 From: Stanislav Nijnikov To: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, gregkh@linuxfoundation.org, jaegeuk@kernel.org, Bart.VanAssche@wdc.com Cc: alex.lemberg@wdc.com, Stanislav Nijnikov Subject: [PATCH v6 07/11] scsi: ufs: sysfs: string descriptors Date: Thu, 15 Feb 2018 14:14:07 +0200 Message-Id: <1518696851-6730-8-git-send-email-stanislav.nijnikov@wdc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518696851-6730-1-git-send-email-stanislav.nijnikov@wdc.com> References: <1518696851-6730-1-git-send-email-stanislav.nijnikov@wdc.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces a sysfs group entry for the UFS string descriptors. The group adds "string_descriptors" folder under the UFS driver sysfs entry (/sys/bus/platform/drivers/ufshcd/*). The folder will contain 5 files that will show string values defined by the UFS spec: a manufacturer name, a product name, an OEM id, a serial number and a product revision. The full information about the string descriptors could be found at UFS specifications 2.1. Signed-off-by: Stanislav Nijnikov Reviewed-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-driver-ufs | 39 +++++++++++++++++++++ drivers/scsi/ufs/ufs-sysfs.c | 56 ++++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.c | 14 ++++---- drivers/scsi/ufs/ufshcd.h | 9 +++++ 4 files changed, 111 insertions(+), 7 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 7460566..c17a968 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -451,3 +451,42 @@ Description: This file shows maximum VCC, VCCQ and VCCQ2 value for power descriptor parameters. 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/manufacturer_name +Date: February 2018 +Contact: Stanislav Nijnikov +Description: This file contains a device manufactureer name string. + 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 +Date: February 2018 +Contact: Stanislav Nijnikov +Description: This file contains a product name string. 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 +Date: February 2018 +Contact: Stanislav Nijnikov +Description: This file contains a OEM ID string. 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 +Date: February 2018 +Contact: Stanislav Nijnikov +Description: This file contains a device serial number string. 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 +Date: February 2018 +Contact: Stanislav Nijnikov +Description: This file contains a product revision string. The full + information about the descriptor could be found at + UFS specifications 2.1. + The file is read only. diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 16e357a..c1aeb8a 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -484,6 +484,61 @@ static const struct attribute_group ufs_sysfs_power_descriptor_group = { .attrs = ufs_sysfs_power_descriptor, }; +#define UFS_STRING_DESCRIPTOR(_name, _pname) \ +static ssize_t _name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + u8 index; \ + struct ufs_hba *hba = dev_get_drvdata(dev); \ + int ret; \ + int desc_len = QUERY_DESC_MAX_SIZE; \ + u8 *desc_buf; \ + desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC); \ + if (!desc_buf) \ + return -ENOMEM; \ + ret = ufshcd_query_descriptor_retry(hba, \ + UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE, \ + 0, 0, desc_buf, &desc_len); \ + if (ret) { \ + ret = -EINVAL; \ + goto out; \ + } \ + index = desc_buf[DEVICE_DESC_PARAM##_pname]; \ + memset(desc_buf, 0, QUERY_DESC_MAX_SIZE); \ + if (ufshcd_read_string_desc(hba, index, desc_buf, \ + QUERY_DESC_MAX_SIZE, true)) { \ + ret = -EINVAL; \ + goto out; \ + } \ + ret = snprintf(buf, PAGE_SIZE, "%s\n", \ + desc_buf + QUERY_DESC_HDR_SIZE); \ +out: \ + kfree(desc_buf); \ + return ret; \ +} \ +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); + +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, +}; + +static const struct attribute_group ufs_sysfs_string_descriptors_group = { + .name = "string_descriptors", + .attrs = ufs_sysfs_string_descriptors, +}; + + static const struct attribute_group *ufs_sysfs_groups[] = { &ufs_sysfs_default_group, &ufs_sysfs_device_descriptor_group, @@ -491,6 +546,7 @@ static const struct attribute_group *ufs_sysfs_groups[] = { &ufs_sysfs_geometry_descriptor_group, &ufs_sysfs_health_descriptor_group, &ufs_sysfs_power_descriptor_group, + &ufs_sysfs_string_descriptors_group, NULL, }; diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index b88fcf7..9cfdd8e 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -2873,11 +2873,11 @@ static int __ufshcd_query_descriptor(struct ufs_hba *hba, * The buf_len parameter will contain, on return, the length parameter * received on the response. */ -static int ufshcd_query_descriptor_retry(struct ufs_hba *hba, - enum query_opcode opcode, - enum desc_idn idn, u8 index, - u8 selector, - u8 *desc_buf, int *buf_len) +int ufshcd_query_descriptor_retry(struct ufs_hba *hba, + enum query_opcode opcode, + enum desc_idn idn, u8 index, + u8 selector, + u8 *desc_buf, int *buf_len) { int err; int retries; @@ -3093,8 +3093,8 @@ static int ufshcd_read_device_desc(struct ufs_hba *hba, u8 *buf, u32 size) * Return 0 in case of success, non-zero otherwise */ #define ASCII_STD true -static int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, - u8 *buf, u32 size, bool ascii) +int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, + u8 *buf, u32 size, bool ascii) { int err = 0; diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 515c6e6..2dad9da 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -842,6 +842,12 @@ static inline bool ufshcd_is_hs_mode(struct ufs_pa_layer_attr *pwr_info) } /* Expose Query-Request API */ +int ufshcd_query_descriptor_retry(struct ufs_hba *hba, + enum query_opcode opcode, + enum desc_idn idn, u8 index, + u8 selector, + u8 *desc_buf, int *buf_len); + int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id, int desc_index, @@ -850,6 +856,9 @@ int ufshcd_read_desc_param(struct ufs_hba *hba, u8 param_size); int ufshcd_query_flag(struct ufs_hba *hba, enum query_opcode opcode, enum flag_idn idn, bool *flag_res); +int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, + u8 *buf, u32 size, bool ascii); + int ufshcd_hold(struct ufs_hba *hba, bool async); void ufshcd_release(struct ufs_hba *hba); -- 2.7.4