Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
To: lgirdwood@gmail.com, broonie@kernel.org,
	pierre-louis.bossart@linux.intel.com
Cc: guennadi.liakhovetski@linux.intel.com,
	alsa-devel@alsa-project.org, ranjani.sridharan@linux.intel.com,
	kai.vehmanen@linux.intel.com
Subject: [PATCH 14/19] ASoC: SOF: Introduce macro to set the firmware state
Date: Wed,  6 Oct 2021 14:06:40 +0300	[thread overview]
Message-ID: <20211006110645.26679-15-peter.ujfalusi@linux.intel.com> (raw)
In-Reply-To: <20211006110645.26679-1-peter.ujfalusi@linux.intel.com>

Add sof_set_fw_state() macro to wrap the sdev->fw_state management to allow
actions to be taken when certain state is set or when state is changing.

Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
---
 sound/soc/sof/core.c     |  8 ++++----
 sound/soc/sof/ipc.c      |  4 ++--
 sound/soc/sof/loader.c   |  2 +-
 sound/soc/sof/pm.c       |  6 +++---
 sound/soc/sof/sof-priv.h | 13 +++++++++++++
 5 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/sound/soc/sof/core.c b/sound/soc/sof/core.c
index 2ea29186e397..22a1c5090ae0 100644
--- a/sound/soc/sof/core.c
+++ b/sound/soc/sof/core.c
@@ -147,7 +147,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 		return ret;
 	}
 
-	sdev->fw_state = SOF_FW_BOOT_PREPARE;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
 
 	/* check machine info */
 	ret = sof_machine_check(sdev);
@@ -189,7 +189,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 		goto fw_load_err;
 	}
 
-	sdev->fw_state = SOF_FW_BOOT_IN_PROGRESS;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_IN_PROGRESS);
 
 	/*
 	 * Boot the firmware. The FW boot status will be modified
@@ -265,7 +265,7 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
 	snd_sof_remove(sdev);
 
 	/* all resources freed, update state to match */
-	sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 	sdev->first_boot = true;
 
 	return ret;
@@ -300,7 +300,7 @@ int snd_sof_device_probe(struct device *dev, struct snd_sof_pdata *plat_data)
 
 	sdev->pdata = plat_data;
 	sdev->first_boot = true;
-	sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 #if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_PROBES)
 	sdev->extractor_stream_tag = SOF_PROBE_INVALID_NODE_ID;
 #endif
diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c
index 5c698fa662f4..5a308c62f7ca 100644
--- a/sound/soc/sof/ipc.c
+++ b/sound/soc/sof/ipc.c
@@ -458,9 +458,9 @@ void snd_sof_ipc_msgs_rx(struct snd_sof_dev *sdev)
 		if (sdev->fw_state == SOF_FW_BOOT_IN_PROGRESS) {
 			err = sof_ops(sdev)->fw_ready(sdev, cmd);
 			if (err < 0)
-				sdev->fw_state = SOF_FW_BOOT_READY_FAILED;
+				sof_set_fw_state(sdev, SOF_FW_BOOT_READY_FAILED);
 			else
-				sdev->fw_state = SOF_FW_BOOT_COMPLETE;
+				sof_set_fw_state(sdev, SOF_FW_BOOT_COMPLETE);
 
 			/* wake up firmware loader */
 			wake_up(&sdev->boot_wait);
diff --git a/sound/soc/sof/loader.c b/sound/soc/sof/loader.c
index a0ae174f9bb0..de7082f3226c 100644
--- a/sound/soc/sof/loader.c
+++ b/sound/soc/sof/loader.c
@@ -838,7 +838,7 @@ int snd_sof_run_firmware(struct snd_sof_dev *sdev)
 		dev_err(sdev->dev, "error: firmware boot failure\n");
 		snd_sof_dsp_dbg_dump(sdev, SOF_DBG_DUMP_REGS | SOF_DBG_DUMP_MBOX |
 				     SOF_DBG_DUMP_TEXT | SOF_DBG_DUMP_PCI);
-		sdev->fw_state = SOF_FW_BOOT_FAILED;
+		sof_set_fw_state(sdev, SOF_FW_BOOT_FAILED);
 		return -EIO;
 	}
 
diff --git a/sound/soc/sof/pm.c b/sound/soc/sof/pm.c
index 77a3496d3dbd..bf759bfa305e 100644
--- a/sound/soc/sof/pm.c
+++ b/sound/soc/sof/pm.c
@@ -122,7 +122,7 @@ static int sof_resume(struct device *dev, bool runtime_resume)
 	    old_state == SOF_DSP_PM_D0)
 		return 0;
 
