init.c 8.4 KB

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