Unverified Commit 2ab4c50f authored by Pierre-Louis Bossart's avatar Pierre-Louis Bossart Committed by Mark Brown
Browse files

ASoC: SOF: trace: move to opt-in with Kconfig and module parameter



In a number of debug cases, the DMA-based trace can add problems
(e.g. with HDaudio channel allocation). It also generates additional
traffic on the bus and if the DMA handling is unreliable will prevent
audio use-cases from working normally. Using the trace also requires
tools to be installed on the target.

The trace can be instead handled as dynamic debug. We can use a
Kconfig to force the trace to be enabled in all cases, or use a module
parameter to enable it on a need-basis, e.g. by setting "options
snd_sof sof_debug=0x1" in a /etc/modprobe.d file.

Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20190927200538.660-4-pierre-louis.bossart@linux.intel.com


Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 767b0bc5
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -142,6 +142,14 @@ config SND_SOC_SOF_DEBUG_ENABLE_DEBUGFS_CACHE
	  Say Y if you want to enable caching the memory windows.
	  If unsure, select "N".

config SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE
	bool "SOF enable firmware trace"
	help
	  The firmware trace can be enabled either at build-time with
	  this option, or dynamically by setting flags in the SOF core
	  module parameter (similar to dynamic debug)
	  If unsure, select "N".

config SND_SOC_SOF_DEBUG_IPC_FLOOD_TEST
	bool "SOF enable IPC flood test"
	help
+19 −6
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@
#include "sof-priv.h"
#include "ops.h"

/* see SOF_DBG_ flags */
int sof_core_debug;
module_param_named(sof_debug, sof_core_debug, int, 0444);
MODULE_PARM_DESC(sof_debug, "SOF core debug options (0x0 all off)");

/* SOF defaults if not provided by the platform in ms */
#define TIMEOUT_DEFAULT_IPC_MS  500
#define TIMEOUT_DEFAULT_BOOT_MS 2000
@@ -350,12 +355,20 @@ static int sof_probe_continue(struct snd_sof_dev *sdev)
		goto fw_run_err;
	}

	if (IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_ENABLE_FIRMWARE_TRACE) ||
	    (sof_core_debug & SOF_DBG_ENABLE_TRACE)) {
		sdev->dtrace_is_supported = true;

		/* init DMA trace */
		ret = snd_sof_init_trace(sdev);
		if (ret < 0) {
			/* non fatal */
			dev_warn(sdev->dev,
			 "warning: failed to initialize trace %d\n", ret);
				 "warning: failed to initialize trace %d\n",
				 ret);
		}
	} else {
		dev_dbg(sdev->dev, "SOF firmware trace disabled\n");
	}

	/* hereafter all FW boot flows are for PM reasons */
+9 −4
Original line number Diff line number Diff line
@@ -28,11 +28,15 @@
#include <uapi/sound/sof/fw.h>

/* debug flags */
#define SOF_DBG_ENABLE_TRACE	BIT(0)
#define SOF_DBG_REGS		BIT(1)
#define SOF_DBG_MBOX		BIT(2)
#define SOF_DBG_TEXT		BIT(3)
#define SOF_DBG_PCI		BIT(4)

/* global debug state set by SOF_DBG_ flags */
extern int sof_core_debug;

/* max BARs mmaped devices can use */
#define SND_SOF_BARS	8

@@ -434,6 +438,7 @@ struct snd_sof_dev {
	int dma_trace_pages;
	wait_queue_head_t trace_sleep;
	u32 host_offset;
	u32 dtrace_is_supported; /* set with Kconfig or module parameter */
	u32 dtrace_is_enabled;
	u32 dtrace_error;
	u32 dtrace_draining;
+16 −1
Original line number Diff line number Diff line
@@ -162,6 +162,9 @@ int snd_sof_init_trace_ipc(struct snd_sof_dev *sdev)
	struct sof_ipc_reply ipc_reply;
	int ret;

	if (!sdev->dtrace_is_supported)
		return 0;

	if (sdev->dtrace_is_enabled || !sdev->dma_trace_pages)
		return -EINVAL;

@@ -222,6 +225,9 @@ int snd_sof_init_trace(struct snd_sof_dev *sdev)
{
	int ret;

	if (!sdev->dtrace_is_supported)
		return 0;

	/* set false before start initialization */
	sdev->dtrace_is_enabled = false;

@@ -277,6 +283,9 @@ EXPORT_SYMBOL(snd_sof_init_trace);
int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
			     struct sof_ipc_dma_trace_posn *posn)
{
	if (!sdev->dtrace_is_supported)
		return 0;

	if (sdev->dtrace_is_enabled && sdev->host_offset != posn->host_offset) {
		sdev->host_offset = posn->host_offset;
		wake_up(&sdev->trace_sleep);
@@ -293,6 +302,9 @@ int snd_sof_trace_update_pos(struct snd_sof_dev *sdev,
/* an error has occurred within the DSP that prevents further trace */
void snd_sof_trace_notify_for_error(struct snd_sof_dev *sdev)
{
	if (!sdev->dtrace_is_supported)
		return;

	if (sdev->dtrace_is_enabled) {
		dev_err(sdev->dev, "error: waking up any trace sleepers\n");
		sdev->dtrace_error = true;
@@ -305,7 +317,7 @@ void snd_sof_release_trace(struct snd_sof_dev *sdev)
{
	int ret;

	if (!sdev->dtrace_is_enabled)
	if (!sdev->dtrace_is_supported || !sdev->dtrace_is_enabled)
		return;

	ret = snd_sof_dma_trace_trigger(sdev, SNDRV_PCM_TRIGGER_STOP);
@@ -326,6 +338,9 @@ EXPORT_SYMBOL(snd_sof_release_trace);

void snd_sof_free_trace(struct snd_sof_dev *sdev)
{
	if (!sdev->dtrace_is_supported)
		return;

	snd_sof_release_trace(sdev);

	snd_dma_free_pages(&sdev->dmatb);