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"
32 * expand feature list to array of feature strings.
34 #define BRCMF_FEAT_DEF(_f) \
36 static const char *brcmf_feat_names[] = {
41 struct brcmf_feat_fwcap {
42 enum brcmf_feat_id feature;
43 const char * const fwcap_id;
46 static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = {
47 { BRCMF_FEAT_MBSS, "mbss" },
48 { BRCMF_FEAT_MCHAN, "mchan" },
49 { BRCMF_FEAT_P2P, "p2p" },
54 * expand quirk list to array of quirk strings.
56 #define BRCMF_QUIRK_DEF(_q) \
58 static const char * const brcmf_quirk_names[] = {
61 #undef BRCMF_QUIRK_DEF
64 * brcmf_feat_debugfs_read() - expose feature info to debugfs.
66 * @seq: sequence for debugfs entry.
67 * @data: raw data pointer.
69 static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
71 struct brcmf_bus *bus_if = dev_get_drvdata(seq->private);
72 u32 feats = bus_if->drvr->feat_flags;
73 u32 quirks = bus_if->drvr->chip_quirks;
76 seq_printf(seq, "Features: %08x\n", feats);
77 for (id = 0; id < BRCMF_FEAT_LAST; id++)
79 seq_printf(seq, "\t%s\n", brcmf_feat_names[id]);
80 seq_printf(seq, "\nQuirks: %08x\n", quirks);
81 for (id = 0; id < BRCMF_FEAT_QUIRK_LAST; id++)
83 seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]);
87 static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
94 * brcmf_feat_iovar_int_get() - determine feature through iovar query.
96 * @ifp: interface to query.
100 static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
101 enum brcmf_feat_id id, char *name)
106 err = brcmf_fil_iovar_int_get(ifp, name, &data);
108 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
109 ifp->drvr->feat_flags |= BIT(id);
111 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
112 brcmf_feat_names[id], err);
116 static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp)
119 enum brcmf_feat_id id;
122 brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps));
123 brcmf_dbg(INFO, "[ %s]\n", caps);
125 for (i = 0; i < ARRAY_SIZE(brcmf_fwcap_map); i++) {
126 if (strnstr(caps, brcmf_fwcap_map[i].fwcap_id, sizeof(caps))) {
127 id = brcmf_fwcap_map[i].feature;
128 brcmf_dbg(INFO, "enabling feature: %s\n",
129 brcmf_feat_names[id]);
130 ifp->drvr->feat_flags |= BIT(id);
135 void brcmf_feat_attach(struct brcmf_pub *drvr)
137 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
138 struct brcmf_pno_macaddr_le pfn_mac;
142 brcmf_feat_firmware_capabilities(ifp);
144 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn");
145 if (drvr->bus_if->wowl_supported)
146 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl");
147 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) {
148 err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap);
150 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_WOWL_ARP_ND);
151 if (wowl_cap & BRCMF_WOWL_PFN_FOUND)
152 ifp->drvr->feat_flags |=
153 BIT(BRCMF_FEAT_WOWL_ND);
154 if (wowl_cap & BRCMF_WOWL_GTK_FAILURE)
155 ifp->drvr->feat_flags |=
156 BIT(BRCMF_FEAT_WOWL_GTK);
159 /* MBSS does not work for 43362 */
160 if (drvr->bus_if->chip == BRCM_CC_43362_CHIP_ID)
161 ifp->drvr->feat_flags &= ~BIT(BRCMF_FEAT_MBSS);
162 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode");
163 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable");
164 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MFP, "mfp");
166 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
167 err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac,
170 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC);
172 if (drvr->settings->feature_disable) {
173 brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n",
174 ifp->drvr->feat_flags,
175 drvr->settings->feature_disable);
176 ifp->drvr->feat_flags &= ~drvr->settings->feature_disable;
179 /* set chip related quirks */
180 switch (drvr->bus_if->chip) {
181 case BRCM_CC_43236_CHIP_ID:
182 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH);
184 case BRCM_CC_4329_CHIP_ID:
185 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC);
192 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read);
195 bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id)
197 return (ifp->drvr->feat_flags & BIT(id));
200 bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp,
201 enum brcmf_feat_quirk quirk)
203 return (ifp->drvr->chip_quirks & BIT(quirk));