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>
36 #include "wl12xx_80211.h"
41 #define WL1271_CMD_FAST_POLL_COUNT 50
44 * send command to firmware
48 * @buf: buffer containing the command, must work with dma
49 * @len: length of the buffer
51 int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
54 struct wl1271_cmd_header *cmd;
55 unsigned long timeout;
62 cmd->id = cpu_to_le16(id);
65 WARN_ON(len % 4 != 0);
66 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
68 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
70 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
72 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
74 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
75 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
76 if (time_after(jiffies, timeout)) {
77 wl1271_error("command complete timeout");
83 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
88 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
91 /* read back the status code of the command */
93 res_len = sizeof(struct wl1271_cmd_header);
94 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
96 status = le16_to_cpu(cmd->status);
97 if (status != CMD_STATUS_SUCCESS) {
98 wl1271_error("command execute failure %d", status);
103 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
104 WL1271_ACX_INTR_CMD_COMPLETE);
109 wl12xx_queue_recovery_work(wl);
113 int wl1271_cmd_general_parms(struct wl1271 *wl)
115 struct wl1271_general_parms_cmd *gen_parms;
116 struct wl1271_ini_general_params *gp =
117 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
124 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
125 wl1271_warning("FEM index from INI out of bounds");
129 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
133 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
135 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
137 if (gp->tx_bip_fem_auto_detect)
140 /* Override the REF CLK from the NVS with the one from platform data */
141 gen_parms->general_params.ref_clock = wl->ref_clock;
143 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
145 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
149 gp->tx_bip_fem_manufacturer =
150 gen_parms->general_params.tx_bip_fem_manufacturer;
152 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
153 wl1271_warning("FEM index from FW out of bounds");
158 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
159 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
166 int wl128x_cmd_general_parms(struct wl1271 *wl)
168 struct wl128x_general_parms_cmd *gen_parms;
169 struct wl128x_ini_general_params *gp =
170 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
177 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
178 wl1271_warning("FEM index from ini out of bounds");
182 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
186 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
188 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
190 if (gp->tx_bip_fem_auto_detect)
193 /* Replace REF and TCXO CLKs with the ones from platform data */
194 gen_parms->general_params.ref_clock = wl->ref_clock;
195 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
197 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
199 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
203 gp->tx_bip_fem_manufacturer =
204 gen_parms->general_params.tx_bip_fem_manufacturer;
206 if (gp->tx_bip_fem_manufacturer >= WL1271_INI_FEM_MODULE_COUNT) {
207 wl1271_warning("FEM index from FW out of bounds");
212 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
213 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
220 int wl1271_cmd_radio_parms(struct wl1271 *wl)
222 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
223 struct wl1271_radio_parms_cmd *radio_parms;
224 struct wl1271_ini_general_params *gp = &nvs->general_params;
230 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
234 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
236 /* 2.4GHz parameters */
237 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
238 sizeof(struct wl1271_ini_band_params_2));
239 memcpy(&radio_parms->dyn_params_2,
240 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
241 sizeof(struct wl1271_ini_fem_params_2));
243 /* 5GHz parameters */
244 memcpy(&radio_parms->static_params_5,
245 &nvs->stat_radio_params_5,
246 sizeof(struct wl1271_ini_band_params_5));
247 memcpy(&radio_parms->dyn_params_5,
248 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
249 sizeof(struct wl1271_ini_fem_params_5));
251 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
252 radio_parms, sizeof(*radio_parms));
254 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
256 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
262 int wl128x_cmd_radio_parms(struct wl1271 *wl)
264 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
265 struct wl128x_radio_parms_cmd *radio_parms;
266 struct wl128x_ini_general_params *gp = &nvs->general_params;
272 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
276 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
278 /* 2.4GHz parameters */
279 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
280 sizeof(struct wl128x_ini_band_params_2));
281 memcpy(&radio_parms->dyn_params_2,
282 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
283 sizeof(struct wl128x_ini_fem_params_2));
285 /* 5GHz parameters */
286 memcpy(&radio_parms->static_params_5,
287 &nvs->stat_radio_params_5,
288 sizeof(struct wl128x_ini_band_params_5));
289 memcpy(&radio_parms->dyn_params_5,
290 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
291 sizeof(struct wl128x_ini_fem_params_5));
293 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
295 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
296 radio_parms, sizeof(*radio_parms));
298 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
300 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
306 int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
308 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
309 struct conf_rf_settings *rf = &wl->conf.rf;
315 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
316 if (!ext_radio_parms)
319 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
321 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
322 rf->tx_per_channel_power_compensation_2,
323 CONF_TX_PWR_COMPENSATION_LEN_2);
324 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
325 rf->tx_per_channel_power_compensation_5,
326 CONF_TX_PWR_COMPENSATION_LEN_5);
328 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
329 ext_radio_parms, sizeof(*ext_radio_parms));
331 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
333 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
335 kfree(ext_radio_parms);
340 * Poll the mailbox event field until any of the bits in the mask is set or a
341 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
343 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
345 u32 events_vector, event;
346 unsigned long timeout;
348 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
351 if (time_after(jiffies, timeout)) {
352 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
359 /* read from both event fields */
360 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
361 sizeof(events_vector), false);
362 event = events_vector & mask;
363 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
364 sizeof(events_vector), false);
365 event |= events_vector & mask;
371 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
375 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
377 wl12xx_queue_recovery_work(wl);
384 int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
387 struct wl12xx_cmd_role_enable *cmd;
390 wl1271_debug(DEBUG_CMD, "cmd role enable");
392 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
395 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
402 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
403 if (cmd->role_id >= WL12XX_MAX_ROLES) {
408 memcpy(cmd->mac_address, addr, ETH_ALEN);
409 cmd->role_type = role_type;
411 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
413 wl1271_error("failed to initiate cmd role enable");
417 __set_bit(cmd->role_id, wl->roles_map);
418 *role_id = cmd->role_id;
427 int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
429 struct wl12xx_cmd_role_disable *cmd;
432 wl1271_debug(DEBUG_CMD, "cmd role disable");
434 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
437 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
442 cmd->role_id = *role_id;
444 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
446 wl1271_error("failed to initiate cmd role disable");
450 __clear_bit(*role_id, wl->roles_map);
451 *role_id = WL12XX_INVALID_ROLE_ID;
460 int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
462 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
463 if (link >= WL12XX_MAX_LINKS)
466 __set_bit(link, wl->links_map);
467 __set_bit(link, wlvif->links_map);
472 void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
474 if (*hlid == WL12XX_INVALID_LINK_ID)
477 __clear_bit(*hlid, wl->links_map);
478 __clear_bit(*hlid, wlvif->links_map);
479 *hlid = WL12XX_INVALID_LINK_ID;
482 static int wl12xx_get_new_session_id(struct wl1271 *wl,
483 struct wl12xx_vif *wlvif)
485 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
486 wlvif->session_counter = 0;
488 wlvif->session_counter++;
490 return wlvif->session_counter;
493 static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
494 struct wl12xx_vif *wlvif)
496 struct wl12xx_cmd_role_start *cmd;
499 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
505 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
507 cmd->role_id = wlvif->dev_role_id;
508 if (wlvif->band == IEEE80211_BAND_5GHZ)
509 cmd->band = WL12XX_BAND_5GHZ;
510 cmd->channel = wlvif->channel;
512 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
513 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
517 cmd->device.hlid = wlvif->dev_hlid;
518 cmd->device.session = wlvif->session_counter;
520 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
521 cmd->role_id, cmd->device.hlid, cmd->device.session);
523 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
525 wl1271_error("failed to initiate cmd role enable");
532 /* clear links on error */
533 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
542 static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
543 struct wl12xx_vif *wlvif)
545 struct wl12xx_cmd_role_stop *cmd;
548 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
551 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
557 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
559 cmd->role_id = wlvif->dev_role_id;
560 cmd->disc_type = DISCONNECT_IMMEDIATE;
561 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
563 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
565 wl1271_error("failed to initiate cmd role stop");
569 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
571 wl1271_error("cmd role stop dev event completion error");
575 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
584 int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
586 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
587 struct wl12xx_cmd_role_start *cmd;
590 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
596 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
598 cmd->role_id = wlvif->role_id;
599 if (wlvif->band == IEEE80211_BAND_5GHZ)
600 cmd->band = WL12XX_BAND_5GHZ;
601 cmd->channel = wlvif->channel;
602 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
603 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
604 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
605 cmd->sta.ssid_len = wlvif->ssid_len;
606 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
607 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
608 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
610 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
611 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
615 cmd->sta.hlid = wlvif->sta.hlid;
616 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
617 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
619 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
620 "basic_rate_set: 0x%x, remote_rates: 0x%x",
621 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
622 wlvif->basic_rate_set, wlvif->rate_set);
624 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
626 wl1271_error("failed to initiate cmd role start sta");
633 /* clear links on error. */
634 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
643 /* use this function to stop ibss as well */
644 int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
646 struct wl12xx_cmd_role_stop *cmd;
649 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
652 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
658 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
660 cmd->role_id = wlvif->role_id;
661 cmd->disc_type = DISCONNECT_IMMEDIATE;
662 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
664 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
666 wl1271_error("failed to initiate cmd role stop sta");
670 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
679 int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
681 struct wl12xx_cmd_role_start *cmd;
682 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
683 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
686 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
688 /* trying to use hidden SSID with an old hostapd version */
689 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
690 wl1271_error("got a null SSID from beacon/bss");
695 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
701 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
705 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
707 goto out_free_global;
709 cmd->role_id = wlvif->role_id;
710 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
711 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
712 cmd->ap.global_hlid = wlvif->ap.global_hlid;
713 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
714 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
715 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
716 cmd->ap.dtim_interval = bss_conf->dtim_period;
717 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
718 cmd->channel = wlvif->channel;
720 if (!bss_conf->hidden_ssid) {
721 /* take the SSID from the beacon for backward compatibility */
722 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
723 cmd->ap.ssid_len = wlvif->ssid_len;
724 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
726 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
727 cmd->ap.ssid_len = bss_conf->ssid_len;
728 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
731 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
733 switch (wlvif->band) {
734 case IEEE80211_BAND_2GHZ:
735 cmd->band = RADIO_BAND_2_4GHZ;
737 case IEEE80211_BAND_5GHZ:
738 cmd->band = RADIO_BAND_5GHZ;
741 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
742 cmd->band = RADIO_BAND_2_4GHZ;
746 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
748 wl1271_error("failed to initiate cmd role start ap");
755 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
758 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
767 int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
769 struct wl12xx_cmd_role_stop *cmd;
772 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
778 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
780 cmd->role_id = wlvif->role_id;
782 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
784 wl1271_error("failed to initiate cmd role stop ap");
788 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
789 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
798 int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
800 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
801 struct wl12xx_cmd_role_start *cmd;
802 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
805 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
811 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
813 cmd->role_id = wlvif->role_id;
814 if (wlvif->band == IEEE80211_BAND_5GHZ)
815 cmd->band = WL12XX_BAND_5GHZ;
816 cmd->channel = wlvif->channel;
817 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
818 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
819 cmd->ibss.dtim_interval = bss_conf->dtim_period;
820 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
821 cmd->ibss.ssid_len = wlvif->ssid_len;
822 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
823 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
824 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
826 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
827 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
831 cmd->ibss.hlid = wlvif->sta.hlid;
832 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
834 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
835 "basic_rate_set: 0x%x, remote_rates: 0x%x",
836 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
837 wlvif->basic_rate_set, wlvif->rate_set);
839 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
840 vif->bss_conf.bssid);
842 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
844 wl1271_error("failed to initiate cmd role enable");
851 /* clear links on error. */
852 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
863 * send test command to firmware
866 * @buf: buffer containing the command, with all headers, must work with dma
867 * @len: length of the buffer
868 * @answer: is answer needed
870 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
875 wl1271_debug(DEBUG_CMD, "cmd test");
880 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
883 wl1271_warning("TEST command failed");
891 * read acx from firmware
895 * @buf: buffer for the response, including all headers, must work with dma
896 * @len: length of buf
898 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
900 struct acx_header *acx = buf;
903 wl1271_debug(DEBUG_CMD, "cmd interrogate");
905 acx->id = cpu_to_le16(id);
907 /* payload length, does not include any headers */
908 acx->len = cpu_to_le16(len - sizeof(*acx));
910 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
912 wl1271_error("INTERROGATE command failed");
918 * write acx value to firmware
922 * @buf: buffer containing acx, including all headers, must work with dma
923 * @len: length of buf
925 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
927 struct acx_header *acx = buf;
930 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
932 acx->id = cpu_to_le16(id);
934 /* payload length, does not include any headers */
935 acx->len = cpu_to_le16(len - sizeof(*acx));
937 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
939 wl1271_warning("CONFIGURE command NOK");
946 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
948 struct cmd_enabledisable_path *cmd;
952 wl1271_debug(DEBUG_CMD, "cmd data path");
954 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
960 /* the channel here is only used for calibration, so hardcoded to 1 */
964 cmd_rx = CMD_ENABLE_RX;
965 cmd_tx = CMD_ENABLE_TX;
967 cmd_rx = CMD_DISABLE_RX;
968 cmd_tx = CMD_DISABLE_TX;
971 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
973 wl1271_error("rx %s cmd for channel %d failed",
974 enable ? "start" : "stop", cmd->channel);
978 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
979 enable ? "start" : "stop", cmd->channel);
981 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
983 wl1271_error("tx %s cmd for channel %d failed",
984 enable ? "start" : "stop", cmd->channel);
988 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
989 enable ? "start" : "stop", cmd->channel);
996 int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
999 struct wl1271_cmd_ps_params *ps_params = NULL;
1002 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
1004 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
1010 ps_params->role_id = wlvif->role_id;
1011 ps_params->ps_mode = ps_mode;
1013 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
1014 sizeof(*ps_params), 0);
1016 wl1271_error("cmd set_ps_mode failed");
1025 int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
1026 void *buf, size_t buf_len, int index, u32 rates)
1028 struct wl1271_cmd_template_set *cmd;
1031 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
1033 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
1034 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
1036 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1042 cmd->len = cpu_to_le16(buf_len);
1043 cmd->template_type = template_id;
1044 cmd->enabled_rates = cpu_to_le32(rates);
1045 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
1046 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
1050 memcpy(cmd->template_data, buf, buf_len);
1052 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
1054 wl1271_warning("cmd set_template failed: %d", ret);
1065 int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1067 struct sk_buff *skb = NULL;
1073 if (wlvif->bss_type == BSS_TYPE_IBSS) {
1074 size = sizeof(struct wl12xx_null_data_template);
1077 skb = ieee80211_nullfunc_get(wl->hw,
1078 wl12xx_wlvif_to_vif(wlvif));
1085 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
1091 wl1271_warning("cmd buld null data failed %d", ret);
1097 int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1098 struct wl12xx_vif *wlvif)
1100 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1101 struct sk_buff *skb = NULL;
1104 skb = ieee80211_nullfunc_get(wl->hw, vif);
1108 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
1109 skb->data, skb->len,
1110 CMD_TEMPL_KLV_IDX_NULL_DATA,
1116 wl1271_warning("cmd build klv null data failed %d", ret);
1122 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1125 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1126 struct sk_buff *skb;
1129 skb = ieee80211_pspoll_get(wl->hw, vif);
1133 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
1134 skb->len, 0, wlvif->basic_rate_set);
1141 int wl1271_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1142 const u8 *ssid, size_t ssid_len,
1143 const u8 *ie, size_t ie_len, u8 band)
1145 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1146 struct sk_buff *skb;
1150 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1157 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1159 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1160 if (band == IEEE80211_BAND_2GHZ)
1161 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1162 skb->data, skb->len, 0, rate);
1164 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
1165 skb->data, skb->len, 0, rate);
1172 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1173 struct wl12xx_vif *wlvif,
1174 struct sk_buff *skb)
1176 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1181 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1185 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1187 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1188 if (wlvif->band == IEEE80211_BAND_2GHZ)
1189 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1190 skb->data, skb->len, 0, rate);
1192 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
1193 skb->data, skb->len, 0, rate);
1196 wl1271_error("Unable to set ap probe request template.");
1202 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1206 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1207 struct wl12xx_arp_rsp_template tmpl;
1208 struct ieee80211_hdr_3addr *hdr;
1209 struct arphdr *arp_hdr;
1211 memset(&tmpl, 0, sizeof(tmpl));
1213 /* mac80211 header */
1215 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1216 IEEE80211_STYPE_DATA |
1217 IEEE80211_FCTL_TODS);
1218 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1219 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1220 memset(hdr->addr3, 0xff, ETH_ALEN);
1223 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1224 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
1227 arp_hdr = &tmpl.arp_hdr;
1228 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1229 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1230 arp_hdr->ar_hln = ETH_ALEN;
1231 arp_hdr->ar_pln = 4;
1232 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1235 memcpy(tmpl.sender_hw, vif->addr, ETH_ALEN);
1236 tmpl.sender_ip = ip_addr;
1238 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
1239 &tmpl, sizeof(tmpl), 0,
1245 int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1247 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1248 struct ieee80211_qos_hdr template;
1250 memset(&template, 0, sizeof(template));
1252 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1253 memcpy(template.addr2, vif->addr, ETH_ALEN);
1254 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1256 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1257 IEEE80211_STYPE_QOS_NULLFUNC |
1258 IEEE80211_FCTL_TODS);
1260 /* FIXME: not sure what priority to use here */
1261 template.qos_ctrl = cpu_to_le16(0);
1263 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
1264 sizeof(template), 0,
1268 int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1270 struct wl1271_cmd_set_keys *cmd;
1273 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1275 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1283 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1284 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1285 cmd->key_type = KEY_WEP;
1287 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1289 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1299 int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1300 u16 action, u8 id, u8 key_type,
1301 u8 key_size, const u8 *key, const u8 *addr,
1302 u32 tx_seq_32, u16 tx_seq_16)
1304 struct wl1271_cmd_set_keys *cmd;
1307 /* hlid might have already been deleted */
1308 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1311 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1317 cmd->hlid = wlvif->sta.hlid;
1319 if (key_type == KEY_WEP)
1320 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1321 else if (is_broadcast_ether_addr(addr))
1322 cmd->lid_key_type = BROADCAST_LID_TYPE;
1324 cmd->lid_key_type = UNICAST_LID_TYPE;
1326 cmd->key_action = cpu_to_le16(action);
1327 cmd->key_size = key_size;
1328 cmd->key_type = key_type;
1330 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1331 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1335 if (key_type == KEY_TKIP) {
1337 * We get the key in the following form:
1338 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1339 * but the target is expecting:
1340 * TKIP - RX MIC - TX MIC
1342 memcpy(cmd->key, key, 16);
1343 memcpy(cmd->key + 16, key + 24, 8);
1344 memcpy(cmd->key + 24, key + 16, 8);
1347 memcpy(cmd->key, key, key_size);
1350 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1352 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1354 wl1271_warning("could not set keys");
1365 * TODO: merge with sta/ibss into 1 set_key function.
1366 * note there are slight diffs
1368 int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1369 u16 action, u8 id, u8 key_type,
1370 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1373 struct wl1271_cmd_set_keys *cmd;
1377 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1381 if (hlid == wlvif->ap.bcast_hlid) {
1382 if (key_type == KEY_WEP)
1383 lid_type = WEP_DEFAULT_LID_TYPE;
1385 lid_type = BROADCAST_LID_TYPE;
1387 lid_type = UNICAST_LID_TYPE;
1390 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1391 " hlid: %d", (int)action, (int)id, (int)lid_type,
1392 (int)key_type, (int)hlid);
1394 cmd->lid_key_type = lid_type;
1396 cmd->key_action = cpu_to_le16(action);
1397 cmd->key_size = key_size;
1398 cmd->key_type = key_type;
1400 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1401 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1403 if (key_type == KEY_TKIP) {
1405 * We get the key in the following form:
1406 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1407 * but the target is expecting:
1408 * TKIP - RX MIC - TX MIC
1410 memcpy(cmd->key, key, 16);
1411 memcpy(cmd->key + 16, key + 24, 8);
1412 memcpy(cmd->key + 24, key + 16, 8);
1414 memcpy(cmd->key, key, key_size);
1417 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1419 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1421 wl1271_warning("could not set ap keys");
1430 int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1432 struct wl12xx_cmd_set_peer_state *cmd;
1435 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1437 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1444 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1446 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1448 wl1271_error("failed to send set peer state command");
1459 int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1460 struct ieee80211_sta *sta, u8 hlid)
1462 struct wl12xx_cmd_add_peer *cmd;
1466 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1468 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1474 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1475 cmd->bss_index = WL1271_AP_BSS_INDEX;
1476 cmd->aid = sta->aid;
1478 cmd->sp_len = sta->max_sp;
1479 cmd->wmm = sta->wme ? 1 : 0;
1481 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1482 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1483 cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
1485 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1487 sta_rates = sta->supp_rates[wlvif->band];
1488 if (sta->ht_cap.ht_supported)
1489 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1491 cmd->supported_rates =
1492 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1495 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1496 cmd->supported_rates, sta->uapsd_queues);
1498 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1500 wl1271_error("failed to initiate cmd add peer");
1511 int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1513 struct wl12xx_cmd_remove_peer *cmd;
1516 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1518 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1525 /* We never send a deauth, mac80211 is in charge of this */
1526 cmd->reason_opcode = 0;
1527 cmd->send_deauth_flag = 0;
1529 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1531 wl1271_error("failed to initiate cmd remove peer");
1536 * We are ok with a timeout here. The event is sometimes not sent
1537 * due to a firmware bug.
1539 wl1271_cmd_wait_for_event_or_timeout(wl,
1540 PEER_REMOVE_COMPLETE_EVENT_ID);
1549 int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1551 struct wl12xx_cmd_config_fwlog *cmd;
1554 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1556 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1562 cmd->logger_mode = wl->conf.fwlog.mode;
1563 cmd->log_severity = wl->conf.fwlog.severity;
1564 cmd->timestamp = wl->conf.fwlog.timestamp;
1565 cmd->output = wl->conf.fwlog.output;
1566 cmd->threshold = wl->conf.fwlog.threshold;
1568 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1570 wl1271_error("failed to send config firmware logger command");
1581 int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1583 struct wl12xx_cmd_start_fwlog *cmd;
1586 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1588 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1594 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1596 wl1271_error("failed to send start firmware logger command");
1607 int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1609 struct wl12xx_cmd_stop_fwlog *cmd;
1612 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1614 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1620 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1622 wl1271_error("failed to send stop firmware logger command");
1633 static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1636 struct wl12xx_cmd_roc *cmd;
1639 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1641 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1644 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1650 cmd->role_id = role_id;
1651 cmd->channel = wlvif->channel;
1652 switch (wlvif->band) {
1653 case IEEE80211_BAND_2GHZ:
1654 cmd->band = RADIO_BAND_2_4GHZ;
1656 case IEEE80211_BAND_5GHZ:
1657 cmd->band = RADIO_BAND_5GHZ;
1660 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1666 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1668 wl1271_error("failed to send ROC command");
1679 static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1681 struct wl12xx_cmd_croc *cmd;
1684 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1686 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1691 cmd->role_id = role_id;
1693 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1696 wl1271_error("failed to send ROC command");
1707 int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1711 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1714 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1718 ret = wl1271_cmd_wait_for_event(wl,
1719 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1721 wl1271_error("cmd roc event completion error");
1725 __set_bit(role_id, wl->roc_map);
1730 int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1734 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1737 ret = wl12xx_cmd_croc(wl, role_id);
1741 __clear_bit(role_id, wl->roc_map);
1746 int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1747 struct ieee80211_channel_switch *ch_switch)
1749 struct wl12xx_cmd_channel_switch *cmd;
1752 wl1271_debug(DEBUG_ACX, "cmd channel switch");
1754 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1760 cmd->channel = ch_switch->channel->hw_value;
1761 cmd->switch_time = ch_switch->count;
1762 cmd->tx_suspend = ch_switch->block_tx;
1763 cmd->flush = 0; /* this value is ignored by the FW */
1765 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
1767 wl1271_error("failed to send channel switch command");
1778 int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
1780 struct wl12xx_cmd_stop_channel_switch *cmd;
1783 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1785 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1791 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
1793 wl1271_error("failed to stop channel switch command");
1804 /* start dev role and roc on its channel */
1805 int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1809 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1810 wlvif->bss_type == BSS_TYPE_IBSS)))
1813 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1817 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1824 wl12xx_cmd_role_stop_dev(wl, wlvif);
1829 /* croc dev hlid, and stop the role */
1830 int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1834 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1835 wlvif->bss_type == BSS_TYPE_IBSS)))
1838 /* flush all pending packets */
1839 wl1271_tx_work_locked(wl);
1841 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1842 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1847 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);