wl1251_init.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Kalle Valo <kalle.valo@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 "wl1251_init.h"
  27. #include "wl12xx_80211.h"
  28. #include "wl1251_acx.h"
  29. #include "wl1251_cmd.h"
  30. #include "wl1251_reg.h"
  31. int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
  32. {
  33. int ret;
  34. ret = wl1251_acx_feature_cfg(wl);
  35. if (ret < 0) {
  36. wl1251_warning("couldn't set feature config");
  37. return ret;
  38. }
  39. ret = wl1251_acx_default_key(wl, wl->default_key);
  40. if (ret < 0) {
  41. wl1251_warning("couldn't set default key");
  42. return ret;
  43. }
  44. return 0;
  45. }
  46. int wl1251_hw_init_templates_config(struct wl1251 *wl)
  47. {
  48. int ret;
  49. u8 partial_vbm[PARTIAL_VBM_MAX];
  50. /* send empty templates for fw memory reservation */
  51. ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
  52. sizeof(struct wl12xx_probe_req_template));
  53. if (ret < 0)
  54. return ret;
  55. ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
  56. sizeof(struct wl12xx_null_data_template));
  57. if (ret < 0)
  58. return ret;
  59. ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
  60. sizeof(struct wl12xx_ps_poll_template));
  61. if (ret < 0)
  62. return ret;
  63. ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
  64. sizeof
  65. (struct wl12xx_qos_null_data_template));
  66. if (ret < 0)
  67. return ret;
  68. ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
  69. sizeof
  70. (struct wl12xx_probe_resp_template));
  71. if (ret < 0)
  72. return ret;
  73. ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
  74. sizeof
  75. (struct wl12xx_beacon_template));
  76. if (ret < 0)
  77. return ret;
  78. /* tim templates, first reserve space then allocate an empty one */
  79. memset(partial_vbm, 0, PARTIAL_VBM_MAX);
  80. ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
  81. if (ret < 0)
  82. return ret;
  83. ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
  84. if (ret < 0)
  85. return ret;
  86. return 0;
  87. }
  88. int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
  89. {
  90. int ret;
  91. ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
  92. if (ret < 0)
  93. return ret;
  94. ret = wl1251_acx_rx_config(wl, config, filter);
  95. if (ret < 0)
  96. return ret;
  97. return 0;
  98. }
  99. int wl1251_hw_init_phy_config(struct wl1251 *wl)
  100. {
  101. int ret;
  102. ret = wl1251_acx_pd_threshold(wl);
  103. if (ret < 0)
  104. return ret;
  105. ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
  106. if (ret < 0)
  107. return ret;
  108. ret = wl1251_acx_group_address_tbl(wl);
  109. if (ret < 0)
  110. return ret;
  111. ret = wl1251_acx_service_period_timeout(wl);
  112. if (ret < 0)
  113. return ret;
  114. ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
  115. if (ret < 0)
  116. return ret;
  117. return 0;
  118. }
  119. int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
  120. {
  121. int ret;
  122. /* disable beacon filtering at this stage */
  123. ret = wl1251_acx_beacon_filter_opt(wl, false);
  124. if (ret < 0)
  125. return ret;
  126. ret = wl1251_acx_beacon_filter_table(wl);
  127. if (ret < 0)
  128. return ret;
  129. return 0;
  130. }
  131. int wl1251_hw_init_pta(struct wl1251 *wl)
  132. {
  133. int ret;
  134. ret = wl1251_acx_sg_enable(wl);
  135. if (ret < 0)
  136. return ret;
  137. ret = wl1251_acx_sg_cfg(wl);
  138. if (ret < 0)
  139. return ret;
  140. return 0;
  141. }
  142. int wl1251_hw_init_energy_detection(struct wl1251 *wl)
  143. {
  144. int ret;
  145. ret = wl1251_acx_cca_threshold(wl);
  146. if (ret < 0)
  147. return ret;
  148. return 0;
  149. }
  150. int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
  151. {
  152. int ret;
  153. ret = wl1251_acx_bcn_dtim_options(wl);
  154. if (ret < 0)
  155. return ret;
  156. return 0;
  157. }
  158. int wl1251_hw_init_power_auth(struct wl1251 *wl)
  159. {
  160. return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
  161. }
  162. int wl1251_hw_init_mem_config(struct wl1251 *wl)
  163. {
  164. int ret;
  165. ret = wl1251_acx_mem_cfg(wl);
  166. if (ret < 0)
  167. return ret;
  168. wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
  169. GFP_KERNEL);
  170. if (!wl->target_mem_map) {
  171. wl1251_error("couldn't allocate target memory map");
  172. return -ENOMEM;
  173. }
  174. /* we now ask for the firmware built memory map */
  175. ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
  176. sizeof(struct wl1251_acx_mem_map));
  177. if (ret < 0) {
  178. wl1251_error("couldn't retrieve firmware memory map");
  179. kfree(wl->target_mem_map);
  180. wl->target_mem_map = NULL;
  181. return ret;
  182. }
  183. return 0;
  184. }
  185. static int wl1251_hw_init_txq_fill(u8 qid,
  186. struct acx_tx_queue_qos_config *config,
  187. u32 num_blocks)
  188. {
  189. config->qid = qid;
  190. switch (qid) {
  191. case QOS_AC_BE:
  192. config->high_threshold =
  193. (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
  194. config->low_threshold =
  195. (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
  196. break;
  197. case QOS_AC_BK:
  198. config->high_threshold =
  199. (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
  200. config->low_threshold =
  201. (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
  202. break;
  203. case QOS_AC_VI:
  204. config->high_threshold =
  205. (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
  206. config->low_threshold =
  207. (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
  208. break;
  209. case QOS_AC_VO:
  210. config->high_threshold =
  211. (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
  212. config->low_threshold =
  213. (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
  214. break;
  215. default:
  216. wl1251_error("Invalid TX queue id: %d", qid);
  217. return -EINVAL;
  218. }
  219. return 0;
  220. }
  221. static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
  222. {
  223. struct acx_tx_queue_qos_config *config;
  224. struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
  225. int ret, i;
  226. wl1251_debug(DEBUG_ACX, "acx tx queue config");
  227. config = kzalloc(sizeof(*config), GFP_KERNEL);
  228. if (!config) {
  229. ret = -ENOMEM;
  230. goto out;
  231. }
  232. for (i = 0; i < MAX_NUM_OF_AC; i++) {
  233. ret = wl1251_hw_init_txq_fill(i, config,
  234. wl_mem_map->num_tx_mem_blocks);
  235. if (ret < 0)
  236. goto out;
  237. ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
  238. config, sizeof(*config));
  239. if (ret < 0)
  240. goto out;
  241. }
  242. wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
  243. wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
  244. wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
  245. wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
  246. out:
  247. kfree(config);
  248. return ret;
  249. }
  250. static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
  251. {
  252. int ret;
  253. /* asking for the data path parameters */
  254. wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
  255. GFP_KERNEL);
  256. if (!wl->data_path) {
  257. wl1251_error("Couldnt allocate data path parameters");
  258. return -ENOMEM;
  259. }
  260. ret = wl1251_acx_data_path_params(wl, wl->data_path);
  261. if (ret < 0) {
  262. kfree(wl->data_path);
  263. wl->data_path = NULL;
  264. return ret;
  265. }
  266. return 0;
  267. }
  268. int wl1251_hw_init(struct wl1251 *wl)
  269. {
  270. struct wl1251_acx_mem_map *wl_mem_map;
  271. int ret;
  272. ret = wl1251_hw_init_hwenc_config(wl);
  273. if (ret < 0)
  274. return ret;
  275. /* Template settings */
  276. ret = wl1251_hw_init_templates_config(wl);
  277. if (ret < 0)
  278. return ret;
  279. /* Default memory configuration */
  280. ret = wl1251_hw_init_mem_config(wl);
  281. if (ret < 0)
  282. return ret;
  283. /* Default data path configuration */
  284. ret = wl1251_hw_init_data_path_config(wl);
  285. if (ret < 0)
  286. goto out_free_memmap;
  287. /* RX config */
  288. ret = wl1251_hw_init_rx_config(wl,
  289. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  290. RX_FILTER_OPTION_DEF);
  291. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  292. RX_FILTER_OPTION_FILTER_ALL); */
  293. if (ret < 0)
  294. goto out_free_data_path;
  295. /* TX queues config */
  296. ret = wl1251_hw_init_tx_queue_config(wl);
  297. if (ret < 0)
  298. goto out_free_data_path;
  299. /* PHY layer config */
  300. ret = wl1251_hw_init_phy_config(wl);
  301. if (ret < 0)
  302. goto out_free_data_path;
  303. /* Initialize connection monitoring thresholds */
  304. ret = wl1251_acx_conn_monit_params(wl);
  305. if (ret < 0)
  306. goto out_free_data_path;
  307. /* Beacon filtering */
  308. ret = wl1251_hw_init_beacon_filter(wl);
  309. if (ret < 0)
  310. goto out_free_data_path;
  311. /* Bluetooth WLAN coexistence */
  312. ret = wl1251_hw_init_pta(wl);
  313. if (ret < 0)
  314. goto out_free_data_path;
  315. /* Energy detection */
  316. ret = wl1251_hw_init_energy_detection(wl);
  317. if (ret < 0)
  318. goto out_free_data_path;
  319. /* Beacons and boradcast settings */
  320. ret = wl1251_hw_init_beacon_broadcast(wl);
  321. if (ret < 0)
  322. goto out_free_data_path;
  323. /* Enable data path */
  324. ret = wl1251_cmd_data_path(wl, wl->channel, 1);
  325. if (ret < 0)
  326. goto out_free_data_path;
  327. /* Default power state */
  328. ret = wl1251_hw_init_power_auth(wl);
  329. if (ret < 0)
  330. goto out_free_data_path;
  331. wl_mem_map = wl->target_mem_map;
  332. wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
  333. wl_mem_map->num_tx_mem_blocks,
  334. wl->data_path->tx_control_addr,
  335. wl_mem_map->num_rx_mem_blocks,
  336. wl->data_path->rx_control_addr);
  337. return 0;
  338. out_free_data_path:
  339. kfree(wl->data_path);
  340. out_free_memmap:
  341. kfree(wl->target_mem_map);
  342. return ret;
  343. }