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"
40 #define WL1271_CMD_FAST_POLL_COUNT 50
43 * send command to firmware
47 * @buf: buffer containing the command, must work with dma
48 * @len: length of the buffer
50 int wl1271_cmd_send(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
,
53 struct wl1271_cmd_header
*cmd
;
54 unsigned long timeout
;
61 cmd
->id
= cpu_to_le16(id
);
64 WARN_ON(len
% 4 != 0);
65 WARN_ON(test_bit(WL1271_FLAG_IN_ELP
, &wl
->flags
));
67 wl1271_write(wl
, wl
->cmd_box_addr
, buf
, len
, false);
69 wl1271_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_CMD
);
71 timeout
= jiffies
+ msecs_to_jiffies(WL1271_COMMAND_TIMEOUT
);
73 intr
= wl1271_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
74 while (!(intr
& WL1271_ACX_INTR_CMD_COMPLETE
)) {
75 if (time_after(jiffies
, timeout
)) {
76 wl1271_error("command complete timeout");
82 if (poll_count
< WL1271_CMD_FAST_POLL_COUNT
)
87 intr
= wl1271_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
90 /* read back the status code of the command */
92 res_len
= sizeof(struct wl1271_cmd_header
);
93 wl1271_read(wl
, wl
->cmd_box_addr
, cmd
, res_len
, false);
95 status
= le16_to_cpu(cmd
->status
);
96 if (status
!= CMD_STATUS_SUCCESS
) {
97 wl1271_error("command execute failure %d", status
);
102 wl1271_write32(wl
, ACX_REG_INTERRUPT_ACK
,
103 WL1271_ACX_INTR_CMD_COMPLETE
);
108 wl12xx_queue_recovery_work(wl
);
112 int wl1271_cmd_general_parms(struct wl1271
*wl
)
114 struct wl1271_general_parms_cmd
*gen_parms
;
115 struct wl1271_ini_general_params
*gp
=
116 &((struct wl1271_nvs_file
*)wl
->nvs
)->general_params
;
123 gen_parms
= kzalloc(sizeof(*gen_parms
), GFP_KERNEL
);
127 gen_parms
->test
.id
= TEST_CMD_INI_FILE_GENERAL_PARAM
;
129 memcpy(&gen_parms
->general_params
, gp
, sizeof(*gp
));
131 if (gp
->tx_bip_fem_auto_detect
)
134 /* Override the REF CLK from the NVS with the one from platform data */
135 gen_parms
->general_params
.ref_clock
= wl
->ref_clock
;
137 ret
= wl1271_cmd_test(wl
, gen_parms
, sizeof(*gen_parms
), answer
);
139 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
143 gp
->tx_bip_fem_manufacturer
=
144 gen_parms
->general_params
.tx_bip_fem_manufacturer
;
146 wl1271_debug(DEBUG_CMD
, "FEM autodetect: %s, manufacturer: %d\n",
147 answer
? "auto" : "manual", gp
->tx_bip_fem_manufacturer
);
154 int wl128x_cmd_general_parms(struct wl1271
*wl
)
156 struct wl128x_general_parms_cmd
*gen_parms
;
157 struct wl128x_ini_general_params
*gp
=
158 &((struct wl128x_nvs_file
*)wl
->nvs
)->general_params
;
165 gen_parms
= kzalloc(sizeof(*gen_parms
), GFP_KERNEL
);
169 gen_parms
->test
.id
= TEST_CMD_INI_FILE_GENERAL_PARAM
;
171 memcpy(&gen_parms
->general_params
, gp
, sizeof(*gp
));
173 if (gp
->tx_bip_fem_auto_detect
)
176 /* Replace REF and TCXO CLKs with the ones from platform data */
177 gen_parms
->general_params
.ref_clock
= wl
->ref_clock
;
178 gen_parms
->general_params
.tcxo_ref_clock
= wl
->tcxo_clock
;
180 ret
= wl1271_cmd_test(wl
, gen_parms
, sizeof(*gen_parms
), answer
);
182 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
186 gp
->tx_bip_fem_manufacturer
=
187 gen_parms
->general_params
.tx_bip_fem_manufacturer
;
189 wl1271_debug(DEBUG_CMD
, "FEM autodetect: %s, manufacturer: %d\n",
190 answer
? "auto" : "manual", gp
->tx_bip_fem_manufacturer
);
197 int wl1271_cmd_radio_parms(struct wl1271
*wl
)
199 struct wl1271_nvs_file
*nvs
= (struct wl1271_nvs_file
*)wl
->nvs
;
200 struct wl1271_radio_parms_cmd
*radio_parms
;
201 struct wl1271_ini_general_params
*gp
= &nvs
->general_params
;
207 radio_parms
= kzalloc(sizeof(*radio_parms
), GFP_KERNEL
);
211 radio_parms
->test
.id
= TEST_CMD_INI_FILE_RADIO_PARAM
;
213 /* 2.4GHz parameters */
214 memcpy(&radio_parms
->static_params_2
, &nvs
->stat_radio_params_2
,
215 sizeof(struct wl1271_ini_band_params_2
));
216 memcpy(&radio_parms
->dyn_params_2
,
217 &nvs
->dyn_radio_params_2
[gp
->tx_bip_fem_manufacturer
].params
,
218 sizeof(struct wl1271_ini_fem_params_2
));
220 /* 5GHz parameters */
221 memcpy(&radio_parms
->static_params_5
,
222 &nvs
->stat_radio_params_5
,
223 sizeof(struct wl1271_ini_band_params_5
));
224 memcpy(&radio_parms
->dyn_params_5
,
225 &nvs
->dyn_radio_params_5
[gp
->tx_bip_fem_manufacturer
].params
,
226 sizeof(struct wl1271_ini_fem_params_5
));
228 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
229 radio_parms
, sizeof(*radio_parms
));
231 ret
= wl1271_cmd_test(wl
, radio_parms
, sizeof(*radio_parms
), 0);
233 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
239 int wl128x_cmd_radio_parms(struct wl1271
*wl
)
241 struct wl128x_nvs_file
*nvs
= (struct wl128x_nvs_file
*)wl
->nvs
;
242 struct wl128x_radio_parms_cmd
*radio_parms
;
243 struct wl128x_ini_general_params
*gp
= &nvs
->general_params
;
249 radio_parms
= kzalloc(sizeof(*radio_parms
), GFP_KERNEL
);
253 radio_parms
->test
.id
= TEST_CMD_INI_FILE_RADIO_PARAM
;
255 /* 2.4GHz parameters */
256 memcpy(&radio_parms
->static_params_2
, &nvs
->stat_radio_params_2
,
257 sizeof(struct wl128x_ini_band_params_2
));
258 memcpy(&radio_parms
->dyn_params_2
,
259 &nvs
->dyn_radio_params_2
[gp
->tx_bip_fem_manufacturer
].params
,
260 sizeof(struct wl128x_ini_fem_params_2
));
262 /* 5GHz parameters */
263 memcpy(&radio_parms
->static_params_5
,
264 &nvs
->stat_radio_params_5
,
265 sizeof(struct wl128x_ini_band_params_5
));
266 memcpy(&radio_parms
->dyn_params_5
,
267 &nvs
->dyn_radio_params_5
[gp
->tx_bip_fem_manufacturer
].params
,
268 sizeof(struct wl128x_ini_fem_params_5
));
270 radio_parms
->fem_vendor_and_options
= nvs
->fem_vendor_and_options
;
272 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
273 radio_parms
, sizeof(*radio_parms
));
275 ret
= wl1271_cmd_test(wl
, radio_parms
, sizeof(*radio_parms
), 0);
277 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
283 int wl1271_cmd_ext_radio_parms(struct wl1271
*wl
)
285 struct wl1271_ext_radio_parms_cmd
*ext_radio_parms
;
286 struct conf_rf_settings
*rf
= &wl
->conf
.rf
;
292 ext_radio_parms
= kzalloc(sizeof(*ext_radio_parms
), GFP_KERNEL
);
293 if (!ext_radio_parms
)
296 ext_radio_parms
->test
.id
= TEST_CMD_INI_FILE_RF_EXTENDED_PARAM
;
298 memcpy(ext_radio_parms
->tx_per_channel_power_compensation_2
,
299 rf
->tx_per_channel_power_compensation_2
,
300 CONF_TX_PWR_COMPENSATION_LEN_2
);
301 memcpy(ext_radio_parms
->tx_per_channel_power_compensation_5
,
302 rf
->tx_per_channel_power_compensation_5
,
303 CONF_TX_PWR_COMPENSATION_LEN_5
);
305 wl1271_dump(DEBUG_CMD
, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
306 ext_radio_parms
, sizeof(*ext_radio_parms
));
308 ret
= wl1271_cmd_test(wl
, ext_radio_parms
, sizeof(*ext_radio_parms
), 0);
310 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
312 kfree(ext_radio_parms
);
317 * Poll the mailbox event field until any of the bits in the mask is set or a
318 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
320 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271
*wl
, u32 mask
)
322 u32 events_vector
, event
;
323 unsigned long timeout
;
325 timeout
= jiffies
+ msecs_to_jiffies(WL1271_EVENT_TIMEOUT
);
328 if (time_after(jiffies
, timeout
)) {
329 wl1271_debug(DEBUG_CMD
, "timeout waiting for event %d",
336 /* read from both event fields */
337 wl1271_read(wl
, wl
->mbox_ptr
[0], &events_vector
,
338 sizeof(events_vector
), false);
339 event
= events_vector
& mask
;
340 wl1271_read(wl
, wl
->mbox_ptr
[1], &events_vector
,
341 sizeof(events_vector
), false);
342 event
|= events_vector
& mask
;
348 static int wl1271_cmd_wait_for_event(struct wl1271
*wl
, u32 mask
)
352 ret
= wl1271_cmd_wait_for_event_or_timeout(wl
, mask
);
354 wl12xx_queue_recovery_work(wl
);
361 int wl12xx_cmd_role_enable(struct wl1271
*wl
, u8
*addr
, u8 role_type
,
364 struct wl12xx_cmd_role_enable
*cmd
;
367 wl1271_debug(DEBUG_CMD
, "cmd role enable");
369 if (WARN_ON(*role_id
!= WL12XX_INVALID_ROLE_ID
))
372 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
379 cmd
->role_id
= find_first_zero_bit(wl
->roles_map
, WL12XX_MAX_ROLES
);
380 if (cmd
->role_id
>= WL12XX_MAX_ROLES
) {
385 memcpy(cmd
->mac_address
, addr
, ETH_ALEN
);
386 cmd
->role_type
= role_type
;
388 ret
= wl1271_cmd_send(wl
, CMD_ROLE_ENABLE
, cmd
, sizeof(*cmd
), 0);
390 wl1271_error("failed to initiate cmd role enable");
394 __set_bit(cmd
->role_id
, wl
->roles_map
);
395 *role_id
= cmd
->role_id
;
404 int wl12xx_cmd_role_disable(struct wl1271
*wl
, u8
*role_id
)
406 struct wl12xx_cmd_role_disable
*cmd
;
409 wl1271_debug(DEBUG_CMD
, "cmd role disable");
411 if (WARN_ON(*role_id
== WL12XX_INVALID_ROLE_ID
))
414 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
419 cmd
->role_id
= *role_id
;
421 ret
= wl1271_cmd_send(wl
, CMD_ROLE_DISABLE
, cmd
, sizeof(*cmd
), 0);
423 wl1271_error("failed to initiate cmd role disable");
427 __clear_bit(*role_id
, wl
->roles_map
);
428 *role_id
= WL12XX_INVALID_ROLE_ID
;
437 int wl12xx_allocate_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
439 u8 link
= find_first_zero_bit(wl
->links_map
, WL12XX_MAX_LINKS
);
440 if (link
>= WL12XX_MAX_LINKS
)
443 __set_bit(link
, wl
->links_map
);
444 __set_bit(link
, wlvif
->links_map
);
449 void wl12xx_free_link(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8
*hlid
)
451 if (*hlid
== WL12XX_INVALID_LINK_ID
)
454 __clear_bit(*hlid
, wl
->links_map
);
455 __clear_bit(*hlid
, wlvif
->links_map
);
456 *hlid
= WL12XX_INVALID_LINK_ID
;
459 static int wl12xx_get_new_session_id(struct wl1271
*wl
,
460 struct wl12xx_vif
*wlvif
)
462 if (wlvif
->session_counter
>= SESSION_COUNTER_MAX
)
463 wlvif
->session_counter
= 0;
465 wlvif
->session_counter
++;
467 return wlvif
->session_counter
;
470 int wl12xx_cmd_role_start_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
472 struct wl12xx_cmd_role_start
*cmd
;
475 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
481 wl1271_debug(DEBUG_CMD
, "cmd role start dev %d", wlvif
->dev_role_id
);
483 cmd
->role_id
= wlvif
->dev_role_id
;
484 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
485 cmd
->band
= WL12XX_BAND_5GHZ
;
486 cmd
->channel
= wlvif
->channel
;
488 if (wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
) {
489 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->dev_hlid
);
493 cmd
->device
.hlid
= wlvif
->dev_hlid
;
494 cmd
->device
.session
= wlvif
->session_counter
;
496 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d",
497 cmd
->role_id
, cmd
->device
.hlid
, cmd
->device
.session
);
499 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
501 wl1271_error("failed to initiate cmd role enable");
508 /* clear links on error */
509 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
518 int wl12xx_cmd_role_stop_dev(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
520 struct wl12xx_cmd_role_stop
*cmd
;
523 if (WARN_ON(wlvif
->dev_hlid
== WL12XX_INVALID_LINK_ID
))
526 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
532 wl1271_debug(DEBUG_CMD
, "cmd role stop dev");
534 cmd
->role_id
= wlvif
->dev_role_id
;
535 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
536 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
538 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
540 wl1271_error("failed to initiate cmd role stop");
544 ret
= wl1271_cmd_wait_for_event(wl
, DISCONNECT_EVENT_COMPLETE_ID
);
546 wl1271_error("cmd role stop dev event completion error");
550 wl12xx_free_link(wl
, wlvif
, &wlvif
->dev_hlid
);
559 int wl12xx_cmd_role_start_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
561 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
562 struct wl12xx_cmd_role_start
*cmd
;
565 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
571 wl1271_debug(DEBUG_CMD
, "cmd role start sta %d", wlvif
->role_id
);
573 cmd
->role_id
= wlvif
->role_id
;
574 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
575 cmd
->band
= WL12XX_BAND_5GHZ
;
576 cmd
->channel
= wlvif
->channel
;
577 cmd
->sta
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
578 cmd
->sta
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
579 cmd
->sta
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
580 cmd
->sta
.ssid_len
= wlvif
->ssid_len
;
581 memcpy(cmd
->sta
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
582 memcpy(cmd
->sta
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
583 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
585 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
586 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
590 cmd
->sta
.hlid
= wlvif
->sta
.hlid
;
591 cmd
->sta
.session
= wl12xx_get_new_session_id(wl
, wlvif
);
592 cmd
->sta
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
594 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
595 "basic_rate_set: 0x%x, remote_rates: 0x%x",
596 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
597 wlvif
->basic_rate_set
, wlvif
->rate_set
);
599 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
601 wl1271_error("failed to initiate cmd role start sta");
608 /* clear links on error. */
609 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
618 /* use this function to stop ibss as well */
619 int wl12xx_cmd_role_stop_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
621 struct wl12xx_cmd_role_stop
*cmd
;
624 if (WARN_ON(wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
))
627 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
633 wl1271_debug(DEBUG_CMD
, "cmd role stop sta %d", wlvif
->role_id
);
635 cmd
->role_id
= wlvif
->role_id
;
636 cmd
->disc_type
= DISCONNECT_IMMEDIATE
;
637 cmd
->reason
= cpu_to_le16(WLAN_REASON_UNSPECIFIED
);
639 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
641 wl1271_error("failed to initiate cmd role stop sta");
645 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
654 int wl12xx_cmd_role_start_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
656 struct wl12xx_cmd_role_start
*cmd
;
657 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
658 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
661 wl1271_debug(DEBUG_CMD
, "cmd role start ap %d", wlvif
->role_id
);
663 /* trying to use hidden SSID with an old hostapd version */
664 if (wlvif
->ssid_len
== 0 && !bss_conf
->hidden_ssid
) {
665 wl1271_error("got a null SSID from beacon/bss");
670 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
676 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
680 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
682 goto out_free_global
;
684 cmd
->role_id
= wlvif
->role_id
;
685 cmd
->ap
.aging_period
= cpu_to_le16(wl
->conf
.tx
.ap_aging_period
);
686 cmd
->ap
.bss_index
= WL1271_AP_BSS_INDEX
;
687 cmd
->ap
.global_hlid
= wlvif
->ap
.global_hlid
;
688 cmd
->ap
.broadcast_hlid
= wlvif
->ap
.bcast_hlid
;
689 cmd
->ap
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
690 cmd
->ap
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
691 cmd
->ap
.dtim_interval
= bss_conf
->dtim_period
;
692 cmd
->ap
.beacon_expiry
= WL1271_AP_DEF_BEACON_EXP
;
693 cmd
->channel
= wlvif
->channel
;
695 if (!bss_conf
->hidden_ssid
) {
696 /* take the SSID from the beacon for backward compatibility */
697 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_PUBLIC
;
698 cmd
->ap
.ssid_len
= wlvif
->ssid_len
;
699 memcpy(cmd
->ap
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
701 cmd
->ap
.ssid_type
= WL12XX_SSID_TYPE_HIDDEN
;
702 cmd
->ap
.ssid_len
= bss_conf
->ssid_len
;
703 memcpy(cmd
->ap
.ssid
, bss_conf
->ssid
, bss_conf
->ssid_len
);
706 cmd
->ap
.local_rates
= cpu_to_le32(0xffffffff);
708 switch (wlvif
->band
) {
709 case IEEE80211_BAND_2GHZ
:
710 cmd
->band
= RADIO_BAND_2_4GHZ
;
712 case IEEE80211_BAND_5GHZ
:
713 cmd
->band
= RADIO_BAND_5GHZ
;
716 wl1271_warning("ap start - unknown band: %d", (int)wlvif
->band
);
717 cmd
->band
= RADIO_BAND_2_4GHZ
;
721 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
723 wl1271_error("failed to initiate cmd role start ap");
730 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
733 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
742 int wl12xx_cmd_role_stop_ap(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
744 struct wl12xx_cmd_role_stop
*cmd
;
747 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
753 wl1271_debug(DEBUG_CMD
, "cmd role stop ap %d", wlvif
->role_id
);
755 cmd
->role_id
= wlvif
->role_id
;
757 ret
= wl1271_cmd_send(wl
, CMD_ROLE_STOP
, cmd
, sizeof(*cmd
), 0);
759 wl1271_error("failed to initiate cmd role stop ap");
763 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.bcast_hlid
);
764 wl12xx_free_link(wl
, wlvif
, &wlvif
->ap
.global_hlid
);
773 int wl12xx_cmd_role_start_ibss(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
775 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
776 struct wl12xx_cmd_role_start
*cmd
;
777 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
780 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
786 wl1271_debug(DEBUG_CMD
, "cmd role start ibss %d", wlvif
->role_id
);
788 cmd
->role_id
= wlvif
->role_id
;
789 if (wlvif
->band
== IEEE80211_BAND_5GHZ
)
790 cmd
->band
= WL12XX_BAND_5GHZ
;
791 cmd
->channel
= wlvif
->channel
;
792 cmd
->ibss
.basic_rate_set
= cpu_to_le32(wlvif
->basic_rate_set
);
793 cmd
->ibss
.beacon_interval
= cpu_to_le16(wlvif
->beacon_int
);
794 cmd
->ibss
.dtim_interval
= bss_conf
->dtim_period
;
795 cmd
->ibss
.ssid_type
= WL12XX_SSID_TYPE_ANY
;
796 cmd
->ibss
.ssid_len
= wlvif
->ssid_len
;
797 memcpy(cmd
->ibss
.ssid
, wlvif
->ssid
, wlvif
->ssid_len
);
798 memcpy(cmd
->ibss
.bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
799 cmd
->sta
.local_rates
= cpu_to_le32(wlvif
->rate_set
);
801 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
) {
802 ret
= wl12xx_allocate_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
806 cmd
->ibss
.hlid
= wlvif
->sta
.hlid
;
807 cmd
->ibss
.remote_rates
= cpu_to_le32(wlvif
->rate_set
);
809 wl1271_debug(DEBUG_CMD
, "role start: roleid=%d, hlid=%d, session=%d "
810 "basic_rate_set: 0x%x, remote_rates: 0x%x",
811 wlvif
->role_id
, cmd
->sta
.hlid
, cmd
->sta
.session
,
812 wlvif
->basic_rate_set
, wlvif
->rate_set
);
814 wl1271_debug(DEBUG_CMD
, "vif->bss_conf.bssid = %pM",
815 vif
->bss_conf
.bssid
);
817 ret
= wl1271_cmd_send(wl
, CMD_ROLE_START
, cmd
, sizeof(*cmd
), 0);
819 wl1271_error("failed to initiate cmd role enable");
826 /* clear links on error. */
827 wl12xx_free_link(wl
, wlvif
, &wlvif
->sta
.hlid
);
838 * send test command to firmware
841 * @buf: buffer containing the command, with all headers, must work with dma
842 * @len: length of the buffer
843 * @answer: is answer needed
845 int wl1271_cmd_test(struct wl1271
*wl
, void *buf
, size_t buf_len
, u8 answer
)
850 wl1271_debug(DEBUG_CMD
, "cmd test");
855 ret
= wl1271_cmd_send(wl
, CMD_TEST
, buf
, buf_len
, res_len
);
858 wl1271_warning("TEST command failed");
866 * read acx from firmware
870 * @buf: buffer for the response, including all headers, must work with dma
871 * @len: length of buf
873 int wl1271_cmd_interrogate(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
875 struct acx_header
*acx
= buf
;
878 wl1271_debug(DEBUG_CMD
, "cmd interrogate");
880 acx
->id
= cpu_to_le16(id
);
882 /* payload length, does not include any headers */
883 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
885 ret
= wl1271_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
), len
);
887 wl1271_error("INTERROGATE command failed");
893 * write acx value to firmware
897 * @buf: buffer containing acx, including all headers, must work with dma
898 * @len: length of buf
900 int wl1271_cmd_configure(struct wl1271
*wl
, u16 id
, void *buf
, size_t len
)
902 struct acx_header
*acx
= buf
;
905 wl1271_debug(DEBUG_CMD
, "cmd configure (%d)", id
);
907 acx
->id
= cpu_to_le16(id
);
909 /* payload length, does not include any headers */
910 acx
->len
= cpu_to_le16(len
- sizeof(*acx
));
912 ret
= wl1271_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
, 0);
914 wl1271_warning("CONFIGURE command NOK");
921 int wl1271_cmd_data_path(struct wl1271
*wl
, bool enable
)
923 struct cmd_enabledisable_path
*cmd
;
927 wl1271_debug(DEBUG_CMD
, "cmd data path");
929 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
935 /* the channel here is only used for calibration, so hardcoded to 1 */
939 cmd_rx
= CMD_ENABLE_RX
;
940 cmd_tx
= CMD_ENABLE_TX
;
942 cmd_rx
= CMD_DISABLE_RX
;
943 cmd_tx
= CMD_DISABLE_TX
;
946 ret
= wl1271_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
), 0);
948 wl1271_error("rx %s cmd for channel %d failed",
949 enable
? "start" : "stop", cmd
->channel
);
953 wl1271_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
954 enable
? "start" : "stop", cmd
->channel
);
956 ret
= wl1271_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
), 0);
958 wl1271_error("tx %s cmd for channel %d failed",
959 enable
? "start" : "stop", cmd
->channel
);
963 wl1271_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
964 enable
? "start" : "stop", cmd
->channel
);
971 int wl1271_cmd_ps_mode(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
974 struct wl1271_cmd_ps_params
*ps_params
= NULL
;
977 wl1271_debug(DEBUG_CMD
, "cmd set ps mode");
979 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
985 ps_params
->role_id
= wlvif
->role_id
;
986 ps_params
->ps_mode
= ps_mode
;
988 ret
= wl1271_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
989 sizeof(*ps_params
), 0);
991 wl1271_error("cmd set_ps_mode failed");
1000 int wl1271_cmd_template_set(struct wl1271
*wl
, u16 template_id
,
1001 void *buf
, size_t buf_len
, int index
, u32 rates
)
1003 struct wl1271_cmd_template_set
*cmd
;
1006 wl1271_debug(DEBUG_CMD
, "cmd template_set %d", template_id
);
1008 WARN_ON(buf_len
> WL1271_CMD_TEMPL_MAX_SIZE
);
1009 buf_len
= min_t(size_t, buf_len
, WL1271_CMD_TEMPL_MAX_SIZE
);
1011 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1017 cmd
->len
= cpu_to_le16(buf_len
);
1018 cmd
->template_type
= template_id
;
1019 cmd
->enabled_rates
= cpu_to_le32(rates
);
1020 cmd
->short_retry_limit
= wl
->conf
.tx
.tmpl_short_retry_limit
;
1021 cmd
->long_retry_limit
= wl
->conf
.tx
.tmpl_long_retry_limit
;
1025 memcpy(cmd
->template_data
, buf
, buf_len
);
1027 ret
= wl1271_cmd_send(wl
, CMD_SET_TEMPLATE
, cmd
, sizeof(*cmd
), 0);
1029 wl1271_warning("cmd set_template failed: %d", ret
);
1040 int wl12xx_cmd_build_null_data(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1042 struct sk_buff
*skb
= NULL
;
1048 if (wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1049 size
= sizeof(struct wl12xx_null_data_template
);
1052 skb
= ieee80211_nullfunc_get(wl
->hw
,
1053 wl12xx_wlvif_to_vif(wlvif
));
1060 ret
= wl1271_cmd_template_set(wl
, 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
, CMD_TEMPL_KLV
,
1084 skb
->data
, skb
->len
,
1085 CMD_TEMPL_KLV_IDX_NULL_DATA
,
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
, CMD_TEMPL_PS_POLL
, skb
->data
,
1109 skb
->len
, 0, wlvif
->basic_rate_set
);
1116 int wl1271_cmd_build_probe_req(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1117 const u8
*ssid
, size_t ssid_len
,
1118 const u8
*ie
, size_t ie_len
, u8 band
)
1120 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1121 struct sk_buff
*skb
;
1125 skb
= ieee80211_probereq_get(wl
->hw
, vif
, ssid
, ssid_len
,
1132 wl1271_dump(DEBUG_SCAN
, "PROBE REQ: ", skb
->data
, skb
->len
);
1134 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[band
]);
1135 if (band
== IEEE80211_BAND_2GHZ
)
1136 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1137 skb
->data
, skb
->len
, 0, rate
);
1139 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
1140 skb
->data
, skb
->len
, 0, rate
);
1147 struct sk_buff
*wl1271_cmd_build_ap_probe_req(struct wl1271
*wl
,
1148 struct wl12xx_vif
*wlvif
,
1149 struct sk_buff
*skb
)
1151 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1156 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
1160 wl1271_dump(DEBUG_SCAN
, "AP PROBE REQ: ", skb
->data
, skb
->len
);
1162 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->bitrate_masks
[wlvif
->band
]);
1163 if (wlvif
->band
== IEEE80211_BAND_2GHZ
)
1164 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_2_4
,
1165 skb
->data
, skb
->len
, 0, rate
);
1167 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_CFG_PROBE_REQ_5
,
1168 skb
->data
, skb
->len
, 0, rate
);
1171 wl1271_error("Unable to set ap probe request template.");
1177 int wl1271_cmd_build_arp_rsp(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1181 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
1182 struct wl12xx_arp_rsp_template tmpl
;
1183 struct ieee80211_hdr_3addr
*hdr
;
1184 struct arphdr
*arp_hdr
;
1186 memset(&tmpl
, 0, sizeof(tmpl
));
1188 /* mac80211 header */
1190 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1191 IEEE80211_STYPE_DATA
|
1192 IEEE80211_FCTL_TODS
);
1193 memcpy(hdr
->addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1194 memcpy(hdr
->addr2
, vif
->addr
, ETH_ALEN
);
1195 memset(hdr
->addr3
, 0xff, ETH_ALEN
);
1198 memcpy(tmpl
.llc_hdr
, rfc1042_header
, sizeof(rfc1042_header
));
1199 tmpl
.llc_type
= cpu_to_be16(ETH_P_ARP
);
1202 arp_hdr
= &tmpl
.arp_hdr
;
1203 arp_hdr
->ar_hrd
= cpu_to_be16(ARPHRD_ETHER
);
1204 arp_hdr
->ar_pro
= cpu_to_be16(ETH_P_IP
);
1205 arp_hdr
->ar_hln
= ETH_ALEN
;
1206 arp_hdr
->ar_pln
= 4;
1207 arp_hdr
->ar_op
= cpu_to_be16(ARPOP_REPLY
);
1210 memcpy(tmpl
.sender_hw
, vif
->addr
, ETH_ALEN
);
1211 tmpl
.sender_ip
= ip_addr
;
1213 ret
= wl1271_cmd_template_set(wl
, CMD_TEMPL_ARP_RSP
,
1214 &tmpl
, sizeof(tmpl
), 0,
1220 int wl1271_build_qos_null_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1222 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1223 struct ieee80211_qos_hdr
template;
1225 memset(&template, 0, sizeof(template));
1227 memcpy(template.addr1
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1228 memcpy(template.addr2
, vif
->addr
, ETH_ALEN
);
1229 memcpy(template.addr3
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1231 template.frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1232 IEEE80211_STYPE_QOS_NULLFUNC
|
1233 IEEE80211_FCTL_TODS
);
1235 /* FIXME: not sure what priority to use here */
1236 template.qos_ctrl
= cpu_to_le16(0);
1238 return wl1271_cmd_template_set(wl
, CMD_TEMPL_QOS_NULL_DATA
, &template,
1239 sizeof(template), 0,
1243 int wl12xx_cmd_set_default_wep_key(struct wl1271
*wl
, u8 id
, u8 hlid
)
1245 struct wl1271_cmd_set_keys
*cmd
;
1248 wl1271_debug(DEBUG_CMD
, "cmd set_default_wep_key %d", id
);
1250 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1258 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1259 cmd
->key_action
= cpu_to_le16(KEY_SET_ID
);
1260 cmd
->key_type
= KEY_WEP
;
1262 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1264 wl1271_warning("cmd set_default_wep_key failed: %d", ret
);
1274 int wl1271_cmd_set_sta_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1275 u16 action
, u8 id
, u8 key_type
,
1276 u8 key_size
, const u8
*key
, const u8
*addr
,
1277 u32 tx_seq_32
, u16 tx_seq_16
)
1279 struct wl1271_cmd_set_keys
*cmd
;
1282 /* hlid might have already been deleted */
1283 if (wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
1286 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1292 cmd
->hlid
= wlvif
->sta
.hlid
;
1294 if (key_type
== KEY_WEP
)
1295 cmd
->lid_key_type
= WEP_DEFAULT_LID_TYPE
;
1296 else if (is_broadcast_ether_addr(addr
))
1297 cmd
->lid_key_type
= BROADCAST_LID_TYPE
;
1299 cmd
->lid_key_type
= UNICAST_LID_TYPE
;
1301 cmd
->key_action
= cpu_to_le16(action
);
1302 cmd
->key_size
= key_size
;
1303 cmd
->key_type
= key_type
;
1305 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1306 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1310 if (key_type
== KEY_TKIP
) {
1312 * We get the key in the following form:
1313 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1314 * but the target is expecting:
1315 * TKIP - RX MIC - TX MIC
1317 memcpy(cmd
->key
, key
, 16);
1318 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1319 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1322 memcpy(cmd
->key
, key
, key_size
);
1325 wl1271_dump(DEBUG_CRYPT
, "TARGET KEY: ", cmd
, sizeof(*cmd
));
1327 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1329 wl1271_warning("could not set keys");
1340 * TODO: merge with sta/ibss into 1 set_key function.
1341 * note there are slight diffs
1343 int wl1271_cmd_set_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1344 u16 action
, u8 id
, u8 key_type
,
1345 u8 key_size
, const u8
*key
, u8 hlid
, u32 tx_seq_32
,
1348 struct wl1271_cmd_set_keys
*cmd
;
1352 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1356 if (hlid
== wlvif
->ap
.bcast_hlid
) {
1357 if (key_type
== KEY_WEP
)
1358 lid_type
= WEP_DEFAULT_LID_TYPE
;
1360 lid_type
= BROADCAST_LID_TYPE
;
1362 lid_type
= UNICAST_LID_TYPE
;
1365 wl1271_debug(DEBUG_CRYPT
, "ap key action: %d id: %d lid: %d type: %d"
1366 " hlid: %d", (int)action
, (int)id
, (int)lid_type
,
1367 (int)key_type
, (int)hlid
);
1369 cmd
->lid_key_type
= lid_type
;
1371 cmd
->key_action
= cpu_to_le16(action
);
1372 cmd
->key_size
= key_size
;
1373 cmd
->key_type
= key_type
;
1375 cmd
->ac_seq_num16
[0] = cpu_to_le16(tx_seq_16
);
1376 cmd
->ac_seq_num32
[0] = cpu_to_le32(tx_seq_32
);
1378 if (key_type
== KEY_TKIP
) {
1380 * We get the key in the following form:
1381 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1382 * but the target is expecting:
1383 * TKIP - RX MIC - TX MIC
1385 memcpy(cmd
->key
, key
, 16);
1386 memcpy(cmd
->key
+ 16, key
+ 24, 8);
1387 memcpy(cmd
->key
+ 24, key
+ 16, 8);
1389 memcpy(cmd
->key
, key
, key_size
);
1392 wl1271_dump(DEBUG_CRYPT
, "TARGET AP KEY: ", cmd
, sizeof(*cmd
));
1394 ret
= wl1271_cmd_send(wl
, CMD_SET_KEYS
, cmd
, sizeof(*cmd
), 0);
1396 wl1271_warning("could not set ap keys");
1405 int wl12xx_cmd_set_peer_state(struct wl1271
*wl
, u8 hlid
)
1407 struct wl12xx_cmd_set_peer_state
*cmd
;
1410 wl1271_debug(DEBUG_CMD
, "cmd set peer state (hlid=%d)", hlid
);
1412 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1419 cmd
->state
= WL1271_CMD_STA_STATE_CONNECTED
;
1421 ret
= wl1271_cmd_send(wl
, CMD_SET_PEER_STATE
, cmd
, sizeof(*cmd
), 0);
1423 wl1271_error("failed to send set peer state command");
1434 int wl12xx_cmd_add_peer(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1435 struct ieee80211_sta
*sta
, u8 hlid
)
1437 struct wl12xx_cmd_add_peer
*cmd
;
1441 wl1271_debug(DEBUG_CMD
, "cmd add peer %d", (int)hlid
);
1443 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1449 memcpy(cmd
->addr
, sta
->addr
, ETH_ALEN
);
1450 cmd
->bss_index
= WL1271_AP_BSS_INDEX
;
1451 cmd
->aid
= sta
->aid
;
1453 cmd
->sp_len
= sta
->max_sp
;
1454 cmd
->wmm
= sta
->wme
? 1 : 0;
1456 for (i
= 0; i
< NUM_ACCESS_CATEGORIES_COPY
; i
++)
1457 if (sta
->wme
&& (sta
->uapsd_queues
& BIT(i
)))
1458 cmd
->psd_type
[i
] = WL1271_PSD_UPSD_TRIGGER
;
1460 cmd
->psd_type
[i
] = WL1271_PSD_LEGACY
;
1462 sta_rates
= sta
->supp_rates
[wlvif
->band
];
1463 if (sta
->ht_cap
.ht_supported
)
1464 sta_rates
|= sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
;
1466 cmd
->supported_rates
=
1467 cpu_to_le32(wl1271_tx_enabled_rates_get(wl
, sta_rates
,
1470 wl1271_debug(DEBUG_CMD
, "new peer rates=0x%x queues=0x%x",
1471 cmd
->supported_rates
, sta
->uapsd_queues
);
1473 ret
= wl1271_cmd_send(wl
, CMD_ADD_PEER
, cmd
, sizeof(*cmd
), 0);
1475 wl1271_error("failed to initiate cmd add peer");
1486 int wl12xx_cmd_remove_peer(struct wl1271
*wl
, u8 hlid
)
1488 struct wl12xx_cmd_remove_peer
*cmd
;
1491 wl1271_debug(DEBUG_CMD
, "cmd remove peer %d", (int)hlid
);
1493 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1500 /* We never send a deauth, mac80211 is in charge of this */
1501 cmd
->reason_opcode
= 0;
1502 cmd
->send_deauth_flag
= 0;
1504 ret
= wl1271_cmd_send(wl
, CMD_REMOVE_PEER
, cmd
, sizeof(*cmd
), 0);
1506 wl1271_error("failed to initiate cmd remove peer");
1511 * We are ok with a timeout here. The event is sometimes not sent
1512 * due to a firmware bug.
1514 wl1271_cmd_wait_for_event_or_timeout(wl
,
1515 PEER_REMOVE_COMPLETE_EVENT_ID
);
1524 int wl12xx_cmd_config_fwlog(struct wl1271
*wl
)
1526 struct wl12xx_cmd_config_fwlog
*cmd
;
1529 wl1271_debug(DEBUG_CMD
, "cmd config firmware logger");
1531 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1537 cmd
->logger_mode
= wl
->conf
.fwlog
.mode
;
1538 cmd
->log_severity
= wl
->conf
.fwlog
.severity
;
1539 cmd
->timestamp
= wl
->conf
.fwlog
.timestamp
;
1540 cmd
->output
= wl
->conf
.fwlog
.output
;
1541 cmd
->threshold
= wl
->conf
.fwlog
.threshold
;
1543 ret
= wl1271_cmd_send(wl
, CMD_CONFIG_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1545 wl1271_error("failed to send config firmware logger command");
1556 int wl12xx_cmd_start_fwlog(struct wl1271
*wl
)
1558 struct wl12xx_cmd_start_fwlog
*cmd
;
1561 wl1271_debug(DEBUG_CMD
, "cmd start firmware logger");
1563 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1569 ret
= wl1271_cmd_send(wl
, CMD_START_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1571 wl1271_error("failed to send start firmware logger command");
1582 int wl12xx_cmd_stop_fwlog(struct wl1271
*wl
)
1584 struct wl12xx_cmd_stop_fwlog
*cmd
;
1587 wl1271_debug(DEBUG_CMD
, "cmd stop firmware logger");
1589 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1595 ret
= wl1271_cmd_send(wl
, CMD_STOP_FWLOGGER
, cmd
, sizeof(*cmd
), 0);
1597 wl1271_error("failed to send stop firmware logger command");
1608 static int wl12xx_cmd_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
1611 struct wl12xx_cmd_roc
*cmd
;
1614 wl1271_debug(DEBUG_CMD
, "cmd roc %d (%d)", wlvif
->channel
, role_id
);
1616 if (WARN_ON(role_id
== WL12XX_INVALID_ROLE_ID
))
1619 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1625 cmd
->role_id
= role_id
;
1626 cmd
->channel
= wlvif
->channel
;
1627 switch (wlvif
->band
) {
1628 case IEEE80211_BAND_2GHZ
:
1629 cmd
->band
= RADIO_BAND_2_4GHZ
;
1631 case IEEE80211_BAND_5GHZ
:
1632 cmd
->band
= RADIO_BAND_5GHZ
;
1635 wl1271_error("roc - unknown band: %d", (int)wlvif
->band
);
1641 ret
= wl1271_cmd_send(wl
, CMD_REMAIN_ON_CHANNEL
, cmd
, sizeof(*cmd
), 0);
1643 wl1271_error("failed to send ROC command");
1654 static int wl12xx_cmd_croc(struct wl1271
*wl
, u8 role_id
)
1656 struct wl12xx_cmd_croc
*cmd
;
1659 wl1271_debug(DEBUG_CMD
, "cmd croc (%d)", role_id
);
1661 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1666 cmd
->role_id
= role_id
;
1668 ret
= wl1271_cmd_send(wl
, CMD_CANCEL_REMAIN_ON_CHANNEL
, cmd
,
1671 wl1271_error("failed to send ROC command");
1682 int wl12xx_roc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 role_id
)
1686 if (WARN_ON(test_bit(role_id
, wl
->roc_map
)))
1689 ret
= wl12xx_cmd_roc(wl
, wlvif
, role_id
);
1693 ret
= wl1271_cmd_wait_for_event(wl
,
1694 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID
);
1696 wl1271_error("cmd roc event completion error");
1700 __set_bit(role_id
, wl
->roc_map
);
1705 int wl12xx_croc(struct wl1271
*wl
, u8 role_id
)
1709 if (WARN_ON(!test_bit(role_id
, wl
->roc_map
)))
1712 ret
= wl12xx_cmd_croc(wl
, role_id
);
1716 __clear_bit(role_id
, wl
->roc_map
);
1721 int wl12xx_cmd_channel_switch(struct wl1271
*wl
,
1722 struct ieee80211_channel_switch
*ch_switch
)
1724 struct wl12xx_cmd_channel_switch
*cmd
;
1727 wl1271_debug(DEBUG_ACX
, "cmd channel switch");
1729 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1735 cmd
->channel
= ch_switch
->channel
->hw_value
;
1736 cmd
->switch_time
= ch_switch
->count
;
1737 cmd
->tx_suspend
= ch_switch
->block_tx
;
1738 cmd
->flush
= 0; /* this value is ignored by the FW */
1740 ret
= wl1271_cmd_send(wl
, CMD_CHANNEL_SWITCH
, cmd
, sizeof(*cmd
), 0);
1742 wl1271_error("failed to send channel switch command");
1753 int wl12xx_cmd_stop_channel_switch(struct wl1271
*wl
)
1755 struct wl12xx_cmd_stop_channel_switch
*cmd
;
1758 wl1271_debug(DEBUG_ACX
, "cmd stop channel switch");
1760 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
1766 ret
= wl1271_cmd_send(wl
, CMD_STOP_CHANNEL_SWICTH
, cmd
, sizeof(*cmd
), 0);
1768 wl1271_error("failed to stop channel switch command");