wl1271_acx.c 23 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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 = 70;
  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 = 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 = config;
  192. rx_config->filter_options = 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 = 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 = wl->conf.rx.ps_poll_timeout;
  280. rx_timeout->upsd_timeout = 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 = 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_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
  313. {
  314. struct acx_beacon_filter_option *beacon_filter = NULL;
  315. int ret = 0;
  316. wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
  317. if (enable_filter &&
  318. wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
  319. goto out;
  320. beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
  321. if (!beacon_filter) {
  322. ret = -ENOMEM;
  323. goto out;
  324. }
  325. beacon_filter->enable = enable_filter;
  326. /*
  327. * When set to zero, and the filter is enabled, beacons
  328. * without the unicast TIM bit set are dropped.
  329. */
  330. beacon_filter->max_num_beacons = 0;
  331. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
  332. beacon_filter, sizeof(*beacon_filter));
  333. if (ret < 0) {
  334. wl1271_warning("failed to set beacon filter opt: %d", ret);
  335. goto out;
  336. }
  337. out:
  338. kfree(beacon_filter);
  339. return ret;
  340. }
  341. int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
  342. {
  343. struct acx_beacon_filter_ie_table *ie_table;
  344. int i, idx = 0;
  345. int ret;
  346. bool vendor_spec = false;
  347. wl1271_debug(DEBUG_ACX, "acx beacon filter table");
  348. ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
  349. if (!ie_table) {
  350. ret = -ENOMEM;
  351. goto out;
  352. }
  353. /* configure default beacon pass-through rules */
  354. ie_table->num_ie = 0;
  355. for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
  356. struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
  357. ie_table->table[idx++] = r->ie;
  358. ie_table->table[idx++] = r->rule;
  359. if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
  360. /* only one vendor specific ie allowed */
  361. if (vendor_spec)
  362. continue;
  363. /* for vendor specific rules configure the
  364. additional fields */
  365. memcpy(&(ie_table->table[idx]), r->oui,
  366. CONF_BCN_IE_OUI_LEN);
  367. idx += CONF_BCN_IE_OUI_LEN;
  368. ie_table->table[idx++] = r->type;
  369. memcpy(&(ie_table->table[idx]), r->version,
  370. CONF_BCN_IE_VER_LEN);
  371. idx += CONF_BCN_IE_VER_LEN;
  372. vendor_spec = true;
  373. }
  374. ie_table->num_ie++;
  375. }
  376. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
  377. ie_table, sizeof(*ie_table));
  378. if (ret < 0) {
  379. wl1271_warning("failed to set beacon filter table: %d", ret);
  380. goto out;
  381. }
  382. out:
  383. kfree(ie_table);
  384. return ret;
  385. }
  386. int wl1271_acx_conn_monit_params(struct wl1271 *wl)
  387. {
  388. struct acx_conn_monit_params *acx;
  389. int ret;
  390. wl1271_debug(DEBUG_ACX, "acx connection monitor parameters");
  391. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  392. if (!acx) {
  393. ret = -ENOMEM;
  394. goto out;
  395. }
  396. acx->synch_fail_thold = wl->conf.conn.synch_fail_thold;
  397. acx->bss_lose_timeout = wl->conf.conn.bss_lose_timeout;
  398. ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
  399. acx, sizeof(*acx));
  400. if (ret < 0) {
  401. wl1271_warning("failed to set connection monitor "
  402. "parameters: %d", ret);
  403. goto out;
  404. }
  405. out:
  406. kfree(acx);
  407. return ret;
  408. }
  409. int wl1271_acx_sg_enable(struct wl1271 *wl)
  410. {
  411. struct acx_bt_wlan_coex *pta;
  412. int ret;
  413. wl1271_debug(DEBUG_ACX, "acx sg enable");
  414. pta = kzalloc(sizeof(*pta), GFP_KERNEL);
  415. if (!pta) {
  416. ret = -ENOMEM;
  417. goto out;
  418. }
  419. pta->enable = SG_ENABLE;
  420. ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
  421. if (ret < 0) {
  422. wl1271_warning("failed to set softgemini enable: %d", ret);
  423. goto out;
  424. }
  425. out:
  426. kfree(pta);
  427. return ret;
  428. }
  429. int wl1271_acx_sg_cfg(struct wl1271 *wl)
  430. {
  431. struct acx_bt_wlan_coex_param *param;
  432. struct conf_sg_settings *c = &wl->conf.sg;
  433. int ret;
  434. wl1271_debug(DEBUG_ACX, "acx sg cfg");
  435. param = kzalloc(sizeof(*param), GFP_KERNEL);
  436. if (!param) {
  437. ret = -ENOMEM;
  438. goto out;
  439. }
  440. /* BT-WLAN coext parameters */
  441. param->per_threshold = c->per_threshold;
  442. param->max_scan_compensation_time = c->max_scan_compensation_time;
  443. param->nfs_sample_interval = c->nfs_sample_interval;
  444. param->load_ratio = c->load_ratio;
  445. param->auto_ps_mode = c->auto_ps_mode;
  446. param->probe_req_compensation = c->probe_req_compensation;
  447. param->scan_window_compensation = c->scan_window_compensation;
  448. param->antenna_config = c->antenna_config;
  449. param->beacon_miss_threshold = c->beacon_miss_threshold;
  450. param->rate_adaptation_threshold = c->rate_adaptation_threshold;
  451. param->rate_adaptation_snr = c->rate_adaptation_snr;
  452. ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
  453. if (ret < 0) {
  454. wl1271_warning("failed to set sg config: %d", ret);
  455. goto out;
  456. }
  457. out:
  458. kfree(param);
  459. return ret;
  460. }
  461. int wl1271_acx_cca_threshold(struct wl1271 *wl)
  462. {
  463. struct acx_energy_detection *detection;
  464. int ret;
  465. wl1271_debug(DEBUG_ACX, "acx cca threshold");
  466. detection = kzalloc(sizeof(*detection), GFP_KERNEL);
  467. if (!detection) {
  468. ret = -ENOMEM;
  469. goto out;
  470. }
  471. detection->rx_cca_threshold = wl->conf.rx.rx_cca_threshold;
  472. detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
  473. ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
  474. detection, sizeof(*detection));
  475. if (ret < 0) {
  476. wl1271_warning("failed to set cca threshold: %d", ret);
  477. return ret;
  478. }
  479. out:
  480. kfree(detection);
  481. return ret;
  482. }
  483. int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
  484. {
  485. struct acx_beacon_broadcast *bb;
  486. int ret;
  487. wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
  488. bb = kzalloc(sizeof(*bb), GFP_KERNEL);
  489. if (!bb) {
  490. ret = -ENOMEM;
  491. goto out;
  492. }
  493. bb->beacon_rx_timeout = wl->conf.conn.beacon_rx_timeout;
  494. bb->broadcast_timeout = wl->conf.conn.broadcast_timeout;
  495. bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
  496. bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
  497. ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
  498. if (ret < 0) {
  499. wl1271_warning("failed to set rx config: %d", ret);
  500. goto out;
  501. }
  502. out:
  503. kfree(bb);
  504. return ret;
  505. }
  506. int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
  507. {
  508. struct acx_aid *acx_aid;
  509. int ret;
  510. wl1271_debug(DEBUG_ACX, "acx aid");
  511. acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
  512. if (!acx_aid) {
  513. ret = -ENOMEM;
  514. goto out;
  515. }
  516. acx_aid->aid = aid;
  517. ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
  518. if (ret < 0) {
  519. wl1271_warning("failed to set aid: %d", ret);
  520. goto out;
  521. }
  522. out:
  523. kfree(acx_aid);
  524. return ret;
  525. }
  526. int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
  527. {
  528. struct acx_event_mask *mask;
  529. int ret;
  530. wl1271_debug(DEBUG_ACX, "acx event mbox mask");
  531. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  532. if (!mask) {
  533. ret = -ENOMEM;
  534. goto out;
  535. }
  536. /* high event mask is unused */
  537. mask->high_event_mask = 0xffffffff;
  538. mask->event_mask = event_mask;
  539. ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
  540. mask, sizeof(*mask));
  541. if (ret < 0) {
  542. wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
  543. goto out;
  544. }
  545. out:
  546. kfree(mask);
  547. return ret;
  548. }
  549. int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
  550. {
  551. struct acx_preamble *acx;
  552. int ret;
  553. wl1271_debug(DEBUG_ACX, "acx_set_preamble");
  554. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  555. if (!acx) {
  556. ret = -ENOMEM;
  557. goto out;
  558. }
  559. acx->preamble = preamble;
  560. ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
  561. if (ret < 0) {
  562. wl1271_warning("Setting of preamble failed: %d", ret);
  563. goto out;
  564. }
  565. out:
  566. kfree(acx);
  567. return ret;
  568. }
  569. int wl1271_acx_cts_protect(struct wl1271 *wl,
  570. enum acx_ctsprotect_type ctsprotect)
  571. {
  572. struct acx_ctsprotect *acx;
  573. int ret;
  574. wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
  575. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  576. if (!acx) {
  577. ret = -ENOMEM;
  578. goto out;
  579. }
  580. acx->ctsprotect = ctsprotect;
  581. ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
  582. if (ret < 0) {
  583. wl1271_warning("Setting of ctsprotect failed: %d", ret);
  584. goto out;
  585. }
  586. out:
  587. kfree(acx);
  588. return ret;
  589. }
  590. int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
  591. {
  592. int ret;
  593. wl1271_debug(DEBUG_ACX, "acx statistics");
  594. ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
  595. sizeof(*stats));
  596. if (ret < 0) {
  597. wl1271_warning("acx statistics failed: %d", ret);
  598. return -ENOMEM;
  599. }
  600. return 0;
  601. }
  602. int wl1271_acx_rate_policies(struct wl1271 *wl, u32 enabled_rates)
  603. {
  604. struct acx_rate_policy *acx;
  605. struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
  606. int ret = 0;
  607. wl1271_debug(DEBUG_ACX, "acx rate policies");
  608. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  609. if (!acx) {
  610. ret = -ENOMEM;
  611. goto out;
  612. }
  613. /* configure one default (one-size-fits-all) rate class */
  614. acx->rate_class_cnt = 1;
  615. acx->rate_class[0].enabled_rates = enabled_rates;
  616. acx->rate_class[0].short_retry_limit = c->short_retry_limit;
  617. acx->rate_class[0].long_retry_limit = c->long_retry_limit;
  618. acx->rate_class[0].aflags = c->aflags;
  619. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  620. if (ret < 0) {
  621. wl1271_warning("Setting of rate policies failed: %d", ret);
  622. goto out;
  623. }
  624. out:
  625. kfree(acx);
  626. return ret;
  627. }
  628. int wl1271_acx_ac_cfg(struct wl1271 *wl)
  629. {
  630. struct acx_ac_cfg *acx;
  631. int i, ret = 0;
  632. wl1271_debug(DEBUG_ACX, "acx access category config");
  633. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  634. if (!acx) {
  635. ret = -ENOMEM;
  636. goto out;
  637. }
  638. for (i = 0; i < wl->conf.tx.ac_conf_count; i++) {
  639. struct conf_tx_ac_category *c = &(wl->conf.tx.ac_conf[i]);
  640. acx->ac = c->ac;
  641. acx->cw_min = c->cw_min;
  642. acx->cw_max = c->cw_max;
  643. acx->aifsn = c->aifsn;
  644. acx->reserved = 0;
  645. acx->tx_op_limit = c->tx_op_limit;
  646. ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  647. if (ret < 0) {
  648. wl1271_warning("Setting of access category "
  649. "config: %d", ret);
  650. goto out;
  651. }
  652. }
  653. out:
  654. kfree(acx);
  655. return ret;
  656. }
  657. int wl1271_acx_tid_cfg(struct wl1271 *wl)
  658. {
  659. struct acx_tid_config *acx;
  660. int i, ret = 0;
  661. wl1271_debug(DEBUG_ACX, "acx tid config");
  662. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  663. if (!acx) {
  664. ret = -ENOMEM;
  665. goto out;
  666. }
  667. for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
  668. struct conf_tx_tid *c = &(wl->conf.tx.tid_conf[i]);
  669. acx->queue_id = c->queue_id;
  670. acx->channel_type = c->channel_type;
  671. acx->tsid = c->tsid;
  672. acx->ps_scheme = c->ps_scheme;
  673. acx->ack_policy = c->ack_policy;
  674. acx->apsd_conf[0] = c->apsd_conf[0];
  675. acx->apsd_conf[1] = c->apsd_conf[1];
  676. ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  677. if (ret < 0) {
  678. wl1271_warning("Setting of tid config failed: %d", ret);
  679. goto out;
  680. }
  681. }
  682. out:
  683. kfree(acx);
  684. return ret;
  685. }
  686. int wl1271_acx_frag_threshold(struct wl1271 *wl)
  687. {
  688. struct acx_frag_threshold *acx;
  689. int ret = 0;
  690. wl1271_debug(DEBUG_ACX, "acx frag threshold");
  691. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  692. if (!acx) {
  693. ret = -ENOMEM;
  694. goto out;
  695. }
  696. acx->frag_threshold = wl->conf.tx.frag_threshold;
  697. ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
  698. if (ret < 0) {
  699. wl1271_warning("Setting of frag threshold failed: %d", ret);
  700. goto out;
  701. }
  702. out:
  703. kfree(acx);
  704. return ret;
  705. }
  706. int wl1271_acx_tx_config_options(struct wl1271 *wl)
  707. {
  708. struct acx_tx_config_options *acx;
  709. int ret = 0;
  710. wl1271_debug(DEBUG_ACX, "acx tx config options");
  711. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  712. if (!acx) {
  713. ret = -ENOMEM;
  714. goto out;
  715. }
  716. acx->tx_compl_timeout = wl->conf.tx.tx_compl_timeout;
  717. acx->tx_compl_threshold = wl->conf.tx.tx_compl_threshold;
  718. ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
  719. if (ret < 0) {
  720. wl1271_warning("Setting of tx options failed: %d", ret);
  721. goto out;
  722. }
  723. out:
  724. kfree(acx);
  725. return ret;
  726. }
  727. int wl1271_acx_mem_cfg(struct wl1271 *wl)
  728. {
  729. struct wl1271_acx_config_memory *mem_conf;
  730. int ret;
  731. wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
  732. mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
  733. if (!mem_conf) {
  734. ret = -ENOMEM;
  735. goto out;
  736. }
  737. /* memory config */
  738. mem_conf->num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
  739. mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
  740. mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
  741. mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
  742. mem_conf->total_tx_descriptors = ACX_TX_DESCRIPTORS;
  743. ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
  744. sizeof(*mem_conf));
  745. if (ret < 0) {
  746. wl1271_warning("wl1271 mem config failed: %d", ret);
  747. goto out;
  748. }
  749. out:
  750. kfree(mem_conf);
  751. return ret;
  752. }
  753. int wl1271_acx_init_mem_config(struct wl1271 *wl)
  754. {
  755. int ret;
  756. ret = wl1271_acx_mem_cfg(wl);
  757. if (ret < 0)
  758. return ret;
  759. wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
  760. GFP_KERNEL);
  761. if (!wl->target_mem_map) {
  762. wl1271_error("couldn't allocate target memory map");
  763. return -ENOMEM;
  764. }
  765. /* we now ask for the firmware built memory map */
  766. ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
  767. sizeof(struct wl1271_acx_mem_map));
  768. if (ret < 0) {
  769. wl1271_error("couldn't retrieve firmware memory map");
  770. kfree(wl->target_mem_map);
  771. wl->target_mem_map = NULL;
  772. return ret;
  773. }
  774. /* initialize TX block book keeping */
  775. wl->tx_blocks_available = wl->target_mem_map->num_tx_mem_blocks;
  776. wl1271_debug(DEBUG_TX, "available tx blocks: %d",
  777. wl->tx_blocks_available);
  778. return 0;
  779. }
  780. int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
  781. {
  782. struct wl1271_acx_rx_config_opt *rx_conf;
  783. int ret;
  784. wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
  785. rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
  786. if (!rx_conf) {
  787. ret = -ENOMEM;
  788. goto out;
  789. }
  790. rx_conf->threshold = wl->conf.rx.irq_pkt_threshold;
  791. rx_conf->timeout = wl->conf.rx.irq_timeout;
  792. rx_conf->mblk_threshold = wl->conf.rx.irq_blk_threshold;
  793. rx_conf->queue_type = wl->conf.rx.queue_type;
  794. ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
  795. sizeof(*rx_conf));
  796. if (ret < 0) {
  797. wl1271_warning("wl1271 rx config opt failed: %d", ret);
  798. goto out;
  799. }
  800. out:
  801. kfree(rx_conf);
  802. return ret;
  803. }
  804. int wl1271_acx_smart_reflex(struct wl1271 *wl)
  805. {
  806. struct acx_smart_reflex_state *sr_state = NULL;
  807. struct acx_smart_reflex_config_params *sr_param = NULL;
  808. int i, ret;
  809. wl1271_debug(DEBUG_ACX, "acx smart reflex");
  810. sr_param = kzalloc(sizeof(*sr_param), GFP_KERNEL);
  811. if (!sr_param) {
  812. ret = -ENOMEM;
  813. goto out;
  814. }
  815. for (i = 0; i < CONF_SR_ERR_TBL_COUNT; i++) {
  816. struct conf_mart_reflex_err_table *e =
  817. &(wl->conf.init.sr_err_tbl[i]);
  818. sr_param->error_table[i].len = e->len;
  819. sr_param->error_table[i].upper_limit = e->upper_limit;
  820. memcpy(sr_param->error_table[i].values, e->values, e->len);
  821. }
  822. ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_PARAMS,
  823. sr_param, sizeof(*sr_param));
  824. if (ret < 0) {
  825. wl1271_warning("failed to set smart reflex params: %d", ret);
  826. goto out;
  827. }
  828. sr_state = kzalloc(sizeof(*sr_state), GFP_KERNEL);
  829. if (!sr_state) {
  830. ret = -ENOMEM;
  831. goto out;
  832. }
  833. /* enable smart reflex */
  834. sr_state->enable = wl->conf.init.sr_enable;
  835. ret = wl1271_cmd_configure(wl, ACX_SET_SMART_REFLEX_STATE,
  836. sr_state, sizeof(*sr_state));
  837. if (ret < 0) {
  838. wl1271_warning("failed to set smart reflex params: %d", ret);
  839. goto out;
  840. }
  841. out:
  842. kfree(sr_state);
  843. kfree(sr_param);
  844. return ret;
  845. }
  846. int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
  847. {
  848. struct wl1271_acx_bet_enable *acx = NULL;
  849. int ret = 0;
  850. wl1271_debug(DEBUG_ACX, "acx bet enable");
  851. if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
  852. goto out;
  853. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  854. if (!acx) {
  855. ret = -ENOMEM;
  856. goto out;
  857. }
  858. acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
  859. acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
  860. ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
  861. if (ret < 0) {
  862. wl1271_warning("acx bet enable failed: %d", ret);
  863. goto out;
  864. }
  865. out:
  866. kfree(acx);
  867. return ret;
  868. }