Skip to contentSkip to conversation

scsi: ufs: Split struct ufs_hba

PATCH New Bart Van Assche 1 participant 1 message May 31, 2022

Subsystems (2)
lore
Share & tools
lore

Bart Van Assche

author reviewer
#0 lore raw

PATCH 1/1 scsi: ufs: Split struct ufs_hba

Improve separation between UFSHCI core and host drivers by splitting struct ufs_hba. This patch does not change the behavior of the UFS driver. The conversions between the struct ufs_hba and the struct ufs_hba_priv pointer types do not introduce any overhead since the compiler can optimize these out.

Cc Adrian Hunter <[email protected]>
Cc Avri Altman <[email protected]>
Cc Bean Huo <[email protected]>
Cc Bjorn Andersson <[email protected]>
Cc Keoseong Park <[email protected]>
Cc Eric Biggers <[email protected]>
---
 drivers/ufs/core/ufs-debugfs.c   |   79 +-
 drivers/ufs/core/ufs-hwmon.c     |   42 +-
 drivers/ufs/core/ufs-sysfs.c     |  141 ++-
 drivers/ufs/core/ufs_bsg.c       |   14 +-
 drivers/ufs/core/ufshcd-crypto.c |   49 +-
 drivers/ufs/core/ufshcd-priv.h   |  229 +++-
 drivers/ufs/core/ufshcd.c        | 1782 ++++++++++++++++--------------
 drivers/ufs/core/ufshpb.c        |   40 +-
 include/ufs/ufshcd.h             |  175 +--
 9 files changed, 1409 insertions(+), 1142 deletions(-)
