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"
32 #define MAX_HEX_DUMP_LEN 64
36 brcmf_fil_cmd_data(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
, bool set
)
38 struct brcmf_pub
*drvr
= ifp
->drvr
;
41 if (drvr
->bus_if
->state
!= BRCMF_BUS_DATA
) {
42 brcmf_err("bus is down. we have nothing to do.\n");
47 len
= min_t(uint
, len
, BRCMF_DCMD_MAXLEN
);
49 err
= brcmf_proto_cdc_set_dcmd(drvr
, ifp
->ifidx
, cmd
, data
,
52 err
= brcmf_proto_cdc_query_dcmd(drvr
, ifp
->ifidx
, cmd
, data
,
58 brcmf_err("Failed err=%d\n", err
);
64 brcmf_fil_cmd_data_set(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
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
);
81 brcmf_fil_cmd_data_get(struct brcmf_if
*ifp
, u32 cmd
, void *data
, u32 len
)
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
);
99 brcmf_fil_cmd_int_set(struct brcmf_if
*ifp
, u32 cmd
, u32 data
)
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
);
113 brcmf_fil_cmd_int_get(struct brcmf_if
*ifp
, u32 cmd
, u32
*data
)
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
);
128 brcmf_create_iovar(char *name
, char *data
, u32 datalen
, char *buf
, u32 buflen
)
132 len
= strlen(name
) + 1;
134 if ((len
+ datalen
) > buflen
)
137 memcpy(buf
, name
, len
);
139 /* append data onto the end of the name string */
141 memcpy(&buf
[len
], data
, datalen
);
143 return len
+ datalen
;
148 brcmf_fil_iovar_data_set(struct brcmf_if
*ifp
, char *name
, void *data
,
151 struct brcmf_pub
*drvr
= ifp
->drvr
;
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
));
164 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
168 brcmf_err("Creating iovar failed\n");
171 mutex_unlock(&drvr
->proto_block
);
176 brcmf_fil_iovar_data_get(struct brcmf_if
*ifp
, char *name
, void *data
,
179 struct brcmf_pub
*drvr
= ifp
->drvr
;
183 mutex_lock(&drvr
->proto_block
);
185 buflen
= brcmf_create_iovar(name
, data
, len
, drvr
->proto_buf
,
186 sizeof(drvr
->proto_buf
));
188 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
191 memcpy(data
, drvr
->proto_buf
, len
);
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
);
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
);
219 err
= brcmf_fil_iovar_data_get(ifp
, name
, &data_le
, sizeof(data_le
));
221 *data
= le32_to_cpu(data_le
);
226 brcmf_create_bsscfg(s32 bssidx
, char *name
, char *data
, u32 datalen
, char *buf
,
229 const s8
*prefix
= "bsscfg:";
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");
250 /* copy prefix, no null */
251 memcpy(p
, prefix
, prefixlen
);
254 /* copy iovar name including null */
255 memcpy(p
, name
, 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 */
265 memcpy(p
, data
, datalen
);
271 brcmf_fil_bsscfg_data_set(struct brcmf_if
*ifp
, char *name
,
274 struct brcmf_pub
*drvr
= ifp
->drvr
;
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
));
287 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_SET_VAR
, drvr
->proto_buf
,
291 brcmf_err("Creating bsscfg failed\n");
294 mutex_unlock(&drvr
->proto_block
);
299 brcmf_fil_bsscfg_data_get(struct brcmf_if
*ifp
, char *name
,
302 struct brcmf_pub
*drvr
= ifp
->drvr
;
306 mutex_lock(&drvr
->proto_block
);
308 buflen
= brcmf_create_bsscfg(ifp
->bssidx
, name
, data
, len
,
309 drvr
->proto_buf
, sizeof(drvr
->proto_buf
));
311 err
= brcmf_fil_cmd_data(ifp
, BRCMF_C_GET_VAR
, drvr
->proto_buf
,
314 memcpy(data
, drvr
->proto_buf
, len
);
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
);
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
,
338 brcmf_fil_bsscfg_int_get(struct brcmf_if
*ifp
, char *name
, u32
*data
)
340 __le32 data_le
= cpu_to_le32(*data
);
343 err
= brcmf_fil_bsscfg_data_get(ifp
, name
, &data_le
,
346 *data
= le32_to_cpu(data_le
);