mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Avri Altman <Avri.Altman@wdc.com>
To: Nia Espera <a5b6@riseup.net>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	"James E . J . Bottomley" <jejb@linux.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	"linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: "~postmarketos/upstreaming@lists.sr.ht" 
	<~postmarketos/upstreaming@lists.sr.ht>,
	"phone-devel@vger.kernel.org" <phone-devel@vger.kernel.org>
Subject: RE: [RESEND PATCH] scsi: ufs: sysfs: support writing boot_lun attr
Date: Wed, 25 May 2022 18:34:34 +0000	[thread overview]
Message-ID: <DM6PR04MB65750969ACD36EEEB48374DFFCD69@DM6PR04MB6575.namprd04.prod.outlook.com> (raw)
In-Reply-To: <20220525164013.93748-1-a5b6@riseup.net>

Hi,
> Expands sysfs boot_lun attribute to be writable. Necessary to enable
> proper support for LUN switching on some UFS devices.
Can you please elaborate why is it necessary?
What use case are you running?

> 
> Signed-off-by: Nia Espera <a5b6@riseup.net>
> ---
>  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))
Clearly bBootLunEn is not a WB attribute.

> +               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;
You need to verify that no one set bBootLunEn = 0x0 because the device won't boot.
Better check explicitly that slot != bBootLunEn and its either 1 or 2.

Thanks,
Avri

> +
> +       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


  reply	other threads:[~2022-05-25 18:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-25 16:40 Nia Espera
2022-05-25 18:34 ` Avri Altman [this message]
2022-05-26 20:12   ` -
2022-05-27  6:17     ` Avri Altman
2022-05-27 12:50       ` Caleb Connolly
2022-06-01 17:05         ` Avri Altman
2022-06-05  3:55           ` Bart Van Assche
2022-06-06  2:48             ` Damien Le Moal
2022-06-06 13:16               ` Bart Van Assche
2022-06-07  0:42                 ` Damien Le Moal

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM6PR04MB65750969ACD36EEEB48374DFFCD69@DM6PR04MB6575.namprd04.prod.outlook.com \
    --to=avri.altman@wdc.com \
    --cc=a5b6@riseup.net \
    --cc=alim.akhtar@samsung.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=phone-devel@vger.kernel.org \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®