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 ret
= wlcore_write_reg(wl
, REG_INTERRUPT_ACK
,
120 WL1271_ACX_INTR_CMD_COMPLETE
);
128 wl12xx_queue_recovery_work(wl
);
133 * Poll the mailbox event field until any of the bits in the mask is set or a
134 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
136 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271
*wl
, u32 mask
)
140 unsigned long timeout
;
143 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
147 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
150 if (time_after(jiffies
, timeout
)) {
151 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
159 /* read from both event fields */
160 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
161 sizeof(*events_vector
), false);
165 event
= *events_vector
& mask
;
167 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
168 sizeof(*events_vector
), false);
172 event
|= *events_vector
& mask
;
176 kfree(events_vector
);
180 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
184 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
186 wl12xx_queue_recovery_work(wl
);
193 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
196 struct wl12xx_cmd_role_enable
*cmd
;
199 wl1271_debug(DEBUG_CMD
, "cmd role enable");
201 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
204 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
211 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
212 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
217 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
218 cmd
->role_type
= role_type
;
220 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
222 wl1271_error("failed to initiate cmd role enable");
226 __set_bit(cmd
->role_id
, wl
->roles_map
);
227 *role_id
= cmd
->role_id
;
236 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
238 struct wl12xx_cmd_role_disable
*cmd
;
241 wl1271_debug(DEBUG_CMD
, "cmd role disable");
243 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
246 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
251 cmd
->role_id
= *role_id
;
253 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
255 wl1271_error("failed to initiate cmd role disable");
259 __clear_bit(*role_id
, wl
->roles_map
);
260 *role_id
= WL12XX_INVALID_ROLE_ID
;
269 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
272 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
273 if (link
>= WL12XX_MAX_LINKS
)
276 /* these bits are used by op_tx */
277 spin_lock_irqsave(&wl
->wl_lock
, flags
);
278 __set_bit(link
, wl
->links_map
);
279 __set_bit(link
, wlvif
->links_map
);
280 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
285 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
289 if (*hlid
== WL12XX_INVALID_LINK_ID
)
292 /* these bits are used by op_tx */
293 spin_lock_irqsave(&wl
->wl_lock
, flags
);
294 __clear_bit(*hlid
, wl
->links_map
);
295 __clear_bit(*hlid
, wlvif
->links_map
);
296 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
299 * At this point op_tx() will not add more packets to the queues. We
302 wl1271_tx_reset_link_queues(wl
, *hlid
);
304 *hlid
= WL12XX_INVALID_LINK_ID
;
307 static int wl12xx_get_new_session_id(struct wl1271
*wl
,
308 struct wl12xx_vif
*wlvif
)
310 if (wlvif
->session_counter
>= SESSION_COUNTER_MAX
)
311 wlvif
->session_counter
= 0;
313 wlvif
->session_counter
++;
315 return wlvif
->session_counter
;
318 static u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
320 switch (nl_channel_type
) {
321 case NL80211_CHAN_NO_HT
:
322 return WLCORE_CHAN_NO_HT
;
323 case NL80211_CHAN_HT20
:
324 return WLCORE_CHAN_HT20
;
325 case NL80211_CHAN_HT40MINUS
:
326 return WLCORE_CHAN_HT40MINUS
;
327 case NL80211_CHAN_HT40PLUS
:
328 return WLCORE_CHAN_HT40PLUS
;
331 return WLCORE_CHAN_NO_HT
;
335 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
336 struct wl12xx_vif
*wlvif
)
338 struct wl12xx_cmd_role_start
*cmd
;
341 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
347 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
349 cmd
->role_id
= wlvif
->dev_role_id
;
350 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
351 cmd
->band
= WLCORE_BAND_5GHZ
;
352 cmd
->channel
= wlvif
->channel
;
354 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
355 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
359 cmd
->device
.hlid
= wlvif
->dev_hlid
;
360 cmd
->device
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
362 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
363 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
365 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
367 wl1271_error("failed to initiate cmd role enable");
374 /* clear links on error */
375 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
384 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
385 struct wl12xx_vif
*wlvif
)
387 struct wl12xx_cmd_role_stop
*cmd
;
390 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
393 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
399 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
401 cmd
->role_id
= wlvif
->dev_role_id
;
402 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
403 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
405 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
407 wl1271_error("failed to initiate cmd role stop");
411 ret
= wl1271_cmd_wait_for_event(wl
, ROLE_STOP_COMPLETE_EVENT_ID
);
413 wl1271_error("cmd role stop dev event completion error");
417 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
426 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
428 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
429 struct wl12xx_cmd_role_start
*cmd
;
432 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
438 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
440 cmd
->role_id
= wlvif
->role_id
;
441 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
442 cmd
->band
= WLCORE_BAND_5GHZ
;
443 cmd
->channel
= wlvif
->channel
;
444 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
445 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
446 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
447 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
448 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
449 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
450 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
451 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
453 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
454 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
458 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
459 cmd
->sta
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
460 cmd
->sta
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
462 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
463 "basic_rate_set: 0x%x, remote_rates: 0x%x",
464 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
465 wlvif
->basic_rate_set
, wlvif
->rate_set
);
467 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
469 wl1271_error("failed to initiate cmd role start sta");
476 /* clear links on error. */
477 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
486 /* use this function to stop ibss as well */
487 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
489 struct wl12xx_cmd_role_stop
*cmd
;
492 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
495 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
501 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
503 cmd
->role_id
= wlvif
->role_id
;
504 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
505 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
507 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
509 wl1271_error("failed to initiate cmd role stop sta");
513 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
522 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
524 struct wl12xx_cmd_role_start
*cmd
;
525 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
526 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
530 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
532 /* trying to use hidden SSID with an old hostapd version */
533 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
534 wl1271_error("got a null SSID from beacon/bss");
539 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
545 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
549 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
551 goto out_free_global
;
553 cmd
->role_id
= wlvif
->role_id
;
554 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
555 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
556 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
557 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
558 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
559 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
560 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
561 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
562 /* FIXME: Change when adding DFS */
563 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
564 cmd
->channel
= wlvif
->channel
;
565 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
567 if (!bss_conf
->hidden_ssid
) {
568 /* take the SSID from the beacon for backward compatibility */
569 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
570 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
571 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
573 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
574 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
575 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
578 supported_rates
= CONF_TX_AP_ENABLED_RATES
| CONF_TX_MCS_RATES
|
579 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
581 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
584 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
586 switch (wlvif
->band
) {
587 case IEEE80211_BAND_2GHZ
:
588 cmd
->band
= WLCORE_BAND_2_4GHZ
;
590 case IEEE80211_BAND_5GHZ
:
591 cmd
->band
= WLCORE_BAND_5GHZ
;
594 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
595 cmd
->band
= WLCORE_BAND_2_4GHZ
;
599 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
601 wl1271_error("failed to initiate cmd role start ap");
608 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
611 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
620 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
622 struct wl12xx_cmd_role_stop
*cmd
;
625 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
631 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
633 cmd
->role_id
= wlvif
->role_id
;
635 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
637 wl1271_error("failed to initiate cmd role stop ap");
641 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
642 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
651 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
653 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
654 struct wl12xx_cmd_role_start
*cmd
;
655 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
658 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
664 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
666 cmd
->role_id
= wlvif
->role_id
;
667 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
668 cmd
->band
= WLCORE_BAND_5GHZ
;
669 cmd
->channel
= wlvif
->channel
;
670 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
671 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
672 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
673 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
674 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
675 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
676 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
677 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
679 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
680 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
684 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
685 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
687 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
688 "basic_rate_set: 0x%x, remote_rates: 0x%x",
689 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
690 wlvif
->basic_rate_set
, wlvif
->rate_set
);
692 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
693 vif
->bss_conf
.bssid
);
695 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
697 wl1271_error("failed to initiate cmd role enable");
704 /* clear links on error. */
705 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
716 * send test command to firmware
719 * @buf: buffer containing the command, with all headers, must work with dma
720 * @len: length of the buffer
721 * @answer: is answer needed
723 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
728 wl1271_debug(DEBUG_CMD
, "cmd test");
733 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
736 wl1271_warning("TEST command failed");
742 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
745 * read acx from firmware
749 * @buf: buffer for the response, including all headers, must work with dma
750 * @len: length of buf
752 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
754 struct acx_header
*acx
= buf
;
757 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
759 acx
->id
= cpu_to_le16(id
);
761 /* payload length, does not include any headers */
762 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
764 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
766 wl1271_error("INTERROGATE command failed");
772 * write acx value to firmware
776 * @buf: buffer containing acx, including all headers, must work with dma
777 * @len: length of buf
779 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
781 struct acx_header
*acx
= buf
;
784 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
786 acx
->id
= cpu_to_le16(id
);
788 /* payload length, does not include any headers */
789 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
791 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
793 wl1271_warning("CONFIGURE command NOK");
799 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
801 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
803 struct cmd_enabledisable_path
*cmd
;
807 wl1271_debug(DEBUG_CMD
, "cmd data path");
809 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
815 /* the channel here is only used for calibration, so hardcoded to 1 */
819 cmd_rx
= CMD_ENABLE_RX
;
820 cmd_tx
= CMD_ENABLE_TX
;
822 cmd_rx
= CMD_DISABLE_RX
;
823 cmd_tx
= CMD_DISABLE_TX
;
826 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
828 wl1271_error("rx %s cmd for channel %d failed",
829 enable
? "start" : "stop", cmd
->channel
);
833 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
834 enable
? "start" : "stop", cmd
->channel
);
836 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
838 wl1271_error("tx %s cmd for channel %d failed",
839 enable
? "start" : "stop", cmd
->channel
);
843 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
844 enable
? "start" : "stop", cmd
->channel
);
850 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
852 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
853 u8 ps_mode
, u16 auto_ps_timeout
)
855 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
858 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
860 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
866 ps_params
->role_id
= wlvif
->role_id
;
867 ps_params
->ps_mode
= ps_mode
;
868 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
870 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
871 sizeof(*ps_params
), 0);
873 wl1271_error("cmd set_ps_mode failed");
882 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
883 u16 template_id
, void *buf
, size_t buf_len
,
884 int index
, u32 rates
)
886 struct wl1271_cmd_template_set
*cmd
;
889 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
890 template_id
, role_id
);
892 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
893 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
895 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
901 /* during initialization wlvif is NULL */
902 cmd
->role_id
= role_id
;
903 cmd
->len
= cpu_to_le16(buf_len
);
904 cmd
->template_type
= template_id
;
905 cmd
->enabled_rates
= cpu_to_le32(rates
);
906 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
907 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
911 memcpy(cmd
->template_data
, buf
, buf_len
);
913 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
915 wl1271_warning("cmd set_template failed: %d", ret
);
926 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
928 struct sk_buff
*skb
= NULL
;
934 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
935 size
= sizeof(struct wl12xx_null_data_template
);
938 skb
= ieee80211_nullfunc_get(wl
->hw
,
939 wl12xx_wlvif_to_vif(wlvif
));
946 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
947 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
953 wl1271_warning("cmd buld null data failed %d", ret
);
959 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
960 struct wl12xx_vif
*wlvif
)
962 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
963 struct sk_buff
*skb
= NULL
;
966 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
970 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
972 CMD_TEMPL_KLV_IDX_NULL_DATA
,
978 wl1271_warning("cmd build klv null data failed %d", ret
);
984 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
987 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
991 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
995 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
996 CMD_TEMPL_PS_POLL
, skb
->data
,
997 skb
->len
, 0, wlvif
->basic_rate_set
);
1004 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1005 u8 role_id
, u8 band
,
1006 const u8
*ssid
, size_t ssid_len
,
1007 const u8
*ie
, size_t ie_len
)
1009 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1010 struct sk_buff
*skb
;
1014 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1021 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
1023 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1024 if (band
== IEEE80211_BAND_2GHZ
)
1025 ret
= wl1271_cmd_template_set(wl
, role_id
,
1026 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1027 skb
->data
, skb
->len
, 0, rate
);
1029 ret
= wl1271_cmd_template_set(wl
, role_id
,
1030 CMD_TEMPL_CFG_PROBE_REQ_5
,
1031 skb
->data
, skb
->len
, 0, rate
);
1038 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1039 struct wl12xx_vif
*wlvif
,
1040 struct sk_buff
*skb
)
1042 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1047 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1051 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1053 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1054 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1055 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1056 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1057 skb
->data
, skb
->len
, 0, rate
);
1059 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1060 CMD_TEMPL_CFG_PROBE_REQ_5
,
1061 skb
->data
, skb
->len
, 0, rate
);
1064 wl1271_error("Unable to set ap probe request template.");
1070 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1074 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1075 struct sk_buff
*skb
;
1076 struct wl12xx_arp_rsp_template
*tmpl
;
1077 struct ieee80211_hdr_3addr
*hdr
;
1078 struct arphdr
*arp_hdr
;
1080 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1081 WL1271_EXTRA_SPACE_MAX
);
1083 wl1271_error("failed to allocate buffer for arp rsp template");
1087 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1089 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1090 memset(tmpl
, 0, sizeof(*tmpl
));
1093 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1094 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1097 arp_hdr
= &tmpl
->arp_hdr
;
1098 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1099 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1100 arp_hdr
->ar_hln
= ETH_ALEN
;
1101 arp_hdr
->ar_pln
= 4;
1102 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1105 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1106 tmpl
->sender_ip
= wlvif
->ip_addr
;
1108 /* encryption space */
1109 switch (wlvif
->encryption_type
) {
1111 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1112 extra
= WL1271_EXTRA_SPACE_TKIP
;
1115 extra
= WL1271_EXTRA_SPACE_AES
;
1123 wl1271_warning("Unknown encryption type: %d",
1124 wlvif
->encryption_type
);
1130 u8
*space
= skb_push(skb
, extra
);
1131 memset(space
, 0, extra
);
1134 /* QoS header - BE */
1136 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1138 /* mac80211 header */
1139 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1140 memset(hdr
, 0, sizeof(*hdr
));
1141 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1143 fc
|= IEEE80211_STYPE_QOS_DATA
;
1145 fc
|= IEEE80211_STYPE_DATA
;
1146 if (wlvif
->encryption_type
!= KEY_NONE
)
1147 fc
|= IEEE80211_FCTL_PROTECTED
;
1149 hdr
->frame_control
= cpu_to_le16(fc
);
1150 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1151 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1152 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1154 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1155 skb
->data
, skb
->len
, 0,
1162 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1164 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1165 struct ieee80211_qos_hdr
template;
1167 memset(&template, 0, sizeof(template));
1169 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1170 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1171 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1173 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1174 IEEE80211_STYPE_QOS_NULLFUNC
|
1175 IEEE80211_FCTL_TODS
);
1177 /* FIXME: not sure what priority to use here */
1178 template.qos_ctrl
= cpu_to_le16(0);
1180 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1181 CMD_TEMPL_QOS_NULL_DATA
, &template,
1182 sizeof(template), 0,
1186 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1188 struct wl1271_cmd_set_keys
*cmd
;
1191 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1193 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1201 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1202 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1203 cmd
->key_type
= KEY_WEP
;
1205 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1207 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1217 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1218 u16 action
, u8 id
, u8 key_type
,
1219 u8 key_size
, const u8
*key
, const u8
*addr
,
1220 u32 tx_seq_32
, u16 tx_seq_16
)
1222 struct wl1271_cmd_set_keys
*cmd
;
1225 /* hlid might have already been deleted */
1226 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1229 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1235 cmd
->hlid
= wlvif
->sta
.hlid
;
1237 if (key_type
== KEY_WEP
)
1238 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1239 else if (is_broadcast_ether_addr(addr
))
1240 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1242 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1244 cmd
->key_action
= cpu_to_le16(action
);
1245 cmd
->key_size
= key_size
;
1246 cmd
->key_type
= key_type
;
1248 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1249 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1253 if (key_type
== KEY_TKIP
) {
1255 * We get the key in the following form:
1256 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1257 * but the target is expecting:
1258 * TKIP - RX MIC - TX MIC
1260 memcpy(cmd
->key
, key
, 16);
1261 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1262 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1265 memcpy(cmd
->key
, key
, key_size
);
1268 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1270 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1272 wl1271_warning("could not set keys");
1283 * TODO: merge with sta/ibss into 1 set_key function.
1284 * note there are slight diffs
1286 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1287 u16 action
, u8 id
, u8 key_type
,
1288 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1291 struct wl1271_cmd_set_keys
*cmd
;
1295 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1299 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1300 if (key_type
== KEY_WEP
)
1301 lid_type
= WEP_DEFAULT_LID_TYPE
;
1303 lid_type
= BROADCAST_LID_TYPE
;
1305 lid_type
= UNICAST_LID_TYPE
;
1308 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1309 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1310 (int)key_type
, (int)hlid
);
1312 cmd
->lid_key_type
= lid_type
;
1314 cmd
->key_action
= cpu_to_le16(action
);
1315 cmd
->key_size
= key_size
;
1316 cmd
->key_type
= key_type
;
1318 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1319 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1321 if (key_type
== KEY_TKIP
) {
1323 * We get the key in the following form:
1324 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1325 * but the target is expecting:
1326 * TKIP - RX MIC - TX MIC
1328 memcpy(cmd
->key
, key
, 16);
1329 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1330 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1332 memcpy(cmd
->key
, key
, key_size
);
1335 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1337 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1339 wl1271_warning("could not set ap keys");
1348 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, u8 hlid
)
1350 struct wl12xx_cmd_set_peer_state
*cmd
;
1353 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1355 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1362 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1364 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1366 wl1271_error("failed to send set peer state command");
1377 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1378 struct ieee80211_sta
*sta
, u8 hlid
)
1380 struct wl12xx_cmd_add_peer
*cmd
;
1384 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1386 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1392 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1393 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1394 cmd
->aid
= sta
->aid
;
1396 cmd
->sp_len
= sta
->max_sp
;
1397 cmd
->wmm
= sta
->wme
? 1 : 0;
1399 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1400 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1401 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1402 WL1271_PSD_UPSD_TRIGGER
;
1404 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1408 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1409 if (sta
->ht_cap
.ht_supported
)
1411 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1412 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1414 cmd
->supported_rates
=
1415 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1418 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1419 cmd
->supported_rates
, sta
->uapsd_queues
);
1421 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1423 wl1271_error("failed to initiate cmd add peer");
1434 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1436 struct wl12xx_cmd_remove_peer
*cmd
;
1439 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1441 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1448 /* We never send a deauth, mac80211 is in charge of this */
1449 cmd
->reason_opcode
= 0;
1450 cmd
->send_deauth_flag
= 0;
1452 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1454 wl1271_error("failed to initiate cmd remove peer");
1459 * We are ok with a timeout here. The event is sometimes not sent
1460 * due to a firmware bug.
1462 wl1271_cmd_wait_for_event_or_timeout(wl
,
1463 PEER_REMOVE_COMPLETE_EVENT_ID
);
1472 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1474 struct wl12xx_cmd_config_fwlog
*cmd
;
1477 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1479 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1485 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1486 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1487 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1488 cmd
->output
= wl
->conf
.fwlog
.output
;
1489 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1491 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1493 wl1271_error("failed to send config firmware logger command");
1504 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1506 struct wl12xx_cmd_start_fwlog
*cmd
;
1509 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1511 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1517 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1519 wl1271_error("failed to send start firmware logger command");
1530 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1532 struct wl12xx_cmd_stop_fwlog
*cmd
;
1535 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1537 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1543 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1545 wl1271_error("failed to send stop firmware logger command");
1556 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1559 struct wl12xx_cmd_roc
*cmd
;
1562 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", wlvif
->channel
, role_id
);
1564 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1567 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1573 cmd
->role_id
= role_id
;
1574 cmd
->channel
= wlvif
->channel
;
1575 switch (wlvif
->band
) {
1576 case IEEE80211_BAND_2GHZ
:
1577 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1579 case IEEE80211_BAND_5GHZ
:
1580 cmd
->band
= WLCORE_BAND_5GHZ
;
1583 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1589 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1591 wl1271_error("failed to send ROC command");
1602 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1604 struct wl12xx_cmd_croc
*cmd
;
1607 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1609 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1614 cmd
->role_id
= role_id
;
1616 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1619 wl1271_error("failed to send ROC command");
1630 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
)
1635 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1638 is_first_roc
= (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >=
1641 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
);
1646 ret
= wl1271_cmd_wait_for_event(wl
,
1647 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
);
1649 wl1271_error("cmd roc event completion error");
1654 __set_bit(role_id
, wl
->roc_map
);
1659 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1663 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1666 ret
= wl12xx_cmd_croc(wl
, role_id
);
1670 __clear_bit(role_id
, wl
->roc_map
);
1673 * Rearm the tx watchdog when removing the last ROC. This prevents
1674 * recoveries due to just finished ROCs - when Tx hasn't yet had
1675 * a chance to get out.
1677 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1678 wl12xx_rearm_tx_watchdog_locked(wl
);
1683 int wl12xx_cmd_channel_switch(struct wl1271
*wl
,
1684 struct wl12xx_vif
*wlvif
,
1685 struct ieee80211_channel_switch
*ch_switch
)
1687 struct wl12xx_cmd_channel_switch
*cmd
;
1690 wl1271_debug(DEBUG_ACX
, "cmd channel switch");
1692 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1698 cmd
->role_id
= wlvif
->role_id
;
1699 cmd
->channel
= ch_switch
->channel
->hw_value
;
1700 cmd
->switch_time
= ch_switch
->count
;
1701 cmd
->stop_tx
= ch_switch
->block_tx
;
1703 /* FIXME: control from mac80211 in the future */
1704 cmd
->post_switch_tx_disable
= 0; /* Enable TX on the target channel */
1706 ret
= wl1271_cmd_send(wl
, CMD_CHANNEL_SWITCH
, cmd
, sizeof(*cmd
), 0);
1708 wl1271_error("failed to send channel switch command");
1719 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
)
1721 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1724 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1726 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1732 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1734 wl1271_error("failed to stop channel switch command");
1745 /* start dev role and roc on its channel */
1746 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1750 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1751 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1754 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
);
1758 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
);
1765 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
1770 /* croc dev hlid, and stop the role */
1771 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1775 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1776 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1779 /* flush all pending packets */
1780 ret
= wlcore_tx_work_locked(wl
);
1784 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
1785 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
1790 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);