wl1271_acx.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  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, bool enable)
  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. if (enable)
  437. pta->enable = wl->conf.sg.state;
  438. else
  439. pta->enable = CONF_SG_DISABLE;
  440. ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
  441. if (ret < 0) {
  442. wl1271_warning("failed to set softgemini enable: %d", ret);
  443. goto out;
  444. }
  445. out:
  446. kfree(pta);
  447. return ret;
  448. }
  449. int wl1271_acx_sg_cfg(struct wl1271 *wl)
  450. {
  451. struct acx_bt_wlan_coex_param *param;
  452. struct conf_sg_settings *c = &wl->conf.sg;
  453. int i, ret;
  454. wl1271_debug(DEBUG_ACX, "acx sg cfg");
  455. param = kzalloc(sizeof(*param), GFP_KERNEL);
  456. if (!param) {
  457. ret = -ENOMEM;
  458. goto out;
  459. }
  460. /* BT-WLAN coext parameters */
  461. for (i = 0; i < CONF_SG_PARAMS_MAX; i++)
  462. param->params[i] = c->params[i];
  463. param->param_idx = CONF_SG_PARAMS_ALL;
  464. ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
  465. if (ret < 0) {
  466. wl1271_warning("failed to set sg config: %d", ret);
  467. goto out;
  468. }
  469. out:
  470. kfree(param);
  471. return ret;
  472. }
  473. int wl1271_acx_cca_threshold(struct wl1271 *wl)
  474. {
  475. struct acx_energy_detection *detection;
  476. int ret;
  477. wl1271_debug(DEBUG_ACX, "acx cca threshold");
  478. detection = kzalloc(sizeof(*detection), GFP_KERNEL);
  479. if (!detection) {
  480. ret = -ENOMEM;
  481. goto out;
  482. }
  483. detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
  484. detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
  485. ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
  486. detection, sizeof(*detection));
  487. if (ret < 0) {
  488. wl1271_warning("failed to set cca threshold: %d", ret);
  489. return ret;
  490. }
  491. out:
  492. kfree(detection);
  493. return ret;
  494. }
  495. int wl1271_acx_bcn_dtim_options(struct wl1271 *wl)
  496. {
  497. struct acx_beacon_broadcast *bb;
  498. int ret;
  499. wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
  500. bb = kzalloc(sizeof(*bb), GFP_KERNEL);
  501. if (!bb) {
  502. ret = -ENOMEM;
  503. goto out;
  504. }
  505. bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
  506. bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
  507. bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
  508. bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
  509. ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
  510. if (ret < 0) {
  511. wl1271_warning("failed to set rx config: %d", ret);
  512. goto out;
  513. }
  514. out:
  515. kfree(bb);
  516. return ret;
  517. }
  518. int wl1271_acx_aid(struct wl1271 *wl, u16 aid)
  519. {
  520. struct acx_aid *acx_aid;
  521. int ret;
  522. wl1271_debug(DEBUG_ACX, "acx aid");
  523. acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
  524. if (!acx_aid) {
  525. ret = -ENOMEM;
  526. goto out;
  527. }
  528. acx_aid->aid = cpu_to_le16(aid);
  529. ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
  530. if (ret < 0) {
  531. wl1271_warning("failed to set aid: %d", ret);
  532. goto out;
  533. }
  534. out:
  535. kfree(acx_aid);
  536. return ret;
  537. }
  538. int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
  539. {
  540. struct acx_event_mask *mask;
  541. int ret;
  542. wl1271_debug(DEBUG_ACX, "acx event mbox mask");
  543. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  544. if (!mask) {
  545. ret = -ENOMEM;
  546. goto out;
  547. }
  548. /* high event mask is unused */
  549. mask->high_event_mask = cpu_to_le32(0xffffffff);
  550. mask->event_mask = cpu_to_le32(event_mask);
  551. ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
  552. mask, sizeof(*mask));
  553. if (ret < 0) {
  554. wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
  555. goto out;
  556. }
  557. out:
  558. kfree(mask);
  559. return ret;
  560. }
  561. int wl1271_acx_set_preamble(struct wl1271 *wl, enum acx_preamble_type preamble)
  562. {
  563. struct acx_preamble *acx;
  564. int ret;
  565. wl1271_debug(DEBUG_ACX, "acx_set_preamble");
  566. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  567. if (!acx) {
  568. ret = -ENOMEM;
  569. goto out;
  570. }
  571. acx->preamble = preamble;
  572. ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
  573. if (ret < 0) {
  574. wl1271_warning("Setting of preamble failed: %d", ret);
  575. goto out;
  576. }
  577. out:
  578. kfree(acx);
  579. return ret;
  580. }
  581. int wl1271_acx_cts_protect(struct wl1271 *wl,
  582. enum acx_ctsprotect_type ctsprotect)
  583. {
  584. struct acx_ctsprotect *acx;
  585. int ret;
  586. wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
  587. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  588. if (!acx) {
  589. ret = -ENOMEM;
  590. goto out;
  591. }
  592. acx->ctsprotect = ctsprotect;
  593. ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
  594. if (ret < 0) {
  595. wl1271_warning("Setting of ctsprotect failed: %d", ret);
  596. goto out;
  597. }
  598. out:
  599. kfree(acx);
  600. return ret;
  601. }
  602. int wl1271_acx_statistics(struct wl1271 *wl, struct acx_statistics *stats)
  603. {
  604. int ret;
  605. wl1271_debug(DEBUG_ACX, "acx statistics");
  606. ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
  607. sizeof(*stats));
  608. if (ret < 0) {
  609. wl1271_warning("acx statistics failed: %d", ret);
  610. return -ENOMEM;
  611. }
  612. return 0;
  613. }
  614. int wl1271_acx_rate_policies(struct wl1271 *wl)
  615. {
  616. struct acx_rate_policy *acx;
  617. struct conf_tx_rate_class *c = &wl->conf.tx.rc_conf;
  618. int idx = 0;
  619. int ret = 0;
  620. wl1271_debug(DEBUG_ACX, "acx rate policies");
  621. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  622. if (!acx) {
  623. ret = -ENOMEM;
  624. goto out;
  625. }
  626. /* configure one basic rate class */
  627. idx = ACX_TX_BASIC_RATE;
  628. acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->basic_rate_set);
  629. acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
  630. acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
  631. acx->rate_class[idx].aflags = c->aflags;
  632. /* configure one AP supported rate class */
  633. idx = ACX_TX_AP_FULL_RATE;
  634. acx->rate_class[idx].enabled_rates = cpu_to_le32(wl->rate_set);
  635. acx->rate_class[idx].short_retry_limit = c->short_retry_limit;
  636. acx->rate_class[idx].long_retry_limit = c->long_retry_limit;
  637. acx->rate_class[idx].aflags = c->aflags;
  638. acx->rate_class_cnt = cpu_to_le32(ACX_TX_RATE_POLICY_CNT);
  639. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  640. if (ret < 0) {
  641. wl1271_warning("Setting of rate policies failed: %d", ret);
  642. goto out;
  643. }
  644. out:
  645. kfree(acx);
  646. return ret;
  647. }
  648. int wl1271_acx_ac_cfg(struct wl1271 *wl, u8 ac, u8 cw_min, u16 cw_max,
  649. u8 aifsn, u16 txop)
  650. {
  651. struct acx_ac_cfg *acx;
  652. int ret = 0;
  653. wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
  654. "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
  655. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  656. if (!acx) {
  657. ret = -ENOMEM;
  658. goto out;
  659. }
  660. acx->ac = ac;
  661. acx->cw_min = cw_min;
  662. acx->cw_max = cpu_to_le16(cw_max);
  663. acx->aifsn = aifsn;
  664. acx->tx_op_limit = cpu_to_le16(txop);
  665. ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  666. if (ret < 0) {
  667. wl1271_warning("acx ac cfg failed: %d", ret);
  668. goto out;
  669. }
  670. out:
  671. kfree(acx);
  672. return ret;
  673. }
  674. int wl1271_acx_tid_cfg(struct wl1271 *wl, u8 queue_id, u8 channel_type,
  675. u8 tsid, u8 ps_scheme, u8 ack_policy,
  676. u32 apsd_conf0, u32 apsd_conf1)
  677. {
  678. struct acx_tid_config *acx;
  679. int ret = 0;
  680. wl1271_debug(DEBUG_ACX, "acx tid config");
  681. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  682. if (!acx) {
  683. ret = -ENOMEM;
  684. goto out;
  685. }
  686. acx->queue_id = queue_id;
  687. acx->channel_type = channel_type;
  688. acx->tsid = tsid;
  689. acx->ps_scheme = ps_scheme;
  690. acx->ack_policy = ack_policy;
  691. acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
  692. acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
  693. ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  694. if (ret < 0) {
  695. wl1271_warning("Setting of tid config failed: %d", ret);
  696. goto out;
  697. }
  698. out:
  699. kfree(acx);
  700. return ret;
  701. }
  702. int wl1271_acx_frag_threshold(struct wl1271 *wl)
  703. {
  704. struct acx_frag_threshold *acx;
  705. int ret = 0;
  706. wl1271_debug(DEBUG_ACX, "acx frag threshold");
  707. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  708. if (!acx) {
  709. ret = -ENOMEM;
  710. goto out;
  711. }
  712. acx->frag_threshold = cpu_to_le16(wl->conf.tx.frag_threshold);
  713. ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
  714. if (ret < 0) {
  715. wl1271_warning("Setting of frag threshold failed: %d", ret);
  716. goto out;
  717. }
  718. out:
  719. kfree(acx);
  720. return ret;
  721. }
  722. int wl1271_acx_tx_config_options(struct wl1271 *wl)
  723. {
  724. struct acx_tx_config_options *acx;
  725. int ret = 0;
  726. wl1271_debug(DEBUG_ACX, "acx tx config options");
  727. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  728. if (!acx) {
  729. ret = -ENOMEM;
  730. goto out;
  731. }
  732. acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
  733. acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
  734. ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
  735. if (ret < 0) {
  736. wl1271_warning("Setting of tx options failed: %d", ret);
  737. goto out;
  738. }
  739. out:
  740. kfree(acx);
  741. return ret;
  742. }
  743. int wl1271_acx_mem_cfg(struct wl1271 *wl)
  744. {
  745. struct wl1271_acx_config_memory *mem_conf;
  746. int ret;
  747. wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
  748. mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
  749. if (!mem_conf) {
  750. ret = -ENOMEM;
  751. goto out;
  752. }
  753. /* memory config */
  754. mem_conf->num_stations = DEFAULT_NUM_STATIONS;
  755. mem_conf->rx_mem_block_num = ACX_RX_MEM_BLOCKS;
  756. mem_conf->tx_min_mem_block_num = ACX_TX_MIN_MEM_BLOCKS;
  757. mem_conf->num_ssid_profiles = ACX_NUM_SSID_PROFILES;
  758. mem_conf->total_tx_descriptors = cpu_to_le32(ACX_TX_DESCRIPTORS);
  759. ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
  760. sizeof(*mem_conf));
  761. if (ret < 0) {
  762. wl1271_warning("wl1271 mem config failed: %d", ret);
  763. goto out;
  764. }
  765. out:
  766. kfree(mem_conf);
  767. return ret;
  768. }
  769. int wl1271_acx_init_mem_config(struct wl1271 *wl)
  770. {
  771. int ret;
  772. ret = wl1271_acx_mem_cfg(wl);
  773. if (ret < 0)
  774. return ret;
  775. wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
  776. GFP_KERNEL);
  777. if (!wl->target_mem_map) {
  778. wl1271_error("couldn't allocate target memory map");
  779. return -ENOMEM;
  780. }
  781. /* we now ask for the firmware built memory map */
  782. ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
  783. sizeof(struct wl1271_acx_mem_map));
  784. if (ret < 0) {
  785. wl1271_error("couldn't retrieve firmware memory map");
  786. kfree(wl->target_mem_map);
  787. wl->target_mem_map = NULL;
  788. return ret;
  789. }
  790. /* initialize TX block book keeping */
  791. wl->tx_blocks_available =
  792. le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
  793. wl1271_debug(DEBUG_TX, "available tx blocks: %d",
  794. wl->tx_blocks_available);
  795. return 0;
  796. }
  797. int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
  798. {
  799. struct wl1271_acx_rx_config_opt *rx_conf;
  800. int ret;
  801. wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
  802. rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
  803. if (!rx_conf) {
  804. ret = -ENOMEM;
  805. goto out;
  806. }
  807. rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
  808. rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
  809. rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
  810. rx_conf->queue_type = wl->conf.rx.queue_type;
  811. ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
  812. sizeof(*rx_conf));
  813. if (ret < 0) {
  814. wl1271_warning("wl1271 rx config opt failed: %d", ret);
  815. goto out;
  816. }
  817. out:
  818. kfree(rx_conf);
  819. return ret;
  820. }
  821. int wl1271_acx_bet_enable(struct wl1271 *wl, bool enable)
  822. {
  823. struct wl1271_acx_bet_enable *acx = NULL;
  824. int ret = 0;
  825. wl1271_debug(DEBUG_ACX, "acx bet enable");
  826. if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
  827. goto out;
  828. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  829. if (!acx) {
  830. ret = -ENOMEM;
  831. goto out;
  832. }
  833. acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
  834. acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
  835. ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
  836. if (ret < 0) {
  837. wl1271_warning("acx bet enable failed: %d", ret);
  838. goto out;
  839. }
  840. out:
  841. kfree(acx);
  842. return ret;
  843. }
  844. int wl1271_acx_arp_ip_filter(struct wl1271 *wl, bool enable, u8 *address,
  845. u8 version)
  846. {
  847. struct wl1271_acx_arp_filter *acx;
  848. int ret;
  849. wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
  850. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  851. if (!acx) {
  852. ret = -ENOMEM;
  853. goto out;
  854. }
  855. acx->version = version;
  856. acx->enable = enable;
  857. if (enable == true) {
  858. if (version == ACX_IPV4_VERSION)
  859. memcpy(acx->address, address, ACX_IPV4_ADDR_SIZE);
  860. else if (version == ACX_IPV6_VERSION)
  861. memcpy(acx->address, address, sizeof(acx->address));
  862. else
  863. wl1271_error("Invalid IP version");
  864. }
  865. ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
  866. acx, sizeof(*acx));
  867. if (ret < 0) {
  868. wl1271_warning("failed to set arp ip filter: %d", ret);
  869. goto out;
  870. }
  871. out:
  872. kfree(acx);
  873. return ret;
  874. }
  875. int wl1271_acx_pm_config(struct wl1271 *wl)
  876. {
  877. struct wl1271_acx_pm_config *acx = NULL;
  878. struct conf_pm_config_settings *c = &wl->conf.pm_config;
  879. int ret = 0;
  880. wl1271_debug(DEBUG_ACX, "acx pm config");
  881. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  882. if (!acx) {
  883. ret = -ENOMEM;
  884. goto out;
  885. }
  886. acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
  887. acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
  888. ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
  889. if (ret < 0) {
  890. wl1271_warning("acx pm config failed: %d", ret);
  891. goto out;
  892. }
  893. out:
  894. kfree(acx);
  895. return ret;
  896. }