acx.c 42 KB

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