-	sdev->fw_state = SOF_FW_BOOT_PREPARE;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_PREPARE);
 
 	/* load the firmware */
 	ret = snd_sof_load_firmware(sdev);
@@ -133,7 +133,7 @@ static int sof_resume(struct device *dev, bool runtime_resume)
 		return ret;
 	}
 
-	sdev->fw_state = SOF_FW_BOOT_IN_PROGRESS;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_IN_PROGRESS);
 
 	/*
 	 * Boot the firmware. The FW boot status will be modified
@@ -257,7 +257,7 @@ static int sof_suspend(struct device *dev, bool runtime_suspend)
 		return ret;
 
 	/* reset FW state */
-	sdev->fw_state = SOF_FW_BOOT_NOT_STARTED;
+	sof_set_fw_state(sdev, SOF_FW_BOOT_NOT_STARTED);
 	sdev->enabled_cores_mask = 0;
 
 	return ret;
diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h
index 5c1939339936..d9525f3ff5cd 100644
--- a/sound/soc/sof/sof-priv.h
+++ b/sound/soc/sof/sof-priv.h
@@ -561,6 +561,19 @@ static inline void sof_oops(struct snd_sof_dev *sdev, void *oops)
 
 extern const struct dsp_arch_ops sof_xtensa_arch_ops;
 
+/*
+ * Firmware state tracking
+ */
+static inline void sof_set_fw_state(struct snd_sof_dev *sdev,
+				    enum snd_sof_fw_state new_state)
+{
+	if (sdev->fw_state == new_state)
+		return;
+
+	dev_dbg(sdev->dev, "fw_state change: %d -> %d\n", sdev->fw_state, new_state);
+	sdev->fw_state = new_state;
+}
+
 /*
  * Utilities
  */
-- 
2.33.0


  parent reply	other threads:[~2021-10-06 11:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-06 11:06 [PATCH 00/19] ASoC: SOF: Improvements for debugging Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 01/19] ASoC: SOF: core: debug: force all processing on primary core Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 02/19] ASoC: SOF: debug: Swap the dsp_dump and ipc_dump sequence for fw_exception Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 03/19] ASoC: SOF: ipc and dsp dump: Add markers for better visibility Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 04/19] ASoC: SOF: Print the dbg_dump and ipc_dump once to reduce kernel log noise Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 05/19] ASoC: SOF: loader: Print the DSP dump if boot fails Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 06/19] ASoC: SOF: intel: atom: No need to do a DSP dump in atom_run() Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 07/19] ASoC: SOF: debug/ops: Move the IPC and DSP dump functions out from the header Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 08/19] ASoC: SOF: debug: Add SOF_DBG_DUMP_OPTIONAL flag for DSP dumping Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 09/19] ASoC: SOF: intel: hda-loader: Use snd_sof_dsp_dbg_dump() for DSP dump Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 10/19] ASoC: SOF: Drop SOF_DBG_DUMP_FORCE_ERR_LEVEL and sof_dev_dbg_or_err Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 11/19] ASoC: SOF: debug: Print out the fw_state along with the DSP dump Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 12/19] ASoC: SOF: ipc: Re-enable dumps after successful IPC tx Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 13/19] ASoC: SOF: ops: Force DSP panic dumps to be printed Peter Ujfalusi
2021-10-06 11:06 ` Peter Ujfalusi [this message]
2021-10-06 11:06 ` [PATCH 15/19] ASoC: SOF: intel: hda: Drop 'error' prefix from error dump functions Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 16/19] ASoC: SOF: core: Clean up snd_sof_get_status() prints Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 17/19] ASoC: SOF: loader: Drop SOF_DBG_DUMP_REGS flag when firmware start fails Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 18/19] ASoC: SOF: Intel: hda-loader: Drop SOF_DBG_DUMP_REGS flag from dbg_dump calls Peter Ujfalusi
2021-10-06 11:06 ` [PATCH 19/19] ASoC: SOF: Intel: hda: Dump registers and stack when SOF_DBG_DUMP_REGS is set Peter Ujfalusi
2021-10-06 11:23 ` [PATCH 00/19] ASoC: SOF: Improvements for debugging Mark Brown
2021-10-06 12:32   ` Pierre-Louis Bossart
2021-10-07  6:42   ` Péter Ujfalusi
2021-10-07  6:46   ` Péter Ujfalusi
2021-10-07 21:37 ` Mark Brown

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=20211006110645.26679-15-peter.ujfalusi@linux.intel.com \
    --to=peter.ujfalusi@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=guennadi.liakhovetski@linux.intel.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.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