debugfs使用记录
#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);