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_KERNEL
| GFP_DMA
);
130 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
133 if (time_after(jiffies
, timeout
)) {
134 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
142 /* read from both event fields */
143 wl1271_read(wl
, wl
->mbox_ptr
[0], events_vector
,
144 sizeof(*events_vector
), false);
145 event
= *events_vector
& mask
;
146 wl1271_read(wl
, wl
->mbox_ptr
[1], events_vector
,
147 sizeof(*events_vector
), false);
148 event
|= *events_vector
& mask
;
152 kfree(events_vector
);
156 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
160 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
162 wl12xx_queue_recovery_work(wl
);
169 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
172 struct wl12xx_cmd_role_enable
*cmd
;
175 wl1271_debug(DEBUG_CMD
, "cmd role enable");
177 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
180 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
187 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
188 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
193 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
194 cmd
->role_type
= role_type
;
196 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
198 wl1271_error("failed to initiate cmd role enable");
202 __set_bit(cmd
->role_id
, wl
->roles_map
);
203 *role_id
= cmd
->role_id
;
212 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
214 struct wl12xx_cmd_role_disable
*cmd
;
217 wl1271_debug(DEBUG_CMD
, "cmd role disable");
219 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
222 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
227 cmd
->role_id
= *role_id
;
229 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
231 wl1271_error("failed to initiate cmd role disable");
235 __clear_bit(*role_id
, wl
->roles_map
);
236 *role_id
= WL12XX_INVALID_ROLE_ID
;
245 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
248 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
249 if (link
>= WL12XX_MAX_LINKS
)
252 /* these bits are used by op_tx */
253 spin_lock_irqsave(&wl
->wl_lock
, flags
);
254 __set_bit(link
, wl
->links_map
);
255 __set_bit(link
, wlvif
->links_map
);
256 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
261 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
265 if (*hlid
== WL12XX_INVALID_LINK_ID
)
268 /* these bits are used by op_tx */
269 spin_lock_irqsave(&wl
->wl_lock
, flags
);
270 __clear_bit(*hlid
, wl
->links_map
);
271 __clear_bit(*hlid
, wlvif
->links_map
);
272 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
275 * At this point op_tx() will not add more packets to the queues. We
278 wl1271_tx_reset_link_queues(wl
, *hlid
);
280 *hlid
= WL12XX_INVALID_LINK_ID
;
283 static int wl12xx_get_new_session_id(struct wl1271
*wl
,
284 struct wl12xx_vif
*wlvif
)
286 if (wlvif
->session_counter
>= SESSION_COUNTER_MAX
)
287 wlvif
->session_counter
= 0;
289 wlvif
->session_counter
++;
291 return wlvif
->session_counter
;
294 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
295 struct wl12xx_vif
*wlvif
)
297 struct wl12xx_cmd_role_start
*cmd
;
300 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
306 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
308 cmd
->role_id
= wlvif
->dev_role_id
;
309 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
310 cmd
->band
= WLCORE_BAND_5GHZ
;
311 cmd
->channel
= wlvif
->channel
;
313 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
314 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
318 cmd
->device
.hlid
= wlvif
->dev_hlid
;
319 cmd
->device
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
321 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
322 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
324 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
326 wl1271_error("failed to initiate cmd role enable");
333 /* clear links on error */
334 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
343 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
344 struct wl12xx_vif
*wlvif
)
346 struct wl12xx_cmd_role_stop
*cmd
;
349 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
352 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
358 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
360 cmd
->role_id
= wlvif
->dev_role_id
;
361 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
362 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
364 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
366 wl1271_error("failed to initiate cmd role stop");
370 ret
= wl1271_cmd_wait_for_event(wl
, ROLE_STOP_COMPLETE_EVENT_ID
);
372 wl1271_error("cmd role stop dev event completion error");
376 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
385 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
387 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
388 struct wl12xx_cmd_role_start
*cmd
;
391 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
397 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
399 cmd
->role_id
= wlvif
->role_id
;
400 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
401 cmd
->band
= WLCORE_BAND_5GHZ
;
402 cmd
->channel
= wlvif
->channel
;
403 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
404 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
405 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
406 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
407 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
408 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
409 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
411 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
412 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
416 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
417 cmd
->sta
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
418 cmd
->sta
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
420 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
421 "basic_rate_set: 0x%x, remote_rates: 0x%x",
422 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
423 wlvif
->basic_rate_set
, wlvif
->rate_set
);
425 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
427 wl1271_error("failed to initiate cmd role start sta");
434 /* clear links on error. */
435 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
444 /* use this function to stop ibss as well */
445 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
447 struct wl12xx_cmd_role_stop
*cmd
;
450 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
453 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
459 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
461 cmd
->role_id
= wlvif
->role_id
;
462 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
463 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
465 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
467 wl1271_error("failed to initiate cmd role stop sta");
471 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
480 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
482 struct wl12xx_cmd_role_start
*cmd
;
483 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
484 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
487 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
489 /* trying to use hidden SSID with an old hostapd version */
490 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
491 wl1271_error("got a null SSID from beacon/bss");
496 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
502 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
506 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
508 goto out_free_global
;
510 cmd
->role_id
= wlvif
->role_id
;
511 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
512 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
513 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
514 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
515 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
516 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
517 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
518 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
519 /* FIXME: Change when adding DFS */
520 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
521 cmd
->channel
= wlvif
->channel
;
523 if (!bss_conf
->hidden_ssid
) {
524 /* take the SSID from the beacon for backward compatibility */
525 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
526 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
527 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
529 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
530 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
531 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
534 cmd
->ap
.local_rates
= cpu_to_le32(0xffffffff);
536 switch (wlvif
->band
) {
537 case IEEE80211_BAND_2GHZ
:
538 cmd
->band
= WLCORE_BAND_2_4GHZ
;
540 case IEEE80211_BAND_5GHZ
:
541 cmd
->band
= WLCORE_BAND_5GHZ
;
544 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
545 cmd
->band
= WLCORE_BAND_2_4GHZ
;
549 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
551 wl1271_error("failed to initiate cmd role start ap");
558 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
561 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
570 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
572 struct wl12xx_cmd_role_stop
*cmd
;
575 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
581 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
583 cmd
->role_id
= wlvif
->role_id
;
585 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
587 wl1271_error("failed to initiate cmd role stop ap");
591 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
592 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
601 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
603 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
604 struct wl12xx_cmd_role_start
*cmd
;
605 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
608 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
614 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
616 cmd
->role_id
= wlvif
->role_id
;
617 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
618 cmd
->band
= WLCORE_BAND_5GHZ
;
619 cmd
->channel
= wlvif
->channel
;
620 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
621 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
622 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
623 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
624 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
625 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
626 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
627 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
629 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
630 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
634 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
635 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
637 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
638 "basic_rate_set: 0x%x, remote_rates: 0x%x",
639 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
640 wlvif
->basic_rate_set
, wlvif
->rate_set
);
642 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
643 vif
->bss_conf
.bssid
);
645 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
647 wl1271_error("failed to initiate cmd role enable");
654 /* clear links on error. */
655 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
666 * send test command to firmware
669 * @buf: buffer containing the command, with all headers, must work with dma
670 * @len: length of the buffer
671 * @answer: is answer needed
673 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
678 wl1271_debug(DEBUG_CMD
, "cmd test");
683 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
686 wl1271_warning("TEST command failed");
692 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
695 * read acx from firmware
699 * @buf: buffer for the response, including all headers, must work with dma
700 * @len: length of buf
702 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
704 struct acx_header
*acx
= buf
;
707 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
709 acx
->id
= cpu_to_le16(id
);
711 /* payload length, does not include any headers */
712 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
714 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
716 wl1271_error("INTERROGATE command failed");
722 * write acx value to firmware
726 * @buf: buffer containing acx, including all headers, must work with dma
727 * @len: length of buf
729 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
731 struct acx_header
*acx
= buf
;
734 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
736 acx
->id
= cpu_to_le16(id
);
738 /* payload length, does not include any headers */
739 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
741 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
743 wl1271_warning("CONFIGURE command NOK");
749 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
751 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
753 struct cmd_enabledisable_path
*cmd
;
757 wl1271_debug(DEBUG_CMD
, "cmd data path");
759 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
765 /* the channel here is only used for calibration, so hardcoded to 1 */
769 cmd_rx
= CMD_ENABLE_RX
;
770 cmd_tx
= CMD_ENABLE_TX
;
772 cmd_rx
= CMD_DISABLE_RX
;
773 cmd_tx
= CMD_DISABLE_TX
;
776 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
778 wl1271_error("rx %s cmd for channel %d failed",
779 enable
? "start" : "stop", cmd
->channel
);
783 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
784 enable
? "start" : "stop", cmd
->channel
);
786 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
788 wl1271_error("tx %s cmd for channel %d failed",
789 enable
? "start" : "stop", cmd
->channel
);
793 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
794 enable
? "start" : "stop", cmd
->channel
);
801 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
802 u8 ps_mode
, u16 auto_ps_timeout
)
804 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
807 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
809 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
815 ps_params
->role_id
= wlvif
->role_id
;
816 ps_params
->ps_mode
= ps_mode
;
817 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
819 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
820 sizeof(*ps_params
), 0);
822 wl1271_error("cmd set_ps_mode failed");
831 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
832 u16 template_id
, void *buf
, size_t buf_len
,
833 int index
, u32 rates
)
835 struct wl1271_cmd_template_set
*cmd
;
838 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
839 template_id
, role_id
);
841 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
842 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
844 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
850 /* during initialization wlvif is NULL */
851 cmd
->role_id
= role_id
;
852 cmd
->len
= cpu_to_le16(buf_len
);
853 cmd
->template_type
= template_id
;
854 cmd
->enabled_rates
= cpu_to_le32(rates
);
855 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
856 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
860 memcpy(cmd
->template_data
, buf
, buf_len
);
862 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
864 wl1271_warning("cmd set_template failed: %d", ret
);
875 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
877 struct sk_buff
*skb
= NULL
;
883 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
884 size
= sizeof(struct wl12xx_null_data_template
);
887 skb
= ieee80211_nullfunc_get(wl
->hw
,
888 wl12xx_wlvif_to_vif(wlvif
));
895 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
896 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
902 wl1271_warning("cmd buld null data failed %d", ret
);
908 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
909 struct wl12xx_vif
*wlvif
)
911 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
912 struct sk_buff
*skb
= NULL
;
915 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
919 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
921 CMD_TEMPL_KLV_IDX_NULL_DATA
,
927 wl1271_warning("cmd build klv null data failed %d", ret
);
933 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
936 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
940 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
944 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
945 CMD_TEMPL_PS_POLL
, skb
->data
,
946 skb
->len
, 0, wlvif
->basic_rate_set
);
953 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
955 const u8
*ssid
, size_t ssid_len
,
956 const u8
*ie
, size_t ie_len
)
958 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
963 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
970 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
972 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
973 if (band
== IEEE80211_BAND_2GHZ
)
974 ret
= wl1271_cmd_template_set(wl
, role_id
,
975 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
976 skb
->data
, skb
->len
, 0, rate
);
978 ret
= wl1271_cmd_template_set(wl
, role_id
,
979 CMD_TEMPL_CFG_PROBE_REQ_5
,
980 skb
->data
, skb
->len
, 0, rate
);
987 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
988 struct wl12xx_vif
*wlvif
,
991 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
996 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1000 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1002 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1003 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1004 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1005 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1006 skb
->data
, skb
->len
, 0, rate
);
1008 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1009 CMD_TEMPL_CFG_PROBE_REQ_5
,
1010 skb
->data
, skb
->len
, 0, rate
);
1013 wl1271_error("Unable to set ap probe request template.");
1019 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1023 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1024 struct sk_buff
*skb
;
1025 struct wl12xx_arp_rsp_template
*tmpl
;
1026 struct ieee80211_hdr_3addr
*hdr
;
1027 struct arphdr
*arp_hdr
;
1029 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1030 WL1271_EXTRA_SPACE_MAX
);
1032 wl1271_error("failed to allocate buffer for arp rsp template");
1036 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1038 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1039 memset(tmpl
, 0, sizeof(*tmpl
));
1042 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1043 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1046 arp_hdr
= &tmpl
->arp_hdr
;
1047 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1048 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1049 arp_hdr
->ar_hln
= ETH_ALEN
;
1050 arp_hdr
->ar_pln
= 4;
1051 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1054 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1055 tmpl
->sender_ip
= wlvif
->ip_addr
;
1057 /* encryption space */
1058 switch (wlvif
->encryption_type
) {
1060 extra
= WL1271_EXTRA_SPACE_TKIP
;
1063 extra
= WL1271_EXTRA_SPACE_AES
;
1071 wl1271_warning("Unknown encryption type: %d",
1072 wlvif
->encryption_type
);
1078 u8
*space
= skb_push(skb
, extra
);
1079 memset(space
, 0, extra
);
1082 /* QoS header - BE */
1084 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1086 /* mac80211 header */
1087 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1088 memset(hdr
, 0, sizeof(*hdr
));
1089 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1091 fc
|= IEEE80211_STYPE_QOS_DATA
;
1093 fc
|= IEEE80211_STYPE_DATA
;
1094 if (wlvif
->encryption_type
!= KEY_NONE
)
1095 fc
|= IEEE80211_FCTL_PROTECTED
;
1097 hdr
->frame_control
= cpu_to_le16(fc
);
1098 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1099 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1100 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1102 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1103 skb
->data
, skb
->len
, 0,
1110 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1112 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1113 struct ieee80211_qos_hdr
template;
1115 memset(&template, 0, sizeof(template));
1117 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1118 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1119 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1121 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1122 IEEE80211_STYPE_QOS_NULLFUNC
|
1123 IEEE80211_FCTL_TODS
);
1125 /* FIXME: not sure what priority to use here */
1126 template.qos_ctrl
= cpu_to_le16(0);
1128 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1129 CMD_TEMPL_QOS_NULL_DATA
, &template,
1130 sizeof(template), 0,
1134 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1136 struct wl1271_cmd_set_keys
*cmd
;
1139 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1141 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1149 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1150 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1151 cmd
->key_type
= KEY_WEP
;
1153 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1155 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1165 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1166 u16 action
, u8 id
, u8 key_type
,
1167 u8 key_size
, const u8
*key
, const u8
*addr
,
1168 u32 tx_seq_32
, u16 tx_seq_16
)
1170 struct wl1271_cmd_set_keys
*cmd
;
1173 /* hlid might have already been deleted */
1174 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1177 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1183 cmd
->hlid
= wlvif
->sta
.hlid
;
1185 if (key_type
== KEY_WEP
)
1186 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1187 else if (is_broadcast_ether_addr(addr
))
1188 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1190 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1192 cmd
->key_action
= cpu_to_le16(action
);
1193 cmd
->key_size
= key_size
;
1194 cmd
->key_type
= key_type
;
1196 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1197 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1201 if (key_type
== KEY_TKIP
) {
1203 * We get the key in the following form:
1204 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1205 * but the target is expecting:
1206 * TKIP - RX MIC - TX MIC
1208 memcpy(cmd
->key
, key
, 16);
1209 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1210 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1213 memcpy(cmd
->key
, key
, key_size
);
1216 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1218 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1220 wl1271_warning("could not set keys");
1231 * TODO: merge with sta/ibss into 1 set_key function.
1232 * note there are slight diffs
1234 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1235 u16 action
, u8 id
, u8 key_type
,
1236 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1239 struct wl1271_cmd_set_keys
*cmd
;
1243 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1247 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1248 if (key_type
== KEY_WEP
)
1249 lid_type
= WEP_DEFAULT_LID_TYPE
;
1251 lid_type
= BROADCAST_LID_TYPE
;
1253 lid_type
= UNICAST_LID_TYPE
;
1256 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1257 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1258 (int)key_type
, (int)hlid
);
1260 cmd
->lid_key_type
= lid_type
;
1262 cmd
->key_action
= cpu_to_le16(action
);
1263 cmd
->key_size
= key_size
;
1264 cmd
->key_type
= key_type
;
1266 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1267 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1269 if (key_type
== KEY_TKIP
) {
1271 * We get the key in the following form:
1272 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1273 * but the target is expecting:
1274 * TKIP - RX MIC - TX MIC
1276 memcpy(cmd
->key
, key
, 16);
1277 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1278 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1280 memcpy(cmd
->key
, key
, key_size
);
1283 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1285 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1287 wl1271_warning("could not set ap keys");
1296 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, u8 hlid
)
1298 struct wl12xx_cmd_set_peer_state
*cmd
;
1301 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1303 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1310 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1312 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1314 wl1271_error("failed to send set peer state command");
1325 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1326 struct ieee80211_sta
*sta
, u8 hlid
)
1328 struct wl12xx_cmd_add_peer
*cmd
;
1332 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1334 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1340 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1341 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1342 cmd
->aid
= sta
->aid
;
1344 cmd
->sp_len
= sta
->max_sp
;
1345 cmd
->wmm
= sta
->wme
? 1 : 0;
1347 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1348 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1349 cmd
->psd_type
[i
] = WL1271_PSD_UPSD_TRIGGER
;
1351 cmd
->psd_type
[i
] = WL1271_PSD_LEGACY
;
1353 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1354 if (sta
->ht_cap
.ht_supported
)
1355 sta_rates
|= sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
;
1357 cmd
->supported_rates
=
1358 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1361 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1362 cmd
->supported_rates
, sta
->uapsd_queues
);
1364 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1366 wl1271_error("failed to initiate cmd add peer");
1377 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1379 struct wl12xx_cmd_remove_peer
*cmd
;
1382 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1384 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1391 /* We never send a deauth, mac80211 is in charge of this */
1392 cmd
->reason_opcode
= 0;
1393 cmd
->send_deauth_flag
= 0;
1395 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1397 wl1271_error("failed to initiate cmd remove peer");
1402 * We are ok with a timeout here. The event is sometimes not sent
1403 * due to a firmware bug.
1405 wl1271_cmd_wait_for_event_or_timeout(wl
,
1406 PEER_REMOVE_COMPLETE_EVENT_ID
);
1415 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1417 struct wl12xx_cmd_config_fwlog
*cmd
;
1420 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1422 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1428 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1429 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1430 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1431 cmd
->output
= wl
->conf
.fwlog
.output
;
1432 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1434 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1436 wl1271_error("failed to send config firmware logger command");
1447 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1449 struct wl12xx_cmd_start_fwlog
*cmd
;
1452 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1454 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1460 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1462 wl1271_error("failed to send start firmware logger command");
1473 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1475 struct wl12xx_cmd_stop_fwlog
*cmd
;
1478 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1480 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1486 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1488 wl1271_error("failed to send stop firmware logger command");
1499 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1502 struct wl12xx_cmd_roc
*cmd
;
1505 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", wlvif
->channel
, role_id
);
1507 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1510 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1516 cmd
->role_id
= role_id
;
1517 cmd
->channel
= wlvif
->channel
;
1518 switch (wlvif
->band
) {
1519 case IEEE80211_BAND_2GHZ
:
1520 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1522 case IEEE80211_BAND_5GHZ
:
1523 cmd
->band
= WLCORE_BAND_5GHZ
;
1526 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1532 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1534 wl1271_error("failed to send ROC command");
1545 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1547 struct wl12xx_cmd_croc
*cmd
;
1550 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1552 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1557 cmd
->role_id
= role_id
;
1559 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1562 wl1271_error("failed to send ROC command");
1573 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
)
1577 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1580 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
);
1584 ret
= wl1271_cmd_wait_for_event(wl
,
1585 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
);
1587 wl1271_error("cmd roc event completion error");
1591 __set_bit(role_id
, wl
->roc_map
);
1596 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1600 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1603 ret
= wl12xx_cmd_croc(wl
, role_id
);
1607 __clear_bit(role_id
, wl
->roc_map
);
1610 * Rearm the tx watchdog when removing the last ROC. This prevents
1611 * recoveries due to just finished ROCs - when Tx hasn't yet had
1612 * a chance to get out.
1614 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1615 wl12xx_rearm_tx_watchdog_locked(wl
);
1620 int wl12xx_cmd_channel_switch(struct wl1271
*wl
,
1621 struct wl12xx_vif
*wlvif
,
1622 struct ieee80211_channel_switch
*ch_switch
)
1624 struct wl12xx_cmd_channel_switch
*cmd
;
1627 wl1271_debug(DEBUG_ACX
, "cmd channel switch");
1629 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1635 cmd
->role_id
= wlvif
->role_id
;
1636 cmd
->channel
= ch_switch
->channel
->hw_value
;
1637 cmd
->switch_time
= ch_switch
->count
;
1638 cmd
->stop_tx
= ch_switch
->block_tx
;
1640 /* FIXME: control from mac80211 in the future */
1641 cmd
->post_switch_tx_disable
= 0; /* Enable TX on the target channel */
1643 ret
= wl1271_cmd_send(wl
, CMD_CHANNEL_SWITCH
, cmd
, sizeof(*cmd
), 0);
1645 wl1271_error("failed to send channel switch command");
1656 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
)
1658 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1661 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1663 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1669 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1671 wl1271_error("failed to stop channel switch command");
1682 /* start dev role and roc on its channel */
1683 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1687 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1688 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1691 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
);
1695 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
);
1702 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
1707 /* croc dev hlid, and stop the role */
1708 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1712 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1713 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1716 /* flush all pending packets */
1717 wl1271_tx_work_locked(wl
);
1719 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
1720 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
1725 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);