1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) Meta Platforms, Inc. and affiliates. */
3
4 #include <linux/debugfs.h>
5 #include <linux/pci.h>
6 #include <linux/rtnetlink.h>
7 #include <linux/seq_file.h>
8
9 #include "fbnic.h"
10
11 static struct dentry *fbnic_dbg_root;
12
fbnic_dbg_pcie_stats_show(struct seq_file * s,void * v)13 static int fbnic_dbg_pcie_stats_show(struct seq_file *s, void *v)
14 {
15 struct fbnic_dev *fbd = s->private;
16
17 rtnl_lock();
18 fbnic_get_hw_stats(fbd);
19
20 seq_printf(s, "ob_rd_tlp: %llu\n", fbd->hw_stats.pcie.ob_rd_tlp.value);
21 seq_printf(s, "ob_rd_dword: %llu\n",
22 fbd->hw_stats.pcie.ob_rd_dword.value);
23 seq_printf(s, "ob_wr_tlp: %llu\n", fbd->hw_stats.pcie.ob_wr_tlp.value);
24 seq_printf(s, "ob_wr_dword: %llu\n",
25 fbd->hw_stats.pcie.ob_wr_dword.value);
26 seq_printf(s, "ob_cpl_tlp: %llu\n",
27 fbd->hw_stats.pcie.ob_cpl_tlp.value);
28 seq_printf(s, "ob_cpl_dword: %llu\n",
29 fbd->hw_stats.pcie.ob_cpl_dword.value);
30 seq_printf(s, "ob_rd_no_tag: %llu\n",
31 fbd->hw_stats.pcie.ob_rd_no_tag.value);
32 seq_printf(s, "ob_rd_no_cpl_cred: %llu\n",
33 fbd->hw_stats.pcie.ob_rd_no_cpl_cred.value);
34 seq_printf(s, "ob_rd_no_np_cred: %llu\n",
35 fbd->hw_stats.pcie.ob_rd_no_np_cred.value);
36 rtnl_unlock();
37
38 return 0;
39 }
40
41 DEFINE_SHOW_ATTRIBUTE(fbnic_dbg_pcie_stats);
42
fbnic_dbg_fbd_init(struct fbnic_dev * fbd)43 void fbnic_dbg_fbd_init(struct fbnic_dev *fbd)
44 {
45 struct pci_dev *pdev = to_pci_dev(fbd->dev);
46 const char *name = pci_name(pdev);
47
48 fbd->dbg_fbd = debugfs_create_dir(name, fbnic_dbg_root);
49 debugfs_create_file("pcie_stats", 0400, fbd->dbg_fbd, fbd,
50 &fbnic_dbg_pcie_stats_fops);
51 }
52
fbnic_dbg_fbd_exit(struct fbnic_dev * fbd)53 void fbnic_dbg_fbd_exit(struct fbnic_dev *fbd)
54 {
55 debugfs_remove_recursive(fbd->dbg_fbd);
56 fbd->dbg_fbd = NULL;
57 }
58
fbnic_dbg_init(void)59 void fbnic_dbg_init(void)
60 {
61 fbnic_dbg_root = debugfs_create_dir(fbnic_driver_name, NULL);
62 }
63
fbnic_dbg_exit(void)64 void fbnic_dbg_exit(void)
65 {
66 debugfs_remove_recursive(fbnic_dbg_root);
67 fbnic_dbg_root = NULL;
68 }
69