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 int ath10k_wmi_wait_for_service_ready(struct ath10k *ar)
29 ret = wait_for_completion_timeout(&ar->wmi.service_ready,
30 WMI_SERVICE_READY_TIMEOUT_HZ);
34 int ath10k_wmi_wait_for_unified_ready(struct ath10k *ar)
37 ret = wait_for_completion_timeout(&ar->wmi.unified_ready,
38 WMI_UNIFIED_READY_TIMEOUT_HZ);
42 static struct sk_buff *ath10k_wmi_alloc_skb(u32 len)
45 u32 round_len = roundup(len, 4);
47 skb = ath10k_htc_alloc_skb(WMI_SKB_HEADROOM + round_len);
51 skb_reserve(skb, WMI_SKB_HEADROOM);
52 if (!IS_ALIGNED((unsigned long)skb->data, 4))
53 ath10k_warn("Unaligned WMI skb\n");
55 skb_put(skb, round_len);
56 memset(skb->data, 0, round_len);
61 static void ath10k_wmi_htc_tx_complete(struct ath10k *ar, struct sk_buff *skb)
66 static int ath10k_wmi_cmd_send_nowait(struct ath10k *ar, struct sk_buff *skb,
67 enum wmi_cmd_id cmd_id)
69 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(skb);
70 struct wmi_cmd_hdr *cmd_hdr;
74 if (skb_push(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
77 cmd |= SM(cmd_id, WMI_CMD_HDR_CMD_ID);
79 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
80 cmd_hdr->cmd_id = __cpu_to_le32(cmd);
82 memset(skb_cb, 0, sizeof(*skb_cb));
83 ret = ath10k_htc_send(&ar->htc, ar->wmi.eid, skb);
84 trace_ath10k_wmi_cmd(cmd_id, skb->data, skb->len, ret);
92 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
96 static void ath10k_wmi_tx_beacon_nowait(struct ath10k_vif *arvif)
98 struct wmi_bcn_tx_arg arg = {0};
101 lockdep_assert_held(&arvif->ar->data_lock);
103 if (arvif->beacon == NULL)
106 arg.vdev_id = arvif->vdev_id;
109 arg.bcn = arvif->beacon->data;
110 arg.bcn_len = arvif->beacon->len;
112 ret = ath10k_wmi_beacon_send_nowait(arvif->ar, &arg);
116 dev_kfree_skb_any(arvif->beacon);
117 arvif->beacon = NULL;
120 static void ath10k_wmi_tx_beacons_iter(void *data, u8 *mac,
121 struct ieee80211_vif *vif)
123 struct ath10k_vif *arvif = ath10k_vif_to_arvif(vif);
125 ath10k_wmi_tx_beacon_nowait(arvif);
128 static void ath10k_wmi_tx_beacons_nowait(struct ath10k *ar)
130 spin_lock_bh(&ar->data_lock);
131 ieee80211_iterate_active_interfaces_atomic(ar->hw,
132 IEEE80211_IFACE_ITER_NORMAL,
133 ath10k_wmi_tx_beacons_iter,
135 spin_unlock_bh(&ar->data_lock);
138 static void ath10k_wmi_op_ep_tx_credits(struct ath10k *ar)
140 /* try to send pending beacons first. they take priority */
141 ath10k_wmi_tx_beacons_nowait(ar);
143 wake_up(&ar->wmi.tx_credits_wq);
146 static int ath10k_wmi_cmd_send(struct ath10k *ar, struct sk_buff *skb,
147 enum wmi_cmd_id cmd_id)
151 wait_event_timeout(ar->wmi.tx_credits_wq, ({
152 /* try to send pending beacons first. they take priority */
153 ath10k_wmi_tx_beacons_nowait(ar);
155 ret = ath10k_wmi_cmd_send_nowait(ar, skb, cmd_id);
160 dev_kfree_skb_any(skb);
165 static int ath10k_wmi_event_scan(struct ath10k *ar, struct sk_buff *skb)
167 struct wmi_scan_event *event = (struct wmi_scan_event *)skb->data;
168 enum wmi_scan_event_type event_type;
169 enum wmi_scan_completion_reason reason;
175 event_type = __le32_to_cpu(event->event_type);
176 reason = __le32_to_cpu(event->reason);
177 freq = __le32_to_cpu(event->channel_freq);
178 req_id = __le32_to_cpu(event->scan_req_id);
179 scan_id = __le32_to_cpu(event->scan_id);
180 vdev_id = __le32_to_cpu(event->vdev_id);
182 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENTID\n");
183 ath10k_dbg(ATH10K_DBG_WMI,
184 "scan event type %d reason %d freq %d req_id %d "
185 "scan_id %d vdev_id %d\n",
186 event_type, reason, freq, req_id, scan_id, vdev_id);
188 spin_lock_bh(&ar->data_lock);
190 switch (event_type) {
191 case WMI_SCAN_EVENT_STARTED:
192 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_STARTED\n");
193 if (ar->scan.in_progress && ar->scan.is_roc)
194 ieee80211_ready_on_channel(ar->hw);
196 complete(&ar->scan.started);
198 case WMI_SCAN_EVENT_COMPLETED:
199 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_COMPLETED\n");
201 case WMI_SCAN_REASON_COMPLETED:
202 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_COMPLETED\n");
204 case WMI_SCAN_REASON_CANCELLED:
205 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_CANCELED\n");
207 case WMI_SCAN_REASON_PREEMPTED:
208 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_PREEMPTED\n");
210 case WMI_SCAN_REASON_TIMEDOUT:
211 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_REASON_TIMEDOUT\n");
217 ar->scan_channel = NULL;
218 if (!ar->scan.in_progress) {
219 ath10k_warn("no scan requested, ignoring\n");
223 if (ar->scan.is_roc) {
224 ath10k_offchan_tx_purge(ar);
226 if (!ar->scan.aborting)
227 ieee80211_remain_on_channel_expired(ar->hw);
229 ieee80211_scan_completed(ar->hw, ar->scan.aborting);
232 del_timer(&ar->scan.timeout);
233 complete_all(&ar->scan.completed);
234 ar->scan.in_progress = false;
236 case WMI_SCAN_EVENT_BSS_CHANNEL:
237 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_BSS_CHANNEL\n");
238 ar->scan_channel = NULL;
240 case WMI_SCAN_EVENT_FOREIGN_CHANNEL:
241 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_FOREIGN_CHANNEL\n");
242 ar->scan_channel = ieee80211_get_channel(ar->hw->wiphy, freq);
243 if (ar->scan.in_progress && ar->scan.is_roc &&
244 ar->scan.roc_freq == freq) {
245 complete(&ar->scan.on_channel);
248 case WMI_SCAN_EVENT_DEQUEUED:
249 ath10k_dbg(ATH10K_DBG_WMI, "SCAN_EVENT_DEQUEUED\n");
251 case WMI_SCAN_EVENT_PREEMPTED:
252 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_PREEMPTED\n");
254 case WMI_SCAN_EVENT_START_FAILED:
255 ath10k_dbg(ATH10K_DBG_WMI, "WMI_SCAN_EVENT_START_FAILED\n");
261 spin_unlock_bh(&ar->data_lock);
265 static inline enum ieee80211_band phy_mode_to_band(u32 phy_mode)
267 enum ieee80211_band band;
273 case MODE_11AC_VHT20:
274 case MODE_11AC_VHT40:
275 case MODE_11AC_VHT80:
276 band = IEEE80211_BAND_5GHZ;
283 case MODE_11AC_VHT20_2G:
284 case MODE_11AC_VHT40_2G:
285 case MODE_11AC_VHT80_2G:
287 band = IEEE80211_BAND_2GHZ;
293 static inline u8 get_rate_idx(u32 rate, enum ieee80211_band band)
339 if (band == IEEE80211_BAND_5GHZ) {
350 static int ath10k_wmi_event_mgmt_rx(struct ath10k *ar, struct sk_buff *skb)
352 struct wmi_mgmt_rx_event_v1 *ev_v1;
353 struct wmi_mgmt_rx_event_v2 *ev_v2;
354 struct wmi_mgmt_rx_hdr_v1 *ev_hdr;
355 struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
356 struct ieee80211_hdr *hdr;
366 if (test_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features)) {
367 ev_v2 = (struct wmi_mgmt_rx_event_v2 *)skb->data;
368 ev_hdr = &ev_v2->hdr.v1;
369 pull_len = sizeof(*ev_v2);
371 ev_v1 = (struct wmi_mgmt_rx_event_v1 *)skb->data;
372 ev_hdr = &ev_v1->hdr;
373 pull_len = sizeof(*ev_v1);
376 channel = __le32_to_cpu(ev_hdr->channel);
377 buf_len = __le32_to_cpu(ev_hdr->buf_len);
378 rx_status = __le32_to_cpu(ev_hdr->status);
379 snr = __le32_to_cpu(ev_hdr->snr);
380 phy_mode = __le32_to_cpu(ev_hdr->phy_mode);
381 rate = __le32_to_cpu(ev_hdr->rate);
383 memset(status, 0, sizeof(*status));
385 ath10k_dbg(ATH10K_DBG_MGMT,
386 "event mgmt rx status %08x\n", rx_status);
388 if (rx_status & WMI_RX_STATUS_ERR_DECRYPT) {
393 if (rx_status & WMI_RX_STATUS_ERR_KEY_CACHE_MISS) {
398 if (rx_status & WMI_RX_STATUS_ERR_CRC)
399 status->flag |= RX_FLAG_FAILED_FCS_CRC;
400 if (rx_status & WMI_RX_STATUS_ERR_MIC)
401 status->flag |= RX_FLAG_MMIC_ERROR;
403 status->band = phy_mode_to_band(phy_mode);
404 status->freq = ieee80211_channel_to_frequency(channel, status->band);
405 status->signal = snr + ATH10K_DEFAULT_NOISE_FLOOR;
406 status->rate_idx = get_rate_idx(rate, status->band);
408 skb_pull(skb, pull_len);
410 hdr = (struct ieee80211_hdr *)skb->data;
411 fc = le16_to_cpu(hdr->frame_control);
413 if (fc & IEEE80211_FCTL_PROTECTED) {
414 status->flag |= RX_FLAG_DECRYPTED | RX_FLAG_IV_STRIPPED |
415 RX_FLAG_MMIC_STRIPPED;
416 hdr->frame_control = __cpu_to_le16(fc &
417 ~IEEE80211_FCTL_PROTECTED);
420 ath10k_dbg(ATH10K_DBG_MGMT,
421 "event mgmt rx skb %p len %d ftype %02x stype %02x\n",
423 fc & IEEE80211_FCTL_FTYPE, fc & IEEE80211_FCTL_STYPE);
425 ath10k_dbg(ATH10K_DBG_MGMT,
426 "event mgmt rx freq %d band %d snr %d, rate_idx %d\n",
427 status->freq, status->band, status->signal,
431 * packets from HTC come aligned to 4byte boundaries
432 * because they can originally come in along with a trailer
434 skb_trim(skb, buf_len);
436 ieee80211_rx(ar->hw, skb);
440 static int freq_to_idx(struct ath10k *ar, int freq)
442 struct ieee80211_supported_band *sband;
443 int band, ch, idx = 0;
445 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
446 sband = ar->hw->wiphy->bands[band];
450 for (ch = 0; ch < sband->n_channels; ch++, idx++)
451 if (sband->channels[ch].center_freq == freq)
459 static void ath10k_wmi_event_chan_info(struct ath10k *ar, struct sk_buff *skb)
461 struct wmi_chan_info_event *ev;
462 struct survey_info *survey;
463 u32 err_code, freq, cmd_flags, noise_floor, rx_clear_count, cycle_count;
466 ev = (struct wmi_chan_info_event *)skb->data;
468 err_code = __le32_to_cpu(ev->err_code);
469 freq = __le32_to_cpu(ev->freq);
470 cmd_flags = __le32_to_cpu(ev->cmd_flags);
471 noise_floor = __le32_to_cpu(ev->noise_floor);
472 rx_clear_count = __le32_to_cpu(ev->rx_clear_count);
473 cycle_count = __le32_to_cpu(ev->cycle_count);
475 ath10k_dbg(ATH10K_DBG_WMI,
476 "chan info err_code %d freq %d cmd_flags %d noise_floor %d rx_clear_count %d cycle_count %d\n",
477 err_code, freq, cmd_flags, noise_floor, rx_clear_count,
480 spin_lock_bh(&ar->data_lock);
482 if (!ar->scan.in_progress) {
483 ath10k_warn("chan info event without a scan request?\n");
487 idx = freq_to_idx(ar, freq);
488 if (idx >= ARRAY_SIZE(ar->survey)) {
489 ath10k_warn("chan info: invalid frequency %d (idx %d out of bounds)\n",
494 if (cmd_flags & WMI_CHAN_INFO_FLAG_COMPLETE) {
495 /* During scanning chan info is reported twice for each
496 * visited channel. The reported cycle count is global
497 * and per-channel cycle count must be calculated */
499 cycle_count -= ar->survey_last_cycle_count;
500 rx_clear_count -= ar->survey_last_rx_clear_count;
502 survey = &ar->survey[idx];
503 survey->channel_time = WMI_CHAN_INFO_MSEC(cycle_count);
504 survey->channel_time_rx = WMI_CHAN_INFO_MSEC(rx_clear_count);
505 survey->noise = noise_floor;
506 survey->filled = SURVEY_INFO_CHANNEL_TIME |
507 SURVEY_INFO_CHANNEL_TIME_RX |
508 SURVEY_INFO_NOISE_DBM;
511 ar->survey_last_rx_clear_count = rx_clear_count;
512 ar->survey_last_cycle_count = cycle_count;
515 spin_unlock_bh(&ar->data_lock);
518 static void ath10k_wmi_event_echo(struct ath10k *ar, struct sk_buff *skb)
520 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ECHO_EVENTID\n");
523 static void ath10k_wmi_event_debug_mesg(struct ath10k *ar, struct sk_buff *skb)
525 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_MESG_EVENTID\n");
528 static void ath10k_wmi_event_update_stats(struct ath10k *ar,
531 struct wmi_stats_event *ev = (struct wmi_stats_event *)skb->data;
533 ath10k_dbg(ATH10K_DBG_WMI, "WMI_UPDATE_STATS_EVENTID\n");
535 ath10k_debug_read_target_stats(ar, ev);
538 static void ath10k_wmi_event_vdev_start_resp(struct ath10k *ar,
541 struct wmi_vdev_start_response_event *ev;
543 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_START_RESP_EVENTID\n");
545 ev = (struct wmi_vdev_start_response_event *)skb->data;
547 if (WARN_ON(__le32_to_cpu(ev->status)))
550 complete(&ar->vdev_setup_done);
553 static void ath10k_wmi_event_vdev_stopped(struct ath10k *ar,
556 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_STOPPED_EVENTID\n");
557 complete(&ar->vdev_setup_done);
560 static void ath10k_wmi_event_peer_sta_kickout(struct ath10k *ar,
563 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PEER_STA_KICKOUT_EVENTID\n");
569 * We don't report to mac80211 sleep state of connected
570 * stations. Due to this mac80211 can't fill in TIM IE
573 * I know of no way of getting nullfunc frames that contain
574 * sleep transition from connected stations - these do not
575 * seem to be sent from the target to the host. There also
576 * doesn't seem to be a dedicated event for that. So the
577 * only way left to do this would be to read tim_bitmap
580 * We could probably try using tim_bitmap from SWBA to tell
581 * mac80211 which stations are asleep and which are not. The
582 * problem here is calling mac80211 functions so many times
583 * could take too long and make us miss the time to submit
584 * the beacon to the target.
586 * So as a workaround we try to extend the TIM IE if there
587 * is unicast buffered for stations with aid > 7 and fill it
590 static void ath10k_wmi_update_tim(struct ath10k *ar,
591 struct ath10k_vif *arvif,
593 struct wmi_bcn_info *bcn_info)
595 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)bcn->data;
596 struct ieee80211_tim_ie *tim;
600 /* if next SWBA has no tim_changed the tim_bitmap is garbage.
601 * we must copy the bitmap upon change and reuse it later */
602 if (__le32_to_cpu(bcn_info->tim_info.tim_changed)) {
605 BUILD_BUG_ON(sizeof(arvif->u.ap.tim_bitmap) !=
606 sizeof(bcn_info->tim_info.tim_bitmap));
608 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++) {
609 __le32 t = bcn_info->tim_info.tim_bitmap[i / 4];
610 u32 v = __le32_to_cpu(t);
611 arvif->u.ap.tim_bitmap[i] = (v >> ((i % 4) * 8)) & 0xFF;
614 /* FW reports either length 0 or 16
615 * so we calculate this on our own */
616 arvif->u.ap.tim_len = 0;
617 for (i = 0; i < sizeof(arvif->u.ap.tim_bitmap); i++)
618 if (arvif->u.ap.tim_bitmap[i])
619 arvif->u.ap.tim_len = i;
621 arvif->u.ap.tim_len++;
625 ies += ieee80211_hdrlen(hdr->frame_control);
626 ies += 12; /* fixed parameters */
628 ie = (u8 *)cfg80211_find_ie(WLAN_EID_TIM, ies,
629 (u8 *)skb_tail_pointer(bcn) - ies);
631 if (arvif->vdev_type != WMI_VDEV_TYPE_IBSS)
632 ath10k_warn("no tim ie found;\n");
636 tim = (void *)ie + 2;
638 pvm_len = ie_len - 3; /* exclude dtim count, dtim period, bmap ctl */
640 if (pvm_len < arvif->u.ap.tim_len) {
641 int expand_size = sizeof(arvif->u.ap.tim_bitmap) - pvm_len;
642 int move_size = skb_tail_pointer(bcn) - (ie + 2 + ie_len);
643 void *next_ie = ie + 2 + ie_len;
645 if (skb_put(bcn, expand_size)) {
646 memmove(next_ie + expand_size, next_ie, move_size);
648 ie[1] += expand_size;
649 ie_len += expand_size;
650 pvm_len += expand_size;
652 ath10k_warn("tim expansion failed\n");
656 if (pvm_len > sizeof(arvif->u.ap.tim_bitmap)) {
657 ath10k_warn("tim pvm length is too great (%d)\n", pvm_len);
661 tim->bitmap_ctrl = !!__le32_to_cpu(bcn_info->tim_info.tim_mcast);
662 memcpy(tim->virtual_map, arvif->u.ap.tim_bitmap, pvm_len);
664 ath10k_dbg(ATH10K_DBG_MGMT, "dtim %d/%d mcast %d pvmlen %d\n",
665 tim->dtim_count, tim->dtim_period,
666 tim->bitmap_ctrl, pvm_len);
669 static void ath10k_p2p_fill_noa_ie(u8 *data, u32 len,
670 struct wmi_p2p_noa_info *noa)
672 struct ieee80211_p2p_noa_attr *noa_attr;
673 u8 ctwindow_oppps = noa->ctwindow_oppps;
674 u8 ctwindow = ctwindow_oppps >> WMI_P2P_OPPPS_CTWINDOW_OFFSET;
675 bool oppps = !!(ctwindow_oppps & WMI_P2P_OPPPS_ENABLE_BIT);
676 __le16 *noa_attr_len;
678 u8 noa_descriptors = noa->num_descriptors;
682 data[0] = WLAN_EID_VENDOR_SPECIFIC;
684 data[2] = (WLAN_OUI_WFA >> 16) & 0xff;
685 data[3] = (WLAN_OUI_WFA >> 8) & 0xff;
686 data[4] = (WLAN_OUI_WFA >> 0) & 0xff;
687 data[5] = WLAN_OUI_TYPE_WFA_P2P;
690 data[6] = IEEE80211_P2P_ATTR_ABSENCE_NOTICE;
691 noa_attr_len = (__le16 *)&data[7]; /* 2 bytes */
692 noa_attr = (struct ieee80211_p2p_noa_attr *)&data[9];
694 noa_attr->index = noa->index;
695 noa_attr->oppps_ctwindow = ctwindow;
697 noa_attr->oppps_ctwindow |= IEEE80211_P2P_OPPPS_ENABLE_BIT;
699 for (i = 0; i < noa_descriptors; i++) {
700 noa_attr->desc[i].count =
701 __le32_to_cpu(noa->descriptors[i].type_count);
702 noa_attr->desc[i].duration = noa->descriptors[i].duration;
703 noa_attr->desc[i].interval = noa->descriptors[i].interval;
704 noa_attr->desc[i].start_time = noa->descriptors[i].start_time;
707 attr_len = 2; /* index + oppps_ctwindow */
708 attr_len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
709 *noa_attr_len = __cpu_to_le16(attr_len);
712 static u32 ath10k_p2p_calc_noa_ie_len(struct wmi_p2p_noa_info *noa)
715 u8 noa_descriptors = noa->num_descriptors;
716 u8 opp_ps_info = noa->ctwindow_oppps;
717 bool opps_enabled = !!(opp_ps_info & WMI_P2P_OPPPS_ENABLE_BIT);
720 if (!noa_descriptors && !opps_enabled)
723 len += 1 + 1 + 4; /* EID + len + OUI */
724 len += 1 + 2; /* noa attr + attr len */
725 len += 1 + 1; /* index + oppps_ctwindow */
726 len += noa_descriptors * sizeof(struct ieee80211_p2p_noa_desc);
731 static void ath10k_wmi_update_noa(struct ath10k *ar, struct ath10k_vif *arvif,
733 struct wmi_bcn_info *bcn_info)
735 struct wmi_p2p_noa_info *noa = &bcn_info->p2p_noa_info;
736 u8 *new_data, *old_data = arvif->u.ap.noa_data;
739 if (arvif->vdev_subtype != WMI_VDEV_SUBTYPE_P2P_GO)
742 ath10k_dbg(ATH10K_DBG_MGMT, "noa changed: %d\n", noa->changed);
743 if (noa->changed & WMI_P2P_NOA_CHANGED_BIT) {
744 new_len = ath10k_p2p_calc_noa_ie_len(noa);
748 new_data = kmalloc(new_len, GFP_ATOMIC);
752 ath10k_p2p_fill_noa_ie(new_data, new_len, noa);
754 spin_lock_bh(&ar->data_lock);
755 arvif->u.ap.noa_data = new_data;
756 arvif->u.ap.noa_len = new_len;
757 spin_unlock_bh(&ar->data_lock);
761 if (arvif->u.ap.noa_data)
762 if (!pskb_expand_head(bcn, 0, arvif->u.ap.noa_len, GFP_ATOMIC))
763 memcpy(skb_put(bcn, arvif->u.ap.noa_len),
764 arvif->u.ap.noa_data,
765 arvif->u.ap.noa_len);
769 spin_lock_bh(&ar->data_lock);
770 arvif->u.ap.noa_data = NULL;
771 arvif->u.ap.noa_len = 0;
772 spin_unlock_bh(&ar->data_lock);
777 static void ath10k_wmi_event_host_swba(struct ath10k *ar, struct sk_buff *skb)
779 struct wmi_host_swba_event *ev;
782 struct wmi_bcn_info *bcn_info;
783 struct ath10k_vif *arvif;
787 ath10k_dbg(ATH10K_DBG_MGMT, "WMI_HOST_SWBA_EVENTID\n");
789 ev = (struct wmi_host_swba_event *)skb->data;
790 map = __le32_to_cpu(ev->vdev_map);
792 ath10k_dbg(ATH10K_DBG_MGMT, "host swba:\n"
796 for (; map; map >>= 1, vdev_id++) {
802 if (i >= WMI_MAX_AP_VDEV) {
803 ath10k_warn("swba has corrupted vdev map\n");
807 bcn_info = &ev->bcn_info[i];
809 ath10k_dbg(ATH10K_DBG_MGMT,
814 "--tim_num_ps_pending %d\n"
815 "--tim_bitmap 0x%08x%08x%08x%08x\n",
817 __le32_to_cpu(bcn_info->tim_info.tim_len),
818 __le32_to_cpu(bcn_info->tim_info.tim_mcast),
819 __le32_to_cpu(bcn_info->tim_info.tim_changed),
820 __le32_to_cpu(bcn_info->tim_info.tim_num_ps_pending),
821 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[3]),
822 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[2]),
823 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[1]),
824 __le32_to_cpu(bcn_info->tim_info.tim_bitmap[0]));
826 arvif = ath10k_get_arvif(ar, vdev_id);
828 ath10k_warn("no vif for vdev_id %d found\n", vdev_id);
832 bcn = ieee80211_beacon_get(ar->hw, arvif->vif);
834 ath10k_warn("could not get mac80211 beacon\n");
838 ath10k_tx_h_seq_no(bcn);
839 ath10k_wmi_update_tim(ar, arvif, bcn, bcn_info);
840 ath10k_wmi_update_noa(ar, arvif, bcn, bcn_info);
842 spin_lock_bh(&ar->data_lock);
844 ath10k_warn("SWBA overrun on vdev %d\n",
846 dev_kfree_skb_any(arvif->beacon);
851 ath10k_wmi_tx_beacon_nowait(arvif);
852 spin_unlock_bh(&ar->data_lock);
856 static void ath10k_wmi_event_tbttoffset_update(struct ath10k *ar,
859 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TBTTOFFSET_UPDATE_EVENTID\n");
862 static void ath10k_wmi_event_phyerr(struct ath10k *ar, struct sk_buff *skb)
864 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PHYERR_EVENTID\n");
867 static void ath10k_wmi_event_roam(struct ath10k *ar, struct sk_buff *skb)
869 ath10k_dbg(ATH10K_DBG_WMI, "WMI_ROAM_EVENTID\n");
872 static void ath10k_wmi_event_profile_match(struct ath10k *ar,
875 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PROFILE_MATCH\n");
878 static void ath10k_wmi_event_debug_print(struct ath10k *ar,
881 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DEBUG_PRINT_EVENTID\n");
884 static void ath10k_wmi_event_pdev_qvit(struct ath10k *ar, struct sk_buff *skb)
886 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_QVIT_EVENTID\n");
889 static void ath10k_wmi_event_wlan_profile_data(struct ath10k *ar,
892 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WLAN_PROFILE_DATA_EVENTID\n");
895 static void ath10k_wmi_event_rtt_measurement_report(struct ath10k *ar,
898 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_MEASUREMENT_REPORT_EVENTID\n");
901 static void ath10k_wmi_event_tsf_measurement_report(struct ath10k *ar,
904 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TSF_MEASUREMENT_REPORT_EVENTID\n");
907 static void ath10k_wmi_event_rtt_error_report(struct ath10k *ar,
910 ath10k_dbg(ATH10K_DBG_WMI, "WMI_RTT_ERROR_REPORT_EVENTID\n");
913 static void ath10k_wmi_event_wow_wakeup_host(struct ath10k *ar,
916 ath10k_dbg(ATH10K_DBG_WMI, "WMI_WOW_WAKEUP_HOST_EVENTID\n");
919 static void ath10k_wmi_event_dcs_interference(struct ath10k *ar,
922 ath10k_dbg(ATH10K_DBG_WMI, "WMI_DCS_INTERFERENCE_EVENTID\n");
925 static void ath10k_wmi_event_pdev_tpc_config(struct ath10k *ar,
928 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_TPC_CONFIG_EVENTID\n");
931 static void ath10k_wmi_event_pdev_ftm_intg(struct ath10k *ar,
934 ath10k_dbg(ATH10K_DBG_WMI, "WMI_PDEV_FTM_INTG_EVENTID\n");
937 static void ath10k_wmi_event_gtk_offload_status(struct ath10k *ar,
940 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_OFFLOAD_STATUS_EVENTID\n");
943 static void ath10k_wmi_event_gtk_rekey_fail(struct ath10k *ar,
946 ath10k_dbg(ATH10K_DBG_WMI, "WMI_GTK_REKEY_FAIL_EVENTID\n");
949 static void ath10k_wmi_event_delba_complete(struct ath10k *ar,
952 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_DELBA_COMPLETE_EVENTID\n");
955 static void ath10k_wmi_event_addba_complete(struct ath10k *ar,
958 ath10k_dbg(ATH10K_DBG_WMI, "WMI_TX_ADDBA_COMPLETE_EVENTID\n");
961 static void ath10k_wmi_event_vdev_install_key_complete(struct ath10k *ar,
964 ath10k_dbg(ATH10K_DBG_WMI, "WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID\n");
967 static void ath10k_wmi_service_ready_event_rx(struct ath10k *ar,
970 struct wmi_service_ready_event *ev = (void *)skb->data;
972 if (skb->len < sizeof(*ev)) {
973 ath10k_warn("Service ready event was %d B but expected %zu B. Wrong firmware version?\n",
974 skb->len, sizeof(*ev));
978 ar->hw_min_tx_power = __le32_to_cpu(ev->hw_min_tx_power);
979 ar->hw_max_tx_power = __le32_to_cpu(ev->hw_max_tx_power);
980 ar->ht_cap_info = __le32_to_cpu(ev->ht_cap_info);
981 ar->vht_cap_info = __le32_to_cpu(ev->vht_cap_info);
982 ar->fw_version_major =
983 (__le32_to_cpu(ev->sw_version) & 0xff000000) >> 24;
984 ar->fw_version_minor = (__le32_to_cpu(ev->sw_version) & 0x00ffffff);
985 ar->fw_version_release =
986 (__le32_to_cpu(ev->sw_version_1) & 0xffff0000) >> 16;
987 ar->fw_version_build = (__le32_to_cpu(ev->sw_version_1) & 0x0000ffff);
988 ar->phy_capability = __le32_to_cpu(ev->phy_capability);
989 ar->num_rf_chains = __le32_to_cpu(ev->num_rf_chains);
991 if (ar->fw_version_build > 636)
992 set_bit(ATH10K_FW_FEATURE_EXT_WMI_MGMT_RX, ar->fw_features);
994 if (ar->num_rf_chains > WMI_MAX_SPATIAL_STREAM) {
995 ath10k_warn("hardware advertises support for more spatial streams than it should (%d > %d)\n",
996 ar->num_rf_chains, WMI_MAX_SPATIAL_STREAM);
997 ar->num_rf_chains = WMI_MAX_SPATIAL_STREAM;
1000 ar->ath_common.regulatory.current_rd =
1001 __le32_to_cpu(ev->hal_reg_capabilities.eeprom_rd);
1003 ath10k_debug_read_service_map(ar, ev->wmi_service_bitmap,
1004 sizeof(ev->wmi_service_bitmap));
1006 if (strlen(ar->hw->wiphy->fw_version) == 0) {
1007 snprintf(ar->hw->wiphy->fw_version,
1008 sizeof(ar->hw->wiphy->fw_version),
1010 ar->fw_version_major,
1011 ar->fw_version_minor,
1012 ar->fw_version_release,
1013 ar->fw_version_build);
1016 /* FIXME: it probably should be better to support this */
1017 if (__le32_to_cpu(ev->num_mem_reqs) > 0) {
1018 ath10k_warn("target requested %d memory chunks; ignoring\n",
1019 __le32_to_cpu(ev->num_mem_reqs));
1022 ath10k_dbg(ATH10K_DBG_WMI,
1023 "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",
1024 __le32_to_cpu(ev->sw_version),
1025 __le32_to_cpu(ev->sw_version_1),
1026 __le32_to_cpu(ev->abi_version),
1027 __le32_to_cpu(ev->phy_capability),
1028 __le32_to_cpu(ev->ht_cap_info),
1029 __le32_to_cpu(ev->vht_cap_info),
1030 __le32_to_cpu(ev->vht_supp_mcs),
1031 __le32_to_cpu(ev->sys_cap_info),
1032 __le32_to_cpu(ev->num_mem_reqs),
1033 __le32_to_cpu(ev->num_rf_chains));
1035 complete(&ar->wmi.service_ready);
1038 static int ath10k_wmi_ready_event_rx(struct ath10k *ar, struct sk_buff *skb)
1040 struct wmi_ready_event *ev = (struct wmi_ready_event *)skb->data;
1042 if (WARN_ON(skb->len < sizeof(*ev)))
1045 memcpy(ar->mac_addr, ev->mac_addr.addr, ETH_ALEN);
1047 ath10k_dbg(ATH10K_DBG_WMI,
1048 "wmi event ready sw_version %u abi_version %u mac_addr %pM status %d\n",
1049 __le32_to_cpu(ev->sw_version),
1050 __le32_to_cpu(ev->abi_version),
1052 __le32_to_cpu(ev->status));
1054 complete(&ar->wmi.unified_ready);
1058 static void ath10k_wmi_process_rx(struct ath10k *ar, struct sk_buff *skb)
1060 struct wmi_cmd_hdr *cmd_hdr;
1061 enum wmi_event_id id;
1064 cmd_hdr = (struct wmi_cmd_hdr *)skb->data;
1065 id = MS(__le32_to_cpu(cmd_hdr->cmd_id), WMI_CMD_HDR_CMD_ID);
1067 if (skb_pull(skb, sizeof(struct wmi_cmd_hdr)) == NULL)
1072 trace_ath10k_wmi_event(id, skb->data, skb->len);
1075 case WMI_MGMT_RX_EVENTID:
1076 ath10k_wmi_event_mgmt_rx(ar, skb);
1077 /* mgmt_rx() owns the skb now! */
1079 case WMI_SCAN_EVENTID:
1080 ath10k_wmi_event_scan(ar, skb);
1082 case WMI_CHAN_INFO_EVENTID:
1083 ath10k_wmi_event_chan_info(ar, skb);
1085 case WMI_ECHO_EVENTID:
1086 ath10k_wmi_event_echo(ar, skb);
1088 case WMI_DEBUG_MESG_EVENTID:
1089 ath10k_wmi_event_debug_mesg(ar, skb);
1091 case WMI_UPDATE_STATS_EVENTID:
1092 ath10k_wmi_event_update_stats(ar, skb);
1094 case WMI_VDEV_START_RESP_EVENTID:
1095 ath10k_wmi_event_vdev_start_resp(ar, skb);
1097 case WMI_VDEV_STOPPED_EVENTID:
1098 ath10k_wmi_event_vdev_stopped(ar, skb);
1100 case WMI_PEER_STA_KICKOUT_EVENTID:
1101 ath10k_wmi_event_peer_sta_kickout(ar, skb);
1103 case WMI_HOST_SWBA_EVENTID:
1104 ath10k_wmi_event_host_swba(ar, skb);
1106 case WMI_TBTTOFFSET_UPDATE_EVENTID:
1107 ath10k_wmi_event_tbttoffset_update(ar, skb);
1109 case WMI_PHYERR_EVENTID:
1110 ath10k_wmi_event_phyerr(ar, skb);
1112 case WMI_ROAM_EVENTID:
1113 ath10k_wmi_event_roam(ar, skb);
1115 case WMI_PROFILE_MATCH:
1116 ath10k_wmi_event_profile_match(ar, skb);
1118 case WMI_DEBUG_PRINT_EVENTID:
1119 ath10k_wmi_event_debug_print(ar, skb);
1121 case WMI_PDEV_QVIT_EVENTID:
1122 ath10k_wmi_event_pdev_qvit(ar, skb);
1124 case WMI_WLAN_PROFILE_DATA_EVENTID:
1125 ath10k_wmi_event_wlan_profile_data(ar, skb);
1127 case WMI_RTT_MEASUREMENT_REPORT_EVENTID:
1128 ath10k_wmi_event_rtt_measurement_report(ar, skb);
1130 case WMI_TSF_MEASUREMENT_REPORT_EVENTID:
1131 ath10k_wmi_event_tsf_measurement_report(ar, skb);
1133 case WMI_RTT_ERROR_REPORT_EVENTID:
1134 ath10k_wmi_event_rtt_error_report(ar, skb);
1136 case WMI_WOW_WAKEUP_HOST_EVENTID:
1137 ath10k_wmi_event_wow_wakeup_host(ar, skb);
1139 case WMI_DCS_INTERFERENCE_EVENTID:
1140 ath10k_wmi_event_dcs_interference(ar, skb);
1142 case WMI_PDEV_TPC_CONFIG_EVENTID:
1143 ath10k_wmi_event_pdev_tpc_config(ar, skb);
1145 case WMI_PDEV_FTM_INTG_EVENTID:
1146 ath10k_wmi_event_pdev_ftm_intg(ar, skb);
1148 case WMI_GTK_OFFLOAD_STATUS_EVENTID:
1149 ath10k_wmi_event_gtk_offload_status(ar, skb);
1151 case WMI_GTK_REKEY_FAIL_EVENTID:
1152 ath10k_wmi_event_gtk_rekey_fail(ar, skb);
1154 case WMI_TX_DELBA_COMPLETE_EVENTID:
1155 ath10k_wmi_event_delba_complete(ar, skb);
1157 case WMI_TX_ADDBA_COMPLETE_EVENTID:
1158 ath10k_wmi_event_addba_complete(ar, skb);
1160 case WMI_VDEV_INSTALL_KEY_COMPLETE_EVENTID:
1161 ath10k_wmi_event_vdev_install_key_complete(ar, skb);
1163 case WMI_SERVICE_READY_EVENTID:
1164 ath10k_wmi_service_ready_event_rx(ar, skb);
1166 case WMI_READY_EVENTID:
1167 ath10k_wmi_ready_event_rx(ar, skb);
1170 ath10k_warn("Unknown eventid: %d\n", id);
1177 /* WMI Initialization functions */
1178 int ath10k_wmi_attach(struct ath10k *ar)
1180 init_completion(&ar->wmi.service_ready);
1181 init_completion(&ar->wmi.unified_ready);
1182 init_waitqueue_head(&ar->wmi.tx_credits_wq);
1187 void ath10k_wmi_detach(struct ath10k *ar)
1191 int ath10k_wmi_connect_htc_service(struct ath10k *ar)
1194 struct ath10k_htc_svc_conn_req conn_req;
1195 struct ath10k_htc_svc_conn_resp conn_resp;
1197 memset(&conn_req, 0, sizeof(conn_req));
1198 memset(&conn_resp, 0, sizeof(conn_resp));
1200 /* these fields are the same for all service endpoints */
1201 conn_req.ep_ops.ep_tx_complete = ath10k_wmi_htc_tx_complete;
1202 conn_req.ep_ops.ep_rx_complete = ath10k_wmi_process_rx;
1203 conn_req.ep_ops.ep_tx_credits = ath10k_wmi_op_ep_tx_credits;
1205 /* connect to control service */
1206 conn_req.service_id = ATH10K_HTC_SVC_ID_WMI_CONTROL;
1208 status = ath10k_htc_connect_service(&ar->htc, &conn_req, &conn_resp);
1210 ath10k_warn("failed to connect to WMI CONTROL service status: %d\n",
1215 ar->wmi.eid = conn_resp.eid;
1219 int ath10k_wmi_pdev_set_regdomain(struct ath10k *ar, u16 rd, u16 rd2g,
1220 u16 rd5g, u16 ctl2g, u16 ctl5g)
1222 struct wmi_pdev_set_regdomain_cmd *cmd;
1223 struct sk_buff *skb;
1225 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1229 cmd = (struct wmi_pdev_set_regdomain_cmd *)skb->data;
1230 cmd->reg_domain = __cpu_to_le32(rd);
1231 cmd->reg_domain_2G = __cpu_to_le32(rd2g);
1232 cmd->reg_domain_5G = __cpu_to_le32(rd5g);
1233 cmd->conformance_test_limit_2G = __cpu_to_le32(ctl2g);
1234 cmd->conformance_test_limit_5G = __cpu_to_le32(ctl5g);
1236 ath10k_dbg(ATH10K_DBG_WMI,
1237 "wmi pdev regdomain rd %x rd2g %x rd5g %x ctl2g %x ctl5g %x\n",
1238 rd, rd2g, rd5g, ctl2g, ctl5g);
1240 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_REGDOMAIN_CMDID);
1243 int ath10k_wmi_pdev_set_channel(struct ath10k *ar,
1244 const struct wmi_channel_arg *arg)
1246 struct wmi_set_channel_cmd *cmd;
1247 struct sk_buff *skb;
1252 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1256 cmd = (struct wmi_set_channel_cmd *)skb->data;
1257 cmd->chan.mhz = __cpu_to_le32(arg->freq);
1258 cmd->chan.band_center_freq1 = __cpu_to_le32(arg->freq);
1259 cmd->chan.mode = arg->mode;
1260 cmd->chan.min_power = arg->min_power;
1261 cmd->chan.max_power = arg->max_power;
1262 cmd->chan.reg_power = arg->max_reg_power;
1263 cmd->chan.reg_classid = arg->reg_class_id;
1264 cmd->chan.antenna_max = arg->max_antenna_gain;
1266 ath10k_dbg(ATH10K_DBG_WMI,
1267 "wmi set channel mode %d freq %d\n",
1268 arg->mode, arg->freq);
1270 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_CHANNEL_CMDID);
1273 int ath10k_wmi_pdev_suspend_target(struct ath10k *ar)
1275 struct wmi_pdev_suspend_cmd *cmd;
1276 struct sk_buff *skb;
1278 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1282 cmd = (struct wmi_pdev_suspend_cmd *)skb->data;
1283 cmd->suspend_opt = WMI_PDEV_SUSPEND;
1285 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SUSPEND_CMDID);
1288 int ath10k_wmi_pdev_resume_target(struct ath10k *ar)
1290 struct sk_buff *skb;
1292 skb = ath10k_wmi_alloc_skb(0);
1296 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_RESUME_CMDID);
1299 int ath10k_wmi_pdev_set_param(struct ath10k *ar, enum wmi_pdev_param id,
1302 struct wmi_pdev_set_param_cmd *cmd;
1303 struct sk_buff *skb;
1305 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1309 cmd = (struct wmi_pdev_set_param_cmd *)skb->data;
1310 cmd->param_id = __cpu_to_le32(id);
1311 cmd->param_value = __cpu_to_le32(value);
1313 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set param %d value %d\n",
1315 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_PARAM_CMDID);
1318 int ath10k_wmi_cmd_init(struct ath10k *ar)
1320 struct wmi_init_cmd *cmd;
1321 struct sk_buff *buf;
1322 struct wmi_resource_config config = {};
1325 config.num_vdevs = __cpu_to_le32(TARGET_NUM_VDEVS);
1326 config.num_peers = __cpu_to_le32(TARGET_NUM_PEERS + TARGET_NUM_VDEVS);
1327 config.num_offload_peers = __cpu_to_le32(TARGET_NUM_OFFLOAD_PEERS);
1329 config.num_offload_reorder_bufs =
1330 __cpu_to_le32(TARGET_NUM_OFFLOAD_REORDER_BUFS);
1332 config.num_peer_keys = __cpu_to_le32(TARGET_NUM_PEER_KEYS);
1333 config.num_tids = __cpu_to_le32(TARGET_NUM_TIDS);
1334 config.ast_skid_limit = __cpu_to_le32(TARGET_AST_SKID_LIMIT);
1335 config.tx_chain_mask = __cpu_to_le32(TARGET_TX_CHAIN_MASK);
1336 config.rx_chain_mask = __cpu_to_le32(TARGET_RX_CHAIN_MASK);
1337 config.rx_timeout_pri_vo = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1338 config.rx_timeout_pri_vi = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1339 config.rx_timeout_pri_be = __cpu_to_le32(TARGET_RX_TIMEOUT_LO_PRI);
1340 config.rx_timeout_pri_bk = __cpu_to_le32(TARGET_RX_TIMEOUT_HI_PRI);
1341 config.rx_decap_mode = __cpu_to_le32(TARGET_RX_DECAP_MODE);
1343 config.scan_max_pending_reqs =
1344 __cpu_to_le32(TARGET_SCAN_MAX_PENDING_REQS);
1346 config.bmiss_offload_max_vdev =
1347 __cpu_to_le32(TARGET_BMISS_OFFLOAD_MAX_VDEV);
1349 config.roam_offload_max_vdev =
1350 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_VDEV);
1352 config.roam_offload_max_ap_profiles =
1353 __cpu_to_le32(TARGET_ROAM_OFFLOAD_MAX_AP_PROFILES);
1355 config.num_mcast_groups = __cpu_to_le32(TARGET_NUM_MCAST_GROUPS);
1356 config.num_mcast_table_elems =
1357 __cpu_to_le32(TARGET_NUM_MCAST_TABLE_ELEMS);
1359 config.mcast2ucast_mode = __cpu_to_le32(TARGET_MCAST2UCAST_MODE);
1360 config.tx_dbg_log_size = __cpu_to_le32(TARGET_TX_DBG_LOG_SIZE);
1361 config.num_wds_entries = __cpu_to_le32(TARGET_NUM_WDS_ENTRIES);
1362 config.dma_burst_size = __cpu_to_le32(TARGET_DMA_BURST_SIZE);
1363 config.mac_aggr_delim = __cpu_to_le32(TARGET_MAC_AGGR_DELIM);
1365 val = TARGET_RX_SKIP_DEFRAG_TIMEOUT_DUP_DETECTION_CHECK;
1366 config.rx_skip_defrag_timeout_dup_detection_check = __cpu_to_le32(val);
1368 config.vow_config = __cpu_to_le32(TARGET_VOW_CONFIG);
1370 config.gtk_offload_max_vdev =
1371 __cpu_to_le32(TARGET_GTK_OFFLOAD_MAX_VDEV);
1373 config.num_msdu_desc = __cpu_to_le32(TARGET_NUM_MSDU_DESC);
1374 config.max_frag_entries = __cpu_to_le32(TARGET_MAX_FRAG_ENTRIES);
1376 buf = ath10k_wmi_alloc_skb(sizeof(*cmd));
1380 cmd = (struct wmi_init_cmd *)buf->data;
1381 cmd->num_host_mem_chunks = 0;
1382 memcpy(&cmd->resource_config, &config, sizeof(config));
1384 ath10k_dbg(ATH10K_DBG_WMI, "wmi init\n");
1385 return ath10k_wmi_cmd_send(ar, buf, WMI_INIT_CMDID);
1388 static int ath10k_wmi_start_scan_calc_len(const struct wmi_start_scan_arg *arg)
1392 len = sizeof(struct wmi_start_scan_cmd);
1397 if (arg->ie_len > WLAN_SCAN_PARAMS_MAX_IE_LEN)
1400 len += sizeof(struct wmi_ie_data);
1401 len += roundup(arg->ie_len, 4);
1404 if (arg->n_channels) {
1407 if (arg->n_channels > ARRAY_SIZE(arg->channels))
1410 len += sizeof(struct wmi_chan_list);
1411 len += sizeof(__le32) * arg->n_channels;
1417 if (arg->n_ssids > WLAN_SCAN_PARAMS_MAX_SSID)
1420 len += sizeof(struct wmi_ssid_list);
1421 len += sizeof(struct wmi_ssid) * arg->n_ssids;
1424 if (arg->n_bssids) {
1427 if (arg->n_bssids > WLAN_SCAN_PARAMS_MAX_BSSID)
1430 len += sizeof(struct wmi_bssid_list);
1431 len += sizeof(struct wmi_mac_addr) * arg->n_bssids;
1437 int ath10k_wmi_start_scan(struct ath10k *ar,
1438 const struct wmi_start_scan_arg *arg)
1440 struct wmi_start_scan_cmd *cmd;
1441 struct sk_buff *skb;
1442 struct wmi_ie_data *ie;
1443 struct wmi_chan_list *channels;
1444 struct wmi_ssid_list *ssids;
1445 struct wmi_bssid_list *bssids;
1452 len = ath10k_wmi_start_scan_calc_len(arg);
1454 return len; /* len contains error code here */
1456 skb = ath10k_wmi_alloc_skb(len);
1460 scan_id = WMI_HOST_SCAN_REQ_ID_PREFIX;
1461 scan_id |= arg->scan_id;
1463 scan_req_id = WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1464 scan_req_id |= arg->scan_req_id;
1466 cmd = (struct wmi_start_scan_cmd *)skb->data;
1467 cmd->scan_id = __cpu_to_le32(scan_id);
1468 cmd->scan_req_id = __cpu_to_le32(scan_req_id);
1469 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1470 cmd->scan_priority = __cpu_to_le32(arg->scan_priority);
1471 cmd->notify_scan_events = __cpu_to_le32(arg->notify_scan_events);
1472 cmd->dwell_time_active = __cpu_to_le32(arg->dwell_time_active);
1473 cmd->dwell_time_passive = __cpu_to_le32(arg->dwell_time_passive);
1474 cmd->min_rest_time = __cpu_to_le32(arg->min_rest_time);
1475 cmd->max_rest_time = __cpu_to_le32(arg->max_rest_time);
1476 cmd->repeat_probe_time = __cpu_to_le32(arg->repeat_probe_time);
1477 cmd->probe_spacing_time = __cpu_to_le32(arg->probe_spacing_time);
1478 cmd->idle_time = __cpu_to_le32(arg->idle_time);
1479 cmd->max_scan_time = __cpu_to_le32(arg->max_scan_time);
1480 cmd->probe_delay = __cpu_to_le32(arg->probe_delay);
1481 cmd->scan_ctrl_flags = __cpu_to_le32(arg->scan_ctrl_flags);
1483 /* TLV list starts after fields included in the struct */
1486 if (arg->n_channels) {
1487 channels = (void *)skb->data + off;
1488 channels->tag = __cpu_to_le32(WMI_CHAN_LIST_TAG);
1489 channels->num_chan = __cpu_to_le32(arg->n_channels);
1491 for (i = 0; i < arg->n_channels; i++)
1492 channels->channel_list[i] =
1493 __cpu_to_le32(arg->channels[i]);
1495 off += sizeof(*channels);
1496 off += sizeof(__le32) * arg->n_channels;
1500 ssids = (void *)skb->data + off;
1501 ssids->tag = __cpu_to_le32(WMI_SSID_LIST_TAG);
1502 ssids->num_ssids = __cpu_to_le32(arg->n_ssids);
1504 for (i = 0; i < arg->n_ssids; i++) {
1505 ssids->ssids[i].ssid_len =
1506 __cpu_to_le32(arg->ssids[i].len);
1507 memcpy(&ssids->ssids[i].ssid,
1512 off += sizeof(*ssids);
1513 off += sizeof(struct wmi_ssid) * arg->n_ssids;
1516 if (arg->n_bssids) {
1517 bssids = (void *)skb->data + off;
1518 bssids->tag = __cpu_to_le32(WMI_BSSID_LIST_TAG);
1519 bssids->num_bssid = __cpu_to_le32(arg->n_bssids);
1521 for (i = 0; i < arg->n_bssids; i++)
1522 memcpy(&bssids->bssid_list[i],
1523 arg->bssids[i].bssid,
1526 off += sizeof(*bssids);
1527 off += sizeof(struct wmi_mac_addr) * arg->n_bssids;
1531 ie = (void *)skb->data + off;
1532 ie->tag = __cpu_to_le32(WMI_IE_TAG);
1533 ie->ie_len = __cpu_to_le32(arg->ie_len);
1534 memcpy(ie->ie_data, arg->ie, arg->ie_len);
1537 off += roundup(arg->ie_len, 4);
1540 if (off != skb->len) {
1545 ath10k_dbg(ATH10K_DBG_WMI, "wmi start scan\n");
1546 return ath10k_wmi_cmd_send(ar, skb, WMI_START_SCAN_CMDID);
1549 void ath10k_wmi_start_scan_init(struct ath10k *ar,
1550 struct wmi_start_scan_arg *arg)
1552 /* setup commonly used values */
1553 arg->scan_req_id = 1;
1554 arg->scan_priority = WMI_SCAN_PRIORITY_LOW;
1555 arg->dwell_time_active = 50;
1556 arg->dwell_time_passive = 150;
1557 arg->min_rest_time = 50;
1558 arg->max_rest_time = 500;
1559 arg->repeat_probe_time = 0;
1560 arg->probe_spacing_time = 0;
1562 arg->max_scan_time = 5000;
1563 arg->probe_delay = 5;
1564 arg->notify_scan_events = WMI_SCAN_EVENT_STARTED
1565 | WMI_SCAN_EVENT_COMPLETED
1566 | WMI_SCAN_EVENT_BSS_CHANNEL
1567 | WMI_SCAN_EVENT_FOREIGN_CHANNEL
1568 | WMI_SCAN_EVENT_DEQUEUED;
1569 arg->scan_ctrl_flags |= WMI_SCAN_ADD_OFDM_RATES;
1570 arg->scan_ctrl_flags |= WMI_SCAN_CHAN_STAT_EVENT;
1572 arg->bssids[0].bssid = "\xFF\xFF\xFF\xFF\xFF\xFF";
1575 int ath10k_wmi_stop_scan(struct ath10k *ar, const struct wmi_stop_scan_arg *arg)
1577 struct wmi_stop_scan_cmd *cmd;
1578 struct sk_buff *skb;
1582 if (arg->req_id > 0xFFF)
1584 if (arg->req_type == WMI_SCAN_STOP_ONE && arg->u.scan_id > 0xFFF)
1587 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1591 scan_id = arg->u.scan_id;
1592 scan_id |= WMI_HOST_SCAN_REQ_ID_PREFIX;
1594 req_id = arg->req_id;
1595 req_id |= WMI_HOST_SCAN_REQUESTOR_ID_PREFIX;
1597 cmd = (struct wmi_stop_scan_cmd *)skb->data;
1598 cmd->req_type = __cpu_to_le32(arg->req_type);
1599 cmd->vdev_id = __cpu_to_le32(arg->u.vdev_id);
1600 cmd->scan_id = __cpu_to_le32(scan_id);
1601 cmd->scan_req_id = __cpu_to_le32(req_id);
1603 ath10k_dbg(ATH10K_DBG_WMI,
1604 "wmi stop scan reqid %d req_type %d vdev/scan_id %d\n",
1605 arg->req_id, arg->req_type, arg->u.scan_id);
1606 return ath10k_wmi_cmd_send(ar, skb, WMI_STOP_SCAN_CMDID);
1609 int ath10k_wmi_vdev_create(struct ath10k *ar, u32 vdev_id,
1610 enum wmi_vdev_type type,
1611 enum wmi_vdev_subtype subtype,
1612 const u8 macaddr[ETH_ALEN])
1614 struct wmi_vdev_create_cmd *cmd;
1615 struct sk_buff *skb;
1617 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1621 cmd = (struct wmi_vdev_create_cmd *)skb->data;
1622 cmd->vdev_id = __cpu_to_le32(vdev_id);
1623 cmd->vdev_type = __cpu_to_le32(type);
1624 cmd->vdev_subtype = __cpu_to_le32(subtype);
1625 memcpy(cmd->vdev_macaddr.addr, macaddr, ETH_ALEN);
1627 ath10k_dbg(ATH10K_DBG_WMI,
1628 "WMI vdev create: id %d type %d subtype %d macaddr %pM\n",
1629 vdev_id, type, subtype, macaddr);
1631 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_CREATE_CMDID);
1634 int ath10k_wmi_vdev_delete(struct ath10k *ar, u32 vdev_id)
1636 struct wmi_vdev_delete_cmd *cmd;
1637 struct sk_buff *skb;
1639 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1643 cmd = (struct wmi_vdev_delete_cmd *)skb->data;
1644 cmd->vdev_id = __cpu_to_le32(vdev_id);
1646 ath10k_dbg(ATH10K_DBG_WMI,
1647 "WMI vdev delete id %d\n", vdev_id);
1649 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_DELETE_CMDID);
1652 static int ath10k_wmi_vdev_start_restart(struct ath10k *ar,
1653 const struct wmi_vdev_start_request_arg *arg,
1654 enum wmi_cmd_id cmd_id)
1656 struct wmi_vdev_start_request_cmd *cmd;
1657 struct sk_buff *skb;
1658 const char *cmdname;
1661 if (cmd_id != WMI_VDEV_START_REQUEST_CMDID &&
1662 cmd_id != WMI_VDEV_RESTART_REQUEST_CMDID)
1664 if (WARN_ON(arg->ssid && arg->ssid_len == 0))
1666 if (WARN_ON(arg->hidden_ssid && !arg->ssid))
1668 if (WARN_ON(arg->ssid_len > sizeof(cmd->ssid.ssid)))
1671 if (cmd_id == WMI_VDEV_START_REQUEST_CMDID)
1673 else if (cmd_id == WMI_VDEV_RESTART_REQUEST_CMDID)
1674 cmdname = "restart";
1676 return -EINVAL; /* should not happen, we already check cmd_id */
1678 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1682 if (arg->hidden_ssid)
1683 flags |= WMI_VDEV_START_HIDDEN_SSID;
1684 if (arg->pmf_enabled)
1685 flags |= WMI_VDEV_START_PMF_ENABLED;
1687 cmd = (struct wmi_vdev_start_request_cmd *)skb->data;
1688 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1689 cmd->disable_hw_ack = __cpu_to_le32(arg->disable_hw_ack);
1690 cmd->beacon_interval = __cpu_to_le32(arg->bcn_intval);
1691 cmd->dtim_period = __cpu_to_le32(arg->dtim_period);
1692 cmd->flags = __cpu_to_le32(flags);
1693 cmd->bcn_tx_rate = __cpu_to_le32(arg->bcn_tx_rate);
1694 cmd->bcn_tx_power = __cpu_to_le32(arg->bcn_tx_power);
1697 cmd->ssid.ssid_len = __cpu_to_le32(arg->ssid_len);
1698 memcpy(cmd->ssid.ssid, arg->ssid, arg->ssid_len);
1701 cmd->chan.mhz = __cpu_to_le32(arg->channel.freq);
1703 cmd->chan.band_center_freq1 =
1704 __cpu_to_le32(arg->channel.band_center_freq1);
1706 cmd->chan.mode = arg->channel.mode;
1707 cmd->chan.min_power = arg->channel.min_power;
1708 cmd->chan.max_power = arg->channel.max_power;
1709 cmd->chan.reg_power = arg->channel.max_reg_power;
1710 cmd->chan.reg_classid = arg->channel.reg_class_id;
1711 cmd->chan.antenna_max = arg->channel.max_antenna_gain;
1713 ath10k_dbg(ATH10K_DBG_WMI,
1714 "wmi vdev %s id 0x%x freq %d, mode %d, ch_flags: 0x%0X,"
1715 "max_power: %d\n", cmdname, arg->vdev_id, arg->channel.freq,
1716 arg->channel.mode, flags, arg->channel.max_power);
1718 return ath10k_wmi_cmd_send(ar, skb, cmd_id);
1721 int ath10k_wmi_vdev_start(struct ath10k *ar,
1722 const struct wmi_vdev_start_request_arg *arg)
1724 return ath10k_wmi_vdev_start_restart(ar, arg,
1725 WMI_VDEV_START_REQUEST_CMDID);
1728 int ath10k_wmi_vdev_restart(struct ath10k *ar,
1729 const struct wmi_vdev_start_request_arg *arg)
1731 return ath10k_wmi_vdev_start_restart(ar, arg,
1732 WMI_VDEV_RESTART_REQUEST_CMDID);
1735 int ath10k_wmi_vdev_stop(struct ath10k *ar, u32 vdev_id)
1737 struct wmi_vdev_stop_cmd *cmd;
1738 struct sk_buff *skb;
1740 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1744 cmd = (struct wmi_vdev_stop_cmd *)skb->data;
1745 cmd->vdev_id = __cpu_to_le32(vdev_id);
1747 ath10k_dbg(ATH10K_DBG_WMI, "wmi vdev stop id 0x%x\n", vdev_id);
1749 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_STOP_CMDID);
1752 int ath10k_wmi_vdev_up(struct ath10k *ar, u32 vdev_id, u32 aid, const u8 *bssid)
1754 struct wmi_vdev_up_cmd *cmd;
1755 struct sk_buff *skb;
1757 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1761 cmd = (struct wmi_vdev_up_cmd *)skb->data;
1762 cmd->vdev_id = __cpu_to_le32(vdev_id);
1763 cmd->vdev_assoc_id = __cpu_to_le32(aid);
1764 memcpy(&cmd->vdev_bssid.addr, bssid, ETH_ALEN);
1766 ath10k_dbg(ATH10K_DBG_WMI,
1767 "wmi mgmt vdev up id 0x%x assoc id %d bssid %pM\n",
1768 vdev_id, aid, bssid);
1770 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_UP_CMDID);
1773 int ath10k_wmi_vdev_down(struct ath10k *ar, u32 vdev_id)
1775 struct wmi_vdev_down_cmd *cmd;
1776 struct sk_buff *skb;
1778 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1782 cmd = (struct wmi_vdev_down_cmd *)skb->data;
1783 cmd->vdev_id = __cpu_to_le32(vdev_id);
1785 ath10k_dbg(ATH10K_DBG_WMI,
1786 "wmi mgmt vdev down id 0x%x\n", vdev_id);
1788 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_DOWN_CMDID);
1791 int ath10k_wmi_vdev_set_param(struct ath10k *ar, u32 vdev_id,
1792 enum wmi_vdev_param param_id, u32 param_value)
1794 struct wmi_vdev_set_param_cmd *cmd;
1795 struct sk_buff *skb;
1797 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1801 cmd = (struct wmi_vdev_set_param_cmd *)skb->data;
1802 cmd->vdev_id = __cpu_to_le32(vdev_id);
1803 cmd->param_id = __cpu_to_le32(param_id);
1804 cmd->param_value = __cpu_to_le32(param_value);
1806 ath10k_dbg(ATH10K_DBG_WMI,
1807 "wmi vdev id 0x%x set param %d value %d\n",
1808 vdev_id, param_id, param_value);
1810 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_SET_PARAM_CMDID);
1813 int ath10k_wmi_vdev_install_key(struct ath10k *ar,
1814 const struct wmi_vdev_install_key_arg *arg)
1816 struct wmi_vdev_install_key_cmd *cmd;
1817 struct sk_buff *skb;
1819 if (arg->key_cipher == WMI_CIPHER_NONE && arg->key_data != NULL)
1821 if (arg->key_cipher != WMI_CIPHER_NONE && arg->key_data == NULL)
1824 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->key_len);
1828 cmd = (struct wmi_vdev_install_key_cmd *)skb->data;
1829 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
1830 cmd->key_idx = __cpu_to_le32(arg->key_idx);
1831 cmd->key_flags = __cpu_to_le32(arg->key_flags);
1832 cmd->key_cipher = __cpu_to_le32(arg->key_cipher);
1833 cmd->key_len = __cpu_to_le32(arg->key_len);
1834 cmd->key_txmic_len = __cpu_to_le32(arg->key_txmic_len);
1835 cmd->key_rxmic_len = __cpu_to_le32(arg->key_rxmic_len);
1838 memcpy(cmd->peer_macaddr.addr, arg->macaddr, ETH_ALEN);
1840 memcpy(cmd->key_data, arg->key_data, arg->key_len);
1842 ath10k_dbg(ATH10K_DBG_WMI,
1843 "wmi vdev install key idx %d cipher %d len %d\n",
1844 arg->key_idx, arg->key_cipher, arg->key_len);
1845 return ath10k_wmi_cmd_send(ar, skb, WMI_VDEV_INSTALL_KEY_CMDID);
1848 int ath10k_wmi_peer_create(struct ath10k *ar, u32 vdev_id,
1849 const u8 peer_addr[ETH_ALEN])
1851 struct wmi_peer_create_cmd *cmd;
1852 struct sk_buff *skb;
1854 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1858 cmd = (struct wmi_peer_create_cmd *)skb->data;
1859 cmd->vdev_id = __cpu_to_le32(vdev_id);
1860 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1862 ath10k_dbg(ATH10K_DBG_WMI,
1863 "wmi peer create vdev_id %d peer_addr %pM\n",
1864 vdev_id, peer_addr);
1865 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_CREATE_CMDID);
1868 int ath10k_wmi_peer_delete(struct ath10k *ar, u32 vdev_id,
1869 const u8 peer_addr[ETH_ALEN])
1871 struct wmi_peer_delete_cmd *cmd;
1872 struct sk_buff *skb;
1874 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1878 cmd = (struct wmi_peer_delete_cmd *)skb->data;
1879 cmd->vdev_id = __cpu_to_le32(vdev_id);
1880 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1882 ath10k_dbg(ATH10K_DBG_WMI,
1883 "wmi peer delete vdev_id %d peer_addr %pM\n",
1884 vdev_id, peer_addr);
1885 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_DELETE_CMDID);
1888 int ath10k_wmi_peer_flush(struct ath10k *ar, u32 vdev_id,
1889 const u8 peer_addr[ETH_ALEN], u32 tid_bitmap)
1891 struct wmi_peer_flush_tids_cmd *cmd;
1892 struct sk_buff *skb;
1894 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1898 cmd = (struct wmi_peer_flush_tids_cmd *)skb->data;
1899 cmd->vdev_id = __cpu_to_le32(vdev_id);
1900 cmd->peer_tid_bitmap = __cpu_to_le32(tid_bitmap);
1901 memcpy(cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1903 ath10k_dbg(ATH10K_DBG_WMI,
1904 "wmi peer flush vdev_id %d peer_addr %pM tids %08x\n",
1905 vdev_id, peer_addr, tid_bitmap);
1906 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_FLUSH_TIDS_CMDID);
1909 int ath10k_wmi_peer_set_param(struct ath10k *ar, u32 vdev_id,
1910 const u8 *peer_addr, enum wmi_peer_param param_id,
1913 struct wmi_peer_set_param_cmd *cmd;
1914 struct sk_buff *skb;
1916 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1920 cmd = (struct wmi_peer_set_param_cmd *)skb->data;
1921 cmd->vdev_id = __cpu_to_le32(vdev_id);
1922 cmd->param_id = __cpu_to_le32(param_id);
1923 cmd->param_value = __cpu_to_le32(param_value);
1924 memcpy(&cmd->peer_macaddr.addr, peer_addr, ETH_ALEN);
1926 ath10k_dbg(ATH10K_DBG_WMI,
1927 "wmi vdev %d peer 0x%pM set param %d value %d\n",
1928 vdev_id, peer_addr, param_id, param_value);
1930 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_SET_PARAM_CMDID);
1933 int ath10k_wmi_set_psmode(struct ath10k *ar, u32 vdev_id,
1934 enum wmi_sta_ps_mode psmode)
1936 struct wmi_sta_powersave_mode_cmd *cmd;
1937 struct sk_buff *skb;
1939 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1943 cmd = (struct wmi_sta_powersave_mode_cmd *)skb->data;
1944 cmd->vdev_id = __cpu_to_le32(vdev_id);
1945 cmd->sta_ps_mode = __cpu_to_le32(psmode);
1947 ath10k_dbg(ATH10K_DBG_WMI,
1948 "wmi set powersave id 0x%x mode %d\n",
1951 return ath10k_wmi_cmd_send(ar, skb, WMI_STA_POWERSAVE_MODE_CMDID);
1954 int ath10k_wmi_set_sta_ps_param(struct ath10k *ar, u32 vdev_id,
1955 enum wmi_sta_powersave_param param_id,
1958 struct wmi_sta_powersave_param_cmd *cmd;
1959 struct sk_buff *skb;
1961 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1965 cmd = (struct wmi_sta_powersave_param_cmd *)skb->data;
1966 cmd->vdev_id = __cpu_to_le32(vdev_id);
1967 cmd->param_id = __cpu_to_le32(param_id);
1968 cmd->param_value = __cpu_to_le32(value);
1970 ath10k_dbg(ATH10K_DBG_WMI,
1971 "wmi sta ps param vdev_id 0x%x param %d value %d\n",
1972 vdev_id, param_id, value);
1973 return ath10k_wmi_cmd_send(ar, skb, WMI_STA_POWERSAVE_PARAM_CMDID);
1976 int ath10k_wmi_set_ap_ps_param(struct ath10k *ar, u32 vdev_id, const u8 *mac,
1977 enum wmi_ap_ps_peer_param param_id, u32 value)
1979 struct wmi_ap_ps_peer_cmd *cmd;
1980 struct sk_buff *skb;
1985 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
1989 cmd = (struct wmi_ap_ps_peer_cmd *)skb->data;
1990 cmd->vdev_id = __cpu_to_le32(vdev_id);
1991 cmd->param_id = __cpu_to_le32(param_id);
1992 cmd->param_value = __cpu_to_le32(value);
1993 memcpy(&cmd->peer_macaddr, mac, ETH_ALEN);
1995 ath10k_dbg(ATH10K_DBG_WMI,
1996 "wmi ap ps param vdev_id 0x%X param %d value %d mac_addr %pM\n",
1997 vdev_id, param_id, value, mac);
1999 return ath10k_wmi_cmd_send(ar, skb, WMI_AP_PS_PEER_PARAM_CMDID);
2002 int ath10k_wmi_scan_chan_list(struct ath10k *ar,
2003 const struct wmi_scan_chan_list_arg *arg)
2005 struct wmi_scan_chan_list_cmd *cmd;
2006 struct sk_buff *skb;
2007 struct wmi_channel_arg *ch;
2008 struct wmi_channel *ci;
2012 len = sizeof(*cmd) + arg->n_channels * sizeof(struct wmi_channel);
2014 skb = ath10k_wmi_alloc_skb(len);
2018 cmd = (struct wmi_scan_chan_list_cmd *)skb->data;
2019 cmd->num_scan_chans = __cpu_to_le32(arg->n_channels);
2021 for (i = 0; i < arg->n_channels; i++) {
2024 ch = &arg->channels[i];
2025 ci = &cmd->chan_info[i];
2028 flags |= WMI_CHAN_FLAG_PASSIVE;
2030 flags |= WMI_CHAN_FLAG_ADHOC_ALLOWED;
2032 flags |= WMI_CHAN_FLAG_ALLOW_HT;
2034 flags |= WMI_CHAN_FLAG_ALLOW_VHT;
2036 flags |= WMI_CHAN_FLAG_HT40_PLUS;
2038 ci->mhz = __cpu_to_le32(ch->freq);
2039 ci->band_center_freq1 = __cpu_to_le32(ch->freq);
2040 ci->band_center_freq2 = 0;
2041 ci->min_power = ch->min_power;
2042 ci->max_power = ch->max_power;
2043 ci->reg_power = ch->max_reg_power;
2044 ci->antenna_max = ch->max_antenna_gain;
2045 ci->antenna_max = 0;
2047 /* mode & flags share storage */
2048 ci->mode = ch->mode;
2049 ci->flags |= __cpu_to_le32(flags);
2052 return ath10k_wmi_cmd_send(ar, skb, WMI_SCAN_CHAN_LIST_CMDID);
2055 int ath10k_wmi_peer_assoc(struct ath10k *ar,
2056 const struct wmi_peer_assoc_complete_arg *arg)
2058 struct wmi_peer_assoc_complete_cmd *cmd;
2059 struct sk_buff *skb;
2061 if (arg->peer_mpdu_density > 16)
2063 if (arg->peer_legacy_rates.num_rates > MAX_SUPPORTED_RATES)
2065 if (arg->peer_ht_rates.num_rates > MAX_SUPPORTED_RATES)
2068 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2072 cmd = (struct wmi_peer_assoc_complete_cmd *)skb->data;
2073 cmd->vdev_id = __cpu_to_le32(arg->vdev_id);
2074 cmd->peer_new_assoc = __cpu_to_le32(arg->peer_reassoc ? 0 : 1);
2075 cmd->peer_associd = __cpu_to_le32(arg->peer_aid);
2076 cmd->peer_flags = __cpu_to_le32(arg->peer_flags);
2077 cmd->peer_caps = __cpu_to_le32(arg->peer_caps);
2078 cmd->peer_listen_intval = __cpu_to_le32(arg->peer_listen_intval);
2079 cmd->peer_ht_caps = __cpu_to_le32(arg->peer_ht_caps);
2080 cmd->peer_max_mpdu = __cpu_to_le32(arg->peer_max_mpdu);
2081 cmd->peer_mpdu_density = __cpu_to_le32(arg->peer_mpdu_density);
2082 cmd->peer_rate_caps = __cpu_to_le32(arg->peer_rate_caps);
2083 cmd->peer_nss = __cpu_to_le32(arg->peer_num_spatial_streams);
2084 cmd->peer_vht_caps = __cpu_to_le32(arg->peer_vht_caps);
2085 cmd->peer_phymode = __cpu_to_le32(arg->peer_phymode);
2087 memcpy(cmd->peer_macaddr.addr, arg->addr, ETH_ALEN);
2089 cmd->peer_legacy_rates.num_rates =
2090 __cpu_to_le32(arg->peer_legacy_rates.num_rates);
2091 memcpy(cmd->peer_legacy_rates.rates, arg->peer_legacy_rates.rates,
2092 arg->peer_legacy_rates.num_rates);
2094 cmd->peer_ht_rates.num_rates =
2095 __cpu_to_le32(arg->peer_ht_rates.num_rates);
2096 memcpy(cmd->peer_ht_rates.rates, arg->peer_ht_rates.rates,
2097 arg->peer_ht_rates.num_rates);
2099 cmd->peer_vht_rates.rx_max_rate =
2100 __cpu_to_le32(arg->peer_vht_rates.rx_max_rate);
2101 cmd->peer_vht_rates.rx_mcs_set =
2102 __cpu_to_le32(arg->peer_vht_rates.rx_mcs_set);
2103 cmd->peer_vht_rates.tx_max_rate =
2104 __cpu_to_le32(arg->peer_vht_rates.tx_max_rate);
2105 cmd->peer_vht_rates.tx_mcs_set =
2106 __cpu_to_le32(arg->peer_vht_rates.tx_mcs_set);
2108 ath10k_dbg(ATH10K_DBG_WMI,
2109 "wmi peer assoc vdev %d addr %pM\n",
2110 arg->vdev_id, arg->addr);
2111 return ath10k_wmi_cmd_send(ar, skb, WMI_PEER_ASSOC_CMDID);
2114 int ath10k_wmi_beacon_send_nowait(struct ath10k *ar,
2115 const struct wmi_bcn_tx_arg *arg)
2117 struct wmi_bcn_tx_cmd *cmd;
2118 struct sk_buff *skb;
2120 skb = ath10k_wmi_alloc_skb(sizeof(*cmd) + arg->bcn_len);
2124 cmd = (struct wmi_bcn_tx_cmd *)skb->data;
2125 cmd->hdr.vdev_id = __cpu_to_le32(arg->vdev_id);
2126 cmd->hdr.tx_rate = __cpu_to_le32(arg->tx_rate);
2127 cmd->hdr.tx_power = __cpu_to_le32(arg->tx_power);
2128 cmd->hdr.bcn_len = __cpu_to_le32(arg->bcn_len);
2129 memcpy(cmd->bcn, arg->bcn, arg->bcn_len);
2131 return ath10k_wmi_cmd_send_nowait(ar, skb, WMI_BCN_TX_CMDID);
2134 static void ath10k_wmi_pdev_set_wmm_param(struct wmi_wmm_params *params,
2135 const struct wmi_wmm_params_arg *arg)
2137 params->cwmin = __cpu_to_le32(arg->cwmin);
2138 params->cwmax = __cpu_to_le32(arg->cwmax);
2139 params->aifs = __cpu_to_le32(arg->aifs);
2140 params->txop = __cpu_to_le32(arg->txop);
2141 params->acm = __cpu_to_le32(arg->acm);
2142 params->no_ack = __cpu_to_le32(arg->no_ack);
2145 int ath10k_wmi_pdev_set_wmm_params(struct ath10k *ar,
2146 const struct wmi_pdev_set_wmm_params_arg *arg)
2148 struct wmi_pdev_set_wmm_params *cmd;
2149 struct sk_buff *skb;
2151 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2155 cmd = (struct wmi_pdev_set_wmm_params *)skb->data;
2156 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_be, &arg->ac_be);
2157 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_bk, &arg->ac_bk);
2158 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vi, &arg->ac_vi);
2159 ath10k_wmi_pdev_set_wmm_param(&cmd->ac_vo, &arg->ac_vo);
2161 ath10k_dbg(ATH10K_DBG_WMI, "wmi pdev set wmm params\n");
2162 return ath10k_wmi_cmd_send(ar, skb, WMI_PDEV_SET_WMM_PARAMS_CMDID);
2165 int ath10k_wmi_request_stats(struct ath10k *ar, enum wmi_stats_id stats_id)
2167 struct wmi_request_stats_cmd *cmd;
2168 struct sk_buff *skb;
2170 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2174 cmd = (struct wmi_request_stats_cmd *)skb->data;
2175 cmd->stats_id = __cpu_to_le32(stats_id);
2177 ath10k_dbg(ATH10K_DBG_WMI, "wmi request stats %d\n", (int)stats_id);
2178 return ath10k_wmi_cmd_send(ar, skb, WMI_REQUEST_STATS_CMDID);
2181 int ath10k_wmi_force_fw_hang(struct ath10k *ar,
2182 enum wmi_force_fw_hang_type type, u32 delay_ms)
2184 struct wmi_force_fw_hang_cmd *cmd;
2185 struct sk_buff *skb;
2187 skb = ath10k_wmi_alloc_skb(sizeof(*cmd));
2191 cmd = (struct wmi_force_fw_hang_cmd *)skb->data;
2192 cmd->type = __cpu_to_le32(type);
2193 cmd->delay_ms = __cpu_to_le32(delay_ms);
2195 ath10k_dbg(ATH10K_DBG_WMI, "wmi force fw hang %d delay %d\n",
2197 return ath10k_wmi_cmd_send(ar, skb, WMI_FORCE_FW_HANG_CMDID);