cmd.c 42 KB

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