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 "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 ieee80211_qos_hdr),
  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. sizeof(struct ieee80211_qos_hdr),
  103. i, 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. /* PS config */
  266. ret = wl12xx_acx_config_ps(wl, wlvif);
  267. if (ret < 0)
  268. return ret;
  269. /* FM WLAN coexistence */
  270. ret = wl1271_acx_fm_coex(wl);
  271. if (ret < 0)
  272. return ret;
  273. ret = wl1271_acx_sta_rate_policies(wl, wlvif);
  274. if (ret < 0)
  275. return ret;
  276. return 0;
  277. }
  278. static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl,
  279. struct ieee80211_vif *vif)
  280. {
  281. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  282. int ret, i;
  283. /* disable all keep-alive templates */
  284. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  285. ret = wl1271_acx_keep_alive_config(wl, wlvif, i,
  286. ACX_KEEP_ALIVE_TPL_INVALID);
  287. if (ret < 0)
  288. return ret;
  289. }
  290. /* disable the keep-alive feature */
  291. ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
  292. if (ret < 0)
  293. return ret;
  294. return 0;
  295. }
  296. /* generic ap initialization (non vif-specific) */
  297. static int wl1271_ap_hw_init(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  298. {
  299. int ret;
  300. ret = wl1271_init_ap_rates(wl, wlvif);
  301. if (ret < 0)
  302. return ret;
  303. return 0;
  304. }
  305. int wl1271_ap_init_templates(struct wl1271 *wl, struct ieee80211_vif *vif)
  306. {
  307. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  308. int ret;
  309. ret = wl1271_ap_init_deauth_template(wl, wlvif);
  310. if (ret < 0)
  311. return ret;
  312. ret = wl1271_ap_init_null_template(wl, vif);
  313. if (ret < 0)
  314. return ret;
  315. ret = wl1271_ap_init_qos_null_template(wl, vif);
  316. if (ret < 0)
  317. return ret;
  318. /*
  319. * when operating as AP we want to receive external beacons for
  320. * configuring ERP protection.
  321. */
  322. ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
  323. if (ret < 0)
  324. return ret;
  325. return 0;
  326. }
  327. static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl,
  328. struct ieee80211_vif *vif)
  329. {
  330. return wl1271_ap_init_templates(wl, vif);
  331. }
  332. int wl1271_init_ap_rates(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  333. {
  334. int i, ret;
  335. struct conf_tx_rate_class rc;
  336. u32 supported_rates;
  337. wl1271_debug(DEBUG_AP, "AP basic rate set: 0x%x",
  338. wlvif->basic_rate_set);
  339. if (wlvif->basic_rate_set == 0)
  340. return -EINVAL;
  341. rc.enabled_rates = wlvif->basic_rate_set;
  342. rc.long_retry_limit = 10;
  343. rc.short_retry_limit = 10;
  344. rc.aflags = 0;
  345. ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.mgmt_rate_idx);
  346. if (ret < 0)
  347. return ret;
  348. /* use the min basic rate for AP broadcast/multicast */
  349. rc.enabled_rates = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
  350. rc.short_retry_limit = 10;
  351. rc.long_retry_limit = 10;
  352. rc.aflags = 0;
  353. ret = wl1271_acx_ap_rate_policy(wl, &rc, wlvif->ap.bcast_rate_idx);
  354. if (ret < 0)
  355. return ret;
  356. /*
  357. * If the basic rates contain OFDM rates, use OFDM only
  358. * rates for unicast TX as well. Else use all supported rates.
  359. */
  360. if ((wlvif->basic_rate_set & CONF_TX_OFDM_RATES))
  361. supported_rates = CONF_TX_OFDM_RATES;
  362. else
  363. supported_rates = CONF_TX_AP_ENABLED_RATES;
  364. /* unconditionally enable HT rates */
  365. supported_rates |= CONF_TX_MCS_RATES;
  366. /* configure unicast TX rate classes */
  367. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  368. rc.enabled_rates = supported_rates;
  369. rc.short_retry_limit = 10;
  370. rc.long_retry_limit = 10;
  371. rc.aflags = 0;
  372. ret = wl1271_acx_ap_rate_policy(wl, &rc,
  373. wlvif->ap.ucast_rate_idx[i]);
  374. if (ret < 0)
  375. return ret;
  376. }
  377. return 0;
  378. }
  379. static int wl1271_set_ba_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  380. {
  381. /* Reset the BA RX indicators */
  382. wlvif->ba_allowed = true;
  383. wl->ba_rx_session_count = 0;
  384. /* BA is supported in STA/AP modes */
  385. if (wlvif->bss_type != BSS_TYPE_AP_BSS &&
  386. wlvif->bss_type != BSS_TYPE_STA_BSS) {
  387. wlvif->ba_support = false;
  388. return 0;
  389. }
  390. wlvif->ba_support = true;
  391. /* 802.11n initiator BA session setting */
  392. return wl12xx_acx_set_ba_initiator_policy(wl, wlvif);
  393. }
  394. int wl1271_chip_specific_init(struct wl1271 *wl)
  395. {
  396. int ret = 0;
  397. if (wl->chip.id == CHIP_ID_1283_PG20) {
  398. u32 host_cfg_bitmap = HOST_IF_CFG_RX_FIFO_ENABLE;
  399. if (!(wl->quirks & WL12XX_QUIRK_NO_BLOCKSIZE_ALIGNMENT))
  400. /* Enable SDIO padding */
  401. host_cfg_bitmap |= HOST_IF_CFG_TX_PAD_TO_SDIO_BLK;
  402. /* Must be before wl1271_acx_init_mem_config() */
  403. ret = wl1271_acx_host_if_cfg_bitmap(wl, host_cfg_bitmap);
  404. if (ret < 0)
  405. goto out;
  406. }
  407. out:
  408. return ret;
  409. }
  410. /* vif-specifc initialization */
  411. static int wl12xx_init_sta_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  412. {
  413. int ret;
  414. ret = wl1271_acx_group_address_tbl(wl, wlvif, true, NULL, 0);
  415. if (ret < 0)
  416. return ret;
  417. /* Initialize connection monitoring thresholds */
  418. ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
  419. if (ret < 0)
  420. return ret;
  421. /* Beacon filtering */
  422. ret = wl1271_init_sta_beacon_filter(wl, wlvif);
  423. if (ret < 0)
  424. return ret;
  425. /* Beacons and broadcast settings */
  426. ret = wl1271_init_beacon_broadcast(wl, wlvif);
  427. if (ret < 0)
  428. return ret;
  429. /* Configure rssi/snr averaging weights */
  430. ret = wl1271_acx_rssi_snr_avg_weights(wl, wlvif);
  431. if (ret < 0)
  432. return ret;
  433. return 0;
  434. }
  435. /* vif-specific intialization */
  436. static int wl12xx_init_ap_role(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  437. {
  438. int ret;
  439. ret = wl1271_acx_ap_max_tx_retry(wl, wlvif);
  440. if (ret < 0)
  441. return ret;
  442. /* initialize Tx power */
  443. ret = wl1271_acx_tx_power(wl, wlvif, wlvif->power_level);
  444. if (ret < 0)
  445. return ret;
  446. return 0;
  447. }
  448. int wl1271_init_vif_specific(struct wl1271 *wl, struct ieee80211_vif *vif)
  449. {
  450. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  451. struct conf_tx_ac_category *conf_ac;
  452. struct conf_tx_tid *conf_tid;
  453. bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
  454. int ret, i;
  455. /*
  456. * consider all existing roles before configuring psm.
  457. * TODO: reconfigure on interface removal.
  458. */
  459. if (!wl->ap_count) {
  460. if (is_ap) {
  461. /* Configure for power always on */
  462. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
  463. if (ret < 0)
  464. return ret;
  465. } else if (!wl->sta_count) {
  466. /* Configure for ELP power saving */
  467. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  468. if (ret < 0)
  469. return ret;
  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. return 0;
  526. }
  527. int wl1271_hw_init(struct wl1271 *wl)
  528. {
  529. int ret;
  530. if (wl->chip.id == CHIP_ID_1283_PG20) {
  531. ret = wl128x_cmd_general_parms(wl);
  532. if (ret < 0)
  533. return ret;
  534. ret = wl128x_cmd_radio_parms(wl);
  535. if (ret < 0)
  536. return ret;
  537. } else {
  538. ret = wl1271_cmd_general_parms(wl);
  539. if (ret < 0)
  540. return ret;
  541. ret = wl1271_cmd_radio_parms(wl);
  542. if (ret < 0)
  543. return ret;
  544. ret = wl1271_cmd_ext_radio_parms(wl);
  545. if (ret < 0)
  546. return ret;
  547. }
  548. /* Chip-specific init */
  549. ret = wl1271_chip_specific_init(wl);
  550. if (ret < 0)
  551. return ret;
  552. /* Init templates */
  553. ret = wl1271_init_templates_config(wl);
  554. if (ret < 0)
  555. return ret;
  556. ret = wl12xx_acx_mem_cfg(wl);
  557. if (ret < 0)
  558. return ret;
  559. /* Configure the FW logger */
  560. ret = wl12xx_init_fwlog(wl);
  561. if (ret < 0)
  562. return ret;
  563. /* Bluetooth WLAN coexistence */
  564. ret = wl1271_init_pta(wl);
  565. if (ret < 0)
  566. return ret;
  567. /* Default memory configuration */
  568. ret = wl1271_acx_init_mem_config(wl);
  569. if (ret < 0)
  570. return ret;
  571. /* RX config */
  572. ret = wl12xx_init_rx_config(wl);
  573. if (ret < 0)
  574. goto out_free_memmap;
  575. /* PHY layer config */
  576. ret = wl1271_init_phy_config(wl);
  577. if (ret < 0)
  578. goto out_free_memmap;
  579. ret = wl1271_acx_dco_itrim_params(wl);
  580. if (ret < 0)
  581. goto out_free_memmap;
  582. /* Configure TX patch complete interrupt behavior */
  583. ret = wl1271_acx_tx_config_options(wl);
  584. if (ret < 0)
  585. goto out_free_memmap;
  586. /* RX complete interrupt pacing */
  587. ret = wl1271_acx_init_rx_interrupt(wl);
  588. if (ret < 0)
  589. goto out_free_memmap;
  590. /* Energy detection */
  591. ret = wl1271_init_energy_detection(wl);
  592. if (ret < 0)
  593. goto out_free_memmap;
  594. /* Default fragmentation threshold */
  595. ret = wl1271_acx_frag_threshold(wl, wl->hw->wiphy->frag_threshold);
  596. if (ret < 0)
  597. goto out_free_memmap;
  598. /* Enable data path */
  599. ret = wl1271_cmd_data_path(wl, 1);
  600. if (ret < 0)
  601. goto out_free_memmap;
  602. /* configure PM */
  603. ret = wl1271_acx_pm_config(wl);
  604. if (ret < 0)
  605. goto out_free_memmap;
  606. ret = wl12xx_acx_set_rate_mgmt_params(wl);
  607. if (ret < 0)
  608. goto out_free_memmap;
  609. /* configure hangover */
  610. ret = wl12xx_acx_config_hangover(wl);
  611. if (ret < 0)
  612. goto out_free_memmap;
  613. return 0;
  614. out_free_memmap:
  615. kfree(wl->target_mem_map);
  616. wl->target_mem_map = NULL;
  617. return ret;
  618. }