您的位置:首页 > 娱乐 > 八卦 > debugfs使用记录

debugfs使用记录

2024/10/4 0:31:13 来源:https://blog.csdn.net/weixin_43300893/article/details/140608135  浏览:    关键词:debugfs使用记录

debugfs使用记录

/*debugfs文件调试例:先进行echo 命令write 文件再进行cat 命令,读取文件
*/#define STMMAC_DC0 "dc0"
#define OPEN_RX     "open_rx"
#define CLOSE_RX    "close_rx"
#define OPEN_RX_LEN   7
#define CLOSE_RX_LEN   8
#define OPEN_DUMP_REGS "dump_regs"
#define DUMP_REGS_LEN  9
#define CLOSE_DUMP_REGS "no_dump_regs"
#define NO_DUMP_REGS_LEN  12static ssize_t stmmac_write(struct file *fs, char __user *buf, size_t len, loff_t *lf)
{char cmd[len];memset(cmd, 0, len);if (copy_from_user(cmd, buf, len) < 0) {pr_err("can't copy data\n);return -EINVAL;}if (!strncmp(cmd, OPEN_RX, OPEN_RX_LEN)) {open_rx = true;pr_info("open rx\n");} else if (!strncmp(cmd, CLOSE_RX, CLOSE_RX_LEN)) {open_rx = false;pr_info("close rx\n");} else if (!strncmp(cmd, OPEN_DUMP_REGS, DUMP_REGS_LEN)) {dump_regs = true;pr_info("open dump regs\n");} else if (!strncmp(cmd, CLOSE_DUMP_REGS, NO_DUMP_REGS_LEN)) {dump_regs = false;pr_info("close dump regs\n");} else {pr_info("please put in valid cmd:\n");pr_info("usage: echo cmd > /proc/stmmac/dump_info\n");pr_info("    cmd is one of these values as follows:\n");pr_info("        open_rx: open rx");pr_info("        close_rx: close rx");pr_info("        dump_reas: open dumping regs");pr_info("        no_dump_reas: close dumping regs");}
}static ssize_t stmmac_read(struct file *fs, char __user *buf, size_t len, loff_t *lf)
{struct stmmac_prive *priv;unsigned int rxsize = 0;unsigned int count = 0;struct dma_desc *p = NULL;struct net_device *netdev;struct sk_buff *skb;void *ioaddr;netdev = dev_get_by_name(&init_net, STMMAC_DC0);if (!netdev) {pr_err("invalid netdev\n");return -EINVAL;}ioaddr = (void *)netdev->base_addr;if (!ioaddr) {pr_err("invalid ioaddr\n");return -EINVAL;}priv = netdev_priv(netdev);if (!priv) {pr_err("invalid priv\n");return -EINVAL;}if (dump_regs) {/* 读取寄存器信息 */priv->hw->mac->dump_regs(ioaddr);}rxsize = priv->dma_rx_size;if (dump_xstats) {DUMP_XSTATS(priv)}if (dump_erx_desc01) {LOOP_DUMP_ERX_DESC(priv);}return 0;
}static const struct file_operations stmmac_proc_ops = {.owner = THIS_MODULE,.open = simple_open,.read = stmmac_read,.write = stmmac_write,
};static struct proc_dir_entry *stmmac_dump_dir = NULL;
static struct proc_dir_entry *stmmac_dump_proc = NULL;stmmac_dump_init(void{int ret = 0;stmmac_dump_dir = proc_mkdir("stmmac", NULL);if (!stmmac_dump_dir) {ret = -EINVAL;goto out;}stmmac_dump_proc = proc_creat("dump_info", 0666, stmmac_dump_dir, &stmmac_proc_ops);if (!stmmac_dump_proc) {remove_proc_entry("stmmac", NULL);ret = -EINVAL;}
out:return ret;
}static void stmmac_dump_exit(void)
{if (stmmac_dump_dir) {remove_proc_entry("dump_info", stmmac_dump_dir);}if (stmmac_dump_dir) {remove_proc_entry("stmmac", NULL);}
}module_init(stmmac_dump_init);
module_exit(stmmac_dump_exit);

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com