cmd.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009-2010 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 <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/ieee80211.h>
  28. #include <linux/slab.h>
  29. #include "wl12xx.h"
  30. #include "debug.h"
  31. #include "reg.h"
  32. #include "io.h"
  33. #include "acx.h"
  34. #include "wl12xx_80211.h"
  35. #include "cmd.h"
  36. #include "event.h"
  37. #include "tx.h"
  38. #define WL1271_CMD_FAST_POLL_COUNT 50
  39. /*
  40. * send command to firmware
  41. *
  42. * @wl: wl struct
  43. * @id: command id
  44. * @buf: buffer containing the command, must work with dma
  45. * @len: length of the buffer
  46. */
  47. int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
  48. size_t res_len)
  49. {
  50. struct wl1271_cmd_header *cmd;
  51. unsigned long timeout;
  52. u32 intr;
  53. int ret = 0;
  54. u16 status;
  55. u16 poll_count = 0;
  56. cmd = buf;
  57. cmd->id = cpu_to_le16(id);
  58. cmd->status = 0;
  59. WARN_ON(len % 4 != 0);
  60. WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
  61. wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
  62. wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
  63. timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
  64. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  65. while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
  66. if (time_after(jiffies, timeout)) {
  67. wl1271_error("command complete timeout");
  68. ret = -ETIMEDOUT;
  69. goto fail;
  70. }
  71. poll_count++;
  72. if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
  73. udelay(10);
  74. else
  75. msleep(1);
  76. intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
  77. }
  78. /* read back the status code of the command */
  79. if (res_len == 0)
  80. res_len = sizeof(struct wl1271_cmd_header);
  81. wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
  82. status = le16_to_cpu(cmd->status);
  83. if (status != CMD_STATUS_SUCCESS) {
  84. wl1271_error("command execute failure %d", status);
  85. ret = -EIO;
  86. goto fail;
  87. }
  88. wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
  89. WL1271_ACX_INTR_CMD_COMPLETE);
  90. return 0;
  91. fail:
  92. WARN_ON(1);
  93. wl12xx_queue_recovery_work(wl);
  94. return ret;
  95. }
  96. int wl1271_cmd_general_parms(struct wl1271 *wl)
  97. {
  98. struct wl1271_general_parms_cmd *gen_parms;
  99. struct wl1271_ini_general_params *gp =
  100. &((struct wl1271_nvs_file *)wl->nvs)->general_params;
  101. bool answer = false;
  102. int ret;
  103. if (!wl->nvs)
  104. return -ENODEV;
  105. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  106. wl1271_warning("FEM index from INI out of bounds");
  107. return -EINVAL;
  108. }
  109. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  110. if (!gen_parms)
  111. return -ENOMEM;
  112. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  113. memcpy(&gen_parms->general_params, gp, sizeof(*gp));
  114. if (gp->tx_bip_fem_auto_detect)
  115. answer = true;
  116. /* Override the REF CLK from the NVS with the one from platform data */
  117. gen_parms->general_params.ref_clock = wl->ref_clock;
  118. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
  119. if (ret < 0) {
  120. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  121. goto out;
  122. }
  123. gp->tx_bip_fem_manufacturer =
  124. gen_parms->general_params.tx_bip_fem_manufacturer;
  125. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  126. wl1271_warning("FEM index from FW out of bounds");
  127. ret = -EINVAL;
  128. goto out;
  129. }
  130. wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
  131. answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
  132. out:
  133. kfree(gen_parms);
  134. return ret;
  135. }
  136. int wl128x_cmd_general_parms(struct wl1271 *wl)
  137. {
  138. struct wl128x_general_parms_cmd *gen_parms;
  139. struct wl128x_ini_general_params *gp =
  140. &((struct wl128x_nvs_file *)wl->nvs)->general_params;
  141. bool answer = false;
  142. int ret;
  143. if (!wl->nvs)
  144. return -ENODEV;
  145. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  146. wl1271_warning("FEM index from ini out of bounds");
  147. return -EINVAL;
  148. }
  149. gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
  150. if (!gen_parms)
  151. return -ENOMEM;
  152. gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
  153. memcpy(&gen_parms->general_params, gp, sizeof(*gp));
  154. if (gp->tx_bip_fem_auto_detect)
  155. answer = true;
  156. /* Replace REF and TCXO CLKs with the ones from platform data */
  157. gen_parms->general_params.ref_clock = wl->ref_clock;
  158. gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
  159. ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
  160. if (ret < 0) {
  161. wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
  162. goto out;
  163. }
  164. gp->tx_bip_fem_manufacturer =
  165. gen_parms->general_params.tx_bip_fem_manufacturer;
  166. if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
  167. wl1271_warning("FEM index from FW out of bounds");
  168. ret = -EINVAL;
  169. goto out;
  170. }
  171. wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
  172. answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
  173. out:
  174. kfree(gen_parms);
  175. return ret;
  176. }
  177. int wl1271_cmd_radio_parms(struct wl1271 *wl)
  178. {
  179. struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
  180. struct wl1271_radio_parms_cmd *radio_parms;
  181. struct wl1271_ini_general_params *gp = &nvs->general_params;
  182. int ret;
  183. if (!wl->nvs)
  184. return -ENODEV;
  185. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  186. if (!radio_parms)
  187. return -ENOMEM;
  188. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  189. /* 2.4GHz parameters */
  190. memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
  191. sizeof(struct wl1271_ini_band_params_2));
  192. memcpy(&radio_parms->dyn_params_2,
  193. &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  194. sizeof(struct wl1271_ini_fem_params_2));
  195. /* 5GHz parameters */
  196. memcpy(&radio_parms->static_params_5,
  197. &nvs->stat_radio_params_5,
  198. sizeof(struct wl1271_ini_band_params_5));
  199. memcpy(&radio_parms->dyn_params_5,
  200. &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  201. sizeof(struct wl1271_ini_fem_params_5));
  202. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  203. radio_parms, sizeof(*radio_parms));
  204. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  205. if (ret < 0)
  206. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  207. kfree(radio_parms);
  208. return ret;
  209. }
  210. int wl128x_cmd_radio_parms(struct wl1271 *wl)
  211. {
  212. struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
  213. struct wl128x_radio_parms_cmd *radio_parms;
  214. struct wl128x_ini_general_params *gp = &nvs->general_params;
  215. int ret;
  216. if (!wl->nvs)
  217. return -ENODEV;
  218. radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
  219. if (!radio_parms)
  220. return -ENOMEM;
  221. radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
  222. /* 2.4GHz parameters */
  223. memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
  224. sizeof(struct wl128x_ini_band_params_2));
  225. memcpy(&radio_parms->dyn_params_2,
  226. &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
  227. sizeof(struct wl128x_ini_fem_params_2));
  228. /* 5GHz parameters */
  229. memcpy(&radio_parms->static_params_5,
  230. &nvs->stat_radio_params_5,
  231. sizeof(struct wl128x_ini_band_params_5));
  232. memcpy(&radio_parms->dyn_params_5,
  233. &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
  234. sizeof(struct wl128x_ini_fem_params_5));
  235. radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
  236. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
  237. radio_parms, sizeof(*radio_parms));
  238. ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
  239. if (ret < 0)
  240. wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
  241. kfree(radio_parms);
  242. return ret;
  243. }
  244. int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
  245. {
  246. struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
  247. struct conf_rf_settings *rf = &wl->conf.rf;
  248. int ret;
  249. if (!wl->nvs)
  250. return -ENODEV;
  251. ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
  252. if (!ext_radio_parms)
  253. return -ENOMEM;
  254. ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
  255. memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
  256. rf->tx_per_channel_power_compensation_2,
  257. CONF_TX_PWR_COMPENSATION_LEN_2);
  258. memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
  259. rf->tx_per_channel_power_compensation_5,
  260. CONF_TX_PWR_COMPENSATION_LEN_5);
  261. wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
  262. ext_radio_parms, sizeof(*ext_radio_parms));
  263. ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
  264. if (ret < 0)
  265. wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
  266. kfree(ext_radio_parms);
  267. return ret;
  268. }
  269. /*
  270. * Poll the mailbox event field until any of the bits in the mask is set or a
  271. * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
  272. */
  273. static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
  274. {
  275. u32 events_vector, event;
  276. unsigned long timeout;
  277. timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
  278. do {
  279. if (time_after(jiffies, timeout)) {
  280. wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
  281. (int)mask);
  282. return -ETIMEDOUT;
  283. }
  284. msleep(1);
  285. /* read from both event fields */
  286. wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
  287. sizeof(events_vector), false);
  288. event = events_vector & mask;
  289. wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
  290. sizeof(events_vector), false);
  291. event |= events_vector & mask;
  292. } while (!event);
  293. return 0;
  294. }
  295. static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
  296. {
  297. int ret;
  298. ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
  299. if (ret != 0) {
  300. wl12xx_queue_recovery_work(wl);
  301. return ret;
  302. }
  303. return 0;
  304. }
  305. int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
  306. u8 *role_id)
  307. {
  308. struct wl12xx_cmd_role_enable *cmd;
  309. int ret;
  310. wl1271_debug(DEBUG_CMD, "cmd role enable");
  311. if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
  312. return -EBUSY;
  313. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  314. if (!cmd) {
  315. ret = -ENOMEM;
  316. goto out;
  317. }
  318. /* get role id */
  319. cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
  320. if (cmd->role_id >= WL12XX_MAX_ROLES) {
  321. ret = -EBUSY;
  322. goto out_free;
  323. }
  324. memcpy(cmd->mac_address, addr, ETH_ALEN);
  325. cmd->role_type = role_type;
  326. ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
  327. if (ret < 0) {
  328. wl1271_error("failed to initiate cmd role enable");
  329. goto out_free;
  330. }
  331. __set_bit(cmd->role_id, wl->roles_map);
  332. *role_id = cmd->role_id;
  333. out_free:
  334. kfree(cmd);
  335. out:
  336. return ret;
  337. }
  338. int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
  339. {
  340. struct wl12xx_cmd_role_disable *cmd;
  341. int ret;
  342. wl1271_debug(DEBUG_CMD, "cmd role disable");
  343. if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
  344. return -ENOENT;
  345. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  346. if (!cmd) {
  347. ret = -ENOMEM;
  348. goto out;
  349. }
  350. cmd->role_id = *role_id;
  351. ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
  352. if (ret < 0) {
  353. wl1271_error("failed to initiate cmd role disable");
  354. goto out_free;
  355. }
  356. __clear_bit(*role_id, wl->roles_map);
  357. *role_id = WL12XX_INVALID_ROLE_ID;
  358. out_free:
  359. kfree(cmd);
  360. out:
  361. return ret;
  362. }
  363. int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
  364. {
  365. unsigned long flags;
  366. u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
  367. if (link >= WL12XX_MAX_LINKS)
  368. return -EBUSY;
  369. /* these bits are used by op_tx */
  370. spin_lock_irqsave(&wl->wl_lock, flags);
  371. __set_bit(link, wl->links_map);
  372. __set_bit(link, wlvif->links_map);
  373. spin_unlock_irqrestore(&wl->wl_lock, flags);
  374. *hlid = link;
  375. return 0;
  376. }
  377. void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
  378. {
  379. unsigned long flags;
  380. if (*hlid == WL12XX_INVALID_LINK_ID)
  381. return;
  382. /* these bits are used by op_tx */
  383. spin_lock_irqsave(&wl->wl_lock, flags);
  384. __clear_bit(*hlid, wl->links_map);
  385. __clear_bit(*hlid, wlvif->links_map);
  386. spin_unlock_irqrestore(&wl->wl_lock, flags);
  387. *hlid = WL12XX_INVALID_LINK_ID;
  388. }
  389. static int wl12xx_get_new_session_id(struct wl1271 *wl,
  390. struct wl12xx_vif *wlvif)
  391. {
  392. if (wlvif->session_counter >= SESSION_COUNTER_MAX)
  393. wlvif->session_counter = 0;
  394. wlvif->session_counter++;
  395. return wlvif->session_counter;
  396. }
  397. static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
  398. struct wl12xx_vif *wlvif)
  399. {
  400. struct wl12xx_cmd_role_start *cmd;
  401. int ret;
  402. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  403. if (!cmd) {
  404. ret = -ENOMEM;
  405. goto out;
  406. }
  407. wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
  408. cmd->role_id = wlvif->dev_role_id;
  409. if (wlvif->band == IEEE80211_BAND_5GHZ)
  410. cmd->band = WL12XX_BAND_5GHZ;
  411. cmd->channel = wlvif->channel;
  412. if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
  413. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
  414. if (ret)
  415. goto out_free;
  416. }
  417. cmd->device.hlid = wlvif->dev_hlid;
  418. cmd->device.session = wlvif->session_counter;
  419. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
  420. cmd->role_id, cmd->device.hlid, cmd->device.session);
  421. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  422. if (ret < 0) {
  423. wl1271_error("failed to initiate cmd role enable");
  424. goto err_hlid;
  425. }
  426. goto out_free;
  427. err_hlid:
  428. /* clear links on error */
  429. wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
  430. out_free:
  431. kfree(cmd);
  432. out:
  433. return ret;
  434. }
  435. static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
  436. struct wl12xx_vif *wlvif)
  437. {
  438. struct wl12xx_cmd_role_stop *cmd;
  439. int ret;
  440. if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
  441. return -EINVAL;
  442. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  443. if (!cmd) {
  444. ret = -ENOMEM;
  445. goto out;
  446. }
  447. wl1271_debug(DEBUG_CMD, "cmd role stop dev");
  448. cmd->role_id = wlvif->dev_role_id;
  449. cmd->disc_type = DISCONNECT_IMMEDIATE;
  450. cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
  451. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  452. if (ret < 0) {
  453. wl1271_error("failed to initiate cmd role stop");
  454. goto out_free;
  455. }
  456. ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
  457. if (ret < 0) {
  458. wl1271_error("cmd role stop dev event completion error");
  459. goto out_free;
  460. }
  461. wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
  462. out_free:
  463. kfree(cmd);
  464. out:
  465. return ret;
  466. }
  467. int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  468. {
  469. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  470. struct wl12xx_cmd_role_start *cmd;
  471. int ret;
  472. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  473. if (!cmd) {
  474. ret = -ENOMEM;
  475. goto out;
  476. }
  477. wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
  478. cmd->role_id = wlvif->role_id;
  479. if (wlvif->band == IEEE80211_BAND_5GHZ)
  480. cmd->band = WL12XX_BAND_5GHZ;
  481. cmd->channel = wlvif->channel;
  482. cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  483. cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  484. cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
  485. cmd->sta.ssid_len = wlvif->ssid_len;
  486. memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
  487. memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
  488. cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
  489. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
  490. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
  491. if (ret)
  492. goto out_free;
  493. }
  494. cmd->sta.hlid = wlvif->sta.hlid;
  495. cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
  496. cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
  497. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
  498. "basic_rate_set: 0x%x, remote_rates: 0x%x",
  499. wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
  500. wlvif->basic_rate_set, wlvif->rate_set);
  501. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  502. if (ret < 0) {
  503. wl1271_error("failed to initiate cmd role start sta");
  504. goto err_hlid;
  505. }
  506. goto out_free;
  507. err_hlid:
  508. /* clear links on error. */
  509. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  510. out_free:
  511. kfree(cmd);
  512. out:
  513. return ret;
  514. }
  515. /* use this function to stop ibss as well */
  516. int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  517. {
  518. struct wl12xx_cmd_role_stop *cmd;
  519. int ret;
  520. if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
  521. return -EINVAL;
  522. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  523. if (!cmd) {
  524. ret = -ENOMEM;
  525. goto out;
  526. }
  527. wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
  528. cmd->role_id = wlvif->role_id;
  529. cmd->disc_type = DISCONNECT_IMMEDIATE;
  530. cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
  531. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  532. if (ret < 0) {
  533. wl1271_error("failed to initiate cmd role stop sta");
  534. goto out_free;
  535. }
  536. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  537. out_free:
  538. kfree(cmd);
  539. out:
  540. return ret;
  541. }
  542. int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  543. {
  544. struct wl12xx_cmd_role_start *cmd;
  545. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  546. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  547. int ret;
  548. wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
  549. /* trying to use hidden SSID with an old hostapd version */
  550. if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
  551. wl1271_error("got a null SSID from beacon/bss");
  552. ret = -EINVAL;
  553. goto out;
  554. }
  555. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  556. if (!cmd) {
  557. ret = -ENOMEM;
  558. goto out;
  559. }
  560. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
  561. if (ret < 0)
  562. goto out_free;
  563. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  564. if (ret < 0)
  565. goto out_free_global;
  566. cmd->role_id = wlvif->role_id;
  567. cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
  568. cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
  569. cmd->ap.global_hlid = wlvif->ap.global_hlid;
  570. cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
  571. cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  572. cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  573. cmd->ap.dtim_interval = bss_conf->dtim_period;
  574. cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
  575. /* FIXME: Change when adding DFS */
  576. cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
  577. cmd->channel = wlvif->channel;
  578. if (!bss_conf->hidden_ssid) {
  579. /* take the SSID from the beacon for backward compatibility */
  580. cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
  581. cmd->ap.ssid_len = wlvif->ssid_len;
  582. memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
  583. } else {
  584. cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
  585. cmd->ap.ssid_len = bss_conf->ssid_len;
  586. memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
  587. }
  588. cmd->ap.local_rates = cpu_to_le32(0xffffffff);
  589. switch (wlvif->band) {
  590. case IEEE80211_BAND_2GHZ:
  591. cmd->band = RADIO_BAND_2_4GHZ;
  592. break;
  593. case IEEE80211_BAND_5GHZ:
  594. cmd->band = RADIO_BAND_5GHZ;
  595. break;
  596. default:
  597. wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
  598. cmd->band = RADIO_BAND_2_4GHZ;
  599. break;
  600. }
  601. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  602. if (ret < 0) {
  603. wl1271_error("failed to initiate cmd role start ap");
  604. goto out_free_bcast;
  605. }
  606. goto out_free;
  607. out_free_bcast:
  608. wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  609. out_free_global:
  610. wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
  611. out_free:
  612. kfree(cmd);
  613. out:
  614. return ret;
  615. }
  616. int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  617. {
  618. struct wl12xx_cmd_role_stop *cmd;
  619. int ret;
  620. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  621. if (!cmd) {
  622. ret = -ENOMEM;
  623. goto out;
  624. }
  625. wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
  626. cmd->role_id = wlvif->role_id;
  627. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  628. if (ret < 0) {
  629. wl1271_error("failed to initiate cmd role stop ap");
  630. goto out_free;
  631. }
  632. wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  633. wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
  634. out_free:
  635. kfree(cmd);
  636. out:
  637. return ret;
  638. }
  639. int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  640. {
  641. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  642. struct wl12xx_cmd_role_start *cmd;
  643. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  644. int ret;
  645. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  646. if (!cmd) {
  647. ret = -ENOMEM;
  648. goto out;
  649. }
  650. wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
  651. cmd->role_id = wlvif->role_id;
  652. if (wlvif->band == IEEE80211_BAND_5GHZ)
  653. cmd->band = WL12XX_BAND_5GHZ;
  654. cmd->channel = wlvif->channel;
  655. cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  656. cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  657. cmd->ibss.dtim_interval = bss_conf->dtim_period;
  658. cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
  659. cmd->ibss.ssid_len = wlvif->ssid_len;
  660. memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
  661. memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
  662. cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
  663. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
  664. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
  665. if (ret)
  666. goto out_free;
  667. }
  668. cmd->ibss.hlid = wlvif->sta.hlid;
  669. cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
  670. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
  671. "basic_rate_set: 0x%x, remote_rates: 0x%x",
  672. wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
  673. wlvif->basic_rate_set, wlvif->rate_set);
  674. wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
  675. vif->bss_conf.bssid);
  676. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  677. if (ret < 0) {
  678. wl1271_error("failed to initiate cmd role enable");
  679. goto err_hlid;
  680. }
  681. goto out_free;
  682. err_hlid:
  683. /* clear links on error. */
  684. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  685. out_free:
  686. kfree(cmd);
  687. out:
  688. return ret;
  689. }
  690. /**
  691. * send test command to firmware
  692. *
  693. * @wl: wl struct
  694. * @buf: buffer containing the command, with all headers, must work with dma
  695. * @len: length of the buffer
  696. * @answer: is answer needed
  697. */
  698. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  699. {
  700. int ret;
  701. size_t res_len = 0;
  702. wl1271_debug(DEBUG_CMD, "cmd test");
  703. if (answer)
  704. res_len = buf_len;
  705. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  706. if (ret < 0) {
  707. wl1271_warning("TEST command failed");
  708. return ret;
  709. }
  710. return ret;
  711. }
  712. /**
  713. * read acx from firmware
  714. *
  715. * @wl: wl struct
  716. * @id: acx id
  717. * @buf: buffer for the response, including all headers, must work with dma
  718. * @len: length of buf
  719. */
  720. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  721. {
  722. struct acx_header *acx = buf;
  723. int ret;
  724. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  725. acx->id = cpu_to_le16(id);
  726. /* payload length, does not include any headers */
  727. acx->len = cpu_to_le16(len - sizeof(*acx));
  728. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  729. if (ret < 0)
  730. wl1271_error("INTERROGATE command failed");
  731. return ret;
  732. }
  733. /**
  734. * write acx value to firmware
  735. *
  736. * @wl: wl struct
  737. * @id: acx id
  738. * @buf: buffer containing acx, including all headers, must work with dma
  739. * @len: length of buf
  740. */
  741. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  742. {
  743. struct acx_header *acx = buf;
  744. int ret;
  745. wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
  746. acx->id = cpu_to_le16(id);
  747. /* payload length, does not include any headers */
  748. acx->len = cpu_to_le16(len - sizeof(*acx));
  749. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  750. if (ret < 0) {
  751. wl1271_warning("CONFIGURE command NOK");
  752. return ret;
  753. }
  754. return 0;
  755. }
  756. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  757. {
  758. struct cmd_enabledisable_path *cmd;
  759. int ret;
  760. u16 cmd_rx, cmd_tx;
  761. wl1271_debug(DEBUG_CMD, "cmd data path");
  762. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  763. if (!cmd) {
  764. ret = -ENOMEM;
  765. goto out;
  766. }
  767. /* the channel here is only used for calibration, so hardcoded to 1 */
  768. cmd->channel = 1;
  769. if (enable) {
  770. cmd_rx = CMD_ENABLE_RX;
  771. cmd_tx = CMD_ENABLE_TX;
  772. } else {
  773. cmd_rx = CMD_DISABLE_RX;
  774. cmd_tx = CMD_DISABLE_TX;
  775. }
  776. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  777. if (ret < 0) {
  778. wl1271_error("rx %s cmd for channel %d failed",
  779. enable ? "start" : "stop", cmd->channel);
  780. goto out;
  781. }
  782. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  783. enable ? "start" : "stop", cmd->channel);
  784. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  785. if (ret < 0) {
  786. wl1271_error("tx %s cmd for channel %d failed",
  787. enable ? "start" : "stop", cmd->channel);
  788. goto out;
  789. }
  790. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  791. enable ? "start" : "stop", cmd->channel);
  792. out:
  793. kfree(cmd);
  794. return ret;
  795. }
  796. int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  797. u8 ps_mode, u16 auto_ps_timeout)
  798. {
  799. struct wl1271_cmd_ps_params *ps_params = NULL;
  800. int ret = 0;
  801. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  802. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  803. if (!ps_params) {
  804. ret = -ENOMEM;
  805. goto out;
  806. }
  807. ps_params->role_id = wlvif->role_id;
  808. ps_params->ps_mode = ps_mode;
  809. ps_params->auto_ps_timeout = auto_ps_timeout;
  810. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  811. sizeof(*ps_params), 0);
  812. if (ret < 0) {
  813. wl1271_error("cmd set_ps_mode failed");
  814. goto out;
  815. }
  816. out:
  817. kfree(ps_params);
  818. return ret;
  819. }
  820. int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
  821. u16 template_id, void *buf, size_t buf_len,
  822. int index, u32 rates)
  823. {
  824. struct wl1271_cmd_template_set *cmd;
  825. int ret = 0;
  826. wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
  827. template_id, role_id);
  828. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  829. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  830. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  831. if (!cmd) {
  832. ret = -ENOMEM;
  833. goto out;
  834. }
  835. /* during initialization wlvif is NULL */
  836. cmd->role_id = role_id;
  837. cmd->len = cpu_to_le16(buf_len);
  838. cmd->template_type = template_id;
  839. cmd->enabled_rates = cpu_to_le32(rates);
  840. cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
  841. cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
  842. cmd->index = index;
  843. if (buf)
  844. memcpy(cmd->template_data, buf, buf_len);
  845. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  846. if (ret < 0) {
  847. wl1271_warning("cmd set_template failed: %d", ret);
  848. goto out_free;
  849. }
  850. out_free:
  851. kfree(cmd);
  852. out:
  853. return ret;
  854. }
  855. int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  856. {
  857. struct sk_buff *skb = NULL;
  858. int size;
  859. void *ptr;
  860. int ret = -ENOMEM;
  861. if (wlvif->bss_type == BSS_TYPE_IBSS) {
  862. size = sizeof(struct wl12xx_null_data_template);
  863. ptr = NULL;
  864. } else {
  865. skb = ieee80211_nullfunc_get(wl->hw,
  866. wl12xx_wlvif_to_vif(wlvif));
  867. if (!skb)
  868. goto out;
  869. size = skb->len;
  870. ptr = skb->data;
  871. }
  872. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  873. CMD_TEMPL_NULL_DATA, ptr, size, 0,
  874. wlvif->basic_rate);
  875. out:
  876. dev_kfree_skb(skb);
  877. if (ret)
  878. wl1271_warning("cmd buld null data failed %d", ret);
  879. return ret;
  880. }
  881. int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
  882. struct wl12xx_vif *wlvif)
  883. {
  884. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  885. struct sk_buff *skb = NULL;
  886. int ret = -ENOMEM;
  887. skb = ieee80211_nullfunc_get(wl->hw, vif);
  888. if (!skb)
  889. goto out;
  890. ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
  891. skb->data, skb->len,
  892. CMD_TEMPL_KLV_IDX_NULL_DATA,
  893. wlvif->basic_rate);
  894. out:
  895. dev_kfree_skb(skb);
  896. if (ret)
  897. wl1271_warning("cmd build klv null data failed %d", ret);
  898. return ret;
  899. }
  900. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  901. u16 aid)
  902. {
  903. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  904. struct sk_buff *skb;
  905. int ret = 0;
  906. skb = ieee80211_pspoll_get(wl->hw, vif);
  907. if (!skb)
  908. goto out;
  909. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  910. CMD_TEMPL_PS_POLL, skb->data,
  911. skb->len, 0, wlvif->basic_rate_set);
  912. out:
  913. dev_kfree_skb(skb);
  914. return ret;
  915. }
  916. int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  917. u8 role_id, u8 band,
  918. const u8 *ssid, size_t ssid_len,
  919. const u8 *ie, size_t ie_len)
  920. {
  921. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  922. struct sk_buff *skb;
  923. int ret;
  924. u32 rate;
  925. skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
  926. ie, ie_len);
  927. if (!skb) {
  928. ret = -ENOMEM;
  929. goto out;
  930. }
  931. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  932. rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
  933. if (band == IEEE80211_BAND_2GHZ)
  934. ret = wl1271_cmd_template_set(wl, role_id,
  935. CMD_TEMPL_CFG_PROBE_REQ_2_4,
  936. skb->data, skb->len, 0, rate);
  937. else
  938. ret = wl1271_cmd_template_set(wl, role_id,
  939. CMD_TEMPL_CFG_PROBE_REQ_5,
  940. skb->data, skb->len, 0, rate);
  941. out:
  942. dev_kfree_skb(skb);
  943. return ret;
  944. }
  945. struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
  946. struct wl12xx_vif *wlvif,
  947. struct sk_buff *skb)
  948. {
  949. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  950. int ret;
  951. u32 rate;
  952. if (!skb)
  953. skb = ieee80211_ap_probereq_get(wl->hw, vif);
  954. if (!skb)
  955. goto out;
  956. wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
  957. rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
  958. if (wlvif->band == IEEE80211_BAND_2GHZ)
  959. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  960. CMD_TEMPL_CFG_PROBE_REQ_2_4,
  961. skb->data, skb->len, 0, rate);
  962. else
  963. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  964. CMD_TEMPL_CFG_PROBE_REQ_5,
  965. skb->data, skb->len, 0, rate);
  966. if (ret < 0)
  967. wl1271_error("Unable to set ap probe request template.");
  968. out:
  969. return skb;
  970. }
  971. int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  972. {
  973. int ret, extra;
  974. u16 fc;
  975. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  976. struct sk_buff *skb;
  977. struct wl12xx_arp_rsp_template *tmpl;
  978. struct ieee80211_hdr_3addr *hdr;
  979. struct arphdr *arp_hdr;
  980. skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
  981. WL1271_EXTRA_SPACE_MAX);
  982. if (!skb) {
  983. wl1271_error("failed to allocate buffer for arp rsp template");
  984. return -ENOMEM;
  985. }
  986. skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
  987. tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
  988. memset(tmpl, 0, sizeof(tmpl));
  989. /* llc layer */
  990. memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
  991. tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
  992. /* arp header */
  993. arp_hdr = &tmpl->arp_hdr;
  994. arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
  995. arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
  996. arp_hdr->ar_hln = ETH_ALEN;
  997. arp_hdr->ar_pln = 4;
  998. arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
  999. /* arp payload */
  1000. memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
  1001. tmpl->sender_ip = wlvif->ip_addr;
  1002. /* encryption space */
  1003. switch (wlvif->encryption_type) {
  1004. case KEY_TKIP:
  1005. extra = WL1271_EXTRA_SPACE_TKIP;
  1006. break;
  1007. case KEY_AES:
  1008. extra = WL1271_EXTRA_SPACE_AES;
  1009. break;
  1010. case KEY_NONE:
  1011. case KEY_WEP:
  1012. case KEY_GEM:
  1013. extra = 0;
  1014. break;
  1015. default:
  1016. wl1271_warning("Unknown encryption type: %d",
  1017. wlvif->encryption_type);
  1018. ret = -EINVAL;
  1019. goto out;
  1020. }
  1021. if (extra) {
  1022. u8 *space = skb_push(skb, extra);
  1023. memset(space, 0, extra);
  1024. }
  1025. /* QoS header - BE */
  1026. if (wlvif->sta.qos)
  1027. memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
  1028. /* mac80211 header */
  1029. hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
  1030. memset(hdr, 0, sizeof(hdr));
  1031. fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
  1032. if (wlvif->sta.qos)
  1033. fc |= IEEE80211_STYPE_QOS_DATA;
  1034. else
  1035. fc |= IEEE80211_STYPE_DATA;
  1036. if (wlvif->encryption_type != KEY_NONE)
  1037. fc |= IEEE80211_FCTL_PROTECTED;
  1038. hdr->frame_control = cpu_to_le16(fc);
  1039. memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
  1040. memcpy(hdr->addr2, vif->addr, ETH_ALEN);
  1041. memset(hdr->addr3, 0xff, ETH_ALEN);
  1042. ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
  1043. skb->data, skb->len, 0,
  1044. wlvif->basic_rate);
  1045. out:
  1046. dev_kfree_skb(skb);
  1047. return ret;
  1048. }
  1049. int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
  1050. {
  1051. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  1052. struct ieee80211_qos_hdr template;
  1053. memset(&template, 0, sizeof(template));
  1054. memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
  1055. memcpy(template.addr2, vif->addr, ETH_ALEN);
  1056. memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
  1057. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  1058. IEEE80211_STYPE_QOS_NULLFUNC |
  1059. IEEE80211_FCTL_TODS);
  1060. /* FIXME: not sure what priority to use here */
  1061. template.qos_ctrl = cpu_to_le16(0);
  1062. return wl1271_cmd_template_set(wl, wlvif->role_id,
  1063. CMD_TEMPL_QOS_NULL_DATA, &template,
  1064. sizeof(template), 0,
  1065. wlvif->basic_rate);
  1066. }
  1067. int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
  1068. {
  1069. struct wl1271_cmd_set_keys *cmd;
  1070. int ret = 0;
  1071. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  1072. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1073. if (!cmd) {
  1074. ret = -ENOMEM;
  1075. goto out;
  1076. }
  1077. cmd->hlid = hlid;
  1078. cmd->key_id = id;
  1079. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  1080. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  1081. cmd->key_type = KEY_WEP;
  1082. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1083. if (ret < 0) {
  1084. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  1085. goto out;
  1086. }
  1087. out:
  1088. kfree(cmd);
  1089. return ret;
  1090. }
  1091. int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1092. u16 action, u8 id, u8 key_type,
  1093. u8 key_size, const u8 *key, const u8 *addr,
  1094. u32 tx_seq_32, u16 tx_seq_16)
  1095. {
  1096. struct wl1271_cmd_set_keys *cmd;
  1097. int ret = 0;
  1098. /* hlid might have already been deleted */
  1099. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
  1100. return 0;
  1101. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1102. if (!cmd) {
  1103. ret = -ENOMEM;
  1104. goto out;
  1105. }
  1106. cmd->hlid = wlvif->sta.hlid;
  1107. if (key_type == KEY_WEP)
  1108. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  1109. else if (is_broadcast_ether_addr(addr))
  1110. cmd->lid_key_type = BROADCAST_LID_TYPE;
  1111. else
  1112. cmd->lid_key_type = UNICAST_LID_TYPE;
  1113. cmd->key_action = cpu_to_le16(action);
  1114. cmd->key_size = key_size;
  1115. cmd->key_type = key_type;
  1116. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  1117. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  1118. cmd->key_id = id;
  1119. if (key_type == KEY_TKIP) {
  1120. /*
  1121. * We get the key in the following form:
  1122. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  1123. * but the target is expecting:
  1124. * TKIP - RX MIC - TX MIC
  1125. */
  1126. memcpy(cmd->key, key, 16);
  1127. memcpy(cmd->key + 16, key + 24, 8);
  1128. memcpy(cmd->key + 24, key + 16, 8);
  1129. } else {
  1130. memcpy(cmd->key, key, key_size);
  1131. }
  1132. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  1133. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1134. if (ret < 0) {
  1135. wl1271_warning("could not set keys");
  1136. goto out;
  1137. }
  1138. out:
  1139. kfree(cmd);
  1140. return ret;
  1141. }
  1142. /*
  1143. * TODO: merge with sta/ibss into 1 set_key function.
  1144. * note there are slight diffs
  1145. */
  1146. int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1147. u16 action, u8 id, u8 key_type,
  1148. u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
  1149. u16 tx_seq_16)
  1150. {
  1151. struct wl1271_cmd_set_keys *cmd;
  1152. int ret = 0;
  1153. u8 lid_type;
  1154. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1155. if (!cmd)
  1156. return -ENOMEM;
  1157. if (hlid == wlvif->ap.bcast_hlid) {
  1158. if (key_type == KEY_WEP)
  1159. lid_type = WEP_DEFAULT_LID_TYPE;
  1160. else
  1161. lid_type = BROADCAST_LID_TYPE;
  1162. } else {
  1163. lid_type = UNICAST_LID_TYPE;
  1164. }
  1165. wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
  1166. " hlid: %d", (int)action, (int)id, (int)lid_type,
  1167. (int)key_type, (int)hlid);
  1168. cmd->lid_key_type = lid_type;
  1169. cmd->hlid = hlid;
  1170. cmd->key_action = cpu_to_le16(action);
  1171. cmd->key_size = key_size;
  1172. cmd->key_type = key_type;
  1173. cmd->key_id = id;
  1174. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  1175. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  1176. if (key_type == KEY_TKIP) {
  1177. /*
  1178. * We get the key in the following form:
  1179. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  1180. * but the target is expecting:
  1181. * TKIP - RX MIC - TX MIC
  1182. */
  1183. memcpy(cmd->key, key, 16);
  1184. memcpy(cmd->key + 16, key + 24, 8);
  1185. memcpy(cmd->key + 24, key + 16, 8);
  1186. } else {
  1187. memcpy(cmd->key, key, key_size);
  1188. }
  1189. wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
  1190. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1191. if (ret < 0) {
  1192. wl1271_warning("could not set ap keys");
  1193. goto out;
  1194. }
  1195. out:
  1196. kfree(cmd);
  1197. return ret;
  1198. }
  1199. int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
  1200. {
  1201. struct wl12xx_cmd_set_peer_state *cmd;
  1202. int ret = 0;
  1203. wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
  1204. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1205. if (!cmd) {
  1206. ret = -ENOMEM;
  1207. goto out;
  1208. }
  1209. cmd->hlid = hlid;
  1210. cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
  1211. ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
  1212. if (ret < 0) {
  1213. wl1271_error("failed to send set peer state command");
  1214. goto out_free;
  1215. }
  1216. out_free:
  1217. kfree(cmd);
  1218. out:
  1219. return ret;
  1220. }
  1221. int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1222. struct ieee80211_sta *sta, u8 hlid)
  1223. {
  1224. struct wl12xx_cmd_add_peer *cmd;
  1225. int i, ret;
  1226. u32 sta_rates;
  1227. wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
  1228. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1229. if (!cmd) {
  1230. ret = -ENOMEM;
  1231. goto out;
  1232. }
  1233. memcpy(cmd->addr, sta->addr, ETH_ALEN);
  1234. cmd->bss_index = WL1271_AP_BSS_INDEX;
  1235. cmd->aid = sta->aid;
  1236. cmd->hlid = hlid;
  1237. cmd->sp_len = sta->max_sp;
  1238. cmd->wmm = sta->wme ? 1 : 0;
  1239. for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
  1240. if (sta->wme && (sta->uapsd_queues & BIT(i)))
  1241. cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
  1242. else
  1243. cmd->psd_type[i] = WL1271_PSD_LEGACY;
  1244. sta_rates = sta->supp_rates[wlvif->band];
  1245. if (sta->ht_cap.ht_supported)
  1246. sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
  1247. cmd->supported_rates =
  1248. cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
  1249. wlvif->band));
  1250. wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
  1251. cmd->supported_rates, sta->uapsd_queues);
  1252. ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
  1253. if (ret < 0) {
  1254. wl1271_error("failed to initiate cmd add peer");
  1255. goto out_free;
  1256. }
  1257. out_free:
  1258. kfree(cmd);
  1259. out:
  1260. return ret;
  1261. }
  1262. int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
  1263. {
  1264. struct wl12xx_cmd_remove_peer *cmd;
  1265. int ret;
  1266. wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
  1267. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1268. if (!cmd) {
  1269. ret = -ENOMEM;
  1270. goto out;
  1271. }
  1272. cmd->hlid = hlid;
  1273. /* We never send a deauth, mac80211 is in charge of this */
  1274. cmd->reason_opcode = 0;
  1275. cmd->send_deauth_flag = 0;
  1276. ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
  1277. if (ret < 0) {
  1278. wl1271_error("failed to initiate cmd remove peer");
  1279. goto out_free;
  1280. }
  1281. /*
  1282. * We are ok with a timeout here. The event is sometimes not sent
  1283. * due to a firmware bug.
  1284. */
  1285. wl1271_cmd_wait_for_event_or_timeout(wl,
  1286. PEER_REMOVE_COMPLETE_EVENT_ID);
  1287. out_free:
  1288. kfree(cmd);
  1289. out:
  1290. return ret;
  1291. }
  1292. int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
  1293. {
  1294. struct wl12xx_cmd_config_fwlog *cmd;
  1295. int ret = 0;
  1296. wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
  1297. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1298. if (!cmd) {
  1299. ret = -ENOMEM;
  1300. goto out;
  1301. }
  1302. cmd->logger_mode = wl->conf.fwlog.mode;
  1303. cmd->log_severity = wl->conf.fwlog.severity;
  1304. cmd->timestamp = wl->conf.fwlog.timestamp;
  1305. cmd->output = wl->conf.fwlog.output;
  1306. cmd->threshold = wl->conf.fwlog.threshold;
  1307. ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
  1308. if (ret < 0) {
  1309. wl1271_error("failed to send config firmware logger command");
  1310. goto out_free;
  1311. }
  1312. out_free:
  1313. kfree(cmd);
  1314. out:
  1315. return ret;
  1316. }
  1317. int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
  1318. {
  1319. struct wl12xx_cmd_start_fwlog *cmd;
  1320. int ret = 0;
  1321. wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
  1322. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1323. if (!cmd) {
  1324. ret = -ENOMEM;
  1325. goto out;
  1326. }
  1327. ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
  1328. if (ret < 0) {
  1329. wl1271_error("failed to send start firmware logger command");
  1330. goto out_free;
  1331. }
  1332. out_free:
  1333. kfree(cmd);
  1334. out:
  1335. return ret;
  1336. }
  1337. int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
  1338. {
  1339. struct wl12xx_cmd_stop_fwlog *cmd;
  1340. int ret = 0;
  1341. wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
  1342. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1343. if (!cmd) {
  1344. ret = -ENOMEM;
  1345. goto out;
  1346. }
  1347. ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
  1348. if (ret < 0) {
  1349. wl1271_error("failed to send stop firmware logger command");
  1350. goto out_free;
  1351. }
  1352. out_free:
  1353. kfree(cmd);
  1354. out:
  1355. return ret;
  1356. }
  1357. static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1358. u8 role_id)
  1359. {
  1360. struct wl12xx_cmd_roc *cmd;
  1361. int ret = 0;
  1362. wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
  1363. if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
  1364. return -EINVAL;
  1365. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1366. if (!cmd) {
  1367. ret = -ENOMEM;
  1368. goto out;
  1369. }
  1370. cmd->role_id = role_id;
  1371. cmd->channel = wlvif->channel;
  1372. switch (wlvif->band) {
  1373. case IEEE80211_BAND_2GHZ:
  1374. cmd->band = RADIO_BAND_2_4GHZ;
  1375. break;
  1376. case IEEE80211_BAND_5GHZ:
  1377. cmd->band = RADIO_BAND_5GHZ;
  1378. break;
  1379. default:
  1380. wl1271_error("roc - unknown band: %d", (int)wlvif->band);
  1381. ret = -EINVAL;
  1382. goto out_free;
  1383. }
  1384. ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
  1385. if (ret < 0) {
  1386. wl1271_error("failed to send ROC command");
  1387. goto out_free;
  1388. }
  1389. out_free:
  1390. kfree(cmd);
  1391. out:
  1392. return ret;
  1393. }
  1394. static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
  1395. {
  1396. struct wl12xx_cmd_croc *cmd;
  1397. int ret = 0;
  1398. wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
  1399. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1400. if (!cmd) {
  1401. ret = -ENOMEM;
  1402. goto out;
  1403. }
  1404. cmd->role_id = role_id;
  1405. ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
  1406. sizeof(*cmd), 0);
  1407. if (ret < 0) {
  1408. wl1271_error("failed to send ROC command");
  1409. goto out_free;
  1410. }
  1411. out_free:
  1412. kfree(cmd);
  1413. out:
  1414. return ret;
  1415. }
  1416. int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
  1417. {
  1418. int ret = 0;
  1419. if (WARN_ON(test_bit(role_id, wl->roc_map)))
  1420. return 0;
  1421. ret = wl12xx_cmd_roc(wl, wlvif, role_id);
  1422. if (ret < 0)
  1423. goto out;
  1424. ret = wl1271_cmd_wait_for_event(wl,
  1425. REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
  1426. if (ret < 0) {
  1427. wl1271_error("cmd roc event completion error");
  1428. goto out;
  1429. }
  1430. __set_bit(role_id, wl->roc_map);
  1431. out:
  1432. return ret;
  1433. }
  1434. int wl12xx_croc(struct wl1271 *wl, u8 role_id)
  1435. {
  1436. int ret = 0;
  1437. if (WARN_ON(!test_bit(role_id, wl->roc_map)))
  1438. return 0;
  1439. ret = wl12xx_cmd_croc(wl, role_id);
  1440. if (ret < 0)
  1441. goto out;
  1442. __clear_bit(role_id, wl->roc_map);
  1443. out:
  1444. return ret;
  1445. }
  1446. int wl12xx_cmd_channel_switch(struct wl1271 *wl,
  1447. struct wl12xx_vif *wlvif,
  1448. struct ieee80211_channel_switch *ch_switch)
  1449. {
  1450. struct wl12xx_cmd_channel_switch *cmd;
  1451. int ret;
  1452. wl1271_debug(DEBUG_ACX, "cmd channel switch");
  1453. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1454. if (!cmd) {
  1455. ret = -ENOMEM;
  1456. goto out;
  1457. }
  1458. cmd->role_id = wlvif->role_id;
  1459. cmd->channel = ch_switch->channel->hw_value;
  1460. cmd->switch_time = ch_switch->count;
  1461. cmd->stop_tx = ch_switch->block_tx;
  1462. /* FIXME: control from mac80211 in the future */
  1463. cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
  1464. ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
  1465. if (ret < 0) {
  1466. wl1271_error("failed to send channel switch command");
  1467. goto out_free;
  1468. }
  1469. out_free:
  1470. kfree(cmd);
  1471. out:
  1472. return ret;
  1473. }
  1474. int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
  1475. {
  1476. struct wl12xx_cmd_stop_channel_switch *cmd;
  1477. int ret;
  1478. wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
  1479. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1480. if (!cmd) {
  1481. ret = -ENOMEM;
  1482. goto out;
  1483. }
  1484. ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
  1485. if (ret < 0) {
  1486. wl1271_error("failed to stop channel switch command");
  1487. goto out_free;
  1488. }
  1489. out_free:
  1490. kfree(cmd);
  1491. out:
  1492. return ret;
  1493. }
  1494. /* start dev role and roc on its channel */
  1495. int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1496. {
  1497. int ret;
  1498. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1499. wlvif->bss_type == BSS_TYPE_IBSS)))
  1500. return -EINVAL;
  1501. ret = wl12xx_cmd_role_start_dev(wl, wlvif);
  1502. if (ret < 0)
  1503. goto out;
  1504. ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
  1505. if (ret < 0)
  1506. goto out_stop;
  1507. return 0;
  1508. out_stop:
  1509. wl12xx_cmd_role_stop_dev(wl, wlvif);
  1510. out:
  1511. return ret;
  1512. }
  1513. /* croc dev hlid, and stop the role */
  1514. int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1515. {
  1516. int ret;
  1517. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1518. wlvif->bss_type == BSS_TYPE_IBSS)))
  1519. return -EINVAL;
  1520. /* flush all pending packets */
  1521. wl1271_tx_work_locked(wl);
  1522. if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
  1523. ret = wl12xx_croc(wl, wlvif->dev_role_id);
  1524. if (ret < 0)
  1525. goto out;
  1526. }
  1527. ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
  1528. if (ret < 0)
  1529. goto out;
  1530. out:
  1531. return ret;
  1532. }