net: wireless: bcmdhd: Fix compilation warnings
[linux-3.10.git] / drivers / net / wireless / bcmdhd / dhd_custom_sysfs_tegra_rssi.c
1 /*
2  * drivers/net/wireless/bcmdhd/dhd_custom_sysfs_tegra_rssi.c
3  *
4  * NVIDIA Tegra Sysfs for BCMDHD driver
5  *
6  * Copyright (C) 2014-2015 NVIDIA Corporation. All rights reserved.
7  *
8  * This software is licensed under the terms of the GNU General Public
9  * License version 2, as published by the Free Software Foundation, and
10  * may be copied, distributed, and modified under those terms.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  */
18
19 #include "dhd_custom_sysfs_tegra.h"
20 #include "wlioctl.h"
21 #include "wldev_common.h"
22
23 extern struct net_device *dhd_custom_sysfs_tegra_histogram_stat_netdev;
24
25 static void
26 rssi_work_func(struct work_struct *work);
27
28 static unsigned int rssi_rate_ms = 10 * 1000;
29 static DECLARE_DELAYED_WORK(rssi_work, rssi_work_func);
30
31 static void
32 rssi_work_func(struct work_struct *work)
33 {
34         struct delayed_work *dwork = to_delayed_work(work);
35         struct net_device *net = dhd_custom_sysfs_tegra_histogram_stat_netdev;
36         char *netif = net ? net->name : "";
37         scb_val_t scb_val;
38         int err;
39         int i;
40
41         UNUSED_PARAMETER(dwork);
42
43 //      pr_info("%s\n", __func__);
44
45         /* create rssi request */
46         memset(&scb_val, 0, sizeof(scb_val));
47         scb_val.val = 0;
48
49         /* send rssi request */
50         err = wldev_ioctl(net, WLC_GET_RSSI, &scb_val, sizeof(scb_val), false);
51         if (err) {
52 //              pr_err("%s: wldev_ioctl(WLC_GET_RSSI) failed\n", __func__);
53                 goto fail;
54         }
55
56         /* log rssi request */
57         for (i = 0; i < sizeof(scb_val.val); i += 64) {
58                 tcpdump_pkt_save('r' + i / 64,
59                         netif,
60                         __func__,
61                         __LINE__,
62                         ((unsigned char *) &scb_val.val) + i,
63                         (i + 64) <= sizeof(scb_val.val)
64                                 ? 64 : sizeof(scb_val.val) - i,
65                         0);
66         }
67
68         /* schedule next rssi */
69 fail:
70         schedule_delayed_work(&rssi_work,
71                 msecs_to_jiffies(rssi_rate_ms));
72
73 }
74
75 void
76 tegra_sysfs_histogram_rssi_work_start(void)
77 {
78 //      pr_info("%s\n", __func__);
79         if (rssi_rate_ms > 0)
80                 schedule_delayed_work(&rssi_work,
81                         msecs_to_jiffies(rssi_rate_ms));
82 }
83
84 void
85 tegra_sysfs_histogram_rssi_work_stop(void)
86 {
87 //      pr_info("%s\n", __func__);
88         cancel_delayed_work_sync(&rssi_work);
89 }
90
91 ssize_t
92 tegra_sysfs_histogram_rssi_show(struct device *dev,
93         struct device_attribute *attr,
94         char *buf)
95 {
96         static int i;
97
98 //      pr_info("%s\n", __func__);
99
100         if (!i) {
101                 i++;
102                 strcpy(buf, "dummy rssi!");
103                 return strlen(buf);
104         } else {
105                 i = 0;
106                 return 0;
107         }
108 }
109
110 ssize_t
111 tegra_sysfs_histogram_rssi_store(struct device *dev,
112         struct device_attribute *attr,
113         const char *buf, size_t count)
114 {
115         int err;
116         unsigned int uint;
117
118 //      pr_info("%s\n", __func__);
119
120         if (strncmp(buf, "enable", 6) == 0) {
121                 pr_info("%s: starting rssi delayed work...\n", __func__);
122                 tegra_sysfs_histogram_rssi_work_start();
123         } else if (strncmp(buf, "disable", 7) == 0) {
124                 pr_info("%s: stopping rssi delayed work...\n", __func__);
125                 tegra_sysfs_histogram_rssi_work_stop();
126         } else if (strncmp(buf, "rate ", 5) == 0) {
127                 err = kstrtouint(buf + 5, 0, &uint);
128                 if (err < 0) {
129                         pr_err("%s: invalid rssi rate (ms)\n", __func__);
130                         return count;
131                 }
132                 pr_info("%s: set rssi rate (ms) %u\n", __func__, uint);
133                 rssi_rate_ms = uint;
134         } else {
135                 pr_err("%s: unknown command\n", __func__);
136         }
137
138         return count;
139 }