Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: "Martin K . Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org, Bart Van Assche <bvanassche@acm.org>,
	"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	Peter Wang <peter.wang@mediatek.com>,
	Avri Altman <avri.altman@sandisk.com>,
	Bean Huo <beanhuo@micron.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	"Bao D. Nguyen" <quic_nguyenb@quicinc.com>
Subject: [PATCH 5/7] ufs: core: Remove unused code and data structures
Date: Fri, 16 Jan 2026 10:26:07 -0800	[thread overview]
Message-ID: <20260116182628.3255116-6-bvanassche@acm.org> (raw)
In-Reply-To: <20260116182628.3255116-1-bvanassche@acm.org>

Remove the code and data structures that are no longer used due to patch
"ufs: core: Switch from clock gating to RPM".

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 drivers/ufs/core/ufs_trace.h |  27 -------
 drivers/ufs/core/ufshcd.c    | 152 +----------------------------------
 include/ufs/ufshcd.h         |  33 --------
 3 files changed, 4 insertions(+), 208 deletions(-)

diff --git a/drivers/ufs/core/ufs_trace.h b/drivers/ufs/core/ufs_trace.h
index 309ae51b4906..a8395d97ad77 100644
--- a/drivers/ufs/core/ufs_trace.h
+++ b/drivers/ufs/core/ufs_trace.h
@@ -63,7 +63,6 @@
 
 UFS_LINK_STATES;
 UFS_PWR_MODES;
-UFSCHD_CLK_GATING_STATES;
 UFS_CMD_TRACE_STRINGS
 UFS_CMD_TRACE_TSF_TYPES
 
@@ -81,27 +80,6 @@ UFS_CMD_TRACE_TSF_TYPES
 #define show_ufs_cmd_trace_tsf(tsf)	\
 				__print_symbolic(tsf, UFS_CMD_TRACE_TSF_TYPES)
 
