wl1271_init.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. if (wl1271_11a_enabled()) {
  54. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  55. NULL,
  56. sizeof(struct wl12xx_probe_req_template));
  57. if (ret < 0)
  58. return ret;
  59. }
  60. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  61. sizeof(struct wl12xx_null_data_template));
  62. if (ret < 0)
  63. return ret;
  64. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
  65. sizeof(struct wl12xx_ps_poll_template));
  66. if (ret < 0)
  67. return ret;
  68. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  69. sizeof
  70. (struct wl12xx_qos_null_data_template));
  71. if (ret < 0)
  72. return ret;
  73. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
  74. sizeof
  75. (struct wl12xx_probe_resp_template));
  76. if (ret < 0)
  77. return ret;
  78. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
  79. sizeof
  80. (struct wl12xx_beacon_template));
  81. if (ret < 0)
  82. return ret;
  83. return 0;
  84. }
  85. static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  86. {
  87. int ret;
  88. ret = wl1271_acx_rx_msdu_life_time(wl);
  89. if (ret < 0)
  90. return ret;
  91. ret = wl1271_acx_rx_config(wl, config, filter);
  92. if (ret < 0)
  93. return ret;
  94. return 0;
  95. }
  96. static int wl1271_init_phy_config(struct wl1271 *wl)
  97. {
  98. int ret;
  99. ret = wl1271_acx_pd_threshold(wl);
  100. if (ret < 0)
  101. return ret;
  102. ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
  103. if (ret < 0)
  104. return ret;
  105. ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
  106. if (ret < 0)
  107. return ret;
  108. ret = wl1271_acx_service_period_timeout(wl);
  109. if (ret < 0)
  110. return ret;
  111. ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
  112. if (ret < 0)
  113. return ret;
  114. return 0;
  115. }
  116. static int wl1271_init_beacon_filter(struct wl1271 *wl)
  117. {
  118. int ret;
  119. /* disable beacon filtering at this stage */
  120. ret = wl1271_acx_beacon_filter_opt(wl, false);
  121. if (ret < 0)
  122. return ret;
  123. ret = wl1271_acx_beacon_filter_table(wl);
  124. if (ret < 0)
  125. return ret;
  126. return 0;
  127. }
  128. static int wl1271_init_pta(struct wl1271 *wl)
  129. {
  130. int ret;
  131. ret = wl1271_acx_sg_enable(wl);
  132. if (ret < 0)
  133. return ret;
  134. ret = wl1271_acx_sg_cfg(wl);
  135. if (ret < 0)
  136. return ret;
  137. return 0;
  138. }
  139. static int wl1271_init_energy_detection(struct wl1271 *wl)
  140. {
  141. int ret;
  142. ret = wl1271_acx_cca_threshold(wl);
  143. if (ret < 0)
  144. return ret;
  145. return 0;
  146. }
  147. static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
  148. {
  149. int ret;
  150. ret = wl1271_acx_bcn_dtim_options(wl);
  151. if (ret < 0)
  152. return ret;
  153. return 0;
  154. }
  155. static int wl1271_init_general_parms(struct wl1271 *wl)
  156. {
  157. struct wl1271_general_parms *gen_parms;
  158. struct conf_general_parms *g = &wl->conf.init.genparam;
  159. int ret;
  160. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  161. if (!gen_parms)
  162. return -ENOMEM;
  163. gen_parms->id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  164. gen_parms->ref_clk = g->ref_clk;
  165. gen_parms->settling_time = g->settling_time;
  166. gen_parms->clk_valid_on_wakeup = g->clk_valid_on_wakeup;
  167. gen_parms->dc2dcmode = g->dc2dcmode;
  168. gen_parms->single_dual_band = g->single_dual_band;
  169. gen_parms->tx_bip_fem_autodetect = g->tx_bip_fem_autodetect;
  170. gen_parms->tx_bip_fem_manufacturer = g->tx_bip_fem_manufacturer;
  171. gen_parms->settings = g->settings;
  172. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
  173. if (ret < 0) {
  174. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  175. return ret;
  176. }
  177. kfree(gen_parms);
  178. return 0;
  179. }
  180. static int wl1271_init_radio_parms(struct wl1271 *wl)
  181. {
  182. struct wl1271_radio_parms *radio_parms;
  183. struct conf_radio_parms *r = &wl->conf.init.radioparam;
  184. int i, ret;
  185. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  186. if (!radio_parms)
  187. return -ENOMEM;
  188. radio_parms->id = TEST_CMD_INI_FILE_RADIO_PARAM;
  189. /* Static radio parameters */
  190. radio_parms->rx_trace_loss = r->rx_trace_loss;
  191. radio_parms->tx_trace_loss = r->tx_trace_loss;
  192. memcpy(radio_parms->rx_rssi_and_proc_compens,
  193. r->rx_rssi_and_proc_compens,
  194. CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE);
  195. memcpy(radio_parms->rx_trace_loss_5, r->rx_trace_loss_5,
  196. CONF_NUMBER_OF_SUB_BANDS_5);
  197. memcpy(radio_parms->tx_trace_loss_5, r->tx_trace_loss_5,
  198. CONF_NUMBER_OF_SUB_BANDS_5);
  199. memcpy(radio_parms->rx_rssi_and_proc_compens_5,
  200. r->rx_rssi_and_proc_compens_5,
  201. CONF_RSSI_AND_PROCESS_COMPENSATION_SIZE);
  202. /* Dynamic radio parameters */
  203. radio_parms->tx_ref_pd_voltage = cpu_to_le16(r->tx_ref_pd_voltage);
  204. radio_parms->tx_ref_power = r->tx_ref_power;
  205. radio_parms->tx_offset_db = r->tx_offset_db;
  206. memcpy(radio_parms->tx_rate_limits_normal, r->tx_rate_limits_normal,
  207. CONF_NUMBER_OF_RATE_GROUPS);
  208. memcpy(radio_parms->tx_rate_limits_degraded, r->tx_rate_limits_degraded,
  209. CONF_NUMBER_OF_RATE_GROUPS);
  210. memcpy(radio_parms->tx_channel_limits_11b, r->tx_channel_limits_11b,
  211. CONF_NUMBER_OF_CHANNELS_2_4);
  212. memcpy(radio_parms->tx_channel_limits_ofdm, r->tx_channel_limits_ofdm,
  213. CONF_NUMBER_OF_CHANNELS_2_4);
  214. memcpy(radio_parms->tx_pdv_rate_offsets, r->tx_pdv_rate_offsets,
  215. CONF_NUMBER_OF_RATE_GROUPS);
  216. memcpy(radio_parms->tx_ibias, r->tx_ibias, CONF_NUMBER_OF_RATE_GROUPS);
  217. radio_parms->rx_fem_insertion_loss = r->rx_fem_insertion_loss;
  218. for (i = 0; i < CONF_NUMBER_OF_SUB_BANDS_5; i++)
  219. radio_parms->tx_ref_pd_voltage_5[i] =
  220. cpu_to_le16(r->tx_ref_pd_voltage_5[i]);
  221. memcpy(radio_parms->tx_ref_power_5, r->tx_ref_power_5,
  222. CONF_NUMBER_OF_SUB_BANDS_5);
  223. memcpy(radio_parms->tx_offset_db_5, r->tx_offset_db_5,
  224. CONF_NUMBER_OF_SUB_BANDS_5);
  225. memcpy(radio_parms->tx_rate_limits_normal_5,
  226. r->tx_rate_limits_normal_5, CONF_NUMBER_OF_RATE_GROUPS);
  227. memcpy(radio_parms->tx_rate_limits_degraded_5,
  228. r->tx_rate_limits_degraded_5, CONF_NUMBER_OF_RATE_GROUPS);
  229. memcpy(radio_parms->tx_channel_limits_ofdm_5,
  230. r->tx_channel_limits_ofdm_5, CONF_NUMBER_OF_CHANNELS_5);
  231. memcpy(radio_parms->tx_pdv_rate_offsets_5, r->tx_pdv_rate_offsets_5,
  232. CONF_NUMBER_OF_RATE_GROUPS);
  233. memcpy(radio_parms->tx_ibias_5, r->tx_ibias_5,
  234. CONF_NUMBER_OF_RATE_GROUPS);
  235. memcpy(radio_parms->rx_fem_insertion_loss_5,
  236. r->rx_fem_insertion_loss_5, CONF_NUMBER_OF_SUB_BANDS_5);
  237. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  238. if (ret < 0)
  239. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  240. kfree(radio_parms);
  241. return ret;
  242. }
  243. int wl1271_hw_init(struct wl1271 *wl)
  244. {
  245. int ret;
  246. /* FIXME: the following parameter setting functions return error
  247. * codes - the reason is so far unknown. The -EIO is therefore
  248. * ignored for the time being. */
  249. ret = wl1271_init_general_parms(wl);
  250. if (ret < 0 && ret != -EIO)
  251. return ret;
  252. ret = wl1271_init_radio_parms(wl);
  253. if (ret < 0 && ret != -EIO)
  254. return ret;
  255. /* Template settings */
  256. ret = wl1271_init_templates_config(wl);
  257. if (ret < 0)
  258. return ret;
  259. /* Default memory configuration */
  260. ret = wl1271_acx_init_mem_config(wl);
  261. if (ret < 0)
  262. return ret;
  263. /* RX config */
  264. ret = wl1271_init_rx_config(wl,
  265. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  266. RX_FILTER_OPTION_DEF);
  267. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  268. RX_FILTER_OPTION_FILTER_ALL); */
  269. if (ret < 0)
  270. goto out_free_memmap;
  271. /* PHY layer config */
  272. ret = wl1271_init_phy_config(wl);
  273. if (ret < 0)
  274. goto out_free_memmap;
  275. /* Initialize connection monitoring thresholds */
  276. ret = wl1271_acx_conn_monit_params(wl);
  277. if (ret < 0)
  278. goto out_free_memmap;
  279. /* Beacon filtering */
  280. ret = wl1271_init_beacon_filter(wl);
  281. if (ret < 0)
  282. goto out_free_memmap;
  283. /* Configure TX patch complete interrupt behavior */
  284. ret = wl1271_acx_tx_config_options(wl);
  285. if (ret < 0)
  286. goto out_free_memmap;
  287. /* RX complete interrupt pacing */
  288. ret = wl1271_acx_init_rx_interrupt(wl);
  289. if (ret < 0)
  290. goto out_free_memmap;
  291. /* Bluetooth WLAN coexistence */
  292. ret = wl1271_init_pta(wl);
  293. if (ret < 0)
  294. goto out_free_memmap;
  295. /* Energy detection */
  296. ret = wl1271_init_energy_detection(wl);
  297. if (ret < 0)
  298. goto out_free_memmap;
  299. /* Beacons and boradcast settings */
  300. ret = wl1271_init_beacon_broadcast(wl);
  301. if (ret < 0)
  302. goto out_free_memmap;
  303. /* Default fragmentation threshold */
  304. ret = wl1271_acx_frag_threshold(wl);
  305. if (ret < 0)
  306. goto out_free_memmap;
  307. /* Default TID configuration */
  308. ret = wl1271_acx_tid_cfg(wl);
  309. if (ret < 0)
  310. goto out_free_memmap;
  311. /* Default AC configuration */
  312. ret = wl1271_acx_ac_cfg(wl);
  313. if (ret < 0)
  314. goto out_free_memmap;
  315. /* Configure TX rate classes */
  316. ret = wl1271_acx_rate_policies(wl, CONF_TX_RATE_MASK_ALL);
  317. if (ret < 0)
  318. goto out_free_memmap;
  319. /* Enable data path */
  320. ret = wl1271_cmd_data_path(wl, wl->channel, 1);
  321. if (ret < 0)
  322. goto out_free_memmap;
  323. /* Configure for ELP power saving */
  324. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  325. if (ret < 0)
  326. goto out_free_memmap;
  327. /* Configure HW encryption */
  328. ret = wl1271_init_hwenc_config(wl);
  329. if (ret < 0)
  330. goto out_free_memmap;
  331. /* Configure smart reflex */
  332. ret = wl1271_acx_smart_reflex(wl);
  333. if (ret < 0)
  334. goto out_free_memmap;
  335. return 0;
  336. out_free_memmap:
  337. kfree(wl->target_mem_map);
  338. wl->target_mem_map = NULL;
  339. return ret;
  340. }