cmd.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  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, ie_len);
  836. if (!skb) {
  837. ret = -ENOMEM;
  838. goto out;
  839. }
  840. wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
  841. if (!sched_scan &&
  842. (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) {
  843. template_id_2_4 = CMD_TEMPL_APP_PROBE_REQ_2_4;
  844. template_id_5 = CMD_TEMPL_APP_PROBE_REQ_5;
  845. }
  846. rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
  847. if (band == IEEE80211_BAND_2GHZ)
  848. ret = wl1271_cmd_template_set(wl, role_id,
  849. template_id_2_4,
  850. skb->data, skb->len, 0, rate);
  851. else
  852. ret = wl1271_cmd_template_set(wl, role_id,
  853. template_id_5,
  854. skb->data, skb->len, 0, rate);
  855. out:
  856. dev_kfree_skb(skb);
  857. return ret;
  858. }
  859. struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
  860. struct wl12xx_vif *wlvif,
  861. struct sk_buff *skb)
  862. {
  863. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  864. int ret;
  865. u32 rate;
  866. if (!skb)
  867. skb = ieee80211_ap_probereq_get(wl->hw, vif);
  868. if (!skb)
  869. goto out;
  870. wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
  871. rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
  872. if (wlvif->band == IEEE80211_BAND_2GHZ)
  873. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  874. CMD_TEMPL_CFG_PROBE_REQ_2_4,
  875. skb->data, skb->len, 0, rate);
  876. else
  877. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  878. CMD_TEMPL_CFG_PROBE_REQ_5,
  879. skb->data, skb->len, 0, rate);
  880. if (ret < 0)
  881. wl1271_error("Unable to set ap probe request template.");
  882. out:
  883. return skb;
  884. }
  885. int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  886. {
  887. int ret, extra = 0;
  888. u16 fc;
  889. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  890. struct sk_buff *skb;
  891. struct wl12xx_arp_rsp_template *tmpl;
  892. struct ieee80211_hdr_3addr *hdr;
  893. struct arphdr *arp_hdr;
  894. skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
  895. WL1271_EXTRA_SPACE_MAX);
  896. if (!skb) {
  897. wl1271_error("failed to allocate buffer for arp rsp template");
  898. return -ENOMEM;
  899. }
  900. skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
  901. tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
  902. memset(tmpl, 0, sizeof(*tmpl));
  903. /* llc layer */
  904. memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
  905. tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
  906. /* arp header */
  907. arp_hdr = &tmpl->arp_hdr;
  908. arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
  909. arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
  910. arp_hdr->ar_hln = ETH_ALEN;
  911. arp_hdr->ar_pln = 4;
  912. arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
  913. /* arp payload */
  914. memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
  915. tmpl->sender_ip = wlvif->ip_addr;
  916. /* encryption space */
  917. switch (wlvif->encryption_type) {
  918. case KEY_TKIP:
  919. if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE)
  920. extra = WL1271_EXTRA_SPACE_TKIP;
  921. break;
  922. case KEY_AES:
  923. extra = WL1271_EXTRA_SPACE_AES;
  924. break;
  925. case KEY_NONE:
  926. case KEY_WEP:
  927. case KEY_GEM:
  928. extra = 0;
  929. break;
  930. default:
  931. wl1271_warning("Unknown encryption type: %d",
  932. wlvif->encryption_type);
  933. ret = -EINVAL;
  934. goto out;
  935. }
  936. if (extra) {
  937. u8 *space = skb_push(skb, extra);
  938. memset(space, 0, extra);
  939. }
  940. /* QoS header - BE */
  941. if (wlvif->sta.qos)
  942. memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
  943. /* mac80211 header */
  944. hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
  945. memset(hdr, 0, sizeof(*hdr));
  946. fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
  947. if (wlvif->sta.qos)
  948. fc |= IEEE80211_STYPE_QOS_DATA;
  949. else
  950. fc |= IEEE80211_STYPE_DATA;
  951. if (wlvif->encryption_type != KEY_NONE)
  952. fc |= IEEE80211_FCTL_PROTECTED;
  953. hdr->frame_control = cpu_to_le16(fc);
  954. memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
  955. memcpy(hdr->addr2, vif->addr, ETH_ALEN);
  956. memset(hdr->addr3, 0xff, ETH_ALEN);
  957. ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
  958. skb->data, skb->len, 0,
  959. wlvif->basic_rate);
  960. out:
  961. dev_kfree_skb(skb);
  962. return ret;
  963. }
  964. int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
  965. {
  966. struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
  967. struct ieee80211_qos_hdr template;
  968. memset(&template, 0, sizeof(template));
  969. memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
  970. memcpy(template.addr2, vif->addr, ETH_ALEN);
  971. memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
  972. template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  973. IEEE80211_STYPE_QOS_NULLFUNC |
  974. IEEE80211_FCTL_TODS);
  975. /* FIXME: not sure what priority to use here */
  976. template.qos_ctrl = cpu_to_le16(0);
  977. return wl1271_cmd_template_set(wl, wlvif->role_id,
  978. CMD_TEMPL_QOS_NULL_DATA, &template,
  979. sizeof(template), 0,
  980. wlvif->basic_rate);
  981. }
  982. int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
  983. {
  984. struct wl1271_cmd_set_keys *cmd;
  985. int ret = 0;
  986. wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
  987. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  988. if (!cmd) {
  989. ret = -ENOMEM;
  990. goto out;
  991. }
  992. cmd->hlid = hlid;
  993. cmd->key_id = id;
  994. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  995. cmd->key_action = cpu_to_le16(KEY_SET_ID);
  996. cmd->key_type = KEY_WEP;
  997. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  998. if (ret < 0) {
  999. wl1271_warning("cmd set_default_wep_key failed: %d", ret);
  1000. goto out;
  1001. }
  1002. out:
  1003. kfree(cmd);
  1004. return ret;
  1005. }
  1006. int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1007. u16 action, u8 id, u8 key_type,
  1008. u8 key_size, const u8 *key, const u8 *addr,
  1009. u32 tx_seq_32, u16 tx_seq_16)
  1010. {
  1011. struct wl1271_cmd_set_keys *cmd;
  1012. int ret = 0;
  1013. /* hlid might have already been deleted */
  1014. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
  1015. return 0;
  1016. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1017. if (!cmd) {
  1018. ret = -ENOMEM;
  1019. goto out;
  1020. }
  1021. cmd->hlid = wlvif->sta.hlid;
  1022. if (key_type == KEY_WEP)
  1023. cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
  1024. else if (is_broadcast_ether_addr(addr))
  1025. cmd->lid_key_type = BROADCAST_LID_TYPE;
  1026. else
  1027. cmd->lid_key_type = UNICAST_LID_TYPE;
  1028. cmd->key_action = cpu_to_le16(action);
  1029. cmd->key_size = key_size;
  1030. cmd->key_type = key_type;
  1031. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  1032. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  1033. cmd->key_id = id;
  1034. if (key_type == KEY_TKIP) {
  1035. /*
  1036. * We get the key in the following form:
  1037. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  1038. * but the target is expecting:
  1039. * TKIP - RX MIC - TX MIC
  1040. */
  1041. memcpy(cmd->key, key, 16);
  1042. memcpy(cmd->key + 16, key + 24, 8);
  1043. memcpy(cmd->key + 24, key + 16, 8);
  1044. } else {
  1045. memcpy(cmd->key, key, key_size);
  1046. }
  1047. wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
  1048. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1049. if (ret < 0) {
  1050. wl1271_warning("could not set keys");
  1051. goto out;
  1052. }
  1053. out:
  1054. kfree(cmd);
  1055. return ret;
  1056. }
  1057. /*
  1058. * TODO: merge with sta/ibss into 1 set_key function.
  1059. * note there are slight diffs
  1060. */
  1061. int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1062. u16 action, u8 id, u8 key_type,
  1063. u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
  1064. u16 tx_seq_16)
  1065. {
  1066. struct wl1271_cmd_set_keys *cmd;
  1067. int ret = 0;
  1068. u8 lid_type;
  1069. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1070. if (!cmd)
  1071. return -ENOMEM;
  1072. if (hlid == wlvif->ap.bcast_hlid) {
  1073. if (key_type == KEY_WEP)
  1074. lid_type = WEP_DEFAULT_LID_TYPE;
  1075. else
  1076. lid_type = BROADCAST_LID_TYPE;
  1077. } else {
  1078. lid_type = UNICAST_LID_TYPE;
  1079. }
  1080. wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
  1081. " hlid: %d", (int)action, (int)id, (int)lid_type,
  1082. (int)key_type, (int)hlid);
  1083. cmd->lid_key_type = lid_type;
  1084. cmd->hlid = hlid;
  1085. cmd->key_action = cpu_to_le16(action);
  1086. cmd->key_size = key_size;
  1087. cmd->key_type = key_type;
  1088. cmd->key_id = id;
  1089. cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
  1090. cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
  1091. if (key_type == KEY_TKIP) {
  1092. /*
  1093. * We get the key in the following form:
  1094. * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
  1095. * but the target is expecting:
  1096. * TKIP - RX MIC - TX MIC
  1097. */
  1098. memcpy(cmd->key, key, 16);
  1099. memcpy(cmd->key + 16, key + 24, 8);
  1100. memcpy(cmd->key + 24, key + 16, 8);
  1101. } else {
  1102. memcpy(cmd->key, key, key_size);
  1103. }
  1104. wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
  1105. ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
  1106. if (ret < 0) {
  1107. wl1271_warning("could not set ap keys");
  1108. goto out;
  1109. }
  1110. out:
  1111. kfree(cmd);
  1112. return ret;
  1113. }
  1114. int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
  1115. {
  1116. struct wl12xx_cmd_set_peer_state *cmd;
  1117. int ret = 0;
  1118. wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
  1119. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1120. if (!cmd) {
  1121. ret = -ENOMEM;
  1122. goto out;
  1123. }
  1124. cmd->hlid = hlid;
  1125. cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
  1126. ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
  1127. if (ret < 0) {
  1128. wl1271_error("failed to send set peer state command");
  1129. goto out_free;
  1130. }
  1131. out_free:
  1132. kfree(cmd);
  1133. out:
  1134. return ret;
  1135. }
  1136. int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1137. struct ieee80211_sta *sta, u8 hlid)
  1138. {
  1139. struct wl12xx_cmd_add_peer *cmd;
  1140. int i, ret;
  1141. u32 sta_rates;
  1142. wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
  1143. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1144. if (!cmd) {
  1145. ret = -ENOMEM;
  1146. goto out;
  1147. }
  1148. memcpy(cmd->addr, sta->addr, ETH_ALEN);
  1149. cmd->bss_index = WL1271_AP_BSS_INDEX;
  1150. cmd->aid = sta->aid;
  1151. cmd->hlid = hlid;
  1152. cmd->sp_len = sta->max_sp;
  1153. cmd->wmm = sta->wme ? 1 : 0;
  1154. for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
  1155. if (sta->wme && (sta->uapsd_queues & BIT(i)))
  1156. cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
  1157. WL1271_PSD_UPSD_TRIGGER;
  1158. else
  1159. cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
  1160. WL1271_PSD_LEGACY;
  1161. sta_rates = sta->supp_rates[wlvif->band];
  1162. if (sta->ht_cap.ht_supported)
  1163. sta_rates |=
  1164. (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
  1165. (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
  1166. cmd->supported_rates =
  1167. cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
  1168. wlvif->band));
  1169. wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
  1170. cmd->supported_rates, sta->uapsd_queues);
  1171. ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
  1172. if (ret < 0) {
  1173. wl1271_error("failed to initiate cmd add peer");
  1174. goto out_free;
  1175. }
  1176. out_free:
  1177. kfree(cmd);
  1178. out:
  1179. return ret;
  1180. }
  1181. int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
  1182. {
  1183. struct wl12xx_cmd_remove_peer *cmd;
  1184. int ret;
  1185. bool timeout = false;
  1186. wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
  1187. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1188. if (!cmd) {
  1189. ret = -ENOMEM;
  1190. goto out;
  1191. }
  1192. cmd->hlid = hlid;
  1193. /* We never send a deauth, mac80211 is in charge of this */
  1194. cmd->reason_opcode = 0;
  1195. cmd->send_deauth_flag = 0;
  1196. ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
  1197. if (ret < 0) {
  1198. wl1271_error("failed to initiate cmd remove peer");
  1199. goto out_free;
  1200. }
  1201. ret = wl1271_cmd_wait_for_event_or_timeout(wl,
  1202. PEER_REMOVE_COMPLETE_EVENT_ID,
  1203. &timeout);
  1204. /*
  1205. * We are ok with a timeout here. The event is sometimes not sent
  1206. * due to a firmware bug. In case of another error (like SDIO timeout)
  1207. * queue a recovery.
  1208. */
  1209. if (ret)
  1210. wl12xx_queue_recovery_work(wl);
  1211. out_free:
  1212. kfree(cmd);
  1213. out:
  1214. return ret;
  1215. }
  1216. int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
  1217. {
  1218. struct wl12xx_cmd_config_fwlog *cmd;
  1219. int ret = 0;
  1220. wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
  1221. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1222. if (!cmd) {
  1223. ret = -ENOMEM;
  1224. goto out;
  1225. }
  1226. cmd->logger_mode = wl->conf.fwlog.mode;
  1227. cmd->log_severity = wl->conf.fwlog.severity;
  1228. cmd->timestamp = wl->conf.fwlog.timestamp;
  1229. cmd->output = wl->conf.fwlog.output;
  1230. cmd->threshold = wl->conf.fwlog.threshold;
  1231. ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
  1232. if (ret < 0) {
  1233. wl1271_error("failed to send config firmware logger command");
  1234. goto out_free;
  1235. }
  1236. out_free:
  1237. kfree(cmd);
  1238. out:
  1239. return ret;
  1240. }
  1241. int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
  1242. {
  1243. struct wl12xx_cmd_start_fwlog *cmd;
  1244. int ret = 0;
  1245. wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
  1246. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1247. if (!cmd) {
  1248. ret = -ENOMEM;
  1249. goto out;
  1250. }
  1251. ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
  1252. if (ret < 0) {
  1253. wl1271_error("failed to send start firmware logger command");
  1254. goto out_free;
  1255. }
  1256. out_free:
  1257. kfree(cmd);
  1258. out:
  1259. return ret;
  1260. }
  1261. int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
  1262. {
  1263. struct wl12xx_cmd_stop_fwlog *cmd;
  1264. int ret = 0;
  1265. wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
  1266. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1267. if (!cmd) {
  1268. ret = -ENOMEM;
  1269. goto out;
  1270. }
  1271. ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
  1272. if (ret < 0) {
  1273. wl1271_error("failed to send stop firmware logger command");
  1274. goto out_free;
  1275. }
  1276. out_free:
  1277. kfree(cmd);
  1278. out:
  1279. return ret;
  1280. }
  1281. static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1282. u8 role_id)
  1283. {
  1284. struct wl12xx_cmd_roc *cmd;
  1285. int ret = 0;
  1286. wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
  1287. if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
  1288. return -EINVAL;
  1289. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1290. if (!cmd) {
  1291. ret = -ENOMEM;
  1292. goto out;
  1293. }
  1294. cmd->role_id = role_id;
  1295. cmd->channel = wlvif->channel;
  1296. switch (wlvif->band) {
  1297. case IEEE80211_BAND_2GHZ:
  1298. cmd->band = WLCORE_BAND_2_4GHZ;
  1299. break;
  1300. case IEEE80211_BAND_5GHZ:
  1301. cmd->band = WLCORE_BAND_5GHZ;
  1302. break;
  1303. default:
  1304. wl1271_error("roc - unknown band: %d", (int)wlvif->band);
  1305. ret = -EINVAL;
  1306. goto out_free;
  1307. }
  1308. ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
  1309. if (ret < 0) {
  1310. wl1271_error("failed to send ROC command");
  1311. goto out_free;
  1312. }
  1313. out_free:
  1314. kfree(cmd);
  1315. out:
  1316. return ret;
  1317. }
  1318. static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
  1319. {
  1320. struct wl12xx_cmd_croc *cmd;
  1321. int ret = 0;
  1322. wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
  1323. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1324. if (!cmd) {
  1325. ret = -ENOMEM;
  1326. goto out;
  1327. }
  1328. cmd->role_id = role_id;
  1329. ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
  1330. sizeof(*cmd), 0);
  1331. if (ret < 0) {
  1332. wl1271_error("failed to send ROC command");
  1333. goto out_free;
  1334. }
  1335. out_free:
  1336. kfree(cmd);
  1337. out:
  1338. return ret;
  1339. }
  1340. int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
  1341. {
  1342. int ret = 0;
  1343. bool is_first_roc;
  1344. if (WARN_ON(test_bit(role_id, wl->roc_map)))
  1345. return 0;
  1346. is_first_roc = (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >=
  1347. WL12XX_MAX_ROLES);
  1348. ret = wl12xx_cmd_roc(wl, wlvif, role_id);
  1349. if (ret < 0)
  1350. goto out;
  1351. if (is_first_roc) {
  1352. ret = wl1271_cmd_wait_for_event(wl,
  1353. REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
  1354. if (ret < 0) {
  1355. wl1271_error("cmd roc event completion error");
  1356. goto out;
  1357. }
  1358. }
  1359. __set_bit(role_id, wl->roc_map);
  1360. out:
  1361. return ret;
  1362. }
  1363. int wl12xx_croc(struct wl1271 *wl, u8 role_id)
  1364. {
  1365. int ret = 0;
  1366. if (WARN_ON(!test_bit(role_id, wl->roc_map)))
  1367. return 0;
  1368. ret = wl12xx_cmd_croc(wl, role_id);
  1369. if (ret < 0)
  1370. goto out;
  1371. __clear_bit(role_id, wl->roc_map);
  1372. /*
  1373. * Rearm the tx watchdog when removing the last ROC. This prevents
  1374. * recoveries due to just finished ROCs - when Tx hasn't yet had
  1375. * a chance to get out.
  1376. */
  1377. if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
  1378. wl12xx_rearm_tx_watchdog_locked(wl);
  1379. out:
  1380. return ret;
  1381. }
  1382. int wl12xx_cmd_channel_switch(struct wl1271 *wl,
  1383. struct wl12xx_vif *wlvif,
  1384. struct ieee80211_channel_switch *ch_switch)
  1385. {
  1386. struct wl12xx_cmd_channel_switch *cmd;
  1387. int ret;
  1388. wl1271_debug(DEBUG_ACX, "cmd channel switch");
  1389. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1390. if (!cmd) {
  1391. ret = -ENOMEM;
  1392. goto out;
  1393. }
  1394. cmd->role_id = wlvif->role_id;
  1395. cmd->channel = ch_switch->channel->hw_value;
  1396. cmd->switch_time = ch_switch->count;
  1397. cmd->stop_tx = ch_switch->block_tx;
  1398. /* FIXME: control from mac80211 in the future */
  1399. cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
  1400. ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
  1401. if (ret < 0) {
  1402. wl1271_error("failed to send channel switch command");
  1403. goto out_free;
  1404. }
  1405. out_free:
  1406. kfree(cmd);
  1407. out:
  1408. return ret;
  1409. }
  1410. int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
  1411. {
  1412. struct wl12xx_cmd_stop_channel_switch *cmd;
  1413. int ret;
  1414. wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
  1415. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1416. if (!cmd) {
  1417. ret = -ENOMEM;
  1418. goto out;
  1419. }
  1420. ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
  1421. if (ret < 0) {
  1422. wl1271_error("failed to stop channel switch command");
  1423. goto out_free;
  1424. }
  1425. out_free:
  1426. kfree(cmd);
  1427. out:
  1428. return ret;
  1429. }
  1430. /* start dev role and roc on its channel */
  1431. int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1432. {
  1433. int ret;
  1434. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1435. wlvif->bss_type == BSS_TYPE_IBSS)))
  1436. return -EINVAL;
  1437. ret = wl12xx_cmd_role_enable(wl,
  1438. wl12xx_wlvif_to_vif(wlvif)->addr,
  1439. WL1271_ROLE_DEVICE,
  1440. &wlvif->dev_role_id);
  1441. if (ret < 0)
  1442. goto out;
  1443. ret = wl12xx_cmd_role_start_dev(wl, wlvif);
  1444. if (ret < 0)
  1445. goto out_disable;
  1446. ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
  1447. if (ret < 0)
  1448. goto out_stop;
  1449. return 0;
  1450. out_stop:
  1451. wl12xx_cmd_role_stop_dev(wl, wlvif);
  1452. out_disable:
  1453. wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
  1454. out:
  1455. return ret;
  1456. }
  1457. /* croc dev hlid, and stop the role */
  1458. int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1459. {
  1460. int ret;
  1461. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1462. wlvif->bss_type == BSS_TYPE_IBSS)))
  1463. return -EINVAL;
  1464. /* flush all pending packets */
  1465. ret = wlcore_tx_work_locked(wl);
  1466. if (ret < 0)
  1467. goto out;
  1468. if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
  1469. ret = wl12xx_croc(wl, wlvif->dev_role_id);
  1470. if (ret < 0)
  1471. goto out;
  1472. }
  1473. ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
  1474. if (ret < 0)
  1475. goto out;
  1476. ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
  1477. if (ret < 0)
  1478. goto out;
  1479. out:
  1480. return ret;
  1481. }