feature.c 8.6 KB

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