wl1271_acx.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287
  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, __be32 address)
  854. {
  855. struct wl1271_acx_arp_filter *acx;
  856. int ret;
  857. wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
  858. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  859. if (!acx) {
  860. ret = -ENOMEM;
  861. goto out;
  862. }
  863. acx->version = ACX_IPV4_VERSION;
  864. acx->enable = enable;
  865. if (enable == true)
  866. memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
  867. ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
  868. acx, sizeof(*acx));
  869. if (ret < 0) {
  870. wl1271_warning("failed to set arp ip filter: %d", ret);
  871. goto out;
  872. }
  873. out:
  874. kfree(acx);
  875. return ret;
  876. }
  877. int wl1271_acx_pm_config(struct wl1271 *wl)
  878. {
  879. struct wl1271_acx_pm_config *acx = NULL;
  880. struct conf_pm_config_settings *c = &wl->conf.pm_config;
  881. int ret = 0;
  882. wl1271_debug(DEBUG_ACX, "acx pm config");
  883. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  884. if (!acx) {
  885. ret = -ENOMEM;
  886. goto out;
  887. }
  888. acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
  889. acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
  890. ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
  891. if (ret < 0) {
  892. wl1271_warning("acx pm config failed: %d", ret);
  893. goto out;
  894. }
  895. out:
  896. kfree(acx);
  897. return ret;
  898. }
  899. int wl1271_acx_keep_alive_mode(struct wl1271 *wl, bool enable)
  900. {
  901. struct wl1271_acx_keep_alive_mode *acx = NULL;
  902. int ret = 0;
  903. wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
  904. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  905. if (!acx) {
  906. ret = -ENOMEM;
  907. goto out;
  908. }
  909. acx->enabled = enable;
  910. ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
  911. if (ret < 0) {
  912. wl1271_warning("acx keep alive mode failed: %d", ret);
  913. goto out;
  914. }
  915. out:
  916. kfree(acx);
  917. return ret;
  918. }
  919. int wl1271_acx_keep_alive_config(struct wl1271 *wl, u8 index, u8 tpl_valid)
  920. {
  921. struct wl1271_acx_keep_alive_config *acx = NULL;
  922. int ret = 0;
  923. wl1271_debug(DEBUG_ACX, "acx keep alive config");
  924. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  925. if (!acx) {
  926. ret = -ENOMEM;
  927. goto out;
  928. }
  929. acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
  930. acx->index = index;
  931. acx->tpl_validation = tpl_valid;
  932. acx->trigger = ACX_KEEP_ALIVE_NO_TX;
  933. ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
  934. acx, sizeof(*acx));
  935. if (ret < 0) {
  936. wl1271_warning("acx keep alive config failed: %d", ret);
  937. goto out;
  938. }
  939. out:
  940. kfree(acx);
  941. return ret;
  942. }
  943. int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, bool enable,
  944. s16 thold, u8 hyst)
  945. {
  946. struct wl1271_acx_rssi_snr_trigger *acx = NULL;
  947. int ret = 0;
  948. wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
  949. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  950. if (!acx) {
  951. ret = -ENOMEM;
  952. goto out;
  953. }
  954. wl->last_rssi_event = -1;
  955. acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
  956. acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
  957. acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
  958. if (enable)
  959. acx->enable = WL1271_ACX_TRIG_ENABLE;
  960. else
  961. acx->enable = WL1271_ACX_TRIG_DISABLE;
  962. acx->index = WL1271_ACX_TRIG_IDX_RSSI;
  963. acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
  964. acx->threshold = cpu_to_le16(thold);
  965. acx->hysteresis = hyst;
  966. ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
  967. if (ret < 0) {
  968. wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
  969. goto out;
  970. }
  971. out:
  972. kfree(acx);
  973. return ret;
  974. }
  975. int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl)
  976. {
  977. struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
  978. struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
  979. int ret = 0;
  980. wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
  981. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  982. if (!acx) {
  983. ret = -ENOMEM;
  984. goto out;
  985. }
  986. acx->rssi_beacon = c->avg_weight_rssi_beacon;
  987. acx->rssi_data = c->avg_weight_rssi_data;
  988. acx->snr_beacon = c->avg_weight_snr_beacon;
  989. acx->snr_data = c->avg_weight_snr_data;
  990. ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
  991. if (ret < 0) {
  992. wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
  993. goto out;
  994. }
  995. out:
  996. kfree(acx);
  997. return ret;
  998. }
  999. int wl1271_acx_tsf_info(struct wl1271 *wl, u64 *mactime)
  1000. {
  1001. struct wl1271_acx_fw_tsf_information *tsf_info;
  1002. int ret;
  1003. tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
  1004. if (!tsf_info) {
  1005. ret = -ENOMEM;
  1006. goto out;
  1007. }
  1008. ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO,
  1009. tsf_info, sizeof(*tsf_info));
  1010. if (ret < 0) {
  1011. wl1271_warning("acx tsf info interrogate failed");
  1012. goto out;
  1013. }
  1014. *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
  1015. ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
  1016. out:
  1017. kfree(tsf_info);
  1018. return ret;
  1019. }