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