cmd.c 46 KB

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