862d2acb7a1670ce9edca882ac647cf7c00a7aac
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / net / wireless / brcm80211 / brcmfmac / dhd_dbg.c
1 /*
2  * Copyright (c) 2012 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 #include <linux/debugfs.h>
17 #include <linux/if_ether.h>
18 #include <linux/if.h>
19 #include <linux/netdevice.h>
20 #include <linux/ieee80211.h>
21 #include <linux/module.h>
22 #include <linux/netdevice.h>
23
24 #include <defs.h>
25 #include <brcmu_wifi.h>
26 #include <brcmu_utils.h>
27 #include "dhd.h"
28 #include "dhd_bus.h"
29 #include "dhd_dbg.h"
30
31 static struct dentry *root_folder;
32
33 void brcmf_debugfs_init(void)
34 {
35         root_folder = debugfs_create_dir(KBUILD_MODNAME, NULL);
36         if (IS_ERR(root_folder))
37                 root_folder = NULL;
38 }
39
40 void brcmf_debugfs_exit(void)
41 {
42         if (!root_folder)
43                 return;
44
45         debugfs_remove_recursive(root_folder);
46         root_folder = NULL;
47 }
48
49 int brcmf_debugfs_attach(struct brcmf_pub *drvr)
50 {
51         if (!root_folder)
52                 return -ENODEV;
53
54         drvr->dbgfs_dir = debugfs_create_dir(dev_name(drvr->dev), root_folder);
55         return PTR_RET(drvr->dbgfs_dir);
56 }
57
58 void brcmf_debugfs_detach(struct brcmf_pub *drvr)
59 {
60         if (!IS_ERR_OR_NULL(drvr->dbgfs_dir))
61                 debugfs_remove_recursive(drvr->dbgfs_dir);
62 }
63
64 struct dentry *brcmf_debugfs_get_devdir(struct brcmf_pub *drvr)
65 {
66         return drvr->dbgfs_dir;
67 }
68
69 static
70 ssize_t brcmf_debugfs_sdio_counter_read(struct file *f, char __user *data,
71                                         size_t count, loff_t *ppos)
72 {
73         struct brcmf_sdio_count *sdcnt = f->private_data;
74         char buf[750];
75         int res;
76
77         /* only allow read from start */
78         if (*ppos > 0)
79                 return 0;
80
81         res = scnprintf(buf, sizeof(buf),
82                         "intrcount:    %u\nlastintrs:    %u\n"
83                         "pollcnt:      %u\nregfails:     %u\n"
84                         "tx_sderrs:    %u\nfcqueued:     %u\n"
85                         "rxrtx:        %u\nrx_toolong:   %u\n"
86                         "rxc_errors:   %u\nrx_hdrfail:   %u\n"
87                         "rx_badhdr:    %u\nrx_badseq:    %u\n"
88                         "fc_rcvd:      %u\nfc_xoff:      %u\n"
89                         "fc_xon:       %u\nrxglomfail:   %u\n"
90                         "rxglomframes: %u\nrxglompkts:   %u\n"
91                         "f2rxhdrs:     %u\nf2rxdata:     %u\n"
92                         "f2txdata:     %u\nf1regdata:    %u\n"
93                         "tickcnt:      %u\ntx_ctlerrs:   %lu\n"
94                         "tx_ctlpkts:   %lu\nrx_ctlerrs:   %lu\n"
95                         "rx_ctlpkts:   %lu\nrx_readahead: %lu\n",
96                         sdcnt->intrcount, sdcnt->lastintrs,
97                         sdcnt->pollcnt, sdcnt->regfails,
98                         sdcnt->tx_sderrs, sdcnt->fcqueued,
99                         sdcnt->rxrtx, sdcnt->rx_toolong,
100                         sdcnt->rxc_errors, sdcnt->rx_hdrfail,
101                         sdcnt->rx_badhdr, sdcnt->rx_badseq,
102                         sdcnt->fc_rcvd, sdcnt->fc_xoff,
103                         sdcnt->fc_xon, sdcnt->rxglomfail,
104                         sdcnt->rxglomframes, sdcnt->rxglompkts,
105                         sdcnt->f2rxhdrs, sdcnt->f2rxdata,
106                         sdcnt->f2txdata, sdcnt->f1regdata,
107                         sdcnt->tickcnt, sdcnt->tx_ctlerrs,
108                         sdcnt->tx_ctlpkts, sdcnt->rx_ctlerrs,
109                         sdcnt->rx_ctlpkts, sdcnt->rx_readahead_cnt);
110
111         return simple_read_from_buffer(data, count, ppos, buf, res);
112 }
113
114 static const struct file_operations brcmf_debugfs_sdio_counter_ops = {
115         .owner = THIS_MODULE,
116         .open = simple_open,
117         .read = brcmf_debugfs_sdio_counter_read
118 };
119
120 void brcmf_debugfs_create_sdio_count(struct brcmf_pub *drvr,
121                                      struct brcmf_sdio_count *sdcnt)
122 {
123         struct dentry *dentry = drvr->dbgfs_dir;
124
125         if (!IS_ERR_OR_NULL(dentry))
126                 debugfs_create_file("counters", S_IRUGO, dentry,
127                                     sdcnt, &brcmf_debugfs_sdio_counter_ops);
128 }