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> 18 #include <linux/module.h> 19 20 #include <brcm_hw_ids.h> 21 #include <brcmu_wifi.h> 22 #include "core.h" 23 #include "bus.h" 24 #include "debug.h" 25 #include "fwil.h" 26 #include "fwil_types.h" 27 #include "feature.h" 28 #include "common.h" 29 30 31 /* 32 * expand feature list to array of feature strings. 33 */ 34 #define BRCMF_FEAT_DEF(_f) \ 35 #_f, 36 static const char *brcmf_feat_names[] = { 37 BRCMF_FEAT_LIST 38 }; 39 #undef BRCMF_FEAT_DEF 40 41 struct brcmf_feat_fwcap { 42 enum brcmf_feat_id feature; 43 const char * const fwcap_id; 44 }; 45 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" }, 50 }; 51 52 #ifdef DEBUG 53 /* 54 * expand quirk list to array of quirk strings. 55 */ 56 #define BRCMF_QUIRK_DEF(_q) \ 57 #_q, 58 static 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 */ 69 static 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 87 static 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 */ 100 static 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 116 static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp) 117 { 118 char caps[256]; 119 enum brcmf_feat_id id; 120 int i; 121 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 } 132 } 133 } 134 135 void brcmf_feat_attach(struct brcmf_pub *drvr) 136 { 137 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0); 138 struct brcmf_pno_macaddr_le pfn_mac; 139 s32 err; 140 141 brcmf_feat_firmware_capabilities(ifp); 142 143 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn"); 144 if (drvr->bus_if->wowl_supported) 145 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl"); 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); 149 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode"); 150 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable"); 151 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 158 if (drvr->settings->feature_disable) { 159 brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n", 160 ifp->drvr->feat_flags, 161 drvr->settings->feature_disable); 162 ifp->drvr->feat_flags &= ~drvr->settings->feature_disable; 163 } 164 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 181 bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id) 182 { 183 return (ifp->drvr->feat_flags & BIT(id)); 184 } 185 186 bool 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 } 191