init.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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. int wl1271_sta_init_templates_config(struct wl1271 *wl)
  33. {
  34. int ret, i;
  35. /* send empty templates for fw memory reservation */
  36. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4, NULL,
  37. WL1271_CMD_TEMPL_MAX_SIZE,
  38. 0, WL1271_RATE_AUTOMATIC);
  39. if (ret < 0)
  40. return ret;
  41. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
  42. NULL, WL1271_CMD_TEMPL_MAX_SIZE, 0,
  43. WL1271_RATE_AUTOMATIC);
  44. if (ret < 0)
  45. return ret;
  46. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  47. sizeof(struct wl12xx_null_data_template),
  48. 0, WL1271_RATE_AUTOMATIC);
  49. if (ret < 0)
  50. return ret;
  51. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, NULL,
  52. sizeof(struct wl12xx_ps_poll_template),
  53. 0, WL1271_RATE_AUTOMATIC);
  54. if (ret < 0)
  55. return ret;
  56. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  57. sizeof
  58. (struct wl12xx_qos_null_data_template),
  59. 0, WL1271_RATE_AUTOMATIC);
  60. if (ret < 0)
  61. return ret;
  62. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PROBE_RESPONSE, NULL,
  63. sizeof
  64. (struct wl12xx_probe_resp_template),
  65. 0, WL1271_RATE_AUTOMATIC);
  66. if (ret < 0)
  67. return ret;
  68. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_BEACON, NULL,
  69. sizeof
  70. (struct wl12xx_beacon_template),
  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. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  81. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV, NULL,
  82. WL1271_CMD_TEMPL_MAX_SIZE, i,
  83. WL1271_RATE_AUTOMATIC);
  84. if (ret < 0)
  85. return ret;
  86. }
  87. return 0;
  88. }
  89. static int wl1271_ap_init_deauth_template(struct wl1271 *wl)
  90. {
  91. struct wl12xx_disconn_template *tmpl;
  92. int ret;
  93. tmpl = kzalloc(sizeof(*tmpl), GFP_KERNEL);
  94. if (!tmpl) {
  95. ret = -ENOMEM;
  96. goto out;
  97. }
  98. tmpl->header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  99. IEEE80211_STYPE_DEAUTH);
  100. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP,
  101. tmpl, sizeof(*tmpl), 0,
  102. wl1271_tx_min_rate_get(wl));
  103. out:
  104. kfree(tmpl);
  105. return ret;
  106. }
  107. static int wl1271_ap_init_null_template(struct wl1271 *wl)
  108. {
  109. struct ieee80211_hdr_3addr *nullfunc;
  110. int ret;
  111. nullfunc = kzalloc(sizeof(*nullfunc), GFP_KERNEL);
  112. if (!nullfunc) {
  113. ret = -ENOMEM;
  114. goto out;
  115. }
  116. nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  117. IEEE80211_STYPE_NULLFUNC |
  118. IEEE80211_FCTL_FROMDS);
  119. /* nullfunc->addr1 is filled by FW */
  120. memcpy(nullfunc->addr2, wl->mac_addr, ETH_ALEN);
  121. memcpy(nullfunc->addr3, wl->mac_addr, ETH_ALEN);
  122. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, nullfunc,
  123. sizeof(*nullfunc), 0,
  124. wl1271_tx_min_rate_get(wl));
  125. out:
  126. kfree(nullfunc);
  127. return ret;
  128. }
  129. static int wl1271_ap_init_qos_null_template(struct wl1271 *wl)
  130. {
  131. struct ieee80211_qos_hdr *qosnull;
  132. int ret;
  133. qosnull = kzalloc(sizeof(*qosnull), GFP_KERNEL);
  134. if (!qosnull) {
  135. ret = -ENOMEM;
  136. goto out;
  137. }
  138. qosnull->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  139. IEEE80211_STYPE_QOS_NULLFUNC |
  140. IEEE80211_FCTL_FROMDS);
  141. /* qosnull->addr1 is filled by FW */
  142. memcpy(qosnull->addr2, wl->mac_addr, ETH_ALEN);
  143. memcpy(qosnull->addr3, wl->mac_addr, ETH_ALEN);
  144. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, qosnull,
  145. sizeof(*qosnull), 0,
  146. wl1271_tx_min_rate_get(wl));
  147. out:
  148. kfree(qosnull);
  149. return ret;
  150. }
  151. static int wl1271_ap_init_templates_config(struct wl1271 *wl)
  152. {
  153. int ret;
  154. /*
  155. * Put very large empty placeholders for all templates. These
  156. * reserve memory for later.
  157. */
  158. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_PROBE_RESPONSE, NULL,
  159. sizeof
  160. (struct wl12xx_probe_resp_template),
  161. 0, WL1271_RATE_AUTOMATIC);
  162. if (ret < 0)
  163. return ret;
  164. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_AP_BEACON, NULL,
  165. sizeof
  166. (struct wl12xx_beacon_template),
  167. 0, WL1271_RATE_AUTOMATIC);
  168. if (ret < 0)
  169. return ret;
  170. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_DEAUTH_AP, NULL,
  171. sizeof
  172. (struct wl12xx_disconn_template),
  173. 0, WL1271_RATE_AUTOMATIC);
  174. if (ret < 0)
  175. return ret;
  176. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, NULL,
  177. sizeof(struct wl12xx_null_data_template),
  178. 0, WL1271_RATE_AUTOMATIC);
  179. if (ret < 0)
  180. return ret;
  181. ret = wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, NULL,
  182. sizeof
  183. (struct wl12xx_qos_null_data_template),
  184. 0, WL1271_RATE_AUTOMATIC);
  185. if (ret < 0)
  186. return ret;
  187. return 0;
  188. }
  189. static int wl1271_init_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  190. {
  191. int ret;
  192. ret = wl1271_acx_rx_msdu_life_time(wl);
  193. if (ret < 0)
  194. return ret;
  195. ret = wl1271_acx_rx_config(wl, config, filter);
  196. if (ret < 0)
  197. return ret;
  198. return 0;
  199. }
  200. int wl1271_init_phy_config(struct wl1271 *wl)
  201. {
  202. int ret;
  203. ret = wl1271_acx_pd_threshold(wl);
  204. if (ret < 0)
  205. return ret;
  206. ret = wl1271_acx_slot(wl, DEFAULT_SLOT_TIME);
  207. if (ret < 0)
  208. return ret;
  209. ret = wl1271_acx_service_period_timeout(wl);
  210. if (ret < 0)
  211. return ret;
  212. ret = wl1271_acx_rts_threshold(wl, wl->conf.rx.rts_threshold);
  213. if (ret < 0)
  214. return ret;
  215. return 0;
  216. }
  217. static int wl1271_init_beacon_filter(struct wl1271 *wl)
  218. {
  219. int ret;
  220. /* disable beacon filtering at this stage */
  221. ret = wl1271_acx_beacon_filter_opt(wl, false);
  222. if (ret < 0)
  223. return ret;
  224. ret = wl1271_acx_beacon_filter_table(wl);
  225. if (ret < 0)
  226. return ret;
  227. return 0;
  228. }
  229. int wl1271_init_pta(struct wl1271 *wl)
  230. {
  231. int ret;
  232. ret = wl1271_acx_sg_cfg(wl);
  233. if (ret < 0)
  234. return ret;
  235. ret = wl1271_acx_sg_enable(wl, wl->sg_enabled);
  236. if (ret < 0)
  237. return ret;
  238. return 0;
  239. }
  240. int wl1271_init_energy_detection(struct wl1271 *wl)
  241. {
  242. int ret;
  243. ret = wl1271_acx_cca_threshold(wl);
  244. if (ret < 0)
  245. return ret;
  246. return 0;
  247. }
  248. static int wl1271_init_beacon_broadcast(struct wl1271 *wl)
  249. {
  250. int ret;
  251. ret = wl1271_acx_bcn_dtim_options(wl);
  252. if (ret < 0)
  253. return ret;
  254. return 0;
  255. }
  256. static int wl1271_sta_hw_init(struct wl1271 *wl)
  257. {
  258. int ret;
  259. ret = wl1271_cmd_ext_radio_parms(wl);
  260. if (ret < 0)
  261. return ret;
  262. ret = wl1271_sta_init_templates_config(wl);
  263. if (ret < 0)
  264. return ret;
  265. ret = wl1271_acx_group_address_tbl(wl, true, NULL, 0);
  266. if (ret < 0)
  267. return ret;
  268. /* Initialize connection monitoring thresholds */
  269. ret = wl1271_acx_conn_monit_params(wl, false);
  270. if (ret < 0)
  271. return ret;
  272. /* Beacon filtering */
  273. ret = wl1271_init_beacon_filter(wl);
  274. if (ret < 0)
  275. return ret;
  276. /* Bluetooth WLAN coexistence */
  277. ret = wl1271_init_pta(wl);
  278. if (ret < 0)
  279. return ret;
  280. /* Beacons and broadcast settings */
  281. ret = wl1271_init_beacon_broadcast(wl);
  282. if (ret < 0)
  283. return ret;
  284. /* Configure for ELP power saving */
  285. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_ELP);
  286. if (ret < 0)
  287. return ret;
  288. /* Configure rssi/snr averaging weights */
  289. ret = wl1271_acx_rssi_snr_avg_weights(wl);
  290. if (ret < 0)
  291. return ret;
  292. ret = wl1271_acx_sta_rate_policies(wl);
  293. if (ret < 0)
  294. return ret;
  295. return 0;
  296. }
  297. static int wl1271_sta_hw_init_post_mem(struct wl1271 *wl)
  298. {
  299. int ret, i;
  300. ret = wl1271_cmd_set_sta_default_wep_key(wl, wl->default_key);
  301. if (ret < 0) {
  302. wl1271_warning("couldn't set default key");
  303. return ret;
  304. }
  305. /* disable all keep-alive templates */
  306. for (i = 0; i < CMD_TEMPL_KLV_IDX_MAX; i++) {
  307. ret = wl1271_acx_keep_alive_config(wl, i,
  308. ACX_KEEP_ALIVE_TPL_INVALID);
  309. if (ret < 0)
  310. return ret;
  311. }
  312. /* disable the keep-alive feature */
  313. ret = wl1271_acx_keep_alive_mode(wl, false);
  314. if (ret < 0)
  315. return ret;
  316. return 0;
  317. }
  318. static int wl1271_ap_hw_init(struct wl1271 *wl)
  319. {
  320. int ret, i;
  321. ret = wl1271_ap_init_templates_config(wl);
  322. if (ret < 0)
  323. return ret;
  324. /* Configure for power always on */
  325. ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
  326. if (ret < 0)
  327. return ret;
  328. /* Configure initial TX rate classes */
  329. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  330. ret = wl1271_acx_ap_rate_policy(wl,
  331. &wl->conf.tx.ap_rc_conf[i], i);
  332. if (ret < 0)
  333. return ret;
  334. }
  335. ret = wl1271_acx_ap_rate_policy(wl,
  336. &wl->conf.tx.ap_mgmt_conf,
  337. ACX_TX_AP_MODE_MGMT_RATE);
  338. if (ret < 0)
  339. return ret;
  340. ret = wl1271_acx_ap_rate_policy(wl,
  341. &wl->conf.tx.ap_bcst_conf,
  342. ACX_TX_AP_MODE_BCST_RATE);
  343. if (ret < 0)
  344. return ret;
  345. ret = wl1271_acx_max_tx_retry(wl);
  346. if (ret < 0)
  347. return ret;
  348. return 0;
  349. }
  350. static int wl1271_ap_hw_init_post_mem(struct wl1271 *wl)
  351. {
  352. int ret;
  353. ret = wl1271_ap_init_deauth_template(wl);
  354. if (ret < 0)
  355. return ret;
  356. ret = wl1271_ap_init_null_template(wl);
  357. if (ret < 0)
  358. return ret;
  359. ret = wl1271_ap_init_qos_null_template(wl);
  360. if (ret < 0)
  361. return ret;
  362. return 0;
  363. }
  364. int wl1271_hw_init(struct wl1271 *wl)
  365. {
  366. struct conf_tx_ac_category *conf_ac;
  367. struct conf_tx_tid *conf_tid;
  368. int ret, i;
  369. bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
  370. ret = wl1271_cmd_general_parms(wl);
  371. if (ret < 0)
  372. return ret;
  373. ret = wl1271_cmd_radio_parms(wl);
  374. if (ret < 0)
  375. return ret;
  376. /* Mode specific init */
  377. if (is_ap)
  378. ret = wl1271_ap_hw_init(wl);
  379. else
  380. ret = wl1271_sta_hw_init(wl);
  381. if (ret < 0)
  382. return ret;
  383. /* Default memory configuration */
  384. ret = wl1271_acx_init_mem_config(wl);
  385. if (ret < 0)
  386. return ret;
  387. /* RX config */
  388. ret = wl1271_init_rx_config(wl,
  389. RX_CFG_PROMISCUOUS | RX_CFG_TSF,
  390. RX_FILTER_OPTION_DEF);
  391. /* RX_CONFIG_OPTION_ANY_DST_ANY_BSS,
  392. RX_FILTER_OPTION_FILTER_ALL); */
  393. if (ret < 0)
  394. goto out_free_memmap;
  395. /* PHY layer config */
  396. ret = wl1271_init_phy_config(wl);
  397. if (ret < 0)
  398. goto out_free_memmap;
  399. ret = wl1271_acx_dco_itrim_params(wl);
  400. if (ret < 0)
  401. goto out_free_memmap;
  402. /* Configure TX patch complete interrupt behavior */
  403. ret = wl1271_acx_tx_config_options(wl);
  404. if (ret < 0)
  405. goto out_free_memmap;
  406. /* RX complete interrupt pacing */
  407. ret = wl1271_acx_init_rx_interrupt(wl);
  408. if (ret < 0)
  409. goto out_free_memmap;
  410. /* Energy detection */
  411. ret = wl1271_init_energy_detection(wl);
  412. if (ret < 0)
  413. goto out_free_memmap;
  414. /* Default fragmentation threshold */
  415. ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
  416. if (ret < 0)
  417. goto out_free_memmap;
  418. /* Default TID/AC configuration */
  419. BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
  420. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  421. conf_ac = &wl->conf.tx.ac_conf[i];
  422. ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
  423. conf_ac->cw_max, conf_ac->aifsn,
  424. conf_ac->tx_op_limit);
  425. if (ret < 0)
  426. goto out_free_memmap;
  427. conf_tid = &wl->conf.tx.tid_conf[i];
  428. ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
  429. conf_tid->channel_type,
  430. conf_tid->tsid,
  431. conf_tid->ps_scheme,
  432. conf_tid->ack_policy,
  433. conf_tid->apsd_conf[0],
  434. conf_tid->apsd_conf[1]);
  435. if (ret < 0)
  436. goto out_free_memmap;
  437. }
  438. /* Enable data path */
  439. ret = wl1271_cmd_data_path(wl, 1);
  440. if (ret < 0)
  441. goto out_free_memmap;
  442. /* Configure HW encryption */
  443. ret = wl1271_acx_feature_cfg(wl);
  444. if (ret < 0)
  445. goto out_free_memmap;
  446. /* configure PM */
  447. ret = wl1271_acx_pm_config(wl);
  448. if (ret < 0)
  449. goto out_free_memmap;
  450. /* Mode specific init - post mem init */
  451. if (is_ap)
  452. ret = wl1271_ap_hw_init_post_mem(wl);
  453. else
  454. ret = wl1271_sta_hw_init_post_mem(wl);
  455. if (ret < 0)
  456. goto out_free_memmap;
  457. return 0;
  458. out_free_memmap:
  459. kfree(wl->target_mem_map);
  460. wl->target_mem_map = NULL;
  461. return ret;
  462. }