wl1271_acx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2008-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 "wl1271_acx.h"
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/crc7.h>
  27. #include <linux/spi/spi.h>
  28. #include "wl1271.h"
  29. #include "wl12xx_80211.h"
  30. #include "wl1271_reg.h"
  31. #include "wl1271_spi.h"
  32. #include "wl1271_ps.h"
  33. int wl1271_acx_wake_up_conditions(struct wl1271 *wl, u8 wake_up_event,
  34. u8 listen_interval)
  35. {
  36. struct acx_wake_up_condition *wake_up;
  37. int ret;
  38. wl1271_debug(DEBUG_ACX, "acx wake up conditions");
  39. wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
  40. if (!wake_up) {
  41. ret = -ENOMEM;
  42. goto out;
  43. }
  44. wake_up->wake_up_event = wake_up_event;
  45. wake_up->listen_interval = listen_interval;
  46. ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
  47. wake_up, sizeof(*wake_up));
  48. if (ret < 0) {
  49. wl1271_warning("could not set wake up conditions: %d", ret);
  50. goto out;
  51. }
  52. out:
  53. kfree(wake_up);
  54. return ret;
  55. }
  56. int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
  57. {
  58. struct acx_sleep_auth *auth;
  59. int ret;
  60. wl1271_debug(DEBUG_ACX, "acx sleep auth");
  61. auth = kzalloc(sizeof(*auth), GFP_KERNEL);
  62. if (!auth) {
  63. ret = -ENOMEM;
  64. goto out;
  65. }
  66. auth->sleep_auth = sleep_auth;
  67. ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
  68. if (ret < 0)
  69. return ret;
  70. out:
  71. kfree(auth);
  72. return ret;
  73. }
  74. int wl1271_acx_fw_version(struct wl1271 *wl, char *buf, size_t len)
  75. {
  76. struct acx_revision *rev;
  77. int ret;
  78. wl1271_debug(DEBUG_ACX, "acx fw rev");
  79. rev = kzalloc(sizeof(*rev), GFP_KERNEL);
  80. if (!rev) {
  81. ret = -ENOMEM;
  82. goto out;
  83. }
  84. ret = wl1271_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
  85. if (ret < 0) {
  86. wl1271_warning("ACX_FW_REV interrogate failed");
  87. goto out;
  88. }
  89. /* be careful with the buffer sizes */
  90. strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
  91. /*
  92. * if the firmware version string is exactly
  93. * sizeof(rev->fw_version) long or fw_len is less than
  94. * sizeof(rev->fw_version) it won't be null terminated
  95. */
  96. buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
  97. out:
  98. kfree(rev);
  99. return ret;
  100. }
  101. int wl1271_acx_tx_power(struct wl1271 *wl, int power)
  102. {
  103. struct acx_current_tx_power *acx;
  104. int ret;
  105. wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
  106. if (power < 0 || power > 25)
  107. return -EINVAL;
  108. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  109. if (!acx) {
  110. ret = -ENOMEM;
  111. goto out;
  112. }
  113. /*
  114. * FIXME: This is a workaround needed while we don't the correct
  115. * calibration, to avoid distortions
  116. */
  117. /* acx->current_tx_power = power * 10; */
  118. acx->current_tx_power = 70;
  119. ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
  120. if (ret < 0) {
  121. wl1271_warning("configure of tx power failed: %d", ret);
  122. goto out;
  123. }
  124. out:
  125. kfree(acx);
  126. return ret;
  127. }
  128. int wl1271_acx_feature_cfg(struct wl1271 *wl)
  129. {
  130. struct acx_feature_config *feature;
  131. int ret;
  132. wl1271_debug(DEBUG_ACX, "acx feature cfg");
  133. feature = kzalloc(sizeof(*feature), GFP_KERNEL);
  134. if (!feature) {
  135. ret = -ENOMEM;
  136. goto out;
  137. }
  138. /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
  139. feature->data_flow_options = 0;
  140. feature->options = 0;
  141. ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
  142. feature, sizeof(*feature));
  143. if (ret < 0) {
  144. wl1271_error("Couldnt set HW encryption");
  145. goto out;
  146. }
  147. out:
  148. kfree(feature);
  149. return ret;
  150. }
  151. int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
  152. size_t len)
  153. {
  154. int ret;
  155. wl1271_debug(DEBUG_ACX, "acx mem map");
  156. ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
  157. if (ret < 0)
  158. return ret;
  159. return 0;
  160. }
  161. int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
  162. {
  163. struct acx_rx_msdu_lifetime *acx;
  164. int ret;
  165. wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
  166. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  167. if (!acx) {
  168. ret = -ENOMEM;
  169. goto out;
  170. }
  171. acx->lifetime = wl->conf.rx.rx_msdu_life_time;
  172. ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
  173. acx, sizeof(*acx));
  174. if (ret < 0) {
  175. wl1271_warning("failed to set rx msdu life time: %d", ret);
  176. goto out;
  177. }
  178. out:
  179. kfree(acx);
  180. return ret;
  181. }
  182. int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  183. {
  184. struct acx_rx_config *rx_config;
  185. int ret;
  186. wl1271_debug(DEBUG_ACX, "acx rx config");
  187. rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
  188. if (!rx_config) {
  189. ret = -ENOMEM;
  190. goto out;
  191. }
  192. rx_config->config_options = config;
  193. rx_config->filter_options = filter;
  194. ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
  195. rx_config, sizeof(*rx_config));
  196. if (ret < 0) {
  197. wl1271_warning("failed to set rx config: %d", ret);
  198. goto out;
  199. }
  200. out:
  201. kfree(rx_config);
  202. return ret;
  203. }
  204. int wl1271_acx_pd_threshold(struct wl1271 *wl)
  205. {
  206. struct acx_packet_detection *pd;
  207. int ret;
  208. wl1271_debug(DEBUG_ACX, "acx data pd threshold");
  209. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  210. if (!pd) {
  211. ret = -ENOMEM;
  212. goto out;
  213. }
  214. pd->threshold = wl->conf.rx.packet_detection_threshold;
  215. ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
  216. if (ret < 0) {
  217. wl1271_warning("failed to set pd threshold: %d", ret);
  218. goto out;
  219. }
  220. out:
  221. kfree(pd);
  222. return 0;
  223. }
  224. int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
  225. {
  226. struct acx_slot *slot;
  227. int ret;
  228. wl1271_debug(DEBUG_ACX, "acx slot");
  229. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  230. if (!slot) {
  231. ret = -ENOMEM;
  232. goto out;
  233. }
  234. slot->wone_index = STATION_WONE_INDEX;
  235. slot->slot_time = slot_time;
  236. ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
  237. if (ret < 0) {
  238. wl1271_warning("failed to set slot time: %d", ret);
  239. goto out;
  240. }
  241. out:
  242. kfree(slot);
  243. return ret;
  244. }
  245. int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
  246. void *mc_list, u32 mc_list_len)
  247. {
  248. struct acx_dot11_grp_addr_tbl *acx;
  249. int ret;
  250. wl1271_debug(DEBUG_ACX, "acx group address tbl");
  251. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  252. if (!acx) {
  253. ret = -ENOMEM;
  254. goto out;
  255. }
  256. /* MAC filtering */
  257. acx->enabled = enable;
  258. acx->num_groups = mc_list_len;
  259. memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
  260. ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
  261. acx, sizeof(*acx));
  262. if (ret < 0) {
  263. wl1271_warning("failed to set group addr table: %d", ret);
  264. goto out;
  265. }
  266. out:
  267. kfree(acx);
  268. return ret;
  269. }
  270. int wl1271_acx_service_period_timeout(struct wl1271 *wl)
  271. {
  272. struct acx_rx_timeout *rx_timeout;
  273. int ret;
  274. rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
  275. if (!rx_timeout) {
  276. ret = -ENOMEM;
  277. goto out;
  278. }
  279. wl1271_debug(DEBUG_ACX, "acx service period timeout");
  280. rx_timeout->ps_poll_timeout = wl->conf.rx.ps_poll_timeout;
  281. rx_timeout->upsd_timeout = wl->conf.rx.upsd_timeout;
  282. ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
  283. rx_timeout, sizeof(*rx_timeout));
  284. if (ret < 0) {
  285. wl1271_warning("failed to set service period timeout: %d",
  286. ret);
  287. goto out;
  288. }
  289. out:
  290. kfree(rx_timeout);
  291. return ret;
  292. }
  293. int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
  294. {
  295. struct acx_rts_threshold *rts;
  296. int ret;
  297. wl1271_debug(DEBUG_ACX, "acx rts threshold");
  298. rts = kzalloc(sizeof(*rts), GFP_KERNEL);
  299. if (!rts) {
  300. ret = -ENOMEM;
  301. goto out;
  302. }
  303. rts->threshold = rts_threshold;
  304. ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
  305. if (ret < 0) {
  306. wl1271_warning("failed to set rts threshold: %d", ret);
  307. goto out;
  308. }
  309. out:
  310. kfree(rts);
  311. return ret;
  312. }
  313. int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
  314. {
  315. struct acx_beacon_filter_option *beacon_filter;
  316. int ret;
  317. wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
  318. beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
  319. if (!beacon_filter) {
  320. ret = -ENOMEM;
  321. goto out;
  322. }
  323. beacon_filter->enable = enable_filter;
  324. beacon_filter->max_num_beacons = 0;
  325. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
  326. beacon_filter, sizeof(*beacon_filter));
  327. if (ret < 0) {
  328. wl1271_warning("failed to set beacon filter opt: %d", ret);
  329. goto out;
  330. }
  331. out:
  332. kfree(beacon_filter);
  333. return ret;
  334. }
  335. int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
  336. {
  337. struct acx_beacon_filter_ie_table *ie_table;
  338. int idx = 0;
  339. int ret;
  340. wl1271_debug(DEBUG_ACX, "acx beacon filter table");
  341. ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
  342. if (!ie_table) {
  343. ret = -ENOMEM;
  344. goto out;
  345. }
  346. /* configure default beacon pass-through rules */
  347. ie_table->num_ie = 1;
  348. ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
  349. ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
  350. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
  351. ie_table, sizeof(*ie_table));
  352. if (ret < 0) {
  353. wl1271_warning("failed to set beacon filter table: %d", ret);
  354. goto out;
  355. }
  356. out:
  357. kfree(ie_table);
  358. return ret;
  359. }
  360. int wl1271_acx_conn_monit_params(struct wl1271 *wl)
  361. {
  362. struct acx_conn_monit_params *acx;
  363. int ret;
  364. wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
  365. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  366. if (!acx) {
  367. ret = -ENOMEM;
  368. goto out;
  369. }
  370. acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
  371. acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
  372. ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
  373. acx, sizeof(*acx));
  374. if (ret < 0) {
  375. wl1271_warning("failed to set connection monitor "
  376. "parameters: %d", ret);
  377. goto out;
  378. }
  379. out:
  380. kfree(acx);
  381. return ret;
  382. }
  383. int wl1271_acx_sg_enable(struct wl1271 *wl)
  384. {
  385. struct acx_bt_wlan_coex *pta;
  386. int ret;
  387. wl1271_debug(DEBUG_ACX, "acx sg enable");
  388. pta = kzalloc(sizeof(*pta), GFP_KERNEL);
  389. if (!pta) {
  390. ret = -ENOMEM;
  391. goto out;
  392. }
  393. pta->enable = SG_ENABLE;
  394. ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
  395. if (ret < 0) {
  396. wl1271_warning("failed to set softgemini enable: %d", ret);
  397. goto out;
  398. }
  399. out:
  400. kfree(pta);
  401. return ret;
  402. }
  403. int wl1271_acx_sg_cfg(struct wl1271 *wl)
  404. {
  405. struct acx_bt_wlan_coex_param *param;
  406. struct conf_sg_settings *c = &wl->conf.sg;
  407. int ret;
  408. wl1271_debug(DEBUG_ACX, "acx sg cfg");
  409. param = kzalloc(sizeof(*param), GFP_KERNEL);
  410. if (!param) {
  411. ret = -ENOMEM;
  412. goto out;
  413. }
  414. /* BT-WLAN coext parameters */
  415. param->per_threshold = c->per_threshold;
  416. param->max_scan_compensation_time = c->max_scan_compensation_time;
  417. param->nfs_sample_interval = c->nfs_sample_interval;
  418. param->load_ratio = c->load_ratio;
  419. param->auto_ps_mode = c->auto_ps_mode;
  420. param->probe_req_compensation = c->probe_req_compensation;
  421. param->scan_window_compensation = c->scan_window_compensation;
  422. param->antenna_config = c->antenna_config;
  423. param->beacon_miss_threshold = c->beacon_miss_threshold;
  424. param->rate_adaptation_threshold = c->rate_adaptation_threshold;
  425. param->rate_adaptation_snr = c->rate_adaptation_snr;
  426. ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
  427. if (ret < 0) {
  428. wl1271_warning("failed to set sg config: %d", ret);
  429. goto out;
  430. }
  431. out:
  432. kfree(param);
  433. return ret;
  434. }
  435. int wl1271_acx_cca_threshold(struct wl1271 *wl)
  436. {
  437. struct acx_energy_detection *detection;
  438. int ret;
  439. wl1271_debug(DEBUG_ACX, "acx cca threshold");
  440. detection = kzalloc(sizeof(*detection), GFP_KERNEL);
  441. if (!detection) {
  442. ret = -ENOMEM;
  443. goto out;
  444. }
  445. detection->rx_cca_threshold = wl->conf.rx.rx_cca_threshold;
  446. detection->tx_energy_detection = 0;
  447. ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
  448. detection, sizeof(*detection));
  449. if (ret < 0) {
  450. wl1271_warning("failed to set cca threshold: %d", ret);
  451. return ret;
  452. }
  453. out:
  454. kfree(detection);
  455. return ret;
  456. }
  457. int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
  458. {
  459. struct acx_beacon_broadcast *bb;
  460. int ret;
  461. wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
  462. bb = kzalloc(sizeof(*bb), GFP_KERNEL);
  463. if (!bb) {
  464. ret = -ENOMEM;
  465. goto out;
  466. }
  467. bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
  468. bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
  469. bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
  470. bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
  471. ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
  472. if (ret < 0) {
  473. wl1271_warning("failed to set rx config: %d", ret);
  474. goto out;
  475. }
  476. out:
  477. kfree(bb);
  478. return ret;
  479. }
  480. int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
  481. {
  482. struct acx_aid *acx_aid;
  483. int ret;
  484. wl1271_debug(DEBUG_ACX, "acx aid");
  485. acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
  486. if (!acx_aid) {
  487. ret = -ENOMEM;
  488. goto out;
  489. }
  490. acx_aid->aid = aid;
  491. ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
  492. if (ret < 0) {
  493. wl1271_warning("failed to set aid: %d", ret);
  494. goto out;
  495. }
  496. out:
  497. kfree(acx_aid);
  498. return ret;
  499. }
  500. int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
  501. {
  502. struct acx_event_mask *mask;
  503. int ret;
  504. wl1271_debug(DEBUG_ACX, "acx event mbox mask");
  505. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  506. if (!mask) {
  507. ret = -ENOMEM;
  508. goto out;
  509. }
  510. /* high event mask is unused */
  511. mask->high_event_mask = 0xffffffff;
  512. mask->event_mask = event_mask;
  513. ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
  514. mask, sizeof(*mask));
  515. if (ret < 0) {
  516. wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
  517. goto out;
  518. }
  519. out:
  520. kfree(mask);
  521. return ret;
  522. }
  523. int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
  524. {
  525. struct acx_preamble *acx;
  526. int ret;
  527. wl1271_debug(DEBUG_ACX, "acx_set_preamble");
  528. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  529. if (!acx) {
  530. ret = -ENOMEM;
  531. goto out;
  532. }
  533. acx->preamble = preamble;
  534. ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
  535. if (ret < 0) {
  536. wl1271_warning("Setting of preamble failed: %d", ret);
  537. goto out;
  538. }
  539. out:
  540. kfree(acx);
  541. return ret;
  542. }
  543. int wl1271_acx_cts_protect(struct wl1271 *wl,
  544. enum acx_ctsprotect_type ctsprotect)
  545. {
  546. struct acx_ctsprotect *acx;
  547. int ret;
  548. wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
  549. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  550. if (!acx) {
  551. ret = -ENOMEM;
  552. goto out;
  553. }
  554. acx->ctsprotect = ctsprotect;
  555. ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
  556. if (ret < 0) {
  557. wl1271_warning("Setting of ctsprotect failed: %d", ret);
  558. goto out;
  559. }
  560. out:
  561. kfree(acx);
  562. return ret;
  563. }
  564. int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
  565. {
  566. int ret;
  567. wl1271_debug(DEBUG_ACX, "acx statistics");
  568. ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
  569. sizeof(*stats));
  570. if (ret < 0) {
  571. wl1271_warning("acx statistics failed: %d", ret);
  572. return -ENOMEM;
  573. }
  574. return 0;
  575. }
  576. int wl1271_acx_rate_policies(struct wl1271 *wl, u32 enabled_rates)
  577. {
  578. struct acx_rate_policy *acx;
  579. int ret = 0;
  580. wl1271_debug(DEBUG_ACX, "acx rate policies");
  581. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  582. if (!acx) {
  583. ret = -ENOMEM;
  584. goto out;
  585. }
  586. /* configure one default (one-size-fits-all) rate class */
  587. acx->rate_class_cnt = 1;
  588. acx->rate_class[0].enabled_rates = enabled_rates;
  589. acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
  590. acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
  591. acx->rate_class[0].aflags = 0;
  592. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  593. if (ret < 0) {
  594. wl1271_warning("Setting of rate policies failed: %d", ret);
  595. goto out;
  596. }
  597. out:
  598. kfree(acx);
  599. return ret;
  600. }
  601. int wl1271_acx_ac_cfg(struct wl1271 *wl)
  602. {
  603. struct acx_ac_cfg *acx;
  604. int i, ret = 0;
  605. wl1271_debug(DEBUG_ACX, "acx access category config");
  606. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  607. if (!acx) {
  608. ret = -ENOMEM;
  609. goto out;
  610. }
  611. /*
  612. * FIXME: Configure each AC with appropriate values (most suitable
  613. * values will probably be different for each AC.
  614. */
  615. for (i = 0; i < WL1271_ACX_AC_COUNT; i++) {
  616. acx->ac = i;
  617. /*
  618. * FIXME: The following default values originate from
  619. * the TI reference driver. What do they mean?
  620. */
  621. acx->cw_min = 15;
  622. acx->cw_max = 63;
  623. acx->aifsn = 3;
  624. acx->reserved = 0;
  625. acx->tx_op_limit = 0;
  626. ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  627. if (ret < 0) {
  628. wl1271_warning("Setting of access category "
  629. "config: %d", ret);
  630. goto out;
  631. }
  632. }
  633. out:
  634. kfree(acx);
  635. return ret;
  636. }
  637. int wl1271_acx_tid_cfg(struct wl1271 *wl)
  638. {
  639. struct acx_tid_config *acx;
  640. int i, ret = 0;
  641. wl1271_debug(DEBUG_ACX, "acx tid config");
  642. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  643. if (!acx) {
  644. ret = -ENOMEM;
  645. goto out;
  646. }
  647. /* FIXME: configure each TID with a different AC reference */
  648. for (i = 0; i < WL1271_ACX_TID_COUNT; i++) {
  649. acx->queue_id = i;
  650. acx->tsid = WL1271_ACX_AC_BE;
  651. acx->ps_scheme = WL1271_ACX_PS_SCHEME_LEGACY;
  652. acx->ack_policy = WL1271_ACX_ACK_POLICY_LEGACY;
  653. ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  654. if (ret < 0) {
  655. wl1271_warning("Setting of tid config failed: %d", ret);
  656. goto out;
  657. }
  658. }
  659. out:
  660. kfree(acx);
  661. return ret;
  662. }
  663. int wl1271_acx_frag_threshold(struct wl1271 *wl)
  664. {
  665. struct acx_frag_threshold *acx;
  666. int ret = 0;
  667. wl1271_debug(DEBUG_ACX, "acx frag threshold");
  668. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  669. if (!acx) {
  670. ret = -ENOMEM;
  671. goto out;
  672. }
  673. acx->frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
  674. ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
  675. if (ret < 0) {
  676. wl1271_warning("Setting of frag threshold failed: %d", ret);
  677. goto out;
  678. }
  679. out:
  680. kfree(acx);
  681. return ret;
  682. }
  683. int wl1271_acx_tx_config_options(struct wl1271 *wl)
  684. {
  685. struct acx_tx_config_options *acx;
  686. int ret = 0;
  687. wl1271_debug(DEBUG_ACX, "acx tx config options");
  688. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  689. if (!acx) {
  690. ret = -ENOMEM;
  691. goto out;
  692. }
  693. acx->tx_compl_timeout = WL1271_ACX_TX_COMPL_TIMEOUT;
  694. acx->tx_compl_threshold = WL1271_ACX_TX_COMPL_THRESHOLD;
  695. ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
  696. if (ret < 0) {
  697. wl1271_warning("Setting of tx options failed: %d", ret);
  698. goto out;
  699. }
  700. out:
  701. kfree(acx);
  702. return ret;
  703. }
  704. int wl1271_acx_mem_cfg(struct wl1271 *wl)
  705. {
  706. struct wl1271_acx_config_memory *mem_conf;
  707. int ret;
  708. wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
  709. mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
  710. if (!mem_conf) {
  711. ret = -ENOMEM;
  712. goto out;
  713. }
  714. /* memory config */
  715. mem_conf->num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
  716. mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
  717. mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
  718. mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
  719. mem_conf->total_tx_descriptors = ACX_TX_DESCRIPTORS;
  720. ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
  721. sizeof(*mem_conf));
  722. if (ret < 0) {
  723. wl1271_warning("wl1271 mem config failed: %d", ret);
  724. goto out;
  725. }
  726. out:
  727. kfree(mem_conf);
  728. return ret;
  729. }
  730. int wl1271_acx_init_mem_config(struct wl1271 *wl)
  731. {
  732. int ret;
  733. ret = wl1271_acx_mem_cfg(wl);
  734. if (ret < 0)
  735. return ret;
  736. wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
  737. GFP_KERNEL);
  738. if (!wl->target_mem_map) {
  739. wl1271_error("couldn't allocate target memory map");
  740. return -ENOMEM;
  741. }
  742. /* we now ask for the firmware built memory map */
  743. ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
  744. sizeof(struct wl1271_acx_mem_map));
  745. if (ret < 0) {
  746. wl1271_error("couldn't retrieve firmware memory map");
  747. kfree(wl->target_mem_map);
  748. wl->target_mem_map = NULL;
  749. return ret;
  750. }
  751. /* initialize TX block book keeping */
  752. wl->tx_blocks_available = wl->target_mem_map->num_tx_mem_blocks;
  753. wl1271_debug(DEBUG_TX, "available tx blocks: %d",
  754. wl->tx_blocks_available);
  755. return 0;
  756. }
  757. int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
  758. {
  759. struct wl1271_acx_rx_config_opt *rx_conf;
  760. int ret;
  761. wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
  762. rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
  763. if (!rx_conf) {
  764. ret = -ENOMEM;
  765. goto out;
  766. }
  767. rx_conf->threshold = wl->conf.rx.irq_pkt_threshold;
  768. rx_conf->timeout = wl->conf.rx.irq_timeout;
  769. rx_conf->mblk_threshold = wl->conf.rx.irq_blk_threshold;
  770. rx_conf->queue_type = wl->conf.rx.queue_type;
  771. ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
  772. sizeof(*rx_conf));
  773. if (ret < 0) {
  774. wl1271_warning("wl1271 rx config opt failed: %d", ret);
  775. goto out;
  776. }
  777. out:
  778. kfree(rx_conf);
  779. return ret;
  780. }
  781. int wl1271_acx_smart_reflex(struct wl1271 *wl)
  782. {
  783. struct acx_smart_reflex_state *sr_state = NULL;
  784. struct acx_smart_reflex_config_params *sr_param = NULL;
  785. int ret;
  786. wl1271_debug(DEBUG_ACX, "acx smart reflex");
  787. sr_param = kzalloc(sizeof(*sr_param), GFP_KERNEL);
  788. if (!sr_param) {
  789. ret = -ENOMEM;
  790. goto out;
  791. }
  792. /* set cryptic smart reflex parameters - source TI reference code */
  793. sr_param->error_table[0].len = 0x07;
  794. sr_param->error_table[0].upper_limit = 0x03;
  795. sr_param->error_table[0].values[0] = 0x18;
  796. sr_param->error_table[0].values[1] = 0x10;
  797. sr_param->error_table[0].values[2] = 0x05;
  798. sr_param->error_table[0].values[3] = 0xfb;
  799. sr_param->error_table[0].values[4] = 0xf0;
  800. sr_param->error_table[0].values[5] = 0xe8;
  801. sr_param->error_table[1].len = 0x07;
  802. sr_param->error_table[1].upper_limit = 0x03;
  803. sr_param->error_table[1].values[0] = 0x18;
  804. sr_param->error_table[1].values[1] = 0x10;
  805. sr_param->error_table[1].values[2] = 0x05;
  806. sr_param->error_table[1].values[3] = 0xf6;
  807. sr_param->error_table[1].values[4] = 0xf0;
  808. sr_param->error_table[1].values[5] = 0xe8;
  809. sr_param->error_table[2].len = 0x07;
  810. sr_param->error_table[2].upper_limit = 0x03;
  811. sr_param->error_table[2].values[0] = 0x18;
  812. sr_param->error_table[2].values[1] = 0x10;
  813. sr_param->error_table[2].values[2] = 0x05;
  814. sr_param->error_table[2].values[3] = 0xfb;
  815. sr_param->error_table[2].values[4] = 0xf0;
  816. sr_param->error_table[2].values[5] = 0xe8;
  817. ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_PARAMS,
  818. sr_param, sizeof(*sr_param));
  819. if (ret < 0) {
  820. wl1271_warning("failed to set smart reflex params: %d", ret);
  821. goto out;
  822. }
  823. sr_state = kzalloc(sizeof(*sr_state), GFP_KERNEL);
  824. if (!sr_state) {
  825. ret = -ENOMEM;
  826. goto out;
  827. }
  828. /* enable smart reflex */
  829. sr_state->enable = 1;
  830. ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_STATE,
  831. sr_state, sizeof(*sr_state));
  832. if (ret < 0) {
  833. wl1271_warning("failed to set smart reflex params: %d", ret);
  834. goto out;
  835. }
  836. out:
  837. kfree(sr_state);
  838. kfree(sr_param);
  839. return ret;
  840. }