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 */
114 atomic_dec(&ar->wmi.pending_tx_count);
118 memset(skb_cb, 0, sizeof(*skb_cb));
120 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len);
122 status = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
124 dev_kfree_skb_any(skb);
125 atomic_dec(&ar->wmi.pending_tx_count);
132 static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
134 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
135 enum wmi_scan_event_type event_type;
136 enum wmi_scan_completion_reason reason;
142 event_type = __le32_to_cpu(event->event_type);
143 reason = __le32_to_cpu(event->reason);
144 freq = __le32_to_cpu(event->channel_freq);
145 req_id = __le32_to_cpu(event->scan_req_id);
146 scan_id = __le32_to_cpu(event->scan_id);
147 vdev_id = __le32_to_cpu(event->vdev_id);
149 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENTID\n");
150 ath10k_dbg(ATH10K_DBG_WMI,
151 "scan event type %d reason %d freq %d req_id %d "
152 "scan_id %d vdev_id %d\n",
153 event_type, reason, freq, req_id, scan_id, vdev_id);
155 spin_lock_bh(&ar->data_lock);
157 switch (event_type) {
158 case WMI_SCAN_EVENT_STARTED:
159 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_STARTED\n");
160 if (ar->scan.in_progress && ar->scan.is_roc)
161 ieee80211_ready_on_channel(ar->hw);
163 complete(&ar->scan.started);
165 case WMI_SCAN_EVENT_COMPLETED:
166 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_COMPLETED\n");
168 case WMI_SCAN_REASON_COMPLETED:
169 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_COMPLETED\n");
171 case WMI_SCAN_REASON_CANCELLED:
172 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_CANCELED\n");
174 case WMI_SCAN_REASON_PREEMPTED:
175 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_PREEMPTED\n");
177 case WMI_SCAN_REASON_TIMEDOUT:
178 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_TIMEDOUT\n");
184 ar->scan_channel = NULL;
185 if (!ar->scan.in_progress) {
186 ath10k_warn("no scan requested, ignoring\n");
190 if (ar->scan.is_roc) {
191 ath10k_offchan_tx_purge(ar);
193 if (!ar->scan.aborting)
194 ieee80211_remain_on_channel_expired(ar->hw);
196 ieee80211_scan_completed(ar->hw, ar->scan.aborting);
199 del_timer(&ar->scan.timeout);
200 complete_all(&ar->scan.completed);
201 ar->scan.in_progress = false;
203 case WMI_SCAN_EVENT_BSS_CHANNEL:
204 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_BSS_CHANNEL\n");
205 ar->scan_channel = NULL;
207 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
208 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_FOREIGN_CHANNEL\n");
209 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
210 if (ar->scan.in_progress && ar->scan.is_roc &&
211 ar->scan.roc_freq == freq) {
212 complete(&ar->scan.on_channel);
215 case WMI_SCAN_EVENT_DEQUEUED:
216 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_DEQUEUED\n");
218 case WMI_SCAN_EVENT_PREEMPTED:
219 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_PREEMPTED\n");
221 case WMI_SCAN_EVENT_START_FAILED:
222 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_START_FAILED\n");
228 spin_unlock_bh(&ar->data_lock);
232 static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
234 enum ieee80211_band band;
240 case MODE_11AC_VHT20:
241 case MODE_11AC_VHT40:
242 case MODE_11AC_VHT80:
243 band = IEEE80211_BAND_5GHZ;
250 case MODE_11AC_VHT20_2G:
251 case MODE_11AC_VHT40_2G:
252 case MODE_11AC_VHT80_2G:
254 band = IEEE80211_BAND_2GHZ;
260 static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
306 if (band == IEEE80211_BAND_5GHZ) {
317 static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
319 struct wmi_mgmt_rx_event_v1 *ev_v1;
320 struct wmi_mgmt_rx_event_v2 *ev_v2;
321 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
322 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
323 struct ieee80211_hdr *hdr;
333 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
334 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
335 ev_hdr = &ev_v2->hdr.v1;
336 pull_len = sizeof(*ev_v2);
338 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
339 ev_hdr = &ev_v1->hdr;
340 pull_len = sizeof(*ev_v1);
343 channel = __le32_to_cpu(ev_hdr->channel);
344 buf_len = __le32_to_cpu(ev_hdr->buf_len);
345 rx_status = __le32_to_cpu(ev_hdr->status);
346 snr = __le32_to_cpu(ev_hdr->snr);
347 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
348 rate = __le32_to_cpu(ev_hdr->rate);
350 memset(status, 0, sizeof(*status));
352 ath10k_dbg(ATH10K_DBG_MGMT,
353 "event mgmt rx status %08x\n", rx_status);
355 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
360 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
365 if (rx_status & WMI_RX_STATUS_ERR_CRC)
366 status->flag |= RX_FLAG_FAILED_FCS_CRC;
367 if (rx_status & WMI_RX_STATUS_ERR_MIC)
368 status->flag |= RX_FLAG_MMIC_ERROR;
370 status->band = phy_mode_to_band(phy_mode);
371 status->freq = ieee80211_channel_to_frequency(channel, status->band);
372 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
373 status->rate_idx = get_rate_idx(rate, status->band);
375 skb_pull(skb, pull_len);
377 hdr = (struct ieee80211_hdr *)skb->data;
378 fc = le16_to_cpu(hdr->frame_control);
380 if (fc & IEEE80211_FCTL_PROTECTED) {
381 status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED |
382 RX_FLAG_MMIC_STRIPPED;
383 hdr->frame_control = __cpu_to_le16(fc &
384 ~IEEE80211_FCTL_PROTECTED);
387 ath10k_dbg(ATH10K_DBG_MGMT,
388 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
390 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
392 ath10k_dbg(ATH10K_DBG_MGMT,
393 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
394 status->freq, status->band, status->signal,
398 * packets from HTC come aligned to 4byte boundaries
399 * because they can originally come in along with a trailer
401 skb_trim(skb, buf_len);
403 ieee80211_rx(ar->hw, skb);
407 static int freq_to_idx(struct ath10k *ar, int freq)
409 struct ieee80211_supported_band *sband;
410 int band, ch, idx = 0;
412 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
413 sband = ar->hw->wiphy->bands[band];
417 for (ch = 0; ch < sband->n_channels; ch++, idx++)
418 if (sband->channels[ch].center_freq == freq)
426 static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
428 struct wmi_chan_info_event *ev;
429 struct survey_info *survey;
430 u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
433 ev = (struct wmi_chan_info_event *)skb->data;
435 err_code = __le32_to_cpu(ev->err_code);
436 freq = __le32_to_cpu(ev->freq);
437 cmd_flags = __le32_to_cpu(ev->cmd_flags);
438 noise_floor = __le32_to_cpu(ev->noise_floor);
439 rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
440 cycle_count = __le32_to_cpu(ev->cycle_count);
442 ath10k_dbg(ATH10K_DBG_WMI,
443 "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
444 err_code, freq, cmd_flags, noise_floor, rx_clear_count,
447 spin_lock_bh(&ar->data_lock);
449 if (!ar->scan.in_progress) {
450 ath10k_warn("chan info event without a scan request?\n");
454 idx = freq_to_idx(ar, freq);
455 if (idx >= ARRAY_SIZE(ar->survey)) {
456 ath10k_warn("chan info: invalid frequency %d (idx %d out of bounds)\n",
461 if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
462 /* During scanning chan info is reported twice for each
463 * visited channel. The reported cycle count is global
464 * and per-channel cycle count must be calculated */
466 cycle_count -= ar->survey_last_cycle_count;
467 rx_clear_count -= ar->survey_last_rx_clear_count;
469 survey = &ar->survey[idx];
470 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
471 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
472 survey->noise = noise_floor;
473 survey->filled = SURVEY_INFO_CHANNEL_TIME |
474 SURVEY_INFO_CHANNEL_TIME_RX |
475 SURVEY_INFO_NOISE_DBM;
478 ar->survey_last_rx_clear_count = rx_clear_count;
479 ar->survey_last_cycle_count = cycle_count;
482 spin_unlock_bh(&ar->data_lock);
485 static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
487 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
490 static void ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
492 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_MESG_EVENTID\n");
495 static void ath10k_wmi_event_update_stats(struct ath10k *ar,
498 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
500 ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
502 ath10k_debug_read_target_stats(ar, ev);
505 static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
508 struct wmi_vdev_start_response_event *ev;
510 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
512 ev = (struct wmi_vdev_start_response_event *)skb->data;
514 if (WARN_ON(__le32_to_cpu(ev->status)))
517 complete(&ar->vdev_setup_done);
520 static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
523 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
524 complete(&ar->vdev_setup_done);
527 static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
530 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PEER_STA_KICKOUT_EVENTID\n");
536 * We don't report to mac80211 sleep state of connected
537 * stations. Due to this mac80211 can't fill in TIM IE
540 * I know of no way of getting nullfunc frames that contain
541 * sleep transition from connected stations - these do not
542 * seem to be sent from the target to the host. There also
543 * doesn't seem to be a dedicated event for that. So the
544 * only way left to do this would be to read tim_bitmap
547 * We could probably try using tim_bitmap from SWBA to tell
548 * mac80211 which stations are asleep and which are not. The
549 * problem here is calling mac80211 functions so many times
550 * could take too long and make us miss the time to submit
551 * the beacon to the target.
553 * So as a workaround we try to extend the TIM IE if there
554 * is unicast buffered for stations with aid > 7 and fill it
557 static void ath10k_wmi_update_tim(struct ath10k *ar,
558 struct ath10k_vif *arvif,
560 struct wmi_bcn_info *bcn_info)
562 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
563 struct ieee80211_tim_ie *tim;
567 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
568 * we must copy the bitmap upon change and reuse it later */
569 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
572 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
573 sizeof(bcn_info->tim_info.tim_bitmap));
575 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
576 __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
577 u32 v = __le32_to_cpu(t);
578 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
581 /* FW reports either length 0 or 16
582 * so we calculate this on our own */
583 arvif->u.ap.tim_len = 0;
584 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
585 if (arvif->u.ap.tim_bitmap[i])
586 arvif->u.ap.tim_len = i;
588 arvif->u.ap.tim_len++;
592 ies += ieee80211_hdrlen(hdr->frame_control);
593 ies += 12; /* fixed parameters */
595 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
596 (u8 *)skb_tail_pointer(bcn) - ies);
598 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
599 ath10k_warn("no tim ie found;\n");
603 tim = (void *)ie + 2;
605 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
607 if (pvm_len < arvif->u.ap.tim_len) {
608 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
609 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
610 void *next_ie = ie + 2 + ie_len;
612 if (skb_put(bcn, expand_size)) {
613 memmove(next_ie + expand_size, next_ie, move_size);
615 ie[1] += expand_size;
616 ie_len += expand_size;
617 pvm_len += expand_size;
619 ath10k_warn("tim expansion failed\n");
623 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
624 ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
628 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
629 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
631 ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
632 tim->dtim_count, tim->dtim_period,
633 tim->bitmap_ctrl, pvm_len);
636 static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
637 struct wmi_p2p_noa_info *noa)
639 struct ieee80211_p2p_noa_attr *noa_attr;
640 u8 ctwindow_oppps = noa->ctwindow_oppps;
641 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
642 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
643 __le16 *noa_attr_len;
645 u8 noa_descriptors = noa->num_descriptors;
649 data[0] = WLAN_EID_VENDOR_SPECIFIC;
651 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
652 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
653 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
654 data[5] = WLAN_OUI_TYPE_WFA_P2P;
657 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
658 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
659 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
661 noa_attr->index = noa->index;
662 noa_attr->oppps_ctwindow = ctwindow;
664 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
666 for (i = 0; i < noa_descriptors; i++) {
667 noa_attr->desc[i].count =
668 __le32_to_cpu(noa->descriptors[i].type_count);
669 noa_attr->desc[i].duration = noa->descriptors[i].duration;
670 noa_attr->desc[i].interval = noa->descriptors[i].interval;
671 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
674 attr_len = 2; /* index + oppps_ctwindow */
675 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
676 *noa_attr_len = __cpu_to_le16(attr_len);
679 static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
682 u8 noa_descriptors = noa->num_descriptors;
683 u8 opp_ps_info = noa->ctwindow_oppps;
684 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
687 if (!noa_descriptors && !opps_enabled)
690 len += 1 + 1 + 4; /* EID + len + OUI */
691 len += 1 + 2; /* noa attr + attr len */
692 len += 1 + 1; /* index + oppps_ctwindow */
693 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
698 static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
700 struct wmi_bcn_info *bcn_info)
702 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
703 u8 *new_data, *old_data = arvif->u.ap.noa_data;
706 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
709 ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
710 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
711 new_len = ath10k_p2p_calc_noa_ie_len(noa);
715 new_data = kmalloc(new_len, GFP_ATOMIC);
719 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
721 spin_lock_bh(&ar->data_lock);
722 arvif->u.ap.noa_data = new_data;
723 arvif->u.ap.noa_len = new_len;
724 spin_unlock_bh(&ar->data_lock);
728 if (arvif->u.ap.noa_data)
729 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
730 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
731 arvif->u.ap.noa_data,
732 arvif->u.ap.noa_len);
736 spin_lock_bh(&ar->data_lock);
737 arvif->u.ap.noa_data = NULL;
738 arvif->u.ap.noa_len = 0;
739 spin_unlock_bh(&ar->data_lock);
744 static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
746 struct wmi_host_swba_event *ev;
749 struct wmi_bcn_info *bcn_info;
750 struct ath10k_vif *arvif;
751 struct wmi_bcn_tx_arg arg;
756 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
758 ev = (struct wmi_host_swba_event *)skb->data;
759 map = __le32_to_cpu(ev->vdev_map);
761 ath10k_dbg(ATH10K_DBG_MGMT, "host swba:\n"
765 for (; map; map >>= 1, vdev_id++) {
771 if (i >= WMI_MAX_AP_VDEV) {
772 ath10k_warn("swba has corrupted vdev map\n");
776 bcn_info = &ev->bcn_info[i];
778 ath10k_dbg(ATH10K_DBG_MGMT,
783 "--tim_num_ps_pending %d\n"
784 "--tim_bitmap 0x%08x%08x%08x%08x\n",
786 __le32_to_cpu(bcn_info->tim_info.tim_len),
787 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
788 __le32_to_cpu(bcn_info->tim_info.tim_changed),
789 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
790 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
791 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
792 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
793 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
795 arvif = ath10k_get_arvif(ar, vdev_id);
797 ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
801 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
803 ath10k_warn("could not get mac80211 beacon\n");
807 ath10k_tx_h_seq_no(bcn);
808 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
809 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
811 arg.vdev_id = arvif->vdev_id;
815 arg.bcn_len = bcn->len;
817 ret = ath10k_wmi_beacon_send(ar, &arg);
819 ath10k_warn("could not send beacon (%d)\n", ret);
821 dev_kfree_skb_any(bcn);
825 static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
828 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
831 static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
833 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PHYERR_EVENTID\n");
836 static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
838 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
841 static void ath10k_wmi_event_profile_match(struct ath10k *ar,
844 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
847 static void ath10k_wmi_event_debug_print(struct ath10k *ar,
850 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_PRINT_EVENTID\n");
853 static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
855 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
858 static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
861 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
864 static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
867 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
870 static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
873 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
876 static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
879 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
882 static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
885 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
888 static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
891 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
894 static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
897 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
900 static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
903 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
906 static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
909 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
912 static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
915 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
918 static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
921 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
924 static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
927 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
930 static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
933 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
936 static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
939 struct wmi_service_ready_event *ev = (void *)skb->data;
941 if (skb->len < sizeof(*ev)) {
942 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
943 skb->len, sizeof(*ev));
947 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
948 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
949 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
950 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
951 ar->fw_version_major =
952 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
953 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
954 ar->fw_version_release =
955 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
956 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
957 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
958 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
960 if (ar->fw_version_build > 636)
961 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
963 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
964 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
965 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
966 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
969 ar->ath_common.regulatory.current_rd =
970 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
972 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
973 sizeof(ev->wmi_service_bitmap));
975 if (strlen(ar->hw->wiphy->fw_version) == 0) {
976 snprintf(ar->hw->wiphy->fw_version,
977 sizeof(ar->hw->wiphy->fw_version),
979 ar->fw_version_major,
980 ar->fw_version_minor,
981 ar->fw_version_release,
982 ar->fw_version_build);
985 /* FIXME: it probably should be better to support this */
986 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
987 ath10k_warn("target requested %d memory chunks; ignoring\n",
988 __le32_to_cpu(ev->num_mem_reqs));
991 ath10k_dbg(ATH10K_DBG_WMI,
992 "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 num_rf_chains %u\n",
993 __le32_to_cpu(ev->sw_version),
994 __le32_to_cpu(ev->sw_version_1),
995 __le32_to_cpu(ev->abi_version),
996 __le32_to_cpu(ev->phy_capability),
997 __le32_to_cpu(ev->ht_cap_info),
998 __le32_to_cpu(ev->vht_cap_info),
999 __le32_to_cpu(ev->vht_supp_mcs),
1000 __le32_to_cpu(ev->sys_cap_info),
1001 __le32_to_cpu(ev->num_mem_reqs),
1002 __le32_to_cpu(ev->num_rf_chains));
1004 complete(&ar->wmi.service_ready);
1007 static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
1009 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
1011 if (WARN_ON(skb->len < sizeof(*ev)))
1014 memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
1016 ath10k_dbg(ATH10K_DBG_WMI,
1017 "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d\n",
1018 __le32_to_cpu(ev->sw_version),
1019 __le32_to_cpu(ev->abi_version),
1021 __le32_to_cpu(ev->status));
1023 complete(&ar->wmi.unified_ready);
1027 static void ath10k_wmi_event_process(struct ath10k *ar, struct sk_buff *skb)
1029 struct wmi_cmd_hdr *cmd_hdr;
1030 enum wmi_event_id id;
1033 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
1034 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
1036 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
1041 trace_ath10k_wmi_event(id, skb->data, skb->len);
1044 case WMI_MGMT_RX_EVENTID:
1045 ath10k_wmi_event_mgmt_rx(ar, skb);
1046 /* mgmt_rx() owns the skb now! */
1048 case WMI_SCAN_EVENTID:
1049 ath10k_wmi_event_scan(ar, skb);
1051 case WMI_CHAN_INFO_EVENTID:
1052 ath10k_wmi_event_chan_info(ar, skb);
1054 case WMI_ECHO_EVENTID:
1055 ath10k_wmi_event_echo(ar, skb);
1057 case WMI_DEBUG_MESG_EVENTID:
1058 ath10k_wmi_event_debug_mesg(ar, skb);
1060 case WMI_UPDATE_STATS_EVENTID:
1061 ath10k_wmi_event_update_stats(ar, skb);
1063 case WMI_VDEV_START_RESP_EVENTID:
1064 ath10k_wmi_event_vdev_start_resp(ar, skb);
1066 case WMI_VDEV_STOPPED_EVENTID:
1067 ath10k_wmi_event_vdev_stopped(ar, skb);
1069 case WMI_PEER_STA_KICKOUT_EVENTID:
1070 ath10k_wmi_event_peer_sta_kickout(ar, skb);
1072 case WMI_HOST_SWBA_EVENTID:
1073 ath10k_wmi_event_host_swba(ar, skb);
1075 case WMI_TBTTOFFSET_UPDATE_EVENTID:
1076 ath10k_wmi_event_tbttoffset_update(ar, skb);
1078 case WMI_PHYERR_EVENTID:
1079 ath10k_wmi_event_phyerr(ar, skb);
1081 case WMI_ROAM_EVENTID:
1082 ath10k_wmi_event_roam(ar, skb);
1084 case WMI_PROFILE_MATCH:
1085 ath10k_wmi_event_profile_match(ar, skb);
1087 case WMI_DEBUG_PRINT_EVENTID:
1088 ath10k_wmi_event_debug_print(ar, skb);
1090 case WMI_PDEV_QVIT_EVENTID:
1091 ath10k_wmi_event_pdev_qvit(ar, skb);
1093 case WMI_WLAN_PROFILE_DATA_EVENTID:
1094 ath10k_wmi_event_wlan_profile_data(ar, skb);
1096 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
1097 ath10k_wmi_event_rtt_measurement_report(ar, skb);
1099 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
1100 ath10k_wmi_event_tsf_measurement_report(ar, skb);
1102 case WMI_RTT_ERROR_REPORT_EVENTID:
1103 ath10k_wmi_event_rtt_error_report(ar, skb);
1105 case WMI_WOW_WAKEUP_HOST_EVENTID:
1106 ath10k_wmi_event_wow_wakeup_host(ar, skb);
1108 case WMI_DCS_INTERFERENCE_EVENTID:
1109 ath10k_wmi_event_dcs_interference(ar, skb);
1111 case WMI_PDEV_TPC_CONFIG_EVENTID:
1112 ath10k_wmi_event_pdev_tpc_config(ar, skb);
1114 case WMI_PDEV_FTM_INTG_EVENTID:
1115 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
1117 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
1118 ath10k_wmi_event_gtk_offload_status(ar, skb);
1120 case WMI_GTK_REKEY_FAIL_EVENTID:
1121 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
1123 case WMI_TX_DELBA_COMPLETE_EVENTID:
1124 ath10k_wmi_event_delba_complete(ar, skb);
1126 case WMI_TX_ADDBA_COMPLETE_EVENTID:
1127 ath10k_wmi_event_addba_complete(ar, skb);
1129 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
1130 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
1132 case WMI_SERVICE_READY_EVENTID:
1133 ath10k_wmi_service_ready_event_rx(ar, skb);
1135 case WMI_READY_EVENTID:
1136 ath10k_wmi_ready_event_rx(ar, skb);
1139 ath10k_warn("Unknown eventid: %d\n", id);
1146 static void ath10k_wmi_event_work(struct work_struct *work)
1148 struct ath10k *ar = container_of(work, struct ath10k,
1149 wmi.wmi_event_work);
1150 struct sk_buff *skb;
1153 skb = skb_dequeue(&ar->wmi.wmi_event_list);
1157 ath10k_wmi_event_process(ar, skb);
1161 static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
1163 struct wmi_cmd_hdr *cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
1164 enum wmi_event_id event_id;
1166 event_id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
1168 /* some events require to be handled ASAP
1169 * thus can't be defered to a worker thread */
1171 case WMI_HOST_SWBA_EVENTID:
1172 case WMI_MGMT_RX_EVENTID:
1173 ath10k_wmi_event_process(ar, skb);
1179 skb_queue_tail(&ar->wmi.wmi_event_list, skb);
1180 queue_work(ar->workqueue, &ar->wmi.wmi_event_work);
1183 /* WMI Initialization functions */
1184 int ath10k_wmi_attach(struct ath10k *ar)
1186 init_completion(&ar->wmi.service_ready);
1187 init_completion(&ar->wmi.unified_ready);
1188 init_waitqueue_head(&ar->wmi.wq);
1190 skb_queue_head_init(&ar->wmi.wmi_event_list);
1191 INIT_WORK(&ar->wmi.wmi_event_work, ath10k_wmi_event_work);
1196 void ath10k_wmi_detach(struct ath10k *ar)
1198 /* HTC should've drained the packets already */
1199 if (WARN_ON(atomic_read(&ar->wmi.pending_tx_count) > 0))
1200 ath10k_warn("there are still pending packets\n");
1202 cancel_work_sync(&ar->wmi.wmi_event_work);
1203 skb_queue_purge(&ar->wmi.wmi_event_list);
1206 int ath10k_wmi_connect_htc_service(struct ath10k *ar)
1209 struct ath10k_htc_svc_conn_req conn_req;
1210 struct ath10k_htc_svc_conn_resp conn_resp;
1212 memset(&conn_req, 0, sizeof(conn_req));
1213 memset(&conn_resp, 0, sizeof(conn_resp));
1215 /* these fields are the same for all service endpoints */
1216 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
1217 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
1219 /* connect to control service */
1220 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
1222 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
1224 ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
1229 ar->wmi.eid = conn_resp.eid;
1233 int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
1234 u16 rd5g, u16 ctl2g, u16 ctl5g)
1236 struct wmi_pdev_set_regdomain_cmd *cmd;
1237 struct sk_buff *skb;
1239 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1243 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1244 cmd->reg_domain = __cpu_to_le32(rd);
1245 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
1246 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
1247 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
1248 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
1250 ath10k_dbg(ATH10K_DBG_WMI,
1251 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
1252 rd, rd2g, rd5g, ctl2g, ctl5g);
1254 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1257 int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
1258 const struct wmi_channel_arg *arg)
1260 struct wmi_set_channel_cmd *cmd;
1261 struct sk_buff *skb;
1266 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1270 cmd = (struct wmi_set_channel_cmd *)skb->data;
1271 cmd->chan.mhz = __cpu_to_le32(arg->freq);
1272 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
1273 cmd->chan.mode = arg->mode;
1274 cmd->chan.min_power = arg->min_power;
1275 cmd->chan.max_power = arg->max_power;
1276 cmd->chan.reg_power = arg->max_reg_power;
1277 cmd->chan.reg_classid = arg->reg_class_id;
1278 cmd->chan.antenna_max = arg->max_antenna_gain;
1280 ath10k_dbg(ATH10K_DBG_WMI,
1281 "wmi set channel mode %d freq %d\n",
1282 arg->mode, arg->freq);
1284 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_CHANNEL_CMDID);
1287 int ath10k_wmi_pdev_suspend_target(struct ath10k *ar)
1289 struct wmi_pdev_suspend_cmd *cmd;
1290 struct sk_buff *skb;
1292 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1296 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1297 cmd->suspend_opt = WMI_PDEV_SUSPEND;
1299 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SUSPEND_CMDID);
1302 int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
1304 struct sk_buff *skb;
1306 skb = ath10k_wmi_alloc_skb(0);
1310 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_RESUME_CMDID);
1313 int ath10k_wmi_pdev_set_param(struct ath10k *ar, enum wmi_pdev_param id,
1316 struct wmi_pdev_set_param_cmd *cmd;
1317 struct sk_buff *skb;
1319 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1323 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1324 cmd->param_id = __cpu_to_le32(id);
1325 cmd->param_value = __cpu_to_le32(value);
1327 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
1329 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_PARAM_CMDID);
1332 int ath10k_wmi_cmd_init(struct ath10k *ar)
1334 struct wmi_init_cmd *cmd;
1335 struct sk_buff *buf;
1336 struct wmi_resource_config config = {};
1339 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
1340 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
1341 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
1343 config.num_offload_reorder_bufs =
1344 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
1346 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
1347 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
1348 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
1349 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
1350 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
1351 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1352 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1353 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1354 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
1355 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
1357 config.scan_max_pending_reqs =
1358 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
1360 config.bmiss_offload_max_vdev =
1361 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
1363 config.roam_offload_max_vdev =
1364 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
1366 config.roam_offload_max_ap_profiles =
1367 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
1369 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
1370 config.num_mcast_table_elems =
1371 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
1373 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
1374 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
1375 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
1376 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
1377 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
1379 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
1380 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
1382 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
1384 config.gtk_offload_max_vdev =
1385 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
1387 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
1388 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
1390 buf = ath10k_wmi_alloc_skb(sizeof(*cmd));
1394 cmd = (struct wmi_init_cmd *)buf->data;
1395 cmd->num_host_mem_chunks = 0;
1396 memcpy(&cmd->resource_config, &config, sizeof(config));
1398 ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
1399 return ath10k_wmi_cmd_send(ar, buf, WMI_INIT_CMDID);
1402 static int ath10k_wmi_start_scan_calc_len(const struct wmi_start_scan_arg *arg)
1406 len = sizeof(struct wmi_start_scan_cmd);
1411 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
1414 len += sizeof(struct wmi_ie_data);
1415 len += roundup(arg->ie_len, 4);
1418 if (arg->n_channels) {
1421 if (arg->n_channels > ARRAY_SIZE(arg->channels))
1424 len += sizeof(struct wmi_chan_list);
1425 len += sizeof(__le32) * arg->n_channels;
1431 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
1434 len += sizeof(struct wmi_ssid_list);
1435 len += sizeof(struct wmi_ssid) * arg->n_ssids;
1438 if (arg->n_bssids) {
1441 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
1444 len += sizeof(struct wmi_bssid_list);
1445 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
1451 int ath10k_wmi_start_scan(struct ath10k *ar,
1452 const struct wmi_start_scan_arg *arg)
1454 struct wmi_start_scan_cmd *cmd;
1455 struct sk_buff *skb;
1456 struct wmi_ie_data *ie;
1457 struct wmi_chan_list *channels;
1458 struct wmi_ssid_list *ssids;
1459 struct wmi_bssid_list *bssids;
1466 len = ath10k_wmi_start_scan_calc_len(arg);
1468 return len; /* len contains error code here */
1470 skb = ath10k_wmi_alloc_skb(len);
1474 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
1475 scan_id |= arg->scan_id;
1477 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1478 scan_req_id |= arg->scan_req_id;
1480 cmd = (struct wmi_start_scan_cmd *)skb->data;
1481 cmd->scan_id = __cpu_to_le32(scan_id);
1482 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
1483 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1484 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
1485 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
1486 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
1487 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
1488 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
1489 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
1490 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
1491 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
1492 cmd->idle_time = __cpu_to_le32(arg->idle_time);
1493 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
1494 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
1495 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
1497 /* TLV list starts after fields included in the struct */
1500 if (arg->n_channels) {
1501 channels = (void *)skb->data + off;
1502 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
1503 channels->num_chan = __cpu_to_le32(arg->n_channels);
1505 for (i = 0; i < arg->n_channels; i++)
1506 channels->channel_list[i] =
1507 __cpu_to_le32(arg->channels[i]);
1509 off += sizeof(*channels);
1510 off += sizeof(__le32) * arg->n_channels;
1514 ssids = (void *)skb->data + off;
1515 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
1516 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
1518 for (i = 0; i < arg->n_ssids; i++) {
1519 ssids->ssids[i].ssid_len =
1520 __cpu_to_le32(arg->ssids[i].len);
1521 memcpy(&ssids->ssids[i].ssid,
1526 off += sizeof(*ssids);
1527 off += sizeof(struct wmi_ssid) * arg->n_ssids;
1530 if (arg->n_bssids) {
1531 bssids = (void *)skb->data + off;
1532 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
1533 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
1535 for (i = 0; i < arg->n_bssids; i++)
1536 memcpy(&bssids->bssid_list[i],
1537 arg->bssids[i].bssid,
1540 off += sizeof(*bssids);
1541 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
1545 ie = (void *)skb->data + off;
1546 ie->tag = __cpu_to_le32(WMI_IE_TAG);
1547 ie->ie_len = __cpu_to_le32(arg->ie_len);
1548 memcpy(ie->ie_data, arg->ie, arg->ie_len);
1551 off += roundup(arg->ie_len, 4);
1554 if (off != skb->len) {
1559 ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
1560 return ath10k_wmi_cmd_send(ar, skb, WMI_START_SCAN_CMDID);
1563 void ath10k_wmi_start_scan_init(struct ath10k *ar,
1564 struct wmi_start_scan_arg *arg)
1566 /* setup commonly used values */
1567 arg->scan_req_id = 1;
1568 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
1569 arg->dwell_time_active = 50;
1570 arg->dwell_time_passive = 150;
1571 arg->min_rest_time = 50;
1572 arg->max_rest_time = 500;
1573 arg->repeat_probe_time = 0;
1574 arg->probe_spacing_time = 0;
1576 arg->max_scan_time = 5000;
1577 arg->probe_delay = 5;
1578 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
1579 | WMI_SCAN_EVENT_COMPLETED
1580 | WMI_SCAN_EVENT_BSS_CHANNEL
1581 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
1582 | WMI_SCAN_EVENT_DEQUEUED;
1583 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
1584 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
1586 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
1589 int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
1591 struct wmi_stop_scan_cmd *cmd;
1592 struct sk_buff *skb;
1596 if (arg->req_id > 0xFFF)
1598 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
1601 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1605 scan_id = arg->u.scan_id;
1606 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
1608 req_id = arg->req_id;
1609 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1611 cmd = (struct wmi_stop_scan_cmd *)skb->data;
1612 cmd->req_type = __cpu_to_le32(arg->req_type);
1613 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
1614 cmd->scan_id = __cpu_to_le32(scan_id);
1615 cmd->scan_req_id = __cpu_to_le32(req_id);
1617 ath10k_dbg(ATH10K_DBG_WMI,
1618 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
1619 arg->req_id, arg->req_type, arg->u.scan_id);
1620 return ath10k_wmi_cmd_send(ar, skb, WMI_STOP_SCAN_CMDID);
1623 int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
1624 enum wmi_vdev_type type,
1625 enum wmi_vdev_subtype subtype,
1626 const u8 macaddr[ETH_ALEN])
1628 struct wmi_vdev_create_cmd *cmd;
1629 struct sk_buff *skb;
1631 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1635 cmd = (struct wmi_vdev_create_cmd *)skb->data;
1636 cmd->vdev_id = __cpu_to_le32(vdev_id);
1637 cmd->vdev_type = __cpu_to_le32(type);
1638 cmd->vdev_subtype = __cpu_to_le32(subtype);
1639 memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
1641 ath10k_dbg(ATH10K_DBG_WMI,
1642 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
1643 vdev_id, type, subtype, macaddr);
1645 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_CREATE_CMDID);
1648 int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
1650 struct wmi_vdev_delete_cmd *cmd;
1651 struct sk_buff *skb;
1653 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1657 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
1658 cmd->vdev_id = __cpu_to_le32(vdev_id);
1660 ath10k_dbg(ATH10K_DBG_WMI,
1661 "WMI vdev delete id %d\n", vdev_id);
1663 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_DELETE_CMDID);
1666 static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
1667 const struct wmi_vdev_start_request_arg *arg,
1668 enum wmi_cmd_id cmd_id)
1670 struct wmi_vdev_start_request_cmd *cmd;
1671 struct sk_buff *skb;
1672 const char *cmdname;
1675 if (cmd_id != WMI_VDEV_START_REQUEST_CMDID &&
1676 cmd_id != WMI_VDEV_RESTART_REQUEST_CMDID)
1678 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
1680 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
1682 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
1685 if (cmd_id == WMI_VDEV_START_REQUEST_CMDID)
1687 else if (cmd_id == WMI_VDEV_RESTART_REQUEST_CMDID)
1688 cmdname = "restart";
1690 return -EINVAL; /* should not happen, we already check cmd_id */
1692 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1696 if (arg->hidden_ssid)
1697 flags |= WMI_VDEV_START_HIDDEN_SSID;
1698 if (arg->pmf_enabled)
1699 flags |= WMI_VDEV_START_PMF_ENABLED;
1701 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
1702 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1703 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
1704 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
1705 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
1706 cmd->flags = __cpu_to_le32(flags);
1707 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
1708 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
1711 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
1712 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
1715 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
1717 cmd->chan.band_center_freq1 =
1718 __cpu_to_le32(arg->channel.band_center_freq1);
1720 cmd->chan.mode = arg->channel.mode;
1721 cmd->chan.min_power = arg->channel.min_power;
1722 cmd->chan.max_power = arg->channel.max_power;
1723 cmd->chan.reg_power = arg->channel.max_reg_power;
1724 cmd->chan.reg_classid = arg->channel.reg_class_id;
1725 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
1727 ath10k_dbg(ATH10K_DBG_WMI,
1728 "wmi vdev %s id 0x%x freq %d, mode %d, ch_flags: 0x%0X,"
1729 "max_power: %d\n", cmdname, arg->vdev_id, arg->channel.freq,
1730 arg->channel.mode, flags, arg->channel.max_power);
1732 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
1735 int ath10k_wmi_vdev_start(struct ath10k *ar,
1736 const struct wmi_vdev_start_request_arg *arg)
1738 return ath10k_wmi_vdev_start_restart(ar, arg,
1739 WMI_VDEV_START_REQUEST_CMDID);
1742 int ath10k_wmi_vdev_restart(struct ath10k *ar,
1743 const struct wmi_vdev_start_request_arg *arg)
1745 return ath10k_wmi_vdev_start_restart(ar, arg,
1746 WMI_VDEV_RESTART_REQUEST_CMDID);
1749 int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
1751 struct wmi_vdev_stop_cmd *cmd;
1752 struct sk_buff *skb;
1754 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1758 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
1759 cmd->vdev_id = __cpu_to_le32(vdev_id);
1761 ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
1763 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_STOP_CMDID);
1766 int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
1768 struct wmi_vdev_up_cmd *cmd;
1769 struct sk_buff *skb;
1771 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1775 cmd = (struct wmi_vdev_up_cmd *)skb->data;
1776 cmd->vdev_id = __cpu_to_le32(vdev_id);
1777 cmd->vdev_assoc_id = __cpu_to_le32(aid);
1778 memcpy(&cmd->vdev_bssid.addr, bssid, 6);
1780 ath10k_dbg(ATH10K_DBG_WMI,
1781 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
1782 vdev_id, aid, bssid);
1784 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_UP_CMDID);
1787 int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
1789 struct wmi_vdev_down_cmd *cmd;
1790 struct sk_buff *skb;
1792 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1796 cmd = (struct wmi_vdev_down_cmd *)skb->data;
1797 cmd->vdev_id = __cpu_to_le32(vdev_id);
1799 ath10k_dbg(ATH10K_DBG_WMI,
1800 "wmi mgmt vdev down id 0x%x\n", vdev_id);
1802 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_DOWN_CMDID);
1805 int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
1806 enum wmi_vdev_param param_id, u32 param_value)
1808 struct wmi_vdev_set_param_cmd *cmd;
1809 struct sk_buff *skb;
1811 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1815 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1816 cmd->vdev_id = __cpu_to_le32(vdev_id);
1817 cmd->param_id = __cpu_to_le32(param_id);
1818 cmd->param_value = __cpu_to_le32(param_value);
1820 ath10k_dbg(ATH10K_DBG_WMI,
1821 "wmi vdev id 0x%x set param %d value %d\n",
1822 vdev_id, param_id, param_value);
1824 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_SET_PARAM_CMDID);
1827 int ath10k_wmi_vdev_install_key(struct ath10k *ar,
1828 const struct wmi_vdev_install_key_arg *arg)
1830 struct wmi_vdev_install_key_cmd *cmd;
1831 struct sk_buff *skb;
1833 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
1835 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
1838 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
1842 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1843 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1844 cmd->key_idx = __cpu_to_le32(arg->key_idx);
1845 cmd->key_flags = __cpu_to_le32(arg->key_flags);
1846 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
1847 cmd->key_len = __cpu_to_le32(arg->key_len);
1848 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
1849 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
1852 memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
1854 memcpy(cmd->key_data, arg->key_data, arg->key_len);
1856 ath10k_dbg(ATH10K_DBG_WMI,
1857 "wmi vdev install key idx %d cipher %d len %d\n",
1858 arg->key_idx, arg->key_cipher, arg->key_len);
1859 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1862 int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
1863 const u8 peer_addr[ETH_ALEN])
1865 struct wmi_peer_create_cmd *cmd;
1866 struct sk_buff *skb;
1868 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1872 cmd = (struct wmi_peer_create_cmd *)skb->data;
1873 cmd->vdev_id = __cpu_to_le32(vdev_id);
1874 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1876 ath10k_dbg(ATH10K_DBG_WMI,
1877 "wmi peer create vdev_id %d peer_addr %pM\n",
1878 vdev_id, peer_addr);
1879 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_CREATE_CMDID);
1882 int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
1883 const u8 peer_addr[ETH_ALEN])
1885 struct wmi_peer_delete_cmd *cmd;
1886 struct sk_buff *skb;
1888 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1892 cmd = (struct wmi_peer_delete_cmd *)skb->data;
1893 cmd->vdev_id = __cpu_to_le32(vdev_id);
1894 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1896 ath10k_dbg(ATH10K_DBG_WMI,
1897 "wmi peer delete vdev_id %d peer_addr %pM\n",
1898 vdev_id, peer_addr);
1899 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_DELETE_CMDID);
1902 int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
1903 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
1905 struct wmi_peer_flush_tids_cmd *cmd;
1906 struct sk_buff *skb;
1908 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1912 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1913 cmd->vdev_id = __cpu_to_le32(vdev_id);
1914 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
1915 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1917 ath10k_dbg(ATH10K_DBG_WMI,
1918 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
1919 vdev_id, peer_addr, tid_bitmap);
1920 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1923 int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
1924 const u8 *peer_addr, enum wmi_peer_param param_id,
1927 struct wmi_peer_set_param_cmd *cmd;
1928 struct sk_buff *skb;
1930 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1934 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1935 cmd->vdev_id = __cpu_to_le32(vdev_id);
1936 cmd->param_id = __cpu_to_le32(param_id);
1937 cmd->param_value = __cpu_to_le32(param_value);
1938 memcpy(&cmd->peer_macaddr.addr, peer_addr, 6);
1940 ath10k_dbg(ATH10K_DBG_WMI,
1941 "wmi vdev %d peer 0x%pM set param %d value %d\n",
1942 vdev_id, peer_addr, param_id, param_value);
1944 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_SET_PARAM_CMDID);
1947 int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
1948 enum wmi_sta_ps_mode psmode)
1950 struct wmi_sta_powersave_mode_cmd *cmd;
1951 struct sk_buff *skb;
1953 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1957 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
1958 cmd->vdev_id = __cpu_to_le32(vdev_id);
1959 cmd->sta_ps_mode = __cpu_to_le32(psmode);
1961 ath10k_dbg(ATH10K_DBG_WMI,
1962 "wmi set powersave id 0x%x mode %d\n",
1965 return ath10k_wmi_cmd_send(ar, skb, WMI_STA_POWERSAVE_MODE_CMDID);
1968 int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
1969 enum wmi_sta_powersave_param param_id,
1972 struct wmi_sta_powersave_param_cmd *cmd;
1973 struct sk_buff *skb;
1975 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1979 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1980 cmd->vdev_id = __cpu_to_le32(vdev_id);
1981 cmd->param_id = __cpu_to_le32(param_id);
1982 cmd->param_value = __cpu_to_le32(value);
1984 ath10k_dbg(ATH10K_DBG_WMI,
1985 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
1986 vdev_id, param_id, value);
1987 return ath10k_wmi_cmd_send(ar, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1990 int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
1991 enum wmi_ap_ps_peer_param param_id, u32 value)
1993 struct wmi_ap_ps_peer_cmd *cmd;
1994 struct sk_buff *skb;
1999 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2003 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
2004 cmd->vdev_id = __cpu_to_le32(vdev_id);
2005 cmd->param_id = __cpu_to_le32(param_id);
2006 cmd->param_value = __cpu_to_le32(value);
2007 memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
2009 ath10k_dbg(ATH10K_DBG_WMI,
2010 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
2011 vdev_id, param_id, value, mac);
2013 return ath10k_wmi_cmd_send(ar, skb, WMI_AP_PS_PEER_PARAM_CMDID);
2016 int ath10k_wmi_scan_chan_list(struct ath10k *ar,
2017 const struct wmi_scan_chan_list_arg *arg)
2019 struct wmi_scan_chan_list_cmd *cmd;
2020 struct sk_buff *skb;
2021 struct wmi_channel_arg *ch;
2022 struct wmi_channel *ci;
2026 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
2028 skb = ath10k_wmi_alloc_skb(len);
2032 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2033 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
2035 for (i = 0; i < arg->n_channels; i++) {
2038 ch = &arg->channels[i];
2039 ci = &cmd->chan_info[i];
2042 flags |= WMI_CHAN_FLAG_PASSIVE;
2044 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
2046 flags |= WMI_CHAN_FLAG_ALLOW_HT;
2048 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
2050 flags |= WMI_CHAN_FLAG_HT40_PLUS;
2052 ci->mhz = __cpu_to_le32(ch->freq);
2053 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
2054 ci->band_center_freq2 = 0;
2055 ci->min_power = ch->min_power;
2056 ci->max_power = ch->max_power;
2057 ci->reg_power = ch->max_reg_power;
2058 ci->antenna_max = ch->max_antenna_gain;
2059 ci->antenna_max = 0;
2061 /* mode & flags share storage */
2062 ci->mode = ch->mode;
2063 ci->flags |= __cpu_to_le32(flags);
2066 return ath10k_wmi_cmd_send(ar, skb, WMI_SCAN_CHAN_LIST_CMDID);
2069 int ath10k_wmi_peer_assoc(struct ath10k *ar,
2070 const struct wmi_peer_assoc_complete_arg *arg)
2072 struct wmi_peer_assoc_complete_cmd *cmd;
2073 struct sk_buff *skb;
2075 if (arg->peer_mpdu_density > 16)
2077 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
2079 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
2082 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2086 cmd = (struct wmi_peer_assoc_complete_cmd *)skb->data;
2087 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2088 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
2089 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
2090 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
2091 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
2092 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
2093 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
2094 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
2095 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
2096 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
2097 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
2098 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
2099 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
2101 memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
2103 cmd->peer_legacy_rates.num_rates =
2104 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
2105 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
2106 arg->peer_legacy_rates.num_rates);
2108 cmd->peer_ht_rates.num_rates =
2109 __cpu_to_le32(arg->peer_ht_rates.num_rates);
2110 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
2111 arg->peer_ht_rates.num_rates);
2113 cmd->peer_vht_rates.rx_max_rate =
2114 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
2115 cmd->peer_vht_rates.rx_mcs_set =
2116 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
2117 cmd->peer_vht_rates.tx_max_rate =
2118 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
2119 cmd->peer_vht_rates.tx_mcs_set =
2120 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
2122 ath10k_dbg(ATH10K_DBG_WMI,
2123 "wmi peer assoc vdev %d addr %pM\n",
2124 arg->vdev_id, arg->addr);
2125 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_ASSOC_CMDID);
2128 int ath10k_wmi_beacon_send(struct ath10k *ar, const struct wmi_bcn_tx_arg *arg)
2130 struct wmi_bcn_tx_cmd *cmd;
2131 struct sk_buff *skb;
2133 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->bcn_len);
2137 cmd = (struct wmi_bcn_tx_cmd *)skb->data;
2138 cmd->hdr.vdev_id = __cpu_to_le32(arg->vdev_id);
2139 cmd->hdr.tx_rate = __cpu_to_le32(arg->tx_rate);
2140 cmd->hdr.tx_power = __cpu_to_le32(arg->tx_power);
2141 cmd->hdr.bcn_len = __cpu_to_le32(arg->bcn_len);
2142 memcpy(cmd->bcn, arg->bcn, arg->bcn_len);
2144 return ath10k_wmi_cmd_send(ar, skb, WMI_BCN_TX_CMDID);
2147 static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
2148 const struct wmi_wmm_params_arg *arg)
2150 params->cwmin = __cpu_to_le32(arg->cwmin);
2151 params->cwmax = __cpu_to_le32(arg->cwmax);
2152 params->aifs = __cpu_to_le32(arg->aifs);
2153 params->txop = __cpu_to_le32(arg->txop);
2154 params->acm = __cpu_to_le32(arg->acm);
2155 params->no_ack = __cpu_to_le32(arg->no_ack);
2158 int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
2159 const struct wmi_pdev_set_wmm_params_arg *arg)
2161 struct wmi_pdev_set_wmm_params *cmd;
2162 struct sk_buff *skb;
2164 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2168 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
2169 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
2170 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
2171 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
2172 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
2174 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
2175 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_WMM_PARAMS_CMDID);
2178 int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
2180 struct wmi_request_stats_cmd *cmd;
2181 struct sk_buff *skb;
2183 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2187 cmd = (struct wmi_request_stats_cmd *)skb->data;
2188 cmd->stats_id = __cpu_to_le32(stats_id);
2190 ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
2191 return ath10k_wmi_cmd_send(ar, skb, WMI_REQUEST_STATS_CMDID);
2194 int ath10k_wmi_force_fw_hang(struct ath10k *ar,
2195 enum wmi_force_fw_hang_type type, u32 delay_ms)
2197 struct wmi_force_fw_hang_cmd *cmd;
2198 struct sk_buff *skb;
2200 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2204 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
2205 cmd->type = __cpu_to_le32(type);
2206 cmd->delay_ms = __cpu_to_le32(delay_ms);
2208 ath10k_dbg(ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
2210 return ath10k_wmi_cmd_send(ar, skb, WMI_FORCE_FW_HANG_CMDID);