init.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@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 "init.h"
  27. #include "wl12xx_80211.h"
  28. #include "acx.h"
  29. #include "cmd.h"
  30. #include "reg.h"
  31. #include "tx.h"
  32. int wl1271_sta_init_templates_config(struct wl1271 *wl)
  33. {
  34. int ret, i;
  35. /* send empty templates for fw memory reservation */
  36. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
  37. WL1271_CMD_TEMPL_MAX_SIZE,
  38. 0, WL1271_RATE_AUTOMATIC);
  39. if (ret < 0)
  40. return ret;
  41. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  42. NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
  43. WL1271_RATE_AUTOMATIC);
  44. if (ret < 0)
  45. return ret;
  46. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  47. sizeof(struct wl12xx_null_data_template),
  48. 0, WL1271_RATE_AUTOMATIC);
  49. if (ret < 0)
  50. return ret;
  51. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
  52. sizeof(struct wl12xx_ps_poll_template),
  53. 0, WL1271_RATE_AUTOMATIC);
  54. if (ret < 0)
  55. return ret;
  56. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  57. sizeof
  58. (struct wl12xx_qos_null_data_template),
  59. 0, WL1271_RATE_AUTOMATIC);
  60. if (ret < 0)
  61. return ret;
  62. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
  63. sizeof
  64. (struct wl12xx_probe_resp_template),
  65. 0, WL1271_RATE_AUTOMATIC);
  66. if (ret < 0)
  67. return ret;
  68. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
  69. sizeof
  70. (struct wl12xx_beacon_template),
  71. 0, WL1271_RATE_AUTOMATIC);
  72. if (ret < 0)
  73. return ret;
  74. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
  75. sizeof
  76. (struct wl12xx_arp_rsp_template),
  77. 0, WL1271_RATE_AUTOMATIC);
  78. if (ret < 0)
  79. return ret;
  80. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  81. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
  82. WL1271_CMD_TEMPL_MAX_SIZE, i,
  83. WL1271_RATE_AUTOMATIC);
  84. if (ret < 0)
  85. return ret;
  86. }
  87. return 0;
  88. }
  89. static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
  90. {
  91. struct wl12xx_disconn_template *tmpl;
  92. int ret;
  93. tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
  94. if (!tmpl) {
  95. ret = -ENOMEM;
  96. goto out;
  97. }
  98. tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  99. IEEE80211_STYPE_DEAUTH);
  100. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
  101. tmpl, sizeof(*tmpl), 0,
  102. wl1271_tx_min_rate_get(wl));
  103. out:
  104. kfree(tmpl);
  105. return ret;
  106. }
  107. static int wl1271_ap_init_null_template(struct wl1271 *wl)
  108. {
  109. struct ieee80211_hdr_3addr *nullfunc;
  110. int ret;
  111. nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
  112. if (!nullfunc) {
  113. ret = -ENOMEM;
  114. goto out;
  115. }
  116. nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  117. IEEE80211_STYPE_NULLFUNC |
  118. IEEE80211_FCTL_FROMDS);
  119. /* nullfunc->addr1 is filled by FW */
  120. memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN);
  121. memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN);
  122. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
  123. sizeof(*nullfunc), 0,
  124. wl1271_tx_min_rate_get(wl));
  125. out:
  126. kfree(nullfunc);
  127. return ret;
  128. }
  129. static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
  130. {
  131. struct ieee80211_qos_hdr *qosnull;
  132. int ret;
  133. qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
  134. if (!qosnull) {
  135. ret = -ENOMEM;
  136. goto out;
  137. }
  138. qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  139. IEEE80211_STYPE_QOS_NULLFUNC |
  140. IEEE80211_FCTL_FROMDS);
  141. /* qosnull->addr1 is filled by FW */
  142. memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
  143. memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
  144. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
  145. sizeof(*qosnull), 0,
  146. wl1271_tx_min_rate_get(wl));
  147. out:
  148. kfree(qosnull);
  149. return ret;
  150. }
  151. static int wl1271_ap_init_templates_config(struct wl1271 *wl)
  152. {
  153. int ret;
  154. /*
  155. * Put very large empty placeholders for all templates. These
  156. * reserve memory for later.
  157. */
  158. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
  159. sizeof
  160. (struct wl12xx_probe_resp_template),
  161. 0, WL1271_RATE_AUTOMATIC);
  162. if (ret < 0)
  163. return ret;
  164. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
  165. sizeof
  166. (struct wl12xx_beacon_template),
  167. 0, WL1271_RATE_AUTOMATIC);
  168. if (ret < 0)
  169. return ret;
  170. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
  171. sizeof
  172. (struct wl12xx_disconn_template),
  173. 0, WL1271_RATE_AUTOMATIC);
  174. if (ret < 0)
  175. return ret;
  176. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  177. sizeof(struct wl12xx_null_data_template),
  178. 0, WL1271_RATE_AUTOMATIC);
  179. if (ret < 0)
  180. return ret;
  181. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  182. sizeof
  183. (struct wl12xx_qos_null_data_template),
  184. 0, WL1271_RATE_AUTOMATIC);
  185. if (ret < 0)
  186. return ret;
  187. return 0;
  188. }
  189. static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  190. {
  191. int ret;
  192. ret = wl1271_acx_rx_msdu_life_time(wl);
  193. if (ret < 0)
  194. return ret;
  195. ret = wl1271_acx_rx_config(wl, config, filter);
  196. if (ret < 0)
  197. return ret;
  198. return 0;
  199. }
  200. int wl1271_init_phy_config(struct wl1271 *wl)
  201. {
  202. int ret;
  203. ret = wl1271_acx_pd_threshold(wl);
  204. if (ret < 0)
  205. return ret;
  206. ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
  207. if (ret < 0)
  208. return ret;
  209. ret = wl1271_acx_service_period_timeout(wl);
  210. if (ret < 0)
  211. return ret;
  212. ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
  213. if (ret < 0)
  214. return ret;
  215. return 0;
  216. }
  217. static int wl1271_init_beacon_filter(struct wl1271 *wl)
  218. {
  219. int ret;
  220. /* disable beacon filtering at this stage */
  221. ret = wl1271_acx_beacon_filter_opt(wl, false);
  222. if (ret < 0)
  223. return ret;
  224. ret = wl1271_acx_beacon_filter_table(wl);
  225. if (ret < 0)
  226. return ret;
  227. return 0;
  228. }
  229. int wl1271_init_pta(struct wl1271 *wl)
  230. {
  231. int ret;
  232. ret = wl1271_acx_sg_cfg(wl);
  233. if (ret < 0)
  234. return ret;
  235. ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
  236. if (ret < 0)
  237. return ret;
  238. return 0;
  239. }
  240. int wl1271_init_energy_detection(struct wl1271 *wl)
  241. {
  242. int ret;
  243. ret = wl1271_acx_cca_threshold(wl);
  244. if (ret < 0)
  245. return ret;
  246. return 0;
  247. }
  248. static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
  249. {
  250. int ret;
  251. ret = wl1271_acx_bcn_dtim_options(wl);
  252. if (ret < 0)
  253. return ret;
  254. return 0;
  255. }
  256. static int wl1271_sta_hw_init(struct wl1271 *wl)
  257. {
  258. int ret;
  259. ret = wl1271_cmd_ext_radio_parms(wl);
  260. if (ret < 0)
  261. return ret;
  262. /* PS config */
  263. ret = wl1271_acx_config_ps(wl);
  264. if (ret < 0)
  265. return ret;
  266. ret = wl1271_sta_init_templates_config(wl);
  267. if (ret < 0)
  268. return ret;
  269. ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
  270. if (ret < 0)
  271. return ret;
  272. /* Initialize connection monitoring thresholds */
  273. ret = wl1271_acx_conn_monit_params(wl, false);
  274. if (ret < 0)
  275. return ret;
  276. /* Beacon filtering */
  277. ret = wl1271_init_beacon_filter(wl);
  278. if (ret < 0)
  279. return ret;
  280. /* Bluetooth WLAN coexistence */
  281. ret = wl1271_init_pta(wl);
  282. if (ret < 0)
  283. return ret;
  284. /* Beacons and broadcast settings */
  285. ret = wl1271_init_beacon_broadcast(wl);
  286. if (ret < 0)
  287. return ret;
  288. /* Configure for ELP power saving */
  289. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  290. if (ret < 0)
  291. return ret;
  292. /* Configure rssi/snr averaging weights */
  293. ret = wl1271_acx_rssi_snr_avg_weights(wl);
  294. if (ret < 0)
  295. return ret;
  296. ret = wl1271_acx_sta_rate_policies(wl);
  297. if (ret < 0)
  298. return ret;
  299. ret = wl1271_acx_sta_mem_cfg(wl);
  300. if (ret < 0)
  301. return ret;
  302. return 0;
  303. }
  304. static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
  305. {
  306. int ret, i;
  307. ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
  308. if (ret < 0) {
  309. wl1271_warning("couldn't set default key");
  310. return ret;
  311. }
  312. /* disable all keep-alive templates */
  313. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  314. ret = wl1271_acx_keep_alive_config(wl, i,
  315. ACX_KEEP_ALIVE_TPL_INVALID);
  316. if (ret < 0)
  317. return ret;
  318. }
  319. /* disable the keep-alive feature */
  320. ret = wl1271_acx_keep_alive_mode(wl, false);
  321. if (ret < 0)
  322. return ret;
  323. return 0;
  324. }
  325. static int wl1271_ap_hw_init(struct wl1271 *wl)
  326. {
  327. int ret, i;
  328. ret = wl1271_ap_init_templates_config(wl);
  329. if (ret < 0)
  330. return ret;
  331. /* Configure for power always on */
  332. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
  333. if (ret < 0)
  334. return ret;
  335. /* Configure initial TX rate classes */
  336. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  337. ret = wl1271_acx_ap_rate_policy(wl,
  338. &wl->conf.tx.ap_rc_conf[i], i);
  339. if (ret < 0)
  340. return ret;
  341. }
  342. ret = wl1271_acx_ap_rate_policy(wl,
  343. &wl->conf.tx.ap_mgmt_conf,
  344. ACX_TX_AP_MODE_MGMT_RATE);
  345. if (ret < 0)
  346. return ret;
  347. ret = wl1271_acx_ap_rate_policy(wl,
  348. &wl->conf.tx.ap_bcst_conf,
  349. ACX_TX_AP_MODE_BCST_RATE);
  350. if (ret < 0)
  351. return ret;
  352. ret = wl1271_acx_max_tx_retry(wl);
  353. if (ret < 0)
  354. return ret;
  355. ret = wl1271_acx_ap_mem_cfg(wl);
  356. if (ret < 0)
  357. return ret;
  358. return 0;
  359. }
  360. static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
  361. {
  362. int ret;
  363. ret = wl1271_ap_init_deauth_template(wl);
  364. if (ret < 0)
  365. return ret;
  366. ret = wl1271_ap_init_null_template(wl);
  367. if (ret < 0)
  368. return ret;
  369. ret = wl1271_ap_init_qos_null_template(wl);
  370. if (ret < 0)
  371. return ret;
  372. return 0;
  373. }
  374. static void wl1271_check_ba_support(struct wl1271 *wl)
  375. {
  376. /* validate FW cose ver x.x.x.50-60.x */
  377. if ((wl->chip.fw_ver[3] >= WL12XX_BA_SUPPORT_FW_COST_VER2_START) &&
  378. (wl->chip.fw_ver[3] < WL12XX_BA_SUPPORT_FW_COST_VER2_END)) {
  379. wl->ba_support = true;
  380. return;
  381. }
  382. wl->ba_support = false;
  383. }
  384. static int wl1271_set_ba_policies(struct wl1271 *wl)
  385. {
  386. u8 tid_index;
  387. int ret = 0;
  388. /* Reset the BA RX indicators */
  389. wl->ba_rx_bitmap = 0;
  390. /* validate that FW support BA */
  391. wl1271_check_ba_support(wl);
  392. if (wl->ba_support)
  393. /* 802.11n initiator BA session setting */
  394. for (tid_index = 0; tid_index < CONF_TX_MAX_TID_COUNT;
  395. ++tid_index) {
  396. ret = wl1271_acx_set_ba_session(wl, WLAN_BACK_INITIATOR,
  397. tid_index, true);
  398. if (ret < 0)
  399. break;
  400. }
  401. return ret;
  402. }
  403. int wl1271_hw_init(struct wl1271 *wl)
  404. {
  405. struct conf_tx_ac_category *conf_ac;
  406. struct conf_tx_tid *conf_tid;
  407. int ret, i;
  408. bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
  409. ret = wl1271_cmd_general_parms(wl);
  410. if (ret < 0)
  411. return ret;
  412. ret = wl1271_cmd_radio_parms(wl);
  413. if (ret < 0)
  414. return ret;
  415. /* Mode specific init */
  416. if (is_ap)
  417. ret = wl1271_ap_hw_init(wl);
  418. else
  419. ret = wl1271_sta_hw_init(wl);
  420. if (ret < 0)
  421. return ret;
  422. /* Default memory configuration */
  423. ret = wl1271_acx_init_mem_config(wl);
  424. if (ret < 0)
  425. return ret;
  426. /* RX config */
  427. ret = wl1271_init_rx_config(wl,
  428. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  429. RX_FILTER_OPTION_DEF);
  430. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  431. RX_FILTER_OPTION_FILTER_ALL); */
  432. if (ret < 0)
  433. goto out_free_memmap;
  434. /* PHY layer config */
  435. ret = wl1271_init_phy_config(wl);
  436. if (ret < 0)
  437. goto out_free_memmap;
  438. ret = wl1271_acx_dco_itrim_params(wl);
  439. if (ret < 0)
  440. goto out_free_memmap;
  441. /* Configure TX patch complete interrupt behavior */
  442. ret = wl1271_acx_tx_config_options(wl);
  443. if (ret < 0)
  444. goto out_free_memmap;
  445. /* RX complete interrupt pacing */
  446. ret = wl1271_acx_init_rx_interrupt(wl);
  447. if (ret < 0)
  448. goto out_free_memmap;
  449. /* Energy detection */
  450. ret = wl1271_init_energy_detection(wl);
  451. if (ret < 0)
  452. goto out_free_memmap;
  453. /* Default fragmentation threshold */
  454. ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
  455. if (ret < 0)
  456. goto out_free_memmap;
  457. /* Default TID/AC configuration */
  458. BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
  459. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  460. conf_ac = &wl->conf.tx.ac_conf[i];
  461. ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
  462. conf_ac->cw_max, conf_ac->aifsn,
  463. conf_ac->tx_op_limit);
  464. if (ret < 0)
  465. goto out_free_memmap;
  466. conf_tid = &wl->conf.tx.tid_conf[i];
  467. ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
  468. conf_tid->channel_type,
  469. conf_tid->tsid,
  470. conf_tid->ps_scheme,
  471. conf_tid->ack_policy,
  472. conf_tid->apsd_conf[0],
  473. conf_tid->apsd_conf[1]);
  474. if (ret < 0)
  475. goto out_free_memmap;
  476. }
  477. /* Enable data path */
  478. ret = wl1271_cmd_data_path(wl, 1);
  479. if (ret < 0)
  480. goto out_free_memmap;
  481. /* Configure HW encryption */
  482. ret = wl1271_acx_feature_cfg(wl);
  483. if (ret < 0)
  484. goto out_free_memmap;
  485. /* configure PM */
  486. ret = wl1271_acx_pm_config(wl);
  487. if (ret < 0)
  488. goto out_free_memmap;
  489. /* Mode specific init - post mem init */
  490. if (is_ap)
  491. ret = wl1271_ap_hw_init_post_mem(wl);
  492. else
  493. ret = wl1271_sta_hw_init_post_mem(wl);
  494. if (ret < 0)
  495. goto out_free_memmap;
  496. /* Configure initiator BA sessions policies */
  497. ret = wl1271_set_ba_policies(wl);
  498. if (ret < 0)
  499. goto out_free_memmap;
  500. return 0;
  501. out_free_memmap:
  502. kfree(wl->target_mem_map);
  503. wl->target_mem_map = NULL;
  504. return ret;
  505. }