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>
28 #include "tracepoint.h"
33 #define MAX_HEX_DUMP_LEN 64
36 static const char * const brcmf_fil_errstr
[] = {
56 "BCME_OUTOFRANGECHAN",
68 "BCME_WME_NOT_ENABLED",
69 "BCME_TSPEC_NOTFOUND",
70 "BCME_ACM_NOTSUPPORTED",
71 "BCME_NOT_WME_ASSOCIATION",
78 "BCME_NMODE_DISABLED",
83 "BCME_SERIAL_PORT_ERR",
92 static const char *brcmf_fil_get_errstr(u32 err
)
94 if (err
>= ARRAY_SIZE(brcmf_fil_errstr
))
97 return brcmf_fil_errstr
[err
];
100 static const char *brcmf_fil_get_errstr(u32 err
)
107 brcmf_fil_cmd_data(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
, bool set
)
109 struct brcmf_pub
*drvr
= ifp
->drvr
;
112 if (drvr
->bus_if
->state
!= BRCMF_BUS_UP
) {
113 brcmf_err("bus is down. we have nothing to do.\n");
118 len
= min_t(uint
, len
, BRCMF_DCMD_MAXLEN
);
120 err
= brcmf_proto_set_dcmd(drvr
, ifp
->ifidx
, cmd
,
123 err
= brcmf_proto_query_dcmd(drvr
, ifp
->ifidx
, cmd
,
127 brcmf_dbg(FIL
, "Failed: %s (%d)\n",
128 brcmf_fil_get_errstr((u32
)(-err
)), err
);
129 } else if (fwerr
< 0) {
130 brcmf_dbg(FIL
, "Firmware error: %s (%d)\n",
131 brcmf_fil_get_errstr((u32
)(-fwerr
)), fwerr
);
141 brcmf_fil_cmd_data_set(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
145 mutex_lock(&ifp
->drvr
->proto_block
);
147 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, len=%d\n", ifp
->ifidx
, cmd
, len
);
148 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
149 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
151 err
= brcmf_fil_cmd_data(ifp
, cmd
, data
, len
, true);
152 mutex_unlock(&ifp
->drvr
->proto_block
);
158 brcmf_fil_cmd_data_get(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
162 mutex_lock(&ifp
->drvr
->proto_block
);
163 err
= brcmf_fil_cmd_data(ifp
, cmd
, data
, len
, false);
165 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, len=%d\n", ifp
->ifidx
, cmd
, len
);
166 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
167 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
169 mutex_unlock(&ifp
->drvr
->proto_block
);
176 brcmf_fil_cmd_int_set(struct brcmf_if
*ifp
, u32 cmd
, u32 data
)
179 __le32 data_le
= cpu_to_le32(data
);
181 mutex_lock(&ifp
->drvr
->proto_block
);
182 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, value=%d\n", ifp
->ifidx
, cmd
, data
);
183 err
= brcmf_fil_cmd_data(ifp
, cmd
, &data_le
, sizeof(data_le
), true);
184 mutex_unlock(&ifp
->drvr
->proto_block
);
190 brcmf_fil_cmd_int_get(struct brcmf_if
*ifp
, u32 cmd
, u32
*data
)
193 __le32 data_le
= cpu_to_le32(*data
);
195 mutex_lock(&ifp
->drvr
->proto_block
);
196 err
= brcmf_fil_cmd_data(ifp
, cmd
, &data_le
, sizeof(data_le
), false);
197 mutex_unlock(&ifp
->drvr
->proto_block
);
198 *data
= le32_to_cpu(data_le
);
199 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, value=%d\n", ifp
->ifidx
, cmd
, *data
);
205 brcmf_create_iovar(char *name
, const char *data
, u32 datalen
,
206 char *buf
, u32 buflen
)
210 len
= strlen(name
) + 1;
212 if ((len
+ datalen
) > buflen
)
215 memcpy(buf
, name
, len
);
217 /* append data onto the end of the name string */
219 memcpy(&buf
[len
], data
, datalen
);
221 return len
+ datalen
;
226 brcmf_fil_iovar_data_set(struct brcmf_if
*ifp
, char *name
, const void *data
,
229 struct brcmf_pub
*drvr
= ifp
->drvr
;
233 mutex_lock(&drvr
->proto_block
);
235 brcmf_dbg(FIL
, "ifidx=%d, name=%s, len=%d\n", ifp
->ifidx
, name
, len
);
236 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
237 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
239 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
240 sizeof(drvr
->proto_buf
));
242 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
246 brcmf_err("Creating iovar failed\n");
249 mutex_unlock(&drvr
->proto_block
);
254 brcmf_fil_iovar_data_get(struct brcmf_if
*ifp
, char *name
, void *data
,
257 struct brcmf_pub
*drvr
= ifp
->drvr
;
261 mutex_lock(&drvr
->proto_block
);
263 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
264 sizeof(drvr
->proto_buf
));
266 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
269 memcpy(data
, drvr
->proto_buf
, len
);
272 brcmf_err("Creating iovar failed\n");
275 brcmf_dbg(FIL
, "ifidx=%d, name=%s, len=%d\n", ifp
->ifidx
, name
, len
);
276 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
277 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
279 mutex_unlock(&drvr
->proto_block
);
284 brcmf_fil_iovar_int_set(struct brcmf_if
*ifp
, char *name
, u32 data
)
286 __le32 data_le
= cpu_to_le32(data
);
288 return brcmf_fil_iovar_data_set(ifp
, name
, &data_le
, sizeof(data_le
));
292 brcmf_fil_iovar_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
294 __le32 data_le
= cpu_to_le32(*data
);
297 err
= brcmf_fil_iovar_data_get(ifp
, name
, &data_le
, sizeof(data_le
));
299 *data
= le32_to_cpu(data_le
);
304 brcmf_create_bsscfg(s32 bsscfgidx
, char *name
, char *data
, u32 datalen
,
305 char *buf
, u32 buflen
)
307 const s8
*prefix
= "bsscfg:";
315 return brcmf_create_iovar(name
, data
, datalen
, buf
, buflen
);
317 prefixlen
= strlen(prefix
);
318 namelen
= strlen(name
) + 1; /* lengh of iovar name + null */
319 iolen
= prefixlen
+ namelen
+ sizeof(bsscfgidx_le
) + datalen
;
321 if (buflen
< iolen
) {
322 brcmf_err("buffer is too short\n");
328 /* copy prefix, no null */
329 memcpy(p
, prefix
, prefixlen
);
332 /* copy iovar name including null */
333 memcpy(p
, name
, namelen
);
336 /* bss config index as first data */
337 bsscfgidx_le
= cpu_to_le32(bsscfgidx
);
338 memcpy(p
, &bsscfgidx_le
, sizeof(bsscfgidx_le
));
339 p
+= sizeof(bsscfgidx_le
);
341 /* parameter buffer follows */
343 memcpy(p
, data
, datalen
);
349 brcmf_fil_bsscfg_data_set(struct brcmf_if
*ifp
, char *name
,
352 struct brcmf_pub
*drvr
= ifp
->drvr
;
356 mutex_lock(&drvr
->proto_block
);
358 brcmf_dbg(FIL
, "ifidx=%d, bsscfgidx=%d, name=%s, len=%d\n", ifp
->ifidx
,
359 ifp
->bsscfgidx
, name
, len
);
360 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
361 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
363 buflen
= brcmf_create_bsscfg(ifp
->bsscfgidx
, name
, data
, len
,
364 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
366 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
370 brcmf_err("Creating bsscfg failed\n");
373 mutex_unlock(&drvr
->proto_block
);
378 brcmf_fil_bsscfg_data_get(struct brcmf_if
*ifp
, char *name
,
381 struct brcmf_pub
*drvr
= ifp
->drvr
;
385 mutex_lock(&drvr
->proto_block
);
387 buflen
= brcmf_create_bsscfg(ifp
->bsscfgidx
, name
, data
, len
,
388 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
390 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
393 memcpy(data
, drvr
->proto_buf
, len
);
396 brcmf_err("Creating bsscfg failed\n");
398 brcmf_dbg(FIL
, "ifidx=%d, bsscfgidx=%d, name=%s, len=%d\n", ifp
->ifidx
,
399 ifp
->bsscfgidx
, name
, len
);
400 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
401 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
403 mutex_unlock(&drvr
->proto_block
);
409 brcmf_fil_bsscfg_int_set(struct brcmf_if
*ifp
, char *name
, u32 data
)
411 __le32 data_le
= cpu_to_le32(data
);
413 return brcmf_fil_bsscfg_data_set(ifp
, name
, &data_le
,
418 brcmf_fil_bsscfg_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
420 __le32 data_le
= cpu_to_le32(*data
);
423 err
= brcmf_fil_bsscfg_data_get(ifp
, name
, &data_le
,
426 *data
= le32_to_cpu(data_le
);