wl1271_init.c 7.6 KB

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