wl1271_acx.c 24 KB

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