1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wl1271
5 * Copyright (C) 2009-2010 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/pm_runtime.h>
13 #include <linux/spi/spi.h>
14 #include <linux/etherdevice.h>
15 #include <linux/ieee80211.h>
16 #include <linux/slab.h>
22 #include "wl12xx_80211.h"
28 #define WL1271_CMD_FAST_POLL_COUNT 50
29 #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20
32 * send command to firmware
36 * @buf: buffer containing the command, must work with dma
37 * @len: length of the buffer
38 * return the cmd status code on success.
40 static int __wlcore_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
,
41 size_t len
, size_t res_len
)
43 struct wl1271_cmd_header
*cmd
;
44 unsigned long timeout
;
50 if (unlikely(wl
->state
== WLCORE_STATE_RESTARTING
&&
51 id
!= CMD_STOP_FWLOGGER
))
54 if (WARN_ON_ONCE(len
< sizeof(*cmd
)))
58 cmd
->id
= cpu_to_le16(id
);
61 WARN_ON(len
% 4 != 0);
62 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
64 ret
= wlcore_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
69 * TODO: we just need this because one bit is in a different
70 * place. Is there any better way?
72 ret
= wl
->ops
->trigger_cmd(wl
, wl
->cmd_box_addr
, buf
, len
);
76 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
78 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
82 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
83 if (time_after(jiffies
, timeout
)) {
84 wl1271_error("command complete timeout");
89 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
94 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &intr
);
99 /* read back the status code of the command */
101 res_len
= sizeof(struct wl1271_cmd_header
);
103 ret
= wlcore_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
107 status
= le16_to_cpu(cmd
->status
);
109 ret
= wlcore_write_reg(wl
, REG_INTERRUPT_ACK
,
110 WL1271_ACX_INTR_CMD_COMPLETE
);
118 * send command to fw and return cmd status on success
119 * valid_rets contains a bitmap of allowed error codes
121 static int wlcore_cmd_send_failsafe(struct wl1271
*wl
, u16 id
, void *buf
,
122 size_t len
, size_t res_len
,
123 unsigned long valid_rets
)
125 int ret
= __wlcore_cmd_send(wl
, id
, buf
, len
, res_len
);
130 /* success is always a valid status */
131 valid_rets
|= BIT(CMD_STATUS_SUCCESS
);
133 if (ret
>= MAX_COMMAND_STATUS
||
134 !test_bit(ret
, &valid_rets
)) {
135 wl1271_error("command execute failure %d", ret
);
141 wl12xx_queue_recovery_work(wl
);
146 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
147 * return 0 on success.
149 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
152 int ret
= wlcore_cmd_send_failsafe(wl
, id
, buf
, len
, res_len
, 0);
158 EXPORT_SYMBOL_GPL(wl1271_cmd_send
);
161 * Poll the mailbox event field until any of the bits in the mask is set or a
162 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
164 int wlcore_cmd_wait_for_event_or_timeout(struct wl1271
*wl
,
165 u32 mask
, bool *timeout
)
169 unsigned long timeout_time
;
175 events_vector
= kmalloc(sizeof(*events_vector
), GFP_KERNEL
| GFP_DMA
);
179 timeout_time
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
181 ret
= pm_runtime_get_sync(wl
->dev
);
183 pm_runtime_put_noidle(wl
->dev
);
188 if (time_after(jiffies
, timeout_time
)) {
189 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
196 if (poll_count
< WL1271_WAIT_EVENT_FAST_POLL_COUNT
)
197 usleep_range(50, 51);
199 usleep_range(1000, 5000);
201 /* read from both event fields */
202 ret
= wlcore_read(wl
, wl
->mbox_ptr
[0], events_vector
,
203 sizeof(*events_vector
), false);
207 event
= *events_vector
& mask
;
209 ret
= wlcore_read(wl
, wl
->mbox_ptr
[1], events_vector
,
210 sizeof(*events_vector
), false);
214 event
|= *events_vector
& mask
;
218 pm_runtime_mark_last_busy(wl
->dev
);
219 pm_runtime_put_autosuspend(wl
->dev
);
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
, wl
->num_links
);
316 if (link
>= wl
->num_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
);
328 * take the last "freed packets" value from the current FW status.
329 * on recovery, we might not have fw_status yet, and
330 * tx_lnk_free_pkts will be NULL. check for it.
332 if (wl
->fw_status
->counters
.tx_lnk_free_pkts
)
333 wl
->links
[link
].prev_freed_pkts
=
334 wl
->fw_status
->counters
.tx_lnk_free_pkts
[link
];
335 wl
->links
[link
].wlvif
= wlvif
;
338 * Take saved value for total freed packets from wlvif, in case this is
341 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
)
342 wl
->links
[link
].total_freed_pkts
= wlvif
->total_freed_pkts
;
346 wl
->active_link_count
++;
350 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
354 if (*hlid
== WL12XX_INVALID_LINK_ID
)
357 /* these bits are used by op_tx */
358 spin_lock_irqsave(&wl
->wl_lock
, flags
);
359 __clear_bit(*hlid
, wl
->links_map
);
360 __clear_bit(*hlid
, wlvif
->links_map
);
361 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
363 wl
->links
[*hlid
].allocated_pkts
= 0;
364 wl
->links
[*hlid
].prev_freed_pkts
= 0;
365 wl
->links
[*hlid
].ba_bitmap
= 0;
366 eth_zero_addr(wl
->links
[*hlid
].addr
);
369 * At this point op_tx() will not add more packets to the queues. We
372 wl1271_tx_reset_link_queues(wl
, *hlid
);
373 wl
->links
[*hlid
].wlvif
= NULL
;
375 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
&&
376 *hlid
== wlvif
->ap
.bcast_hlid
) {
377 u32 sqn_padding
= WL1271_TX_SQN_POST_RECOVERY_PADDING
;
379 * save the total freed packets in the wlvif, in case this is
380 * recovery or suspend
382 wlvif
->total_freed_pkts
= wl
->links
[*hlid
].total_freed_pkts
;
385 * increment the initial seq number on recovery to account for
386 * transmitted packets that we haven't yet got in the FW status
388 if (wlvif
->encryption_type
== KEY_GEM
)
389 sqn_padding
= WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM
;
391 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
392 wlvif
->total_freed_pkts
+= sqn_padding
;
395 wl
->links
[*hlid
].total_freed_pkts
= 0;
397 *hlid
= WL12XX_INVALID_LINK_ID
;
398 wl
->active_link_count
--;
399 WARN_ON_ONCE(wl
->active_link_count
< 0);
402 u8
wlcore_get_native_channel_type(u8 nl_channel_type
)
404 switch (nl_channel_type
) {
405 case NL80211_CHAN_NO_HT
:
406 return WLCORE_CHAN_NO_HT
;
407 case NL80211_CHAN_HT20
:
408 return WLCORE_CHAN_HT20
;
409 case NL80211_CHAN_HT40MINUS
:
410 return WLCORE_CHAN_HT40MINUS
;
411 case NL80211_CHAN_HT40PLUS
:
412 return WLCORE_CHAN_HT40PLUS
;
415 return WLCORE_CHAN_NO_HT
;
418 EXPORT_SYMBOL_GPL(wlcore_get_native_channel_type
);
420 static int wl12xx_cmd_role_start_dev(struct wl1271
*wl
,
421 struct wl12xx_vif
*wlvif
,
422 enum nl80211_band band
,
425 struct wl12xx_cmd_role_start
*cmd
;
428 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
434 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
436 cmd
->role_id
= wlvif
->dev_role_id
;
437 if (band
== NL80211_BAND_5GHZ
)
438 cmd
->band
= WLCORE_BAND_5GHZ
;
439 cmd
->channel
= channel
;
441 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
442 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
446 cmd
->device
.hlid
= wlvif
->dev_hlid
;
447 cmd
->device
.session
= wl
->session_ids
[wlvif
->dev_hlid
];
449 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
450 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
452 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
454 wl1271_error("failed to initiate cmd role enable");
461 /* clear links on error */
462 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
471 static int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
,
472 struct wl12xx_vif
*wlvif
)
474 struct wl12xx_cmd_role_stop
*cmd
;
477 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
480 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
486 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
488 cmd
->role_id
= wlvif
->dev_role_id
;
489 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
490 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
492 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
494 wl1271_error("failed to initiate cmd role stop");
498 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
507 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
509 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
510 struct wl12xx_cmd_role_start
*cmd
;
514 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
520 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
522 cmd
->role_id
= wlvif
->role_id
;
523 if (wlvif
->band
== NL80211_BAND_5GHZ
)
524 cmd
->band
= WLCORE_BAND_5GHZ
;
525 cmd
->channel
= wlvif
->channel
;
526 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
527 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
528 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
529 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
530 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
531 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
533 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
534 wlcore_hw_sta_get_ap_rate_mask(wl
, wlvif
);
536 supported_rates
&= ~CONF_TX_CCK_RATES
;
538 cmd
->sta
.local_rates
= cpu_to_le32(supported_rates
);
540 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
542 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
543 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
547 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
548 cmd
->sta
.session
= wl
->session_ids
[wlvif
->sta
.hlid
];
550 * We don't have the correct remote rates in this stage. The
551 * rates will be reconfigured later, after association, if the
552 * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
553 * we can do, so use all supported_rates here.
555 cmd
->sta
.remote_rates
= cpu_to_le32(supported_rates
);
557 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
558 "basic_rate_set: 0x%x, remote_rates: 0x%x",
559 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
560 wlvif
->basic_rate_set
, wlvif
->rate_set
);
562 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
564 wl1271_error("failed to initiate cmd role start sta");
568 wlvif
->sta
.role_chan_type
= wlvif
->channel_type
;
572 /* clear links on error. */
573 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
582 /* use this function to stop ibss as well */
583 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
585 struct wl12xx_cmd_role_stop
*cmd
;
588 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
591 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
597 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
599 cmd
->role_id
= wlvif
->role_id
;
600 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
601 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
603 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
605 wl1271_error("failed to initiate cmd role stop sta");
609 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
618 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
620 struct wl12xx_cmd_role_start
*cmd
;
621 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
622 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
626 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
628 /* If MESH --> ssid_len is always 0 */
629 if (!ieee80211_vif_is_mesh(vif
)) {
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");
638 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
644 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
648 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
650 goto out_free_global
;
652 /* use the previous security seq, if this is a recovery/resume */
653 wl
->links
[wlvif
->ap
.bcast_hlid
].total_freed_pkts
=
654 wlvif
->total_freed_pkts
;
656 cmd
->role_id
= wlvif
->role_id
;
657 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
658 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
659 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
660 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
661 cmd
->ap
.global_session_id
= wl
->session_ids
[wlvif
->ap
.global_hlid
];
662 cmd
->ap
.bcast_session_id
= wl
->session_ids
[wlvif
->ap
.bcast_hlid
];
663 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
664 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
665 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
666 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
667 /* FIXME: Change when adding DFS */
668 cmd
->ap
.reset_tsf
= 1; /* By default reset AP TSF */
669 cmd
->ap
.wmm
= wlvif
->wmm_enabled
;
670 cmd
->channel
= wlvif
->channel
;
671 cmd
->channel_type
= wlcore_get_native_channel_type(wlvif
->channel_type
);
673 if (!bss_conf
->hidden_ssid
) {
674 /* take the SSID from the beacon for backward compatibility */
675 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
676 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
677 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
679 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
680 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
681 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
684 supported_rates
= CONF_TX_ENABLED_RATES
| CONF_TX_MCS_RATES
|
685 wlcore_hw_ap_get_mimo_wide_rate_mask(wl
, wlvif
);
687 supported_rates
&= ~CONF_TX_CCK_RATES
;
689 wl1271_debug(DEBUG_CMD
, "cmd role start ap with supported_rates 0x%08x",
692 cmd
->ap
.local_rates
= cpu_to_le32(supported_rates
);
694 switch (wlvif
->band
) {
695 case NL80211_BAND_2GHZ
:
696 cmd
->band
= WLCORE_BAND_2_4GHZ
;
698 case NL80211_BAND_5GHZ
:
699 cmd
->band
= WLCORE_BAND_5GHZ
;
702 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
703 cmd
->band
= WLCORE_BAND_2_4GHZ
;
707 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
709 wl1271_error("failed to initiate cmd role start ap");
716 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
719 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
728 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
730 struct wl12xx_cmd_role_stop
*cmd
;
733 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
739 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
741 cmd
->role_id
= wlvif
->role_id
;
743 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
745 wl1271_error("failed to initiate cmd role stop ap");
749 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
750 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
759 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
761 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
762 struct wl12xx_cmd_role_start
*cmd
;
763 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
766 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
772 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
774 cmd
->role_id
= wlvif
->role_id
;
775 if (wlvif
->band
== NL80211_BAND_5GHZ
)
776 cmd
->band
= WLCORE_BAND_5GHZ
;
777 cmd
->channel
= wlvif
->channel
;
778 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
779 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
780 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
781 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
782 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
783 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
784 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
785 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
787 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
788 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
792 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
793 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
795 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
796 "basic_rate_set: 0x%x, remote_rates: 0x%x",
797 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
798 wlvif
->basic_rate_set
, wlvif
->rate_set
);
800 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
801 vif
->bss_conf
.bssid
);
803 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
805 wl1271_error("failed to initiate cmd role enable");
812 /* clear links on error. */
813 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
824 * send test command to firmware
827 * @buf: buffer containing the command, with all headers, must work with dma
828 * @len: length of the buffer
829 * @answer: is answer needed
831 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
836 wl1271_debug(DEBUG_CMD
, "cmd test");
841 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
844 wl1271_warning("TEST command failed");
850 EXPORT_SYMBOL_GPL(wl1271_cmd_test
);
853 * read acx from firmware
857 * @buf: buffer for the response, including all headers, must work with dma
858 * @len: length of buf
860 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
,
861 size_t cmd_len
, size_t res_len
)
863 struct acx_header
*acx
= buf
;
866 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
868 acx
->id
= cpu_to_le16(id
);
870 /* response payload length, does not include any headers */
871 acx
->len
= cpu_to_le16(res_len
- sizeof(*acx
));
873 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, cmd_len
, res_len
);
875 wl1271_error("INTERROGATE command failed");
881 * write acx value to firmware
885 * @buf: buffer containing acx, including all headers, must work with dma
886 * @len: length of buf
887 * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
888 * return the cmd status on success.
890 int wlcore_cmd_configure_failsafe(struct wl1271
*wl
, u16 id
, void *buf
,
891 size_t len
, unsigned long valid_rets
)
893 struct acx_header
*acx
= buf
;
896 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
898 if (WARN_ON_ONCE(len
< sizeof(*acx
)))
901 acx
->id
= cpu_to_le16(id
);
903 /* payload length, does not include any headers */
904 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
906 ret
= wlcore_cmd_send_failsafe(wl
, CMD_CONFIGURE
, acx
, len
, 0,
909 wl1271_warning("CONFIGURE command NOK");
917 * wrapper for wlcore_cmd_configure that accepts only success status.
918 * return 0 on success
920 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
922 int ret
= wlcore_cmd_configure_failsafe(wl
, id
, buf
, len
, 0);
928 EXPORT_SYMBOL_GPL(wl1271_cmd_configure
);
930 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
932 struct cmd_enabledisable_path
*cmd
;
936 wl1271_debug(DEBUG_CMD
, "cmd data path");
938 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
944 /* the channel here is only used for calibration, so hardcoded to 1 */
948 cmd_rx
= CMD_ENABLE_RX
;
949 cmd_tx
= CMD_ENABLE_TX
;
951 cmd_rx
= CMD_DISABLE_RX
;
952 cmd_tx
= CMD_DISABLE_TX
;
955 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
957 wl1271_error("rx %s cmd for channel %d failed",
958 enable
? "start" : "stop", cmd
->channel
);
962 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
963 enable
? "start" : "stop", cmd
->channel
);
965 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
967 wl1271_error("tx %s cmd for channel %d failed",
968 enable
? "start" : "stop", cmd
->channel
);
972 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
973 enable
? "start" : "stop", cmd
->channel
);
979 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path
);
981 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
982 u8 ps_mode
, u16 auto_ps_timeout
)
984 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
987 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
989 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
995 ps_params
->role_id
= wlvif
->role_id
;
996 ps_params
->ps_mode
= ps_mode
;
997 ps_params
->auto_ps_timeout
= auto_ps_timeout
;
999 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
1000 sizeof(*ps_params
), 0);
1002 wl1271_error("cmd set_ps_mode failed");
1011 int wl1271_cmd_template_set(struct wl1271
*wl
, u8 role_id
,
1012 u16 template_id
, void *buf
, size_t buf_len
,
1013 int index
, u32 rates
)
1015 struct wl1271_cmd_template_set
*cmd
;
1018 wl1271_debug(DEBUG_CMD
, "cmd template_set %d (role %d)",
1019 template_id
, role_id
);
1021 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1022 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1024 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1030 /* during initialization wlvif is NULL */
1031 cmd
->role_id
= role_id
;
1032 cmd
->len
= cpu_to_le16(buf_len
);
1033 cmd
->template_type
= template_id
;
1034 cmd
->enabled_rates
= cpu_to_le32(rates
);
1035 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1036 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1040 memcpy(cmd
->template_data
, buf
, buf_len
);
1042 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1044 wl1271_warning("cmd set_template failed: %d", ret
);
1055 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1057 struct sk_buff
*skb
= NULL
;
1063 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1064 size
= sizeof(struct wl12xx_null_data_template
);
1067 skb
= ieee80211_nullfunc_get(wl
->hw
,
1068 wl12xx_wlvif_to_vif(wlvif
),
1076 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1077 CMD_TEMPL_NULL_DATA
, ptr
, size
, 0,
1083 wl1271_warning("cmd buld null data failed %d", ret
);
1089 int wl12xx_cmd_build_klv_null_data(struct wl1271
*wl
,
1090 struct wl12xx_vif
*wlvif
)
1092 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1093 struct sk_buff
*skb
= NULL
;
1096 skb
= ieee80211_nullfunc_get(wl
->hw
, vif
, false);
1100 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_KLV
,
1101 skb
->data
, skb
->len
,
1102 wlvif
->sta
.klv_template_id
,
1108 wl1271_warning("cmd build klv null data failed %d", ret
);
1114 int wl1271_cmd_build_ps_poll(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1117 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1118 struct sk_buff
*skb
;
1121 skb
= ieee80211_pspoll_get(wl
->hw
, vif
);
1125 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1126 CMD_TEMPL_PS_POLL
, skb
->data
,
1127 skb
->len
, 0, wlvif
->basic_rate_set
);
1134 int wl12xx_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1135 u8 role_id
, u8 band
,
1136 const u8
*ssid
, size_t ssid_len
,
1137 const u8
*ie0
, size_t ie0_len
, const u8
*ie1
,
1138 size_t ie1_len
, bool sched_scan
)
1140 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1141 struct sk_buff
*skb
;
1144 u16 template_id_2_4
= wl
->scan_templ_id_2_4
;
1145 u16 template_id_5
= wl
->scan_templ_id_5
;
1147 wl1271_debug(DEBUG_SCAN
, "build probe request band %d", band
);
1149 skb
= ieee80211_probereq_get(wl
->hw
, vif
->addr
, ssid
, ssid_len
,
1156 skb_put_data(skb
, ie0
, ie0_len
);
1158 skb_put_data(skb
, ie1
, ie1_len
);
1161 (wl
->quirks
& WLCORE_QUIRK_DUAL_PROBE_TMPL
)) {
1162 template_id_2_4
= wl
->sched_scan_templ_id_2_4
;
1163 template_id_5
= wl
->sched_scan_templ_id_5
;
1166 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1167 if (band
== NL80211_BAND_2GHZ
)
1168 ret
= wl1271_cmd_template_set(wl
, role_id
,
1170 skb
->data
, skb
->len
, 0, rate
);
1172 ret
= wl1271_cmd_template_set(wl
, role_id
,
1174 skb
->data
, skb
->len
, 0, rate
);
1180 EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req
);
1182 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1183 struct wl12xx_vif
*wlvif
,
1184 struct sk_buff
*skb
)
1186 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1191 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1195 wl1271_debug(DEBUG_SCAN
, "set ap probe request template");
1197 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1198 if (wlvif
->band
== NL80211_BAND_2GHZ
)
1199 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1200 CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1201 skb
->data
, skb
->len
, 0, rate
);
1203 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1204 CMD_TEMPL_CFG_PROBE_REQ_5
,
1205 skb
->data
, skb
->len
, 0, rate
);
1208 wl1271_error("Unable to set ap probe request template.");
1214 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1218 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1219 struct sk_buff
*skb
;
1220 struct wl12xx_arp_rsp_template
*tmpl
;
1221 struct ieee80211_hdr_3addr
*hdr
;
1222 struct arphdr
*arp_hdr
;
1224 skb
= dev_alloc_skb(sizeof(*hdr
) + sizeof(__le16
) + sizeof(*tmpl
) +
1225 WL1271_EXTRA_SPACE_MAX
);
1227 wl1271_error("failed to allocate buffer for arp rsp template");
1231 skb_reserve(skb
, sizeof(*hdr
) + WL1271_EXTRA_SPACE_MAX
);
1233 tmpl
= skb_put_zero(skb
, sizeof(*tmpl
));
1236 memcpy(tmpl
->llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1237 tmpl
->llc_type
= cpu_to_be16(ETH_P_ARP
);
1240 arp_hdr
= &tmpl
->arp_hdr
;
1241 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1242 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1243 arp_hdr
->ar_hln
= ETH_ALEN
;
1244 arp_hdr
->ar_pln
= 4;
1245 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1248 memcpy(tmpl
->sender_hw
, vif
->addr
, ETH_ALEN
);
1249 tmpl
->sender_ip
= wlvif
->ip_addr
;
1251 /* encryption space */
1252 switch (wlvif
->encryption_type
) {
1254 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
1255 extra
= WL1271_EXTRA_SPACE_TKIP
;
1258 extra
= WL1271_EXTRA_SPACE_AES
;
1266 wl1271_warning("Unknown encryption type: %d",
1267 wlvif
->encryption_type
);
1273 u8
*space
= skb_push(skb
, extra
);
1274 memset(space
, 0, extra
);
1277 /* QoS header - BE */
1279 memset(skb_push(skb
, sizeof(__le16
)), 0, sizeof(__le16
));
1281 /* mac80211 header */
1282 hdr
= skb_push(skb
, sizeof(*hdr
));
1283 memset(hdr
, 0, sizeof(*hdr
));
1284 fc
= IEEE80211_FTYPE_DATA
| IEEE80211_FCTL_TODS
;
1286 fc
|= IEEE80211_STYPE_QOS_DATA
;
1288 fc
|= IEEE80211_STYPE_DATA
;
1289 if (wlvif
->encryption_type
!= KEY_NONE
)
1290 fc
|= IEEE80211_FCTL_PROTECTED
;
1292 hdr
->frame_control
= cpu_to_le16(fc
);
1293 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1294 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1295 eth_broadcast_addr(hdr
->addr3
);
1297 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, CMD_TEMPL_ARP_RSP
,
1298 skb
->data
, skb
->len
, 0,
1305 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1307 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1308 struct ieee80211_qos_hdr
template;
1310 memset(&template, 0, sizeof(template));
1312 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1313 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1314 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1316 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1317 IEEE80211_STYPE_QOS_NULLFUNC
|
1318 IEEE80211_FCTL_TODS
);
1320 /* FIXME: not sure what priority to use here */
1321 template.qos_ctrl
= cpu_to_le16(0);
1323 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
1324 CMD_TEMPL_QOS_NULL_DATA
, &template,
1325 sizeof(template), 0,
1329 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1331 struct wl1271_cmd_set_keys
*cmd
;
1334 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1336 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1344 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1345 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1346 cmd
->key_type
= KEY_WEP
;
1348 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1350 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1360 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1361 u16 action
, u8 id
, u8 key_type
,
1362 u8 key_size
, const u8
*key
, const u8
*addr
,
1363 u32 tx_seq_32
, u16 tx_seq_16
)
1365 struct wl1271_cmd_set_keys
*cmd
;
1368 /* hlid might have already been deleted */
1369 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1372 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1378 cmd
->hlid
= wlvif
->sta
.hlid
;
1380 if (key_type
== KEY_WEP
)
1381 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1382 else if (is_broadcast_ether_addr(addr
))
1383 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1385 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1387 cmd
->key_action
= cpu_to_le16(action
);
1388 cmd
->key_size
= key_size
;
1389 cmd
->key_type
= key_type
;
1391 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1392 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1396 if (key_type
== KEY_TKIP
) {
1398 * We get the key in the following form:
1399 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1400 * but the target is expecting:
1401 * TKIP - RX MIC - TX MIC
1403 memcpy(cmd
->key
, key
, 16);
1404 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1405 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1408 memcpy(cmd
->key
, key
, key_size
);
1411 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1413 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1415 wl1271_warning("could not set keys");
1426 * TODO: merge with sta/ibss into 1 set_key function.
1427 * note there are slight diffs
1429 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1430 u16 action
, u8 id
, u8 key_type
,
1431 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1432 u16 tx_seq_16
, bool is_pairwise
)
1434 struct wl1271_cmd_set_keys
*cmd
;
1438 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1442 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1443 if (key_type
== KEY_WEP
)
1444 lid_type
= WEP_DEFAULT_LID_TYPE
;
1446 lid_type
= BROADCAST_LID_TYPE
;
1447 } else if (is_pairwise
) {
1448 lid_type
= UNICAST_LID_TYPE
;
1450 lid_type
= BROADCAST_LID_TYPE
;
1453 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1454 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1455 (int)key_type
, (int)hlid
);
1457 cmd
->lid_key_type
= lid_type
;
1459 cmd
->key_action
= cpu_to_le16(action
);
1460 cmd
->key_size
= key_size
;
1461 cmd
->key_type
= key_type
;
1463 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1464 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1466 if (key_type
== KEY_TKIP
) {
1468 * We get the key in the following form:
1469 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1470 * but the target is expecting:
1471 * TKIP - RX MIC - TX MIC
1473 memcpy(cmd
->key
, key
, 16);
1474 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1475 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1477 memcpy(cmd
->key
, key
, key_size
);
1480 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1482 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1484 wl1271_warning("could not set ap keys");
1493 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1496 struct wl12xx_cmd_set_peer_state
*cmd
;
1499 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1501 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1508 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1510 /* wmm param is valid only for station role */
1511 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1512 cmd
->wmm
= wlvif
->wmm_enabled
;
1514 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1516 wl1271_error("failed to send set peer state command");
1527 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1528 struct ieee80211_sta
*sta
, u8 hlid
)
1530 struct wl12xx_cmd_add_peer
*cmd
;
1534 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1536 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1542 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1543 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1544 cmd
->aid
= sta
->aid
;
1546 cmd
->sp_len
= sta
->max_sp
;
1547 cmd
->wmm
= sta
->wme
? 1 : 0;
1548 cmd
->session_id
= wl
->session_ids
[hlid
];
1549 cmd
->role_id
= wlvif
->role_id
;
1551 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1552 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1553 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1554 WL1271_PSD_UPSD_TRIGGER
;
1556 cmd
->psd_type
[NUM_ACCESS_CATEGORIES_COPY
-1-i
] =
1560 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1561 if (sta
->ht_cap
.ht_supported
)
1563 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
1564 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
1566 cmd
->supported_rates
=
1567 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1570 if (!cmd
->supported_rates
) {
1571 wl1271_debug(DEBUG_CMD
,
1572 "peer has no supported rates yet, configuring basic rates: 0x%x",
1573 wlvif
->basic_rate_set
);
1574 cmd
->supported_rates
= cpu_to_le32(wlvif
->basic_rate_set
);
1577 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1578 cmd
->supported_rates
, sta
->uapsd_queues
);
1580 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1582 wl1271_error("failed to initiate cmd add peer");
1593 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1596 struct wl12xx_cmd_remove_peer
*cmd
;
1598 bool timeout
= false;
1600 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1602 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1609 /* We never send a deauth, mac80211 is in charge of this */
1610 cmd
->reason_opcode
= 0;
1611 cmd
->send_deauth_flag
= 0;
1612 cmd
->role_id
= wlvif
->role_id
;
1614 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1616 wl1271_error("failed to initiate cmd remove peer");
1620 ret
= wl
->ops
->wait_for_event(wl
,
1621 WLCORE_EVENT_PEER_REMOVE_COMPLETE
,
1625 * We are ok with a timeout here. The event is sometimes not sent
1626 * due to a firmware bug. In case of another error (like SDIO timeout)
1630 wl12xx_queue_recovery_work(wl
);
1639 static int wlcore_get_reg_conf_ch_idx(enum nl80211_band band
, u16 ch
)
1642 * map the given band/channel to the respective predefined
1643 * bit expected by the fw
1646 case NL80211_BAND_2GHZ
:
1647 /* channels 1..14 are mapped to 0..13 */
1648 if (ch
>= 1 && ch
<= 14)
1651 case NL80211_BAND_5GHZ
:
1654 /* channels 8,12,16 are mapped to 18,19,20 */
1655 return 18 + (ch
-8)/4;
1657 /* channels 34,36..48 are mapped to 21..28 */
1658 return 21 + (ch
-34)/2;
1660 /* channels 52,56..64 are mapped to 29..32 */
1661 return 29 + (ch
-52)/4;
1663 /* channels 100,104..140 are mapped to 33..43 */
1664 return 33 + (ch
-100)/4;
1666 /* channels 149,153..165 are mapped to 44..48 */
1667 return 44 + (ch
-149)/4;
1676 wl1271_error("%s: unknown band/channel: %d/%d", __func__
, band
, ch
);
1680 void wlcore_set_pending_regdomain_ch(struct wl1271
*wl
, u16 channel
,
1681 enum nl80211_band band
)
1685 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1688 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(band
, channel
);
1690 if (ch_bit_idx
>= 0 && ch_bit_idx
<= WL1271_MAX_CHANNELS
)
1691 __set_bit_le(ch_bit_idx
, (long *)wl
->reg_ch_conf_pending
);
1694 int wlcore_cmd_regdomain_config_locked(struct wl1271
*wl
)
1696 struct wl12xx_cmd_regdomain_dfs_config
*cmd
= NULL
;
1697 int ret
= 0, i
, b
, ch_bit_idx
;
1698 __le32 tmp_ch_bitmap
[2] __aligned(sizeof(unsigned long));
1699 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1700 struct ieee80211_supported_band
*band
;
1701 bool timeout
= false;
1703 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
1706 wl1271_debug(DEBUG_CMD
, "cmd reg domain config");
1708 memcpy(tmp_ch_bitmap
, wl
->reg_ch_conf_pending
, sizeof(tmp_ch_bitmap
));
1710 for (b
= NL80211_BAND_2GHZ
; b
<= NL80211_BAND_5GHZ
; b
++) {
1711 band
= wiphy
->bands
[b
];
1712 for (i
= 0; i
< band
->n_channels
; i
++) {
1713 struct ieee80211_channel
*channel
= &band
->channels
[i
];
1714 u16 ch
= channel
->hw_value
;
1715 u32 flags
= channel
->flags
;
1717 if (flags
& (IEEE80211_CHAN_DISABLED
|
1718 IEEE80211_CHAN_NO_IR
))
1721 if ((flags
& IEEE80211_CHAN_RADAR
) &&
1722 channel
->dfs_state
!= NL80211_DFS_AVAILABLE
)
1725 ch_bit_idx
= wlcore_get_reg_conf_ch_idx(b
, ch
);
1729 __set_bit_le(ch_bit_idx
, (long *)tmp_ch_bitmap
);
1733 if (!memcmp(tmp_ch_bitmap
, wl
->reg_ch_conf_last
, sizeof(tmp_ch_bitmap
)))
1736 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1742 cmd
->ch_bit_map1
= tmp_ch_bitmap
[0];
1743 cmd
->ch_bit_map2
= tmp_ch_bitmap
[1];
1744 cmd
->dfs_region
= wl
->dfs_region
;
1746 wl1271_debug(DEBUG_CMD
,
1747 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x",
1748 cmd
->ch_bit_map1
, cmd
->ch_bit_map2
);
1750 ret
= wl1271_cmd_send(wl
, CMD_DFS_CHANNEL_CONFIG
, cmd
, sizeof(*cmd
), 0);
1752 wl1271_error("failed to send reg domain dfs config");
1756 ret
= wl
->ops
->wait_for_event(wl
,
1757 WLCORE_EVENT_DFS_CONFIG_COMPLETE
,
1759 if (ret
< 0 || timeout
) {
1760 wl1271_error("reg domain conf %serror",
1761 timeout
? "completion " : "");
1762 ret
= timeout
? -ETIMEDOUT
: ret
;
1766 memcpy(wl
->reg_ch_conf_last
, tmp_ch_bitmap
, sizeof(tmp_ch_bitmap
));
1767 memset(wl
->reg_ch_conf_pending
, 0, sizeof(wl
->reg_ch_conf_pending
));
1774 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1776 struct wl12xx_cmd_config_fwlog
*cmd
;
1779 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1781 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1787 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1788 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1789 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1790 cmd
->output
= wl
->conf
.fwlog
.output
;
1791 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1793 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1795 wl1271_error("failed to send config firmware logger command");
1806 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1808 struct wl12xx_cmd_start_fwlog
*cmd
;
1811 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1813 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1819 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1821 wl1271_error("failed to send start firmware logger command");
1832 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1834 struct wl12xx_cmd_stop_fwlog
*cmd
;
1837 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1839 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1845 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1847 wl1271_error("failed to send stop firmware logger command");
1858 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1859 u8 role_id
, enum nl80211_band band
, u8 channel
)
1861 struct wl12xx_cmd_roc
*cmd
;
1864 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", channel
, role_id
);
1866 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1869 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1875 cmd
->role_id
= role_id
;
1876 cmd
->channel
= channel
;
1878 case NL80211_BAND_2GHZ
:
1879 cmd
->band
= WLCORE_BAND_2_4GHZ
;
1881 case NL80211_BAND_5GHZ
:
1882 cmd
->band
= WLCORE_BAND_5GHZ
;
1885 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1891 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1893 wl1271_error("failed to send ROC command");
1904 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1906 struct wl12xx_cmd_croc
*cmd
;
1909 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1911 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1916 cmd
->role_id
= role_id
;
1918 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1921 wl1271_error("failed to send ROC command");
1932 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
,
1933 enum nl80211_band band
, u8 channel
)
1937 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1940 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
, band
, channel
);
1944 __set_bit(role_id
, wl
->roc_map
);
1949 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1953 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1956 ret
= wl12xx_cmd_croc(wl
, role_id
);
1960 __clear_bit(role_id
, wl
->roc_map
);
1963 * Rearm the tx watchdog when removing the last ROC. This prevents
1964 * recoveries due to just finished ROCs - when Tx hasn't yet had
1965 * a chance to get out.
1967 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
)
1968 wl12xx_rearm_tx_watchdog_locked(wl
);
1973 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1975 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1978 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1980 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1986 cmd
->role_id
= wlvif
->role_id
;
1988 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1990 wl1271_error("failed to stop channel switch command");
2001 /* start dev role and roc on its channel */
2002 int wl12xx_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2003 enum nl80211_band band
, int channel
)
2007 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2008 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2011 /* the dev role is already started for p2p mgmt interfaces */
2012 if (!wlcore_is_p2p_mgmt(wlvif
)) {
2013 ret
= wl12xx_cmd_role_enable(wl
,
2014 wl12xx_wlvif_to_vif(wlvif
)->addr
,
2016 &wlvif
->dev_role_id
);
2021 ret
= wl12xx_cmd_role_start_dev(wl
, wlvif
, band
, channel
);
2025 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->dev_role_id
, band
, channel
);
2032 wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2034 if (!wlcore_is_p2p_mgmt(wlvif
))
2035 wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2040 /* croc dev hlid, and stop the role */
2041 int wl12xx_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2045 if (WARN_ON(!(wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2046 wlvif
->bss_type
== BSS_TYPE_IBSS
)))
2049 /* flush all pending packets */
2050 ret
= wlcore_tx_work_locked(wl
);
2054 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
2055 ret
= wl12xx_croc(wl
, wlvif
->dev_role_id
);
2060 ret
= wl12xx_cmd_role_stop_dev(wl
, wlvif
);
2064 if (!wlcore_is_p2p_mgmt(wlvif
)) {
2065 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2074 int wlcore_cmd_generic_cfg(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2075 u8 feature
, u8 enable
, u8 value
)
2077 struct wlcore_cmd_generic_cfg
*cmd
;
2080 wl1271_debug(DEBUG_CMD
,
2081 "cmd generic cfg (role %d feature %d enable %d value %d)",
2082 wlvif
->role_id
, feature
, enable
, value
);
2084 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
2088 cmd
->role_id
= wlvif
->role_id
;
2089 cmd
->feature
= feature
;
2090 cmd
->enable
= enable
;
2093 ret
= wl1271_cmd_send(wl
, CMD_GENERIC_CFG
, cmd
, sizeof(*cmd
), 0);
2095 wl1271_error("failed to send generic cfg command");
2102 EXPORT_SYMBOL_GPL(wlcore_cmd_generic_cfg
);