2 * Copyright (c) 2014 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 #include <linux/netdevice.h>
18 #include <linux/module.h>
20 #include <brcm_hw_ids.h>
21 #include <brcmu_wifi.h>
26 #include "fwil_types.h"
30 #define BRCMF_FW_UNSUPPORTED 23
33 * expand feature list to array of feature strings.
35 #define BRCMF_FEAT_DEF(_f) \
37 static const char *brcmf_feat_names
[] = {
42 struct brcmf_feat_fwcap
{
43 enum brcmf_feat_id feature
;
44 const char * const fwcap_id
;
47 static const struct brcmf_feat_fwcap brcmf_fwcap_map
[] = {
48 { BRCMF_FEAT_MBSS
, "mbss" },
49 { BRCMF_FEAT_MCHAN
, "mchan" },
50 { BRCMF_FEAT_P2P
, "p2p" },
51 { BRCMF_FEAT_MONITOR
, "monitor" },
52 { BRCMF_FEAT_MONITOR_FMT_RADIOTAP
, "rtap" },
57 * expand quirk list to array of quirk strings.
59 #define BRCMF_QUIRK_DEF(_q) \
61 static const char * const brcmf_quirk_names
[] = {
64 #undef BRCMF_QUIRK_DEF
67 * brcmf_feat_debugfs_read() - expose feature info to debugfs.
69 * @seq: sequence for debugfs entry.
70 * @data: raw data pointer.
72 static int brcmf_feat_debugfs_read(struct seq_file
*seq
, void *data
)
74 struct brcmf_bus
*bus_if
= dev_get_drvdata(seq
->private);
75 u32 feats
= bus_if
->drvr
->feat_flags
;
76 u32 quirks
= bus_if
->drvr
->chip_quirks
;
79 seq_printf(seq
, "Features: %08x\n", feats
);
80 for (id
= 0; id
< BRCMF_FEAT_LAST
; id
++)
82 seq_printf(seq
, "\t%s\n", brcmf_feat_names
[id
]);
83 seq_printf(seq
, "\nQuirks: %08x\n", quirks
);
84 for (id
= 0; id
< BRCMF_FEAT_QUIRK_LAST
; id
++)
86 seq_printf(seq
, "\t%s\n", brcmf_quirk_names
[id
]);
90 static int brcmf_feat_debugfs_read(struct seq_file
*seq
, void *data
)
96 struct brcmf_feat_fwfeat
{
97 const char * const fwid
;
101 static const struct brcmf_feat_fwfeat brcmf_feat_fwfeat_map
[] = {
102 /* brcmfmac43602-pcie.ap.bin from linux-firmware.git commit ea1178515b88 */
103 { "01-6cb8e269", BIT(BRCMF_FEAT_MONITOR
) },
104 /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 52442afee990 */
105 { "01-c47a91a4", BIT(BRCMF_FEAT_MONITOR
) },
108 static void brcmf_feat_firmware_overrides(struct brcmf_pub
*drv
)
110 const struct brcmf_feat_fwfeat
*e
;
114 for (i
= 0; i
< ARRAY_SIZE(brcmf_feat_fwfeat_map
); i
++) {
115 e
= &brcmf_feat_fwfeat_map
[i
];
116 if (!strcmp(e
->fwid
, drv
->fwver
)) {
117 feat_flags
= e
->feat_flags
;
125 for (i
= 0; i
< BRCMF_FEAT_LAST
; i
++)
126 if (feat_flags
& BIT(i
))
127 brcmf_dbg(INFO
, "enabling firmware feature: %s\n",
128 brcmf_feat_names
[i
]);
129 drv
->feat_flags
|= feat_flags
;
133 * brcmf_feat_iovar_int_get() - determine feature through iovar query.
135 * @ifp: interface to query.
139 static void brcmf_feat_iovar_int_get(struct brcmf_if
*ifp
,
140 enum brcmf_feat_id id
, char *name
)
145 /* we need to know firmware error */
146 ifp
->fwil_fwerr
= true;
148 err
= brcmf_fil_iovar_int_get(ifp
, name
, &data
);
150 brcmf_dbg(INFO
, "enabling feature: %s\n", brcmf_feat_names
[id
]);
151 ifp
->drvr
->feat_flags
|= BIT(id
);
153 brcmf_dbg(TRACE
, "%s feature check failed: %d\n",
154 brcmf_feat_names
[id
], err
);
157 ifp
->fwil_fwerr
= false;
160 static void brcmf_feat_iovar_data_set(struct brcmf_if
*ifp
,
161 enum brcmf_feat_id id
, char *name
,
162 const void *data
, size_t len
)
166 /* we need to know firmware error */
167 ifp
->fwil_fwerr
= true;
169 err
= brcmf_fil_iovar_data_set(ifp
, name
, data
, len
);
170 if (err
!= -BRCMF_FW_UNSUPPORTED
) {
171 brcmf_dbg(INFO
, "enabling feature: %s\n", brcmf_feat_names
[id
]);
172 ifp
->drvr
->feat_flags
|= BIT(id
);
174 brcmf_dbg(TRACE
, "%s feature check failed: %d\n",
175 brcmf_feat_names
[id
], err
);
178 ifp
->fwil_fwerr
= false;
181 #define MAX_CAPS_BUFFER_SIZE 768
182 static void brcmf_feat_firmware_capabilities(struct brcmf_if
*ifp
)
184 char caps
[MAX_CAPS_BUFFER_SIZE
];
185 enum brcmf_feat_id id
;
188 err
= brcmf_fil_iovar_data_get(ifp
, "cap", caps
, sizeof(caps
));
190 brcmf_err("could not get firmware cap (%d)\n", err
);
194 brcmf_dbg(INFO
, "[ %s]\n", caps
);
196 for (i
= 0; i
< ARRAY_SIZE(brcmf_fwcap_map
); i
++) {
197 if (strnstr(caps
, brcmf_fwcap_map
[i
].fwcap_id
, sizeof(caps
))) {
198 id
= brcmf_fwcap_map
[i
].feature
;
199 brcmf_dbg(INFO
, "enabling feature: %s\n",
200 brcmf_feat_names
[id
]);
201 ifp
->drvr
->feat_flags
|= BIT(id
);
207 * brcmf_feat_fwcap_debugfs_read() - expose firmware capabilities to debugfs.
209 * @seq: sequence for debugfs entry.
210 * @data: raw data pointer.
212 static int brcmf_feat_fwcap_debugfs_read(struct seq_file
*seq
, void *data
)
214 struct brcmf_bus
*bus_if
= dev_get_drvdata(seq
->private);
215 struct brcmf_if
*ifp
= brcmf_get_ifp(bus_if
->drvr
, 0);
216 char caps
[MAX_CAPS_BUFFER_SIZE
+ 1] = { };
220 err
= brcmf_fil_iovar_data_get(ifp
, "cap", caps
, sizeof(caps
));
222 brcmf_err("could not get firmware cap (%d)\n", err
);
226 /* Put every capability in a new line */
227 for (tmp
= caps
; *tmp
; tmp
++) {
232 /* Usually there is a space at the end of capabilities string */
233 seq_printf(seq
, "%s", caps
);
234 /* So make sure we don't print two line breaks */
235 if (tmp
> caps
&& *(tmp
- 1) != '\n')
236 seq_printf(seq
, "\n");
241 void brcmf_feat_attach(struct brcmf_pub
*drvr
)
243 struct brcmf_if
*ifp
= brcmf_get_ifp(drvr
, 0);
244 struct brcmf_pno_macaddr_le pfn_mac
;
245 struct brcmf_gscan_config gscan_cfg
;
249 brcmf_feat_firmware_capabilities(ifp
);
250 memset(&gscan_cfg
, 0, sizeof(gscan_cfg
));
251 if (drvr
->bus_if
->chip
!= BRCM_CC_43430_CHIP_ID
&&
252 drvr
->bus_if
->chip
!= BRCM_CC_4345_CHIP_ID
)
253 brcmf_feat_iovar_data_set(ifp
, BRCMF_FEAT_GSCAN
,
255 &gscan_cfg
, sizeof(gscan_cfg
));
256 brcmf_feat_iovar_int_get(ifp
, BRCMF_FEAT_PNO
, "pfn");
257 if (drvr
->bus_if
->wowl_supported
)
258 brcmf_feat_iovar_int_get(ifp
, BRCMF_FEAT_WOWL
, "wowl");
259 if (brcmf_feat_is_enabled(ifp
, BRCMF_FEAT_WOWL
)) {
260 err
= brcmf_fil_iovar_int_get(ifp
, "wowl_cap", &wowl_cap
);
262 ifp
->drvr
->feat_flags
|= BIT(BRCMF_FEAT_WOWL_ARP_ND
);
263 if (wowl_cap
& BRCMF_WOWL_PFN_FOUND
)
264 ifp
->drvr
->feat_flags
|=
265 BIT(BRCMF_FEAT_WOWL_ND
);
266 if (wowl_cap
& BRCMF_WOWL_GTK_FAILURE
)
267 ifp
->drvr
->feat_flags
|=
268 BIT(BRCMF_FEAT_WOWL_GTK
);
271 /* MBSS does not work for 43362 */
272 if (drvr
->bus_if
->chip
== BRCM_CC_43362_CHIP_ID
)
273 ifp
->drvr
->feat_flags
&= ~BIT(BRCMF_FEAT_MBSS
);
274 brcmf_feat_iovar_int_get(ifp
, BRCMF_FEAT_RSDB
, "rsdb_mode");
275 brcmf_feat_iovar_int_get(ifp
, BRCMF_FEAT_TDLS
, "tdls_enable");
276 brcmf_feat_iovar_int_get(ifp
, BRCMF_FEAT_MFP
, "mfp");
278 pfn_mac
.version
= BRCMF_PFN_MACADDR_CFG_VER
;
279 err
= brcmf_fil_iovar_data_get(ifp
, "pfn_macaddr", &pfn_mac
,
282 ifp
->drvr
->feat_flags
|= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC
);
284 brcmf_feat_iovar_int_get(ifp
, BRCMF_FEAT_FWSUP
, "sup_wpa");
286 if (drvr
->settings
->feature_disable
) {
287 brcmf_dbg(INFO
, "Features: 0x%02x, disable: 0x%02x\n",
288 ifp
->drvr
->feat_flags
,
289 drvr
->settings
->feature_disable
);
290 ifp
->drvr
->feat_flags
&= ~drvr
->settings
->feature_disable
;
293 brcmf_feat_firmware_overrides(drvr
);
295 /* set chip related quirks */
296 switch (drvr
->bus_if
->chip
) {
297 case BRCM_CC_43236_CHIP_ID
:
298 drvr
->chip_quirks
|= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH
);
300 case BRCM_CC_4329_CHIP_ID
:
301 drvr
->chip_quirks
|= BIT(BRCMF_FEAT_QUIRK_NEED_MPC
);
309 void brcmf_feat_debugfs_create(struct brcmf_pub
*drvr
)
311 brcmf_debugfs_add_entry(drvr
, "features", brcmf_feat_debugfs_read
);
312 brcmf_debugfs_add_entry(drvr
, "fwcap", brcmf_feat_fwcap_debugfs_read
);
315 bool brcmf_feat_is_enabled(struct brcmf_if
*ifp
, enum brcmf_feat_id id
)
317 return (ifp
->drvr
->feat_flags
& BIT(id
));
320 bool brcmf_feat_is_quirk_enabled(struct brcmf_if
*ifp
,
321 enum brcmf_feat_quirk quirk
)
323 return (ifp
->drvr
->chip_quirks
& BIT(quirk
));