cmd.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919
  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. u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
  366. if (link >= WL12XX_MAX_LINKS)
  367. return -EBUSY;
  368. __set_bit(link, wl->links_map);
  369. __set_bit(link, wlvif->links_map);
  370. *hlid = link;
  371. return 0;
  372. }
  373. void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
  374. {
  375. if (*hlid == WL12XX_INVALID_LINK_ID)
  376. return;
  377. __clear_bit(*hlid, wl->links_map);
  378. __clear_bit(*hlid, wlvif->links_map);
  379. *hlid = WL12XX_INVALID_LINK_ID;
  380. }
  381. static int wl12xx_get_new_session_id(struct wl1271 *wl,
  382. struct wl12xx_vif *wlvif)
  383. {
  384. if (wlvif->session_counter >= SESSION_COUNTER_MAX)
  385. wlvif->session_counter = 0;
  386. wlvif->session_counter++;
  387. return wlvif->session_counter;
  388. }
  389. static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
  390. struct wl12xx_vif *wlvif)
  391. {
  392. struct wl12xx_cmd_role_start *cmd;
  393. int ret;
  394. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  395. if (!cmd) {
  396. ret = -ENOMEM;
  397. goto out;
  398. }
  399. wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
  400. cmd->role_id = wlvif->dev_role_id;
  401. if (wlvif->band == IEEE80211_BAND_5GHZ)
  402. cmd->band = WL12XX_BAND_5GHZ;
  403. cmd->channel = wlvif->channel;
  404. if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
  405. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
  406. if (ret)
  407. goto out_free;
  408. }
  409. cmd->device.hlid = wlvif->dev_hlid;
  410. cmd->device.session = wlvif->session_counter;
  411. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
  412. cmd->role_id, cmd->device.hlid, cmd->device.session);
  413. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  414. if (ret < 0) {
  415. wl1271_error("failed to initiate cmd role enable");
  416. goto err_hlid;
  417. }
  418. goto out_free;
  419. err_hlid:
  420. /* clear links on error */
  421. wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
  422. out_free:
  423. kfree(cmd);
  424. out:
  425. return ret;
  426. }
  427. static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
  428. struct wl12xx_vif *wlvif)
  429. {
  430. struct wl12xx_cmd_role_stop *cmd;
  431. int ret;
  432. if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
  433. return -EINVAL;
  434. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  435. if (!cmd) {
  436. ret = -ENOMEM;
  437. goto out;
  438. }
  439. wl1271_debug(DEBUG_CMD, "cmd role stop dev");
  440. cmd->role_id = wlvif->dev_role_id;
  441. cmd->disc_type = DISCONNECT_IMMEDIATE;
  442. cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
  443. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  444. if (ret < 0) {
  445. wl1271_error("failed to initiate cmd role stop");
  446. goto out_free;
  447. }
  448. ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
  449. if (ret < 0) {
  450. wl1271_error("cmd role stop dev event completion error");
  451. goto out_free;
  452. }
  453. wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
  454. out_free:
  455. kfree(cmd);
  456. out:
  457. return ret;
  458. }
  459. int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  460. {
  461. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  462. struct wl12xx_cmd_role_start *cmd;
  463. int ret;
  464. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  465. if (!cmd) {
  466. ret = -ENOMEM;
  467. goto out;
  468. }
  469. wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
  470. cmd->role_id = wlvif->role_id;
  471. if (wlvif->band == IEEE80211_BAND_5GHZ)
  472. cmd->band = WL12XX_BAND_5GHZ;
  473. cmd->channel = wlvif->channel;
  474. cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  475. cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  476. cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
  477. cmd->sta.ssid_len = wlvif->ssid_len;
  478. memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
  479. memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
  480. cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
  481. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
  482. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
  483. if (ret)
  484. goto out_free;
  485. }
  486. cmd->sta.hlid = wlvif->sta.hlid;
  487. cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
  488. cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
  489. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
  490. "basic_rate_set: 0x%x, remote_rates: 0x%x",
  491. wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
  492. wlvif->basic_rate_set, wlvif->rate_set);
  493. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  494. if (ret < 0) {
  495. wl1271_error("failed to initiate cmd role start sta");
  496. goto err_hlid;
  497. }
  498. goto out_free;
  499. err_hlid:
  500. /* clear links on error. */
  501. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  502. out_free:
  503. kfree(cmd);
  504. out:
  505. return ret;
  506. }
  507. /* use this function to stop ibss as well */
  508. int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  509. {
  510. struct wl12xx_cmd_role_stop *cmd;
  511. int ret;
  512. if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
  513. return -EINVAL;
  514. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  515. if (!cmd) {
  516. ret = -ENOMEM;
  517. goto out;
  518. }
  519. wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
  520. cmd->role_id = wlvif->role_id;
  521. cmd->disc_type = DISCONNECT_IMMEDIATE;
  522. cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
  523. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  524. if (ret < 0) {
  525. wl1271_error("failed to initiate cmd role stop sta");
  526. goto out_free;
  527. }
  528. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  529. out_free:
  530. kfree(cmd);
  531. out:
  532. return ret;
  533. }
  534. int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  535. {
  536. struct wl12xx_cmd_role_start *cmd;
  537. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  538. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  539. int ret;
  540. wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
  541. /* trying to use hidden SSID with an old hostapd version */
  542. if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
  543. wl1271_error("got a null SSID from beacon/bss");
  544. ret = -EINVAL;
  545. goto out;
  546. }
  547. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  548. if (!cmd) {
  549. ret = -ENOMEM;
  550. goto out;
  551. }
  552. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
  553. if (ret < 0)
  554. goto out_free;
  555. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  556. if (ret < 0)
  557. goto out_free_global;
  558. cmd->role_id = wlvif->role_id;
  559. cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
  560. cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
  561. cmd->ap.global_hlid = wlvif->ap.global_hlid;
  562. cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
  563. cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  564. cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  565. cmd->ap.dtim_interval = bss_conf->dtim_period;
  566. cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
  567. /* FIXME: Change when adding DFS */
  568. cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
  569. cmd->channel = wlvif->channel;
  570. if (!bss_conf->hidden_ssid) {
  571. /* take the SSID from the beacon for backward compatibility */
  572. cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
  573. cmd->ap.ssid_len = wlvif->ssid_len;
  574. memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
  575. } else {
  576. cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
  577. cmd->ap.ssid_len = bss_conf->ssid_len;
  578. memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
  579. }
  580. cmd->ap.local_rates = cpu_to_le32(0xffffffff);
  581. switch (wlvif->band) {
  582. case IEEE80211_BAND_2GHZ:
  583. cmd->band = RADIO_BAND_2_4GHZ;
  584. break;
  585. case IEEE80211_BAND_5GHZ:
  586. cmd->band = RADIO_BAND_5GHZ;
  587. break;
  588. default:
  589. wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
  590. cmd->band = RADIO_BAND_2_4GHZ;
  591. break;
  592. }
  593. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  594. if (ret < 0) {
  595. wl1271_error("failed to initiate cmd role start ap");
  596. goto out_free_bcast;
  597. }
  598. goto out_free;
  599. out_free_bcast:
  600. wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  601. out_free_global:
  602. wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
  603. out_free:
  604. kfree(cmd);
  605. out:
  606. return ret;
  607. }
  608. int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  609. {
  610. struct wl12xx_cmd_role_stop *cmd;
  611. int ret;
  612. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  613. if (!cmd) {
  614. ret = -ENOMEM;
  615. goto out;
  616. }
  617. wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
  618. cmd->role_id = wlvif->role_id;
  619. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  620. if (ret < 0) {
  621. wl1271_error("failed to initiate cmd role stop ap");
  622. goto out_free;
  623. }
  624. wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  625. wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
  626. out_free:
  627. kfree(cmd);
  628. out:
  629. return ret;
  630. }
  631. int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  632. {
  633. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  634. struct wl12xx_cmd_role_start *cmd;
  635. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  636. int ret;
  637. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  638. if (!cmd) {
  639. ret = -ENOMEM;
  640. goto out;
  641. }
  642. wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
  643. cmd->role_id = wlvif->role_id;
  644. if (wlvif->band == IEEE80211_BAND_5GHZ)
  645. cmd->band = WL12XX_BAND_5GHZ;
  646. cmd->channel = wlvif->channel;
  647. cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  648. cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  649. cmd->ibss.dtim_interval = bss_conf->dtim_period;
  650. cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
  651. cmd->ibss.ssid_len = wlvif->ssid_len;
  652. memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
  653. memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
  654. cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
  655. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
  656. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
  657. if (ret)
  658. goto out_free;
  659. }
  660. cmd->ibss.hlid = wlvif->sta.hlid;
  661. cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
  662. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
  663. "basic_rate_set: 0x%x, remote_rates: 0x%x",
  664. wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
  665. wlvif->basic_rate_set, wlvif->rate_set);
  666. wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
  667. vif->bss_conf.bssid);
  668. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  669. if (ret < 0) {
  670. wl1271_error("failed to initiate cmd role enable");
  671. goto err_hlid;
  672. }
  673. goto out_free;
  674. err_hlid:
  675. /* clear links on error. */
  676. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  677. out_free:
  678. kfree(cmd);
  679. out:
  680. return ret;
  681. }
  682. /**
  683. * send test command to firmware
  684. *
  685. * @wl: wl struct
  686. * @buf: buffer containing the command, with all headers, must work with dma
  687. * @len: length of the buffer
  688. * @answer: is answer needed
  689. */
  690. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  691. {
  692. int ret;
  693. size_t res_len = 0;
  694. wl1271_debug(DEBUG_CMD, "cmd test");
  695. if (answer)
  696. res_len = buf_len;
  697. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  698. if (ret < 0) {
  699. wl1271_warning("TEST command failed");
  700. return ret;
  701. }
  702. return ret;
  703. }
  704. /**
  705. * read acx from firmware
  706. *
  707. * @wl: wl struct
  708. * @id: acx id
  709. * @buf: buffer for the response, including all headers, must work with dma
  710. * @len: length of buf
  711. */
  712. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  713. {
  714. struct acx_header *acx = buf;
  715. int ret;
  716. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  717. acx->id = cpu_to_le16(id);
  718. /* payload length, does not include any headers */
  719. acx->len = cpu_to_le16(len - sizeof(*acx));
  720. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  721. if (ret < 0)
  722. wl1271_error("INTERROGATE command failed");
  723. return ret;
  724. }
  725. /**
  726. * write acx value to firmware
  727. *
  728. * @wl: wl struct
  729. * @id: acx id
  730. * @buf: buffer containing acx, including all headers, must work with dma
  731. * @len: length of buf
  732. */
  733. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  734. {
  735. struct acx_header *acx = buf;
  736. int ret;
  737. wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
  738. acx->id = cpu_to_le16(id);
  739. /* payload length, does not include any headers */
  740. acx->len = cpu_to_le16(len - sizeof(*acx));
  741. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  742. if (ret < 0) {
  743. wl1271_warning("CONFIGURE command NOK");
  744. return ret;
  745. }
  746. return 0;
  747. }
  748. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  749. {
  750. struct cmd_enabledisable_path *cmd;
  751. int ret;
  752. u16 cmd_rx, cmd_tx;
  753. wl1271_debug(DEBUG_CMD, "cmd data path");
  754. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  755. if (!cmd) {
  756. ret = -ENOMEM;
  757. goto out;
  758. }
  759. /* the channel here is only used for calibration, so hardcoded to 1 */
  760. cmd->channel = 1;
  761. if (enable) {
  762. cmd_rx = CMD_ENABLE_RX;
  763. cmd_tx = CMD_ENABLE_TX;
  764. } else {
  765. cmd_rx = CMD_DISABLE_RX;
  766. cmd_tx = CMD_DISABLE_TX;
  767. }
  768. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  769. if (ret < 0) {
  770. wl1271_error("rx %s cmd for channel %d failed",
  771. enable ? "start" : "stop", cmd->channel);
  772. goto out;
  773. }
  774. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  775. enable ? "start" : "stop", cmd->channel);
  776. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  777. if (ret < 0) {
  778. wl1271_error("tx %s cmd for channel %d failed",
  779. enable ? "start" : "stop", cmd->channel);
  780. goto out;
  781. }
  782. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  783. enable ? "start" : "stop", cmd->channel);
  784. out:
  785. kfree(cmd);
  786. return ret;
  787. }
  788. int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  789. u8 ps_mode, u16 auto_ps_timeout)
  790. {
  791. struct wl1271_cmd_ps_params *ps_params = NULL;
  792. int ret = 0;
  793. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  794. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  795. if (!ps_params) {
  796. ret = -ENOMEM;
  797. goto out;
  798. }
  799. ps_params->role_id = wlvif->role_id;
  800. ps_params->ps_mode = ps_mode;
  801. ps_params->auto_ps_timeout = auto_ps_timeout;
  802. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  803. sizeof(*ps_params), 0);
  804. if (ret < 0) {
  805. wl1271_error("cmd set_ps_mode failed");
  806. goto out;
  807. }
  808. out:
  809. kfree(ps_params);
  810. return ret;
  811. }
  812. int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
  813. u16 template_id, void *buf, size_t buf_len,
  814. int index, u32 rates)
  815. {
  816. struct wl1271_cmd_template_set *cmd;
  817. int ret = 0;
  818. wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
  819. template_id, role_id);
  820. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  821. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  822. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  823. if (!cmd) {
  824. ret = -ENOMEM;
  825. goto out;
  826. }
  827. /* during initialization wlvif is NULL */
  828. cmd->role_id = role_id;
  829. cmd->len = cpu_to_le16(buf_len);
  830. cmd->template_type = template_id;
  831. cmd->enabled_rates = cpu_to_le32(rates);
  832. cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
  833. cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
  834. cmd->index = index;
  835. if (buf)
  836. memcpy(cmd->template_data, buf, buf_len);
  837. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  838. if (ret < 0) {
  839. wl1271_warning("cmd set_template failed: %d", ret);
  840. goto out_free;
  841. }
  842. out_free:
  843. kfree(cmd);
  844. out:
  845. return ret;
  846. }
  847. int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  848. {
  849. struct sk_buff *skb = NULL;
  850. int size;
  851. void *ptr;
  852. int ret = -ENOMEM;
  853. if (wlvif->bss_type == BSS_TYPE_IBSS) {
  854. size = sizeof(struct wl12xx_null_data_template);
  855. ptr = NULL;
  856. } else {
  857. skb = ieee80211_nullfunc_get(wl->hw,
  858. wl12xx_wlvif_to_vif(wlvif));
  859. if (!skb)
  860. goto out;
  861. size = skb->len;
  862. ptr = skb->data;
  863. }
  864. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  865. CMD_TEMPL_NULL_DATA, ptr, size, 0,
  866. wlvif->basic_rate);
  867. out:
  868. dev_kfree_skb(skb);
  869. if (ret)
  870. wl1271_warning("cmd buld null data failed %d", ret);
  871. return ret;
  872. }
  873. int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
  874. struct wl12xx_vif *wlvif)
  875. {
  876. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  877. struct sk_buff *skb = NULL;
  878. int ret = -ENOMEM;
  879. skb = ieee80211_nullfunc_get(wl->hw, vif);
  880. if (!skb)
  881. goto out;
  882. ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
  883. skb->data, skb->len,
  884. CMD_TEMPL_KLV_IDX_NULL_DATA,
  885. wlvif->basic_rate);
  886. out:
  887. dev_kfree_skb(skb);
  888. if (ret)
  889. wl1271_warning("cmd build klv null data failed %d", ret);
  890. return ret;
  891. }
  892. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  893. u16 aid)
  894. {
  895. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  896. struct sk_buff *skb;
  897. int ret = 0;
  898. skb = ieee80211_pspoll_get(wl->hw, vif);
  899. if (!skb)
  900. goto out;
  901. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  902. CMD_TEMPL_PS_POLL, skb->data,
  903. skb->len, 0, wlvif->basic_rate_set);
  904. out:
  905. dev_kfree_skb(skb);
  906. return ret;
  907. }
  908. int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  909. u8 role_id, u8 band,
  910. const u8 *ssid, size_t ssid_len,
  911. const u8 *ie, size_t ie_len)
  912. {
  913. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  914. struct sk_buff *skb;
  915. int ret;
  916. u32 rate;
  917. skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
  918. ie, ie_len);
  919. if (!skb) {
  920. ret = -ENOMEM;
  921. goto out;
  922. }
  923. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  924. rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
  925. if (band == IEEE80211_BAND_2GHZ)
  926. ret = wl1271_cmd_template_set(wl, role_id,
  927. CMD_TEMPL_CFG_PROBE_REQ_2_4,
  928. skb->data, skb->len, 0, rate);
  929. else
  930. ret = wl1271_cmd_template_set(wl, role_id,
  931. CMD_TEMPL_CFG_PROBE_REQ_5,
  932. skb->data, skb->len, 0, rate);
  933. out:
  934. dev_kfree_skb(skb);
  935. return ret;
  936. }
  937. struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
  938. struct wl12xx_vif *wlvif,
  939. struct sk_buff *skb)
  940. {
  941. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  942. int ret;
  943. u32 rate;
  944. if (!skb)
  945. skb = ieee80211_ap_probereq_get(wl->hw, vif);
  946. if (!skb)
  947. goto out;
  948. wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
  949. rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
  950. if (wlvif->band == IEEE80211_BAND_2GHZ)
  951. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  952. CMD_TEMPL_CFG_PROBE_REQ_2_4,
  953. skb->data, skb->len, 0, rate);
  954. else
  955. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  956. CMD_TEMPL_CFG_PROBE_REQ_5,
  957. skb->data, skb->len, 0, rate);
  958. if (ret < 0)
  959. wl1271_error("Unable to set ap probe request template.");
  960. out:
  961. return skb;
  962. }
  963. int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  964. {
  965. int ret, extra;
  966. u16 fc;
  967. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  968. struct sk_buff *skb;
  969. struct wl12xx_arp_rsp_template *tmpl;
  970. struct ieee80211_hdr_3addr *hdr;
  971. struct arphdr *arp_hdr;
  972. skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
  973. WL1271_EXTRA_SPACE_MAX);
  974. if (!skb) {
  975. wl1271_error("failed to allocate buffer for arp rsp template");
  976. return -ENOMEM;
  977. }
  978. skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
  979. tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
  980. memset(tmpl, 0, sizeof(tmpl));
  981. /* llc layer */
  982. memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
  983. tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
  984. /* arp header */
  985. arp_hdr = &tmpl->arp_hdr;
  986. arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
  987. arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
  988. arp_hdr->ar_hln = ETH_ALEN;
  989. arp_hdr->ar_pln = 4;
  990. arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
  991. /* arp payload */
  992. memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
  993. tmpl->sender_ip = wlvif->ip_addr;
  994. /* encryption space */
  995. switch (wlvif->encryption_type) {
  996. case KEY_TKIP:
  997. extra = WL1271_EXTRA_SPACE_TKIP;
  998. break;
  999. case KEY_AES:
  1000. extra = WL1271_EXTRA_SPACE_AES;
  1001. break;
  1002. case KEY_NONE:
  1003. case KEY_WEP:
  1004. case KEY_GEM:
  1005. extra = 0;
  1006. break;
  1007. default:
  1008. wl1271_warning("Unknown encryption type: %d",
  1009. wlvif->encryption_type);
  1010. ret = -EINVAL;
  1011. goto out;
  1012. }
  1013. if (extra) {
  1014. u8 *space = skb_push(skb, extra);
  1015. memset(space, 0, extra);
  1016. }
  1017. /* QoS header - BE */
  1018. if (wlvif->sta.qos)
  1019. memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
  1020. /* mac80211 header */
  1021. hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
  1022. memset(hdr, 0, sizeof(hdr));
  1023. fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
  1024. if (wlvif->sta.qos)
  1025. fc |= IEEE80211_STYPE_QOS_DATA;
  1026. else
  1027. fc |= IEEE80211_STYPE_DATA;
  1028. if (wlvif->encryption_type != KEY_NONE)
  1029. fc |= IEEE80211_FCTL_PROTECTED;
  1030. hdr->frame_control = cpu_to_le16(fc);
  1031. memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
  1032. memcpy(hdr->addr2, vif->addr, ETH_ALEN);
  1033. memset(hdr->addr3, 0xff, ETH_ALEN);
  1034. ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
  1035. skb->data, skb->len, 0,
  1036. wlvif->basic_rate);
  1037. out:
  1038. dev_kfree_skb(skb);
  1039. return ret;
  1040. }
  1041. int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
  1042. {
  1043. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  1044. struct ieee80211_qos_hdr template;
  1045. memset(&template, 0, sizeof(template));
  1046. memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
  1047. memcpy(template.addr2, vif->addr, ETH_ALEN);
  1048. memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
  1049. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  1050. IEEE80211_STYPE_QOS_NULLFUNC |
  1051. IEEE80211_FCTL_TODS);
  1052. /* FIXME: not sure what priority to use here */
  1053. template.qos_ctrl = cpu_to_le16(0);
  1054. return wl1271_cmd_template_set(wl, wlvif->role_id,
  1055. CMD_TEMPL_QOS_NULL_DATA, &template,
  1056. sizeof(template), 0,
  1057. wlvif->basic_rate);
  1058. }
  1059. int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
  1060. {
  1061. struct wl1271_cmd_set_keys *cmd;
  1062. int ret = 0;
  1063. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  1064. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1065. if (!cmd) {
  1066. ret = -ENOMEM;
  1067. goto out;
  1068. }
  1069. cmd->hlid = hlid;
  1070. cmd->key_id = id;
  1071. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  1072. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  1073. cmd->key_type = KEY_WEP;
  1074. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1075. if (ret < 0) {
  1076. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  1077. goto out;
  1078. }
  1079. out:
  1080. kfree(cmd);
  1081. return ret;
  1082. }
  1083. int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1084. u16 action, u8 id, u8 key_type,
  1085. u8 key_size, const u8 *key, const u8 *addr,
  1086. u32 tx_seq_32, u16 tx_seq_16)
  1087. {
  1088. struct wl1271_cmd_set_keys *cmd;
  1089. int ret = 0;
  1090. /* hlid might have already been deleted */
  1091. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
  1092. return 0;
  1093. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1094. if (!cmd) {
  1095. ret = -ENOMEM;
  1096. goto out;
  1097. }
  1098. cmd->hlid = wlvif->sta.hlid;
  1099. if (key_type == KEY_WEP)
  1100. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  1101. else if (is_broadcast_ether_addr(addr))
  1102. cmd->lid_key_type = BROADCAST_LID_TYPE;
  1103. else
  1104. cmd->lid_key_type = UNICAST_LID_TYPE;
  1105. cmd->key_action = cpu_to_le16(action);
  1106. cmd->key_size = key_size;
  1107. cmd->key_type = key_type;
  1108. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  1109. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  1110. cmd->key_id = id;
  1111. if (key_type == KEY_TKIP) {
  1112. /*
  1113. * We get the key in the following form:
  1114. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  1115. * but the target is expecting:
  1116. * TKIP - RX MIC - TX MIC
  1117. */
  1118. memcpy(cmd->key, key, 16);
  1119. memcpy(cmd->key + 16, key + 24, 8);
  1120. memcpy(cmd->key + 24, key + 16, 8);
  1121. } else {
  1122. memcpy(cmd->key, key, key_size);
  1123. }
  1124. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  1125. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1126. if (ret < 0) {
  1127. wl1271_warning("could not set keys");
  1128. goto out;
  1129. }
  1130. out:
  1131. kfree(cmd);
  1132. return ret;
  1133. }
  1134. /*
  1135. * TODO: merge with sta/ibss into 1 set_key function.
  1136. * note there are slight diffs
  1137. */
  1138. int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1139. u16 action, u8 id, u8 key_type,
  1140. u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
  1141. u16 tx_seq_16)
  1142. {
  1143. struct wl1271_cmd_set_keys *cmd;
  1144. int ret = 0;
  1145. u8 lid_type;
  1146. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1147. if (!cmd)
  1148. return -ENOMEM;
  1149. if (hlid == wlvif->ap.bcast_hlid) {
  1150. if (key_type == KEY_WEP)
  1151. lid_type = WEP_DEFAULT_LID_TYPE;
  1152. else
  1153. lid_type = BROADCAST_LID_TYPE;
  1154. } else {
  1155. lid_type = UNICAST_LID_TYPE;
  1156. }
  1157. wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
  1158. " hlid: %d", (int)action, (int)id, (int)lid_type,
  1159. (int)key_type, (int)hlid);
  1160. cmd->lid_key_type = lid_type;
  1161. cmd->hlid = hlid;
  1162. cmd->key_action = cpu_to_le16(action);
  1163. cmd->key_size = key_size;
  1164. cmd->key_type = key_type;
  1165. cmd->key_id = id;
  1166. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  1167. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  1168. if (key_type == KEY_TKIP) {
  1169. /*
  1170. * We get the key in the following form:
  1171. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  1172. * but the target is expecting:
  1173. * TKIP - RX MIC - TX MIC
  1174. */
  1175. memcpy(cmd->key, key, 16);
  1176. memcpy(cmd->key + 16, key + 24, 8);
  1177. memcpy(cmd->key + 24, key + 16, 8);
  1178. } else {
  1179. memcpy(cmd->key, key, key_size);
  1180. }
  1181. wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
  1182. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1183. if (ret < 0) {
  1184. wl1271_warning("could not set ap keys");
  1185. goto out;
  1186. }
  1187. out:
  1188. kfree(cmd);
  1189. return ret;
  1190. }
  1191. int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
  1192. {
  1193. struct wl12xx_cmd_set_peer_state *cmd;
  1194. int ret = 0;
  1195. wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
  1196. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1197. if (!cmd) {
  1198. ret = -ENOMEM;
  1199. goto out;
  1200. }
  1201. cmd->hlid = hlid;
  1202. cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
  1203. ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
  1204. if (ret < 0) {
  1205. wl1271_error("failed to send set peer state command");
  1206. goto out_free;
  1207. }
  1208. out_free:
  1209. kfree(cmd);
  1210. out:
  1211. return ret;
  1212. }
  1213. int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1214. struct ieee80211_sta *sta, u8 hlid)
  1215. {
  1216. struct wl12xx_cmd_add_peer *cmd;
  1217. int i, ret;
  1218. u32 sta_rates;
  1219. wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
  1220. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1221. if (!cmd) {
  1222. ret = -ENOMEM;
  1223. goto out;
  1224. }
  1225. memcpy(cmd->addr, sta->addr, ETH_ALEN);
  1226. cmd->bss_index = WL1271_AP_BSS_INDEX;
  1227. cmd->aid = sta->aid;
  1228. cmd->hlid = hlid;
  1229. cmd->sp_len = sta->max_sp;
  1230. cmd->wmm = sta->wme ? 1 : 0;
  1231. for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
  1232. if (sta->wme && (sta->uapsd_queues & BIT(i)))
  1233. cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
  1234. else
  1235. cmd->psd_type[i] = WL1271_PSD_LEGACY;
  1236. sta_rates = sta->supp_rates[wlvif->band];
  1237. if (sta->ht_cap.ht_supported)
  1238. sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
  1239. cmd->supported_rates =
  1240. cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
  1241. wlvif->band));
  1242. wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
  1243. cmd->supported_rates, sta->uapsd_queues);
  1244. ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
  1245. if (ret < 0) {
  1246. wl1271_error("failed to initiate cmd add peer");
  1247. goto out_free;
  1248. }
  1249. out_free:
  1250. kfree(cmd);
  1251. out:
  1252. return ret;
  1253. }
  1254. int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
  1255. {
  1256. struct wl12xx_cmd_remove_peer *cmd;
  1257. int ret;
  1258. wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
  1259. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1260. if (!cmd) {
  1261. ret = -ENOMEM;
  1262. goto out;
  1263. }
  1264. cmd->hlid = hlid;
  1265. /* We never send a deauth, mac80211 is in charge of this */
  1266. cmd->reason_opcode = 0;
  1267. cmd->send_deauth_flag = 0;
  1268. ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
  1269. if (ret < 0) {
  1270. wl1271_error("failed to initiate cmd remove peer");
  1271. goto out_free;
  1272. }
  1273. /*
  1274. * We are ok with a timeout here. The event is sometimes not sent
  1275. * due to a firmware bug.
  1276. */
  1277. wl1271_cmd_wait_for_event_or_timeout(wl,
  1278. PEER_REMOVE_COMPLETE_EVENT_ID);
  1279. out_free:
  1280. kfree(cmd);
  1281. out:
  1282. return ret;
  1283. }
  1284. int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
  1285. {
  1286. struct wl12xx_cmd_config_fwlog *cmd;
  1287. int ret = 0;
  1288. wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
  1289. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1290. if (!cmd) {
  1291. ret = -ENOMEM;
  1292. goto out;
  1293. }
  1294. cmd->logger_mode = wl->conf.fwlog.mode;
  1295. cmd->log_severity = wl->conf.fwlog.severity;
  1296. cmd->timestamp = wl->conf.fwlog.timestamp;
  1297. cmd->output = wl->conf.fwlog.output;
  1298. cmd->threshold = wl->conf.fwlog.threshold;
  1299. ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
  1300. if (ret < 0) {
  1301. wl1271_error("failed to send config firmware logger command");
  1302. goto out_free;
  1303. }
  1304. out_free:
  1305. kfree(cmd);
  1306. out:
  1307. return ret;
  1308. }
  1309. int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
  1310. {
  1311. struct wl12xx_cmd_start_fwlog *cmd;
  1312. int ret = 0;
  1313. wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
  1314. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1315. if (!cmd) {
  1316. ret = -ENOMEM;
  1317. goto out;
  1318. }
  1319. ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
  1320. if (ret < 0) {
  1321. wl1271_error("failed to send start firmware logger command");
  1322. goto out_free;
  1323. }
  1324. out_free:
  1325. kfree(cmd);
  1326. out:
  1327. return ret;
  1328. }
  1329. int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
  1330. {
  1331. struct wl12xx_cmd_stop_fwlog *cmd;
  1332. int ret = 0;
  1333. wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
  1334. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1335. if (!cmd) {
  1336. ret = -ENOMEM;
  1337. goto out;
  1338. }
  1339. ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
  1340. if (ret < 0) {
  1341. wl1271_error("failed to send stop firmware logger command");
  1342. goto out_free;
  1343. }
  1344. out_free:
  1345. kfree(cmd);
  1346. out:
  1347. return ret;
  1348. }
  1349. static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1350. u8 role_id)
  1351. {
  1352. struct wl12xx_cmd_roc *cmd;
  1353. int ret = 0;
  1354. wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
  1355. if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
  1356. return -EINVAL;
  1357. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1358. if (!cmd) {
  1359. ret = -ENOMEM;
  1360. goto out;
  1361. }
  1362. cmd->role_id = role_id;
  1363. cmd->channel = wlvif->channel;
  1364. switch (wlvif->band) {
  1365. case IEEE80211_BAND_2GHZ:
  1366. cmd->band = RADIO_BAND_2_4GHZ;
  1367. break;
  1368. case IEEE80211_BAND_5GHZ:
  1369. cmd->band = RADIO_BAND_5GHZ;
  1370. break;
  1371. default:
  1372. wl1271_error("roc - unknown band: %d", (int)wlvif->band);
  1373. ret = -EINVAL;
  1374. goto out_free;
  1375. }
  1376. ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
  1377. if (ret < 0) {
  1378. wl1271_error("failed to send ROC command");
  1379. goto out_free;
  1380. }
  1381. out_free:
  1382. kfree(cmd);
  1383. out:
  1384. return ret;
  1385. }
  1386. static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
  1387. {
  1388. struct wl12xx_cmd_croc *cmd;
  1389. int ret = 0;
  1390. wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
  1391. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1392. if (!cmd) {
  1393. ret = -ENOMEM;
  1394. goto out;
  1395. }
  1396. cmd->role_id = role_id;
  1397. ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
  1398. sizeof(*cmd), 0);
  1399. if (ret < 0) {
  1400. wl1271_error("failed to send ROC command");
  1401. goto out_free;
  1402. }
  1403. out_free:
  1404. kfree(cmd);
  1405. out:
  1406. return ret;
  1407. }
  1408. int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
  1409. {
  1410. int ret = 0;
  1411. if (WARN_ON(test_bit(role_id, wl->roc_map)))
  1412. return 0;
  1413. ret = wl12xx_cmd_roc(wl, wlvif, role_id);
  1414. if (ret < 0)
  1415. goto out;
  1416. ret = wl1271_cmd_wait_for_event(wl,
  1417. REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
  1418. if (ret < 0) {
  1419. wl1271_error("cmd roc event completion error");
  1420. goto out;
  1421. }
  1422. __set_bit(role_id, wl->roc_map);
  1423. out:
  1424. return ret;
  1425. }
  1426. int wl12xx_croc(struct wl1271 *wl, u8 role_id)
  1427. {
  1428. int ret = 0;
  1429. if (WARN_ON(!test_bit(role_id, wl->roc_map)))
  1430. return 0;
  1431. ret = wl12xx_cmd_croc(wl, role_id);
  1432. if (ret < 0)
  1433. goto out;
  1434. __clear_bit(role_id, wl->roc_map);
  1435. out:
  1436. return ret;
  1437. }
  1438. int wl12xx_cmd_channel_switch(struct wl1271 *wl,
  1439. struct wl12xx_vif *wlvif,
  1440. struct ieee80211_channel_switch *ch_switch)
  1441. {
  1442. struct wl12xx_cmd_channel_switch *cmd;
  1443. int ret;
  1444. wl1271_debug(DEBUG_ACX, "cmd channel switch");
  1445. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1446. if (!cmd) {
  1447. ret = -ENOMEM;
  1448. goto out;
  1449. }
  1450. cmd->role_id = wlvif->role_id;
  1451. cmd->channel = ch_switch->channel->hw_value;
  1452. cmd->switch_time = ch_switch->count;
  1453. cmd->stop_tx = ch_switch->block_tx;
  1454. /* FIXME: control from mac80211 in the future */
  1455. cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
  1456. ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
  1457. if (ret < 0) {
  1458. wl1271_error("failed to send channel switch command");
  1459. goto out_free;
  1460. }
  1461. out_free:
  1462. kfree(cmd);
  1463. out:
  1464. return ret;
  1465. }
  1466. int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
  1467. {
  1468. struct wl12xx_cmd_stop_channel_switch *cmd;
  1469. int ret;
  1470. wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
  1471. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1472. if (!cmd) {
  1473. ret = -ENOMEM;
  1474. goto out;
  1475. }
  1476. ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
  1477. if (ret < 0) {
  1478. wl1271_error("failed to stop channel switch command");
  1479. goto out_free;
  1480. }
  1481. out_free:
  1482. kfree(cmd);
  1483. out:
  1484. return ret;
  1485. }
  1486. /* start dev role and roc on its channel */
  1487. int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1488. {
  1489. int ret;
  1490. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1491. wlvif->bss_type == BSS_TYPE_IBSS)))
  1492. return -EINVAL;
  1493. ret = wl12xx_cmd_role_start_dev(wl, wlvif);
  1494. if (ret < 0)
  1495. goto out;
  1496. ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
  1497. if (ret < 0)
  1498. goto out_stop;
  1499. return 0;
  1500. out_stop:
  1501. wl12xx_cmd_role_stop_dev(wl, wlvif);
  1502. out:
  1503. return ret;
  1504. }
  1505. /* croc dev hlid, and stop the role */
  1506. int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1507. {
  1508. int ret;
  1509. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1510. wlvif->bss_type == BSS_TYPE_IBSS)))
  1511. return -EINVAL;
  1512. /* flush all pending packets */
  1513. wl1271_tx_work_locked(wl);
  1514. if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
  1515. ret = wl12xx_croc(wl, wlvif->dev_role_id);
  1516. if (ret < 0)
  1517. goto out;
  1518. }
  1519. ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
  1520. if (ret < 0)
  1521. goto out;
  1522. out:
  1523. return ret;
  1524. }