-TRACE_EVENT(ufshcd_clk_gating,
-
-	TP_PROTO(struct ufs_hba *hba, int state),
-
-	TP_ARGS(hba, state),
-
-	TP_STRUCT__entry(
-		__field(struct ufs_hba *, hba)
-		__field(int, state)
-	),
-
-	TP_fast_assign(
-		__entry->hba = hba;
-		__entry->state = state;
-	),
-
-	TP_printk("%s: gating state changed to %s",
-		dev_name(__entry->hba->dev),
-		__print_symbolic(__entry->state, UFSCHD_CLK_GATING_STATES))
-);
-
 TRACE_EVENT(ufshcd_clk_scaling,
 
 	TP_PROTO(struct ufs_hba *hba, const char *state, const char *clk,
@@ -180,11 +158,6 @@ DEFINE_EVENT(ufshcd_profiling_template, ufshcd_profile_hibern8,
 		 int err),
 	TP_ARGS(hba, profile_info, time_us, err));
 
-DEFINE_EVENT(ufshcd_profiling_template, ufshcd_profile_clk_gating,
-	TP_PROTO(struct ufs_hba *hba, const char *profile_info, s64 time_us,
-		 int err),
-	TP_ARGS(hba, profile_info, time_us, err));
-
 DEFINE_EVENT(ufshcd_profiling_template, ufshcd_profile_clk_scaling,
 	TP_PROTO(struct ufs_hba *hba, const char *profile_info, s64 time_us,
 		 int err),
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index b3d75152abd9..1189a9fd39ff 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -689,7 +689,6 @@ static void ufshcd_print_host_state(struct ufs_hba *hba)
 		hba->pm_op_in_progress, hba->is_sys_suspended);
 	dev_err(hba->dev, "Auto BKOPS=%d, Host self-block=%d\n",
 		hba->auto_bkops_enabled, hba->host->host_self_blocked);
-	dev_err(hba->dev, "Clk gate=%d\n", hba->clk_gating.state);
 	dev_err(hba->dev,
 		"last_hibern8_exit_tstamp at %lld us, hibern8_exit_cnt=%d\n",
 		div_u64(hba->ufs_stats.last_hibern8_exit_tstamp, 1000),
@@ -1895,40 +1894,6 @@ static void ufshcd_exit_clk_scaling(struct ufs_hba *hba)
 	hba->clk_scaling.is_initialized = false;
 }
 
-static void ufshcd_ungate_work(struct work_struct *work)
-{
-	int ret;
-	struct ufs_hba *hba = container_of(work, struct ufs_hba,
-			clk_gating.ungate_work);
-
-	cancel_delayed_work_sync(&hba->clk_gating.gate_work);
-
-	scoped_guard(spinlock_irqsave, &hba->clk_gating.lock) {
-		if (hba->clk_gating.state == CLKS_ON)
-			return;
-	}
-
-	ufshcd_hba_vreg_set_hpm(hba);
-	ufshcd_setup_clocks(hba, true);
-
-	ufshcd_enable_irq(hba);
-
-	/* Exit from hibern8 */
-	if (ufshcd_can_hibern8_during_gating(hba)) {
-		/* Prevent gating in this path */
-		hba->clk_gating.is_suspended = true;
-		if (ufshcd_is_link_hibern8(hba)) {
-			ret = ufshcd_uic_hibern8_exit(hba);
-			if (ret)
-				dev_err(hba->dev, "%s: hibern8 exit failed %d\n",
-					__func__, ret);
-			else
-				ufshcd_set_link_active(hba);
-		}
-		hba->clk_gating.is_suspended = false;
-	}
-}
-
 /**
  * ufshcd_hold - Enable clocks that were gated earlier due to ufshcd_release.
  * Also, exit from hibern8 mode and set the link as active.
@@ -1943,74 +1908,6 @@ void ufshcd_hold(struct ufs_hba *hba)
 }
 EXPORT_SYMBOL_GPL(ufshcd_hold);
 
-static void ufshcd_gate_work(struct work_struct *work)
-{
-	struct ufs_hba *hba = container_of(work, struct ufs_hba,
-			clk_gating.gate_work.work);
-	int ret;
-
-	scoped_guard(spinlock_irqsave, &hba->clk_gating.lock) {
-		/*
-		 * In case you are here to cancel this work the gating state
-		 * would be marked as REQ_CLKS_ON. In this case save time by
-		 * skipping the gating work and exit after changing the clock
-		 * state to CLKS_ON.
-		 */
-		if (hba->clk_gating.is_suspended ||
-		    hba->clk_gating.state != REQ_CLKS_OFF) {
-			hba->clk_gating.state = CLKS_ON;
-			trace_ufshcd_clk_gating(hba,
-						hba->clk_gating.state);
-			return;
-		}
-
-		if (hba->clk_gating.active_reqs)
-			return;
-	}
-
-	scoped_guard(spinlock_irqsave, hba->host->host_lock) {
-		if (ufshcd_is_ufs_dev_busy(hba) ||
-		    hba->ufshcd_state != UFSHCD_STATE_OPERATIONAL)
-			return;
-	}
-
-	/* put the link into hibern8 mode before turning off clocks */
-	if (ufshcd_can_hibern8_during_gating(hba)) {
-		ret = ufshcd_uic_hibern8_enter(hba);
-		if (ret) {
-			hba->clk_gating.state = CLKS_ON;
-			dev_err(hba->dev, "%s: hibern8 enter failed %d\n",
-					__func__, ret);
-			trace_ufshcd_clk_gating(hba,
-						hba->clk_gating.state);
-			return;
-		}
-		ufshcd_set_link_hibern8(hba);
-	}
-
-	ufshcd_disable_irq(hba);
-
-	ufshcd_setup_clocks(hba, false);
-
-	/* Put the host controller in low power mode if possible */
-	ufshcd_hba_vreg_set_lpm(hba);
-	/*
-	 * In case you are here to cancel this work the gating state
-	 * would be marked as REQ_CLKS_ON. In this case keep the state
-	 * as REQ_CLKS_ON which would anyway imply that clocks are off
-	 * and a request to turn them on is pending. By doing this way,
-	 * we keep the state machine in tact and this would ultimately
-	 * prevent from doing cancel work multiple times when there are
-	 * new requests arriving before the current cancel work is done.
-	 */
-	guard(spinlock_irqsave)(&hba->clk_gating.lock);
-	if (hba->clk_gating.state == REQ_CLKS_OFF) {
-		hba->clk_gating.state = CLKS_OFF;
-		trace_ufshcd_clk_gating(hba,
-					hba->clk_gating.state);
-	}
-}
-
 void ufshcd_release(struct ufs_hba *hba)
 {
 	/* blk_pm_runtime_init() sets q->dev */
@@ -2127,19 +2024,8 @@ static void ufshcd_init_clk_gating(struct ufs_hba *hba)
 	if (!ufshcd_is_clkgating_allowed(hba))
 		return;
 
-	hba->clk_gating.state = CLKS_ON;
-
-	hba->clk_gating.delay_ms = 150;
-	INIT_DELAYED_WORK(&hba->clk_gating.gate_work, ufshcd_gate_work);
-	INIT_WORK(&hba->clk_gating.ungate_work, ufshcd_ungate_work);
-
-	hba->clk_gating.clk_gating_workq = alloc_ordered_workqueue(
-		"ufs_clk_gating_%d", WQ_MEM_RECLAIM | WQ_HIGHPRI,
-		hba->host->host_no);
-
 	ufshcd_init_clk_gating_sysfs(hba);
 
-	hba->clk_gating.is_enabled = true;
 	hba->clk_gating.is_initialized = true;
 }
 
