wl1271_acx.c 22 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  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 = wl->conf.tx.tx_energy_detection;
  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. struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
  580. int ret = 0;
  581. wl1271_debug(DEBUG_ACX, "acx rate policies");
  582. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  583. if (!acx) {
  584. ret = -ENOMEM;
  585. goto out;
  586. }
  587. /* configure one default (one-size-fits-all) rate class */
  588. acx->rate_class_cnt = 1;
  589. acx->rate_class[0].enabled_rates = enabled_rates;
  590. acx->rate_class[0].short_retry_limit = c->short_retry_limit;
  591. acx->rate_class[0].long_retry_limit = c->long_retry_limit;
  592. acx->rate_class[0].aflags = c->aflags;
  593. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  594. if (ret < 0) {
  595. wl1271_warning("Setting of rate policies failed: %d", ret);
  596. goto out;
  597. }
  598. out:
  599. kfree(acx);
  600. return ret;
  601. }
  602. int wl1271_acx_ac_cfg(struct wl1271 *wl)
  603. {
  604. struct acx_ac_cfg *acx;
  605. int i, ret = 0;
  606. wl1271_debug(DEBUG_ACX, "acx access category config");
  607. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  608. if (!acx) {
  609. ret = -ENOMEM;
  610. goto out;
  611. }
  612. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  613. struct conf_tx_ac_category *c = &(wl->conf.tx.ac_conf[i]);
  614. acx->ac = c->ac;
  615. acx->cw_min = c->cw_min;
  616. acx->cw_max = c->cw_max;
  617. acx->aifsn = c->aifsn;
  618. acx->reserved = 0;
  619. acx->tx_op_limit = c->tx_op_limit;
  620. ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  621. if (ret < 0) {
  622. wl1271_warning("Setting of access category "
  623. "config: %d", ret);
  624. goto out;
  625. }
  626. }
  627. out:
  628. kfree(acx);
  629. return ret;
  630. }
  631. int wl1271_acx_tid_cfg(struct wl1271 *wl)
  632. {
  633. struct acx_tid_config *acx;
  634. int i, ret = 0;
  635. wl1271_debug(DEBUG_ACX, "acx tid config");
  636. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  637. if (!acx) {
  638. ret = -ENOMEM;
  639. goto out;
  640. }
  641. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  642. struct conf_tx_tid *c = &(wl->conf.tx.tid_conf[i]);
  643. acx->queue_id = c->queue_id;
  644. acx->channel_type = c->channel_type;
  645. acx->tsid = c->tsid;
  646. acx->ps_scheme = c->ps_scheme;
  647. acx->ack_policy = c->ack_policy;
  648. acx->apsd_conf[0] = c->apsd_conf[0];
  649. acx->apsd_conf[1] = c->apsd_conf[1];
  650. ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  651. if (ret < 0) {
  652. wl1271_warning("Setting of tid config failed: %d", ret);
  653. goto out;
  654. }
  655. }
  656. out:
  657. kfree(acx);
  658. return ret;
  659. }
  660. int wl1271_acx_frag_threshold(struct wl1271 *wl)
  661. {
  662. struct acx_frag_threshold *acx;
  663. int ret = 0;
  664. wl1271_debug(DEBUG_ACX, "acx frag threshold");
  665. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  666. if (!acx) {
  667. ret = -ENOMEM;
  668. goto out;
  669. }
  670. acx->frag_threshold = wl->conf.tx.frag_threshold;
  671. ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
  672. if (ret < 0) {
  673. wl1271_warning("Setting of frag threshold failed: %d", ret);
  674. goto out;
  675. }
  676. out:
  677. kfree(acx);
  678. return ret;
  679. }
  680. int wl1271_acx_tx_config_options(struct wl1271 *wl)
  681. {
  682. struct acx_tx_config_options *acx;
  683. int ret = 0;
  684. wl1271_debug(DEBUG_ACX, "acx tx config options");
  685. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  686. if (!acx) {
  687. ret = -ENOMEM;
  688. goto out;
  689. }
  690. acx->tx_compl_timeout = wl->conf.tx.tx_compl_timeout;
  691. acx->tx_compl_threshold = wl->conf.tx.tx_compl_threshold;
  692. ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
  693. if (ret < 0) {
  694. wl1271_warning("Setting of tx options failed: %d", ret);
  695. goto out;
  696. }
  697. out:
  698. kfree(acx);
  699. return ret;
  700. }
  701. int wl1271_acx_mem_cfg(struct wl1271 *wl)
  702. {
  703. struct wl1271_acx_config_memory *mem_conf;
  704. int ret;
  705. wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
  706. mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
  707. if (!mem_conf) {
  708. ret = -ENOMEM;
  709. goto out;
  710. }
  711. /* memory config */
  712. mem_conf->num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
  713. mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
  714. mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
  715. mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
  716. mem_conf->total_tx_descriptors = ACX_TX_DESCRIPTORS;
  717. ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
  718. sizeof(*mem_conf));
  719. if (ret < 0) {
  720. wl1271_warning("wl1271 mem config failed: %d", ret);
  721. goto out;
  722. }
  723. out:
  724. kfree(mem_conf);
  725. return ret;
  726. }
  727. int wl1271_acx_init_mem_config(struct wl1271 *wl)
  728. {
  729. int ret;
  730. ret = wl1271_acx_mem_cfg(wl);
  731. if (ret < 0)
  732. return ret;
  733. wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
  734. GFP_KERNEL);
  735. if (!wl->target_mem_map) {
  736. wl1271_error("couldn't allocate target memory map");
  737. return -ENOMEM;
  738. }
  739. /* we now ask for the firmware built memory map */
  740. ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
  741. sizeof(struct wl1271_acx_mem_map));
  742. if (ret < 0) {
  743. wl1271_error("couldn't retrieve firmware memory map");
  744. kfree(wl->target_mem_map);
  745. wl->target_mem_map = NULL;
  746. return ret;
  747. }
  748. /* initialize TX block book keeping */
  749. wl->tx_blocks_available = wl->target_mem_map->num_tx_mem_blocks;
  750. wl1271_debug(DEBUG_TX, "available tx blocks: %d",
  751. wl->tx_blocks_available);
  752. return 0;
  753. }
  754. int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
  755. {
  756. struct wl1271_acx_rx_config_opt *rx_conf;
  757. int ret;
  758. wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
  759. rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
  760. if (!rx_conf) {
  761. ret = -ENOMEM;
  762. goto out;
  763. }
  764. rx_conf->threshold = wl->conf.rx.irq_pkt_threshold;
  765. rx_conf->timeout = wl->conf.rx.irq_timeout;
  766. rx_conf->mblk_threshold = wl->conf.rx.irq_blk_threshold;
  767. rx_conf->queue_type = wl->conf.rx.queue_type;
  768. ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
  769. sizeof(*rx_conf));
  770. if (ret < 0) {
  771. wl1271_warning("wl1271 rx config opt failed: %d", ret);
  772. goto out;
  773. }
  774. out:
  775. kfree(rx_conf);
  776. return ret;
  777. }
  778. int wl1271_acx_smart_reflex(struct wl1271 *wl)
  779. {
  780. struct acx_smart_reflex_state *sr_state = NULL;
  781. struct acx_smart_reflex_config_params *sr_param = NULL;
  782. int ret;
  783. wl1271_debug(DEBUG_ACX, "acx smart reflex");
  784. sr_param = kzalloc(sizeof(*sr_param), GFP_KERNEL);
  785. if (!sr_param) {
  786. ret = -ENOMEM;
  787. goto out;
  788. }
  789. /* set cryptic smart reflex parameters - source TI reference code */
  790. sr_param->error_table[0].len = 0x07;
  791. sr_param->error_table[0].upper_limit = 0x03;
  792. sr_param->error_table[0].values[0] = 0x18;
  793. sr_param->error_table[0].values[1] = 0x10;
  794. sr_param->error_table[0].values[2] = 0x05;
  795. sr_param->error_table[0].values[3] = 0xfb;
  796. sr_param->error_table[0].values[4] = 0xf0;
  797. sr_param->error_table[0].values[5] = 0xe8;
  798. sr_param->error_table[1].len = 0x07;
  799. sr_param->error_table[1].upper_limit = 0x03;
  800. sr_param->error_table[1].values[0] = 0x18;
  801. sr_param->error_table[1].values[1] = 0x10;
  802. sr_param->error_table[1].values[2] = 0x05;
  803. sr_param->error_table[1].values[3] = 0xf6;
  804. sr_param->error_table[1].values[4] = 0xf0;
  805. sr_param->error_table[1].values[5] = 0xe8;
  806. sr_param->error_table[2].len = 0x07;
  807. sr_param->error_table[2].upper_limit = 0x03;
  808. sr_param->error_table[2].values[0] = 0x18;
  809. sr_param->error_table[2].values[1] = 0x10;
  810. sr_param->error_table[2].values[2] = 0x05;
  811. sr_param->error_table[2].values[3] = 0xfb;
  812. sr_param->error_table[2].values[4] = 0xf0;
  813. sr_param->error_table[2].values[5] = 0xe8;
  814. ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_PARAMS,
  815. sr_param, sizeof(*sr_param));
  816. if (ret < 0) {
  817. wl1271_warning("failed to set smart reflex params: %d", ret);
  818. goto out;
  819. }
  820. sr_state = kzalloc(sizeof(*sr_state), GFP_KERNEL);
  821. if (!sr_state) {
  822. ret = -ENOMEM;
  823. goto out;
  824. }
  825. /* enable smart reflex */
  826. sr_state->enable = 1;
  827. ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_STATE,
  828. sr_state, sizeof(*sr_state));
  829. if (ret < 0) {
  830. wl1271_warning("failed to set smart reflex params: %d", ret);
  831. goto out;
  832. }
  833. out:
  834. kfree(sr_state);
  835. kfree(sr_param);
  836. return ret;
  837. }