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)
347 unsigned long timeout;
350 events_vector = kmalloc(sizeof(*events_vector), GFP_DMA);
352 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
355 if (time_after(jiffies, timeout)) {
356 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
364 /* read from both event fields */
365 wl1271_read(wl, wl->mbox_ptr[0], events_vector,
366 sizeof(*events_vector), false);
367 event = *events_vector & mask;
368 wl1271_read(wl, wl->mbox_ptr[1], events_vector,
369 sizeof(*events_vector), false);
370 event |= *events_vector & mask;
374 kfree(events_vector);
378 static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
382 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
384 wl12xx_queue_recovery_work(wl);
391 int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
394 struct wl12xx_cmd_role_enable *cmd;
397 wl1271_debug(DEBUG_CMD, "cmd role enable");
399 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
402 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
409 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
410 if (cmd->role_id >= WL12XX_MAX_ROLES) {
415 memcpy(cmd->mac_address, addr, ETH_ALEN);
416 cmd->role_type = role_type;
418 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
420 wl1271_error("failed to initiate cmd role enable");
424 __set_bit(cmd->role_id, wl->roles_map);
425 *role_id = cmd->role_id;
434 int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
436 struct wl12xx_cmd_role_disable *cmd;
439 wl1271_debug(DEBUG_CMD, "cmd role disable");
441 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
444 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
449 cmd->role_id = *role_id;
451 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
453 wl1271_error("failed to initiate cmd role disable");
457 __clear_bit(*role_id, wl->roles_map);
458 *role_id = WL12XX_INVALID_ROLE_ID;
467 int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
470 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
471 if (link >= WL12XX_MAX_LINKS)
474 /* these bits are used by op_tx */
475 spin_lock_irqsave(&wl->wl_lock, flags);
476 __set_bit(link, wl->links_map);
477 __set_bit(link, wlvif->links_map);
478 spin_unlock_irqrestore(&wl->wl_lock, flags);
483 void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
487 if (*hlid == WL12XX_INVALID_LINK_ID)
490 /* these bits are used by op_tx */
491 spin_lock_irqsave(&wl->wl_lock, flags);
492 __clear_bit(*hlid, wl->links_map);
493 __clear_bit(*hlid, wlvif->links_map);
494 spin_unlock_irqrestore(&wl->wl_lock, flags);
497 * At this point op_tx() will not add more packets to the queues. We
500 wl1271_tx_reset_link_queues(wl, *hlid);
502 *hlid = WL12XX_INVALID_LINK_ID;
505 static int wl12xx_get_new_session_id(struct wl1271 *wl,
506 struct wl12xx_vif *wlvif)
508 if (wlvif->session_counter >= SESSION_COUNTER_MAX)
509 wlvif->session_counter = 0;
511 wlvif->session_counter++;
513 return wlvif->session_counter;
516 static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
517 struct wl12xx_vif *wlvif)
519 struct wl12xx_cmd_role_start *cmd;
522 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
528 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
530 cmd->role_id = wlvif->dev_role_id;
531 if (wlvif->band == IEEE80211_BAND_5GHZ)
532 cmd->band = WL12XX_BAND_5GHZ;
533 cmd->channel = wlvif->channel;
535 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
536 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
540 cmd->device.hlid = wlvif->dev_hlid;
541 cmd->device.session = wl12xx_get_new_session_id(wl, wlvif);
543 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
544 cmd->role_id, cmd->device.hlid, cmd->device.session);
546 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
548 wl1271_error("failed to initiate cmd role enable");
555 /* clear links on error */
556 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
565 static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
566 struct wl12xx_vif *wlvif)
568 struct wl12xx_cmd_role_stop *cmd;
571 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
574 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
580 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
582 cmd->role_id = wlvif->dev_role_id;
583 cmd->disc_type = DISCONNECT_IMMEDIATE;
584 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
586 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
588 wl1271_error("failed to initiate cmd role stop");
592 ret = wl1271_cmd_wait_for_event(wl, ROLE_STOP_COMPLETE_EVENT_ID);
594 wl1271_error("cmd role stop dev event completion error");
598 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
607 int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
609 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
610 struct wl12xx_cmd_role_start *cmd;
613 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
619 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
621 cmd->role_id = wlvif->role_id;
622 if (wlvif->band == IEEE80211_BAND_5GHZ)
623 cmd->band = WL12XX_BAND_5GHZ;
624 cmd->channel = wlvif->channel;
625 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
626 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
627 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
628 cmd->sta.ssid_len = wlvif->ssid_len;
629 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
630 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
631 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
633 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
634 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
638 cmd->sta.hlid = wlvif->sta.hlid;
639 cmd->sta.session = wl12xx_get_new_session_id(wl, wlvif);
640 cmd->sta.remote_rates = cpu_to_le32(wlvif->rate_set);
642 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
643 "basic_rate_set: 0x%x, remote_rates: 0x%x",
644 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
645 wlvif->basic_rate_set, wlvif->rate_set);
647 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
649 wl1271_error("failed to initiate cmd role start sta");
656 /* clear links on error. */
657 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
666 /* use this function to stop ibss as well */
667 int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
669 struct wl12xx_cmd_role_stop *cmd;
672 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
675 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
681 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
683 cmd->role_id = wlvif->role_id;
684 cmd->disc_type = DISCONNECT_IMMEDIATE;
685 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
687 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
689 wl1271_error("failed to initiate cmd role stop sta");
693 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
702 int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
704 struct wl12xx_cmd_role_start *cmd;
705 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
706 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
709 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
711 /* trying to use hidden SSID with an old hostapd version */
712 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
713 wl1271_error("got a null SSID from beacon/bss");
718 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
724 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
728 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
730 goto out_free_global;
732 cmd->role_id = wlvif->role_id;
733 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
734 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
735 cmd->ap.global_hlid = wlvif->ap.global_hlid;
736 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
737 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
738 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
739 cmd->ap.dtim_interval = bss_conf->dtim_period;
740 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
741 /* FIXME: Change when adding DFS */
742 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
743 cmd->channel = wlvif->channel;
745 if (!bss_conf->hidden_ssid) {
746 /* take the SSID from the beacon for backward compatibility */
747 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
748 cmd->ap.ssid_len = wlvif->ssid_len;
749 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
751 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
752 cmd->ap.ssid_len = bss_conf->ssid_len;
753 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
756 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
758 switch (wlvif->band) {
759 case IEEE80211_BAND_2GHZ:
760 cmd->band = RADIO_BAND_2_4GHZ;
762 case IEEE80211_BAND_5GHZ:
763 cmd->band = RADIO_BAND_5GHZ;
766 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
767 cmd->band = RADIO_BAND_2_4GHZ;
771 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
773 wl1271_error("failed to initiate cmd role start ap");
780 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
783 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
792 int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
794 struct wl12xx_cmd_role_stop *cmd;
797 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
803 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
805 cmd->role_id = wlvif->role_id;
807 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
809 wl1271_error("failed to initiate cmd role stop ap");
813 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
814 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
823 int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
825 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
826 struct wl12xx_cmd_role_start *cmd;
827 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
830 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
836 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
838 cmd->role_id = wlvif->role_id;
839 if (wlvif->band == IEEE80211_BAND_5GHZ)
840 cmd->band = WL12XX_BAND_5GHZ;
841 cmd->channel = wlvif->channel;
842 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
843 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
844 cmd->ibss.dtim_interval = bss_conf->dtim_period;
845 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
846 cmd->ibss.ssid_len = wlvif->ssid_len;
847 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
848 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
849 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
851 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
852 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
856 cmd->ibss.hlid = wlvif->sta.hlid;
857 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
859 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
860 "basic_rate_set: 0x%x, remote_rates: 0x%x",
861 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
862 wlvif->basic_rate_set, wlvif->rate_set);
864 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
865 vif->bss_conf.bssid);
867 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
869 wl1271_error("failed to initiate cmd role enable");
876 /* clear links on error. */
877 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
888 * send test command to firmware
891 * @buf: buffer containing the command, with all headers, must work with dma
892 * @len: length of the buffer
893 * @answer: is answer needed
895 int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
900 wl1271_debug(DEBUG_CMD, "cmd test");
905 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
908 wl1271_warning("TEST command failed");
916 * read acx from firmware
920 * @buf: buffer for the response, including all headers, must work with dma
921 * @len: length of buf
923 int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
925 struct acx_header *acx = buf;
928 wl1271_debug(DEBUG_CMD, "cmd interrogate");
930 acx->id = cpu_to_le16(id);
932 /* payload length, does not include any headers */
933 acx->len = cpu_to_le16(len - sizeof(*acx));
935 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
937 wl1271_error("INTERROGATE command failed");
943 * write acx value to firmware
947 * @buf: buffer containing acx, including all headers, must work with dma
948 * @len: length of buf
950 int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
952 struct acx_header *acx = buf;
955 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
957 acx->id = cpu_to_le16(id);
959 /* payload length, does not include any headers */
960 acx->len = cpu_to_le16(len - sizeof(*acx));
962 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
964 wl1271_warning("CONFIGURE command NOK");
971 int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
973 struct cmd_enabledisable_path *cmd;
977 wl1271_debug(DEBUG_CMD, "cmd data path");
979 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
985 /* the channel here is only used for calibration, so hardcoded to 1 */
989 cmd_rx = CMD_ENABLE_RX;
990 cmd_tx = CMD_ENABLE_TX;
992 cmd_rx = CMD_DISABLE_RX;
993 cmd_tx = CMD_DISABLE_TX;
996 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
998 wl1271_error("rx %s cmd for channel %d failed",
999 enable ? "start" : "stop", cmd->channel);
1003 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
1004 enable ? "start" : "stop", cmd->channel);
1006 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
1008 wl1271_error("tx %s cmd for channel %d failed",
1009 enable ? "start" : "stop", cmd->channel);
1013 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
1014 enable ? "start" : "stop", cmd->channel);
1021 int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1022 u8 ps_mode, u16 auto_ps_timeout)
1024 struct wl1271_cmd_ps_params *ps_params = NULL;
1027 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
1029 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
1035 ps_params->role_id = wlvif->role_id;
1036 ps_params->ps_mode = ps_mode;
1037 ps_params->auto_ps_timeout = auto_ps_timeout;
1039 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
1040 sizeof(*ps_params), 0);
1042 wl1271_error("cmd set_ps_mode failed");
1051 int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
1052 u16 template_id, void *buf, size_t buf_len,
1053 int index, u32 rates)
1055 struct wl1271_cmd_template_set *cmd;
1058 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
1059 template_id, role_id);
1061 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
1062 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
1064 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1070 /* during initialization wlvif is NULL */
1071 cmd->role_id = role_id;
1072 cmd->len = cpu_to_le16(buf_len);
1073 cmd->template_type = template_id;
1074 cmd->enabled_rates = cpu_to_le32(rates);
1075 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
1076 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
1080 memcpy(cmd->template_data, buf, buf_len);
1082 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
1084 wl1271_warning("cmd set_template failed: %d", ret);
1095 int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1097 struct sk_buff *skb = NULL;
1103 if (wlvif->bss_type == BSS_TYPE_IBSS) {
1104 size = sizeof(struct wl12xx_null_data_template);
1107 skb = ieee80211_nullfunc_get(wl->hw,
1108 wl12xx_wlvif_to_vif(wlvif));
1115 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1116 CMD_TEMPL_NULL_DATA, ptr, size, 0,
1122 wl1271_warning("cmd buld null data failed %d", ret);
1128 int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1129 struct wl12xx_vif *wlvif)
1131 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1132 struct sk_buff *skb = NULL;
1135 skb = ieee80211_nullfunc_get(wl->hw, vif);
1139 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
1140 skb->data, skb->len,
1141 CMD_TEMPL_KLV_IDX_NULL_DATA,
1147 wl1271_warning("cmd build klv null data failed %d", ret);
1153 int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1156 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1157 struct sk_buff *skb;
1160 skb = ieee80211_pspoll_get(wl->hw, vif);
1164 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1165 CMD_TEMPL_PS_POLL, skb->data,
1166 skb->len, 0, wlvif->basic_rate_set);
1173 int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1174 u8 role_id, u8 band,
1175 const u8 *ssid, size_t ssid_len,
1176 const u8 *ie, size_t ie_len)
1178 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1179 struct sk_buff *skb;
1183 skb = ieee80211_probereq_get(wl->hw, vif, ssid, ssid_len,
1190 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
1192 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
1193 if (band == IEEE80211_BAND_2GHZ)
1194 ret = wl1271_cmd_template_set(wl, role_id,
1195 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1196 skb->data, skb->len, 0, rate);
1198 ret = wl1271_cmd_template_set(wl, role_id,
1199 CMD_TEMPL_CFG_PROBE_REQ_5,
1200 skb->data, skb->len, 0, rate);
1207 struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1208 struct wl12xx_vif *wlvif,
1209 struct sk_buff *skb)
1211 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1216 skb = ieee80211_ap_probereq_get(wl->hw, vif);
1220 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1222 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
1223 if (wlvif->band == IEEE80211_BAND_2GHZ)
1224 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1225 CMD_TEMPL_CFG_PROBE_REQ_2_4,
1226 skb->data, skb->len, 0, rate);
1228 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1229 CMD_TEMPL_CFG_PROBE_REQ_5,
1230 skb->data, skb->len, 0, rate);
1233 wl1271_error("Unable to set ap probe request template.");
1239 int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1243 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
1244 struct sk_buff *skb;
1245 struct wl12xx_arp_rsp_template *tmpl;
1246 struct ieee80211_hdr_3addr *hdr;
1247 struct arphdr *arp_hdr;
1249 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
1250 WL1271_EXTRA_SPACE_MAX);
1252 wl1271_error("failed to allocate buffer for arp rsp template");
1256 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
1258 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
1259 memset(tmpl, 0, sizeof(tmpl));
1262 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1263 tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
1266 arp_hdr = &tmpl->arp_hdr;
1267 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1268 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
1269 arp_hdr->ar_hln = ETH_ALEN;
1270 arp_hdr->ar_pln = 4;
1271 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
1274 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
1275 tmpl->sender_ip = wlvif->ip_addr;
1277 /* encryption space */
1278 switch (wlvif->encryption_type) {
1280 extra = WL1271_EXTRA_SPACE_TKIP;
1283 extra = WL1271_EXTRA_SPACE_AES;
1291 wl1271_warning("Unknown encryption type: %d",
1292 wlvif->encryption_type);
1298 u8 *space = skb_push(skb, extra);
1299 memset(space, 0, extra);
1302 /* QoS header - BE */
1304 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
1306 /* mac80211 header */
1307 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
1308 memset(hdr, 0, sizeof(hdr));
1309 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
1311 fc |= IEEE80211_STYPE_QOS_DATA;
1313 fc |= IEEE80211_STYPE_DATA;
1314 if (wlvif->encryption_type != KEY_NONE)
1315 fc |= IEEE80211_FCTL_PROTECTED;
1317 hdr->frame_control = cpu_to_le16(fc);
1318 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1319 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
1320 memset(hdr->addr3, 0xff, ETH_ALEN);
1322 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
1323 skb->data, skb->len, 0,
1330 int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1332 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1333 struct ieee80211_qos_hdr template;
1335 memset(&template, 0, sizeof(template));
1337 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
1338 memcpy(template.addr2, vif->addr, ETH_ALEN);
1339 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
1341 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1342 IEEE80211_STYPE_QOS_NULLFUNC |
1343 IEEE80211_FCTL_TODS);
1345 /* FIXME: not sure what priority to use here */
1346 template.qos_ctrl = cpu_to_le16(0);
1348 return wl1271_cmd_template_set(wl, wlvif->role_id,
1349 CMD_TEMPL_QOS_NULL_DATA, &template,
1350 sizeof(template), 0,
1354 int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
1356 struct wl1271_cmd_set_keys *cmd;
1359 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1361 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1369 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1370 cmd->key_action = cpu_to_le16(KEY_SET_ID);
1371 cmd->key_type = KEY_WEP;
1373 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1375 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1385 int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1386 u16 action, u8 id, u8 key_type,
1387 u8 key_size, const u8 *key, const u8 *addr,
1388 u32 tx_seq_32, u16 tx_seq_16)
1390 struct wl1271_cmd_set_keys *cmd;
1393 /* hlid might have already been deleted */
1394 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
1397 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1403 cmd->hlid = wlvif->sta.hlid;
1405 if (key_type == KEY_WEP)
1406 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1407 else if (is_broadcast_ether_addr(addr))
1408 cmd->lid_key_type = BROADCAST_LID_TYPE;
1410 cmd->lid_key_type = UNICAST_LID_TYPE;
1412 cmd->key_action = cpu_to_le16(action);
1413 cmd->key_size = key_size;
1414 cmd->key_type = key_type;
1416 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1417 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1421 if (key_type == KEY_TKIP) {
1423 * We get the key in the following form:
1424 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1425 * but the target is expecting:
1426 * TKIP - RX MIC - TX MIC
1428 memcpy(cmd->key, key, 16);
1429 memcpy(cmd->key + 16, key + 24, 8);
1430 memcpy(cmd->key + 24, key + 16, 8);
1433 memcpy(cmd->key, key, key_size);
1436 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1438 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1440 wl1271_warning("could not set keys");
1451 * TODO: merge with sta/ibss into 1 set_key function.
1452 * note there are slight diffs
1454 int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1455 u16 action, u8 id, u8 key_type,
1456 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1459 struct wl1271_cmd_set_keys *cmd;
1463 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1467 if (hlid == wlvif->ap.bcast_hlid) {
1468 if (key_type == KEY_WEP)
1469 lid_type = WEP_DEFAULT_LID_TYPE;
1471 lid_type = BROADCAST_LID_TYPE;
1473 lid_type = UNICAST_LID_TYPE;
1476 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1477 " hlid: %d", (int)action, (int)id, (int)lid_type,
1478 (int)key_type, (int)hlid);
1480 cmd->lid_key_type = lid_type;
1482 cmd->key_action = cpu_to_le16(action);
1483 cmd->key_size = key_size;
1484 cmd->key_type = key_type;
1486 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1487 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1489 if (key_type == KEY_TKIP) {
1491 * We get the key in the following form:
1492 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1493 * but the target is expecting:
1494 * TKIP - RX MIC - TX MIC
1496 memcpy(cmd->key, key, 16);
1497 memcpy(cmd->key + 16, key + 24, 8);
1498 memcpy(cmd->key + 24, key + 16, 8);
1500 memcpy(cmd->key, key, key_size);
1503 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1505 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1507 wl1271_warning("could not set ap keys");
1516 int wl12xx_cmd_set_peer_state(struct wl1271 *wl, u8 hlid)
1518 struct wl12xx_cmd_set_peer_state *cmd;
1521 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
1523 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1530 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1532 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
1534 wl1271_error("failed to send set peer state command");
1545 int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1546 struct ieee80211_sta *sta, u8 hlid)
1548 struct wl12xx_cmd_add_peer *cmd;
1552 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
1554 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1560 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1561 cmd->bss_index = WL1271_AP_BSS_INDEX;
1562 cmd->aid = sta->aid;
1564 cmd->sp_len = sta->max_sp;
1565 cmd->wmm = sta->wme ? 1 : 0;
1567 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1568 if (sta->wme && (sta->uapsd_queues & BIT(i)))
1569 cmd->psd_type[i] = WL1271_PSD_UPSD_TRIGGER;
1571 cmd->psd_type[i] = WL1271_PSD_LEGACY;
1573 sta_rates = sta->supp_rates[wlvif->band];
1574 if (sta->ht_cap.ht_supported)
1575 sta_rates |= sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET;
1577 cmd->supported_rates =
1578 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
1581 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1582 cmd->supported_rates, sta->uapsd_queues);
1584 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
1586 wl1271_error("failed to initiate cmd add peer");
1597 int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
1599 struct wl12xx_cmd_remove_peer *cmd;
1602 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
1604 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1611 /* We never send a deauth, mac80211 is in charge of this */
1612 cmd->reason_opcode = 0;
1613 cmd->send_deauth_flag = 0;
1615 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
1617 wl1271_error("failed to initiate cmd remove peer");
1622 * We are ok with a timeout here. The event is sometimes not sent
1623 * due to a firmware bug.
1625 wl1271_cmd_wait_for_event_or_timeout(wl,
1626 PEER_REMOVE_COMPLETE_EVENT_ID);
1635 int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1637 struct wl12xx_cmd_config_fwlog *cmd;
1640 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1642 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1648 cmd->logger_mode = wl->conf.fwlog.mode;
1649 cmd->log_severity = wl->conf.fwlog.severity;
1650 cmd->timestamp = wl->conf.fwlog.timestamp;
1651 cmd->output = wl->conf.fwlog.output;
1652 cmd->threshold = wl->conf.fwlog.threshold;
1654 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1656 wl1271_error("failed to send config firmware logger command");
1667 int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1669 struct wl12xx_cmd_start_fwlog *cmd;
1672 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1674 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1680 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1682 wl1271_error("failed to send start firmware logger command");
1693 int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1695 struct wl12xx_cmd_stop_fwlog *cmd;
1698 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1700 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1706 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1708 wl1271_error("failed to send stop firmware logger command");
1719 static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1722 struct wl12xx_cmd_roc *cmd;
1725 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wlvif->channel, role_id);
1727 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1730 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1736 cmd->role_id = role_id;
1737 cmd->channel = wlvif->channel;
1738 switch (wlvif->band) {
1739 case IEEE80211_BAND_2GHZ:
1740 cmd->band = RADIO_BAND_2_4GHZ;
1742 case IEEE80211_BAND_5GHZ:
1743 cmd->band = RADIO_BAND_5GHZ;
1746 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
1752 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1754 wl1271_error("failed to send ROC command");
1765 static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1767 struct wl12xx_cmd_croc *cmd;
1770 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1772 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1777 cmd->role_id = role_id;
1779 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1782 wl1271_error("failed to send ROC command");
1793 int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id)
1797 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1800 ret = wl12xx_cmd_roc(wl, wlvif, role_id);
1804 ret = wl1271_cmd_wait_for_event(wl,
1805 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1807 wl1271_error("cmd roc event completion error");
1811 __set_bit(role_id, wl->roc_map);
1816 int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1820 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1823 ret = wl12xx_cmd_croc(wl, role_id);
1827 __clear_bit(role_id, wl->roc_map);
1830 * Rearm the tx watchdog when removing the last ROC. This prevents
1831 * recoveries due to just finished ROCs - when Tx hasn't yet had
1832 * a chance to get out.
1834 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
1835 wl12xx_rearm_tx_watchdog_locked(wl);
1840 int wl12xx_cmd_channel_switch(struct wl1271 *wl,
1841 struct wl12xx_vif *wlvif,
1842 struct ieee80211_channel_switch *ch_switch)
1844 struct wl12xx_cmd_channel_switch *cmd;
1847 wl1271_debug(DEBUG_ACX, "cmd channel switch");
1849 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1855 cmd->role_id = wlvif->role_id;
1856 cmd->channel = ch_switch->channel->hw_value;
1857 cmd->switch_time = ch_switch->count;
1858 cmd->stop_tx = ch_switch->block_tx;
1860 /* FIXME: control from mac80211 in the future */
1861 cmd->post_switch_tx_disable = 0; /* Enable TX on the target channel */
1863 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
1865 wl1271_error("failed to send channel switch command");
1876 int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl)
1878 struct wl12xx_cmd_stop_channel_switch *cmd;
1881 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1883 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1889 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
1891 wl1271_error("failed to stop channel switch command");
1902 /* start dev role and roc on its channel */
1903 int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1907 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1908 wlvif->bss_type == BSS_TYPE_IBSS)))
1911 ret = wl12xx_cmd_role_start_dev(wl, wlvif);
1915 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id);
1922 wl12xx_cmd_role_stop_dev(wl, wlvif);
1927 /* croc dev hlid, and stop the role */
1928 int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1932 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
1933 wlvif->bss_type == BSS_TYPE_IBSS)))
1936 /* flush all pending packets */
1937 wl1271_tx_work_locked(wl);
1939 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
1940 ret = wl12xx_croc(wl, wlvif->dev_role_id);
1945 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);