wl1271_acx.c 24 KB

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