2 * This file is part of wl1271
4 * Copyright (C) 2009-2010 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/spi/spi.h>
27 #include <linux/etherdevice.h>
28 #include <linux/ieee80211.h>
29 #include <linux/slab.h>
35 #include "wl12xx_80211.h"
41 #define WL1271_CMD_FAST_POLL_COUNT 50
42 #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20
45 * send command to firmware
49 * @buf: buffer containing the command, must work with dma
50 * @len: length of the buffer
52 int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
55 struct wl1271_cmd_header *cmd;
56 unsigned long timeout;
62 if (WARN_ON(unlikely(wl->state == WLCORE_STATE_RESTARTING)))
66 cmd->id = cpu_to_le16(id);
69 WARN_ON(len % 4 != 0);
70 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
72 ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false);
77 * TODO: we just need this because one bit is in a different
78 * place. Is there any better way?
80 ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len);
84 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
86 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
90 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
91 if (time_after(jiffies, timeout)) {
92 wl1271_error("command complete timeout");
98 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
103 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
108 /* read back the status code of the command */
110 res_len = sizeof(struct wl1271_cmd_header);
112 ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false);
116 status = le16_to_cpu(cmd->status);
117 if (status != CMD_STATUS_SUCCESS) {
118 wl1271_error("command execute failure %d", status);
123 ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK,
124 WL1271_ACX_INTR_CMD_COMPLETE);
131 wl12xx_queue_recovery_work(wl);
136 * Poll the mailbox event field until any of the bits in the mask is set or a
137 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
139 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl,
140 u32 mask, bool *timeout)
144 unsigned long timeout_time;
150 events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA);
154 timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
157 if (time_after(jiffies, timeout_time)) {
158 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
165 if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT)
166 usleep_range(50, 51);
168 usleep_range(1000, 5000);
170 /* read from both event fields */
171 ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector,
172 sizeof(*events_vector), false);
176 event = *events_vector & mask;
178 ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector,
179 sizeof(*events_vector), false);
183 event |= *events_vector & mask;
187 kfree(events_vector);
191 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
194 bool timeout = false;
196 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask, &timeout);
197 if (ret != 0 || timeout) {
198 wl12xx_queue_recovery_work(wl);
205 int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
208 struct wl12xx_cmd_role_enable *cmd;
211 wl1271_debug(DEBUG_CMD, "cmd role enable");
213 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
216 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
223 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
224 if (cmd->role_id >= WL12XX_MAX_ROLES) {
229 memcpy(cmd->mac_address, addr, ETH_ALEN);
230 cmd->role_type = role_type;
232 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
234 wl1271_error("failed to initiate cmd role enable");
238 __set_bit(cmd->role_id, wl->roles_map);
239 *role_id = cmd->role_id;
248 int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
250 struct wl12xx_cmd_role_disable *cmd;
253 wl1271_debug(DEBUG_CMD, "cmd role disable");
255 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
258 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
263 cmd->role_id = *role_id;
265 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
267 wl1271_error("failed to initiate cmd role disable");
271 __clear_bit(*role_id, wl->roles_map);
272 *role_id = WL12XX_INVALID_ROLE_ID;
281 int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
284 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
285 if (link >= WL12XX_MAX_LINKS)
288 /* these bits are used by op_tx */
289 spin_lock_irqsave(&wl->wl_lock, flags);
290 __set_bit(link, wl->links_map);
291 __set_bit(link, wlvif->links_map);
292 spin_unlock_irqrestore(&wl->wl_lock, flags);
297 void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
301 if (*hlid == WL12XX_INVALID_LINK_ID)
304 /* these bits are used by op_tx */
305 spin_lock_irqsave(&wl->wl_lock, flags);
306 __clear_bit(*hlid, wl->links_map);
307 __clear_bit(*hlid, wlvif->links_map);
308 spin_unlock_irqrestore(&wl->wl_lock, flags);
311 * At this point op_tx() will not add more packets to the queues. We
314 wl1271_tx_reset_link_queues(wl, *hlid);
316 *hlid = WL12XX_INVALID_LINK_ID;
319 static int wl12xx_get_new_session_id(struct wl1271 *wl,
320 struct wl12xx_vif *wlvif)
322 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
323 wlvif->session_counter = 0;
325 wlvif->session_counter++;
327 return wlvif->session_counter;
330 static u8 wlcore_get_native_channel_type(u8 nl_channel_type)
332 switch (nl_channel_type) {
333 case NL80211_CHAN_NO_HT:
334 return WLCORE_CHAN_NO_HT;
335 case NL80211_CHAN_HT20:
336 return WLCORE_CHAN_HT20;
337 case NL80211_CHAN_HT40MINUS:
338 return WLCORE_CHAN_HT40MINUS;
339 case NL80211_CHAN_HT40PLUS:
340 return WLCORE_CHAN_HT40PLUS;
343 return WLCORE_CHAN_NO_HT;
347 static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
348 struct wl12xx_vif *wlvif)
350 struct wl12xx_cmd_role_start *cmd;
353 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
359 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
361 cmd->role_id = wlvif->dev_role_id;
362 if (wlvif->band == IEEE80211_BAND_5GHZ)
363 cmd->band = WLCORE_BAND_5GHZ;
364 cmd->channel = wlvif->channel;
366 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
367 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
371 cmd->device.hlid = wlvif->dev_hlid;
372 cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
374 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
375 cmd->role_id, cmd->device.hlid, cmd->device.session);
377 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
379 wl1271_error("failed to initiate cmd role enable");
386 /* clear links on error */
387 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
396 static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
397 struct wl12xx_vif *wlvif)
399 struct wl12xx_cmd_role_stop *cmd;
402 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
405 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
411 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
413 cmd->role_id = wlvif->dev_role_id;
414 cmd->disc_type = DISCONNECT_IMMEDIATE;
415 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
417 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
419 wl1271_error("failed to initiate cmd role stop");
423 ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
425 wl1271_error("cmd role stop dev event completion error");
429 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
438 int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
440 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
441 struct wl12xx_cmd_role_start *cmd;
444 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
450 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
452 cmd->role_id = wlvif->role_id;
453 if (wlvif->band == IEEE80211_BAND_5GHZ)
454 cmd->band = WLCORE_BAND_5GHZ;
455 cmd->channel = wlvif->channel;
456 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
457 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
458 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
459 cmd->sta.ssid_len = wlvif->ssid_len;
460 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
461 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
462 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
463 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
465 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
466 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
470 cmd->sta.hlid = wlvif->sta.hlid;
471 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
472 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
474 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
475 "basic_rate_set: 0x%x, remote_rates: 0x%x",
476 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
477 wlvif->basic_rate_set, wlvif->rate_set);
479 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
481 wl1271_error("failed to initiate cmd role start sta");
488 /* clear links on error. */
489 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
498 /* use this function to stop ibss as well */
499 int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
501 struct wl12xx_cmd_role_stop *cmd;
503 bool timeout = false;
505 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
508 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
514 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
516 cmd->role_id = wlvif->role_id;
517 cmd->disc_type = DISCONNECT_IMMEDIATE;
518 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
520 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
522 wl1271_error("failed to initiate cmd role stop sta");
527 * Sometimes the firmware doesn't send this event, so we just
528 * time out without failing. Queue recovery for other
531 ret = wl1271_cmd_wait_for_event_or_timeout(wl,
532 ROLE_STOP_COMPLETE_EVENT_ID,
535 wl12xx_queue_recovery_work(wl);
537 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
546 int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
548 struct wl12xx_cmd_role_start *cmd;
549 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
550 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
554 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
556 /* trying to use hidden SSID with an old hostapd version */
557 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
558 wl1271_error("got a null SSID from beacon/bss");
563 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
569 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
573 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
575 goto out_free_global;
577 cmd->role_id = wlvif->role_id;
578 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
579 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
580 cmd->ap.global_hlid = wlvif->ap.global_hlid;
581 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
582 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
583 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
584 cmd->ap.dtim_interval = bss_conf->dtim_period;
585 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
586 /* FIXME: Change when adding DFS */
587 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
588 cmd->channel = wlvif->channel;
589 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
591 if (!bss_conf->hidden_ssid) {
592 /* take the SSID from the beacon for backward compatibility */
593 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
594 cmd->ap.ssid_len = wlvif->ssid_len;
595 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
597 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
598 cmd->ap.ssid_len = bss_conf->ssid_len;
599 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
602 supported_rates = CONF_TX_AP_ENABLED_RATES | CONF_TX_MCS_RATES |
603 wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
605 wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x",
608 cmd->ap.local_rates = cpu_to_le32(supported_rates);
610 switch (wlvif->band) {
611 case IEEE80211_BAND_2GHZ:
612 cmd->band = WLCORE_BAND_2_4GHZ;
614 case IEEE80211_BAND_5GHZ:
615 cmd->band = WLCORE_BAND_5GHZ;
618 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
619 cmd->band = WLCORE_BAND_2_4GHZ;
623 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
625 wl1271_error("failed to initiate cmd role start ap");
632 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
635 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
644 int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
646 struct wl12xx_cmd_role_stop *cmd;
649 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
655 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
657 cmd->role_id = wlvif->role_id;
659 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
661 wl1271_error("failed to initiate cmd role stop ap");
665 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
666 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
675 int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
677 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
678 struct wl12xx_cmd_role_start *cmd;
679 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
682 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
688 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
690 cmd->role_id = wlvif->role_id;
691 if (wlvif->band == IEEE80211_BAND_5GHZ)
692 cmd->band = WLCORE_BAND_5GHZ;
693 cmd->channel = wlvif->channel;
694 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
695 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
696 cmd->ibss.dtim_interval = bss_conf->dtim_period;
697 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
698 cmd->ibss.ssid_len = wlvif->ssid_len;
699 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
700 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
701 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
703 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
704 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
708 cmd->ibss.hlid = wlvif->sta.hlid;
709 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
711 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
712 "basic_rate_set: 0x%x, remote_rates: 0x%x",
713 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
714 wlvif->basic_rate_set, wlvif->rate_set);
716 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
717 vif->bss_conf.bssid);
719 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
721 wl1271_error("failed to initiate cmd role enable");
728 /* clear links on error. */
729 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
740 * send test command to firmware
743 * @buf: buffer containing the command, with all headers, must work with dma
744 * @len: length of the buffer
745 * @answer: is answer needed
747 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
752 wl1271_debug(DEBUG_CMD, "cmd test");
757 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
760 wl1271_warning("TEST command failed");
766 EXPORT_SYMBOL_GPL(wl1271_cmd_test);
769 * read acx from firmware
773 * @buf: buffer for the response, including all headers, must work with dma
774 * @len: length of buf
776 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
778 struct acx_header *acx = buf;
781 wl1271_debug(DEBUG_CMD, "cmd interrogate");
783 acx->id = cpu_to_le16(id);
785 /* payload length, does not include any headers */
786 acx->len = cpu_to_le16(len - sizeof(*acx));
788 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
790 wl1271_error("INTERROGATE command failed");
796 * write acx value to firmware
800 * @buf: buffer containing acx, including all headers, must work with dma
801 * @len: length of buf
803 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
805 struct acx_header *acx = buf;
808 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
810 acx->id = cpu_to_le16(id);
812 /* payload length, does not include any headers */
813 acx->len = cpu_to_le16(len - sizeof(*acx));
815 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
817 wl1271_warning("CONFIGURE command NOK");
823 EXPORT_SYMBOL_GPL(wl1271_cmd_configure);
825 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
827 struct cmd_enabledisable_path *cmd;
831 wl1271_debug(DEBUG_CMD, "cmd data path");
833 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
839 /* the channel here is only used for calibration, so hardcoded to 1 */
843 cmd_rx = CMD_ENABLE_RX;
844 cmd_tx = CMD_ENABLE_TX;
846 cmd_rx = CMD_DISABLE_RX;
847 cmd_tx = CMD_DISABLE_TX;
850 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
852 wl1271_error("rx %s cmd for channel %d failed",
853 enable ? "start" : "stop", cmd->channel);
857 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
858 enable ? "start" : "stop", cmd->channel);
860 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
862 wl1271_error("tx %s cmd for channel %d failed",
863 enable ? "start" : "stop", cmd->channel);
867 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
868 enable ? "start" : "stop", cmd->channel);
874 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path);
876 int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
877 u8 ps_mode, u16 auto_ps_timeout)
879 struct wl1271_cmd_ps_params *ps_params = NULL;
882 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
884 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
890 ps_params->role_id = wlvif->role_id;
891 ps_params->ps_mode = ps_mode;
892 ps_params->auto_ps_timeout = auto_ps_timeout;
894 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
895 sizeof(*ps_params), 0);
897 wl1271_error("cmd set_ps_mode failed");
906 int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
907 u16 template_id, void *buf, size_t buf_len,
908 int index, u32 rates)
910 struct wl1271_cmd_template_set *cmd;
913 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
914 template_id, role_id);
916 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
917 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
919 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
925 /* during initialization wlvif is NULL */
926 cmd->role_id = role_id;
927 cmd->len = cpu_to_le16(buf_len);
928 cmd->template_type = template_id;
929 cmd->enabled_rates = cpu_to_le32(rates);
930 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
931 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
935 memcpy(cmd->template_data, buf, buf_len);
937 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
939 wl1271_warning("cmd set_template failed: %d", ret);
950 int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
952 struct sk_buff *skb = NULL;
958 if (wlvif->bss_type == BSS_TYPE_IBSS) {
959 size = sizeof(struct wl12xx_null_data_template);
962 skb = ieee80211_nullfunc_get(wl->hw,
963 wl12xx_wlvif_to_vif(wlvif));
970 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
971 CMD_TEMPL_NULL_DATA, ptr, size, 0,
977 wl1271_warning("cmd buld null data failed %d", ret);
983 int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
984 struct wl12xx_vif *wlvif)
986 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
987 struct sk_buff *skb = NULL;
990 skb = ieee80211_nullfunc_get(wl->hw, vif);
994 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
996 wlvif->sta.klv_template_id,
1002 wl1271_warning("cmd build klv null data failed %d", ret);
1008 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1011 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1012 struct sk_buff *skb;
1015 skb = ieee80211_pspoll_get(wl->hw, vif);
1019 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1020 CMD_TEMPL_PS_POLL, skb->data,
1021 skb->len, 0, wlvif->basic_rate_set);
1028 int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1029 u8 role_id, u8 band,
1030 const u8 *ssid, size_t ssid_len,
1031 const u8 *ie, size_t ie_len, bool sched_scan)
1033 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1034 struct sk_buff *skb;
1037 u16 template_id_2_4 = CMD_TEMPL_CFG_PROBE_REQ_2_4;
1038 u16 template_id_5 = CMD_TEMPL_CFG_PROBE_REQ_5;
1040 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1047 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1050 (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) {
1051 template_id_2_4 = CMD_TEMPL_APP_PROBE_REQ_2_4;
1052 template_id_5 = CMD_TEMPL_APP_PROBE_REQ_5;
1055 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1056 if (band == IEEE80211_BAND_2GHZ)
1057 ret = wl1271_cmd_template_set(wl, role_id,
1059 skb->data, skb->len, 0, rate);
1061 ret = wl1271_cmd_template_set(wl, role_id,
1063 skb->data, skb->len, 0, rate);
1070 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1071 struct wl12xx_vif *wlvif,
1072 struct sk_buff *skb)
1074 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1079 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1083 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1085 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1086 if (wlvif->band == IEEE80211_BAND_2GHZ)
1087 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1088 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1089 skb->data, skb->len, 0, rate);
1091 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1092 CMD_TEMPL_CFG_PROBE_REQ_5,
1093 skb->data, skb->len, 0, rate);
1096 wl1271_error("Unable to set ap probe request template.");
1102 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1106 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1107 struct sk_buff *skb;
1108 struct wl12xx_arp_rsp_template *tmpl;
1109 struct ieee80211_hdr_3addr *hdr;
1110 struct arphdr *arp_hdr;
1112 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
1113 WL1271_EXTRA_SPACE_MAX);
1115 wl1271_error("failed to allocate buffer for arp rsp template");
1119 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
1121 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
1122 memset(tmpl, 0, sizeof(*tmpl));
1125 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1126 tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
1129 arp_hdr = &tmpl->arp_hdr;
1130 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1131 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1132 arp_hdr->ar_hln = ETH_ALEN;
1133 arp_hdr->ar_pln = 4;
1134 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1137 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
1138 tmpl->sender_ip = wlvif->ip_addr;
1140 /* encryption space */
1141 switch (wlvif->encryption_type) {
1143 if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE)
1144 extra = WL1271_EXTRA_SPACE_TKIP;
1147 extra = WL1271_EXTRA_SPACE_AES;
1155 wl1271_warning("Unknown encryption type: %d",
1156 wlvif->encryption_type);
1162 u8 *space = skb_push(skb, extra);
1163 memset(space, 0, extra);
1166 /* QoS header - BE */
1168 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
1170 /* mac80211 header */
1171 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
1172 memset(hdr, 0, sizeof(*hdr));
1173 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
1175 fc |= IEEE80211_STYPE_QOS_DATA;
1177 fc |= IEEE80211_STYPE_DATA;
1178 if (wlvif->encryption_type != KEY_NONE)
1179 fc |= IEEE80211_FCTL_PROTECTED;
1181 hdr->frame_control = cpu_to_le16(fc);
1182 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1183 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1184 memset(hdr->addr3, 0xff, ETH_ALEN);
1186 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
1187 skb->data, skb->len, 0,
1194 int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1196 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1197 struct ieee80211_qos_hdr template;
1199 memset(&template, 0, sizeof(template));
1201 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1202 memcpy(template.addr2, vif->addr, ETH_ALEN);
1203 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1205 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1206 IEEE80211_STYPE_QOS_NULLFUNC |
1207 IEEE80211_FCTL_TODS);
1209 /* FIXME: not sure what priority to use here */
1210 template.qos_ctrl = cpu_to_le16(0);
1212 return wl1271_cmd_template_set(wl, wlvif->role_id,
1213 CMD_TEMPL_QOS_NULL_DATA, &template,
1214 sizeof(template), 0,
1218 int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1220 struct wl1271_cmd_set_keys *cmd;
1223 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1225 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1233 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1234 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1235 cmd->key_type = KEY_WEP;
1237 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1239 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1249 int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1250 u16 action, u8 id, u8 key_type,
1251 u8 key_size, const u8 *key, const u8 *addr,
1252 u32 tx_seq_32, u16 tx_seq_16)
1254 struct wl1271_cmd_set_keys *cmd;
1257 /* hlid might have already been deleted */
1258 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1261 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1267 cmd->hlid = wlvif->sta.hlid;
1269 if (key_type == KEY_WEP)
1270 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1271 else if (is_broadcast_ether_addr(addr))
1272 cmd->lid_key_type = BROADCAST_LID_TYPE;
1274 cmd->lid_key_type = UNICAST_LID_TYPE;
1276 cmd->key_action = cpu_to_le16(action);
1277 cmd->key_size = key_size;
1278 cmd->key_type = key_type;
1280 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1281 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1285 if (key_type == KEY_TKIP) {
1287 * We get the key in the following form:
1288 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1289 * but the target is expecting:
1290 * TKIP - RX MIC - TX MIC
1292 memcpy(cmd->key, key, 16);
1293 memcpy(cmd->key + 16, key + 24, 8);
1294 memcpy(cmd->key + 24, key + 16, 8);
1297 memcpy(cmd->key, key, key_size);
1300 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1302 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1304 wl1271_warning("could not set keys");
1315 * TODO: merge with sta/ibss into 1 set_key function.
1316 * note there are slight diffs
1318 int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1319 u16 action, u8 id, u8 key_type,
1320 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1323 struct wl1271_cmd_set_keys *cmd;
1327 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1331 if (hlid == wlvif->ap.bcast_hlid) {
1332 if (key_type == KEY_WEP)
1333 lid_type = WEP_DEFAULT_LID_TYPE;
1335 lid_type = BROADCAST_LID_TYPE;
1337 lid_type = UNICAST_LID_TYPE;
1340 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1341 " hlid: %d", (int)action, (int)id, (int)lid_type,
1342 (int)key_type, (int)hlid);
1344 cmd->lid_key_type = lid_type;
1346 cmd->key_action = cpu_to_le16(action);
1347 cmd->key_size = key_size;
1348 cmd->key_type = key_type;
1350 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1351 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1353 if (key_type == KEY_TKIP) {
1355 * We get the key in the following form:
1356 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1357 * but the target is expecting:
1358 * TKIP - RX MIC - TX MIC
1360 memcpy(cmd->key, key, 16);
1361 memcpy(cmd->key + 16, key + 24, 8);
1362 memcpy(cmd->key + 24, key + 16, 8);
1364 memcpy(cmd->key, key, key_size);
1367 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1369 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1371 wl1271_warning("could not set ap keys");
1380 int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1382 struct wl12xx_cmd_set_peer_state *cmd;
1385 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1387 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1394 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1396 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1398 wl1271_error("failed to send set peer state command");
1409 int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1410 struct ieee80211_sta *sta, u8 hlid)
1412 struct wl12xx_cmd_add_peer *cmd;
1416 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1418 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1424 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1425 cmd->bss_index = WL1271_AP_BSS_INDEX;
1426 cmd->aid = sta->aid;
1428 cmd->sp_len = sta->max_sp;
1429 cmd->wmm = sta->wme ? 1 : 0;
1431 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1432 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1433 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1434 WL1271_PSD_UPSD_TRIGGER;
1436 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1440 sta_rates = sta->supp_rates[wlvif->band];
1441 if (sta->ht_cap.ht_supported)
1443 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
1444 (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
1446 cmd->supported_rates =
1447 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1450 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1451 cmd->supported_rates, sta->uapsd_queues);
1453 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1455 wl1271_error("failed to initiate cmd add peer");
1466 int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1468 struct wl12xx_cmd_remove_peer *cmd;
1470 bool timeout = false;
1472 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1474 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1481 /* We never send a deauth, mac80211 is in charge of this */
1482 cmd->reason_opcode = 0;
1483 cmd->send_deauth_flag = 0;
1485 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1487 wl1271_error("failed to initiate cmd remove peer");
1491 ret = wl1271_cmd_wait_for_event_or_timeout(wl,
1492 PEER_REMOVE_COMPLETE_EVENT_ID,
1495 * We are ok with a timeout here. The event is sometimes not sent
1496 * due to a firmware bug. In case of another error (like SDIO timeout)
1500 wl12xx_queue_recovery_work(wl);
1509 int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1511 struct wl12xx_cmd_config_fwlog *cmd;
1514 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1516 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1522 cmd->logger_mode = wl->conf.fwlog.mode;
1523 cmd->log_severity = wl->conf.fwlog.severity;
1524 cmd->timestamp = wl->conf.fwlog.timestamp;
1525 cmd->output = wl->conf.fwlog.output;
1526 cmd->threshold = wl->conf.fwlog.threshold;
1528 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1530 wl1271_error("failed to send config firmware logger command");
1541 int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1543 struct wl12xx_cmd_start_fwlog *cmd;
1546 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1548 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1554 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1556 wl1271_error("failed to send start firmware logger command");
1567 int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1569 struct wl12xx_cmd_stop_fwlog *cmd;
1572 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1574 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1580 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1582 wl1271_error("failed to send stop firmware logger command");
1593 static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1596 struct wl12xx_cmd_roc *cmd;
1599 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1601 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1604 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1610 cmd->role_id = role_id;
1611 cmd->channel = wlvif->channel;
1612 switch (wlvif->band) {
1613 case IEEE80211_BAND_2GHZ:
1614 cmd->band = WLCORE_BAND_2_4GHZ;
1616 case IEEE80211_BAND_5GHZ:
1617 cmd->band = WLCORE_BAND_5GHZ;
1620 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1626 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1628 wl1271_error("failed to send ROC command");
1639 static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1641 struct wl12xx_cmd_croc *cmd;
1644 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1646 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1651 cmd->role_id = role_id;
1653 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1656 wl1271_error("failed to send ROC command");
1667 int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1672 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1675 is_first_roc = (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >=
1678 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1683 ret = wl1271_cmd_wait_for_event(wl,
1684 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1686 wl1271_error("cmd roc event completion error");
1691 __set_bit(role_id, wl->roc_map);
1696 int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1700 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1703 ret = wl12xx_cmd_croc(wl, role_id);
1707 __clear_bit(role_id, wl->roc_map);
1710 * Rearm the tx watchdog when removing the last ROC. This prevents
1711 * recoveries due to just finished ROCs - when Tx hasn't yet had
1712 * a chance to get out.
1714 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
1715 wl12xx_rearm_tx_watchdog_locked(wl);
1720 int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1721 struct wl12xx_vif *wlvif,
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->role_id = wlvif->role_id;
1736 cmd->channel = ch_switch->channel->hw_value;
1737 cmd->switch_time = ch_switch->count;
1738 cmd->stop_tx = ch_switch->block_tx;
1740 /* FIXME: control from mac80211 in the future */
1741 cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
1743 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
1745 wl1271_error("failed to send channel switch command");
1756 int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
1758 struct wl12xx_cmd_stop_channel_switch *cmd;
1761 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1763 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1769 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
1771 wl1271_error("failed to stop channel switch command");
1782 /* start dev role and roc on its channel */
1783 int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1787 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1788 wlvif->bss_type == BSS_TYPE_IBSS)))
1791 ret = wl12xx_cmd_role_enable(wl,
1792 wl12xx_wlvif_to_vif(wlvif)->addr,
1794 &wlvif->dev_role_id);
1798 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1802 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1809 wl12xx_cmd_role_stop_dev(wl, wlvif);
1811 wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
1816 /* croc dev hlid, and stop the role */
1817 int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1821 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1822 wlvif->bss_type == BSS_TYPE_IBSS)))
1825 /* flush all pending packets */
1826 ret = wlcore_tx_work_locked(wl);
1830 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1831 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1836 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
1840 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);