Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp441918imm; Fri, 1 Jun 2018 03:51:15 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKuhrAyNFH3dqdS7FVTJJ5tLxcztOQzzu5Kq3Mnl4d/r73+Wv/hvPzXoKO9lzbebBoM/28M X-Received: by 2002:a62:8910:: with SMTP id v16-v6mr10240119pfd.13.1527850275629; Fri, 01 Jun 2018 03:51:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527850275; cv=none; d=google.com; s=arc-20160816; b=IDx85Q6FniM4jaTF+axW/X3FqQARP1qU02AT8NWyGMLqs2wRvU+O1Y10I0BBbUqwns YRxTDE0mXSnLrsRMhchNUBn6UpTgcn5lhcz5uVKW2jegE/OA9b8Z0Xo3sJwHkPXtxa2V vk28BbvxdRmIjXX/dSRrWWE9zWT9GrkBSzY9LLZKRRcfNW76L5229zdYZb5UkRvKFnyG HGk+bBVMcoj8mQ+oBZD5BvxWcfThed9WtE30Ahj7WrTzFZsvFhqUqycyLTAhEGJLzoQI bmTDkJ3nmDNCZAnblv/OhKOs5rblg5U1V0WP6Aiusg6/o6Fy7jZU5SnsgRXJcUhvKGz+ itaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language:thread-index :content-transfer-encoding:mime-version:message-id:date:subject :in-reply-to:references:cc:to:from:dmarc-filter:dkim-signature :dkim-signature:arc-authentication-results; bh=2nWUhZ1SXUTyAYmWVkkg1KhsDbpPVN7LM9ziLC7+tIU=; b=gkb02DsY2sCbKxi9xzJ3ym0Qr6Y6mK1GdrKpOkgfDx/D3igyryl0asN11vXqUaYvN1 ucqO+uUJcVqa8tQ2R+a6wZCD94q8X3ceAhQIzR3LWGf+yML1DRs+/DZLhfJq3EnrFOFE 9QCLjdHR7lrbyAMl5NFaeQwgA8yycz/lnxAdNa9MY+GUQWViR2WIAftUOa+XhG5aTpSY D/gzOqv/B2klBYJNRVxRwkDN3PENqaGPaxQ3YFx3tPitKk/8LghgVVPxxFWe955pTeSh s1ky+48eGrSQkUoa3jnPZ5aNCJL3Ys6UXtOFZk5OgG5I+ZI7BBNsTAIGmbVCiWI2/Ynh ktlg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=MDJTuPsa; dkim=pass header.i=@codeaurora.org header.s=default header.b=g5bihyAI; 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 u13-v6si8513741pgb.610.2018.06.01.03.51.01; Fri, 01 Jun 2018 03:51:15 -0700 (PDT) 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=pass header.i=@codeaurora.org header.s=default header.b=MDJTuPsa; dkim=pass header.i=@codeaurora.org header.s=default header.b=g5bihyAI; 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 S1751722AbeFAKtX (ORCPT + 99 others); Fri, 1 Jun 2018 06:49:23 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:52922 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751518AbeFAKtS (ORCPT ); Fri, 1 Jun 2018 06:49:18 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id AC02960708; Fri, 1 Jun 2018 10:49:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527850157; bh=qbkT5lYkO5i53tnYyZdg+j8SSjfIxS958D2SHQUSE/0=; h=From:To:Cc:References:In-Reply-To:Subject:Date:From; b=MDJTuPsa/laCDDF0cnNjzgRoUWpZR22xzXIBfKOG6gCx7nmZPKcVvzdNao773gUKd QrQmsnsq4rrCJ4hH7lixO4A2z0yqQejTmF41Ce56RdZ6NboGMs2QXilR5oOqI1mBC4 NFkvHeUW0CjzN4dEpIuIAyxozt8hlNLcjfYoPLao= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.6 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,TVD_RCVD_SINGLE,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from SAYALIL (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: sayalil@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 3638E601A1; Fri, 1 Jun 2018 10:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527850151; bh=qbkT5lYkO5i53tnYyZdg+j8SSjfIxS958D2SHQUSE/0=; h=From:To:Cc:References:In-Reply-To:Subject:Date:From; b=g5bihyAIRyZJU3vX6S5EISlLrWRfxnN8Ty9lxmkc4QcQPqUaaGNiqe0c1A8mbo3Z7 aCGgGCFeohwIe0GcC7l4eiEv5/bFDUR0LYmI3//Cw4zI/QTfnu7ZJ5GA+PvSDLVE+u fWJvIMlh2F+HBxSyyTQ4nisPtO3gElfBt6VIXTG8= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 3638E601A1 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sayalil@codeaurora.org From: "sayali" To: Cc: , "'Stanislav Nijnikov'" , "'Greg Kroah-Hartman'" , "'Adrian Hunter'" , "'open list'" , , , , , , , , References: <1527849774-7623-1-git-send-email-sayalil@codeaurora.org> <1527849774-7623-4-git-send-email-sayalil@codeaurora.org> In-Reply-To: <1527849774-7623-4-git-send-email-sayalil@codeaurora.org> Subject: RE: [PATCH V1 3/3] scsi: ufs: Add sysfs support for ufs provision Date: Fri, 1 Jun 2018 16:19:02 +0530 Message-ID: <000f01d3f996$2c16d1e0$844475a0$@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQKGja9h2+sAa9B7VDYjBpPLWNjYigGinHYVotj7tAA= Content-Language: en-us Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Evan, I am working on upstreaming runtime UFS provisioning patches and have posted my latest (V1) patches for review. I have noticed that you are also working on the same and would appreciate if you could also review my patches. I believe it will save us all some time and duplicate effort. Let me know if you have any concern or comments on this. Thanks, Sayali -----Original Message----- From: Sayali Lokhande [mailto:sayalil@codeaurora.org] Sent: Friday, June 01, 2018 4:13 PM To: subhashj@codeaurora.org; cang@codeaurora.org; vivek.gautam@codeaurora.org; rnayak@codeaurora.org; vinholikatti@gmail.com; jejb@linux.vnet.ibm.com; martin.petersen@oracle.com; asutoshd@codeaurora.org; evgreen@chromium.org Cc: linux-scsi@vger.kernel.org; Sayali Lokhande ; Stanislav Nijnikov ; Greg Kroah-Hartman ; Adrian Hunter ; open list Subject: [PATCH V1 3/3] scsi: ufs: Add sysfs support for ufs provision Add sysfs support to trigger ufs provisioning at runtime. Usage : echo > /sys/bus/platform/drivers/*/ config_descriptor/ufs_provision To check provisioning status: cat /sys/bus/platform/drivers/*/config_descriptor/ufs_provision 1- > Success (Reboot device to check updated provisioning) Signed-off-by: Sayali Lokhande --- Documentation/ABI/testing/sysfs-driver-ufs | 16 ++++ drivers/scsi/ufs/ufs-sysfs.c | 25 ++++++ drivers/scsi/ufs/ufs.h | 2 + drivers/scsi/ufs/ufshcd.c | 128 +++++++++++++++++++++++++++++ drivers/scsi/ufs/ufshcd.h | 5 ++ 5 files changed, 176 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-driver-ufs b/Documentation/ABI/testing/sysfs-driver-ufs index 016724e..43419b5 100644 --- a/Documentation/ABI/testing/sysfs-driver-ufs +++ b/Documentation/ABI/testing/sysfs-driver-ufs @@ -883,3 +883,19 @@ Contact: Subhash Jadavani Description: This entry shows the target state of an UFS UIC link for the chosen system power management level. The file is read only. + +What: /sys/bus/platform/drivers/ufshcd/*/config_descriptor/ufs_provision +Date: February 2018 +Contact: Sayali Lokhande +Description: This file shows the status of runtime ufs provisioning. + This can be used to provision ufs device if bConfigDescrLock is 0. + Configuration buffer needs to be written in space separated format + specificied as: + echo + + + + + > ufs_provision + To check updated configuration check unit_descriptor and + device_descriptor sysfs fields. diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 8d9332b..8b68813 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -252,6 +252,30 @@ static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba, return ret; } +static ssize_t ufs_provision_show(struct device *dev, + struct device_attribute *attr, char *buf) { + return ufshcd_desc_config_show(dev, attr, buf); } + +static ssize_t ufs_provision_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { + return ufshcd_desc_config_store(dev, attr, buf, count); } + +DEVICE_ATTR_RW(ufs_provision); + +static struct attribute *ufs_sysfs_config_descriptor[] = { + &dev_attr_ufs_provision.attr, + NULL, +}; + +static const struct attribute_group ufs_sysfs_config_descriptor_group = { + .name = "config_descriptor", + .attrs = ufs_sysfs_config_descriptor, +}; + #define UFS_DESC_PARAM(_name, _puname, _duname, _size) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -713,6 +737,7 @@ static DEVICE_ATTR_RO(_name) static const struct attribute_group *ufs_sysfs_groups[] = { &ufs_sysfs_default_group, &ufs_sysfs_device_descriptor_group, + &ufs_sysfs_config_descriptor_group, &ufs_sysfs_interconnect_descriptor_group, &ufs_sysfs_geometry_descriptor_group, &ufs_sysfs_health_descriptor_group, diff --git a/drivers/scsi/ufs/ufs.h b/drivers/scsi/ufs/ufs.h index 1f99904..0b497fc 100644 --- a/drivers/scsi/ufs/ufs.h +++ b/drivers/scsi/ufs/ufs.h @@ -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 */ diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 3fd29e0..122c119 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1580,6 +1580,131 @@ void ufshcd_release(struct ufs_hba *hba) } EXPORT_SYMBOL_GPL(ufshcd_release); +ssize_t ufshcd_desc_config_show(struct device *dev, + struct device_attribute *attr, char *buf) { + struct ufs_hba *hba = dev_get_drvdata(dev); + + return snprintf(buf, PAGE_SIZE, "provision_enabled = %d\n", + hba->provision_enabled); +} + +ssize_t ufshcd_desc_config_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) { + struct ufs_hba *hba = dev_get_drvdata(dev); + struct ufs_config_descr *cfg = &hba->cfgs; + char *strbuf; + char *strbuf_copy; + int desc_buf[count]; + int *pt; + char *token; + int i, ret; + int value, commit = 0; + int num_luns = 0; + int KB_per_block = 4; + + /* reserve one byte for null termination */ + strbuf = kmalloc(count + 1, GFP_KERNEL); + if (!strbuf) + return -ENOMEM; + + strbuf_copy = strbuf; + strlcpy(strbuf, buf, count + 1); + memset(desc_buf, 0, count); + + /* Just return if bConfigDescrLock is already set */ + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_CONF_DESC_LOCK, 0, 0, &cfg->bConfigDescrLock); + if (ret) { + dev_err(hba->dev, "%s: Failed reading bConfigDescrLock %d, cannot re-provision device!\n", + __func__, ret); + hba->provision_enabled = 0; + goto out; + } + if (cfg->bConfigDescrLock == 1) { + dev_err(hba->dev, "%s: bConfigDescrLock already set to %u, cannot re-provision device!\n", + __func__, cfg->bConfigDescrLock); + hba->provision_enabled = 0; + goto out; + } + + for (i = 0; i < count; i++) { + token = strsep(&strbuf, " "); + if (!token && i) { + num_luns = desc_buf[i-1]; + dev_dbg(hba->dev, "%s: token %s, num_luns %d\n", + __func__, token, num_luns); + if (num_luns > 8) { + dev_err(hba->dev, "%s: Invalid num_luns %d\n", + __func__, num_luns); + hba->provision_enabled = 0; + goto out; + } + break; + } + + ret = kstrtoint(token, 0, &value); + if (ret) { + dev_err(hba->dev, "%s: kstrtoint failed %d %s\n", + __func__, ret, token); + break; + } + desc_buf[i] = value; + dev_dbg(hba->dev, " desc_buf[%d] 0x%x", i, desc_buf[i]); + } + + /* Fill in the descriptors with parsed configuration data */ + pt = desc_buf; + cfg->bNumberLU = *pt++; + cfg->bBootEnable = *pt++; + cfg->bDescrAccessEn = *pt++; + cfg->bInitPowerMode = *pt++; + cfg->bHighPriorityLUN = *pt++; + cfg->bSecureRemovalType = *pt++; + cfg->bInitActiveICCLevel = *pt++; + cfg->wPeriodicRTCUpdate = *pt++; + cfg->bConfigDescrLock = *pt++; + dev_dbg(hba->dev, "%s: %u %u %u %u %u %u %u %u %u\n", __func__, + cfg->bNumberLU, cfg->bBootEnable, cfg->bDescrAccessEn, + cfg->bInitPowerMode, cfg->bHighPriorityLUN, cfg->bSecureRemovalType, + cfg->bInitActiveICCLevel, cfg->wPeriodicRTCUpdate, + cfg->bConfigDescrLock); + + for (i = 0; i < num_luns; i++) { + cfg->unit[i].LUNum = *pt++; + cfg->unit[i].bLUEnable = *pt++; + cfg->unit[i].bBootLunID = *pt++; + /* dNumAllocUnits = size_in_kb/KB_per_block */ + cfg->unit[i].dNumAllocUnits = (u32)(*pt++ / KB_per_block); + cfg->unit[i].bDataReliability = *pt++; + cfg->unit[i].bLUWriteProtect = *pt++; + cfg->unit[i].bMemoryType = *pt++; + cfg->unit[i].bLogicalBlockSize = *pt++; + cfg->unit[i].bProvisioningType = *pt++; + cfg->unit[i].wContextCapabilities = *pt++; + } + + cfg->lun_to_grow = *pt++; + commit = *pt++; + cfg->num_luns = *pt; + dev_dbg(hba->dev, "%s: lun_to_grow %u, commit %u num_luns %u\n", + __func__, cfg->lun_to_grow, commit, cfg->num_luns); + if (commit == 1) { + ret = ufshcd_do_config_device(hba); + if (!ret) { + hba->provision_enabled = 1; + dev_err(hba->dev, + "%s: UFS Provisioning completed,num_luns %u, reboot now !\n", + __func__, cfg->num_luns); + } + } else + dev_err(hba->dev, "%s: Invalid commit %u\n", __func__, commit); +out: + kfree(strbuf_copy); + return count; +} + static ssize_t ufshcd_clkgate_delay_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -6532,6 +6657,9 @@ static int ufshcd_do_config_device(struct ufs_hba *hba) pt = pt + 3; // Reserved fields set to 0 } + for (i = 0; i < buff_len; i++) + dev_dbg(hba->dev, " desc_buf[%d] 0x%x", i, desc_buf[i]); + ret = ufshcd_query_descriptor_retry(hba, UPIU_QUERY_OPCODE_WRITE_DESC, QUERY_DESC_IDN_CONFIGURATION, 0, 0, desc_buf, &buff_len); diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h index 982bfdf..1b8304f 100644 --- a/drivers/scsi/ufs/ufshcd.h +++ b/drivers/scsi/ufs/ufshcd.h @@ -651,6 +651,7 @@ struct ufs_hba { struct ufs_pwr_mode_info max_pwr_info; struct ufs_clk_gating clk_gating; + bool provision_enabled; /* Control to enable/disable host capabilities */ u32 caps; /* Allow dynamic clk gating */ @@ -867,6 +868,10 @@ int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index, int ufshcd_hold(struct ufs_hba *hba, bool async); void ufshcd_release(struct ufs_hba *hba); +ssize_t ufshcd_desc_config_show(struct device *dev, + struct device_attribute *attr, char *buf); ssize_t +ufshcd_desc_config_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count); int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_id, int *desc_length); -- The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project