x86/xen: resume timer irqs early
[linux/fpc-iii.git] / drivers / net / wireless / brcm80211 / brcmfmac / fwil.c
blob04f395930d86742372585ff42b3ce3837f0d606d
1 /*
2 * Copyright (c) 2012 Broadcom Corporation
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.
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.
17 /* FWIL is the Firmware Interface Layer. In this module the support functions
18 * are located to set and get variables to and from the firmware.
21 #include <linux/kernel.h>
22 #include <linux/netdevice.h>
23 #include <brcmu_utils.h>
24 #include <brcmu_wifi.h>
25 #include "dhd.h"
26 #include "dhd_bus.h"
27 #include "dhd_dbg.h"
28 #include "tracepoint.h"
29 #include "fwil.h"
32 #define MAX_HEX_DUMP_LEN 64
35 static s32
36 brcmf_fil_cmd_data(struct brcmf_if *ifp, u32 cmd, void *data, u32 len, bool set)
38 struct brcmf_pub *drvr = ifp->drvr;
39 s32 err;
41 if (drvr->bus_if->state != BRCMF_BUS_DATA) {
42 brcmf_err("bus is down. we have nothing to do.\n");
43 return -EIO;
46 if (data != NULL)
47 len = min_t(uint, len, BRCMF_DCMD_MAXLEN);
48 if (set)
49 err = brcmf_proto_cdc_set_dcmd(drvr, ifp->ifidx, cmd, data,
50 len);
51 else
52 err = brcmf_proto_cdc_query_dcmd(drvr, ifp->ifidx, cmd, data,
53 len);
55 if (err >= 0)
56 err = 0;
57 else
58 brcmf_err("Failed err=%d\n", err);
60 return err;
63 s32
64 brcmf_fil_cmd_data_set(struct brcmf_if *ifp, u32 cmd, void *data, u32 len)
66 s32 err;
68 mutex_lock(&ifp->drvr->proto_block);
70 brcmf_dbg(FIL, "cmd=%d, len=%d\n", cmd, len);
71 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data,
72 min_t(uint, len, MAX_HEX_DUMP_LEN), "data");
74 err = brcmf_fil_cmd_data(ifp, cmd, data, len, true);
75 mutex_unlock(&ifp->drvr->proto_block);
77 return err;
80 s32
81 brcmf_fil_cmd_data_get(struct brcmf_if *ifp, u32 cmd, void *data, u32 len)
83 s32 err;
85 mutex_lock(&ifp->drvr->proto_block);
86 err = brcmf_fil_cmd_data(ifp, cmd, data, len, false);
88 brcmf_dbg(FIL, "cmd=%d, len=%d\n", cmd, len);
89 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data,
90 min_t(uint, len, MAX_HEX_DUMP_LEN), "data");
92 mutex_unlock(&ifp->drvr->proto_block);
94 return err;
98 s32
99 brcmf_fil_cmd_int_set(struct brcmf_if *ifp, u32 cmd, u32 data)
101 s32 err;
102 __le32 data_le = cpu_to_le32(data);
104 mutex_lock(&ifp->drvr->proto_block);
105 brcmf_dbg(FIL, "cmd=%d, value=%d\n", cmd, data);
106 err = brcmf_fil_cmd_data(ifp, cmd, &data_le, sizeof(data_le), true);
107 mutex_unlock(&ifp->drvr->proto_block);
109 return err;
113 brcmf_fil_cmd_int_get(struct brcmf_if *ifp, u32 cmd, u32 *data)
115 s32 err;
116 __le32 data_le = cpu_to_le32(*data);
118 mutex_lock(&ifp->drvr->proto_block);
119 err = brcmf_fil_cmd_data(ifp, cmd, &data_le, sizeof(data_le), false);
120 mutex_unlock(&ifp->drvr->proto_block);
121 *data = le32_to_cpu(data_le);
122 brcmf_dbg(FIL, "cmd=%d, value=%d\n", cmd, *data);
124 return err;
127 static u32
128 brcmf_create_iovar(char *name, char *data, u32 datalen, char *buf, u32 buflen)
130 u32 len;
132 len = strlen(name) + 1;
134 if ((len + datalen) > buflen)
135 return 0;
137 memcpy(buf, name, len);
139 /* append data onto the end of the name string */
140 if (data && datalen)
141 memcpy(&buf[len], data, datalen);
143 return len + datalen;
148 brcmf_fil_iovar_data_set(struct brcmf_if *ifp, char *name, void *data,
149 u32 len)
151 struct brcmf_pub *drvr = ifp->drvr;
152 s32 err;
153 u32 buflen;
155 mutex_lock(&drvr->proto_block);
157 brcmf_dbg(FIL, "name=%s, len=%d\n", name, len);
158 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data,
159 min_t(uint, len, MAX_HEX_DUMP_LEN), "data");
161 buflen = brcmf_create_iovar(name, data, len, drvr->proto_buf,
162 sizeof(drvr->proto_buf));
163 if (buflen) {
164 err = brcmf_fil_cmd_data(ifp, BRCMF_C_SET_VAR, drvr->proto_buf,
165 buflen, true);
166 } else {
167 err = -EPERM;
168 brcmf_err("Creating iovar failed\n");
171 mutex_unlock(&drvr->proto_block);
172 return err;
176 brcmf_fil_iovar_data_get(struct brcmf_if *ifp, char *name, void *data,
177 u32 len)
179 struct brcmf_pub *drvr = ifp->drvr;
180 s32 err;
181 u32 buflen;
183 mutex_lock(&drvr->proto_block);
185 buflen = brcmf_create_iovar(name, data, len, drvr->proto_buf,
186 sizeof(drvr->proto_buf));
187 if (buflen) {
188 err = brcmf_fil_cmd_data(ifp, BRCMF_C_GET_VAR, drvr->proto_buf,
189 buflen, false);
190 if (err == 0)
191 memcpy(data, drvr->proto_buf, len);
192 } else {
193 err = -EPERM;
194 brcmf_err("Creating iovar failed\n");
197 brcmf_dbg(FIL, "name=%s, len=%d\n", name, len);
198 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data,
199 min_t(uint, len, MAX_HEX_DUMP_LEN), "data");
201 mutex_unlock(&drvr->proto_block);
202 return err;
206 brcmf_fil_iovar_int_set(struct brcmf_if *ifp, char *name, u32 data)
208 __le32 data_le = cpu_to_le32(data);
210 return brcmf_fil_iovar_data_set(ifp, name, &data_le, sizeof(data_le));
214 brcmf_fil_iovar_int_get(struct brcmf_if *ifp, char *name, u32 *data)
216 __le32 data_le = cpu_to_le32(*data);
217 s32 err;
219 err = brcmf_fil_iovar_data_get(ifp, name, &data_le, sizeof(data_le));
220 if (err == 0)
221 *data = le32_to_cpu(data_le);
222 return err;
225 static u32
226 brcmf_create_bsscfg(s32 bssidx, char *name, char *data, u32 datalen, char *buf,
227 u32 buflen)
229 const s8 *prefix = "bsscfg:";
230 s8 *p;
231 u32 prefixlen;
232 u32 namelen;
233 u32 iolen;
234 __le32 bssidx_le;
236 if (bssidx == 0)
237 return brcmf_create_iovar(name, data, datalen, buf, buflen);
239 prefixlen = strlen(prefix);
240 namelen = strlen(name) + 1; /* lengh of iovar name + null */
241 iolen = prefixlen + namelen + sizeof(bssidx_le) + datalen;
243 if (buflen < iolen) {
244 brcmf_err("buffer is too short\n");
245 return 0;
248 p = buf;
250 /* copy prefix, no null */
251 memcpy(p, prefix, prefixlen);
252 p += prefixlen;
254 /* copy iovar name including null */
255 memcpy(p, name, namelen);
256 p += namelen;
258 /* bss config index as first data */
259 bssidx_le = cpu_to_le32(bssidx);
260 memcpy(p, &bssidx_le, sizeof(bssidx_le));
261 p += sizeof(bssidx_le);
263 /* parameter buffer follows */
264 if (datalen)
265 memcpy(p, data, datalen);
267 return iolen;
271 brcmf_fil_bsscfg_data_set(struct brcmf_if *ifp, char *name,
272 void *data, u32 len)
274 struct brcmf_pub *drvr = ifp->drvr;
275 s32 err;
276 u32 buflen;
278 mutex_lock(&drvr->proto_block);
280 brcmf_dbg(FIL, "bssidx=%d, name=%s, len=%d\n", ifp->bssidx, name, len);
281 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data,
282 min_t(uint, len, MAX_HEX_DUMP_LEN), "data");
284 buflen = brcmf_create_bsscfg(ifp->bssidx, name, data, len,
285 drvr->proto_buf, sizeof(drvr->proto_buf));
286 if (buflen) {
287 err = brcmf_fil_cmd_data(ifp, BRCMF_C_SET_VAR, drvr->proto_buf,
288 buflen, true);
289 } else {
290 err = -EPERM;
291 brcmf_err("Creating bsscfg failed\n");
294 mutex_unlock(&drvr->proto_block);
295 return err;
299 brcmf_fil_bsscfg_data_get(struct brcmf_if *ifp, char *name,
300 void *data, u32 len)
302 struct brcmf_pub *drvr = ifp->drvr;
303 s32 err;
304 u32 buflen;
306 mutex_lock(&drvr->proto_block);
308 buflen = brcmf_create_bsscfg(ifp->bssidx, name, data, len,
309 drvr->proto_buf, sizeof(drvr->proto_buf));
310 if (buflen) {
311 err = brcmf_fil_cmd_data(ifp, BRCMF_C_GET_VAR, drvr->proto_buf,
312 buflen, false);
313 if (err == 0)
314 memcpy(data, drvr->proto_buf, len);
315 } else {
316 err = -EPERM;
317 brcmf_err("Creating bsscfg failed\n");
319 brcmf_dbg(FIL, "bssidx=%d, name=%s, len=%d\n", ifp->bssidx, name, len);
320 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data,
321 min_t(uint, len, MAX_HEX_DUMP_LEN), "data");
323 mutex_unlock(&drvr->proto_block);
324 return err;
329 brcmf_fil_bsscfg_int_set(struct brcmf_if *ifp, char *name, u32 data)
331 __le32 data_le = cpu_to_le32(data);
333 return brcmf_fil_bsscfg_data_set(ifp, name, &data_le,
334 sizeof(data_le));
338 brcmf_fil_bsscfg_int_get(struct brcmf_if *ifp, char *name, u32 *data)
340 __le32 data_le = cpu_to_le32(*data);
341 s32 err;
343 err = brcmf_fil_bsscfg_data_get(ifp, name, &data_le,
344 sizeof(data_le));
345 if (err == 0)
346 *data = le32_to_cpu(data_le);
347 return err;