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;
63 cmd->id = cpu_to_le16(id);
66 WARN_ON(len % 4 != 0);
67 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
69 ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false);
74 * TODO: we just need this because one bit is in a different
75 * place. Is there any better way?
77 ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len);
81 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
83 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
87 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
88 if (time_after(jiffies, timeout)) {
89 wl1271_error("command complete timeout");
95 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
100 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
105 /* read back the status code of the command */
107 res_len = sizeof(struct wl1271_cmd_header);
109 ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false);
113 status = le16_to_cpu(cmd->status);
114 if (status != CMD_STATUS_SUCCESS) {
115 wl1271_error("command execute failure %d", status);
120 ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK,
121 WL1271_ACX_INTR_CMD_COMPLETE);
128 wl12xx_queue_recovery_work(wl);
133 * Poll the mailbox event field until any of the bits in the mask is set or a
134 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
136 static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl,
137 u32 mask, bool *timeout)
141 unsigned long timeout_time;
147 events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA);
151 timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
154 if (time_after(jiffies, timeout_time)) {
155 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
162 if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT)
163 usleep_range(50, 51);
165 usleep_range(1000, 5000);
167 /* read from both event fields */
168 ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector,
169 sizeof(*events_vector), false);
173 event = *events_vector & mask;
175 ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector,
176 sizeof(*events_vector), false);
180 event |= *events_vector & mask;
184 kfree(events_vector);
188 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
191 bool timeout = false;
193 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask, &timeout);
194 if (ret != 0 || timeout) {
195 wl12xx_queue_recovery_work(wl);
202 int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
205 struct wl12xx_cmd_role_enable *cmd;
208 wl1271_debug(DEBUG_CMD, "cmd role enable");
210 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
213 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
220 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
221 if (cmd->role_id >= WL12XX_MAX_ROLES) {
226 memcpy(cmd->mac_address, addr, ETH_ALEN);
227 cmd->role_type = role_type;
229 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
231 wl1271_error("failed to initiate cmd role enable");
235 __set_bit(cmd->role_id, wl->roles_map);
236 *role_id = cmd->role_id;
245 int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
247 struct wl12xx_cmd_role_disable *cmd;
250 wl1271_debug(DEBUG_CMD, "cmd role disable");
252 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
255 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
260 cmd->role_id = *role_id;
262 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
264 wl1271_error("failed to initiate cmd role disable");
268 __clear_bit(*role_id, wl->roles_map);
269 *role_id = WL12XX_INVALID_ROLE_ID;
278 int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
281 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
282 if (link >= WL12XX_MAX_LINKS)
285 /* these bits are used by op_tx */
286 spin_lock_irqsave(&wl->wl_lock, flags);
287 __set_bit(link, wl->links_map);
288 __set_bit(link, wlvif->links_map);
289 spin_unlock_irqrestore(&wl->wl_lock, flags);
294 void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
298 if (*hlid == WL12XX_INVALID_LINK_ID)
301 /* these bits are used by op_tx */
302 spin_lock_irqsave(&wl->wl_lock, flags);
303 __clear_bit(*hlid, wl->links_map);
304 __clear_bit(*hlid, wlvif->links_map);
305 spin_unlock_irqrestore(&wl->wl_lock, flags);
308 * At this point op_tx() will not add more packets to the queues. We
311 wl1271_tx_reset_link_queues(wl, *hlid);
313 *hlid = WL12XX_INVALID_LINK_ID;
316 static int wl12xx_get_new_session_id(struct wl1271 *wl,
317 struct wl12xx_vif *wlvif)
319 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
320 wlvif->session_counter = 0;
322 wlvif->session_counter++;
324 return wlvif->session_counter;
327 static u8 wlcore_get_native_channel_type(u8 nl_channel_type)
329 switch (nl_channel_type) {
330 case NL80211_CHAN_NO_HT:
331 return WLCORE_CHAN_NO_HT;
332 case NL80211_CHAN_HT20:
333 return WLCORE_CHAN_HT20;
334 case NL80211_CHAN_HT40MINUS:
335 return WLCORE_CHAN_HT40MINUS;
336 case NL80211_CHAN_HT40PLUS:
337 return WLCORE_CHAN_HT40PLUS;
340 return WLCORE_CHAN_NO_HT;
344 static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
345 struct wl12xx_vif *wlvif)
347 struct wl12xx_cmd_role_start *cmd;
350 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
356 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
358 cmd->role_id = wlvif->dev_role_id;
359 if (wlvif->band == IEEE80211_BAND_5GHZ)
360 cmd->band = WLCORE_BAND_5GHZ;
361 cmd->channel = wlvif->channel;
363 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
364 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
368 cmd->device.hlid = wlvif->dev_hlid;
369 cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
371 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
372 cmd->role_id, cmd->device.hlid, cmd->device.session);
374 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
376 wl1271_error("failed to initiate cmd role enable");
383 /* clear links on error */
384 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
393 static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
394 struct wl12xx_vif *wlvif)
396 struct wl12xx_cmd_role_stop *cmd;
399 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
402 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
408 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
410 cmd->role_id = wlvif->dev_role_id;
411 cmd->disc_type = DISCONNECT_IMMEDIATE;
412 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
414 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
416 wl1271_error("failed to initiate cmd role stop");
420 ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
422 wl1271_error("cmd role stop dev event completion error");
426 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
435 int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
437 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
438 struct wl12xx_cmd_role_start *cmd;
441 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
447 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
449 cmd->role_id = wlvif->role_id;
450 if (wlvif->band == IEEE80211_BAND_5GHZ)
451 cmd->band = WLCORE_BAND_5GHZ;
452 cmd->channel = wlvif->channel;
453 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
454 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
455 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
456 cmd->sta.ssid_len = wlvif->ssid_len;
457 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
458 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
459 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
460 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
462 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
463 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
467 cmd->sta.hlid = wlvif->sta.hlid;
468 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
469 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
471 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
472 "basic_rate_set: 0x%x, remote_rates: 0x%x",
473 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
474 wlvif->basic_rate_set, wlvif->rate_set);
476 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
478 wl1271_error("failed to initiate cmd role start sta");
485 /* clear links on error. */
486 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
495 /* use this function to stop ibss as well */
496 int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
498 struct wl12xx_cmd_role_stop *cmd;
500 bool timeout = false;
502 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
505 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
511 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
513 cmd->role_id = wlvif->role_id;
514 cmd->disc_type = DISCONNECT_IMMEDIATE;
515 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
517 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
519 wl1271_error("failed to initiate cmd role stop sta");
524 * Sometimes the firmware doesn't send this event, so we just
525 * time out without failing. Queue recovery for other
528 ret = wl1271_cmd_wait_for_event_or_timeout(wl,
529 ROLE_STOP_COMPLETE_EVENT_ID,
532 wl12xx_queue_recovery_work(wl);
534 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
543 int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
545 struct wl12xx_cmd_role_start *cmd;
546 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
547 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
551 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
553 /* trying to use hidden SSID with an old hostapd version */
554 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
555 wl1271_error("got a null SSID from beacon/bss");
560 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
566 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
570 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
572 goto out_free_global;
574 cmd->role_id = wlvif->role_id;
575 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
576 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
577 cmd->ap.global_hlid = wlvif->ap.global_hlid;
578 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
579 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
580 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
581 cmd->ap.dtim_interval = bss_conf->dtim_period;
582 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
583 /* FIXME: Change when adding DFS */
584 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
585 cmd->channel = wlvif->channel;
586 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
588 if (!bss_conf->hidden_ssid) {
589 /* take the SSID from the beacon for backward compatibility */
590 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
591 cmd->ap.ssid_len = wlvif->ssid_len;
592 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
594 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
595 cmd->ap.ssid_len = bss_conf->ssid_len;
596 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
599 supported_rates = CONF_TX_AP_ENABLED_RATES | CONF_TX_MCS_RATES |
600 wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
602 wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x",
605 cmd->ap.local_rates = cpu_to_le32(supported_rates);
607 switch (wlvif->band) {
608 case IEEE80211_BAND_2GHZ:
609 cmd->band = WLCORE_BAND_2_4GHZ;
611 case IEEE80211_BAND_5GHZ:
612 cmd->band = WLCORE_BAND_5GHZ;
615 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
616 cmd->band = WLCORE_BAND_2_4GHZ;
620 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
622 wl1271_error("failed to initiate cmd role start ap");
629 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
632 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
641 int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
643 struct wl12xx_cmd_role_stop *cmd;
646 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
652 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
654 cmd->role_id = wlvif->role_id;
656 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
658 wl1271_error("failed to initiate cmd role stop ap");
662 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
663 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
672 int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
674 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
675 struct wl12xx_cmd_role_start *cmd;
676 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
679 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
685 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
687 cmd->role_id = wlvif->role_id;
688 if (wlvif->band == IEEE80211_BAND_5GHZ)
689 cmd->band = WLCORE_BAND_5GHZ;
690 cmd->channel = wlvif->channel;
691 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
692 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
693 cmd->ibss.dtim_interval = bss_conf->dtim_period;
694 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
695 cmd->ibss.ssid_len = wlvif->ssid_len;
696 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
697 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
698 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
700 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
701 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
705 cmd->ibss.hlid = wlvif->sta.hlid;
706 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
708 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
709 "basic_rate_set: 0x%x, remote_rates: 0x%x",
710 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
711 wlvif->basic_rate_set, wlvif->rate_set);
713 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
714 vif->bss_conf.bssid);
716 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
718 wl1271_error("failed to initiate cmd role enable");
725 /* clear links on error. */
726 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
737 * send test command to firmware
740 * @buf: buffer containing the command, with all headers, must work with dma
741 * @len: length of the buffer
742 * @answer: is answer needed
744 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
749 wl1271_debug(DEBUG_CMD, "cmd test");
754 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
757 wl1271_warning("TEST command failed");
763 EXPORT_SYMBOL_GPL(wl1271_cmd_test);
766 * read acx from firmware
770 * @buf: buffer for the response, including all headers, must work with dma
771 * @len: length of buf
773 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
775 struct acx_header *acx = buf;
778 wl1271_debug(DEBUG_CMD, "cmd interrogate");
780 acx->id = cpu_to_le16(id);
782 /* payload length, does not include any headers */
783 acx->len = cpu_to_le16(len - sizeof(*acx));
785 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
787 wl1271_error("INTERROGATE command failed");
793 * write acx value to firmware
797 * @buf: buffer containing acx, including all headers, must work with dma
798 * @len: length of buf
800 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
802 struct acx_header *acx = buf;
805 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
807 acx->id = cpu_to_le16(id);
809 /* payload length, does not include any headers */
810 acx->len = cpu_to_le16(len - sizeof(*acx));
812 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
814 wl1271_warning("CONFIGURE command NOK");
820 EXPORT_SYMBOL_GPL(wl1271_cmd_configure);
822 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
824 struct cmd_enabledisable_path *cmd;
828 wl1271_debug(DEBUG_CMD, "cmd data path");
830 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
836 /* the channel here is only used for calibration, so hardcoded to 1 */
840 cmd_rx = CMD_ENABLE_RX;
841 cmd_tx = CMD_ENABLE_TX;
843 cmd_rx = CMD_DISABLE_RX;
844 cmd_tx = CMD_DISABLE_TX;
847 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
849 wl1271_error("rx %s cmd for channel %d failed",
850 enable ? "start" : "stop", cmd->channel);
854 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
855 enable ? "start" : "stop", cmd->channel);
857 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
859 wl1271_error("tx %s cmd for channel %d failed",
860 enable ? "start" : "stop", cmd->channel);
864 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
865 enable ? "start" : "stop", cmd->channel);
871 EXPORT_SYMBOL_GPL(wl1271_cmd_data_path);
873 int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
874 u8 ps_mode, u16 auto_ps_timeout)
876 struct wl1271_cmd_ps_params *ps_params = NULL;
879 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
881 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
887 ps_params->role_id = wlvif->role_id;
888 ps_params->ps_mode = ps_mode;
889 ps_params->auto_ps_timeout = auto_ps_timeout;
891 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
892 sizeof(*ps_params), 0);
894 wl1271_error("cmd set_ps_mode failed");
903 int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
904 u16 template_id, void *buf, size_t buf_len,
905 int index, u32 rates)
907 struct wl1271_cmd_template_set *cmd;
910 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
911 template_id, role_id);
913 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
914 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
916 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
922 /* during initialization wlvif is NULL */
923 cmd->role_id = role_id;
924 cmd->len = cpu_to_le16(buf_len);
925 cmd->template_type = template_id;
926 cmd->enabled_rates = cpu_to_le32(rates);
927 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
928 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
932 memcpy(cmd->template_data, buf, buf_len);
934 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
936 wl1271_warning("cmd set_template failed: %d", ret);
947 int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
949 struct sk_buff *skb = NULL;
955 if (wlvif->bss_type == BSS_TYPE_IBSS) {
956 size = sizeof(struct wl12xx_null_data_template);
959 skb = ieee80211_nullfunc_get(wl->hw,
960 wl12xx_wlvif_to_vif(wlvif));
967 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
968 CMD_TEMPL_NULL_DATA, ptr, size, 0,
974 wl1271_warning("cmd buld null data failed %d", ret);
980 int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
981 struct wl12xx_vif *wlvif)
983 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
984 struct sk_buff *skb = NULL;
987 skb = ieee80211_nullfunc_get(wl->hw, vif);
991 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
993 CMD_TEMPL_KLV_IDX_NULL_DATA,
999 wl1271_warning("cmd build klv null data failed %d", ret);
1005 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1008 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1009 struct sk_buff *skb;
1012 skb = ieee80211_pspoll_get(wl->hw, vif);
1016 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1017 CMD_TEMPL_PS_POLL, skb->data,
1018 skb->len, 0, wlvif->basic_rate_set);
1025 int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1026 u8 role_id, u8 band,
1027 const u8 *ssid, size_t ssid_len,
1028 const u8 *ie, size_t ie_len, bool sched_scan)
1030 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1031 struct sk_buff *skb;
1034 u16 template_id_2_4 = CMD_TEMPL_CFG_PROBE_REQ_2_4;
1035 u16 template_id_5 = CMD_TEMPL_CFG_PROBE_REQ_5;
1037 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1044 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1047 (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) {
1048 template_id_2_4 = CMD_TEMPL_APP_PROBE_REQ_2_4;
1049 template_id_5 = CMD_TEMPL_APP_PROBE_REQ_5;
1052 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1053 if (band == IEEE80211_BAND_2GHZ)
1054 ret = wl1271_cmd_template_set(wl, role_id,
1056 skb->data, skb->len, 0, rate);
1058 ret = wl1271_cmd_template_set(wl, role_id,
1060 skb->data, skb->len, 0, rate);
1067 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1068 struct wl12xx_vif *wlvif,
1069 struct sk_buff *skb)
1071 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1076 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1080 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1082 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1083 if (wlvif->band == IEEE80211_BAND_2GHZ)
1084 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1085 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1086 skb->data, skb->len, 0, rate);
1088 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1089 CMD_TEMPL_CFG_PROBE_REQ_5,
1090 skb->data, skb->len, 0, rate);
1093 wl1271_error("Unable to set ap probe request template.");
1099 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1103 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1104 struct sk_buff *skb;
1105 struct wl12xx_arp_rsp_template *tmpl;
1106 struct ieee80211_hdr_3addr *hdr;
1107 struct arphdr *arp_hdr;
1109 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
1110 WL1271_EXTRA_SPACE_MAX);
1112 wl1271_error("failed to allocate buffer for arp rsp template");
1116 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
1118 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
1119 memset(tmpl, 0, sizeof(*tmpl));
1122 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1123 tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
1126 arp_hdr = &tmpl->arp_hdr;
1127 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1128 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1129 arp_hdr->ar_hln = ETH_ALEN;
1130 arp_hdr->ar_pln = 4;
1131 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1134 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
1135 tmpl->sender_ip = wlvif->ip_addr;
1137 /* encryption space */
1138 switch (wlvif->encryption_type) {
1140 if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE)
1141 extra = WL1271_EXTRA_SPACE_TKIP;
1144 extra = WL1271_EXTRA_SPACE_AES;
1152 wl1271_warning("Unknown encryption type: %d",
1153 wlvif->encryption_type);
1159 u8 *space = skb_push(skb, extra);
1160 memset(space, 0, extra);
1163 /* QoS header - BE */
1165 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
1167 /* mac80211 header */
1168 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
1169 memset(hdr, 0, sizeof(*hdr));
1170 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
1172 fc |= IEEE80211_STYPE_QOS_DATA;
1174 fc |= IEEE80211_STYPE_DATA;
1175 if (wlvif->encryption_type != KEY_NONE)
1176 fc |= IEEE80211_FCTL_PROTECTED;
1178 hdr->frame_control = cpu_to_le16(fc);
1179 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1180 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1181 memset(hdr->addr3, 0xff, ETH_ALEN);
1183 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
1184 skb->data, skb->len, 0,
1191 int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1193 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1194 struct ieee80211_qos_hdr template;
1196 memset(&template, 0, sizeof(template));
1198 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1199 memcpy(template.addr2, vif->addr, ETH_ALEN);
1200 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1202 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1203 IEEE80211_STYPE_QOS_NULLFUNC |
1204 IEEE80211_FCTL_TODS);
1206 /* FIXME: not sure what priority to use here */
1207 template.qos_ctrl = cpu_to_le16(0);
1209 return wl1271_cmd_template_set(wl, wlvif->role_id,
1210 CMD_TEMPL_QOS_NULL_DATA, &template,
1211 sizeof(template), 0,
1215 int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1217 struct wl1271_cmd_set_keys *cmd;
1220 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1222 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1230 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1231 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1232 cmd->key_type = KEY_WEP;
1234 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1236 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1246 int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1247 u16 action, u8 id, u8 key_type,
1248 u8 key_size, const u8 *key, const u8 *addr,
1249 u32 tx_seq_32, u16 tx_seq_16)
1251 struct wl1271_cmd_set_keys *cmd;
1254 /* hlid might have already been deleted */
1255 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1258 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1264 cmd->hlid = wlvif->sta.hlid;
1266 if (key_type == KEY_WEP)
1267 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1268 else if (is_broadcast_ether_addr(addr))
1269 cmd->lid_key_type = BROADCAST_LID_TYPE;
1271 cmd->lid_key_type = UNICAST_LID_TYPE;
1273 cmd->key_action = cpu_to_le16(action);
1274 cmd->key_size = key_size;
1275 cmd->key_type = key_type;
1277 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1278 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1282 if (key_type == KEY_TKIP) {
1284 * We get the key in the following form:
1285 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1286 * but the target is expecting:
1287 * TKIP - RX MIC - TX MIC
1289 memcpy(cmd->key, key, 16);
1290 memcpy(cmd->key + 16, key + 24, 8);
1291 memcpy(cmd->key + 24, key + 16, 8);
1294 memcpy(cmd->key, key, key_size);
1297 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1299 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1301 wl1271_warning("could not set keys");
1312 * TODO: merge with sta/ibss into 1 set_key function.
1313 * note there are slight diffs
1315 int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1316 u16 action, u8 id, u8 key_type,
1317 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1320 struct wl1271_cmd_set_keys *cmd;
1324 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1328 if (hlid == wlvif->ap.bcast_hlid) {
1329 if (key_type == KEY_WEP)
1330 lid_type = WEP_DEFAULT_LID_TYPE;
1332 lid_type = BROADCAST_LID_TYPE;
1334 lid_type = UNICAST_LID_TYPE;
1337 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1338 " hlid: %d", (int)action, (int)id, (int)lid_type,
1339 (int)key_type, (int)hlid);
1341 cmd->lid_key_type = lid_type;
1343 cmd->key_action = cpu_to_le16(action);
1344 cmd->key_size = key_size;
1345 cmd->key_type = key_type;
1347 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1348 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1350 if (key_type == KEY_TKIP) {
1352 * We get the key in the following form:
1353 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1354 * but the target is expecting:
1355 * TKIP - RX MIC - TX MIC
1357 memcpy(cmd->key, key, 16);
1358 memcpy(cmd->key + 16, key + 24, 8);
1359 memcpy(cmd->key + 24, key + 16, 8);
1361 memcpy(cmd->key, key, key_size);
1364 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1366 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1368 wl1271_warning("could not set ap keys");
1377 int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1379 struct wl12xx_cmd_set_peer_state *cmd;
1382 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1384 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1391 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1393 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1395 wl1271_error("failed to send set peer state command");
1406 int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1407 struct ieee80211_sta *sta, u8 hlid)
1409 struct wl12xx_cmd_add_peer *cmd;
1413 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1415 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1421 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1422 cmd->bss_index = WL1271_AP_BSS_INDEX;
1423 cmd->aid = sta->aid;
1425 cmd->sp_len = sta->max_sp;
1426 cmd->wmm = sta->wme ? 1 : 0;
1428 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1429 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1430 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1431 WL1271_PSD_UPSD_TRIGGER;
1433 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1437 sta_rates = sta->supp_rates[wlvif->band];
1438 if (sta->ht_cap.ht_supported)
1440 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
1441 (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
1443 cmd->supported_rates =
1444 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1447 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1448 cmd->supported_rates, sta->uapsd_queues);
1450 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1452 wl1271_error("failed to initiate cmd add peer");
1463 int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1465 struct wl12xx_cmd_remove_peer *cmd;
1467 bool timeout = false;
1469 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1471 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1478 /* We never send a deauth, mac80211 is in charge of this */
1479 cmd->reason_opcode = 0;
1480 cmd->send_deauth_flag = 0;
1482 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1484 wl1271_error("failed to initiate cmd remove peer");
1488 ret = wl1271_cmd_wait_for_event_or_timeout(wl,
1489 PEER_REMOVE_COMPLETE_EVENT_ID,
1492 * We are ok with a timeout here. The event is sometimes not sent
1493 * due to a firmware bug. In case of another error (like SDIO timeout)
1497 wl12xx_queue_recovery_work(wl);
1506 int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1508 struct wl12xx_cmd_config_fwlog *cmd;
1511 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1513 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1519 cmd->logger_mode = wl->conf.fwlog.mode;
1520 cmd->log_severity = wl->conf.fwlog.severity;
1521 cmd->timestamp = wl->conf.fwlog.timestamp;
1522 cmd->output = wl->conf.fwlog.output;
1523 cmd->threshold = wl->conf.fwlog.threshold;
1525 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1527 wl1271_error("failed to send config firmware logger command");
1538 int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1540 struct wl12xx_cmd_start_fwlog *cmd;
1543 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1545 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1551 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1553 wl1271_error("failed to send start firmware logger command");
1564 int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1566 struct wl12xx_cmd_stop_fwlog *cmd;
1569 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1571 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1577 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1579 wl1271_error("failed to send stop firmware logger command");
1590 static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1593 struct wl12xx_cmd_roc *cmd;
1596 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1598 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1601 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1607 cmd->role_id = role_id;
1608 cmd->channel = wlvif->channel;
1609 switch (wlvif->band) {
1610 case IEEE80211_BAND_2GHZ:
1611 cmd->band = WLCORE_BAND_2_4GHZ;
1613 case IEEE80211_BAND_5GHZ:
1614 cmd->band = WLCORE_BAND_5GHZ;
1617 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1623 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1625 wl1271_error("failed to send ROC command");
1636 static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1638 struct wl12xx_cmd_croc *cmd;
1641 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1643 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1648 cmd->role_id = role_id;
1650 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1653 wl1271_error("failed to send ROC command");
1664 int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1669 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1672 is_first_roc = (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >=
1675 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1680 ret = wl1271_cmd_wait_for_event(wl,
1681 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1683 wl1271_error("cmd roc event completion error");
1688 __set_bit(role_id, wl->roc_map);
1693 int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1697 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1700 ret = wl12xx_cmd_croc(wl, role_id);
1704 __clear_bit(role_id, wl->roc_map);
1707 * Rearm the tx watchdog when removing the last ROC. This prevents
1708 * recoveries due to just finished ROCs - when Tx hasn't yet had
1709 * a chance to get out.
1711 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
1712 wl12xx_rearm_tx_watchdog_locked(wl);
1717 int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1718 struct wl12xx_vif *wlvif,
1719 struct ieee80211_channel_switch *ch_switch)
1721 struct wl12xx_cmd_channel_switch *cmd;
1724 wl1271_debug(DEBUG_ACX, "cmd channel switch");
1726 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1732 cmd->role_id = wlvif->role_id;
1733 cmd->channel = ch_switch->channel->hw_value;
1734 cmd->switch_time = ch_switch->count;
1735 cmd->stop_tx = ch_switch->block_tx;
1737 /* FIXME: control from mac80211 in the future */
1738 cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
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");
1779 /* start dev role and roc on its channel */
1780 int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1784 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1785 wlvif->bss_type == BSS_TYPE_IBSS)))
1788 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1792 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1799 wl12xx_cmd_role_stop_dev(wl, wlvif);
1804 /* croc dev hlid, and stop the role */
1805 int wl12xx_stop_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 /* flush all pending packets */
1814 ret = wlcore_tx_work_locked(wl);
1818 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1819 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1824 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);