[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1589538614-24048-11-git-send-email-avri.altman@wdc.com>
Date: Fri, 15 May 2020 13:30:11 +0300
From: Avri Altman <avri.altman@....com>
To: "James E . J . Bottomley" <jejb@...ux.vnet.ibm.com>,
"Martin K . Petersen" <martin.petersen@...cle.com>,
linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Bart Van Assche <bvanassche@....org>, alim.akhtar@...sung.com,
asutoshd@...eaurora.org, Zang Leigang <zangleigang@...ilicon.com>,
Avi Shchislowski <avi.shchislowski@....com>,
Bean Huo <beanhuo@...ron.com>, cang@...eaurora.org,
stanley.chu@...iatek.com,
MOHAMMED RAFIQ KAMAL BASHA <md.rafiq@...sung.com>,
Sang-yoon Oh <sangyoon.oh@...sung.com>,
yongmyung lee <ymhungry.lee@...sung.com>,
Jinyoung CHOI <j-young.choi@...sung.com>,
Avri Altman <avri.altman@....com>
Subject: [RFC PATCH 10/13] scsi: dh: ufshpb: Add ufshpb_set_params
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@....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
Powered by blists - more mailing lists