feature.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. };
  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. * brcmf_feat_debugfs_read() - expose feature info to debugfs.
  58. *
  59. * @seq: sequence for debugfs entry.
  60. * @data: raw data pointer.
  61. */
  62. static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
  63. {
  64. struct brcmf_bus *bus_if = dev_get_drvdata(seq->private);
  65. u32 feats = bus_if->drvr->feat_flags;
  66. u32 quirks = bus_if->drvr->chip_quirks;
  67. int id;
  68. seq_printf(seq, "Features: %08x\n", feats);
  69. for (id = 0; id < BRCMF_FEAT_LAST; id++)
  70. if (feats & BIT(id))
  71. seq_printf(seq, "\t%s\n", brcmf_feat_names[id]);
  72. seq_printf(seq, "\nQuirks: %08x\n", quirks);
  73. for (id = 0; id < BRCMF_FEAT_QUIRK_LAST; id++)
  74. if (quirks & BIT(id))
  75. seq_printf(seq, "\t%s\n", brcmf_quirk_names[id]);
  76. return 0;
  77. }
  78. #else
  79. static int brcmf_feat_debugfs_read(struct seq_file *seq, void *data)
  80. {
  81. return 0;
  82. }
  83. #endif /* DEBUG */
  84. /**
  85. * brcmf_feat_iovar_int_get() - determine feature through iovar query.
  86. *
  87. * @ifp: interface to query.
  88. * @id: feature id.
  89. * @name: iovar name.
  90. */
  91. static void brcmf_feat_iovar_int_get(struct brcmf_if *ifp,
  92. enum brcmf_feat_id id, char *name)
  93. {
  94. u32 data;
  95. int err;
  96. /* we need to know firmware error */
  97. ifp->fwil_fwerr = true;
  98. err = brcmf_fil_iovar_int_get(ifp, name, &data);
  99. if (err == 0) {
  100. brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
  101. ifp->drvr->feat_flags |= BIT(id);
  102. } else {
  103. brcmf_dbg(TRACE, "%s feature check failed: %d\n",
  104. brcmf_feat_names[id], err);
  105. }
  106. ifp->fwil_fwerr = false;
  107. }
  108. static void brcmf_feat_iovar_data_set(struct brcmf_if *ifp,
  109. enum brcmf_feat_id id, char *name,
  110. const void *data, size_t len)
  111. {
  112. int err;
  113. /* we need to know firmware error */
  114. ifp->fwil_fwerr = true;
  115. err = brcmf_fil_iovar_data_set(ifp, name, data, len);
  116. if (err != -BRCMF_FW_UNSUPPORTED) {
  117. brcmf_dbg(INFO, "enabling feature: %s\n", brcmf_feat_names[id]);
  118. ifp->drvr->feat_flags |= BIT(id);
  119. } else {
  120. brcmf_dbg(TRACE, "%s feature check failed: %d\n",
  121. brcmf_feat_names[id], err);
  122. }
  123. ifp->fwil_fwerr = false;
  124. }
  125. #define MAX_CAPS_BUFFER_SIZE 512
  126. static void brcmf_feat_firmware_capabilities(struct brcmf_if *ifp)
  127. {
  128. char caps[MAX_CAPS_BUFFER_SIZE];
  129. enum brcmf_feat_id id;
  130. int i, err;
  131. err = brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps));
  132. if (err) {
  133. brcmf_err("could not get firmware cap (%d)\n", err);
  134. return;
  135. }
  136. brcmf_dbg(INFO, "[ %s]\n", caps);
  137. for (i = 0; i < ARRAY_SIZE(brcmf_fwcap_map); i++) {
  138. if (strnstr(caps, brcmf_fwcap_map[i].fwcap_id, sizeof(caps))) {
  139. id = brcmf_fwcap_map[i].feature;
  140. brcmf_dbg(INFO, "enabling feature: %s\n",
  141. brcmf_feat_names[id]);
  142. ifp->drvr->feat_flags |= BIT(id);
  143. }
  144. }
  145. }
  146. /**
  147. * brcmf_feat_fwcap_debugfs_read() - expose firmware capabilities to debugfs.
  148. *
  149. * @seq: sequence for debugfs entry.
  150. * @data: raw data pointer.
  151. */
  152. static int brcmf_feat_fwcap_debugfs_read(struct seq_file *seq, void *data)
  153. {
  154. struct brcmf_bus *bus_if = dev_get_drvdata(seq->private);
  155. struct brcmf_if *ifp = brcmf_get_ifp(bus_if->drvr, 0);
  156. char caps[MAX_CAPS_BUFFER_SIZE + 1] = { };
  157. char *tmp;
  158. int err;
  159. err = brcmf_fil_iovar_data_get(ifp, "cap", caps, sizeof(caps));
  160. if (err) {
  161. brcmf_err("could not get firmware cap (%d)\n", err);
  162. return err;
  163. }
  164. /* Put every capability in a new line */
  165. for (tmp = caps; *tmp; tmp++) {
  166. if (*tmp == ' ')
  167. *tmp = '\n';
  168. }
  169. /* Usually there is a space at the end of capabilities string */
  170. seq_printf(seq, "%s", caps);
  171. /* So make sure we don't print two line breaks */
  172. if (tmp > caps && *(tmp - 1) != '\n')
  173. seq_printf(seq, "\n");
  174. return 0;
  175. }
  176. void brcmf_feat_attach(struct brcmf_pub *drvr)
  177. {
  178. struct brcmf_if *ifp = brcmf_get_ifp(drvr, 0);
  179. struct brcmf_pno_macaddr_le pfn_mac;
  180. struct brcmf_gscan_config gscan_cfg;
  181. u32 wowl_cap;
  182. s32 err;
  183. brcmf_feat_firmware_capabilities(ifp);
  184. memset(&gscan_cfg, 0, sizeof(gscan_cfg));
  185. if (drvr->bus_if->chip != BRCM_CC_43430_CHIP_ID &&
  186. drvr->bus_if->chip != BRCM_CC_4345_CHIP_ID)
  187. brcmf_feat_iovar_data_set(ifp, BRCMF_FEAT_GSCAN,
  188. "pfn_gscan_cfg",
  189. &gscan_cfg, sizeof(gscan_cfg));
  190. brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_PNO, "pfn");
  191. if (drvr->bus_if->wowl_supported)
  192. brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_WOWL, "wowl");
  193. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL)) {
  194. err = brcmf_fil_iovar_int_get(ifp, "wowl_cap", &wowl_cap);
  195. if (!err) {
  196. ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_WOWL_ARP_ND);
  197. if (wowl_cap & BRCMF_WOWL_PFN_FOUND)
  198. ifp->drvr->feat_flags |=
  199. BIT(BRCMF_FEAT_WOWL_ND);
  200. if (wowl_cap & BRCMF_WOWL_GTK_FAILURE)
  201. ifp->drvr->feat_flags |=
  202. BIT(BRCMF_FEAT_WOWL_GTK);
  203. }
  204. }
  205. /* MBSS does not work for 43362 */
  206. if (drvr->bus_if->chip == BRCM_CC_43362_CHIP_ID)
  207. ifp->drvr->feat_flags &= ~BIT(BRCMF_FEAT_MBSS);
  208. brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_RSDB, "rsdb_mode");
  209. brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_TDLS, "tdls_enable");
  210. brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_MFP, "mfp");
  211. pfn_mac.version = BRCMF_PFN_MACADDR_CFG_VER;
  212. err = brcmf_fil_iovar_data_get(ifp, "pfn_macaddr", &pfn_mac,
  213. sizeof(pfn_mac));
  214. if (!err)
  215. ifp->drvr->feat_flags |= BIT(BRCMF_FEAT_SCAN_RANDOM_MAC);
  216. if (drvr->settings->feature_disable) {
  217. brcmf_dbg(INFO, "Features: 0x%02x, disable: 0x%02x\n",
  218. ifp->drvr->feat_flags,
  219. drvr->settings->feature_disable);
  220. ifp->drvr->feat_flags &= ~drvr->settings->feature_disable;
  221. }
  222. brcmf_feat_iovar_int_get(ifp, BRCMF_FEAT_FWSUP, "sup_wpa");
  223. /* set chip related quirks */
  224. switch (drvr->bus_if->chip) {
  225. case BRCM_CC_43236_CHIP_ID:
  226. drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_AUTO_AUTH);
  227. break;
  228. case BRCM_CC_4329_CHIP_ID:
  229. drvr->chip_quirks |= BIT(BRCMF_FEAT_QUIRK_NEED_MPC);
  230. break;
  231. default:
  232. /* no quirks */
  233. break;
  234. }
  235. }
  236. void brcmf_feat_debugfs_create(struct brcmf_pub *drvr)
  237. {
  238. brcmf_debugfs_add_entry(drvr, "features", brcmf_feat_debugfs_read);
  239. brcmf_debugfs_add_entry(drvr, "fwcap", brcmf_feat_fwcap_debugfs_read);
  240. }
  241. bool brcmf_feat_is_enabled(struct brcmf_if *ifp, enum brcmf_feat_id id)
  242. {
  243. return (ifp->drvr->feat_flags & BIT(id));
  244. }
  245. bool brcmf_feat_is_quirk_enabled(struct brcmf_if *ifp,
  246. enum brcmf_feat_quirk quirk)
  247. {
  248. return (ifp->drvr->chip_quirks & BIT(quirk));
  249. }