diff mbox series

[RFC,2/5] scsi: ufs: Add UFS-feature layer

Message ID 336371513.41591320902369.JavaMail.epsvc@epcpadp1 (mailing list archive)
State Superseded
Headers show
Series scsi: ufs: Add Host Performance Booster Support | expand

Commit Message

Daejun Park June 5, 2020, 1:30 a.m. UTC
This patch is adding UFS feature layer to UFS core driver.

UFS Driver data structure (struct ufs_hba)
	│
┌--------------┐
│ UFS feature  │ <-- HPB module
│    layer     │ <-- other extended feature module
└--------------┘
Each extended UFS-Feature module has a bus of ufs-ext feature type.
The UFS feature layer manages common APIs used by each extended feature
module. The APIs are set of UFS Query requests and UFS Vendor commands
related to each extended feature module.

The following 6 callback functions have been added to "ufshcd.c".
prep_fn: called after construct upiu structure
reset: called after proving hba
reset_host: called before ufshcd_host_reset_and_restore
suspend: called before ufshcd_suspend
resume: called after ufshcd_resume
rsp_upiu: called in ufshcd_transfer_rsp_status with SAM_STAT_GOOD state

Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
 drivers/scsi/ufs/Makefile     |   2 +-
 drivers/scsi/ufs/ufsfeature.c | 178 ++++++++++++++++++++++++++++++++++
 drivers/scsi/ufs/ufsfeature.h |  95 ++++++++++++++++++
 drivers/scsi/ufs/ufshcd.c     |  17 ++++
 drivers/scsi/ufs/ufshcd.h     |   3 +
 5 files changed, 294 insertions(+), 1 deletion(-)
 create mode 100644 drivers/scsi/ufs/ufsfeature.c
 create mode 100644 drivers/scsi/ufs/ufsfeature.h

Comments

Bart Van Assche June 10, 2020, 4:15 a.m. UTC | #1
On 2020-06-04 18:30, Daejun Park wrote:
> +inline void ufsf_slave_configure(struct ufs_hba *hba,
> +				 struct scsi_device *sdev)
> +{
> +	/* skip well-known LU */
> +	if (sdev->lun >= UFS_UPIU_MAX_UNIT_NUM_ID)
> +		return;
> +
> +	if (!(hba->dev_info.b_ufs_feature_sup & UFS_FEATURE_SUPPORT_HPB_BIT))
> +		return;
> +
> +	atomic_inc(&hba->ufsf.slave_conf_cnt);
> +	smp_mb__after_atomic(); /* for slave_conf_cnt */
> +
> +	/* waiting sdev init.*/
> +	if (waitqueue_active(&hba->ufsf.sdev_wait))
> +		wake_up(&hba->ufsf.sdev_wait);
> +}

Guarding a wake_up() call with a waitqueue_active() check is an
anti-pattern. Please don't do that and call wake_up() directly.
Additionally, wake_up() includes a barrier if it wakes up a kernel
thread so the smp_mb__after_atomic() can be left out if the
waitqueue_active() call is removed.

> +/**
> + * struct ufsf_operation - UFS feature specific callbacks
> + * @prep_fn: called after construct upiu structure
> + * @reset: called after proving hba
                           ^^^^^^^
Is this a typo? Should "proving" perhaps be changed into "probing"?

> +struct ufshpb_driver {
> +	struct device_driver drv;
> +	struct list_head lh_hpb_lu;
> +
> +	struct ufsf_operation ufshpb_ops;
> +
> +	/* memory management */
> +	struct kmem_cache *ufshpb_mctx_cache;
> +	mempool_t *ufshpb_mctx_pool;
> +	mempool_t *ufshpb_page_pool;
> +
> +	struct workqueue_struct *ufshpb_wq;
> +};

Why is a dedicated workqueue needed? Why are the standard workqueues not
good enough?

