acx.c 23 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include "acx.h"
  3. #include <linux/module.h>
  4. #include <linux/slab.h>
  5. #include "wl1251.h"
  6. #include "reg.h"
  7. #include "cmd.h"
  8. #include "ps.h"
  9. int wl1251_acx_frame_rates(struct wl1251 *wl, u8 ctrl_rate, u8 ctrl_mod,
  10. u8 mgt_rate, u8 mgt_mod)
  11. {
  12. struct acx_fw_gen_frame_rates *rates;
  13. int ret;
  14. wl1251_debug(DEBUG_ACX, "acx frame rates");
  15. rates = kzalloc(sizeof(*rates), GFP_KERNEL);
  16. if (!rates)
  17. return -ENOMEM;
  18. rates->tx_ctrl_frame_rate = ctrl_rate;
  19. rates->tx_ctrl_frame_mod = ctrl_mod;
  20. rates->tx_mgt_frame_rate = mgt_rate;
  21. rates->tx_mgt_frame_mod = mgt_mod;
  22. ret = wl1251_cmd_configure(wl, ACX_FW_GEN_FRAME_RATES,
  23. rates, sizeof(*rates));
  24. if (ret < 0) {
  25. wl1251_error("Failed to set FW rates and modulation");
  26. goto out;
  27. }
  28. out:
  29. kfree(rates);
  30. return ret;
  31. }
  32. int wl1251_acx_station_id(struct wl1251 *wl)
  33. {
  34. struct acx_dot11_station_id *mac;
  35. int ret, i;
  36. wl1251_debug(DEBUG_ACX, "acx dot11_station_id");
  37. mac = kzalloc(sizeof(*mac), GFP_KERNEL);
  38. if (!mac)
  39. return -ENOMEM;
  40. for (i = 0; i < ETH_ALEN; i++)
  41. mac->mac[i] = wl->mac_addr[ETH_ALEN - 1 - i];
  42. ret = wl1251_cmd_configure(wl, DOT11_STATION_ID, mac, sizeof(*mac));
  43. kfree(mac);
  44. return ret;
  45. }
  46. int wl1251_acx_default_key(struct wl1251 *wl, u8 key_id)
  47. {
  48. struct acx_dot11_default_key *default_key;
  49. int ret;
  50. wl1251_debug(DEBUG_ACX, "acx dot11_default_key (%d)", key_id);
  51. default_key = kzalloc(sizeof(*default_key), GFP_KERNEL);
  52. if (!default_key)
  53. return -ENOMEM;
  54. default_key->id = key_id;
  55. ret = wl1251_cmd_configure(wl, DOT11_DEFAULT_KEY,
  56. default_key, sizeof(*default_key));
  57. if (ret < 0) {
  58. wl1251_error("Couldn't set default key");
  59. goto out;
  60. }
  61. wl->default_key = key_id;
  62. out:
  63. kfree(default_key);
  64. return ret;
  65. }
  66. int wl1251_acx_wake_up_conditions(struct wl1251 *wl, u8 wake_up_event,
  67. u8 listen_interval)
  68. {
  69. struct acx_wake_up_condition *wake_up;
  70. int ret;
  71. wl1251_debug(DEBUG_ACX, "acx wake up conditions");
  72. wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
  73. if (!wake_up)
  74. return -ENOMEM;
  75. wake_up->wake_up_event = wake_up_event;
  76. wake_up->listen_interval = listen_interval;
  77. ret = wl1251_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
  78. wake_up, sizeof(*wake_up));
  79. if (ret < 0) {
  80. wl1251_warning("could not set wake up conditions: %d", ret);
  81. goto out;
  82. }
  83. out:
  84. kfree(wake_up);
  85. return ret;
  86. }
  87. int wl1251_acx_sleep_auth(struct wl1251 *wl, u8 sleep_auth)
  88. {
  89. struct acx_sleep_auth *auth;
  90. int ret;
  91. wl1251_debug(DEBUG_ACX, "acx sleep auth");
  92. auth = kzalloc(sizeof(*auth), GFP_KERNEL);
  93. if (!auth)
  94. return -ENOMEM;
  95. auth->sleep_auth = sleep_auth;
  96. ret = wl1251_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
  97. kfree(auth);
  98. return ret;
  99. }
  100. int wl1251_acx_fw_version(struct wl1251 *wl, char *buf, size_t len)
  101. {
  102. struct acx_revision *rev;
  103. int ret;
  104. wl1251_debug(DEBUG_ACX, "acx fw rev");
  105. rev = kzalloc(sizeof(*rev), GFP_KERNEL);
  106. if (!rev)
  107. return -ENOMEM;
  108. ret = wl1251_cmd_interrogate(wl, ACX_FW_REV, rev, sizeof(*rev));
  109. if (ret < 0) {
  110. wl1251_warning("ACX_FW_REV interrogate failed");
  111. goto out;
  112. }
  113. /* be careful with the buffer sizes */
  114. strncpy(buf, rev->fw_version, min(len, sizeof(rev->fw_version)));
  115. /*
  116. * if the firmware version string is exactly
  117. * sizeof(rev->fw_version) long or fw_len is less than
  118. * sizeof(rev->fw_version) it won't be null terminated
  119. */
  120. buf[min(len, sizeof(rev->fw_version)) - 1] = '\0';
  121. out:
  122. kfree(rev);
  123. return ret;
  124. }
  125. int wl1251_acx_tx_power(struct wl1251 *wl, int power)
  126. {
  127. struct acx_current_tx_power *acx;
  128. int ret;
  129. wl1251_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr");
  130. if (power < 0 || power > 25)
  131. return -EINVAL;
  132. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  133. if (!acx)
  134. return -ENOMEM;
  135. acx->current_tx_power = power * 10;
  136. ret = wl1251_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
  137. if (ret < 0) {
  138. wl1251_warning("configure of tx power failed: %d", ret);
  139. goto out;
  140. }
  141. out:
  142. kfree(acx);
  143. return ret;
  144. }
  145. int wl1251_acx_feature_cfg(struct wl1251 *wl, u32 data_flow_options)
  146. {
  147. struct acx_feature_config *feature;
  148. int ret;
  149. wl1251_debug(DEBUG_ACX, "acx feature cfg");
  150. feature = kzalloc(sizeof(*feature), GFP_KERNEL);
  151. if (!feature)
  152. return -ENOMEM;
  153. /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE can be set */
  154. feature->data_flow_options = data_flow_options;
  155. feature->options = 0;
  156. ret = wl1251_cmd_configure(wl, ACX_FEATURE_CFG,
  157. feature, sizeof(*feature));
  158. if (ret < 0) {
  159. wl1251_error("Couldn't set HW encryption");
  160. goto out;
  161. }
  162. out:
  163. kfree(feature);
  164. return ret;
  165. }
  166. int wl1251_acx_mem_map(struct wl1251 *wl, struct acx_header *mem_map,
  167. size_t len)
  168. {
  169. int ret;
  170. wl1251_debug(DEBUG_ACX, "acx mem map");
  171. ret = wl1251_cmd_interrogate(wl, ACX_MEM_MAP, mem_map, len);
  172. if (ret < 0)
  173. return ret;
  174. return 0;
  175. }
  176. int wl1251_acx_data_path_params(struct wl1251 *wl,
  177. struct acx_data_path_params_resp *resp)
  178. {
  179. struct acx_data_path_params *params;
  180. int ret;
  181. wl1251_debug(DEBUG_ACX, "acx data path params");
  182. params = kzalloc(sizeof(*params), GFP_KERNEL);
  183. if (!params)
  184. return -ENOMEM;
  185. params->rx_packet_ring_chunk_size = DP_RX_PACKET_RING_CHUNK_SIZE;
  186. params->tx_packet_ring_chunk_size = DP_TX_PACKET_RING_CHUNK_SIZE;
  187. params->rx_packet_ring_chunk_num = DP_RX_PACKET_RING_CHUNK_NUM;
  188. params->tx_packet_ring_chunk_num = DP_TX_PACKET_RING_CHUNK_NUM;
  189. params->tx_complete_threshold = 1;
  190. params->tx_complete_ring_depth = FW_TX_CMPLT_BLOCK_SIZE;
  191. params->tx_complete_timeout = DP_TX_COMPLETE_TIME_OUT;
  192. ret = wl1251_cmd_configure(wl, ACX_DATA_PATH_PARAMS,
  193. params, sizeof(*params));
  194. if (ret < 0)
  195. goto out;
  196. /* FIXME: shouldn't this be ACX_DATA_PATH_RESP_PARAMS? */
  197. ret = wl1251_cmd_interrogate(wl, ACX_DATA_PATH_PARAMS,
  198. resp, sizeof(*resp));
  199. if (ret < 0) {
  200. wl1251_warning("failed to read data path parameters: %d", ret);
  201. goto out;
  202. } else if (resp->header.cmd.status != CMD_STATUS_SUCCESS) {
  203. wl1251_warning("data path parameter acx status failed");
  204. ret = -EIO;
  205. goto out;
  206. }
  207. out:
  208. kfree(params);
  209. return ret;
  210. }
  211. int wl1251_acx_rx_msdu_life_time(struct wl1251 *wl, u32 life_time)
  212. {
  213. struct acx_rx_msdu_lifetime *acx;
  214. int ret;
  215. wl1251_debug(DEBUG_ACX, "acx rx msdu life time");
  216. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  217. if (!acx)
  218. return -ENOMEM;
  219. acx->lifetime = life_time;
  220. ret = wl1251_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
  221. acx, sizeof(*acx));
  222. if (ret < 0) {
  223. wl1251_warning("failed to set rx msdu life time: %d", ret);
  224. goto out;
  225. }
  226. out:
  227. kfree(acx);
  228. return ret;
  229. }
  230. int wl1251_acx_rx_config(struct wl1251 *wl, u32 config, u32 filter)
  231. {
  232. struct acx_rx_config *rx_config;
  233. int ret;
  234. wl1251_debug(DEBUG_ACX, "acx rx config");
  235. rx_config = kzalloc(sizeof(*rx_config), GFP_KERNEL);
  236. if (!rx_config)
  237. return -ENOMEM;
  238. rx_config->config_options = config;
  239. rx_config->filter_options = filter;
  240. ret = wl1251_cmd_configure(wl, ACX_RX_CFG,
  241. rx_config, sizeof(*rx_config));
  242. if (ret < 0) {
  243. wl1251_warning("failed to set rx config: %d", ret);
  244. goto out;
  245. }
  246. out:
  247. kfree(rx_config);
  248. return ret;
  249. }
  250. int wl1251_acx_pd_threshold(struct wl1251 *wl)
  251. {
  252. struct acx_packet_detection *pd;
  253. int ret;
  254. wl1251_debug(DEBUG_ACX, "acx data pd threshold");
  255. pd = kzalloc(sizeof(*pd), GFP_KERNEL);
  256. if (!pd)
  257. return -ENOMEM;
  258. /* FIXME: threshold value not set */
  259. ret = wl1251_cmd_configure(wl, ACX_PD_THRESHOLD, pd, sizeof(*pd));
  260. if (ret < 0) {
  261. wl1251_warning("failed to set pd threshold: %d", ret);
  262. goto out;
  263. }
  264. out:
  265. kfree(pd);
  266. return ret;
  267. }
  268. int wl1251_acx_slot(struct wl1251 *wl, enum acx_slot_type slot_time)
  269. {
  270. struct acx_slot *slot;
  271. int ret;
  272. wl1251_debug(DEBUG_ACX, "acx slot");
  273. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  274. if (!slot)
  275. return -ENOMEM;
  276. slot->wone_index = STATION_WONE_INDEX;
  277. slot->slot_time = slot_time;
  278. ret = wl1251_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
  279. if (ret < 0) {
  280. wl1251_warning("failed to set slot time: %d", ret);
  281. goto out;
  282. }
  283. out:
  284. kfree(slot);
  285. return ret;
  286. }
  287. int wl1251_acx_group_address_tbl(struct wl1251 *wl, bool enable,
  288. void *mc_list, u32 mc_list_len)
  289. {
  290. struct acx_dot11_grp_addr_tbl *acx;
  291. int ret;
  292. wl1251_debug(DEBUG_ACX, "acx group address tbl");
  293. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  294. if (!acx)
  295. return -ENOMEM;
  296. /* MAC filtering */
  297. acx->enabled = enable;
  298. acx->num_groups = mc_list_len;
  299. memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
  300. ret = wl1251_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
  301. acx, sizeof(*acx));
  302. if (ret < 0) {
  303. wl1251_warning("failed to set group addr table: %d", ret);
  304. goto out;
  305. }
  306. out:
  307. kfree(acx);
  308. return ret;
  309. }
  310. int wl1251_acx_service_period_timeout(struct wl1251 *wl)
  311. {
  312. struct acx_rx_timeout *rx_timeout;
  313. int ret;
  314. rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
  315. if (!rx_timeout)
  316. return -ENOMEM;
  317. wl1251_debug(DEBUG_ACX, "acx service period timeout");
  318. rx_timeout->ps_poll_timeout = RX_TIMEOUT_PS_POLL_DEF;
  319. rx_timeout->upsd_timeout = RX_TIMEOUT_UPSD_DEF;
  320. ret = wl1251_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
  321. rx_timeout, sizeof(*rx_timeout));
  322. if (ret < 0) {
  323. wl1251_warning("failed to set service period timeout: %d",
  324. ret);
  325. goto out;
  326. }
  327. out:
  328. kfree(rx_timeout);
  329. return ret;
  330. }
  331. int wl1251_acx_rts_threshold(struct wl1251 *wl, u16 rts_threshold)
  332. {
  333. struct acx_rts_threshold *rts;
  334. int ret;
  335. wl1251_debug(DEBUG_ACX, "acx rts threshold");
  336. rts = kzalloc(sizeof(*rts), GFP_KERNEL);
  337. if (!rts)
  338. return -ENOMEM;
  339. rts->threshold = rts_threshold;
  340. ret = wl1251_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
  341. if (ret < 0) {
  342. wl1251_warning("failed to set rts threshold: %d", ret);
  343. goto out;
  344. }
  345. out:
  346. kfree(rts);
  347. return ret;
  348. }
  349. int wl1251_acx_beacon_filter_opt(struct wl1251 *wl, bool enable_filter)
  350. {
  351. struct acx_beacon_filter_option *beacon_filter;
  352. int ret;
  353. wl1251_debug(DEBUG_ACX, "acx beacon filter opt");
  354. beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
  355. if (!beacon_filter)
  356. return -ENOMEM;
  357. beacon_filter->enable = enable_filter;
  358. beacon_filter->max_num_beacons = 0;
  359. ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
  360. beacon_filter, sizeof(*beacon_filter));
  361. if (ret < 0) {
  362. wl1251_warning("failed to set beacon filter opt: %d", ret);
  363. goto out;
  364. }
  365. out:
  366. kfree(beacon_filter);
  367. return ret;
  368. }
  369. int wl1251_acx_beacon_filter_table(struct wl1251 *wl)
  370. {
  371. struct acx_beacon_filter_ie_table *ie_table;
  372. int idx = 0;
  373. int ret;
  374. wl1251_debug(DEBUG_ACX, "acx beacon filter table");
  375. ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
  376. if (!ie_table)
  377. return -ENOMEM;
  378. /* configure default beacon pass-through rules */
  379. ie_table->num_ie = 1;
  380. ie_table->table[idx++] = BEACON_FILTER_IE_ID_CHANNEL_SWITCH_ANN;
  381. ie_table->table[idx++] = BEACON_RULE_PASS_ON_APPEARANCE;
  382. ret = wl1251_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
  383. ie_table, sizeof(*ie_table));
  384. if (ret < 0) {
  385. wl1251_warning("failed to set beacon filter table: %d", ret);
  386. goto out;
  387. }
  388. out:
  389. kfree(ie_table);
  390. return ret;
  391. }
  392. int wl1251_acx_conn_monit_params(struct wl1251 *wl)
  393. {
  394. struct acx_conn_monit_params *acx;
  395. int ret;
  396. wl1251_debug(DEBUG_ACX, "acx connection monitor parameters");
  397. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  398. if (!acx)
  399. return -ENOMEM;
  400. acx->synch_fail_thold = SYNCH_FAIL_DEFAULT_THRESHOLD;
  401. acx->bss_lose_timeout = NO_BEACON_DEFAULT_TIMEOUT;
  402. ret = wl1251_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
  403. acx, sizeof(*acx));
  404. if (ret < 0) {
  405. wl1251_warning("failed to set connection monitor "
  406. "parameters: %d", ret);
  407. goto out;
  408. }
  409. out:
  410. kfree(acx);
  411. return ret;
  412. }
  413. int wl1251_acx_sg_enable(struct wl1251 *wl)
  414. {
  415. struct acx_bt_wlan_coex *pta;
  416. int ret;
  417. wl1251_debug(DEBUG_ACX, "acx sg enable");
  418. pta = kzalloc(sizeof(*pta), GFP_KERNEL);
  419. if (!pta)
  420. return -ENOMEM;
  421. pta->enable = SG_ENABLE;
  422. ret = wl1251_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
  423. if (ret < 0) {
  424. wl1251_warning("failed to set softgemini enable: %d", ret);
  425. goto out;
  426. }
  427. out:
  428. kfree(pta);
  429. return ret;
  430. }
  431. int wl1251_acx_sg_cfg(struct wl1251 *wl)
  432. {
  433. struct acx_bt_wlan_coex_param *param;
  434. int ret;
  435. wl1251_debug(DEBUG_ACX, "acx sg cfg");
  436. param = kzalloc(sizeof(*param), GFP_KERNEL);
  437. if (!param)
  438. return -ENOMEM;
  439. /* BT-WLAN coext parameters */
  440. param->min_rate = RATE_INDEX_24MBPS;
  441. param->bt_hp_max_time = PTA_BT_HP_MAXTIME_DEF;
  442. param->wlan_hp_max_time = PTA_WLAN_HP_MAX_TIME_DEF;
  443. param->sense_disable_timer = PTA_SENSE_DISABLE_TIMER_DEF;
  444. param->rx_time_bt_hp = PTA_PROTECTIVE_RX_TIME_DEF;
  445. param->tx_time_bt_hp = PTA_PROTECTIVE_TX_TIME_DEF;
  446. param->rx_time_bt_hp_fast = PTA_PROTECTIVE_RX_TIME_FAST_DEF;
  447. param->tx_time_bt_hp_fast = PTA_PROTECTIVE_TX_TIME_FAST_DEF;
  448. param->wlan_cycle_fast = PTA_CYCLE_TIME_FAST_DEF;
  449. param->bt_anti_starvation_period = PTA_ANTI_STARVE_PERIOD_DEF;
  450. param->next_bt_lp_packet = PTA_TIMEOUT_NEXT_BT_LP_PACKET_DEF;
  451. param->wake_up_beacon = PTA_TIME_BEFORE_BEACON_DEF;
  452. param->hp_dm_max_guard_time = PTA_HPDM_MAX_TIME_DEF;
  453. param->next_wlan_packet = PTA_TIME_OUT_NEXT_WLAN_DEF;
  454. param->antenna_type = PTA_ANTENNA_TYPE_DEF;
  455. param->signal_type = PTA_SIGNALING_TYPE_DEF;
  456. param->afh_leverage_on = PTA_AFH_LEVERAGE_ON_DEF;
  457. param->quiet_cycle_num = PTA_NUMBER_QUIET_CYCLE_DEF;
  458. param->max_cts = PTA_MAX_NUM_CTS_DEF;
  459. param->wlan_packets_num = PTA_NUMBER_OF_WLAN_PACKETS_DEF;
  460. param->bt_packets_num = PTA_NUMBER_OF_BT_PACKETS_DEF;
  461. param->missed_rx_avalanche = PTA_RX_FOR_AVALANCHE_DEF;
  462. param->wlan_elp_hp = PTA_ELP_HP_DEF;
  463. param->bt_anti_starvation_cycles = PTA_ANTI_STARVE_NUM_CYCLE_DEF;
  464. param->ack_mode_dual_ant = PTA_ACK_MODE_DEF;
  465. param->pa_sd_enable = PTA_ALLOW_PA_SD_DEF;
  466. param->pta_auto_mode_enable = PTA_AUTO_MODE_NO_CTS_DEF;
  467. param->bt_hp_respected_num = PTA_BT_HP_RESPECTED_DEF;
  468. ret = wl1251_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
  469. if (ret < 0) {
  470. wl1251_warning("failed to set sg config: %d", ret);
  471. goto out;
  472. }
  473. out:
  474. kfree(param);
  475. return ret;
  476. }
  477. int wl1251_acx_cca_threshold(struct wl1251 *wl)
  478. {
  479. struct acx_energy_detection *detection;
  480. int ret;
  481. wl1251_debug(DEBUG_ACX, "acx cca threshold");
  482. detection = kzalloc(sizeof(*detection), GFP_KERNEL);
  483. if (!detection)
  484. return -ENOMEM;
  485. detection->rx_cca_threshold = CCA_THRSH_DISABLE_ENERGY_D;
  486. detection->tx_energy_detection = 0;
  487. ret = wl1251_cmd_configure(wl, ACX_CCA_THRESHOLD,
  488. detection, sizeof(*detection));
  489. if (ret < 0)
  490. wl1251_warning("failed to set cca threshold: %d", ret);
  491. kfree(detection);
  492. return ret;
  493. }
  494. int wl1251_acx_bcn_dtim_options(struct wl1251 *wl)
  495. {
  496. struct acx_beacon_broadcast *bb;
  497. int ret;
  498. wl1251_debug(DEBUG_ACX, "acx bcn dtim options");
  499. bb = kzalloc(sizeof(*bb), GFP_KERNEL);
  500. if (!bb)
  501. return -ENOMEM;
  502. bb->beacon_rx_timeout = BCN_RX_TIMEOUT_DEF_VALUE;
  503. bb->broadcast_timeout = BROADCAST_RX_TIMEOUT_DEF_VALUE;
  504. bb->rx_broadcast_in_ps = RX_BROADCAST_IN_PS_DEF_VALUE;
  505. bb->ps_poll_threshold = CONSECUTIVE_PS_POLL_FAILURE_DEF;
  506. ret = wl1251_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
  507. if (ret < 0) {
  508. wl1251_warning("failed to set rx config: %d", ret);
  509. goto out;
  510. }
  511. out:
  512. kfree(bb);
  513. return ret;
  514. }
  515. int wl1251_acx_aid(struct wl1251 *wl, u16 aid)
  516. {
  517. struct acx_aid *acx_aid;
  518. int ret;
  519. wl1251_debug(DEBUG_ACX, "acx aid");
  520. acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
  521. if (!acx_aid)
  522. return -ENOMEM;
  523. acx_aid->aid = aid;
  524. ret = wl1251_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
  525. if (ret < 0) {
  526. wl1251_warning("failed to set aid: %d", ret);
  527. goto out;
  528. }
  529. out:
  530. kfree(acx_aid);
  531. return ret;
  532. }
  533. int wl1251_acx_event_mbox_mask(struct wl1251 *wl, u32 event_mask)
  534. {
  535. struct acx_event_mask *mask;
  536. int ret;
  537. wl1251_debug(DEBUG_ACX, "acx event mbox mask");
  538. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  539. if (!mask)
  540. return -ENOMEM;
  541. /* high event mask is unused */
  542. mask->high_event_mask = 0xffffffff;
  543. mask->event_mask = event_mask;
  544. ret = wl1251_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
  545. mask, sizeof(*mask));
  546. if (ret < 0) {
  547. wl1251_warning("failed to set acx_event_mbox_mask: %d", ret);
  548. goto out;
  549. }
  550. out:
  551. kfree(mask);
  552. return ret;
  553. }
  554. int wl1251_acx_low_rssi(struct wl1251 *wl, s8 threshold, u8 weight,
  555. u8 depth, enum wl1251_acx_low_rssi_type type)
  556. {
  557. struct acx_low_rssi *rssi;
  558. int ret;
  559. wl1251_debug(DEBUG_ACX, "acx low rssi");
  560. rssi = kzalloc(sizeof(*rssi), GFP_KERNEL);
  561. if (!rssi)
  562. return -ENOMEM;
  563. rssi->threshold = threshold;
  564. rssi->weight = weight;
  565. rssi->depth = depth;
  566. rssi->type = type;
  567. ret = wl1251_cmd_configure(wl, ACX_LOW_RSSI, rssi, sizeof(*rssi));
  568. if (ret < 0)
  569. wl1251_warning("failed to set low rssi threshold: %d", ret);
  570. kfree(rssi);
  571. return ret;
  572. }
  573. int wl1251_acx_set_preamble(struct wl1251 *wl, enum acx_preamble_type preamble)
  574. {
  575. struct acx_preamble *acx;
  576. int ret;
  577. wl1251_debug(DEBUG_ACX, "acx_set_preamble");
  578. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  579. if (!acx)
  580. return -ENOMEM;
  581. acx->preamble = preamble;
  582. ret = wl1251_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
  583. if (ret < 0) {
  584. wl1251_warning("Setting of preamble failed: %d", ret);
  585. goto out;
  586. }
  587. out:
  588. kfree(acx);
  589. return ret;
  590. }
  591. int wl1251_acx_cts_protect(struct wl1251 *wl,
  592. enum acx_ctsprotect_type ctsprotect)
  593. {
  594. struct acx_ctsprotect *acx;
  595. int ret;
  596. wl1251_debug(DEBUG_ACX, "acx_set_ctsprotect");
  597. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  598. if (!acx)
  599. return -ENOMEM;
  600. acx->ctsprotect = ctsprotect;
  601. ret = wl1251_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
  602. if (ret < 0) {
  603. wl1251_warning("Setting of ctsprotect failed: %d", ret);
  604. goto out;
  605. }
  606. out:
  607. kfree(acx);
  608. return ret;
  609. }
  610. int wl1251_acx_tsf_info(struct wl1251 *wl, u64 *mactime)
  611. {
  612. struct acx_tsf_info *tsf_info;
  613. int ret;
  614. tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
  615. if (!tsf_info)
  616. return -ENOMEM;
  617. ret = wl1251_cmd_interrogate(wl, ACX_TSF_INFO,
  618. tsf_info, sizeof(*tsf_info));
  619. if (ret < 0) {
  620. wl1251_warning("ACX_FW_REV interrogate failed");
  621. goto out;
  622. }
  623. *mactime = tsf_info->current_tsf_lsb |
  624. ((u64)tsf_info->current_tsf_msb << 32);
  625. out:
  626. kfree(tsf_info);
  627. return ret;
  628. }
  629. int wl1251_acx_statistics(struct wl1251 *wl, struct acx_statistics *stats)
  630. {
  631. int ret;
  632. wl1251_debug(DEBUG_ACX, "acx statistics");
  633. ret = wl1251_cmd_interrogate(wl, ACX_STATISTICS, stats,
  634. sizeof(*stats));
  635. if (ret < 0) {
  636. wl1251_warning("acx statistics failed: %d", ret);
  637. return -ENOMEM;
  638. }
  639. return 0;
  640. }
  641. int wl1251_acx_rate_policies(struct wl1251 *wl)
  642. {
  643. struct acx_rate_policy *acx;
  644. int ret = 0;
  645. wl1251_debug(DEBUG_ACX, "acx rate policies");
  646. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  647. if (!acx)
  648. return -ENOMEM;
  649. /* configure one default (one-size-fits-all) rate class */
  650. acx->rate_class_cnt = 2;
  651. acx->rate_class[0].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
  652. acx->rate_class[0].short_retry_limit = ACX_RATE_RETRY_LIMIT;
  653. acx->rate_class[0].long_retry_limit = ACX_RATE_RETRY_LIMIT;
  654. acx->rate_class[0].aflags = 0;
  655. /* no-retry rate class */
  656. acx->rate_class[1].enabled_rates = ACX_RATE_MASK_UNSPECIFIED;
  657. acx->rate_class[1].short_retry_limit = 0;
  658. acx->rate_class[1].long_retry_limit = 0;
  659. acx->rate_class[1].aflags = 0;
  660. ret = wl1251_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  661. if (ret < 0) {
  662. wl1251_warning("Setting of rate policies failed: %d", ret);
  663. goto out;
  664. }
  665. out:
  666. kfree(acx);
  667. return ret;
  668. }
  669. int wl1251_acx_mem_cfg(struct wl1251 *wl)
  670. {
  671. struct wl1251_acx_config_memory *mem_conf;
  672. int ret, i;
  673. wl1251_debug(DEBUG_ACX, "acx mem cfg");
  674. mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
  675. if (!mem_conf)
  676. return -ENOMEM;
  677. /* memory config */
  678. mem_conf->mem_config.num_stations = cpu_to_le16(DEFAULT_NUM_STATIONS);
  679. mem_conf->mem_config.rx_mem_block_num = 35;
  680. mem_conf->mem_config.tx_min_mem_block_num = 64;
  681. mem_conf->mem_config.num_tx_queues = MAX_TX_QUEUES;
  682. mem_conf->mem_config.host_if_options = HOSTIF_PKT_RING;
  683. mem_conf->mem_config.num_ssid_profiles = 1;
  684. mem_conf->mem_config.debug_buffer_size =
  685. cpu_to_le16(TRACE_BUFFER_MAX_SIZE);
  686. /* RX queue config */
  687. mem_conf->rx_queue_config.dma_address = 0;
  688. mem_conf->rx_queue_config.num_descs = ACX_RX_DESC_DEF;
  689. mem_conf->rx_queue_config.priority = DEFAULT_RXQ_PRIORITY;
  690. mem_conf->rx_queue_config.type = DEFAULT_RXQ_TYPE;
  691. /* TX queue config */
  692. for (i = 0; i < MAX_TX_QUEUES; i++) {
  693. mem_conf->tx_queue_config[i].num_descs = ACX_TX_DESC_DEF;
  694. mem_conf->tx_queue_config[i].attributes = i;
  695. }
  696. ret = wl1251_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
  697. sizeof(*mem_conf));
  698. if (ret < 0) {
  699. wl1251_warning("wl1251 mem config failed: %d", ret);
  700. goto out;
  701. }
  702. out:
  703. kfree(mem_conf);
  704. return ret;
  705. }
  706. int wl1251_acx_wr_tbtt_and_dtim(struct wl1251 *wl, u16 tbtt, u8 dtim)
  707. {
  708. struct wl1251_acx_wr_tbtt_and_dtim *acx;
  709. int ret;
  710. wl1251_debug(DEBUG_ACX, "acx tbtt and dtim");
  711. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  712. if (!acx)
  713. return -ENOMEM;
  714. acx->tbtt = tbtt;
  715. acx->dtim = dtim;
  716. ret = wl1251_cmd_configure(wl, ACX_WR_TBTT_AND_DTIM,
  717. acx, sizeof(*acx));
  718. if (ret < 0) {
  719. wl1251_warning("failed to set tbtt and dtim: %d", ret);
  720. goto out;
  721. }
  722. out:
  723. kfree(acx);
  724. return ret;
  725. }
  726. int wl1251_acx_bet_enable(struct wl1251 *wl, enum wl1251_acx_bet_mode mode,
  727. u8 max_consecutive)
  728. {
  729. struct wl1251_acx_bet_enable *acx;
  730. int ret;
  731. wl1251_debug(DEBUG_ACX, "acx bet enable");
  732. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  733. if (!acx)
  734. return -ENOMEM;
  735. acx->enable = mode;
  736. acx->max_consecutive = max_consecutive;
  737. ret = wl1251_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
  738. if (ret < 0) {
  739. wl1251_warning("wl1251 acx bet enable failed: %d", ret);
  740. goto out;
  741. }
  742. out:
  743. kfree(acx);
  744. return ret;
  745. }
  746. int wl1251_acx_arp_ip_filter(struct wl1251 *wl, bool enable, __be32 address)
  747. {
  748. struct wl1251_acx_arp_filter *acx;
  749. int ret;
  750. wl1251_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
  751. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  752. if (!acx)
  753. return -ENOMEM;
  754. acx->version = ACX_IPV4_VERSION;
  755. acx->enable = enable;
  756. if (enable)
  757. memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
  758. ret = wl1251_cmd_configure(wl, ACX_ARP_IP_FILTER,
  759. acx, sizeof(*acx));
  760. if (ret < 0)
  761. wl1251_warning("failed to set arp ip filter: %d", ret);
  762. kfree(acx);
  763. return ret;
  764. }
  765. int wl1251_acx_ac_cfg(struct wl1251 *wl, u8 ac, u8 cw_min, u16 cw_max,
  766. u8 aifs, u16 txop)
  767. {
  768. struct wl1251_acx_ac_cfg *acx;
  769. int ret = 0;
  770. wl1251_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
  771. "aifs %d txop %d", ac, cw_min, cw_max, aifs, txop);
  772. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  773. if (!acx)
  774. return -ENOMEM;
  775. acx->ac = ac;
  776. acx->cw_min = cw_min;
  777. acx->cw_max = cw_max;
  778. acx->aifsn = aifs;
  779. acx->txop_limit = txop;
  780. ret = wl1251_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  781. if (ret < 0) {
  782. wl1251_warning("acx ac cfg failed: %d", ret);
  783. goto out;
  784. }
  785. out:
  786. kfree(acx);
  787. return ret;
  788. }
  789. int wl1251_acx_tid_cfg(struct wl1251 *wl, u8 queue,
  790. enum wl1251_acx_channel_type type,
  791. u8 tsid, enum wl1251_acx_ps_scheme ps_scheme,
  792. enum wl1251_acx_ack_policy ack_policy)
  793. {
  794. struct wl1251_acx_tid_cfg *acx;
  795. int ret = 0;
  796. wl1251_debug(DEBUG_ACX, "acx tid cfg %d type %d tsid %d "
  797. "ps_scheme %d ack_policy %d", queue, type, tsid,
  798. ps_scheme, ack_policy);
  799. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  800. if (!acx)
  801. return -ENOMEM;
  802. acx->queue = queue;
  803. acx->type = type;
  804. acx->tsid = tsid;
  805. acx->ps_scheme = ps_scheme;
  806. acx->ack_policy = ack_policy;
  807. ret = wl1251_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  808. if (ret < 0) {
  809. wl1251_warning("acx tid cfg failed: %d", ret);
  810. goto out;
  811. }
  812. out:
  813. kfree(acx);
  814. return ret;
  815. }