wl1271_acx.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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_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. acx->current_tx_power = power * 10;
  113. ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
  114. if (ret < 0) {
  115. wl1271_warning("configure of tx power failed: %d", ret);
  116. goto out;
  117. }
  118. out:
  119. kfree(acx);
  120. return ret;
  121. }
  122. int wl1271_acx_feature_cfg(struct wl1271 *wl)
  123. {
  124. struct acx_feature_config *feature;
  125. int ret;
  126. wl1271_debug(DEBUG_ACX, "acx feature cfg");
  127. feature = kzalloc(sizeof(*feature), GFP_KERNEL);
  128. if (!feature) {
  129. ret = -ENOMEM;
  130. goto out;
  131. }
  132. /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
  133. feature->data_flow_options = 0;
  134. feature->options = 0;
  135. ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
  136. feature, sizeof(*feature));
  137. if (ret < 0) {
  138. wl1271_error("Couldnt set HW encryption");
  139. goto out;
  140. }
  141. out:
  142. kfree(feature);
  143. return ret;
  144. }
  145. int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
  146. size_t len)
  147. {
  148. int ret;
  149. wl1271_debug(DEBUG_ACX, "acx mem map");
  150. ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
  151. if (ret < 0)
  152. return ret;
  153. return 0;
  154. }
  155. int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
  156. {
  157. struct acx_rx_msdu_lifetime *acx;
  158. int ret;
  159. wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
  160. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  161. if (!acx) {
  162. ret = -ENOMEM;
  163. goto out;
  164. }
  165. acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
  166. ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
  167. acx, sizeof(*acx));
  168. if (ret < 0) {
  169. wl1271_warning("failed to set rx msdu life time: %d", ret);
  170. goto out;
  171. }
  172. out:
  173. kfree(acx);
  174. return ret;
  175. }
  176. int wl1271_acx_rx_config(struct wl1271 *wl, u32 config, u32 filter)
  177. {
  178. struct acx_rx_config *rx_config;
  179. int ret;
  180. wl1271_debug(DEBUG_ACX, "acx rx config");
  181. rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
  182. if (!rx_config) {
  183. ret = -ENOMEM;
  184. goto out;
  185. }
  186. rx_config->config_options = cpu_to_le32(config);
  187. rx_config->filter_options = cpu_to_le32(filter);
  188. ret = wl1271_cmd_configure(wl, ACX_RX_CFG,
  189. rx_config, sizeof(*rx_config));
  190. if (ret < 0) {
  191. wl1271_warning("failed to set rx config: %d", ret);
  192. goto out;
  193. }
  194. out:
  195. kfree(rx_config);
  196. return ret;
  197. }
  198. int wl1271_acx_pd_threshold(struct wl1271 *wl)
  199. {
  200. struct acx_packet_detection *pd;
  201. int ret;
  202. wl1271_debug(DEBUG_ACX, "acx data pd threshold");
  203. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  204. if (!pd) {
  205. ret = -ENOMEM;
  206. goto out;
  207. }
  208. pd->threshold = cpu_to_le32(wl->conf.rx.packet_detection_threshold);
  209. ret = wl1271_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
  210. if (ret < 0) {
  211. wl1271_warning("failed to set pd threshold: %d", ret);
  212. goto out;
  213. }
  214. out:
  215. kfree(pd);
  216. return 0;
  217. }
  218. int wl1271_acx_slot(struct wl1271 *wl, enum acx_slot_type slot_time)
  219. {
  220. struct acx_slot *slot;
  221. int ret;
  222. wl1271_debug(DEBUG_ACX, "acx slot");
  223. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  224. if (!slot) {
  225. ret = -ENOMEM;
  226. goto out;
  227. }
  228. slot->wone_index = STATION_WONE_INDEX;
  229. slot->slot_time = slot_time;
  230. ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
  231. if (ret < 0) {
  232. wl1271_warning("failed to set slot time: %d", ret);
  233. goto out;
  234. }
  235. out:
  236. kfree(slot);
  237. return ret;
  238. }
  239. int wl1271_acx_group_address_tbl(struct wl1271 *wl, bool enable,
  240. void *mc_list, u32 mc_list_len)
  241. {
  242. struct acx_dot11_grp_addr_tbl *acx;
  243. int ret;
  244. wl1271_debug(DEBUG_ACX, "acx group address tbl");
  245. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  246. if (!acx) {
  247. ret = -ENOMEM;
  248. goto out;
  249. }
  250. /* MAC filtering */
  251. acx->enabled = enable;
  252. acx->num_groups = mc_list_len;
  253. memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
  254. ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
  255. acx, sizeof(*acx));
  256. if (ret < 0) {
  257. wl1271_warning("failed to set group addr table: %d", ret);
  258. goto out;
  259. }
  260. out:
  261. kfree(acx);
  262. return ret;
  263. }
  264. int wl1271_acx_service_period_timeout(struct wl1271 *wl)
  265. {
  266. struct acx_rx_timeout *rx_timeout;
  267. int ret;
  268. rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
  269. if (!rx_timeout) {
  270. ret = -ENOMEM;
  271. goto out;
  272. }
  273. wl1271_debug(DEBUG_ACX, "acx service period timeout");
  274. rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
  275. rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
  276. ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
  277. rx_timeout, sizeof(*rx_timeout));
  278. if (ret < 0) {
  279. wl1271_warning("failed to set service period timeout: %d",
  280. ret);
  281. goto out;
  282. }
  283. out:
  284. kfree(rx_timeout);
  285. return ret;
  286. }
  287. int wl1271_acx_rts_threshold(struct wl1271 *wl, u16 rts_threshold)
  288. {
  289. struct acx_rts_threshold *rts;
  290. int ret;
  291. wl1271_debug(DEBUG_ACX, "acx rts threshold");
  292. rts = kzalloc(sizeof(*rts), GFP_KERNEL);
  293. if (!rts) {
  294. ret = -ENOMEM;
  295. goto out;
  296. }
  297. rts->threshold = cpu_to_le16(rts_threshold);
  298. ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
  299. if (ret < 0) {
  300. wl1271_warning("failed to set rts threshold: %d", ret);
  301. goto out;
  302. }
  303. out:
  304. kfree(rts);
  305. return ret;
  306. }
  307. int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
  308. {
  309. struct acx_dco_itrim_params *dco;
  310. struct conf_itrim_settings *c = &wl->conf.itrim;
  311. int ret;
  312. wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
  313. dco = kzalloc(sizeof(*dco), GFP_KERNEL);
  314. if (!dco) {
  315. ret = -ENOMEM;
  316. goto out;
  317. }
  318. dco->enable = c->enable;
  319. dco->timeout = cpu_to_le32(c->timeout);
  320. ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
  321. dco, sizeof(*dco));
  322. if (ret < 0) {
  323. wl1271_warning("failed to set dco itrim parameters: %d", ret);
  324. goto out;
  325. }
  326. out:
  327. kfree(dco);
  328. return ret;
  329. }
  330. int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, bool enable_filter)
  331. {
  332. struct acx_beacon_filter_option *beacon_filter = NULL;
  333. int ret = 0;
  334. wl1271_debug(DEBUG_ACX, "acx beacon filter opt");
  335. if (enable_filter &&
  336. wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
  337. goto out;
  338. beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
  339. if (!beacon_filter) {
  340. ret = -ENOMEM;
  341. goto out;
  342. }
  343. beacon_filter->enable = enable_filter;
  344. /*
  345. * When set to zero, and the filter is enabled, beacons
  346. * without the unicast TIM bit set are dropped.
  347. */
  348. beacon_filter->max_num_beacons = 0;
  349. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
  350. beacon_filter, sizeof(*beacon_filter));
  351. if (ret < 0) {
  352. wl1271_warning("failed to set beacon filter opt: %d", ret);
  353. goto out;
  354. }
  355. out:
  356. kfree(beacon_filter);
  357. return ret;
  358. }
  359. int wl1271_acx_beacon_filter_table(struct wl1271 *wl)
  360. {
  361. struct acx_beacon_filter_ie_table *ie_table;
  362. int i, idx = 0;
  363. int ret;
  364. bool vendor_spec = false;
  365. wl1271_debug(DEBUG_ACX, "acx beacon filter table");
  366. ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
  367. if (!ie_table) {
  368. ret = -ENOMEM;
  369. goto out;
  370. }
  371. /* configure default beacon pass-through rules */
  372. ie_table->num_ie = 0;
  373. for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
  374. struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
  375. ie_table->table[idx++] = r->ie;
  376. ie_table->table[idx++] = r->rule;
  377. if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
  378. /* only one vendor specific ie allowed */
  379. if (vendor_spec)
  380. continue;
  381. /* for vendor specific rules configure the
  382. additional fields */
  383. memcpy(&(ie_table->table[idx]), r->oui,
  384. CONF_BCN_IE_OUI_LEN);
  385. idx += CONF_BCN_IE_OUI_LEN;
  386. ie_table->table[idx++] = r->type;
  387. memcpy(&(ie_table->table[idx]), r->version,
  388. CONF_BCN_IE_VER_LEN);
  389. idx += CONF_BCN_IE_VER_LEN;
  390. vendor_spec = true;
  391. }
  392. ie_table->num_ie++;
  393. }
  394. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
  395. ie_table, sizeof(*ie_table));
  396. if (ret < 0) {
  397. wl1271_warning("failed to set beacon filter table: %d", ret);
  398. goto out;
  399. }
  400. out:
  401. kfree(ie_table);
  402. return ret;
  403. }
  404. #define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
  405. int wl1271_acx_conn_monit_params(struct wl1271 *wl, bool enable)
  406. {
  407. struct acx_conn_monit_params *acx;
  408. u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
  409. u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
  410. int ret;
  411. wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
  412. enable ? "enabled" : "disabled");
  413. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  414. if (!acx) {
  415. ret = -ENOMEM;
  416. goto out;
  417. }
  418. if (enable) {
  419. threshold = wl->conf.conn.synch_fail_thold;
  420. timeout = wl->conf.conn.bss_lose_timeout;
  421. }
  422. acx->synch_fail_thold = cpu_to_le32(threshold);
  423. acx->bss_lose_timeout = cpu_to_le32(timeout);
  424. ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
  425. acx, sizeof(*acx));
  426. if (ret < 0) {
  427. wl1271_warning("failed to set connection monitor "
  428. "parameters: %d", ret);
  429. goto out;
  430. }
  431. out:
  432. kfree(acx);
  433. return ret;
  434. }
  435. int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
  436. {
  437. struct acx_bt_wlan_coex *pta;
  438. int ret;
  439. wl1271_debug(DEBUG_ACX, "acx sg enable");
  440. pta = kzalloc(sizeof(*pta), GFP_KERNEL);
  441. if (!pta) {
  442. ret = -ENOMEM;
  443. goto out;
  444. }
  445. if (enable)
  446. pta->enable = wl->conf.sg.state;
  447. else
  448. pta->enable = CONF_SG_DISABLE;
  449. ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
  450. if (ret < 0) {
  451. wl1271_warning("failed to set softgemini enable: %d", ret);
  452. goto out;
  453. }
  454. out:
  455. kfree(pta);
  456. return ret;
  457. }
  458. int wl1271_acx_sg_cfg(struct wl1271 *wl)
  459. {
  460. struct acx_bt_wlan_coex_param *param;
  461. struct conf_sg_settings *c = &wl->conf.sg;
  462. int i, ret;
  463. wl1271_debug(DEBUG_ACX, "acx sg cfg");
  464. param = kzalloc(sizeof(*param), GFP_KERNEL);
  465. if (!param) {
  466. ret = -ENOMEM;
  467. goto out;
  468. }
  469. /* BT-WLAN coext parameters */
  470. for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
  471. param->params[i] = cpu_to_le32(c->params[i]);
  472. param->param_idx = CONF_SG_PARAMS_ALL;
  473. ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
  474. if (ret < 0) {
  475. wl1271_warning("failed to set sg config: %d", ret);
  476. goto out;
  477. }
  478. out:
  479. kfree(param);
  480. return ret;
  481. }
  482. int wl1271_acx_cca_threshold(struct wl1271 *wl)
  483. {
  484. struct acx_energy_detection *detection;
  485. int ret;
  486. wl1271_debug(DEBUG_ACX, "acx cca threshold");
  487. detection = kzalloc(sizeof(*detection), GFP_KERNEL);
  488. if (!detection) {
  489. ret = -ENOMEM;
  490. goto out;
  491. }
  492. detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
  493. detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
  494. ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
  495. detection, sizeof(*detection));
  496. if (ret < 0) {
  497. wl1271_warning("failed to set cca threshold: %d", ret);
  498. return ret;
  499. }
  500. out:
  501. kfree(detection);
  502. return ret;
  503. }
  504. int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
  505. {
  506. struct acx_beacon_broadcast *bb;
  507. int ret;
  508. wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
  509. bb = kzalloc(sizeof(*bb), GFP_KERNEL);
  510. if (!bb) {
  511. ret = -ENOMEM;
  512. goto out;
  513. }
  514. bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
  515. bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
  516. bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
  517. bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
  518. ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
  519. if (ret < 0) {
  520. wl1271_warning("failed to set rx config: %d", ret);
  521. goto out;
  522. }
  523. out:
  524. kfree(bb);
  525. return ret;
  526. }
  527. int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
  528. {
  529. struct acx_aid *acx_aid;
  530. int ret;
  531. wl1271_debug(DEBUG_ACX, "acx aid");
  532. acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
  533. if (!acx_aid) {
  534. ret = -ENOMEM;
  535. goto out;
  536. }
  537. acx_aid->aid = cpu_to_le16(aid);
  538. ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
  539. if (ret < 0) {
  540. wl1271_warning("failed to set aid: %d", ret);
  541. goto out;
  542. }
  543. out:
  544. kfree(acx_aid);
  545. return ret;
  546. }
  547. int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
  548. {
  549. struct acx_event_mask *mask;
  550. int ret;
  551. wl1271_debug(DEBUG_ACX, "acx event mbox mask");
  552. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  553. if (!mask) {
  554. ret = -ENOMEM;
  555. goto out;
  556. }
  557. /* high event mask is unused */
  558. mask->high_event_mask = cpu_to_le32(0xffffffff);
  559. mask->event_mask = cpu_to_le32(event_mask);
  560. ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
  561. mask, sizeof(*mask));
  562. if (ret < 0) {
  563. wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
  564. goto out;
  565. }
  566. out:
  567. kfree(mask);
  568. return ret;
  569. }
  570. int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
  571. {
  572. struct acx_preamble *acx;
  573. int ret;
  574. wl1271_debug(DEBUG_ACX, "acx_set_preamble");
  575. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  576. if (!acx) {
  577. ret = -ENOMEM;
  578. goto out;
  579. }
  580. acx->preamble = preamble;
  581. ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
  582. if (ret < 0) {
  583. wl1271_warning("Setting of preamble failed: %d", ret);
  584. goto out;
  585. }
  586. out:
  587. kfree(acx);
  588. return ret;
  589. }
  590. int wl1271_acx_cts_protect(struct wl1271 *wl,
  591. enum acx_ctsprotect_type ctsprotect)
  592. {
  593. struct acx_ctsprotect *acx;
  594. int ret;
  595. wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
  596. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  597. if (!acx) {
  598. ret = -ENOMEM;
  599. goto out;
  600. }
  601. acx->ctsprotect = ctsprotect;
  602. ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
  603. if (ret < 0) {
  604. wl1271_warning("Setting of ctsprotect failed: %d", ret);
  605. goto out;
  606. }
  607. out:
  608. kfree(acx);
  609. return ret;
  610. }
  611. int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
  612. {
  613. int ret;
  614. wl1271_debug(DEBUG_ACX, "acx statistics");
  615. ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
  616. sizeof(*stats));
  617. if (ret < 0) {
  618. wl1271_warning("acx statistics failed: %d", ret);
  619. return -ENOMEM;
  620. }
  621. return 0;
  622. }
  623. int wl1271_acx_rate_policies(struct wl1271 *wl)
  624. {
  625. struct acx_rate_policy *acx;
  626. struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
  627. int idx = 0;
  628. int ret = 0;
  629. wl1271_debug(DEBUG_ACX, "acx rate policies");
  630. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  631. if (!acx) {
  632. ret = -ENOMEM;
  633. goto out;
  634. }
  635. /* configure one basic rate class */
  636. idx = ACX_TX_BASIC_RATE;
  637. acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate);
  638. acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
  639. acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
  640. acx->rate_class[idx].aflags = c->aflags;
  641. /* configure one AP supported rate class */
  642. idx = ACX_TX_AP_FULL_RATE;
  643. acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
  644. acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
  645. acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
  646. acx->rate_class[idx].aflags = c->aflags;
  647. acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
  648. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  649. if (ret < 0) {
  650. wl1271_warning("Setting of rate policies failed: %d", ret);
  651. goto out;
  652. }
  653. out:
  654. kfree(acx);
  655. return ret;
  656. }
  657. int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
  658. u8 aifsn, u16 txop)
  659. {
  660. struct acx_ac_cfg *acx;
  661. int ret = 0;
  662. wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
  663. "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
  664. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  665. if (!acx) {
  666. ret = -ENOMEM;
  667. goto out;
  668. }
  669. acx->ac = ac;
  670. acx->cw_min = cw_min;
  671. acx->cw_max = cpu_to_le16(cw_max);
  672. acx->aifsn = aifsn;
  673. acx->tx_op_limit = cpu_to_le16(txop);
  674. ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  675. if (ret < 0) {
  676. wl1271_warning("acx ac cfg failed: %d", ret);
  677. goto out;
  678. }
  679. out:
  680. kfree(acx);
  681. return ret;
  682. }
  683. int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
  684. u8 tsid, u8 ps_scheme, u8 ack_policy,
  685. u32 apsd_conf0, u32 apsd_conf1)
  686. {
  687. struct acx_tid_config *acx;
  688. int ret = 0;
  689. wl1271_debug(DEBUG_ACX, "acx tid config");
  690. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  691. if (!acx) {
  692. ret = -ENOMEM;
  693. goto out;
  694. }
  695. acx->queue_id = queue_id;
  696. acx->channel_type = channel_type;
  697. acx->tsid = tsid;
  698. acx->ps_scheme = ps_scheme;
  699. acx->ack_policy = ack_policy;
  700. acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
  701. acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
  702. ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  703. if (ret < 0) {
  704. wl1271_warning("Setting of tid config failed: %d", ret);
  705. goto out;
  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_bet_enable(struct wl1271 *wl, bool enable)
  831. {
  832. struct wl1271_acx_bet_enable *acx = NULL;
  833. int ret = 0;
  834. wl1271_debug(DEBUG_ACX, "acx bet enable");
  835. if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
  836. goto out;
  837. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  838. if (!acx) {
  839. ret = -ENOMEM;
  840. goto out;
  841. }
  842. acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
  843. acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
  844. ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
  845. if (ret < 0) {
  846. wl1271_warning("acx bet enable failed: %d", ret);
  847. goto out;
  848. }
  849. out:
  850. kfree(acx);
  851. return ret;
  852. }
  853. int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
  854. u8 version)
  855. {
  856. struct wl1271_acx_arp_filter *acx;
  857. int ret;
  858. wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
  859. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  860. if (!acx) {
  861. ret = -ENOMEM;
  862. goto out;
  863. }
  864. acx->version = version;
  865. acx->enable = enable;
  866. if (enable == true) {
  867. if (version == ACX_IPV4_VERSION)
  868. memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
  869. else if (version == ACX_IPV6_VERSION)
  870. memcpy(acx->address, address, sizeof(acx->address));
  871. else
  872. wl1271_error("Invalid IP version");
  873. }
  874. ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
  875. acx, sizeof(*acx));
  876. if (ret < 0) {
  877. wl1271_warning("failed to set arp ip filter: %d", ret);
  878. goto out;
  879. }
  880. out:
  881. kfree(acx);
  882. return ret;
  883. }
  884. int wl1271_acx_pm_config(struct wl1271 *wl)
  885. {
  886. struct wl1271_acx_pm_config *acx = NULL;
  887. struct conf_pm_config_settings *c = &wl->conf.pm_config;
  888. int ret = 0;
  889. wl1271_debug(DEBUG_ACX, "acx pm config");
  890. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  891. if (!acx) {
  892. ret = -ENOMEM;
  893. goto out;
  894. }
  895. acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
  896. acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
  897. ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
  898. if (ret < 0) {
  899. wl1271_warning("acx pm config failed: %d", ret);
  900. goto out;
  901. }
  902. out:
  903. kfree(acx);
  904. return ret;
  905. }
  906. int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
  907. {
  908. struct wl1271_acx_keep_alive_mode *acx = NULL;
  909. int ret = 0;
  910. wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
  911. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  912. if (!acx) {
  913. ret = -ENOMEM;
  914. goto out;
  915. }
  916. acx->enabled = enable;
  917. ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
  918. if (ret < 0) {
  919. wl1271_warning("acx keep alive mode failed: %d", ret);
  920. goto out;
  921. }
  922. out:
  923. kfree(acx);
  924. return ret;
  925. }
  926. int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
  927. {
  928. struct wl1271_acx_keep_alive_config *acx = NULL;
  929. int ret = 0;
  930. wl1271_debug(DEBUG_ACX, "acx keep alive config");
  931. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  932. if (!acx) {
  933. ret = -ENOMEM;
  934. goto out;
  935. }
  936. acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
  937. acx->index = index;
  938. acx->tpl_validation = tpl_valid;
  939. acx->trigger = ACX_KEEP_ALIVE_NO_TX;
  940. ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
  941. acx, sizeof(*acx));
  942. if (ret < 0) {
  943. wl1271_warning("acx keep alive config failed: %d", ret);
  944. goto out;
  945. }
  946. out:
  947. kfree(acx);
  948. return ret;
  949. }
  950. int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
  951. s16 thold, u8 hyst)
  952. {
  953. struct wl1271_acx_rssi_snr_trigger *acx = NULL;
  954. int ret = 0;
  955. wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
  956. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  957. if (!acx) {
  958. ret = -ENOMEM;
  959. goto out;
  960. }
  961. wl->last_rssi_event = -1;
  962. acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
  963. acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
  964. acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
  965. if (enable)
  966. acx->enable = WL1271_ACX_TRIG_ENABLE;
  967. else
  968. acx->enable = WL1271_ACX_TRIG_DISABLE;
  969. acx->index = WL1271_ACX_TRIG_IDX_RSSI;
  970. acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
  971. acx->threshold = cpu_to_le16(thold);
  972. acx->hysteresis = hyst;
  973. ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
  974. if (ret < 0) {
  975. wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
  976. goto out;
  977. }
  978. out:
  979. kfree(acx);
  980. return ret;
  981. }
  982. int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
  983. {
  984. struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
  985. struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
  986. int ret = 0;
  987. wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
  988. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  989. if (!acx) {
  990. ret = -ENOMEM;
  991. goto out;
  992. }
  993. acx->rssi_beacon = c->avg_weight_rssi_beacon;
  994. acx->rssi_data = c->avg_weight_rssi_data;
  995. acx->snr_beacon = c->avg_weight_snr_beacon;
  996. acx->snr_data = c->avg_weight_snr_data;
  997. ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
  998. if (ret < 0) {
  999. wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
  1000. goto out;
  1001. }
  1002. out:
  1003. kfree(acx);
  1004. return ret;
  1005. }