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)
463 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
464 if (link >= WL12XX_MAX_LINKS)
467 /* these bits are used by op_tx */
468 spin_lock_irqsave(&wl->wl_lock, flags);
469 __set_bit(link, wl->links_map);
470 __set_bit(link, wlvif->links_map);
471 spin_unlock_irqrestore(&wl->wl_lock, flags);
476 void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
480 if (*hlid == WL12XX_INVALID_LINK_ID)
483 /* these bits are used by op_tx */
484 spin_lock_irqsave(&wl->wl_lock, flags);
485 __clear_bit(*hlid, wl->links_map);
486 __clear_bit(*hlid, wlvif->links_map);
487 spin_unlock_irqrestore(&wl->wl_lock, flags);
490 * At this point op_tx() will not add more packets to the queues. We
493 wl1271_tx_reset_link_queues(wl, *hlid);
495 *hlid = WL12XX_INVALID_LINK_ID;
498 static int wl12xx_get_new_session_id(struct wl1271 *wl,
499 struct wl12xx_vif *wlvif)
501 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
502 wlvif->session_counter = 0;
504 wlvif->session_counter++;
506 return wlvif->session_counter;
509 static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
510 struct wl12xx_vif *wlvif)
512 struct wl12xx_cmd_role_start *cmd;
515 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
521 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
523 cmd->role_id = wlvif->dev_role_id;
524 if (wlvif->band == IEEE80211_BAND_5GHZ)
525 cmd->band = WL12XX_BAND_5GHZ;
526 cmd->channel = wlvif->channel;
528 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
529 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
533 cmd->device.hlid = wlvif->dev_hlid;
534 cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
536 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
537 cmd->role_id, cmd->device.hlid, cmd->device.session);
539 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
541 wl1271_error("failed to initiate cmd role enable");
548 /* clear links on error */
549 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
558 static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
559 struct wl12xx_vif *wlvif)
561 struct wl12xx_cmd_role_stop *cmd;
564 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
567 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
573 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
575 cmd->role_id = wlvif->dev_role_id;
576 cmd->disc_type = DISCONNECT_IMMEDIATE;
577 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
579 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
581 wl1271_error("failed to initiate cmd role stop");
585 ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
587 wl1271_error("cmd role stop dev event completion error");
591 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
600 int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
602 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
603 struct wl12xx_cmd_role_start *cmd;
606 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
612 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
614 cmd->role_id = wlvif->role_id;
615 if (wlvif->band == IEEE80211_BAND_5GHZ)
616 cmd->band = WL12XX_BAND_5GHZ;
617 cmd->channel = wlvif->channel;
618 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
619 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
620 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
621 cmd->sta.ssid_len = wlvif->ssid_len;
622 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
623 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
624 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
626 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
627 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
631 cmd->sta.hlid = wlvif->sta.hlid;
632 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
633 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
635 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
636 "basic_rate_set: 0x%x, remote_rates: 0x%x",
637 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
638 wlvif->basic_rate_set, wlvif->rate_set);
640 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
642 wl1271_error("failed to initiate cmd role start sta");
649 /* clear links on error. */
650 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
659 /* use this function to stop ibss as well */
660 int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
662 struct wl12xx_cmd_role_stop *cmd;
665 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
668 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
674 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
676 cmd->role_id = wlvif->role_id;
677 cmd->disc_type = DISCONNECT_IMMEDIATE;
678 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
680 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
682 wl1271_error("failed to initiate cmd role stop sta");
686 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
695 int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
697 struct wl12xx_cmd_role_start *cmd;
698 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
699 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
702 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
704 /* trying to use hidden SSID with an old hostapd version */
705 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
706 wl1271_error("got a null SSID from beacon/bss");
711 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
717 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
721 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
723 goto out_free_global;
725 cmd->role_id = wlvif->role_id;
726 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
727 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
728 cmd->ap.global_hlid = wlvif->ap.global_hlid;
729 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
730 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
731 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
732 cmd->ap.dtim_interval = bss_conf->dtim_period;
733 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
734 /* FIXME: Change when adding DFS */
735 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
736 cmd->channel = wlvif->channel;
738 if (!bss_conf->hidden_ssid) {
739 /* take the SSID from the beacon for backward compatibility */
740 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
741 cmd->ap.ssid_len = wlvif->ssid_len;
742 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
744 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
745 cmd->ap.ssid_len = bss_conf->ssid_len;
746 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
749 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
751 switch (wlvif->band) {
752 case IEEE80211_BAND_2GHZ:
753 cmd->band = RADIO_BAND_2_4GHZ;
755 case IEEE80211_BAND_5GHZ:
756 cmd->band = RADIO_BAND_5GHZ;
759 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
760 cmd->band = RADIO_BAND_2_4GHZ;
764 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
766 wl1271_error("failed to initiate cmd role start ap");
773 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
776 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
785 int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
787 struct wl12xx_cmd_role_stop *cmd;
790 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
796 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
798 cmd->role_id = wlvif->role_id;
800 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
802 wl1271_error("failed to initiate cmd role stop ap");
806 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
807 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
816 int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
818 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
819 struct wl12xx_cmd_role_start *cmd;
820 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
823 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
829 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
831 cmd->role_id = wlvif->role_id;
832 if (wlvif->band == IEEE80211_BAND_5GHZ)
833 cmd->band = WL12XX_BAND_5GHZ;
834 cmd->channel = wlvif->channel;
835 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
836 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
837 cmd->ibss.dtim_interval = bss_conf->dtim_period;
838 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
839 cmd->ibss.ssid_len = wlvif->ssid_len;
840 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
841 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
842 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
844 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
845 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
849 cmd->ibss.hlid = wlvif->sta.hlid;
850 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
852 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
853 "basic_rate_set: 0x%x, remote_rates: 0x%x",
854 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
855 wlvif->basic_rate_set, wlvif->rate_set);
857 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
858 vif->bss_conf.bssid);
860 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
862 wl1271_error("failed to initiate cmd role enable");
869 /* clear links on error. */
870 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
881 * send test command to firmware
884 * @buf: buffer containing the command, with all headers, must work with dma
885 * @len: length of the buffer
886 * @answer: is answer needed
888 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
893 wl1271_debug(DEBUG_CMD, "cmd test");
898 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
901 wl1271_warning("TEST command failed");
909 * read acx from firmware
913 * @buf: buffer for the response, including all headers, must work with dma
914 * @len: length of buf
916 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
918 struct acx_header *acx = buf;
921 wl1271_debug(DEBUG_CMD, "cmd interrogate");
923 acx->id = cpu_to_le16(id);
925 /* payload length, does not include any headers */
926 acx->len = cpu_to_le16(len - sizeof(*acx));
928 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
930 wl1271_error("INTERROGATE command failed");
936 * write acx value to firmware
940 * @buf: buffer containing acx, including all headers, must work with dma
941 * @len: length of buf
943 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
945 struct acx_header *acx = buf;
948 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
950 acx->id = cpu_to_le16(id);
952 /* payload length, does not include any headers */
953 acx->len = cpu_to_le16(len - sizeof(*acx));
955 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
957 wl1271_warning("CONFIGURE command NOK");
964 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
966 struct cmd_enabledisable_path *cmd;
970 wl1271_debug(DEBUG_CMD, "cmd data path");
972 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
978 /* the channel here is only used for calibration, so hardcoded to 1 */
982 cmd_rx = CMD_ENABLE_RX;
983 cmd_tx = CMD_ENABLE_TX;
985 cmd_rx = CMD_DISABLE_RX;
986 cmd_tx = CMD_DISABLE_TX;
989 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
991 wl1271_error("rx %s cmd for channel %d failed",
992 enable ? "start" : "stop", cmd->channel);
996 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
997 enable ? "start" : "stop", cmd->channel);
999 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
1001 wl1271_error("tx %s cmd for channel %d failed",
1002 enable ? "start" : "stop", cmd->channel);
1006 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
1007 enable ? "start" : "stop", cmd->channel);
1014 int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1015 u8 ps_mode, u16 auto_ps_timeout)
1017 struct wl1271_cmd_ps_params *ps_params = NULL;
1020 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
1022 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
1028 ps_params->role_id = wlvif->role_id;
1029 ps_params->ps_mode = ps_mode;
1030 ps_params->auto_ps_timeout = auto_ps_timeout;
1032 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
1033 sizeof(*ps_params), 0);
1035 wl1271_error("cmd set_ps_mode failed");
1044 int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
1045 u16 template_id, void *buf, size_t buf_len,
1046 int index, u32 rates)
1048 struct wl1271_cmd_template_set *cmd;
1051 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
1052 template_id, role_id);
1054 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
1055 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
1057 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1063 /* during initialization wlvif is NULL */
1064 cmd->role_id = role_id;
1065 cmd->len = cpu_to_le16(buf_len);
1066 cmd->template_type = template_id;
1067 cmd->enabled_rates = cpu_to_le32(rates);
1068 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
1069 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
1073 memcpy(cmd->template_data, buf, buf_len);
1075 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
1077 wl1271_warning("cmd set_template failed: %d", ret);
1088 int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1090 struct sk_buff *skb = NULL;
1096 if (wlvif->bss_type == BSS_TYPE_IBSS) {
1097 size = sizeof(struct wl12xx_null_data_template);
1100 skb = ieee80211_nullfunc_get(wl->hw,
1101 wl12xx_wlvif_to_vif(wlvif));
1108 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1109 CMD_TEMPL_NULL_DATA, ptr, size, 0,
1115 wl1271_warning("cmd buld null data failed %d", ret);
1121 int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1122 struct wl12xx_vif *wlvif)
1124 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1125 struct sk_buff *skb = NULL;
1128 skb = ieee80211_nullfunc_get(wl->hw, vif);
1132 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
1133 skb->data, skb->len,
1134 CMD_TEMPL_KLV_IDX_NULL_DATA,
1140 wl1271_warning("cmd build klv null data failed %d", ret);
1146 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1149 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1150 struct sk_buff *skb;
1153 skb = ieee80211_pspoll_get(wl->hw, vif);
1157 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1158 CMD_TEMPL_PS_POLL, skb->data,
1159 skb->len, 0, wlvif->basic_rate_set);
1166 int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1167 u8 role_id, u8 band,
1168 const u8 *ssid, size_t ssid_len,
1169 const u8 *ie, size_t ie_len)
1171 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1172 struct sk_buff *skb;
1176 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1183 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1185 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1186 if (band == IEEE80211_BAND_2GHZ)
1187 ret = wl1271_cmd_template_set(wl, role_id,
1188 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1189 skb->data, skb->len, 0, rate);
1191 ret = wl1271_cmd_template_set(wl, role_id,
1192 CMD_TEMPL_CFG_PROBE_REQ_5,
1193 skb->data, skb->len, 0, rate);
1200 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1201 struct wl12xx_vif *wlvif,
1202 struct sk_buff *skb)
1204 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1209 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1213 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1215 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1216 if (wlvif->band == IEEE80211_BAND_2GHZ)
1217 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1218 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1219 skb->data, skb->len, 0, rate);
1221 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1222 CMD_TEMPL_CFG_PROBE_REQ_5,
1223 skb->data, skb->len, 0, rate);
1226 wl1271_error("Unable to set ap probe request template.");
1232 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1236 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1237 struct sk_buff *skb;
1238 struct wl12xx_arp_rsp_template *tmpl;
1239 struct ieee80211_hdr_3addr *hdr;
1240 struct arphdr *arp_hdr;
1242 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
1243 WL1271_EXTRA_SPACE_MAX);
1245 wl1271_error("failed to allocate buffer for arp rsp template");
1249 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
1251 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
1252 memset(tmpl, 0, sizeof(tmpl));
1255 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1256 tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
1259 arp_hdr = &tmpl->arp_hdr;
1260 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1261 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1262 arp_hdr->ar_hln = ETH_ALEN;
1263 arp_hdr->ar_pln = 4;
1264 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1267 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
1268 tmpl->sender_ip = wlvif->ip_addr;
1270 /* encryption space */
1271 switch (wlvif->encryption_type) {
1273 extra = WL1271_EXTRA_SPACE_TKIP;
1276 extra = WL1271_EXTRA_SPACE_AES;
1284 wl1271_warning("Unknown encryption type: %d",
1285 wlvif->encryption_type);
1291 u8 *space = skb_push(skb, extra);
1292 memset(space, 0, extra);
1295 /* QoS header - BE */
1297 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
1299 /* mac80211 header */
1300 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
1301 memset(hdr, 0, sizeof(hdr));
1302 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
1304 fc |= IEEE80211_STYPE_QOS_DATA;
1306 fc |= IEEE80211_STYPE_DATA;
1307 if (wlvif->encryption_type != KEY_NONE)
1308 fc |= IEEE80211_FCTL_PROTECTED;
1310 hdr->frame_control = cpu_to_le16(fc);
1311 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1312 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1313 memset(hdr->addr3, 0xff, ETH_ALEN);
1315 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
1316 skb->data, skb->len, 0,
1323 int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1325 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1326 struct ieee80211_qos_hdr template;
1328 memset(&template, 0, sizeof(template));
1330 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1331 memcpy(template.addr2, vif->addr, ETH_ALEN);
1332 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1334 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1335 IEEE80211_STYPE_QOS_NULLFUNC |
1336 IEEE80211_FCTL_TODS);
1338 /* FIXME: not sure what priority to use here */
1339 template.qos_ctrl = cpu_to_le16(0);
1341 return wl1271_cmd_template_set(wl, wlvif->role_id,
1342 CMD_TEMPL_QOS_NULL_DATA, &template,
1343 sizeof(template), 0,
1347 int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1349 struct wl1271_cmd_set_keys *cmd;
1352 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1354 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1362 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1363 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1364 cmd->key_type = KEY_WEP;
1366 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1368 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1378 int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1379 u16 action, u8 id, u8 key_type,
1380 u8 key_size, const u8 *key, const u8 *addr,
1381 u32 tx_seq_32, u16 tx_seq_16)
1383 struct wl1271_cmd_set_keys *cmd;
1386 /* hlid might have already been deleted */
1387 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1390 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1396 cmd->hlid = wlvif->sta.hlid;
1398 if (key_type == KEY_WEP)
1399 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1400 else if (is_broadcast_ether_addr(addr))
1401 cmd->lid_key_type = BROADCAST_LID_TYPE;
1403 cmd->lid_key_type = UNICAST_LID_TYPE;
1405 cmd->key_action = cpu_to_le16(action);
1406 cmd->key_size = key_size;
1407 cmd->key_type = key_type;
1409 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1410 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1414 if (key_type == KEY_TKIP) {
1416 * We get the key in the following form:
1417 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1418 * but the target is expecting:
1419 * TKIP - RX MIC - TX MIC
1421 memcpy(cmd->key, key, 16);
1422 memcpy(cmd->key + 16, key + 24, 8);
1423 memcpy(cmd->key + 24, key + 16, 8);
1426 memcpy(cmd->key, key, key_size);
1429 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1431 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1433 wl1271_warning("could not set keys");
1444 * TODO: merge with sta/ibss into 1 set_key function.
1445 * note there are slight diffs
1447 int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1448 u16 action, u8 id, u8 key_type,
1449 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1452 struct wl1271_cmd_set_keys *cmd;
1456 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1460 if (hlid == wlvif->ap.bcast_hlid) {
1461 if (key_type == KEY_WEP)
1462 lid_type = WEP_DEFAULT_LID_TYPE;
1464 lid_type = BROADCAST_LID_TYPE;
1466 lid_type = UNICAST_LID_TYPE;
1469 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1470 " hlid: %d", (int)action, (int)id, (int)lid_type,
1471 (int)key_type, (int)hlid);
1473 cmd->lid_key_type = lid_type;
1475 cmd->key_action = cpu_to_le16(action);
1476 cmd->key_size = key_size;
1477 cmd->key_type = key_type;
1479 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1480 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1482 if (key_type == KEY_TKIP) {
1484 * We get the key in the following form:
1485 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1486 * but the target is expecting:
1487 * TKIP - RX MIC - TX MIC
1489 memcpy(cmd->key, key, 16);
1490 memcpy(cmd->key + 16, key + 24, 8);
1491 memcpy(cmd->key + 24, key + 16, 8);
1493 memcpy(cmd->key, key, key_size);
1496 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1498 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1500 wl1271_warning("could not set ap keys");
1509 int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1511 struct wl12xx_cmd_set_peer_state *cmd;
1514 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1516 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1523 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1525 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1527 wl1271_error("failed to send set peer state command");
1538 int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1539 struct ieee80211_sta *sta, u8 hlid)
1541 struct wl12xx_cmd_add_peer *cmd;
1545 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1547 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1553 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1554 cmd->bss_index = WL1271_AP_BSS_INDEX;
1555 cmd->aid = sta->aid;
1557 cmd->sp_len = sta->max_sp;
1558 cmd->wmm = sta->wme ? 1 : 0;
1560 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1561 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1562 cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
1564 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1566 sta_rates = sta->supp_rates[wlvif->band];
1567 if (sta->ht_cap.ht_supported)
1568 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1570 cmd->supported_rates =
1571 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1574 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1575 cmd->supported_rates, sta->uapsd_queues);
1577 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1579 wl1271_error("failed to initiate cmd add peer");
1590 int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1592 struct wl12xx_cmd_remove_peer *cmd;
1595 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1597 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1604 /* We never send a deauth, mac80211 is in charge of this */
1605 cmd->reason_opcode = 0;
1606 cmd->send_deauth_flag = 0;
1608 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1610 wl1271_error("failed to initiate cmd remove peer");
1615 * We are ok with a timeout here. The event is sometimes not sent
1616 * due to a firmware bug.
1618 wl1271_cmd_wait_for_event_or_timeout(wl,
1619 PEER_REMOVE_COMPLETE_EVENT_ID);
1628 int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1630 struct wl12xx_cmd_config_fwlog *cmd;
1633 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1635 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1641 cmd->logger_mode = wl->conf.fwlog.mode;
1642 cmd->log_severity = wl->conf.fwlog.severity;
1643 cmd->timestamp = wl->conf.fwlog.timestamp;
1644 cmd->output = wl->conf.fwlog.output;
1645 cmd->threshold = wl->conf.fwlog.threshold;
1647 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1649 wl1271_error("failed to send config firmware logger command");
1660 int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1662 struct wl12xx_cmd_start_fwlog *cmd;
1665 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1667 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1673 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1675 wl1271_error("failed to send start firmware logger command");
1686 int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1688 struct wl12xx_cmd_stop_fwlog *cmd;
1691 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1693 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1699 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1701 wl1271_error("failed to send stop firmware logger command");
1712 static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1715 struct wl12xx_cmd_roc *cmd;
1718 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1720 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1723 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1729 cmd->role_id = role_id;
1730 cmd->channel = wlvif->channel;
1731 switch (wlvif->band) {
1732 case IEEE80211_BAND_2GHZ:
1733 cmd->band = RADIO_BAND_2_4GHZ;
1735 case IEEE80211_BAND_5GHZ:
1736 cmd->band = RADIO_BAND_5GHZ;
1739 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1745 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1747 wl1271_error("failed to send ROC command");
1758 static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1760 struct wl12xx_cmd_croc *cmd;
1763 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1765 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1770 cmd->role_id = role_id;
1772 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1775 wl1271_error("failed to send ROC command");
1786 int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1790 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1793 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1797 ret = wl1271_cmd_wait_for_event(wl,
1798 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1800 wl1271_error("cmd roc event completion error");
1804 __set_bit(role_id, wl->roc_map);
1809 int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1813 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1816 ret = wl12xx_cmd_croc(wl, role_id);
1820 __clear_bit(role_id, wl->roc_map);
1823 * Rearm the tx watchdog when removing the last ROC. This prevents
1824 * recoveries due to just finished ROCs - when Tx hasn't yet had
1825 * a chance to get out.
1827 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
1828 wl12xx_rearm_tx_watchdog_locked(wl);
1833 int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1834 struct wl12xx_vif *wlvif,
1835 struct ieee80211_channel_switch *ch_switch)
1837 struct wl12xx_cmd_channel_switch *cmd;
1840 wl1271_debug(DEBUG_ACX, "cmd channel switch");
1842 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1848 cmd->role_id = wlvif->role_id;
1849 cmd->channel = ch_switch->channel->hw_value;
1850 cmd->switch_time = ch_switch->count;
1851 cmd->stop_tx = ch_switch->block_tx;
1853 /* FIXME: control from mac80211 in the future */
1854 cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
1856 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
1858 wl1271_error("failed to send channel switch command");
1869 int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
1871 struct wl12xx_cmd_stop_channel_switch *cmd;
1874 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1876 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1882 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
1884 wl1271_error("failed to stop channel switch command");
1895 /* start dev role and roc on its channel */
1896 int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1900 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1901 wlvif->bss_type == BSS_TYPE_IBSS)))
1904 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1908 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1915 wl12xx_cmd_role_stop_dev(wl, wlvif);
1920 /* croc dev hlid, and stop the role */
1921 int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1925 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1926 wlvif->bss_type == BSS_TYPE_IBSS)))
1929 /* flush all pending packets */
1930 wl1271_tx_work_locked(wl);
1932 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1933 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1938 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);