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
44 * send command to firmware
48 * @buf: buffer containing the command, must work with dma
49 * @len: length of the buffer
51 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
54 struct wl1271_cmd_header
*cmd
;
55 unsigned long timeout
;
62 cmd
->id
= cpu_to_le16(id
);
65 WARN_ON(len
% 4 != 0);
66 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
68 ret
= wlcore_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
73 * TODO: we just need this because one bit is in a different
74 * place. Is there any better way?
76 ret
= wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
80 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
82 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
86 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
87 if (time_after(jiffies
, timeout
)) {
88 wl1271_error("command complete timeout");
94 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
99 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
104 /* read back the status code of the command */
106 res_len
= sizeof(struct wl1271_cmd_header
);
108 ret
= wlcore_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
112 status
= le16_to_cpu(cmd
->status
);
113 if (status
!= CMD_STATUS_SUCCESS
) {
114 wl1271_error("command execute failure %d", status
);
119 wlcore_write_reg(wl
, REG_INTERRUPT_ACK
, WL1271_ACX_INTR_CMD_COMPLETE
);
124 wl12xx_queue_recovery_work(wl
);
129 * Poll the mailbox event field until any of the bits in the mask is set or a
130 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
132 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271
*wl
, u32 mask
)
136 unsigned long timeout
;
139 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
143 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
146 if (time_after(jiffies
, timeout
)) {
147 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
155 /* read from both event fields */
156 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
157 sizeof(*events_vector
), false);
161 event
= *events_vector
& mask
;
163 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
164 sizeof(*events_vector
), false);
168 event
|= *events_vector
& mask
;
172 kfree(events_vector
);
176 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
180 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
182 wl12xx_queue_recovery_work(wl
);
189 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
192 struct wl12xx_cmd_role_enable
*cmd
;
195 wl1271_debug(DEBUG_CMD
, "cmd role enable");
197 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
200 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
207 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
208 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
213 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
214 cmd
->role_type
= role_type
;
216 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
218 wl1271_error("failed to initiate cmd role enable");
222 __set_bit(cmd
->role_id
, wl
->roles_map
);
223 *role_id
= cmd
->role_id
;
232 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
234 struct wl12xx_cmd_role_disable
*cmd
;
237 wl1271_debug(DEBUG_CMD
, "cmd role disable");
239 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
242 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
247 cmd
->role_id
= *role_id
;
249 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
251 wl1271_error("failed to initiate cmd role disable");
255 __clear_bit(*role_id
, wl
->roles_map
);
256 *role_id
= WL12XX_INVALID_ROLE_ID
;
265 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
268 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
269 if (link
>= WL12XX_MAX_LINKS
)
272 /* these bits are used by op_tx */
273 spin_lock_irqsave(&wl
->wl_lock
, flags
);
274 __set_bit(link
, wl
->links_map
);
275 __set_bit(link
, wlvif
->links_map
);
276 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
281 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
285 if (*hlid
== WL12XX_INVALID_LINK_ID
)
288 /* these bits are used by op_tx */
289 spin_lock_irqsave(&wl
->wl_lock
, flags
);
290 __clear_bit(*hlid
, wl
->links_map
);
291 __clear_bit(*hlid
, wlvif
->links_map
);
292 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
295 * At this point op_tx() will not add more packets to the queues. We
298 wl1271_tx_reset_link_queues(wl
, *hlid
);
300 *hlid
= WL12XX_INVALID_LINK_ID
;
303 static int wl12xx_get_new_session_id(struct wl1271
*wl
,
304 struct wl12xx_vif
*wlvif
)
306 if (wlvif
->session_counter
>= SESSION_COUNTER_MAX
)
307 wlvif
->session_counter
= 0;
309 wlvif
->session_counter
++;
311 return wlvif
->session_counter
;
314 static u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
316 switch (nl_channel_type
) {
317 case NL80211_CHAN_NO_HT
:
318 return WLCORE_CHAN_NO_HT
;
319 case NL80211_CHAN_HT20
:
320 return WLCORE_CHAN_HT20
;
321 case NL80211_CHAN_HT40MINUS
:
322 return WLCORE_CHAN_HT40MINUS
;
323 case NL80211_CHAN_HT40PLUS
:
324 return WLCORE_CHAN_HT40PLUS
;
327 return WLCORE_CHAN_NO_HT
;
331 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
332 struct wl12xx_vif
*wlvif
)
334 struct wl12xx_cmd_role_start
*cmd
;
337 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
343 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
345 cmd
->role_id
= wlvif
->dev_role_id
;
346 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
347 cmd
->band
= WLCORE_BAND_5GHZ
;
348 cmd
->channel
= wlvif
->channel
;
350 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
351 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
355 cmd
->device
.hlid
= wlvif
->dev_hlid
;
356 cmd
->device
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
358 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
359 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
361 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
363 wl1271_error("failed to initiate cmd role enable");
370 /* clear links on error */
371 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
380 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
381 struct wl12xx_vif
*wlvif
)
383 struct wl12xx_cmd_role_stop
*cmd
;
386 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
389 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
395 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
397 cmd
->role_id
= wlvif
->dev_role_id
;
398 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
399 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
401 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
403 wl1271_error("failed to initiate cmd role stop");
407 ret
= wl1271_cmd_wait_for_event(wl
, ROLE_STOP_COMPLETE_EVENT_ID
);
409 wl1271_error("cmd role stop dev event completion error");
413 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
422 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
424 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
425 struct wl12xx_cmd_role_start
*cmd
;
428 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
434 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
436 cmd
->role_id
= wlvif
->role_id
;
437 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
438 cmd
->band
= WLCORE_BAND_5GHZ
;
439 cmd
->channel
= wlvif
->channel
;
440 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
441 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
442 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
443 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
444 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
445 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
446 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
447 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
449 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
450 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
454 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
455 cmd
->sta
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
456 cmd
->sta
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
458 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
459 "basic_rate_set: 0x%x, remote_rates: 0x%x",
460 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
461 wlvif
->basic_rate_set
, wlvif
->rate_set
);
463 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
465 wl1271_error("failed to initiate cmd role start sta");
472 /* clear links on error. */
473 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
482 /* use this function to stop ibss as well */
483 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
485 struct wl12xx_cmd_role_stop
*cmd
;
488 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
491 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
497 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
499 cmd
->role_id
= wlvif
->role_id
;
500 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
501 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
503 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
505 wl1271_error("failed to initiate cmd role stop sta");
509 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
518 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
520 struct wl12xx_cmd_role_start
*cmd
;
521 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
522 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
526 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
528 /* trying to use hidden SSID with an old hostapd version */
529 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
530 wl1271_error("got a null SSID from beacon/bss");
535 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
541 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
545 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
547 goto out_free_global
;
549 cmd
->role_id
= wlvif
->role_id
;
550 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
551 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
552 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
553 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
554 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
555 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
556 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
557 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
558 /* FIXME: Change when adding DFS */
559 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
560 cmd
->channel
= wlvif
->channel
;
561 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
563 if (!bss_conf
->hidden_ssid
) {
564 /* take the SSID from the beacon for backward compatibility */
565 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
566 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
567 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
569 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
570 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
571 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
574 supported_rates
= CONF_TX_AP_ENABLED_RATES
| CONF_TX_MCS_RATES
|
575 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
577 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
580 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
582 switch (wlvif
->band
) {
583 case IEEE80211_BAND_2GHZ
:
584 cmd
->band
= WLCORE_BAND_2_4GHZ
;
586 case IEEE80211_BAND_5GHZ
:
587 cmd
->band
= WLCORE_BAND_5GHZ
;
590 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
591 cmd
->band
= WLCORE_BAND_2_4GHZ
;
595 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
597 wl1271_error("failed to initiate cmd role start ap");
604 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
607 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
616 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
618 struct wl12xx_cmd_role_stop
*cmd
;
621 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
627 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
629 cmd
->role_id
= wlvif
->role_id
;
631 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
633 wl1271_error("failed to initiate cmd role stop ap");
637 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
638 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
647 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
649 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
650 struct wl12xx_cmd_role_start
*cmd
;
651 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
654 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
660 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
662 cmd
->role_id
= wlvif
->role_id
;
663 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
664 cmd
->band
= WLCORE_BAND_5GHZ
;
665 cmd
->channel
= wlvif
->channel
;
666 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
667 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
668 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
669 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
670 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
671 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
672 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
673 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
675 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
676 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
680 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
681 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
683 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
684 "basic_rate_set: 0x%x, remote_rates: 0x%x",
685 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
686 wlvif
->basic_rate_set
, wlvif
->rate_set
);
688 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
689 vif
->bss_conf
.bssid
);
691 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
693 wl1271_error("failed to initiate cmd role enable");
700 /* clear links on error. */
701 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
712 * send test command to firmware
715 * @buf: buffer containing the command, with all headers, must work with dma
716 * @len: length of the buffer
717 * @answer: is answer needed
719 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
724 wl1271_debug(DEBUG_CMD
, "cmd test");
729 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
732 wl1271_warning("TEST command failed");
738 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
741 * read acx from firmware
745 * @buf: buffer for the response, including all headers, must work with dma
746 * @len: length of buf
748 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
750 struct acx_header
*acx
= buf
;
753 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
755 acx
->id
= cpu_to_le16(id
);
757 /* payload length, does not include any headers */
758 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
760 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
762 wl1271_error("INTERROGATE command failed");
768 * write acx value to firmware
772 * @buf: buffer containing acx, including all headers, must work with dma
773 * @len: length of buf
775 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
777 struct acx_header
*acx
= buf
;
780 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
782 acx
->id
= cpu_to_le16(id
);
784 /* payload length, does not include any headers */
785 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
787 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
789 wl1271_warning("CONFIGURE command NOK");
795 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
797 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
799 struct cmd_enabledisable_path
*cmd
;
803 wl1271_debug(DEBUG_CMD
, "cmd data path");
805 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
811 /* the channel here is only used for calibration, so hardcoded to 1 */
815 cmd_rx
= CMD_ENABLE_RX
;
816 cmd_tx
= CMD_ENABLE_TX
;
818 cmd_rx
= CMD_DISABLE_RX
;
819 cmd_tx
= CMD_DISABLE_TX
;
822 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
824 wl1271_error("rx %s cmd for channel %d failed",
825 enable
? "start" : "stop", cmd
->channel
);
829 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
830 enable
? "start" : "stop", cmd
->channel
);
832 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
834 wl1271_error("tx %s cmd for channel %d failed",
835 enable
? "start" : "stop", cmd
->channel
);
839 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
840 enable
? "start" : "stop", cmd
->channel
);
846 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
848 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
849 u8 ps_mode
, u16 auto_ps_timeout
)
851 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
854 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
856 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
862 ps_params
->role_id
= wlvif
->role_id
;
863 ps_params
->ps_mode
= ps_mode
;
864 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
866 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
867 sizeof(*ps_params
), 0);
869 wl1271_error("cmd set_ps_mode failed");
878 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
879 u16 template_id
, void *buf
, size_t buf_len
,
880 int index
, u32 rates
)
882 struct wl1271_cmd_template_set
*cmd
;
885 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
886 template_id
, role_id
);
888 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
889 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
891 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
897 /* during initialization wlvif is NULL */
898 cmd
->role_id
= role_id
;
899 cmd
->len
= cpu_to_le16(buf_len
);
900 cmd
->template_type
= template_id
;
901 cmd
->enabled_rates
= cpu_to_le32(rates
);
902 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
903 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
907 memcpy(cmd
->template_data
, buf
, buf_len
);
909 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
911 wl1271_warning("cmd set_template failed: %d", ret
);
922 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
924 struct sk_buff
*skb
= NULL
;
930 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
931 size
= sizeof(struct wl12xx_null_data_template
);
934 skb
= ieee80211_nullfunc_get(wl
->hw
,
935 wl12xx_wlvif_to_vif(wlvif
));
942 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
943 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
949 wl1271_warning("cmd buld null data failed %d", ret
);
955 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
956 struct wl12xx_vif
*wlvif
)
958 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
959 struct sk_buff
*skb
= NULL
;
962 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
966 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
968 CMD_TEMPL_KLV_IDX_NULL_DATA
,
974 wl1271_warning("cmd build klv null data failed %d", ret
);
980 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
983 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
987 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
991 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
992 CMD_TEMPL_PS_POLL
, skb
->data
,
993 skb
->len
, 0, wlvif
->basic_rate_set
);
1000 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1001 u8 role_id
, u8 band
,
1002 const u8
*ssid
, size_t ssid_len
,
1003 const u8
*ie
, size_t ie_len
)
1005 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1006 struct sk_buff
*skb
;
1010 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1017 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
1019 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1020 if (band
== IEEE80211_BAND_2GHZ
)
1021 ret
= wl1271_cmd_template_set(wl
, role_id
,
1022 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1023 skb
->data
, skb
->len
, 0, rate
);
1025 ret
= wl1271_cmd_template_set(wl
, role_id
,
1026 CMD_TEMPL_CFG_PROBE_REQ_5
,
1027 skb
->data
, skb
->len
, 0, rate
);
1034 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1035 struct wl12xx_vif
*wlvif
,
1036 struct sk_buff
*skb
)
1038 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1043 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1047 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1049 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1050 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1051 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1052 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1053 skb
->data
, skb
->len
, 0, rate
);
1055 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1056 CMD_TEMPL_CFG_PROBE_REQ_5
,
1057 skb
->data
, skb
->len
, 0, rate
);
1060 wl1271_error("Unable to set ap probe request template.");
1066 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1070 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1071 struct sk_buff
*skb
;
1072 struct wl12xx_arp_rsp_template
*tmpl
;
1073 struct ieee80211_hdr_3addr
*hdr
;
1074 struct arphdr
*arp_hdr
;
1076 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1077 WL1271_EXTRA_SPACE_MAX
);
1079 wl1271_error("failed to allocate buffer for arp rsp template");
1083 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1085 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1086 memset(tmpl
, 0, sizeof(*tmpl
));
1089 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1090 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1093 arp_hdr
= &tmpl
->arp_hdr
;
1094 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1095 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1096 arp_hdr
->ar_hln
= ETH_ALEN
;
1097 arp_hdr
->ar_pln
= 4;
1098 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1101 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1102 tmpl
->sender_ip
= wlvif
->ip_addr
;
1104 /* encryption space */
1105 switch (wlvif
->encryption_type
) {
1107 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1108 extra
= WL1271_EXTRA_SPACE_TKIP
;
1111 extra
= WL1271_EXTRA_SPACE_AES
;
1119 wl1271_warning("Unknown encryption type: %d",
1120 wlvif
->encryption_type
);
1126 u8
*space
= skb_push(skb
, extra
);
1127 memset(space
, 0, extra
);
1130 /* QoS header - BE */
1132 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1134 /* mac80211 header */
1135 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1136 memset(hdr
, 0, sizeof(*hdr
));
1137 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1139 fc
|= IEEE80211_STYPE_QOS_DATA
;
1141 fc
|= IEEE80211_STYPE_DATA
;
1142 if (wlvif
->encryption_type
!= KEY_NONE
)
1143 fc
|= IEEE80211_FCTL_PROTECTED
;
1145 hdr
->frame_control
= cpu_to_le16(fc
);
1146 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1147 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1148 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1150 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1151 skb
->data
, skb
->len
, 0,
1158 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1160 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1161 struct ieee80211_qos_hdr
template;
1163 memset(&template, 0, sizeof(template));
1165 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1166 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1167 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1169 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1170 IEEE80211_STYPE_QOS_NULLFUNC
|
1171 IEEE80211_FCTL_TODS
);
1173 /* FIXME: not sure what priority to use here */
1174 template.qos_ctrl
= cpu_to_le16(0);
1176 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1177 CMD_TEMPL_QOS_NULL_DATA
, &template,
1178 sizeof(template), 0,
1182 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1184 struct wl1271_cmd_set_keys
*cmd
;
1187 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1189 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1197 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1198 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1199 cmd
->key_type
= KEY_WEP
;
1201 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1203 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1213 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1214 u16 action
, u8 id
, u8 key_type
,
1215 u8 key_size
, const u8
*key
, const u8
*addr
,
1216 u32 tx_seq_32
, u16 tx_seq_16
)
1218 struct wl1271_cmd_set_keys
*cmd
;
1221 /* hlid might have already been deleted */
1222 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1225 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1231 cmd
->hlid
= wlvif
->sta
.hlid
;
1233 if (key_type
== KEY_WEP
)
1234 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1235 else if (is_broadcast_ether_addr(addr
))
1236 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1238 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1240 cmd
->key_action
= cpu_to_le16(action
);
1241 cmd
->key_size
= key_size
;
1242 cmd
->key_type
= key_type
;
1244 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1245 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1249 if (key_type
== KEY_TKIP
) {
1251 * We get the key in the following form:
1252 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1253 * but the target is expecting:
1254 * TKIP - RX MIC - TX MIC
1256 memcpy(cmd
->key
, key
, 16);
1257 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1258 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1261 memcpy(cmd
->key
, key
, key_size
);
1264 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1266 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1268 wl1271_warning("could not set keys");
1279 * TODO: merge with sta/ibss into 1 set_key function.
1280 * note there are slight diffs
1282 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1283 u16 action
, u8 id
, u8 key_type
,
1284 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1287 struct wl1271_cmd_set_keys
*cmd
;
1291 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1295 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1296 if (key_type
== KEY_WEP
)
1297 lid_type
= WEP_DEFAULT_LID_TYPE
;
1299 lid_type
= BROADCAST_LID_TYPE
;
1301 lid_type
= UNICAST_LID_TYPE
;
1304 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1305 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1306 (int)key_type
, (int)hlid
);
1308 cmd
->lid_key_type
= lid_type
;
1310 cmd
->key_action
= cpu_to_le16(action
);
1311 cmd
->key_size
= key_size
;
1312 cmd
->key_type
= key_type
;
1314 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1315 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1317 if (key_type
== KEY_TKIP
) {
1319 * We get the key in the following form:
1320 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1321 * but the target is expecting:
1322 * TKIP - RX MIC - TX MIC
1324 memcpy(cmd
->key
, key
, 16);
1325 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1326 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1328 memcpy(cmd
->key
, key
, key_size
);
1331 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1333 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1335 wl1271_warning("could not set ap keys");
1344 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, u8 hlid
)
1346 struct wl12xx_cmd_set_peer_state
*cmd
;
1349 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1351 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1358 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1360 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1362 wl1271_error("failed to send set peer state command");
1373 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1374 struct ieee80211_sta
*sta
, u8 hlid
)
1376 struct wl12xx_cmd_add_peer
*cmd
;
1380 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1382 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1388 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1389 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1390 cmd
->aid
= sta
->aid
;
1392 cmd
->sp_len
= sta
->max_sp
;
1393 cmd
->wmm
= sta
->wme
? 1 : 0;
1395 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1396 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1397 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1398 WL1271_PSD_UPSD_TRIGGER
;
1400 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1404 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1405 if (sta
->ht_cap
.ht_supported
)
1407 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1408 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1410 cmd
->supported_rates
=
1411 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1414 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1415 cmd
->supported_rates
, sta
->uapsd_queues
);
1417 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1419 wl1271_error("failed to initiate cmd add peer");
1430 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1432 struct wl12xx_cmd_remove_peer
*cmd
;
1435 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1437 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1444 /* We never send a deauth, mac80211 is in charge of this */
1445 cmd
->reason_opcode
= 0;
1446 cmd
->send_deauth_flag
= 0;
1448 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1450 wl1271_error("failed to initiate cmd remove peer");
1455 * We are ok with a timeout here. The event is sometimes not sent
1456 * due to a firmware bug.
1458 wl1271_cmd_wait_for_event_or_timeout(wl
,
1459 PEER_REMOVE_COMPLETE_EVENT_ID
);
1468 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1470 struct wl12xx_cmd_config_fwlog
*cmd
;
1473 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1475 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1481 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1482 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1483 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1484 cmd
->output
= wl
->conf
.fwlog
.output
;
1485 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1487 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1489 wl1271_error("failed to send config firmware logger command");
1500 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1502 struct wl12xx_cmd_start_fwlog
*cmd
;
1505 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1507 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1513 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1515 wl1271_error("failed to send start firmware logger command");
1526 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1528 struct wl12xx_cmd_stop_fwlog
*cmd
;
1531 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1533 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1539 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1541 wl1271_error("failed to send stop firmware logger command");
1552 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1555 struct wl12xx_cmd_roc
*cmd
;
1558 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", wlvif
->channel
, role_id
);
1560 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1563 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1569 cmd
->role_id
= role_id
;
1570 cmd
->channel
= wlvif
->channel
;
1571 switch (wlvif
->band
) {
1572 case IEEE80211_BAND_2GHZ
:
1573 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1575 case IEEE80211_BAND_5GHZ
:
1576 cmd
->band
= WLCORE_BAND_5GHZ
;
1579 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1585 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1587 wl1271_error("failed to send ROC command");
1598 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1600 struct wl12xx_cmd_croc
*cmd
;
1603 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1605 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1610 cmd
->role_id
= role_id
;
1612 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1615 wl1271_error("failed to send ROC command");
1626 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
)
1631 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1634 is_first_roc
= (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >=
1637 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
);
1642 ret
= wl1271_cmd_wait_for_event(wl
,
1643 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
);
1645 wl1271_error("cmd roc event completion error");
1650 __set_bit(role_id
, wl
->roc_map
);
1655 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1659 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1662 ret
= wl12xx_cmd_croc(wl
, role_id
);
1666 __clear_bit(role_id
, wl
->roc_map
);
1669 * Rearm the tx watchdog when removing the last ROC. This prevents
1670 * recoveries due to just finished ROCs - when Tx hasn't yet had
1671 * a chance to get out.
1673 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1674 wl12xx_rearm_tx_watchdog_locked(wl
);
1679 int wl12xx_cmd_channel_switch(struct wl1271
*wl
,
1680 struct wl12xx_vif
*wlvif
,
1681 struct ieee80211_channel_switch
*ch_switch
)
1683 struct wl12xx_cmd_channel_switch
*cmd
;
1686 wl1271_debug(DEBUG_ACX
, "cmd channel switch");
1688 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1694 cmd
->role_id
= wlvif
->role_id
;
1695 cmd
->channel
= ch_switch
->channel
->hw_value
;
1696 cmd
->switch_time
= ch_switch
->count
;
1697 cmd
->stop_tx
= ch_switch
->block_tx
;
1699 /* FIXME: control from mac80211 in the future */
1700 cmd
->post_switch_tx_disable
= 0; /* Enable TX on the target channel */
1702 ret
= wl1271_cmd_send(wl
, CMD_CHANNEL_SWITCH
, cmd
, sizeof(*cmd
), 0);
1704 wl1271_error("failed to send channel switch command");
1715 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
)
1717 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1720 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1722 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1728 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1730 wl1271_error("failed to stop channel switch command");
1741 /* start dev role and roc on its channel */
1742 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1746 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1747 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1750 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
);
1754 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
);
1761 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
1766 /* croc dev hlid, and stop the role */
1767 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1771 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1772 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1775 /* flush all pending packets */
1776 ret
= wlcore_tx_work_locked(wl
);
1780 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
1781 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
1786 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);