2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
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.
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.
18 #include <linux/skbuff.h>
26 void ath10k_wmi_flush_tx(struct ath10k *ar)
30 lockdep_assert_held(&ar->conf_mutex);
32 if (ar->state == ATH10K_STATE_WEDGED) {
33 ath10k_warn("wmi flush skipped - device is wedged anyway\n");
37 ret = wait_event_timeout(ar->wmi.wq,
38 atomic_read(&ar->wmi.pending_tx_count) == 0,
40 if (atomic_read(&ar->wmi.pending_tx_count) == 0)
47 ath10k_warn("wmi flush failed (%d)\n", ret);
50 int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
53 ret = wait_for_completion_timeout(&ar->wmi.service_ready,
54 WMI_SERVICE_READY_TIMEOUT_HZ);
58 int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
61 ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
62 WMI_UNIFIED_READY_TIMEOUT_HZ);
66 static struct sk_buff *ath10k_wmi_alloc_skb(u32 len)
69 u32 round_len = roundup(len, 4);
71 skb = ath10k_htc_alloc_skb(WMI_SKB_HEADROOM + round_len);
75 skb_reserve(skb, WMI_SKB_HEADROOM);
76 if (!IS_ALIGNED((unsigned long)skb->data, 4))
77 ath10k_warn("Unaligned WMI skb\n");
79 skb_put(skb, round_len);
80 memset(skb->data, 0, round_len);
85 static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
89 if (atomic_sub_return(1, &ar->wmi.pending_tx_count) == 0)
94 static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
95 enum wmi_cmd_id cmd_id)
97 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
98 struct wmi_cmd_hdr *cmd_hdr;
102 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
105 cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
107 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
108 cmd_hdr->cmd_id = __cpu_to_le32(cmd);
110 if (atomic_add_return(1, &ar->wmi.pending_tx_count) >
111 WMI_MAX_PENDING_TX_COUNT) {
112 /* avoid using up memory when FW hangs */
113 atomic_dec(&ar->wmi.pending_tx_count);
117 memset(skb_cb, 0, sizeof(*skb_cb));
119 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len);
121 status = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
123 dev_kfree_skb_any(skb);
124 atomic_dec(&ar->wmi.pending_tx_count);
131 static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
133 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
134 enum wmi_scan_event_type event_type;
135 enum wmi_scan_completion_reason reason;
141 event_type = __le32_to_cpu(event->event_type);
142 reason = __le32_to_cpu(event->reason);
143 freq = __le32_to_cpu(event->channel_freq);
144 req_id = __le32_to_cpu(event->scan_req_id);
145 scan_id = __le32_to_cpu(event->scan_id);
146 vdev_id = __le32_to_cpu(event->vdev_id);
148 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENTID\n");
149 ath10k_dbg(ATH10K_DBG_WMI,
150 "scan event type %d reason %d freq %d req_id %d "
151 "scan_id %d vdev_id %d\n",
152 event_type, reason, freq, req_id, scan_id, vdev_id);
154 spin_lock_bh(&ar->data_lock);
156 switch (event_type) {
157 case WMI_SCAN_EVENT_STARTED:
158 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_STARTED\n");
159 if (ar->scan.in_progress && ar->scan.is_roc)
160 ieee80211_ready_on_channel(ar->hw);
162 complete(&ar->scan.started);
164 case WMI_SCAN_EVENT_COMPLETED:
165 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_COMPLETED\n");
167 case WMI_SCAN_REASON_COMPLETED:
168 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_COMPLETED\n");
170 case WMI_SCAN_REASON_CANCELLED:
171 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_CANCELED\n");
173 case WMI_SCAN_REASON_PREEMPTED:
174 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_PREEMPTED\n");
176 case WMI_SCAN_REASON_TIMEDOUT:
177 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_TIMEDOUT\n");
183 ar->scan_channel = NULL;
184 if (!ar->scan.in_progress) {
185 ath10k_warn("no scan requested, ignoring\n");
189 if (ar->scan.is_roc) {
190 ath10k_offchan_tx_purge(ar);
192 if (!ar->scan.aborting)
193 ieee80211_remain_on_channel_expired(ar->hw);
195 ieee80211_scan_completed(ar->hw, ar->scan.aborting);
198 del_timer(&ar->scan.timeout);
199 complete_all(&ar->scan.completed);
200 ar->scan.in_progress = false;
202 case WMI_SCAN_EVENT_BSS_CHANNEL:
203 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_BSS_CHANNEL\n");
204 ar->scan_channel = NULL;
206 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
207 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_FOREIGN_CHANNEL\n");
208 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
209 if (ar->scan.in_progress && ar->scan.is_roc &&
210 ar->scan.roc_freq == freq) {
211 complete(&ar->scan.on_channel);
214 case WMI_SCAN_EVENT_DEQUEUED:
215 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_DEQUEUED\n");
217 case WMI_SCAN_EVENT_PREEMPTED:
218 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_PREEMPTED\n");
220 case WMI_SCAN_EVENT_START_FAILED:
221 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_START_FAILED\n");
227 spin_unlock_bh(&ar->data_lock);
231 static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
233 enum ieee80211_band band;
239 case MODE_11AC_VHT20:
240 case MODE_11AC_VHT40:
241 case MODE_11AC_VHT80:
242 band = IEEE80211_BAND_5GHZ;
249 case MODE_11AC_VHT20_2G:
250 case MODE_11AC_VHT40_2G:
251 case MODE_11AC_VHT80_2G:
253 band = IEEE80211_BAND_2GHZ;
259 static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
305 if (band == IEEE80211_BAND_5GHZ) {
316 static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
318 struct wmi_mgmt_rx_event *event = (struct wmi_mgmt_rx_event *)skb->data;
319 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
320 struct ieee80211_hdr *hdr;
329 channel = __le32_to_cpu(event->hdr.channel);
330 buf_len = __le32_to_cpu(event->hdr.buf_len);
331 rx_status = __le32_to_cpu(event->hdr.status);
332 snr = __le32_to_cpu(event->hdr.snr);
333 phy_mode = __le32_to_cpu(event->hdr.phy_mode);
334 rate = __le32_to_cpu(event->hdr.rate);
336 memset(status, 0, sizeof(*status));
338 ath10k_dbg(ATH10K_DBG_MGMT,
339 "event mgmt rx status %08x\n", rx_status);
341 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
346 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
351 if (rx_status & WMI_RX_STATUS_ERR_CRC)
352 status->flag |= RX_FLAG_FAILED_FCS_CRC;
353 if (rx_status & WMI_RX_STATUS_ERR_MIC)
354 status->flag |= RX_FLAG_MMIC_ERROR;
356 status->band = phy_mode_to_band(phy_mode);
357 status->freq = ieee80211_channel_to_frequency(channel, status->band);
358 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
359 status->rate_idx = get_rate_idx(rate, status->band);
361 skb_pull(skb, sizeof(event->hdr));
363 hdr = (struct ieee80211_hdr *)skb->data;
364 fc = le16_to_cpu(hdr->frame_control);
366 if (fc & IEEE80211_FCTL_PROTECTED) {
367 status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED |
368 RX_FLAG_MMIC_STRIPPED;
369 hdr->frame_control = __cpu_to_le16(fc &
370 ~IEEE80211_FCTL_PROTECTED);
373 ath10k_dbg(ATH10K_DBG_MGMT,
374 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
376 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
378 ath10k_dbg(ATH10K_DBG_MGMT,
379 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
380 status->freq, status->band, status->signal,
384 * packets from HTC come aligned to 4byte boundaries
385 * because they can originally come in along with a trailer
387 skb_trim(skb, buf_len);
389 ieee80211_rx(ar->hw, skb);
393 static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
395 ath10k_dbg(ATH10K_DBG_WMI, "WMI_CHAN_INFO_EVENTID\n");
398 static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
400 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
403 static void ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
405 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_MESG_EVENTID\n");
408 static void ath10k_wmi_event_update_stats(struct ath10k *ar,
411 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
413 ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
415 ath10k_debug_read_target_stats(ar, ev);
418 static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
421 struct wmi_vdev_start_response_event *ev;
423 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
425 ev = (struct wmi_vdev_start_response_event *)skb->data;
427 if (WARN_ON(__le32_to_cpu(ev->status)))
430 complete(&ar->vdev_setup_done);
433 static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
436 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
437 complete(&ar->vdev_setup_done);
440 static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
443 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PEER_STA_KICKOUT_EVENTID\n");
449 * We don't report to mac80211 sleep state of connected
450 * stations. Due to this mac80211 can't fill in TIM IE
453 * I know of no way of getting nullfunc frames that contain
454 * sleep transition from connected stations - these do not
455 * seem to be sent from the target to the host. There also
456 * doesn't seem to be a dedicated event for that. So the
457 * only way left to do this would be to read tim_bitmap
460 * We could probably try using tim_bitmap from SWBA to tell
461 * mac80211 which stations are asleep and which are not. The
462 * problem here is calling mac80211 functions so many times
463 * could take too long and make us miss the time to submit
464 * the beacon to the target.
466 * So as a workaround we try to extend the TIM IE if there
467 * is unicast buffered for stations with aid > 7 and fill it
470 static void ath10k_wmi_update_tim(struct ath10k *ar,
471 struct ath10k_vif *arvif,
473 struct wmi_bcn_info *bcn_info)
475 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
476 struct ieee80211_tim_ie *tim;
480 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
481 * we must copy the bitmap upon change and reuse it later */
482 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
485 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
486 sizeof(bcn_info->tim_info.tim_bitmap));
488 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
489 __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
490 u32 v = __le32_to_cpu(t);
491 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
494 /* FW reports either length 0 or 16
495 * so we calculate this on our own */
496 arvif->u.ap.tim_len = 0;
497 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
498 if (arvif->u.ap.tim_bitmap[i])
499 arvif->u.ap.tim_len = i;
501 arvif->u.ap.tim_len++;
505 ies += ieee80211_hdrlen(hdr->frame_control);
506 ies += 12; /* fixed parameters */
508 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
509 (u8 *)skb_tail_pointer(bcn) - ies);
511 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
512 ath10k_warn("no tim ie found;\n");
516 tim = (void *)ie + 2;
518 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
520 if (pvm_len < arvif->u.ap.tim_len) {
521 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
522 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
523 void *next_ie = ie + 2 + ie_len;
525 if (skb_put(bcn, expand_size)) {
526 memmove(next_ie + expand_size, next_ie, move_size);
528 ie[1] += expand_size;
529 ie_len += expand_size;
530 pvm_len += expand_size;
532 ath10k_warn("tim expansion failed\n");
536 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
537 ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
541 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
542 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
544 ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
545 tim->dtim_count, tim->dtim_period,
546 tim->bitmap_ctrl, pvm_len);
549 static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
550 struct wmi_p2p_noa_info *noa)
552 struct ieee80211_p2p_noa_attr *noa_attr;
553 u8 ctwindow_oppps = noa->ctwindow_oppps;
554 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
555 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
556 __le16 *noa_attr_len;
558 u8 noa_descriptors = noa->num_descriptors;
562 data[0] = WLAN_EID_VENDOR_SPECIFIC;
564 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
565 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
566 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
567 data[5] = WLAN_OUI_TYPE_WFA_P2P;
570 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
571 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
572 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
574 noa_attr->index = noa->index;
575 noa_attr->oppps_ctwindow = ctwindow;
577 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
579 for (i = 0; i < noa_descriptors; i++) {
580 noa_attr->desc[i].count =
581 __le32_to_cpu(noa->descriptors[i].type_count);
582 noa_attr->desc[i].duration = noa->descriptors[i].duration;
583 noa_attr->desc[i].interval = noa->descriptors[i].interval;
584 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
587 attr_len = 2; /* index + oppps_ctwindow */
588 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
589 *noa_attr_len = __cpu_to_le16(attr_len);
592 static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
595 u8 noa_descriptors = noa->num_descriptors;
596 u8 opp_ps_info = noa->ctwindow_oppps;
597 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
600 if (!noa_descriptors && !opps_enabled)
603 len += 1 + 1 + 4; /* EID + len + OUI */
604 len += 1 + 2; /* noa attr + attr len */
605 len += 1 + 1; /* index + oppps_ctwindow */
606 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
611 static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
613 struct wmi_bcn_info *bcn_info)
615 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
616 u8 *new_data, *old_data = arvif->u.ap.noa_data;
619 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
622 ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
623 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
624 new_len = ath10k_p2p_calc_noa_ie_len(noa);
628 new_data = kmalloc(new_len, GFP_ATOMIC);
632 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
634 spin_lock_bh(&ar->data_lock);
635 arvif->u.ap.noa_data = new_data;
636 arvif->u.ap.noa_len = new_len;
637 spin_unlock_bh(&ar->data_lock);
641 if (arvif->u.ap.noa_data)
642 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
643 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
644 arvif->u.ap.noa_data,
645 arvif->u.ap.noa_len);
649 spin_lock_bh(&ar->data_lock);
650 arvif->u.ap.noa_data = NULL;
651 arvif->u.ap.noa_len = 0;
652 spin_unlock_bh(&ar->data_lock);
657 static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
659 struct wmi_host_swba_event *ev;
662 struct wmi_bcn_info *bcn_info;
663 struct ath10k_vif *arvif;
664 struct wmi_bcn_tx_arg arg;
669 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
671 ev = (struct wmi_host_swba_event *)skb->data;
672 map = __le32_to_cpu(ev->vdev_map);
674 ath10k_dbg(ATH10K_DBG_MGMT, "host swba:\n"
678 for (; map; map >>= 1, vdev_id++) {
684 if (i >= WMI_MAX_AP_VDEV) {
685 ath10k_warn("swba has corrupted vdev map\n");
689 bcn_info = &ev->bcn_info[i];
691 ath10k_dbg(ATH10K_DBG_MGMT,
696 "--tim_num_ps_pending %d\n"
697 "--tim_bitmap 0x%08x%08x%08x%08x\n",
699 __le32_to_cpu(bcn_info->tim_info.tim_len),
700 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
701 __le32_to_cpu(bcn_info->tim_info.tim_changed),
702 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
703 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
704 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
705 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
706 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
708 arvif = ath10k_get_arvif(ar, vdev_id);
710 ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
714 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
716 ath10k_warn("could not get mac80211 beacon\n");
720 ath10k_tx_h_seq_no(bcn);
721 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
722 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
724 arg.vdev_id = arvif->vdev_id;
728 arg.bcn_len = bcn->len;
730 ret = ath10k_wmi_beacon_send(ar, &arg);
732 ath10k_warn("could not send beacon (%d)\n", ret);
734 dev_kfree_skb_any(bcn);
738 static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
741 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
744 static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
746 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PHYERR_EVENTID\n");
749 static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
751 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
754 static void ath10k_wmi_event_profile_match(struct ath10k *ar,
757 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
760 static void ath10k_wmi_event_debug_print(struct ath10k *ar,
763 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_PRINT_EVENTID\n");
766 static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
768 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
771 static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
774 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
777 static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
780 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
783 static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
786 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
789 static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
792 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
795 static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
798 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
801 static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
804 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
807 static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
810 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
813 static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
816 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
819 static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
822 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
825 static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
828 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
831 static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
834 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
837 static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
840 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
843 static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
846 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
849 static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
852 struct wmi_service_ready_event *ev = (void *)skb->data;
854 if (skb->len < sizeof(*ev)) {
855 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
856 skb->len, sizeof(*ev));
860 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
861 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
862 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
863 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
864 ar->fw_version_major =
865 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
866 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
867 ar->fw_version_release =
868 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
869 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
870 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
872 ar->ath_common.regulatory.current_rd =
873 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
875 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
876 sizeof(ev->wmi_service_bitmap));
878 if (strlen(ar->hw->wiphy->fw_version) == 0) {
879 snprintf(ar->hw->wiphy->fw_version,
880 sizeof(ar->hw->wiphy->fw_version),
882 ar->fw_version_major,
883 ar->fw_version_minor,
884 ar->fw_version_release,
885 ar->fw_version_build);
888 /* FIXME: it probably should be better to support this */
889 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
890 ath10k_warn("target requested %d memory chunks; ignoring\n",
891 __le32_to_cpu(ev->num_mem_reqs));
894 ath10k_dbg(ATH10K_DBG_WMI,
895 "wmi event service ready sw_ver 0x%08x sw_ver1 0x%08x abi_ver %u phy_cap 0x%08x ht_cap 0x%08x vht_cap 0x%08x vht_supp_msc 0x%08x sys_cap_info 0x%08x mem_reqs %u\n",
896 __le32_to_cpu(ev->sw_version),
897 __le32_to_cpu(ev->sw_version_1),
898 __le32_to_cpu(ev->abi_version),
899 __le32_to_cpu(ev->phy_capability),
900 __le32_to_cpu(ev->ht_cap_info),
901 __le32_to_cpu(ev->vht_cap_info),
902 __le32_to_cpu(ev->vht_supp_mcs),
903 __le32_to_cpu(ev->sys_cap_info),
904 __le32_to_cpu(ev->num_mem_reqs));
906 complete(&ar->wmi.service_ready);
909 static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
911 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
913 if (WARN_ON(skb->len < sizeof(*ev)))
916 memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
918 ath10k_dbg(ATH10K_DBG_WMI,
919 "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d\n",
920 __le32_to_cpu(ev->sw_version),
921 __le32_to_cpu(ev->abi_version),
923 __le32_to_cpu(ev->status));
925 complete(&ar->wmi.unified_ready);
929 static void ath10k_wmi_event_process(struct ath10k *ar, struct sk_buff *skb)
931 struct wmi_cmd_hdr *cmd_hdr;
932 enum wmi_event_id id;
935 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
936 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
938 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
943 trace_ath10k_wmi_event(id, skb->data, skb->len);
946 case WMI_MGMT_RX_EVENTID:
947 ath10k_wmi_event_mgmt_rx(ar, skb);
948 /* mgmt_rx() owns the skb now! */
950 case WMI_SCAN_EVENTID:
951 ath10k_wmi_event_scan(ar, skb);
953 case WMI_CHAN_INFO_EVENTID:
954 ath10k_wmi_event_chan_info(ar, skb);
956 case WMI_ECHO_EVENTID:
957 ath10k_wmi_event_echo(ar, skb);
959 case WMI_DEBUG_MESG_EVENTID:
960 ath10k_wmi_event_debug_mesg(ar, skb);
962 case WMI_UPDATE_STATS_EVENTID:
963 ath10k_wmi_event_update_stats(ar, skb);
965 case WMI_VDEV_START_RESP_EVENTID:
966 ath10k_wmi_event_vdev_start_resp(ar, skb);
968 case WMI_VDEV_STOPPED_EVENTID:
969 ath10k_wmi_event_vdev_stopped(ar, skb);
971 case WMI_PEER_STA_KICKOUT_EVENTID:
972 ath10k_wmi_event_peer_sta_kickout(ar, skb);
974 case WMI_HOST_SWBA_EVENTID:
975 ath10k_wmi_event_host_swba(ar, skb);
977 case WMI_TBTTOFFSET_UPDATE_EVENTID:
978 ath10k_wmi_event_tbttoffset_update(ar, skb);
980 case WMI_PHYERR_EVENTID:
981 ath10k_wmi_event_phyerr(ar, skb);
983 case WMI_ROAM_EVENTID:
984 ath10k_wmi_event_roam(ar, skb);
986 case WMI_PROFILE_MATCH:
987 ath10k_wmi_event_profile_match(ar, skb);
989 case WMI_DEBUG_PRINT_EVENTID:
990 ath10k_wmi_event_debug_print(ar, skb);
992 case WMI_PDEV_QVIT_EVENTID:
993 ath10k_wmi_event_pdev_qvit(ar, skb);
995 case WMI_WLAN_PROFILE_DATA_EVENTID:
996 ath10k_wmi_event_wlan_profile_data(ar, skb);
998 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
999 ath10k_wmi_event_rtt_measurement_report(ar, skb);
1001 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
1002 ath10k_wmi_event_tsf_measurement_report(ar, skb);
1004 case WMI_RTT_ERROR_REPORT_EVENTID:
1005 ath10k_wmi_event_rtt_error_report(ar, skb);
1007 case WMI_WOW_WAKEUP_HOST_EVENTID:
1008 ath10k_wmi_event_wow_wakeup_host(ar, skb);
1010 case WMI_DCS_INTERFERENCE_EVENTID:
1011 ath10k_wmi_event_dcs_interference(ar, skb);
1013 case WMI_PDEV_TPC_CONFIG_EVENTID:
1014 ath10k_wmi_event_pdev_tpc_config(ar, skb);
1016 case WMI_PDEV_FTM_INTG_EVENTID:
1017 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
1019 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
1020 ath10k_wmi_event_gtk_offload_status(ar, skb);
1022 case WMI_GTK_REKEY_FAIL_EVENTID:
1023 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
1025 case WMI_TX_DELBA_COMPLETE_EVENTID:
1026 ath10k_wmi_event_delba_complete(ar, skb);
1028 case WMI_TX_ADDBA_COMPLETE_EVENTID:
1029 ath10k_wmi_event_addba_complete(ar, skb);
1031 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
1032 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
1034 case WMI_SERVICE_READY_EVENTID:
1035 ath10k_wmi_service_ready_event_rx(ar, skb);
1037 case WMI_READY_EVENTID:
1038 ath10k_wmi_ready_event_rx(ar, skb);
1041 ath10k_warn("Unknown eventid: %d\n", id);
1048 static void ath10k_wmi_event_work(struct work_struct *work)
1050 struct ath10k *ar = container_of(work, struct ath10k,
1051 wmi.wmi_event_work);
1052 struct sk_buff *skb;
1055 skb = skb_dequeue(&ar->wmi.wmi_event_list);
1059 ath10k_wmi_event_process(ar, skb);
1063 static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
1065 struct wmi_cmd_hdr *cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
1066 enum wmi_event_id event_id;
1068 event_id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
1070 /* some events require to be handled ASAP
1071 * thus can't be defered to a worker thread */
1073 case WMI_HOST_SWBA_EVENTID:
1074 case WMI_MGMT_RX_EVENTID:
1075 ath10k_wmi_event_process(ar, skb);
1081 skb_queue_tail(&ar->wmi.wmi_event_list, skb);
1082 queue_work(ar->workqueue, &ar->wmi.wmi_event_work);
1085 /* WMI Initialization functions */
1086 int ath10k_wmi_attach(struct ath10k *ar)
1088 init_completion(&ar->wmi.service_ready);
1089 init_completion(&ar->wmi.unified_ready);
1090 init_waitqueue_head(&ar->wmi.wq);
1092 skb_queue_head_init(&ar->wmi.wmi_event_list);
1093 INIT_WORK(&ar->wmi.wmi_event_work, ath10k_wmi_event_work);
1098 void ath10k_wmi_detach(struct ath10k *ar)
1100 /* HTC should've drained the packets already */
1101 if (WARN_ON(atomic_read(&ar->wmi.pending_tx_count) > 0))
1102 ath10k_warn("there are still pending packets\n");
1104 cancel_work_sync(&ar->wmi.wmi_event_work);
1105 skb_queue_purge(&ar->wmi.wmi_event_list);
1108 int ath10k_wmi_connect_htc_service(struct ath10k *ar)
1111 struct ath10k_htc_svc_conn_req conn_req;
1112 struct ath10k_htc_svc_conn_resp conn_resp;
1114 memset(&conn_req, 0, sizeof(conn_req));
1115 memset(&conn_resp, 0, sizeof(conn_resp));
1117 /* these fields are the same for all service endpoints */
1118 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
1119 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
1121 /* connect to control service */
1122 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
1124 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
1126 ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
1131 ar->wmi.eid = conn_resp.eid;
1135 int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
1136 u16 rd5g, u16 ctl2g, u16 ctl5g)
1138 struct wmi_pdev_set_regdomain_cmd *cmd;
1139 struct sk_buff *skb;
1141 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1145 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1146 cmd->reg_domain = __cpu_to_le32(rd);
1147 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
1148 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
1149 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
1150 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
1152 ath10k_dbg(ATH10K_DBG_WMI,
1153 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
1154 rd, rd2g, rd5g, ctl2g, ctl5g);
1156 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1159 int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
1160 const struct wmi_channel_arg *arg)
1162 struct wmi_set_channel_cmd *cmd;
1163 struct sk_buff *skb;
1168 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1172 cmd = (struct wmi_set_channel_cmd *)skb->data;
1173 cmd->chan.mhz = __cpu_to_le32(arg->freq);
1174 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
1175 cmd->chan.mode = arg->mode;
1176 cmd->chan.min_power = arg->min_power;
1177 cmd->chan.max_power = arg->max_power;
1178 cmd->chan.reg_power = arg->max_reg_power;
1179 cmd->chan.reg_classid = arg->reg_class_id;
1180 cmd->chan.antenna_max = arg->max_antenna_gain;
1182 ath10k_dbg(ATH10K_DBG_WMI,
1183 "wmi set channel mode %d freq %d\n",
1184 arg->mode, arg->freq);
1186 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_CHANNEL_CMDID);
1189 int ath10k_wmi_pdev_suspend_target(struct ath10k *ar)
1191 struct wmi_pdev_suspend_cmd *cmd;
1192 struct sk_buff *skb;
1194 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1198 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1199 cmd->suspend_opt = WMI_PDEV_SUSPEND;
1201 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SUSPEND_CMDID);
1204 int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
1206 struct sk_buff *skb;
1208 skb = ath10k_wmi_alloc_skb(0);
1212 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_RESUME_CMDID);
1215 int ath10k_wmi_pdev_set_param(struct ath10k *ar, enum wmi_pdev_param id,
1218 struct wmi_pdev_set_param_cmd *cmd;
1219 struct sk_buff *skb;
1221 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1225 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1226 cmd->param_id = __cpu_to_le32(id);
1227 cmd->param_value = __cpu_to_le32(value);
1229 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
1231 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_PARAM_CMDID);
1234 int ath10k_wmi_cmd_init(struct ath10k *ar)
1236 struct wmi_init_cmd *cmd;
1237 struct sk_buff *buf;
1238 struct wmi_resource_config config = {};
1241 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
1242 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
1243 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
1245 config.num_offload_reorder_bufs =
1246 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
1248 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
1249 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
1250 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
1251 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
1252 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
1253 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1254 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1255 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1256 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
1257 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
1259 config.scan_max_pending_reqs =
1260 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
1262 config.bmiss_offload_max_vdev =
1263 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
1265 config.roam_offload_max_vdev =
1266 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
1268 config.roam_offload_max_ap_profiles =
1269 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
1271 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
1272 config.num_mcast_table_elems =
1273 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
1275 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
1276 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
1277 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
1278 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
1279 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
1281 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
1282 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
1284 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
1286 config.gtk_offload_max_vdev =
1287 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
1289 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
1290 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
1292 buf = ath10k_wmi_alloc_skb(sizeof(*cmd));
1296 cmd = (struct wmi_init_cmd *)buf->data;
1297 cmd->num_host_mem_chunks = 0;
1298 memcpy(&cmd->resource_config, &config, sizeof(config));
1300 ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
1301 return ath10k_wmi_cmd_send(ar, buf, WMI_INIT_CMDID);
1304 static int ath10k_wmi_start_scan_calc_len(const struct wmi_start_scan_arg *arg)
1308 len = sizeof(struct wmi_start_scan_cmd);
1313 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
1316 len += sizeof(struct wmi_ie_data);
1317 len += roundup(arg->ie_len, 4);
1320 if (arg->n_channels) {
1323 if (arg->n_channels > ARRAY_SIZE(arg->channels))
1326 len += sizeof(struct wmi_chan_list);
1327 len += sizeof(__le32) * arg->n_channels;
1333 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
1336 len += sizeof(struct wmi_ssid_list);
1337 len += sizeof(struct wmi_ssid) * arg->n_ssids;
1340 if (arg->n_bssids) {
1343 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
1346 len += sizeof(struct wmi_bssid_list);
1347 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
1353 int ath10k_wmi_start_scan(struct ath10k *ar,
1354 const struct wmi_start_scan_arg *arg)
1356 struct wmi_start_scan_cmd *cmd;
1357 struct sk_buff *skb;
1358 struct wmi_ie_data *ie;
1359 struct wmi_chan_list *channels;
1360 struct wmi_ssid_list *ssids;
1361 struct wmi_bssid_list *bssids;
1368 len = ath10k_wmi_start_scan_calc_len(arg);
1370 return len; /* len contains error code here */
1372 skb = ath10k_wmi_alloc_skb(len);
1376 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
1377 scan_id |= arg->scan_id;
1379 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1380 scan_req_id |= arg->scan_req_id;
1382 cmd = (struct wmi_start_scan_cmd *)skb->data;
1383 cmd->scan_id = __cpu_to_le32(scan_id);
1384 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
1385 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1386 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
1387 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
1388 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
1389 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
1390 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
1391 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
1392 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
1393 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
1394 cmd->idle_time = __cpu_to_le32(arg->idle_time);
1395 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
1396 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
1397 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
1399 /* TLV list starts after fields included in the struct */
1402 if (arg->n_channels) {
1403 channels = (void *)skb->data + off;
1404 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
1405 channels->num_chan = __cpu_to_le32(arg->n_channels);
1407 for (i = 0; i < arg->n_channels; i++)
1408 channels->channel_list[i] =
1409 __cpu_to_le32(arg->channels[i]);
1411 off += sizeof(*channels);
1412 off += sizeof(__le32) * arg->n_channels;
1416 ssids = (void *)skb->data + off;
1417 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
1418 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
1420 for (i = 0; i < arg->n_ssids; i++) {
1421 ssids->ssids[i].ssid_len =
1422 __cpu_to_le32(arg->ssids[i].len);
1423 memcpy(&ssids->ssids[i].ssid,
1428 off += sizeof(*ssids);
1429 off += sizeof(struct wmi_ssid) * arg->n_ssids;
1432 if (arg->n_bssids) {
1433 bssids = (void *)skb->data + off;
1434 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
1435 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
1437 for (i = 0; i < arg->n_bssids; i++)
1438 memcpy(&bssids->bssid_list[i],
1439 arg->bssids[i].bssid,
1442 off += sizeof(*bssids);
1443 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
1447 ie = (void *)skb->data + off;
1448 ie->tag = __cpu_to_le32(WMI_IE_TAG);
1449 ie->ie_len = __cpu_to_le32(arg->ie_len);
1450 memcpy(ie->ie_data, arg->ie, arg->ie_len);
1453 off += roundup(arg->ie_len, 4);
1456 if (off != skb->len) {
1461 ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
1462 return ath10k_wmi_cmd_send(ar, skb, WMI_START_SCAN_CMDID);
1465 void ath10k_wmi_start_scan_init(struct ath10k *ar,
1466 struct wmi_start_scan_arg *arg)
1468 /* setup commonly used values */
1469 arg->scan_req_id = 1;
1470 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
1471 arg->dwell_time_active = 50;
1472 arg->dwell_time_passive = 150;
1473 arg->min_rest_time = 50;
1474 arg->max_rest_time = 500;
1475 arg->repeat_probe_time = 0;
1476 arg->probe_spacing_time = 0;
1478 arg->max_scan_time = 5000;
1479 arg->probe_delay = 5;
1480 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
1481 | WMI_SCAN_EVENT_COMPLETED
1482 | WMI_SCAN_EVENT_BSS_CHANNEL
1483 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
1484 | WMI_SCAN_EVENT_DEQUEUED;
1485 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
1486 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
1488 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
1491 int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
1493 struct wmi_stop_scan_cmd *cmd;
1494 struct sk_buff *skb;
1498 if (arg->req_id > 0xFFF)
1500 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
1503 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1507 scan_id = arg->u.scan_id;
1508 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
1510 req_id = arg->req_id;
1511 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1513 cmd = (struct wmi_stop_scan_cmd *)skb->data;
1514 cmd->req_type = __cpu_to_le32(arg->req_type);
1515 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
1516 cmd->scan_id = __cpu_to_le32(scan_id);
1517 cmd->scan_req_id = __cpu_to_le32(req_id);
1519 ath10k_dbg(ATH10K_DBG_WMI,
1520 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
1521 arg->req_id, arg->req_type, arg->u.scan_id);
1522 return ath10k_wmi_cmd_send(ar, skb, WMI_STOP_SCAN_CMDID);
1525 int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
1526 enum wmi_vdev_type type,
1527 enum wmi_vdev_subtype subtype,
1528 const u8 macaddr[ETH_ALEN])
1530 struct wmi_vdev_create_cmd *cmd;
1531 struct sk_buff *skb;
1533 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1537 cmd = (struct wmi_vdev_create_cmd *)skb->data;
1538 cmd->vdev_id = __cpu_to_le32(vdev_id);
1539 cmd->vdev_type = __cpu_to_le32(type);
1540 cmd->vdev_subtype = __cpu_to_le32(subtype);
1541 memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
1543 ath10k_dbg(ATH10K_DBG_WMI,
1544 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
1545 vdev_id, type, subtype, macaddr);
1547 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_CREATE_CMDID);
1550 int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
1552 struct wmi_vdev_delete_cmd *cmd;
1553 struct sk_buff *skb;
1555 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1559 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
1560 cmd->vdev_id = __cpu_to_le32(vdev_id);
1562 ath10k_dbg(ATH10K_DBG_WMI,
1563 "WMI vdev delete id %d\n", vdev_id);
1565 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_DELETE_CMDID);
1568 static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
1569 const struct wmi_vdev_start_request_arg *arg,
1570 enum wmi_cmd_id cmd_id)
1572 struct wmi_vdev_start_request_cmd *cmd;
1573 struct sk_buff *skb;
1574 const char *cmdname;
1577 if (cmd_id != WMI_VDEV_START_REQUEST_CMDID &&
1578 cmd_id != WMI_VDEV_RESTART_REQUEST_CMDID)
1580 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
1582 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
1584 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
1587 if (cmd_id == WMI_VDEV_START_REQUEST_CMDID)
1589 else if (cmd_id == WMI_VDEV_RESTART_REQUEST_CMDID)
1590 cmdname = "restart";
1592 return -EINVAL; /* should not happen, we already check cmd_id */
1594 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1598 if (arg->hidden_ssid)
1599 flags |= WMI_VDEV_START_HIDDEN_SSID;
1600 if (arg->pmf_enabled)
1601 flags |= WMI_VDEV_START_PMF_ENABLED;
1603 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
1604 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1605 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
1606 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
1607 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
1608 cmd->flags = __cpu_to_le32(flags);
1609 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
1610 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
1613 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
1614 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
1617 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
1619 cmd->chan.band_center_freq1 =
1620 __cpu_to_le32(arg->channel.band_center_freq1);
1622 cmd->chan.mode = arg->channel.mode;
1623 cmd->chan.min_power = arg->channel.min_power;
1624 cmd->chan.max_power = arg->channel.max_power;
1625 cmd->chan.reg_power = arg->channel.max_reg_power;
1626 cmd->chan.reg_classid = arg->channel.reg_class_id;
1627 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
1629 ath10k_dbg(ATH10K_DBG_WMI,
1630 "wmi vdev %s id 0x%x freq %d, mode %d, ch_flags: 0x%0X,"
1631 "max_power: %d\n", cmdname, arg->vdev_id, arg->channel.freq,
1632 arg->channel.mode, flags, arg->channel.max_power);
1634 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
1637 int ath10k_wmi_vdev_start(struct ath10k *ar,
1638 const struct wmi_vdev_start_request_arg *arg)
1640 return ath10k_wmi_vdev_start_restart(ar, arg,
1641 WMI_VDEV_START_REQUEST_CMDID);
1644 int ath10k_wmi_vdev_restart(struct ath10k *ar,
1645 const struct wmi_vdev_start_request_arg *arg)
1647 return ath10k_wmi_vdev_start_restart(ar, arg,
1648 WMI_VDEV_RESTART_REQUEST_CMDID);
1651 int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
1653 struct wmi_vdev_stop_cmd *cmd;
1654 struct sk_buff *skb;
1656 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1660 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
1661 cmd->vdev_id = __cpu_to_le32(vdev_id);
1663 ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
1665 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_STOP_CMDID);
1668 int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
1670 struct wmi_vdev_up_cmd *cmd;
1671 struct sk_buff *skb;
1673 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1677 cmd = (struct wmi_vdev_up_cmd *)skb->data;
1678 cmd->vdev_id = __cpu_to_le32(vdev_id);
1679 cmd->vdev_assoc_id = __cpu_to_le32(aid);
1680 memcpy(&cmd->vdev_bssid.addr, bssid, 6);
1682 ath10k_dbg(ATH10K_DBG_WMI,
1683 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
1684 vdev_id, aid, bssid);
1686 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_UP_CMDID);
1689 int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
1691 struct wmi_vdev_down_cmd *cmd;
1692 struct sk_buff *skb;
1694 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1698 cmd = (struct wmi_vdev_down_cmd *)skb->data;
1699 cmd->vdev_id = __cpu_to_le32(vdev_id);
1701 ath10k_dbg(ATH10K_DBG_WMI,
1702 "wmi mgmt vdev down id 0x%x\n", vdev_id);
1704 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_DOWN_CMDID);
1707 int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
1708 enum wmi_vdev_param param_id, u32 param_value)
1710 struct wmi_vdev_set_param_cmd *cmd;
1711 struct sk_buff *skb;
1713 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1717 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1718 cmd->vdev_id = __cpu_to_le32(vdev_id);
1719 cmd->param_id = __cpu_to_le32(param_id);
1720 cmd->param_value = __cpu_to_le32(param_value);
1722 ath10k_dbg(ATH10K_DBG_WMI,
1723 "wmi vdev id 0x%x set param %d value %d\n",
1724 vdev_id, param_id, param_value);
1726 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_SET_PARAM_CMDID);
1729 int ath10k_wmi_vdev_install_key(struct ath10k *ar,
1730 const struct wmi_vdev_install_key_arg *arg)
1732 struct wmi_vdev_install_key_cmd *cmd;
1733 struct sk_buff *skb;
1735 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
1737 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
1740 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
1744 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1745 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1746 cmd->key_idx = __cpu_to_le32(arg->key_idx);
1747 cmd->key_flags = __cpu_to_le32(arg->key_flags);
1748 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
1749 cmd->key_len = __cpu_to_le32(arg->key_len);
1750 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
1751 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
1754 memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
1756 memcpy(cmd->key_data, arg->key_data, arg->key_len);
1758 ath10k_dbg(ATH10K_DBG_WMI,
1759 "wmi vdev install key idx %d cipher %d len %d\n",
1760 arg->key_idx, arg->key_cipher, arg->key_len);
1761 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1764 int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
1765 const u8 peer_addr[ETH_ALEN])
1767 struct wmi_peer_create_cmd *cmd;
1768 struct sk_buff *skb;
1770 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1774 cmd = (struct wmi_peer_create_cmd *)skb->data;
1775 cmd->vdev_id = __cpu_to_le32(vdev_id);
1776 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1778 ath10k_dbg(ATH10K_DBG_WMI,
1779 "wmi peer create vdev_id %d peer_addr %pM\n",
1780 vdev_id, peer_addr);
1781 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_CREATE_CMDID);
1784 int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
1785 const u8 peer_addr[ETH_ALEN])
1787 struct wmi_peer_delete_cmd *cmd;
1788 struct sk_buff *skb;
1790 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1794 cmd = (struct wmi_peer_delete_cmd *)skb->data;
1795 cmd->vdev_id = __cpu_to_le32(vdev_id);
1796 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1798 ath10k_dbg(ATH10K_DBG_WMI,
1799 "wmi peer delete vdev_id %d peer_addr %pM\n",
1800 vdev_id, peer_addr);
1801 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_DELETE_CMDID);
1804 int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
1805 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
1807 struct wmi_peer_flush_tids_cmd *cmd;
1808 struct sk_buff *skb;
1810 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1814 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1815 cmd->vdev_id = __cpu_to_le32(vdev_id);
1816 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
1817 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1819 ath10k_dbg(ATH10K_DBG_WMI,
1820 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
1821 vdev_id, peer_addr, tid_bitmap);
1822 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1825 int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
1826 const u8 *peer_addr, enum wmi_peer_param param_id,
1829 struct wmi_peer_set_param_cmd *cmd;
1830 struct sk_buff *skb;
1832 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1836 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1837 cmd->vdev_id = __cpu_to_le32(vdev_id);
1838 cmd->param_id = __cpu_to_le32(param_id);
1839 cmd->param_value = __cpu_to_le32(param_value);
1840 memcpy(&cmd->peer_macaddr.addr, peer_addr, 6);
1842 ath10k_dbg(ATH10K_DBG_WMI,
1843 "wmi vdev %d peer 0x%pM set param %d value %d\n",
1844 vdev_id, peer_addr, param_id, param_value);
1846 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_SET_PARAM_CMDID);
1849 int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
1850 enum wmi_sta_ps_mode psmode)
1852 struct wmi_sta_powersave_mode_cmd *cmd;
1853 struct sk_buff *skb;
1855 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1859 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
1860 cmd->vdev_id = __cpu_to_le32(vdev_id);
1861 cmd->sta_ps_mode = __cpu_to_le32(psmode);
1863 ath10k_dbg(ATH10K_DBG_WMI,
1864 "wmi set powersave id 0x%x mode %d\n",
1867 return ath10k_wmi_cmd_send(ar, skb, WMI_STA_POWERSAVE_MODE_CMDID);
1870 int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
1871 enum wmi_sta_powersave_param param_id,
1874 struct wmi_sta_powersave_param_cmd *cmd;
1875 struct sk_buff *skb;
1877 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1881 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1882 cmd->vdev_id = __cpu_to_le32(vdev_id);
1883 cmd->param_id = __cpu_to_le32(param_id);
1884 cmd->param_value = __cpu_to_le32(value);
1886 ath10k_dbg(ATH10K_DBG_WMI,
1887 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
1888 vdev_id, param_id, value);
1889 return ath10k_wmi_cmd_send(ar, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1892 int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
1893 enum wmi_ap_ps_peer_param param_id, u32 value)
1895 struct wmi_ap_ps_peer_cmd *cmd;
1896 struct sk_buff *skb;
1901 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1905 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1906 cmd->vdev_id = __cpu_to_le32(vdev_id);
1907 cmd->param_id = __cpu_to_le32(param_id);
1908 cmd->param_value = __cpu_to_le32(value);
1909 memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
1911 ath10k_dbg(ATH10K_DBG_WMI,
1912 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
1913 vdev_id, param_id, value, mac);
1915 return ath10k_wmi_cmd_send(ar, skb, WMI_AP_PS_PEER_PARAM_CMDID);
1918 int ath10k_wmi_scan_chan_list(struct ath10k *ar,
1919 const struct wmi_scan_chan_list_arg *arg)
1921 struct wmi_scan_chan_list_cmd *cmd;
1922 struct sk_buff *skb;
1923 struct wmi_channel_arg *ch;
1924 struct wmi_channel *ci;
1928 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
1930 skb = ath10k_wmi_alloc_skb(len);
1934 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
1935 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
1937 for (i = 0; i < arg->n_channels; i++) {
1940 ch = &arg->channels[i];
1941 ci = &cmd->chan_info[i];
1944 flags |= WMI_CHAN_FLAG_PASSIVE;
1946 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
1948 flags |= WMI_CHAN_FLAG_ALLOW_HT;
1950 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
1952 flags |= WMI_CHAN_FLAG_HT40_PLUS;
1954 ci->mhz = __cpu_to_le32(ch->freq);
1955 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
1956 ci->band_center_freq2 = 0;
1957 ci->min_power = ch->min_power;
1958 ci->max_power = ch->max_power;
1959 ci->reg_power = ch->max_reg_power;
1960 ci->antenna_max = ch->max_antenna_gain;
1961 ci->antenna_max = 0;
1963 /* mode & flags share storage */
1964 ci->mode = ch->mode;
1965 ci->flags |= __cpu_to_le32(flags);
1968 return ath10k_wmi_cmd_send(ar, skb, WMI_SCAN_CHAN_LIST_CMDID);
1971 int ath10k_wmi_peer_assoc(struct ath10k *ar,
1972 const struct wmi_peer_assoc_complete_arg *arg)
1974 struct wmi_peer_assoc_complete_cmd *cmd;
1975 struct sk_buff *skb;
1977 if (arg->peer_mpdu_density > 16)
1979 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
1981 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
1984 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1988 cmd = (struct wmi_peer_assoc_complete_cmd *)skb->data;
1989 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1990 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
1991 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
1992 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
1993 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
1994 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
1995 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
1996 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
1997 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
1998 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
1999 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
2000 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
2001 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
2003 memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
2005 cmd->peer_legacy_rates.num_rates =
2006 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
2007 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
2008 arg->peer_legacy_rates.num_rates);
2010 cmd->peer_ht_rates.num_rates =
2011 __cpu_to_le32(arg->peer_ht_rates.num_rates);
2012 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
2013 arg->peer_ht_rates.num_rates);
2015 cmd->peer_vht_rates.rx_max_rate =
2016 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
2017 cmd->peer_vht_rates.rx_mcs_set =
2018 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
2019 cmd->peer_vht_rates.tx_max_rate =
2020 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
2021 cmd->peer_vht_rates.tx_mcs_set =
2022 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
2024 ath10k_dbg(ATH10K_DBG_WMI,
2025 "wmi peer assoc vdev %d addr %pM\n",
2026 arg->vdev_id, arg->addr);
2027 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_ASSOC_CMDID);
2030 int ath10k_wmi_beacon_send(struct ath10k *ar, const struct wmi_bcn_tx_arg *arg)
2032 struct wmi_bcn_tx_cmd *cmd;
2033 struct sk_buff *skb;
2035 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->bcn_len);
2039 cmd = (struct wmi_bcn_tx_cmd *)skb->data;
2040 cmd->hdr.vdev_id = __cpu_to_le32(arg->vdev_id);
2041 cmd->hdr.tx_rate = __cpu_to_le32(arg->tx_rate);
2042 cmd->hdr.tx_power = __cpu_to_le32(arg->tx_power);
2043 cmd->hdr.bcn_len = __cpu_to_le32(arg->bcn_len);
2044 memcpy(cmd->bcn, arg->bcn, arg->bcn_len);
2046 return ath10k_wmi_cmd_send(ar, skb, WMI_BCN_TX_CMDID);
2049 static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
2050 const struct wmi_wmm_params_arg *arg)
2052 params->cwmin = __cpu_to_le32(arg->cwmin);
2053 params->cwmax = __cpu_to_le32(arg->cwmax);
2054 params->aifs = __cpu_to_le32(arg->aifs);
2055 params->txop = __cpu_to_le32(arg->txop);
2056 params->acm = __cpu_to_le32(arg->acm);
2057 params->no_ack = __cpu_to_le32(arg->no_ack);
2060 int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
2061 const struct wmi_pdev_set_wmm_params_arg *arg)
2063 struct wmi_pdev_set_wmm_params *cmd;
2064 struct sk_buff *skb;
2066 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2070 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
2071 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
2072 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
2073 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
2074 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
2076 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
2077 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_WMM_PARAMS_CMDID);
2080 int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
2082 struct wmi_request_stats_cmd *cmd;
2083 struct sk_buff *skb;
2085 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2089 cmd = (struct wmi_request_stats_cmd *)skb->data;
2090 cmd->stats_id = __cpu_to_le32(stats_id);
2092 ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
2093 return ath10k_wmi_cmd_send(ar, skb, WMI_REQUEST_STATS_CMDID);