drivers/ufs/core/ufs-debugfs.c +47 -32
index e3baed6c70bd..12ff7bdf84aa 100644
@@ -34,7 +34,8 @@ void ufs_debugfs_exit(void)
 static int ufs_debugfs_stats_show(struct seq_file *s, void *data)
 {
 	struct ufs_hba *hba = hba_from_file(s->file);
-	struct ufs_event_hist *e = hba->ufs_stats.event;
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
+	struct ufs_event_hist *e = priv->ufs_stats.event;
 
 #define PRT(fmt, typ) \
 	seq_printf(s, fmt, e[UFS_EVT_ ## typ].cnt)
@@ -60,17 +61,20 @@ DEFINE_SHOW_ATTRIBUTE(ufs_debugfs_stats);
 static int ee_usr_mask_get(void *data, u64 *val)
 {
 	struct ufs_hba *hba = data;
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
 
-	*val = hba->ee_usr_mask;
+	*val = priv->ee_usr_mask;
 	return 0;
 }
 
 static int ufs_debugfs_get_user_access(struct ufs_hba *hba)
-__acquires(&hba->host_sem)
+	__acquires(&priv->host_sem)
 {
-	down(&hba->host_sem);
-	if (!ufshcd_is_user_access_allowed(hba)) {
-		up(&hba->host_sem);
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
+
+	down(&priv->host_sem);
+	if (!ufshcd_is_user_access_allowed(priv)) {
+		up(&priv->host_sem);
 		return -EBUSY;
 	}
 	ufshcd_rpm_get_sync(hba);
@@ -78,15 +82,18 @@ __acquires(&hba->host_sem)
 }
 
 static void ufs_debugfs_put_user_access(struct ufs_hba *hba)
-__releases(&hba->host_sem)
+	__releases(&priv->host_sem)
 {
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
+
 	ufshcd_rpm_put_sync(hba);
-	up(&hba->host_sem);
+	up(&priv->host_sem);
 }
 
 static int ee_usr_mask_set(void *data, u64 val)
 {
 	struct ufs_hba *hba = data;
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
 	int err;
 
 	if (val & ~(u64)MASK_EE_STATUS)
@@ -94,7 +101,7 @@ static int ee_usr_mask_set(void *data, u64 val)
 	err = ufs_debugfs_get_user_access(hba);
 	if (err)
 		return err;
-	err = ufshcd_update_ee_usr_mask(hba, val, MASK_EE_STATUS);
+	err = ufshcd_update_ee_usr_mask(priv, val, MASK_EE_STATUS);
 	ufs_debugfs_put_user_access(hba);
 	return err;
 }
@@ -103,36 +110,39 @@ DEFINE_DEBUGFS_ATTRIBUTE(ee_usr_mask_fops, ee_usr_mask_get, ee_usr_mask_set, "%#
 
 void ufs_debugfs_exception_event(struct ufs_hba *hba, u16 status)
 {
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
 	bool chgd = false;
 	u16 ee_ctrl_mask;
 	int err = 0;
 
-	if (!hba->debugfs_ee_rate_limit_ms || !status)
+	if (!priv->debugfs_ee_rate_limit_ms || !status)
 		return;
 
-	mutex_lock(&hba->ee_ctrl_mutex);
-	ee_ctrl_mask = hba->ee_drv_mask | (hba->ee_usr_mask & ~status);
-	chgd = ee_ctrl_mask != hba->ee_ctrl_mask;
+	mutex_lock(&priv->ee_ctrl_mutex);
+	ee_ctrl_mask = priv->ee_drv_mask | (priv->ee_usr_mask & ~status);
+	chgd = ee_ctrl_mask != priv->ee_ctrl_mask;
 	if (chgd) {
 		err = __ufshcd_write_ee_control(hba, ee_ctrl_mask);
 		if (err)
 			dev_err(hba->dev, "%s: failed to write ee control %d\n",
 				__func__, err);
 	}
-	mutex_unlock(&hba->ee_ctrl_mutex);
+	mutex_unlock(&priv->ee_ctrl_mutex);
 
 	if (chgd && !err) {
-		unsigned long delay = msecs_to_jiffies(hba->debugfs_ee_rate_limit_ms);
+		unsigned long delay = msecs_to_jiffies(priv->debugfs_ee_rate_limit_ms);
 
-		queue_delayed_work(system_freezable_wq, &hba->debugfs_ee_work, delay);
+		queue_delayed_work(system_freezable_wq, &priv->debugfs_ee_work, delay);
 	}
 }
 
 static void ufs_debugfs_restart_ee(struct work_struct *work)
 {
-	struct ufs_hba *hba = container_of(work, struct ufs_hba, debugfs_ee_work.work);
+	struct ufs_hba_priv *priv = container_of(work, struct ufs_hba_priv,
+						 debugfs_ee_work.work);
+	struct ufs_hba *hba = &priv->hba;
 
-	if (!hba->ee_usr_mask || pm_runtime_suspended(hba->dev) ||
+	if (!priv->ee_usr_mask || pm_runtime_suspended(hba->dev) ||
 	    ufs_debugfs_get_user_access(hba))
 		return;
 	ufshcd_write_ee_control(hba);
@@ -143,12 +153,13 @@ static int ufs_saved_err_show(struct seq_file *s, void *data)
 {
 	struct ufs_debugfs_attr *attr = s->private;
 	struct ufs_hba *hba = hba_from_file(s->file);
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
 	const int *p;
 
 	if (strcmp(attr->name, "saved_err") == 0) {
-		p = &hba->saved_err;
+		p = &priv->saved_err;
 	} else if (strcmp(attr->name, "saved_uic_err") == 0) {
-		p = &hba->saved_uic_err;
+		p = &priv->saved_uic_err;
 	} else {
 		return -ENOENT;
 	}
@@ -162,6 +173,7 @@ static ssize_t ufs_saved_err_write(struct file *file, const char __user *buf,
 {
 	struct ufs_debugfs_attr *attr = file->f_inode->i_private;
 	struct ufs_hba *hba = hba_from_file(file);
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
 	char val_str[16] = { };
 	int val, ret;
 
@@ -173,17 +185,17 @@ static ssize_t ufs_saved_err_write(struct file *file, const char __user *buf,
 	if (ret < 0)
 		return ret;
 
-	spin_lock_irq(hba->host->host_lock);
+	spin_lock_irq(priv->host->host_lock);
 	if (strcmp(attr->name, "saved_err") == 0) {
-		hba->saved_err = val;
+		priv->saved_err = val;
 	} else if (strcmp(attr->name, "saved_uic_err") == 0) {
-		hba->saved_uic_err = val;
+		priv->saved_uic_err = val;
 	} else {
 		ret = -ENOENT;
 	}
 	if (ret == 0)
 		ufshcd_schedule_eh_work(hba);
-	spin_unlock_irq(hba->host->host_lock);
+	spin_unlock_irq(priv->host->host_lock);
 
 	return ret < 0 ? ret : count;
 }
@@ -211,29 +223,32 @@ static const struct ufs_debugfs_attr ufs_attrs[] = {
 
 void ufs_debugfs_hba_init(struct ufs_hba *hba)
 {
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
 	const struct ufs_debugfs_attr *attr;
 	struct dentry *root;
 
 	/* Set default exception event rate limit period to 20ms */
-	hba->debugfs_ee_rate_limit_ms = 20;
-	INIT_DELAYED_WORK(&hba->debugfs_ee_work, ufs_debugfs_restart_ee);
+	priv->debugfs_ee_rate_limit_ms = 20;
+	INIT_DELAYED_WORK(&priv->debugfs_ee_work, ufs_debugfs_restart_ee);
 
 	root = debugfs_create_dir(dev_name(hba->dev), ufs_debugfs_root);
 	if (IS_ERR_OR_NULL(root))
 		return;
-	hba->debugfs_root = root;
+	priv->debugfs_root = root;
 	d_inode(root)->i_private = hba;
 	for (attr = ufs_attrs; attr->name; attr++)
 		debugfs_create_file(attr->name, attr->mode, root, (void *)attr,
 				    attr->fops);
-	debugfs_create_file("exception_event_mask", 0600, hba->debugfs_root,
+	debugfs_create_file("exception_event_mask", 0600, priv->debugfs_root,
 			    hba, &ee_usr_mask_fops);
-	debugfs_create_u32("exception_event_rate_limit_ms", 0600, hba->debugfs_root,
-			   &hba->debugfs_ee_rate_limit_ms);
+	debugfs_create_u32("exception_event_rate_limit_ms", 0600, priv->debugfs_root,
+			   &priv->debugfs_ee_rate_limit_ms);
 }
 
 void ufs_debugfs_hba_exit(struct ufs_hba *hba)
 {
-	debugfs_remove_recursive(hba->debugfs_root);
-	cancel_delayed_work_sync(&hba->debugfs_ee_work);
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
+
+	debugfs_remove_recursive(priv->debugfs_root);
+	cancel_delayed_work_sync(&priv->debugfs_ee_work);
 }
drivers/ufs/core/ufs-hwmon.c +24 -18

108 lines not on this page · raw message

drivers/ufs/core/ufs-sysfs.c +85 -56

447 lines not on this page · raw message

drivers/ufs/core/ufs_bsg.c +8 -6
index b99e3f3dc4ef..abfc4a827c31 100644
@@ -175,12 +175,13 @@ static int ufs_bsg_request(struct bsg_job *job)
  */
 void ufs_bsg_remove(struct ufs_hba *hba)
 {
-	struct device *bsg_dev = &hba->bsg_dev;
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
+	struct device *bsg_dev = &priv->bsg_dev;
 
-	if (!hba->bsg_queue)
+	if (!priv->bsg_queue)
 		return;
 
-	bsg_remove_queue(hba->bsg_queue);
+	bsg_remove_queue(priv->bsg_queue);
 
 	device_del(bsg_dev);
 	put_device(bsg_dev);
@@ -199,8 +200,9 @@ static inline void ufs_bsg_node_release(struct device *dev)
  */
 int ufs_bsg_probe(struct ufs_hba *hba)
 {
-	struct device *bsg_dev = &hba->bsg_dev;
-	struct Scsi_Host *shost = hba->host;
+	struct ufs_hba_priv *priv = container_of(hba, typeof(*priv), hba);
+	struct device *bsg_dev = &priv->bsg_dev;
+	struct Scsi_Host *shost = priv->host;
 	struct device *parent = &shost->shost_gendev;
 	struct request_queue *q;
 	int ret;
@@ -222,7 +224,7 @@ int ufs_bsg_probe(struct ufs_hba *hba)
 		goto out;
 	}
 
-	hba->bsg_queue = q;
+	priv->bsg_queue = q;
 
 	return 0;
 
drivers/ufs/core/ufshcd-crypto.c +29 -20

135 lines not on this page · raw message

drivers/ufs/core/ufshcd-priv.h +214 -15

269 lines not on this page · raw message

drivers/ufs/core/ufshcd.c +974 -808

1,813 lines not on this page · raw message

drivers/ufs/core/ufshpb.c +27 -13
index aee0ec4cee70..298f88c89b21 100644

Lines of this file are not shown. View the raw message.

include/ufs/ufshcd.h +1 -174

175 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.