wl1271_init.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include "wl1271_init.h"
  26. #include "wl12xx_80211.h"
  27. #include "wl1271_acx.h"
  28. #include "wl1271_cmd.h"
  29. #include "wl1271_reg.h"
  30. static int wl1271_init_hwenc_config(struct wl1271 *wl)
  31. {
  32. int ret;
  33. ret = wl1271_acx_feature_cfg(wl);
  34. if (ret < 0) {
  35. wl1271_warning("couldn't set feature config");
  36. return ret;
  37. }
  38. ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
  39. if (ret < 0) {
  40. wl1271_warning("couldn't set default key");
  41. return ret;
  42. }
  43. return 0;
  44. }
  45. static int wl1271_init_templates_config(struct wl1271 *wl)
  46. {
  47. int ret;
  48. /* send empty templates for fw memory reservation */
  49. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
  50. sizeof(struct wl12xx_probe_req_template));
  51. if (ret < 0)
  52. return ret;
  53. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  54. sizeof(struct wl12xx_null_data_template));
  55. if (ret < 0)
  56. return ret;
  57. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
  58. sizeof(struct wl12xx_ps_poll_template));
  59. if (ret < 0)
  60. return ret;
  61. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  62. sizeof
  63. (struct wl12xx_qos_null_data_template));
  64. if (ret < 0)
  65. return ret;
  66. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
  67. sizeof
  68. (struct wl12xx_probe_resp_template));
  69. if (ret < 0)
  70. return ret;
  71. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
  72. sizeof
  73. (struct wl12xx_beacon_template));
  74. if (ret < 0)
  75. return ret;
  76. return 0;
  77. }
  78. static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  79. {
  80. int ret;
  81. ret = wl1271_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
  82. if (ret < 0)
  83. return ret;
  84. ret = wl1271_acx_rx_config(wl, config, filter);
  85. if (ret < 0)
  86. return ret;
  87. return 0;
  88. }
  89. static int wl1271_init_phy_config(struct wl1271 *wl)
  90. {
  91. int ret;
  92. ret = wl1271_acx_pd_threshold(wl);
  93. if (ret < 0)
  94. return ret;
  95. ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
  96. if (ret < 0)
  97. return ret;
  98. ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
  99. if (ret < 0)
  100. return ret;
  101. ret = wl1271_acx_service_period_timeout(wl);
  102. if (ret < 0)
  103. return ret;
  104. ret = wl1271_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
  105. if (ret < 0)
  106. return ret;
  107. return 0;
  108. }
  109. static int wl1271_init_beacon_filter(struct wl1271 *wl)
  110. {
  111. int ret;
  112. /* disable beacon filtering at this stage */
  113. ret = wl1271_acx_beacon_filter_opt(wl, false);
  114. if (ret < 0)
  115. return ret;
  116. ret = wl1271_acx_beacon_filter_table(wl);
  117. if (ret < 0)
  118. return ret;
  119. return 0;
  120. }
  121. static int wl1271_init_pta(struct wl1271 *wl)
  122. {
  123. int ret;
  124. ret = wl1271_acx_sg_enable(wl);
  125. if (ret < 0)
  126. return ret;
  127. ret = wl1271_acx_sg_cfg(wl);
  128. if (ret < 0)
  129. return ret;
  130. return 0;
  131. }
  132. static int wl1271_init_energy_detection(struct wl1271 *wl)
  133. {
  134. int ret;
  135. ret = wl1271_acx_cca_threshold(wl);
  136. if (ret < 0)
  137. return ret;
  138. return 0;
  139. }
  140. static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
  141. {
  142. int ret;
  143. ret = wl1271_acx_bcn_dtim_options(wl);
  144. if (ret < 0)
  145. return ret;
  146. return 0;
  147. }
  148. static int wl1271_init_general_parms(struct wl1271 *wl)
  149. {
  150. struct wl1271_general_parms *gen_parms;
  151. int ret;
  152. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  153. if (!gen_parms)
  154. return -ENOMEM;
  155. gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  156. gen_parms->ref_clk = REF_CLK_38_4_E;
  157. /* FIXME: magic numbers */
  158. gen_parms->settling_time = 5;
  159. gen_parms->clk_valid_on_wakeup = 0;
  160. gen_parms->dc2dcmode = 0;
  161. gen_parms->single_dual_band = 0;
  162. gen_parms->tx_bip_fem_autodetect = 0;
  163. gen_parms->tx_bip_fem_manufacturer = 1;
  164. gen_parms->settings = 1;
  165. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
  166. if (ret < 0) {
  167. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  168. return ret;
  169. }
  170. kfree(gen_parms);
  171. return 0;
  172. }
  173. static int wl1271_init_radio_parms(struct wl1271 *wl)
  174. {
  175. /*
  176. * FIXME: All these magic numbers should be moved to some place where
  177. * they can be configured (separate file?)
  178. */
  179. struct wl1271_radio_parms *radio_parms;
  180. int ret;
  181. u8 compensation[] = { 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8, 0xfc, 0x00,
  182. 0x08, 0x10, 0xf0, 0xf8, 0x00, 0x0a, 0x14 };
  183. u8 tx_rate_limits_normal[] = { 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 };
  184. u8 tx_rate_limits_degraded[] = { 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 };
  185. u8 tx_channel_limits_11b[] = { 0x22, 0x50, 0x50, 0x50,
  186. 0x50, 0x50, 0x50, 0x50,
  187. 0x50, 0x50, 0x22, 0x50,
  188. 0x22, 0x50 };
  189. u8 tx_channel_limits_ofdm[] = { 0x20, 0x50, 0x50, 0x50,
  190. 0x50, 0x50, 0x50, 0x50,
  191. 0x50, 0x50, 0x20, 0x50,
  192. 0x20, 0x50 };
  193. u8 tx_pdv_rate_offsets[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  194. u8 tx_ibias[] = { 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 };
  195. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  196. if (!radio_parms)
  197. return -ENOMEM;
  198. radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
  199. /* Static radio parameters */
  200. radio_parms->rx_trace_loss = 10;
  201. radio_parms->tx_trace_loss = 10;
  202. memcpy(radio_parms->rx_rssi_and_proc_compens, compensation,
  203. sizeof(compensation));
  204. /* We don't set the 5GHz -- N/A */
  205. /* Dynamic radio parameters */
  206. radio_parms->tx_ref_pd_voltage = cpu_to_le16(0x24e);
  207. radio_parms->tx_ref_power = 0x78;
  208. radio_parms->tx_offset_db = 0x0;
  209. memcpy(radio_parms->tx_rate_limits_normal, tx_rate_limits_normal,
  210. sizeof(tx_rate_limits_normal));
  211. memcpy(radio_parms->tx_rate_limits_degraded, tx_rate_limits_degraded,
  212. sizeof(tx_rate_limits_degraded));
  213. memcpy(radio_parms->tx_channel_limits_11b, tx_channel_limits_11b,
  214. sizeof(tx_channel_limits_11b));
  215. memcpy(radio_parms->tx_channel_limits_ofdm, tx_channel_limits_ofdm,
  216. sizeof(tx_channel_limits_ofdm));
  217. memcpy(radio_parms->tx_pdv_rate_offsets, tx_pdv_rate_offsets,
  218. sizeof(tx_pdv_rate_offsets));
  219. memcpy(radio_parms->tx_ibias, tx_ibias,
  220. sizeof(tx_ibias));
  221. radio_parms->rx_fem_insertion_loss = 0x14;
  222. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  223. if (ret < 0)
  224. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  225. kfree(radio_parms);
  226. return ret;
  227. }
  228. int wl1271_hw_init(struct wl1271 *wl)
  229. {
  230. int ret;
  231. ret = wl1271_init_general_parms(wl);
  232. if (ret < 0)
  233. return ret;
  234. ret = wl1271_init_radio_parms(wl);
  235. if (ret < 0)
  236. return ret;
  237. /* Template settings */
  238. ret = wl1271_init_templates_config(wl);
  239. if (ret < 0)
  240. return ret;
  241. /* Default memory configuration */
  242. ret = wl1271_acx_init_mem_config(wl);
  243. if (ret < 0)
  244. return ret;
  245. /* RX config */
  246. ret = wl1271_init_rx_config(wl,
  247. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  248. RX_FILTER_OPTION_DEF);
  249. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  250. RX_FILTER_OPTION_FILTER_ALL); */
  251. if (ret < 0)
  252. goto out_free_memmap;
  253. /* PHY layer config */
  254. ret = wl1271_init_phy_config(wl);
  255. if (ret < 0)
  256. goto out_free_memmap;
  257. /* Initialize connection monitoring thresholds */
  258. ret = wl1271_acx_conn_monit_params(wl);
  259. if (ret < 0)
  260. goto out_free_memmap;
  261. /* Beacon filtering */
  262. ret = wl1271_init_beacon_filter(wl);
  263. if (ret < 0)
  264. goto out_free_memmap;
  265. /* Configure TX patch complete interrupt behavior */
  266. ret = wl1271_acx_tx_config_options(wl);
  267. if (ret < 0)
  268. goto out_free_memmap;
  269. /* RX complete interrupt pacing */
  270. ret = wl1271_acx_init_rx_interrupt(wl);
  271. if (ret < 0)
  272. goto out_free_memmap;
  273. /* Bluetooth WLAN coexistence */
  274. ret = wl1271_init_pta(wl);
  275. if (ret < 0)
  276. goto out_free_memmap;
  277. /* Energy detection */
  278. ret = wl1271_init_energy_detection(wl);
  279. if (ret < 0)
  280. goto out_free_memmap;
  281. /* Beacons and boradcast settings */
  282. ret = wl1271_init_beacon_broadcast(wl);
  283. if (ret < 0)
  284. goto out_free_memmap;
  285. /* Default fragmentation threshold */
  286. ret = wl1271_acx_frag_threshold(wl);
  287. if (ret < 0)
  288. goto out_free_memmap;
  289. /* Default TID configuration */
  290. ret = wl1271_acx_tid_cfg(wl);
  291. if (ret < 0)
  292. goto out_free_memmap;
  293. /* Default AC configuration */
  294. ret = wl1271_acx_ac_cfg(wl);
  295. if (ret < 0)
  296. goto out_free_memmap;
  297. /* Configure TX rate classes */
  298. ret = wl1271_acx_rate_policies(wl, ACX_RATE_MASK_ALL);
  299. if (ret < 0)
  300. goto out_free_memmap;
  301. /* Enable data path */
  302. ret = wl1271_cmd_data_path(wl, wl->channel, 1);
  303. if (ret < 0)
  304. goto out_free_memmap;
  305. /* Configure for ELP power saving */
  306. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  307. if (ret < 0)
  308. goto out_free_memmap;
  309. /* Configure HW encryption */
  310. ret = wl1271_init_hwenc_config(wl);
  311. if (ret < 0)
  312. goto out_free_memmap;
  313. /* Configure smart reflex */
  314. ret = wl1271_acx_smart_reflex(wl);
  315. if (ret < 0)
  316. goto out_free_memmap;
  317. return 0;
  318. out_free_memmap:
  319. kfree(wl->target_mem_map);
  320. wl->target_mem_map = NULL;
  321. return ret;
  322. }