Thomas Bogendoerfer 51f9d9
From: Harman Kalra <hkalra@marvell.com>
Thomas Bogendoerfer 51f9d9
Date: Wed, 27 Oct 2021 23:37:44 +0530
Thomas Bogendoerfer 51f9d9
Subject: octeontx2-af: cn10k: debugfs for dumping LMTST map table
Thomas Bogendoerfer 51f9d9
Patch-mainline: v5.16-rc1
Thomas Bogendoerfer 51f9d9
Git-commit: 0daa55d033b02a899a5979e407cc3af530980f1e
Thomas Bogendoerfer 51f9d9
References: jsc#SLE-24682
Thomas Bogendoerfer 51f9d9
Thomas Bogendoerfer 51f9d9
CN10k SoCs use atomic stores of up to 128 bytes to submit
Thomas Bogendoerfer 51f9d9
packets/instructions into co-processor cores. The enqueueing is performed
Thomas Bogendoerfer 51f9d9
using Large Memory Transaction Store (LMTST) operations. They allow for
Thomas Bogendoerfer 51f9d9
lockless enqueue operations - i.e., two different CPU cores can submit
Thomas Bogendoerfer 51f9d9
instructions to the same queue without needing to lock the queue or
Thomas Bogendoerfer 51f9d9
synchronize their accesses.
Thomas Bogendoerfer 51f9d9
Thomas Bogendoerfer 51f9d9
This patch implements a new debugfs entry for dumping LMTST map
Thomas Bogendoerfer 51f9d9
table present on CN10K, as this might be very useful to debug any issue
Thomas Bogendoerfer 51f9d9
in case of shared LMTST region among multiple pci functions.
Thomas Bogendoerfer 51f9d9
Thomas Bogendoerfer 51f9d9
Signed-off-by: Harman Kalra <hkalra@marvell.com>
Thomas Bogendoerfer 51f9d9
Signed-off-by: Bhaskara Budiredla <bbudiredla@marvell.com>
Thomas Bogendoerfer 51f9d9
Signed-off-by: Rakesh Babu <rsaladi2@marvell.com>
Thomas Bogendoerfer 51f9d9
Signed-off-by: Sunil Kovvuri Goutham <sgoutham@marvell.com>
Thomas Bogendoerfer 51f9d9
Signed-off-by: David S. Miller <davem@davemloft.net>
Thomas Bogendoerfer 51f9d9
Acked-by: Thomas Bogendoerfer <tbogendoerfer@suse.de>
Thomas Bogendoerfer 51f9d9
---
Thomas Bogendoerfer 51f9d9
 drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c |   94 ++++++++++++++++
Thomas Bogendoerfer 51f9d9
 1 file changed, 94 insertions(+)
Thomas Bogendoerfer 51f9d9
Thomas Bogendoerfer 51f9d9
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
Thomas Bogendoerfer 51f9d9
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
Thomas Bogendoerfer 51f9d9
@@ -293,6 +293,96 @@ static int get_max_column_width(struct r
Thomas Bogendoerfer 51f9d9
 	return lf_str_size;
Thomas Bogendoerfer 51f9d9
 }
Thomas Bogendoerfer 51f9d9
 
