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 u32 wowl_cap; 140 s32 err; 141 142 brcmf_feat_firmware_capabilities(ifp); 143 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); 149 if (!err) { 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); 157 } 158 } 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"); 165 166 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER; 167 err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac, 168 sizeof(pfn_mac)); 169 if (!err) 170 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC); 171 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; 177 } 178 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); 183 break; 184 case BRCM_CC_4329_CHIP_ID: 185 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC); 186 break; 187 default: 188 /* no quirks */ 189 break; 190 } 191 192 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read); 193 } 194 195 bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id) 196 { 197 return (ifp->drvr->feat_flags & BIT(id)); 198 } 199 200 bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp, 201 enum brcmf_feat_quirk quirk) 202 { 203 return (ifp->drvr->chip_quirks & BIT(quirk)); 204 } 205