> @@ -2525,6 +2525,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
>  
>  	ufshcd_comp_scsi_upiu(hba, lrbp);
>  
> +	ufsf_ops_prep_fn(hba, lrbp);
> +
>  	err = ufshcd_map_sg(hba, lrbp);
>  	if (err) {
>  		lrbp->cmd = NULL;

What happens if a SCSI command is retried and hence ufsf_ops_prep_fn()
is called multiple times for the same SCSI command?

Thanks,

Bart.
Bart Van Assche June 11, 2020, 1:39 a.m. UTC | #2
On 2020-06-04 18:30, Daejun Park wrote:
> This patch is adding UFS feature layer to UFS core driver.
> 
> UFS Driver data structure (struct ufs_hba)
> 	│
> ┌--------------┐
> │ UFS feature  │ <-- HPB module
> │    layer     │ <-- other extended feature module
> └--------------┘
> Each extended UFS-Feature module has a bus of ufs-ext feature type.
> The UFS feature layer manages common APIs used by each extended feature
> module. The APIs are set of UFS Query requests and UFS Vendor commands
> related to each extended feature module.

Personally I'm less than enthusiast that this new feature layer has been
implemented using the driver/bus model. But it seems like nobody else
objects against this model ...

Bart.
Daejun Park June 12, 2020, 2:27 a.m. UTC | #3
Hi Bart,

On 2020-06-04 18:30, Daejun Park wrote:
> > +inline void ufsf_slave_configure(struct ufs_hba *hba,
> > +         struct scsi_device *sdev)
> > +{
> > +  /* skip well-known LU */
> > +  if (sdev->lun >= UFS_UPIU_MAX_UNIT_NUM_ID)
> > +    return;
> > +
> > +  if (!(hba->dev_info.b_ufs_feature_sup & UFS_FEATURE_SUPPORT_HPB_BIT))
> > +    return;
> > +
> > +  atomic_inc(&hba->ufsf.slave_conf_cnt);
> > +  smp_mb__after_atomic(); /* for slave_conf_cnt */
> > +
> > +  /* waiting sdev init.*/
> > +  if (waitqueue_active(&hba->ufsf.sdev_wait))
> > +    wake_up(&hba->ufsf.sdev_wait);
> > +}

> Guarding a wake_up() call with a waitqueue_active() check is an
> anti-pattern. Please don't do that and call wake_up() directly.
> Additionally, wake_up() includes a barrier if it wakes up a kernel
> thread so the smp_mb__after_atomic() can be left out if the
> waitqueue_active() call is removed.
OK, I will change it.

> > +/**
> > + * struct ufsf_operation - UFS feature specific callbacks
> > + * @prep_fn: called after construct upiu structure
> > + * @reset: called after proving hba
                           ^^^^^^^
> Is this a typo? Should "proving" perhaps be changed into "probing"?
Yes, I will change.

> > +struct ufshpb_driver {
> > +  struct device_driver drv;
> > +  struct list_head lh_hpb_lu;
> > +
> > +  struct ufsf_operation ufshpb_ops;
> > +
> > +  /* memory management */
> > +  struct kmem_cache *ufshpb_mctx_cache;
> > +  mempool_t *ufshpb_mctx_pool;
> > +  mempool_t *ufshpb_page_pool;
> > +
> > +  struct workqueue_struct *ufshpb_wq;
> > +};

> Why is a dedicated workqueue needed? Why are the standard workqueues not
> good enough?
The map_work handles map related operations, including IO operations. So, adding
this task to the standard WQ can interfere with other jobs and degrade HPB related performance.


