wl1251_init.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  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. ret = wl1251_acx_beacon_filter_opt(wl);
  122. if (ret < 0)
  123. return ret;
  124. ret = wl1251_acx_beacon_filter_table(wl);
  125. if (ret < 0)
  126. return ret;
  127. return 0;
  128. }
  129. int wl1251_hw_init_pta(struct wl1251 *wl)
  130. {
  131. int ret;
  132. ret = wl1251_acx_sg_enable(wl);
  133. if (ret < 0)
  134. return ret;
  135. ret = wl1251_acx_sg_cfg(wl);
  136. if (ret < 0)
  137. return ret;
  138. return 0;
  139. }
  140. int wl1251_hw_init_energy_detection(struct wl1251 *wl)
  141. {
  142. int ret;
  143. ret = wl1251_acx_cca_threshold(wl);
  144. if (ret < 0)
  145. return ret;
  146. return 0;
  147. }
  148. int wl1251_hw_init_beacon_broadcast(struct wl1251 *wl)
  149. {
  150. int ret;
  151. ret = wl1251_acx_bcn_dtim_options(wl);
  152. if (ret < 0)
  153. return ret;
  154. return 0;
  155. }
  156. int wl1251_hw_init_power_auth(struct wl1251 *wl)
  157. {
  158. return wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
  159. }
  160. int wl1251_hw_init_mem_config(struct wl1251 *wl)
  161. {
  162. int ret;
  163. ret = wl1251_acx_mem_cfg(wl);
  164. if (ret < 0)
  165. return ret;
  166. wl->target_mem_map = kzalloc(sizeof(struct wl1251_acx_mem_map),
  167. GFP_KERNEL);
  168. if (!wl->target_mem_map) {
  169. wl1251_error("couldn't allocate target memory map");
  170. return -ENOMEM;
  171. }
  172. /* we now ask for the firmware built memory map */
  173. ret = wl1251_acx_mem_map(wl, wl->target_mem_map,
  174. sizeof(struct wl1251_acx_mem_map));
  175. if (ret < 0) {
  176. wl1251_error("couldn't retrieve firmware memory map");
  177. kfree(wl->target_mem_map);
  178. wl->target_mem_map = NULL;
  179. return ret;
  180. }
  181. return 0;
  182. }
  183. static int wl1251_hw_init_txq_fill(u8 qid,
  184. struct acx_tx_queue_qos_config *config,
  185. u32 num_blocks)
  186. {
  187. config->qid = qid;
  188. switch (qid) {
  189. case QOS_AC_BE:
  190. config->high_threshold =
  191. (QOS_TX_HIGH_BE_DEF * num_blocks) / 100;
  192. config->low_threshold =
  193. (QOS_TX_LOW_BE_DEF * num_blocks) / 100;
  194. break;
  195. case QOS_AC_BK:
  196. config->high_threshold =
  197. (QOS_TX_HIGH_BK_DEF * num_blocks) / 100;
  198. config->low_threshold =
  199. (QOS_TX_LOW_BK_DEF * num_blocks) / 100;
  200. break;
  201. case QOS_AC_VI:
  202. config->high_threshold =
  203. (QOS_TX_HIGH_VI_DEF * num_blocks) / 100;
  204. config->low_threshold =
  205. (QOS_TX_LOW_VI_DEF * num_blocks) / 100;
  206. break;
  207. case QOS_AC_VO:
  208. config->high_threshold =
  209. (QOS_TX_HIGH_VO_DEF * num_blocks) / 100;
  210. config->low_threshold =
  211. (QOS_TX_LOW_VO_DEF * num_blocks) / 100;
  212. break;
  213. default:
  214. wl1251_error("Invalid TX queue id: %d", qid);
  215. return -EINVAL;
  216. }
  217. return 0;
  218. }
  219. static int wl1251_hw_init_tx_queue_config(struct wl1251 *wl)
  220. {
  221. struct acx_tx_queue_qos_config *config;
  222. struct wl1251_acx_mem_map *wl_mem_map = wl->target_mem_map;
  223. int ret, i;
  224. wl1251_debug(DEBUG_ACX, "acx tx queue config");
  225. config = kzalloc(sizeof(*config), GFP_KERNEL);
  226. if (!config) {
  227. ret = -ENOMEM;
  228. goto out;
  229. }
  230. for (i = 0; i < MAX_NUM_OF_AC; i++) {
  231. ret = wl1251_hw_init_txq_fill(i, config,
  232. wl_mem_map->num_tx_mem_blocks);
  233. if (ret < 0)
  234. goto out;
  235. ret = wl1251_cmd_configure(wl, ACX_TX_QUEUE_CFG,
  236. config, sizeof(*config));
  237. if (ret < 0)
  238. goto out;
  239. }
  240. out:
  241. kfree(config);
  242. return ret;
  243. }
  244. static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
  245. {
  246. int ret;
  247. /* asking for the data path parameters */
  248. wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
  249. GFP_KERNEL);
  250. if (!wl->data_path) {
  251. wl1251_error("Couldnt allocate data path parameters");
  252. return -ENOMEM;
  253. }
  254. ret = wl1251_acx_data_path_params(wl, wl->data_path);
  255. if (ret < 0) {
  256. kfree(wl->data_path);
  257. wl->data_path = NULL;
  258. return ret;
  259. }
  260. return 0;
  261. }
  262. int wl1251_hw_init(struct wl1251 *wl)
  263. {
  264. struct wl1251_acx_mem_map *wl_mem_map;
  265. int ret;
  266. ret = wl1251_hw_init_hwenc_config(wl);
  267. if (ret < 0)
  268. return ret;
  269. /* Template settings */
  270. ret = wl1251_hw_init_templates_config(wl);
  271. if (ret < 0)
  272. return ret;
  273. /* Default memory configuration */
  274. ret = wl1251_hw_init_mem_config(wl);
  275. if (ret < 0)
  276. return ret;
  277. /* Default data path configuration */
  278. ret = wl1251_hw_init_data_path_config(wl);
  279. if (ret < 0)
  280. goto out_free_memmap;
  281. /* RX config */
  282. ret = wl1251_hw_init_rx_config(wl,
  283. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  284. RX_FILTER_OPTION_DEF);
  285. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  286. RX_FILTER_OPTION_FILTER_ALL); */
  287. if (ret < 0)
  288. goto out_free_data_path;
  289. /* TX queues config */
  290. ret = wl1251_hw_init_tx_queue_config(wl);
  291. if (ret < 0)
  292. goto out_free_data_path;
  293. /* PHY layer config */
  294. ret = wl1251_hw_init_phy_config(wl);
  295. if (ret < 0)
  296. goto out_free_data_path;
  297. /* Beacon filtering */
  298. ret = wl1251_hw_init_beacon_filter(wl);
  299. if (ret < 0)
  300. goto out_free_data_path;
  301. /* Bluetooth WLAN coexistence */
  302. ret = wl1251_hw_init_pta(wl);
  303. if (ret < 0)
  304. goto out_free_data_path;
  305. /* Energy detection */
  306. ret = wl1251_hw_init_energy_detection(wl);
  307. if (ret < 0)
  308. goto out_free_data_path;
  309. /* Beacons and boradcast settings */
  310. ret = wl1251_hw_init_beacon_broadcast(wl);
  311. if (ret < 0)
  312. goto out_free_data_path;
  313. /* Enable data path */
  314. ret = wl1251_cmd_data_path(wl, wl->channel, 1);
  315. if (ret < 0)
  316. goto out_free_data_path;
  317. /* Default power state */
  318. ret = wl1251_hw_init_power_auth(wl);
  319. if (ret < 0)
  320. goto out_free_data_path;
  321. wl_mem_map = wl->target_mem_map;
  322. wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
  323. wl_mem_map->num_tx_mem_blocks,
  324. wl->data_path->tx_control_addr,
  325. wl_mem_map->num_rx_mem_blocks,
  326. wl->data_path->rx_control_addr);
  327. return 0;
  328. out_free_data_path:
  329. kfree(wl->data_path);
  330. out_free_memmap:
  331. kfree(wl->target_mem_map);
  332. return ret;
  333. }