]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
Merge tag 'for-linus-20170825' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / broadcom / brcm80211 / brcmfmac / feature.c
CommitLineData
c08437b4
AS
1/*
2 * Copyright (c) 2014 Broadcom Corporation
3 *
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.
7 *
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.
15 */
16
17#include <linux/netdevice.h>
8268c201 18#include <linux/module.h>
c08437b4
AS
19
20#include <brcm_hw_ids.h>
48ed16e8 21#include <brcmu_wifi.h>
122d3d04 22#include "core.h"
d14f78b9 23#include "bus.h"
a8e8ed34 24#include "debug.h"
c08437b4 25#include "fwil.h"
48ed16e8 26#include "fwil_types.h"
c08437b4 27#include "feature.h"
7d34b056 28#include "common.h"
c08437b4 29
9fe929aa 30#define BRCMF_FW_UNSUPPORTED 23
8268c201 31
c08437b4
AS
32/*
33 * expand feature list to array of feature strings.
34 */
35#define BRCMF_FEAT_DEF(_f) \
36 #_f,
37static const char *brcmf_feat_names[] = {
38 BRCMF_FEAT_LIST
39};
40#undef BRCMF_FEAT_DEF
41
ec64241c
AS
42struct brcmf_feat_fwcap {
43 enum brcmf_feat_id feature;
44 const char * const fwcap_id;
45};
46
47static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = {
48 { BRCMF_FEAT_MBSS, "mbss" },
49 { BRCMF_FEAT_MCHAN, "mchan" },
50 { BRCMF_FEAT_P2P, "p2p" },
51};
52
c08437b4
AS
53#ifdef DEBUG
54/*
55 * expand quirk list to array of quirk strings.
56 */
57#define BRCMF_QUIRK_DEF(_q) \
58 #_q,
59static const char * const brcmf_quirk_names[] = {
60 BRCMF_QUIRK_LIST
61};
62#undef BRCMF_QUIRK_DEF
63
64/**
65 * brcmf_feat_debugfs_read() - expose feature info to debugfs.
66 *
67 * @seq: sequence for debugfs entry.
68 * @data: raw data pointer.
69 */
70static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
71{
72 struct brcmf_bus *bus_if = dev_get_drvdata(seq->private);
73 u32 feats = bus_if->drvr->feat_flags;
74 u32 quirks = bus_if->drvr->chip_quirks;
75 int id;
76
77 seq_printf(seq, "Features: %08x\n", feats);
78 for (id = 0; id < BRCMF_FEAT_LAST; id++)
79 if (feats & BIT(id))
80 seq_printf(seq, "\t%s\n", brcmf_feat_names[id]);
81 seq_printf(seq, "\nQuirks: %08x\n", quirks);
82 for (id = 0; id < BRCMF_FEAT_QUIRK_LAST; id++)
83 if (quirks & BIT(id))
84 seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]);
85 return 0;
86}
87#else
88static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
89{
90 return 0;
91}
92#endif /* DEBUG */
93
94/**
95 * brcmf_feat_iovar_int_get() - determine feature through iovar query.
96 *
97 * @ifp: interface to query.
98 * @id: feature id.
99 * @name: iovar name.
100 */
101static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
102 enum brcmf_feat_id id, char *name)
103{
104 u32 data;
105 int err;
106
107 err = brcmf_fil_iovar_int_get(ifp, name, &data);
108 if (err == 0) {
109 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
110 ifp->drvr->feat_flags |= BIT(id);
111 } else {
112 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
113 brcmf_feat_names[id], err);
114 }
115}
116
9fe929aa
AS
117static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp,
118 enum brcmf_feat_id id, char *name,
119 const void *data, size_t len)
120{
121 int err;
122
123 err = brcmf_fil_iovar_data_set(ifp, name, data, len);
124 if (err != -BRCMF_FW_UNSUPPORTED) {
125 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
126 ifp->drvr->feat_flags |= BIT(id);
127 } else {
128 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
129 brcmf_feat_names[id], err);
130 }
131}
132
ec64241c 133static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp)
a44aa400 134{
ec64241c
AS
135 char caps[256];
136 enum brcmf_feat_id id;
137 int i;
a44aa400 138
ec64241c
AS
139 brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps));
140 brcmf_dbg(INFO, "[ %s]\n", caps);
141
142 for (i = 0; i < ARRAY_SIZE(brcmf_fwcap_map); i++) {
143 if (strnstr(caps, brcmf_fwcap_map[i].fwcap_id, sizeof(caps))) {
144 id = brcmf_fwcap_map[i].feature;
145 brcmf_dbg(INFO, "enabling feature: %s\n",
146 brcmf_feat_names[id]);
147 ifp->drvr->feat_flags |= BIT(id);
148 }
a44aa400
HM
149 }
150}
151
c08437b4
AS
152void brcmf_feat_attach(struct brcmf_pub *drvr)
153{
46f3b6ee 154 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
48ed16e8 155 struct brcmf_pno_macaddr_le pfn_mac;
9fe929aa 156 struct brcmf_gscan_config gscan_cfg;
5c22fb85 157 u32 wowl_cap;
48ed16e8 158 s32 err;
c08437b4 159
ec64241c 160 brcmf_feat_firmware_capabilities(ifp);
9fe929aa 161 memset(&gscan_cfg, 0, sizeof(gscan_cfg));
e9bf53ab
AVS
162 if (drvr->bus_if->chip != BRCM_CC_43430_CHIP_ID)
163 brcmf_feat_iovar_data_set(ifp, BRCMF_FEAT_GSCAN,
164 "pfn_gscan_cfg",
165 &gscan_cfg, sizeof(gscan_cfg));
7a7a87dc 166 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn");
4eb3af7c
HM
167 if (drvr->bus_if->wowl_supported)
168 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl");
5c22fb85
HM
169 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) {
170 err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap);
171 if (!err) {
73ef9e64 172 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_WOWL_ARP_ND);
5c22fb85
HM
173 if (wowl_cap & BRCMF_WOWL_PFN_FOUND)
174 ifp->drvr->feat_flags |=
175 BIT(BRCMF_FEAT_WOWL_ND);
176 if (wowl_cap & BRCMF_WOWL_GTK_FAILURE)
177 ifp->drvr->feat_flags |=
178 BIT(BRCMF_FEAT_WOWL_GTK);
179 }
180 }
ec64241c
AS
181 /* MBSS does not work for 43362 */
182 if (drvr->bus_if->chip == BRCM_CC_43362_CHIP_ID)
183 ifp->drvr->feat_flags &= ~BIT(BRCMF_FEAT_MBSS);
8abffd81 184 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode");
a7b82d47 185 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable");
240d61a9 186 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MFP, "mfp");
c08437b4 187
48ed16e8
HM
188 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
189 err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac,
190 sizeof(pfn_mac));
191 if (!err)
192 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC);
193
7d34b056 194 if (drvr->settings->feature_disable) {
8268c201 195 brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n",
7d34b056
HM
196 ifp->drvr->feat_flags,
197 drvr->settings->feature_disable);
198 ifp->drvr->feat_flags &= ~drvr->settings->feature_disable;
8268c201 199 }
b8a64f0e 200 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_FWSUP, "sup_wpa");
8268c201 201
c08437b4
AS
202 /* set chip related quirks */
203 switch (drvr->bus_if->chip) {
204 case BRCM_CC_43236_CHIP_ID:
205 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH);
206 break;
207 case BRCM_CC_4329_CHIP_ID:
208 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC);
209 break;
210 default:
211 /* no quirks */
212 break;
213 }
214
215 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read);
216}
217
218bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id)
219{
220 return (ifp->drvr->feat_flags & BIT(id));
221}
222
223bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp,
224 enum brcmf_feat_quirk quirk)
225{
226 return (ifp->drvr->chip_quirks & BIT(quirk));
227}