cmd.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837
  1. /*
  2. * This file is part of wl1271
  3. *
  4. * Copyright (C) 2009-2010 Nokia Corporation
  5. *
  6. * Contact: Luciano Coelho <luciano.coelho@nokia.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/spi/spi.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/ieee80211.h>
  28. #include <linux/slab.h>
  29. #include "wlcore.h"
  30. #include "debug.h"
  31. #include "io.h"
  32. #include "acx.h"
  33. #include "wl12xx_80211.h"
  34. #include "cmd.h"
  35. #include "event.h"
  36. #include "tx.h"
  37. #include "hw_ops.h"
  38. #define WL1271_CMD_FAST_POLL_COUNT 50
  39. #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20
  40. /*
  41. * send command to firmware
  42. *
  43. * @wl: wl struct
  44. * @id: command id
  45. * @buf: buffer containing the command, must work with dma
  46. * @len: length of the buffer
  47. */
  48. int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
  49. size_t res_len)
  50. {
  51. struct wl1271_cmd_header *cmd;
  52. unsigned long timeout;
  53. u32 intr;
  54. int ret = 0;
  55. u16 status;
  56. u16 poll_count = 0;
  57. if (WARN_ON(unlikely(wl->state == WLCORE_STATE_RESTARTING)))
  58. return -EIO;
  59. cmd = buf;
  60. cmd->id = cpu_to_le16(id);
  61. cmd->status = 0;
  62. WARN_ON(len % 4 != 0);
  63. WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
  64. ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false);
  65. if (ret < 0)
  66. goto fail;
  67. /*
  68. * TODO: we just need this because one bit is in a different
  69. * place. Is there any better way?
  70. */
  71. ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len);
  72. if (ret < 0)
  73. goto fail;
  74. timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
  75. ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
  76. if (ret < 0)
  77. goto fail;
  78. while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
  79. if (time_after(jiffies, timeout)) {
  80. wl1271_error("command complete timeout");
  81. ret = -ETIMEDOUT;
  82. goto fail;
  83. }
  84. poll_count++;
  85. if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
  86. udelay(10);
  87. else
  88. msleep(1);
  89. ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
  90. if (ret < 0)
  91. goto fail;
  92. }
  93. /* read back the status code of the command */
  94. if (res_len == 0)
  95. res_len = sizeof(struct wl1271_cmd_header);
  96. ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false);
  97. if (ret < 0)
  98. goto fail;
  99. status = le16_to_cpu(cmd->status);
  100. if (status != CMD_STATUS_SUCCESS) {
  101. wl1271_error("command execute failure %d", status);
  102. ret = -EIO;
  103. goto fail;
  104. }
  105. ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK,
  106. WL1271_ACX_INTR_CMD_COMPLETE);
  107. if (ret < 0)
  108. goto fail;
  109. return 0;
  110. fail:
  111. wl12xx_queue_recovery_work(wl);
  112. return ret;
  113. }
  114. /*
  115. * Poll the mailbox event field until any of the bits in the mask is set or a
  116. * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
  117. */
  118. static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl,
  119. u32 mask, bool *timeout)
  120. {
  121. u32 *events_vector;
  122. u32 event;
  123. unsigned long timeout_time;
  124. u16 poll_count = 0;
  125. int ret = 0;
  126. *timeout = false;
  127. events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA);
  128. if (!events_vector)
  129. return -ENOMEM;
  130. timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
  131. do {
  132. if (time_after(jiffies, timeout_time)) {
  133. wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
  134. (int)mask);
  135. *timeout = true;
  136. goto out;
  137. }
  138. poll_count++;
  139. if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT)
  140. usleep_range(50, 51);
  141. else
  142. usleep_range(1000, 5000);
  143. /* read from both event fields */
  144. ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector,
  145. sizeof(*events_vector), false);
  146. if (ret < 0)
  147. goto out;
  148. event = *events_vector & mask;
  149. ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector,
  150. sizeof(*events_vector), false);
  151. if (ret < 0)
  152. goto out;
  153. event |= *events_vector & mask;
  154. } while (!event);
  155. out:
  156. kfree(events_vector);
  157. return ret;
  158. }
  159. static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
  160. {
  161. int ret;
  162. bool timeout = false;
  163. ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask, &timeout);
  164. if (ret != 0 || timeout) {
  165. wl12xx_queue_recovery_work(wl);
  166. return ret;
  167. }
  168. return 0;
  169. }
  170. int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
  171. u8 *role_id)
  172. {
  173. struct wl12xx_cmd_role_enable *cmd;
  174. int ret;
  175. wl1271_debug(DEBUG_CMD, "cmd role enable");
  176. if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
  177. return -EBUSY;
  178. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  179. if (!cmd) {
  180. ret = -ENOMEM;
  181. goto out;
  182. }
  183. /* get role id */
  184. cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
  185. if (cmd->role_id >= WL12XX_MAX_ROLES) {
  186. ret = -EBUSY;
  187. goto out_free;
  188. }
  189. memcpy(cmd->mac_address, addr, ETH_ALEN);
  190. cmd->role_type = role_type;
  191. ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
  192. if (ret < 0) {
  193. wl1271_error("failed to initiate cmd role enable");
  194. goto out_free;
  195. }
  196. __set_bit(cmd->role_id, wl->roles_map);
  197. *role_id = cmd->role_id;
  198. out_free:
  199. kfree(cmd);
  200. out:
  201. return ret;
  202. }
  203. int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
  204. {
  205. struct wl12xx_cmd_role_disable *cmd;
  206. int ret;
  207. wl1271_debug(DEBUG_CMD, "cmd role disable");
  208. if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
  209. return -ENOENT;
  210. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  211. if (!cmd) {
  212. ret = -ENOMEM;
  213. goto out;
  214. }
  215. cmd->role_id = *role_id;
  216. ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
  217. if (ret < 0) {
  218. wl1271_error("failed to initiate cmd role disable");
  219. goto out_free;
  220. }
  221. __clear_bit(*role_id, wl->roles_map);
  222. *role_id = WL12XX_INVALID_ROLE_ID;
  223. out_free:
  224. kfree(cmd);
  225. out:
  226. return ret;
  227. }
  228. int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
  229. {
  230. unsigned long flags;
  231. u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
  232. if (link >= WL12XX_MAX_LINKS)
  233. return -EBUSY;
  234. /* these bits are used by op_tx */
  235. spin_lock_irqsave(&wl->wl_lock, flags);
  236. __set_bit(link, wl->links_map);
  237. __set_bit(link, wlvif->links_map);
  238. spin_unlock_irqrestore(&wl->wl_lock, flags);
  239. *hlid = link;
  240. return 0;
  241. }
  242. void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
  243. {
  244. unsigned long flags;
  245. if (*hlid == WL12XX_INVALID_LINK_ID)
  246. return;
  247. /* these bits are used by op_tx */
  248. spin_lock_irqsave(&wl->wl_lock, flags);
  249. __clear_bit(*hlid, wl->links_map);
  250. __clear_bit(*hlid, wlvif->links_map);
  251. spin_unlock_irqrestore(&wl->wl_lock, flags);
  252. /*
  253. * At this point op_tx() will not add more packets to the queues. We
  254. * can purge them.
  255. */
  256. wl1271_tx_reset_link_queues(wl, *hlid);
  257. *hlid = WL12XX_INVALID_LINK_ID;
  258. }
  259. static int wl12xx_get_new_session_id(struct wl1271 *wl,
  260. struct wl12xx_vif *wlvif)
  261. {
  262. if (wlvif->session_counter >= SESSION_COUNTER_MAX)
  263. wlvif->session_counter = 0;
  264. wlvif->session_counter++;
  265. return wlvif->session_counter;
  266. }
  267. static u8 wlcore_get_native_channel_type(u8 nl_channel_type)
  268. {
  269. switch (nl_channel_type) {
  270. case NL80211_CHAN_NO_HT:
  271. return WLCORE_CHAN_NO_HT;
  272. case NL80211_CHAN_HT20:
  273. return WLCORE_CHAN_HT20;
  274. case NL80211_CHAN_HT40MINUS:
  275. return WLCORE_CHAN_HT40MINUS;
  276. case NL80211_CHAN_HT40PLUS:
  277. return WLCORE_CHAN_HT40PLUS;
  278. default:
  279. WARN_ON(1);
  280. return WLCORE_CHAN_NO_HT;
  281. }
  282. }
  283. static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
  284. struct wl12xx_vif *wlvif,
  285. enum ieee80211_band band,
  286. int channel)
  287. {
  288. struct wl12xx_cmd_role_start *cmd;
  289. int ret;
  290. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  291. if (!cmd) {
  292. ret = -ENOMEM;
  293. goto out;
  294. }
  295. wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
  296. cmd->role_id = wlvif->dev_role_id;
  297. if (band == IEEE80211_BAND_5GHZ)
  298. cmd->band = WLCORE_BAND_5GHZ;
  299. cmd->channel = channel;
  300. if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
  301. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
  302. if (ret)
  303. goto out_free;
  304. }
  305. cmd->device.hlid = wlvif->dev_hlid;
  306. cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
  307. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
  308. cmd->role_id, cmd->device.hlid, cmd->device.session);
  309. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  310. if (ret < 0) {
  311. wl1271_error("failed to initiate cmd role enable");
  312. goto err_hlid;
  313. }
  314. goto out_free;
  315. err_hlid:
  316. /* clear links on error */
  317. wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
  318. out_free:
  319. kfree(cmd);
  320. out:
  321. return ret;
  322. }
  323. static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
  324. struct wl12xx_vif *wlvif)
  325. {
  326. struct wl12xx_cmd_role_stop *cmd;
  327. int ret;
  328. if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
  329. return -EINVAL;
  330. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  331. if (!cmd) {
  332. ret = -ENOMEM;
  333. goto out;
  334. }
  335. wl1271_debug(DEBUG_CMD, "cmd role stop dev");
  336. cmd->role_id = wlvif->dev_role_id;
  337. cmd->disc_type = DISCONNECT_IMMEDIATE;
  338. cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
  339. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  340. if (ret < 0) {
  341. wl1271_error("failed to initiate cmd role stop");
  342. goto out_free;
  343. }
  344. ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
  345. if (ret < 0) {
  346. wl1271_error("cmd role stop dev event completion error");
  347. goto out_free;
  348. }
  349. wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
  350. out_free:
  351. kfree(cmd);
  352. out:
  353. return ret;
  354. }
  355. int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  356. {
  357. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  358. struct wl12xx_cmd_role_start *cmd;
  359. int ret;
  360. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  361. if (!cmd) {
  362. ret = -ENOMEM;
  363. goto out;
  364. }
  365. wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
  366. cmd->role_id = wlvif->role_id;
  367. if (wlvif->band == IEEE80211_BAND_5GHZ)
  368. cmd->band = WLCORE_BAND_5GHZ;
  369. cmd->channel = wlvif->channel;
  370. cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  371. cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  372. cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
  373. cmd->sta.ssid_len = wlvif->ssid_len;
  374. memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
  375. memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
  376. cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
  377. cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
  378. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
  379. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
  380. if (ret)
  381. goto out_free;
  382. }
  383. cmd->sta.hlid = wlvif->sta.hlid;
  384. cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
  385. cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
  386. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
  387. "basic_rate_set: 0x%x, remote_rates: 0x%x",
  388. wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
  389. wlvif->basic_rate_set, wlvif->rate_set);
  390. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  391. if (ret < 0) {
  392. wl1271_error("failed to initiate cmd role start sta");
  393. goto err_hlid;
  394. }
  395. goto out_free;
  396. err_hlid:
  397. /* clear links on error. */
  398. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  399. out_free:
  400. kfree(cmd);
  401. out:
  402. return ret;
  403. }
  404. /* use this function to stop ibss as well */
  405. int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  406. {
  407. struct wl12xx_cmd_role_stop *cmd;
  408. int ret;
  409. bool timeout = false;
  410. if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
  411. return -EINVAL;
  412. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  413. if (!cmd) {
  414. ret = -ENOMEM;
  415. goto out;
  416. }
  417. wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
  418. cmd->role_id = wlvif->role_id;
  419. cmd->disc_type = DISCONNECT_IMMEDIATE;
  420. cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
  421. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  422. if (ret < 0) {
  423. wl1271_error("failed to initiate cmd role stop sta");
  424. goto out_free;
  425. }
  426. /*
  427. * Sometimes the firmware doesn't send this event, so we just
  428. * time out without failing. Queue recovery for other
  429. * failures.
  430. */
  431. ret = wl1271_cmd_wait_for_event_or_timeout(wl,
  432. ROLE_STOP_COMPLETE_EVENT_ID,
  433. &timeout);
  434. if (ret)
  435. wl12xx_queue_recovery_work(wl);
  436. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  437. out_free:
  438. kfree(cmd);
  439. out:
  440. return ret;
  441. }
  442. int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  443. {
  444. struct wl12xx_cmd_role_start *cmd;
  445. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  446. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  447. u32 supported_rates;
  448. int ret;
  449. wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
  450. /* trying to use hidden SSID with an old hostapd version */
  451. if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
  452. wl1271_error("got a null SSID from beacon/bss");
  453. ret = -EINVAL;
  454. goto out;
  455. }
  456. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  457. if (!cmd) {
  458. ret = -ENOMEM;
  459. goto out;
  460. }
  461. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
  462. if (ret < 0)
  463. goto out_free;
  464. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  465. if (ret < 0)
  466. goto out_free_global;
  467. cmd->role_id = wlvif->role_id;
  468. cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
  469. cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
  470. cmd->ap.global_hlid = wlvif->ap.global_hlid;
  471. cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
  472. cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  473. cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  474. cmd->ap.dtim_interval = bss_conf->dtim_period;
  475. cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
  476. /* FIXME: Change when adding DFS */
  477. cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
  478. cmd->channel = wlvif->channel;
  479. cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
  480. if (!bss_conf->hidden_ssid) {
  481. /* take the SSID from the beacon for backward compatibility */
  482. cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
  483. cmd->ap.ssid_len = wlvif->ssid_len;
  484. memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
  485. } else {
  486. cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
  487. cmd->ap.ssid_len = bss_conf->ssid_len;
  488. memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
  489. }
  490. supported_rates = CONF_TX_AP_ENABLED_RATES | CONF_TX_MCS_RATES |
  491. wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
  492. wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x",
  493. supported_rates);
  494. cmd->ap.local_rates = cpu_to_le32(supported_rates);
  495. switch (wlvif->band) {
  496. case IEEE80211_BAND_2GHZ:
  497. cmd->band = WLCORE_BAND_2_4GHZ;
  498. break;
  499. case IEEE80211_BAND_5GHZ:
  500. cmd->band = WLCORE_BAND_5GHZ;
  501. break;
  502. default:
  503. wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
  504. cmd->band = WLCORE_BAND_2_4GHZ;
  505. break;
  506. }
  507. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  508. if (ret < 0) {
  509. wl1271_error("failed to initiate cmd role start ap");
  510. goto out_free_bcast;
  511. }
  512. goto out_free;
  513. out_free_bcast:
  514. wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  515. out_free_global:
  516. wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
  517. out_free:
  518. kfree(cmd);
  519. out:
  520. return ret;
  521. }
  522. int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  523. {
  524. struct wl12xx_cmd_role_stop *cmd;
  525. int ret;
  526. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  527. if (!cmd) {
  528. ret = -ENOMEM;
  529. goto out;
  530. }
  531. wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
  532. cmd->role_id = wlvif->role_id;
  533. ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
  534. if (ret < 0) {
  535. wl1271_error("failed to initiate cmd role stop ap");
  536. goto out_free;
  537. }
  538. wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
  539. wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
  540. out_free:
  541. kfree(cmd);
  542. out:
  543. return ret;
  544. }
  545. int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  546. {
  547. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  548. struct wl12xx_cmd_role_start *cmd;
  549. struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
  550. int ret;
  551. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  552. if (!cmd) {
  553. ret = -ENOMEM;
  554. goto out;
  555. }
  556. wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
  557. cmd->role_id = wlvif->role_id;
  558. if (wlvif->band == IEEE80211_BAND_5GHZ)
  559. cmd->band = WLCORE_BAND_5GHZ;
  560. cmd->channel = wlvif->channel;
  561. cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
  562. cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
  563. cmd->ibss.dtim_interval = bss_conf->dtim_period;
  564. cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
  565. cmd->ibss.ssid_len = wlvif->ssid_len;
  566. memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
  567. memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
  568. cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
  569. if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
  570. ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
  571. if (ret)
  572. goto out_free;
  573. }
  574. cmd->ibss.hlid = wlvif->sta.hlid;
  575. cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
  576. wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
  577. "basic_rate_set: 0x%x, remote_rates: 0x%x",
  578. wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
  579. wlvif->basic_rate_set, wlvif->rate_set);
  580. wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
  581. vif->bss_conf.bssid);
  582. ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
  583. if (ret < 0) {
  584. wl1271_error("failed to initiate cmd role enable");
  585. goto err_hlid;
  586. }
  587. goto out_free;
  588. err_hlid:
  589. /* clear links on error. */
  590. wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
  591. out_free:
  592. kfree(cmd);
  593. out:
  594. return ret;
  595. }
  596. /**
  597. * send test command to firmware
  598. *
  599. * @wl: wl struct
  600. * @buf: buffer containing the command, with all headers, must work with dma
  601. * @len: length of the buffer
  602. * @answer: is answer needed
  603. */
  604. int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
  605. {
  606. int ret;
  607. size_t res_len = 0;
  608. wl1271_debug(DEBUG_CMD, "cmd test");
  609. if (answer)
  610. res_len = buf_len;
  611. ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
  612. if (ret < 0) {
  613. wl1271_warning("TEST command failed");
  614. return ret;
  615. }
  616. return ret;
  617. }
  618. EXPORT_SYMBOL_GPL(wl1271_cmd_test);
  619. /**
  620. * read acx from firmware
  621. *
  622. * @wl: wl struct
  623. * @id: acx id
  624. * @buf: buffer for the response, including all headers, must work with dma
  625. * @len: length of buf
  626. */
  627. int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
  628. {
  629. struct acx_header *acx = buf;
  630. int ret;
  631. wl1271_debug(DEBUG_CMD, "cmd interrogate");
  632. acx->id = cpu_to_le16(id);
  633. /* payload length, does not include any headers */
  634. acx->len = cpu_to_le16(len - sizeof(*acx));
  635. ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
  636. if (ret < 0)
  637. wl1271_error("INTERROGATE command failed");
  638. return ret;
  639. }
  640. /**
  641. * write acx value to firmware
  642. *
  643. * @wl: wl struct
  644. * @id: acx id
  645. * @buf: buffer containing acx, including all headers, must work with dma
  646. * @len: length of buf
  647. */
  648. int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
  649. {
  650. struct acx_header *acx = buf;
  651. int ret;
  652. wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
  653. acx->id = cpu_to_le16(id);
  654. /* payload length, does not include any headers */
  655. acx->len = cpu_to_le16(len - sizeof(*acx));
  656. ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
  657. if (ret < 0) {
  658. wl1271_warning("CONFIGURE command NOK");
  659. return ret;
  660. }
  661. return 0;
  662. }
  663. EXPORT_SYMBOL_GPL(wl1271_cmd_configure);
  664. int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
  665. {
  666. struct cmd_enabledisable_path *cmd;
  667. int ret;
  668. u16 cmd_rx, cmd_tx;
  669. wl1271_debug(DEBUG_CMD, "cmd data path");
  670. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  671. if (!cmd) {
  672. ret = -ENOMEM;
  673. goto out;
  674. }
  675. /* the channel here is only used for calibration, so hardcoded to 1 */
  676. cmd->channel = 1;
  677. if (enable) {
  678. cmd_rx = CMD_ENABLE_RX;
  679. cmd_tx = CMD_ENABLE_TX;
  680. } else {
  681. cmd_rx = CMD_DISABLE_RX;
  682. cmd_tx = CMD_DISABLE_TX;
  683. }
  684. ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
  685. if (ret < 0) {
  686. wl1271_error("rx %s cmd for channel %d failed",
  687. enable ? "start" : "stop", cmd->channel);
  688. goto out;
  689. }
  690. wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
  691. enable ? "start" : "stop", cmd->channel);
  692. ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
  693. if (ret < 0) {
  694. wl1271_error("tx %s cmd for channel %d failed",
  695. enable ? "start" : "stop", cmd->channel);
  696. goto out;
  697. }
  698. wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
  699. enable ? "start" : "stop", cmd->channel);
  700. out:
  701. kfree(cmd);
  702. return ret;
  703. }
  704. EXPORT_SYMBOL_GPL(wl1271_cmd_data_path);
  705. int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  706. u8 ps_mode, u16 auto_ps_timeout)
  707. {
  708. struct wl1271_cmd_ps_params *ps_params = NULL;
  709. int ret = 0;
  710. wl1271_debug(DEBUG_CMD, "cmd set ps mode");
  711. ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
  712. if (!ps_params) {
  713. ret = -ENOMEM;
  714. goto out;
  715. }
  716. ps_params->role_id = wlvif->role_id;
  717. ps_params->ps_mode = ps_mode;
  718. ps_params->auto_ps_timeout = auto_ps_timeout;
  719. ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
  720. sizeof(*ps_params), 0);
  721. if (ret < 0) {
  722. wl1271_error("cmd set_ps_mode failed");
  723. goto out;
  724. }
  725. out:
  726. kfree(ps_params);
  727. return ret;
  728. }
  729. int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
  730. u16 template_id, void *buf, size_t buf_len,
  731. int index, u32 rates)
  732. {
  733. struct wl1271_cmd_template_set *cmd;
  734. int ret = 0;
  735. wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
  736. template_id, role_id);
  737. WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
  738. buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
  739. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  740. if (!cmd) {
  741. ret = -ENOMEM;
  742. goto out;
  743. }
  744. /* during initialization wlvif is NULL */
  745. cmd->role_id = role_id;
  746. cmd->len = cpu_to_le16(buf_len);
  747. cmd->template_type = template_id;
  748. cmd->enabled_rates = cpu_to_le32(rates);
  749. cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
  750. cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
  751. cmd->index = index;
  752. if (buf)
  753. memcpy(cmd->template_data, buf, buf_len);
  754. ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
  755. if (ret < 0) {
  756. wl1271_warning("cmd set_template failed: %d", ret);
  757. goto out_free;
  758. }
  759. out_free:
  760. kfree(cmd);
  761. out:
  762. return ret;
  763. }
  764. int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  765. {
  766. struct sk_buff *skb = NULL;
  767. int size;
  768. void *ptr;
  769. int ret = -ENOMEM;
  770. if (wlvif->bss_type == BSS_TYPE_IBSS) {
  771. size = sizeof(struct wl12xx_null_data_template);
  772. ptr = NULL;
  773. } else {
  774. skb = ieee80211_nullfunc_get(wl->hw,
  775. wl12xx_wlvif_to_vif(wlvif));
  776. if (!skb)
  777. goto out;
  778. size = skb->len;
  779. ptr = skb->data;
  780. }
  781. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  782. CMD_TEMPL_NULL_DATA, ptr, size, 0,
  783. wlvif->basic_rate);
  784. out:
  785. dev_kfree_skb(skb);
  786. if (ret)
  787. wl1271_warning("cmd buld null data failed %d", ret);
  788. return ret;
  789. }
  790. int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
  791. struct wl12xx_vif *wlvif)
  792. {
  793. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  794. struct sk_buff *skb = NULL;
  795. int ret = -ENOMEM;
  796. skb = ieee80211_nullfunc_get(wl->hw, vif);
  797. if (!skb)
  798. goto out;
  799. ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
  800. skb->data, skb->len,
  801. wlvif->sta.klv_template_id,
  802. wlvif->basic_rate);
  803. out:
  804. dev_kfree_skb(skb);
  805. if (ret)
  806. wl1271_warning("cmd build klv null data failed %d", ret);
  807. return ret;
  808. }
  809. int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  810. u16 aid)
  811. {
  812. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  813. struct sk_buff *skb;
  814. int ret = 0;
  815. skb = ieee80211_pspoll_get(wl->hw, vif);
  816. if (!skb)
  817. goto out;
  818. ret = wl1271_cmd_template_set(wl, wlvif->role_id,
  819. CMD_TEMPL_PS_POLL, skb->data,
  820. skb->len, 0, wlvif->basic_rate_set);
  821. out:
  822. dev_kfree_skb(skb);
  823. return ret;
  824. }
  825. int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  826. u8 role_id, u8 band,
  827. const u8 *ssid, size_t ssid_len,
  828. const u8 *ie, size_t ie_len, bool sched_scan)
  829. {
  830. struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
  831. struct sk_buff *skb;
  832. int ret;
  833. u32 rate;
  834. u16 template_id_2_4 = CMD_TEMPL_CFG_PROBE_REQ_2_4;
  835. u16 template_id_5 = CMD_TEMPL_CFG_PROBE_REQ_5;
  836. skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
  837. ie, ie_len);
  838. if (!skb) {
  839. ret = -ENOMEM;
  840. goto out;
  841. }
  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, enum ieee80211_band band, u8 channel)
  1285. {
  1286. struct wl12xx_cmd_roc *cmd;
  1287. int ret = 0;
  1288. wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", 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 = channel;
  1298. switch (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. enum ieee80211_band band, u8 channel)
  1344. {
  1345. int ret = 0;
  1346. if (WARN_ON(test_bit(role_id, wl->roc_map)))
  1347. return 0;
  1348. ret = wl12xx_cmd_roc(wl, wlvif, role_id, band, channel);
  1349. if (ret < 0)
  1350. goto out;
  1351. __set_bit(role_id, wl->roc_map);
  1352. out:
  1353. return ret;
  1354. }
  1355. int wl12xx_croc(struct wl1271 *wl, u8 role_id)
  1356. {
  1357. int ret = 0;
  1358. if (WARN_ON(!test_bit(role_id, wl->roc_map)))
  1359. return 0;
  1360. ret = wl12xx_cmd_croc(wl, role_id);
  1361. if (ret < 0)
  1362. goto out;
  1363. __clear_bit(role_id, wl->roc_map);
  1364. /*
  1365. * Rearm the tx watchdog when removing the last ROC. This prevents
  1366. * recoveries due to just finished ROCs - when Tx hasn't yet had
  1367. * a chance to get out.
  1368. */
  1369. if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
  1370. wl12xx_rearm_tx_watchdog_locked(wl);
  1371. out:
  1372. return ret;
  1373. }
  1374. int wl12xx_cmd_channel_switch(struct wl1271 *wl,
  1375. struct wl12xx_vif *wlvif,
  1376. struct ieee80211_channel_switch *ch_switch)
  1377. {
  1378. struct wl12xx_cmd_channel_switch *cmd;
  1379. int ret;
  1380. wl1271_debug(DEBUG_ACX, "cmd channel switch");
  1381. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1382. if (!cmd) {
  1383. ret = -ENOMEM;
  1384. goto out;
  1385. }
  1386. cmd->role_id = wlvif->role_id;
  1387. cmd->channel = ch_switch->channel->hw_value;
  1388. cmd->switch_time = ch_switch->count;
  1389. cmd->stop_tx = ch_switch->block_tx;
  1390. /* FIXME: control from mac80211 in the future */
  1391. cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
  1392. ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
  1393. if (ret < 0) {
  1394. wl1271_error("failed to send channel switch command");
  1395. goto out_free;
  1396. }
  1397. out_free:
  1398. kfree(cmd);
  1399. out:
  1400. return ret;
  1401. }
  1402. int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
  1403. {
  1404. struct wl12xx_cmd_stop_channel_switch *cmd;
  1405. int ret;
  1406. wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
  1407. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1408. if (!cmd) {
  1409. ret = -ENOMEM;
  1410. goto out;
  1411. }
  1412. ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
  1413. if (ret < 0) {
  1414. wl1271_error("failed to stop channel switch command");
  1415. goto out_free;
  1416. }
  1417. out_free:
  1418. kfree(cmd);
  1419. out:
  1420. return ret;
  1421. }
  1422. /* start dev role and roc on its channel */
  1423. int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif,
  1424. enum ieee80211_band band, int channel)
  1425. {
  1426. int ret;
  1427. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1428. wlvif->bss_type == BSS_TYPE_IBSS)))
  1429. return -EINVAL;
  1430. ret = wl12xx_cmd_role_enable(wl,
  1431. wl12xx_wlvif_to_vif(wlvif)->addr,
  1432. WL1271_ROLE_DEVICE,
  1433. &wlvif->dev_role_id);
  1434. if (ret < 0)
  1435. goto out;
  1436. ret = wl12xx_cmd_role_start_dev(wl, wlvif, band, channel);
  1437. if (ret < 0)
  1438. goto out_disable;
  1439. ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id, band, channel);
  1440. if (ret < 0)
  1441. goto out_stop;
  1442. return 0;
  1443. out_stop:
  1444. wl12xx_cmd_role_stop_dev(wl, wlvif);
  1445. out_disable:
  1446. wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
  1447. out:
  1448. return ret;
  1449. }
  1450. /* croc dev hlid, and stop the role */
  1451. int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
  1452. {
  1453. int ret;
  1454. if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
  1455. wlvif->bss_type == BSS_TYPE_IBSS)))
  1456. return -EINVAL;
  1457. /* flush all pending packets */
  1458. ret = wlcore_tx_work_locked(wl);
  1459. if (ret < 0)
  1460. goto out;
  1461. if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
  1462. ret = wl12xx_croc(wl, wlvif->dev_role_id);
  1463. if (ret < 0)
  1464. goto out;
  1465. }
  1466. ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
  1467. if (ret < 0)
  1468. goto out;
  1469. ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
  1470. if (ret < 0)
  1471. goto out;
  1472. out:
  1473. return ret;
  1474. }