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>
19 #include <brcm_hw_ids.h>
27 * firmware error code received if iovar is unsupported.
29 #define EBRCMF_FEAT_UNSUPPORTED 23
32 * expand feature list to array of feature strings.
34 #define BRCMF_FEAT_DEF(_f) \
36 static const char *brcmf_feat_names[] = {
43 * expand quirk list to array of quirk strings.
45 #define BRCMF_QUIRK_DEF(_q) \
47 static const char * const brcmf_quirk_names[] = {
50 #undef BRCMF_QUIRK_DEF
53 * brcmf_feat_debugfs_read() - expose feature info to debugfs.
55 * @seq: sequence for debugfs entry.
56 * @data: raw data pointer.
58 static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
60 struct brcmf_bus *bus_if = dev_get_drvdata(seq->private);
61 u32 feats = bus_if->drvr->feat_flags;
62 u32 quirks = bus_if->drvr->chip_quirks;
65 seq_printf(seq, "Features: %08x\n", feats);
66 for (id = 0; id < BRCMF_FEAT_LAST; id++)
68 seq_printf(seq, "\t%s\n", brcmf_feat_names[id]);
69 seq_printf(seq, "\nQuirks: %08x\n", quirks);
70 for (id = 0; id < BRCMF_FEAT_QUIRK_LAST; id++)
72 seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]);
76 static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
83 * brcmf_feat_iovar_int_get() - determine feature through iovar query.
85 * @ifp: interface to query.
89 static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
90 enum brcmf_feat_id id, char *name)
95 err = brcmf_fil_iovar_int_get(ifp, name, &data);
97 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
98 ifp->drvr->feat_flags |= BIT(id);
100 brcmf_dbg(TRACE, "%s feature check failed: %d\n",
101 brcmf_feat_names[id], err);
105 void brcmf_feat_attach(struct brcmf_pub *drvr)
107 struct brcmf_if *ifp = drvr->iflist[0];
109 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MCHAN, "mchan");
110 if (drvr->bus_if->wowl_supported)
111 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl");
113 /* set chip related quirks */
114 switch (drvr->bus_if->chip) {
115 case BRCM_CC_43236_CHIP_ID:
116 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH);
118 case BRCM_CC_4329_CHIP_ID:
119 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC);
126 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read);
129 bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id)
131 return (ifp->drvr->feat_flags & BIT(id));
134 bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp,
135 enum brcmf_feat_quirk quirk)
137 return (ifp->drvr->chip_quirks & BIT(quirk));