From patchwork Tue May 29 18:17:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 10436683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2EC13601E9 for ; Tue, 29 May 2018 18:19:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2095C2892C for ; Tue, 29 May 2018 18:19:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1567928939; Tue, 29 May 2018 18:19:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ADA0C2892C for ; Tue, 29 May 2018 18:19:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966071AbeE2STM (ORCPT ); Tue, 29 May 2018 14:19:12 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:44136 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937035AbeE2SSW (ORCPT ); Tue, 29 May 2018 14:18:22 -0400 Received: by mail-pg0-f67.google.com with SMTP id p21-v6so6935899pgd.11 for ; Tue, 29 May 2018 11:18:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=hTe/CNbogXPkCAxLtKB3Z56xIKyI1gMpssyUEZQoau4=; b=NLfTCEUPhJA8pOQJmHBBzp3c1H5O2jKqqBJF+DmdGboPTvZO4kj/WS4UN8KN8GpEVZ tQxojCsWEn5vVvCz+RI+A/+1jBwJQ8kZp2zjx8GO3UTI8Mh5+mh+CEVX/LqV4CDdExSJ gfD2ue8qeypWHHHsj0+uyhOVUdAAhwFYFufo0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=hTe/CNbogXPkCAxLtKB3Z56xIKyI1gMpssyUEZQoau4=; b=kDr81Op77MIgXUa8ublccjEpbGoeQ4d3bLHX4FGUGh3zhTOPlIpZqWOuGRK8/NlTvk RqZFzFZSlSVubdvaXLO7Y+djIpGz3jekeRbHgTtGwc8f1g3f2CUTKA1uSxv8lUQTH4o0 N2O3SFBcJY4G/1/gs3VgmoHXahjJsHY33nujcGGEWnPQgZnHD6qfJgu/GPMOCEaG7BEf YPuY0U2PqpNhsv64PIlhLgY4JCkWrNqXt3Necop1rvzcsnGal0spPGufiwfFCsR8uD7t HrhQ1xfSoXlluybUgfCf1p8IOwdu2v2Hz/WSv9t44P0fvuZJXNHBp1BNxHgDvkrZQpUx 7aRA== X-Gm-Message-State: ALKqPwemxC3aKEcokKLASqW1qyn4oTbxFGKawVYXP3M56mFgMh6rkLlI SyOKG4YS6g6xnmmPRU6NQT6q0A== X-Google-Smtp-Source: AB8JxZpW908x+WVxr7AZcXM1BVXd5Tuw/+XYGx3mJ259QnVlfFP15mVDQA9kgcxM5D/kI7rt5aaIGg== X-Received: by 2002:a62:850f:: with SMTP id u15-v6mr18314162pfd.160.1527617901663; Tue, 29 May 2018 11:18:21 -0700 (PDT) Received: from evgreen2.mtv.corp.google.com ([2620:0:1000:1511:116f:8bf3:133b:f7fd]) by smtp.gmail.com with ESMTPSA id b74-v6sm18255704pfl.138.2018.05.29.11.18.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 May 2018 11:18:20 -0700 (PDT) From: Evan Green To: Vinayak Holikatti , "James E.J. Bottomley" , "Martin K. Petersen" , Stanislav Nijnikov , linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org Cc: Gwendal Grignou , Evan Green Subject: [PATCH 6/7] scsi: ufs: Enable writing config descriptor Date: Tue, 29 May 2018 11:17:39 -0700 Message-Id: <20180529181740.195362-7-evgreen@chromium.org> X-Mailer: git-send-email 2.13.5 In-Reply-To: <20180529181740.195362-1-evgreen@chromium.org> References: <20180529181740.195362-1-evgreen@chromium.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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);