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
37 brcmf_fil_cmd_data(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
, bool set
)
39 struct brcmf_pub
*drvr
= ifp
->drvr
;
42 if (drvr
->bus_if
->state
!= BRCMF_BUS_DATA
) {
43 brcmf_err("bus is down. we have nothing to do.\n");
48 len
= min_t(uint
, len
, BRCMF_DCMD_MAXLEN
);
50 err
= brcmf_proto_set_dcmd(drvr
, ifp
->ifidx
, cmd
, data
, len
);
52 err
= brcmf_proto_query_dcmd(drvr
, ifp
->ifidx
, cmd
, data
, len
);
57 brcmf_err("Failed err=%d\n", err
);
63 brcmf_fil_cmd_data_set(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
67 mutex_lock(&ifp
->drvr
->proto_block
);
69 brcmf_dbg(FIL
, "cmd=%d, len=%d\n", cmd
, len
);
70 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
71 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
73 err
= brcmf_fil_cmd_data(ifp
, cmd
, data
, len
, true);
74 mutex_unlock(&ifp
->drvr
->proto_block
);
80 brcmf_fil_cmd_data_get(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
84 mutex_lock(&ifp
->drvr
->proto_block
);
85 err
= brcmf_fil_cmd_data(ifp
, cmd
, data
, len
, false);
87 brcmf_dbg(FIL
, "cmd=%d, len=%d\n", cmd
, len
);
88 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
89 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
91 mutex_unlock(&ifp
->drvr
->proto_block
);
98 brcmf_fil_cmd_int_set(struct brcmf_if
*ifp
, u32 cmd
, u32 data
)
101 __le32 data_le
= cpu_to_le32(data
);
103 mutex_lock(&ifp
->drvr
->proto_block
);
104 brcmf_dbg(FIL
, "cmd=%d, value=%d\n", cmd
, data
);
105 err
= brcmf_fil_cmd_data(ifp
, cmd
, &data_le
, sizeof(data_le
), true);
106 mutex_unlock(&ifp
->drvr
->proto_block
);
112 brcmf_fil_cmd_int_get(struct brcmf_if
*ifp
, u32 cmd
, u32
*data
)
115 __le32 data_le
= cpu_to_le32(*data
);
117 mutex_lock(&ifp
->drvr
->proto_block
);
118 err
= brcmf_fil_cmd_data(ifp
, cmd
, &data_le
, sizeof(data_le
), false);
119 mutex_unlock(&ifp
->drvr
->proto_block
);
120 *data
= le32_to_cpu(data_le
);
121 brcmf_dbg(FIL
, "cmd=%d, value=%d\n", cmd
, *data
);
127 brcmf_create_iovar(char *name
, char *data
, u32 datalen
, char *buf
, u32 buflen
)
131 len
= strlen(name
) + 1;
133 if ((len
+ datalen
) > buflen
)
136 memcpy(buf
, name
, len
);
138 /* append data onto the end of the name string */
140 memcpy(&buf
[len
], data
, datalen
);
142 return len
+ datalen
;
147 brcmf_fil_iovar_data_set(struct brcmf_if
*ifp
, char *name
, void *data
,
150 struct brcmf_pub
*drvr
= ifp
->drvr
;
154 mutex_lock(&drvr
->proto_block
);
156 brcmf_dbg(FIL
, "name=%s, len=%d\n", name
, len
);
157 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
158 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
160 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
161 sizeof(drvr
->proto_buf
));
163 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
167 brcmf_err("Creating iovar failed\n");
170 mutex_unlock(&drvr
->proto_block
);
175 brcmf_fil_iovar_data_get(struct brcmf_if
*ifp
, char *name
, void *data
,
178 struct brcmf_pub
*drvr
= ifp
->drvr
;
182 mutex_lock(&drvr
->proto_block
);
184 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
185 sizeof(drvr
->proto_buf
));
187 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
190 memcpy(data
, drvr
->proto_buf
, len
);
193 brcmf_err("Creating iovar failed\n");
196 brcmf_dbg(FIL
, "name=%s, len=%d\n", name
, len
);
197 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
198 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
200 mutex_unlock(&drvr
->proto_block
);
205 brcmf_fil_iovar_int_set(struct brcmf_if
*ifp
, char *name
, u32 data
)
207 __le32 data_le
= cpu_to_le32(data
);
209 return brcmf_fil_iovar_data_set(ifp
, name
, &data_le
, sizeof(data_le
));
213 brcmf_fil_iovar_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
215 __le32 data_le
= cpu_to_le32(*data
);
218 err
= brcmf_fil_iovar_data_get(ifp
, name
, &data_le
, sizeof(data_le
));
220 *data
= le32_to_cpu(data_le
);
225 brcmf_create_bsscfg(s32 bssidx
, char *name
, char *data
, u32 datalen
, char *buf
,
228 const s8
*prefix
= "bsscfg:";
236 return brcmf_create_iovar(name
, data
, datalen
, buf
, buflen
);
238 prefixlen
= strlen(prefix
);
239 namelen
= strlen(name
) + 1; /* lengh of iovar name + null */
240 iolen
= prefixlen
+ namelen
+ sizeof(bssidx_le
) + datalen
;
242 if (buflen
< iolen
) {
243 brcmf_err("buffer is too short\n");
249 /* copy prefix, no null */
250 memcpy(p
, prefix
, prefixlen
);
253 /* copy iovar name including null */
254 memcpy(p
, name
, namelen
);
257 /* bss config index as first data */
258 bssidx_le
= cpu_to_le32(bssidx
);
259 memcpy(p
, &bssidx_le
, sizeof(bssidx_le
));
260 p
+= sizeof(bssidx_le
);
262 /* parameter buffer follows */
264 memcpy(p
, data
, datalen
);
270 brcmf_fil_bsscfg_data_set(struct brcmf_if
*ifp
, char *name
,
273 struct brcmf_pub
*drvr
= ifp
->drvr
;
277 mutex_lock(&drvr
->proto_block
);
279 brcmf_dbg(FIL
, "bssidx=%d, name=%s, len=%d\n", ifp
->bssidx
, name
, len
);
280 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
281 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
283 buflen
= brcmf_create_bsscfg(ifp
->bssidx
, name
, data
, len
,
284 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
286 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
290 brcmf_err("Creating bsscfg failed\n");
293 mutex_unlock(&drvr
->proto_block
);
298 brcmf_fil_bsscfg_data_get(struct brcmf_if
*ifp
, char *name
,
301 struct brcmf_pub
*drvr
= ifp
->drvr
;
305 mutex_lock(&drvr
->proto_block
);
307 buflen
= brcmf_create_bsscfg(ifp
->bssidx
, name
, data
, len
,
308 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
310 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
313 memcpy(data
, drvr
->proto_buf
, len
);
316 brcmf_err("Creating bsscfg failed\n");
318 brcmf_dbg(FIL
, "bssidx=%d, name=%s, len=%d\n", ifp
->bssidx
, name
, len
);
319 brcmf_dbg_hex_dump(BRCMF_FIL_ON(), data
,
320 min_t(uint
, len
, MAX_HEX_DUMP_LEN
), "data\n");
322 mutex_unlock(&drvr
->proto_block
);
328 brcmf_fil_bsscfg_int_set(struct brcmf_if
*ifp
, char *name
, u32 data
)
330 __le32 data_le
= cpu_to_le32(data
);
332 return brcmf_fil_bsscfg_data_set(ifp
, name
, &data_le
,
337 brcmf_fil_bsscfg_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
339 __le32 data_le
= cpu_to_le32(*data
);
342 err
= brcmf_fil_bsscfg_data_get(ifp
, name
, &data_le
,
345 *data
= le32_to_cpu(data_le
);