init.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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 "init.h"
  27. #include "wl12xx_80211.h"
  28. #include "acx.h"
  29. #include "cmd.h"
  30. #include "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. size_t size;
  50. /* send empty templates for fw memory reservation */
  51. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
  52. sizeof(struct wl12xx_probe_req_template),
  53. 0, WL1271_RATE_AUTOMATIC);
  54. if (ret < 0)
  55. return ret;
  56. 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. 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. ret = wl1271_cmd_ext_radio_parms(wl);
  181. if (ret < 0)
  182. return ret;
  183. /* Template settings */
  184. ret = wl1271_init_templates_config(wl);
  185. if (ret < 0)
  186. return ret;
  187. /* Default memory configuration */
  188. ret = wl1271_acx_init_mem_config(wl);
  189. if (ret < 0)
  190. return ret;
  191. /* RX config */
  192. ret = wl1271_init_rx_config(wl,
  193. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  194. RX_FILTER_OPTION_DEF);
  195. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  196. RX_FILTER_OPTION_FILTER_ALL); */
  197. if (ret < 0)
  198. goto out_free_memmap;
  199. /* PHY layer config */
  200. ret = wl1271_init_phy_config(wl);
  201. if (ret < 0)
  202. goto out_free_memmap;
  203. ret = wl1271_acx_dco_itrim_params(wl);
  204. if (ret < 0)
  205. goto out_free_memmap;
  206. /* Initialize connection monitoring thresholds */
  207. ret = wl1271_acx_conn_monit_params(wl, false);
  208. if (ret < 0)
  209. goto out_free_memmap;
  210. /* Beacon filtering */
  211. ret = wl1271_init_beacon_filter(wl);
  212. if (ret < 0)
  213. goto out_free_memmap;
  214. /* Configure TX patch complete interrupt behavior */
  215. ret = wl1271_acx_tx_config_options(wl);
  216. if (ret < 0)
  217. goto out_free_memmap;
  218. /* RX complete interrupt pacing */
  219. ret = wl1271_acx_init_rx_interrupt(wl);
  220. if (ret < 0)
  221. goto out_free_memmap;
  222. /* Bluetooth WLAN coexistence */
  223. ret = wl1271_init_pta(wl);
  224. if (ret < 0)
  225. goto out_free_memmap;
  226. /* Energy detection */
  227. ret = wl1271_init_energy_detection(wl);
  228. if (ret < 0)
  229. goto out_free_memmap;
  230. /* Beacons and boradcast settings */
  231. ret = wl1271_init_beacon_broadcast(wl);
  232. if (ret < 0)
  233. goto out_free_memmap;
  234. /* Default fragmentation threshold */
  235. ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
  236. if (ret < 0)
  237. goto out_free_memmap;
  238. /* Default TID/AC configuration */
  239. BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
  240. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  241. conf_ac = &wl->conf.tx.ac_conf[i];
  242. ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
  243. conf_ac->cw_max, conf_ac->aifsn,
  244. conf_ac->tx_op_limit);
  245. if (ret < 0)
  246. goto out_free_memmap;
  247. conf_tid = &wl->conf.tx.tid_conf[i];
  248. ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
  249. conf_tid->channel_type,
  250. conf_tid->tsid,
  251. conf_tid->ps_scheme,
  252. conf_tid->ack_policy,
  253. conf_tid->apsd_conf[0],
  254. conf_tid->apsd_conf[1]);
  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. }