init.c 16 KB

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