mmc: cmdq_hci: Add cyclic buffer to keep history of last 32 tasks

Keep track of task history for the last 32 tasks and dump it
along with registers in case of any error for debugging.

The log is of the following format:
[index] <DATA|DCMD> Task: <lower 32bits> | Args: <upper 32bits>
of the task descriptor structure. The values need to be decoded
accordingly depending on the data or dcmd task descriptor.
The last entry index denotes the latest entry in this list.

---- Circular Task History ----
cmdq-host: Last entry index: 1
cmdq-host: [00]DATA Task: 0x0400002f | Args: 0x00d37d18
cmdq-host: [01]DATA Task: 0x0400002f | Args: 0x00d38118
cmdq-host: [02]DCMD Task: 0x0186402f | Args: 0x03200101

Add a debugfs entry to enable/disable this dynamically. It is
disabled by default. This applies only to eMMC devices.

Usage: echo Y > /sys/kernel/debug/mmcX/cmdq_task_history
X - denotes the slot id

Change-Id: I6abf29aa928d3d8270405cfc104241043dadfe45
Signed-off-by: Venkat Gopalakrishnan <venkatg@codeaurora.org>
[subhashj@codeaurora.org: fixed compilation error]
Signed-off-by: Subhash Jadavani <subhashj@codeaurora.org>
diff --git a/drivers/mmc/host/cmdq_hci.h b/drivers/mmc/host/cmdq_hci.h
index 2c917069..b8a8ccd 100644
--- a/drivers/mmc/host/cmdq_hci.h
+++ b/drivers/mmc/host/cmdq_hci.h
@@ -144,6 +144,11 @@
 #define CQ_VENDOR_CFG	0x100
 #define CMDQ_SEND_STATUS_TRIGGER (1 << 31)
 
+struct task_history {
+	u64 task;
+	bool is_dcmd;
+};
+
 struct cmdq_host {
 	const struct cmdq_host_ops *ops;
 	void __iomem *mmio;
@@ -183,6 +188,9 @@
 	dma_addr_t desc_dma_base;
 	dma_addr_t trans_desc_dma_base;
 
+	struct task_history *thist;
+	u8 thist_idx;
+
 	struct completion halt_comp;
 	struct mmc_request **mrq_slot;
 	void *private;