wl1271_init.c 7.8 KB

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