wl1271_acx.c 24 KB

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