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 (WARN_ON(unlikely(wl
->state
== WLCORE_STATE_RESTARTING
)))
67 cmd
->id
= cpu_to_le16(id
);
70 WARN_ON(len
% 4 != 0);
71 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
73 ret
= wlcore_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
78 * TODO: we just need this because one bit is in a different
79 * place. Is there any better way?
81 ret
= wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
85 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
87 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
91 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
92 if (time_after(jiffies
, timeout
)) {
93 wl1271_error("command complete timeout");
98 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
103 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
108 /* read back the status code of the command */
110 res_len
= sizeof(struct wl1271_cmd_header
);
112 ret
= wlcore_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
116 status
= le16_to_cpu(cmd
->status
);
118 ret
= wlcore_write_reg(wl
, REG_INTERRUPT_ACK
,
119 WL1271_ACX_INTR_CMD_COMPLETE
);
127 * send command to fw and return cmd status on success
128 * valid_rets contains a bitmap of allowed error codes
130 int wlcore_cmd_send_failsafe(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
131 size_t res_len
, unsigned long valid_rets
)
133 int ret
= __wlcore_cmd_send(wl
, id
, buf
, len
, res_len
);
138 /* success is always a valid status */
139 valid_rets
|= BIT(CMD_STATUS_SUCCESS
);
141 if (ret
>= MAX_COMMAND_STATUS
||
142 !test_bit(ret
, &valid_rets
)) {
143 wl1271_error("command execute failure %d", ret
);
149 wl12xx_queue_recovery_work(wl
);
152 EXPORT_SYMBOL_GPL(wl1271_cmd_send
);
155 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
156 * return 0 on success.
158 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
161 int ret
= wlcore_cmd_send_failsafe(wl
, id
, buf
, len
, res_len
, 0);
169 * Poll the mailbox event field until any of the bits in the mask is set or a
170 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
172 int wlcore_cmd_wait_for_event_or_timeout(struct wl1271
*wl
,
173 u32 mask
, bool *timeout
)
177 unsigned long timeout_time
;
183 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
187 timeout_time
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
190 if (time_after(jiffies
, timeout_time
)) {
191 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
198 if (poll_count
< WL1271_WAIT_EVENT_FAST_POLL_COUNT
)
199 usleep_range(50, 51);
201 usleep_range(1000, 5000);
203 /* read from both event fields */
204 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
205 sizeof(*events_vector
), false);
209 event
= *events_vector
& mask
;
211 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
212 sizeof(*events_vector
), false);
216 event
|= *events_vector
& mask
;
220 kfree(events_vector
);
223 EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout
);
225 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
228 struct wl12xx_cmd_role_enable
*cmd
;
231 wl1271_debug(DEBUG_CMD
, "cmd role enable");
233 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
236 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
243 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
244 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
249 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
250 cmd
->role_type
= role_type
;
252 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
254 wl1271_error("failed to initiate cmd role enable");
258 __set_bit(cmd
->role_id
, wl
->roles_map
);
259 *role_id
= cmd
->role_id
;
268 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
270 struct wl12xx_cmd_role_disable
*cmd
;
273 wl1271_debug(DEBUG_CMD
, "cmd role disable");
275 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
278 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
283 cmd
->role_id
= *role_id
;
285 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
287 wl1271_error("failed to initiate cmd role disable");
291 __clear_bit(*role_id
, wl
->roles_map
);
292 *role_id
= WL12XX_INVALID_ROLE_ID
;
301 static int wlcore_get_new_session_id(struct wl1271
*wl
, u8 hlid
)
303 if (wl
->session_ids
[hlid
] >= SESSION_COUNTER_MAX
)
304 wl
->session_ids
[hlid
] = 0;
306 wl
->session_ids
[hlid
]++;
308 return wl
->session_ids
[hlid
];
311 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
314 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
315 if (link
>= WL12XX_MAX_LINKS
)
318 wl
->session_ids
[link
] = wlcore_get_new_session_id(wl
, link
);
320 /* these bits are used by op_tx */
321 spin_lock_irqsave(&wl
->wl_lock
, flags
);
322 __set_bit(link
, wl
->links_map
);
323 __set_bit(link
, wlvif
->links_map
);
324 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
326 /* take the last "freed packets" value from the current FW status */
327 wl
->links
[link
].prev_freed_pkts
=
328 wl
->fw_status_2
->counters
.tx_lnk_free_pkts
[link
];
329 wl
->links
[link
].wlvif
= wlvif
;
332 * Take saved value for total freed packets from wlvif, in case this is
335 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
)
336 wl
->links
[link
].total_freed_pkts
= wlvif
->total_freed_pkts
;
340 wl
->active_link_count
++;
344 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
348 if (*hlid
== WL12XX_INVALID_LINK_ID
)
351 /* these bits are used by op_tx */
352 spin_lock_irqsave(&wl
->wl_lock
, flags
);
353 __clear_bit(*hlid
, wl
->links_map
);
354 __clear_bit(*hlid
, wlvif
->links_map
);
355 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
357 wl
->links
[*hlid
].allocated_pkts
= 0;
358 wl
->links
[*hlid
].prev_freed_pkts
= 0;
359 wl
->links
[*hlid
].ba_bitmap
= 0;
360 memset(wl
->links
[*hlid
].addr
, 0, ETH_ALEN
);
363 * At this point op_tx() will not add more packets to the queues. We
366 wl1271_tx_reset_link_queues(wl
, *hlid
);
367 wl
->links
[*hlid
].wlvif
= NULL
;
369 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
370 (wlvif
->bss_type
== BSS_TYPE_AP_BSS
&&
371 *hlid
== wlvif
->ap
.bcast_hlid
)) {
373 * save the total freed packets in the wlvif, in case this is
374 * recovery or suspend
376 wlvif
->total_freed_pkts
= wl
->links
[*hlid
].total_freed_pkts
;
379 * increment the initial seq number on recovery to account for
380 * transmitted packets that we haven't yet got in the FW status
382 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
383 wlvif
->total_freed_pkts
+=
384 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
387 wl
->links
[*hlid
].total_freed_pkts
= 0;
389 *hlid
= WL12XX_INVALID_LINK_ID
;
390 wl
->active_link_count
--;
391 WARN_ON_ONCE(wl
->active_link_count
< 0);
394 static u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
396 switch (nl_channel_type
) {
397 case NL80211_CHAN_NO_HT
:
398 return WLCORE_CHAN_NO_HT
;
399 case NL80211_CHAN_HT20
:
400 return WLCORE_CHAN_HT20
;
401 case NL80211_CHAN_HT40MINUS
:
402 return WLCORE_CHAN_HT40MINUS
;
403 case NL80211_CHAN_HT40PLUS
:
404 return WLCORE_CHAN_HT40PLUS
;
407 return WLCORE_CHAN_NO_HT
;
411 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
412 struct wl12xx_vif
*wlvif
,
413 enum ieee80211_band band
,
416 struct wl12xx_cmd_role_start
*cmd
;
419 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
425 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
427 cmd
->role_id
= wlvif
->dev_role_id
;
428 if (band
== IEEE80211_BAND_5GHZ
)
429 cmd
->band
= WLCORE_BAND_5GHZ
;
430 cmd
->channel
= channel
;
432 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
433 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
437 cmd
->device
.hlid
= wlvif
->dev_hlid
;
438 cmd
->device
.session
= wl
->session_ids
[wlvif
->dev_hlid
];
440 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
441 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
443 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
445 wl1271_error("failed to initiate cmd role enable");
452 /* clear links on error */
453 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
462 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
463 struct wl12xx_vif
*wlvif
)
465 struct wl12xx_cmd_role_stop
*cmd
;
468 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
471 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
477 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
479 cmd
->role_id
= wlvif
->dev_role_id
;
480 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
481 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
483 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
485 wl1271_error("failed to initiate cmd role stop");
489 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
498 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
500 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
501 struct wl12xx_cmd_role_start
*cmd
;
505 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
511 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
513 cmd
->role_id
= wlvif
->role_id
;
514 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
515 cmd
->band
= WLCORE_BAND_5GHZ
;
516 cmd
->channel
= wlvif
->channel
;
517 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
518 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
519 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
520 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
521 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
522 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
524 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
525 wlcore_hw_sta_get_ap_rate_mask(wl
, wlvif
);
527 supported_rates
&= ~CONF_TX_CCK_RATES
;
529 cmd
->sta
.local_rates
= cpu_to_le32(supported_rates
);
531 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
533 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
534 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
538 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
539 cmd
->sta
.session
= wl
->session_ids
[wlvif
->sta
.hlid
];
541 * We don't have the correct remote rates in this stage. The
542 * rates will be reconfigured later, after association, if the
543 * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
544 * we can do, so use all supported_rates here.
546 cmd
->sta
.remote_rates
= cpu_to_le32(supported_rates
);
548 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
549 "basic_rate_set: 0x%x, remote_rates: 0x%x",
550 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
551 wlvif
->basic_rate_set
, wlvif
->rate_set
);
553 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
555 wl1271_error("failed to initiate cmd role start sta");
559 wlvif
->sta
.role_chan_type
= wlvif
->channel_type
;
563 /* clear links on error. */
564 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
573 /* use this function to stop ibss as well */
574 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
576 struct wl12xx_cmd_role_stop
*cmd
;
579 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
582 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
588 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
590 cmd
->role_id
= wlvif
->role_id
;
591 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
592 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
594 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
596 wl1271_error("failed to initiate cmd role stop sta");
600 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
609 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
611 struct wl12xx_cmd_role_start
*cmd
;
612 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
613 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
617 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
619 /* trying to use hidden SSID with an old hostapd version */
620 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
621 wl1271_error("got a null SSID from beacon/bss");
626 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
632 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
636 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
638 goto out_free_global
;
640 /* use the previous security seq, if this is a recovery/resume */
641 wl
->links
[wlvif
->ap
.bcast_hlid
].total_freed_pkts
=
642 wlvif
->total_freed_pkts
;
644 cmd
->role_id
= wlvif
->role_id
;
645 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
646 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
647 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
648 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
649 cmd
->ap
.global_session_id
= wl
->session_ids
[wlvif
->ap
.global_hlid
];
650 cmd
->ap
.bcast_session_id
= wl
->session_ids
[wlvif
->ap
.bcast_hlid
];
651 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
652 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
653 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
654 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
655 /* FIXME: Change when adding DFS */
656 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
657 cmd
->ap
.wmm
= wlvif
->wmm_enabled
;
658 cmd
->channel
= wlvif
->channel
;
659 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
661 if (!bss_conf
->hidden_ssid
) {
662 /* take the SSID from the beacon for backward compatibility */
663 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
664 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
665 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
667 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
668 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
669 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
672 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
673 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
675 supported_rates
&= ~CONF_TX_CCK_RATES
;
677 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
680 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
682 switch (wlvif
->band
) {
683 case IEEE80211_BAND_2GHZ
:
684 cmd
->band
= WLCORE_BAND_2_4GHZ
;
686 case IEEE80211_BAND_5GHZ
:
687 cmd
->band
= WLCORE_BAND_5GHZ
;
690 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
691 cmd
->band
= WLCORE_BAND_2_4GHZ
;
695 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
697 wl1271_error("failed to initiate cmd role start ap");
704 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
707 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
716 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
718 struct wl12xx_cmd_role_stop
*cmd
;
721 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
727 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
729 cmd
->role_id
= wlvif
->role_id
;
731 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
733 wl1271_error("failed to initiate cmd role stop ap");
737 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
738 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
747 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
749 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
750 struct wl12xx_cmd_role_start
*cmd
;
751 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
754 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
760 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
762 cmd
->role_id
= wlvif
->role_id
;
763 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
764 cmd
->band
= WLCORE_BAND_5GHZ
;
765 cmd
->channel
= wlvif
->channel
;
766 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
767 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
768 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
769 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
770 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
771 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
772 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
773 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
775 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
776 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
780 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
781 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
783 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
784 "basic_rate_set: 0x%x, remote_rates: 0x%x",
785 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
786 wlvif
->basic_rate_set
, wlvif
->rate_set
);
788 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
789 vif
->bss_conf
.bssid
);
791 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
793 wl1271_error("failed to initiate cmd role enable");
800 /* clear links on error. */
801 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
812 * send test command to firmware
815 * @buf: buffer containing the command, with all headers, must work with dma
816 * @len: length of the buffer
817 * @answer: is answer needed
819 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
824 wl1271_debug(DEBUG_CMD
, "cmd test");
829 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
832 wl1271_warning("TEST command failed");
838 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
841 * read acx from firmware
845 * @buf: buffer for the response, including all headers, must work with dma
846 * @len: length of buf
848 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
850 struct acx_header
*acx
= buf
;
853 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
855 acx
->id
= cpu_to_le16(id
);
857 /* payload length, does not include any headers */
858 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
860 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
862 wl1271_error("INTERROGATE command failed");
868 * write acx value to firmware
872 * @buf: buffer containing acx, including all headers, must work with dma
873 * @len: length of buf
874 * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
875 * return the cmd status on success.
877 int wlcore_cmd_configure_failsafe(struct wl1271
*wl
, u16 id
, void *buf
,
878 size_t len
, unsigned long valid_rets
)
880 struct acx_header
*acx
= buf
;
883 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
885 acx
->id
= cpu_to_le16(id
);
887 /* payload length, does not include any headers */
888 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
890 ret
= wlcore_cmd_send_failsafe(wl
, CMD_CONFIGURE
, acx
, len
, 0,
893 wl1271_warning("CONFIGURE command NOK");
901 * wrapper for wlcore_cmd_configure that accepts only success status.
902 * return 0 on success
904 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
906 int ret
= wlcore_cmd_configure_failsafe(wl
, id
, buf
, len
, 0);
912 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
914 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
916 struct cmd_enabledisable_path
*cmd
;
920 wl1271_debug(DEBUG_CMD
, "cmd data path");
922 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
928 /* the channel here is only used for calibration, so hardcoded to 1 */
932 cmd_rx
= CMD_ENABLE_RX
;
933 cmd_tx
= CMD_ENABLE_TX
;
935 cmd_rx
= CMD_DISABLE_RX
;
936 cmd_tx
= CMD_DISABLE_TX
;
939 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
941 wl1271_error("rx %s cmd for channel %d failed",
942 enable
? "start" : "stop", cmd
->channel
);
946 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
947 enable
? "start" : "stop", cmd
->channel
);
949 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
951 wl1271_error("tx %s cmd for channel %d failed",
952 enable
? "start" : "stop", cmd
->channel
);
956 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
957 enable
? "start" : "stop", cmd
->channel
);
963 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
965 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
966 u8 ps_mode
, u16 auto_ps_timeout
)
968 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
971 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
973 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
979 ps_params
->role_id
= wlvif
->role_id
;
980 ps_params
->ps_mode
= ps_mode
;
981 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
983 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
984 sizeof(*ps_params
), 0);
986 wl1271_error("cmd set_ps_mode failed");
995 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
996 u16 template_id
, void *buf
, size_t buf_len
,
997 int index
, u32 rates
)
999 struct wl1271_cmd_template_set
*cmd
;
1002 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
1003 template_id
, role_id
);
1005 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1006 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1008 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1014 /* during initialization wlvif is NULL */
1015 cmd
->role_id
= role_id
;
1016 cmd
->len
= cpu_to_le16(buf_len
);
1017 cmd
->template_type
= template_id
;
1018 cmd
->enabled_rates
= cpu_to_le32(rates
);
1019 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1020 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1024 memcpy(cmd
->template_data
, buf
, buf_len
);
1026 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1028 wl1271_warning("cmd set_template failed: %d", ret
);
1039 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1041 struct sk_buff
*skb
= NULL
;
1047 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1048 size
= sizeof(struct wl12xx_null_data_template
);
1051 skb
= ieee80211_nullfunc_get(wl
->hw
,
1052 wl12xx_wlvif_to_vif(wlvif
));
1059 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1060 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
1066 wl1271_warning("cmd buld null data failed %d", ret
);
1072 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
1073 struct wl12xx_vif
*wlvif
)
1075 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1076 struct sk_buff
*skb
= NULL
;
1079 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
1083 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
1084 skb
->data
, skb
->len
,
1085 wlvif
->sta
.klv_template_id
,
1091 wl1271_warning("cmd build klv null data failed %d", ret
);
1097 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1100 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1101 struct sk_buff
*skb
;
1104 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
1108 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1109 CMD_TEMPL_PS_POLL
, skb
->data
,
1110 skb
->len
, 0, wlvif
->basic_rate_set
);
1117 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1118 u8 role_id
, u8 band
,
1119 const u8
*ssid
, size_t ssid_len
,
1120 const u8
*ie
, size_t ie_len
, bool sched_scan
)
1122 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1123 struct sk_buff
*skb
;
1126 u16 template_id_2_4
= wl
->scan_templ_id_2_4
;
1127 u16 template_id_5
= wl
->scan_templ_id_5
;
1129 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1136 memcpy(skb_put(skb
, ie_len
), ie
, ie_len
);
1138 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
1141 (wl
->quirks
& WLCORE_QUIRK_DUAL_PROBE_TMPL
)) {
1142 template_id_2_4
= wl
->sched_scan_templ_id_2_4
;
1143 template_id_5
= wl
->sched_scan_templ_id_5
;
1146 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1147 if (band
== IEEE80211_BAND_2GHZ
)
1148 ret
= wl1271_cmd_template_set(wl
, role_id
,
1150 skb
->data
, skb
->len
, 0, rate
);
1152 ret
= wl1271_cmd_template_set(wl
, role_id
,
1154 skb
->data
, skb
->len
, 0, rate
);
1160 EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req
);
1162 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1163 struct wl12xx_vif
*wlvif
,
1164 struct sk_buff
*skb
)
1166 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1171 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1175 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1177 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1178 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1179 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1180 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1181 skb
->data
, skb
->len
, 0, rate
);
1183 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1184 CMD_TEMPL_CFG_PROBE_REQ_5
,
1185 skb
->data
, skb
->len
, 0, rate
);
1188 wl1271_error("Unable to set ap probe request template.");
1194 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1198 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1199 struct sk_buff
*skb
;
1200 struct wl12xx_arp_rsp_template
*tmpl
;
1201 struct ieee80211_hdr_3addr
*hdr
;
1202 struct arphdr
*arp_hdr
;
1204 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1205 WL1271_EXTRA_SPACE_MAX
);
1207 wl1271_error("failed to allocate buffer for arp rsp template");
1211 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1213 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1214 memset(tmpl
, 0, sizeof(*tmpl
));
1217 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1218 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1221 arp_hdr
= &tmpl
->arp_hdr
;
1222 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1223 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1224 arp_hdr
->ar_hln
= ETH_ALEN
;
1225 arp_hdr
->ar_pln
= 4;
1226 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1229 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1230 tmpl
->sender_ip
= wlvif
->ip_addr
;
1232 /* encryption space */
1233 switch (wlvif
->encryption_type
) {
1235 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1236 extra
= WL1271_EXTRA_SPACE_TKIP
;
1239 extra
= WL1271_EXTRA_SPACE_AES
;
1247 wl1271_warning("Unknown encryption type: %d",
1248 wlvif
->encryption_type
);
1254 u8
*space
= skb_push(skb
, extra
);
1255 memset(space
, 0, extra
);
1258 /* QoS header - BE */
1260 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1262 /* mac80211 header */
1263 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1264 memset(hdr
, 0, sizeof(*hdr
));
1265 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1267 fc
|= IEEE80211_STYPE_QOS_DATA
;
1269 fc
|= IEEE80211_STYPE_DATA
;
1270 if (wlvif
->encryption_type
!= KEY_NONE
)
1271 fc
|= IEEE80211_FCTL_PROTECTED
;
1273 hdr
->frame_control
= cpu_to_le16(fc
);
1274 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1275 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1276 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1278 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1279 skb
->data
, skb
->len
, 0,
1286 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1288 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1289 struct ieee80211_qos_hdr
template;
1291 memset(&template, 0, sizeof(template));
1293 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1294 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1295 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1297 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1298 IEEE80211_STYPE_QOS_NULLFUNC
|
1299 IEEE80211_FCTL_TODS
);
1301 /* FIXME: not sure what priority to use here */
1302 template.qos_ctrl
= cpu_to_le16(0);
1304 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1305 CMD_TEMPL_QOS_NULL_DATA
, &template,
1306 sizeof(template), 0,
1310 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1312 struct wl1271_cmd_set_keys
*cmd
;
1315 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1317 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1325 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1326 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1327 cmd
->key_type
= KEY_WEP
;
1329 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1331 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1341 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1342 u16 action
, u8 id
, u8 key_type
,
1343 u8 key_size
, const u8
*key
, const u8
*addr
,
1344 u32 tx_seq_32
, u16 tx_seq_16
)
1346 struct wl1271_cmd_set_keys
*cmd
;
1349 /* hlid might have already been deleted */
1350 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1353 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1359 cmd
->hlid
= wlvif
->sta
.hlid
;
1361 if (key_type
== KEY_WEP
)
1362 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1363 else if (is_broadcast_ether_addr(addr
))
1364 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1366 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1368 cmd
->key_action
= cpu_to_le16(action
);
1369 cmd
->key_size
= key_size
;
1370 cmd
->key_type
= key_type
;
1372 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1373 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1377 if (key_type
== KEY_TKIP
) {
1379 * We get the key in the following form:
1380 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1381 * but the target is expecting:
1382 * TKIP - RX MIC - TX MIC
1384 memcpy(cmd
->key
, key
, 16);
1385 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1386 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1389 memcpy(cmd
->key
, key
, key_size
);
1392 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1394 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1396 wl1271_warning("could not set keys");
1407 * TODO: merge with sta/ibss into 1 set_key function.
1408 * note there are slight diffs
1410 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1411 u16 action
, u8 id
, u8 key_type
,
1412 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1415 struct wl1271_cmd_set_keys
*cmd
;
1419 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1423 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1424 if (key_type
== KEY_WEP
)
1425 lid_type
= WEP_DEFAULT_LID_TYPE
;
1427 lid_type
= BROADCAST_LID_TYPE
;
1429 lid_type
= UNICAST_LID_TYPE
;
1432 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1433 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1434 (int)key_type
, (int)hlid
);
1436 cmd
->lid_key_type
= lid_type
;
1438 cmd
->key_action
= cpu_to_le16(action
);
1439 cmd
->key_size
= key_size
;
1440 cmd
->key_type
= key_type
;
1442 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1443 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1445 if (key_type
== KEY_TKIP
) {
1447 * We get the key in the following form:
1448 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1449 * but the target is expecting:
1450 * TKIP - RX MIC - TX MIC
1452 memcpy(cmd
->key
, key
, 16);
1453 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1454 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1456 memcpy(cmd
->key
, key
, key_size
);
1459 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1461 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1463 wl1271_warning("could not set ap keys");
1472 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1475 struct wl12xx_cmd_set_peer_state
*cmd
;
1478 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1480 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1487 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1489 /* wmm param is valid only for station role */
1490 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1491 cmd
->wmm
= wlvif
->wmm_enabled
;
1493 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1495 wl1271_error("failed to send set peer state command");
1506 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1507 struct ieee80211_sta
*sta
, u8 hlid
)
1509 struct wl12xx_cmd_add_peer
*cmd
;
1513 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1515 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1521 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1522 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1523 cmd
->aid
= sta
->aid
;
1525 cmd
->sp_len
= sta
->max_sp
;
1526 cmd
->wmm
= sta
->wme
? 1 : 0;
1527 cmd
->session_id
= wl
->session_ids
[hlid
];
1529 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1530 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1531 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1532 WL1271_PSD_UPSD_TRIGGER
;
1534 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1538 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1539 if (sta
->ht_cap
.ht_supported
)
1541 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1542 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1544 cmd
->supported_rates
=
1545 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1548 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1549 cmd
->supported_rates
, sta
->uapsd_queues
);
1551 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1553 wl1271_error("failed to initiate cmd add peer");
1564 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1566 struct wl12xx_cmd_remove_peer
*cmd
;
1568 bool timeout
= false;
1570 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1572 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1579 /* We never send a deauth, mac80211 is in charge of this */
1580 cmd
->reason_opcode
= 0;
1581 cmd
->send_deauth_flag
= 0;
1583 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1585 wl1271_error("failed to initiate cmd remove peer");
1589 ret
= wl
->ops
->wait_for_event(wl
,
1590 WLCORE_EVENT_PEER_REMOVE_COMPLETE
,
1594 * We are ok with a timeout here. The event is sometimes not sent
1595 * due to a firmware bug. In case of another error (like SDIO timeout)
1599 wl12xx_queue_recovery_work(wl
);
1608 static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band
, u16 ch
)
1613 case IEEE80211_BAND_5GHZ
:
1614 if (ch
>= 8 && ch
<= 16)
1615 idx
= ((ch
-8)/4 + 18);
1616 else if (ch
>= 34 && ch
<= 64)
1617 idx
= ((ch
-34)/2 + 3 + 18);
1618 else if (ch
>= 100 && ch
<= 140)
1619 idx
= ((ch
-100)/4 + 15 + 18);
1620 else if (ch
>= 149 && ch
<= 165)
1621 idx
= ((ch
-149)/4 + 26 + 18);
1625 case IEEE80211_BAND_2GHZ
:
1626 if (ch
>= 1 && ch
<= 14)
1632 wl1271_error("get reg conf ch idx - unknown band: %d",
1639 void wlcore_set_pending_regdomain_ch(struct wl1271
*wl
, u16 channel
,
1640 enum ieee80211_band band
)
1644 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1647 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(band
, channel
);
1649 if (ch_bit_idx
> 0 && ch_bit_idx
<= WL1271_MAX_CHANNELS
)
1650 set_bit(ch_bit_idx
, (long *)wl
->reg_ch_conf_pending
);
1653 int wlcore_cmd_regdomain_config_locked(struct wl1271
*wl
)
1655 struct wl12xx_cmd_regdomain_dfs_config
*cmd
= NULL
;
1656 int ret
= 0, i
, b
, ch_bit_idx
;
1657 struct ieee80211_channel
*channel
;
1658 u32 tmp_ch_bitmap
[2];
1660 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1661 struct ieee80211_supported_band
*band
;
1662 bool timeout
= false;
1664 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1667 wl1271_debug(DEBUG_CMD
, "cmd reg domain config");
1669 memset(tmp_ch_bitmap
, 0, sizeof(tmp_ch_bitmap
));
1671 for (b
= IEEE80211_BAND_2GHZ
; b
<= IEEE80211_BAND_5GHZ
; b
++) {
1672 band
= wiphy
->bands
[b
];
1673 for (i
= 0; i
< band
->n_channels
; i
++) {
1674 channel
= &band
->channels
[i
];
1675 ch
= channel
->hw_value
;
1677 if (channel
->flags
& (IEEE80211_CHAN_DISABLED
|
1678 IEEE80211_CHAN_RADAR
|
1679 IEEE80211_CHAN_PASSIVE_SCAN
))
1682 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(b
, ch
);
1686 set_bit(ch_bit_idx
, (long *)tmp_ch_bitmap
);
1690 tmp_ch_bitmap
[0] |= wl
->reg_ch_conf_pending
[0];
1691 tmp_ch_bitmap
[1] |= wl
->reg_ch_conf_pending
[1];
1693 if (!memcmp(tmp_ch_bitmap
, wl
->reg_ch_conf_last
, sizeof(tmp_ch_bitmap
)))
1696 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1702 cmd
->ch_bit_map1
= cpu_to_le32(tmp_ch_bitmap
[0]);
1703 cmd
->ch_bit_map2
= cpu_to_le32(tmp_ch_bitmap
[1]);
1705 wl1271_debug(DEBUG_CMD
,
1706 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x",
1707 cmd
->ch_bit_map1
, cmd
->ch_bit_map2
);
1709 ret
= wl1271_cmd_send(wl
, CMD_DFS_CHANNEL_CONFIG
, cmd
, sizeof(*cmd
), 0);
1711 wl1271_error("failed to send reg domain dfs config");
1715 ret
= wl
->ops
->wait_for_event(wl
,
1716 WLCORE_EVENT_DFS_CONFIG_COMPLETE
,
1718 if (ret
< 0 || timeout
) {
1719 wl1271_error("reg domain conf %serror",
1720 timeout
? "completion " : "");
1721 ret
= timeout
? -ETIMEDOUT
: ret
;
1725 memcpy(wl
->reg_ch_conf_last
, tmp_ch_bitmap
, sizeof(tmp_ch_bitmap
));
1726 memset(wl
->reg_ch_conf_pending
, 0, sizeof(wl
->reg_ch_conf_pending
));
1733 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1735 struct wl12xx_cmd_config_fwlog
*cmd
;
1738 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1740 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1746 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1747 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1748 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1749 cmd
->output
= wl
->conf
.fwlog
.output
;
1750 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1752 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1754 wl1271_error("failed to send config firmware logger command");
1765 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1767 struct wl12xx_cmd_start_fwlog
*cmd
;
1770 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1772 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1778 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1780 wl1271_error("failed to send start firmware logger command");
1791 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1793 struct wl12xx_cmd_stop_fwlog
*cmd
;
1796 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1798 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1804 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1806 wl1271_error("failed to send stop firmware logger command");
1817 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1818 u8 role_id
, enum ieee80211_band band
, u8 channel
)
1820 struct wl12xx_cmd_roc
*cmd
;
1823 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", channel
, role_id
);
1825 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1828 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1834 cmd
->role_id
= role_id
;
1835 cmd
->channel
= channel
;
1837 case IEEE80211_BAND_2GHZ
:
1838 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1840 case IEEE80211_BAND_5GHZ
:
1841 cmd
->band
= WLCORE_BAND_5GHZ
;
1844 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1850 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1852 wl1271_error("failed to send ROC command");
1863 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1865 struct wl12xx_cmd_croc
*cmd
;
1868 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1870 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1875 cmd
->role_id
= role_id
;
1877 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1880 wl1271_error("failed to send ROC command");
1891 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
,
1892 enum ieee80211_band band
, u8 channel
)
1896 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1899 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
, band
, channel
);
1903 __set_bit(role_id
, wl
->roc_map
);
1908 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1912 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1915 ret
= wl12xx_cmd_croc(wl
, role_id
);
1919 __clear_bit(role_id
, wl
->roc_map
);
1922 * Rearm the tx watchdog when removing the last ROC. This prevents
1923 * recoveries due to just finished ROCs - when Tx hasn't yet had
1924 * a chance to get out.
1926 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1927 wl12xx_rearm_tx_watchdog_locked(wl
);
1932 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1934 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1937 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1939 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1945 cmd
->role_id
= wlvif
->role_id
;
1947 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1949 wl1271_error("failed to stop channel switch command");
1960 /* start dev role and roc on its channel */
1961 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1962 enum ieee80211_band band
, int channel
)
1966 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1967 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1970 ret
= wl12xx_cmd_role_enable(wl
,
1971 wl12xx_wlvif_to_vif(wlvif
)->addr
,
1973 &wlvif
->dev_role_id
);
1977 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
, band
, channel
);
1981 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
, band
, channel
);
1988 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
1990 wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
1995 /* croc dev hlid, and stop the role */
1996 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2000 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2001 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2004 /* flush all pending packets */
2005 ret
= wlcore_tx_work_locked(wl
);
2009 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
2010 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
2015 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2019 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);