Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3673836imm; Tue, 29 May 2018 11:20:23 -0700 (PDT) X-Google-Smtp-Source: AB8JxZplerWD/UXSDKpK88CKd/sKkCI1EEZE9YKKNdroHPBuenqhP97UCiboN4wHHKQOat9Q10Zq X-Received: by 2002:a62:a50c:: with SMTP id v12-v6mr18496592pfm.237.1527618023158; Tue, 29 May 2018 11:20:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527618023; cv=none; d=google.com; s=arc-20160816; b=DvUlDzZ2tRTqmqXjT7w+fvWt98967ZEknyU91md58R+BIzk94LgU2HTyR3tB+QyP/b 6tlPcAW6HvVjzObdwjJD2vo2rNQJmFV8SeCJe5DQIqxfJY+86Ccv+erBWv5tQzBDUNaq 2W1oiDUTn/Pf+Q6lT68Q+FnQ5DRNW4BzZy/K4g+5NKrpilOAXpy56XZiwWUMex3IbQdo 0utfqe+3WnWaSD6LOU5i/PjJkRHgFqAJo2iJWRYkG27GJBFzNCSInVOVCPLaB/s6zpW2 vf41Kmp2TMh5Th66txlv3RqPqzcRv0Be+FZ6F5a8mfWkwnHuXJydw1az4bOGhJO2borx OXWA== 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=IgEfsWuGw25nTWP2+zxDl0JNe8y1tsn1ykZefuMHf2k=; b=P4y3ysWC/Qpo8Eh/z0qebX4tAcZtsCQBdegqQNLNtRBoNdL2iSNLi+4oif6/lbaD/0 0Vj16FEpo/YsC2siEONKYISQM0UfNNwiCuvAzyvvY5JSdpQbdpyU+6VmrEdwLQkj+xlV KN/VgCKF+CSjCMF/E1SqKuH7zVbzqby/FuRm3DqB2pbppsVvU2atzCe9eok6Hq7Dfe1f xmkT5h4EvKxC5F+0Uq/9EWYqaOCunDF4bjWvRCAXZc9QjebZkg9VSOIbLBDIJvMJWSDS D4NNhT/p1fGtTivBHx1VKOUMz+X+AU44Lvk8tSIBZJth6MtA/T9upZl/2ULUdsrJP9kb qDaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=On++kUOv; 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 x17-v6si33780384pfh.354.2018.05.29.11.20.09; Tue, 29 May 2018 11:20:23 -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=On++kUOv; 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 S966150AbeE2STU (ORCPT + 99 others); Tue, 29 May 2018 14:19:20 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:33410 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965608AbeE2SSS (ORCPT ); Tue, 29 May 2018 14:18:18 -0400 Received: by mail-pf0-f194.google.com with SMTP id a20-v6so7680426pfo.0 for ; Tue, 29 May 2018 11:18:17 -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=IgEfsWuGw25nTWP2+zxDl0JNe8y1tsn1ykZefuMHf2k=; b=On++kUOvTVURwmwLhddebAaic884JSLUNxlVZrXgQK1VuE80Szy0cUg7CHr2UWsdpz gBqH6zSLGKdotBEuP6ijb1+FSlDCe1V5+KLXlB9NG9wC1r1i5hqcHwlkFmlZHORE73x4 3Oi86GulL/dYFOl2l8ioKJiy8vmTQs/a5T904= 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=IgEfsWuGw25nTWP2+zxDl0JNe8y1tsn1ykZefuMHf2k=; b=QHsRays1v0336L8pgz33X27Hi5HtVdjxX7aWgLVPYjcrv+sJsckLE66nh7Cy02MHC1 qyXufiauV9gvYI8nTsjCFUDtwxDUVxKEDeTfdikSpSwwUu/+vJjSuFMcPPc8rIunGGx7 M2BV7kDkuT7Me8zZSWKt3tG9U/7OPadI/ncHZ3yMHrj414uMrJWfjHbwDrZRy2J+QrD4 r07+A40JCJeFbTiDU38FYLPNF2YneA4xDbK8C7LmPAf8PqS/yVajandnjkQQEPNvyVQj AfN+1KdK+T2Yhc5Q1hXWWN47yg7U9G4VAoV43iv6sxXshSpBolOAjQ+cUY4ryB3bRNc7 rCsg== X-Gm-Message-State: ALKqPwe7yz7nj67NTSw0iR2rvIaDYjmPPwJYa3Q9HnKy/sakd5rWwnE5 1fg3w0XS1tnPjSc1snecBLlAMEKlhBY= X-Received: by 2002:a62:9e0b:: with SMTP id s11-v6mr9609507pfd.198.1527617896889; Tue, 29 May 2018 11:18:16 -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.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 May 2018 11:18:15 -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 3/7] scsi: ufs: Make sysfs attributes writable Date: Tue, 29 May 2018 11:17:36 -0700 Message-Id: <20180529181740.195362-4-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 makes the UFS controller's sysfs attributes writable, which will enable users to provision unprovisioned UFS devices, or re-provision unlocked UFS devices. Signed-off-by: Evan Green --- drivers/scsi/ufs/ufs-sysfs.c | 58 +++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index a7d65492832a..51bf54e6b47a 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -751,7 +751,7 @@ static const struct attribute_group ufs_sysfs_flags_group = { .attrs = ufs_sysfs_device_flags, }; -#define UFS_ATTRIBUTE(_name, _uname) \ +#define UFS_ATTRIBUTE_SHOW(_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ { \ @@ -761,25 +761,45 @@ static ssize_t _name##_show(struct device *dev, \ QUERY_ATTR_IDN##_uname, 0, 0, &value)) \ return -EINVAL; \ return sprintf(buf, "0x%08X\n", value); \ -} \ -static DEVICE_ATTR_RO(_name) +} -UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN); -UFS_ATTRIBUTE(current_power_mode, _POWER_MODE); -UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL); -UFS_ATTRIBUTE(ooo_data_enabled, _OOO_DATA_EN); -UFS_ATTRIBUTE(bkops_status, _BKOPS_STATUS); -UFS_ATTRIBUTE(purge_status, _PURGE_STATUS); -UFS_ATTRIBUTE(max_data_in_size, _MAX_DATA_IN); -UFS_ATTRIBUTE(max_data_out_size, _MAX_DATA_OUT); -UFS_ATTRIBUTE(reference_clock_frequency, _REF_CLK_FREQ); -UFS_ATTRIBUTE(configuration_descriptor_lock, _CONF_DESC_LOCK); -UFS_ATTRIBUTE(max_number_of_rtt, _MAX_NUM_OF_RTT); -UFS_ATTRIBUTE(exception_event_control, _EE_CONTROL); -UFS_ATTRIBUTE(exception_event_status, _EE_STATUS); -UFS_ATTRIBUTE(ffu_status, _FFU_STATUS); -UFS_ATTRIBUTE(psa_state, _PSA_STATE); -UFS_ATTRIBUTE(psa_data_size, _PSA_DATA_SIZE); +#define UFS_ATTRIBUTE_RO(_name, _uname) \ +UFS_ATTRIBUTE_SHOW(_name, _uname) \ +DEVICE_ATTR_RO(_name) + +#define UFS_ATTRIBUTE_RW(_name, _uname) \ +UFS_ATTRIBUTE_SHOW(_name, _uname) \ +static ssize_t _name##_store(struct device *dev, \ + struct device_attribute *attr, const char *buf, \ + size_t count) \ +{ \ + struct ufs_hba *hba = dev_get_drvdata(dev); \ + unsigned long value; \ + if (kstrtoul(buf, 0, &value)) \ + return -EINVAL; \ + if (ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, \ + QUERY_ATTR_IDN##_uname, 0, 0, (u32 *)&value)) \ + return -EINVAL; \ + return count; \ +} \ +static DEVICE_ATTR_RW(_name) + +UFS_ATTRIBUTE_RW(boot_lun_enabled, _BOOT_LU_EN); +UFS_ATTRIBUTE_RO(current_power_mode, _POWER_MODE); +UFS_ATTRIBUTE_RW(active_icc_level, _ACTIVE_ICC_LVL); +UFS_ATTRIBUTE_RW(ooo_data_enabled, _OOO_DATA_EN); +UFS_ATTRIBUTE_RO(bkops_status, _BKOPS_STATUS); +UFS_ATTRIBUTE_RO(purge_status, _PURGE_STATUS); +UFS_ATTRIBUTE_RW(max_data_in_size, _MAX_DATA_IN); +UFS_ATTRIBUTE_RW(max_data_out_size, _MAX_DATA_OUT); +UFS_ATTRIBUTE_RW(reference_clock_frequency, _REF_CLK_FREQ); +UFS_ATTRIBUTE_RW(configuration_descriptor_lock, _CONF_DESC_LOCK); +UFS_ATTRIBUTE_RW(max_number_of_rtt, _MAX_NUM_OF_RTT); +UFS_ATTRIBUTE_RW(exception_event_control, _EE_CONTROL); +UFS_ATTRIBUTE_RW(exception_event_status, _EE_STATUS); +UFS_ATTRIBUTE_RO(ffu_status, _FFU_STATUS); +UFS_ATTRIBUTE_RO(psa_state, _PSA_STATE); +UFS_ATTRIBUTE_RO(psa_data_size, _PSA_DATA_SIZE); static struct attribute *ufs_sysfs_attributes[] = { &dev_attr_boot_lun_enabled.attr, -- 2.13.5