@@ -2154,8 +2040,6 @@ static void ufshcd_exit_clk_gating(struct ufs_hba *hba)
 	ufshcd_hold(hba);
 	hba->clk_gating.is_initialized = false;
 	ufshcd_release(hba);
-
-	destroy_workqueue(hba->clk_gating.clk_gating_workq);
 }
 
 static void ufshcd_clk_scaling_start_busy(struct ufs_hba *hba)
@@ -8407,8 +8291,7 @@ static void ufshcd_rtc_work(struct work_struct *work)
 
 	 /* Update RTC only when there are no requests in progress and UFSHCI is operational */
 	if (!ufshcd_is_ufs_dev_busy(hba) &&
-	    hba->ufshcd_state == UFSHCD_STATE_OPERATIONAL &&
-	    !hba->clk_gating.active_reqs)
+	    hba->ufshcd_state == UFSHCD_STATE_OPERATIONAL)
 		ufshcd_update_rtc(hba);
 
 	if (ufshcd_is_ufs_dev_active(hba) && hba->dev_info.rtc_update_period)
@@ -9420,7 +9303,6 @@ static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
 	int ret = 0;
 	struct ufs_clk_info *clki;
 	struct list_head *head = &hba->clk_list_head;
-	ktime_t start = ktime_get();
 	bool clk_state_changed = false;
 
 	if (list_empty(head))
@@ -9469,17 +9351,8 @@ static int ufshcd_setup_clocks(struct ufs_hba *hba, bool on)
 			if (!IS_ERR_OR_NULL(clki->clk) && clki->enabled)
 				clk_disable_unprepare(clki->clk);
 		}
-	} else if (!ret && on && hba->clk_gating.is_initialized) {
-		scoped_guard(spinlock_irqsave, &hba->clk_gating.lock)
-			hba->clk_gating.state = CLKS_ON;
-		trace_ufshcd_clk_gating(hba,
-					hba->clk_gating.state);
 	}
 
-	if (clk_state_changed)
-		trace_ufshcd_profile_clk_gating(hba,
-			(on ? "on" : "off"),
-			ktime_to_us(ktime_sub(ktime_get(), start)), ret);
 	return ret;
 }
 
@@ -9913,9 +9786,6 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 	 * If we can't transition into any of the low power modes
 	 * just gate the clocks.
 	 */
-	ufshcd_hold(hba);
-	hba->clk_gating.is_suspended = true;
-
 	if (ufshcd_is_clkscaling_supported(hba))
 		ufshcd_clk_scaling_suspend(hba, true);
 
@@ -10063,11 +9933,9 @@ static int __ufshcd_wl_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 			msecs_to_jiffies(RPM_DEV_FLUSH_RECHECK_WORK_DELAY_MS));
 	}
 
-	if (ret) {
+	if (ret)
 		ufshcd_update_evt_hist(hba, UFS_EVT_WL_SUSP_ERR, (u32)ret);
-		hba->clk_gating.is_suspended = false;
-		ufshcd_release(hba);
-	}
+
 	hba->pm_op_in_progress = false;
 	return ret;
 }
@@ -10158,8 +10026,7 @@ static int __ufshcd_wl_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 out:
 	if (ret)
 		ufshcd_update_evt_hist(hba, UFS_EVT_WL_RES_ERR, (u32)ret);
-	hba->clk_gating.is_suspended = false;
-	ufshcd_release(hba);
+
 	hba->pm_op_in_progress = false;
 	return ret;
 }
@@ -10288,11 +10155,6 @@ static int ufshcd_suspend(struct ufs_hba *hba)
 		ufshcd_enable_irq(hba);
 		return ret;
 	}
-	if (ufshcd_is_clkgating_allowed(hba)) {
-		hba->clk_gating.state = CLKS_OFF;
-		trace_ufshcd_clk_gating(hba,
-					hba->clk_gating.state);
-	}
 
 	ufshcd_vreg_set_lpm(hba);
 	/* Put the host controller in low power mode if possible */
