acx.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855
  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 "acx.h"
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/spi/spi.h>
  27. #include <linux/slab.h>
  28. #include "wlcore.h"
  29. #include "debug.h"
  30. #include "wl12xx_80211.h"
  31. #include "ps.h"
  32. #include "hw_ops.h"
  33. int wl1271_acx_wake_up_conditions(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  34. u8 wake_up_event, u8 listen_interval)
  35. {
  36. struct acx_wake_up_condition *wake_up;
  37. int ret;
  38. wl1271_debug(DEBUG_ACX, "acx wake up conditions (wake_up_event %d listen_interval %d)",
  39. wake_up_event, listen_interval);
  40. wake_up = kzalloc(sizeof(*wake_up), GFP_KERNEL);
  41. if (!wake_up) {
  42. ret = -ENOMEM;
  43. goto out;
  44. }
  45. wake_up->role_id = wlvif->role_id;
  46. wake_up->wake_up_event = wake_up_event;
  47. wake_up->listen_interval = listen_interval;
  48. ret = wl1271_cmd_configure(wl, ACX_WAKE_UP_CONDITIONS,
  49. wake_up, sizeof(*wake_up));
  50. if (ret < 0) {
  51. wl1271_warning("could not set wake up conditions: %d", ret);
  52. goto out;
  53. }
  54. out:
  55. kfree(wake_up);
  56. return ret;
  57. }
  58. int wl1271_acx_sleep_auth(struct wl1271 *wl, u8 sleep_auth)
  59. {
  60. struct acx_sleep_auth *auth;
  61. int ret;
  62. wl1271_debug(DEBUG_ACX, "acx sleep auth %d", sleep_auth);
  63. auth = kzalloc(sizeof(*auth), GFP_KERNEL);
  64. if (!auth) {
  65. ret = -ENOMEM;
  66. goto out;
  67. }
  68. auth->sleep_auth = sleep_auth;
  69. ret = wl1271_cmd_configure(wl, ACX_SLEEP_AUTH, auth, sizeof(*auth));
  70. if (ret < 0) {
  71. wl1271_error("could not configure sleep_auth to %d: %d",
  72. sleep_auth, ret);
  73. goto out;
  74. }
  75. wl->sleep_auth = sleep_auth;
  76. out:
  77. kfree(auth);
  78. return ret;
  79. }
  80. EXPORT_SYMBOL_GPL(wl1271_acx_sleep_auth);
  81. int wl1271_acx_tx_power(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  82. int power)
  83. {
  84. struct acx_current_tx_power *acx;
  85. int ret;
  86. wl1271_debug(DEBUG_ACX, "acx dot11_cur_tx_pwr %d", power);
  87. if (power < 0 || power > 25)
  88. return -EINVAL;
  89. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  90. if (!acx) {
  91. ret = -ENOMEM;
  92. goto out;
  93. }
  94. acx->role_id = wlvif->role_id;
  95. acx->current_tx_power = power * 10;
  96. ret = wl1271_cmd_configure(wl, DOT11_CUR_TX_PWR, acx, sizeof(*acx));
  97. if (ret < 0) {
  98. wl1271_warning("configure of tx power failed: %d", ret);
  99. goto out;
  100. }
  101. out:
  102. kfree(acx);
  103. return ret;
  104. }
  105. int wl1271_acx_feature_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  106. {
  107. struct acx_feature_config *feature;
  108. int ret;
  109. wl1271_debug(DEBUG_ACX, "acx feature cfg");
  110. feature = kzalloc(sizeof(*feature), GFP_KERNEL);
  111. if (!feature) {
  112. ret = -ENOMEM;
  113. goto out;
  114. }
  115. /* DF_ENCRYPTION_DISABLE and DF_SNIFF_MODE_ENABLE are disabled */
  116. feature->role_id = wlvif->role_id;
  117. feature->data_flow_options = 0;
  118. feature->options = 0;
  119. ret = wl1271_cmd_configure(wl, ACX_FEATURE_CFG,
  120. feature, sizeof(*feature));
  121. if (ret < 0) {
  122. wl1271_error("Couldnt set HW encryption");
  123. goto out;
  124. }
  125. out:
  126. kfree(feature);
  127. return ret;
  128. }
  129. int wl1271_acx_mem_map(struct wl1271 *wl, struct acx_header *mem_map,
  130. size_t len)
  131. {
  132. int ret;
  133. wl1271_debug(DEBUG_ACX, "acx mem map");
  134. ret = wl1271_cmd_interrogate(wl, ACX_MEM_MAP, mem_map,
  135. sizeof(struct acx_header), len);
  136. if (ret < 0)
  137. return ret;
  138. return 0;
  139. }
  140. int wl1271_acx_rx_msdu_life_time(struct wl1271 *wl)
  141. {
  142. struct acx_rx_msdu_lifetime *acx;
  143. int ret;
  144. wl1271_debug(DEBUG_ACX, "acx rx msdu life time");
  145. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  146. if (!acx) {
  147. ret = -ENOMEM;
  148. goto out;
  149. }
  150. acx->lifetime = cpu_to_le32(wl->conf.rx.rx_msdu_life_time);
  151. ret = wl1271_cmd_configure(wl, DOT11_RX_MSDU_LIFE_TIME,
  152. acx, sizeof(*acx));
  153. if (ret < 0) {
  154. wl1271_warning("failed to set rx msdu life time: %d", ret);
  155. goto out;
  156. }
  157. out:
  158. kfree(acx);
  159. return ret;
  160. }
  161. int wl1271_acx_slot(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  162. enum acx_slot_type slot_time)
  163. {
  164. struct acx_slot *slot;
  165. int ret;
  166. wl1271_debug(DEBUG_ACX, "acx slot");
  167. slot = kzalloc(sizeof(*slot), GFP_KERNEL);
  168. if (!slot) {
  169. ret = -ENOMEM;
  170. goto out;
  171. }
  172. slot->role_id = wlvif->role_id;
  173. slot->wone_index = STATION_WONE_INDEX;
  174. slot->slot_time = slot_time;
  175. ret = wl1271_cmd_configure(wl, ACX_SLOT, slot, sizeof(*slot));
  176. if (ret < 0) {
  177. wl1271_warning("failed to set slot time: %d", ret);
  178. goto out;
  179. }
  180. out:
  181. kfree(slot);
  182. return ret;
  183. }
  184. int wl1271_acx_group_address_tbl(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  185. bool enable, void *mc_list, u32 mc_list_len)
  186. {
  187. struct acx_dot11_grp_addr_tbl *acx;
  188. int ret;
  189. wl1271_debug(DEBUG_ACX, "acx group address tbl");
  190. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  191. if (!acx) {
  192. ret = -ENOMEM;
  193. goto out;
  194. }
  195. /* MAC filtering */
  196. acx->role_id = wlvif->role_id;
  197. acx->enabled = enable;
  198. acx->num_groups = mc_list_len;
  199. memcpy(acx->mac_table, mc_list, mc_list_len * ETH_ALEN);
  200. ret = wl1271_cmd_configure(wl, DOT11_GROUP_ADDRESS_TBL,
  201. acx, sizeof(*acx));
  202. if (ret < 0) {
  203. wl1271_warning("failed to set group addr table: %d", ret);
  204. goto out;
  205. }
  206. out:
  207. kfree(acx);
  208. return ret;
  209. }
  210. int wl1271_acx_service_period_timeout(struct wl1271 *wl,
  211. struct wl12xx_vif *wlvif)
  212. {
  213. struct acx_rx_timeout *rx_timeout;
  214. int ret;
  215. rx_timeout = kzalloc(sizeof(*rx_timeout), GFP_KERNEL);
  216. if (!rx_timeout) {
  217. ret = -ENOMEM;
  218. goto out;
  219. }
  220. wl1271_debug(DEBUG_ACX, "acx service period timeout");
  221. rx_timeout->role_id = wlvif->role_id;
  222. rx_timeout->ps_poll_timeout = cpu_to_le16(wl->conf.rx.ps_poll_timeout);
  223. rx_timeout->upsd_timeout = cpu_to_le16(wl->conf.rx.upsd_timeout);
  224. ret = wl1271_cmd_configure(wl, ACX_SERVICE_PERIOD_TIMEOUT,
  225. rx_timeout, sizeof(*rx_timeout));
  226. if (ret < 0) {
  227. wl1271_warning("failed to set service period timeout: %d",
  228. ret);
  229. goto out;
  230. }
  231. out:
  232. kfree(rx_timeout);
  233. return ret;
  234. }
  235. int wl1271_acx_rts_threshold(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  236. u32 rts_threshold)
  237. {
  238. struct acx_rts_threshold *rts;
  239. int ret;
  240. /*
  241. * If the RTS threshold is not configured or out of range, use the
  242. * default value.
  243. */
  244. if (rts_threshold > IEEE80211_MAX_RTS_THRESHOLD)
  245. rts_threshold = wl->conf.rx.rts_threshold;
  246. wl1271_debug(DEBUG_ACX, "acx rts threshold: %d", rts_threshold);
  247. rts = kzalloc(sizeof(*rts), GFP_KERNEL);
  248. if (!rts) {
  249. ret = -ENOMEM;
  250. goto out;
  251. }
  252. rts->role_id = wlvif->role_id;
  253. rts->threshold = cpu_to_le16((u16)rts_threshold);
  254. ret = wl1271_cmd_configure(wl, DOT11_RTS_THRESHOLD, rts, sizeof(*rts));
  255. if (ret < 0) {
  256. wl1271_warning("failed to set rts threshold: %d", ret);
  257. goto out;
  258. }
  259. out:
  260. kfree(rts);
  261. return ret;
  262. }
  263. int wl1271_acx_dco_itrim_params(struct wl1271 *wl)
  264. {
  265. struct acx_dco_itrim_params *dco;
  266. struct conf_itrim_settings *c = &wl->conf.itrim;
  267. int ret;
  268. wl1271_debug(DEBUG_ACX, "acx dco itrim parameters");
  269. dco = kzalloc(sizeof(*dco), GFP_KERNEL);
  270. if (!dco) {
  271. ret = -ENOMEM;
  272. goto out;
  273. }
  274. dco->enable = c->enable;
  275. dco->timeout = cpu_to_le32(c->timeout);
  276. ret = wl1271_cmd_configure(wl, ACX_SET_DCO_ITRIM_PARAMS,
  277. dco, sizeof(*dco));
  278. if (ret < 0) {
  279. wl1271_warning("failed to set dco itrim parameters: %d", ret);
  280. goto out;
  281. }
  282. out:
  283. kfree(dco);
  284. return ret;
  285. }
  286. int wl1271_acx_beacon_filter_opt(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  287. bool enable_filter)
  288. {
  289. struct acx_beacon_filter_option *beacon_filter = NULL;
  290. int ret = 0;
  291. wl1271_debug(DEBUG_ACX, "acx beacon filter opt enable=%d",
  292. enable_filter);
  293. if (enable_filter &&
  294. wl->conf.conn.bcn_filt_mode == CONF_BCN_FILT_MODE_DISABLED)
  295. goto out;
  296. beacon_filter = kzalloc(sizeof(*beacon_filter), GFP_KERNEL);
  297. if (!beacon_filter) {
  298. ret = -ENOMEM;
  299. goto out;
  300. }
  301. beacon_filter->role_id = wlvif->role_id;
  302. beacon_filter->enable = enable_filter;
  303. /*
  304. * When set to zero, and the filter is enabled, beacons
  305. * without the unicast TIM bit set are dropped.
  306. */
  307. beacon_filter->max_num_beacons = 0;
  308. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_OPT,
  309. beacon_filter, sizeof(*beacon_filter));
  310. if (ret < 0) {
  311. wl1271_warning("failed to set beacon filter opt: %d", ret);
  312. goto out;
  313. }
  314. out:
  315. kfree(beacon_filter);
  316. return ret;
  317. }
  318. int wl1271_acx_beacon_filter_table(struct wl1271 *wl,
  319. struct wl12xx_vif *wlvif)
  320. {
  321. struct acx_beacon_filter_ie_table *ie_table;
  322. int i, idx = 0;
  323. int ret;
  324. bool vendor_spec = false;
  325. wl1271_debug(DEBUG_ACX, "acx beacon filter table");
  326. ie_table = kzalloc(sizeof(*ie_table), GFP_KERNEL);
  327. if (!ie_table) {
  328. ret = -ENOMEM;
  329. goto out;
  330. }
  331. /* configure default beacon pass-through rules */
  332. ie_table->role_id = wlvif->role_id;
  333. ie_table->num_ie = 0;
  334. for (i = 0; i < wl->conf.conn.bcn_filt_ie_count; i++) {
  335. struct conf_bcn_filt_rule *r = &(wl->conf.conn.bcn_filt_ie[i]);
  336. ie_table->table[idx++] = r->ie;
  337. ie_table->table[idx++] = r->rule;
  338. if (r->ie == WLAN_EID_VENDOR_SPECIFIC) {
  339. /* only one vendor specific ie allowed */
  340. if (vendor_spec)
  341. continue;
  342. /* for vendor specific rules configure the
  343. additional fields */
  344. memcpy(&(ie_table->table[idx]), r->oui,
  345. CONF_BCN_IE_OUI_LEN);
  346. idx += CONF_BCN_IE_OUI_LEN;
  347. ie_table->table[idx++] = r->type;
  348. memcpy(&(ie_table->table[idx]), r->version,
  349. CONF_BCN_IE_VER_LEN);
  350. idx += CONF_BCN_IE_VER_LEN;
  351. vendor_spec = true;
  352. }
  353. ie_table->num_ie++;
  354. }
  355. ret = wl1271_cmd_configure(wl, ACX_BEACON_FILTER_TABLE,
  356. ie_table, sizeof(*ie_table));
  357. if (ret < 0) {
  358. wl1271_warning("failed to set beacon filter table: %d", ret);
  359. goto out;
  360. }
  361. out:
  362. kfree(ie_table);
  363. return ret;
  364. }
  365. #define ACX_CONN_MONIT_DISABLE_VALUE 0xffffffff
  366. int wl1271_acx_conn_monit_params(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  367. bool enable)
  368. {
  369. struct acx_conn_monit_params *acx;
  370. u32 threshold = ACX_CONN_MONIT_DISABLE_VALUE;
  371. u32 timeout = ACX_CONN_MONIT_DISABLE_VALUE;
  372. int ret;
  373. wl1271_debug(DEBUG_ACX, "acx connection monitor parameters: %s",
  374. enable ? "enabled" : "disabled");
  375. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  376. if (!acx) {
  377. ret = -ENOMEM;
  378. goto out;
  379. }
  380. if (enable) {
  381. threshold = wl->conf.conn.synch_fail_thold;
  382. timeout = wl->conf.conn.bss_lose_timeout;
  383. }
  384. acx->role_id = wlvif->role_id;
  385. acx->synch_fail_thold = cpu_to_le32(threshold);
  386. acx->bss_lose_timeout = cpu_to_le32(timeout);
  387. ret = wl1271_cmd_configure(wl, ACX_CONN_MONIT_PARAMS,
  388. acx, sizeof(*acx));
  389. if (ret < 0) {
  390. wl1271_warning("failed to set connection monitor "
  391. "parameters: %d", ret);
  392. goto out;
  393. }
  394. out:
  395. kfree(acx);
  396. return ret;
  397. }
  398. int wl1271_acx_sg_enable(struct wl1271 *wl, bool enable)
  399. {
  400. struct acx_bt_wlan_coex *pta;
  401. int ret;
  402. wl1271_debug(DEBUG_ACX, "acx sg enable");
  403. pta = kzalloc(sizeof(*pta), GFP_KERNEL);
  404. if (!pta) {
  405. ret = -ENOMEM;
  406. goto out;
  407. }
  408. if (enable)
  409. pta->enable = wl->conf.sg.state;
  410. else
  411. pta->enable = CONF_SG_DISABLE;
  412. ret = wl1271_cmd_configure(wl, ACX_SG_ENABLE, pta, sizeof(*pta));
  413. if (ret < 0) {
  414. wl1271_warning("failed to set softgemini enable: %d", ret);
  415. goto out;
  416. }
  417. out:
  418. kfree(pta);
  419. return ret;
  420. }
  421. int wl12xx_acx_sg_cfg(struct wl1271 *wl)
  422. {
  423. struct acx_bt_wlan_coex_param *param;
  424. struct conf_sg_settings *c = &wl->conf.sg;
  425. int i, ret;
  426. wl1271_debug(DEBUG_ACX, "acx sg cfg");
  427. param = kzalloc(sizeof(*param), GFP_KERNEL);
  428. if (!param) {
  429. ret = -ENOMEM;
  430. goto out;
  431. }
  432. /* BT-WLAN coext parameters */
  433. for (i = 0; i < WLCORE_CONF_SG_PARAMS_MAX; i++)
  434. param->params[i] = cpu_to_le32(c->params[i]);
  435. param->param_idx = WLCORE_CONF_SG_PARAMS_ALL;
  436. ret = wl1271_cmd_configure(wl, ACX_SG_CFG, param, sizeof(*param));
  437. if (ret < 0) {
  438. wl1271_warning("failed to set sg config: %d", ret);
  439. goto out;
  440. }
  441. out:
  442. kfree(param);
  443. return ret;
  444. }
  445. int wl1271_acx_cca_threshold(struct wl1271 *wl)
  446. {
  447. struct acx_energy_detection *detection;
  448. int ret;
  449. wl1271_debug(DEBUG_ACX, "acx cca threshold");
  450. detection = kzalloc(sizeof(*detection), GFP_KERNEL);
  451. if (!detection) {
  452. ret = -ENOMEM;
  453. goto out;
  454. }
  455. detection->rx_cca_threshold = cpu_to_le16(wl->conf.rx.rx_cca_threshold);
  456. detection->tx_energy_detection = wl->conf.tx.tx_energy_detection;
  457. ret = wl1271_cmd_configure(wl, ACX_CCA_THRESHOLD,
  458. detection, sizeof(*detection));
  459. if (ret < 0)
  460. wl1271_warning("failed to set cca threshold: %d", ret);
  461. out:
  462. kfree(detection);
  463. return ret;
  464. }
  465. int wl1271_acx_bcn_dtim_options(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  466. {
  467. struct acx_beacon_broadcast *bb;
  468. int ret;
  469. wl1271_debug(DEBUG_ACX, "acx bcn dtim options");
  470. bb = kzalloc(sizeof(*bb), GFP_KERNEL);
  471. if (!bb) {
  472. ret = -ENOMEM;
  473. goto out;
  474. }
  475. bb->role_id = wlvif->role_id;
  476. bb->beacon_rx_timeout = cpu_to_le16(wl->conf.conn.beacon_rx_timeout);
  477. bb->broadcast_timeout = cpu_to_le16(wl->conf.conn.broadcast_timeout);
  478. bb->rx_broadcast_in_ps = wl->conf.conn.rx_broadcast_in_ps;
  479. bb->ps_poll_threshold = wl->conf.conn.ps_poll_threshold;
  480. ret = wl1271_cmd_configure(wl, ACX_BCN_DTIM_OPTIONS, bb, sizeof(*bb));
  481. if (ret < 0) {
  482. wl1271_warning("failed to set rx config: %d", ret);
  483. goto out;
  484. }
  485. out:
  486. kfree(bb);
  487. return ret;
  488. }
  489. int wl1271_acx_aid(struct wl1271 *wl, struct wl12xx_vif *wlvif, u16 aid)
  490. {
  491. struct acx_aid *acx_aid;
  492. int ret;
  493. wl1271_debug(DEBUG_ACX, "acx aid");
  494. acx_aid = kzalloc(sizeof(*acx_aid), GFP_KERNEL);
  495. if (!acx_aid) {
  496. ret = -ENOMEM;
  497. goto out;
  498. }
  499. acx_aid->role_id = wlvif->role_id;
  500. acx_aid->aid = cpu_to_le16(aid);
  501. ret = wl1271_cmd_configure(wl, ACX_AID, acx_aid, sizeof(*acx_aid));
  502. if (ret < 0) {
  503. wl1271_warning("failed to set aid: %d", ret);
  504. goto out;
  505. }
  506. out:
  507. kfree(acx_aid);
  508. return ret;
  509. }
  510. int wl1271_acx_event_mbox_mask(struct wl1271 *wl, u32 event_mask)
  511. {
  512. struct acx_event_mask *mask;
  513. int ret;
  514. wl1271_debug(DEBUG_ACX, "acx event mbox mask");
  515. mask = kzalloc(sizeof(*mask), GFP_KERNEL);
  516. if (!mask) {
  517. ret = -ENOMEM;
  518. goto out;
  519. }
  520. /* high event mask is unused */
  521. mask->high_event_mask = cpu_to_le32(0xffffffff);
  522. mask->event_mask = cpu_to_le32(event_mask);
  523. ret = wl1271_cmd_configure(wl, ACX_EVENT_MBOX_MASK,
  524. mask, sizeof(*mask));
  525. if (ret < 0) {
  526. wl1271_warning("failed to set acx_event_mbox_mask: %d", ret);
  527. goto out;
  528. }
  529. out:
  530. kfree(mask);
  531. return ret;
  532. }
  533. int wl1271_acx_set_preamble(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  534. enum acx_preamble_type preamble)
  535. {
  536. struct acx_preamble *acx;
  537. int ret;
  538. wl1271_debug(DEBUG_ACX, "acx_set_preamble");
  539. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  540. if (!acx) {
  541. ret = -ENOMEM;
  542. goto out;
  543. }
  544. acx->role_id = wlvif->role_id;
  545. acx->preamble = preamble;
  546. ret = wl1271_cmd_configure(wl, ACX_PREAMBLE_TYPE, acx, sizeof(*acx));
  547. if (ret < 0) {
  548. wl1271_warning("Setting of preamble failed: %d", ret);
  549. goto out;
  550. }
  551. out:
  552. kfree(acx);
  553. return ret;
  554. }
  555. int wl1271_acx_cts_protect(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  556. enum acx_ctsprotect_type ctsprotect)
  557. {
  558. struct acx_ctsprotect *acx;
  559. int ret;
  560. wl1271_debug(DEBUG_ACX, "acx_set_ctsprotect");
  561. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  562. if (!acx) {
  563. ret = -ENOMEM;
  564. goto out;
  565. }
  566. acx->role_id = wlvif->role_id;
  567. acx->ctsprotect = ctsprotect;
  568. ret = wl1271_cmd_configure(wl, ACX_CTS_PROTECTION, acx, sizeof(*acx));
  569. if (ret < 0) {
  570. wl1271_warning("Setting of ctsprotect failed: %d", ret);
  571. goto out;
  572. }
  573. out:
  574. kfree(acx);
  575. return ret;
  576. }
  577. int wl1271_acx_statistics(struct wl1271 *wl, void *stats)
  578. {
  579. int ret;
  580. wl1271_debug(DEBUG_ACX, "acx statistics");
  581. ret = wl1271_cmd_interrogate(wl, ACX_STATISTICS, stats,
  582. sizeof(struct acx_header),
  583. wl->stats.fw_stats_len);
  584. if (ret < 0) {
  585. wl1271_warning("acx statistics failed: %d", ret);
  586. return -ENOMEM;
  587. }
  588. return 0;
  589. }
  590. int wl1271_acx_sta_rate_policies(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  591. {
  592. struct acx_rate_policy *acx;
  593. struct conf_tx_rate_class *c = &wl->conf.tx.sta_rc_conf;
  594. int ret = 0;
  595. wl1271_debug(DEBUG_ACX, "acx rate policies");
  596. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  597. if (!acx) {
  598. ret = -ENOMEM;
  599. goto out;
  600. }
  601. wl1271_debug(DEBUG_ACX, "basic_rate: 0x%x, full_rate: 0x%x",
  602. wlvif->basic_rate, wlvif->rate_set);
  603. /* configure one basic rate class */
  604. acx->rate_policy_idx = cpu_to_le32(wlvif->sta.basic_rate_idx);
  605. acx->rate_policy.enabled_rates = cpu_to_le32(wlvif->basic_rate);
  606. acx->rate_policy.short_retry_limit = c->short_retry_limit;
  607. acx->rate_policy.long_retry_limit = c->long_retry_limit;
  608. acx->rate_policy.aflags = c->aflags;
  609. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  610. if (ret < 0) {
  611. wl1271_warning("Setting of rate policies failed: %d", ret);
  612. goto out;
  613. }
  614. /* configure one AP supported rate class */
  615. acx->rate_policy_idx = cpu_to_le32(wlvif->sta.ap_rate_idx);
  616. /* the AP policy is HW specific */
  617. acx->rate_policy.enabled_rates =
  618. cpu_to_le32(wlcore_hw_sta_get_ap_rate_mask(wl, wlvif));
  619. acx->rate_policy.short_retry_limit = c->short_retry_limit;
  620. acx->rate_policy.long_retry_limit = c->long_retry_limit;
  621. acx->rate_policy.aflags = c->aflags;
  622. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  623. if (ret < 0) {
  624. wl1271_warning("Setting of rate policies failed: %d", ret);
  625. goto out;
  626. }
  627. /*
  628. * configure one rate class for basic p2p operations.
  629. * (p2p packets should always go out with OFDM rates, even
  630. * if we are currently connected to 11b AP)
  631. */
  632. acx->rate_policy_idx = cpu_to_le32(wlvif->sta.p2p_rate_idx);
  633. acx->rate_policy.enabled_rates =
  634. cpu_to_le32(CONF_TX_RATE_MASK_BASIC_P2P);
  635. acx->rate_policy.short_retry_limit = c->short_retry_limit;
  636. acx->rate_policy.long_retry_limit = c->long_retry_limit;
  637. acx->rate_policy.aflags = c->aflags;
  638. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  639. if (ret < 0) {
  640. wl1271_warning("Setting of rate policies failed: %d", ret);
  641. goto out;
  642. }
  643. out:
  644. kfree(acx);
  645. return ret;
  646. }
  647. int wl1271_acx_ap_rate_policy(struct wl1271 *wl, struct conf_tx_rate_class *c,
  648. u8 idx)
  649. {
  650. struct acx_rate_policy *acx;
  651. int ret = 0;
  652. wl1271_debug(DEBUG_ACX, "acx ap rate policy %d rates 0x%x",
  653. idx, c->enabled_rates);
  654. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  655. if (!acx) {
  656. ret = -ENOMEM;
  657. goto out;
  658. }
  659. acx->rate_policy.enabled_rates = cpu_to_le32(c->enabled_rates);
  660. acx->rate_policy.short_retry_limit = c->short_retry_limit;
  661. acx->rate_policy.long_retry_limit = c->long_retry_limit;
  662. acx->rate_policy.aflags = c->aflags;
  663. acx->rate_policy_idx = cpu_to_le32(idx);
  664. ret = wl1271_cmd_configure(wl, ACX_RATE_POLICY, acx, sizeof(*acx));
  665. if (ret < 0) {
  666. wl1271_warning("Setting of ap rate policy failed: %d", ret);
  667. goto out;
  668. }
  669. out:
  670. kfree(acx);
  671. return ret;
  672. }
  673. int wl1271_acx_ac_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  674. u8 ac, u8 cw_min, u16 cw_max, u8 aifsn, u16 txop)
  675. {
  676. struct acx_ac_cfg *acx;
  677. int ret = 0;
  678. wl1271_debug(DEBUG_ACX, "acx ac cfg %d cw_ming %d cw_max %d "
  679. "aifs %d txop %d", ac, cw_min, cw_max, aifsn, txop);
  680. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  681. if (!acx) {
  682. ret = -ENOMEM;
  683. goto out;
  684. }
  685. acx->role_id = wlvif->role_id;
  686. acx->ac = ac;
  687. acx->cw_min = cw_min;
  688. acx->cw_max = cpu_to_le16(cw_max);
  689. acx->aifsn = aifsn;
  690. acx->tx_op_limit = cpu_to_le16(txop);
  691. ret = wl1271_cmd_configure(wl, ACX_AC_CFG, acx, sizeof(*acx));
  692. if (ret < 0) {
  693. wl1271_warning("acx ac cfg failed: %d", ret);
  694. goto out;
  695. }
  696. out:
  697. kfree(acx);
  698. return ret;
  699. }
  700. int wl1271_acx_tid_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  701. u8 queue_id, u8 channel_type,
  702. u8 tsid, u8 ps_scheme, u8 ack_policy,
  703. u32 apsd_conf0, u32 apsd_conf1)
  704. {
  705. struct acx_tid_config *acx;
  706. int ret = 0;
  707. wl1271_debug(DEBUG_ACX, "acx tid config");
  708. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  709. if (!acx) {
  710. ret = -ENOMEM;
  711. goto out;
  712. }
  713. acx->role_id = wlvif->role_id;
  714. acx->queue_id = queue_id;
  715. acx->channel_type = channel_type;
  716. acx->tsid = tsid;
  717. acx->ps_scheme = ps_scheme;
  718. acx->ack_policy = ack_policy;
  719. acx->apsd_conf[0] = cpu_to_le32(apsd_conf0);
  720. acx->apsd_conf[1] = cpu_to_le32(apsd_conf1);
  721. ret = wl1271_cmd_configure(wl, ACX_TID_CFG, acx, sizeof(*acx));
  722. if (ret < 0) {
  723. wl1271_warning("Setting of tid config failed: %d", ret);
  724. goto out;
  725. }
  726. out:
  727. kfree(acx);
  728. return ret;
  729. }
  730. int wl1271_acx_frag_threshold(struct wl1271 *wl, u32 frag_threshold)
  731. {
  732. struct acx_frag_threshold *acx;
  733. int ret = 0;
  734. /*
  735. * If the fragmentation is not configured or out of range, use the
  736. * default value.
  737. */
  738. if (frag_threshold > IEEE80211_MAX_FRAG_THRESHOLD)
  739. frag_threshold = wl->conf.tx.frag_threshold;
  740. wl1271_debug(DEBUG_ACX, "acx frag threshold: %d", frag_threshold);
  741. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  742. if (!acx) {
  743. ret = -ENOMEM;
  744. goto out;
  745. }
  746. acx->frag_threshold = cpu_to_le16((u16)frag_threshold);
  747. ret = wl1271_cmd_configure(wl, ACX_FRAG_CFG, acx, sizeof(*acx));
  748. if (ret < 0) {
  749. wl1271_warning("Setting of frag threshold failed: %d", ret);
  750. goto out;
  751. }
  752. out:
  753. kfree(acx);
  754. return ret;
  755. }
  756. int wl1271_acx_tx_config_options(struct wl1271 *wl)
  757. {
  758. struct acx_tx_config_options *acx;
  759. int ret = 0;
  760. wl1271_debug(DEBUG_ACX, "acx tx config options");
  761. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  762. if (!acx) {
  763. ret = -ENOMEM;
  764. goto out;
  765. }
  766. acx->tx_compl_timeout = cpu_to_le16(wl->conf.tx.tx_compl_timeout);
  767. acx->tx_compl_threshold = cpu_to_le16(wl->conf.tx.tx_compl_threshold);
  768. ret = wl1271_cmd_configure(wl, ACX_TX_CONFIG_OPT, acx, sizeof(*acx));
  769. if (ret < 0) {
  770. wl1271_warning("Setting of tx options failed: %d", ret);
  771. goto out;
  772. }
  773. out:
  774. kfree(acx);
  775. return ret;
  776. }
  777. int wl12xx_acx_mem_cfg(struct wl1271 *wl)
  778. {
  779. struct wl12xx_acx_config_memory *mem_conf;
  780. struct conf_memory_settings *mem;
  781. int ret;
  782. wl1271_debug(DEBUG_ACX, "wl1271 mem cfg");
  783. mem_conf = kzalloc(sizeof(*mem_conf), GFP_KERNEL);
  784. if (!mem_conf) {
  785. ret = -ENOMEM;
  786. goto out;
  787. }
  788. mem = &wl->conf.mem;
  789. /* memory config */
  790. mem_conf->num_stations = mem->num_stations;
  791. mem_conf->rx_mem_block_num = mem->rx_block_num;
  792. mem_conf->tx_min_mem_block_num = mem->tx_min_block_num;
  793. mem_conf->num_ssid_profiles = mem->ssid_profiles;
  794. mem_conf->total_tx_descriptors = cpu_to_le32(wl->num_tx_desc);
  795. mem_conf->dyn_mem_enable = mem->dynamic_memory;
  796. mem_conf->tx_free_req = mem->min_req_tx_blocks;
  797. mem_conf->rx_free_req = mem->min_req_rx_blocks;
  798. mem_conf->tx_min = mem->tx_min;
  799. mem_conf->fwlog_blocks = wl->conf.fwlog.mem_blocks;
  800. ret = wl1271_cmd_configure(wl, ACX_MEM_CFG, mem_conf,
  801. sizeof(*mem_conf));
  802. if (ret < 0) {
  803. wl1271_warning("wl1271 mem config failed: %d", ret);
  804. goto out;
  805. }
  806. out:
  807. kfree(mem_conf);
  808. return ret;
  809. }
  810. EXPORT_SYMBOL_GPL(wl12xx_acx_mem_cfg);
  811. int wl1271_acx_init_mem_config(struct wl1271 *wl)
  812. {
  813. int ret;
  814. wl->target_mem_map = kzalloc(sizeof(struct wl1271_acx_mem_map),
  815. GFP_KERNEL);
  816. if (!wl->target_mem_map) {
  817. wl1271_error("couldn't allocate target memory map");
  818. return -ENOMEM;
  819. }
  820. /* we now ask for the firmware built memory map */
  821. ret = wl1271_acx_mem_map(wl, (void *)wl->target_mem_map,
  822. sizeof(struct wl1271_acx_mem_map));
  823. if (ret < 0) {
  824. wl1271_error("couldn't retrieve firmware memory map");
  825. kfree(wl->target_mem_map);
  826. wl->target_mem_map = NULL;
  827. return ret;
  828. }
  829. /* initialize TX block book keeping */
  830. wl->tx_blocks_available =
  831. le32_to_cpu(wl->target_mem_map->num_tx_mem_blocks);
  832. wl1271_debug(DEBUG_TX, "available tx blocks: %d",
  833. wl->tx_blocks_available);
  834. return 0;
  835. }
  836. EXPORT_SYMBOL_GPL(wl1271_acx_init_mem_config);
  837. int wl1271_acx_init_rx_interrupt(struct wl1271 *wl)
  838. {
  839. struct wl1271_acx_rx_config_opt *rx_conf;
  840. int ret;
  841. wl1271_debug(DEBUG_ACX, "wl1271 rx interrupt config");
  842. rx_conf = kzalloc(sizeof(*rx_conf), GFP_KERNEL);
  843. if (!rx_conf) {
  844. ret = -ENOMEM;
  845. goto out;
  846. }
  847. rx_conf->threshold = cpu_to_le16(wl->conf.rx.irq_pkt_threshold);
  848. rx_conf->timeout = cpu_to_le16(wl->conf.rx.irq_timeout);
  849. rx_conf->mblk_threshold = cpu_to_le16(wl->conf.rx.irq_blk_threshold);
  850. rx_conf->queue_type = wl->conf.rx.queue_type;
  851. ret = wl1271_cmd_configure(wl, ACX_RX_CONFIG_OPT, rx_conf,
  852. sizeof(*rx_conf));
  853. if (ret < 0) {
  854. wl1271_warning("wl1271 rx config opt failed: %d", ret);
  855. goto out;
  856. }
  857. out:
  858. kfree(rx_conf);
  859. return ret;
  860. }
  861. int wl1271_acx_bet_enable(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  862. bool enable)
  863. {
  864. struct wl1271_acx_bet_enable *acx = NULL;
  865. int ret = 0;
  866. wl1271_debug(DEBUG_ACX, "acx bet enable");
  867. if (enable && wl->conf.conn.bet_enable == CONF_BET_MODE_DISABLE)
  868. goto out;
  869. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  870. if (!acx) {
  871. ret = -ENOMEM;
  872. goto out;
  873. }
  874. acx->role_id = wlvif->role_id;
  875. acx->enable = enable ? CONF_BET_MODE_ENABLE : CONF_BET_MODE_DISABLE;
  876. acx->max_consecutive = wl->conf.conn.bet_max_consecutive;
  877. ret = wl1271_cmd_configure(wl, ACX_BET_ENABLE, acx, sizeof(*acx));
  878. if (ret < 0) {
  879. wl1271_warning("acx bet enable failed: %d", ret);
  880. goto out;
  881. }
  882. out:
  883. kfree(acx);
  884. return ret;
  885. }
  886. int wl1271_acx_arp_ip_filter(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  887. u8 enable, __be32 address)
  888. {
  889. struct wl1271_acx_arp_filter *acx;
  890. int ret;
  891. wl1271_debug(DEBUG_ACX, "acx arp ip filter, enable: %d", enable);
  892. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  893. if (!acx) {
  894. ret = -ENOMEM;
  895. goto out;
  896. }
  897. acx->role_id = wlvif->role_id;
  898. acx->version = ACX_IPV4_VERSION;
  899. acx->enable = enable;
  900. if (enable)
  901. memcpy(acx->address, &address, ACX_IPV4_ADDR_SIZE);
  902. ret = wl1271_cmd_configure(wl, ACX_ARP_IP_FILTER,
  903. acx, sizeof(*acx));
  904. if (ret < 0) {
  905. wl1271_warning("failed to set arp ip filter: %d", ret);
  906. goto out;
  907. }
  908. out:
  909. kfree(acx);
  910. return ret;
  911. }
  912. int wl1271_acx_pm_config(struct wl1271 *wl)
  913. {
  914. struct wl1271_acx_pm_config *acx = NULL;
  915. struct conf_pm_config_settings *c = &wl->conf.pm_config;
  916. int ret = 0;
  917. wl1271_debug(DEBUG_ACX, "acx pm config");
  918. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  919. if (!acx) {
  920. ret = -ENOMEM;
  921. goto out;
  922. }
  923. acx->host_clk_settling_time = cpu_to_le32(c->host_clk_settling_time);
  924. acx->host_fast_wakeup_support = c->host_fast_wakeup_support;
  925. ret = wl1271_cmd_configure(wl, ACX_PM_CONFIG, acx, sizeof(*acx));
  926. if (ret < 0) {
  927. wl1271_warning("acx pm config failed: %d", ret);
  928. goto out;
  929. }
  930. out:
  931. kfree(acx);
  932. return ret;
  933. }
  934. EXPORT_SYMBOL_GPL(wl1271_acx_pm_config);
  935. int wl1271_acx_keep_alive_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  936. bool enable)
  937. {
  938. struct wl1271_acx_keep_alive_mode *acx = NULL;
  939. int ret = 0;
  940. wl1271_debug(DEBUG_ACX, "acx keep alive mode: %d", enable);
  941. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  942. if (!acx) {
  943. ret = -ENOMEM;
  944. goto out;
  945. }
  946. acx->role_id = wlvif->role_id;
  947. acx->enabled = enable;
  948. ret = wl1271_cmd_configure(wl, ACX_KEEP_ALIVE_MODE, acx, sizeof(*acx));
  949. if (ret < 0) {
  950. wl1271_warning("acx keep alive mode failed: %d", ret);
  951. goto out;
  952. }
  953. out:
  954. kfree(acx);
  955. return ret;
  956. }
  957. int wl1271_acx_keep_alive_config(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  958. u8 index, u8 tpl_valid)
  959. {
  960. struct wl1271_acx_keep_alive_config *acx = NULL;
  961. int ret = 0;
  962. wl1271_debug(DEBUG_ACX, "acx keep alive config");
  963. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  964. if (!acx) {
  965. ret = -ENOMEM;
  966. goto out;
  967. }
  968. acx->role_id = wlvif->role_id;
  969. acx->period = cpu_to_le32(wl->conf.conn.keep_alive_interval);
  970. acx->index = index;
  971. acx->tpl_validation = tpl_valid;
  972. acx->trigger = ACX_KEEP_ALIVE_NO_TX;
  973. ret = wl1271_cmd_configure(wl, ACX_SET_KEEP_ALIVE_CONFIG,
  974. acx, sizeof(*acx));
  975. if (ret < 0) {
  976. wl1271_warning("acx keep alive config failed: %d", ret);
  977. goto out;
  978. }
  979. out:
  980. kfree(acx);
  981. return ret;
  982. }
  983. int wl1271_acx_rssi_snr_trigger(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  984. bool enable, s16 thold, u8 hyst)
  985. {
  986. struct wl1271_acx_rssi_snr_trigger *acx = NULL;
  987. int ret = 0;
  988. wl1271_debug(DEBUG_ACX, "acx rssi snr trigger");
  989. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  990. if (!acx) {
  991. ret = -ENOMEM;
  992. goto out;
  993. }
  994. wlvif->last_rssi_event = -1;
  995. acx->role_id = wlvif->role_id;
  996. acx->pacing = cpu_to_le16(wl->conf.roam_trigger.trigger_pacing);
  997. acx->metric = WL1271_ACX_TRIG_METRIC_RSSI_BEACON;
  998. acx->type = WL1271_ACX_TRIG_TYPE_EDGE;
  999. if (enable)
  1000. acx->enable = WL1271_ACX_TRIG_ENABLE;
  1001. else
  1002. acx->enable = WL1271_ACX_TRIG_DISABLE;
  1003. acx->index = WL1271_ACX_TRIG_IDX_RSSI;
  1004. acx->dir = WL1271_ACX_TRIG_DIR_BIDIR;
  1005. acx->threshold = cpu_to_le16(thold);
  1006. acx->hysteresis = hyst;
  1007. ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_TRIGGER, acx, sizeof(*acx));
  1008. if (ret < 0) {
  1009. wl1271_warning("acx rssi snr trigger setting failed: %d", ret);
  1010. goto out;
  1011. }
  1012. out:
  1013. kfree(acx);
  1014. return ret;
  1015. }
  1016. int wl1271_acx_rssi_snr_avg_weights(struct wl1271 *wl,
  1017. struct wl12xx_vif *wlvif)
  1018. {
  1019. struct wl1271_acx_rssi_snr_avg_weights *acx = NULL;
  1020. struct conf_roam_trigger_settings *c = &wl->conf.roam_trigger;
  1021. int ret = 0;
  1022. wl1271_debug(DEBUG_ACX, "acx rssi snr avg weights");
  1023. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1024. if (!acx) {
  1025. ret = -ENOMEM;
  1026. goto out;
  1027. }
  1028. acx->role_id = wlvif->role_id;
  1029. acx->rssi_beacon = c->avg_weight_rssi_beacon;
  1030. acx->rssi_data = c->avg_weight_rssi_data;
  1031. acx->snr_beacon = c->avg_weight_snr_beacon;
  1032. acx->snr_data = c->avg_weight_snr_data;
  1033. ret = wl1271_cmd_configure(wl, ACX_RSSI_SNR_WEIGHTS, acx, sizeof(*acx));
  1034. if (ret < 0) {
  1035. wl1271_warning("acx rssi snr trigger weights failed: %d", ret);
  1036. goto out;
  1037. }
  1038. out:
  1039. kfree(acx);
  1040. return ret;
  1041. }
  1042. int wl1271_acx_set_ht_capabilities(struct wl1271 *wl,
  1043. struct ieee80211_sta_ht_cap *ht_cap,
  1044. bool allow_ht_operation, u8 hlid)
  1045. {
  1046. struct wl1271_acx_ht_capabilities *acx;
  1047. int ret = 0;
  1048. u32 ht_capabilites = 0;
  1049. wl1271_debug(DEBUG_ACX, "acx ht capabilities setting "
  1050. "sta supp: %d sta cap: %d", ht_cap->ht_supported,
  1051. ht_cap->cap);
  1052. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1053. if (!acx) {
  1054. ret = -ENOMEM;
  1055. goto out;
  1056. }
  1057. if (allow_ht_operation && ht_cap->ht_supported) {
  1058. /* no need to translate capabilities - use the spec values */
  1059. ht_capabilites = ht_cap->cap;
  1060. /*
  1061. * this bit is not employed by the spec but only by FW to
  1062. * indicate peer HT support
  1063. */
  1064. ht_capabilites |= WL12XX_HT_CAP_HT_OPERATION;
  1065. /* get data from A-MPDU parameters field */
  1066. acx->ampdu_max_length = ht_cap->ampdu_factor;
  1067. acx->ampdu_min_spacing = ht_cap->ampdu_density;
  1068. }
  1069. acx->hlid = hlid;
  1070. acx->ht_capabilites = cpu_to_le32(ht_capabilites);
  1071. ret = wl1271_cmd_configure(wl, ACX_PEER_HT_CAP, acx, sizeof(*acx));
  1072. if (ret < 0) {
  1073. wl1271_warning("acx ht capabilities setting failed: %d", ret);
  1074. goto out;
  1075. }
  1076. out:
  1077. kfree(acx);
  1078. return ret;
  1079. }
  1080. EXPORT_SYMBOL_GPL(wl1271_acx_set_ht_capabilities);
  1081. int wl1271_acx_set_ht_information(struct wl1271 *wl,
  1082. struct wl12xx_vif *wlvif,
  1083. u16 ht_operation_mode)
  1084. {
  1085. struct wl1271_acx_ht_information *acx;
  1086. int ret = 0;
  1087. wl1271_debug(DEBUG_ACX, "acx ht information setting");
  1088. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1089. if (!acx) {
  1090. ret = -ENOMEM;
  1091. goto out;
  1092. }
  1093. acx->role_id = wlvif->role_id;
  1094. acx->ht_protection =
  1095. (u8)(ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION);
  1096. acx->rifs_mode = 0;
  1097. acx->gf_protection =
  1098. !!(ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  1099. acx->ht_tx_burst_limit = 0;
  1100. acx->dual_cts_protection = 0;
  1101. ret = wl1271_cmd_configure(wl, ACX_HT_BSS_OPERATION, acx, sizeof(*acx));
  1102. if (ret < 0) {
  1103. wl1271_warning("acx ht information setting failed: %d", ret);
  1104. goto out;
  1105. }
  1106. out:
  1107. kfree(acx);
  1108. return ret;
  1109. }
  1110. /* Configure BA session initiator/receiver parameters setting in the FW. */
  1111. int wl12xx_acx_set_ba_initiator_policy(struct wl1271 *wl,
  1112. struct wl12xx_vif *wlvif)
  1113. {
  1114. struct wl1271_acx_ba_initiator_policy *acx;
  1115. int ret;
  1116. wl1271_debug(DEBUG_ACX, "acx ba initiator policy");
  1117. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1118. if (!acx) {
  1119. ret = -ENOMEM;
  1120. goto out;
  1121. }
  1122. /* set for the current role */
  1123. acx->role_id = wlvif->role_id;
  1124. acx->tid_bitmap = wl->conf.ht.tx_ba_tid_bitmap;
  1125. acx->win_size = wl->conf.ht.tx_ba_win_size;
  1126. acx->inactivity_timeout = wl->conf.ht.inactivity_timeout;
  1127. ret = wl1271_cmd_configure(wl,
  1128. ACX_BA_SESSION_INIT_POLICY,
  1129. acx,
  1130. sizeof(*acx));
  1131. if (ret < 0) {
  1132. wl1271_warning("acx ba initiator policy failed: %d", ret);
  1133. goto out;
  1134. }
  1135. out:
  1136. kfree(acx);
  1137. return ret;
  1138. }
  1139. /* setup BA session receiver setting in the FW. */
  1140. int wl12xx_acx_set_ba_receiver_session(struct wl1271 *wl, u8 tid_index,
  1141. u16 ssn, bool enable, u8 peer_hlid,
  1142. u8 win_size)
  1143. {
  1144. struct wl1271_acx_ba_receiver_setup *acx;
  1145. int ret;
  1146. wl1271_debug(DEBUG_ACX, "acx ba receiver session setting");
  1147. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1148. if (!acx) {
  1149. ret = -ENOMEM;
  1150. goto out;
  1151. }
  1152. acx->hlid = peer_hlid;
  1153. acx->tid = tid_index;
  1154. acx->enable = enable;
  1155. acx->win_size = win_size;
  1156. acx->ssn = ssn;
  1157. ret = wlcore_cmd_configure_failsafe(wl, ACX_BA_SESSION_RX_SETUP, acx,
  1158. sizeof(*acx),
  1159. BIT(CMD_STATUS_NO_RX_BA_SESSION));
  1160. if (ret < 0) {
  1161. wl1271_warning("acx ba receiver session failed: %d", ret);
  1162. goto out;
  1163. }
  1164. /* sometimes we can't start the session */
  1165. if (ret == CMD_STATUS_NO_RX_BA_SESSION) {
  1166. wl1271_warning("no fw rx ba on tid %d", tid_index);
  1167. ret = -EBUSY;
  1168. goto out;
  1169. }
  1170. ret = 0;
  1171. out:
  1172. kfree(acx);
  1173. return ret;
  1174. }
  1175. int wl12xx_acx_tsf_info(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1176. u64 *mactime)
  1177. {
  1178. struct wl12xx_acx_fw_tsf_information *tsf_info;
  1179. int ret;
  1180. tsf_info = kzalloc(sizeof(*tsf_info), GFP_KERNEL);
  1181. if (!tsf_info) {
  1182. ret = -ENOMEM;
  1183. goto out;
  1184. }
  1185. tsf_info->role_id = wlvif->role_id;
  1186. ret = wl1271_cmd_interrogate(wl, ACX_TSF_INFO, tsf_info,
  1187. sizeof(struct acx_header), sizeof(*tsf_info));
  1188. if (ret < 0) {
  1189. wl1271_warning("acx tsf info interrogate failed");
  1190. goto out;
  1191. }
  1192. *mactime = le32_to_cpu(tsf_info->current_tsf_low) |
  1193. ((u64) le32_to_cpu(tsf_info->current_tsf_high) << 32);
  1194. out:
  1195. kfree(tsf_info);
  1196. return ret;
  1197. }
  1198. int wl1271_acx_ps_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1199. bool enable)
  1200. {
  1201. struct wl1271_acx_ps_rx_streaming *rx_streaming;
  1202. u32 conf_queues, enable_queues;
  1203. int i, ret = 0;
  1204. wl1271_debug(DEBUG_ACX, "acx ps rx streaming");
  1205. rx_streaming = kzalloc(sizeof(*rx_streaming), GFP_KERNEL);
  1206. if (!rx_streaming) {
  1207. ret = -ENOMEM;
  1208. goto out;
  1209. }
  1210. conf_queues = wl->conf.rx_streaming.queues;
  1211. if (enable)
  1212. enable_queues = conf_queues;
  1213. else
  1214. enable_queues = 0;
  1215. for (i = 0; i < 8; i++) {
  1216. /*
  1217. * Skip non-changed queues, to avoid redundant acxs.
  1218. * this check assumes conf.rx_streaming.queues can't
  1219. * be changed while rx_streaming is enabled.
  1220. */
  1221. if (!(conf_queues & BIT(i)))
  1222. continue;
  1223. rx_streaming->role_id = wlvif->role_id;
  1224. rx_streaming->tid = i;
  1225. rx_streaming->enable = enable_queues & BIT(i);
  1226. rx_streaming->period = wl->conf.rx_streaming.interval;
  1227. rx_streaming->timeout = wl->conf.rx_streaming.interval;
  1228. ret = wl1271_cmd_configure(wl, ACX_PS_RX_STREAMING,
  1229. rx_streaming,
  1230. sizeof(*rx_streaming));
  1231. if (ret < 0) {
  1232. wl1271_warning("acx ps rx streaming failed: %d", ret);
  1233. goto out;
  1234. }
  1235. }
  1236. out:
  1237. kfree(rx_streaming);
  1238. return ret;
  1239. }
  1240. int wl1271_acx_ap_max_tx_retry(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1241. {
  1242. struct wl1271_acx_ap_max_tx_retry *acx = NULL;
  1243. int ret;
  1244. wl1271_debug(DEBUG_ACX, "acx ap max tx retry");
  1245. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1246. if (!acx)
  1247. return -ENOMEM;
  1248. acx->role_id = wlvif->role_id;
  1249. acx->max_tx_retry = cpu_to_le16(wl->conf.tx.max_tx_retries);
  1250. ret = wl1271_cmd_configure(wl, ACX_MAX_TX_FAILURE, acx, sizeof(*acx));
  1251. if (ret < 0) {
  1252. wl1271_warning("acx ap max tx retry failed: %d", ret);
  1253. goto out;
  1254. }
  1255. out:
  1256. kfree(acx);
  1257. return ret;
  1258. }
  1259. int wl12xx_acx_config_ps(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1260. {
  1261. struct wl1271_acx_config_ps *config_ps;
  1262. int ret;
  1263. wl1271_debug(DEBUG_ACX, "acx config ps");
  1264. config_ps = kzalloc(sizeof(*config_ps), GFP_KERNEL);
  1265. if (!config_ps) {
  1266. ret = -ENOMEM;
  1267. goto out;
  1268. }
  1269. config_ps->exit_retries = wl->conf.conn.psm_exit_retries;
  1270. config_ps->enter_retries = wl->conf.conn.psm_entry_retries;
  1271. config_ps->null_data_rate = cpu_to_le32(wlvif->basic_rate);
  1272. ret = wl1271_cmd_configure(wl, ACX_CONFIG_PS, config_ps,
  1273. sizeof(*config_ps));
  1274. if (ret < 0) {
  1275. wl1271_warning("acx config ps failed: %d", ret);
  1276. goto out;
  1277. }
  1278. out:
  1279. kfree(config_ps);
  1280. return ret;
  1281. }
  1282. int wl1271_acx_set_inconnection_sta(struct wl1271 *wl,
  1283. struct wl12xx_vif *wlvif, u8 *addr)
  1284. {
  1285. struct wl1271_acx_inconnection_sta *acx = NULL;
  1286. int ret;
  1287. wl1271_debug(DEBUG_ACX, "acx set inconnaction sta %pM", addr);
  1288. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1289. if (!acx)
  1290. return -ENOMEM;
  1291. memcpy(acx->addr, addr, ETH_ALEN);
  1292. acx->role_id = wlvif->role_id;
  1293. ret = wl1271_cmd_configure(wl, ACX_UPDATE_INCONNECTION_STA_LIST,
  1294. acx, sizeof(*acx));
  1295. if (ret < 0) {
  1296. wl1271_warning("acx set inconnaction sta failed: %d", ret);
  1297. goto out;
  1298. }
  1299. out:
  1300. kfree(acx);
  1301. return ret;
  1302. }
  1303. int wl1271_acx_fm_coex(struct wl1271 *wl)
  1304. {
  1305. struct wl1271_acx_fm_coex *acx;
  1306. int ret;
  1307. wl1271_debug(DEBUG_ACX, "acx fm coex setting");
  1308. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1309. if (!acx) {
  1310. ret = -ENOMEM;
  1311. goto out;
  1312. }
  1313. acx->enable = wl->conf.fm_coex.enable;
  1314. acx->swallow_period = wl->conf.fm_coex.swallow_period;
  1315. acx->n_divider_fref_set_1 = wl->conf.fm_coex.n_divider_fref_set_1;
  1316. acx->n_divider_fref_set_2 = wl->conf.fm_coex.n_divider_fref_set_2;
  1317. acx->m_divider_fref_set_1 =
  1318. cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_1);
  1319. acx->m_divider_fref_set_2 =
  1320. cpu_to_le16(wl->conf.fm_coex.m_divider_fref_set_2);
  1321. acx->coex_pll_stabilization_time =
  1322. cpu_to_le32(wl->conf.fm_coex.coex_pll_stabilization_time);
  1323. acx->ldo_stabilization_time =
  1324. cpu_to_le16(wl->conf.fm_coex.ldo_stabilization_time);
  1325. acx->fm_disturbed_band_margin =
  1326. wl->conf.fm_coex.fm_disturbed_band_margin;
  1327. acx->swallow_clk_diff = wl->conf.fm_coex.swallow_clk_diff;
  1328. ret = wl1271_cmd_configure(wl, ACX_FM_COEX_CFG, acx, sizeof(*acx));
  1329. if (ret < 0) {
  1330. wl1271_warning("acx fm coex setting failed: %d", ret);
  1331. goto out;
  1332. }
  1333. out:
  1334. kfree(acx);
  1335. return ret;
  1336. }
  1337. int wl12xx_acx_set_rate_mgmt_params(struct wl1271 *wl)
  1338. {
  1339. struct wl12xx_acx_set_rate_mgmt_params *acx = NULL;
  1340. struct conf_rate_policy_settings *conf = &wl->conf.rate;
  1341. int ret;
  1342. wl1271_debug(DEBUG_ACX, "acx set rate mgmt params");
  1343. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1344. if (!acx)
  1345. return -ENOMEM;
  1346. acx->index = ACX_RATE_MGMT_ALL_PARAMS;
  1347. acx->rate_retry_score = cpu_to_le16(conf->rate_retry_score);
  1348. acx->per_add = cpu_to_le16(conf->per_add);
  1349. acx->per_th1 = cpu_to_le16(conf->per_th1);
  1350. acx->per_th2 = cpu_to_le16(conf->per_th2);
  1351. acx->max_per = cpu_to_le16(conf->max_per);
  1352. acx->inverse_curiosity_factor = conf->inverse_curiosity_factor;
  1353. acx->tx_fail_low_th = conf->tx_fail_low_th;
  1354. acx->tx_fail_high_th = conf->tx_fail_high_th;
  1355. acx->per_alpha_shift = conf->per_alpha_shift;
  1356. acx->per_add_shift = conf->per_add_shift;
  1357. acx->per_beta1_shift = conf->per_beta1_shift;
  1358. acx->per_beta2_shift = conf->per_beta2_shift;
  1359. acx->rate_check_up = conf->rate_check_up;
  1360. acx->rate_check_down = conf->rate_check_down;
  1361. memcpy(acx->rate_retry_policy, conf->rate_retry_policy,
  1362. sizeof(acx->rate_retry_policy));
  1363. ret = wl1271_cmd_configure(wl, ACX_SET_RATE_MGMT_PARAMS,
  1364. acx, sizeof(*acx));
  1365. if (ret < 0) {
  1366. wl1271_warning("acx set rate mgmt params failed: %d", ret);
  1367. goto out;
  1368. }
  1369. out:
  1370. kfree(acx);
  1371. return ret;
  1372. }
  1373. int wl12xx_acx_config_hangover(struct wl1271 *wl)
  1374. {
  1375. struct wl12xx_acx_config_hangover *acx;
  1376. struct conf_hangover_settings *conf = &wl->conf.hangover;
  1377. int ret;
  1378. wl1271_debug(DEBUG_ACX, "acx config hangover");
  1379. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1380. if (!acx) {
  1381. ret = -ENOMEM;
  1382. goto out;
  1383. }
  1384. acx->recover_time = cpu_to_le32(conf->recover_time);
  1385. acx->hangover_period = conf->hangover_period;
  1386. acx->dynamic_mode = conf->dynamic_mode;
  1387. acx->early_termination_mode = conf->early_termination_mode;
  1388. acx->max_period = conf->max_period;
  1389. acx->min_period = conf->min_period;
  1390. acx->increase_delta = conf->increase_delta;
  1391. acx->decrease_delta = conf->decrease_delta;
  1392. acx->quiet_time = conf->quiet_time;
  1393. acx->increase_time = conf->increase_time;
  1394. acx->window_size = conf->window_size;
  1395. ret = wl1271_cmd_configure(wl, ACX_CONFIG_HANGOVER, acx,
  1396. sizeof(*acx));
  1397. if (ret < 0) {
  1398. wl1271_warning("acx config hangover failed: %d", ret);
  1399. goto out;
  1400. }
  1401. out:
  1402. kfree(acx);
  1403. return ret;
  1404. }
  1405. int wlcore_acx_average_rssi(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1406. s8 *avg_rssi)
  1407. {
  1408. struct acx_roaming_stats *acx;
  1409. int ret = 0;
  1410. wl1271_debug(DEBUG_ACX, "acx roaming statistics");
  1411. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1412. if (!acx) {
  1413. ret = -ENOMEM;
  1414. goto out;
  1415. }
  1416. acx->role_id = wlvif->role_id;
  1417. ret = wl1271_cmd_interrogate(wl, ACX_ROAMING_STATISTICS_TBL,
  1418. acx, sizeof(*acx), sizeof(*acx));
  1419. if (ret < 0) {
  1420. wl1271_warning("acx roaming statistics failed: %d", ret);
  1421. ret = -ENOMEM;
  1422. goto out;
  1423. }
  1424. *avg_rssi = acx->rssi_beacon;
  1425. out:
  1426. kfree(acx);
  1427. return ret;
  1428. }
  1429. #ifdef CONFIG_PM
  1430. /* Set the global behaviour of RX filters - On/Off + default action */
  1431. int wl1271_acx_default_rx_filter_enable(struct wl1271 *wl, bool enable,
  1432. enum rx_filter_action action)
  1433. {
  1434. struct acx_default_rx_filter *acx;
  1435. int ret;
  1436. wl1271_debug(DEBUG_ACX, "acx default rx filter en: %d act: %d",
  1437. enable, action);
  1438. acx = kzalloc(sizeof(*acx), GFP_KERNEL);
  1439. if (!acx)
  1440. return -ENOMEM;
  1441. acx->enable = enable;
  1442. acx->default_action = action;
  1443. ret = wl1271_cmd_configure(wl, ACX_ENABLE_RX_DATA_FILTER, acx,
  1444. sizeof(*acx));
  1445. if (ret < 0) {
  1446. wl1271_warning("acx default rx filter enable failed: %d", ret);
  1447. goto out;
  1448. }
  1449. out:
  1450. kfree(acx);
  1451. return ret;
  1452. }
  1453. /* Configure or disable a specific RX filter pattern */
  1454. int wl1271_acx_set_rx_filter(struct wl1271 *wl, u8 index, bool enable,
  1455. struct wl12xx_rx_filter *filter)
  1456. {
  1457. struct acx_rx_filter_cfg *acx;
  1458. int fields_size = 0;
  1459. int acx_size;
  1460. int ret;
  1461. WARN_ON(enable && !filter);
  1462. WARN_ON(index >= WL1271_MAX_RX_FILTERS);
  1463. wl1271_debug(DEBUG_ACX,
  1464. "acx set rx filter idx: %d enable: %d filter: %p",
  1465. index, enable, filter);
  1466. if (enable) {
  1467. fields_size = wl1271_rx_filter_get_fields_size(filter);
  1468. wl1271_debug(DEBUG_ACX, "act: %d num_fields: %d field_size: %d",
  1469. filter->action, filter->num_fields, fields_size);
  1470. }
  1471. acx_size = ALIGN(sizeof(*acx) + fields_size, 4);
  1472. acx = kzalloc(acx_size, GFP_KERNEL);
  1473. if (!acx)
  1474. return -ENOMEM;
  1475. acx->enable = enable;
  1476. acx->index = index;
  1477. if (enable) {
  1478. acx->num_fields = filter->num_fields;
  1479. acx->action = filter->action;
  1480. wl1271_rx_filter_flatten_fields(filter, acx->fields);
  1481. }
  1482. wl1271_dump(DEBUG_ACX, "RX_FILTER: ", acx, acx_size);
  1483. ret = wl1271_cmd_configure(wl, ACX_SET_RX_DATA_FILTER, acx, acx_size);
  1484. if (ret < 0) {
  1485. wl1271_warning("setting rx filter failed: %d", ret);
  1486. goto out;
  1487. }
  1488. out:
  1489. kfree(acx);
  1490. return ret;
  1491. }
  1492. #endif /* CONFIG_PM */