From: Martin Kepplinger <martin.kepplinger@puri.sm>
To: jejb@linux.ibm.com, martin.petersen@oracle.com,
stern@rowland.harvard.edu, bvanassche@acm.org
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Martin Kepplinger <martin.kepplinger@puri.sm>
Subject: [PATCH 2/3] scsi: add expect_media_change_suspend sysfs device setting
Date: Mon, 11 Jan 2021 16:20:28 +0100 [thread overview]
Message-ID: <20210111152029.28426-3-martin.kepplinger@puri.sm> (raw)
In-Reply-To: <20210111152029.28426-1-martin.kepplinger@puri.sm>
Add a user-facing flag that sets expecting_media_change on runtime
resume. That works around devices that send MEDIA_CHANGED when it
actually is just resumed from suspend and the media can be expected
not to have changed.
Signed-off-by: Martin Kepplinger <martin.kepplinger@puri.sm>
---
drivers/scsi/scsi_sysfs.c | 38 ++++++++++++++++++++++++++++++++++++++
include/scsi/scsi_device.h | 2 ++
2 files changed, 40 insertions(+)
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index b6378c8ca783..a049290addff 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -1189,6 +1189,43 @@ static DEVICE_ATTR(queue_ramp_up_period, S_IRUGO | S_IWUSR,
sdev_show_queue_ramp_up_period,
sdev_store_queue_ramp_up_period);
+static ssize_t
+sdev_show_expect_media_change_suspend(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct scsi_device *sdev;
+ sdev = to_scsi_device(dev);
+
+ if (sdev->expect_media_change_suspend)
+ return sprintf(buf, "1\n");
+ else
+ return sprintf(buf, "0\n");
+}
+
+static ssize_t
+sdev_store_expect_media_change_suspend(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct scsi_device *sdev;
+ unsigned int flag;
+ int err;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EACCES;
+
+ sdev = to_scsi_device(dev);
+ err = kstrtouint(buf, 10, &flag);
+ if (err)
+ return err;
+ sdev->expect_media_change_suspend = !!flag;
+
+ return count;
+}
+static DEVICE_ATTR(expect_media_change_suspend, S_IRUGO | S_IWUSR,
+ sdev_show_expect_media_change_suspend,
+ sdev_store_expect_media_change_suspend);
+
static umode_t scsi_sdev_attr_is_visible(struct kobject *kobj,
struct attribute *attr, int i)
{
@@ -1260,6 +1297,7 @@ static struct attribute *scsi_sdev_attrs[] = {
&dev_attr_queue_type.attr,
&dev_attr_wwid.attr,
&dev_attr_blacklist.attr,
+ &dev_attr_expect_media_change_suspend.attr,
#ifdef CONFIG_SCSI_DH
&dev_attr_dh_state.attr,
&dev_attr_access_state.attr,
diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
index ca2c3eb5830f..fafb8e6ea4d0 100644
--- a/include/scsi/scsi_device.h
+++ b/include/scsi/scsi_device.h
@@ -171,6 +171,8 @@ struct scsi_device {
unsigned expecting_cc_ua:1; /* Expecting a CHECK_CONDITION/UNIT_ATTN
* because we did a bus reset. */
unsigned expecting_media_change:1; /* Expecting "media changed" UA */
+ unsigned expect_media_change_suspend:1; /* User facing flag to enable
+ * the above flag on runtime resume */
unsigned use_10_for_rw:1; /* first try 10-byte read / write */
unsigned use_10_for_ms:1; /* first try 10-byte mode sense/select */
unsigned set_dbd_for_ms:1; /* Set "DBD" field in mode sense */
--
2.20.1
next prev parent reply other threads:[~2021-01-11 15:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-11 15:20 [PATCH 0/3] scsi: add runtime PM workaround for SD cardreaders Martin Kepplinger
2021-01-11 15:20 ` [PATCH 1/3] scsi: add expecting_media_change flag to error path Martin Kepplinger
2021-01-11 15:20 ` Martin Kepplinger [this message]
2021-01-11 15:20 ` [PATCH 3/3] scsi: sd: add support for expect_media_change_suspend flag Martin Kepplinger
2021-01-11 15:31 ` Martin Kepplinger
2021-01-11 17:37 ` kernel test robot
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=20210111152029.28426-3-martin.kepplinger@puri.sm \
--to=martin.kepplinger@puri.sm \
--cc=bvanassche@acm.org \
--cc=jejb@linux.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=stern@rowland.harvard.edu \
/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;
as well as URLs for NNTP newsgroup(s).