@@ -10751,12 +10613,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
 	hba->irq = irq;
 	hba->vps = &ufs_hba_vps;
 
-	/*
-	 * Initialize clk_gating.lock early since it is being used in
-	 * ufshcd_setup_clocks()
-	 */
-	spin_lock_init(&hba->clk_gating.lock);
-
 	/* Initialize mutex for PM QoS request synchronization */
 	mutex_init(&hba->pm_qos_mutex);
 
diff --git a/include/ufs/ufshcd.h b/include/ufs/ufshcd.h
index dac07a5cd998..69e86185e652 100644
--- a/include/ufs/ufshcd.h
+++ b/include/ufs/ufshcd.h
@@ -382,49 +382,16 @@ struct ufs_hba_variant_ops {
 	u32	(*freq_to_gear_speed)(struct ufs_hba *hba, unsigned long freq);
 };
 
-/* clock gating state  */
-enum clk_gating_state {
-	CLKS_OFF,
-	CLKS_ON,
-	REQ_CLKS_OFF,
-	REQ_CLKS_ON,
-};
-
 /**
  * struct ufs_clk_gating - UFS clock gating related info
- * @gate_work: worker to turn off clocks after some delay as specified in
- * delay_ms
- * @ungate_work: worker to turn on clocks that will be used in case of
- * interrupt context
- * @clk_gating_workq: workqueue for clock gating work.
- * @lock: serialize access to some struct ufs_clk_gating members. An outer lock
- * relative to the host lock
- * @state: the current clocks state
- * @delay_ms: gating delay in ms
- * @is_suspended: clk gating is suspended when set to 1 which can be used
- * during suspend/resume
  * @delay_attr: sysfs attribute to control delay_attr
  * @enable_attr: sysfs attribute to enable/disable clock gating
- * @is_enabled: Indicates the current status of clock gating
  * @is_initialized: Indicates whether clock gating is initialized or not
- * @active_reqs: number of requests that are pending and should be waited for
- * completion before gating clocks.
  */
 struct ufs_clk_gating {
-	struct delayed_work gate_work;
-	struct work_struct ungate_work;
-	struct workqueue_struct *clk_gating_workq;
-
-	spinlock_t lock;
-
-	enum clk_gating_state state;
-	unsigned long delay_ms;
-	bool is_suspended;
 	struct device_attribute delay_attr;
 	struct device_attribute enable_attr;
-	bool is_enabled;
 	bool is_initialized;
-	int active_reqs;
 };
 
 /**

  parent reply	other threads:[~2026-01-16 18:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-16 18:26 [PATCH 0/7] ufs: Remove the clock gating code Bart Van Assche
2026-01-16 18:26 ` [PATCH 1/7] ufs: core: Change the type of an ufshcd_clkgate_delay_set() argument Bart Van Assche
2026-01-16 18:26 ` [PATCH 2/7] ufs: host: mediatek: Use ufshcd_clkgate_delay_set() Bart Van Assche
2026-01-16 18:26 ` [PATCH 3/7] ufs: core: Redirect clock gating to RPM Bart Van Assche
2026-01-17  2:05   ` kernel test robot
2026-01-17  2:16   ` kernel test robot
2026-01-16 18:26 ` [PATCH 4/7] ufs: core: Switch from " Bart Van Assche
2026-01-16 18:26 ` Bart Van Assche [this message]
2026-01-17  2:16   ` [PATCH 5/7] ufs: core: Remove unused code and data structures kernel test robot
2026-01-16 18:26 ` [PATCH 6/7] ufs: core: Remove superfluous ufshcd_{hold,release}() calls Bart Van Assche
2026-01-16 18:26 ` [PATCH 7/7] ufs: core: Remove ufshcd_{hold,release}() calls from the I/O path Bart Van Assche
2026-01-22 17:30 ` [PATCH 0/7] ufs: Remove the clock gating code Manivannan Sadhasivam
2026-01-23  7:26   ` Peter Wang (王信友)
2026-01-23 23:27     ` Bart Van Assche
2026-01-26  3:44       ` Peter Wang (王信友)
2026-01-26 22:27         ` Bart Van Assche

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=20260116182628.3255116-6-bvanassche@acm.org \
    --to=bvanassche@acm.org \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=adrian.hunter@intel.com \
    --cc=avri.altman@sandisk.com \
    --cc=beanhuo@micron.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=peter.wang@mediatek.com \
    --cc=quic_nguyenb@quicinc.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