init.c 17 KB

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