From: Vamsi Atluri <[email protected]>

Add debugfs file to display host memory allocations including tag,
size, order, and physical address for each memory request.

Signed-off-by: Vamsi Atluri <[email protected]>
---
 drivers/net/ethernet/amd/pds_core/debugfs.c | 43 +++++++++++++++++++++++++++++
 drivers/net/ethernet/amd/pds_core/main.c    |  2 ++
 2 files changed, 45 insertions(+)

diff --git a/drivers/net/ethernet/amd/pds_core/debugfs.c 
b/drivers/net/ethernet/amd/pds_core/debugfs.c
index 04c5e3abd8d7..79312107f721 100644
--- a/drivers/net/ethernet/amd/pds_core/debugfs.c
+++ b/drivers/net/ethernet/amd/pds_core/debugfs.c
@@ -173,3 +173,46 @@ void pdsc_debugfs_del_qcq(struct pdsc_qcq *qcq)
        debugfs_remove_recursive(qcq->dentry);
        qcq->dentry = NULL;
 }
+
+static int host_mem_show(struct seq_file *seq, void *v)
+{
+       struct pdsc *pdsc = seq->private;
+       struct pdsc_host_mem *hm;
+       int i;
+
+       if (!pdsc->host_mem_reqs || pdsc->num_host_mem_reqs == 0) {
+               seq_puts(seq, "No host memory allocated\n");
+               return 0;
+       }
+
+       seq_printf(seq, "Host memory requests: %d\n\n", 
pdsc->num_host_mem_reqs);
+       seq_puts(seq, "Tag    Size         Order  PA\n");
+       seq_puts(seq, "---    ----         -----  --\n");
+
+       for (i = 0; i < pdsc->num_host_mem_reqs; i++) {
+               hm = &pdsc->host_mem_reqs[i];
+
+               if (!hm->pg)
+                       continue;
+
+               seq_printf(seq, "%-6d %-12u %-6d 0x%llx\n",
+                          hm->tag, hm->size, hm->order,
+                          (unsigned long long)hm->pa);
+       }
+
+       return 0;
+}
+DEFINE_SHOW_ATTRIBUTE(host_mem);
+
+void pdsc_debugfs_add_host_mem(struct pdsc *pdsc)
+{
+       if (!(pdsc->dev_ident.capabilities & 
cpu_to_le64(PDS_CORE_DEV_CAP_HOST_MEM)))
+               return;
+
+       /* This file will already exist in the reset flow */
+       if (debugfs_lookup("host_mem", pdsc->dentry))
+               return;
+
+       debugfs_create_file("host_mem", 0400, pdsc->dentry,
+                           pdsc, &host_mem_fops);
+}
diff --git a/drivers/net/ethernet/amd/pds_core/main.c 
b/drivers/net/ethernet/amd/pds_core/main.c
index 0a0542bf7cbb..4c14198eaafe 100644
--- a/drivers/net/ethernet/amd/pds_core/main.c
+++ b/drivers/net/ethernet/amd/pds_core/main.c
@@ -264,6 +264,8 @@ static int pdsc_init_pf(struct pdsc *pdsc)
 
        mutex_unlock(&pdsc->config_lock);
 
+       pdsc_debugfs_add_host_mem(pdsc);
+
        err = pdsc_auxbus_dev_add(pdsc, pdsc, PDS_DEV_TYPE_FWCTL, &pdsc->padev);
        if (err)
                goto err_out_stop;

-- 
2.43.0


Reply via email to