init.c 8.1 KB

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