0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/debugfs.h>
0011 #include <linux/module.h>
0012 #include <linux/pci.h>
0013 #include "bnxt_hsi.h"
0014 #include <linux/dim.h>
0015 #include "bnxt.h"
0016 #include "bnxt_debugfs.h"
0017
0018 static struct dentry *bnxt_debug_mnt;
0019
0020 static ssize_t debugfs_dim_read(struct file *filep,
0021 char __user *buffer,
0022 size_t count, loff_t *ppos)
0023 {
0024 struct dim *dim = filep->private_data;
0025 int len;
0026 char *buf;
0027
0028 if (*ppos)
0029 return 0;
0030 if (!dim)
0031 return -ENODEV;
0032 buf = kasprintf(GFP_KERNEL,
0033 "state = %d\n" \
0034 "profile_ix = %d\n" \
0035 "mode = %d\n" \
0036 "tune_state = %d\n" \
0037 "steps_right = %d\n" \
0038 "steps_left = %d\n" \
0039 "tired = %d\n",
0040 dim->state,
0041 dim->profile_ix,
0042 dim->mode,
0043 dim->tune_state,
0044 dim->steps_right,
0045 dim->steps_left,
0046 dim->tired);
0047 if (!buf)
0048 return -ENOMEM;
0049 if (count < strlen(buf)) {
0050 kfree(buf);
0051 return -ENOSPC;
0052 }
0053 len = simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
0054 kfree(buf);
0055 return len;
0056 }
0057
0058 static const struct file_operations debugfs_dim_fops = {
0059 .owner = THIS_MODULE,
0060 .open = simple_open,
0061 .read = debugfs_dim_read,
0062 };
0063
0064 static void debugfs_dim_ring_init(struct dim *dim, int ring_idx,
0065 struct dentry *dd)
0066 {
0067 static char qname[16];
0068
0069 snprintf(qname, 10, "%d", ring_idx);
0070 debugfs_create_file(qname, 0600, dd, dim, &debugfs_dim_fops);
0071 }
0072
0073 void bnxt_debug_dev_init(struct bnxt *bp)
0074 {
0075 const char *pname = pci_name(bp->pdev);
0076 struct dentry *dir;
0077 int i;
0078
0079 bp->debugfs_pdev = debugfs_create_dir(pname, bnxt_debug_mnt);
0080 dir = debugfs_create_dir("dim", bp->debugfs_pdev);
0081
0082
0083 for (i = 0; i < bp->cp_nr_rings; i++) {
0084 struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring;
0085
0086 if (cpr && bp->bnapi[i]->rx_ring)
0087 debugfs_dim_ring_init(&cpr->dim, i, dir);
0088 }
0089 }
0090
0091 void bnxt_debug_dev_exit(struct bnxt *bp)
0092 {
0093 if (bp) {
0094 debugfs_remove_recursive(bp->debugfs_pdev);
0095 bp->debugfs_pdev = NULL;
0096 }
0097 }
0098
0099 void bnxt_debug_init(void)
0100 {
0101 bnxt_debug_mnt = debugfs_create_dir("bnxt_en", NULL);
0102 }
0103
0104 void bnxt_debug_exit(void)
0105 {
0106 debugfs_remove_recursive(bnxt_debug_mnt);
0107 }