PageRenderTime 158ms CodeModel.GetById 33ms RepoModel.GetById 5ms app.codeStats 2ms

/drivers/net/wireless/ath/ath6kl/wmi.c

http://github.com/mirrors/linux
C | 4173 lines | 3177 code | 764 blank | 232 comment | 489 complexity | 5cecb7efd1534bb7667e9e3a2b41f31d MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.0
  1. /*
  2. * Copyright (c) 2004-2011 Atheros Communications Inc.
  3. * Copyright (c) 2011-2012 Qualcomm Atheros, Inc.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <linux/ip.h>
  18. #include <linux/in.h>
  19. #include "core.h"
  20. #include "debug.h"
  21. #include "testmode.h"
  22. #include "trace.h"
  23. #include "../regd.h"
  24. #include "../regd_common.h"
  25. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx);
  26. static const s32 wmi_rate_tbl[][2] = {
  27. /* {W/O SGI, with SGI} */
  28. {1000, 1000},
  29. {2000, 2000},
  30. {5500, 5500},
  31. {11000, 11000},
  32. {6000, 6000},
  33. {9000, 9000},
  34. {12000, 12000},
  35. {18000, 18000},
  36. {24000, 24000},
  37. {36000, 36000},
  38. {48000, 48000},
  39. {54000, 54000},
  40. {6500, 7200},
  41. {13000, 14400},
  42. {19500, 21700},
  43. {26000, 28900},
  44. {39000, 43300},
  45. {52000, 57800},
  46. {58500, 65000},
  47. {65000, 72200},
  48. {13500, 15000},
  49. {27000, 30000},
  50. {40500, 45000},
  51. {54000, 60000},
  52. {81000, 90000},
  53. {108000, 120000},
  54. {121500, 135000},
  55. {135000, 150000},
  56. {0, 0}
  57. };
  58. static const s32 wmi_rate_tbl_mcs15[][2] = {
  59. /* {W/O SGI, with SGI} */
  60. {1000, 1000},
  61. {2000, 2000},
  62. {5500, 5500},
  63. {11000, 11000},
  64. {6000, 6000},
  65. {9000, 9000},
  66. {12000, 12000},
  67. {18000, 18000},
  68. {24000, 24000},
  69. {36000, 36000},
  70. {48000, 48000},
  71. {54000, 54000},
  72. {6500, 7200}, /* HT 20, MCS 0 */
  73. {13000, 14400},
  74. {19500, 21700},
  75. {26000, 28900},
  76. {39000, 43300},
  77. {52000, 57800},
  78. {58500, 65000},
  79. {65000, 72200},
  80. {13000, 14400}, /* HT 20, MCS 8 */
  81. {26000, 28900},
  82. {39000, 43300},
  83. {52000, 57800},
  84. {78000, 86700},
  85. {104000, 115600},
  86. {117000, 130000},
  87. {130000, 144400}, /* HT 20, MCS 15 */
  88. {13500, 15000}, /*HT 40, MCS 0 */
  89. {27000, 30000},
  90. {40500, 45000},
  91. {54000, 60000},
  92. {81000, 90000},
  93. {108000, 120000},
  94. {121500, 135000},
  95. {135000, 150000},
  96. {27000, 30000}, /*HT 40, MCS 8 */
  97. {54000, 60000},
  98. {81000, 90000},
  99. {108000, 120000},
  100. {162000, 180000},
  101. {216000, 240000},
  102. {243000, 270000},
  103. {270000, 300000}, /*HT 40, MCS 15 */
  104. {0, 0}
  105. };
  106. /* 802.1d to AC mapping. Refer pg 57 of WMM-test-plan-v1.2 */
  107. static const u8 up_to_ac[] = {
  108. WMM_AC_BE,
  109. WMM_AC_BK,
  110. WMM_AC_BK,
  111. WMM_AC_BE,
  112. WMM_AC_VI,
  113. WMM_AC_VI,
  114. WMM_AC_VO,
  115. WMM_AC_VO,
  116. };
  117. void ath6kl_wmi_set_control_ep(struct wmi *wmi, enum htc_endpoint_id ep_id)
  118. {
  119. if (WARN_ON(ep_id == ENDPOINT_UNUSED || ep_id >= ENDPOINT_MAX))
  120. return;
  121. wmi->ep_id = ep_id;
  122. }
  123. enum htc_endpoint_id ath6kl_wmi_get_control_ep(struct wmi *wmi)
  124. {
  125. return wmi->ep_id;
  126. }
  127. struct ath6kl_vif *ath6kl_get_vif_by_index(struct ath6kl *ar, u8 if_idx)
  128. {
  129. struct ath6kl_vif *vif, *found = NULL;
  130. if (WARN_ON(if_idx > (ar->vif_max - 1)))
  131. return NULL;
  132. /* FIXME: Locking */
  133. spin_lock_bh(&ar->list_lock);
  134. list_for_each_entry(vif, &ar->vif_list, list) {
  135. if (vif->fw_vif_idx == if_idx) {
  136. found = vif;
  137. break;
  138. }
  139. }
  140. spin_unlock_bh(&ar->list_lock);
  141. return found;
  142. }
  143. /* Performs DIX to 802.3 encapsulation for transmit packets.
  144. * Assumes the entire DIX header is contiguous and that there is
  145. * enough room in the buffer for a 802.3 mac header and LLC+SNAP headers.
  146. */
  147. int ath6kl_wmi_dix_2_dot3(struct wmi *wmi, struct sk_buff *skb)
  148. {
  149. struct ath6kl_llc_snap_hdr *llc_hdr;
  150. struct ethhdr *eth_hdr;
  151. size_t new_len;
  152. __be16 type;
  153. u8 *datap;
  154. u16 size;
  155. if (WARN_ON(skb == NULL))
  156. return -EINVAL;
  157. size = sizeof(struct ath6kl_llc_snap_hdr) + sizeof(struct wmi_data_hdr);
  158. if (skb_headroom(skb) < size)
  159. return -ENOMEM;
  160. eth_hdr = (struct ethhdr *) skb->data;
  161. type = eth_hdr->h_proto;
  162. if (!is_ethertype(be16_to_cpu(type))) {
  163. ath6kl_dbg(ATH6KL_DBG_WMI,
  164. "%s: pkt is already in 802.3 format\n", __func__);
  165. return 0;
  166. }
  167. new_len = skb->len - sizeof(*eth_hdr) + sizeof(*llc_hdr);
  168. skb_push(skb, sizeof(struct ath6kl_llc_snap_hdr));
  169. datap = skb->data;
  170. eth_hdr->h_proto = cpu_to_be16(new_len);
  171. memcpy(datap, eth_hdr, sizeof(*eth_hdr));
  172. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap + sizeof(*eth_hdr));
  173. llc_hdr->dsap = 0xAA;
  174. llc_hdr->ssap = 0xAA;
  175. llc_hdr->cntl = 0x03;
  176. llc_hdr->org_code[0] = 0x0;
  177. llc_hdr->org_code[1] = 0x0;
  178. llc_hdr->org_code[2] = 0x0;
  179. llc_hdr->eth_type = type;
  180. return 0;
  181. }
  182. static int ath6kl_wmi_meta_add(struct wmi *wmi, struct sk_buff *skb,
  183. u8 *version, void *tx_meta_info)
  184. {
  185. struct wmi_tx_meta_v1 *v1;
  186. struct wmi_tx_meta_v2 *v2;
  187. if (WARN_ON(skb == NULL || version == NULL))
  188. return -EINVAL;
  189. switch (*version) {
  190. case WMI_META_VERSION_1:
  191. skb_push(skb, WMI_MAX_TX_META_SZ);
  192. v1 = (struct wmi_tx_meta_v1 *) skb->data;
  193. v1->pkt_id = 0;
  194. v1->rate_plcy_id = 0;
  195. *version = WMI_META_VERSION_1;
  196. break;
  197. case WMI_META_VERSION_2:
  198. skb_push(skb, WMI_MAX_TX_META_SZ);
  199. v2 = (struct wmi_tx_meta_v2 *) skb->data;
  200. memcpy(v2, (struct wmi_tx_meta_v2 *) tx_meta_info,
  201. sizeof(struct wmi_tx_meta_v2));
  202. break;
  203. }
  204. return 0;
  205. }
  206. int ath6kl_wmi_data_hdr_add(struct wmi *wmi, struct sk_buff *skb,
  207. u8 msg_type, u32 flags,
  208. enum wmi_data_hdr_data_type data_type,
  209. u8 meta_ver, void *tx_meta_info, u8 if_idx)
  210. {
  211. struct wmi_data_hdr *data_hdr;
  212. int ret;
  213. if (WARN_ON(skb == NULL || (if_idx > wmi->parent_dev->vif_max - 1)))
  214. return -EINVAL;
  215. if (tx_meta_info) {
  216. ret = ath6kl_wmi_meta_add(wmi, skb, &meta_ver, tx_meta_info);
  217. if (ret)
  218. return ret;
  219. }
  220. skb_push(skb, sizeof(struct wmi_data_hdr));
  221. data_hdr = (struct wmi_data_hdr *)skb->data;
  222. memset(data_hdr, 0, sizeof(struct wmi_data_hdr));
  223. data_hdr->info = msg_type << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  224. data_hdr->info |= data_type << WMI_DATA_HDR_DATA_TYPE_SHIFT;
  225. if (flags & WMI_DATA_HDR_FLAGS_MORE)
  226. data_hdr->info |= WMI_DATA_HDR_MORE;
  227. if (flags & WMI_DATA_HDR_FLAGS_EOSP)
  228. data_hdr->info3 |= cpu_to_le16(WMI_DATA_HDR_EOSP);
  229. data_hdr->info2 |= cpu_to_le16(meta_ver << WMI_DATA_HDR_META_SHIFT);
  230. data_hdr->info3 |= cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  231. return 0;
  232. }
  233. u8 ath6kl_wmi_determine_user_priority(u8 *pkt, u32 layer2_pri)
  234. {
  235. struct iphdr *ip_hdr = (struct iphdr *) pkt;
  236. u8 ip_pri;
  237. /*
  238. * Determine IPTOS priority
  239. *
  240. * IP-TOS - 8bits
  241. * : DSCP(6-bits) ECN(2-bits)
  242. * : DSCP - P2 P1 P0 X X X
  243. * where (P2 P1 P0) form 802.1D
  244. */
  245. ip_pri = ip_hdr->tos >> 5;
  246. ip_pri &= 0x7;
  247. if ((layer2_pri & 0x7) > ip_pri)
  248. return (u8) layer2_pri & 0x7;
  249. else
  250. return ip_pri;
  251. }
  252. u8 ath6kl_wmi_get_traffic_class(u8 user_priority)
  253. {
  254. return up_to_ac[user_priority & 0x7];
  255. }
  256. int ath6kl_wmi_implicit_create_pstream(struct wmi *wmi, u8 if_idx,
  257. struct sk_buff *skb,
  258. u32 layer2_priority, bool wmm_enabled,
  259. u8 *ac)
  260. {
  261. struct wmi_data_hdr *data_hdr;
  262. struct ath6kl_llc_snap_hdr *llc_hdr;
  263. struct wmi_create_pstream_cmd cmd;
  264. u32 meta_size, hdr_size;
  265. u16 ip_type = IP_ETHERTYPE;
  266. u8 stream_exist, usr_pri;
  267. u8 traffic_class = WMM_AC_BE;
  268. u8 *datap;
  269. if (WARN_ON(skb == NULL))
  270. return -EINVAL;
  271. datap = skb->data;
  272. data_hdr = (struct wmi_data_hdr *) datap;
  273. meta_size = ((le16_to_cpu(data_hdr->info2) >> WMI_DATA_HDR_META_SHIFT) &
  274. WMI_DATA_HDR_META_MASK) ? WMI_MAX_TX_META_SZ : 0;
  275. if (!wmm_enabled) {
  276. /* If WMM is disabled all traffic goes as BE traffic */
  277. usr_pri = 0;
  278. } else {
  279. hdr_size = sizeof(struct ethhdr);
  280. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap +
  281. sizeof(struct
  282. wmi_data_hdr) +
  283. meta_size + hdr_size);
  284. if (llc_hdr->eth_type == htons(ip_type)) {
  285. /*
  286. * Extract the endpoint info from the TOS field
  287. * in the IP header.
  288. */
  289. usr_pri =
  290. ath6kl_wmi_determine_user_priority(((u8 *) llc_hdr) +
  291. sizeof(struct ath6kl_llc_snap_hdr),
  292. layer2_priority);
  293. } else {
  294. usr_pri = layer2_priority & 0x7;
  295. }
  296. /*
  297. * Queue the EAPOL frames in the same WMM_AC_VO queue
  298. * as that of management frames.
  299. */
  300. if (skb->protocol == cpu_to_be16(ETH_P_PAE))
  301. usr_pri = WMI_VOICE_USER_PRIORITY;
  302. }
  303. /*
  304. * workaround for WMM S5
  305. *
  306. * FIXME: wmi->traffic_class is always 100 so this test doesn't
  307. * make sense
  308. */
  309. if ((wmi->traffic_class == WMM_AC_VI) &&
  310. ((usr_pri == 5) || (usr_pri == 4)))
  311. usr_pri = 1;
  312. /* Convert user priority to traffic class */
  313. traffic_class = up_to_ac[usr_pri & 0x7];
  314. wmi_data_hdr_set_up(data_hdr, usr_pri);
  315. spin_lock_bh(&wmi->lock);
  316. stream_exist = wmi->fat_pipe_exist;
  317. spin_unlock_bh(&wmi->lock);
  318. if (!(stream_exist & (1 << traffic_class))) {
  319. memset(&cmd, 0, sizeof(cmd));
  320. cmd.traffic_class = traffic_class;
  321. cmd.user_pri = usr_pri;
  322. cmd.inactivity_int =
  323. cpu_to_le32(WMI_IMPLICIT_PSTREAM_INACTIVITY_INT);
  324. /* Implicit streams are created with TSID 0xFF */
  325. cmd.tsid = WMI_IMPLICIT_PSTREAM;
  326. ath6kl_wmi_create_pstream_cmd(wmi, if_idx, &cmd);
  327. }
  328. *ac = traffic_class;
  329. return 0;
  330. }
  331. int ath6kl_wmi_dot11_hdr_remove(struct wmi *wmi, struct sk_buff *skb)
  332. {
  333. struct ieee80211_hdr_3addr *pwh, wh;
  334. struct ath6kl_llc_snap_hdr *llc_hdr;
  335. struct ethhdr eth_hdr;
  336. u32 hdr_size;
  337. u8 *datap;
  338. __le16 sub_type;
  339. if (WARN_ON(skb == NULL))
  340. return -EINVAL;
  341. datap = skb->data;
  342. pwh = (struct ieee80211_hdr_3addr *) datap;
  343. sub_type = pwh->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  344. memcpy((u8 *) &wh, datap, sizeof(struct ieee80211_hdr_3addr));
  345. /* Strip off the 802.11 header */
  346. if (sub_type == cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  347. hdr_size = roundup(sizeof(struct ieee80211_qos_hdr),
  348. sizeof(u32));
  349. skb_pull(skb, hdr_size);
  350. } else if (sub_type == cpu_to_le16(IEEE80211_STYPE_DATA)) {
  351. skb_pull(skb, sizeof(struct ieee80211_hdr_3addr));
  352. }
  353. datap = skb->data;
  354. llc_hdr = (struct ath6kl_llc_snap_hdr *)(datap);
  355. memset(&eth_hdr, 0, sizeof(eth_hdr));
  356. eth_hdr.h_proto = llc_hdr->eth_type;
  357. switch ((le16_to_cpu(wh.frame_control)) &
  358. (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
  359. case IEEE80211_FCTL_TODS:
  360. memcpy(eth_hdr.h_dest, wh.addr3, ETH_ALEN);
  361. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  362. break;
  363. case IEEE80211_FCTL_FROMDS:
  364. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  365. memcpy(eth_hdr.h_source, wh.addr3, ETH_ALEN);
  366. break;
  367. case IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS:
  368. break;
  369. default:
  370. memcpy(eth_hdr.h_dest, wh.addr1, ETH_ALEN);
  371. memcpy(eth_hdr.h_source, wh.addr2, ETH_ALEN);
  372. break;
  373. }
  374. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  375. skb_push(skb, sizeof(eth_hdr));
  376. datap = skb->data;
  377. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  378. return 0;
  379. }
  380. /*
  381. * Performs 802.3 to DIX encapsulation for received packets.
  382. * Assumes the entire 802.3 header is contiguous.
  383. */
  384. int ath6kl_wmi_dot3_2_dix(struct sk_buff *skb)
  385. {
  386. struct ath6kl_llc_snap_hdr *llc_hdr;
  387. struct ethhdr eth_hdr;
  388. u8 *datap;
  389. if (WARN_ON(skb == NULL))
  390. return -EINVAL;
  391. datap = skb->data;
  392. memcpy(&eth_hdr, datap, sizeof(eth_hdr));
  393. llc_hdr = (struct ath6kl_llc_snap_hdr *) (datap + sizeof(eth_hdr));
  394. eth_hdr.h_proto = llc_hdr->eth_type;
  395. skb_pull(skb, sizeof(struct ath6kl_llc_snap_hdr));
  396. datap = skb->data;
  397. memcpy(datap, &eth_hdr, sizeof(eth_hdr));
  398. return 0;
  399. }
  400. static int ath6kl_wmi_tx_complete_event_rx(u8 *datap, int len)
  401. {
  402. struct tx_complete_msg_v1 *msg_v1;
  403. struct wmi_tx_complete_event *evt;
  404. int index;
  405. u16 size;
  406. evt = (struct wmi_tx_complete_event *) datap;
  407. ath6kl_dbg(ATH6KL_DBG_WMI, "comp: %d %d %d\n",
  408. evt->num_msg, evt->msg_len, evt->msg_type);
  409. for (index = 0; index < evt->num_msg; index++) {
  410. size = sizeof(struct wmi_tx_complete_event) +
  411. (index * sizeof(struct tx_complete_msg_v1));
  412. msg_v1 = (struct tx_complete_msg_v1 *)(datap + size);
  413. ath6kl_dbg(ATH6KL_DBG_WMI, "msg: %d %d %d %d\n",
  414. msg_v1->status, msg_v1->pkt_id,
  415. msg_v1->rate_idx, msg_v1->ack_failures);
  416. }
  417. return 0;
  418. }
  419. static int ath6kl_wmi_remain_on_chnl_event_rx(struct wmi *wmi, u8 *datap,
  420. int len, struct ath6kl_vif *vif)
  421. {
  422. struct wmi_remain_on_chnl_event *ev;
  423. u32 freq;
  424. u32 dur;
  425. struct ieee80211_channel *chan;
  426. struct ath6kl *ar = wmi->parent_dev;
  427. u32 id;
  428. if (len < sizeof(*ev))
  429. return -EINVAL;
  430. ev = (struct wmi_remain_on_chnl_event *) datap;
  431. freq = le32_to_cpu(ev->freq);
  432. dur = le32_to_cpu(ev->duration);
  433. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl: freq=%u dur=%u\n",
  434. freq, dur);
  435. chan = ieee80211_get_channel(ar->wiphy, freq);
  436. if (!chan) {
  437. ath6kl_dbg(ATH6KL_DBG_WMI,
  438. "remain_on_chnl: Unknown channel (freq=%u)\n",
  439. freq);
  440. return -EINVAL;
  441. }
  442. id = vif->last_roc_id;
  443. cfg80211_ready_on_channel(&vif->wdev, id, chan,
  444. dur, GFP_ATOMIC);
  445. return 0;
  446. }
  447. static int ath6kl_wmi_cancel_remain_on_chnl_event_rx(struct wmi *wmi,
  448. u8 *datap, int len,
  449. struct ath6kl_vif *vif)
  450. {
  451. struct wmi_cancel_remain_on_chnl_event *ev;
  452. u32 freq;
  453. u32 dur;
  454. struct ieee80211_channel *chan;
  455. struct ath6kl *ar = wmi->parent_dev;
  456. u32 id;
  457. if (len < sizeof(*ev))
  458. return -EINVAL;
  459. ev = (struct wmi_cancel_remain_on_chnl_event *) datap;
  460. freq = le32_to_cpu(ev->freq);
  461. dur = le32_to_cpu(ev->duration);
  462. ath6kl_dbg(ATH6KL_DBG_WMI,
  463. "cancel_remain_on_chnl: freq=%u dur=%u status=%u\n",
  464. freq, dur, ev->status);
  465. chan = ieee80211_get_channel(ar->wiphy, freq);
  466. if (!chan) {
  467. ath6kl_dbg(ATH6KL_DBG_WMI,
  468. "cancel_remain_on_chnl: Unknown channel (freq=%u)\n",
  469. freq);
  470. return -EINVAL;
  471. }
  472. if (vif->last_cancel_roc_id &&
  473. vif->last_cancel_roc_id + 1 == vif->last_roc_id)
  474. id = vif->last_cancel_roc_id; /* event for cancel command */
  475. else
  476. id = vif->last_roc_id; /* timeout on uncanceled r-o-c */
  477. vif->last_cancel_roc_id = 0;
  478. cfg80211_remain_on_channel_expired(&vif->wdev, id, chan, GFP_ATOMIC);
  479. return 0;
  480. }
  481. static int ath6kl_wmi_tx_status_event_rx(struct wmi *wmi, u8 *datap, int len,
  482. struct ath6kl_vif *vif)
  483. {
  484. struct wmi_tx_status_event *ev;
  485. u32 id;
  486. if (len < sizeof(*ev))
  487. return -EINVAL;
  488. ev = (struct wmi_tx_status_event *) datap;
  489. id = le32_to_cpu(ev->id);
  490. ath6kl_dbg(ATH6KL_DBG_WMI, "tx_status: id=%x ack_status=%u\n",
  491. id, ev->ack_status);
  492. if (wmi->last_mgmt_tx_frame) {
  493. cfg80211_mgmt_tx_status(&vif->wdev, id,
  494. wmi->last_mgmt_tx_frame,
  495. wmi->last_mgmt_tx_frame_len,
  496. !!ev->ack_status, GFP_ATOMIC);
  497. kfree(wmi->last_mgmt_tx_frame);
  498. wmi->last_mgmt_tx_frame = NULL;
  499. wmi->last_mgmt_tx_frame_len = 0;
  500. }
  501. return 0;
  502. }
  503. static int ath6kl_wmi_rx_probe_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  504. struct ath6kl_vif *vif)
  505. {
  506. struct wmi_p2p_rx_probe_req_event *ev;
  507. u32 freq;
  508. u16 dlen;
  509. if (len < sizeof(*ev))
  510. return -EINVAL;
  511. ev = (struct wmi_p2p_rx_probe_req_event *) datap;
  512. freq = le32_to_cpu(ev->freq);
  513. dlen = le16_to_cpu(ev->len);
  514. if (datap + len < ev->data + dlen) {
  515. ath6kl_err("invalid wmi_p2p_rx_probe_req_event: len=%d dlen=%u\n",
  516. len, dlen);
  517. return -EINVAL;
  518. }
  519. ath6kl_dbg(ATH6KL_DBG_WMI,
  520. "rx_probe_req: len=%u freq=%u probe_req_report=%d\n",
  521. dlen, freq, vif->probe_req_report);
  522. if (vif->probe_req_report || vif->nw_type == AP_NETWORK)
  523. cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
  524. return 0;
  525. }
  526. static int ath6kl_wmi_p2p_capabilities_event_rx(u8 *datap, int len)
  527. {
  528. struct wmi_p2p_capabilities_event *ev;
  529. u16 dlen;
  530. if (len < sizeof(*ev))
  531. return -EINVAL;
  532. ev = (struct wmi_p2p_capabilities_event *) datap;
  533. dlen = le16_to_cpu(ev->len);
  534. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_capab: len=%u\n", dlen);
  535. return 0;
  536. }
  537. static int ath6kl_wmi_rx_action_event_rx(struct wmi *wmi, u8 *datap, int len,
  538. struct ath6kl_vif *vif)
  539. {
  540. struct wmi_rx_action_event *ev;
  541. u32 freq;
  542. u16 dlen;
  543. if (len < sizeof(*ev))
  544. return -EINVAL;
  545. ev = (struct wmi_rx_action_event *) datap;
  546. freq = le32_to_cpu(ev->freq);
  547. dlen = le16_to_cpu(ev->len);
  548. if (datap + len < ev->data + dlen) {
  549. ath6kl_err("invalid wmi_rx_action_event: len=%d dlen=%u\n",
  550. len, dlen);
  551. return -EINVAL;
  552. }
  553. ath6kl_dbg(ATH6KL_DBG_WMI, "rx_action: len=%u freq=%u\n", dlen, freq);
  554. cfg80211_rx_mgmt(&vif->wdev, freq, 0, ev->data, dlen, 0);
  555. return 0;
  556. }
  557. static int ath6kl_wmi_p2p_info_event_rx(u8 *datap, int len)
  558. {
  559. struct wmi_p2p_info_event *ev;
  560. u32 flags;
  561. u16 dlen;
  562. if (len < sizeof(*ev))
  563. return -EINVAL;
  564. ev = (struct wmi_p2p_info_event *) datap;
  565. flags = le32_to_cpu(ev->info_req_flags);
  566. dlen = le16_to_cpu(ev->len);
  567. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: flags=%x len=%d\n", flags, dlen);
  568. if (flags & P2P_FLAG_CAPABILITIES_REQ) {
  569. struct wmi_p2p_capabilities *cap;
  570. if (dlen < sizeof(*cap))
  571. return -EINVAL;
  572. cap = (struct wmi_p2p_capabilities *) ev->data;
  573. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: GO Power Save = %d\n",
  574. cap->go_power_save);
  575. }
  576. if (flags & P2P_FLAG_MACADDR_REQ) {
  577. struct wmi_p2p_macaddr *mac;
  578. if (dlen < sizeof(*mac))
  579. return -EINVAL;
  580. mac = (struct wmi_p2p_macaddr *) ev->data;
  581. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: MAC Address = %pM\n",
  582. mac->mac_addr);
  583. }
  584. if (flags & P2P_FLAG_HMODEL_REQ) {
  585. struct wmi_p2p_hmodel *mod;
  586. if (dlen < sizeof(*mod))
  587. return -EINVAL;
  588. mod = (struct wmi_p2p_hmodel *) ev->data;
  589. ath6kl_dbg(ATH6KL_DBG_WMI, "p2p_info: P2P Model = %d (%s)\n",
  590. mod->p2p_model,
  591. mod->p2p_model ? "host" : "firmware");
  592. }
  593. return 0;
  594. }
  595. static inline struct sk_buff *ath6kl_wmi_get_new_buf(u32 size)
  596. {
  597. struct sk_buff *skb;
  598. skb = ath6kl_buf_alloc(size);
  599. if (!skb)
  600. return NULL;
  601. skb_put(skb, size);
  602. if (size)
  603. memset(skb->data, 0, size);
  604. return skb;
  605. }
  606. /* Send a "simple" wmi command -- one with no arguments */
  607. static int ath6kl_wmi_simple_cmd(struct wmi *wmi, u8 if_idx,
  608. enum wmi_cmd_id cmd_id)
  609. {
  610. struct sk_buff *skb;
  611. int ret;
  612. skb = ath6kl_wmi_get_new_buf(0);
  613. if (!skb)
  614. return -ENOMEM;
  615. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, cmd_id, NO_SYNC_WMIFLAG);
  616. return ret;
  617. }
  618. static int ath6kl_wmi_ready_event_rx(struct wmi *wmi, u8 *datap, int len)
  619. {
  620. struct wmi_ready_event_2 *ev = (struct wmi_ready_event_2 *) datap;
  621. if (len < sizeof(struct wmi_ready_event_2))
  622. return -EINVAL;
  623. ath6kl_ready_event(wmi->parent_dev, ev->mac_addr,
  624. le32_to_cpu(ev->sw_version),
  625. le32_to_cpu(ev->abi_version), ev->phy_cap);
  626. return 0;
  627. }
  628. /*
  629. * Mechanism to modify the roaming behavior in the firmware. The lower rssi
  630. * at which the station has to roam can be passed with
  631. * WMI_SET_LRSSI_SCAN_PARAMS. Subtract 96 from RSSI to get the signal level
  632. * in dBm.
  633. */
  634. int ath6kl_wmi_set_roam_lrssi_cmd(struct wmi *wmi, u8 lrssi)
  635. {
  636. struct sk_buff *skb;
  637. struct roam_ctrl_cmd *cmd;
  638. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  639. if (!skb)
  640. return -ENOMEM;
  641. cmd = (struct roam_ctrl_cmd *) skb->data;
  642. cmd->info.params.lrssi_scan_period = cpu_to_le16(DEF_LRSSI_SCAN_PERIOD);
  643. cmd->info.params.lrssi_scan_threshold = a_cpu_to_sle16(lrssi +
  644. DEF_SCAN_FOR_ROAM_INTVL);
  645. cmd->info.params.lrssi_roam_threshold = a_cpu_to_sle16(lrssi);
  646. cmd->info.params.roam_rssi_floor = DEF_LRSSI_ROAM_FLOOR;
  647. cmd->roam_ctrl = WMI_SET_LRSSI_SCAN_PARAMS;
  648. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  649. NO_SYNC_WMIFLAG);
  650. }
  651. int ath6kl_wmi_force_roam_cmd(struct wmi *wmi, const u8 *bssid)
  652. {
  653. struct sk_buff *skb;
  654. struct roam_ctrl_cmd *cmd;
  655. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  656. if (!skb)
  657. return -ENOMEM;
  658. cmd = (struct roam_ctrl_cmd *) skb->data;
  659. memcpy(cmd->info.bssid, bssid, ETH_ALEN);
  660. cmd->roam_ctrl = WMI_FORCE_ROAM;
  661. ath6kl_dbg(ATH6KL_DBG_WMI, "force roam to %pM\n", bssid);
  662. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  663. NO_SYNC_WMIFLAG);
  664. }
  665. int ath6kl_wmi_ap_set_beacon_intvl_cmd(struct wmi *wmi, u8 if_idx,
  666. u32 beacon_intvl)
  667. {
  668. struct sk_buff *skb;
  669. struct set_beacon_int_cmd *cmd;
  670. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  671. if (!skb)
  672. return -ENOMEM;
  673. cmd = (struct set_beacon_int_cmd *) skb->data;
  674. cmd->beacon_intvl = cpu_to_le32(beacon_intvl);
  675. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  676. WMI_SET_BEACON_INT_CMDID, NO_SYNC_WMIFLAG);
  677. }
  678. int ath6kl_wmi_ap_set_dtim_cmd(struct wmi *wmi, u8 if_idx, u32 dtim_period)
  679. {
  680. struct sk_buff *skb;
  681. struct set_dtim_cmd *cmd;
  682. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  683. if (!skb)
  684. return -ENOMEM;
  685. cmd = (struct set_dtim_cmd *) skb->data;
  686. cmd->dtim_period = cpu_to_le32(dtim_period);
  687. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  688. WMI_AP_SET_DTIM_CMDID, NO_SYNC_WMIFLAG);
  689. }
  690. int ath6kl_wmi_set_roam_mode_cmd(struct wmi *wmi, enum wmi_roam_mode mode)
  691. {
  692. struct sk_buff *skb;
  693. struct roam_ctrl_cmd *cmd;
  694. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  695. if (!skb)
  696. return -ENOMEM;
  697. cmd = (struct roam_ctrl_cmd *) skb->data;
  698. cmd->info.roam_mode = mode;
  699. cmd->roam_ctrl = WMI_SET_ROAM_MODE;
  700. ath6kl_dbg(ATH6KL_DBG_WMI, "set roam mode %d\n", mode);
  701. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_ROAM_CTRL_CMDID,
  702. NO_SYNC_WMIFLAG);
  703. }
  704. static int ath6kl_wmi_connect_event_rx(struct wmi *wmi, u8 *datap, int len,
  705. struct ath6kl_vif *vif)
  706. {
  707. struct wmi_connect_event *ev;
  708. u8 *pie, *peie;
  709. if (len < sizeof(struct wmi_connect_event))
  710. return -EINVAL;
  711. ev = (struct wmi_connect_event *) datap;
  712. if (vif->nw_type == AP_NETWORK) {
  713. /* AP mode start/STA connected event */
  714. struct net_device *dev = vif->ndev;
  715. if (memcmp(dev->dev_addr, ev->u.ap_bss.bssid, ETH_ALEN) == 0) {
  716. ath6kl_dbg(ATH6KL_DBG_WMI,
  717. "%s: freq %d bssid %pM (AP started)\n",
  718. __func__, le16_to_cpu(ev->u.ap_bss.ch),
  719. ev->u.ap_bss.bssid);
  720. ath6kl_connect_ap_mode_bss(
  721. vif, le16_to_cpu(ev->u.ap_bss.ch));
  722. } else {
  723. ath6kl_dbg(ATH6KL_DBG_WMI,
  724. "%s: aid %u mac_addr %pM auth=%u keymgmt=%u cipher=%u apsd_info=%u (STA connected)\n",
  725. __func__, ev->u.ap_sta.aid,
  726. ev->u.ap_sta.mac_addr,
  727. ev->u.ap_sta.auth,
  728. ev->u.ap_sta.keymgmt,
  729. le16_to_cpu(ev->u.ap_sta.cipher),
  730. ev->u.ap_sta.apsd_info);
  731. ath6kl_connect_ap_mode_sta(
  732. vif, ev->u.ap_sta.aid, ev->u.ap_sta.mac_addr,
  733. ev->u.ap_sta.keymgmt,
  734. le16_to_cpu(ev->u.ap_sta.cipher),
  735. ev->u.ap_sta.auth, ev->assoc_req_len,
  736. ev->assoc_info + ev->beacon_ie_len,
  737. ev->u.ap_sta.apsd_info);
  738. }
  739. return 0;
  740. }
  741. /* STA/IBSS mode connection event */
  742. ath6kl_dbg(ATH6KL_DBG_WMI,
  743. "wmi event connect freq %d bssid %pM listen_intvl %d beacon_intvl %d type %d\n",
  744. le16_to_cpu(ev->u.sta.ch), ev->u.sta.bssid,
  745. le16_to_cpu(ev->u.sta.listen_intvl),
  746. le16_to_cpu(ev->u.sta.beacon_intvl),
  747. le32_to_cpu(ev->u.sta.nw_type));
  748. /* Start of assoc rsp IEs */
  749. pie = ev->assoc_info + ev->beacon_ie_len +
  750. ev->assoc_req_len + (sizeof(u16) * 3); /* capinfo, status, aid */
  751. /* End of assoc rsp IEs */
  752. peie = ev->assoc_info + ev->beacon_ie_len + ev->assoc_req_len +
  753. ev->assoc_resp_len;
  754. while (pie < peie) {
  755. switch (*pie) {
  756. case WLAN_EID_VENDOR_SPECIFIC:
  757. if (pie[1] > 3 && pie[2] == 0x00 && pie[3] == 0x50 &&
  758. pie[4] == 0xf2 && pie[5] == WMM_OUI_TYPE) {
  759. /* WMM OUT (00:50:F2) */
  760. if (pie[1] > 5 &&
  761. pie[6] == WMM_PARAM_OUI_SUBTYPE)
  762. wmi->is_wmm_enabled = true;
  763. }
  764. break;
  765. }
  766. if (wmi->is_wmm_enabled)
  767. break;
  768. pie += pie[1] + 2;
  769. }
  770. ath6kl_connect_event(vif, le16_to_cpu(ev->u.sta.ch),
  771. ev->u.sta.bssid,
  772. le16_to_cpu(ev->u.sta.listen_intvl),
  773. le16_to_cpu(ev->u.sta.beacon_intvl),
  774. le32_to_cpu(ev->u.sta.nw_type),
  775. ev->beacon_ie_len, ev->assoc_req_len,
  776. ev->assoc_resp_len, ev->assoc_info);
  777. return 0;
  778. }
  779. static struct country_code_to_enum_rd *
  780. ath6kl_regd_find_country(u16 countryCode)
  781. {
  782. int i;
  783. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  784. if (allCountries[i].countryCode == countryCode)
  785. return &allCountries[i];
  786. }
  787. return NULL;
  788. }
  789. static struct reg_dmn_pair_mapping *
  790. ath6kl_get_regpair(u16 regdmn)
  791. {
  792. int i;
  793. if (regdmn == NO_ENUMRD)
  794. return NULL;
  795. for (i = 0; i < ARRAY_SIZE(regDomainPairs); i++) {
  796. if (regDomainPairs[i].reg_domain == regdmn)
  797. return &regDomainPairs[i];
  798. }
  799. return NULL;
  800. }
  801. static struct country_code_to_enum_rd *
  802. ath6kl_regd_find_country_by_rd(u16 regdmn)
  803. {
  804. int i;
  805. for (i = 0; i < ARRAY_SIZE(allCountries); i++) {
  806. if (allCountries[i].regDmnEnum == regdmn)
  807. return &allCountries[i];
  808. }
  809. return NULL;
  810. }
  811. static void ath6kl_wmi_regdomain_event(struct wmi *wmi, u8 *datap, int len)
  812. {
  813. struct ath6kl_wmi_regdomain *ev;
  814. struct country_code_to_enum_rd *country = NULL;
  815. struct reg_dmn_pair_mapping *regpair = NULL;
  816. char alpha2[2];
  817. u32 reg_code;
  818. ev = (struct ath6kl_wmi_regdomain *) datap;
  819. reg_code = le32_to_cpu(ev->reg_code);
  820. if ((reg_code >> ATH6KL_COUNTRY_RD_SHIFT) & COUNTRY_ERD_FLAG) {
  821. country = ath6kl_regd_find_country((u16) reg_code);
  822. } else if (!(((u16) reg_code & WORLD_SKU_MASK) == WORLD_SKU_PREFIX)) {
  823. regpair = ath6kl_get_regpair((u16) reg_code);
  824. country = ath6kl_regd_find_country_by_rd((u16) reg_code);
  825. if (regpair)
  826. ath6kl_dbg(ATH6KL_DBG_WMI, "Regpair used: 0x%0x\n",
  827. regpair->reg_domain);
  828. else
  829. ath6kl_warn("Regpair not found reg_code 0x%0x\n",
  830. reg_code);
  831. }
  832. if (country && wmi->parent_dev->wiphy_registered) {
  833. alpha2[0] = country->isoName[0];
  834. alpha2[1] = country->isoName[1];
  835. regulatory_hint(wmi->parent_dev->wiphy, alpha2);
  836. ath6kl_dbg(ATH6KL_DBG_WMI, "Country alpha2 being used: %c%c\n",
  837. alpha2[0], alpha2[1]);
  838. }
  839. }
  840. static int ath6kl_wmi_disconnect_event_rx(struct wmi *wmi, u8 *datap, int len,
  841. struct ath6kl_vif *vif)
  842. {
  843. struct wmi_disconnect_event *ev;
  844. wmi->traffic_class = 100;
  845. if (len < sizeof(struct wmi_disconnect_event))
  846. return -EINVAL;
  847. ev = (struct wmi_disconnect_event *) datap;
  848. ath6kl_dbg(ATH6KL_DBG_WMI,
  849. "wmi event disconnect proto_reason %d bssid %pM wmi_reason %d assoc_resp_len %d\n",
  850. le16_to_cpu(ev->proto_reason_status), ev->bssid,
  851. ev->disconn_reason, ev->assoc_resp_len);
  852. wmi->is_wmm_enabled = false;
  853. ath6kl_disconnect_event(vif, ev->disconn_reason,
  854. ev->bssid, ev->assoc_resp_len, ev->assoc_info,
  855. le16_to_cpu(ev->proto_reason_status));
  856. return 0;
  857. }
  858. static int ath6kl_wmi_peer_node_event_rx(struct wmi *wmi, u8 *datap, int len)
  859. {
  860. struct wmi_peer_node_event *ev;
  861. if (len < sizeof(struct wmi_peer_node_event))
  862. return -EINVAL;
  863. ev = (struct wmi_peer_node_event *) datap;
  864. if (ev->event_code == PEER_NODE_JOIN_EVENT)
  865. ath6kl_dbg(ATH6KL_DBG_WMI, "joined node with mac addr: %pM\n",
  866. ev->peer_mac_addr);
  867. else if (ev->event_code == PEER_NODE_LEAVE_EVENT)
  868. ath6kl_dbg(ATH6KL_DBG_WMI, "left node with mac addr: %pM\n",
  869. ev->peer_mac_addr);
  870. return 0;
  871. }
  872. static int ath6kl_wmi_tkip_micerr_event_rx(struct wmi *wmi, u8 *datap, int len,
  873. struct ath6kl_vif *vif)
  874. {
  875. struct wmi_tkip_micerr_event *ev;
  876. if (len < sizeof(struct wmi_tkip_micerr_event))
  877. return -EINVAL;
  878. ev = (struct wmi_tkip_micerr_event *) datap;
  879. ath6kl_tkip_micerr_event(vif, ev->key_id, ev->is_mcast);
  880. return 0;
  881. }
  882. void ath6kl_wmi_sscan_timer(struct timer_list *t)
  883. {
  884. struct ath6kl_vif *vif = from_timer(vif, t, sched_scan_timer);
  885. cfg80211_sched_scan_results(vif->ar->wiphy, 0);
  886. }
  887. static int ath6kl_wmi_bssinfo_event_rx(struct wmi *wmi, u8 *datap, int len,
  888. struct ath6kl_vif *vif)
  889. {
  890. struct wmi_bss_info_hdr2 *bih;
  891. u8 *buf;
  892. struct ieee80211_channel *channel;
  893. struct ath6kl *ar = wmi->parent_dev;
  894. struct cfg80211_bss *bss;
  895. if (len <= sizeof(struct wmi_bss_info_hdr2))
  896. return -EINVAL;
  897. bih = (struct wmi_bss_info_hdr2 *) datap;
  898. buf = datap + sizeof(struct wmi_bss_info_hdr2);
  899. len -= sizeof(struct wmi_bss_info_hdr2);
  900. ath6kl_dbg(ATH6KL_DBG_WMI,
  901. "bss info evt - ch %u, snr %d, rssi %d, bssid \"%pM\" "
  902. "frame_type=%d\n",
  903. bih->ch, bih->snr, bih->snr - 95, bih->bssid,
  904. bih->frame_type);
  905. if (bih->frame_type != BEACON_FTYPE &&
  906. bih->frame_type != PROBERESP_FTYPE)
  907. return 0; /* Only update BSS table for now */
  908. if (bih->frame_type == BEACON_FTYPE &&
  909. test_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags)) {
  910. clear_bit(CLEAR_BSSFILTER_ON_BEACON, &vif->flags);
  911. ath6kl_wmi_bssfilter_cmd(ar->wmi, vif->fw_vif_idx,
  912. NONE_BSS_FILTER, 0);
  913. }
  914. channel = ieee80211_get_channel(ar->wiphy, le16_to_cpu(bih->ch));
  915. if (channel == NULL)
  916. return -EINVAL;
  917. if (len < 8 + 2 + 2)
  918. return -EINVAL;
  919. if (bih->frame_type == BEACON_FTYPE &&
  920. test_bit(CONNECTED, &vif->flags) &&
  921. memcmp(bih->bssid, vif->bssid, ETH_ALEN) == 0) {
  922. const u8 *tim;
  923. tim = cfg80211_find_ie(WLAN_EID_TIM, buf + 8 + 2 + 2,
  924. len - 8 - 2 - 2);
  925. if (tim && tim[1] >= 2) {
  926. vif->assoc_bss_dtim_period = tim[3];
  927. set_bit(DTIM_PERIOD_AVAIL, &vif->flags);
  928. }
  929. }
  930. bss = cfg80211_inform_bss(ar->wiphy, channel,
  931. bih->frame_type == BEACON_FTYPE ?
  932. CFG80211_BSS_FTYPE_BEACON :
  933. CFG80211_BSS_FTYPE_PRESP,
  934. bih->bssid, get_unaligned_le64((__le64 *)buf),
  935. get_unaligned_le16(((__le16 *)buf) + 5),
  936. get_unaligned_le16(((__le16 *)buf) + 4),
  937. buf + 8 + 2 + 2, len - 8 - 2 - 2,
  938. (bih->snr - 95) * 100, GFP_ATOMIC);
  939. if (bss == NULL)
  940. return -ENOMEM;
  941. cfg80211_put_bss(ar->wiphy, bss);
  942. /*
  943. * Firmware doesn't return any event when scheduled scan has
  944. * finished, so we need to use a timer to find out when there are
  945. * no more results.
  946. *
  947. * The timer is started from the first bss info received, otherwise
  948. * the timer would not ever fire if the scan interval is short
  949. * enough.
  950. */
  951. if (test_bit(SCHED_SCANNING, &vif->flags) &&
  952. !timer_pending(&vif->sched_scan_timer)) {
  953. mod_timer(&vif->sched_scan_timer, jiffies +
  954. msecs_to_jiffies(ATH6KL_SCHED_SCAN_RESULT_DELAY));
  955. }
  956. return 0;
  957. }
  958. /* Inactivity timeout of a fatpipe(pstream) at the target */
  959. static int ath6kl_wmi_pstream_timeout_event_rx(struct wmi *wmi, u8 *datap,
  960. int len)
  961. {
  962. struct wmi_pstream_timeout_event *ev;
  963. if (len < sizeof(struct wmi_pstream_timeout_event))
  964. return -EINVAL;
  965. ev = (struct wmi_pstream_timeout_event *) datap;
  966. if (ev->traffic_class >= WMM_NUM_AC) {
  967. ath6kl_err("invalid traffic class: %d\n", ev->traffic_class);
  968. return -EINVAL;
  969. }
  970. /*
  971. * When the pstream (fat pipe == AC) timesout, it means there were
  972. * no thinStreams within this pstream & it got implicitly created
  973. * due to data flow on this AC. We start the inactivity timer only
  974. * for implicitly created pstream. Just reset the host state.
  975. */
  976. spin_lock_bh(&wmi->lock);
  977. wmi->stream_exist_for_ac[ev->traffic_class] = 0;
  978. wmi->fat_pipe_exist &= ~(1 << ev->traffic_class);
  979. spin_unlock_bh(&wmi->lock);
  980. /* Indicate inactivity to driver layer for this fatpipe (pstream) */
  981. ath6kl_indicate_tx_activity(wmi->parent_dev, ev->traffic_class, false);
  982. return 0;
  983. }
  984. static int ath6kl_wmi_bitrate_reply_rx(struct wmi *wmi, u8 *datap, int len)
  985. {
  986. struct wmi_bit_rate_reply *reply;
  987. s32 rate;
  988. u32 sgi, index;
  989. if (len < sizeof(struct wmi_bit_rate_reply))
  990. return -EINVAL;
  991. reply = (struct wmi_bit_rate_reply *) datap;
  992. ath6kl_dbg(ATH6KL_DBG_WMI, "rateindex %d\n", reply->rate_index);
  993. if (reply->rate_index == (s8) RATE_AUTO) {
  994. rate = RATE_AUTO;
  995. } else {
  996. index = reply->rate_index & 0x7f;
  997. if (WARN_ON_ONCE(index > (RATE_MCS_7_40 + 1)))
  998. return -EINVAL;
  999. sgi = (reply->rate_index & 0x80) ? 1 : 0;
  1000. rate = wmi_rate_tbl[index][sgi];
  1001. }
  1002. ath6kl_wakeup_event(wmi->parent_dev);
  1003. return 0;
  1004. }
  1005. static int ath6kl_wmi_test_rx(struct wmi *wmi, u8 *datap, int len)
  1006. {
  1007. ath6kl_tm_rx_event(wmi->parent_dev, datap, len);
  1008. return 0;
  1009. }
  1010. static int ath6kl_wmi_ratemask_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1011. {
  1012. if (len < sizeof(struct wmi_fix_rates_reply))
  1013. return -EINVAL;
  1014. ath6kl_wakeup_event(wmi->parent_dev);
  1015. return 0;
  1016. }
  1017. static int ath6kl_wmi_ch_list_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1018. {
  1019. if (len < sizeof(struct wmi_channel_list_reply))
  1020. return -EINVAL;
  1021. ath6kl_wakeup_event(wmi->parent_dev);
  1022. return 0;
  1023. }
  1024. static int ath6kl_wmi_tx_pwr_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1025. {
  1026. struct wmi_tx_pwr_reply *reply;
  1027. if (len < sizeof(struct wmi_tx_pwr_reply))
  1028. return -EINVAL;
  1029. reply = (struct wmi_tx_pwr_reply *) datap;
  1030. ath6kl_txpwr_rx_evt(wmi->parent_dev, reply->dbM);
  1031. return 0;
  1032. }
  1033. static int ath6kl_wmi_keepalive_reply_rx(struct wmi *wmi, u8 *datap, int len)
  1034. {
  1035. if (len < sizeof(struct wmi_get_keepalive_cmd))
  1036. return -EINVAL;
  1037. ath6kl_wakeup_event(wmi->parent_dev);
  1038. return 0;
  1039. }
  1040. static int ath6kl_wmi_scan_complete_rx(struct wmi *wmi, u8 *datap, int len,
  1041. struct ath6kl_vif *vif)
  1042. {
  1043. struct wmi_scan_complete_event *ev;
  1044. ev = (struct wmi_scan_complete_event *) datap;
  1045. ath6kl_scan_complete_evt(vif, a_sle32_to_cpu(ev->status));
  1046. wmi->is_probe_ssid = false;
  1047. return 0;
  1048. }
  1049. static int ath6kl_wmi_neighbor_report_event_rx(struct wmi *wmi, u8 *datap,
  1050. int len, struct ath6kl_vif *vif)
  1051. {
  1052. struct wmi_neighbor_report_event *ev;
  1053. u8 i;
  1054. if (len < sizeof(*ev))
  1055. return -EINVAL;
  1056. ev = (struct wmi_neighbor_report_event *) datap;
  1057. if (struct_size(ev, neighbor, ev->num_neighbors) > len) {
  1058. ath6kl_dbg(ATH6KL_DBG_WMI,
  1059. "truncated neighbor event (num=%d len=%d)\n",
  1060. ev->num_neighbors, len);
  1061. return -EINVAL;
  1062. }
  1063. for (i = 0; i < ev->num_neighbors; i++) {
  1064. ath6kl_dbg(ATH6KL_DBG_WMI, "neighbor %d/%d - %pM 0x%x\n",
  1065. i + 1, ev->num_neighbors, ev->neighbor[i].bssid,
  1066. ev->neighbor[i].bss_flags);
  1067. cfg80211_pmksa_candidate_notify(vif->ndev, i,
  1068. ev->neighbor[i].bssid,
  1069. !!(ev->neighbor[i].bss_flags &
  1070. WMI_PREAUTH_CAPABLE_BSS),
  1071. GFP_ATOMIC);
  1072. }
  1073. return 0;
  1074. }
  1075. /*
  1076. * Target is reporting a programming error. This is for
  1077. * developer aid only. Target only checks a few common violations
  1078. * and it is responsibility of host to do all error checking.
  1079. * Behavior of target after wmi error event is undefined.
  1080. * A reset is recommended.
  1081. */
  1082. static int ath6kl_wmi_error_event_rx(struct wmi *wmi, u8 *datap, int len)
  1083. {
  1084. const char *type = "unknown error";
  1085. struct wmi_cmd_error_event *ev;
  1086. ev = (struct wmi_cmd_error_event *) datap;
  1087. switch (ev->err_code) {
  1088. case INVALID_PARAM:
  1089. type = "invalid parameter";
  1090. break;
  1091. case ILLEGAL_STATE:
  1092. type = "invalid state";
  1093. break;
  1094. case INTERNAL_ERROR:
  1095. type = "internal error";
  1096. break;
  1097. }
  1098. ath6kl_dbg(ATH6KL_DBG_WMI, "programming error, cmd=%d %s\n",
  1099. ev->cmd_id, type);
  1100. return 0;
  1101. }
  1102. static int ath6kl_wmi_stats_event_rx(struct wmi *wmi, u8 *datap, int len,
  1103. struct ath6kl_vif *vif)
  1104. {
  1105. ath6kl_tgt_stats_event(vif, datap, len);
  1106. return 0;
  1107. }
  1108. static u8 ath6kl_wmi_get_upper_threshold(s16 rssi,
  1109. struct sq_threshold_params *sq_thresh,
  1110. u32 size)
  1111. {
  1112. u32 index;
  1113. u8 threshold = (u8) sq_thresh->upper_threshold[size - 1];
  1114. /* The list is already in sorted order. Get the next lower value */
  1115. for (index = 0; index < size; index++) {
  1116. if (rssi < sq_thresh->upper_threshold[index]) {
  1117. threshold = (u8) sq_thresh->upper_threshold[index];
  1118. break;
  1119. }
  1120. }
  1121. return threshold;
  1122. }
  1123. static u8 ath6kl_wmi_get_lower_threshold(s16 rssi,
  1124. struct sq_threshold_params *sq_thresh,
  1125. u32 size)
  1126. {
  1127. u32 index;
  1128. u8 threshold = (u8) sq_thresh->lower_threshold[size - 1];
  1129. /* The list is already in sorted order. Get the next lower value */
  1130. for (index = 0; index < size; index++) {
  1131. if (rssi > sq_thresh->lower_threshold[index]) {
  1132. threshold = (u8) sq_thresh->lower_threshold[index];
  1133. break;
  1134. }
  1135. }
  1136. return threshold;
  1137. }
  1138. static int ath6kl_wmi_send_rssi_threshold_params(struct wmi *wmi,
  1139. struct wmi_rssi_threshold_params_cmd *rssi_cmd)
  1140. {
  1141. struct sk_buff *skb;
  1142. struct wmi_rssi_threshold_params_cmd *cmd;
  1143. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1144. if (!skb)
  1145. return -ENOMEM;
  1146. cmd = (struct wmi_rssi_threshold_params_cmd *) skb->data;
  1147. memcpy(cmd, rssi_cmd, sizeof(struct wmi_rssi_threshold_params_cmd));
  1148. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_RSSI_THRESHOLD_PARAMS_CMDID,
  1149. NO_SYNC_WMIFLAG);
  1150. }
  1151. static int ath6kl_wmi_rssi_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1152. int len)
  1153. {
  1154. struct wmi_rssi_threshold_event *reply;
  1155. struct wmi_rssi_threshold_params_cmd cmd;
  1156. struct sq_threshold_params *sq_thresh;
  1157. enum wmi_rssi_threshold_val new_threshold;
  1158. u8 upper_rssi_threshold, lower_rssi_threshold;
  1159. s16 rssi;
  1160. int ret;
  1161. if (len < sizeof(struct wmi_rssi_threshold_event))
  1162. return -EINVAL;
  1163. reply = (struct wmi_rssi_threshold_event *) datap;
  1164. new_threshold = (enum wmi_rssi_threshold_val) reply->range;
  1165. rssi = a_sle16_to_cpu(reply->rssi);
  1166. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_RSSI];
  1167. /*
  1168. * Identify the threshold breached and communicate that to the app.
  1169. * After that install a new set of thresholds based on the signal
  1170. * quality reported by the target
  1171. */
  1172. if (new_threshold) {
  1173. /* Upper threshold breached */
  1174. if (rssi < sq_thresh->upper_threshold[0]) {
  1175. ath6kl_dbg(ATH6KL_DBG_WMI,
  1176. "spurious upper rssi threshold event: %d\n",
  1177. rssi);
  1178. } else if ((rssi < sq_thresh->upper_threshold[1]) &&
  1179. (rssi >= sq_thresh->upper_threshold[0])) {
  1180. new_threshold = WMI_RSSI_THRESHOLD1_ABOVE;
  1181. } else if ((rssi < sq_thresh->upper_threshold[2]) &&
  1182. (rssi >= sq_thresh->upper_threshold[1])) {
  1183. new_threshold = WMI_RSSI_THRESHOLD2_ABOVE;
  1184. } else if ((rssi < sq_thresh->upper_threshold[3]) &&
  1185. (rssi >= sq_thresh->upper_threshold[2])) {
  1186. new_threshold = WMI_RSSI_THRESHOLD3_ABOVE;
  1187. } else if ((rssi < sq_thresh->upper_threshold[4]) &&
  1188. (rssi >= sq_thresh->upper_threshold[3])) {
  1189. new_threshold = WMI_RSSI_THRESHOLD4_ABOVE;
  1190. } else if ((rssi < sq_thresh->upper_threshold[5]) &&
  1191. (rssi >= sq_thresh->upper_threshold[4])) {
  1192. new_threshold = WMI_RSSI_THRESHOLD5_ABOVE;
  1193. } else if (rssi >= sq_thresh->upper_threshold[5]) {
  1194. new_threshold = WMI_RSSI_THRESHOLD6_ABOVE;
  1195. }
  1196. } else {
  1197. /* Lower threshold breached */
  1198. if (rssi > sq_thresh->lower_threshold[0]) {
  1199. ath6kl_dbg(ATH6KL_DBG_WMI,
  1200. "spurious lower rssi threshold event: %d %d\n",
  1201. rssi, sq_thresh->lower_threshold[0]);
  1202. } else if ((rssi > sq_thresh->lower_threshold[1]) &&
  1203. (rssi <= sq_thresh->lower_threshold[0])) {
  1204. new_threshold = WMI_RSSI_THRESHOLD6_BELOW;
  1205. } else if ((rssi > sq_thresh->lower_threshold[2]) &&
  1206. (rssi <= sq_thresh->lower_threshold[1])) {
  1207. new_threshold = WMI_RSSI_THRESHOLD5_BELOW;
  1208. } else if ((rssi > sq_thresh->lower_threshold[3]) &&
  1209. (rssi <= sq_thresh->lower_threshold[2])) {
  1210. new_threshold = WMI_RSSI_THRESHOLD4_BELOW;
  1211. } else if ((rssi > sq_thresh->lower_threshold[4]) &&
  1212. (rssi <= sq_thresh->lower_threshold[3])) {
  1213. new_threshold = WMI_RSSI_THRESHOLD3_BELOW;
  1214. } else if ((rssi > sq_thresh->lower_threshold[5]) &&
  1215. (rssi <= sq_thresh->lower_threshold[4])) {
  1216. new_threshold = WMI_RSSI_THRESHOLD2_BELOW;
  1217. } else if (rssi <= sq_thresh->lower_threshold[5]) {
  1218. new_threshold = WMI_RSSI_THRESHOLD1_BELOW;
  1219. }
  1220. }
  1221. /* Calculate and install the next set of thresholds */
  1222. lower_rssi_threshold = ath6kl_wmi_get_lower_threshold(rssi, sq_thresh,
  1223. sq_thresh->lower_threshold_valid_count);
  1224. upper_rssi_threshold = ath6kl_wmi_get_upper_threshold(rssi, sq_thresh,
  1225. sq_thresh->upper_threshold_valid_count);
  1226. /* Issue a wmi command to install the thresholds */
  1227. cmd.thresh_above1_val = a_cpu_to_sle16(upper_rssi_threshold);
  1228. cmd.thresh_below1_val = a_cpu_to_sle16(lower_rssi_threshold);
  1229. cmd.weight = sq_thresh->weight;
  1230. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1231. ret = ath6kl_wmi_send_rssi_threshold_params(wmi, &cmd);
  1232. if (ret) {
  1233. ath6kl_err("unable to configure rssi thresholds\n");
  1234. return -EIO;
  1235. }
  1236. return 0;
  1237. }
  1238. static int ath6kl_wmi_cac_event_rx(struct wmi *wmi, u8 *datap, int len,
  1239. struct ath6kl_vif *vif)
  1240. {
  1241. struct wmi_cac_event *reply;
  1242. struct ieee80211_tspec_ie *ts;
  1243. u16 active_tsids, tsinfo;
  1244. u8 tsid, index;
  1245. u8 ts_id;
  1246. if (len < sizeof(struct wmi_cac_event))
  1247. return -EINVAL;
  1248. reply = (struct wmi_cac_event *) datap;
  1249. if (reply->ac >= WMM_NUM_AC) {
  1250. ath6kl_err("invalid AC: %d\n", reply->ac);
  1251. return -EINVAL;
  1252. }
  1253. if ((reply->cac_indication == CAC_INDICATION_ADMISSION_RESP) &&
  1254. (reply->status_code != IEEE80211_TSPEC_STATUS_ADMISS_ACCEPTED)) {
  1255. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1256. tsinfo = le16_to_cpu(ts->tsinfo);
  1257. tsid = (tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1258. IEEE80211_WMM_IE_TSPEC_TID_MASK;
  1259. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1260. reply->ac, tsid);
  1261. } else if (reply->cac_indication == CAC_INDICATION_NO_RESP) {
  1262. /*
  1263. * Following assumes that there is only one outstanding
  1264. * ADDTS request when this event is received
  1265. */
  1266. spin_lock_bh(&wmi->lock);
  1267. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1268. spin_unlock_bh(&wmi->lock);
  1269. for (index = 0; index < sizeof(active_tsids) * 8; index++) {
  1270. if ((active_tsids >> index) & 1)
  1271. break;
  1272. }
  1273. if (index < (sizeof(active_tsids) * 8))
  1274. ath6kl_wmi_delete_pstream_cmd(wmi, vif->fw_vif_idx,
  1275. reply->ac, index);
  1276. }
  1277. /*
  1278. * Clear active tsids and Add missing handling
  1279. * for delete qos stream from AP
  1280. */
  1281. else if (reply->cac_indication == CAC_INDICATION_DELETE) {
  1282. ts = (struct ieee80211_tspec_ie *) &(reply->tspec_suggestion);
  1283. tsinfo = le16_to_cpu(ts->tsinfo);
  1284. ts_id = ((tsinfo >> IEEE80211_WMM_IE_TSPEC_TID_SHIFT) &
  1285. IEEE80211_WMM_IE_TSPEC_TID_MASK);
  1286. spin_lock_bh(&wmi->lock);
  1287. wmi->stream_exist_for_ac[reply->ac] &= ~(1 << ts_id);
  1288. active_tsids = wmi->stream_exist_for_ac[reply->ac];
  1289. spin_unlock_bh(&wmi->lock);
  1290. /* Indicate stream inactivity to driver layer only if all tsids
  1291. * within this AC are deleted.
  1292. */
  1293. if (!active_tsids) {
  1294. ath6kl_indicate_tx_activity(wmi->parent_dev, reply->ac,
  1295. false);
  1296. wmi->fat_pipe_exist &= ~(1 << reply->ac);
  1297. }
  1298. }
  1299. return 0;
  1300. }
  1301. static int ath6kl_wmi_txe_notify_event_rx(struct wmi *wmi, u8 *datap, int len,
  1302. struct ath6kl_vif *vif)
  1303. {
  1304. struct wmi_txe_notify_event *ev;
  1305. u32 rate, pkts;
  1306. if (len < sizeof(*ev))
  1307. return -EINVAL;
  1308. if (vif->nw_type != INFRA_NETWORK ||
  1309. !test_bit(ATH6KL_FW_CAPABILITY_TX_ERR_NOTIFY,
  1310. vif->ar->fw_capabilities))
  1311. return -EOPNOTSUPP;
  1312. if (vif->sme_state != SME_CONNECTED)
  1313. return -ENOTCONN;
  1314. ev = (struct wmi_txe_notify_event *) datap;
  1315. rate = le32_to_cpu(ev->rate);
  1316. pkts = le32_to_cpu(ev->pkts);
  1317. ath6kl_dbg(ATH6KL_DBG_WMI, "TXE notify event: peer %pM rate %d%% pkts %d intvl %ds\n",
  1318. vif->bssid, rate, pkts, vif->txe_intvl);
  1319. cfg80211_cqm_txe_notify(vif->ndev, vif->bssid, pkts,
  1320. rate, vif->txe_intvl, GFP_KERNEL);
  1321. return 0;
  1322. }
  1323. int ath6kl_wmi_set_txe_notify(struct wmi *wmi, u8 idx,
  1324. u32 rate, u32 pkts, u32 intvl)
  1325. {
  1326. struct sk_buff *skb;
  1327. struct wmi_txe_notify_cmd *cmd;
  1328. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1329. if (!skb)
  1330. return -ENOMEM;
  1331. cmd = (struct wmi_txe_notify_cmd *) skb->data;
  1332. cmd->rate = cpu_to_le32(rate);
  1333. cmd->pkts = cpu_to_le32(pkts);
  1334. cmd->intvl = cpu_to_le32(intvl);
  1335. return ath6kl_wmi_cmd_send(wmi, idx, skb, WMI_SET_TXE_NOTIFY_CMDID,
  1336. NO_SYNC_WMIFLAG);
  1337. }
  1338. int ath6kl_wmi_set_rssi_filter_cmd(struct wmi *wmi, u8 if_idx, s8 rssi)
  1339. {
  1340. struct sk_buff *skb;
  1341. struct wmi_set_rssi_filter_cmd *cmd;
  1342. int ret;
  1343. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1344. if (!skb)
  1345. return -ENOMEM;
  1346. cmd = (struct wmi_set_rssi_filter_cmd *) skb->data;
  1347. cmd->rssi = rssi;
  1348. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_RSSI_FILTER_CMDID,
  1349. NO_SYNC_WMIFLAG);
  1350. return ret;
  1351. }
  1352. static int ath6kl_wmi_send_snr_threshold_params(struct wmi *wmi,
  1353. struct wmi_snr_threshold_params_cmd *snr_cmd)
  1354. {
  1355. struct sk_buff *skb;
  1356. struct wmi_snr_threshold_params_cmd *cmd;
  1357. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1358. if (!skb)
  1359. return -ENOMEM;
  1360. cmd = (struct wmi_snr_threshold_params_cmd *) skb->data;
  1361. memcpy(cmd, snr_cmd, sizeof(struct wmi_snr_threshold_params_cmd));
  1362. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SNR_THRESHOLD_PARAMS_CMDID,
  1363. NO_SYNC_WMIFLAG);
  1364. }
  1365. static int ath6kl_wmi_snr_threshold_event_rx(struct wmi *wmi, u8 *datap,
  1366. int len)
  1367. {
  1368. struct wmi_snr_threshold_event *reply;
  1369. struct sq_threshold_params *sq_thresh;
  1370. struct wmi_snr_threshold_params_cmd cmd;
  1371. enum wmi_snr_threshold_val new_threshold;
  1372. u8 upper_snr_threshold, lower_snr_threshold;
  1373. s16 snr;
  1374. int ret;
  1375. if (len < sizeof(struct wmi_snr_threshold_event))
  1376. return -EINVAL;
  1377. reply = (struct wmi_snr_threshold_event *) datap;
  1378. new_threshold = (enum wmi_snr_threshold_val) reply->range;
  1379. snr = reply->snr;
  1380. sq_thresh = &wmi->sq_threshld[SIGNAL_QUALITY_METRICS_SNR];
  1381. /*
  1382. * Identify the threshold breached and communicate that to the app.
  1383. * After that install a new set of thresholds based on the signal
  1384. * quality reported by the target.
  1385. */
  1386. if (new_threshold) {
  1387. /* Upper threshold breached */
  1388. if (snr < sq_thresh->upper_threshold[0]) {
  1389. ath6kl_dbg(ATH6KL_DBG_WMI,
  1390. "spurious upper snr threshold event: %d\n",
  1391. snr);
  1392. } else if ((snr < sq_thresh->upper_threshold[1]) &&
  1393. (snr >= sq_thresh->upper_threshold[0])) {
  1394. new_threshold = WMI_SNR_THRESHOLD1_ABOVE;
  1395. } else if ((snr < sq_thresh->upper_threshold[2]) &&
  1396. (snr >= sq_thresh->upper_threshold[1])) {
  1397. new_threshold = WMI_SNR_THRESHOLD2_ABOVE;
  1398. } else if ((snr < sq_thresh->upper_threshold[3]) &&
  1399. (snr >= sq_thresh->upper_threshold[2])) {
  1400. new_threshold = WMI_SNR_THRESHOLD3_ABOVE;
  1401. } else if (snr >= sq_thresh->upper_threshold[3]) {
  1402. new_threshold = WMI_SNR_THRESHOLD4_ABOVE;
  1403. }
  1404. } else {
  1405. /* Lower threshold breached */
  1406. if (snr > sq_thresh->lower_threshold[0]) {
  1407. ath6kl_dbg(ATH6KL_DBG_WMI,
  1408. "spurious lower snr threshold event: %d\n",
  1409. sq_thresh->lower_threshold[0]);
  1410. } else if ((snr > sq_thresh->lower_threshold[1]) &&
  1411. (snr <= sq_thresh->lower_threshold[0])) {
  1412. new_threshold = WMI_SNR_THRESHOLD4_BELOW;
  1413. } else if ((snr > sq_thresh->lower_threshold[2]) &&
  1414. (snr <= sq_thresh->lower_threshold[1])) {
  1415. new_threshold = WMI_SNR_THRESHOLD3_BELOW;
  1416. } else if ((snr > sq_thresh->lower_threshold[3]) &&
  1417. (snr <= sq_thresh->lower_threshold[2])) {
  1418. new_threshold = WMI_SNR_THRESHOLD2_BELOW;
  1419. } else if (snr <= sq_thresh->lower_threshold[3]) {
  1420. new_threshold = WMI_SNR_THRESHOLD1_BELOW;
  1421. }
  1422. }
  1423. /* Calculate and install the next set of thresholds */
  1424. lower_snr_threshold = ath6kl_wmi_get_lower_threshold(snr, sq_thresh,
  1425. sq_thresh->lower_threshold_valid_count);
  1426. upper_snr_threshold = ath6kl_wmi_get_upper_threshold(snr, sq_thresh,
  1427. sq_thresh->upper_threshold_valid_count);
  1428. /* Issue a wmi command to install the thresholds */
  1429. cmd.thresh_above1_val = upper_snr_threshold;
  1430. cmd.thresh_below1_val = lower_snr_threshold;
  1431. cmd.weight = sq_thresh->weight;
  1432. cmd.poll_time = cpu_to_le32(sq_thresh->polling_interval);
  1433. ath6kl_dbg(ATH6KL_DBG_WMI,
  1434. "snr: %d, threshold: %d, lower: %d, upper: %d\n",
  1435. snr, new_threshold,
  1436. lower_snr_threshold, upper_snr_threshold);
  1437. ret = ath6kl_wmi_send_snr_threshold_params(wmi, &cmd);
  1438. if (ret) {
  1439. ath6kl_err("unable to configure snr threshold\n");
  1440. return -EIO;
  1441. }
  1442. return 0;
  1443. }
  1444. static int ath6kl_wmi_aplist_event_rx(struct wmi *wmi, u8 *datap, int len)
  1445. {
  1446. u16 ap_info_entry_size;
  1447. struct wmi_aplist_event *ev = (struct wmi_aplist_event *) datap;
  1448. struct wmi_ap_info_v1 *ap_info_v1;
  1449. u8 index;
  1450. if (len < sizeof(struct wmi_aplist_event) ||
  1451. ev->ap_list_ver != APLIST_VER1)
  1452. return -EINVAL;
  1453. ap_info_entry_size = sizeof(struct wmi_ap_info_v1);
  1454. ap_info_v1 = (struct wmi_ap_info_v1 *) ev->ap_list;
  1455. ath6kl_dbg(ATH6KL_DBG_WMI,
  1456. "number of APs in aplist event: %d\n", ev->num_ap);
  1457. if (len < (int) (sizeof(struct wmi_aplist_event) +
  1458. (ev->num_ap - 1) * ap_info_entry_size))
  1459. return -EINVAL;
  1460. /* AP list version 1 contents */
  1461. for (index = 0; index < ev->num_ap; index++) {
  1462. ath6kl_dbg(ATH6KL_DBG_WMI, "AP#%d BSSID %pM Channel %d\n",
  1463. index, ap_info_v1->bssid, ap_info_v1->channel);
  1464. ap_info_v1++;
  1465. }
  1466. return 0;
  1467. }
  1468. int ath6kl_wmi_cmd_send(struct wmi *wmi, u8 if_idx, struct sk_buff *skb,
  1469. enum wmi_cmd_id cmd_id, enum wmi_sync_flag sync_flag)
  1470. {
  1471. struct wmi_cmd_hdr *cmd_hdr;
  1472. enum htc_endpoint_id ep_id = wmi->ep_id;
  1473. int ret;
  1474. u16 info1;
  1475. if (WARN_ON(skb == NULL ||
  1476. (if_idx > (wmi->parent_dev->vif_max - 1)))) {
  1477. dev_kfree_skb(skb);
  1478. return -EINVAL;
  1479. }
  1480. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi tx id %d len %d flag %d\n",
  1481. cmd_id, skb->len, sync_flag);
  1482. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi tx ",
  1483. skb->data, skb->len);
  1484. if (sync_flag >= END_WMIFLAG) {
  1485. dev_kfree_skb(skb);
  1486. return -EINVAL;
  1487. }
  1488. if ((sync_flag == SYNC_BEFORE_WMIFLAG) ||
  1489. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1490. /*
  1491. * Make sure all data currently queued is transmitted before
  1492. * the cmd execution. Establish a new sync point.
  1493. */
  1494. ath6kl_wmi_sync_point(wmi, if_idx);
  1495. }
  1496. skb_push(skb, sizeof(struct wmi_cmd_hdr));
  1497. cmd_hdr = (struct wmi_cmd_hdr *) skb->data;
  1498. cmd_hdr->cmd_id = cpu_to_le16(cmd_id);
  1499. info1 = if_idx & WMI_CMD_HDR_IF_ID_MASK;
  1500. cmd_hdr->info1 = cpu_to_le16(info1);
  1501. /* Only for OPT_TX_CMD, use BE endpoint. */
  1502. if (cmd_id == WMI_OPT_TX_FRAME_CMDID) {
  1503. ret = ath6kl_wmi_data_hdr_add(wmi, skb, OPT_MSGTYPE,
  1504. false, false, 0, NULL, if_idx);
  1505. if (ret) {
  1506. dev_kfree_skb(skb);
  1507. return ret;
  1508. }
  1509. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev, WMM_AC_BE);
  1510. }
  1511. ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1512. if ((sync_flag == SYNC_AFTER_WMIFLAG) ||
  1513. (sync_flag == SYNC_BOTH_WMIFLAG)) {
  1514. /*
  1515. * Make sure all new data queued waits for the command to
  1516. * execute. Establish a new sync point.
  1517. */
  1518. ath6kl_wmi_sync_point(wmi, if_idx);
  1519. }
  1520. return 0;
  1521. }
  1522. int ath6kl_wmi_connect_cmd(struct wmi *wmi, u8 if_idx,
  1523. enum network_type nw_type,
  1524. enum dot11_auth_mode dot11_auth_mode,
  1525. enum auth_mode auth_mode,
  1526. enum ath6kl_crypto_type pairwise_crypto,
  1527. u8 pairwise_crypto_len,
  1528. enum ath6kl_crypto_type group_crypto,
  1529. u8 group_crypto_len, int ssid_len, u8 *ssid,
  1530. u8 *bssid, u16 channel, u32 ctrl_flags,
  1531. u8 nw_subtype)
  1532. {
  1533. struct sk_buff *skb;
  1534. struct wmi_connect_cmd *cc;
  1535. int ret;
  1536. ath6kl_dbg(ATH6KL_DBG_WMI,
  1537. "wmi connect bssid %pM freq %d flags 0x%x ssid_len %d "
  1538. "type %d dot11_auth %d auth %d pairwise %d group %d\n",
  1539. bssid, channel, ctrl_flags, ssid_len, nw_type,
  1540. dot11_auth_mode, auth_mode, pairwise_crypto, group_crypto);
  1541. ath6kl_dbg_dump(ATH6KL_DBG_WMI, NULL, "ssid ", ssid, ssid_len);
  1542. wmi->traffic_class = 100;
  1543. if ((pairwise_crypto == NONE_CRYPT) && (group_crypto != NONE_CRYPT))
  1544. return -EINVAL;
  1545. if ((pairwise_crypto != NONE_CRYPT) && (group_crypto == NONE_CRYPT))
  1546. return -EINVAL;
  1547. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_connect_cmd));
  1548. if (!skb)
  1549. return -ENOMEM;
  1550. cc = (struct wmi_connect_cmd *) skb->data;
  1551. if (ssid_len)
  1552. memcpy(cc->ssid, ssid, ssid_len);
  1553. cc->ssid_len = ssid_len;
  1554. cc->nw_type = nw_type;
  1555. cc->dot11_auth_mode = dot11_auth_mode;
  1556. cc->auth_mode = auth_mode;
  1557. cc->prwise_crypto_type = pairwise_crypto;
  1558. cc->prwise_crypto_len = pairwise_crypto_len;
  1559. cc->grp_crypto_type = group_crypto;
  1560. cc->grp_crypto_len = group_crypto_len;
  1561. cc->ch = cpu_to_le16(channel);
  1562. cc->ctrl_flags = cpu_to_le32(ctrl_flags);
  1563. cc->nw_subtype = nw_subtype;
  1564. if (bssid != NULL)
  1565. memcpy(cc->bssid, bssid, ETH_ALEN);
  1566. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CONNECT_CMDID,
  1567. NO_SYNC_WMIFLAG);
  1568. return ret;
  1569. }
  1570. int ath6kl_wmi_reconnect_cmd(struct wmi *wmi, u8 if_idx, u8 *bssid,
  1571. u16 channel)
  1572. {
  1573. struct sk_buff *skb;
  1574. struct wmi_reconnect_cmd *cc;
  1575. int ret;
  1576. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi reconnect bssid %pM freq %d\n",
  1577. bssid, channel);
  1578. wmi->traffic_class = 100;
  1579. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_reconnect_cmd));
  1580. if (!skb)
  1581. return -ENOMEM;
  1582. cc = (struct wmi_reconnect_cmd *) skb->data;
  1583. cc->channel = cpu_to_le16(channel);
  1584. if (bssid != NULL)
  1585. memcpy(cc->bssid, bssid, ETH_ALEN);
  1586. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RECONNECT_CMDID,
  1587. NO_SYNC_WMIFLAG);
  1588. return ret;
  1589. }
  1590. int ath6kl_wmi_disconnect_cmd(struct wmi *wmi, u8 if_idx)
  1591. {
  1592. int ret;
  1593. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi disconnect\n");
  1594. wmi->traffic_class = 100;
  1595. /* Disconnect command does not need to do a SYNC before. */
  1596. ret = ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_DISCONNECT_CMDID);
  1597. return ret;
  1598. }
  1599. /* ath6kl_wmi_start_scan_cmd is to be deprecated. Use
  1600. * ath6kl_wmi_begin_scan_cmd instead. The new function supports P2P
  1601. * mgmt operations using station interface.
  1602. */
  1603. static int ath6kl_wmi_startscan_cmd(struct wmi *wmi, u8 if_idx,
  1604. enum wmi_scan_type scan_type,
  1605. u32 force_fgscan, u32 is_legacy,
  1606. u32 home_dwell_time,
  1607. u32 force_scan_interval,
  1608. s8 num_chan, u16 *ch_list)
  1609. {
  1610. struct sk_buff *skb;
  1611. struct wmi_start_scan_cmd *sc;
  1612. s8 size;
  1613. int i, ret;
  1614. size = sizeof(struct wmi_start_scan_cmd);
  1615. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1616. return -EINVAL;
  1617. if (num_chan > WMI_MAX_CHANNELS)
  1618. return -EINVAL;
  1619. if (num_chan)
  1620. size += sizeof(u16) * (num_chan - 1);
  1621. skb = ath6kl_wmi_get_new_buf(size);
  1622. if (!skb)
  1623. return -ENOMEM;
  1624. sc = (struct wmi_start_scan_cmd *) skb->data;
  1625. sc->scan_type = scan_type;
  1626. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1627. sc->is_legacy = cpu_to_le32(is_legacy);
  1628. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1629. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1630. sc->num_ch = num_chan;
  1631. for (i = 0; i < num_chan; i++)
  1632. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1633. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_START_SCAN_CMDID,
  1634. NO_SYNC_WMIFLAG);
  1635. return ret;
  1636. }
  1637. /*
  1638. * beginscan supports (compared to old startscan) P2P mgmt operations using
  1639. * station interface, send additional information like supported rates to
  1640. * advertise and xmit rates for probe requests
  1641. */
  1642. int ath6kl_wmi_beginscan_cmd(struct wmi *wmi, u8 if_idx,
  1643. enum wmi_scan_type scan_type,
  1644. u32 force_fgscan, u32 is_legacy,
  1645. u32 home_dwell_time, u32 force_scan_interval,
  1646. s8 num_chan, u16 *ch_list, u32 no_cck, u32 *rates)
  1647. {
  1648. struct ieee80211_supported_band *sband;
  1649. struct sk_buff *skb;
  1650. struct wmi_begin_scan_cmd *sc;
  1651. s8 size, *supp_rates;
  1652. int i, band, ret;
  1653. struct ath6kl *ar = wmi->parent_dev;
  1654. int num_rates;
  1655. u32 ratemask;
  1656. if (!test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  1657. ar->fw_capabilities)) {
  1658. return ath6kl_wmi_startscan_cmd(wmi, if_idx,
  1659. scan_type, force_fgscan,
  1660. is_legacy, home_dwell_time,
  1661. force_scan_interval,
  1662. num_chan, ch_list);
  1663. }
  1664. size = sizeof(struct wmi_begin_scan_cmd);
  1665. if ((scan_type != WMI_LONG_SCAN) && (scan_type != WMI_SHORT_SCAN))
  1666. return -EINVAL;
  1667. if (num_chan > WMI_MAX_CHANNELS)
  1668. return -EINVAL;
  1669. if (num_chan)
  1670. size += sizeof(u16) * (num_chan - 1);
  1671. skb = ath6kl_wmi_get_new_buf(size);
  1672. if (!skb)
  1673. return -ENOMEM;
  1674. sc = (struct wmi_begin_scan_cmd *) skb->data;
  1675. sc->scan_type = scan_type;
  1676. sc->force_fg_scan = cpu_to_le32(force_fgscan);
  1677. sc->is_legacy = cpu_to_le32(is_legacy);
  1678. sc->home_dwell_time = cpu_to_le32(home_dwell_time);
  1679. sc->force_scan_intvl = cpu_to_le32(force_scan_interval);
  1680. sc->no_cck = cpu_to_le32(no_cck);
  1681. sc->num_ch = num_chan;
  1682. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1683. sband = ar->wiphy->bands[band];
  1684. if (!sband)
  1685. continue;
  1686. if (WARN_ON(band >= ATH6KL_NUM_BANDS))
  1687. break;
  1688. ratemask = rates[band];
  1689. supp_rates = sc->supp_rates[band].rates;
  1690. num_rates = 0;
  1691. for (i = 0; i < sband->n_bitrates; i++) {
  1692. if ((BIT(i) & ratemask) == 0)
  1693. continue; /* skip rate */
  1694. supp_rates[num_rates++] =
  1695. (u8) (sband->bitrates[i].bitrate / 5);
  1696. }
  1697. sc->supp_rates[band].nrates = num_rates;
  1698. }
  1699. for (i = 0; i < num_chan; i++)
  1700. sc->ch_list[i] = cpu_to_le16(ch_list[i]);
  1701. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_BEGIN_SCAN_CMDID,
  1702. NO_SYNC_WMIFLAG);
  1703. return ret;
  1704. }
  1705. int ath6kl_wmi_enable_sched_scan_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  1706. {
  1707. struct sk_buff *skb;
  1708. struct wmi_enable_sched_scan_cmd *sc;
  1709. int ret;
  1710. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1711. if (!skb)
  1712. return -ENOMEM;
  1713. ath6kl_dbg(ATH6KL_DBG_WMI, "%s scheduled scan on vif %d\n",
  1714. enable ? "enabling" : "disabling", if_idx);
  1715. sc = (struct wmi_enable_sched_scan_cmd *) skb->data;
  1716. sc->enable = enable ? 1 : 0;
  1717. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  1718. WMI_ENABLE_SCHED_SCAN_CMDID,
  1719. NO_SYNC_WMIFLAG);
  1720. return ret;
  1721. }
  1722. int ath6kl_wmi_scanparams_cmd(struct wmi *wmi, u8 if_idx,
  1723. u16 fg_start_sec,
  1724. u16 fg_end_sec, u16 bg_sec,
  1725. u16 minact_chdw_msec, u16 maxact_chdw_msec,
  1726. u16 pas_chdw_msec, u8 short_scan_ratio,
  1727. u8 scan_ctrl_flag, u32 max_dfsch_act_time,
  1728. u16 maxact_scan_per_ssid)
  1729. {
  1730. struct sk_buff *skb;
  1731. struct wmi_scan_params_cmd *sc;
  1732. int ret;
  1733. skb = ath6kl_wmi_get_new_buf(sizeof(*sc));
  1734. if (!skb)
  1735. return -ENOMEM;
  1736. sc = (struct wmi_scan_params_cmd *) skb->data;
  1737. sc->fg_start_period = cpu_to_le16(fg_start_sec);
  1738. sc->fg_end_period = cpu_to_le16(fg_end_sec);
  1739. sc->bg_period = cpu_to_le16(bg_sec);
  1740. sc->minact_chdwell_time = cpu_to_le16(minact_chdw_msec);
  1741. sc->maxact_chdwell_time = cpu_to_le16(maxact_chdw_msec);
  1742. sc->pas_chdwell_time = cpu_to_le16(pas_chdw_msec);
  1743. sc->short_scan_ratio = short_scan_ratio;
  1744. sc->scan_ctrl_flags = scan_ctrl_flag;
  1745. sc->max_dfsch_act_time = cpu_to_le32(max_dfsch_act_time);
  1746. sc->maxact_scan_per_ssid = cpu_to_le16(maxact_scan_per_ssid);
  1747. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_SCAN_PARAMS_CMDID,
  1748. NO_SYNC_WMIFLAG);
  1749. return ret;
  1750. }
  1751. int ath6kl_wmi_bssfilter_cmd(struct wmi *wmi, u8 if_idx, u8 filter, u32 ie_mask)
  1752. {
  1753. struct sk_buff *skb;
  1754. struct wmi_bss_filter_cmd *cmd;
  1755. int ret;
  1756. if (filter >= LAST_BSS_FILTER)
  1757. return -EINVAL;
  1758. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1759. if (!skb)
  1760. return -ENOMEM;
  1761. cmd = (struct wmi_bss_filter_cmd *) skb->data;
  1762. cmd->bss_filter = filter;
  1763. cmd->ie_mask = cpu_to_le32(ie_mask);
  1764. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BSS_FILTER_CMDID,
  1765. NO_SYNC_WMIFLAG);
  1766. return ret;
  1767. }
  1768. int ath6kl_wmi_probedssid_cmd(struct wmi *wmi, u8 if_idx, u8 index, u8 flag,
  1769. u8 ssid_len, u8 *ssid)
  1770. {
  1771. struct sk_buff *skb;
  1772. struct wmi_probed_ssid_cmd *cmd;
  1773. int ret;
  1774. if (index >= MAX_PROBED_SSIDS)
  1775. return -EINVAL;
  1776. if (ssid_len > sizeof(cmd->ssid))
  1777. return -EINVAL;
  1778. if ((flag & (DISABLE_SSID_FLAG | ANY_SSID_FLAG)) && (ssid_len > 0))
  1779. return -EINVAL;
  1780. if ((flag & SPECIFIC_SSID_FLAG) && !ssid_len)
  1781. return -EINVAL;
  1782. if (flag & SPECIFIC_SSID_FLAG)
  1783. wmi->is_probe_ssid = true;
  1784. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1785. if (!skb)
  1786. return -ENOMEM;
  1787. cmd = (struct wmi_probed_ssid_cmd *) skb->data;
  1788. cmd->entry_index = index;
  1789. cmd->flag = flag;
  1790. cmd->ssid_len = ssid_len;
  1791. memcpy(cmd->ssid, ssid, ssid_len);
  1792. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PROBED_SSID_CMDID,
  1793. NO_SYNC_WMIFLAG);
  1794. return ret;
  1795. }
  1796. int ath6kl_wmi_listeninterval_cmd(struct wmi *wmi, u8 if_idx,
  1797. u16 listen_interval,
  1798. u16 listen_beacons)
  1799. {
  1800. struct sk_buff *skb;
  1801. struct wmi_listen_int_cmd *cmd;
  1802. int ret;
  1803. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1804. if (!skb)
  1805. return -ENOMEM;
  1806. cmd = (struct wmi_listen_int_cmd *) skb->data;
  1807. cmd->listen_intvl = cpu_to_le16(listen_interval);
  1808. cmd->num_beacons = cpu_to_le16(listen_beacons);
  1809. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LISTEN_INT_CMDID,
  1810. NO_SYNC_WMIFLAG);
  1811. return ret;
  1812. }
  1813. int ath6kl_wmi_bmisstime_cmd(struct wmi *wmi, u8 if_idx,
  1814. u16 bmiss_time, u16 num_beacons)
  1815. {
  1816. struct sk_buff *skb;
  1817. struct wmi_bmiss_time_cmd *cmd;
  1818. int ret;
  1819. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1820. if (!skb)
  1821. return -ENOMEM;
  1822. cmd = (struct wmi_bmiss_time_cmd *) skb->data;
  1823. cmd->bmiss_time = cpu_to_le16(bmiss_time);
  1824. cmd->num_beacons = cpu_to_le16(num_beacons);
  1825. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_BMISS_TIME_CMDID,
  1826. NO_SYNC_WMIFLAG);
  1827. return ret;
  1828. }
  1829. int ath6kl_wmi_powermode_cmd(struct wmi *wmi, u8 if_idx, u8 pwr_mode)
  1830. {
  1831. struct sk_buff *skb;
  1832. struct wmi_power_mode_cmd *cmd;
  1833. int ret;
  1834. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1835. if (!skb)
  1836. return -ENOMEM;
  1837. cmd = (struct wmi_power_mode_cmd *) skb->data;
  1838. cmd->pwr_mode = pwr_mode;
  1839. wmi->pwr_mode = pwr_mode;
  1840. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_MODE_CMDID,
  1841. NO_SYNC_WMIFLAG);
  1842. return ret;
  1843. }
  1844. int ath6kl_wmi_pmparams_cmd(struct wmi *wmi, u8 if_idx, u16 idle_period,
  1845. u16 ps_poll_num, u16 dtim_policy,
  1846. u16 tx_wakeup_policy, u16 num_tx_to_wakeup,
  1847. u16 ps_fail_event_policy)
  1848. {
  1849. struct sk_buff *skb;
  1850. struct wmi_power_params_cmd *pm;
  1851. int ret;
  1852. skb = ath6kl_wmi_get_new_buf(sizeof(*pm));
  1853. if (!skb)
  1854. return -ENOMEM;
  1855. pm = (struct wmi_power_params_cmd *)skb->data;
  1856. pm->idle_period = cpu_to_le16(idle_period);
  1857. pm->pspoll_number = cpu_to_le16(ps_poll_num);
  1858. pm->dtim_policy = cpu_to_le16(dtim_policy);
  1859. pm->tx_wakeup_policy = cpu_to_le16(tx_wakeup_policy);
  1860. pm->num_tx_to_wakeup = cpu_to_le16(num_tx_to_wakeup);
  1861. pm->ps_fail_event_policy = cpu_to_le16(ps_fail_event_policy);
  1862. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_POWER_PARAMS_CMDID,
  1863. NO_SYNC_WMIFLAG);
  1864. return ret;
  1865. }
  1866. int ath6kl_wmi_disctimeout_cmd(struct wmi *wmi, u8 if_idx, u8 timeout)
  1867. {
  1868. struct sk_buff *skb;
  1869. struct wmi_disc_timeout_cmd *cmd;
  1870. int ret;
  1871. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1872. if (!skb)
  1873. return -ENOMEM;
  1874. cmd = (struct wmi_disc_timeout_cmd *) skb->data;
  1875. cmd->discon_timeout = timeout;
  1876. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_DISC_TIMEOUT_CMDID,
  1877. NO_SYNC_WMIFLAG);
  1878. if (ret == 0)
  1879. ath6kl_debug_set_disconnect_timeout(wmi->parent_dev, timeout);
  1880. return ret;
  1881. }
  1882. int ath6kl_wmi_addkey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index,
  1883. enum ath6kl_crypto_type key_type,
  1884. u8 key_usage, u8 key_len,
  1885. u8 *key_rsc, unsigned int key_rsc_len,
  1886. u8 *key_material,
  1887. u8 key_op_ctrl, u8 *mac_addr,
  1888. enum wmi_sync_flag sync_flag)
  1889. {
  1890. struct sk_buff *skb;
  1891. struct wmi_add_cipher_key_cmd *cmd;
  1892. int ret;
  1893. ath6kl_dbg(ATH6KL_DBG_WMI,
  1894. "addkey cmd: key_index=%u key_type=%d key_usage=%d key_len=%d key_op_ctrl=%d\n",
  1895. key_index, key_type, key_usage, key_len, key_op_ctrl);
  1896. if ((key_index > WMI_MAX_KEY_INDEX) || (key_len > WMI_MAX_KEY_LEN) ||
  1897. (key_material == NULL) || key_rsc_len > 8)
  1898. return -EINVAL;
  1899. if ((WEP_CRYPT != key_type) && (NULL == key_rsc))
  1900. return -EINVAL;
  1901. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1902. if (!skb)
  1903. return -ENOMEM;
  1904. cmd = (struct wmi_add_cipher_key_cmd *) skb->data;
  1905. cmd->key_index = key_index;
  1906. cmd->key_type = key_type;
  1907. cmd->key_usage = key_usage;
  1908. cmd->key_len = key_len;
  1909. memcpy(cmd->key, key_material, key_len);
  1910. if (key_rsc != NULL)
  1911. memcpy(cmd->key_rsc, key_rsc, key_rsc_len);
  1912. cmd->key_op_ctrl = key_op_ctrl;
  1913. if (mac_addr)
  1914. memcpy(cmd->key_mac_addr, mac_addr, ETH_ALEN);
  1915. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_CIPHER_KEY_CMDID,
  1916. sync_flag);
  1917. return ret;
  1918. }
  1919. int ath6kl_wmi_add_krk_cmd(struct wmi *wmi, u8 if_idx, const u8 *krk)
  1920. {
  1921. struct sk_buff *skb;
  1922. struct wmi_add_krk_cmd *cmd;
  1923. int ret;
  1924. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1925. if (!skb)
  1926. return -ENOMEM;
  1927. cmd = (struct wmi_add_krk_cmd *) skb->data;
  1928. memcpy(cmd->krk, krk, WMI_KRK_LEN);
  1929. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_KRK_CMDID,
  1930. NO_SYNC_WMIFLAG);
  1931. return ret;
  1932. }
  1933. int ath6kl_wmi_deletekey_cmd(struct wmi *wmi, u8 if_idx, u8 key_index)
  1934. {
  1935. struct sk_buff *skb;
  1936. struct wmi_delete_cipher_key_cmd *cmd;
  1937. int ret;
  1938. if (key_index > WMI_MAX_KEY_INDEX)
  1939. return -EINVAL;
  1940. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1941. if (!skb)
  1942. return -ENOMEM;
  1943. cmd = (struct wmi_delete_cipher_key_cmd *) skb->data;
  1944. cmd->key_index = key_index;
  1945. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_CIPHER_KEY_CMDID,
  1946. NO_SYNC_WMIFLAG);
  1947. return ret;
  1948. }
  1949. int ath6kl_wmi_setpmkid_cmd(struct wmi *wmi, u8 if_idx, const u8 *bssid,
  1950. const u8 *pmkid, bool set)
  1951. {
  1952. struct sk_buff *skb;
  1953. struct wmi_setpmkid_cmd *cmd;
  1954. int ret;
  1955. if (bssid == NULL)
  1956. return -EINVAL;
  1957. if (set && pmkid == NULL)
  1958. return -EINVAL;
  1959. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  1960. if (!skb)
  1961. return -ENOMEM;
  1962. cmd = (struct wmi_setpmkid_cmd *) skb->data;
  1963. memcpy(cmd->bssid, bssid, ETH_ALEN);
  1964. if (set) {
  1965. memcpy(cmd->pmkid, pmkid, sizeof(cmd->pmkid));
  1966. cmd->enable = PMKID_ENABLE;
  1967. } else {
  1968. memset(cmd->pmkid, 0, sizeof(cmd->pmkid));
  1969. cmd->enable = PMKID_DISABLE;
  1970. }
  1971. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_PMKID_CMDID,
  1972. NO_SYNC_WMIFLAG);
  1973. return ret;
  1974. }
  1975. static int ath6kl_wmi_data_sync_send(struct wmi *wmi, struct sk_buff *skb,
  1976. enum htc_endpoint_id ep_id, u8 if_idx)
  1977. {
  1978. struct wmi_data_hdr *data_hdr;
  1979. int ret;
  1980. if (WARN_ON(skb == NULL || ep_id == wmi->ep_id)) {
  1981. dev_kfree_skb(skb);
  1982. return -EINVAL;
  1983. }
  1984. skb_push(skb, sizeof(struct wmi_data_hdr));
  1985. data_hdr = (struct wmi_data_hdr *) skb->data;
  1986. data_hdr->info = SYNC_MSGTYPE << WMI_DATA_HDR_MSG_TYPE_SHIFT;
  1987. data_hdr->info3 = cpu_to_le16(if_idx & WMI_DATA_HDR_IF_IDX_MASK);
  1988. ret = ath6kl_control_tx(wmi->parent_dev, skb, ep_id);
  1989. return ret;
  1990. }
  1991. static int ath6kl_wmi_sync_point(struct wmi *wmi, u8 if_idx)
  1992. {
  1993. struct sk_buff *skb;
  1994. struct wmi_sync_cmd *cmd;
  1995. struct wmi_data_sync_bufs data_sync_bufs[WMM_NUM_AC];
  1996. enum htc_endpoint_id ep_id;
  1997. u8 index, num_pri_streams = 0;
  1998. int ret = 0;
  1999. memset(data_sync_bufs, 0, sizeof(data_sync_bufs));
  2000. spin_lock_bh(&wmi->lock);
  2001. for (index = 0; index < WMM_NUM_AC; index++) {
  2002. if (wmi->fat_pipe_exist & (1 << index)) {
  2003. num_pri_streams++;
  2004. data_sync_bufs[num_pri_streams - 1].traffic_class =
  2005. index;
  2006. }
  2007. }
  2008. spin_unlock_bh(&wmi->lock);
  2009. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2010. if (!skb)
  2011. return -ENOMEM;
  2012. cmd = (struct wmi_sync_cmd *) skb->data;
  2013. /*
  2014. * In the SYNC cmd sent on the control Ep, send a bitmap
  2015. * of the data eps on which the Data Sync will be sent
  2016. */
  2017. cmd->data_sync_map = wmi->fat_pipe_exist;
  2018. for (index = 0; index < num_pri_streams; index++) {
  2019. data_sync_bufs[index].skb = ath6kl_buf_alloc(0);
  2020. if (data_sync_bufs[index].skb == NULL) {
  2021. ret = -ENOMEM;
  2022. break;
  2023. }
  2024. }
  2025. /*
  2026. * If buffer allocation for any of the dataSync fails,
  2027. * then do not send the Synchronize cmd on the control ep
  2028. */
  2029. if (ret)
  2030. goto free_cmd_skb;
  2031. /*
  2032. * Send sync cmd followed by sync data messages on all
  2033. * endpoints being used
  2034. */
  2035. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SYNCHRONIZE_CMDID,
  2036. NO_SYNC_WMIFLAG);
  2037. if (ret)
  2038. goto free_data_skb;
  2039. for (index = 0; index < num_pri_streams; index++) {
  2040. if (WARN_ON(!data_sync_bufs[index].skb))
  2041. goto free_data_skb;
  2042. ep_id = ath6kl_ac2_endpoint_id(wmi->parent_dev,
  2043. data_sync_bufs[index].
  2044. traffic_class);
  2045. ret =
  2046. ath6kl_wmi_data_sync_send(wmi, data_sync_bufs[index].skb,
  2047. ep_id, if_idx);
  2048. data_sync_bufs[index].skb = NULL;
  2049. if (ret)
  2050. goto free_data_skb;
  2051. }
  2052. return 0;
  2053. free_cmd_skb:
  2054. /* free up any resources left over (possibly due to an error) */
  2055. dev_kfree_skb(skb);
  2056. free_data_skb:
  2057. for (index = 0; index < num_pri_streams; index++)
  2058. dev_kfree_skb((struct sk_buff *)data_sync_bufs[index].skb);
  2059. return ret;
  2060. }
  2061. int ath6kl_wmi_create_pstream_cmd(struct wmi *wmi, u8 if_idx,
  2062. struct wmi_create_pstream_cmd *params)
  2063. {
  2064. struct sk_buff *skb;
  2065. struct wmi_create_pstream_cmd *cmd;
  2066. u8 fatpipe_exist_for_ac = 0;
  2067. s32 min_phy = 0;
  2068. s32 nominal_phy = 0;
  2069. int ret;
  2070. if (!((params->user_pri <= 0x7) &&
  2071. (up_to_ac[params->user_pri & 0x7] == params->traffic_class) &&
  2072. (params->traffic_direc == UPLINK_TRAFFIC ||
  2073. params->traffic_direc == DNLINK_TRAFFIC ||
  2074. params->traffic_direc == BIDIR_TRAFFIC) &&
  2075. (params->traffic_type == TRAFFIC_TYPE_APERIODIC ||
  2076. params->traffic_type == TRAFFIC_TYPE_PERIODIC) &&
  2077. (params->voice_psc_cap == DISABLE_FOR_THIS_AC ||
  2078. params->voice_psc_cap == ENABLE_FOR_THIS_AC ||
  2079. params->voice_psc_cap == ENABLE_FOR_ALL_AC) &&
  2080. (params->tsid == WMI_IMPLICIT_PSTREAM ||
  2081. params->tsid <= WMI_MAX_THINSTREAM))) {
  2082. return -EINVAL;
  2083. }
  2084. /*
  2085. * Check nominal PHY rate is >= minimalPHY,
  2086. * so that DUT can allow TSRS IE
  2087. */
  2088. /* Get the physical rate (units of bps) */
  2089. min_phy = ((le32_to_cpu(params->min_phy_rate) / 1000) / 1000);
  2090. /* Check minimal phy < nominal phy rate */
  2091. if (params->nominal_phy >= min_phy) {
  2092. /* unit of 500 kbps */
  2093. nominal_phy = (params->nominal_phy * 1000) / 500;
  2094. ath6kl_dbg(ATH6KL_DBG_WMI,
  2095. "TSRS IE enabled::MinPhy %x->NominalPhy ===> %x\n",
  2096. min_phy, nominal_phy);
  2097. params->nominal_phy = nominal_phy;
  2098. } else {
  2099. params->nominal_phy = 0;
  2100. }
  2101. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2102. if (!skb)
  2103. return -ENOMEM;
  2104. ath6kl_dbg(ATH6KL_DBG_WMI,
  2105. "sending create_pstream_cmd: ac=%d tsid:%d\n",
  2106. params->traffic_class, params->tsid);
  2107. cmd = (struct wmi_create_pstream_cmd *) skb->data;
  2108. memcpy(cmd, params, sizeof(*cmd));
  2109. /* This is an implicitly created Fat pipe */
  2110. if ((u32) params->tsid == (u32) WMI_IMPLICIT_PSTREAM) {
  2111. spin_lock_bh(&wmi->lock);
  2112. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2113. (1 << params->traffic_class));
  2114. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2115. spin_unlock_bh(&wmi->lock);
  2116. } else {
  2117. /* explicitly created thin stream within a fat pipe */
  2118. spin_lock_bh(&wmi->lock);
  2119. fatpipe_exist_for_ac = (wmi->fat_pipe_exist &
  2120. (1 << params->traffic_class));
  2121. wmi->stream_exist_for_ac[params->traffic_class] |=
  2122. (1 << params->tsid);
  2123. /*
  2124. * If a thinstream becomes active, the fat pipe automatically
  2125. * becomes active
  2126. */
  2127. wmi->fat_pipe_exist |= (1 << params->traffic_class);
  2128. spin_unlock_bh(&wmi->lock);
  2129. }
  2130. /*
  2131. * Indicate activty change to driver layer only if this is the
  2132. * first TSID to get created in this AC explicitly or an implicit
  2133. * fat pipe is getting created.
  2134. */
  2135. if (!fatpipe_exist_for_ac)
  2136. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2137. params->traffic_class, true);
  2138. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_CREATE_PSTREAM_CMDID,
  2139. NO_SYNC_WMIFLAG);
  2140. return ret;
  2141. }
  2142. int ath6kl_wmi_delete_pstream_cmd(struct wmi *wmi, u8 if_idx, u8 traffic_class,
  2143. u8 tsid)
  2144. {
  2145. struct sk_buff *skb;
  2146. struct wmi_delete_pstream_cmd *cmd;
  2147. u16 active_tsids = 0;
  2148. int ret;
  2149. if (traffic_class >= WMM_NUM_AC) {
  2150. ath6kl_err("invalid traffic class: %d\n", traffic_class);
  2151. return -EINVAL;
  2152. }
  2153. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2154. if (!skb)
  2155. return -ENOMEM;
  2156. cmd = (struct wmi_delete_pstream_cmd *) skb->data;
  2157. cmd->traffic_class = traffic_class;
  2158. cmd->tsid = tsid;
  2159. spin_lock_bh(&wmi->lock);
  2160. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2161. spin_unlock_bh(&wmi->lock);
  2162. if (!(active_tsids & (1 << tsid))) {
  2163. dev_kfree_skb(skb);
  2164. ath6kl_dbg(ATH6KL_DBG_WMI,
  2165. "TSID %d doesn't exist for traffic class: %d\n",
  2166. tsid, traffic_class);
  2167. return -ENODATA;
  2168. }
  2169. ath6kl_dbg(ATH6KL_DBG_WMI,
  2170. "sending delete_pstream_cmd: traffic class: %d tsid=%d\n",
  2171. traffic_class, tsid);
  2172. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DELETE_PSTREAM_CMDID,
  2173. SYNC_BEFORE_WMIFLAG);
  2174. spin_lock_bh(&wmi->lock);
  2175. wmi->stream_exist_for_ac[traffic_class] &= ~(1 << tsid);
  2176. active_tsids = wmi->stream_exist_for_ac[traffic_class];
  2177. spin_unlock_bh(&wmi->lock);
  2178. /*
  2179. * Indicate stream inactivity to driver layer only if all tsids
  2180. * within this AC are deleted.
  2181. */
  2182. if (!active_tsids) {
  2183. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2184. traffic_class, false);
  2185. wmi->fat_pipe_exist &= ~(1 << traffic_class);
  2186. }
  2187. return ret;
  2188. }
  2189. int ath6kl_wmi_set_ip_cmd(struct wmi *wmi, u8 if_idx,
  2190. __be32 ips0, __be32 ips1)
  2191. {
  2192. struct sk_buff *skb;
  2193. struct wmi_set_ip_cmd *cmd;
  2194. int ret;
  2195. /* Multicast address are not valid */
  2196. if (ipv4_is_multicast(ips0) ||
  2197. ipv4_is_multicast(ips1))
  2198. return -EINVAL;
  2199. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_ip_cmd));
  2200. if (!skb)
  2201. return -ENOMEM;
  2202. cmd = (struct wmi_set_ip_cmd *) skb->data;
  2203. cmd->ips[0] = ips0;
  2204. cmd->ips[1] = ips1;
  2205. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IP_CMDID,
  2206. NO_SYNC_WMIFLAG);
  2207. return ret;
  2208. }
  2209. static void ath6kl_wmi_relinquish_implicit_pstream_credits(struct wmi *wmi)
  2210. {
  2211. u16 active_tsids;
  2212. u8 stream_exist;
  2213. int i;
  2214. /*
  2215. * Relinquish credits from all implicitly created pstreams
  2216. * since when we go to sleep. If user created explicit
  2217. * thinstreams exists with in a fatpipe leave them intact
  2218. * for the user to delete.
  2219. */
  2220. spin_lock_bh(&wmi->lock);
  2221. stream_exist = wmi->fat_pipe_exist;
  2222. spin_unlock_bh(&wmi->lock);
  2223. for (i = 0; i < WMM_NUM_AC; i++) {
  2224. if (stream_exist & (1 << i)) {
  2225. /*
  2226. * FIXME: Is this lock & unlock inside
  2227. * for loop correct? may need rework.
  2228. */
  2229. spin_lock_bh(&wmi->lock);
  2230. active_tsids = wmi->stream_exist_for_ac[i];
  2231. spin_unlock_bh(&wmi->lock);
  2232. /*
  2233. * If there are no user created thin streams
  2234. * delete the fatpipe
  2235. */
  2236. if (!active_tsids) {
  2237. stream_exist &= ~(1 << i);
  2238. /*
  2239. * Indicate inactivity to driver layer for
  2240. * this fatpipe (pstream)
  2241. */
  2242. ath6kl_indicate_tx_activity(wmi->parent_dev,
  2243. i, false);
  2244. }
  2245. }
  2246. }
  2247. /* FIXME: Can we do this assignment without locking ? */
  2248. spin_lock_bh(&wmi->lock);
  2249. wmi->fat_pipe_exist = stream_exist;
  2250. spin_unlock_bh(&wmi->lock);
  2251. }
  2252. static int ath6kl_set_bitrate_mask64(struct wmi *wmi, u8 if_idx,
  2253. const struct cfg80211_bitrate_mask *mask)
  2254. {
  2255. struct sk_buff *skb;
  2256. int ret, mode, band;
  2257. u64 mcsrate, ratemask[ATH6KL_NUM_BANDS];
  2258. struct wmi_set_tx_select_rates64_cmd *cmd;
  2259. memset(&ratemask, 0, sizeof(ratemask));
  2260. /* only check 2.4 and 5 GHz bands, skip the rest */
  2261. for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
  2262. /* copy legacy rate mask */
  2263. ratemask[band] = mask->control[band].legacy;
  2264. if (band == NL80211_BAND_5GHZ)
  2265. ratemask[band] =
  2266. mask->control[band].legacy << 4;
  2267. /* copy mcs rate mask */
  2268. mcsrate = mask->control[band].ht_mcs[1];
  2269. mcsrate <<= 8;
  2270. mcsrate |= mask->control[band].ht_mcs[0];
  2271. ratemask[band] |= mcsrate << 12;
  2272. ratemask[band] |= mcsrate << 28;
  2273. }
  2274. ath6kl_dbg(ATH6KL_DBG_WMI,
  2275. "Ratemask 64 bit: 2.4:%llx 5:%llx\n",
  2276. ratemask[0], ratemask[1]);
  2277. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
  2278. if (!skb)
  2279. return -ENOMEM;
  2280. cmd = (struct wmi_set_tx_select_rates64_cmd *) skb->data;
  2281. for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
  2282. /* A mode operate in 5GHZ band */
  2283. if (mode == WMI_RATES_MODE_11A ||
  2284. mode == WMI_RATES_MODE_11A_HT20 ||
  2285. mode == WMI_RATES_MODE_11A_HT40)
  2286. band = NL80211_BAND_5GHZ;
  2287. else
  2288. band = NL80211_BAND_2GHZ;
  2289. cmd->ratemask[mode] = cpu_to_le64(ratemask[band]);
  2290. }
  2291. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2292. WMI_SET_TX_SELECT_RATES_CMDID,
  2293. NO_SYNC_WMIFLAG);
  2294. return ret;
  2295. }
  2296. static int ath6kl_set_bitrate_mask32(struct wmi *wmi, u8 if_idx,
  2297. const struct cfg80211_bitrate_mask *mask)
  2298. {
  2299. struct sk_buff *skb;
  2300. int ret, mode, band;
  2301. u32 mcsrate, ratemask[ATH6KL_NUM_BANDS];
  2302. struct wmi_set_tx_select_rates32_cmd *cmd;
  2303. memset(&ratemask, 0, sizeof(ratemask));
  2304. /* only check 2.4 and 5 GHz bands, skip the rest */
  2305. for (band = 0; band <= NL80211_BAND_5GHZ; band++) {
  2306. /* copy legacy rate mask */
  2307. ratemask[band] = mask->control[band].legacy;
  2308. if (band == NL80211_BAND_5GHZ)
  2309. ratemask[band] =
  2310. mask->control[band].legacy << 4;
  2311. /* copy mcs rate mask */
  2312. mcsrate = mask->control[band].ht_mcs[0];
  2313. ratemask[band] |= mcsrate << 12;
  2314. ratemask[band] |= mcsrate << 20;
  2315. }
  2316. ath6kl_dbg(ATH6KL_DBG_WMI,
  2317. "Ratemask 32 bit: 2.4:%x 5:%x\n",
  2318. ratemask[0], ratemask[1]);
  2319. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd) * WMI_RATES_MODE_MAX);
  2320. if (!skb)
  2321. return -ENOMEM;
  2322. cmd = (struct wmi_set_tx_select_rates32_cmd *) skb->data;
  2323. for (mode = 0; mode < WMI_RATES_MODE_MAX; mode++) {
  2324. /* A mode operate in 5GHZ band */
  2325. if (mode == WMI_RATES_MODE_11A ||
  2326. mode == WMI_RATES_MODE_11A_HT20 ||
  2327. mode == WMI_RATES_MODE_11A_HT40)
  2328. band = NL80211_BAND_5GHZ;
  2329. else
  2330. band = NL80211_BAND_2GHZ;
  2331. cmd->ratemask[mode] = cpu_to_le32(ratemask[band]);
  2332. }
  2333. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2334. WMI_SET_TX_SELECT_RATES_CMDID,
  2335. NO_SYNC_WMIFLAG);
  2336. return ret;
  2337. }
  2338. int ath6kl_wmi_set_bitrate_mask(struct wmi *wmi, u8 if_idx,
  2339. const struct cfg80211_bitrate_mask *mask)
  2340. {
  2341. struct ath6kl *ar = wmi->parent_dev;
  2342. if (test_bit(ATH6KL_FW_CAPABILITY_64BIT_RATES,
  2343. ar->fw_capabilities))
  2344. return ath6kl_set_bitrate_mask64(wmi, if_idx, mask);
  2345. else
  2346. return ath6kl_set_bitrate_mask32(wmi, if_idx, mask);
  2347. }
  2348. int ath6kl_wmi_set_host_sleep_mode_cmd(struct wmi *wmi, u8 if_idx,
  2349. enum ath6kl_host_mode host_mode)
  2350. {
  2351. struct sk_buff *skb;
  2352. struct wmi_set_host_sleep_mode_cmd *cmd;
  2353. int ret;
  2354. if ((host_mode != ATH6KL_HOST_MODE_ASLEEP) &&
  2355. (host_mode != ATH6KL_HOST_MODE_AWAKE)) {
  2356. ath6kl_err("invalid host sleep mode: %d\n", host_mode);
  2357. return -EINVAL;
  2358. }
  2359. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2360. if (!skb)
  2361. return -ENOMEM;
  2362. cmd = (struct wmi_set_host_sleep_mode_cmd *) skb->data;
  2363. if (host_mode == ATH6KL_HOST_MODE_ASLEEP) {
  2364. ath6kl_wmi_relinquish_implicit_pstream_credits(wmi);
  2365. cmd->asleep = cpu_to_le32(1);
  2366. } else {
  2367. cmd->awake = cpu_to_le32(1);
  2368. }
  2369. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2370. WMI_SET_HOST_SLEEP_MODE_CMDID,
  2371. NO_SYNC_WMIFLAG);
  2372. return ret;
  2373. }
  2374. /* This command has zero length payload */
  2375. static int ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(struct wmi *wmi,
  2376. struct ath6kl_vif *vif)
  2377. {
  2378. struct ath6kl *ar = wmi->parent_dev;
  2379. set_bit(HOST_SLEEP_MODE_CMD_PROCESSED, &vif->flags);
  2380. wake_up(&ar->event_wq);
  2381. return 0;
  2382. }
  2383. int ath6kl_wmi_set_wow_mode_cmd(struct wmi *wmi, u8 if_idx,
  2384. enum ath6kl_wow_mode wow_mode,
  2385. u32 filter, u16 host_req_delay)
  2386. {
  2387. struct sk_buff *skb;
  2388. struct wmi_set_wow_mode_cmd *cmd;
  2389. int ret;
  2390. if ((wow_mode != ATH6KL_WOW_MODE_ENABLE) &&
  2391. wow_mode != ATH6KL_WOW_MODE_DISABLE) {
  2392. ath6kl_err("invalid wow mode: %d\n", wow_mode);
  2393. return -EINVAL;
  2394. }
  2395. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2396. if (!skb)
  2397. return -ENOMEM;
  2398. cmd = (struct wmi_set_wow_mode_cmd *) skb->data;
  2399. cmd->enable_wow = cpu_to_le32(wow_mode);
  2400. cmd->filter = cpu_to_le32(filter);
  2401. cmd->host_req_delay = cpu_to_le16(host_req_delay);
  2402. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WOW_MODE_CMDID,
  2403. NO_SYNC_WMIFLAG);
  2404. return ret;
  2405. }
  2406. int ath6kl_wmi_add_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2407. u8 list_id, u8 filter_size,
  2408. u8 filter_offset, const u8 *filter,
  2409. const u8 *mask)
  2410. {
  2411. struct sk_buff *skb;
  2412. struct wmi_add_wow_pattern_cmd *cmd;
  2413. u16 size;
  2414. u8 *filter_mask;
  2415. int ret;
  2416. /*
  2417. * Allocate additional memory in the buffer to hold
  2418. * filter and mask value, which is twice of filter_size.
  2419. */
  2420. size = sizeof(*cmd) + (2 * filter_size);
  2421. skb = ath6kl_wmi_get_new_buf(size);
  2422. if (!skb)
  2423. return -ENOMEM;
  2424. cmd = (struct wmi_add_wow_pattern_cmd *) skb->data;
  2425. cmd->filter_list_id = list_id;
  2426. cmd->filter_size = filter_size;
  2427. cmd->filter_offset = filter_offset;
  2428. memcpy(cmd->filter, filter, filter_size);
  2429. filter_mask = (u8 *) (cmd->filter + filter_size);
  2430. memcpy(filter_mask, mask, filter_size);
  2431. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_ADD_WOW_PATTERN_CMDID,
  2432. NO_SYNC_WMIFLAG);
  2433. return ret;
  2434. }
  2435. int ath6kl_wmi_del_wow_pattern_cmd(struct wmi *wmi, u8 if_idx,
  2436. u16 list_id, u16 filter_id)
  2437. {
  2438. struct sk_buff *skb;
  2439. struct wmi_del_wow_pattern_cmd *cmd;
  2440. int ret;
  2441. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2442. if (!skb)
  2443. return -ENOMEM;
  2444. cmd = (struct wmi_del_wow_pattern_cmd *) skb->data;
  2445. cmd->filter_list_id = cpu_to_le16(list_id);
  2446. cmd->filter_id = cpu_to_le16(filter_id);
  2447. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_DEL_WOW_PATTERN_CMDID,
  2448. NO_SYNC_WMIFLAG);
  2449. return ret;
  2450. }
  2451. static int ath6kl_wmi_cmd_send_xtnd(struct wmi *wmi, struct sk_buff *skb,
  2452. enum wmix_command_id cmd_id,
  2453. enum wmi_sync_flag sync_flag)
  2454. {
  2455. struct wmix_cmd_hdr *cmd_hdr;
  2456. int ret;
  2457. skb_push(skb, sizeof(struct wmix_cmd_hdr));
  2458. cmd_hdr = (struct wmix_cmd_hdr *) skb->data;
  2459. cmd_hdr->cmd_id = cpu_to_le32(cmd_id);
  2460. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_EXTENSION_CMDID, sync_flag);
  2461. return ret;
  2462. }
  2463. int ath6kl_wmi_get_challenge_resp_cmd(struct wmi *wmi, u32 cookie, u32 source)
  2464. {
  2465. struct sk_buff *skb;
  2466. struct wmix_hb_challenge_resp_cmd *cmd;
  2467. int ret;
  2468. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2469. if (!skb)
  2470. return -ENOMEM;
  2471. cmd = (struct wmix_hb_challenge_resp_cmd *) skb->data;
  2472. cmd->cookie = cpu_to_le32(cookie);
  2473. cmd->source = cpu_to_le32(source);
  2474. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_HB_CHALLENGE_RESP_CMDID,
  2475. NO_SYNC_WMIFLAG);
  2476. return ret;
  2477. }
  2478. int ath6kl_wmi_config_debug_module_cmd(struct wmi *wmi, u32 valid, u32 config)
  2479. {
  2480. struct ath6kl_wmix_dbglog_cfg_module_cmd *cmd;
  2481. struct sk_buff *skb;
  2482. int ret;
  2483. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2484. if (!skb)
  2485. return -ENOMEM;
  2486. cmd = (struct ath6kl_wmix_dbglog_cfg_module_cmd *) skb->data;
  2487. cmd->valid = cpu_to_le32(valid);
  2488. cmd->config = cpu_to_le32(config);
  2489. ret = ath6kl_wmi_cmd_send_xtnd(wmi, skb, WMIX_DBGLOG_CFG_MODULE_CMDID,
  2490. NO_SYNC_WMIFLAG);
  2491. return ret;
  2492. }
  2493. int ath6kl_wmi_get_stats_cmd(struct wmi *wmi, u8 if_idx)
  2494. {
  2495. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_STATISTICS_CMDID);
  2496. }
  2497. int ath6kl_wmi_set_tx_pwr_cmd(struct wmi *wmi, u8 if_idx, u8 dbM)
  2498. {
  2499. struct sk_buff *skb;
  2500. struct wmi_set_tx_pwr_cmd *cmd;
  2501. int ret;
  2502. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_tx_pwr_cmd));
  2503. if (!skb)
  2504. return -ENOMEM;
  2505. cmd = (struct wmi_set_tx_pwr_cmd *) skb->data;
  2506. cmd->dbM = dbM;
  2507. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_TX_PWR_CMDID,
  2508. NO_SYNC_WMIFLAG);
  2509. return ret;
  2510. }
  2511. int ath6kl_wmi_get_tx_pwr_cmd(struct wmi *wmi, u8 if_idx)
  2512. {
  2513. return ath6kl_wmi_simple_cmd(wmi, if_idx, WMI_GET_TX_PWR_CMDID);
  2514. }
  2515. int ath6kl_wmi_get_roam_tbl_cmd(struct wmi *wmi)
  2516. {
  2517. return ath6kl_wmi_simple_cmd(wmi, 0, WMI_GET_ROAM_TBL_CMDID);
  2518. }
  2519. int ath6kl_wmi_set_lpreamble_cmd(struct wmi *wmi, u8 if_idx, u8 status,
  2520. u8 preamble_policy)
  2521. {
  2522. struct sk_buff *skb;
  2523. struct wmi_set_lpreamble_cmd *cmd;
  2524. int ret;
  2525. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_lpreamble_cmd));
  2526. if (!skb)
  2527. return -ENOMEM;
  2528. cmd = (struct wmi_set_lpreamble_cmd *) skb->data;
  2529. cmd->status = status;
  2530. cmd->preamble_policy = preamble_policy;
  2531. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_LPREAMBLE_CMDID,
  2532. NO_SYNC_WMIFLAG);
  2533. return ret;
  2534. }
  2535. int ath6kl_wmi_set_rts_cmd(struct wmi *wmi, u16 threshold)
  2536. {
  2537. struct sk_buff *skb;
  2538. struct wmi_set_rts_cmd *cmd;
  2539. int ret;
  2540. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_rts_cmd));
  2541. if (!skb)
  2542. return -ENOMEM;
  2543. cmd = (struct wmi_set_rts_cmd *) skb->data;
  2544. cmd->threshold = cpu_to_le16(threshold);
  2545. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_SET_RTS_CMDID,
  2546. NO_SYNC_WMIFLAG);
  2547. return ret;
  2548. }
  2549. int ath6kl_wmi_set_wmm_txop(struct wmi *wmi, u8 if_idx, enum wmi_txop_cfg cfg)
  2550. {
  2551. struct sk_buff *skb;
  2552. struct wmi_set_wmm_txop_cmd *cmd;
  2553. int ret;
  2554. if (!((cfg == WMI_TXOP_DISABLED) || (cfg == WMI_TXOP_ENABLED)))
  2555. return -EINVAL;
  2556. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_set_wmm_txop_cmd));
  2557. if (!skb)
  2558. return -ENOMEM;
  2559. cmd = (struct wmi_set_wmm_txop_cmd *) skb->data;
  2560. cmd->txop_enable = cfg;
  2561. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_WMM_TXOP_CMDID,
  2562. NO_SYNC_WMIFLAG);
  2563. return ret;
  2564. }
  2565. int ath6kl_wmi_set_keepalive_cmd(struct wmi *wmi, u8 if_idx,
  2566. u8 keep_alive_intvl)
  2567. {
  2568. struct sk_buff *skb;
  2569. struct wmi_set_keepalive_cmd *cmd;
  2570. int ret;
  2571. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2572. if (!skb)
  2573. return -ENOMEM;
  2574. cmd = (struct wmi_set_keepalive_cmd *) skb->data;
  2575. cmd->keep_alive_intvl = keep_alive_intvl;
  2576. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_KEEPALIVE_CMDID,
  2577. NO_SYNC_WMIFLAG);
  2578. if (ret == 0)
  2579. ath6kl_debug_set_keepalive(wmi->parent_dev, keep_alive_intvl);
  2580. return ret;
  2581. }
  2582. int ath6kl_wmi_set_htcap_cmd(struct wmi *wmi, u8 if_idx,
  2583. enum nl80211_band band,
  2584. struct ath6kl_htcap *htcap)
  2585. {
  2586. struct sk_buff *skb;
  2587. struct wmi_set_htcap_cmd *cmd;
  2588. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2589. if (!skb)
  2590. return -ENOMEM;
  2591. cmd = (struct wmi_set_htcap_cmd *) skb->data;
  2592. /*
  2593. * NOTE: Band in firmware matches enum nl80211_band, it is unlikely
  2594. * this will be changed in firmware. If at all there is any change in
  2595. * band value, the host needs to be fixed.
  2596. */
  2597. cmd->band = band;
  2598. cmd->ht_enable = !!htcap->ht_enable;
  2599. cmd->ht20_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_20);
  2600. cmd->ht40_supported =
  2601. !!(htcap->cap_info & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  2602. cmd->ht40_sgi = !!(htcap->cap_info & IEEE80211_HT_CAP_SGI_40);
  2603. cmd->intolerant_40mhz =
  2604. !!(htcap->cap_info & IEEE80211_HT_CAP_40MHZ_INTOLERANT);
  2605. cmd->max_ampdu_len_exp = htcap->ampdu_factor;
  2606. ath6kl_dbg(ATH6KL_DBG_WMI,
  2607. "Set htcap: band:%d ht_enable:%d 40mhz:%d sgi_20mhz:%d sgi_40mhz:%d 40mhz_intolerant:%d ampdu_len_exp:%d\n",
  2608. cmd->band, cmd->ht_enable, cmd->ht40_supported,
  2609. cmd->ht20_sgi, cmd->ht40_sgi, cmd->intolerant_40mhz,
  2610. cmd->max_ampdu_len_exp);
  2611. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_HT_CAP_CMDID,
  2612. NO_SYNC_WMIFLAG);
  2613. }
  2614. int ath6kl_wmi_test_cmd(struct wmi *wmi, void *buf, size_t len)
  2615. {
  2616. struct sk_buff *skb;
  2617. int ret;
  2618. skb = ath6kl_wmi_get_new_buf(len);
  2619. if (!skb)
  2620. return -ENOMEM;
  2621. memcpy(skb->data, buf, len);
  2622. ret = ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_TEST_CMDID, NO_SYNC_WMIFLAG);
  2623. return ret;
  2624. }
  2625. int ath6kl_wmi_mcast_filter_cmd(struct wmi *wmi, u8 if_idx, bool mc_all_on)
  2626. {
  2627. struct sk_buff *skb;
  2628. struct wmi_mcast_filter_cmd *cmd;
  2629. int ret;
  2630. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2631. if (!skb)
  2632. return -ENOMEM;
  2633. cmd = (struct wmi_mcast_filter_cmd *) skb->data;
  2634. cmd->mcast_all_enable = mc_all_on;
  2635. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_MCAST_FILTER_CMDID,
  2636. NO_SYNC_WMIFLAG);
  2637. return ret;
  2638. }
  2639. int ath6kl_wmi_add_del_mcast_filter_cmd(struct wmi *wmi, u8 if_idx,
  2640. u8 *filter, bool add_filter)
  2641. {
  2642. struct sk_buff *skb;
  2643. struct wmi_mcast_filter_add_del_cmd *cmd;
  2644. int ret;
  2645. if ((filter[0] != 0x33 || filter[1] != 0x33) &&
  2646. (filter[0] != 0x01 || filter[1] != 0x00 ||
  2647. filter[2] != 0x5e || filter[3] > 0x7f)) {
  2648. ath6kl_warn("invalid multicast filter address\n");
  2649. return -EINVAL;
  2650. }
  2651. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2652. if (!skb)
  2653. return -ENOMEM;
  2654. cmd = (struct wmi_mcast_filter_add_del_cmd *) skb->data;
  2655. memcpy(cmd->mcast_mac, filter, ATH6KL_MCAST_FILTER_MAC_ADDR_SIZE);
  2656. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2657. add_filter ? WMI_SET_MCAST_FILTER_CMDID :
  2658. WMI_DEL_MCAST_FILTER_CMDID,
  2659. NO_SYNC_WMIFLAG);
  2660. return ret;
  2661. }
  2662. int ath6kl_wmi_sta_bmiss_enhance_cmd(struct wmi *wmi, u8 if_idx, bool enhance)
  2663. {
  2664. struct sk_buff *skb;
  2665. struct wmi_sta_bmiss_enhance_cmd *cmd;
  2666. int ret;
  2667. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2668. if (!skb)
  2669. return -ENOMEM;
  2670. cmd = (struct wmi_sta_bmiss_enhance_cmd *) skb->data;
  2671. cmd->enable = enhance ? 1 : 0;
  2672. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2673. WMI_STA_BMISS_ENHANCE_CMDID,
  2674. NO_SYNC_WMIFLAG);
  2675. return ret;
  2676. }
  2677. int ath6kl_wmi_set_regdomain_cmd(struct wmi *wmi, const char *alpha2)
  2678. {
  2679. struct sk_buff *skb;
  2680. struct wmi_set_regdomain_cmd *cmd;
  2681. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2682. if (!skb)
  2683. return -ENOMEM;
  2684. cmd = (struct wmi_set_regdomain_cmd *) skb->data;
  2685. memcpy(cmd->iso_name, alpha2, 2);
  2686. return ath6kl_wmi_cmd_send(wmi, 0, skb,
  2687. WMI_SET_REGDOMAIN_CMDID,
  2688. NO_SYNC_WMIFLAG);
  2689. }
  2690. s32 ath6kl_wmi_get_rate(struct wmi *wmi, s8 rate_index)
  2691. {
  2692. struct ath6kl *ar = wmi->parent_dev;
  2693. u8 sgi = 0;
  2694. s32 ret;
  2695. if (rate_index == RATE_AUTO)
  2696. return 0;
  2697. /* SGI is stored as the MSB of the rate_index */
  2698. if (rate_index & RATE_INDEX_MSB) {
  2699. rate_index &= RATE_INDEX_WITHOUT_SGI_MASK;
  2700. sgi = 1;
  2701. }
  2702. if (test_bit(ATH6KL_FW_CAPABILITY_RATETABLE_MCS15,
  2703. ar->fw_capabilities)) {
  2704. if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl_mcs15)))
  2705. return 0;
  2706. ret = wmi_rate_tbl_mcs15[(u32) rate_index][sgi];
  2707. } else {
  2708. if (WARN_ON(rate_index >= ARRAY_SIZE(wmi_rate_tbl)))
  2709. return 0;
  2710. ret = wmi_rate_tbl[(u32) rate_index][sgi];
  2711. }
  2712. return ret;
  2713. }
  2714. static int ath6kl_wmi_get_pmkid_list_event_rx(struct wmi *wmi, u8 *datap,
  2715. u32 len)
  2716. {
  2717. struct wmi_pmkid_list_reply *reply;
  2718. u32 expected_len;
  2719. if (len < sizeof(struct wmi_pmkid_list_reply))
  2720. return -EINVAL;
  2721. reply = (struct wmi_pmkid_list_reply *)datap;
  2722. expected_len = sizeof(reply->num_pmkid) +
  2723. le32_to_cpu(reply->num_pmkid) * WMI_PMKID_LEN;
  2724. if (len < expected_len)
  2725. return -EINVAL;
  2726. return 0;
  2727. }
  2728. static int ath6kl_wmi_addba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2729. struct ath6kl_vif *vif)
  2730. {
  2731. struct wmi_addba_req_event *cmd = (struct wmi_addba_req_event *) datap;
  2732. aggr_recv_addba_req_evt(vif, cmd->tid,
  2733. le16_to_cpu(cmd->st_seq_no), cmd->win_sz);
  2734. return 0;
  2735. }
  2736. static int ath6kl_wmi_delba_req_event_rx(struct wmi *wmi, u8 *datap, int len,
  2737. struct ath6kl_vif *vif)
  2738. {
  2739. struct wmi_delba_event *cmd = (struct wmi_delba_event *) datap;
  2740. aggr_recv_delba_req_evt(vif, cmd->tid);
  2741. return 0;
  2742. }
  2743. /* AP mode functions */
  2744. int ath6kl_wmi_ap_profile_commit(struct wmi *wmip, u8 if_idx,
  2745. struct wmi_connect_cmd *p)
  2746. {
  2747. struct sk_buff *skb;
  2748. struct wmi_connect_cmd *cm;
  2749. int res;
  2750. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2751. if (!skb)
  2752. return -ENOMEM;
  2753. cm = (struct wmi_connect_cmd *) skb->data;
  2754. memcpy(cm, p, sizeof(*cm));
  2755. res = ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_CONFIG_COMMIT_CMDID,
  2756. NO_SYNC_WMIFLAG);
  2757. ath6kl_dbg(ATH6KL_DBG_WMI,
  2758. "%s: nw_type=%u auth_mode=%u ch=%u ctrl_flags=0x%x-> res=%d\n",
  2759. __func__, p->nw_type, p->auth_mode, le16_to_cpu(p->ch),
  2760. le32_to_cpu(p->ctrl_flags), res);
  2761. return res;
  2762. }
  2763. int ath6kl_wmi_ap_set_mlme(struct wmi *wmip, u8 if_idx, u8 cmd, const u8 *mac,
  2764. u16 reason)
  2765. {
  2766. struct sk_buff *skb;
  2767. struct wmi_ap_set_mlme_cmd *cm;
  2768. skb = ath6kl_wmi_get_new_buf(sizeof(*cm));
  2769. if (!skb)
  2770. return -ENOMEM;
  2771. cm = (struct wmi_ap_set_mlme_cmd *) skb->data;
  2772. memcpy(cm->mac, mac, ETH_ALEN);
  2773. cm->reason = cpu_to_le16(reason);
  2774. cm->cmd = cmd;
  2775. ath6kl_dbg(ATH6KL_DBG_WMI, "ap_set_mlme: cmd=%d reason=%d\n", cm->cmd,
  2776. cm->reason);
  2777. return ath6kl_wmi_cmd_send(wmip, if_idx, skb, WMI_AP_SET_MLME_CMDID,
  2778. NO_SYNC_WMIFLAG);
  2779. }
  2780. int ath6kl_wmi_ap_hidden_ssid(struct wmi *wmi, u8 if_idx, bool enable)
  2781. {
  2782. struct sk_buff *skb;
  2783. struct wmi_ap_hidden_ssid_cmd *cmd;
  2784. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2785. if (!skb)
  2786. return -ENOMEM;
  2787. cmd = (struct wmi_ap_hidden_ssid_cmd *) skb->data;
  2788. cmd->hidden_ssid = enable ? 1 : 0;
  2789. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_HIDDEN_SSID_CMDID,
  2790. NO_SYNC_WMIFLAG);
  2791. }
  2792. /* This command will be used to enable/disable AP uAPSD feature */
  2793. int ath6kl_wmi_ap_set_apsd(struct wmi *wmi, u8 if_idx, u8 enable)
  2794. {
  2795. struct wmi_ap_set_apsd_cmd *cmd;
  2796. struct sk_buff *skb;
  2797. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2798. if (!skb)
  2799. return -ENOMEM;
  2800. cmd = (struct wmi_ap_set_apsd_cmd *)skb->data;
  2801. cmd->enable = enable;
  2802. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_APSD_CMDID,
  2803. NO_SYNC_WMIFLAG);
  2804. }
  2805. int ath6kl_wmi_set_apsd_bfrd_traf(struct wmi *wmi, u8 if_idx,
  2806. u16 aid, u16 bitmap, u32 flags)
  2807. {
  2808. struct wmi_ap_apsd_buffered_traffic_cmd *cmd;
  2809. struct sk_buff *skb;
  2810. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2811. if (!skb)
  2812. return -ENOMEM;
  2813. cmd = (struct wmi_ap_apsd_buffered_traffic_cmd *)skb->data;
  2814. cmd->aid = cpu_to_le16(aid);
  2815. cmd->bitmap = cpu_to_le16(bitmap);
  2816. cmd->flags = cpu_to_le32(flags);
  2817. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  2818. WMI_AP_APSD_BUFFERED_TRAFFIC_CMDID,
  2819. NO_SYNC_WMIFLAG);
  2820. }
  2821. static int ath6kl_wmi_pspoll_event_rx(struct wmi *wmi, u8 *datap, int len,
  2822. struct ath6kl_vif *vif)
  2823. {
  2824. struct wmi_pspoll_event *ev;
  2825. if (len < sizeof(struct wmi_pspoll_event))
  2826. return -EINVAL;
  2827. ev = (struct wmi_pspoll_event *) datap;
  2828. ath6kl_pspoll_event(vif, le16_to_cpu(ev->aid));
  2829. return 0;
  2830. }
  2831. static int ath6kl_wmi_dtimexpiry_event_rx(struct wmi *wmi, u8 *datap, int len,
  2832. struct ath6kl_vif *vif)
  2833. {
  2834. ath6kl_dtimexpiry_event(vif);
  2835. return 0;
  2836. }
  2837. int ath6kl_wmi_set_pvb_cmd(struct wmi *wmi, u8 if_idx, u16 aid,
  2838. bool flag)
  2839. {
  2840. struct sk_buff *skb;
  2841. struct wmi_ap_set_pvb_cmd *cmd;
  2842. int ret;
  2843. skb = ath6kl_wmi_get_new_buf(sizeof(struct wmi_ap_set_pvb_cmd));
  2844. if (!skb)
  2845. return -ENOMEM;
  2846. cmd = (struct wmi_ap_set_pvb_cmd *) skb->data;
  2847. cmd->aid = cpu_to_le16(aid);
  2848. cmd->rsvd = cpu_to_le16(0);
  2849. cmd->flag = cpu_to_le32(flag);
  2850. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_SET_PVB_CMDID,
  2851. NO_SYNC_WMIFLAG);
  2852. return ret;
  2853. }
  2854. int ath6kl_wmi_set_rx_frame_format_cmd(struct wmi *wmi, u8 if_idx,
  2855. u8 rx_meta_ver,
  2856. bool rx_dot11_hdr, bool defrag_on_host)
  2857. {
  2858. struct sk_buff *skb;
  2859. struct wmi_rx_frame_format_cmd *cmd;
  2860. int ret;
  2861. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2862. if (!skb)
  2863. return -ENOMEM;
  2864. cmd = (struct wmi_rx_frame_format_cmd *) skb->data;
  2865. cmd->dot11_hdr = rx_dot11_hdr ? 1 : 0;
  2866. cmd->defrag_on_host = defrag_on_host ? 1 : 0;
  2867. cmd->meta_ver = rx_meta_ver;
  2868. /* Delete the local aggr state, on host */
  2869. ret = ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_RX_FRAME_FORMAT_CMDID,
  2870. NO_SYNC_WMIFLAG);
  2871. return ret;
  2872. }
  2873. int ath6kl_wmi_set_appie_cmd(struct wmi *wmi, u8 if_idx, u8 mgmt_frm_type,
  2874. const u8 *ie, u8 ie_len)
  2875. {
  2876. struct sk_buff *skb;
  2877. struct wmi_set_appie_cmd *p;
  2878. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2879. if (!skb)
  2880. return -ENOMEM;
  2881. ath6kl_dbg(ATH6KL_DBG_WMI,
  2882. "set_appie_cmd: mgmt_frm_type=%u ie_len=%u\n",
  2883. mgmt_frm_type, ie_len);
  2884. p = (struct wmi_set_appie_cmd *) skb->data;
  2885. p->mgmt_frm_type = mgmt_frm_type;
  2886. p->ie_len = ie_len;
  2887. if (ie != NULL && ie_len > 0)
  2888. memcpy(p->ie_info, ie, ie_len);
  2889. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_APPIE_CMDID,
  2890. NO_SYNC_WMIFLAG);
  2891. }
  2892. int ath6kl_wmi_set_ie_cmd(struct wmi *wmi, u8 if_idx, u8 ie_id, u8 ie_field,
  2893. const u8 *ie_info, u8 ie_len)
  2894. {
  2895. struct sk_buff *skb;
  2896. struct wmi_set_ie_cmd *p;
  2897. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + ie_len);
  2898. if (!skb)
  2899. return -ENOMEM;
  2900. ath6kl_dbg(ATH6KL_DBG_WMI, "set_ie_cmd: ie_id=%u ie_ie_field=%u ie_len=%u\n",
  2901. ie_id, ie_field, ie_len);
  2902. p = (struct wmi_set_ie_cmd *) skb->data;
  2903. p->ie_id = ie_id;
  2904. p->ie_field = ie_field;
  2905. p->ie_len = ie_len;
  2906. if (ie_info && ie_len > 0)
  2907. memcpy(p->ie_info, ie_info, ie_len);
  2908. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SET_IE_CMDID,
  2909. NO_SYNC_WMIFLAG);
  2910. }
  2911. int ath6kl_wmi_disable_11b_rates_cmd(struct wmi *wmi, bool disable)
  2912. {
  2913. struct sk_buff *skb;
  2914. struct wmi_disable_11b_rates_cmd *cmd;
  2915. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  2916. if (!skb)
  2917. return -ENOMEM;
  2918. ath6kl_dbg(ATH6KL_DBG_WMI, "disable_11b_rates_cmd: disable=%u\n",
  2919. disable);
  2920. cmd = (struct wmi_disable_11b_rates_cmd *) skb->data;
  2921. cmd->disable = disable ? 1 : 0;
  2922. return ath6kl_wmi_cmd_send(wmi, 0, skb, WMI_DISABLE_11B_RATES_CMDID,
  2923. NO_SYNC_WMIFLAG);
  2924. }
  2925. int ath6kl_wmi_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx, u32 freq, u32 dur)
  2926. {
  2927. struct sk_buff *skb;
  2928. struct wmi_remain_on_chnl_cmd *p;
  2929. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  2930. if (!skb)
  2931. return -ENOMEM;
  2932. ath6kl_dbg(ATH6KL_DBG_WMI, "remain_on_chnl_cmd: freq=%u dur=%u\n",
  2933. freq, dur);
  2934. p = (struct wmi_remain_on_chnl_cmd *) skb->data;
  2935. p->freq = cpu_to_le32(freq);
  2936. p->duration = cpu_to_le32(dur);
  2937. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_REMAIN_ON_CHNL_CMDID,
  2938. NO_SYNC_WMIFLAG);
  2939. }
  2940. /* ath6kl_wmi_send_action_cmd is to be deprecated. Use
  2941. * ath6kl_wmi_send_mgmt_cmd instead. The new function supports P2P
  2942. * mgmt operations using station interface.
  2943. */
  2944. static int ath6kl_wmi_send_action_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2945. u32 freq, u32 wait, const u8 *data,
  2946. u16 data_len)
  2947. {
  2948. struct sk_buff *skb;
  2949. struct wmi_send_action_cmd *p;
  2950. u8 *buf;
  2951. if (wait)
  2952. return -EINVAL; /* Offload for wait not supported */
  2953. buf = kmemdup(data, data_len, GFP_KERNEL);
  2954. if (!buf)
  2955. return -ENOMEM;
  2956. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2957. if (!skb) {
  2958. kfree(buf);
  2959. return -ENOMEM;
  2960. }
  2961. kfree(wmi->last_mgmt_tx_frame);
  2962. wmi->last_mgmt_tx_frame = buf;
  2963. wmi->last_mgmt_tx_frame_len = data_len;
  2964. ath6kl_dbg(ATH6KL_DBG_WMI,
  2965. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2966. id, freq, wait, data_len);
  2967. p = (struct wmi_send_action_cmd *) skb->data;
  2968. p->id = cpu_to_le32(id);
  2969. p->freq = cpu_to_le32(freq);
  2970. p->wait = cpu_to_le32(wait);
  2971. p->len = cpu_to_le16(data_len);
  2972. memcpy(p->data, data, data_len);
  2973. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_ACTION_CMDID,
  2974. NO_SYNC_WMIFLAG);
  2975. }
  2976. static int __ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id,
  2977. u32 freq, u32 wait, const u8 *data,
  2978. u16 data_len, u32 no_cck)
  2979. {
  2980. struct sk_buff *skb;
  2981. struct wmi_send_mgmt_cmd *p;
  2982. u8 *buf;
  2983. if (wait)
  2984. return -EINVAL; /* Offload for wait not supported */
  2985. buf = kmemdup(data, data_len, GFP_KERNEL);
  2986. if (!buf)
  2987. return -ENOMEM;
  2988. skb = ath6kl_wmi_get_new_buf(sizeof(*p) + data_len);
  2989. if (!skb) {
  2990. kfree(buf);
  2991. return -ENOMEM;
  2992. }
  2993. kfree(wmi->last_mgmt_tx_frame);
  2994. wmi->last_mgmt_tx_frame = buf;
  2995. wmi->last_mgmt_tx_frame_len = data_len;
  2996. ath6kl_dbg(ATH6KL_DBG_WMI,
  2997. "send_action_cmd: id=%u freq=%u wait=%u len=%u\n",
  2998. id, freq, wait, data_len);
  2999. p = (struct wmi_send_mgmt_cmd *) skb->data;
  3000. p->id = cpu_to_le32(id);
  3001. p->freq = cpu_to_le32(freq);
  3002. p->wait = cpu_to_le32(wait);
  3003. p->no_cck = cpu_to_le32(no_cck);
  3004. p->len = cpu_to_le16(data_len);
  3005. memcpy(p->data, data, data_len);
  3006. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_SEND_MGMT_CMDID,
  3007. NO_SYNC_WMIFLAG);
  3008. }
  3009. int ath6kl_wmi_send_mgmt_cmd(struct wmi *wmi, u8 if_idx, u32 id, u32 freq,
  3010. u32 wait, const u8 *data, u16 data_len,
  3011. u32 no_cck)
  3012. {
  3013. int status;
  3014. struct ath6kl *ar = wmi->parent_dev;
  3015. if (test_bit(ATH6KL_FW_CAPABILITY_STA_P2PDEV_DUPLEX,
  3016. ar->fw_capabilities)) {
  3017. /*
  3018. * If capable of doing P2P mgmt operations using
  3019. * station interface, send additional information like
  3020. * supported rates to advertise and xmit rates for
  3021. * probe requests
  3022. */
  3023. status = __ath6kl_wmi_send_mgmt_cmd(ar->wmi, if_idx, id, freq,
  3024. wait, data, data_len,
  3025. no_cck);
  3026. } else {
  3027. status = ath6kl_wmi_send_action_cmd(ar->wmi, if_idx, id, freq,
  3028. wait, data, data_len);
  3029. }
  3030. return status;
  3031. }
  3032. int ath6kl_wmi_send_probe_response_cmd(struct wmi *wmi, u8 if_idx, u32 freq,
  3033. const u8 *dst, const u8 *data,
  3034. u16 data_len)
  3035. {
  3036. struct sk_buff *skb;
  3037. struct wmi_p2p_probe_response_cmd *p;
  3038. size_t cmd_len = sizeof(*p) + data_len;
  3039. if (data_len == 0)
  3040. cmd_len++; /* work around target minimum length requirement */
  3041. skb = ath6kl_wmi_get_new_buf(cmd_len);
  3042. if (!skb)
  3043. return -ENOMEM;
  3044. ath6kl_dbg(ATH6KL_DBG_WMI,
  3045. "send_probe_response_cmd: freq=%u dst=%pM len=%u\n",
  3046. freq, dst, data_len);
  3047. p = (struct wmi_p2p_probe_response_cmd *) skb->data;
  3048. p->freq = cpu_to_le32(freq);
  3049. memcpy(p->destination_addr, dst, ETH_ALEN);
  3050. p->len = cpu_to_le16(data_len);
  3051. memcpy(p->data, data, data_len);
  3052. return ath6kl_wmi_cmd_send(wmi, if_idx, skb,
  3053. WMI_SEND_PROBE_RESPONSE_CMDID,
  3054. NO_SYNC_WMIFLAG);
  3055. }
  3056. int ath6kl_wmi_probe_report_req_cmd(struct wmi *wmi, u8 if_idx, bool enable)
  3057. {
  3058. struct sk_buff *skb;
  3059. struct wmi_probe_req_report_cmd *p;
  3060. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  3061. if (!skb)
  3062. return -ENOMEM;
  3063. ath6kl_dbg(ATH6KL_DBG_WMI, "probe_report_req_cmd: enable=%u\n",
  3064. enable);
  3065. p = (struct wmi_probe_req_report_cmd *) skb->data;
  3066. p->enable = enable ? 1 : 0;
  3067. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_PROBE_REQ_REPORT_CMDID,
  3068. NO_SYNC_WMIFLAG);
  3069. }
  3070. int ath6kl_wmi_info_req_cmd(struct wmi *wmi, u8 if_idx, u32 info_req_flags)
  3071. {
  3072. struct sk_buff *skb;
  3073. struct wmi_get_p2p_info *p;
  3074. skb = ath6kl_wmi_get_new_buf(sizeof(*p));
  3075. if (!skb)
  3076. return -ENOMEM;
  3077. ath6kl_dbg(ATH6KL_DBG_WMI, "info_req_cmd: flags=%x\n",
  3078. info_req_flags);
  3079. p = (struct wmi_get_p2p_info *) skb->data;
  3080. p->info_req_flags = cpu_to_le32(info_req_flags);
  3081. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_GET_P2P_INFO_CMDID,
  3082. NO_SYNC_WMIFLAG);
  3083. }
  3084. int ath6kl_wmi_cancel_remain_on_chnl_cmd(struct wmi *wmi, u8 if_idx)
  3085. {
  3086. ath6kl_dbg(ATH6KL_DBG_WMI, "cancel_remain_on_chnl_cmd\n");
  3087. return ath6kl_wmi_simple_cmd(wmi, if_idx,
  3088. WMI_CANCEL_REMAIN_ON_CHNL_CMDID);
  3089. }
  3090. int ath6kl_wmi_set_inact_period(struct wmi *wmi, u8 if_idx, int inact_timeout)
  3091. {
  3092. struct sk_buff *skb;
  3093. struct wmi_set_inact_period_cmd *cmd;
  3094. skb = ath6kl_wmi_get_new_buf(sizeof(*cmd));
  3095. if (!skb)
  3096. return -ENOMEM;
  3097. cmd = (struct wmi_set_inact_period_cmd *) skb->data;
  3098. cmd->inact_period = cpu_to_le32(inact_timeout);
  3099. cmd->num_null_func = 0;
  3100. return ath6kl_wmi_cmd_send(wmi, if_idx, skb, WMI_AP_CONN_INACT_CMDID,
  3101. NO_SYNC_WMIFLAG);
  3102. }
  3103. static void ath6kl_wmi_hb_challenge_resp_event(struct wmi *wmi, u8 *datap,
  3104. int len)
  3105. {
  3106. struct wmix_hb_challenge_resp_cmd *cmd;
  3107. if (len < sizeof(struct wmix_hb_challenge_resp_cmd))
  3108. return;
  3109. cmd = (struct wmix_hb_challenge_resp_cmd *) datap;
  3110. ath6kl_recovery_hb_event(wmi->parent_dev,
  3111. le32_to_cpu(cmd->cookie));
  3112. }
  3113. static int ath6kl_wmi_control_rx_xtnd(struct wmi *wmi, struct sk_buff *skb)
  3114. {
  3115. struct wmix_cmd_hdr *cmd;
  3116. u32 len;
  3117. u16 id;
  3118. u8 *datap;
  3119. int ret = 0;
  3120. if (skb->len < sizeof(struct wmix_cmd_hdr)) {
  3121. ath6kl_err("bad packet 1\n");
  3122. return -EINVAL;
  3123. }
  3124. cmd = (struct wmix_cmd_hdr *) skb->data;
  3125. id = le32_to_cpu(cmd->cmd_id);
  3126. skb_pull(skb, sizeof(struct wmix_cmd_hdr));
  3127. datap = skb->data;
  3128. len = skb->len;
  3129. switch (id) {
  3130. case WMIX_HB_CHALLENGE_RESP_EVENTID:
  3131. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event hb challenge resp\n");
  3132. ath6kl_wmi_hb_challenge_resp_event(wmi, datap, len);
  3133. break;
  3134. case WMIX_DBGLOG_EVENTID:
  3135. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi event dbglog len %d\n", len);
  3136. ath6kl_debug_fwlog_event(wmi->parent_dev, datap, len);
  3137. break;
  3138. default:
  3139. ath6kl_warn("unknown cmd id 0x%x\n", id);
  3140. ret = -EINVAL;
  3141. break;
  3142. }
  3143. return ret;
  3144. }
  3145. static int ath6kl_wmi_roam_tbl_event_rx(struct wmi *wmi, u8 *datap, int len)
  3146. {
  3147. return ath6kl_debug_roam_tbl_event(wmi->parent_dev, datap, len);
  3148. }
  3149. /* Process interface specific wmi events, caller would free the datap */
  3150. static int ath6kl_wmi_proc_events_vif(struct wmi *wmi, u16 if_idx, u16 cmd_id,
  3151. u8 *datap, u32 len)
  3152. {
  3153. struct ath6kl_vif *vif;
  3154. vif = ath6kl_get_vif_by_index(wmi->parent_dev, if_idx);
  3155. if (!vif) {
  3156. ath6kl_dbg(ATH6KL_DBG_WMI,
  3157. "Wmi event for unavailable vif, vif_index:%d\n",
  3158. if_idx);
  3159. return -EINVAL;
  3160. }
  3161. switch (cmd_id) {
  3162. case WMI_CONNECT_EVENTID:
  3163. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CONNECT_EVENTID\n");
  3164. return ath6kl_wmi_connect_event_rx(wmi, datap, len, vif);
  3165. case WMI_DISCONNECT_EVENTID:
  3166. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DISCONNECT_EVENTID\n");
  3167. return ath6kl_wmi_disconnect_event_rx(wmi, datap, len, vif);
  3168. case WMI_TKIP_MICERR_EVENTID:
  3169. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TKIP_MICERR_EVENTID\n");
  3170. return ath6kl_wmi_tkip_micerr_event_rx(wmi, datap, len, vif);
  3171. case WMI_BSSINFO_EVENTID:
  3172. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_BSSINFO_EVENTID\n");
  3173. return ath6kl_wmi_bssinfo_event_rx(wmi, datap, len, vif);
  3174. case WMI_NEIGHBOR_REPORT_EVENTID:
  3175. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_NEIGHBOR_REPORT_EVENTID\n");
  3176. return ath6kl_wmi_neighbor_report_event_rx(wmi, datap, len,
  3177. vif);
  3178. case WMI_SCAN_COMPLETE_EVENTID:
  3179. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SCAN_COMPLETE_EVENTID\n");
  3180. return ath6kl_wmi_scan_complete_rx(wmi, datap, len, vif);
  3181. case WMI_REPORT_STATISTICS_EVENTID:
  3182. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_STATISTICS_EVENTID\n");
  3183. return ath6kl_wmi_stats_event_rx(wmi, datap, len, vif);
  3184. case WMI_CAC_EVENTID:
  3185. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CAC_EVENTID\n");
  3186. return ath6kl_wmi_cac_event_rx(wmi, datap, len, vif);
  3187. case WMI_PSPOLL_EVENTID:
  3188. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSPOLL_EVENTID\n");
  3189. return ath6kl_wmi_pspoll_event_rx(wmi, datap, len, vif);
  3190. case WMI_DTIMEXPIRY_EVENTID:
  3191. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DTIMEXPIRY_EVENTID\n");
  3192. return ath6kl_wmi_dtimexpiry_event_rx(wmi, datap, len, vif);
  3193. case WMI_ADDBA_REQ_EVENTID:
  3194. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_REQ_EVENTID\n");
  3195. return ath6kl_wmi_addba_req_event_rx(wmi, datap, len, vif);
  3196. case WMI_DELBA_REQ_EVENTID:
  3197. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_DELBA_REQ_EVENTID\n");
  3198. return ath6kl_wmi_delba_req_event_rx(wmi, datap, len, vif);
  3199. case WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID:
  3200. ath6kl_dbg(ATH6KL_DBG_WMI,
  3201. "WMI_SET_HOST_SLEEP_MODE_CMD_PROCESSED_EVENTID");
  3202. return ath6kl_wmi_host_sleep_mode_cmd_prcd_evt_rx(wmi, vif);
  3203. case WMI_REMAIN_ON_CHNL_EVENTID:
  3204. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REMAIN_ON_CHNL_EVENTID\n");
  3205. return ath6kl_wmi_remain_on_chnl_event_rx(wmi, datap, len, vif);
  3206. case WMI_CANCEL_REMAIN_ON_CHNL_EVENTID:
  3207. ath6kl_dbg(ATH6KL_DBG_WMI,
  3208. "WMI_CANCEL_REMAIN_ON_CHNL_EVENTID\n");
  3209. return ath6kl_wmi_cancel_remain_on_chnl_event_rx(wmi, datap,
  3210. len, vif);
  3211. case WMI_TX_STATUS_EVENTID:
  3212. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_STATUS_EVENTID\n");
  3213. return ath6kl_wmi_tx_status_event_rx(wmi, datap, len, vif);
  3214. case WMI_RX_PROBE_REQ_EVENTID:
  3215. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_PROBE_REQ_EVENTID\n");
  3216. return ath6kl_wmi_rx_probe_req_event_rx(wmi, datap, len, vif);
  3217. case WMI_RX_ACTION_EVENTID:
  3218. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RX_ACTION_EVENTID\n");
  3219. return ath6kl_wmi_rx_action_event_rx(wmi, datap, len, vif);
  3220. case WMI_TXE_NOTIFY_EVENTID:
  3221. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TXE_NOTIFY_EVENTID\n");
  3222. return ath6kl_wmi_txe_notify_event_rx(wmi, datap, len, vif);
  3223. default:
  3224. ath6kl_dbg(ATH6KL_DBG_WMI, "unknown cmd id 0x%x\n", cmd_id);
  3225. return -EINVAL;
  3226. }
  3227. return 0;
  3228. }
  3229. static int ath6kl_wmi_proc_events(struct wmi *wmi, struct sk_buff *skb)
  3230. {
  3231. struct wmi_cmd_hdr *cmd;
  3232. int ret = 0;
  3233. u32 len;
  3234. u16 id;
  3235. u8 if_idx;
  3236. u8 *datap;
  3237. cmd = (struct wmi_cmd_hdr *) skb->data;
  3238. id = le16_to_cpu(cmd->cmd_id);
  3239. if_idx = le16_to_cpu(cmd->info1) & WMI_CMD_HDR_IF_ID_MASK;
  3240. skb_pull(skb, sizeof(struct wmi_cmd_hdr));
  3241. datap = skb->data;
  3242. len = skb->len;
  3243. ath6kl_dbg(ATH6KL_DBG_WMI, "wmi rx id %d len %d\n", id, len);
  3244. ath6kl_dbg_dump(ATH6KL_DBG_WMI_DUMP, NULL, "wmi rx ",
  3245. datap, len);
  3246. switch (id) {
  3247. case WMI_GET_BITRATE_CMDID:
  3248. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_BITRATE_CMDID\n");
  3249. ret = ath6kl_wmi_bitrate_reply_rx(wmi, datap, len);
  3250. break;
  3251. case WMI_GET_CHANNEL_LIST_CMDID:
  3252. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_CHANNEL_LIST_CMDID\n");
  3253. ret = ath6kl_wmi_ch_list_reply_rx(wmi, datap, len);
  3254. break;
  3255. case WMI_GET_TX_PWR_CMDID:
  3256. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_TX_PWR_CMDID\n");
  3257. ret = ath6kl_wmi_tx_pwr_reply_rx(wmi, datap, len);
  3258. break;
  3259. case WMI_READY_EVENTID:
  3260. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_READY_EVENTID\n");
  3261. ret = ath6kl_wmi_ready_event_rx(wmi, datap, len);
  3262. break;
  3263. case WMI_PEER_NODE_EVENTID:
  3264. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PEER_NODE_EVENTID\n");
  3265. ret = ath6kl_wmi_peer_node_event_rx(wmi, datap, len);
  3266. break;
  3267. case WMI_REGDOMAIN_EVENTID:
  3268. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REGDOMAIN_EVENTID\n");
  3269. ath6kl_wmi_regdomain_event(wmi, datap, len);
  3270. break;
  3271. case WMI_PSTREAM_TIMEOUT_EVENTID:
  3272. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_PSTREAM_TIMEOUT_EVENTID\n");
  3273. ret = ath6kl_wmi_pstream_timeout_event_rx(wmi, datap, len);
  3274. break;
  3275. case WMI_CMDERROR_EVENTID:
  3276. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CMDERROR_EVENTID\n");
  3277. ret = ath6kl_wmi_error_event_rx(wmi, datap, len);
  3278. break;
  3279. case WMI_RSSI_THRESHOLD_EVENTID:
  3280. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_RSSI_THRESHOLD_EVENTID\n");
  3281. ret = ath6kl_wmi_rssi_threshold_event_rx(wmi, datap, len);
  3282. break;
  3283. case WMI_ERROR_REPORT_EVENTID:
  3284. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ERROR_REPORT_EVENTID\n");
  3285. break;
  3286. case WMI_OPT_RX_FRAME_EVENTID:
  3287. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_OPT_RX_FRAME_EVENTID\n");
  3288. /* this event has been deprecated */
  3289. break;
  3290. case WMI_REPORT_ROAM_TBL_EVENTID:
  3291. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_TBL_EVENTID\n");
  3292. ret = ath6kl_wmi_roam_tbl_event_rx(wmi, datap, len);
  3293. break;
  3294. case WMI_EXTENSION_EVENTID:
  3295. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_EXTENSION_EVENTID\n");
  3296. ret = ath6kl_wmi_control_rx_xtnd(wmi, skb);
  3297. break;
  3298. case WMI_CHANNEL_CHANGE_EVENTID:
  3299. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_CHANNEL_CHANGE_EVENTID\n");
  3300. break;
  3301. case WMI_REPORT_ROAM_DATA_EVENTID:
  3302. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_REPORT_ROAM_DATA_EVENTID\n");
  3303. break;
  3304. case WMI_TEST_EVENTID:
  3305. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TEST_EVENTID\n");
  3306. ret = ath6kl_wmi_test_rx(wmi, datap, len);
  3307. break;
  3308. case WMI_GET_FIXRATES_CMDID:
  3309. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_FIXRATES_CMDID\n");
  3310. ret = ath6kl_wmi_ratemask_reply_rx(wmi, datap, len);
  3311. break;
  3312. case WMI_TX_RETRY_ERR_EVENTID:
  3313. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_RETRY_ERR_EVENTID\n");
  3314. break;
  3315. case WMI_SNR_THRESHOLD_EVENTID:
  3316. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SNR_THRESHOLD_EVENTID\n");
  3317. ret = ath6kl_wmi_snr_threshold_event_rx(wmi, datap, len);
  3318. break;
  3319. case WMI_LQ_THRESHOLD_EVENTID:
  3320. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_LQ_THRESHOLD_EVENTID\n");
  3321. break;
  3322. case WMI_APLIST_EVENTID:
  3323. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_APLIST_EVENTID\n");
  3324. ret = ath6kl_wmi_aplist_event_rx(wmi, datap, len);
  3325. break;
  3326. case WMI_GET_KEEPALIVE_CMDID:
  3327. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_KEEPALIVE_CMDID\n");
  3328. ret = ath6kl_wmi_keepalive_reply_rx(wmi, datap, len);
  3329. break;
  3330. case WMI_GET_WOW_LIST_EVENTID:
  3331. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_WOW_LIST_EVENTID\n");
  3332. break;
  3333. case WMI_GET_PMKID_LIST_EVENTID:
  3334. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_GET_PMKID_LIST_EVENTID\n");
  3335. ret = ath6kl_wmi_get_pmkid_list_event_rx(wmi, datap, len);
  3336. break;
  3337. case WMI_SET_PARAMS_REPLY_EVENTID:
  3338. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_SET_PARAMS_REPLY_EVENTID\n");
  3339. break;
  3340. case WMI_ADDBA_RESP_EVENTID:
  3341. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_ADDBA_RESP_EVENTID\n");
  3342. break;
  3343. case WMI_REPORT_BTCOEX_CONFIG_EVENTID:
  3344. ath6kl_dbg(ATH6KL_DBG_WMI,
  3345. "WMI_REPORT_BTCOEX_CONFIG_EVENTID\n");
  3346. break;
  3347. case WMI_REPORT_BTCOEX_STATS_EVENTID:
  3348. ath6kl_dbg(ATH6KL_DBG_WMI,
  3349. "WMI_REPORT_BTCOEX_STATS_EVENTID\n");
  3350. break;
  3351. case WMI_TX_COMPLETE_EVENTID:
  3352. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_TX_COMPLETE_EVENTID\n");
  3353. ret = ath6kl_wmi_tx_complete_event_rx(datap, len);
  3354. break;
  3355. case WMI_P2P_CAPABILITIES_EVENTID:
  3356. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_CAPABILITIES_EVENTID\n");
  3357. ret = ath6kl_wmi_p2p_capabilities_event_rx(datap, len);
  3358. break;
  3359. case WMI_P2P_INFO_EVENTID:
  3360. ath6kl_dbg(ATH6KL_DBG_WMI, "WMI_P2P_INFO_EVENTID\n");
  3361. ret = ath6kl_wmi_p2p_info_event_rx(datap, len);
  3362. break;
  3363. default:
  3364. /* may be the event is interface specific */
  3365. ret = ath6kl_wmi_proc_events_vif(wmi, if_idx, id, datap, len);
  3366. break;
  3367. }
  3368. dev_kfree_skb(skb);
  3369. return ret;
  3370. }
  3371. /* Control Path */
  3372. int ath6kl_wmi_control_rx(struct wmi *wmi, struct sk_buff *skb)
  3373. {
  3374. if (WARN_ON(skb == NULL))
  3375. return -EINVAL;
  3376. if (skb->len < sizeof(struct wmi_cmd_hdr)) {
  3377. ath6kl_err("bad packet 1\n");
  3378. dev_kfree_skb(skb);
  3379. return -EINVAL;
  3380. }
  3381. trace_ath6kl_wmi_event(skb->data, skb->len);
  3382. return ath6kl_wmi_proc_events(wmi, skb);
  3383. }
  3384. void ath6kl_wmi_reset(struct wmi *wmi)
  3385. {
  3386. spin_lock_bh(&wmi->lock);
  3387. wmi->fat_pipe_exist = 0;
  3388. memset(wmi->stream_exist_for_ac, 0, sizeof(wmi->stream_exist_for_ac));
  3389. spin_unlock_bh(&wmi->lock);
  3390. }
  3391. void *ath6kl_wmi_init(struct ath6kl *dev)
  3392. {
  3393. struct wmi *wmi;
  3394. wmi = kzalloc(sizeof(struct wmi), GFP_KERNEL);
  3395. if (!wmi)
  3396. return NULL;
  3397. spin_lock_init(&wmi->lock);
  3398. wmi->parent_dev = dev;
  3399. wmi->pwr_mode = REC_POWER;
  3400. ath6kl_wmi_reset(wmi);
  3401. return wmi;
  3402. }
  3403. void ath6kl_wmi_shutdown(struct wmi *wmi)
  3404. {
  3405. if (!wmi)
  3406. return;
  3407. kfree(wmi->last_mgmt_tx_frame);
  3408. kfree(wmi);
  3409. }