1 // SPDX-License-Identifier: ISC 2 /* 3 * Copyright (c) 2014 Broadcom Corporation 4 */ 5 6 #include <linux/netdevice.h> 7 #include <linux/module.h> 8 9 #include <brcm_hw_ids.h> 10 #include <brcmu_wifi.h> 11 #include "core.h" 12 #include "bus.h" 13 #include "debug.h" 14 #include "fwil.h" 15 #include "fwil_types.h" 16 #include "feature.h" 17 #include "common.h" 18 19 #define BRCMF_FW_UNSUPPORTED 23 20 21 /* 22 * expand feature list to array of feature strings. 23 */ 24 #define BRCMF_FEAT_DEF(_f) \ 25 #_f, 26 static const char *brcmf_feat_names[] = { 27 BRCMF_FEAT_LIST 28 }; 29 #undef BRCMF_FEAT_DEF 30 31 struct brcmf_feat_fwcap { 32 enum brcmf_feat_id feature; 33 const char * const fwcap_id; 34 }; 35 36 static const struct brcmf_feat_fwcap brcmf_fwcap_map[] = { 37 { BRCMF_FEAT_MBSS, "mbss" }, 38 { BRCMF_FEAT_MCHAN, "mchan" }, 39 { BRCMF_FEAT_P2P, "p2p" }, 40 { BRCMF_FEAT_MONITOR, "monitor" }, 41 { BRCMF_FEAT_MONITOR_FMT_RADIOTAP, "rtap" }, 42 { BRCMF_FEAT_DOT11H, "802.11h" }, 43 { BRCMF_FEAT_SAE, "sae" }, 44 }; 45 46 #ifdef DEBUG 47 /* 48 * expand quirk list to array of quirk strings. 49 */ 50 #define BRCMF_QUIRK_DEF(_q) \ 51 #_q, 52 static const char * const brcmf_quirk_names[] = { 53 BRCMF_QUIRK_LIST 54 }; 55 #undef BRCMF_QUIRK_DEF 56 57 /** 58 * brcmf_feat_debugfs_read() - expose feature info to debugfs. 59 * 60 * @seq: sequence for debugfs entry. 61 * @data: raw data pointer. 62 */ 63 static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data) 64 { 65 struct brcmf_bus *bus_if = dev_get_drvdata(seq->private); 66 u32 feats = bus_if->drvr->feat_flags; 67 u32 quirks = bus_if->drvr->chip_quirks; 68 int id; 69 70 seq_printf(seq, "Features: %08x\n", feats); 71 for (id = 0; id < BRCMF_FEAT_LAST; id++) 72 if (feats & BIT(id)) 73 seq_printf(seq, "\t%s\n", brcmf_feat_names[id]); 74 seq_printf(seq, "\nQuirks: %08x\n", quirks); 75 for (id = 0; id < BRCMF_FEAT_QUIRK_LAST; id++) 76 if (quirks & BIT(id)) 77 seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]); 78 return 0; 79 } 80 #else 81 static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data) 82 { 83 return 0; 84 } 85 #endif /* DEBUG */ 86 87 struct brcmf_feat_fwfeat { 88 const char * const fwid; 89 u32 feat_flags; 90 }; 91 92 static const struct brcmf_feat_fwfeat brcmf_feat_fwfeat_map[] = { 93 /* brcmfmac43602-pcie.ap.bin from linux-firmware.git commit ea1178515b88 */ 94 { "01-6cb8e269", BIT(BRCMF_FEAT_MONITOR) }, 95 /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 52442afee990 */ 96 { "01-c47a91a4", BIT(BRCMF_FEAT_MONITOR) }, 97 /* brcmfmac4366b-pcie.bin from linux-firmware.git commit 211de1679a68 */ 98 { "01-801fb449", BIT(BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR) }, 99 /* brcmfmac4366c-pcie.bin from linux-firmware.git commit 211de1679a68 */ 100 { "01-d2cbb8fd", BIT(BRCMF_FEAT_MONITOR_FMT_HW_RX_HDR) }, 101 }; 102 103 static void brcmf_feat_firmware_overrides(struct brcmf_pub *drv) 104 { 105 const struct brcmf_feat_fwfeat *e; 106 u32 feat_flags = 0; 107 int i; 108 109 for (i = 0; i < ARRAY_SIZE(brcmf_feat_fwfeat_map); i++) { 110 e = &brcmf_feat_fwfeat_map[i]; 111 if (!strcmp(e->fwid, drv->fwver)) { 112 feat_flags = e->feat_flags; 113 break; 114 } 115 } 116 117 if (!feat_flags) 118 return; 119 120 for (i = 0; i < BRCMF_FEAT_LAST; i++) 121 if (feat_flags & BIT(i)) 122 brcmf_dbg(INFO, "enabling firmware feature: %s\n", 123 brcmf_feat_names[i]); 124 drv->feat_flags |= feat_flags; 125 } 126 127 /** 128 * brcmf_feat_iovar_int_get() - determine feature through iovar query. 129 * 130 * @ifp: interface to query. 131 * @id: feature id. 132 * @name: iovar name. 133 */ 134 static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp, 135 enum brcmf_feat_id id, char *name) 136 { 137 u32 data; 138 int err; 139 140 /* we need to know firmware error */ 141 ifp->fwil_fwerr = true; 142 143 err = brcmf_fil_iovar_int_get(ifp, name, &data); 144 if (err == 0) { 145 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); 146 ifp->drvr->feat_flags |= BIT(id); 147 } else { 148 brcmf_dbg(TRACE, "%s feature check failed: %d\n", 149 brcmf_feat_names[id], err); 150 } 151 152 ifp->fwil_fwerr = false; 153 } 154 155 static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp, 156 enum brcmf_feat_id id, char *name, 157 const void *data, size_t len) 158 { 159 int err; 160 161 /* we need to know firmware error */ 162 ifp->fwil_fwerr = true; 163 164 err = brcmf_fil_iovar_data_set(ifp, name, data, len); 165 if (err != -BRCMF_FW_UNSUPPORTED) { 166 brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]); 167 ifp->drvr->feat_flags |= BIT(id); 168 } else { 169 brcmf_dbg(TRACE, "%s feature check failed: %d\n", 170 brcmf_feat_names[id], err); 171 } 172 173 ifp->fwil_fwerr = false; 174 } 175 176 #define MAX_CAPS_BUFFER_SIZE 768 177 static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp) 178 { 179 struct brcmf_pub *drvr = ifp->drvr; 180 char caps[MAX_CAPS_BUFFER_SIZE]; 181 enum brcmf_feat_id id; 182 int i, err; 183 184 err = brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps)); 185 if (err) { 186 bphy_err(drvr, "could not get firmware cap (%d)\n", err); 187 return; 188 } 189 190 brcmf_dbg(INFO, "[ %s]\n", caps); 191 192 for (i = 0; i < ARRAY_SIZE(brcmf_fwcap_map); i++) { 193 if (strnstr(caps, brcmf_fwcap_map[i].fwcap_id, sizeof(caps))) { 194 id = brcmf_fwcap_map[i].feature; 195 brcmf_dbg(INFO, "enabling feature: %s\n", 196 brcmf_feat_names[id]); 197 ifp->drvr->feat_flags |= BIT(id); 198 } 199 } 200 } 201 202 /** 203 * brcmf_feat_fwcap_debugfs_read() - expose firmware capabilities to debugfs. 204 * 205 * @seq: sequence for debugfs entry. 206 * @data: raw data pointer. 207 */ 208 static int brcmf_feat_fwcap_debugfs_read(struct seq_file *seq, void *data) 209 { 210 struct brcmf_bus *bus_if = dev_get_drvdata(seq->private); 211 struct brcmf_pub *drvr = bus_if->drvr; 212 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0); 213 char caps[MAX_CAPS_BUFFER_SIZE + 1] = { }; 214 char *tmp; 215 int err; 216 217 err = brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps)); 218 if (err) { 219 bphy_err(drvr, "could not get firmware cap (%d)\n", err); 220 return err; 221 } 222 223 /* Put every capability in a new line */ 224 for (tmp = caps; *tmp; tmp++) { 225 if (*tmp == ' ') 226 *tmp = '\n'; 227 } 228 229 /* Usually there is a space at the end of capabilities string */ 230 seq_printf(seq, "%s", caps); 231 /* So make sure we don't print two line breaks */ 232 if (tmp > caps && *(tmp - 1) != '\n') 233 seq_printf(seq, "\n"); 234 235 return 0; 236 } 237 238 void brcmf_feat_attach(struct brcmf_pub *drvr) 239 { 240 struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0); 241 struct brcmf_pno_macaddr_le pfn_mac; 242 struct brcmf_gscan_config gscan_cfg; 243 u32 wowl_cap; 244 s32 err; 245 246 brcmf_feat_firmware_capabilities(ifp); 247 memset(&gscan_cfg, 0, sizeof(gscan_cfg)); 248 if (drvr->bus_if->chip != BRCM_CC_43430_CHIP_ID && 249 drvr->bus_if->chip != BRCM_CC_4345_CHIP_ID) 250 brcmf_feat_iovar_data_set(ifp, BRCMF_FEAT_GSCAN, 251 "pfn_gscan_cfg", 252 &gscan_cfg, sizeof(gscan_cfg)); 253 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn"); 254 if (drvr->bus_if->wowl_supported) 255 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl"); 256 if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) { 257 err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap); 258 if (!err) { 259 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_WOWL_ARP_ND); 260 if (wowl_cap & BRCMF_WOWL_PFN_FOUND) 261 ifp->drvr->feat_flags |= 262 BIT(BRCMF_FEAT_WOWL_ND); 263 if (wowl_cap & BRCMF_WOWL_GTK_FAILURE) 264 ifp->drvr->feat_flags |= 265 BIT(BRCMF_FEAT_WOWL_GTK); 266 } 267 } 268 /* MBSS does not work for all chips */ 269 switch (drvr->bus_if->chip) { 270 case BRCM_CC_4330_CHIP_ID: 271 case BRCM_CC_43362_CHIP_ID: 272 ifp->drvr->feat_flags &= ~BIT(BRCMF_FEAT_MBSS); 273 break; 274 default: 275 break; 276 } 277 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode"); 278 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable"); 279 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MFP, "mfp"); 280 281 pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER; 282 err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac, 283 sizeof(pfn_mac)); 284 if (!err) 285 ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC); 286 287 if (drvr->settings->feature_disable) { 288 brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n", 289 ifp->drvr->feat_flags, 290 drvr->settings->feature_disable); 291 ifp->drvr->feat_flags &= ~drvr->settings->feature_disable; 292 } 293 brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_FWSUP, "sup_wpa"); 294 295 brcmf_feat_firmware_overrides(drvr); 296 297 /* set chip related quirks */ 298 switch (drvr->bus_if->chip) { 299 case BRCM_CC_43236_CHIP_ID: 300 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH); 301 break; 302 case BRCM_CC_4329_CHIP_ID: 303 drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC); 304 break; 305 default: 306 /* no quirks */ 307 break; 308 } 309 } 310 311 void brcmf_feat_debugfs_create(struct brcmf_pub *drvr) 312 { 313 brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read); 314 brcmf_debugfs_add_entry(drvr, "fwcap", brcmf_feat_fwcap_debugfs_read); 315 } 316 317 bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id) 318 { 319 return (ifp->drvr->feat_flags & BIT(id)); 320 } 321 322 bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp, 323 enum brcmf_feat_quirk quirk) 324 { 325 return (ifp->drvr->chip_quirks & BIT(quirk)); 326 } 327