Thomas Bogendoerfer 51f9d9
+#define LMT_MAPTBL_ENTRY_SIZE 16
Thomas Bogendoerfer 51f9d9
+/* Dump LMTST map table */
Thomas Bogendoerfer 51f9d9
+static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp,
Thomas Bogendoerfer 51f9d9
+					       char __user *buffer,
Thomas Bogendoerfer 51f9d9
+					       size_t count, loff_t *ppos)
Thomas Bogendoerfer 51f9d9
+{
Thomas Bogendoerfer 51f9d9
+	struct rvu *rvu = filp->private_data;
Thomas Bogendoerfer 51f9d9
+	u64 lmt_addr, val, tbl_base;
Thomas Bogendoerfer 51f9d9
+	int pf, vf, num_vfs, hw_vfs;
Thomas Bogendoerfer 51f9d9
+	void __iomem *lmt_map_base;
Thomas Bogendoerfer 51f9d9
+	int index = 0, off = 0;
Thomas Bogendoerfer 51f9d9
+	int bytes_not_copied;
Thomas Bogendoerfer 51f9d9
+	int buf_size = 10240;
Thomas Bogendoerfer 51f9d9
+	char *buf;
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	/* don't allow partial reads */
Thomas Bogendoerfer 51f9d9
+	if (*ppos != 0)
Thomas Bogendoerfer 51f9d9
+		return 0;
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	buf = kzalloc(buf_size, GFP_KERNEL);
Thomas Bogendoerfer 51f9d9
+	if (!buf)
Thomas Bogendoerfer 51f9d9
+		return -ENOSPC;
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	tbl_base = rvu_read64(rvu, BLKADDR_APR, APR_AF_LMT_MAP_BASE);
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	lmt_map_base = ioremap_wc(tbl_base, 128 * 1024);
Thomas Bogendoerfer 51f9d9
+	if (!lmt_map_base) {
Thomas Bogendoerfer 51f9d9
+		dev_err(rvu->dev, "Failed to setup lmt map table mapping!!\n");
Thomas Bogendoerfer 51f9d9
+		kfree(buf);
Thomas Bogendoerfer 51f9d9
+		return false;
Thomas Bogendoerfer 51f9d9
+	}
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+			  "\n\t\t\t\t\tLmtst Map Table Entries");
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+			  "\n\t\t\t\t\t=======================");
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off, "\nPcifunc\t\t\t");
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off, "Table Index\t\t");
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+			  "Lmtline Base (word 0)\t\t");
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+			  "Lmt Map Entry (word 1)");
Thomas Bogendoerfer 51f9d9
+	off += scnprintf(&buf[off], buf_size - 1 - off, "\n");
Thomas Bogendoerfer 51f9d9
+	for (pf = 0; pf < rvu->hw->total_pfs; pf++) {
Thomas Bogendoerfer 51f9d9
+		off += scnprintf(&buf[off], buf_size - 1 - off, "PF%d  \t\t\t",
Thomas Bogendoerfer 51f9d9
+				    pf);
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+		index = pf * rvu->hw->total_vfs * LMT_MAPTBL_ENTRY_SIZE;
Thomas Bogendoerfer 51f9d9
+		off += scnprintf(&buf[off], buf_size - 1 - off, " 0x%llx\t\t",
Thomas Bogendoerfer 51f9d9
+				 (tbl_base + index));
Thomas Bogendoerfer 51f9d9
+		lmt_addr = readq(lmt_map_base + index);
Thomas Bogendoerfer 51f9d9
+		off += scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+				 " 0x%016llx\t\t", lmt_addr);
Thomas Bogendoerfer 51f9d9
+		index += 8;
Thomas Bogendoerfer 51f9d9
+		val = readq(lmt_map_base + index);
Thomas Bogendoerfer 51f9d9
+		off += scnprintf(&buf[off], buf_size - 1 - off, " 0x%016llx\n",
Thomas Bogendoerfer 51f9d9
+				 val);
Thomas Bogendoerfer 51f9d9
+		/* Reading num of VFs per PF */
Thomas Bogendoerfer 51f9d9
+		rvu_get_pf_numvfs(rvu, pf, &num_vfs, &hw_vfs);
Thomas Bogendoerfer 51f9d9
+		for (vf = 0; vf < num_vfs; vf++) {
Thomas Bogendoerfer 51f9d9
+			index = (pf * rvu->hw->total_vfs * 16) +
Thomas Bogendoerfer 51f9d9
+				((vf + 1)  * LMT_MAPTBL_ENTRY_SIZE);
Thomas Bogendoerfer 51f9d9
+			off += scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+					    "PF%d:VF%d  \t\t", pf, vf);
Thomas Bogendoerfer 51f9d9
+			off += scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+					 " 0x%llx\t\t", (tbl_base + index));
Thomas Bogendoerfer 51f9d9
+			lmt_addr = readq(lmt_map_base + index);
Thomas Bogendoerfer 51f9d9
+			off += scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+					 " 0x%016llx\t\t", lmt_addr);
Thomas Bogendoerfer 51f9d9
+			index += 8;
Thomas Bogendoerfer 51f9d9
+			val = readq(lmt_map_base + index);
Thomas Bogendoerfer 51f9d9
+			off += scnprintf(&buf[off], buf_size - 1 - off,
Thomas Bogendoerfer 51f9d9
+					 " 0x%016llx\n", val);
Thomas Bogendoerfer 51f9d9
+		}
Thomas Bogendoerfer 51f9d9
+	}
Thomas Bogendoerfer 51f9d9
+	off +=	scnprintf(&buf[off], buf_size - 1 - off, "\n");
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	bytes_not_copied = copy_to_user(buffer, buf, off);
Thomas Bogendoerfer 51f9d9
+	kfree(buf);
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	iounmap(lmt_map_base);
Thomas Bogendoerfer 51f9d9
+	if (bytes_not_copied)
Thomas Bogendoerfer 51f9d9
+		return -EFAULT;
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+	*ppos = off;
Thomas Bogendoerfer 51f9d9
+	return off;
Thomas Bogendoerfer 51f9d9
+}
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
+RVU_DEBUG_FOPS(lmtst_map_table, lmtst_map_table_display, NULL);
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
 /* Dumps current provisioning status of all RVU block LFs */
Thomas Bogendoerfer 51f9d9
 static ssize_t rvu_dbg_rsrc_attach_status(struct file *filp,
Thomas Bogendoerfer 51f9d9
 					  char __user *buffer,
Thomas Bogendoerfer 51f9d9
@@ -2754,6 +2844,10 @@ void rvu_dbg_init(struct rvu *rvu)
Thomas Bogendoerfer 51f9d9
 	debugfs_create_file("rsrc_alloc", 0444, rvu->rvu_dbg.root, rvu,
Thomas Bogendoerfer 51f9d9
 			    &rvu_dbg_rsrc_status_fops);
Thomas Bogendoerfer 51f9d9
 
Thomas Bogendoerfer 51f9d9
+	if (!is_rvu_otx2(rvu))
Thomas Bogendoerfer 51f9d9
+		debugfs_create_file("lmtst_map_table", 0444, rvu->rvu_dbg.root,
Thomas Bogendoerfer 51f9d9
+				    rvu, &rvu_dbg_lmtst_map_table_fops);
Thomas Bogendoerfer 51f9d9
+
Thomas Bogendoerfer 51f9d9
 	if (!cgx_get_cgxcnt_max())
Thomas Bogendoerfer 51f9d9
 		goto create;
Thomas Bogendoerfer 51f9d9