init.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. /*
  2. * This file is part of wl1251
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/kernel.h>
  22. #include <linux/module.h>
  23. #include <linux/slab.h>
  24. #include "init.h"
  25. #include "wl12xx_80211.h"
  26. #include "acx.h"
  27. #include "cmd.h"
  28. #include "reg.h"
  29. int wl1251_hw_init_hwenc_config(struct wl1251 *wl)
  30. {
  31. int ret;
  32. ret = wl1251_acx_feature_cfg(wl, 0);
  33. if (ret < 0) {
  34. wl1251_warning("couldn't set feature config");
  35. return ret;
  36. }
  37. ret = wl1251_acx_default_key(wl, wl->default_key);
  38. if (ret < 0) {
  39. wl1251_warning("couldn't set default key");
  40. return ret;
  41. }
  42. return 0;
  43. }
  44. int wl1251_hw_init_templates_config(struct wl1251 *wl)
  45. {
  46. int ret;
  47. u8 partial_vbm[PARTIAL_VBM_MAX];
  48. /* send empty templates for fw memory reservation */
  49. ret = wl1251_cmd_template_set(wl, CMD_PROBE_REQ, NULL,
  50. sizeof(struct wl12xx_probe_req_template));
  51. if (ret < 0)
  52. return ret;
  53. ret = wl1251_cmd_template_set(wl, CMD_NULL_DATA, NULL,
  54. sizeof(struct wl12xx_null_data_template));
  55. if (ret < 0)
  56. return ret;
  57. ret = wl1251_cmd_template_set(wl, CMD_PS_POLL, NULL,
  58. sizeof(struct wl12xx_ps_poll_template));
  59. if (ret < 0)
  60. return ret;
  61. ret = wl1251_cmd_template_set(wl, CMD_QOS_NULL_DATA, NULL,
  62. sizeof
  63. (struct wl12xx_qos_null_data_template));
  64. if (ret < 0)
  65. return ret;
  66. ret = wl1251_cmd_template_set(wl, CMD_PROBE_RESP, NULL,
  67. sizeof
  68. (struct wl12xx_probe_resp_template));
  69. if (ret < 0)
  70. return ret;
  71. ret = wl1251_cmd_template_set(wl, CMD_BEACON, NULL,
  72. sizeof
  73. (struct wl12xx_beacon_template));
  74. if (ret < 0)
  75. return ret;
  76. /* tim templates, first reserve space then allocate an empty one */
  77. memset(partial_vbm, 0, PARTIAL_VBM_MAX);
  78. ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, PARTIAL_VBM_MAX, 0);
  79. if (ret < 0)
  80. return ret;
  81. ret = wl1251_cmd_vbm(wl, TIM_ELE_ID, partial_vbm, 1, 0);
  82. if (ret < 0)
  83. return ret;
  84. return 0;
  85. }
  86. int wl1251_hw_init_rx_config(struct wl1251 *wl, u32 config, u32 filter)
  87. {
  88. int ret;
  89. ret = wl1251_acx_rx_msdu_life_time(wl, RX_MSDU_LIFETIME_DEF);
  90. if (ret < 0)
  91. return ret;
  92. ret = wl1251_acx_rx_config(wl, config, filter);
  93. if (ret < 0)
  94. return ret;
  95. return 0;
  96. }
  97. int wl1251_hw_init_phy_config(struct wl1251 *wl)
  98. {
  99. int ret;
  100. ret = wl1251_acx_pd_threshold(wl);
  101. if (ret < 0)
  102. return ret;
  103. ret = wl1251_acx_slot(wl, DEFAULT_SLOT_TIME);
  104. if (ret < 0)
  105. return ret;
  106. ret = wl1251_acx_group_address_tbl(wl, true, NULL, 0);
  107. if (ret < 0)
  108. return ret;
  109. ret = wl1251_acx_service_period_timeout(wl);
  110. if (ret < 0)
  111. return ret;
  112. ret = wl1251_acx_rts_threshold(wl, RTS_THRESHOLD_DEF);
  113. if (ret < 0)
  114. return ret;
  115. return 0;
  116. }
  117. int wl1251_hw_init_beacon_filter(struct wl1251 *wl)
  118. {
  119. int ret;
  120. /* disable beacon filtering at this stage */
  121. ret = wl1251_acx_beacon_filter_opt(wl, false);
  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. wl1251_acx_ac_cfg(wl, AC_BE, CWMIN_BE, CWMAX_BE, AIFS_DIFS, TXOP_BE);
  241. wl1251_acx_ac_cfg(wl, AC_BK, CWMIN_BK, CWMAX_BK, AIFS_DIFS, TXOP_BK);
  242. wl1251_acx_ac_cfg(wl, AC_VI, CWMIN_VI, CWMAX_VI, AIFS_DIFS, TXOP_VI);
  243. wl1251_acx_ac_cfg(wl, AC_VO, CWMIN_VO, CWMAX_VO, AIFS_DIFS, TXOP_VO);
  244. out:
  245. kfree(config);
  246. return ret;
  247. }
  248. static int wl1251_hw_init_data_path_config(struct wl1251 *wl)
  249. {
  250. int ret;
  251. /* asking for the data path parameters */
  252. wl->data_path = kzalloc(sizeof(struct acx_data_path_params_resp),
  253. GFP_KERNEL);
  254. if (!wl->data_path) {
  255. wl1251_error("Couldnt allocate data path parameters");
  256. return -ENOMEM;
  257. }
  258. ret = wl1251_acx_data_path_params(wl, wl->data_path);
  259. if (ret < 0) {
  260. kfree(wl->data_path);
  261. wl->data_path = NULL;
  262. return ret;
  263. }
  264. return 0;
  265. }
  266. int wl1251_hw_init(struct wl1251 *wl)
  267. {
  268. struct wl1251_acx_mem_map *wl_mem_map;
  269. int ret;
  270. ret = wl1251_hw_init_hwenc_config(wl);
  271. if (ret < 0)
  272. return ret;
  273. /* Template settings */
  274. ret = wl1251_hw_init_templates_config(wl);
  275. if (ret < 0)
  276. return ret;
  277. /* Default memory configuration */
  278. ret = wl1251_hw_init_mem_config(wl);
  279. if (ret < 0)
  280. return ret;
  281. /* Default data path configuration */
  282. ret = wl1251_hw_init_data_path_config(wl);
  283. if (ret < 0)
  284. goto out_free_memmap;
  285. /* RX config */
  286. ret = wl1251_hw_init_rx_config(wl,
  287. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  288. RX_FILTER_OPTION_DEF);
  289. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  290. RX_FILTER_OPTION_FILTER_ALL); */
  291. if (ret < 0)
  292. goto out_free_data_path;
  293. /* TX queues config */
  294. ret = wl1251_hw_init_tx_queue_config(wl);
  295. if (ret < 0)
  296. goto out_free_data_path;
  297. /* PHY layer config */
  298. ret = wl1251_hw_init_phy_config(wl);
  299. if (ret < 0)
  300. goto out_free_data_path;
  301. /* Initialize connection monitoring thresholds */
  302. ret = wl1251_acx_conn_monit_params(wl);
  303. if (ret < 0)
  304. goto out_free_data_path;
  305. /* Beacon filtering */
  306. ret = wl1251_hw_init_beacon_filter(wl);
  307. if (ret < 0)
  308. goto out_free_data_path;
  309. /* Bluetooth WLAN coexistence */
  310. ret = wl1251_hw_init_pta(wl);
  311. if (ret < 0)
  312. goto out_free_data_path;
  313. /* Energy detection */
  314. ret = wl1251_hw_init_energy_detection(wl);
  315. if (ret < 0)
  316. goto out_free_data_path;
  317. /* Beacons and boradcast settings */
  318. ret = wl1251_hw_init_beacon_broadcast(wl);
  319. if (ret < 0)
  320. goto out_free_data_path;
  321. /* Enable rx data path */
  322. ret = wl1251_cmd_data_path_rx(wl, wl->channel, 1);
  323. if (ret < 0)
  324. goto out_free_data_path;
  325. /* Enable tx data path */
  326. ret = wl1251_cmd_data_path_tx(wl, wl->channel, 1);
  327. if (ret < 0)
  328. goto out_free_data_path;
  329. /* Default power state */
  330. ret = wl1251_hw_init_power_auth(wl);
  331. if (ret < 0)
  332. goto out_free_data_path;
  333. wl_mem_map = wl->target_mem_map;
  334. wl1251_info("%d tx blocks at 0x%x, %d rx blocks at 0x%x",
  335. wl_mem_map->num_tx_mem_blocks,
  336. wl->data_path->tx_control_addr,
  337. wl_mem_map->num_rx_mem_blocks,
  338. wl->data_path->rx_control_addr);
  339. return 0;
  340. out_free_data_path:
  341. kfree(wl->data_path);
  342. out_free_memmap:
  343. kfree(wl->target_mem_map);
  344. return ret;
  345. }