> > @@ -2525,6 +2525,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
> >  
> >    ufshcd_comp_scsi_upiu(hba, lrbp);
> >  
> > +  ufsf_ops_prep_fn(hba, lrbp);
> > +
> >    err = ufshcd_map_sg(hba, lrbp);
> >    if (err) {
> >      lrbp->cmd = NULL;

> What happens if a SCSI command is retried and hence ufsf_ops_prep_fn()
> is called multiple times for the same SCSI command?
Developers of UFS features should implement it so that prep_fn does not have
any problems even if it processes the same SCSI command multiple times.
In HPB feature, prep_fn modifies only upiu  structure. So it is ok to call
it multiple times because the upiu is rebuilt from ufshcd_comp_scsi_upiu().

Thanks,

Daejun.
Bart Van Assche June 12, 2020, 4:28 a.m. UTC | #4
On 2020-06-11 19:27, Daejun Park wrote:
>>> @@ -2525,6 +2525,8 @@ static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
>>>  
>>>    ufshcd_comp_scsi_upiu(hba, lrbp);
>>>  
>>> +  ufsf_ops_prep_fn(hba, lrbp);
>>> +
>>>    err = ufshcd_map_sg(hba, lrbp);
>>>    if (err) {
>>>      lrbp->cmd = NULL;
> 
>> What happens if a SCSI command is retried and hence ufsf_ops_prep_fn()
>> is called multiple times for the same SCSI command?
>
> Developers of UFS features should implement it so that prep_fn does not have
> any problems even if it processes the same SCSI command multiple times.
> In HPB feature, prep_fn modifies only upiu  structure. So it is ok to call
> it multiple times because the upiu is rebuilt from ufshcd_comp_scsi_upiu().

Please make sure that this expectation is documented somewhere.

Thanks,

Bart.
diff mbox series

Patch

diff --git a/drivers/scsi/ufs/Makefile b/drivers/scsi/ufs/Makefile
index 94c6c5d7334b..fe3a92b06c87 100644
--- a/drivers/scsi/ufs/Makefile
+++ b/drivers/scsi/ufs/Makefile
@@ -5,7 +5,7 @@  obj-$(CONFIG_SCSI_UFS_DWC_TC_PLATFORM) += tc-dwc-g210-pltfrm.o ufshcd-dwc.o tc-d
 obj-$(CONFIG_SCSI_UFS_CDNS_PLATFORM) += cdns-pltfrm.o
 obj-$(CONFIG_SCSI_UFS_QCOM) += ufs-qcom.o
 obj-$(CONFIG_SCSI_UFSHCD) += ufshcd-core.o
-ufshcd-core-y				+= ufshcd.o ufs-sysfs.o
+ufshcd-core-y				+= ufshcd.o ufs-sysfs.o ufsfeature.o
 ufshcd-core-$(CONFIG_SCSI_UFS_BSG)	+= ufs_bsg.o
 obj-$(CONFIG_SCSI_UFSHCD_PCI) += ufshcd-pci.o
 obj-$(CONFIG_SCSI_UFSHCD_PLATFORM) += ufshcd-pltfrm.o
diff --git a/drivers/scsi/ufs/ufsfeature.c b/drivers/scsi/ufs/ufsfeature.c
new file mode 100644
index 000000000000..a6671962fad2
--- /dev/null
+++ b/drivers/scsi/ufs/ufsfeature.c
@@ -0,0 +1,178 @@ 
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Universal Flash Storage Feature Support
+ *
+ * Copyright (C) 2017-2018 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Yongmyung Lee <ymhungry.lee@samsung.com>
+ *	Jinyoung Choi <j-young.choi@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * See the COPYING file in the top-level directory or visit
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This program is provided "AS IS" and "WITH ALL FAULTS" and
+ * without warranty of any kind. You are solely responsible for
+ * determining the appropriateness of using and distributing
+ * the program and assume all risks associated with your exercise
+ * of rights with respect to the program, including but not limited
+ * to infringement of third party rights, the risks and costs of
+ * program errors, damage to or loss of data, programs or equipment,
+ * and unavailability or interruption of operations. Under no
+ * circumstances will the contributor of this Program be liable for
+ * any damages of any kind arising from your use or distribution of
+ * this program.
+ *
+ * The Linux Foundation chooses to take subject only to the GPLv2
+ * license terms, and distributes only under these terms.
+ */
+
+#include "ufshcd.h"
+#include "ufsfeature.h"
+
+inline void ufsf_slave_configure(struct ufs_hba *hba,
+				 struct scsi_device *sdev)
+{
+	/* skip well-known LU */
+	if (sdev->lun >= UFS_UPIU_MAX_UNIT_NUM_ID)
+		return;
+
+	if (!(hba->dev_info.b_ufs_feature_sup & UFS_FEATURE_SUPPORT_HPB_BIT))
+		return;
+
+	atomic_inc(&hba->ufsf.slave_conf_cnt);
+	smp_mb__after_atomic(); /* for slave_conf_cnt */
+
+	/* waiting sdev init.*/
+	if (waitqueue_active(&hba->ufsf.sdev_wait))
+		wake_up(&hba->ufsf.sdev_wait);
+}
+
+inline void ufsf_ops_prep_fn(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
+{
+	struct ufshpb_driver *ufshpb_drv;
+
+	ufshpb_drv = dev_get_drvdata(&hba->ufsf.hpb_dev);
+
+	if (ufshpb_drv && ufshpb_drv->ufshpb_ops.prep_fn)
+		ufshpb_drv->ufshpb_ops.prep_fn(hba, lrbp);
+}
+
+inline void ufsf_ops_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
+{
+	struct ufshpb_driver *ufshpb_drv;
+
+	ufshpb_drv = dev_get_drvdata(&hba->ufsf.hpb_dev);
+
+	if (ufshpb_drv && ufshpb_drv->ufshpb_ops.rsp_upiu)
+		ufshpb_drv->ufshpb_ops.rsp_upiu(hba, lrbp);
+}
+
+inline void ufsf_ops_reset_host(struct ufs_hba *hba)
+{
+	struct ufshpb_driver *ufshpb_drv;
+
+	ufshpb_drv = dev_get_drvdata(&hba->ufsf.hpb_dev);
+
+	if (ufshpb_drv && ufshpb_drv->ufshpb_ops.reset_host)
+		ufshpb_drv->ufshpb_ops.reset_host(hba);
+}
+
+inline void ufsf_ops_reset(struct ufs_hba *hba)
+{
+	struct ufshpb_driver *ufshpb_drv;
+
+	ufshpb_drv = dev_get_drvdata(&hba->ufsf.hpb_dev);
+
+	if (ufshpb_drv && ufshpb_drv->ufshpb_ops.reset)
+		ufshpb_drv->ufshpb_ops.reset(hba);
+}
+
+inline void ufsf_ops_suspend(struct ufs_hba *hba)
+{
+	struct ufshpb_driver *ufshpb_drv;
+
+	ufshpb_drv = dev_get_drvdata(&hba->ufsf.hpb_dev);
+
+	if (ufshpb_drv && ufshpb_drv->ufshpb_ops.suspend)
+		ufshpb_drv->ufshpb_ops.suspend(hba);
+}
+
+inline void ufsf_ops_resume(struct ufs_hba *hba)
+{
+	struct ufshpb_driver *ufshpb_drv;
+
+	ufshpb_drv = dev_get_drvdata(&hba->ufsf.hpb_dev);
+
+	if (ufshpb_drv && ufshpb_drv->ufshpb_ops.resume)
+		ufshpb_drv->ufshpb_ops.resume(hba);
+}
+
+struct device_type ufshpb_dev_type = {
+	.name = "ufshpb_device"
+};
+EXPORT_SYMBOL(ufshpb_dev_type);
+
+static int ufsf_bus_match(struct device *dev,
+			 struct device_driver *gendrv)
+{
+	if (dev->type == &ufshpb_dev_type)
+		return 1;
+
+	return 0;
+}
+
+struct bus_type ufsf_bus_type = {
+	.name = "ufsf_bus",
+	.match = ufsf_bus_match,
+};
+EXPORT_SYMBOL(ufsf_bus_type);
+
+static void ufsf_dev_release(struct device *dev)
+{
+	put_device(dev->parent);
+}
+
+void ufsf_scan_features(struct ufs_hba *hba)
+{
+	int ret;
+
+	init_waitqueue_head(&hba->ufsf.sdev_wait);
+	atomic_set(&hba->ufsf.slave_conf_cnt, 0);
+
+	if (hba->dev_info.wspecversion >= HPB_SUPPORTED_VERSION &&
+	    (hba->dev_info.b_ufs_feature_sup & UFS_FEATURE_SUPPORT_HPB_BIT)) {
+		device_initialize(&hba->ufsf.hpb_dev);
+
+		hba->ufsf.hpb_dev.bus = &ufsf_bus_type;
+		hba->ufsf.hpb_dev.type = &ufshpb_dev_type;
+		hba->ufsf.hpb_dev.parent = get_device(hba->dev);
+		hba->ufsf.hpb_dev.release = ufsf_dev_release;
+
+		dev_set_name(&hba->ufsf.hpb_dev, "ufshpb");
+		ret = device_add(&hba->ufsf.hpb_dev);
+		if (ret)
+			dev_warn(hba->dev, "ufshpb: failed to add device\n");
+	}
+}
+
+static int __init ufsf_init(void)
+{
+	int ret;
+
+	ret = bus_register(&ufsf_bus_type);
+	if (ret)
+		pr_err("%s bus_register failed\n", __func__);
+
+	return ret;
+}
+device_initcall(ufsf_init);
diff --git a/drivers/scsi/ufs/ufsfeature.h b/drivers/scsi/ufs/ufsfeature.h
new file mode 100644
index 000000000000..cbac848ec6c6
--- /dev/null
+++ b/drivers/scsi/ufs/ufsfeature.h
@@ -0,0 +1,95 @@ 
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Universal Flash Storage Feature Support
+ *
+ * Copyright (C) 2017-2018 Samsung Electronics Co., Ltd.
+ *
+ * Authors:
+ *	Yongmyung Lee <ymhungry.lee@samsung.com>
+ *	Jinyoung Choi <j-young.choi@samsung.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * See the COPYING file in the top-level directory or visit
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This program is provided "AS IS" and "WITH ALL FAULTS" and
+ * without warranty of any kind. You are solely responsible for
+ * determining the appropriateness of using and distributing
+ * the program and assume all risks associated with your exercise
+ * of rights with respect to the program, including but not limited
+ * to infringement of third party rights, the risks and costs of
+ * program errors, damage to or loss of data, programs or equipment,
+ * and unavailability or interruption of operations. Under no
+ * circumstances will the contributor of this Program be liable for
+ * any damages of any kind arising from your use or distribution of
+ * this program.
+ *
+ * The Linux Foundation chooses to take subject only to the GPLv2
+ * license terms, and distributes only under these terms.
+ */
+
+#ifndef _UFSFEATURE_H_
+#define _UFSFEATURE_H_
+
+#define HPB_SUPPORTED_VERSION			0x0310
+#define UFS_FEATURE_SUPPORT_HPB_BIT		0x80
+
+struct ufs_hba;
+struct ufshcd_lrb;
+
+/**
+ * struct ufsf_operation - UFS feature specific callbacks
+ * @prep_fn: called after construct upiu structure
+ * @reset: called after proving hba
+ * @reset_host: called before ufshcd_host_reset_and_restore
+ * @suspend: called before ufshcd_suspend
+ * @resume: called after ufshcd_resume
+ * @rsp_upiu: called in ufshcd_transfer_rsp_status with SAM_STAT_GOOD state
+ */
+struct ufsf_operation {
+	void (*prep_fn)(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
+	void (*reset)(struct ufs_hba *hba);
+	void (*reset_host)(struct ufs_hba *hba);
+	void (*suspend)(struct ufs_hba *hba);
+	void (*resume)(struct ufs_hba *hba);
+	void (*rsp_upiu)(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
+};
+
+struct ufshpb_driver {
+	struct device_driver drv;
+	struct list_head lh_hpb_lu;
+
+	struct ufsf_operation ufshpb_ops;
+
+	/* memory management */
+	struct kmem_cache *ufshpb_mctx_cache;
+	mempool_t *ufshpb_mctx_pool;
+	mempool_t *ufshpb_page_pool;
+
+	struct workqueue_struct *ufshpb_wq;
+};
+
+struct ufsf_feature_info {
+	atomic_t slave_conf_cnt;
+	wait_queue_head_t sdev_wait;
+	struct device hpb_dev;
+};
+
+void ufsf_slave_configure(struct ufs_hba *hba, struct scsi_device *sdev);
+void ufsf_scan_features(struct ufs_hba *hba);
+void ufsf_ops_prep_fn(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
+void ufsf_ops_rsp_upiu(struct ufs_hba *hba, struct ufshcd_lrb *lrbp);
+void ufsf_ops_reset_host(struct ufs_hba *hba);
+void ufsf_ops_reset(struct ufs_hba *hba);
+void ufsf_ops_suspend(struct ufs_hba *hba);
+void ufsf_ops_resume(struct ufs_hba *hba);
+
+#endif /* End of Header */
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index 5db18f444ea9..de57ba2a0b03 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -2525,6 +2525,8 @@  static int ufshcd_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
 
 	ufshcd_comp_scsi_upiu(hba, lrbp);
 
+	ufsf_ops_prep_fn(hba, lrbp);
+
 	err = ufshcd_map_sg(hba, lrbp);
 	if (err) {
 		lrbp->cmd = NULL;
@@ -4645,6 +4647,8 @@  static int ufshcd_slave_configure(struct scsi_device *sdev)
 	struct ufs_hba *hba = shost_priv(sdev->host);
 	struct request_queue *q = sdev->request_queue;
 
+	ufsf_slave_configure(hba, sdev);
+
 	blk_queue_update_dma_pad(q, PRDT_DATA_BYTE_COUNT_PAD - 1);
 
 	if (ufshcd_is_rpm_autosuspend_allowed(hba))
@@ -4765,6 +4769,9 @@  ufshcd_transfer_rsp_status(struct ufs_hba *hba, struct ufshcd_lrb *lrbp)
 				 */
 				pm_runtime_get_noresume(hba->dev);
 			}
+
+			if (scsi_status == SAM_STAT_GOOD)
+				ufsf_ops_rsp_upiu(hba, lrbp);
 			break;
 		case UPIU_TRANSACTION_REJECT_UPIU:
 			/* TODO: handle Reject UPIU Response */
@@ -6508,6 +6515,8 @@  static int ufshcd_host_reset_and_restore(struct ufs_hba *hba)
 	 * Stop the host controller and complete the requests
 	 * cleared by h/w
 	 */
+	ufsf_ops_reset_host(hba);
+
 	ufshcd_hba_stop(hba);
 
 	spin_lock_irqsave(hba->host->host_lock, flags);
@@ -6934,6 +6943,7 @@  static int ufs_get_device_desc(struct ufs_hba *hba)
 	/* getting Specification Version in big endian format */
 	dev_info->wspecversion = desc_buf[DEVICE_DESC_PARAM_SPEC_VER] << 8 |
 				      desc_buf[DEVICE_DESC_PARAM_SPEC_VER + 1];
+	dev_info->b_ufs_feature_sup = desc_buf[DEVICE_DESC_PARAM_UFS_FEAT];
 
 	model_index = desc_buf[DEVICE_DESC_PARAM_PRDCT_NAME];
 
@@ -7350,6 +7360,7 @@  static int ufshcd_add_lus(struct ufs_hba *hba)
 	}
 
 	ufs_bsg_probe(hba);
+	ufsf_scan_features(hba);
 	scsi_scan_host(hba->host);
 	pm_runtime_put_sync(hba->dev);
 
@@ -7442,6 +7453,7 @@  static int ufshcd_probe_hba(struct ufs_hba *hba, bool async)
 	/* Enable Auto-Hibernate if configured */
 	ufshcd_auto_hibern8_enable(hba);
 
+	ufsf_ops_reset(hba);
 out:
 
 	trace_ufshcd_init(dev_name(hba->dev), ret,
@@ -8199,6 +8211,8 @@  static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 		req_link_state = UIC_LINK_OFF_STATE;
 	}
 
+	ufsf_ops_suspend(hba);
+
 	/*
 	 * If we can't transition into any of the low power modes
 	 * just gate the clocks.
@@ -8320,6 +8334,7 @@  static int ufshcd_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 	hba->clk_gating.is_suspended = false;
 	hba->dev_info.b_rpm_dev_flush_capable = false;
 	ufshcd_release(hba);
+	ufsf_ops_resume(hba);
 out:
 	if (hba->dev_info.b_rpm_dev_flush_capable) {
 		schedule_delayed_work(&hba->rpm_dev_flush_recheck_work,
@@ -8416,6 +8431,8 @@  static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 	/* Enable Auto-Hibernate if configured */
 	ufshcd_auto_hibern8_enable(hba);
 
+	ufsf_ops_resume(hba);
+
 	if (hba->dev_info.b_rpm_dev_flush_capable) {
 		hba->dev_info.b_rpm_dev_flush_capable = false;
 		cancel_delayed_work(&hba->rpm_dev_flush_recheck_work);
diff --git a/drivers/scsi/ufs/ufshcd.h b/drivers/scsi/ufs/ufshcd.h
index bf97d616e597..47866ab722ff 100644
--- a/drivers/scsi/ufs/ufshcd.h
+++ b/drivers/scsi/ufs/ufshcd.h
@@ -71,6 +71,7 @@ 
 #include "ufs.h"
 #include "ufs_quirks.h"
 #include "ufshci.h"
+#include "ufsfeature.h"
 
 #define UFSHCD "ufshcd"
 #define UFSHCD_DRIVER_VERSION "0.2"
@@ -746,6 +747,8 @@  struct ufs_hba {
 	bool wb_buf_flush_enabled;
 	bool wb_enabled;
 	struct delayed_work rpm_dev_flush_recheck_work;
+
+	struct ufsf_feature_info ufsf;
 };
 
 /* Returns true if clocks can be gated. Otherwise false */