wl1271_init.c 7.9 KB

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