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"
40 #define WL1271_CMD_FAST_POLL_COUNT 50
43 * send command to firmware
47 * @buf: buffer containing the command, must work with dma
48 * @len: length of the buffer
50 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
53 struct wl1271_cmd_header
*cmd
;
54 unsigned long timeout
;
61 cmd
->id
= cpu_to_le16(id
);
64 WARN_ON(len
% 4 != 0);
65 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
67 wl1271_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
70 * TODO: we just need this because one bit is in a different
71 * place. Is there any better way?
73 wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
75 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
77 intr
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
);
78 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
79 if (time_after(jiffies
, timeout
)) {
80 wl1271_error("command complete timeout");
86 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
91 intr
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
);
94 /* read back the status code of the command */
96 res_len
= sizeof(struct wl1271_cmd_header
);
97 wl1271_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
99 status
= le16_to_cpu(cmd
->status
);
100 if (status
!= CMD_STATUS_SUCCESS
) {
101 wl1271_error("command execute failure %d", status
);
106 wlcore_write_reg(wl
, REG_INTERRUPT_ACK
, WL1271_ACX_INTR_CMD_COMPLETE
);
111 wl12xx_queue_recovery_work(wl
);
116 * Poll the mailbox event field until any of the bits in the mask is set or a
117 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
119 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271
*wl
, u32 mask
)
123 unsigned long timeout
;
126 events_vector
= kmalloc(sizeof(*events_vector
), GFP_DMA
);
128 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
131 if (time_after(jiffies
, timeout
)) {
132 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
140 /* read from both event fields */
141 wl1271_read(wl
, wl
->mbox_ptr
[0], events_vector
,
142 sizeof(*events_vector
), false);
143 event
= *events_vector
& mask
;
144 wl1271_read(wl
, wl
->mbox_ptr
[1], events_vector
,
145 sizeof(*events_vector
), false);
146 event
|= *events_vector
& mask
;
150 kfree(events_vector
);
154 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
158 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
160 wl12xx_queue_recovery_work(wl
);
167 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
170 struct wl12xx_cmd_role_enable
*cmd
;
173 wl1271_debug(DEBUG_CMD
, "cmd role enable");
175 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
178 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
185 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
186 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
191 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
192 cmd
->role_type
= role_type
;
194 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
196 wl1271_error("failed to initiate cmd role enable");
200 __set_bit(cmd
->role_id
, wl
->roles_map
);
201 *role_id
= cmd
->role_id
;
210 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
212 struct wl12xx_cmd_role_disable
*cmd
;
215 wl1271_debug(DEBUG_CMD
, "cmd role disable");
217 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
220 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
225 cmd
->role_id
= *role_id
;
227 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
229 wl1271_error("failed to initiate cmd role disable");
233 __clear_bit(*role_id
, wl
->roles_map
);
234 *role_id
= WL12XX_INVALID_ROLE_ID
;
243 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
246 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
247 if (link
>= WL12XX_MAX_LINKS
)
250 /* these bits are used by op_tx */
251 spin_lock_irqsave(&wl
->wl_lock
, flags
);
252 __set_bit(link
, wl
->links_map
);
253 __set_bit(link
, wlvif
->links_map
);
254 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
259 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
263 if (*hlid
== WL12XX_INVALID_LINK_ID
)
266 /* these bits are used by op_tx */
267 spin_lock_irqsave(&wl
->wl_lock
, flags
);
268 __clear_bit(*hlid
, wl
->links_map
);
269 __clear_bit(*hlid
, wlvif
->links_map
);
270 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
273 * At this point op_tx() will not add more packets to the queues. We
276 wl1271_tx_reset_link_queues(wl
, *hlid
);
278 *hlid
= WL12XX_INVALID_LINK_ID
;
281 static int wl12xx_get_new_session_id(struct wl1271
*wl
,
282 struct wl12xx_vif
*wlvif
)
284 if (wlvif
->session_counter
>= SESSION_COUNTER_MAX
)
285 wlvif
->session_counter
= 0;
287 wlvif
->session_counter
++;
289 return wlvif
->session_counter
;
292 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
293 struct wl12xx_vif
*wlvif
)
295 struct wl12xx_cmd_role_start
*cmd
;
298 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
304 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
306 cmd
->role_id
= wlvif
->dev_role_id
;
307 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
308 cmd
->band
= WLCORE_BAND_5GHZ
;
309 cmd
->channel
= wlvif
->channel
;
311 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
312 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
316 cmd
->device
.hlid
= wlvif
->dev_hlid
;
317 cmd
->device
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
319 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
320 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
322 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
324 wl1271_error("failed to initiate cmd role enable");
331 /* clear links on error */
332 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
341 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
342 struct wl12xx_vif
*wlvif
)
344 struct wl12xx_cmd_role_stop
*cmd
;
347 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
350 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
356 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
358 cmd
->role_id
= wlvif
->dev_role_id
;
359 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
360 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
362 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
364 wl1271_error("failed to initiate cmd role stop");
368 ret
= wl1271_cmd_wait_for_event(wl
, ROLE_STOP_COMPLETE_EVENT_ID
);
370 wl1271_error("cmd role stop dev event completion error");
374 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
383 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
385 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
386 struct wl12xx_cmd_role_start
*cmd
;
389 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
395 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
397 cmd
->role_id
= wlvif
->role_id
;
398 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
399 cmd
->band
= WLCORE_BAND_5GHZ
;
400 cmd
->channel
= wlvif
->channel
;
401 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
402 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
403 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
404 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
405 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
406 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
407 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
409 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
410 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
414 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
415 cmd
->sta
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
416 cmd
->sta
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
418 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
419 "basic_rate_set: 0x%x, remote_rates: 0x%x",
420 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
421 wlvif
->basic_rate_set
, wlvif
->rate_set
);
423 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
425 wl1271_error("failed to initiate cmd role start sta");
432 /* clear links on error. */
433 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
442 /* use this function to stop ibss as well */
443 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
445 struct wl12xx_cmd_role_stop
*cmd
;
448 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
451 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
457 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
459 cmd
->role_id
= wlvif
->role_id
;
460 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
461 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
463 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
465 wl1271_error("failed to initiate cmd role stop sta");
469 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
478 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
480 struct wl12xx_cmd_role_start
*cmd
;
481 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
482 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
485 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
487 /* trying to use hidden SSID with an old hostapd version */
488 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
489 wl1271_error("got a null SSID from beacon/bss");
494 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
500 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
504 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
506 goto out_free_global
;
508 cmd
->role_id
= wlvif
->role_id
;
509 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
510 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
511 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
512 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
513 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
514 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
515 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
516 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
517 /* FIXME: Change when adding DFS */
518 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
519 cmd
->channel
= wlvif
->channel
;
521 if (!bss_conf
->hidden_ssid
) {
522 /* take the SSID from the beacon for backward compatibility */
523 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
524 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
525 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
527 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
528 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
529 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
532 cmd
->ap
.local_rates
= cpu_to_le32(0xffffffff);
534 switch (wlvif
->band
) {
535 case IEEE80211_BAND_2GHZ
:
536 cmd
->band
= WLCORE_BAND_2_4GHZ
;
538 case IEEE80211_BAND_5GHZ
:
539 cmd
->band
= WLCORE_BAND_5GHZ
;
542 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
543 cmd
->band
= WLCORE_BAND_2_4GHZ
;
547 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
549 wl1271_error("failed to initiate cmd role start ap");
556 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
559 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
568 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
570 struct wl12xx_cmd_role_stop
*cmd
;
573 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
579 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
581 cmd
->role_id
= wlvif
->role_id
;
583 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
585 wl1271_error("failed to initiate cmd role stop ap");
589 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
590 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
599 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
601 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
602 struct wl12xx_cmd_role_start
*cmd
;
603 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
606 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
612 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
614 cmd
->role_id
= wlvif
->role_id
;
615 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
616 cmd
->band
= WLCORE_BAND_5GHZ
;
617 cmd
->channel
= wlvif
->channel
;
618 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
619 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
620 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
621 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
622 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
623 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
624 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
625 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
627 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
628 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
632 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
633 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
635 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
636 "basic_rate_set: 0x%x, remote_rates: 0x%x",
637 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
638 wlvif
->basic_rate_set
, wlvif
->rate_set
);
640 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
641 vif
->bss_conf
.bssid
);
643 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
645 wl1271_error("failed to initiate cmd role enable");
652 /* clear links on error. */
653 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
664 * send test command to firmware
667 * @buf: buffer containing the command, with all headers, must work with dma
668 * @len: length of the buffer
669 * @answer: is answer needed
671 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
676 wl1271_debug(DEBUG_CMD
, "cmd test");
681 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
684 wl1271_warning("TEST command failed");
690 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
693 * read acx from firmware
697 * @buf: buffer for the response, including all headers, must work with dma
698 * @len: length of buf
700 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
702 struct acx_header
*acx
= buf
;
705 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
707 acx
->id
= cpu_to_le16(id
);
709 /* payload length, does not include any headers */
710 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
712 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
714 wl1271_error("INTERROGATE command failed");
720 * write acx value to firmware
724 * @buf: buffer containing acx, including all headers, must work with dma
725 * @len: length of buf
727 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
729 struct acx_header
*acx
= buf
;
732 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
734 acx
->id
= cpu_to_le16(id
);
736 /* payload length, does not include any headers */
737 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
739 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
741 wl1271_warning("CONFIGURE command NOK");
747 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
749 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
751 struct cmd_enabledisable_path
*cmd
;
755 wl1271_debug(DEBUG_CMD
, "cmd data path");
757 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
763 /* the channel here is only used for calibration, so hardcoded to 1 */
767 cmd_rx
= CMD_ENABLE_RX
;
768 cmd_tx
= CMD_ENABLE_TX
;
770 cmd_rx
= CMD_DISABLE_RX
;
771 cmd_tx
= CMD_DISABLE_TX
;
774 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
776 wl1271_error("rx %s cmd for channel %d failed",
777 enable
? "start" : "stop", cmd
->channel
);
781 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
782 enable
? "start" : "stop", cmd
->channel
);
784 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
786 wl1271_error("tx %s cmd for channel %d failed",
787 enable
? "start" : "stop", cmd
->channel
);
791 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
792 enable
? "start" : "stop", cmd
->channel
);
799 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
800 u8 ps_mode
, u16 auto_ps_timeout
)
802 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
805 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
807 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
813 ps_params
->role_id
= wlvif
->role_id
;
814 ps_params
->ps_mode
= ps_mode
;
815 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
817 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
818 sizeof(*ps_params
), 0);
820 wl1271_error("cmd set_ps_mode failed");
829 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
830 u16 template_id
, void *buf
, size_t buf_len
,
831 int index
, u32 rates
)
833 struct wl1271_cmd_template_set
*cmd
;
836 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
837 template_id
, role_id
);
839 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
840 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
842 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
848 /* during initialization wlvif is NULL */
849 cmd
->role_id
= role_id
;
850 cmd
->len
= cpu_to_le16(buf_len
);
851 cmd
->template_type
= template_id
;
852 cmd
->enabled_rates
= cpu_to_le32(rates
);
853 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
854 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
858 memcpy(cmd
->template_data
, buf
, buf_len
);
860 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
862 wl1271_warning("cmd set_template failed: %d", ret
);
873 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
875 struct sk_buff
*skb
= NULL
;
881 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
882 size
= sizeof(struct wl12xx_null_data_template
);
885 skb
= ieee80211_nullfunc_get(wl
->hw
,
886 wl12xx_wlvif_to_vif(wlvif
));
893 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
894 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
900 wl1271_warning("cmd buld null data failed %d", ret
);
906 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
907 struct wl12xx_vif
*wlvif
)
909 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
910 struct sk_buff
*skb
= NULL
;
913 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
917 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
919 CMD_TEMPL_KLV_IDX_NULL_DATA
,
925 wl1271_warning("cmd build klv null data failed %d", ret
);
931 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
934 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
938 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
942 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
943 CMD_TEMPL_PS_POLL
, skb
->data
,
944 skb
->len
, 0, wlvif
->basic_rate_set
);
951 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
953 const u8
*ssid
, size_t ssid_len
,
954 const u8
*ie
, size_t ie_len
)
956 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
961 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
968 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
970 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
971 if (band
== IEEE80211_BAND_2GHZ
)
972 ret
= wl1271_cmd_template_set(wl
, role_id
,
973 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
974 skb
->data
, skb
->len
, 0, rate
);
976 ret
= wl1271_cmd_template_set(wl
, role_id
,
977 CMD_TEMPL_CFG_PROBE_REQ_5
,
978 skb
->data
, skb
->len
, 0, rate
);
985 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
986 struct wl12xx_vif
*wlvif
,
989 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
994 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
998 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1000 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1001 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1002 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1003 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1004 skb
->data
, skb
->len
, 0, rate
);
1006 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1007 CMD_TEMPL_CFG_PROBE_REQ_5
,
1008 skb
->data
, skb
->len
, 0, rate
);
1011 wl1271_error("Unable to set ap probe request template.");
1017 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1021 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1022 struct sk_buff
*skb
;
1023 struct wl12xx_arp_rsp_template
*tmpl
;
1024 struct ieee80211_hdr_3addr
*hdr
;
1025 struct arphdr
*arp_hdr
;
1027 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1028 WL1271_EXTRA_SPACE_MAX
);
1030 wl1271_error("failed to allocate buffer for arp rsp template");
1034 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1036 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1037 memset(tmpl
, 0, sizeof(tmpl
));
1040 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1041 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1044 arp_hdr
= &tmpl
->arp_hdr
;
1045 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1046 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1047 arp_hdr
->ar_hln
= ETH_ALEN
;
1048 arp_hdr
->ar_pln
= 4;
1049 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1052 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1053 tmpl
->sender_ip
= wlvif
->ip_addr
;
1055 /* encryption space */
1056 switch (wlvif
->encryption_type
) {
1058 extra
= WL1271_EXTRA_SPACE_TKIP
;
1061 extra
= WL1271_EXTRA_SPACE_AES
;
1069 wl1271_warning("Unknown encryption type: %d",
1070 wlvif
->encryption_type
);
1076 u8
*space
= skb_push(skb
, extra
);
1077 memset(space
, 0, extra
);
1080 /* QoS header - BE */
1082 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1084 /* mac80211 header */
1085 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1086 memset(hdr
, 0, sizeof(hdr
));
1087 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1089 fc
|= IEEE80211_STYPE_QOS_DATA
;
1091 fc
|= IEEE80211_STYPE_DATA
;
1092 if (wlvif
->encryption_type
!= KEY_NONE
)
1093 fc
|= IEEE80211_FCTL_PROTECTED
;
1095 hdr
->frame_control
= cpu_to_le16(fc
);
1096 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1097 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1098 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1100 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1101 skb
->data
, skb
->len
, 0,
1108 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1110 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1111 struct ieee80211_qos_hdr
template;
1113 memset(&template, 0, sizeof(template));
1115 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1116 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1117 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1119 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1120 IEEE80211_STYPE_QOS_NULLFUNC
|
1121 IEEE80211_FCTL_TODS
);
1123 /* FIXME: not sure what priority to use here */
1124 template.qos_ctrl
= cpu_to_le16(0);
1126 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1127 CMD_TEMPL_QOS_NULL_DATA
, &template,
1128 sizeof(template), 0,
1132 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1134 struct wl1271_cmd_set_keys
*cmd
;
1137 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1139 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1147 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1148 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1149 cmd
->key_type
= KEY_WEP
;
1151 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1153 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1163 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1164 u16 action
, u8 id
, u8 key_type
,
1165 u8 key_size
, const u8
*key
, const u8
*addr
,
1166 u32 tx_seq_32
, u16 tx_seq_16
)
1168 struct wl1271_cmd_set_keys
*cmd
;
1171 /* hlid might have already been deleted */
1172 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1175 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1181 cmd
->hlid
= wlvif
->sta
.hlid
;
1183 if (key_type
== KEY_WEP
)
1184 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1185 else if (is_broadcast_ether_addr(addr
))
1186 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1188 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1190 cmd
->key_action
= cpu_to_le16(action
);
1191 cmd
->key_size
= key_size
;
1192 cmd
->key_type
= key_type
;
1194 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1195 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1199 if (key_type
== KEY_TKIP
) {
1201 * We get the key in the following form:
1202 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1203 * but the target is expecting:
1204 * TKIP - RX MIC - TX MIC
1206 memcpy(cmd
->key
, key
, 16);
1207 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1208 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1211 memcpy(cmd
->key
, key
, key_size
);
1214 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1216 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1218 wl1271_warning("could not set keys");
1229 * TODO: merge with sta/ibss into 1 set_key function.
1230 * note there are slight diffs
1232 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1233 u16 action
, u8 id
, u8 key_type
,
1234 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1237 struct wl1271_cmd_set_keys
*cmd
;
1241 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1245 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1246 if (key_type
== KEY_WEP
)
1247 lid_type
= WEP_DEFAULT_LID_TYPE
;
1249 lid_type
= BROADCAST_LID_TYPE
;
1251 lid_type
= UNICAST_LID_TYPE
;
1254 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1255 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1256 (int)key_type
, (int)hlid
);
1258 cmd
->lid_key_type
= lid_type
;
1260 cmd
->key_action
= cpu_to_le16(action
);
1261 cmd
->key_size
= key_size
;
1262 cmd
->key_type
= key_type
;
1264 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1265 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1267 if (key_type
== KEY_TKIP
) {
1269 * We get the key in the following form:
1270 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1271 * but the target is expecting:
1272 * TKIP - RX MIC - TX MIC
1274 memcpy(cmd
->key
, key
, 16);
1275 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1276 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1278 memcpy(cmd
->key
, key
, key_size
);
1281 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1283 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1285 wl1271_warning("could not set ap keys");
1294 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, u8 hlid
)
1296 struct wl12xx_cmd_set_peer_state
*cmd
;
1299 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1301 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1308 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1310 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1312 wl1271_error("failed to send set peer state command");
1323 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1324 struct ieee80211_sta
*sta
, u8 hlid
)
1326 struct wl12xx_cmd_add_peer
*cmd
;
1330 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1332 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1338 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1339 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1340 cmd
->aid
= sta
->aid
;
1342 cmd
->sp_len
= sta
->max_sp
;
1343 cmd
->wmm
= sta
->wme
? 1 : 0;
1345 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1346 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1347 cmd
->psd_type
[i
] = WL1271_PSD_UPSD_TRIGGER
;
1349 cmd
->psd_type
[i
] = WL1271_PSD_LEGACY
;
1351 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1352 if (sta
->ht_cap
.ht_supported
)
1353 sta_rates
|= sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
;
1355 cmd
->supported_rates
=
1356 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1359 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1360 cmd
->supported_rates
, sta
->uapsd_queues
);
1362 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1364 wl1271_error("failed to initiate cmd add peer");
1375 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1377 struct wl12xx_cmd_remove_peer
*cmd
;
1380 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1382 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1389 /* We never send a deauth, mac80211 is in charge of this */
1390 cmd
->reason_opcode
= 0;
1391 cmd
->send_deauth_flag
= 0;
1393 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1395 wl1271_error("failed to initiate cmd remove peer");
1400 * We are ok with a timeout here. The event is sometimes not sent
1401 * due to a firmware bug.
1403 wl1271_cmd_wait_for_event_or_timeout(wl
,
1404 PEER_REMOVE_COMPLETE_EVENT_ID
);
1413 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1415 struct wl12xx_cmd_config_fwlog
*cmd
;
1418 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1420 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1426 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1427 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1428 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1429 cmd
->output
= wl
->conf
.fwlog
.output
;
1430 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1432 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1434 wl1271_error("failed to send config firmware logger command");
1445 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1447 struct wl12xx_cmd_start_fwlog
*cmd
;
1450 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1452 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1458 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1460 wl1271_error("failed to send start firmware logger command");
1471 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1473 struct wl12xx_cmd_stop_fwlog
*cmd
;
1476 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1478 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1484 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1486 wl1271_error("failed to send stop firmware logger command");
1497 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1500 struct wl12xx_cmd_roc
*cmd
;
1503 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", wlvif
->channel
, role_id
);
1505 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1508 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1514 cmd
->role_id
= role_id
;
1515 cmd
->channel
= wlvif
->channel
;
1516 switch (wlvif
->band
) {
1517 case IEEE80211_BAND_2GHZ
:
1518 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1520 case IEEE80211_BAND_5GHZ
:
1521 cmd
->band
= WLCORE_BAND_5GHZ
;
1524 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1530 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1532 wl1271_error("failed to send ROC command");
1543 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1545 struct wl12xx_cmd_croc
*cmd
;
1548 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1550 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1555 cmd
->role_id
= role_id
;
1557 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1560 wl1271_error("failed to send ROC command");
1571 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
)
1575 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1578 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
);
1582 ret
= wl1271_cmd_wait_for_event(wl
,
1583 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
);
1585 wl1271_error("cmd roc event completion error");
1589 __set_bit(role_id
, wl
->roc_map
);
1594 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1598 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1601 ret
= wl12xx_cmd_croc(wl
, role_id
);
1605 __clear_bit(role_id
, wl
->roc_map
);
1608 * Rearm the tx watchdog when removing the last ROC. This prevents
1609 * recoveries due to just finished ROCs - when Tx hasn't yet had
1610 * a chance to get out.
1612 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1613 wl12xx_rearm_tx_watchdog_locked(wl
);
1618 int wl12xx_cmd_channel_switch(struct wl1271
*wl
,
1619 struct wl12xx_vif
*wlvif
,
1620 struct ieee80211_channel_switch
*ch_switch
)
1622 struct wl12xx_cmd_channel_switch
*cmd
;
1625 wl1271_debug(DEBUG_ACX
, "cmd channel switch");
1627 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1633 cmd
->role_id
= wlvif
->role_id
;
1634 cmd
->channel
= ch_switch
->channel
->hw_value
;
1635 cmd
->switch_time
= ch_switch
->count
;
1636 cmd
->stop_tx
= ch_switch
->block_tx
;
1638 /* FIXME: control from mac80211 in the future */
1639 cmd
->post_switch_tx_disable
= 0; /* Enable TX on the target channel */
1641 ret
= wl1271_cmd_send(wl
, CMD_CHANNEL_SWITCH
, cmd
, sizeof(*cmd
), 0);
1643 wl1271_error("failed to send channel switch command");
1654 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
)
1656 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1659 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1661 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1667 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1669 wl1271_error("failed to stop channel switch command");
1680 /* start dev role and roc on its channel */
1681 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1685 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1686 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1689 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
);
1693 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
);
1700 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
1705 /* croc dev hlid, and stop the role */
1706 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1710 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1711 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1714 /* flush all pending packets */
1715 wl1271_tx_work_locked(wl
);
1717 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
1718 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
1723 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);