Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3675117imm; Tue, 29 May 2018 11:22:00 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp3D1q4exDIDF4xXbUTDPBN7RhPlWMhIxxfNCRI63TPES8+CJzPGxoq6MRufuHM50bGAtbZ X-Received: by 2002:a17:902:9a06:: with SMTP id v6-v6mr18579635plp.21.1527618120715; Tue, 29 May 2018 11:22:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527618120; cv=none; d=google.com; s=arc-20160816; b=aHpGYAQ060BNdxHhJbfyXXzF+VpTVTrqORMKcCr2vb5XMl71xgeEorc5r+UGdPtMAs Djc2ahCU7SsVVC08NeReEtS6Eq2K5bCXSubCnqB+5e4qNx9PcqQW/4KQJYsP+EVPHdOQ Y3sGjZttBn1ryeFM3AJpyobXKu1mXfInlk/vKQlHBBiVaPXZQoZV6zso3skwYkfW161F q/F8FFbwsIPpMB67pYKlhMnm+a56LPFC6QoUKayRTIYnslKTkBMfCJHzrSMYsDLpeb2f d0p1P5Vv5l2D5i5HNxSVVzRLiqtMf6hEvDFl5vie0D8nOGrN2zHhj/qV5+jMDSNyVTAU u/uw== 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=hTe/CNbogXPkCAxLtKB3Z56xIKyI1gMpssyUEZQoau4=; b=J7H1py//KOWt+bC7E/GQwEZnuryVeTNhYXXEvq7NYo4T3pMsvD0Doq2ftstPrn/d7s Lqs1QqsSRDjuA/1crfuMPGdsU1dSqok888pJhwQngWW8ipJP0twQYOArXEQmKrcDB73H heIqVQhzoeUPgk8Tq4i2dE8JzpNoHtKRRpNHwgwWsj/3U1Lujt/qv8xzVbC+o+hSvlRw HXeZN8/UA8VeTBQ9/cPETm9as3Qco/MGTHdrryPbg69aRQweVASPnIIaBmSNdpjxMyW5 GTKlp2TSJFK7j8fZRks10xmExr64E1dOcSpTD0rKY7m5Xct74pf1Z/HOp6z4qxy2hBvD 03WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=NLfTCEUP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p1-v6si22423166plo.363.2018.05.29.11.21.47; Tue, 29 May 2018 11:22:00 -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=@chromium.org header.s=google header.b=NLfTCEUP; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966058AbeE2STK (ORCPT + 99 others); Tue, 29 May 2018 14:19:10 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:33649 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937037AbeE2SSW (ORCPT ); Tue, 29 May 2018 14:18:22 -0400 Received: by mail-pg0-f67.google.com with SMTP id e21-v6so6942508pgv.0 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=EHmO9+Q4lxBBOH5sVe6U7Lszjnha6KXW+rEmmVZhMtIjQXzrPbaY+rvOQ65Edve8rj /QUMdfpnsrcALM6WbiHq7LmK8DBGGT0zW1wKCGzekBLy/Qse6GMAOzGJolH1FcYBbGLs ocTS3GlvXziFt/u8rkEBc6k/4+2I2xlH7nAKv5jZzoVeMhFEmq+L8oc9ATnUx4zmcYyl 4pFZjAaScNOKJpvFDbsHP+6ywWd/2Om2x+Jy+zchZotlh9sYy/CRwhyXNSwcbOQRphtv 30/CNu9STtz7nN64CQrqBPc2Z8m6F9imoqtAnTo7oJv9Hv+r6hfVhauoveF1yvDOEckF JVaQ== X-Gm-Message-State: ALKqPwfWZD+7S5/XmVujBebaILWIEAwj0lnZjFL4FXNYBf0Kq2I7ygGI 5vuDuZtmh6H9V0J87bExCIXs6g== 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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.13.5