Re: [PATCH 05/17] coresight: Add support for TMC ETR SG unit

From: Suzuki K Poulose
Date: Wed Nov 01 2017 - 06:12:03 EST



diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c
index 4b9e2b276122..4424eb67a54c 100644
--- a/drivers/hwtracing/coresight/coresight-tmc-etr.c
+++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c
@@ -21,6 +21,89 @@
 #include "coresight-tmc.h"
 /*
+ * The TMC ETR SG has a page size of 4K. The SG table contains pointers
+ * to 4KB buffers. However, the OS may be use PAGE_SIZE different from

nit:
"the OS may use a PAGE_SIZE different from".



+#define ETR_SG_PAGE_SHIFTÂÂÂÂÂÂÂ 12
+#define ETR_SG_PAGE_SIZEÂÂÂÂÂÂÂ (1UL << ETR_SG_PAGE_SHIFT)
+#define ETR_SG_PAGES_PER_SYSPAGEÂÂÂ (1UL << \
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (PAGE_SHIFT - ETR_SG_PAGE_SHIFT))

I think this would be slightly easier to understand if defined as:
"(PAGE_SIZE / ETR_SG_PAGE_SIZE)".


+/* Dump the given sg_table */
+static void tmc_etr_sg_table_dump(struct etr_sg_table *etr_table)
+{
+ÂÂÂ sgte_t *ptr;
+ÂÂÂ int i = 0;
+ÂÂÂ dma_addr_t addr;
+ÂÂÂ struct tmc_sg_table *sg_table = etr_table->sg_table;
+
+ÂÂÂ ptr = (sgte_t *)tmc_sg_daddr_to_vaddr(sg_table,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ etr_table->hwaddr, true);
+ÂÂÂ while (ptr) {
+ÂÂÂÂÂÂÂ addr = ETR_SG_ADDR(*ptr);
+ÂÂÂÂÂÂÂ switch (ETR_SG_ET(*ptr)) {
+ÂÂÂÂÂÂÂ case ETR_SG_ET_NORMAL:
+ÂÂÂÂÂÂÂÂÂÂÂ pr_debug("%05d: %p\t:[N] 0x%llx\n", i, ptr, addr);
+ÂÂÂÂÂÂÂÂÂÂÂ ptr++;
+ÂÂÂÂÂÂÂÂÂÂÂ break;
+ÂÂÂÂÂÂÂ case ETR_SG_ET_LINK:
+ÂÂÂÂÂÂÂÂÂÂÂ pr_debug("%05d: *** %p\t:{L} 0x%llx ***\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ i, ptr, addr);
+ÂÂÂÂÂÂÂÂÂÂÂ ptr = (sgte_t *)tmc_sg_daddr_to_vaddr(sg_table,
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ addr, true);
+ÂÂÂÂÂÂÂÂÂÂÂ break;
+ÂÂÂÂÂÂÂ case ETR_SG_ET_LAST:
+ÂÂÂÂÂÂÂÂÂÂÂ pr_debug("%05d: ### %p\t:[L] 0x%llx ###\n",
+ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ i, ptr, addr);
+ÂÂÂÂÂÂÂÂÂÂÂ return;

I get this is debug code, but it seems like if ETR_SG_ET(*ptr) is 0 we get stuck in an infinite loop. I guess it is something that supposedly doesn't happen, still I'd prefer having a default case saying the table might be corrupted and either incrementing ptr to try and get more info or breaking out of the loop.


+ÂÂÂÂÂÂÂ }
+ÂÂÂÂÂÂÂ i++;
+ÂÂÂ }
+ÂÂÂ pr_debug("******* End of Table *****\n");
+}
+#endif
+
+/*
+ * Populate the SG Table page table entries from table/data
+ * pages allocated. Each Data page has ETR_SG_PAGES_PER_SYSPAGE SG pages.
+ * So does a Table page. So we keep track of indices of the tables
+ * in each system page and move the pointers accordingly.
+ */
+#define INC_IDX_ROUND(idx, size) (idx = (idx + 1) % size)

Needs more parenthesis around idx and size.


+static void tmc_etr_sg_table_populate(struct etr_sg_table *etr_table)
+{
+ÂÂÂ dma_addr_t paddr;
+ÂÂÂ int i, type, nr_entries;
+ÂÂÂ int tpidx = 0; /* index to the current system table_page */
+ÂÂÂ int sgtidx = 0;ÂÂÂ /* index to the sg_table within the current syspage */
+ÂÂÂ int sgtoffset = 0; /* offset to the next entry within the sg_table */

That's misleading, this seems to be the index of an entry within an ETR_SG_PAGE rather than an offset in bytes.

Maybe ptridx or entryidx would be a better name.

You're right, I have chosen sgtentry for now.

Thanks for the detailed look, I will fix all of them.

Cheers
Suzuki