From patchwork Tue May 29 18:17:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evan Green X-Patchwork-Id: 10436673 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 569E6601E9 for ; Tue, 29 May 2018 18:18:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E46AB287FA for ; Tue, 29 May 2018 18:18:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7C0928826; Tue, 29 May 2018 18:18:25 +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=ham 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 6A7AF287FA for ; Tue, 29 May 2018 18:18:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965659AbeE2SSW (ORCPT ); Tue, 29 May 2018 14:18:22 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40343 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S937018AbeE2SSR (ORCPT ); Tue, 29 May 2018 14:18:17 -0400 Received: by mail-pf0-f194.google.com with SMTP id f189-v6so7678034pfa.7 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=E7/8Oo/6ASpXNIqHqqrY3fGn89YjQ/ae4cIRPdURvd08gyuds88xLnLqcFSqvVOT80 CmNAUsJCdWPx+0KhGM5OSSWF7DQg9kU+7czm2NHf2/kTBPbMLFcSc92bDSZ3VS/hq+T9 9o+0CTyN6tS9fRihtsEoqYqwKItWqUNMXkBgc6n9xxnQd772V3WTdFD1mAa0OzGb9K6j KAyeuGBMIVK7L0drCmvCEIfGsNKmxQYpSClbRX4A7K0Ckb4mKQuqDEczHHXeJV9mKJe2 E13qGIcNRsjeXjOHyfQgVLZ25aKOkIvjyafIdohvq3TIYnVA0EDiVClCXB7/7ASjnVuT 6H1A== X-Gm-Message-State: ALKqPwe0/++5Vc5rTIRH51B6suPCYpHicLqrQkvEjjCdVGgCBxK2oLfq YPIL25vh1Ff4Vr38LyvgmMl8BA== X-Google-Smtp-Source: ADUXVKLqloMkwekKKZLdHISmq2Suoixts9+AI+QdzFF6Aw3g6tXmZSM3/6+HRBFj/t6+Dl4r8jj3pQ== 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-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 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,