linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avri Altman <avri.altman@wdc.com>
To: "James E . J . Bottomley" <jejb@linux.vnet.ibm.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Bart Van Assche <bvanassche@acm.org>,
	alim.akhtar@samsung.com, asutoshd@codeaurora.org,
	Zang Leigang <zangleigang@hisilicon.com>,
	Avi Shchislowski <avi.shchislowski@wdc.com>,
	Bean Huo <beanhuo@micron.com>,
	cang@codeaurora.org, stanley.chu@mediatek.com,
	MOHAMMED RAFIQ KAMAL BASHA <md.rafiq@samsung.com>,
	Sang-yoon Oh <sangyoon.oh@samsung.com>,
	yongmyung lee <ymhungry.lee@samsung.com>,
	Jinyoung CHOI <j-young.choi@samsung.com>,
	Avri Altman <avri.altman@wdc.com>
Subject: [RFC PATCH 10/13] scsi: dh: ufshpb: Add ufshpb_set_params
Date: Fri, 15 May 2020 13:30:11 +0300	[thread overview]
Message-ID: <1589538614-24048-11-git-send-email-avri.altman@wdc.com> (raw)
In-Reply-To: <1589538614-24048-1-git-send-email-avri.altman@wdc.com>

The ufshpb LLD intercepted a response from the device indicating that
some subregion(s) should be activated, or some region(s) should be
inactivated.  Each such message may carry info of up to 2 subregions to
activate, and up to 2 regions to inactivate.

Set the appropriate triggering events to those regions/subregions and
schedule the state machine handler.

In case the device lost the LUN’s HPB information for whatever reason,
it can signal to the host through HPB Sense data. On LUN reset, all of
its active subregions are being updated.

None of the above applies for pinned regions which are not affected by
any of this and stay active.

Inactivation of the entire LUN barriers heavy implications, both with
respect of performance: sending READ_10 instead of HPB_READ, as well as
with respect of overhead – re-activating the entire LUN.  One might
expect that a proper protection against frequent resets and / or
irrational device behavior should be in place.  However, it is out of
scope of the driver to cover for this.  Instead, issue a proper info
message.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/scsi/device_handler/scsi_dh_ufshpb.c | 131 +++++++++++++++++++++++++++
 1 file changed, 131 insertions(+)

diff --git a/drivers/scsi/device_handler/scsi_dh_ufshpb.c b/drivers/scsi/device_handler/scsi_dh_ufshpb.c
index 8f85933..affc143 100644
--- a/drivers/scsi/device_handler/scsi_dh_ufshpb.c
+++ b/drivers/scsi/device_handler/scsi_dh_ufshpb.c
@@ -68,6 +68,16 @@ enum ufshpb_subregion_events {
 	SUBREGION_EVENT_MAX
 };
 
