init.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. #include "io.h"
  33. int wl1271_init_templates_config(struct wl1271 *wl)
  34. {
  35. int ret, i;
  36. /* send empty templates for fw memory reservation */
  37. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
  38. WL1271_CMD_TEMPL_DFLT_SIZE,
  39. 0, WL1271_RATE_AUTOMATIC);
  40. if (ret < 0)
  41. return ret;
  42. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  43. NULL, WL1271_CMD_TEMPL_DFLT_SIZE, 0,
  44. WL1271_RATE_AUTOMATIC);
  45. if (ret < 0)
  46. return ret;
  47. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  48. sizeof(struct wl12xx_null_data_template),
  49. 0, WL1271_RATE_AUTOMATIC);
  50. if (ret < 0)
  51. return ret;
  52. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
  53. sizeof(struct wl12xx_ps_poll_template),
  54. 0, WL1271_RATE_AUTOMATIC);
  55. if (ret < 0)
  56. return ret;
  57. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  58. sizeof
  59. (struct wl12xx_qos_null_data_template),
  60. 0, WL1271_RATE_AUTOMATIC);
  61. if (ret < 0)
  62. return ret;
  63. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
  64. WL1271_CMD_TEMPL_DFLT_SIZE,
  65. 0, WL1271_RATE_AUTOMATIC);
  66. if (ret < 0)
  67. return ret;
  68. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
  69. WL1271_CMD_TEMPL_DFLT_SIZE,
  70. 0, WL1271_RATE_AUTOMATIC);
  71. if (ret < 0)
  72. return ret;
  73. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP, NULL,
  74. sizeof
  75. (struct wl12xx_arp_rsp_template),
  76. 0, WL1271_RATE_AUTOMATIC);
  77. if (ret < 0)
  78. return ret;
  79. /*
  80. * Put very large empty placeholders for all templates. These
  81. * reserve memory for later.
  82. */
  83. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
  84. WL1271_CMD_TEMPL_MAX_SIZE,
  85. 0, WL1271_RATE_AUTOMATIC);
  86. if (ret < 0)
  87. return ret;
  88. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
  89. WL1271_CMD_TEMPL_MAX_SIZE,
  90. 0, WL1271_RATE_AUTOMATIC);
  91. if (ret < 0)
  92. return ret;
  93. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
  94. sizeof
  95. (struct wl12xx_disconn_template),
  96. 0, WL1271_RATE_AUTOMATIC);
  97. if (ret < 0)
  98. return ret;
  99. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  100. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
  101. WL1271_CMD_TEMPL_DFLT_SIZE, i,
  102. WL1271_RATE_AUTOMATIC);
  103. if (ret < 0)
  104. return ret;
  105. }
  106. return 0;
  107. }
  108. static int wl1271_ap_init_deauth_template(struct wl1271 *wl,
  109. struct wl12xx_vif *wlvif)
  110. {
  111. struct wl12xx_disconn_template *tmpl;
  112. int ret;
  113. u32 rate;
  114. tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
  115. if (!tmpl) {
  116. ret = -ENOMEM;
  117. goto out;
  118. }
  119. tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  120. IEEE80211_STYPE_DEAUTH);
  121. rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  122. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
  123. tmpl, sizeof(*tmpl), 0, rate);
  124. out:
  125. kfree(tmpl);
  126. return ret;
  127. }
  128. static int wl1271_ap_init_null_template(struct wl1271 *wl,
  129. struct ieee80211_vif *vif)
  130. {
  131. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  132. struct ieee80211_hdr_3addr *nullfunc;
  133. int ret;
  134. u32 rate;
  135. nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
  136. if (!nullfunc) {
  137. ret = -ENOMEM;
  138. goto out;
  139. }
  140. nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  141. IEEE80211_STYPE_NULLFUNC |
  142. IEEE80211_FCTL_FROMDS);
  143. /* nullfunc->addr1 is filled by FW */
  144. memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
  145. memcpy(nullfunc->addr3, vif->addr, ETH_ALEN);
  146. rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  147. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
  148. sizeof(*nullfunc), 0, rate);
  149. out:
  150. kfree(nullfunc);
  151. return ret;
  152. }
  153. static int wl1271_ap_init_qos_null_template(struct wl1271 *wl,
  154. struct ieee80211_vif *vif)
  155. {
  156. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  157. struct ieee80211_qos_hdr *qosnull;
  158. int ret;
  159. u32 rate;
  160. qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
  161. if (!qosnull) {
  162. ret = -ENOMEM;
  163. goto out;
  164. }
  165. qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  166. IEEE80211_STYPE_QOS_NULLFUNC |
  167. IEEE80211_FCTL_FROMDS);
  168. /* qosnull->addr1 is filled by FW */
  169. memcpy(qosnull->addr2, vif->addr, ETH_ALEN);
  170. memcpy(qosnull->addr3, vif->addr, ETH_ALEN);
  171. rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  172. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
  173. sizeof(*qosnull), 0, rate);
  174. out:
  175. kfree(qosnull);
  176. return ret;
  177. }
  178. static int wl12xx_init_rx_config(struct wl1271 *wl)
  179. {
  180. int ret;
  181. ret = wl1271_acx_rx_msdu_life_time(wl);
  182. if (ret < 0)
  183. return ret;
  184. return 0;
  185. }
  186. int wl1271_init_phy_config(struct wl1271 *wl)
  187. {
  188. int ret;
  189. ret = wl1271_acx_pd_threshold(wl);
  190. if (ret < 0)
  191. return ret;
  192. return 0;
  193. }
  194. static int wl12xx_init_phy_vif_config(struct wl1271 *wl,
  195. struct wl12xx_vif *wlvif)
  196. {
  197. int ret;
  198. ret = wl1271_acx_slot(wl, wlvif, DEFAULT_SLOT_TIME);
  199. if (ret < 0)
  200. return ret;
  201. ret = wl1271_acx_service_period_timeout(wl, wlvif);
  202. if (ret < 0)
  203. return ret;
  204. ret = wl1271_acx_rts_threshold(wl, wlvif, wl->hw->wiphy->rts_threshold);
  205. if (ret < 0)
  206. return ret;
  207. return 0;
  208. }
  209. static int wl1271_init_beacon_filter(struct wl1271 *wl,
  210. struct wl12xx_vif *wlvif)
  211. {
  212. int ret;
  213. /* disable beacon filtering at this stage */
  214. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
  215. if (ret < 0)
  216. return ret;
  217. ret = wl1271_acx_beacon_filter_table(wl, wlvif);
  218. if (ret < 0)
  219. return ret;
  220. return 0;
  221. }
  222. int wl1271_init_pta(struct wl1271 *wl)
  223. {
  224. int ret;
  225. ret = wl12xx_acx_sg_cfg(wl);
  226. if (ret < 0)
  227. return ret;
  228. ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
  229. if (ret < 0)
  230. return ret;
  231. return 0;
  232. }
  233. int wl1271_init_energy_detection(struct wl1271 *wl)
  234. {
  235. int ret;
  236. ret = wl1271_acx_cca_threshold(wl);
  237. if (ret < 0)
  238. return ret;
  239. return 0;
  240. }
  241. static int wl1271_init_beacon_broadcast(struct wl1271 *wl,
  242. struct wl12xx_vif *wlvif)
  243. {
  244. int ret;
  245. ret = wl1271_acx_bcn_dtim_options(wl, wlvif);
  246. if (ret < 0)
  247. return ret;
  248. return 0;
  249. }
  250. static int wl12xx_init_fwlog(struct wl1271 *wl)
  251. {
  252. int ret;
  253. if (wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED)
  254. return 0;
  255. ret = wl12xx_cmd_config_fwlog(wl);
  256. if (ret < 0)
  257. return ret;
  258. return 0;
  259. }
  260. /* generic sta initialization (non vif-specific) */
  261. static int wl1271_sta_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  262. {
  263. int ret;
  264. if (wl->chip.id != CHIP_ID_1283_PG20) {
  265. ret = wl1271_cmd_ext_radio_parms(wl);
  266. if (ret < 0)
  267. return ret;
  268. }
  269. /* PS config */
  270. ret = wl12xx_acx_config_ps(wl, wlvif);
  271. if (ret < 0)
  272. return ret;
  273. /* FM WLAN coexistence */
  274. ret = wl1271_acx_fm_coex(wl);
  275. if (ret < 0)
  276. return ret;
  277. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  278. if (ret < 0)
  279. return ret;
  280. return 0;
  281. }
  282. static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
  283. struct ieee80211_vif *vif)
  284. {
  285. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  286. int ret, i;
  287. /* disable all keep-alive templates */
  288. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  289. ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
  290. ACX_KEEP_ALIVE_TPL_INVALID);
  291. if (ret < 0)
  292. return ret;
  293. }
  294. /* disable the keep-alive feature */
  295. ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
  296. if (ret < 0)
  297. return ret;
  298. return 0;
  299. }
  300. /* generic ap initialization (non vif-specific) */
  301. static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  302. {
  303. int ret;
  304. ret = wl1271_init_ap_rates(wl, wlvif);
  305. if (ret < 0)
  306. return ret;
  307. return 0;
  308. }
  309. int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
  310. {
  311. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  312. int ret;
  313. ret = wl1271_ap_init_deauth_template(wl, wlvif);
  314. if (ret < 0)
  315. return ret;
  316. ret = wl1271_ap_init_null_template(wl, vif);
  317. if (ret < 0)
  318. return ret;
  319. ret = wl1271_ap_init_qos_null_template(wl, vif);
  320. if (ret < 0)
  321. return ret;
  322. /*
  323. * when operating as AP we want to receive external beacons for
  324. * configuring ERP protection.
  325. */
  326. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
  327. if (ret < 0)
  328. return ret;
  329. return 0;
  330. }
  331. static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
  332. struct ieee80211_vif *vif)
  333. {
  334. return wl1271_ap_init_templates(wl, vif);
  335. }
  336. int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  337. {
  338. int i, ret;
  339. struct conf_tx_rate_class rc;
  340. u32 supported_rates;
  341. wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
  342. wlvif->basic_rate_set);
  343. if (wlvif->basic_rate_set == 0)
  344. return -EINVAL;
  345. rc.enabled_rates = wlvif->basic_rate_set;
  346. rc.long_retry_limit = 10;
  347. rc.short_retry_limit = 10;
  348. rc.aflags = 0;
  349. ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
  350. if (ret < 0)
  351. return ret;
  352. /* use the min basic rate for AP broadcast/multicast */
  353. rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  354. rc.short_retry_limit = 10;
  355. rc.long_retry_limit = 10;
  356. rc.aflags = 0;
  357. ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
  358. if (ret < 0)
  359. return ret;
  360. /*
  361. * If the basic rates contain OFDM rates, use OFDM only
  362. * rates for unicast TX as well. Else use all supported rates.
  363. */
  364. if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
  365. supported_rates = CONF_TX_OFDM_RATES;
  366. else
  367. supported_rates = CONF_TX_AP_ENABLED_RATES;
  368. /* unconditionally enable HT rates */
  369. supported_rates |= CONF_TX_MCS_RATES;
  370. /* configure unicast TX rate classes */
  371. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  372. rc.enabled_rates = supported_rates;
  373. rc.short_retry_limit = 10;
  374. rc.long_retry_limit = 10;
  375. rc.aflags = 0;
  376. ret = wl1271_acx_ap_rate_policy(wl, &rc,
  377. wlvif->ap.ucast_rate_idx[i]);
  378. if (ret < 0)
  379. return ret;
  380. }
  381. return 0;
  382. }
  383. static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  384. {
  385. /* Reset the BA RX indicators */
  386. wlvif->ba_allowed = true;
  387. wl->ba_rx_session_count = 0;
  388. /* BA is supported in STA/AP modes */
  389. if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
  390. wlvif->bss_type != BSS_TYPE_STA_BSS) {
  391. wlvif->ba_support = false;
  392. return 0;
  393. }
  394. wlvif->ba_support = true;
  395. /* 802.11n initiator BA session setting */
  396. return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
  397. }
  398. int wl1271_chip_specific_init(struct wl1271 *wl)
  399. {
  400. int ret = 0;
  401. if (wl->chip.id == CHIP_ID_1283_PG20) {
  402. u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
  403. if (wl->quirks & WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT)
  404. /* Enable SDIO padding */
  405. host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
  406. /* Must be before wl1271_acx_init_mem_config() */
  407. ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
  408. if (ret < 0)
  409. goto out;
  410. }
  411. out:
  412. return ret;
  413. }
  414. /* vif-specifc initialization */
  415. static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  416. {
  417. int ret;
  418. ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
  419. if (ret < 0)
  420. return ret;
  421. /* Initialize connection monitoring thresholds */
  422. ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
  423. if (ret < 0)
  424. return ret;
  425. /* Beacon filtering */
  426. ret = wl1271_init_beacon_filter(wl, wlvif);
  427. if (ret < 0)
  428. return ret;
  429. /* Beacons and broadcast settings */
  430. ret = wl1271_init_beacon_broadcast(wl, wlvif);
  431. if (ret < 0)
  432. return ret;
  433. /* Configure rssi/snr averaging weights */
  434. ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
  435. if (ret < 0)
  436. return ret;
  437. return 0;
  438. }
  439. /* vif-specific intialization */
  440. static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  441. {
  442. int ret;
  443. ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
  444. if (ret < 0)
  445. return ret;
  446. /* initialize Tx power */
  447. ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
  448. if (ret < 0)
  449. return ret;
  450. return 0;
  451. }
  452. int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
  453. {
  454. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  455. struct conf_tx_ac_category *conf_ac;
  456. struct conf_tx_tid *conf_tid;
  457. bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
  458. int ret, i;
  459. /*
  460. * consider all existing roles before configuring psm.
  461. * TODO: reconfigure on interface removal.
  462. */
  463. if (!wl->ap_count) {
  464. if (is_ap) {
  465. /* Configure for power always on */
  466. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
  467. if (ret < 0)
  468. return ret;
  469. } else if (!wl->sta_count) {
  470. /* Configure for ELP power saving */
  471. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  472. if (ret < 0)
  473. return ret;
  474. }
  475. }
  476. /* Mode specific init */
  477. if (is_ap) {
  478. ret = wl1271_ap_hw_init(wl, wlvif);
  479. if (ret < 0)
  480. return ret;
  481. ret = wl12xx_init_ap_role(wl, wlvif);
  482. if (ret < 0)
  483. return ret;
  484. } else {
  485. ret = wl1271_sta_hw_init(wl, wlvif);
  486. if (ret < 0)
  487. return ret;
  488. ret = wl12xx_init_sta_role(wl, wlvif);
  489. if (ret < 0)
  490. return ret;
  491. }
  492. wl12xx_init_phy_vif_config(wl, wlvif);
  493. /* Default TID/AC configuration */
  494. BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
  495. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  496. conf_ac = &wl->conf.tx.ac_conf[i];
  497. ret = wl1271_acx_ac_cfg(wl, wlvif, conf_ac->ac,
  498. conf_ac->cw_min, conf_ac->cw_max,
  499. conf_ac->aifsn, conf_ac->tx_op_limit);
  500. if (ret < 0)
  501. return ret;
  502. conf_tid = &wl->conf.tx.tid_conf[i];
  503. ret = wl1271_acx_tid_cfg(wl, wlvif,
  504. conf_tid->queue_id,
  505. conf_tid->channel_type,
  506. conf_tid->tsid,
  507. conf_tid->ps_scheme,
  508. conf_tid->ack_policy,
  509. conf_tid->apsd_conf[0],
  510. conf_tid->apsd_conf[1]);
  511. if (ret < 0)
  512. return ret;
  513. }
  514. /* Configure HW encryption */
  515. ret = wl1271_acx_feature_cfg(wl, wlvif);
  516. if (ret < 0)
  517. return ret;
  518. /* Mode specific init - post mem init */
  519. if (is_ap)
  520. ret = wl1271_ap_hw_init_post_mem(wl, vif);
  521. else
  522. ret = wl1271_sta_hw_init_post_mem(wl, vif);
  523. if (ret < 0)
  524. return ret;
  525. /* Configure initiator BA sessions policies */
  526. ret = wl1271_set_ba_policies(wl, wlvif);
  527. if (ret < 0)
  528. return ret;
  529. return 0;
  530. }
  531. int wl1271_hw_init(struct wl1271 *wl)
  532. {
  533. int ret;
  534. if (wl->chip.id == CHIP_ID_1283_PG20)
  535. ret = wl128x_cmd_general_parms(wl);
  536. else
  537. ret = wl1271_cmd_general_parms(wl);
  538. if (ret < 0)
  539. return ret;
  540. if (wl->chip.id == CHIP_ID_1283_PG20)
  541. ret = wl128x_cmd_radio_parms(wl);
  542. else
  543. ret = wl1271_cmd_radio_parms(wl);
  544. if (ret < 0)
  545. return ret;
  546. /* Chip-specific init */
  547. ret = wl1271_chip_specific_init(wl);
  548. if (ret < 0)
  549. return ret;
  550. /* Init templates */
  551. ret = wl1271_init_templates_config(wl);
  552. if (ret < 0)
  553. return ret;
  554. ret = wl12xx_acx_mem_cfg(wl);
  555. if (ret < 0)
  556. return ret;
  557. /* Configure the FW logger */
  558. ret = wl12xx_init_fwlog(wl);
  559. if (ret < 0)
  560. return ret;
  561. /* Bluetooth WLAN coexistence */
  562. ret = wl1271_init_pta(wl);
  563. if (ret < 0)
  564. return ret;
  565. /* Default memory configuration */
  566. ret = wl1271_acx_init_mem_config(wl);
  567. if (ret < 0)
  568. return ret;
  569. /* RX config */
  570. ret = wl12xx_init_rx_config(wl);
  571. if (ret < 0)
  572. goto out_free_memmap;
  573. /* PHY layer config */
  574. ret = wl1271_init_phy_config(wl);
  575. if (ret < 0)
  576. goto out_free_memmap;
  577. ret = wl1271_acx_dco_itrim_params(wl);
  578. if (ret < 0)
  579. goto out_free_memmap;
  580. /* Configure TX patch complete interrupt behavior */
  581. ret = wl1271_acx_tx_config_options(wl);
  582. if (ret < 0)
  583. goto out_free_memmap;
  584. /* RX complete interrupt pacing */
  585. ret = wl1271_acx_init_rx_interrupt(wl);
  586. if (ret < 0)
  587. goto out_free_memmap;
  588. /* Energy detection */
  589. ret = wl1271_init_energy_detection(wl);
  590. if (ret < 0)
  591. goto out_free_memmap;
  592. /* Default fragmentation threshold */
  593. ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
  594. if (ret < 0)
  595. goto out_free_memmap;
  596. /* Enable data path */
  597. ret = wl1271_cmd_data_path(wl, 1);
  598. if (ret < 0)
  599. goto out_free_memmap;
  600. /* configure PM */
  601. ret = wl1271_acx_pm_config(wl);
  602. if (ret < 0)
  603. goto out_free_memmap;
  604. ret = wl12xx_acx_set_rate_mgmt_params(wl);
  605. if (ret < 0)
  606. goto out_free_memmap;
  607. /* configure hangover */
  608. ret = wl12xx_acx_config_hangover(wl);
  609. if (ret < 0)
  610. goto out_free_memmap;
  611. return 0;
  612. out_free_memmap:
  613. kfree(wl->target_mem_map);
  614. wl->target_mem_map = NULL;
  615. return ret;
  616. }