2 * This file is part of wl1271
4 * Copyright (C) 2009-2010 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/spi/spi.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ieee80211.h>
29 #include <linux/slab.h>
35 #include "wl12xx_80211.h"
41 #define WL1271_CMD_FAST_POLL_COUNT 50
42 #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20
45 * send command to firmware
49 * @buf: buffer containing the command, must work with dma
50 * @len: length of the buffer
51 * return the cmd status code on success.
53 static int __wlcore_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
,
54 size_t len
, size_t res_len
)
56 struct wl1271_cmd_header
*cmd
;
57 unsigned long timeout
;
63 if (unlikely(wl
->state
== WLCORE_STATE_RESTARTING
&&
64 id
!= CMD_STOP_FWLOGGER
))
68 cmd
->id
= cpu_to_le16(id
);
71 WARN_ON(len
% 4 != 0);
72 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
74 ret
= wlcore_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
79 * TODO: we just need this because one bit is in a different
80 * place. Is there any better way?
82 ret
= wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
86 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
88 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
92 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
93 if (time_after(jiffies
, timeout
)) {
94 wl1271_error("command complete timeout");
99 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
104 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
109 /* read back the status code of the command */
111 res_len
= sizeof(struct wl1271_cmd_header
);
113 ret
= wlcore_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
117 status
= le16_to_cpu(cmd
->status
);
119 ret
= wlcore_write_reg(wl
, REG_INTERRUPT_ACK
,
120 WL1271_ACX_INTR_CMD_COMPLETE
);
128 * send command to fw and return cmd status on success
129 * valid_rets contains a bitmap of allowed error codes
131 int wlcore_cmd_send_failsafe(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
132 size_t res_len
, unsigned long valid_rets
)
134 int ret
= __wlcore_cmd_send(wl
, id
, buf
, len
, res_len
);
139 /* success is always a valid status */
140 valid_rets
|= BIT(CMD_STATUS_SUCCESS
);
142 if (ret
>= MAX_COMMAND_STATUS
||
143 !test_bit(ret
, &valid_rets
)) {
144 wl1271_error("command execute failure %d", ret
);
150 wl12xx_queue_recovery_work(wl
);
153 EXPORT_SYMBOL_GPL(wl1271_cmd_send
);
156 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
157 * return 0 on success.
159 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
162 int ret
= wlcore_cmd_send_failsafe(wl
, id
, buf
, len
, res_len
, 0);
170 * Poll the mailbox event field until any of the bits in the mask is set or a
171 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
173 int wlcore_cmd_wait_for_event_or_timeout(struct wl1271
*wl
,
174 u32 mask
, bool *timeout
)
178 unsigned long timeout_time
;
184 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
188 timeout_time
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
191 if (time_after(jiffies
, timeout_time
)) {
192 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
199 if (poll_count
< WL1271_WAIT_EVENT_FAST_POLL_COUNT
)
200 usleep_range(50, 51);
202 usleep_range(1000, 5000);
204 /* read from both event fields */
205 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
206 sizeof(*events_vector
), false);
210 event
= *events_vector
& mask
;
212 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
213 sizeof(*events_vector
), false);
217 event
|= *events_vector
& mask
;
221 kfree(events_vector
);
224 EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout
);
226 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
229 struct wl12xx_cmd_role_enable
*cmd
;
232 wl1271_debug(DEBUG_CMD
, "cmd role enable");
234 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
237 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
244 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
245 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
250 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
251 cmd
->role_type
= role_type
;
253 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
255 wl1271_error("failed to initiate cmd role enable");
259 __set_bit(cmd
->role_id
, wl
->roles_map
);
260 *role_id
= cmd
->role_id
;
269 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
271 struct wl12xx_cmd_role_disable
*cmd
;
274 wl1271_debug(DEBUG_CMD
, "cmd role disable");
276 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
279 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
284 cmd
->role_id
= *role_id
;
286 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
288 wl1271_error("failed to initiate cmd role disable");
292 __clear_bit(*role_id
, wl
->roles_map
);
293 *role_id
= WL12XX_INVALID_ROLE_ID
;
302 static int wlcore_get_new_session_id(struct wl1271
*wl
, u8 hlid
)
304 if (wl
->session_ids
[hlid
] >= SESSION_COUNTER_MAX
)
305 wl
->session_ids
[hlid
] = 0;
307 wl
->session_ids
[hlid
]++;
309 return wl
->session_ids
[hlid
];
312 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
315 u8 link
= find_first_zero_bit(wl
->links_map
, wl
->num_links
);
316 if (link
>= wl
->num_links
)
319 wl
->session_ids
[link
] = wlcore_get_new_session_id(wl
, link
);
321 /* these bits are used by op_tx */
322 spin_lock_irqsave(&wl
->wl_lock
, flags
);
323 __set_bit(link
, wl
->links_map
);
324 __set_bit(link
, wlvif
->links_map
);
325 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
328 * take the last "freed packets" value from the current FW status.
329 * on recovery, we might not have fw_status yet, and
330 * tx_lnk_free_pkts will be NULL. check for it.
332 if (wl
->fw_status
->counters
.tx_lnk_free_pkts
)
333 wl
->links
[link
].prev_freed_pkts
=
334 wl
->fw_status
->counters
.tx_lnk_free_pkts
[link
];
335 wl
->links
[link
].wlvif
= wlvif
;
338 * Take saved value for total freed packets from wlvif, in case this is
341 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
)
342 wl
->links
[link
].total_freed_pkts
= wlvif
->total_freed_pkts
;
346 wl
->active_link_count
++;
350 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
354 if (*hlid
== WL12XX_INVALID_LINK_ID
)
357 /* these bits are used by op_tx */
358 spin_lock_irqsave(&wl
->wl_lock
, flags
);
359 __clear_bit(*hlid
, wl
->links_map
);
360 __clear_bit(*hlid
, wlvif
->links_map
);
361 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
363 wl
->links
[*hlid
].allocated_pkts
= 0;
364 wl
->links
[*hlid
].prev_freed_pkts
= 0;
365 wl
->links
[*hlid
].ba_bitmap
= 0;
366 memset(wl
->links
[*hlid
].addr
, 0, ETH_ALEN
);
369 * At this point op_tx() will not add more packets to the queues. We
372 wl1271_tx_reset_link_queues(wl
, *hlid
);
373 wl
->links
[*hlid
].wlvif
= NULL
;
375 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
&&
376 *hlid
== wlvif
->ap
.bcast_hlid
) {
377 u32 sqn_padding
= WL1271_TX_SQN_POST_RECOVERY_PADDING
;
379 * save the total freed packets in the wlvif, in case this is
380 * recovery or suspend
382 wlvif
->total_freed_pkts
= wl
->links
[*hlid
].total_freed_pkts
;
385 * increment the initial seq number on recovery to account for
386 * transmitted packets that we haven't yet got in the FW status
388 if (wlvif
->encryption_type
== KEY_GEM
)
389 sqn_padding
= WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM
;
391 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
392 wlvif
->total_freed_pkts
+= sqn_padding
;
395 wl
->links
[*hlid
].total_freed_pkts
= 0;
397 *hlid
= WL12XX_INVALID_LINK_ID
;
398 wl
->active_link_count
--;
399 WARN_ON_ONCE(wl
->active_link_count
< 0);
402 static u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
404 switch (nl_channel_type
) {
405 case NL80211_CHAN_NO_HT
:
406 return WLCORE_CHAN_NO_HT
;
407 case NL80211_CHAN_HT20
:
408 return WLCORE_CHAN_HT20
;
409 case NL80211_CHAN_HT40MINUS
:
410 return WLCORE_CHAN_HT40MINUS
;
411 case NL80211_CHAN_HT40PLUS
:
412 return WLCORE_CHAN_HT40PLUS
;
415 return WLCORE_CHAN_NO_HT
;
419 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
420 struct wl12xx_vif
*wlvif
,
421 enum ieee80211_band band
,
424 struct wl12xx_cmd_role_start
*cmd
;
427 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
433 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
435 cmd
->role_id
= wlvif
->dev_role_id
;
436 if (band
== IEEE80211_BAND_5GHZ
)
437 cmd
->band
= WLCORE_BAND_5GHZ
;
438 cmd
->channel
= channel
;
440 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
441 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
445 cmd
->device
.hlid
= wlvif
->dev_hlid
;
446 cmd
->device
.session
= wl
->session_ids
[wlvif
->dev_hlid
];
448 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
449 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
451 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
453 wl1271_error("failed to initiate cmd role enable");
460 /* clear links on error */
461 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
470 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
471 struct wl12xx_vif
*wlvif
)
473 struct wl12xx_cmd_role_stop
*cmd
;
476 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
479 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
485 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
487 cmd
->role_id
= wlvif
->dev_role_id
;
488 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
489 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
491 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
493 wl1271_error("failed to initiate cmd role stop");
497 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
506 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
508 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
509 struct wl12xx_cmd_role_start
*cmd
;
513 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
519 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
521 cmd
->role_id
= wlvif
->role_id
;
522 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
523 cmd
->band
= WLCORE_BAND_5GHZ
;
524 cmd
->channel
= wlvif
->channel
;
525 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
526 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
527 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
528 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
529 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
530 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
532 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
533 wlcore_hw_sta_get_ap_rate_mask(wl
, wlvif
);
535 supported_rates
&= ~CONF_TX_CCK_RATES
;
537 cmd
->sta
.local_rates
= cpu_to_le32(supported_rates
);
539 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
541 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
542 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
546 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
547 cmd
->sta
.session
= wl
->session_ids
[wlvif
->sta
.hlid
];
549 * We don't have the correct remote rates in this stage. The
550 * rates will be reconfigured later, after association, if the
551 * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
552 * we can do, so use all supported_rates here.
554 cmd
->sta
.remote_rates
= cpu_to_le32(supported_rates
);
556 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
557 "basic_rate_set: 0x%x, remote_rates: 0x%x",
558 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
559 wlvif
->basic_rate_set
, wlvif
->rate_set
);
561 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
563 wl1271_error("failed to initiate cmd role start sta");
567 wlvif
->sta
.role_chan_type
= wlvif
->channel_type
;
571 /* clear links on error. */
572 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
581 /* use this function to stop ibss as well */
582 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
584 struct wl12xx_cmd_role_stop
*cmd
;
587 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
590 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
596 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
598 cmd
->role_id
= wlvif
->role_id
;
599 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
600 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
602 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
604 wl1271_error("failed to initiate cmd role stop sta");
608 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
617 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
619 struct wl12xx_cmd_role_start
*cmd
;
620 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
621 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
625 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
627 /* trying to use hidden SSID with an old hostapd version */
628 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
629 wl1271_error("got a null SSID from beacon/bss");
634 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
640 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
644 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
646 goto out_free_global
;
648 /* use the previous security seq, if this is a recovery/resume */
649 wl
->links
[wlvif
->ap
.bcast_hlid
].total_freed_pkts
=
650 wlvif
->total_freed_pkts
;
652 cmd
->role_id
= wlvif
->role_id
;
653 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
654 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
655 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
656 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
657 cmd
->ap
.global_session_id
= wl
->session_ids
[wlvif
->ap
.global_hlid
];
658 cmd
->ap
.bcast_session_id
= wl
->session_ids
[wlvif
->ap
.bcast_hlid
];
659 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
660 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
661 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
662 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
663 /* FIXME: Change when adding DFS */
664 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
665 cmd
->ap
.wmm
= wlvif
->wmm_enabled
;
666 cmd
->channel
= wlvif
->channel
;
667 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
669 if (!bss_conf
->hidden_ssid
) {
670 /* take the SSID from the beacon for backward compatibility */
671 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
672 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
673 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
675 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
676 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
677 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
680 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
681 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
683 supported_rates
&= ~CONF_TX_CCK_RATES
;
685 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
688 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
690 switch (wlvif
->band
) {
691 case IEEE80211_BAND_2GHZ
:
692 cmd
->band
= WLCORE_BAND_2_4GHZ
;
694 case IEEE80211_BAND_5GHZ
:
695 cmd
->band
= WLCORE_BAND_5GHZ
;
698 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
699 cmd
->band
= WLCORE_BAND_2_4GHZ
;
703 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
705 wl1271_error("failed to initiate cmd role start ap");
712 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
715 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
724 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
726 struct wl12xx_cmd_role_stop
*cmd
;
729 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
735 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
737 cmd
->role_id
= wlvif
->role_id
;
739 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
741 wl1271_error("failed to initiate cmd role stop ap");
745 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
746 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
755 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
757 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
758 struct wl12xx_cmd_role_start
*cmd
;
759 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
762 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
768 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
770 cmd
->role_id
= wlvif
->role_id
;
771 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
772 cmd
->band
= WLCORE_BAND_5GHZ
;
773 cmd
->channel
= wlvif
->channel
;
774 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
775 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
776 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
777 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
778 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
779 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
780 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
781 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
783 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
784 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
788 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
789 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
791 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
792 "basic_rate_set: 0x%x, remote_rates: 0x%x",
793 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
794 wlvif
->basic_rate_set
, wlvif
->rate_set
);
796 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
797 vif
->bss_conf
.bssid
);
799 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
801 wl1271_error("failed to initiate cmd role enable");
808 /* clear links on error. */
809 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
820 * send test command to firmware
823 * @buf: buffer containing the command, with all headers, must work with dma
824 * @len: length of the buffer
825 * @answer: is answer needed
827 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
832 wl1271_debug(DEBUG_CMD
, "cmd test");
837 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
840 wl1271_warning("TEST command failed");
846 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
849 * read acx from firmware
853 * @buf: buffer for the response, including all headers, must work with dma
854 * @len: length of buf
856 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
,
857 size_t cmd_len
, size_t res_len
)
859 struct acx_header
*acx
= buf
;
862 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
864 acx
->id
= cpu_to_le16(id
);
866 /* response payload length, does not include any headers */
867 acx
->len
= cpu_to_le16(res_len
- sizeof(*acx
));
869 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, cmd_len
, res_len
);
871 wl1271_error("INTERROGATE command failed");
877 * write acx value to firmware
881 * @buf: buffer containing acx, including all headers, must work with dma
882 * @len: length of buf
883 * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
884 * return the cmd status on success.
886 int wlcore_cmd_configure_failsafe(struct wl1271
*wl
, u16 id
, void *buf
,
887 size_t len
, unsigned long valid_rets
)
889 struct acx_header
*acx
= buf
;
892 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
894 acx
->id
= cpu_to_le16(id
);
896 /* payload length, does not include any headers */
897 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
899 ret
= wlcore_cmd_send_failsafe(wl
, CMD_CONFIGURE
, acx
, len
, 0,
902 wl1271_warning("CONFIGURE command NOK");
910 * wrapper for wlcore_cmd_configure that accepts only success status.
911 * return 0 on success
913 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
915 int ret
= wlcore_cmd_configure_failsafe(wl
, id
, buf
, len
, 0);
921 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
923 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
925 struct cmd_enabledisable_path
*cmd
;
929 wl1271_debug(DEBUG_CMD
, "cmd data path");
931 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
937 /* the channel here is only used for calibration, so hardcoded to 1 */
941 cmd_rx
= CMD_ENABLE_RX
;
942 cmd_tx
= CMD_ENABLE_TX
;
944 cmd_rx
= CMD_DISABLE_RX
;
945 cmd_tx
= CMD_DISABLE_TX
;
948 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
950 wl1271_error("rx %s cmd for channel %d failed",
951 enable
? "start" : "stop", cmd
->channel
);
955 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
956 enable
? "start" : "stop", cmd
->channel
);
958 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
960 wl1271_error("tx %s cmd for channel %d failed",
961 enable
? "start" : "stop", cmd
->channel
);
965 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
966 enable
? "start" : "stop", cmd
->channel
);
972 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
974 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
975 u8 ps_mode
, u16 auto_ps_timeout
)
977 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
980 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
982 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
988 ps_params
->role_id
= wlvif
->role_id
;
989 ps_params
->ps_mode
= ps_mode
;
990 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
992 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
993 sizeof(*ps_params
), 0);
995 wl1271_error("cmd set_ps_mode failed");
1004 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
1005 u16 template_id
, void *buf
, size_t buf_len
,
1006 int index
, u32 rates
)
1008 struct wl1271_cmd_template_set
*cmd
;
1011 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
1012 template_id
, role_id
);
1014 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1015 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1017 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1023 /* during initialization wlvif is NULL */
1024 cmd
->role_id
= role_id
;
1025 cmd
->len
= cpu_to_le16(buf_len
);
1026 cmd
->template_type
= template_id
;
1027 cmd
->enabled_rates
= cpu_to_le32(rates
);
1028 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1029 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1033 memcpy(cmd
->template_data
, buf
, buf_len
);
1035 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1037 wl1271_warning("cmd set_template failed: %d", ret
);
1048 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1050 struct sk_buff
*skb
= NULL
;
1056 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1057 size
= sizeof(struct wl12xx_null_data_template
);
1060 skb
= ieee80211_nullfunc_get(wl
->hw
,
1061 wl12xx_wlvif_to_vif(wlvif
));
1068 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1069 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
1075 wl1271_warning("cmd buld null data failed %d", ret
);
1081 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
1082 struct wl12xx_vif
*wlvif
)
1084 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1085 struct sk_buff
*skb
= NULL
;
1088 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
1092 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
1093 skb
->data
, skb
->len
,
1094 wlvif
->sta
.klv_template_id
,
1100 wl1271_warning("cmd build klv null data failed %d", ret
);
1106 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1109 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1110 struct sk_buff
*skb
;
1113 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
1117 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1118 CMD_TEMPL_PS_POLL
, skb
->data
,
1119 skb
->len
, 0, wlvif
->basic_rate_set
);
1126 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1127 u8 role_id
, u8 band
,
1128 const u8
*ssid
, size_t ssid_len
,
1129 const u8
*ie0
, size_t ie0_len
, const u8
*ie1
,
1130 size_t ie1_len
, bool sched_scan
)
1132 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1133 struct sk_buff
*skb
;
1136 u16 template_id_2_4
= wl
->scan_templ_id_2_4
;
1137 u16 template_id_5
= wl
->scan_templ_id_5
;
1139 wl1271_debug(DEBUG_SCAN
, "build probe request band %d", band
);
1141 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1148 memcpy(skb_put(skb
, ie0_len
), ie0
, ie0_len
);
1150 memcpy(skb_put(skb
, ie1_len
), ie1
, ie1_len
);
1153 (wl
->quirks
& WLCORE_QUIRK_DUAL_PROBE_TMPL
)) {
1154 template_id_2_4
= wl
->sched_scan_templ_id_2_4
;
1155 template_id_5
= wl
->sched_scan_templ_id_5
;
1158 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1159 if (band
== IEEE80211_BAND_2GHZ
)
1160 ret
= wl1271_cmd_template_set(wl
, role_id
,
1162 skb
->data
, skb
->len
, 0, rate
);
1164 ret
= wl1271_cmd_template_set(wl
, role_id
,
1166 skb
->data
, skb
->len
, 0, rate
);
1172 EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req
);
1174 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1175 struct wl12xx_vif
*wlvif
,
1176 struct sk_buff
*skb
)
1178 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1183 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1187 wl1271_debug(DEBUG_SCAN
, "set ap probe request template");
1189 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1190 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1191 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1192 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1193 skb
->data
, skb
->len
, 0, rate
);
1195 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1196 CMD_TEMPL_CFG_PROBE_REQ_5
,
1197 skb
->data
, skb
->len
, 0, rate
);
1200 wl1271_error("Unable to set ap probe request template.");
1206 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1210 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1211 struct sk_buff
*skb
;
1212 struct wl12xx_arp_rsp_template
*tmpl
;
1213 struct ieee80211_hdr_3addr
*hdr
;
1214 struct arphdr
*arp_hdr
;
1216 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1217 WL1271_EXTRA_SPACE_MAX
);
1219 wl1271_error("failed to allocate buffer for arp rsp template");
1223 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1225 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1226 memset(tmpl
, 0, sizeof(*tmpl
));
1229 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1230 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1233 arp_hdr
= &tmpl
->arp_hdr
;
1234 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1235 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1236 arp_hdr
->ar_hln
= ETH_ALEN
;
1237 arp_hdr
->ar_pln
= 4;
1238 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1241 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1242 tmpl
->sender_ip
= wlvif
->ip_addr
;
1244 /* encryption space */
1245 switch (wlvif
->encryption_type
) {
1247 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1248 extra
= WL1271_EXTRA_SPACE_TKIP
;
1251 extra
= WL1271_EXTRA_SPACE_AES
;
1259 wl1271_warning("Unknown encryption type: %d",
1260 wlvif
->encryption_type
);
1266 u8
*space
= skb_push(skb
, extra
);
1267 memset(space
, 0, extra
);
1270 /* QoS header - BE */
1272 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1274 /* mac80211 header */
1275 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1276 memset(hdr
, 0, sizeof(*hdr
));
1277 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1279 fc
|= IEEE80211_STYPE_QOS_DATA
;
1281 fc
|= IEEE80211_STYPE_DATA
;
1282 if (wlvif
->encryption_type
!= KEY_NONE
)
1283 fc
|= IEEE80211_FCTL_PROTECTED
;
1285 hdr
->frame_control
= cpu_to_le16(fc
);
1286 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1287 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1288 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1290 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1291 skb
->data
, skb
->len
, 0,
1298 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1300 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1301 struct ieee80211_qos_hdr
template;
1303 memset(&template, 0, sizeof(template));
1305 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1306 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1307 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1309 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1310 IEEE80211_STYPE_QOS_NULLFUNC
|
1311 IEEE80211_FCTL_TODS
);
1313 /* FIXME: not sure what priority to use here */
1314 template.qos_ctrl
= cpu_to_le16(0);
1316 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1317 CMD_TEMPL_QOS_NULL_DATA
, &template,
1318 sizeof(template), 0,
1322 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1324 struct wl1271_cmd_set_keys
*cmd
;
1327 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1329 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1337 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1338 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1339 cmd
->key_type
= KEY_WEP
;
1341 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1343 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1353 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1354 u16 action
, u8 id
, u8 key_type
,
1355 u8 key_size
, const u8
*key
, const u8
*addr
,
1356 u32 tx_seq_32
, u16 tx_seq_16
)
1358 struct wl1271_cmd_set_keys
*cmd
;
1361 /* hlid might have already been deleted */
1362 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1365 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1371 cmd
->hlid
= wlvif
->sta
.hlid
;
1373 if (key_type
== KEY_WEP
)
1374 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1375 else if (is_broadcast_ether_addr(addr
))
1376 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1378 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1380 cmd
->key_action
= cpu_to_le16(action
);
1381 cmd
->key_size
= key_size
;
1382 cmd
->key_type
= key_type
;
1384 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1385 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1389 if (key_type
== KEY_TKIP
) {
1391 * We get the key in the following form:
1392 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1393 * but the target is expecting:
1394 * TKIP - RX MIC - TX MIC
1396 memcpy(cmd
->key
, key
, 16);
1397 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1398 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1401 memcpy(cmd
->key
, key
, key_size
);
1404 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1406 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1408 wl1271_warning("could not set keys");
1419 * TODO: merge with sta/ibss into 1 set_key function.
1420 * note there are slight diffs
1422 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1423 u16 action
, u8 id
, u8 key_type
,
1424 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1427 struct wl1271_cmd_set_keys
*cmd
;
1431 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1435 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1436 if (key_type
== KEY_WEP
)
1437 lid_type
= WEP_DEFAULT_LID_TYPE
;
1439 lid_type
= BROADCAST_LID_TYPE
;
1441 lid_type
= UNICAST_LID_TYPE
;
1444 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1445 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1446 (int)key_type
, (int)hlid
);
1448 cmd
->lid_key_type
= lid_type
;
1450 cmd
->key_action
= cpu_to_le16(action
);
1451 cmd
->key_size
= key_size
;
1452 cmd
->key_type
= key_type
;
1454 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1455 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1457 if (key_type
== KEY_TKIP
) {
1459 * We get the key in the following form:
1460 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1461 * but the target is expecting:
1462 * TKIP - RX MIC - TX MIC
1464 memcpy(cmd
->key
, key
, 16);
1465 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1466 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1468 memcpy(cmd
->key
, key
, key_size
);
1471 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1473 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1475 wl1271_warning("could not set ap keys");
1484 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1487 struct wl12xx_cmd_set_peer_state
*cmd
;
1490 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1492 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1499 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1501 /* wmm param is valid only for station role */
1502 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1503 cmd
->wmm
= wlvif
->wmm_enabled
;
1505 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1507 wl1271_error("failed to send set peer state command");
1518 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1519 struct ieee80211_sta
*sta
, u8 hlid
)
1521 struct wl12xx_cmd_add_peer
*cmd
;
1525 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1527 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1533 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1534 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1535 cmd
->aid
= sta
->aid
;
1537 cmd
->sp_len
= sta
->max_sp
;
1538 cmd
->wmm
= sta
->wme
? 1 : 0;
1539 cmd
->session_id
= wl
->session_ids
[hlid
];
1540 cmd
->role_id
= wlvif
->role_id
;
1542 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1543 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1544 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1545 WL1271_PSD_UPSD_TRIGGER
;
1547 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1551 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1552 if (sta
->ht_cap
.ht_supported
)
1554 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1555 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1557 cmd
->supported_rates
=
1558 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1561 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1562 cmd
->supported_rates
, sta
->uapsd_queues
);
1564 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1566 wl1271_error("failed to initiate cmd add peer");
1577 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1580 struct wl12xx_cmd_remove_peer
*cmd
;
1582 bool timeout
= false;
1584 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1586 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1593 /* We never send a deauth, mac80211 is in charge of this */
1594 cmd
->reason_opcode
= 0;
1595 cmd
->send_deauth_flag
= 0;
1596 cmd
->role_id
= wlvif
->role_id
;
1598 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1600 wl1271_error("failed to initiate cmd remove peer");
1604 ret
= wl
->ops
->wait_for_event(wl
,
1605 WLCORE_EVENT_PEER_REMOVE_COMPLETE
,
1609 * We are ok with a timeout here. The event is sometimes not sent
1610 * due to a firmware bug. In case of another error (like SDIO timeout)
1614 wl12xx_queue_recovery_work(wl
);
1623 static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band
, u16 ch
)
1626 * map the given band/channel to the respective predefined
1627 * bit expected by the fw
1630 case IEEE80211_BAND_2GHZ
:
1631 /* channels 1..14 are mapped to 0..13 */
1632 if (ch
>= 1 && ch
<= 14)
1635 case IEEE80211_BAND_5GHZ
:
1638 /* channels 8,12,16 are mapped to 18,19,20 */
1639 return 18 + (ch
-8)/4;
1641 /* channels 34,36..48 are mapped to 21..28 */
1642 return 21 + (ch
-34)/2;
1644 /* channels 52,56..64 are mapped to 29..32 */
1645 return 29 + (ch
-52)/4;
1647 /* channels 100,104..140 are mapped to 33..43 */
1648 return 33 + (ch
-100)/4;
1650 /* channels 149,153..165 are mapped to 44..48 */
1651 return 44 + (ch
-149)/4;
1660 wl1271_error("%s: unknown band/channel: %d/%d", __func__
, band
, ch
);
1664 void wlcore_set_pending_regdomain_ch(struct wl1271
*wl
, u16 channel
,
1665 enum ieee80211_band band
)
1669 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1672 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(band
, channel
);
1674 if (ch_bit_idx
>= 0 && ch_bit_idx
<= WL1271_MAX_CHANNELS
)
1675 set_bit(ch_bit_idx
, (long *)wl
->reg_ch_conf_pending
);
1678 int wlcore_cmd_regdomain_config_locked(struct wl1271
*wl
)
1680 struct wl12xx_cmd_regdomain_dfs_config
*cmd
= NULL
;
1681 int ret
= 0, i
, b
, ch_bit_idx
;
1682 struct ieee80211_channel
*channel
;
1683 u32 tmp_ch_bitmap
[2];
1685 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1686 struct ieee80211_supported_band
*band
;
1687 bool timeout
= false;
1689 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1692 wl1271_debug(DEBUG_CMD
, "cmd reg domain config");
1694 memset(tmp_ch_bitmap
, 0, sizeof(tmp_ch_bitmap
));
1696 for (b
= IEEE80211_BAND_2GHZ
; b
<= IEEE80211_BAND_5GHZ
; b
++) {
1697 band
= wiphy
->bands
[b
];
1698 for (i
= 0; i
< band
->n_channels
; i
++) {
1699 channel
= &band
->channels
[i
];
1700 ch
= channel
->hw_value
;
1702 if (channel
->flags
& (IEEE80211_CHAN_DISABLED
|
1703 IEEE80211_CHAN_RADAR
|
1704 IEEE80211_CHAN_NO_IR
))
1707 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(b
, ch
);
1711 set_bit(ch_bit_idx
, (long *)tmp_ch_bitmap
);
1715 tmp_ch_bitmap
[0] |= wl
->reg_ch_conf_pending
[0];
1716 tmp_ch_bitmap
[1] |= wl
->reg_ch_conf_pending
[1];
1718 if (!memcmp(tmp_ch_bitmap
, wl
->reg_ch_conf_last
, sizeof(tmp_ch_bitmap
)))
1721 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1727 cmd
->ch_bit_map1
= cpu_to_le32(tmp_ch_bitmap
[0]);
1728 cmd
->ch_bit_map2
= cpu_to_le32(tmp_ch_bitmap
[1]);
1730 wl1271_debug(DEBUG_CMD
,
1731 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x",
1732 cmd
->ch_bit_map1
, cmd
->ch_bit_map2
);
1734 ret
= wl1271_cmd_send(wl
, CMD_DFS_CHANNEL_CONFIG
, cmd
, sizeof(*cmd
), 0);
1736 wl1271_error("failed to send reg domain dfs config");
1740 ret
= wl
->ops
->wait_for_event(wl
,
1741 WLCORE_EVENT_DFS_CONFIG_COMPLETE
,
1743 if (ret
< 0 || timeout
) {
1744 wl1271_error("reg domain conf %serror",
1745 timeout
? "completion " : "");
1746 ret
= timeout
? -ETIMEDOUT
: ret
;
1750 memcpy(wl
->reg_ch_conf_last
, tmp_ch_bitmap
, sizeof(tmp_ch_bitmap
));
1751 memset(wl
->reg_ch_conf_pending
, 0, sizeof(wl
->reg_ch_conf_pending
));
1758 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1760 struct wl12xx_cmd_config_fwlog
*cmd
;
1763 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1765 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1771 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1772 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1773 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1774 cmd
->output
= wl
->conf
.fwlog
.output
;
1775 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1777 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1779 wl1271_error("failed to send config firmware logger command");
1790 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1792 struct wl12xx_cmd_start_fwlog
*cmd
;
1795 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1797 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1803 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1805 wl1271_error("failed to send start firmware logger command");
1816 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1818 struct wl12xx_cmd_stop_fwlog
*cmd
;
1821 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1823 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1829 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1831 wl1271_error("failed to send stop firmware logger command");
1842 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1843 u8 role_id
, enum ieee80211_band band
, u8 channel
)
1845 struct wl12xx_cmd_roc
*cmd
;
1848 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", channel
, role_id
);
1850 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1853 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1859 cmd
->role_id
= role_id
;
1860 cmd
->channel
= channel
;
1862 case IEEE80211_BAND_2GHZ
:
1863 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1865 case IEEE80211_BAND_5GHZ
:
1866 cmd
->band
= WLCORE_BAND_5GHZ
;
1869 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1875 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1877 wl1271_error("failed to send ROC command");
1888 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1890 struct wl12xx_cmd_croc
*cmd
;
1893 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1895 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1900 cmd
->role_id
= role_id
;
1902 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1905 wl1271_error("failed to send ROC command");
1916 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
,
1917 enum ieee80211_band band
, u8 channel
)
1921 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1924 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
, band
, channel
);
1928 __set_bit(role_id
, wl
->roc_map
);
1933 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1937 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1940 ret
= wl12xx_cmd_croc(wl
, role_id
);
1944 __clear_bit(role_id
, wl
->roc_map
);
1947 * Rearm the tx watchdog when removing the last ROC. This prevents
1948 * recoveries due to just finished ROCs - when Tx hasn't yet had
1949 * a chance to get out.
1951 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1952 wl12xx_rearm_tx_watchdog_locked(wl
);
1957 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1959 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1962 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1964 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1970 cmd
->role_id
= wlvif
->role_id
;
1972 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1974 wl1271_error("failed to stop channel switch command");
1985 /* start dev role and roc on its channel */
1986 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1987 enum ieee80211_band band
, int channel
)
1991 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1992 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1995 ret
= wl12xx_cmd_role_enable(wl
,
1996 wl12xx_wlvif_to_vif(wlvif
)->addr
,
1998 &wlvif
->dev_role_id
);
2002 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
, band
, channel
);
2006 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
, band
, channel
);
2013 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2015 wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2020 /* croc dev hlid, and stop the role */
2021 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2025 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2026 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2029 /* flush all pending packets */
2030 ret
= wlcore_tx_work_locked(wl
);
2034 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
2035 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
2040 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2044 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);