common.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * Copyright (c) 2010 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/kernel.h>
  17. #include <linux/string.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/module.h>
  20. #include <brcmu_wifi.h>
  21. #include <brcmu_utils.h>
  22. #include "core.h"
  23. #include "bus.h"
  24. #include "debug.h"
  25. #include "fwil.h"
  26. #include "fwil_types.h"
  27. #include "tracepoint.h"
  28. #include "common.h"
  29. #include "of.h"
  30. MODULE_AUTHOR("Broadcom Corporation");
  31. MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
  32. MODULE_LICENSE("Dual BSD/GPL");
  33. const u8 ALLFFMAC[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  34. #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME 40
  35. #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME 40
  36. /* default boost value for RSSI_DELTA in preferred join selection */
  37. #define BRCMF_JOIN_PREF_RSSI_BOOST 8
  38. #define BRCMF_DEFAULT_TXGLOM_SIZE 32 /* max tx frames in glom chain */
  39. static int brcmf_sdiod_txglomsz = BRCMF_DEFAULT_TXGLOM_SIZE;
  40. module_param_named(txglomsz, brcmf_sdiod_txglomsz, int, 0);
  41. MODULE_PARM_DESC(txglomsz, "Maximum tx packet chain size [SDIO]");
  42. /* Debug level configuration. See debug.h for bits, sysfs modifiable */
  43. int brcmf_msg_level;
  44. module_param_named(debug, brcmf_msg_level, int, S_IRUSR | S_IWUSR);
  45. MODULE_PARM_DESC(debug, "Level of debug output");
  46. static int brcmf_p2p_enable;
  47. module_param_named(p2pon, brcmf_p2p_enable, int, 0);
  48. MODULE_PARM_DESC(p2pon, "Enable legacy p2p management functionality");
  49. static int brcmf_feature_disable;
  50. module_param_named(feature_disable, brcmf_feature_disable, int, 0);
  51. MODULE_PARM_DESC(feature_disable, "Disable features");
  52. static char brcmf_firmware_path[BRCMF_FW_ALTPATH_LEN];
  53. module_param_string(alternative_fw_path, brcmf_firmware_path,
  54. BRCMF_FW_ALTPATH_LEN, S_IRUSR);
  55. MODULE_PARM_DESC(alternative_fw_path, "Alternative firmware path");
  56. static int brcmf_fcmode;
  57. module_param_named(fcmode, brcmf_fcmode, int, 0);
  58. MODULE_PARM_DESC(fcmode, "Mode of firmware signalled flow control");
  59. static int brcmf_roamoff;
  60. module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
  61. MODULE_PARM_DESC(roamoff, "Do not use internal roaming engine");
  62. #ifdef DEBUG
  63. /* always succeed brcmf_bus_start() */
  64. static int brcmf_ignore_probe_fail;
  65. module_param_named(ignore_probe_fail, brcmf_ignore_probe_fail, int, 0);
  66. MODULE_PARM_DESC(ignore_probe_fail, "always succeed probe for debugging");
  67. #endif
  68. static struct brcmfmac_platform_data *brcmfmac_pdata;
  69. struct brcmf_mp_global_t brcmf_mp_global;
  70. void brcmf_c_set_joinpref_default(struct brcmf_if *ifp)
  71. {
  72. struct brcmf_join_pref_params join_pref_params[2];
  73. int err;
  74. /* Setup join_pref to select target by RSSI (boost on 5GHz) */
  75. join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
  76. join_pref_params[0].len = 2;
  77. join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
  78. join_pref_params[0].band = WLC_BAND_5G;
  79. join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
  80. join_pref_params[1].len = 2;
  81. join_pref_params[1].rssi_gain = 0;
  82. join_pref_params[1].band = 0;
  83. err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
  84. sizeof(join_pref_params));
  85. if (err)
  86. brcmf_err("Set join_pref error (%d)\n", err);
  87. }
  88. int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
  89. {
  90. s8 eventmask[BRCMF_EVENTING_MASK_LEN];
  91. u8 buf[BRCMF_DCMD_SMLEN];
  92. struct brcmf_rev_info_le revinfo;
  93. struct brcmf_rev_info *ri;
  94. char *ptr;
  95. s32 err;
  96. /* retreive mac address */
  97. err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
  98. sizeof(ifp->mac_addr));
  99. if (err < 0) {
  100. brcmf_err("Retreiving cur_etheraddr failed, %d\n", err);
  101. goto done;
  102. }
  103. memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
  104. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_REVINFO,
  105. &revinfo, sizeof(revinfo));
  106. ri = &ifp->drvr->revinfo;
  107. if (err < 0) {
  108. brcmf_err("retrieving revision info failed, %d\n", err);
  109. } else {
  110. ri->vendorid = le32_to_cpu(revinfo.vendorid);
  111. ri->deviceid = le32_to_cpu(revinfo.deviceid);
  112. ri->radiorev = le32_to_cpu(revinfo.radiorev);
  113. ri->chiprev = le32_to_cpu(revinfo.chiprev);
  114. ri->corerev = le32_to_cpu(revinfo.corerev);
  115. ri->boardid = le32_to_cpu(revinfo.boardid);
  116. ri->boardvendor = le32_to_cpu(revinfo.boardvendor);
  117. ri->boardrev = le32_to_cpu(revinfo.boardrev);
  118. ri->driverrev = le32_to_cpu(revinfo.driverrev);
  119. ri->ucoderev = le32_to_cpu(revinfo.ucoderev);
  120. ri->bus = le32_to_cpu(revinfo.bus);
  121. ri->chipnum = le32_to_cpu(revinfo.chipnum);
  122. ri->phytype = le32_to_cpu(revinfo.phytype);
  123. ri->phyrev = le32_to_cpu(revinfo.phyrev);
  124. ri->anarev = le32_to_cpu(revinfo.anarev);
  125. ri->chippkg = le32_to_cpu(revinfo.chippkg);
  126. ri->nvramrev = le32_to_cpu(revinfo.nvramrev);
  127. }
  128. ri->result = err;
  129. /* query for 'ver' to get version info from firmware */
  130. memset(buf, 0, sizeof(buf));
  131. strcpy(buf, "ver");
  132. err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
  133. if (err < 0) {
  134. brcmf_err("Retreiving version information failed, %d\n",
  135. err);
  136. goto done;
  137. }
  138. ptr = (char *)buf;
  139. strsep(&ptr, "\n");
  140. /* Print fw version info */
  141. brcmf_err("Firmware version = %s\n", buf);
  142. /* locate firmware version number for ethtool */
  143. ptr = strrchr(buf, ' ') + 1;
  144. strlcpy(ifp->drvr->fwver, ptr, sizeof(ifp->drvr->fwver));
  145. /* set mpc */
  146. err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
  147. if (err) {
  148. brcmf_err("failed setting mpc\n");
  149. goto done;
  150. }
  151. brcmf_c_set_joinpref_default(ifp);
  152. /* Setup event_msgs, enable E_IF */
  153. err = brcmf_fil_iovar_data_get(ifp, "event_msgs", eventmask,
  154. BRCMF_EVENTING_MASK_LEN);
  155. if (err) {
  156. brcmf_err("Get event_msgs error (%d)\n", err);
  157. goto done;
  158. }
  159. setbit(eventmask, BRCMF_E_IF);
  160. err = brcmf_fil_iovar_data_set(ifp, "event_msgs", eventmask,
  161. BRCMF_EVENTING_MASK_LEN);
  162. if (err) {
  163. brcmf_err("Set event_msgs error (%d)\n", err);
  164. goto done;
  165. }
  166. /* Setup default scan channel time */
  167. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
  168. BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
  169. if (err) {
  170. brcmf_err("BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
  171. err);
  172. goto done;
  173. }
  174. /* Setup default scan unassoc time */
  175. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
  176. BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
  177. if (err) {
  178. brcmf_err("BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
  179. err);
  180. goto done;
  181. }
  182. /* Enable tx beamforming, errors can be ignored (not supported) */
  183. (void)brcmf_fil_iovar_int_set(ifp, "txbf", 1);
  184. /* do bus specific preinit here */
  185. err = brcmf_bus_preinit(ifp->drvr->bus_if);
  186. done:
  187. return err;
  188. }
  189. #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
  190. void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
  191. {
  192. struct va_format vaf = {
  193. .fmt = fmt,
  194. };
  195. va_list args;
  196. va_start(args, fmt);
  197. vaf.va = &args;
  198. if (brcmf_msg_level & level)
  199. pr_debug("%s %pV", func, &vaf);
  200. trace_brcmf_dbg(level, func, &vaf);
  201. va_end(args);
  202. }
  203. #endif
  204. static void brcmf_mp_attach(void)
  205. {
  206. /* If module param firmware path is set then this will always be used,
  207. * if not set then if available use the platform data version. To make
  208. * sure it gets initialized at all, always copy the module param version
  209. */
  210. strlcpy(brcmf_mp_global.firmware_path, brcmf_firmware_path,
  211. BRCMF_FW_ALTPATH_LEN);
  212. if ((brcmfmac_pdata) && (brcmfmac_pdata->fw_alternative_path) &&
  213. (brcmf_mp_global.firmware_path[0] == '\0')) {
  214. strlcpy(brcmf_mp_global.firmware_path,
  215. brcmfmac_pdata->fw_alternative_path,
  216. BRCMF_FW_ALTPATH_LEN);
  217. }
  218. }
  219. struct brcmf_mp_device *brcmf_get_module_param(struct device *dev,
  220. enum brcmf_bus_type bus_type,
  221. u32 chip, u32 chiprev)
  222. {
  223. struct brcmf_mp_device *settings;
  224. struct brcmfmac_pd_device *device_pd;
  225. bool found;
  226. int i;
  227. brcmf_dbg(INFO, "Enter, bus=%d, chip=%d, rev=%d\n", bus_type, chip,
  228. chiprev);
  229. settings = kzalloc(sizeof(*settings), GFP_ATOMIC);
  230. if (!settings)
  231. return NULL;
  232. /* start by using the module paramaters */
  233. settings->p2p_enable = !!brcmf_p2p_enable;
  234. settings->feature_disable = brcmf_feature_disable;
  235. settings->fcmode = brcmf_fcmode;
  236. settings->roamoff = !!brcmf_roamoff;
  237. #ifdef DEBUG
  238. settings->ignore_probe_fail = !!brcmf_ignore_probe_fail;
  239. #endif
  240. if (bus_type == BRCMF_BUSTYPE_SDIO)
  241. settings->bus.sdio.txglomsz = brcmf_sdiod_txglomsz;
  242. /* See if there is any device specific platform data configured */
  243. found = false;
  244. if (brcmfmac_pdata) {
  245. for (i = 0; i < brcmfmac_pdata->device_count; i++) {
  246. device_pd = &brcmfmac_pdata->devices[i];
  247. if ((device_pd->bus_type == bus_type) &&
  248. (device_pd->id == chip) &&
  249. ((device_pd->rev == chiprev) ||
  250. (device_pd->rev == -1))) {
  251. brcmf_dbg(INFO, "Platform data for device found\n");
  252. settings->country_codes =
  253. device_pd->country_codes;
  254. if (device_pd->bus_type == BRCMF_BUSTYPE_SDIO)
  255. memcpy(&settings->bus.sdio,
  256. &device_pd->bus.sdio,
  257. sizeof(settings->bus.sdio));
  258. found = true;
  259. break;
  260. }
  261. }
  262. }
  263. if ((bus_type == BRCMF_BUSTYPE_SDIO) && (!found)) {
  264. /* No platform data for this device. In case of SDIO try OF
  265. * (Open Firwmare) Device Tree.
  266. */
  267. brcmf_of_probe(dev, &settings->bus.sdio);
  268. }
  269. return settings;
  270. }
  271. void brcmf_release_module_param(struct brcmf_mp_device *module_param)
  272. {
  273. kfree(module_param);
  274. }
  275. static int __init brcmf_common_pd_probe(struct platform_device *pdev)
  276. {
  277. brcmf_dbg(INFO, "Enter\n");
  278. brcmfmac_pdata = dev_get_platdata(&pdev->dev);
  279. if (brcmfmac_pdata->power_on)
  280. brcmfmac_pdata->power_on();
  281. return 0;
  282. }
  283. static int brcmf_common_pd_remove(struct platform_device *pdev)
  284. {
  285. brcmf_dbg(INFO, "Enter\n");
  286. if (brcmfmac_pdata->power_off)
  287. brcmfmac_pdata->power_off();
  288. return 0;
  289. }
  290. static struct platform_driver brcmf_pd = {
  291. .remove = brcmf_common_pd_remove,
  292. .driver = {
  293. .name = BRCMFMAC_PDATA_NAME,
  294. }
  295. };
  296. static int __init brcmfmac_module_init(void)
  297. {
  298. int err;
  299. /* Initialize debug system first */
  300. brcmf_debugfs_init();
  301. /* Get the platform data (if available) for our devices */
  302. err = platform_driver_probe(&brcmf_pd, brcmf_common_pd_probe);
  303. if (err == -ENODEV)
  304. brcmf_dbg(INFO, "No platform data available.\n");
  305. /* Initialize global module paramaters */
  306. brcmf_mp_attach();
  307. /* Continue the initialization by registering the different busses */
  308. err = brcmf_core_init();
  309. if (err) {
  310. brcmf_debugfs_exit();
  311. if (brcmfmac_pdata)
  312. platform_driver_unregister(&brcmf_pd);
  313. }
  314. return err;
  315. }
  316. static void __exit brcmfmac_module_exit(void)
  317. {
  318. brcmf_core_exit();
  319. if (brcmfmac_pdata)
  320. platform_driver_unregister(&brcmf_pd);
  321. brcmf_debugfs_exit();
  322. }
  323. module_init(brcmfmac_module_init);
  324. module_exit(brcmfmac_module_exit);