+enum ufshpb_response_opers {
+	OPER_TYPE_ACTIVATE	= 1,
+	OPER_TYPE_RESET		= 2,
+};
+
+enum ufshpb_work_locks {
+	LUN_RESET_WORK = BIT(0),
+};
+
+
 /**
  * struct map_ctx - a mapping context
  * @pages - array of pages
@@ -158,11 +168,13 @@ struct ufshpb_dh_lun {
 	unsigned int last_subregion_size;
 	unsigned int max_active_regions;
 
+	struct work_struct lun_reset_work;
 	atomic_t active_regions;
 
 	struct mutex eviction_lock;
 
 	struct workqueue_struct *wq;
+	unsigned long work_lock;
 };
 
 struct ufshpb_dh_data {
@@ -285,6 +297,9 @@ static bool ufshpb_read_buf_cmd_need_retry(struct ufshpb_dh_lun *hpb,
 	if (atomic_read(&hpb->active_regions) >= hpb->max_active_regions)
 		return false;
 
+	if (test_bit(LUN_RESET_WORK, &hpb->work_lock))
+		return false;
+
 	/* UFS3.1 spec says: "...
 	 * If the device is performing internal maintenance work, for example
 	 * Garbage collection, the device may terminate the HPB READ BUFFER
@@ -667,6 +682,43 @@ static int ufshpb_activate_pinned_regions(struct ufshpb_dh_data *h, bool init)
 	return ret;
 }
 
+static void __region_reset(struct ufshpb_dh_lun *hpb,
+			   struct ufshpb_region *r)
+{
+	struct ufshpb_subregion *subregions = r->subregion_tbl;
+	int j;
+
+	for (j = 0; j < subregions_per_region; j++) {
+		struct ufshpb_subregion *s = subregions + j;
+		int k;
+
+		mutex_lock(&s->state_lock);
+		ufshpb_subregion_update(hpb, r, s, true);
+		for (k = 0; k < SUBREGION_EVENT_MAX; k++)
+			clear_bit(k, &s->event);
+		mutex_unlock(&s->state_lock);
+	}
+}
+
+static void ufshpb_lun_reset_work_handler(struct work_struct *work)
+{
+	struct ufshpb_dh_lun *hpb = container_of(work, struct ufshpb_dh_lun,
+			lun_reset_work);
+	struct ufshpb_region *regions = hpb->region_tbl;
+	int i;
+
+	for (i = 0; i < hpb->regions_per_lun; i++) {
+		struct ufshpb_region *r = regions + i;
+
+		__region_reset(hpb, r);
+	}
+
+	clear_bit(LUN_RESET_WORK, &hpb->work_lock);
+
+	sdev_printk(KERN_INFO, hpb->sdev, "%s: lun reset [%llu]\n",
+		    UFSHPB_NAME, hpb->sdev->lun);
+}
+
 static int ufshpb_mempool_init(struct ufshpb_dh_lun *hpb)
 {
 	unsigned int max_active_subregions = hpb->max_active_regions *
@@ -736,6 +788,7 @@ static int ufshpb_region_tbl_init(struct ufshpb_dh_lun *hpb)
 
 	hpb->region_tbl = regions;
 	mutex_init(&hpb->eviction_lock);
+	INIT_WORK(&hpb->lun_reset_work, ufshpb_lun_reset_work_handler);
 
 	return 0;
 
@@ -826,6 +879,83 @@ static void ufshpb_get_config(const struct ufshpb_config *c)
 	is_configured = true;
 }
 
+/*
+ * ufshpb_set_params - obtain response from the device
+ * @sdev: scsi device of the hpb lun
+ * params - a hpb sense data buffer copied from the device
+ *
+ * set the appropriate triggers for the various regions/subregions
+ * each hpb sense buffer carries the information of up to 2 subregions to
+ * activate.
+ */
+static int ufshpb_set_params(struct scsi_device *sdev, const char *params)
+{
+	struct ufshpb_dh_data *h = sdev->handler_data;
+	struct ufshpb_dh_lun *hpb = h->hpb;
+	struct ufshpb_region *r;
+	struct ufshpb_subregion *s;
+	struct ufshpb_sense_data sense = {};
+	enum ufshpb_state s_state;
+	u16 *pos;
+	u16 region, subregion;
+	int ret;
+	u8 active_reg_cnt = 0;
+
+	memcpy(&sense, params, sizeof(sense));
+
+	if (sense.oper == OPER_TYPE_RESET) {
+		struct ufshpb_dh_lun *rst_hpb;
+
+		list_for_each_entry(rst_hpb, &lh_hpb_lunp, list) {
+			set_bit(LUN_RESET_WORK, &rst_hpb->work_lock);
+			queue_work(rst_hpb->wq, &rst_hpb->lun_reset_work);
+		}
+		return 0;
+	}
+
+	/* is there any subregions to activate? */
+	if (!sense.active_reg_cnt)
+		return -EINVAL;
+
+	active_reg_cnt = sense.active_reg_cnt;
+	if (active_reg_cnt > 2) {
+		/* HPB1.0 allows the device to signal up to 2 subregions */
+		return -EINVAL;
+	}
+
+	ret = 0;
+
+	pos = &sense.active_reg_0;
+
+	do {
+		region = *pos++;
+		subregion = *pos;
+
+		if (region >= hpb->regions_per_lun ||
+				subregion >= subregions_per_region)
+			return -EINVAL;
+
+		r = hpb->region_tbl + region;
+		s = r->subregion_tbl + subregion;
+
+		rcu_read_lock();
+		s_state = s->state;
+		rcu_read_unlock();
+
+		if (s_state == HPB_STATE_ACTIVE)
+			set_bit(SUBREGION_EVENT_UPDATE, &s->event);
+		else
+			set_bit(SUBREGION_EVENT_ACTIVATE, &s->event);
+
+		queue_work(hpb->wq, &s->hpb_work);
+
+		pos++;
+
+	} while (--active_reg_cnt);
+
+	return ret;
+}
+
 static int ufshpb_activate(struct scsi_device *sdev, activate_complete fn,
 			   void *data)
 {
@@ -939,6 +1069,7 @@ static struct scsi_device_handler ufshpb_dh = {
 	.attach		= ufshpb_attach,
 	.detach		= ufshpb_detach,
 	.activate	= ufshpb_activate,
+	.set_params     = ufshpb_set_params,
 };
 
 static int __init ufshpb_init(void)
-- 
2.7.4


  parent reply	other threads:[~2020-05-15 10:32 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-15 10:30 [RFC PATCH 00/13] scsi: ufs: Add HPB Support Avri Altman
2020-05-15 10:30 ` [RFC PATCH 01/13] scsi: ufs: Add HPB parameters Avri Altman
2020-05-15 10:30 ` [RFC PATCH 02/13] scsi: ufshpb: Init part I - Read HPB config Avri Altman
2020-05-15 15:33   ` Randy Dunlap
2020-05-16  1:46   ` Bart Van Assche
2020-05-16  1:57   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 03/13] scsi: scsi_dh: Introduce scsi_dh_ufshpb Avri Altman
2020-05-16  1:48   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 04/13] scsi: ufs: ufshpb: Init part II - Attach scsi device Avri Altman
2020-05-16  1:52   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 05/13] scsi: ufs: ufshpb: Disable HPB if no HPB-enabled luns Avri Altman
2020-05-16  2:02   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 06/13] scsi: scsi_dh: ufshpb: Prepare for L2P cache management Avri Altman
2020-05-16  2:13   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 07/13] scsi: scsi_dh: ufshpb: Add ufshpb state machine Avri Altman
2020-05-16  2:44   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 08/13] scsi: dh: ufshpb: Activate pinned regions Avri Altman
2020-05-15 10:30 ` [RFC PATCH 09/13] scsi: ufshpb: Add response API Avri Altman
2020-05-16  3:06   ` Bart Van Assche
2020-05-15 10:30 ` Avri Altman [this message]
2020-05-15 10:30 ` [RFC PATCH 11/13] scsi: Allow device handler set their own CDB Avri Altman
2020-05-16  3:19   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 12/13] scsi: dh: ufshpb: Add prep_fn handler Avri Altman
2020-05-16  3:40   ` Bart Van Assche
2020-05-15 10:30 ` [RFC PATCH 13/13] scsi: scsi_dh: ufshpb: Add "Cold" subregions timer Avri Altman
2020-05-16  3:50 ` [RFC PATCH 00/13] scsi: ufs: Add HPB Support Bart Van Assche
2020-05-16  9:14   ` Avri Altman
2020-05-16 17:14     ` Bart Van Assche
     [not found]     ` <CGME20200516171420epcas2p108c570904c5117c3654d71e0a2842faa@epcms2p7>
