cmd.c 42 KB

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