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 #define BRCMF_FW_UNSUPPORTED 23 31 32 /* 33 * expand feature list to array of feature strings. 34 */ 35 #define BRCMF_FEAT_DEF(_f) \ 36 #_f, 37 static const char *brcmf_feat_names[] = { 38 BRCMF_FEAT_LIST 39 }; 40 #undef BRCMF_FEAT_DEF 41 42 struct brcmf_feat_fwcap { 43 enum brcmf_feat_id feature; 44 const char * const fwcap_id; 45 }; 46 47 static 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 53 #ifdef DEBUG 54 /* 55 * expand quirk list to array of quirk strings. 56 */ 57 #define BRCMF_QUIRK_DEF(_q) \ 58 #_q, 59 static 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 */ 70 static 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 88 static 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 */ 101 static 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 /* we need to know firmware error */ 108 ifp->fwil_fwerr = true; 109 110 err = brcmf_fil_iovar_int_get(ifp, name, &data); 111 if (err == 0) { 112 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); 113 ifp->drvr->feat_flags |= BIT(id); 114 } else { 115 brcmf_dbg(TRACE, "%s feature check failed: %d\n", 116 brcmf_feat_names[id], err); 117 } 118 119 ifp->fwil_fwerr = false; 120 } 121 122 static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp, 123 enum brcmf_feat_id id, char *name, 124 const void *data, size_t len) 125 { 126 int err; 127 128 /* we need to know firmware error */ 129 ifp->fwil_fwerr = true; 130 131 err = brcmf_fil_iovar_data_set(ifp, name, data, len); 132 if (err != -BRCMF_FW_UNSUPPORTED) { 133 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); 134 ifp->drvr->feat_flags |= BIT(id); 135 } else { 136 brcmf_dbg(TRACE, "%s feature check failed: %d\n", 137 brcmf_feat_names[id], err); 138 } 139 140 ifp->fwil_fwerr = false; 141 } 142 143 #define MAX_CAPS_BUFFER_SIZE 512 144 static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp) 145 { 146 char caps[MAX_CAPS_BUFFER_SIZE]; 147 enum brcmf_feat_id id; 148 int i, err; 149 150 err = brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps)); 151 if (err) { 152 brcmf_err("could not get firmware cap (%d)\n", err); 153 return; 154 } 155 156 brcmf_dbg(INFO, "[ %s]\n", caps); 157 158 for (i = 0; i < ARRAY_SIZE(brcmf_fwcap_map); i++) { 159 if (strnstr(caps, brcmf_fwcap_map[i].fwcap_id, sizeof(caps))) { 160 id = brcmf_fwcap_map[i].feature; 161 brcmf_dbg(INFO, "enabling feature: %s\n", 162 brcmf_feat_names[id]); 163 ifp->drvr->feat_flags |= BIT(id); 164 } 165 } 166 } 167 168 /** 169 * brcmf_feat_fwcap_debugfs_read() - expose firmware capabilities to debugfs. 170 * 171 * @seq: sequence for debugfs entry. 172 * @data: raw data pointer. 173 */ 174 static int brcmf_feat_fwcap_debugfs_read(struct seq_file *seq, void *data) 175 { 176 struct brcmf_bus *bus_if = dev_get_drvdata(seq->private); 177 struct brcmf_if *ifp = brcmf_get_ifp(bus_if->drvr, 0); 178 char caps[MAX_CAPS_BUFFER_SIZE + 1] = { }; 179 char *tmp; 180 int err; 181 182 err = brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps)); 183 if (err) { 184 brcmf_err("could not get firmware cap (%d)\n", err); 185 return err; 186 } 187 188 /* Put every capability in a new line */ 189 for (tmp = caps; *tmp; tmp++) { 190 if (*tmp == ' ') 191 *tmp = '\n'; 192 } 193 194 /* Usually there is a space at the end of capabilities string */ 195 seq_printf(seq, "%s", caps); 196 /* So make sure we don't print two line breaks */ 197 if (tmp > caps && *(tmp - 1) != '\n') 198 seq_printf(seq, "\n"); 199 200 return 0; 201 } 202 203 void brcmf_feat_attach(struct brcmf_pub *drvr) 204 { 205 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0); 206 struct brcmf_pno_macaddr_le pfn_mac; 207 struct brcmf_gscan_config gscan_cfg; 208 u32 wowl_cap; 209 s32 err; 210 211 brcmf_feat_firmware_capabilities(ifp); 212 memset(&gscan_cfg, 0, sizeof(gscan_cfg)); 213 if (drvr->bus_if->chip != BRCM_CC_43430_CHIP_ID && 214 drvr->bus_if->chip != BRCM_CC_4345_CHIP_ID) 215 brcmf_feat_iovar_data_set(ifp, BRCMF_FEAT_GSCAN, 216 "pfn_gscan_cfg", 217 &gscan_cfg, sizeof(gscan_cfg)); 218 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn"); 219 if (drvr->bus_if->wowl_supported) 220 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl"); 221 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) { 222 err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap); 223 if (!err) { 224 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_WOWL_ARP_ND); 225 if (wowl_cap & BRCMF_WOWL_PFN_FOUND) 226 ifp->drvr->feat_flags |= 227 BIT(BRCMF_FEAT_WOWL_ND); 228 if (wowl_cap & BRCMF_WOWL_GTK_FAILURE) 229 ifp->drvr->feat_flags |= 230 BIT(BRCMF_FEAT_WOWL_GTK); 231 } 232 } 233 /* MBSS does not work for 43362 */ 234 if (drvr->bus_if->chip == BRCM_CC_43362_CHIP_ID) 235 ifp->drvr->feat_flags &= ~BIT(BRCMF_FEAT_MBSS); 236 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode"); 237 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable"); 238 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MFP, "mfp"); 239 240 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER; 241 err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac, 242 sizeof(pfn_mac)); 243 if (!err) 244 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC); 245 246 if (drvr->settings->feature_disable) { 247 brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n", 248 ifp->drvr->feat_flags, 249 drvr->settings->feature_disable); 250 ifp->drvr->feat_flags &= ~drvr->settings->feature_disable; 251 } 252 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_FWSUP, "sup_wpa"); 253 254 /* set chip related quirks */ 255 switch (drvr->bus_if->chip) { 256 case BRCM_CC_43236_CHIP_ID: 257 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH); 258 break; 259 case BRCM_CC_4329_CHIP_ID: 260 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC); 261 break; 262 default: 263 /* no quirks */ 264 break; 265 } 266 } 267 268 void brcmf_feat_debugfs_create(struct brcmf_pub *drvr) 269 { 270 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read); 271 brcmf_debugfs_add_entry(drvr, "fwcap", brcmf_feat_fwcap_debugfs_read); 272 } 273 274 bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id) 275 { 276 return (ifp->drvr->feat_flags & BIT(id)); 277 } 278 279 bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp, 280 enum brcmf_feat_quirk quirk) 281 { 282 return (ifp->drvr->chip_quirks & BIT(quirk)); 283 } 284