wl1271_acx.c 25 KB

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