[RFC PATCH 08/13] scsi: dh: ufshpb: Activate pinned regions
From: Avri Altman
Date: Fri May 15 2020 - 06:32:24 EST
Pinned regions are regions that needs to be always active. They are
adjacent starting from a pre-defined starting index. On Init and post
lun reset, those regions are moved promptly to active state.
On init, during the lun activation sequence, we run through the full
sequence of activating all the subregions of the pinned regions. Upon
failure HPB is disabled for that lun.
On lun reset, as it is the middle of the platform life and memory might
not be available, it is ok if a subregion activation has failed. The
region however is counted as one of the lun active regions anyway.
We will also maintain a bitmap per lun indicating its pinned regions, so
that we will not accidently inactivate any of its subregions.
As a general statement, it is undesirable to configure any pinned
regions at all.
Signed-off-by: Avri Altman <avri.altman@xxxxxxx>
---
drivers/scsi/device_handler/scsi_dh_ufshpb.c | 53 ++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)
diff --git a/drivers/scsi/device_handler/scsi_dh_ufshpb.c b/drivers/scsi/device_handler/scsi_dh_ufshpb.c
index c94a616..8f85933 100644
--- a/drivers/scsi/device_handler/scsi_dh_ufshpb.c
+++ b/drivers/scsi/device_handler/scsi_dh_ufshpb.c
@@ -618,6 +618,55 @@ static void ufshpb_work_handler(struct work_struct *work)
mutex_unlock(&s->state_lock);
}
+static int ufshpb_activate_pinned_regions(struct ufshpb_dh_data *h, bool init)
+{
+ const struct ufshpb_lun_config *lun_conf = h->ufshpb_lun_conf;
+ struct ufshpb_dh_lun *hpb = h->hpb;
+ u16 start_idx = lun_conf->pinned_starting_idx;
+ u16 pinned_count = lun_conf->pinned_count;
+ int i, j;
+ int ret;
+
+ if (!pinned_count)
+ return 0;
+
+ for (i = 0; i < pinned_count; i++) {
+ struct ufshpb_region *r = hpb->region_tbl + start_idx + i;
+ struct ufshpb_subregion *subregions = r->subregion_tbl;
+ unsigned int sub_count = subregions_per_region;
+
+ /*
+ * lun might not be region/subregion aligned. pinned region
+ * activation is the only case in which we do care the exact
+ * amount of the regionâs subregions, to avoid sending
+ * HPB_READ_BUFFER to a nonexistent subregion
+ */
+ if (i == hpb->regions_per_lun - 1) {
+ /*
+ * A small trick to avoid checking if the lun is
+ * subregion aligned
+ */
+ sub_count = ((hpb->subregions_per_lun - 1) %
+ subregions_per_region) + 1;
+ }
+
+ for (j = 0; j < sub_count; j++) {
+ struct ufshpb_subregion *s = subregions + j;
+
+ mutex_lock(&s->state_lock);
+ ret = ufshpb_subregion_activate(hpb, r, s, true);
+ mutex_unlock(&s->state_lock);
+
+ if (ret && init)
+ return ret;
+ }
+
+ set_bit(start_idx + i, hpb->pinned_map);
+ }
+
+ return ret;
+}
+
static int ufshpb_mempool_init(struct ufshpb_dh_lun *hpb)
{
unsigned int max_active_subregions = hpb->max_active_regions *
@@ -791,6 +840,10 @@ static int ufshpb_activate(struct scsi_device *sdev, activate_complete fn,
if (ret)
return ret;
+ ret = ufshpb_activate_pinned_regions(h, true);
+ if (ret)
+ return ret;
+
if (fn)
fn(data, ret);
--
2.7.4