2020-05-19 22:31       ` Another approach of UFSHPB yongmyung lee
2020-05-20 17:55         ` Christoph Hellwig
2020-05-20 21:19           ` Bart Van Assche
2020-05-22 16:35             ` Bart Van Assche
2020-05-22 16:49         ` Bart Van Assche
     [not found]         ` <CGME20200516171420epcas2p108c570904c5117c3654d71e0a2842faa@epcms2p4>
2020-05-25  5:40           ` Daejun Park
2020-05-25 14:56             ` Bart Van Assche
2020-05-26  6:15               ` Avri Altman
2020-05-26 17:03                 ` Bart Van Assche
     [not found]                 ` <CGME20200516171420epcas2p108c570904c5117c3654d71e0a2842faa@epcms2p3>
2020-05-27  9:11                   ` Daejun Park
2020-05-27 11:46                     ` Bean Huo

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=1589538614-24048-11-git-send-email-avri.altman@wdc.com \
    --to=avri.altman@wdc.com \
    --cc=alim.akhtar@samsung.com \
    --cc=asutoshd@codeaurora.org \
    --cc=avi.shchislowski@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=bvanassche@acm.org \
    --cc=cang@codeaurora.org \
    --cc=j-young.choi@samsung.com \
    --cc=jejb@linux.vnet.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=md.rafiq@samsung.com \
    --cc=sangyoon.oh@samsung.com \
    --cc=stanley.chu@mediatek.com \
    --cc=ymhungry.lee@samsung.com \
    --cc=zangleigang@hisilicon.com \
    /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).