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: error=%d\n", err
);
128 } else if (fwerr
< 0) {
129 brcmf_dbg(FIL
, "Firmware error: %s (%d)\n",
130 brcmf_fil_get_errstr((u32
)(-fwerr
)), fwerr
);
140 brcmf_fil_cmd_data_set(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
144 mutex_lock(&ifp
->drvr
->proto_block
);
146 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, len=%d\n", ifp
->ifidx
, cmd
, len
);
147 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
148 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
150 err
= brcmf_fil_cmd_data(ifp
, cmd
, data
, len
, true);
151 mutex_unlock(&ifp
->drvr
->proto_block
);
157 brcmf_fil_cmd_data_get(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
161 mutex_lock(&ifp
->drvr
->proto_block
);
162 err
= brcmf_fil_cmd_data(ifp
, cmd
, data
, len
, false);
164 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, len=%d\n", ifp
->ifidx
, cmd
, len
);
165 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
166 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
168 mutex_unlock(&ifp
->drvr
->proto_block
);
175 brcmf_fil_cmd_int_set(struct brcmf_if
*ifp
, u32 cmd
, u32 data
)
178 __le32 data_le
= cpu_to_le32(data
);
180 mutex_lock(&ifp
->drvr
->proto_block
);
181 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, value=%d\n", ifp
->ifidx
, cmd
, data
);
182 err
= brcmf_fil_cmd_data(ifp
, cmd
, &data_le
, sizeof(data_le
), true);
183 mutex_unlock(&ifp
->drvr
->proto_block
);
189 brcmf_fil_cmd_int_get(struct brcmf_if
*ifp
, u32 cmd
, u32
*data
)
192 __le32 data_le
= cpu_to_le32(*data
);
194 mutex_lock(&ifp
->drvr
->proto_block
);
195 err
= brcmf_fil_cmd_data(ifp
, cmd
, &data_le
, sizeof(data_le
), false);
196 mutex_unlock(&ifp
->drvr
->proto_block
);
197 *data
= le32_to_cpu(data_le
);
198 brcmf_dbg(FIL
, "ifidx=%d, cmd=%d, value=%d\n", ifp
->ifidx
, cmd
, *data
);
204 brcmf_create_iovar(char *name
, const char *data
, u32 datalen
,
205 char *buf
, u32 buflen
)
209 len
= strlen(name
) + 1;
211 if ((len
+ datalen
) > buflen
)
214 memcpy(buf
, name
, len
);
216 /* append data onto the end of the name string */
218 memcpy(&buf
[len
], data
, datalen
);
220 return len
+ datalen
;
225 brcmf_fil_iovar_data_set(struct brcmf_if
*ifp
, char *name
, const void *data
,
228 struct brcmf_pub
*drvr
= ifp
->drvr
;
232 mutex_lock(&drvr
->proto_block
);
234 brcmf_dbg(FIL
, "ifidx=%d, name=%s, len=%d\n", ifp
->ifidx
, name
, len
);
235 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
236 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
238 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
239 sizeof(drvr
->proto_buf
));
241 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
245 brcmf_err("Creating iovar failed\n");
248 mutex_unlock(&drvr
->proto_block
);
253 brcmf_fil_iovar_data_get(struct brcmf_if
*ifp
, char *name
, void *data
,
256 struct brcmf_pub
*drvr
= ifp
->drvr
;
260 mutex_lock(&drvr
->proto_block
);
262 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
263 sizeof(drvr
->proto_buf
));
265 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
268 memcpy(data
, drvr
->proto_buf
, len
);
271 brcmf_err("Creating iovar failed\n");
274 brcmf_dbg(FIL
, "ifidx=%d, name=%s, len=%d\n", ifp
->ifidx
, name
, len
);
275 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
276 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
278 mutex_unlock(&drvr
->proto_block
);
283 brcmf_fil_iovar_int_set(struct brcmf_if
*ifp
, char *name
, u32 data
)
285 __le32 data_le
= cpu_to_le32(data
);
287 return brcmf_fil_iovar_data_set(ifp
, name
, &data_le
, sizeof(data_le
));
291 brcmf_fil_iovar_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
293 __le32 data_le
= cpu_to_le32(*data
);
296 err
= brcmf_fil_iovar_data_get(ifp
, name
, &data_le
, sizeof(data_le
));
298 *data
= le32_to_cpu(data_le
);
303 brcmf_create_bsscfg(s32 bsscfgidx
, char *name
, char *data
, u32 datalen
,
304 char *buf
, u32 buflen
)
306 const s8
*prefix
= "bsscfg:";
314 return brcmf_create_iovar(name
, data
, datalen
, buf
, buflen
);
316 prefixlen
= strlen(prefix
);
317 namelen
= strlen(name
) + 1; /* lengh of iovar name + null */
318 iolen
= prefixlen
+ namelen
+ sizeof(bsscfgidx_le
) + datalen
;
320 if (buflen
< iolen
) {
321 brcmf_err("buffer is too short\n");
327 /* copy prefix, no null */
328 memcpy(p
, prefix
, prefixlen
);
331 /* copy iovar name including null */
332 memcpy(p
, name
, namelen
);
335 /* bss config index as first data */
336 bsscfgidx_le
= cpu_to_le32(bsscfgidx
);
337 memcpy(p
, &bsscfgidx_le
, sizeof(bsscfgidx_le
));
338 p
+= sizeof(bsscfgidx_le
);
340 /* parameter buffer follows */
342 memcpy(p
, data
, datalen
);
348 brcmf_fil_bsscfg_data_set(struct brcmf_if
*ifp
, char *name
,
351 struct brcmf_pub
*drvr
= ifp
->drvr
;
355 mutex_lock(&drvr
->proto_block
);
357 brcmf_dbg(FIL
, "ifidx=%d, bsscfgidx=%d, name=%s, len=%d\n", ifp
->ifidx
,
358 ifp
->bsscfgidx
, name
, len
);
359 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
360 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
362 buflen
= brcmf_create_bsscfg(ifp
->bsscfgidx
, name
, data
, len
,
363 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
365 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
369 brcmf_err("Creating bsscfg failed\n");
372 mutex_unlock(&drvr
->proto_block
);
377 brcmf_fil_bsscfg_data_get(struct brcmf_if
*ifp
, char *name
,
380 struct brcmf_pub
*drvr
= ifp
->drvr
;
384 mutex_lock(&drvr
->proto_block
);
386 buflen
= brcmf_create_bsscfg(ifp
->bsscfgidx
, name
, data
, len
,
387 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
389 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
392 memcpy(data
, drvr
->proto_buf
, len
);
395 brcmf_err("Creating bsscfg failed\n");
397 brcmf_dbg(FIL
, "ifidx=%d, bsscfgidx=%d, name=%s, len=%d\n", ifp
->ifidx
,
398 ifp
->bsscfgidx
, name
, len
);
399 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
400 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
402 mutex_unlock(&drvr
->proto_block
);
408 brcmf_fil_bsscfg_int_set(struct brcmf_if
*ifp
, char *name
, u32 data
)
410 __le32 data_le
= cpu_to_le32(data
);
412 return brcmf_fil_bsscfg_data_set(ifp
, name
, &data_le
,
417 brcmf_fil_bsscfg_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
419 __le32 data_le
= cpu_to_le32(*data
);
422 err
= brcmf_fil_bsscfg_data_get(ifp
, name
, &data_le
,
425 *data
= le32_to_cpu(data_le
);