wl1251_init.c 8.7 KB

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