acx.c 38 KB

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