]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c
brcmfmac: move module init and exit to common
[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
8268c201 30
c08437b4
AS
31/*
32 * expand feature list to array of feature strings.
33 */
34#define BRCMF_FEAT_DEF(_f) \
35 #_f,
36static const char *brcmf_feat_names[] = {
37 BRCMF_FEAT_LIST
38};
39#undef BRCMF_FEAT_DEF
40
ec64241c
AS
41struct brcmf_feat_fwcap {
42 enum brcmf_feat_id feature;
43 const char * const fwcap_id;
44};
45
46static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = {
47 { BRCMF_FEAT_MBSS, "mbss" },
48 { BRCMF_FEAT_MCHAN, "mchan" },
49 { BRCMF_FEAT_P2P, "p2p" },
50};
51
c08437b4
AS
52#ifdef DEBUG
53/*
54 * expand quirk list to array of quirk strings.
55 */
56#define BRCMF_QUIRK_DEF(_q) \
57 #_q,
58static const char * const brcmf_quirk_names[] = {
59 BRCMF_QUIRK_LIST
60};
61#undef BRCMF_QUIRK_DEF
62
63/**
64 * brcmf_feat_debugfs_read() - expose feature info to debugfs.
65 *
66 * @seq: sequence for debugfs entry.
67 * @data: raw data pointer.
68 */
69static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
70{
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;
74 int id;
75
76 seq_printf(seq, "Features: %08x\n", feats);
77 for (id = 0; id < BRCMF_FEAT_LAST; id++)
78 if (feats & BIT(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++)
82 if (quirks & BIT(id))
83 seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]);
84 return 0;
85}
86#else
87static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
88{
89 return 0;
90}
91#endif /* DEBUG */
92
93/**
94 * brcmf_feat_iovar_int_get() - determine feature through iovar query.
95 *
96 * @ifp: interface to query.
97 * @id: feature id.
98 * @name: iovar name.
99 */
100static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
101 enum brcmf_feat_id id, char *name)
102{
103 u32 data;
104 int err;
105
106 err = brcmf_fil_iovar_int_get(ifp, name, &data);
107 if (err == 0) {
108 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
109 ifp->drvr->feat_flags |= BIT(id);
110 } else {
111 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
112 brcmf_feat_names[id], err);
113 }
114}
115
ec64241c 116static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp)
a44aa400 117{
ec64241c
AS
118 char caps[256];
119 enum brcmf_feat_id id;
120 int i;
a44aa400 121
ec64241c
AS
122 brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps));
123 brcmf_dbg(INFO, "[ %s]\n", caps);
124
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);
131 }
a44aa400
HM
132 }
133}
134
c08437b4
AS
135void brcmf_feat_attach(struct brcmf_pub *drvr)
136{
46f3b6ee 137 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
48ed16e8
HM
138 struct brcmf_pno_macaddr_le pfn_mac;
139 s32 err;
c08437b4 140
ec64241c
AS
141 brcmf_feat_firmware_capabilities(ifp);
142
7a7a87dc 143 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn");
4eb3af7c
HM
144 if (drvr->bus_if->wowl_supported)
145 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl");
ec64241c
AS
146 /* MBSS does not work for 43362 */
147 if (drvr->bus_if->chip == BRCM_CC_43362_CHIP_ID)
148 ifp->drvr->feat_flags &= ~BIT(BRCMF_FEAT_MBSS);
8abffd81 149 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode");
a7b82d47 150 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable");
c08437b4 151
48ed16e8
HM
152 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
153 err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac,
154 sizeof(pfn_mac));
155 if (!err)
156 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC);
157
7d34b056 158 if (drvr->settings->feature_disable) {
8268c201 159 brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n",
7d34b056
HM
160 ifp->drvr->feat_flags,
161 drvr->settings->feature_disable);
162 ifp->drvr->feat_flags &= ~drvr->settings->feature_disable;
8268c201
HM
163 }
164
c08437b4
AS
165 /* set chip related quirks */
166 switch (drvr->bus_if->chip) {
167 case BRCM_CC_43236_CHIP_ID:
168 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH);
169 break;
170 case BRCM_CC_4329_CHIP_ID:
171 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC);
172 break;
173 default:
174 /* no quirks */
175 break;
176 }
177
178 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read);
179}
180
181bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id)
182{
183 return (ifp->drvr->feat_flags & BIT(id));
184}
185
186bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp,
187 enum brcmf_feat_quirk quirk)
188{
189 return (ifp->drvr->chip_quirks & BIT(quirk));
190}