cmd.c 42 KB

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