Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp268579ioo; Thu, 26 May 2022 03:17:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq/X1olJQc5iD88A/rlpVj1Hilf9cQ8w+GfjRmjrT1cWzgaARNmJyorfxK5Ey98t0h3ki/ X-Received: by 2002:a17:907:3e28:b0:6fe:b5fa:fa9c with SMTP id hp40-20020a1709073e2800b006feb5fafa9cmr25376462ejc.464.1653560269180; Thu, 26 May 2022 03:17:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653560269; cv=none; d=google.com; s=arc-20160816; b=X3KJkAPWGXs4IgTVlEbDDzX8azNBeAkBRAu2zITCfABbI4BTQNuvXj//KYEVX10DNV 5UVK60Xu//8G2gAWG8t/vHkisR8TFSCSgLA+M+ksEs+4kh5K1MZ7vzwmC3Yv7DnXTT66 u3wmvZE8WUEb7j2GzauKDWNeOVJbDxtV7e7UriAoV1+5sy+QBwK1WWelcvM45kXz/jlW m/hYFJrmXEJZW92BO4ZM0dfTIlexFu8/byxsW4tdg2+bGklC6aXUkZhmoWGFY0JjYcCG MCOnPFG+8BWOgmc5+zp21LU3AbU3jp8fxN8snYNzopj+r1K8z3+bz7wam9QZn2EvzuRI F7IQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=16kBQarSnJ8LMUZPuHQSKei1JbMKJKBeBXK4+hg4lHA=; b=Puxd9MY4YnukMwiZhVIUgHu93MPwXTXRk83asbxhZLrxpSf75qfmrP9TVW7NCWey80 rCmcCJl8+aZ05/5+I+2aZqj404w3vVYpJd3txEQ41DTTScIfxiTvhq1S1mrz1hzWMTqV nZLS120ArkAFpDKvEWdYBFM0YO3rRGUlcS9jAjY+K0DFkWUPSa1/QEOPOLuWn2u56k/q 9E40scbMEkUbZ5ypzwspTFIaOMOX/fRSQtFdp6naYmdGIlThyLTzkgEpDh37xNrcInLc RXw94V5UcGZENYV1Wva/EeYc/pO1C12H9N8Qzqr5q999439W1iW6xAIGWU58OWOLXDGP TO/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b=ZTi51qNE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=riseup.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fy39-20020a1709069f2700b006fe78f5ab4esi791247ejc.895.2022.05.26.03.17.22; Thu, 26 May 2022 03:17:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@riseup.net header.s=squak header.b=ZTi51qNE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=riseup.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245445AbiEYQ1g (ORCPT + 99 others); Wed, 25 May 2022 12:27:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233582AbiEYQ1f (ORCPT ); Wed, 25 May 2022 12:27:35 -0400 Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91D67A1AB; Wed, 25 May 2022 09:27:34 -0700 (PDT) Received: from fews2.riseup.net (fews2-pn.riseup.net [10.0.1.84]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "mail.riseup.net", Issuer "R3" (not verified)) by mx1.riseup.net (Postfix) with ESMTPS id 4L7c1163zvzDrgH; Wed, 25 May 2022 09:27:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1653496054; bh=wu6xEaXOL0trEsdjhmzYXfb4lvQfG+o2d5deXcMtdk4=; h=From:To:Cc:Subject:Date:From; b=ZTi51qNEh1CF+IHWU7pTR81tAtn95nnw3fJ4XMr3CbOX43kLfaOv4I4B7GzMaOWm3 GcOkJUm030VkyOOA67zTlB0aV0e7yUTAp7J8T3+0hHRhLcS9K4xlIFIsfkZm9Hnf6G orIjgOPszQTuBFDrYwpdBnGUf/j23/NCWxNOtpu0= X-Riseup-User-ID: CE90C1541A4B1DC364A0A41ACD3E0D74BA5125FD1E1CAF2C6B3680EE9D35C382 Received: from [127.0.0.1] (localhost [127.0.0.1]) by fews2.riseup.net (Postfix) with ESMTPSA id 4L7c0w6WH0z1yXB; Wed, 25 May 2022 09:27:28 -0700 (PDT) From: Nia Espera To: Alim Akhtar , Avri Altman , "James E . J . Bottomley" , "Martin K . Petersen" , linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: ~postmarketos/upstreaming@lists.sr.ht, phone-devel@vger.kernel.org, Nia Espera Subject: [PATCH] add sysfs support for writing to boot lun Date: Wed, 25 May 2022 19:24:40 +0300 Message-Id: <20220525162440.90918-1-a5b6@riseup.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Expands sysfs boot_lun attribute to be writable. Necessary to enable proper support for LUN switching on some UFS devices. Signed-off-by: Nia Espera --- drivers/scsi/ufs/ufs-sysfs.c | 67 +++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 5c405ff7b6ea..7bf5d6c3d0ec 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -1047,6 +1047,71 @@ static inline bool ufshcd_is_wb_attrs(enum attr_idn idn) idn <= QUERY_ATTR_IDN_CURR_WB_BUFF_SIZE; } +static ssize_t boot_lun_enabled_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + u32 slot; + int ret; + u8 index = 0; + + down(&hba->host_sem); + if (!ufshcd_is_user_access_allowed(hba)) { + up(&hba->host_sem); + return -EBUSY; + } + if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN_BOOT_LU_EN)) + index = ufshcd_wb_get_query_index(hba); + ufshcd_rpm_get_sync(hba); + + ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, + QUERY_ATTR_IDN_BOOT_LU_EN, index, 0, &slot); + + ufshcd_rpm_put_sync(hba); + if (ret) { + ret = -EINVAL; + goto out; + } + + ret = sysfs_emit(buf, "0x%08X\n", slot); +out: + up(&hba->host_sem); + return ret; +} + +static ssize_t boot_lun_enabled_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct ufs_hba *hba = dev_get_drvdata(dev); + u32 slot; + int ret; + u8 index = 0; + + if (kstrtouint(buf, 0, &slot) < 0) + return -EINVAL; + + down(&hba->host_sem); + if (!ufshcd_is_user_access_allowed(hba)) { + up(&hba->host_sem); + return -EBUSY; + } + if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN_BOOT_LU_EN)) + index = ufshcd_wb_get_query_index(hba); + ufshcd_rpm_get_sync(hba); + + ret = ufshcd_query_attr_retry(hba, UPIU_QUERY_OPCODE_WRITE_ATTR, + QUERY_ATTR_IDN_BOOT_LU_EN, index, 0, &slot); + ufshcd_rpm_put_sync(hba); + if (ret) { + ret = -EINVAL; + goto out; + } +out: + up(&hba->host_sem); + return ret ? ret : count; +} + #define UFS_ATTRIBUTE(_name, _uname) \ static ssize_t _name##_show(struct device *dev, \ struct device_attribute *attr, char *buf) \ @@ -1077,8 +1142,8 @@ out: \ return ret; \ } \ static DEVICE_ATTR_RO(_name) +static DEVICE_ATTR_RW(boot_lun_enabled); -UFS_ATTRIBUTE(boot_lun_enabled, _BOOT_LU_EN); UFS_ATTRIBUTE(max_data_size_hpb_single_cmd, _MAX_HPB_SINGLE_CMD); UFS_ATTRIBUTE(current_power_mode, _POWER_MODE); UFS_ATTRIBUTE(active_icc_level, _ACTIVE_ICC_LVL); -- 2.36.1