2 * This file is part of wl1271
4 * Copyright (C) 2009-2010 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/spi/spi.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ieee80211.h>
29 #include <linux/slab.h>
35 #include "wl12xx_80211.h"
41 #define WL1271_CMD_FAST_POLL_COUNT 50
42 #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20
45 * send command to firmware
49 * @buf: buffer containing the command, must work with dma
50 * @len: length of the buffer
51 * return the cmd status code on success.
53 static int __wlcore_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
,
54 size_t len
, size_t res_len
)
56 struct wl1271_cmd_header
*cmd
;
57 unsigned long timeout
;
63 if (unlikely(wl
->state
== WLCORE_STATE_RESTARTING
&&
64 id
!= CMD_STOP_FWLOGGER
))
67 if (WARN_ON_ONCE(len
< sizeof(*cmd
)))
71 cmd
->id
= cpu_to_le16(id
);
74 WARN_ON(len
% 4 != 0);
75 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
77 ret
= wlcore_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
82 * TODO: we just need this because one bit is in a different
83 * place. Is there any better way?
85 ret
= wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
89 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
91 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
95 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
96 if (time_after(jiffies
, timeout
)) {
97 wl1271_error("command complete timeout");
102 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
107 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
112 /* read back the status code of the command */
114 res_len
= sizeof(struct wl1271_cmd_header
);
116 ret
= wlcore_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
120 status
= le16_to_cpu(cmd
->status
);
122 ret
= wlcore_write_reg(wl
, REG_INTERRUPT_ACK
,
123 WL1271_ACX_INTR_CMD_COMPLETE
);
131 * send command to fw and return cmd status on success
132 * valid_rets contains a bitmap of allowed error codes
134 int wlcore_cmd_send_failsafe(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
135 size_t res_len
, unsigned long valid_rets
)
137 int ret
= __wlcore_cmd_send(wl
, id
, buf
, len
, res_len
);
142 /* success is always a valid status */
143 valid_rets
|= BIT(CMD_STATUS_SUCCESS
);
145 if (ret
>= MAX_COMMAND_STATUS
||
146 !test_bit(ret
, &valid_rets
)) {
147 wl1271_error("command execute failure %d", ret
);
153 wl12xx_queue_recovery_work(wl
);
156 EXPORT_SYMBOL_GPL(wl1271_cmd_send
);
159 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
160 * return 0 on success.
162 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
165 int ret
= wlcore_cmd_send_failsafe(wl
, id
, buf
, len
, res_len
, 0);
173 * Poll the mailbox event field until any of the bits in the mask is set or a
174 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
176 int wlcore_cmd_wait_for_event_or_timeout(struct wl1271
*wl
,
177 u32 mask
, bool *timeout
)
181 unsigned long timeout_time
;
187 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
191 timeout_time
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
194 if (time_after(jiffies
, timeout_time
)) {
195 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
202 if (poll_count
< WL1271_WAIT_EVENT_FAST_POLL_COUNT
)
203 usleep_range(50, 51);
205 usleep_range(1000, 5000);
207 /* read from both event fields */
208 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
209 sizeof(*events_vector
), false);
213 event
= *events_vector
& mask
;
215 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
216 sizeof(*events_vector
), false);
220 event
|= *events_vector
& mask
;
224 kfree(events_vector
);
227 EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout
);
229 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
232 struct wl12xx_cmd_role_enable
*cmd
;
235 wl1271_debug(DEBUG_CMD
, "cmd role enable");
237 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
240 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
247 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
248 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
253 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
254 cmd
->role_type
= role_type
;
256 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
258 wl1271_error("failed to initiate cmd role enable");
262 __set_bit(cmd
->role_id
, wl
->roles_map
);
263 *role_id
= cmd
->role_id
;
272 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
274 struct wl12xx_cmd_role_disable
*cmd
;
277 wl1271_debug(DEBUG_CMD
, "cmd role disable");
279 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
282 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
287 cmd
->role_id
= *role_id
;
289 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
291 wl1271_error("failed to initiate cmd role disable");
295 __clear_bit(*role_id
, wl
->roles_map
);
296 *role_id
= WL12XX_INVALID_ROLE_ID
;
305 static int wlcore_get_new_session_id(struct wl1271
*wl
, u8 hlid
)
307 if (wl
->session_ids
[hlid
] >= SESSION_COUNTER_MAX
)
308 wl
->session_ids
[hlid
] = 0;
310 wl
->session_ids
[hlid
]++;
312 return wl
->session_ids
[hlid
];
315 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
318 u8 link
= find_first_zero_bit(wl
->links_map
, wl
->num_links
);
319 if (link
>= wl
->num_links
)
322 wl
->session_ids
[link
] = wlcore_get_new_session_id(wl
, link
);
324 /* these bits are used by op_tx */
325 spin_lock_irqsave(&wl
->wl_lock
, flags
);
326 __set_bit(link
, wl
->links_map
);
327 __set_bit(link
, wlvif
->links_map
);
328 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
331 * take the last "freed packets" value from the current FW status.
332 * on recovery, we might not have fw_status yet, and
333 * tx_lnk_free_pkts will be NULL. check for it.
335 if (wl
->fw_status
->counters
.tx_lnk_free_pkts
)
336 wl
->links
[link
].prev_freed_pkts
=
337 wl
->fw_status
->counters
.tx_lnk_free_pkts
[link
];
338 wl
->links
[link
].wlvif
= wlvif
;
341 * Take saved value for total freed packets from wlvif, in case this is
344 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
)
345 wl
->links
[link
].total_freed_pkts
= wlvif
->total_freed_pkts
;
349 wl
->active_link_count
++;
353 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
357 if (*hlid
== WL12XX_INVALID_LINK_ID
)
360 /* these bits are used by op_tx */
361 spin_lock_irqsave(&wl
->wl_lock
, flags
);
362 __clear_bit(*hlid
, wl
->links_map
);
363 __clear_bit(*hlid
, wlvif
->links_map
);
364 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
366 wl
->links
[*hlid
].allocated_pkts
= 0;
367 wl
->links
[*hlid
].prev_freed_pkts
= 0;
368 wl
->links
[*hlid
].ba_bitmap
= 0;
369 memset(wl
->links
[*hlid
].addr
, 0, ETH_ALEN
);
372 * At this point op_tx() will not add more packets to the queues. We
375 wl1271_tx_reset_link_queues(wl
, *hlid
);
376 wl
->links
[*hlid
].wlvif
= NULL
;
378 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
&&
379 *hlid
== wlvif
->ap
.bcast_hlid
) {
380 u32 sqn_padding
= WL1271_TX_SQN_POST_RECOVERY_PADDING
;
382 * save the total freed packets in the wlvif, in case this is
383 * recovery or suspend
385 wlvif
->total_freed_pkts
= wl
->links
[*hlid
].total_freed_pkts
;
388 * increment the initial seq number on recovery to account for
389 * transmitted packets that we haven't yet got in the FW status
391 if (wlvif
->encryption_type
== KEY_GEM
)
392 sqn_padding
= WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM
;
394 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
395 wlvif
->total_freed_pkts
+= sqn_padding
;
398 wl
->links
[*hlid
].total_freed_pkts
= 0;
400 *hlid
= WL12XX_INVALID_LINK_ID
;
401 wl
->active_link_count
--;
402 WARN_ON_ONCE(wl
->active_link_count
< 0);
405 static u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
407 switch (nl_channel_type
) {
408 case NL80211_CHAN_NO_HT
:
409 return WLCORE_CHAN_NO_HT
;
410 case NL80211_CHAN_HT20
:
411 return WLCORE_CHAN_HT20
;
412 case NL80211_CHAN_HT40MINUS
:
413 return WLCORE_CHAN_HT40MINUS
;
414 case NL80211_CHAN_HT40PLUS
:
415 return WLCORE_CHAN_HT40PLUS
;
418 return WLCORE_CHAN_NO_HT
;
422 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
423 struct wl12xx_vif
*wlvif
,
424 enum ieee80211_band band
,
427 struct wl12xx_cmd_role_start
*cmd
;
430 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
436 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
438 cmd
->role_id
= wlvif
->dev_role_id
;
439 if (band
== IEEE80211_BAND_5GHZ
)
440 cmd
->band
= WLCORE_BAND_5GHZ
;
441 cmd
->channel
= channel
;
443 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
444 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
448 cmd
->device
.hlid
= wlvif
->dev_hlid
;
449 cmd
->device
.session
= wl
->session_ids
[wlvif
->dev_hlid
];
451 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
452 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
454 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
456 wl1271_error("failed to initiate cmd role enable");
463 /* clear links on error */
464 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
473 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
474 struct wl12xx_vif
*wlvif
)
476 struct wl12xx_cmd_role_stop
*cmd
;
479 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
482 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
488 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
490 cmd
->role_id
= wlvif
->dev_role_id
;
491 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
492 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
494 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
496 wl1271_error("failed to initiate cmd role stop");
500 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
509 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
511 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
512 struct wl12xx_cmd_role_start
*cmd
;
516 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
522 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
524 cmd
->role_id
= wlvif
->role_id
;
525 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
526 cmd
->band
= WLCORE_BAND_5GHZ
;
527 cmd
->channel
= wlvif
->channel
;
528 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
529 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
530 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
531 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
532 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
533 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
535 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
536 wlcore_hw_sta_get_ap_rate_mask(wl
, wlvif
);
538 supported_rates
&= ~CONF_TX_CCK_RATES
;
540 cmd
->sta
.local_rates
= cpu_to_le32(supported_rates
);
542 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
544 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
545 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
549 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
550 cmd
->sta
.session
= wl
->session_ids
[wlvif
->sta
.hlid
];
552 * We don't have the correct remote rates in this stage. The
553 * rates will be reconfigured later, after association, if the
554 * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
555 * we can do, so use all supported_rates here.
557 cmd
->sta
.remote_rates
= cpu_to_le32(supported_rates
);
559 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
560 "basic_rate_set: 0x%x, remote_rates: 0x%x",
561 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
562 wlvif
->basic_rate_set
, wlvif
->rate_set
);
564 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
566 wl1271_error("failed to initiate cmd role start sta");
570 wlvif
->sta
.role_chan_type
= wlvif
->channel_type
;
574 /* clear links on error. */
575 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
584 /* use this function to stop ibss as well */
585 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
587 struct wl12xx_cmd_role_stop
*cmd
;
590 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
593 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
599 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
601 cmd
->role_id
= wlvif
->role_id
;
602 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
603 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
605 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
607 wl1271_error("failed to initiate cmd role stop sta");
611 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
620 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
622 struct wl12xx_cmd_role_start
*cmd
;
623 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
624 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
628 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
630 /* trying to use hidden SSID with an old hostapd version */
631 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
632 wl1271_error("got a null SSID from beacon/bss");
637 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
643 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
647 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
649 goto out_free_global
;
651 /* use the previous security seq, if this is a recovery/resume */
652 wl
->links
[wlvif
->ap
.bcast_hlid
].total_freed_pkts
=
653 wlvif
->total_freed_pkts
;
655 cmd
->role_id
= wlvif
->role_id
;
656 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
657 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
658 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
659 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
660 cmd
->ap
.global_session_id
= wl
->session_ids
[wlvif
->ap
.global_hlid
];
661 cmd
->ap
.bcast_session_id
= wl
->session_ids
[wlvif
->ap
.bcast_hlid
];
662 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
663 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
664 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
665 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
666 /* FIXME: Change when adding DFS */
667 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
668 cmd
->ap
.wmm
= wlvif
->wmm_enabled
;
669 cmd
->channel
= wlvif
->channel
;
670 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
672 if (!bss_conf
->hidden_ssid
) {
673 /* take the SSID from the beacon for backward compatibility */
674 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
675 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
676 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
678 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
679 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
680 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
683 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
684 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
686 supported_rates
&= ~CONF_TX_CCK_RATES
;
688 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
691 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
693 switch (wlvif
->band
) {
694 case IEEE80211_BAND_2GHZ
:
695 cmd
->band
= WLCORE_BAND_2_4GHZ
;
697 case IEEE80211_BAND_5GHZ
:
698 cmd
->band
= WLCORE_BAND_5GHZ
;
701 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
702 cmd
->band
= WLCORE_BAND_2_4GHZ
;
706 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
708 wl1271_error("failed to initiate cmd role start ap");
715 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
718 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
727 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
729 struct wl12xx_cmd_role_stop
*cmd
;
732 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
738 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
740 cmd
->role_id
= wlvif
->role_id
;
742 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
744 wl1271_error("failed to initiate cmd role stop ap");
748 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
749 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
758 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
760 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
761 struct wl12xx_cmd_role_start
*cmd
;
762 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
765 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
771 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
773 cmd
->role_id
= wlvif
->role_id
;
774 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
775 cmd
->band
= WLCORE_BAND_5GHZ
;
776 cmd
->channel
= wlvif
->channel
;
777 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
778 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
779 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
780 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
781 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
782 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
783 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
784 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
786 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
787 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
791 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
792 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
794 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
795 "basic_rate_set: 0x%x, remote_rates: 0x%x",
796 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
797 wlvif
->basic_rate_set
, wlvif
->rate_set
);
799 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
800 vif
->bss_conf
.bssid
);
802 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
804 wl1271_error("failed to initiate cmd role enable");
811 /* clear links on error. */
812 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
823 * send test command to firmware
826 * @buf: buffer containing the command, with all headers, must work with dma
827 * @len: length of the buffer
828 * @answer: is answer needed
830 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
835 wl1271_debug(DEBUG_CMD
, "cmd test");
840 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
843 wl1271_warning("TEST command failed");
849 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
852 * read acx from firmware
856 * @buf: buffer for the response, including all headers, must work with dma
857 * @len: length of buf
859 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
,
860 size_t cmd_len
, size_t res_len
)
862 struct acx_header
*acx
= buf
;
865 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
867 acx
->id
= cpu_to_le16(id
);
869 /* response payload length, does not include any headers */
870 acx
->len
= cpu_to_le16(res_len
- sizeof(*acx
));
872 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, cmd_len
, res_len
);
874 wl1271_error("INTERROGATE command failed");
880 * write acx value to firmware
884 * @buf: buffer containing acx, including all headers, must work with dma
885 * @len: length of buf
886 * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
887 * return the cmd status on success.
889 int wlcore_cmd_configure_failsafe(struct wl1271
*wl
, u16 id
, void *buf
,
890 size_t len
, unsigned long valid_rets
)
892 struct acx_header
*acx
= buf
;
895 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
897 if (WARN_ON_ONCE(len
< sizeof(*acx
)))
900 acx
->id
= cpu_to_le16(id
);
902 /* payload length, does not include any headers */
903 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
905 ret
= wlcore_cmd_send_failsafe(wl
, CMD_CONFIGURE
, acx
, len
, 0,
908 wl1271_warning("CONFIGURE command NOK");
916 * wrapper for wlcore_cmd_configure that accepts only success status.
917 * return 0 on success
919 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
921 int ret
= wlcore_cmd_configure_failsafe(wl
, id
, buf
, len
, 0);
927 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
929 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
931 struct cmd_enabledisable_path
*cmd
;
935 wl1271_debug(DEBUG_CMD
, "cmd data path");
937 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
943 /* the channel here is only used for calibration, so hardcoded to 1 */
947 cmd_rx
= CMD_ENABLE_RX
;
948 cmd_tx
= CMD_ENABLE_TX
;
950 cmd_rx
= CMD_DISABLE_RX
;
951 cmd_tx
= CMD_DISABLE_TX
;
954 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
956 wl1271_error("rx %s cmd for channel %d failed",
957 enable
? "start" : "stop", cmd
->channel
);
961 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
962 enable
? "start" : "stop", cmd
->channel
);
964 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
966 wl1271_error("tx %s cmd for channel %d failed",
967 enable
? "start" : "stop", cmd
->channel
);
971 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
972 enable
? "start" : "stop", cmd
->channel
);
978 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
980 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
981 u8 ps_mode
, u16 auto_ps_timeout
)
983 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
986 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
988 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
994 ps_params
->role_id
= wlvif
->role_id
;
995 ps_params
->ps_mode
= ps_mode
;
996 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
998 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
999 sizeof(*ps_params
), 0);
1001 wl1271_error("cmd set_ps_mode failed");
1010 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
1011 u16 template_id
, void *buf
, size_t buf_len
,
1012 int index
, u32 rates
)
1014 struct wl1271_cmd_template_set
*cmd
;
1017 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
1018 template_id
, role_id
);
1020 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1021 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1023 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1029 /* during initialization wlvif is NULL */
1030 cmd
->role_id
= role_id
;
1031 cmd
->len
= cpu_to_le16(buf_len
);
1032 cmd
->template_type
= template_id
;
1033 cmd
->enabled_rates
= cpu_to_le32(rates
);
1034 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1035 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1039 memcpy(cmd
->template_data
, buf
, buf_len
);
1041 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1043 wl1271_warning("cmd set_template failed: %d", ret
);
1054 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1056 struct sk_buff
*skb
= NULL
;
1062 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1063 size
= sizeof(struct wl12xx_null_data_template
);
1066 skb
= ieee80211_nullfunc_get(wl
->hw
,
1067 wl12xx_wlvif_to_vif(wlvif
));
1074 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1075 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
1081 wl1271_warning("cmd buld null data failed %d", ret
);
1087 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
1088 struct wl12xx_vif
*wlvif
)
1090 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1091 struct sk_buff
*skb
= NULL
;
1094 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
1098 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
1099 skb
->data
, skb
->len
,
1100 wlvif
->sta
.klv_template_id
,
1106 wl1271_warning("cmd build klv null data failed %d", ret
);
1112 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1115 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1116 struct sk_buff
*skb
;
1119 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
1123 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1124 CMD_TEMPL_PS_POLL
, skb
->data
,
1125 skb
->len
, 0, wlvif
->basic_rate_set
);
1132 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1133 u8 role_id
, u8 band
,
1134 const u8
*ssid
, size_t ssid_len
,
1135 const u8
*ie0
, size_t ie0_len
, const u8
*ie1
,
1136 size_t ie1_len
, bool sched_scan
)
1138 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1139 struct sk_buff
*skb
;
1142 u16 template_id_2_4
= wl
->scan_templ_id_2_4
;
1143 u16 template_id_5
= wl
->scan_templ_id_5
;
1145 wl1271_debug(DEBUG_SCAN
, "build probe request band %d", band
);
1147 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1154 memcpy(skb_put(skb
, ie0_len
), ie0
, ie0_len
);
1156 memcpy(skb_put(skb
, ie1_len
), ie1
, ie1_len
);
1159 (wl
->quirks
& WLCORE_QUIRK_DUAL_PROBE_TMPL
)) {
1160 template_id_2_4
= wl
->sched_scan_templ_id_2_4
;
1161 template_id_5
= wl
->sched_scan_templ_id_5
;
1164 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1165 if (band
== IEEE80211_BAND_2GHZ
)
1166 ret
= wl1271_cmd_template_set(wl
, role_id
,
1168 skb
->data
, skb
->len
, 0, rate
);
1170 ret
= wl1271_cmd_template_set(wl
, role_id
,
1172 skb
->data
, skb
->len
, 0, rate
);
1178 EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req
);
1180 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1181 struct wl12xx_vif
*wlvif
,
1182 struct sk_buff
*skb
)
1184 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1189 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1193 wl1271_debug(DEBUG_SCAN
, "set ap probe request template");
1195 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1196 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1197 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1198 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1199 skb
->data
, skb
->len
, 0, rate
);
1201 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1202 CMD_TEMPL_CFG_PROBE_REQ_5
,
1203 skb
->data
, skb
->len
, 0, rate
);
1206 wl1271_error("Unable to set ap probe request template.");
1212 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1216 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1217 struct sk_buff
*skb
;
1218 struct wl12xx_arp_rsp_template
*tmpl
;
1219 struct ieee80211_hdr_3addr
*hdr
;
1220 struct arphdr
*arp_hdr
;
1222 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1223 WL1271_EXTRA_SPACE_MAX
);
1225 wl1271_error("failed to allocate buffer for arp rsp template");
1229 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1231 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1232 memset(tmpl
, 0, sizeof(*tmpl
));
1235 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1236 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1239 arp_hdr
= &tmpl
->arp_hdr
;
1240 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1241 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1242 arp_hdr
->ar_hln
= ETH_ALEN
;
1243 arp_hdr
->ar_pln
= 4;
1244 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1247 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1248 tmpl
->sender_ip
= wlvif
->ip_addr
;
1250 /* encryption space */
1251 switch (wlvif
->encryption_type
) {
1253 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1254 extra
= WL1271_EXTRA_SPACE_TKIP
;
1257 extra
= WL1271_EXTRA_SPACE_AES
;
1265 wl1271_warning("Unknown encryption type: %d",
1266 wlvif
->encryption_type
);
1272 u8
*space
= skb_push(skb
, extra
);
1273 memset(space
, 0, extra
);
1276 /* QoS header - BE */
1278 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1280 /* mac80211 header */
1281 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1282 memset(hdr
, 0, sizeof(*hdr
));
1283 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1285 fc
|= IEEE80211_STYPE_QOS_DATA
;
1287 fc
|= IEEE80211_STYPE_DATA
;
1288 if (wlvif
->encryption_type
!= KEY_NONE
)
1289 fc
|= IEEE80211_FCTL_PROTECTED
;
1291 hdr
->frame_control
= cpu_to_le16(fc
);
1292 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1293 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1294 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1296 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1297 skb
->data
, skb
->len
, 0,
1304 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1306 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1307 struct ieee80211_qos_hdr
template;
1309 memset(&template, 0, sizeof(template));
1311 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1312 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1313 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1315 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1316 IEEE80211_STYPE_QOS_NULLFUNC
|
1317 IEEE80211_FCTL_TODS
);
1319 /* FIXME: not sure what priority to use here */
1320 template.qos_ctrl
= cpu_to_le16(0);
1322 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1323 CMD_TEMPL_QOS_NULL_DATA
, &template,
1324 sizeof(template), 0,
1328 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1330 struct wl1271_cmd_set_keys
*cmd
;
1333 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1335 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1343 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1344 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1345 cmd
->key_type
= KEY_WEP
;
1347 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1349 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1359 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1360 u16 action
, u8 id
, u8 key_type
,
1361 u8 key_size
, const u8
*key
, const u8
*addr
,
1362 u32 tx_seq_32
, u16 tx_seq_16
)
1364 struct wl1271_cmd_set_keys
*cmd
;
1367 /* hlid might have already been deleted */
1368 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1371 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1377 cmd
->hlid
= wlvif
->sta
.hlid
;
1379 if (key_type
== KEY_WEP
)
1380 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1381 else if (is_broadcast_ether_addr(addr
))
1382 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1384 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1386 cmd
->key_action
= cpu_to_le16(action
);
1387 cmd
->key_size
= key_size
;
1388 cmd
->key_type
= key_type
;
1390 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1391 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1395 if (key_type
== KEY_TKIP
) {
1397 * We get the key in the following form:
1398 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1399 * but the target is expecting:
1400 * TKIP - RX MIC - TX MIC
1402 memcpy(cmd
->key
, key
, 16);
1403 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1404 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1407 memcpy(cmd
->key
, key
, key_size
);
1410 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1412 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1414 wl1271_warning("could not set keys");
1425 * TODO: merge with sta/ibss into 1 set_key function.
1426 * note there are slight diffs
1428 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1429 u16 action
, u8 id
, u8 key_type
,
1430 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1433 struct wl1271_cmd_set_keys
*cmd
;
1437 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1441 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1442 if (key_type
== KEY_WEP
)
1443 lid_type
= WEP_DEFAULT_LID_TYPE
;
1445 lid_type
= BROADCAST_LID_TYPE
;
1447 lid_type
= UNICAST_LID_TYPE
;
1450 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1451 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1452 (int)key_type
, (int)hlid
);
1454 cmd
->lid_key_type
= lid_type
;
1456 cmd
->key_action
= cpu_to_le16(action
);
1457 cmd
->key_size
= key_size
;
1458 cmd
->key_type
= key_type
;
1460 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1461 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1463 if (key_type
== KEY_TKIP
) {
1465 * We get the key in the following form:
1466 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1467 * but the target is expecting:
1468 * TKIP - RX MIC - TX MIC
1470 memcpy(cmd
->key
, key
, 16);
1471 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1472 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1474 memcpy(cmd
->key
, key
, key_size
);
1477 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1479 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1481 wl1271_warning("could not set ap keys");
1490 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1493 struct wl12xx_cmd_set_peer_state
*cmd
;
1496 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1498 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1505 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1507 /* wmm param is valid only for station role */
1508 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1509 cmd
->wmm
= wlvif
->wmm_enabled
;
1511 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1513 wl1271_error("failed to send set peer state command");
1524 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1525 struct ieee80211_sta
*sta
, u8 hlid
)
1527 struct wl12xx_cmd_add_peer
*cmd
;
1531 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1533 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1539 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1540 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1541 cmd
->aid
= sta
->aid
;
1543 cmd
->sp_len
= sta
->max_sp
;
1544 cmd
->wmm
= sta
->wme
? 1 : 0;
1545 cmd
->session_id
= wl
->session_ids
[hlid
];
1546 cmd
->role_id
= wlvif
->role_id
;
1548 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1549 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1550 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1551 WL1271_PSD_UPSD_TRIGGER
;
1553 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1557 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1558 if (sta
->ht_cap
.ht_supported
)
1560 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1561 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1563 cmd
->supported_rates
=
1564 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1567 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1568 cmd
->supported_rates
, sta
->uapsd_queues
);
1570 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1572 wl1271_error("failed to initiate cmd add peer");
1583 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1586 struct wl12xx_cmd_remove_peer
*cmd
;
1588 bool timeout
= false;
1590 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1592 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1599 /* We never send a deauth, mac80211 is in charge of this */
1600 cmd
->reason_opcode
= 0;
1601 cmd
->send_deauth_flag
= 0;
1602 cmd
->role_id
= wlvif
->role_id
;
1604 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1606 wl1271_error("failed to initiate cmd remove peer");
1610 ret
= wl
->ops
->wait_for_event(wl
,
1611 WLCORE_EVENT_PEER_REMOVE_COMPLETE
,
1615 * We are ok with a timeout here. The event is sometimes not sent
1616 * due to a firmware bug. In case of another error (like SDIO timeout)
1620 wl12xx_queue_recovery_work(wl
);
1629 static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band
, u16 ch
)
1632 * map the given band/channel to the respective predefined
1633 * bit expected by the fw
1636 case IEEE80211_BAND_2GHZ
:
1637 /* channels 1..14 are mapped to 0..13 */
1638 if (ch
>= 1 && ch
<= 14)
1641 case IEEE80211_BAND_5GHZ
:
1644 /* channels 8,12,16 are mapped to 18,19,20 */
1645 return 18 + (ch
-8)/4;
1647 /* channels 34,36..48 are mapped to 21..28 */
1648 return 21 + (ch
-34)/2;
1650 /* channels 52,56..64 are mapped to 29..32 */
1651 return 29 + (ch
-52)/4;
1653 /* channels 100,104..140 are mapped to 33..43 */
1654 return 33 + (ch
-100)/4;
1656 /* channels 149,153..165 are mapped to 44..48 */
1657 return 44 + (ch
-149)/4;
1666 wl1271_error("%s: unknown band/channel: %d/%d", __func__
, band
, ch
);
1670 void wlcore_set_pending_regdomain_ch(struct wl1271
*wl
, u16 channel
,
1671 enum ieee80211_band band
)
1675 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1678 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(band
, channel
);
1680 if (ch_bit_idx
>= 0 && ch_bit_idx
<= WL1271_MAX_CHANNELS
)
1681 set_bit(ch_bit_idx
, (long *)wl
->reg_ch_conf_pending
);
1684 int wlcore_cmd_regdomain_config_locked(struct wl1271
*wl
)
1686 struct wl12xx_cmd_regdomain_dfs_config
*cmd
= NULL
;
1687 int ret
= 0, i
, b
, ch_bit_idx
;
1688 struct ieee80211_channel
*channel
;
1689 u32 tmp_ch_bitmap
[2];
1691 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1692 struct ieee80211_supported_band
*band
;
1693 bool timeout
= false;
1695 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1698 wl1271_debug(DEBUG_CMD
, "cmd reg domain config");
1700 memset(tmp_ch_bitmap
, 0, sizeof(tmp_ch_bitmap
));
1702 for (b
= IEEE80211_BAND_2GHZ
; b
<= IEEE80211_BAND_5GHZ
; b
++) {
1703 band
= wiphy
->bands
[b
];
1704 for (i
= 0; i
< band
->n_channels
; i
++) {
1705 channel
= &band
->channels
[i
];
1706 ch
= channel
->hw_value
;
1708 if (channel
->flags
& (IEEE80211_CHAN_DISABLED
|
1709 IEEE80211_CHAN_RADAR
|
1710 IEEE80211_CHAN_NO_IR
))
1713 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(b
, ch
);
1717 set_bit(ch_bit_idx
, (long *)tmp_ch_bitmap
);
1721 tmp_ch_bitmap
[0] |= wl
->reg_ch_conf_pending
[0];
1722 tmp_ch_bitmap
[1] |= wl
->reg_ch_conf_pending
[1];
1724 if (!memcmp(tmp_ch_bitmap
, wl
->reg_ch_conf_last
, sizeof(tmp_ch_bitmap
)))
1727 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1733 cmd
->ch_bit_map1
= cpu_to_le32(tmp_ch_bitmap
[0]);
1734 cmd
->ch_bit_map2
= cpu_to_le32(tmp_ch_bitmap
[1]);
1736 wl1271_debug(DEBUG_CMD
,
1737 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x",
1738 cmd
->ch_bit_map1
, cmd
->ch_bit_map2
);
1740 ret
= wl1271_cmd_send(wl
, CMD_DFS_CHANNEL_CONFIG
, cmd
, sizeof(*cmd
), 0);
1742 wl1271_error("failed to send reg domain dfs config");
1746 ret
= wl
->ops
->wait_for_event(wl
,
1747 WLCORE_EVENT_DFS_CONFIG_COMPLETE
,
1749 if (ret
< 0 || timeout
) {
1750 wl1271_error("reg domain conf %serror",
1751 timeout
? "completion " : "");
1752 ret
= timeout
? -ETIMEDOUT
: ret
;
1756 memcpy(wl
->reg_ch_conf_last
, tmp_ch_bitmap
, sizeof(tmp_ch_bitmap
));
1757 memset(wl
->reg_ch_conf_pending
, 0, sizeof(wl
->reg_ch_conf_pending
));
1764 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1766 struct wl12xx_cmd_config_fwlog
*cmd
;
1769 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1771 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1777 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1778 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1779 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1780 cmd
->output
= wl
->conf
.fwlog
.output
;
1781 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1783 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1785 wl1271_error("failed to send config firmware logger command");
1796 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1798 struct wl12xx_cmd_start_fwlog
*cmd
;
1801 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1803 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1809 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1811 wl1271_error("failed to send start firmware logger command");
1822 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1824 struct wl12xx_cmd_stop_fwlog
*cmd
;
1827 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1829 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1835 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1837 wl1271_error("failed to send stop firmware logger command");
1848 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1849 u8 role_id
, enum ieee80211_band band
, u8 channel
)
1851 struct wl12xx_cmd_roc
*cmd
;
1854 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", channel
, role_id
);
1856 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1859 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1865 cmd
->role_id
= role_id
;
1866 cmd
->channel
= channel
;
1868 case IEEE80211_BAND_2GHZ
:
1869 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1871 case IEEE80211_BAND_5GHZ
:
1872 cmd
->band
= WLCORE_BAND_5GHZ
;
1875 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1881 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1883 wl1271_error("failed to send ROC command");
1894 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1896 struct wl12xx_cmd_croc
*cmd
;
1899 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1901 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1906 cmd
->role_id
= role_id
;
1908 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1911 wl1271_error("failed to send ROC command");
1922 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
,
1923 enum ieee80211_band band
, u8 channel
)
1927 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1930 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
, band
, channel
);
1934 __set_bit(role_id
, wl
->roc_map
);
1939 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1943 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1946 ret
= wl12xx_cmd_croc(wl
, role_id
);
1950 __clear_bit(role_id
, wl
->roc_map
);
1953 * Rearm the tx watchdog when removing the last ROC. This prevents
1954 * recoveries due to just finished ROCs - when Tx hasn't yet had
1955 * a chance to get out.
1957 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1958 wl12xx_rearm_tx_watchdog_locked(wl
);
1963 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1965 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1968 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1970 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1976 cmd
->role_id
= wlvif
->role_id
;
1978 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1980 wl1271_error("failed to stop channel switch command");
1991 /* start dev role and roc on its channel */
1992 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1993 enum ieee80211_band band
, int channel
)
1997 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1998 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2001 ret
= wl12xx_cmd_role_enable(wl
,
2002 wl12xx_wlvif_to_vif(wlvif
)->addr
,
2004 &wlvif
->dev_role_id
);
2008 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
, band
, channel
);
2012 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
, band
, channel
);
2019 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2021 wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2026 /* croc dev hlid, and stop the role */
2027 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2031 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2032 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2035 /* flush all pending packets */
2036 ret
= wlcore_tx_work_locked(wl
);
2040 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
2041 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
2046 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2050 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);