wl1271_init.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 <linux/slab.h>
  26. #include "wl1271_init.h"
  27. #include "wl12xx_80211.h"
  28. #include "wl1271_acx.h"
  29. #include "wl1271_cmd.h"
  30. #include "wl1271_reg.h"
  31. static int wl1271_init_hwenc_config(struct wl1271 *wl)
  32. {
  33. int ret;
  34. ret = wl1271_acx_feature_cfg(wl);
  35. if (ret < 0) {
  36. wl1271_warning("couldn't set feature config");
  37. return ret;
  38. }
  39. ret = wl1271_cmd_set_default_wep_key(wl, wl->default_key);
  40. if (ret < 0) {
  41. wl1271_warning("couldn't set default key");
  42. return ret;
  43. }
  44. return 0;
  45. }
  46. int wl1271_init_templates_config(struct wl1271 *wl)
  47. {
  48. int ret;
  49. /* send empty templates for fw memory reservation */
  50. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
  51. sizeof(struct wl12xx_probe_req_template));
  52. if (ret < 0)
  53. return ret;
  54. if (wl1271_11a_enabled()) {
  55. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  56. NULL,
  57. sizeof(struct wl12xx_probe_req_template));
  58. if (ret < 0)
  59. return ret;
  60. }
  61. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  62. sizeof(struct wl12xx_null_data_template));
  63. if (ret < 0)
  64. return ret;
  65. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
  66. sizeof(struct wl12xx_ps_poll_template));
  67. if (ret < 0)
  68. return ret;
  69. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  70. sizeof
  71. (struct wl12xx_qos_null_data_template));
  72. if (ret < 0)
  73. return ret;
  74. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
  75. sizeof
  76. (struct wl12xx_probe_resp_template));
  77. if (ret < 0)
  78. return ret;
  79. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
  80. sizeof
  81. (struct wl12xx_beacon_template));
  82. if (ret < 0)
  83. return ret;
  84. return 0;
  85. }
  86. static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  87. {
  88. int ret;
  89. ret = wl1271_acx_rx_msdu_life_time(wl);
  90. if (ret < 0)
  91. return ret;
  92. ret = wl1271_acx_rx_config(wl, config, filter);
  93. if (ret < 0)
  94. return ret;
  95. return 0;
  96. }
  97. int wl1271_init_phy_config(struct wl1271 *wl)
  98. {
  99. int ret;
  100. ret = wl1271_acx_pd_threshold(wl);
  101. if (ret < 0)
  102. return ret;
  103. ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
  104. if (ret < 0)
  105. return ret;
  106. ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
  107. if (ret < 0)
  108. return ret;
  109. ret = wl1271_acx_service_period_timeout(wl);
  110. if (ret < 0)
  111. return ret;
  112. ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
  113. if (ret < 0)
  114. return ret;
  115. return 0;
  116. }
  117. static int wl1271_init_beacon_filter(struct wl1271 *wl)
  118. {
  119. int ret;
  120. /* disable beacon filtering at this stage */
  121. ret = wl1271_acx_beacon_filter_opt(wl, false);
  122. if (ret < 0)
  123. return ret;
  124. ret = wl1271_acx_beacon_filter_table(wl);
  125. if (ret < 0)
  126. return ret;
  127. return 0;
  128. }
  129. int wl1271_init_pta(struct wl1271 *wl)
  130. {
  131. int ret;
  132. ret = wl1271_acx_sg_enable(wl);
  133. if (ret < 0)
  134. return ret;
  135. ret = wl1271_acx_sg_cfg(wl);
  136. if (ret < 0)
  137. return ret;
  138. return 0;
  139. }
  140. int wl1271_init_energy_detection(struct wl1271 *wl)
  141. {
  142. int ret;
  143. ret = wl1271_acx_cca_threshold(wl);
  144. if (ret < 0)
  145. return ret;
  146. return 0;
  147. }
  148. static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
  149. {
  150. int ret;
  151. ret = wl1271_acx_bcn_dtim_options(wl);
  152. if (ret < 0)
  153. return ret;
  154. return 0;
  155. }
  156. int wl1271_hw_init(struct wl1271 *wl)
  157. {
  158. struct conf_tx_ac_category *conf_ac;
  159. struct conf_tx_tid *conf_tid;
  160. int ret, i;
  161. ret = wl1271_cmd_general_parms(wl);
  162. if (ret < 0)
  163. return ret;
  164. ret = wl1271_cmd_radio_parms(wl);
  165. if (ret < 0)
  166. return ret;
  167. /* Template settings */
  168. ret = wl1271_init_templates_config(wl);
  169. if (ret < 0)
  170. return ret;
  171. /* Default memory configuration */
  172. ret = wl1271_acx_init_mem_config(wl);
  173. if (ret < 0)
  174. return ret;
  175. /* RX config */
  176. ret = wl1271_init_rx_config(wl,
  177. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  178. RX_FILTER_OPTION_DEF);
  179. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  180. RX_FILTER_OPTION_FILTER_ALL); */
  181. if (ret < 0)
  182. goto out_free_memmap;
  183. /* PHY layer config */
  184. ret = wl1271_init_phy_config(wl);
  185. if (ret < 0)
  186. goto out_free_memmap;
  187. ret = wl1271_acx_dco_itrim_params(wl);
  188. if (ret < 0)
  189. goto out_free_memmap;
  190. /* Initialize connection monitoring thresholds */
  191. ret = wl1271_acx_conn_monit_params(wl);
  192. if (ret < 0)
  193. goto out_free_memmap;
  194. /* Beacon filtering */
  195. ret = wl1271_init_beacon_filter(wl);
  196. if (ret < 0)
  197. goto out_free_memmap;
  198. /* Configure TX patch complete interrupt behavior */
  199. ret = wl1271_acx_tx_config_options(wl);
  200. if (ret < 0)
  201. goto out_free_memmap;
  202. /* RX complete interrupt pacing */
  203. ret = wl1271_acx_init_rx_interrupt(wl);
  204. if (ret < 0)
  205. goto out_free_memmap;
  206. /* Bluetooth WLAN coexistence */
  207. ret = wl1271_init_pta(wl);
  208. if (ret < 0)
  209. goto out_free_memmap;
  210. /* Energy detection */
  211. ret = wl1271_init_energy_detection(wl);
  212. if (ret < 0)
  213. goto out_free_memmap;
  214. /* Beacons and boradcast settings */
  215. ret = wl1271_init_beacon_broadcast(wl);
  216. if (ret < 0)
  217. goto out_free_memmap;
  218. /* Default fragmentation threshold */
  219. ret = wl1271_acx_frag_threshold(wl);
  220. if (ret < 0)
  221. goto out_free_memmap;
  222. /* Default TID configuration */
  223. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  224. conf_tid = &wl->conf.tx.tid_conf[i];
  225. ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
  226. conf_tid->channel_type,
  227. conf_tid->tsid,
  228. conf_tid->ps_scheme,
  229. conf_tid->ack_policy,
  230. conf_tid->apsd_conf[0],
  231. conf_tid->apsd_conf[1]);
  232. if (ret < 0)
  233. goto out_free_memmap;
  234. }
  235. /* Default AC configuration */
  236. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  237. conf_ac = &wl->conf.tx.ac_conf[i];
  238. ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
  239. conf_ac->cw_max, conf_ac->aifsn,
  240. conf_ac->tx_op_limit);
  241. if (ret < 0)
  242. goto out_free_memmap;
  243. }
  244. /* Configure TX rate classes */
  245. ret = wl1271_acx_rate_policies(wl);
  246. if (ret < 0)
  247. goto out_free_memmap;
  248. /* Enable data path */
  249. ret = wl1271_cmd_data_path(wl, 1);
  250. if (ret < 0)
  251. goto out_free_memmap;
  252. /* Configure for ELP power saving */
  253. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  254. if (ret < 0)
  255. goto out_free_memmap;
  256. /* Configure HW encryption */
  257. ret = wl1271_init_hwenc_config(wl);
  258. if (ret < 0)
  259. goto out_free_memmap;
  260. /* configure PM */
  261. ret = wl1271_acx_pm_config(wl);
  262. if (ret < 0)
  263. goto out_free_memmap;
  264. return 0;
  265. out_free_memmap:
  266. kfree(wl->target_mem_map);
  267. wl->target_mem_map = NULL;
  268. return ret;
  269. }