wl1271_init.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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);
  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. ret = wl1271_acx_beacon_filter_opt(wl);
  113. if (ret < 0)
  114. return ret;
  115. ret = wl1271_acx_beacon_filter_table(wl);
  116. if (ret < 0)
  117. return ret;
  118. return 0;
  119. }
  120. static int wl1271_init_pta(struct wl1271 *wl)
  121. {
  122. int ret;
  123. ret = wl1271_acx_sg_enable(wl);
  124. if (ret < 0)
  125. return ret;
  126. ret = wl1271_acx_sg_cfg(wl);
  127. if (ret < 0)
  128. return ret;
  129. return 0;
  130. }
  131. static int wl1271_init_energy_detection(struct wl1271 *wl)
  132. {
  133. int ret;
  134. ret = wl1271_acx_cca_threshold(wl);
  135. if (ret < 0)
  136. return ret;
  137. return 0;
  138. }
  139. static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
  140. {
  141. int ret;
  142. ret = wl1271_acx_bcn_dtim_options(wl);
  143. if (ret < 0)
  144. return ret;
  145. return 0;
  146. }
  147. static int wl1271_init_general_parms(struct wl1271 *wl)
  148. {
  149. struct wl1271_general_parms *gen_parms;
  150. int ret;
  151. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  152. if (!gen_parms)
  153. return -ENOMEM;
  154. gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  155. gen_parms->ref_clk = REF_CLK_38_4_E;
  156. /* FIXME: magic numbers */
  157. gen_parms->settling_time = 5;
  158. gen_parms->clk_valid_on_wakeup = 0;
  159. gen_parms->dc2dcmode = 0;
  160. gen_parms->single_dual_band = 0;
  161. gen_parms->tx_bip_fem_autodetect = 1;
  162. gen_parms->tx_bip_fem_manufacturer = 1;
  163. gen_parms->settings = 1;
  164. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
  165. if (ret < 0) {
  166. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  167. return ret;
  168. }
  169. kfree(gen_parms);
  170. return 0;
  171. }
  172. static int wl1271_init_radio_parms(struct wl1271 *wl)
  173. {
  174. /*
  175. * FIXME: All these magic numbers should be moved to some place where
  176. * they can be configured (separate file?)
  177. */
  178. struct wl1271_radio_parms *radio_parms;
  179. int ret;
  180. u8 compensation[] = { 0xec, 0xf6, 0x00, 0x0c, 0x18, 0xf8, 0xfc, 0x00,
  181. 0x08, 0x10, 0xf0, 0xf8, 0x00, 0x0a, 0x14 };
  182. u8 tx_rate_limits_normal[] = { 0x1e, 0x1f, 0x22, 0x24, 0x28, 0x29 };
  183. u8 tx_rate_limits_degraded[] = { 0x1b, 0x1c, 0x1e, 0x20, 0x24, 0x25 };
  184. u8 tx_channel_limits_11b[] = { 0x22, 0x50, 0x50, 0x50,
  185. 0x50, 0x50, 0x50, 0x50,
  186. 0x50, 0x50, 0x22, 0x50,
  187. 0x22, 0x50 };
  188. u8 tx_channel_limits_ofdm[] = { 0x20, 0x50, 0x50, 0x50,
  189. 0x50, 0x50, 0x50, 0x50,
  190. 0x50, 0x50, 0x20, 0x50,
  191. 0x20, 0x50 };
  192. u8 tx_pdv_rate_offsets[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  193. u8 tx_ibias[] = { 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x27 };
  194. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  195. if (!radio_parms)
  196. return -ENOMEM;
  197. radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
  198. /* Static radio parameters */
  199. radio_parms->rx_trace_loss = 10;
  200. radio_parms->tx_trace_loss = 10;
  201. memcpy(radio_parms->rx_rssi_and_proc_compens, compensation,
  202. sizeof(compensation));
  203. /* We don't set the 5GHz -- N/A */
  204. /* Dynamic radio parameters */
  205. radio_parms->tx_ref_pd_voltage = cpu_to_le16(0x24e);
  206. radio_parms->tx_ref_power = 0x78;
  207. radio_parms->tx_offset_db = 0x0;
  208. memcpy(radio_parms->tx_rate_limits_normal, tx_rate_limits_normal,
  209. sizeof(tx_rate_limits_normal));
  210. memcpy(radio_parms->tx_rate_limits_degraded, tx_rate_limits_degraded,
  211. sizeof(tx_rate_limits_degraded));
  212. memcpy(radio_parms->tx_channel_limits_11b, tx_channel_limits_11b,
  213. sizeof(tx_channel_limits_11b));
  214. memcpy(radio_parms->tx_channel_limits_ofdm, tx_channel_limits_ofdm,
  215. sizeof(tx_channel_limits_ofdm));
  216. memcpy(radio_parms->tx_pdv_rate_offsets, tx_pdv_rate_offsets,
  217. sizeof(tx_pdv_rate_offsets));
  218. memcpy(radio_parms->tx_ibias, tx_ibias,
  219. sizeof(tx_ibias));
  220. radio_parms->rx_fem_insertion_loss = 0x14;
  221. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  222. if (ret < 0)
  223. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  224. kfree(radio_parms);
  225. return ret;
  226. }
  227. int wl1271_hw_init(struct wl1271 *wl)
  228. {
  229. int ret;
  230. ret = wl1271_init_general_parms(wl);
  231. if (ret < 0)
  232. return ret;
  233. ret = wl1271_init_radio_parms(wl);
  234. if (ret < 0)
  235. return ret;
  236. /* Template settings */
  237. ret = wl1271_init_templates_config(wl);
  238. if (ret < 0)
  239. return ret;
  240. /* Default memory configuration */
  241. ret = wl1271_acx_init_mem_config(wl);
  242. if (ret < 0)
  243. return ret;
  244. /* RX config */
  245. ret = wl1271_init_rx_config(wl,
  246. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  247. RX_FILTER_OPTION_DEF);
  248. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  249. RX_FILTER_OPTION_FILTER_ALL); */
  250. if (ret < 0)
  251. goto out_free_memmap;
  252. /* PHY layer config */
  253. ret = wl1271_init_phy_config(wl);
  254. if (ret < 0)
  255. goto out_free_memmap;
  256. /* Beacon filtering */
  257. ret = wl1271_init_beacon_filter(wl);
  258. if (ret < 0)
  259. goto out_free_memmap;
  260. /* Configure TX patch complete interrupt behavior */
  261. ret = wl1271_acx_tx_config_options(wl);
  262. if (ret < 0)
  263. goto out_free_memmap;
  264. /* RX complete interrupt pacing */
  265. ret = wl1271_acx_init_rx_interrupt(wl);
  266. if (ret < 0)
  267. goto out_free_memmap;
  268. /* Bluetooth WLAN coexistence */
  269. ret = wl1271_init_pta(wl);
  270. if (ret < 0)
  271. goto out_free_memmap;
  272. /* Energy detection */
  273. ret = wl1271_init_energy_detection(wl);
  274. if (ret < 0)
  275. goto out_free_memmap;
  276. /* Beacons and boradcast settings */
  277. ret = wl1271_init_beacon_broadcast(wl);
  278. if (ret < 0)
  279. goto out_free_memmap;
  280. /* Default fragmentation threshold */
  281. ret = wl1271_acx_frag_threshold(wl);
  282. if (ret < 0)
  283. goto out_free_memmap;
  284. /* Default TID configuration */
  285. ret = wl1271_acx_tid_cfg(wl);
  286. if (ret < 0)
  287. goto out_free_memmap;
  288. /* Default AC configuration */
  289. ret = wl1271_acx_ac_cfg(wl);
  290. if (ret < 0)
  291. goto out_free_memmap;
  292. /* Configure TX rate classes */
  293. ret = wl1271_acx_rate_policies(wl);
  294. if (ret < 0)
  295. goto out_free_memmap;
  296. /* Enable data path */
  297. ret = wl1271_cmd_data_path(wl, wl->channel, 1);
  298. if (ret < 0)
  299. goto out_free_memmap;
  300. /* Configure for ELP power saving */
  301. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  302. if (ret < 0)
  303. goto out_free_memmap;
  304. /* Configure HW encryption */
  305. ret = wl1271_init_hwenc_config(wl);
  306. if (ret < 0)
  307. goto out_free_memmap;
  308. return 0;
  309. out_free_memmap:
  310. kfree(wl->target_mem_map);
  311. return ret;
  312. }