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(wl
->state
== WLCORE_STATE_RESTARTING
&&
64 id
!= CMD_STOP_FWLOGGER
))
68 cmd
->id
= cpu_to_le16(id
);
71 WARN_ON(len
% 4 != 0);
72 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
74 ret
= wlcore_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
79 * TODO: we just need this because one bit is in a different
80 * place. Is there any better way?
82 ret
= wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
86 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
88 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
92 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
93 if (time_after(jiffies
, timeout
)) {
94 wl1271_error("command complete timeout");
99 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
104 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
109 /* read back the status code of the command */
111 res_len
= sizeof(struct wl1271_cmd_header
);
113 ret
= wlcore_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
117 status
= le16_to_cpu(cmd
->status
);
119 ret
= wlcore_write_reg(wl
, REG_INTERRUPT_ACK
,
120 WL1271_ACX_INTR_CMD_COMPLETE
);
128 * send command to fw and return cmd status on success
129 * valid_rets contains a bitmap of allowed error codes
131 int wlcore_cmd_send_failsafe(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
132 size_t res_len
, unsigned long valid_rets
)
134 int ret
= __wlcore_cmd_send(wl
, id
, buf
, len
, res_len
);
139 /* success is always a valid status */
140 valid_rets
|= BIT(CMD_STATUS_SUCCESS
);
142 if (ret
>= MAX_COMMAND_STATUS
||
143 !test_bit(ret
, &valid_rets
)) {
144 wl1271_error("command execute failure %d", ret
);
150 wl12xx_queue_recovery_work(wl
);
153 EXPORT_SYMBOL_GPL(wl1271_cmd_send
);
156 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
157 * return 0 on success.
159 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
162 int ret
= wlcore_cmd_send_failsafe(wl
, id
, buf
, len
, res_len
, 0);
170 * Poll the mailbox event field until any of the bits in the mask is set or a
171 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
173 int wlcore_cmd_wait_for_event_or_timeout(struct wl1271
*wl
,
174 u32 mask
, bool *timeout
)
178 unsigned long timeout_time
;
184 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
188 timeout_time
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
191 if (time_after(jiffies
, timeout_time
)) {
192 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
199 if (poll_count
< WL1271_WAIT_EVENT_FAST_POLL_COUNT
)
200 usleep_range(50, 51);
202 usleep_range(1000, 5000);
204 /* read from both event fields */
205 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
206 sizeof(*events_vector
), false);
210 event
= *events_vector
& mask
;
212 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
213 sizeof(*events_vector
), false);
217 event
|= *events_vector
& mask
;
221 kfree(events_vector
);
224 EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout
);
226 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
229 struct wl12xx_cmd_role_enable
*cmd
;
232 wl1271_debug(DEBUG_CMD
, "cmd role enable");
234 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
237 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
244 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
245 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
250 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
251 cmd
->role_type
= role_type
;
253 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
255 wl1271_error("failed to initiate cmd role enable");
259 __set_bit(cmd
->role_id
, wl
->roles_map
);
260 *role_id
= cmd
->role_id
;
269 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
271 struct wl12xx_cmd_role_disable
*cmd
;
274 wl1271_debug(DEBUG_CMD
, "cmd role disable");
276 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
279 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
284 cmd
->role_id
= *role_id
;
286 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
288 wl1271_error("failed to initiate cmd role disable");
292 __clear_bit(*role_id
, wl
->roles_map
);
293 *role_id
= WL12XX_INVALID_ROLE_ID
;
302 static int wlcore_get_new_session_id(struct wl1271
*wl
, u8 hlid
)
304 if (wl
->session_ids
[hlid
] >= SESSION_COUNTER_MAX
)
305 wl
->session_ids
[hlid
] = 0;
307 wl
->session_ids
[hlid
]++;
309 return wl
->session_ids
[hlid
];
312 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
315 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
316 if (link
>= WL12XX_MAX_LINKS
)
319 wl
->session_ids
[link
] = wlcore_get_new_session_id(wl
, link
);
321 /* these bits are used by op_tx */
322 spin_lock_irqsave(&wl
->wl_lock
, flags
);
323 __set_bit(link
, wl
->links_map
);
324 __set_bit(link
, wlvif
->links_map
);
325 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
327 /* take the last "freed packets" value from the current FW status */
328 wl
->links
[link
].prev_freed_pkts
=
329 wl
->fw_status_2
->counters
.tx_lnk_free_pkts
[link
];
330 wl
->links
[link
].wlvif
= wlvif
;
333 * Take saved value for total freed packets from wlvif, in case this is
336 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
)
337 wl
->links
[link
].total_freed_pkts
= wlvif
->total_freed_pkts
;
341 wl
->active_link_count
++;
345 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
349 if (*hlid
== WL12XX_INVALID_LINK_ID
)
352 /* these bits are used by op_tx */
353 spin_lock_irqsave(&wl
->wl_lock
, flags
);
354 __clear_bit(*hlid
, wl
->links_map
);
355 __clear_bit(*hlid
, wlvif
->links_map
);
356 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
358 wl
->links
[*hlid
].allocated_pkts
= 0;
359 wl
->links
[*hlid
].prev_freed_pkts
= 0;
360 wl
->links
[*hlid
].ba_bitmap
= 0;
361 memset(wl
->links
[*hlid
].addr
, 0, ETH_ALEN
);
364 * At this point op_tx() will not add more packets to the queues. We
367 wl1271_tx_reset_link_queues(wl
, *hlid
);
368 wl
->links
[*hlid
].wlvif
= NULL
;
370 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
371 (wlvif
->bss_type
== BSS_TYPE_AP_BSS
&&
372 *hlid
== wlvif
->ap
.bcast_hlid
)) {
374 * save the total freed packets in the wlvif, in case this is
375 * recovery or suspend
377 wlvif
->total_freed_pkts
= wl
->links
[*hlid
].total_freed_pkts
;
380 * increment the initial seq number on recovery to account for
381 * transmitted packets that we haven't yet got in the FW status
383 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
384 wlvif
->total_freed_pkts
+=
385 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
388 wl
->links
[*hlid
].total_freed_pkts
= 0;
390 *hlid
= WL12XX_INVALID_LINK_ID
;
391 wl
->active_link_count
--;
392 WARN_ON_ONCE(wl
->active_link_count
< 0);
395 static u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
397 switch (nl_channel_type
) {
398 case NL80211_CHAN_NO_HT
:
399 return WLCORE_CHAN_NO_HT
;
400 case NL80211_CHAN_HT20
:
401 return WLCORE_CHAN_HT20
;
402 case NL80211_CHAN_HT40MINUS
:
403 return WLCORE_CHAN_HT40MINUS
;
404 case NL80211_CHAN_HT40PLUS
:
405 return WLCORE_CHAN_HT40PLUS
;
408 return WLCORE_CHAN_NO_HT
;
412 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
413 struct wl12xx_vif
*wlvif
,
414 enum ieee80211_band band
,
417 struct wl12xx_cmd_role_start
*cmd
;
420 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
426 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
428 cmd
->role_id
= wlvif
->dev_role_id
;
429 if (band
== IEEE80211_BAND_5GHZ
)
430 cmd
->band
= WLCORE_BAND_5GHZ
;
431 cmd
->channel
= channel
;
433 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
434 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
438 cmd
->device
.hlid
= wlvif
->dev_hlid
;
439 cmd
->device
.session
= wl
->session_ids
[wlvif
->dev_hlid
];
441 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
442 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
444 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
446 wl1271_error("failed to initiate cmd role enable");
453 /* clear links on error */
454 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
463 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
464 struct wl12xx_vif
*wlvif
)
466 struct wl12xx_cmd_role_stop
*cmd
;
469 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
472 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
478 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
480 cmd
->role_id
= wlvif
->dev_role_id
;
481 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
482 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
484 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
486 wl1271_error("failed to initiate cmd role stop");
490 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
499 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
501 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
502 struct wl12xx_cmd_role_start
*cmd
;
506 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
512 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
514 cmd
->role_id
= wlvif
->role_id
;
515 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
516 cmd
->band
= WLCORE_BAND_5GHZ
;
517 cmd
->channel
= wlvif
->channel
;
518 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
519 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
520 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
521 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
522 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
523 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
525 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
526 wlcore_hw_sta_get_ap_rate_mask(wl
, wlvif
);
528 supported_rates
&= ~CONF_TX_CCK_RATES
;
530 cmd
->sta
.local_rates
= cpu_to_le32(supported_rates
);
532 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
534 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
535 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
539 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
540 cmd
->sta
.session
= wl
->session_ids
[wlvif
->sta
.hlid
];
542 * We don't have the correct remote rates in this stage. The
543 * rates will be reconfigured later, after association, if the
544 * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
545 * we can do, so use all supported_rates here.
547 cmd
->sta
.remote_rates
= cpu_to_le32(supported_rates
);
549 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
550 "basic_rate_set: 0x%x, remote_rates: 0x%x",
551 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
552 wlvif
->basic_rate_set
, wlvif
->rate_set
);
554 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
556 wl1271_error("failed to initiate cmd role start sta");
560 wlvif
->sta
.role_chan_type
= wlvif
->channel_type
;
564 /* clear links on error. */
565 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
574 /* use this function to stop ibss as well */
575 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
577 struct wl12xx_cmd_role_stop
*cmd
;
580 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
583 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
589 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
591 cmd
->role_id
= wlvif
->role_id
;
592 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
593 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
595 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
597 wl1271_error("failed to initiate cmd role stop sta");
601 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
610 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
612 struct wl12xx_cmd_role_start
*cmd
;
613 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
614 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
618 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
620 /* trying to use hidden SSID with an old hostapd version */
621 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
622 wl1271_error("got a null SSID from beacon/bss");
627 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
633 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
637 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
639 goto out_free_global
;
641 /* use the previous security seq, if this is a recovery/resume */
642 wl
->links
[wlvif
->ap
.bcast_hlid
].total_freed_pkts
=
643 wlvif
->total_freed_pkts
;
645 cmd
->role_id
= wlvif
->role_id
;
646 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
647 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
648 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
649 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
650 cmd
->ap
.global_session_id
= wl
->session_ids
[wlvif
->ap
.global_hlid
];
651 cmd
->ap
.bcast_session_id
= wl
->session_ids
[wlvif
->ap
.bcast_hlid
];
652 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
653 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
654 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
655 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
656 /* FIXME: Change when adding DFS */
657 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
658 cmd
->ap
.wmm
= wlvif
->wmm_enabled
;
659 cmd
->channel
= wlvif
->channel
;
660 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
662 if (!bss_conf
->hidden_ssid
) {
663 /* take the SSID from the beacon for backward compatibility */
664 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
665 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
666 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
668 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
669 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
670 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
673 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
674 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
676 supported_rates
&= ~CONF_TX_CCK_RATES
;
678 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
681 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
683 switch (wlvif
->band
) {
684 case IEEE80211_BAND_2GHZ
:
685 cmd
->band
= WLCORE_BAND_2_4GHZ
;
687 case IEEE80211_BAND_5GHZ
:
688 cmd
->band
= WLCORE_BAND_5GHZ
;
691 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
692 cmd
->band
= WLCORE_BAND_2_4GHZ
;
696 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
698 wl1271_error("failed to initiate cmd role start ap");
705 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
708 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
717 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
719 struct wl12xx_cmd_role_stop
*cmd
;
722 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
728 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
730 cmd
->role_id
= wlvif
->role_id
;
732 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
734 wl1271_error("failed to initiate cmd role stop ap");
738 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
739 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
748 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
750 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
751 struct wl12xx_cmd_role_start
*cmd
;
752 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
755 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
761 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
763 cmd
->role_id
= wlvif
->role_id
;
764 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
765 cmd
->band
= WLCORE_BAND_5GHZ
;
766 cmd
->channel
= wlvif
->channel
;
767 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
768 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
769 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
770 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
771 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
772 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
773 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
774 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
776 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
777 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
781 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
782 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
784 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
785 "basic_rate_set: 0x%x, remote_rates: 0x%x",
786 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
787 wlvif
->basic_rate_set
, wlvif
->rate_set
);
789 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
790 vif
->bss_conf
.bssid
);
792 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
794 wl1271_error("failed to initiate cmd role enable");
801 /* clear links on error. */
802 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
813 * send test command to firmware
816 * @buf: buffer containing the command, with all headers, must work with dma
817 * @len: length of the buffer
818 * @answer: is answer needed
820 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
825 wl1271_debug(DEBUG_CMD
, "cmd test");
830 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
833 wl1271_warning("TEST command failed");
839 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
842 * read acx from firmware
846 * @buf: buffer for the response, including all headers, must work with dma
847 * @len: length of buf
849 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
,
850 size_t cmd_len
, size_t res_len
)
852 struct acx_header
*acx
= buf
;
855 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
857 acx
->id
= cpu_to_le16(id
);
859 /* response payload length, does not include any headers */
860 acx
->len
= cpu_to_le16(res_len
- sizeof(*acx
));
862 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, cmd_len
, res_len
);
864 wl1271_error("INTERROGATE command failed");
870 * write acx value to firmware
874 * @buf: buffer containing acx, including all headers, must work with dma
875 * @len: length of buf
876 * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
877 * return the cmd status on success.
879 int wlcore_cmd_configure_failsafe(struct wl1271
*wl
, u16 id
, void *buf
,
880 size_t len
, unsigned long valid_rets
)
882 struct acx_header
*acx
= buf
;
885 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
887 acx
->id
= cpu_to_le16(id
);
889 /* payload length, does not include any headers */
890 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
892 ret
= wlcore_cmd_send_failsafe(wl
, CMD_CONFIGURE
, acx
, len
, 0,
895 wl1271_warning("CONFIGURE command NOK");
903 * wrapper for wlcore_cmd_configure that accepts only success status.
904 * return 0 on success
906 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
908 int ret
= wlcore_cmd_configure_failsafe(wl
, id
, buf
, len
, 0);
914 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
916 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
918 struct cmd_enabledisable_path
*cmd
;
922 wl1271_debug(DEBUG_CMD
, "cmd data path");
924 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
930 /* the channel here is only used for calibration, so hardcoded to 1 */
934 cmd_rx
= CMD_ENABLE_RX
;
935 cmd_tx
= CMD_ENABLE_TX
;
937 cmd_rx
= CMD_DISABLE_RX
;
938 cmd_tx
= CMD_DISABLE_TX
;
941 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
943 wl1271_error("rx %s cmd for channel %d failed",
944 enable
? "start" : "stop", cmd
->channel
);
948 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
949 enable
? "start" : "stop", cmd
->channel
);
951 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
953 wl1271_error("tx %s cmd for channel %d failed",
954 enable
? "start" : "stop", cmd
->channel
);
958 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
959 enable
? "start" : "stop", cmd
->channel
);
965 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
967 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
968 u8 ps_mode
, u16 auto_ps_timeout
)
970 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
973 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
975 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
981 ps_params
->role_id
= wlvif
->role_id
;
982 ps_params
->ps_mode
= ps_mode
;
983 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
985 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
986 sizeof(*ps_params
), 0);
988 wl1271_error("cmd set_ps_mode failed");
997 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
998 u16 template_id
, void *buf
, size_t buf_len
,
999 int index
, u32 rates
)
1001 struct wl1271_cmd_template_set
*cmd
;
1004 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
1005 template_id
, role_id
);
1007 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1008 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1010 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1016 /* during initialization wlvif is NULL */
1017 cmd
->role_id
= role_id
;
1018 cmd
->len
= cpu_to_le16(buf_len
);
1019 cmd
->template_type
= template_id
;
1020 cmd
->enabled_rates
= cpu_to_le32(rates
);
1021 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1022 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1026 memcpy(cmd
->template_data
, buf
, buf_len
);
1028 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1030 wl1271_warning("cmd set_template failed: %d", ret
);
1041 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1043 struct sk_buff
*skb
= NULL
;
1049 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1050 size
= sizeof(struct wl12xx_null_data_template
);
1053 skb
= ieee80211_nullfunc_get(wl
->hw
,
1054 wl12xx_wlvif_to_vif(wlvif
));
1061 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1062 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
1068 wl1271_warning("cmd buld null data failed %d", ret
);
1074 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
1075 struct wl12xx_vif
*wlvif
)
1077 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1078 struct sk_buff
*skb
= NULL
;
1081 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
);
1085 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
1086 skb
->data
, skb
->len
,
1087 wlvif
->sta
.klv_template_id
,
1093 wl1271_warning("cmd build klv null data failed %d", ret
);
1099 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1102 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1103 struct sk_buff
*skb
;
1106 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
1110 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1111 CMD_TEMPL_PS_POLL
, skb
->data
,
1112 skb
->len
, 0, wlvif
->basic_rate_set
);
1119 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1120 u8 role_id
, u8 band
,
1121 const u8
*ssid
, size_t ssid_len
,
1122 const u8
*ie
, size_t ie_len
, bool sched_scan
)
1124 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1125 struct sk_buff
*skb
;
1128 u16 template_id_2_4
= wl
->scan_templ_id_2_4
;
1129 u16 template_id_5
= wl
->scan_templ_id_5
;
1131 wl1271_debug(DEBUG_SCAN
, "build probe request band %d", band
);
1133 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1140 memcpy(skb_put(skb
, ie_len
), ie
, ie_len
);
1143 (wl
->quirks
& WLCORE_QUIRK_DUAL_PROBE_TMPL
)) {
1144 template_id_2_4
= wl
->sched_scan_templ_id_2_4
;
1145 template_id_5
= wl
->sched_scan_templ_id_5
;
1148 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1149 if (band
== IEEE80211_BAND_2GHZ
)
1150 ret
= wl1271_cmd_template_set(wl
, role_id
,
1152 skb
->data
, skb
->len
, 0, rate
);
1154 ret
= wl1271_cmd_template_set(wl
, role_id
,
1156 skb
->data
, skb
->len
, 0, rate
);
1162 EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req
);
1164 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1165 struct wl12xx_vif
*wlvif
,
1166 struct sk_buff
*skb
)
1168 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1173 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1177 wl1271_debug(DEBUG_SCAN
, "set ap probe request template");
1179 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1180 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1181 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1182 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1183 skb
->data
, skb
->len
, 0, rate
);
1185 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1186 CMD_TEMPL_CFG_PROBE_REQ_5
,
1187 skb
->data
, skb
->len
, 0, rate
);
1190 wl1271_error("Unable to set ap probe request template.");
1196 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1200 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1201 struct sk_buff
*skb
;
1202 struct wl12xx_arp_rsp_template
*tmpl
;
1203 struct ieee80211_hdr_3addr
*hdr
;
1204 struct arphdr
*arp_hdr
;
1206 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1207 WL1271_EXTRA_SPACE_MAX
);
1209 wl1271_error("failed to allocate buffer for arp rsp template");
1213 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1215 tmpl
= (struct wl12xx_arp_rsp_template
*)skb_put(skb
, sizeof(*tmpl
));
1216 memset(tmpl
, 0, sizeof(*tmpl
));
1219 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1220 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1223 arp_hdr
= &tmpl
->arp_hdr
;
1224 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1225 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1226 arp_hdr
->ar_hln
= ETH_ALEN
;
1227 arp_hdr
->ar_pln
= 4;
1228 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1231 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1232 tmpl
->sender_ip
= wlvif
->ip_addr
;
1234 /* encryption space */
1235 switch (wlvif
->encryption_type
) {
1237 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1238 extra
= WL1271_EXTRA_SPACE_TKIP
;
1241 extra
= WL1271_EXTRA_SPACE_AES
;
1249 wl1271_warning("Unknown encryption type: %d",
1250 wlvif
->encryption_type
);
1256 u8
*space
= skb_push(skb
, extra
);
1257 memset(space
, 0, extra
);
1260 /* QoS header - BE */
1262 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1264 /* mac80211 header */
1265 hdr
= (struct ieee80211_hdr_3addr
*)skb_push(skb
, sizeof(*hdr
));
1266 memset(hdr
, 0, sizeof(*hdr
));
1267 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1269 fc
|= IEEE80211_STYPE_QOS_DATA
;
1271 fc
|= IEEE80211_STYPE_DATA
;
1272 if (wlvif
->encryption_type
!= KEY_NONE
)
1273 fc
|= IEEE80211_FCTL_PROTECTED
;
1275 hdr
->frame_control
= cpu_to_le16(fc
);
1276 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1277 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1278 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1280 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1281 skb
->data
, skb
->len
, 0,
1288 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1290 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1291 struct ieee80211_qos_hdr
template;
1293 memset(&template, 0, sizeof(template));
1295 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1296 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1297 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1299 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1300 IEEE80211_STYPE_QOS_NULLFUNC
|
1301 IEEE80211_FCTL_TODS
);
1303 /* FIXME: not sure what priority to use here */
1304 template.qos_ctrl
= cpu_to_le16(0);
1306 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1307 CMD_TEMPL_QOS_NULL_DATA
, &template,
1308 sizeof(template), 0,
1312 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1314 struct wl1271_cmd_set_keys
*cmd
;
1317 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1319 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1327 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1328 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1329 cmd
->key_type
= KEY_WEP
;
1331 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1333 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1343 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1344 u16 action
, u8 id
, u8 key_type
,
1345 u8 key_size
, const u8
*key
, const u8
*addr
,
1346 u32 tx_seq_32
, u16 tx_seq_16
)
1348 struct wl1271_cmd_set_keys
*cmd
;
1351 /* hlid might have already been deleted */
1352 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1355 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1361 cmd
->hlid
= wlvif
->sta
.hlid
;
1363 if (key_type
== KEY_WEP
)
1364 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1365 else if (is_broadcast_ether_addr(addr
))
1366 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1368 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1370 cmd
->key_action
= cpu_to_le16(action
);
1371 cmd
->key_size
= key_size
;
1372 cmd
->key_type
= key_type
;
1374 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1375 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1379 if (key_type
== KEY_TKIP
) {
1381 * We get the key in the following form:
1382 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1383 * but the target is expecting:
1384 * TKIP - RX MIC - TX MIC
1386 memcpy(cmd
->key
, key
, 16);
1387 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1388 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1391 memcpy(cmd
->key
, key
, key_size
);
1394 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1396 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1398 wl1271_warning("could not set keys");
1409 * TODO: merge with sta/ibss into 1 set_key function.
1410 * note there are slight diffs
1412 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1413 u16 action
, u8 id
, u8 key_type
,
1414 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1417 struct wl1271_cmd_set_keys
*cmd
;
1421 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1425 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1426 if (key_type
== KEY_WEP
)
1427 lid_type
= WEP_DEFAULT_LID_TYPE
;
1429 lid_type
= BROADCAST_LID_TYPE
;
1431 lid_type
= UNICAST_LID_TYPE
;
1434 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1435 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1436 (int)key_type
, (int)hlid
);
1438 cmd
->lid_key_type
= lid_type
;
1440 cmd
->key_action
= cpu_to_le16(action
);
1441 cmd
->key_size
= key_size
;
1442 cmd
->key_type
= key_type
;
1444 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1445 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1447 if (key_type
== KEY_TKIP
) {
1449 * We get the key in the following form:
1450 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1451 * but the target is expecting:
1452 * TKIP - RX MIC - TX MIC
1454 memcpy(cmd
->key
, key
, 16);
1455 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1456 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1458 memcpy(cmd
->key
, key
, key_size
);
1461 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1463 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1465 wl1271_warning("could not set ap keys");
1474 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1477 struct wl12xx_cmd_set_peer_state
*cmd
;
1480 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1482 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1489 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1491 /* wmm param is valid only for station role */
1492 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1493 cmd
->wmm
= wlvif
->wmm_enabled
;
1495 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1497 wl1271_error("failed to send set peer state command");
1508 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1509 struct ieee80211_sta
*sta
, u8 hlid
)
1511 struct wl12xx_cmd_add_peer
*cmd
;
1515 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1517 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1523 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1524 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1525 cmd
->aid
= sta
->aid
;
1527 cmd
->sp_len
= sta
->max_sp
;
1528 cmd
->wmm
= sta
->wme
? 1 : 0;
1529 cmd
->session_id
= wl
->session_ids
[hlid
];
1531 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1532 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1533 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1534 WL1271_PSD_UPSD_TRIGGER
;
1536 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1540 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1541 if (sta
->ht_cap
.ht_supported
)
1543 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1544 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1546 cmd
->supported_rates
=
1547 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1550 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1551 cmd
->supported_rates
, sta
->uapsd_queues
);
1553 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1555 wl1271_error("failed to initiate cmd add peer");
1566 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1568 struct wl12xx_cmd_remove_peer
*cmd
;
1570 bool timeout
= false;
1572 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1574 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1581 /* We never send a deauth, mac80211 is in charge of this */
1582 cmd
->reason_opcode
= 0;
1583 cmd
->send_deauth_flag
= 0;
1585 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1587 wl1271_error("failed to initiate cmd remove peer");
1591 ret
= wl
->ops
->wait_for_event(wl
,
1592 WLCORE_EVENT_PEER_REMOVE_COMPLETE
,
1596 * We are ok with a timeout here. The event is sometimes not sent
1597 * due to a firmware bug. In case of another error (like SDIO timeout)
1601 wl12xx_queue_recovery_work(wl
);
1610 static int wlcore_get_reg_conf_ch_idx(enum ieee80211_band band
, u16 ch
)
1613 * map the given band/channel to the respective predefined
1614 * bit expected by the fw
1617 case IEEE80211_BAND_2GHZ
:
1618 /* channels 1..14 are mapped to 0..13 */
1619 if (ch
>= 1 && ch
<= 14)
1622 case IEEE80211_BAND_5GHZ
:
1625 /* channels 8,12,16 are mapped to 18,19,20 */
1626 return 18 + (ch
-8)/4;
1628 /* channels 34,36..48 are mapped to 21..28 */
1629 return 21 + (ch
-34)/2;
1631 /* channels 52,56..64 are mapped to 29..32 */
1632 return 29 + (ch
-52)/4;
1634 /* channels 100,104..140 are mapped to 33..43 */
1635 return 33 + (ch
-100)/4;
1637 /* channels 149,153..165 are mapped to 44..48 */
1638 return 44 + (ch
-149)/4;
1647 wl1271_error("%s: unknown band/channel: %d/%d", __func__
, band
, ch
);
1651 void wlcore_set_pending_regdomain_ch(struct wl1271
*wl
, u16 channel
,
1652 enum ieee80211_band band
)
1656 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1659 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(band
, channel
);
1661 if (ch_bit_idx
>= 0 && ch_bit_idx
<= WL1271_MAX_CHANNELS
)
1662 set_bit(ch_bit_idx
, (long *)wl
->reg_ch_conf_pending
);
1665 int wlcore_cmd_regdomain_config_locked(struct wl1271
*wl
)
1667 struct wl12xx_cmd_regdomain_dfs_config
*cmd
= NULL
;
1668 int ret
= 0, i
, b
, ch_bit_idx
;
1669 struct ieee80211_channel
*channel
;
1670 u32 tmp_ch_bitmap
[2];
1672 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1673 struct ieee80211_supported_band
*band
;
1674 bool timeout
= false;
1676 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1679 wl1271_debug(DEBUG_CMD
, "cmd reg domain config");
1681 memset(tmp_ch_bitmap
, 0, sizeof(tmp_ch_bitmap
));
1683 for (b
= IEEE80211_BAND_2GHZ
; b
<= IEEE80211_BAND_5GHZ
; b
++) {
1684 band
= wiphy
->bands
[b
];
1685 for (i
= 0; i
< band
->n_channels
; i
++) {
1686 channel
= &band
->channels
[i
];
1687 ch
= channel
->hw_value
;
1689 if (channel
->flags
& (IEEE80211_CHAN_DISABLED
|
1690 IEEE80211_CHAN_RADAR
|
1691 IEEE80211_CHAN_NO_IR
))
1694 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(b
, ch
);
1698 set_bit(ch_bit_idx
, (long *)tmp_ch_bitmap
);
1702 tmp_ch_bitmap
[0] |= wl
->reg_ch_conf_pending
[0];
1703 tmp_ch_bitmap
[1] |= wl
->reg_ch_conf_pending
[1];
1705 if (!memcmp(tmp_ch_bitmap
, wl
->reg_ch_conf_last
, sizeof(tmp_ch_bitmap
)))
1708 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1714 cmd
->ch_bit_map1
= cpu_to_le32(tmp_ch_bitmap
[0]);
1715 cmd
->ch_bit_map2
= cpu_to_le32(tmp_ch_bitmap
[1]);
1717 wl1271_debug(DEBUG_CMD
,
1718 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x",
1719 cmd
->ch_bit_map1
, cmd
->ch_bit_map2
);
1721 ret
= wl1271_cmd_send(wl
, CMD_DFS_CHANNEL_CONFIG
, cmd
, sizeof(*cmd
), 0);
1723 wl1271_error("failed to send reg domain dfs config");
1727 ret
= wl
->ops
->wait_for_event(wl
,
1728 WLCORE_EVENT_DFS_CONFIG_COMPLETE
,
1730 if (ret
< 0 || timeout
) {
1731 wl1271_error("reg domain conf %serror",
1732 timeout
? "completion " : "");
1733 ret
= timeout
? -ETIMEDOUT
: ret
;
1737 memcpy(wl
->reg_ch_conf_last
, tmp_ch_bitmap
, sizeof(tmp_ch_bitmap
));
1738 memset(wl
->reg_ch_conf_pending
, 0, sizeof(wl
->reg_ch_conf_pending
));
1745 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1747 struct wl12xx_cmd_config_fwlog
*cmd
;
1750 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1752 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1758 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1759 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1760 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1761 cmd
->output
= wl
->conf
.fwlog
.output
;
1762 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1764 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1766 wl1271_error("failed to send config firmware logger command");
1777 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1779 struct wl12xx_cmd_start_fwlog
*cmd
;
1782 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1784 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1790 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1792 wl1271_error("failed to send start firmware logger command");
1803 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1805 struct wl12xx_cmd_stop_fwlog
*cmd
;
1808 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1810 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1816 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1818 wl1271_error("failed to send stop firmware logger command");
1829 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1830 u8 role_id
, enum ieee80211_band band
, u8 channel
)
1832 struct wl12xx_cmd_roc
*cmd
;
1835 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", channel
, role_id
);
1837 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1840 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1846 cmd
->role_id
= role_id
;
1847 cmd
->channel
= channel
;
1849 case IEEE80211_BAND_2GHZ
:
1850 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1852 case IEEE80211_BAND_5GHZ
:
1853 cmd
->band
= WLCORE_BAND_5GHZ
;
1856 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1862 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1864 wl1271_error("failed to send ROC command");
1875 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1877 struct wl12xx_cmd_croc
*cmd
;
1880 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1882 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1887 cmd
->role_id
= role_id
;
1889 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1892 wl1271_error("failed to send ROC command");
1903 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
,
1904 enum ieee80211_band band
, u8 channel
)
1908 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1911 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
, band
, channel
);
1915 __set_bit(role_id
, wl
->roc_map
);
1920 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1924 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1927 ret
= wl12xx_cmd_croc(wl
, role_id
);
1931 __clear_bit(role_id
, wl
->roc_map
);
1934 * Rearm the tx watchdog when removing the last ROC. This prevents
1935 * recoveries due to just finished ROCs - when Tx hasn't yet had
1936 * a chance to get out.
1938 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1939 wl12xx_rearm_tx_watchdog_locked(wl
);
1944 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1946 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1949 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1951 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1957 cmd
->role_id
= wlvif
->role_id
;
1959 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1961 wl1271_error("failed to stop channel switch command");
1972 /* start dev role and roc on its channel */
1973 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1974 enum ieee80211_band band
, int channel
)
1978 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1979 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
1982 ret
= wl12xx_cmd_role_enable(wl
,
1983 wl12xx_wlvif_to_vif(wlvif
)->addr
,
1985 &wlvif
->dev_role_id
);
1989 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
, band
, channel
);
1993 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
, band
, channel
);
2000 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2002 wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2007 /* croc dev hlid, and stop the role */
2008 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2012 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2013 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2016 /* flush all pending packets */
2017 ret
= wlcore_tx_work_locked(wl
);
2021 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
2022 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
2027 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2031 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);