cmd.c 41 KB

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