3 * This file is part of wl1271
5 * Copyright (C) 2008-2010 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <linux/module.h>
26 #include <linux/firmware.h>
27 #include <linux/delay.h>
28 #include <linux/spi/spi.h>
29 #include <linux/crc32.h>
30 #include <linux/etherdevice.h>
31 #include <linux/vmalloc.h>
32 #include <linux/platform_device.h>
33 #include <linux/slab.h>
34 #include <linux/wl12xx.h>
35 #include <linux/sched.h>
36 #include <linux/interrupt.h>
40 #include "wl12xx_80211.h"
53 /* TODO: remove this once the FUSE definitions are separated */
54 #include "../wl12xx/reg.h"
56 #define WL1271_BOOT_RETRIES 3
58 static struct conf_drv_settings default_conf = {
61 [CONF_SG_ACL_BT_MASTER_MIN_BR] = 10,
62 [CONF_SG_ACL_BT_MASTER_MAX_BR] = 180,
63 [CONF_SG_ACL_BT_SLAVE_MIN_BR] = 10,
64 [CONF_SG_ACL_BT_SLAVE_MAX_BR] = 180,
65 [CONF_SG_ACL_BT_MASTER_MIN_EDR] = 10,
66 [CONF_SG_ACL_BT_MASTER_MAX_EDR] = 80,
67 [CONF_SG_ACL_BT_SLAVE_MIN_EDR] = 10,
68 [CONF_SG_ACL_BT_SLAVE_MAX_EDR] = 80,
69 [CONF_SG_ACL_WLAN_PS_MASTER_BR] = 8,
70 [CONF_SG_ACL_WLAN_PS_SLAVE_BR] = 8,
71 [CONF_SG_ACL_WLAN_PS_MASTER_EDR] = 20,
72 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR] = 20,
73 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR] = 20,
74 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR] = 35,
75 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR] = 16,
76 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR] = 35,
77 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR] = 32,
78 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR] = 50,
79 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR] = 28,
80 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR] = 50,
81 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR] = 10,
82 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR] = 20,
83 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR] = 75,
84 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR] = 15,
85 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR] = 27,
86 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR] = 17,
87 /* active scan params */
88 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
89 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
90 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
91 /* passive scan params */
92 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR] = 800,
93 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR] = 200,
94 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
95 /* passive scan in dual antenna params */
96 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN] = 0,
97 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN] = 0,
98 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN] = 0,
100 [CONF_SG_STA_FORCE_PS_IN_BT_SCO] = 1,
101 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
102 [CONF_SG_BEACON_MISS_PERCENT] = 60,
103 [CONF_SG_DHCP_TIME] = 5000,
104 [CONF_SG_RXT] = 1200,
105 [CONF_SG_TXT] = 1000,
106 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
107 [CONF_SG_GENERAL_USAGE_BIT_MAP] = 3,
108 [CONF_SG_HV3_MAX_SERVED] = 6,
109 [CONF_SG_PS_POLL_TIMEOUT] = 10,
110 [CONF_SG_UPSD_TIMEOUT] = 10,
111 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD] = 2,
112 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM] = 5,
113 [CONF_SG_STA_CONNECTION_PROTECTION_TIME] = 30,
115 [CONF_AP_BEACON_MISS_TX] = 3,
116 [CONF_AP_RX_WINDOW_AFTER_BEACON] = 10,
117 [CONF_AP_BEACON_WINDOW_INTERVAL] = 2,
118 [CONF_AP_CONNECTION_PROTECTION_TIME] = 0,
119 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME] = 25,
120 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME] = 25,
121 /* CTS Diluting params */
122 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH] = 0,
123 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER] = 0,
125 .state = CONF_SG_PROTECTIVE,
128 .rx_msdu_life_time = 512000,
129 .packet_detection_threshold = 0,
130 .ps_poll_timeout = 15,
132 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
133 .rx_cca_threshold = 0,
134 .irq_blk_threshold = 0xFFFF,
135 .irq_pkt_threshold = 0,
137 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
140 .tx_energy_detection = 0,
143 .short_retry_limit = 10,
144 .long_retry_limit = 10,
167 .aifsn = CONF_TX_AIFS_PIFS,
174 .aifsn = CONF_TX_AIFS_PIFS,
178 .max_tx_retries = 100,
179 .ap_aging_period = 300,
183 .queue_id = CONF_TX_AC_BE,
184 .channel_type = CONF_CHANNEL_TYPE_EDCF,
185 .tsid = CONF_TX_AC_BE,
186 .ps_scheme = CONF_PS_SCHEME_LEGACY,
187 .ack_policy = CONF_ACK_POLICY_LEGACY,
191 .queue_id = CONF_TX_AC_BK,
192 .channel_type = CONF_CHANNEL_TYPE_EDCF,
193 .tsid = CONF_TX_AC_BK,
194 .ps_scheme = CONF_PS_SCHEME_LEGACY,
195 .ack_policy = CONF_ACK_POLICY_LEGACY,
199 .queue_id = CONF_TX_AC_VI,
200 .channel_type = CONF_CHANNEL_TYPE_EDCF,
201 .tsid = CONF_TX_AC_VI,
202 .ps_scheme = CONF_PS_SCHEME_LEGACY,
203 .ack_policy = CONF_ACK_POLICY_LEGACY,
207 .queue_id = CONF_TX_AC_VO,
208 .channel_type = CONF_CHANNEL_TYPE_EDCF,
209 .tsid = CONF_TX_AC_VO,
210 .ps_scheme = CONF_PS_SCHEME_LEGACY,
211 .ack_policy = CONF_ACK_POLICY_LEGACY,
215 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
216 .tx_compl_timeout = 700,
217 .tx_compl_threshold = 4,
218 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
219 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
220 .tmpl_short_retry_limit = 10,
221 .tmpl_long_retry_limit = 10,
222 .tx_watchdog_timeout = 5000,
225 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
226 .listen_interval = 1,
227 .suspend_wake_up_event = CONF_WAKE_UP_EVENT_N_DTIM,
228 .suspend_listen_interval = 3,
229 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
230 .bcn_filt_ie_count = 2,
233 .ie = WLAN_EID_CHANNEL_SWITCH,
234 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
237 .ie = WLAN_EID_HT_OPERATION,
238 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
241 .synch_fail_thold = 10,
242 .bss_lose_timeout = 100,
243 .beacon_rx_timeout = 10000,
244 .broadcast_timeout = 20000,
245 .rx_broadcast_in_ps = 1,
246 .ps_poll_threshold = 10,
247 .bet_enable = CONF_BET_MODE_ENABLE,
248 .bet_max_consecutive = 50,
249 .psm_entry_retries = 8,
250 .psm_exit_retries = 16,
251 .psm_entry_nullfunc_retries = 3,
252 .dynamic_ps_timeout = 200,
254 .keep_alive_interval = 55000,
255 .max_listen_interval = 20,
262 .host_clk_settling_time = 5000,
263 .host_fast_wakeup_support = false
267 .avg_weight_rssi_beacon = 20,
268 .avg_weight_rssi_data = 10,
269 .avg_weight_snr_beacon = 20,
270 .avg_weight_snr_data = 10,
273 .min_dwell_time_active = 7500,
274 .max_dwell_time_active = 30000,
275 .min_dwell_time_passive = 100000,
276 .max_dwell_time_passive = 100000,
278 .split_scan_timeout = 50000,
282 * Values are in TU/1000 but since sched scan FW command
283 * params are in TUs rounding up may occur.
285 .base_dwell_time = 7500,
286 .max_dwell_time_delta = 22500,
287 /* based on 250bits per probe @1Mbps */
288 .dwell_time_delta_per_probe = 2000,
289 /* based on 250bits per probe @6Mbps (plus a bit more) */
290 .dwell_time_delta_per_probe_5 = 350,
291 .dwell_time_passive = 100000,
292 .dwell_time_dfs = 150000,
294 .rssi_threshold = -90,
298 .tx_per_channel_power_compensation_2 = {
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 .tx_per_channel_power_compensation_5 = {
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
309 .tx_ba_win_size = 64,
310 .inactivity_timeout = 10000,
311 .tx_ba_tid_bitmap = CONF_TX_BA_ENABLED_TID_BITMAP,
317 .tx_min_block_num = 40,
319 .min_req_tx_blocks = 100,
320 .min_req_rx_blocks = 22,
327 .tx_min_block_num = 40,
329 .min_req_tx_blocks = 45,
330 .min_req_rx_blocks = 22,
336 .n_divider_fref_set_1 = 0xff, /* default */
337 .n_divider_fref_set_2 = 12,
338 .m_divider_fref_set_1 = 148,
339 .m_divider_fref_set_2 = 0xffff, /* default */
340 .coex_pll_stabilization_time = 0xffffffff, /* default */
341 .ldo_stabilization_time = 0xffff, /* default */
342 .fm_disturbed_band_margin = 0xff, /* default */
343 .swallow_clk_diff = 0xff, /* default */
352 .mode = WL12XX_FWLOG_ON_DEMAND,
355 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
356 .output = WL12XX_FWLOG_OUTPUT_HOST,
360 .rate_retry_score = 32000,
365 .inverse_curiosity_factor = 5,
367 .tx_fail_high_th = 10,
368 .per_alpha_shift = 4,
370 .per_beta1_shift = 10,
371 .per_beta2_shift = 8,
373 .rate_check_down = 12,
374 .rate_retry_policy = {
375 0x00, 0x00, 0x00, 0x00, 0x00,
376 0x00, 0x00, 0x00, 0x00, 0x00,
382 .hangover_period = 20,
384 .early_termination_mode = 1,
395 static char *fwlog_param;
396 static bool bug_on_recovery;
398 static void __wl1271_op_remove_interface(struct wl1271 *wl,
399 struct ieee80211_vif *vif,
400 bool reset_tx_queues);
401 static void wl1271_op_stop(struct ieee80211_hw *hw);
402 static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif);
404 static int wl12xx_set_authorized(struct wl1271 *wl,
405 struct wl12xx_vif *wlvif)
409 if (WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS))
412 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
415 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT, &wlvif->flags))
418 ret = wl12xx_cmd_set_peer_state(wl, wlvif->sta.hlid);
422 wl12xx_croc(wl, wlvif->role_id);
424 wl1271_info("Association completed.");
428 static int wl1271_reg_notify(struct wiphy *wiphy,
429 struct regulatory_request *request)
431 struct ieee80211_supported_band *band;
432 struct ieee80211_channel *ch;
435 band = wiphy->bands[IEEE80211_BAND_5GHZ];
436 for (i = 0; i < band->n_channels; i++) {
437 ch = &band->channels[i];
438 if (ch->flags & IEEE80211_CHAN_DISABLED)
441 if (ch->flags & IEEE80211_CHAN_RADAR)
442 ch->flags |= IEEE80211_CHAN_NO_IBSS |
443 IEEE80211_CHAN_PASSIVE_SCAN;
450 static int wl1271_set_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif,
455 /* we should hold wl->mutex */
456 ret = wl1271_acx_ps_rx_streaming(wl, wlvif, enable);
461 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
463 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags);
469 * this function is being called when the rx_streaming interval
470 * has beed changed or rx_streaming should be disabled
472 int wl1271_recalc_rx_streaming(struct wl1271 *wl, struct wl12xx_vif *wlvif)
475 int period = wl->conf.rx_streaming.interval;
477 /* don't reconfigure if rx_streaming is disabled */
478 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
481 /* reconfigure/disable according to new streaming_period */
483 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
484 (wl->conf.rx_streaming.always ||
485 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
486 ret = wl1271_set_rx_streaming(wl, wlvif, true);
488 ret = wl1271_set_rx_streaming(wl, wlvif, false);
489 /* don't cancel_work_sync since we might deadlock */
490 del_timer_sync(&wlvif->rx_streaming_timer);
496 static void wl1271_rx_streaming_enable_work(struct work_struct *work)
499 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
500 rx_streaming_enable_work);
501 struct wl1271 *wl = wlvif->wl;
503 mutex_lock(&wl->mutex);
505 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags) ||
506 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
507 (!wl->conf.rx_streaming.always &&
508 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
511 if (!wl->conf.rx_streaming.interval)
514 ret = wl1271_ps_elp_wakeup(wl);
518 ret = wl1271_set_rx_streaming(wl, wlvif, true);
522 /* stop it after some time of inactivity */
523 mod_timer(&wlvif->rx_streaming_timer,
524 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
527 wl1271_ps_elp_sleep(wl);
529 mutex_unlock(&wl->mutex);
532 static void wl1271_rx_streaming_disable_work(struct work_struct *work)
535 struct wl12xx_vif *wlvif = container_of(work, struct wl12xx_vif,
536 rx_streaming_disable_work);
537 struct wl1271 *wl = wlvif->wl;
539 mutex_lock(&wl->mutex);
541 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED, &wlvif->flags))
544 ret = wl1271_ps_elp_wakeup(wl);
548 ret = wl1271_set_rx_streaming(wl, wlvif, false);
553 wl1271_ps_elp_sleep(wl);
555 mutex_unlock(&wl->mutex);
558 static void wl1271_rx_streaming_timer(unsigned long data)
560 struct wl12xx_vif *wlvif = (struct wl12xx_vif *)data;
561 struct wl1271 *wl = wlvif->wl;
562 ieee80211_queue_work(wl->hw, &wlvif->rx_streaming_disable_work);
565 /* wl->mutex must be taken */
566 void wl12xx_rearm_tx_watchdog_locked(struct wl1271 *wl)
568 /* if the watchdog is not armed, don't do anything */
569 if (wl->tx_allocated_blocks == 0)
572 cancel_delayed_work(&wl->tx_watchdog_work);
573 ieee80211_queue_delayed_work(wl->hw, &wl->tx_watchdog_work,
574 msecs_to_jiffies(wl->conf.tx.tx_watchdog_timeout));
577 static void wl12xx_tx_watchdog_work(struct work_struct *work)
579 struct delayed_work *dwork;
582 dwork = container_of(work, struct delayed_work, work);
583 wl = container_of(dwork, struct wl1271, tx_watchdog_work);
585 mutex_lock(&wl->mutex);
587 if (unlikely(wl->state == WL1271_STATE_OFF))
590 /* Tx went out in the meantime - everything is ok */
591 if (unlikely(wl->tx_allocated_blocks == 0))
595 * if a ROC is in progress, we might not have any Tx for a long
596 * time (e.g. pending Tx on the non-ROC channels)
598 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
599 wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to ROC",
600 wl->conf.tx.tx_watchdog_timeout);
601 wl12xx_rearm_tx_watchdog_locked(wl);
606 * if a scan is in progress, we might not have any Tx for a long
609 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
610 wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms due to scan",
611 wl->conf.tx.tx_watchdog_timeout);
612 wl12xx_rearm_tx_watchdog_locked(wl);
617 * AP might cache a frame for a long time for a sleeping station,
618 * so rearm the timer if there's an AP interface with stations. If
619 * Tx is genuinely stuck we will most hopefully discover it when all
620 * stations are removed due to inactivity.
622 if (wl->active_sta_count) {
623 wl1271_debug(DEBUG_TX, "No Tx (in FW) for %d ms. AP has "
625 wl->conf.tx.tx_watchdog_timeout,
626 wl->active_sta_count);
627 wl12xx_rearm_tx_watchdog_locked(wl);
631 wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
632 wl->conf.tx.tx_watchdog_timeout);
633 wl12xx_queue_recovery_work(wl);
636 mutex_unlock(&wl->mutex);
639 static void wl1271_conf_init(struct wl1271 *wl)
643 * This function applies the default configuration to the driver. This
644 * function is invoked upon driver load (spi probe.)
646 * The configuration is stored in a run-time structure in order to
647 * facilitate for run-time adjustment of any of the parameters. Making
648 * changes to the configuration structure will apply the new values on
649 * the next interface up (wl1271_op_start.)
652 /* apply driver default configuration */
653 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
655 /* Adjust settings according to optional module parameters */
657 if (!strcmp(fwlog_param, "continuous")) {
658 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
659 } else if (!strcmp(fwlog_param, "ondemand")) {
660 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
661 } else if (!strcmp(fwlog_param, "dbgpins")) {
662 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
663 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
664 } else if (!strcmp(fwlog_param, "disable")) {
665 wl->conf.fwlog.mem_blocks = 0;
666 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
668 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
673 static int wl1271_plt_init(struct wl1271 *wl)
677 if (wl->chip.id == CHIP_ID_1283_PG20)
678 ret = wl128x_cmd_general_parms(wl);
680 ret = wl1271_cmd_general_parms(wl);
684 if (wl->chip.id == CHIP_ID_1283_PG20)
685 ret = wl128x_cmd_radio_parms(wl);
687 ret = wl1271_cmd_radio_parms(wl);
691 if (wl->chip.id != CHIP_ID_1283_PG20) {
692 ret = wl1271_cmd_ext_radio_parms(wl);
697 /* Chip-specific initializations */
698 ret = wl1271_chip_specific_init(wl);
702 ret = wl1271_acx_init_mem_config(wl);
706 ret = wl12xx_acx_mem_cfg(wl);
708 goto out_free_memmap;
710 /* Enable data path */
711 ret = wl1271_cmd_data_path(wl, 1);
713 goto out_free_memmap;
715 /* Configure for CAM power saving (ie. always active) */
716 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
718 goto out_free_memmap;
721 ret = wl1271_acx_pm_config(wl);
723 goto out_free_memmap;
728 kfree(wl->target_mem_map);
729 wl->target_mem_map = NULL;
734 static void wl12xx_irq_ps_regulate_link(struct wl1271 *wl,
735 struct wl12xx_vif *wlvif,
738 bool fw_ps, single_sta;
740 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
741 single_sta = (wl->active_sta_count == 1);
744 * Wake up from high level PS if the STA is asleep with too little
745 * packets in FW or if the STA is awake.
747 if (!fw_ps || tx_pkts < WL1271_PS_STA_MAX_PACKETS)
748 wl12xx_ps_link_end(wl, wlvif, hlid);
751 * Start high-level PS if the STA is asleep with enough blocks in FW.
752 * Make an exception if this is the only connected station. In this
753 * case FW-memory congestion is not a problem.
755 else if (!single_sta && fw_ps && tx_pkts >= WL1271_PS_STA_MAX_PACKETS)
756 wl12xx_ps_link_start(wl, wlvif, hlid, true);
759 static void wl12xx_irq_update_links_status(struct wl1271 *wl,
760 struct wl12xx_vif *wlvif,
761 struct wl12xx_fw_status *status)
763 struct wl1271_link *lnk;
767 /* TODO: also use link_fast_bitmap here */
769 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
770 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
771 wl1271_debug(DEBUG_PSM,
772 "link ps prev 0x%x cur 0x%x changed 0x%x",
773 wl->ap_fw_ps_map, cur_fw_ps_map,
774 wl->ap_fw_ps_map ^ cur_fw_ps_map);
776 wl->ap_fw_ps_map = cur_fw_ps_map;
779 for_each_set_bit(hlid, wlvif->ap.sta_hlid_map, WL12XX_MAX_LINKS) {
780 lnk = &wl->links[hlid];
781 cnt = status->tx_lnk_free_pkts[hlid] - lnk->prev_freed_pkts;
783 lnk->prev_freed_pkts = status->tx_lnk_free_pkts[hlid];
784 lnk->allocated_pkts -= cnt;
786 wl12xx_irq_ps_regulate_link(wl, wlvif, hlid,
787 lnk->allocated_pkts);
791 static void wl12xx_fw_status(struct wl1271 *wl,
792 struct wl12xx_fw_status *status)
794 struct wl12xx_vif *wlvif;
796 u32 old_tx_blk_count = wl->tx_blocks_available;
797 int avail, freed_blocks;
800 wlcore_raw_read_data(wl, REG_RAW_FW_STATUS_ADDR, status,
801 sizeof(*status), false);
803 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
804 "drv_rx_counter = %d, tx_results_counter = %d)",
806 status->fw_rx_counter,
807 status->drv_rx_counter,
808 status->tx_results_counter);
810 for (i = 0; i < NUM_TX_QUEUES; i++) {
811 /* prevent wrap-around in freed-packets counter */
812 wl->tx_allocated_pkts[i] -=
813 (status->tx_released_pkts[i] -
814 wl->tx_pkts_freed[i]) & 0xff;
816 wl->tx_pkts_freed[i] = status->tx_released_pkts[i];
819 /* prevent wrap-around in total blocks counter */
820 if (likely(wl->tx_blocks_freed <=
821 le32_to_cpu(status->total_released_blks)))
822 freed_blocks = le32_to_cpu(status->total_released_blks) -
825 freed_blocks = 0x100000000LL - wl->tx_blocks_freed +
826 le32_to_cpu(status->total_released_blks);
828 wl->tx_blocks_freed = le32_to_cpu(status->total_released_blks);
830 wl->tx_allocated_blocks -= freed_blocks;
833 * If the FW freed some blocks:
834 * If we still have allocated blocks - re-arm the timer, Tx is
835 * not stuck. Otherwise, cancel the timer (no Tx currently).
838 if (wl->tx_allocated_blocks)
839 wl12xx_rearm_tx_watchdog_locked(wl);
841 cancel_delayed_work(&wl->tx_watchdog_work);
844 avail = le32_to_cpu(status->tx_total) - wl->tx_allocated_blocks;
847 * The FW might change the total number of TX memblocks before
848 * we get a notification about blocks being released. Thus, the
849 * available blocks calculation might yield a temporary result
850 * which is lower than the actual available blocks. Keeping in
851 * mind that only blocks that were allocated can be moved from
852 * TX to RX, tx_blocks_available should never decrease here.
854 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
857 /* if more blocks are available now, tx work can be scheduled */
858 if (wl->tx_blocks_available > old_tx_blk_count)
859 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
861 /* for AP update num of allocated TX blocks per link and ps status */
862 wl12xx_for_each_wlvif_ap(wl, wlvif) {
863 wl12xx_irq_update_links_status(wl, wlvif, status);
866 /* update the host-chipset time offset */
868 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
869 (s64)le32_to_cpu(status->fw_localtime);
872 static void wl1271_flush_deferred_work(struct wl1271 *wl)
876 /* Pass all received frames to the network stack */
877 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
878 ieee80211_rx_ni(wl->hw, skb);
880 /* Return sent skbs to the network stack */
881 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
882 ieee80211_tx_status_ni(wl->hw, skb);
885 static void wl1271_netstack_work(struct work_struct *work)
888 container_of(work, struct wl1271, netstack_work);
891 wl1271_flush_deferred_work(wl);
892 } while (skb_queue_len(&wl->deferred_rx_queue));
895 #define WL1271_IRQ_MAX_LOOPS 256
897 static irqreturn_t wl1271_irq(int irq, void *cookie)
901 int loopcount = WL1271_IRQ_MAX_LOOPS;
902 struct wl1271 *wl = (struct wl1271 *)cookie;
904 unsigned int defer_count;
907 /* TX might be handled here, avoid redundant work */
908 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
909 cancel_work_sync(&wl->tx_work);
912 * In case edge triggered interrupt must be used, we cannot iterate
913 * more than once without introducing race conditions with the hardirq.
915 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
918 mutex_lock(&wl->mutex);
920 wl1271_debug(DEBUG_IRQ, "IRQ work");
922 if (unlikely(wl->state == WL1271_STATE_OFF))
925 ret = wl1271_ps_elp_wakeup(wl);
929 while (!done && loopcount--) {
931 * In order to avoid a race with the hardirq, clear the flag
932 * before acknowledging the chip. Since the mutex is held,
933 * wl1271_ps_elp_wakeup cannot be called concurrently.
935 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
936 smp_mb__after_clear_bit();
938 wl12xx_fw_status(wl, wl->fw_status);
939 intr = le32_to_cpu(wl->fw_status->intr);
940 intr &= WL1271_INTR_MASK;
946 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
947 wl1271_error("watchdog interrupt received! "
948 "starting recovery.");
949 wl12xx_queue_recovery_work(wl);
951 /* restarting the chip. ignore any other interrupt. */
955 if (likely(intr & WL1271_ACX_INTR_DATA)) {
956 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
958 wl12xx_rx(wl, wl->fw_status);
960 /* Check if any tx blocks were freed */
961 spin_lock_irqsave(&wl->wl_lock, flags);
962 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
963 wl1271_tx_total_queue_count(wl) > 0) {
964 spin_unlock_irqrestore(&wl->wl_lock, flags);
966 * In order to avoid starvation of the TX path,
967 * call the work function directly.
969 wl1271_tx_work_locked(wl);
971 spin_unlock_irqrestore(&wl->wl_lock, flags);
974 /* check for tx results */
975 if (wl->fw_status->tx_results_counter !=
976 (wl->tx_results_count & 0xff))
977 wl1271_tx_complete(wl);
979 /* Make sure the deferred queues don't get too long */
980 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
981 skb_queue_len(&wl->deferred_rx_queue);
982 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
983 wl1271_flush_deferred_work(wl);
986 if (intr & WL1271_ACX_INTR_EVENT_A) {
987 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
988 wl1271_event_handle(wl, 0);
991 if (intr & WL1271_ACX_INTR_EVENT_B) {
992 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
993 wl1271_event_handle(wl, 1);
996 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
997 wl1271_debug(DEBUG_IRQ,
998 "WL1271_ACX_INTR_INIT_COMPLETE");
1000 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
1001 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
1004 wl1271_ps_elp_sleep(wl);
1007 spin_lock_irqsave(&wl->wl_lock, flags);
1008 /* In case TX was not handled here, queue TX work */
1009 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
1010 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1011 wl1271_tx_total_queue_count(wl) > 0)
1012 ieee80211_queue_work(wl->hw, &wl->tx_work);
1013 spin_unlock_irqrestore(&wl->wl_lock, flags);
1015 mutex_unlock(&wl->mutex);
1020 struct vif_counter_data {
1023 struct ieee80211_vif *cur_vif;
1024 bool cur_vif_running;
1027 static void wl12xx_vif_count_iter(void *data, u8 *mac,
1028 struct ieee80211_vif *vif)
1030 struct vif_counter_data *counter = data;
1033 if (counter->cur_vif == vif)
1034 counter->cur_vif_running = true;
1037 /* caller must not hold wl->mutex, as it might deadlock */
1038 static void wl12xx_get_vif_count(struct ieee80211_hw *hw,
1039 struct ieee80211_vif *cur_vif,
1040 struct vif_counter_data *data)
1042 memset(data, 0, sizeof(*data));
1043 data->cur_vif = cur_vif;
1045 ieee80211_iterate_active_interfaces(hw,
1046 wl12xx_vif_count_iter, data);
1049 static int wl12xx_fetch_firmware(struct wl1271 *wl, bool plt)
1051 const struct firmware *fw;
1052 const char *fw_name;
1053 enum wl12xx_fw_type fw_type;
1057 fw_type = WL12XX_FW_TYPE_PLT;
1058 fw_name = wl->plt_fw_name;
1061 * we can't call wl12xx_get_vif_count() here because
1062 * wl->mutex is taken, so use the cached last_vif_count value
1064 if (wl->last_vif_count > 1) {
1065 fw_type = WL12XX_FW_TYPE_MULTI;
1066 fw_name = wl->mr_fw_name;
1068 fw_type = WL12XX_FW_TYPE_NORMAL;
1069 fw_name = wl->sr_fw_name;
1073 if (wl->fw_type == fw_type)
1076 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1078 ret = request_firmware(&fw, fw_name, wl->dev);
1081 wl1271_error("could not get firmware %s: %d", fw_name, ret);
1086 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1093 wl->fw_type = WL12XX_FW_TYPE_NONE;
1094 wl->fw_len = fw->size;
1095 wl->fw = vmalloc(wl->fw_len);
1098 wl1271_error("could not allocate memory for the firmware");
1103 memcpy(wl->fw, fw->data, wl->fw_len);
1105 wl->fw_type = fw_type;
1107 release_firmware(fw);
1112 static int wl1271_fetch_nvs(struct wl1271 *wl)
1114 const struct firmware *fw;
1117 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl->dev);
1120 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME,
1125 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
1128 wl1271_error("could not allocate memory for the nvs file");
1133 wl->nvs_len = fw->size;
1136 release_firmware(fw);
1141 void wl12xx_queue_recovery_work(struct wl1271 *wl)
1143 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1144 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1147 size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1151 /* The FW log is a length-value list, find where the log end */
1152 while (len < maxlen) {
1153 if (memblock[len] == 0)
1155 if (len + memblock[len] + 1 > maxlen)
1157 len += memblock[len] + 1;
1160 /* Make sure we have enough room */
1161 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1163 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1164 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1165 wl->fwlog_size += len;
1170 static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1176 if ((wl->quirks & WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1177 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1178 (wl->conf.fwlog.mem_blocks == 0))
1181 wl1271_info("Reading FW panic log");
1183 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1188 * Make sure the chip is awake and the logger isn't active.
1189 * This might fail if the firmware hanged.
1191 if (!wl1271_ps_elp_wakeup(wl))
1192 wl12xx_cmd_stop_fwlog(wl);
1194 /* Read the first memory block address */
1195 wl12xx_fw_status(wl, wl->fw_status);
1196 first_addr = le32_to_cpu(wl->fw_status->log_start_addr);
1200 /* Traverse the memory blocks linked list */
1203 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1204 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1208 * Memory blocks are linked to one another. The first 4 bytes
1209 * of each memory block hold the hardware address of the next
1210 * one. The last memory block points to the first one.
1212 addr = le32_to_cpup((__le32 *)block);
1213 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1214 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1216 } while (addr && (addr != first_addr));
1218 wake_up_interruptible(&wl->fwlog_waitq);
1224 static void wl1271_recovery_work(struct work_struct *work)
1227 container_of(work, struct wl1271, recovery_work);
1228 struct wl12xx_vif *wlvif;
1229 struct ieee80211_vif *vif;
1231 mutex_lock(&wl->mutex);
1233 if (wl->state != WL1271_STATE_ON || wl->plt)
1236 /* Avoid a recursive recovery */
1237 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1239 wl12xx_read_fwlog_panic(wl);
1241 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1242 wl->chip.fw_ver_str,
1243 wlcore_read_reg(wl, REG_PC_ON_RECOVERY));
1245 BUG_ON(bug_on_recovery &&
1246 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags));
1249 * Advance security sequence number to overcome potential progress
1250 * in the firmware during recovery. This doens't hurt if the network is
1253 wl12xx_for_each_wlvif(wl, wlvif) {
1254 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) ||
1255 test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1256 wlvif->tx_security_seq +=
1257 WL1271_TX_SQN_POST_RECOVERY_PADDING;
1260 /* Prevent spurious TX during FW restart */
1261 ieee80211_stop_queues(wl->hw);
1263 if (wl->sched_scanning) {
1264 ieee80211_sched_scan_stopped(wl->hw);
1265 wl->sched_scanning = false;
1268 /* reboot the chipset */
1269 while (!list_empty(&wl->wlvif_list)) {
1270 wlvif = list_first_entry(&wl->wlvif_list,
1271 struct wl12xx_vif, list);
1272 vif = wl12xx_wlvif_to_vif(wlvif);
1273 __wl1271_op_remove_interface(wl, vif, false);
1275 mutex_unlock(&wl->mutex);
1276 wl1271_op_stop(wl->hw);
1278 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1280 ieee80211_restart_hw(wl->hw);
1283 * Its safe to enable TX now - the queues are stopped after a request
1284 * to restart the HW.
1286 ieee80211_wake_queues(wl->hw);
1289 mutex_unlock(&wl->mutex);
1292 static void wl1271_fw_wakeup(struct wl1271 *wl)
1294 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG, ELPCTRL_WAKE_UP);
1297 static int wl1271_setup(struct wl1271 *wl)
1299 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1303 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1304 if (!wl->tx_res_if) {
1305 kfree(wl->fw_status);
1312 static int wl12xx_set_power_on(struct wl1271 *wl)
1316 msleep(WL1271_PRE_POWER_ON_SLEEP);
1317 ret = wl1271_power_on(wl);
1320 msleep(WL1271_POWER_ON_SLEEP);
1321 wl1271_io_reset(wl);
1324 wlcore_set_partition(wl, &wl->ptable[PART_BOOT]);
1326 /* ELP module wake up */
1327 wl1271_fw_wakeup(wl);
1333 static int wl12xx_chip_wakeup(struct wl1271 *wl, bool plt)
1337 ret = wl12xx_set_power_on(wl);
1342 * For wl127x based devices we could use the default block
1343 * size (512 bytes), but due to a bug in the sdio driver, we
1344 * need to set it explicitly after the chip is powered on. To
1345 * simplify the code and since the performance impact is
1346 * negligible, we use the same block size for all different
1349 if (!wl1271_set_block_size(wl))
1350 wl->quirks |= WLCORE_QUIRK_NO_BLOCKSIZE_ALIGNMENT;
1352 ret = wl->ops->identify_chip(wl);
1356 /* TODO: make sure the lower driver has set things up correctly */
1358 ret = wl1271_setup(wl);
1362 ret = wl12xx_fetch_firmware(wl, plt);
1366 /* No NVS from netlink, try to get it from the filesystem */
1367 if (wl->nvs == NULL) {
1368 ret = wl1271_fetch_nvs(wl);
1377 int wl1271_plt_start(struct wl1271 *wl)
1379 int retries = WL1271_BOOT_RETRIES;
1380 struct wiphy *wiphy = wl->hw->wiphy;
1383 mutex_lock(&wl->mutex);
1385 wl1271_notice("power up");
1387 if (wl->state != WL1271_STATE_OFF) {
1388 wl1271_error("cannot go into PLT state because not "
1389 "in off state: %d", wl->state);
1396 ret = wl12xx_chip_wakeup(wl, true);
1400 ret = wl->ops->boot(wl);
1404 ret = wl1271_plt_init(wl);
1409 wl->state = WL1271_STATE_ON;
1410 wl1271_notice("firmware booted in PLT mode (%s)",
1411 wl->chip.fw_ver_str);
1413 /* update hw/fw version info in wiphy struct */
1414 wiphy->hw_version = wl->chip.id;
1415 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1416 sizeof(wiphy->fw_version));
1421 mutex_unlock(&wl->mutex);
1422 /* Unlocking the mutex in the middle of handling is
1423 inherently unsafe. In this case we deem it safe to do,
1424 because we need to let any possibly pending IRQ out of
1425 the system (and while we are WL1271_STATE_OFF the IRQ
1426 work function will not do anything.) Also, any other
1427 possible concurrent operations will fail due to the
1428 current state, hence the wl1271 struct should be safe. */
1429 wlcore_disable_interrupts(wl);
1430 wl1271_flush_deferred_work(wl);
1431 cancel_work_sync(&wl->netstack_work);
1432 mutex_lock(&wl->mutex);
1434 wl1271_power_off(wl);
1437 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1438 WL1271_BOOT_RETRIES);
1440 mutex_unlock(&wl->mutex);
1445 int wl1271_plt_stop(struct wl1271 *wl)
1449 wl1271_notice("power down");
1452 * Interrupts must be disabled before setting the state to OFF.
1453 * Otherwise, the interrupt handler might be called and exit without
1454 * reading the interrupt status.
1456 wlcore_disable_interrupts(wl);
1457 mutex_lock(&wl->mutex);
1459 mutex_unlock(&wl->mutex);
1462 * This will not necessarily enable interrupts as interrupts
1463 * may have been disabled when op_stop was called. It will,
1464 * however, balance the above call to disable_interrupts().
1466 wlcore_enable_interrupts(wl);
1468 wl1271_error("cannot power down because not in PLT "
1469 "state: %d", wl->state);
1474 mutex_unlock(&wl->mutex);
1476 wl1271_flush_deferred_work(wl);
1477 cancel_work_sync(&wl->netstack_work);
1478 cancel_work_sync(&wl->recovery_work);
1479 cancel_delayed_work_sync(&wl->elp_work);
1480 cancel_delayed_work_sync(&wl->tx_watchdog_work);
1482 mutex_lock(&wl->mutex);
1483 wl1271_power_off(wl);
1485 wl->state = WL1271_STATE_OFF;
1488 mutex_unlock(&wl->mutex);
1494 static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1496 struct wl1271 *wl = hw->priv;
1497 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1498 struct ieee80211_vif *vif = info->control.vif;
1499 struct wl12xx_vif *wlvif = NULL;
1500 unsigned long flags;
1505 wlvif = wl12xx_vif_to_data(vif);
1507 mapping = skb_get_queue_mapping(skb);
1508 q = wl1271_tx_get_queue(mapping);
1510 hlid = wl12xx_tx_get_hlid(wl, wlvif, skb);
1512 spin_lock_irqsave(&wl->wl_lock, flags);
1514 /* queue the packet */
1515 if (hlid == WL12XX_INVALID_LINK_ID ||
1516 (wlvif && !test_bit(hlid, wlvif->links_map))) {
1517 wl1271_debug(DEBUG_TX, "DROP skb hlid %d q %d", hlid, q);
1518 ieee80211_free_txskb(hw, skb);
1522 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d len %d",
1524 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1526 wl->tx_queue_count[q]++;
1529 * The workqueue is slow to process the tx_queue and we need stop
1530 * the queue here, otherwise the queue will get too long.
1532 if (wl->tx_queue_count[q] >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1533 wl1271_debug(DEBUG_TX, "op_tx: stopping queues for q %d", q);
1534 ieee80211_stop_queue(wl->hw, mapping);
1535 set_bit(q, &wl->stopped_queues_map);
1539 * The chip specific setup must run before the first TX packet -
1540 * before that, the tx_work will not be initialized!
1543 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1544 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
1545 ieee80211_queue_work(wl->hw, &wl->tx_work);
1548 spin_unlock_irqrestore(&wl->wl_lock, flags);
1551 int wl1271_tx_dummy_packet(struct wl1271 *wl)
1553 unsigned long flags;
1556 /* no need to queue a new dummy packet if one is already pending */
1557 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags))
1560 q = wl1271_tx_get_queue(skb_get_queue_mapping(wl->dummy_packet));
1562 spin_lock_irqsave(&wl->wl_lock, flags);
1563 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
1564 wl->tx_queue_count[q]++;
1565 spin_unlock_irqrestore(&wl->wl_lock, flags);
1567 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1568 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
1569 wl1271_tx_work_locked(wl);
1572 * If the FW TX is busy, TX work will be scheduled by the threaded
1573 * interrupt handler function
1579 * The size of the dummy packet should be at least 1400 bytes. However, in
1580 * order to minimize the number of bus transactions, aligning it to 512 bytes
1581 * boundaries could be beneficial, performance wise
1583 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1585 static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
1587 struct sk_buff *skb;
1588 struct ieee80211_hdr_3addr *hdr;
1589 unsigned int dummy_packet_size;
1591 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1592 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1594 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
1596 wl1271_warning("Failed to allocate a dummy packet skb");
1600 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1602 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1603 memset(hdr, 0, sizeof(*hdr));
1604 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1605 IEEE80211_STYPE_NULLFUNC |
1606 IEEE80211_FCTL_TODS);
1608 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
1610 /* Dummy packets require the TID to be management */
1611 skb->priority = WL1271_TID_MGMT;
1613 /* Initialize all fields that might be used */
1614 skb_set_queue_mapping(skb, 0);
1615 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
1622 static int wl1271_configure_suspend_sta(struct wl1271 *wl,
1623 struct wl12xx_vif *wlvif)
1627 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
1630 ret = wl1271_ps_elp_wakeup(wl);
1634 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1635 wl->conf.conn.suspend_wake_up_event,
1636 wl->conf.conn.suspend_listen_interval);
1639 wl1271_error("suspend: set wake up conditions failed: %d", ret);
1641 wl1271_ps_elp_sleep(wl);
1648 static int wl1271_configure_suspend_ap(struct wl1271 *wl,
1649 struct wl12xx_vif *wlvif)
1653 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags))
1656 ret = wl1271_ps_elp_wakeup(wl);
1660 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, true);
1662 wl1271_ps_elp_sleep(wl);
1668 static int wl1271_configure_suspend(struct wl1271 *wl,
1669 struct wl12xx_vif *wlvif)
1671 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1672 return wl1271_configure_suspend_sta(wl, wlvif);
1673 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
1674 return wl1271_configure_suspend_ap(wl, wlvif);
1678 static void wl1271_configure_resume(struct wl1271 *wl,
1679 struct wl12xx_vif *wlvif)
1682 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
1683 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
1685 if ((!is_ap) && (!is_sta))
1688 ret = wl1271_ps_elp_wakeup(wl);
1693 ret = wl1271_acx_wake_up_conditions(wl, wlvif,
1694 wl->conf.conn.wake_up_event,
1695 wl->conf.conn.listen_interval);
1698 wl1271_error("resume: wake up conditions failed: %d",
1702 ret = wl1271_acx_beacon_filter_opt(wl, wlvif, false);
1705 wl1271_ps_elp_sleep(wl);
1708 static int wl1271_op_suspend(struct ieee80211_hw *hw,
1709 struct cfg80211_wowlan *wow)
1711 struct wl1271 *wl = hw->priv;
1712 struct wl12xx_vif *wlvif;
1715 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1716 WARN_ON(!wow || !wow->any);
1718 wl1271_tx_flush(wl);
1720 mutex_lock(&wl->mutex);
1721 wl->wow_enabled = true;
1722 wl12xx_for_each_wlvif(wl, wlvif) {
1723 ret = wl1271_configure_suspend(wl, wlvif);
1725 wl1271_warning("couldn't prepare device to suspend");
1729 mutex_unlock(&wl->mutex);
1730 /* flush any remaining work */
1731 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
1734 * disable and re-enable interrupts in order to flush
1737 wlcore_disable_interrupts(wl);
1740 * set suspended flag to avoid triggering a new threaded_irq
1741 * work. no need for spinlock as interrupts are disabled.
1743 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1745 wlcore_enable_interrupts(wl);
1746 flush_work(&wl->tx_work);
1747 flush_delayed_work(&wl->elp_work);
1752 static int wl1271_op_resume(struct ieee80211_hw *hw)
1754 struct wl1271 *wl = hw->priv;
1755 struct wl12xx_vif *wlvif;
1756 unsigned long flags;
1757 bool run_irq_work = false;
1759 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1761 WARN_ON(!wl->wow_enabled);
1764 * re-enable irq_work enqueuing, and call irq_work directly if
1765 * there is a pending work.
1767 spin_lock_irqsave(&wl->wl_lock, flags);
1768 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1769 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1770 run_irq_work = true;
1771 spin_unlock_irqrestore(&wl->wl_lock, flags);
1774 wl1271_debug(DEBUG_MAC80211,
1775 "run postponed irq_work directly");
1777 wlcore_enable_interrupts(wl);
1780 mutex_lock(&wl->mutex);
1781 wl12xx_for_each_wlvif(wl, wlvif) {
1782 wl1271_configure_resume(wl, wlvif);
1784 wl->wow_enabled = false;
1785 mutex_unlock(&wl->mutex);
1791 static int wl1271_op_start(struct ieee80211_hw *hw)
1793 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1796 * We have to delay the booting of the hardware because
1797 * we need to know the local MAC address before downloading and
1798 * initializing the firmware. The MAC address cannot be changed
1799 * after boot, and without the proper MAC address, the firmware
1800 * will not function properly.
1802 * The MAC address is first known when the corresponding interface
1803 * is added. That is where we will initialize the hardware.
1809 static void wl1271_op_stop(struct ieee80211_hw *hw)
1811 struct wl1271 *wl = hw->priv;
1814 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1817 * Interrupts must be disabled before setting the state to OFF.
1818 * Otherwise, the interrupt handler might be called and exit without
1819 * reading the interrupt status.
1821 wlcore_disable_interrupts(wl);
1822 mutex_lock(&wl->mutex);
1823 if (wl->state == WL1271_STATE_OFF) {
1824 mutex_unlock(&wl->mutex);
1827 * This will not necessarily enable interrupts as interrupts
1828 * may have been disabled when op_stop was called. It will,
1829 * however, balance the above call to disable_interrupts().
1831 wlcore_enable_interrupts(wl);
1836 * this must be before the cancel_work calls below, so that the work
1837 * functions don't perform further work.
1839 wl->state = WL1271_STATE_OFF;
1840 mutex_unlock(&wl->mutex);
1842 wl1271_flush_deferred_work(wl);
1843 cancel_delayed_work_sync(&wl->scan_complete_work);
1844 cancel_work_sync(&wl->netstack_work);
1845 cancel_work_sync(&wl->tx_work);
1846 cancel_delayed_work_sync(&wl->elp_work);
1847 cancel_delayed_work_sync(&wl->tx_watchdog_work);
1849 /* let's notify MAC80211 about the remaining pending TX frames */
1850 wl12xx_tx_reset(wl, true);
1851 mutex_lock(&wl->mutex);
1853 wl1271_power_off(wl);
1855 wl->band = IEEE80211_BAND_2GHZ;
1858 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1859 wl->tx_blocks_available = 0;
1860 wl->tx_allocated_blocks = 0;
1861 wl->tx_results_count = 0;
1862 wl->tx_packets_count = 0;
1863 wl->time_offset = 0;
1864 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
1865 wl->ap_fw_ps_map = 0;
1867 wl->sched_scanning = false;
1868 memset(wl->roles_map, 0, sizeof(wl->roles_map));
1869 memset(wl->links_map, 0, sizeof(wl->links_map));
1870 memset(wl->roc_map, 0, sizeof(wl->roc_map));
1871 wl->active_sta_count = 0;
1873 /* The system link is always allocated */
1874 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
1877 * this is performed after the cancel_work calls and the associated
1878 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1879 * get executed before all these vars have been reset.
1883 wl->tx_blocks_freed = 0;
1885 for (i = 0; i < NUM_TX_QUEUES; i++) {
1886 wl->tx_pkts_freed[i] = 0;
1887 wl->tx_allocated_pkts[i] = 0;
1890 wl1271_debugfs_reset(wl);
1892 kfree(wl->fw_status);
1893 wl->fw_status = NULL;
1894 kfree(wl->tx_res_if);
1895 wl->tx_res_if = NULL;
1896 kfree(wl->target_mem_map);
1897 wl->target_mem_map = NULL;
1899 mutex_unlock(&wl->mutex);
1902 static int wl12xx_allocate_rate_policy(struct wl1271 *wl, u8 *idx)
1904 u8 policy = find_first_zero_bit(wl->rate_policies_map,
1905 WL12XX_MAX_RATE_POLICIES);
1906 if (policy >= WL12XX_MAX_RATE_POLICIES)
1909 __set_bit(policy, wl->rate_policies_map);
1914 static void wl12xx_free_rate_policy(struct wl1271 *wl, u8 *idx)
1916 if (WARN_ON(*idx >= WL12XX_MAX_RATE_POLICIES))
1919 __clear_bit(*idx, wl->rate_policies_map);
1920 *idx = WL12XX_MAX_RATE_POLICIES;
1923 static u8 wl12xx_get_role_type(struct wl1271 *wl, struct wl12xx_vif *wlvif)
1925 switch (wlvif->bss_type) {
1926 case BSS_TYPE_AP_BSS:
1928 return WL1271_ROLE_P2P_GO;
1930 return WL1271_ROLE_AP;
1932 case BSS_TYPE_STA_BSS:
1934 return WL1271_ROLE_P2P_CL;
1936 return WL1271_ROLE_STA;
1939 return WL1271_ROLE_IBSS;
1942 wl1271_error("invalid bss_type: %d", wlvif->bss_type);
1944 return WL12XX_INVALID_ROLE_TYPE;
1947 static int wl12xx_init_vif_data(struct wl1271 *wl, struct ieee80211_vif *vif)
1949 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
1952 /* clear everything but the persistent data */
1953 memset(wlvif, 0, offsetof(struct wl12xx_vif, persistent));
1955 switch (ieee80211_vif_type_p2p(vif)) {
1956 case NL80211_IFTYPE_P2P_CLIENT:
1959 case NL80211_IFTYPE_STATION:
1960 wlvif->bss_type = BSS_TYPE_STA_BSS;
1962 case NL80211_IFTYPE_ADHOC:
1963 wlvif->bss_type = BSS_TYPE_IBSS;
1965 case NL80211_IFTYPE_P2P_GO:
1968 case NL80211_IFTYPE_AP:
1969 wlvif->bss_type = BSS_TYPE_AP_BSS;
1972 wlvif->bss_type = MAX_BSS_TYPE;
1976 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
1977 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
1978 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
1980 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
1981 wlvif->bss_type == BSS_TYPE_IBSS) {
1982 /* init sta/ibss data */
1983 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
1984 wl12xx_allocate_rate_policy(wl, &wlvif->sta.basic_rate_idx);
1985 wl12xx_allocate_rate_policy(wl, &wlvif->sta.ap_rate_idx);
1986 wl12xx_allocate_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
1989 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
1990 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
1991 wl12xx_allocate_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
1992 wl12xx_allocate_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
1993 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
1994 wl12xx_allocate_rate_policy(wl,
1995 &wlvif->ap.ucast_rate_idx[i]);
1998 wlvif->bitrate_masks[IEEE80211_BAND_2GHZ] = wl->conf.tx.basic_rate;
1999 wlvif->bitrate_masks[IEEE80211_BAND_5GHZ] = wl->conf.tx.basic_rate_5;
2000 wlvif->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
2001 wlvif->basic_rate = CONF_TX_RATE_MASK_BASIC;
2002 wlvif->rate_set = CONF_TX_RATE_MASK_BASIC;
2003 wlvif->beacon_int = WL1271_DEFAULT_BEACON_INT;
2006 * mac80211 configures some values globally, while we treat them
2007 * per-interface. thus, on init, we have to copy them from wl
2009 wlvif->band = wl->band;
2010 wlvif->channel = wl->channel;
2011 wlvif->power_level = wl->power_level;
2013 INIT_WORK(&wlvif->rx_streaming_enable_work,
2014 wl1271_rx_streaming_enable_work);
2015 INIT_WORK(&wlvif->rx_streaming_disable_work,
2016 wl1271_rx_streaming_disable_work);
2017 INIT_LIST_HEAD(&wlvif->list);
2019 setup_timer(&wlvif->rx_streaming_timer, wl1271_rx_streaming_timer,
2020 (unsigned long) wlvif);
2024 static bool wl12xx_init_fw(struct wl1271 *wl)
2026 int retries = WL1271_BOOT_RETRIES;
2027 bool booted = false;
2028 struct wiphy *wiphy = wl->hw->wiphy;
2033 ret = wl12xx_chip_wakeup(wl, false);
2037 ret = wl->ops->boot(wl);
2041 ret = wl1271_hw_init(wl);
2049 mutex_unlock(&wl->mutex);
2050 /* Unlocking the mutex in the middle of handling is
2051 inherently unsafe. In this case we deem it safe to do,
2052 because we need to let any possibly pending IRQ out of
2053 the system (and while we are WL1271_STATE_OFF the IRQ
2054 work function will not do anything.) Also, any other
2055 possible concurrent operations will fail due to the
2056 current state, hence the wl1271 struct should be safe. */
2057 wlcore_disable_interrupts(wl);
2058 wl1271_flush_deferred_work(wl);
2059 cancel_work_sync(&wl->netstack_work);
2060 mutex_lock(&wl->mutex);
2062 wl1271_power_off(wl);
2066 wl1271_error("firmware boot failed despite %d retries",
2067 WL1271_BOOT_RETRIES);
2071 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
2073 /* update hw/fw version info in wiphy struct */
2074 wiphy->hw_version = wl->chip.id;
2075 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
2076 sizeof(wiphy->fw_version));
2079 * Now we know if 11a is supported (info from the NVS), so disable
2080 * 11a channels if not supported
2082 if (!wl->enable_11a)
2083 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
2085 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
2086 wl->enable_11a ? "" : "not ");
2088 wl->state = WL1271_STATE_ON;
2093 static bool wl12xx_dev_role_started(struct wl12xx_vif *wlvif)
2095 return wlvif->dev_hlid != WL12XX_INVALID_LINK_ID;
2099 * Check whether a fw switch (i.e. moving from one loaded
2100 * fw to another) is needed. This function is also responsible
2101 * for updating wl->last_vif_count, so it must be called before
2102 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2105 static bool wl12xx_need_fw_change(struct wl1271 *wl,
2106 struct vif_counter_data vif_counter_data,
2109 enum wl12xx_fw_type current_fw = wl->fw_type;
2110 u8 vif_count = vif_counter_data.counter;
2112 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags))
2115 /* increase the vif count if this is a new vif */
2116 if (add && !vif_counter_data.cur_vif_running)
2119 wl->last_vif_count = vif_count;
2121 /* no need for fw change if the device is OFF */
2122 if (wl->state == WL1271_STATE_OFF)
2125 if (vif_count > 1 && current_fw == WL12XX_FW_TYPE_NORMAL)
2127 if (vif_count <= 1 && current_fw == WL12XX_FW_TYPE_MULTI)
2134 * Enter "forced psm". Make sure the sta is in psm against the ap,
2135 * to make the fw switch a bit more disconnection-persistent.
2137 static void wl12xx_force_active_psm(struct wl1271 *wl)
2139 struct wl12xx_vif *wlvif;
2141 wl12xx_for_each_wlvif_sta(wl, wlvif) {
2142 wl1271_ps_set_mode(wl, wlvif, STATION_POWER_SAVE_MODE);
2146 static int wl1271_op_add_interface(struct ieee80211_hw *hw,
2147 struct ieee80211_vif *vif)
2149 struct wl1271 *wl = hw->priv;
2150 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2151 struct vif_counter_data vif_count;
2154 bool booted = false;
2156 vif->driver_flags |= IEEE80211_VIF_BEACON_FILTER |
2157 IEEE80211_VIF_SUPPORTS_CQM_RSSI;
2159 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
2160 ieee80211_vif_type_p2p(vif), vif->addr);
2162 wl12xx_get_vif_count(hw, vif, &vif_count);
2164 mutex_lock(&wl->mutex);
2165 ret = wl1271_ps_elp_wakeup(wl);
2170 * in some very corner case HW recovery scenarios its possible to
2171 * get here before __wl1271_op_remove_interface is complete, so
2172 * opt out if that is the case.
2174 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags) ||
2175 test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)) {
2181 ret = wl12xx_init_vif_data(wl, vif);
2186 role_type = wl12xx_get_role_type(wl, wlvif);
2187 if (role_type == WL12XX_INVALID_ROLE_TYPE) {
2192 if (wl12xx_need_fw_change(wl, vif_count, true)) {
2193 wl12xx_force_active_psm(wl);
2194 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
2195 mutex_unlock(&wl->mutex);
2196 wl1271_recovery_work(&wl->recovery_work);
2201 * TODO: after the nvs issue will be solved, move this block
2202 * to start(), and make sure here the driver is ON.
2204 if (wl->state == WL1271_STATE_OFF) {
2206 * we still need this in order to configure the fw
2207 * while uploading the nvs
2209 memcpy(wl->addresses[0].addr, vif->addr, ETH_ALEN);
2211 booted = wl12xx_init_fw(wl);
2218 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2219 wlvif->bss_type == BSS_TYPE_IBSS) {
2221 * The device role is a special role used for
2222 * rx and tx frames prior to association (as
2223 * the STA role can get packets only from
2224 * its associated bssid)
2226 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2228 &wlvif->dev_role_id);
2233 ret = wl12xx_cmd_role_enable(wl, vif->addr,
2234 role_type, &wlvif->role_id);
2238 ret = wl1271_init_vif_specific(wl, vif);
2242 list_add(&wlvif->list, &wl->wlvif_list);
2243 set_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags);
2245 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2250 wl1271_ps_elp_sleep(wl);
2252 mutex_unlock(&wl->mutex);
2257 static void __wl1271_op_remove_interface(struct wl1271 *wl,
2258 struct ieee80211_vif *vif,
2259 bool reset_tx_queues)
2261 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2264 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
2266 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2269 /* because of hardware recovery, we may get here twice */
2270 if (wl->state != WL1271_STATE_ON)
2273 wl1271_info("down");
2275 if (wl->scan.state != WL1271_SCAN_STATE_IDLE &&
2276 wl->scan_vif == vif) {
2278 * Rearm the tx watchdog just before idling scan. This
2279 * prevents just-finished scans from triggering the watchdog
2281 wl12xx_rearm_tx_watchdog_locked(wl);
2283 wl->scan.state = WL1271_SCAN_STATE_IDLE;
2284 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
2285 wl->scan_vif = NULL;
2286 wl->scan.req = NULL;
2287 ieee80211_scan_completed(wl->hw, true);
2290 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) {
2291 /* disable active roles */
2292 ret = wl1271_ps_elp_wakeup(wl);
2296 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2297 wlvif->bss_type == BSS_TYPE_IBSS) {
2298 if (wl12xx_dev_role_started(wlvif))
2299 wl12xx_stop_dev(wl, wlvif);
2301 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
2306 ret = wl12xx_cmd_role_disable(wl, &wlvif->role_id);
2310 wl1271_ps_elp_sleep(wl);
2313 /* clear all hlids (except system_hlid) */
2314 wlvif->dev_hlid = WL12XX_INVALID_LINK_ID;
2316 if (wlvif->bss_type == BSS_TYPE_STA_BSS ||
2317 wlvif->bss_type == BSS_TYPE_IBSS) {
2318 wlvif->sta.hlid = WL12XX_INVALID_LINK_ID;
2319 wl12xx_free_rate_policy(wl, &wlvif->sta.basic_rate_idx);
2320 wl12xx_free_rate_policy(wl, &wlvif->sta.ap_rate_idx);
2321 wl12xx_free_rate_policy(wl, &wlvif->sta.p2p_rate_idx);
2323 wlvif->ap.bcast_hlid = WL12XX_INVALID_LINK_ID;
2324 wlvif->ap.global_hlid = WL12XX_INVALID_LINK_ID;
2325 wl12xx_free_rate_policy(wl, &wlvif->ap.mgmt_rate_idx);
2326 wl12xx_free_rate_policy(wl, &wlvif->ap.bcast_rate_idx);
2327 for (i = 0; i < CONF_TX_MAX_AC_COUNT; i++)
2328 wl12xx_free_rate_policy(wl,
2329 &wlvif->ap.ucast_rate_idx[i]);
2330 wl1271_free_ap_keys(wl, wlvif);
2333 dev_kfree_skb(wlvif->probereq);
2334 wlvif->probereq = NULL;
2335 wl12xx_tx_reset_wlvif(wl, wlvif);
2336 if (wl->last_wlvif == wlvif)
2337 wl->last_wlvif = NULL;
2338 list_del(&wlvif->list);
2339 memset(wlvif->ap.sta_hlid_map, 0, sizeof(wlvif->ap.sta_hlid_map));
2340 wlvif->role_id = WL12XX_INVALID_ROLE_ID;
2341 wlvif->dev_role_id = WL12XX_INVALID_ROLE_ID;
2343 if (wlvif->bss_type == BSS_TYPE_AP_BSS)
2348 mutex_unlock(&wl->mutex);
2350 del_timer_sync(&wlvif->rx_streaming_timer);
2351 cancel_work_sync(&wlvif->rx_streaming_enable_work);
2352 cancel_work_sync(&wlvif->rx_streaming_disable_work);
2354 mutex_lock(&wl->mutex);
2357 static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2358 struct ieee80211_vif *vif)
2360 struct wl1271 *wl = hw->priv;
2361 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
2362 struct wl12xx_vif *iter;
2363 struct vif_counter_data vif_count;
2364 bool cancel_recovery = true;
2366 wl12xx_get_vif_count(hw, vif, &vif_count);
2367 mutex_lock(&wl->mutex);
2369 if (wl->state == WL1271_STATE_OFF ||
2370 !test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
2374 * wl->vif can be null here if someone shuts down the interface
2375 * just when hardware recovery has been started.
2377 wl12xx_for_each_wlvif(wl, iter) {
2381 __wl1271_op_remove_interface(wl, vif, true);
2384 WARN_ON(iter != wlvif);
2385 if (wl12xx_need_fw_change(wl, vif_count, false)) {
2386 wl12xx_force_active_psm(wl);
2387 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY, &wl->flags);
2388 wl12xx_queue_recovery_work(wl);
2389 cancel_recovery = false;
2392 mutex_unlock(&wl->mutex);
2393 if (cancel_recovery)
2394 cancel_work_sync(&wl->recovery_work);
2397 static int wl12xx_op_change_interface(struct ieee80211_hw *hw,
2398 struct ieee80211_vif *vif,
2399 enum nl80211_iftype new_type, bool p2p)
2401 struct wl1271 *wl = hw->priv;
2404 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2405 wl1271_op_remove_interface(hw, vif);
2407 vif->type = new_type;
2409 ret = wl1271_op_add_interface(hw, vif);
2411 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS, &wl->flags);
2415 static int wl1271_join(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2419 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
2422 * One of the side effects of the JOIN command is that is clears
2423 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2424 * to a WPA/WPA2 access point will therefore kill the data-path.
2425 * Currently the only valid scenario for JOIN during association
2426 * is on roaming, in which case we will also be given new keys.
2427 * Keep the below message for now, unless it starts bothering
2428 * users who really like to roam a lot :)
2430 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2431 wl1271_info("JOIN while associated.");
2433 /* clear encryption type */
2434 wlvif->encryption_type = KEY_NONE;
2437 set_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags);
2440 ret = wl12xx_cmd_role_start_ibss(wl, wlvif);
2442 ret = wl12xx_cmd_role_start_sta(wl, wlvif);
2446 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2450 * The join command disable the keep-alive mode, shut down its process,
2451 * and also clear the template config, so we need to reset it all after
2452 * the join. The acx_aid starts the keep-alive process, and the order
2453 * of the commands below is relevant.
2455 ret = wl1271_acx_keep_alive_mode(wl, wlvif, true);
2459 ret = wl1271_acx_aid(wl, wlvif, wlvif->aid);
2463 ret = wl12xx_cmd_build_klv_null_data(wl, wlvif);
2467 ret = wl1271_acx_keep_alive_config(wl, wlvif,
2468 CMD_TEMPL_KLV_IDX_NULL_DATA,
2469 ACX_KEEP_ALIVE_TPL_VALID);
2477 static int wl1271_unjoin(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2481 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags)) {
2482 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
2484 wl12xx_cmd_stop_channel_switch(wl);
2485 ieee80211_chswitch_done(vif, false);
2488 /* to stop listening to a channel, we disconnect */
2489 ret = wl12xx_cmd_role_stop_sta(wl, wlvif);
2493 /* reset TX security counters on a clean disconnect */
2494 wlvif->tx_security_last_seq_lsb = 0;
2495 wlvif->tx_security_seq = 0;
2501 static void wl1271_set_band_rate(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2503 wlvif->basic_rate_set = wlvif->bitrate_masks[wlvif->band];
2504 wlvif->rate_set = wlvif->basic_rate_set;
2507 static int wl1271_sta_handle_idle(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2511 bool cur_idle = !test_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2513 if (idle == cur_idle)
2517 /* no need to croc if we weren't busy (e.g. during boot) */
2518 if (wl12xx_dev_role_started(wlvif)) {
2519 ret = wl12xx_stop_dev(wl, wlvif);
2524 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2525 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2528 ret = wl1271_acx_keep_alive_config(
2529 wl, wlvif, CMD_TEMPL_KLV_IDX_NULL_DATA,
2530 ACX_KEEP_ALIVE_TPL_INVALID);
2533 clear_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2535 /* The current firmware only supports sched_scan in idle */
2536 if (wl->sched_scanning) {
2537 wl1271_scan_sched_scan_stop(wl);
2538 ieee80211_sched_scan_stopped(wl->hw);
2541 ret = wl12xx_start_dev(wl, wlvif);
2544 set_bit(WLVIF_FLAG_IN_USE, &wlvif->flags);
2551 static int wl12xx_config_vif(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2552 struct ieee80211_conf *conf, u32 changed)
2554 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2557 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2559 /* if the channel changes while joined, join again */
2560 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
2561 ((wlvif->band != conf->channel->band) ||
2562 (wlvif->channel != channel))) {
2563 /* send all pending packets */
2564 wl1271_tx_work_locked(wl);
2565 wlvif->band = conf->channel->band;
2566 wlvif->channel = channel;
2570 * FIXME: the mac80211 should really provide a fixed
2571 * rate to use here. for now, just use the smallest
2572 * possible rate for the band as a fixed rate for
2573 * association frames and other control messages.
2575 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags))
2576 wl1271_set_band_rate(wl, wlvif);
2579 wl1271_tx_min_rate_get(wl,
2580 wlvif->basic_rate_set);
2581 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
2583 wl1271_warning("rate policy for channel "
2587 * change the ROC channel. do it only if we are
2588 * not idle. otherwise, CROC will be called
2591 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED,
2593 wl12xx_dev_role_started(wlvif) &&
2594 !(conf->flags & IEEE80211_CONF_IDLE)) {
2595 ret = wl12xx_stop_dev(wl, wlvif);
2599 ret = wl12xx_start_dev(wl, wlvif);
2606 if ((changed & IEEE80211_CONF_CHANGE_PS) && !is_ap) {
2608 if ((conf->flags & IEEE80211_CONF_PS) &&
2609 test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags) &&
2610 !test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
2615 if (wl->conf.conn.forced_ps) {
2616 ps_mode = STATION_POWER_SAVE_MODE;
2617 ps_mode_str = "forced";
2619 ps_mode = STATION_AUTO_PS_MODE;
2620 ps_mode_str = "auto";
2623 wl1271_debug(DEBUG_PSM, "%s ps enabled", ps_mode_str);
2625 ret = wl1271_ps_set_mode(wl, wlvif, ps_mode);
2628 wl1271_warning("enter %s ps failed %d",
2631 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2632 test_bit(WLVIF_FLAG_IN_PS, &wlvif->flags)) {
2634 wl1271_debug(DEBUG_PSM, "auto ps disabled");
2636 ret = wl1271_ps_set_mode(wl, wlvif,
2637 STATION_ACTIVE_MODE);
2639 wl1271_warning("exit auto ps failed %d", ret);
2643 if (conf->power_level != wlvif->power_level) {
2644 ret = wl1271_acx_tx_power(wl, wlvif, conf->power_level);
2648 wlvif->power_level = conf->power_level;
2654 static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2656 struct wl1271 *wl = hw->priv;
2657 struct wl12xx_vif *wlvif;
2658 struct ieee80211_conf *conf = &hw->conf;
2659 int channel, ret = 0;
2661 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2663 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2666 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2668 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2672 * mac80211 will go to idle nearly immediately after transmitting some
2673 * frames, such as the deauth. To make sure those frames reach the air,
2674 * wait here until the TX queue is fully flushed.
2676 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2677 (conf->flags & IEEE80211_CONF_IDLE))
2678 wl1271_tx_flush(wl);
2680 mutex_lock(&wl->mutex);
2682 /* we support configuring the channel and band even while off */
2683 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
2684 wl->band = conf->channel->band;
2685 wl->channel = channel;
2688 if (changed & IEEE80211_CONF_CHANGE_POWER)
2689 wl->power_level = conf->power_level;
2691 if (unlikely(wl->state == WL1271_STATE_OFF))
2694 ret = wl1271_ps_elp_wakeup(wl);
2698 /* configure each interface */
2699 wl12xx_for_each_wlvif(wl, wlvif) {
2700 ret = wl12xx_config_vif(wl, wlvif, conf, changed);
2706 wl1271_ps_elp_sleep(wl);
2709 mutex_unlock(&wl->mutex);
2714 struct wl1271_filter_params {
2717 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2720 static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2721 struct netdev_hw_addr_list *mc_list)
2723 struct wl1271_filter_params *fp;
2724 struct netdev_hw_addr *ha;
2725 struct wl1271 *wl = hw->priv;
2727 if (unlikely(wl->state == WL1271_STATE_OFF))
2730 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
2732 wl1271_error("Out of memory setting filters.");
2736 /* update multicast filtering parameters */
2737 fp->mc_list_length = 0;
2738 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2739 fp->enabled = false;
2742 netdev_hw_addr_list_for_each(ha, mc_list) {
2743 memcpy(fp->mc_list[fp->mc_list_length],
2744 ha->addr, ETH_ALEN);
2745 fp->mc_list_length++;
2749 return (u64)(unsigned long)fp;
2752 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2755 FIF_BCN_PRBRESP_PROMISC | \
2759 static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2760 unsigned int changed,
2761 unsigned int *total, u64 multicast)
2763 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
2764 struct wl1271 *wl = hw->priv;
2765 struct wl12xx_vif *wlvif;
2769 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2770 " total %x", changed, *total);
2772 mutex_lock(&wl->mutex);
2774 *total &= WL1271_SUPPORTED_FILTERS;
2775 changed &= WL1271_SUPPORTED_FILTERS;
2777 if (unlikely(wl->state == WL1271_STATE_OFF))
2780 ret = wl1271_ps_elp_wakeup(wl);
2784 wl12xx_for_each_wlvif(wl, wlvif) {
2785 if (wlvif->bss_type != BSS_TYPE_AP_BSS) {
2786 if (*total & FIF_ALLMULTI)
2787 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2791 ret = wl1271_acx_group_address_tbl(wl, wlvif,
2794 fp->mc_list_length);
2801 * the fw doesn't provide an api to configure the filters. instead,
2802 * the filters configuration is based on the active roles / ROC
2807 wl1271_ps_elp_sleep(wl);
2810 mutex_unlock(&wl->mutex);
2814 static int wl1271_record_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2815 u8 id, u8 key_type, u8 key_size,
2816 const u8 *key, u8 hlid, u32 tx_seq_32,
2819 struct wl1271_ap_key *ap_key;
2822 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2824 if (key_size > MAX_KEY_SIZE)
2828 * Find next free entry in ap_keys. Also check we are not replacing
2831 for (i = 0; i < MAX_NUM_KEYS; i++) {
2832 if (wlvif->ap.recorded_keys[i] == NULL)
2835 if (wlvif->ap.recorded_keys[i]->id == id) {
2836 wl1271_warning("trying to record key replacement");
2841 if (i == MAX_NUM_KEYS)
2844 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2849 ap_key->key_type = key_type;
2850 ap_key->key_size = key_size;
2851 memcpy(ap_key->key, key, key_size);
2852 ap_key->hlid = hlid;
2853 ap_key->tx_seq_32 = tx_seq_32;
2854 ap_key->tx_seq_16 = tx_seq_16;
2856 wlvif->ap.recorded_keys[i] = ap_key;
2860 static void wl1271_free_ap_keys(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2864 for (i = 0; i < MAX_NUM_KEYS; i++) {
2865 kfree(wlvif->ap.recorded_keys[i]);
2866 wlvif->ap.recorded_keys[i] = NULL;
2870 static int wl1271_ap_init_hwenc(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2873 struct wl1271_ap_key *key;
2874 bool wep_key_added = false;
2876 for (i = 0; i < MAX_NUM_KEYS; i++) {
2878 if (wlvif->ap.recorded_keys[i] == NULL)
2881 key = wlvif->ap.recorded_keys[i];
2883 if (hlid == WL12XX_INVALID_LINK_ID)
2884 hlid = wlvif->ap.bcast_hlid;
2886 ret = wl1271_cmd_set_ap_key(wl, wlvif, KEY_ADD_OR_REPLACE,
2887 key->id, key->key_type,
2888 key->key_size, key->key,
2889 hlid, key->tx_seq_32,
2894 if (key->key_type == KEY_WEP)
2895 wep_key_added = true;
2898 if (wep_key_added) {
2899 ret = wl12xx_cmd_set_default_wep_key(wl, wlvif->default_key,
2900 wlvif->ap.bcast_hlid);
2906 wl1271_free_ap_keys(wl, wlvif);
2910 static int wl1271_set_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2911 u16 action, u8 id, u8 key_type,
2912 u8 key_size, const u8 *key, u32 tx_seq_32,
2913 u16 tx_seq_16, struct ieee80211_sta *sta)
2916 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
2919 struct wl1271_station *wl_sta;
2923 wl_sta = (struct wl1271_station *)sta->drv_priv;
2924 hlid = wl_sta->hlid;
2926 hlid = wlvif->ap.bcast_hlid;
2929 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
2931 * We do not support removing keys after AP shutdown.
2932 * Pretend we do to make mac80211 happy.
2934 if (action != KEY_ADD_OR_REPLACE)
2937 ret = wl1271_record_ap_key(wl, wlvif, id,
2939 key, hlid, tx_seq_32,
2942 ret = wl1271_cmd_set_ap_key(wl, wlvif, action,
2943 id, key_type, key_size,
2944 key, hlid, tx_seq_32,
2952 static const u8 bcast_addr[ETH_ALEN] = {
2953 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2957 * A STA set to GEM cipher requires 2 tx spare blocks.
2958 * Return to default value when GEM cipher key is removed
2960 if (key_type == KEY_GEM) {
2961 if (action == KEY_ADD_OR_REPLACE)
2962 wl->tx_spare_blocks = 2;
2963 else if (action == KEY_REMOVE)
2964 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
2967 addr = sta ? sta->addr : bcast_addr;
2969 if (is_zero_ether_addr(addr)) {
2970 /* We dont support TX only encryption */
2974 /* The wl1271 does not allow to remove unicast keys - they
2975 will be cleared automatically on next CMD_JOIN. Ignore the
2976 request silently, as we dont want the mac80211 to emit
2977 an error message. */
2978 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2981 /* don't remove key if hlid was already deleted */
2982 if (action == KEY_REMOVE &&
2983 wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
2986 ret = wl1271_cmd_set_sta_key(wl, wlvif, action,
2987 id, key_type, key_size,
2988 key, addr, tx_seq_32,
2993 /* the default WEP key needs to be configured at least once */
2994 if (key_type == KEY_WEP) {
2995 ret = wl12xx_cmd_set_default_wep_key(wl,
3006 static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3007 struct ieee80211_vif *vif,
3008 struct ieee80211_sta *sta,
3009 struct ieee80211_key_conf *key_conf)
3011 struct wl1271 *wl = hw->priv;
3012 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3018 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
3020 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
3021 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
3022 key_conf->cipher, key_conf->keyidx,
3023 key_conf->keylen, key_conf->flags);
3024 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
3026 mutex_lock(&wl->mutex);
3028 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3033 ret = wl1271_ps_elp_wakeup(wl);
3037 switch (key_conf->cipher) {
3038 case WLAN_CIPHER_SUITE_WEP40:
3039 case WLAN_CIPHER_SUITE_WEP104:
3042 key_conf->hw_key_idx = key_conf->keyidx;
3044 case WLAN_CIPHER_SUITE_TKIP:
3045 key_type = KEY_TKIP;
3047 key_conf->hw_key_idx = key_conf->keyidx;
3048 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
3049 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
3051 case WLAN_CIPHER_SUITE_CCMP:
3054 key_conf->flags |= IEEE80211_KEY_FLAG_PUT_IV_SPACE;
3055 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
3056 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
3058 case WL1271_CIPHER_SUITE_GEM:
3060 tx_seq_32 = WL1271_TX_SECURITY_HI32(wlvif->tx_security_seq);
3061 tx_seq_16 = WL1271_TX_SECURITY_LO16(wlvif->tx_security_seq);
3064 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
3072 ret = wl1271_set_key(wl, wlvif, KEY_ADD_OR_REPLACE,
3073 key_conf->keyidx, key_type,
3074 key_conf->keylen, key_conf->key,
3075 tx_seq_32, tx_seq_16, sta);
3077 wl1271_error("Could not add or replace key");
3082 * reconfiguring arp response if the unicast (or common)
3083 * encryption key type was changed
3085 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
3086 (sta || key_type == KEY_WEP) &&
3087 wlvif->encryption_type != key_type) {
3088 wlvif->encryption_type = key_type;
3089 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
3091 wl1271_warning("build arp rsp failed: %d", ret);
3098 ret = wl1271_set_key(wl, wlvif, KEY_REMOVE,
3099 key_conf->keyidx, key_type,
3100 key_conf->keylen, key_conf->key,
3103 wl1271_error("Could not remove key");
3109 wl1271_error("Unsupported key cmd 0x%x", cmd);
3115 wl1271_ps_elp_sleep(wl);
3118 mutex_unlock(&wl->mutex);
3123 static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
3124 struct ieee80211_vif *vif,
3125 struct cfg80211_scan_request *req)
3127 struct wl1271 *wl = hw->priv;
3132 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
3135 ssid = req->ssids[0].ssid;
3136 len = req->ssids[0].ssid_len;
3139 mutex_lock(&wl->mutex);
3141 if (wl->state == WL1271_STATE_OFF) {
3143 * We cannot return -EBUSY here because cfg80211 will expect
3144 * a call to ieee80211_scan_completed if we do - in this case
3145 * there won't be any call.
3151 ret = wl1271_ps_elp_wakeup(wl);
3155 /* fail if there is any role in ROC */
3156 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) < WL12XX_MAX_ROLES) {
3157 /* don't allow scanning right now */
3162 ret = wl1271_scan(hw->priv, vif, ssid, len, req);
3164 wl1271_ps_elp_sleep(wl);
3166 mutex_unlock(&wl->mutex);
3171 static void wl1271_op_cancel_hw_scan(struct ieee80211_hw *hw,
3172 struct ieee80211_vif *vif)
3174 struct wl1271 *wl = hw->priv;
3177 wl1271_debug(DEBUG_MAC80211, "mac80211 cancel hw scan");
3179 mutex_lock(&wl->mutex);
3181 if (wl->state == WL1271_STATE_OFF)
3184 if (wl->scan.state == WL1271_SCAN_STATE_IDLE)
3187 ret = wl1271_ps_elp_wakeup(wl);
3191 if (wl->scan.state != WL1271_SCAN_STATE_DONE) {
3192 ret = wl1271_scan_stop(wl);
3198 * Rearm the tx watchdog just before idling scan. This
3199 * prevents just-finished scans from triggering the watchdog
3201 wl12xx_rearm_tx_watchdog_locked(wl);
3203 wl->scan.state = WL1271_SCAN_STATE_IDLE;
3204 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
3205 wl->scan_vif = NULL;
3206 wl->scan.req = NULL;
3207 ieee80211_scan_completed(wl->hw, true);
3210 wl1271_ps_elp_sleep(wl);
3212 mutex_unlock(&wl->mutex);
3214 cancel_delayed_work_sync(&wl->scan_complete_work);
3217 static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
3218 struct ieee80211_vif *vif,
3219 struct cfg80211_sched_scan_request *req,
3220 struct ieee80211_sched_scan_ies *ies)
3222 struct wl1271 *wl = hw->priv;
3223 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3226 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
3228 mutex_lock(&wl->mutex);
3230 if (wl->state == WL1271_STATE_OFF) {
3235 ret = wl1271_ps_elp_wakeup(wl);
3239 ret = wl1271_scan_sched_scan_config(wl, wlvif, req, ies);
3243 ret = wl1271_scan_sched_scan_start(wl, wlvif);
3247 wl->sched_scanning = true;
3250 wl1271_ps_elp_sleep(wl);
3252 mutex_unlock(&wl->mutex);
3256 static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
3257 struct ieee80211_vif *vif)
3259 struct wl1271 *wl = hw->priv;
3262 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
3264 mutex_lock(&wl->mutex);
3266 if (wl->state == WL1271_STATE_OFF)
3269 ret = wl1271_ps_elp_wakeup(wl);
3273 wl1271_scan_sched_scan_stop(wl);
3275 wl1271_ps_elp_sleep(wl);
3277 mutex_unlock(&wl->mutex);
3280 static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
3282 struct wl1271 *wl = hw->priv;
3285 mutex_lock(&wl->mutex);
3287 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3292 ret = wl1271_ps_elp_wakeup(wl);
3296 ret = wl1271_acx_frag_threshold(wl, value);
3298 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
3300 wl1271_ps_elp_sleep(wl);
3303 mutex_unlock(&wl->mutex);
3308 static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
3310 struct wl1271 *wl = hw->priv;
3311 struct wl12xx_vif *wlvif;
3314 mutex_lock(&wl->mutex);
3316 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3321 ret = wl1271_ps_elp_wakeup(wl);
3325 wl12xx_for_each_wlvif(wl, wlvif) {
3326 ret = wl1271_acx_rts_threshold(wl, wlvif, value);
3328 wl1271_warning("set rts threshold failed: %d", ret);
3330 wl1271_ps_elp_sleep(wl);
3333 mutex_unlock(&wl->mutex);
3338 static int wl1271_ssid_set(struct ieee80211_vif *vif, struct sk_buff *skb,
3341 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3343 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
3347 wl1271_error("No SSID in IEs!");
3352 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
3353 wl1271_error("SSID is too long!");
3357 wlvif->ssid_len = ssid_len;
3358 memcpy(wlvif->ssid, ptr+2, ssid_len);
3362 static void wl12xx_remove_ie(struct sk_buff *skb, u8 eid, int ieoffset)
3365 const u8 *next, *end = skb->data + skb->len;
3366 u8 *ie = (u8 *)cfg80211_find_ie(eid, skb->data + ieoffset,
3367 skb->len - ieoffset);
3372 memmove(ie, next, end - next);
3373 skb_trim(skb, skb->len - len);
3376 static void wl12xx_remove_vendor_ie(struct sk_buff *skb,
3377 unsigned int oui, u8 oui_type,
3381 const u8 *next, *end = skb->data + skb->len;
3382 u8 *ie = (u8 *)cfg80211_find_vendor_ie(oui, oui_type,
3383 skb->data + ieoffset,
3384 skb->len - ieoffset);
3389 memmove(ie, next, end - next);
3390 skb_trim(skb, skb->len - len);
3393 static int wl1271_ap_set_probe_resp_tmpl(struct wl1271 *wl, u32 rates,
3394 struct ieee80211_vif *vif)
3396 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3397 struct sk_buff *skb;
3400 skb = ieee80211_proberesp_get(wl->hw, vif);
3404 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
3405 CMD_TEMPL_AP_PROBE_RESPONSE,
3414 static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271 *wl,
3415 struct ieee80211_vif *vif,
3417 size_t probe_rsp_len,
3420 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3421 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
3422 u8 probe_rsp_templ[WL1271_CMD_TEMPL_MAX_SIZE];
3423 int ssid_ie_offset, ie_offset, templ_len;
3426 /* no need to change probe response if the SSID is set correctly */
3427 if (wlvif->ssid_len > 0)
3428 return wl1271_cmd_template_set(wl, wlvif->role_id,
3429 CMD_TEMPL_AP_PROBE_RESPONSE,
3434 if (probe_rsp_len + bss_conf->ssid_len > WL1271_CMD_TEMPL_MAX_SIZE) {
3435 wl1271_error("probe_rsp template too big");
3439 /* start searching from IE offset */
3440 ie_offset = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
3442 ptr = cfg80211_find_ie(WLAN_EID_SSID, probe_rsp_data + ie_offset,
3443 probe_rsp_len - ie_offset);
3445 wl1271_error("No SSID in beacon!");
3449 ssid_ie_offset = ptr - probe_rsp_data;
3450 ptr += (ptr[1] + 2);
3452 memcpy(probe_rsp_templ, probe_rsp_data, ssid_ie_offset);
3454 /* insert SSID from bss_conf */
3455 probe_rsp_templ[ssid_ie_offset] = WLAN_EID_SSID;
3456 probe_rsp_templ[ssid_ie_offset + 1] = bss_conf->ssid_len;
3457 memcpy(probe_rsp_templ + ssid_ie_offset + 2,
3458 bss_conf->ssid, bss_conf->ssid_len);
3459 templ_len = ssid_ie_offset + 2 + bss_conf->ssid_len;
3461 memcpy(probe_rsp_templ + ssid_ie_offset + 2 + bss_conf->ssid_len,
3462 ptr, probe_rsp_len - (ptr - probe_rsp_data));
3463 templ_len += probe_rsp_len - (ptr - probe_rsp_data);
3465 return wl1271_cmd_template_set(wl, wlvif->role_id,
3466 CMD_TEMPL_AP_PROBE_RESPONSE,
3472 static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
3473 struct ieee80211_vif *vif,
3474 struct ieee80211_bss_conf *bss_conf,
3477 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3480 if (changed & BSS_CHANGED_ERP_SLOT) {
3481 if (bss_conf->use_short_slot)
3482 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_SHORT);
3484 ret = wl1271_acx_slot(wl, wlvif, SLOT_TIME_LONG);
3486 wl1271_warning("Set slot time failed %d", ret);
3491 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
3492 if (bss_conf->use_short_preamble)
3493 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_SHORT);
3495 wl1271_acx_set_preamble(wl, wlvif, ACX_PREAMBLE_LONG);
3498 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
3499 if (bss_conf->use_cts_prot)
3500 ret = wl1271_acx_cts_protect(wl, wlvif,
3503 ret = wl1271_acx_cts_protect(wl, wlvif,
3504 CTSPROTECT_DISABLE);
3506 wl1271_warning("Set ctsprotect failed %d", ret);
3515 static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
3516 struct ieee80211_vif *vif,
3517 struct ieee80211_bss_conf *bss_conf,
3520 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3521 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
3524 if ((changed & BSS_CHANGED_BEACON_INT)) {
3525 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
3526 bss_conf->beacon_int);
3528 wlvif->beacon_int = bss_conf->beacon_int;
3531 if ((changed & BSS_CHANGED_AP_PROBE_RESP) && is_ap) {
3532 u32 rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3533 if (!wl1271_ap_set_probe_resp_tmpl(wl, rate, vif)) {
3534 wl1271_debug(DEBUG_AP, "probe response updated");
3535 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags);
3539 if ((changed & BSS_CHANGED_BEACON)) {
3540 struct ieee80211_hdr *hdr;
3542 int ieoffset = offsetof(struct ieee80211_mgmt,
3544 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
3552 wl1271_debug(DEBUG_MASTER, "beacon updated");
3554 ret = wl1271_ssid_set(vif, beacon, ieoffset);
3556 dev_kfree_skb(beacon);
3559 min_rate = wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
3560 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
3562 ret = wl1271_cmd_template_set(wl, wlvif->role_id, tmpl_id,
3567 dev_kfree_skb(beacon);
3572 * In case we already have a probe-resp beacon set explicitly
3573 * by usermode, don't use the beacon data.
3575 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET, &wlvif->flags))
3578 /* remove TIM ie from probe response */
3579 wl12xx_remove_ie(beacon, WLAN_EID_TIM, ieoffset);
3582 * remove p2p ie from probe response.
3583 * the fw reponds to probe requests that don't include
3584 * the p2p ie. probe requests with p2p ie will be passed,
3585 * and will be responded by the supplicant (the spec
3586 * forbids including the p2p ie when responding to probe
3587 * requests that didn't include it).
3589 wl12xx_remove_vendor_ie(beacon, WLAN_OUI_WFA,
3590 WLAN_OUI_TYPE_WFA_P2P, ieoffset);
3592 hdr = (struct ieee80211_hdr *) beacon->data;
3593 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3594 IEEE80211_STYPE_PROBE_RESP);
3596 ret = wl1271_ap_set_probe_resp_tmpl_legacy(wl, vif,
3601 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
3602 CMD_TEMPL_PROBE_RESPONSE,
3607 dev_kfree_skb(beacon);
3614 wl1271_error("beacon info change failed: %d", ret);
3618 /* AP mode changes */
3619 static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
3620 struct ieee80211_vif *vif,
3621 struct ieee80211_bss_conf *bss_conf,
3624 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3627 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3628 u32 rates = bss_conf->basic_rates;
3630 wlvif->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates,
3632 wlvif->basic_rate = wl1271_tx_min_rate_get(wl,
3633 wlvif->basic_rate_set);
3635 ret = wl1271_init_ap_rates(wl, wlvif);
3637 wl1271_error("AP rate policy change failed %d", ret);
3641 ret = wl1271_ap_init_templates(wl, vif);
3646 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3650 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3651 if (bss_conf->enable_beacon) {
3652 if (!test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3653 ret = wl12xx_cmd_role_start_ap(wl, wlvif);
3657 ret = wl1271_ap_init_hwenc(wl, wlvif);
3661 set_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3662 wl1271_debug(DEBUG_AP, "started AP");
3665 if (test_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags)) {
3666 ret = wl12xx_cmd_role_stop_ap(wl, wlvif);
3670 clear_bit(WLVIF_FLAG_AP_STARTED, &wlvif->flags);
3671 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET,
3673 wl1271_debug(DEBUG_AP, "stopped AP");
3678 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3682 /* Handle HT information change */
3683 if ((changed & BSS_CHANGED_HT) &&
3684 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3685 ret = wl1271_acx_set_ht_information(wl, wlvif,
3686 bss_conf->ht_operation_mode);
3688 wl1271_warning("Set ht information failed %d", ret);
3697 /* STA/IBSS mode changes */
3698 static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3699 struct ieee80211_vif *vif,
3700 struct ieee80211_bss_conf *bss_conf,
3703 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
3704 bool do_join = false, set_assoc = false;
3705 bool is_ibss = (wlvif->bss_type == BSS_TYPE_IBSS);
3706 bool ibss_joined = false;
3707 u32 sta_rate_set = 0;
3709 struct ieee80211_sta *sta;
3710 bool sta_exists = false;
3711 struct ieee80211_sta_ht_cap sta_ht_cap;
3714 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3720 if (changed & BSS_CHANGED_IBSS) {
3721 if (bss_conf->ibss_joined) {
3722 set_bit(WLVIF_FLAG_IBSS_JOINED, &wlvif->flags);
3725 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED,
3727 wl1271_unjoin(wl, wlvif);
3731 if ((changed & BSS_CHANGED_BEACON_INT) && ibss_joined)
3734 /* Need to update the SSID (for filtering etc) */
3735 if ((changed & BSS_CHANGED_BEACON) && ibss_joined)
3738 if ((changed & BSS_CHANGED_BEACON_ENABLED) && ibss_joined) {
3739 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3740 bss_conf->enable_beacon ? "enabled" : "disabled");
3745 if (changed & BSS_CHANGED_IDLE && !is_ibss) {
3746 ret = wl1271_sta_handle_idle(wl, wlvif, bss_conf->idle);
3748 wl1271_warning("idle mode change failed %d", ret);
3751 if ((changed & BSS_CHANGED_CQM)) {
3752 bool enable = false;
3753 if (bss_conf->cqm_rssi_thold)
3755 ret = wl1271_acx_rssi_snr_trigger(wl, wlvif, enable,
3756 bss_conf->cqm_rssi_thold,
3757 bss_conf->cqm_rssi_hyst);
3760 wlvif->rssi_thold = bss_conf->cqm_rssi_thold;
3763 if (changed & BSS_CHANGED_BSSID)
3764 if (!is_zero_ether_addr(bss_conf->bssid)) {
3765 ret = wl12xx_cmd_build_null_data(wl, wlvif);
3769 ret = wl1271_build_qos_null_data(wl, vif);
3774 if (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_HT)) {
3776 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3780 /* save the supp_rates of the ap */
3781 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3782 if (sta->ht_cap.ht_supported)
3784 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
3785 sta_ht_cap = sta->ht_cap;
3792 if ((changed & BSS_CHANGED_ASSOC)) {
3793 if (bss_conf->assoc) {
3796 wlvif->aid = bss_conf->aid;
3797 wlvif->beacon_int = bss_conf->beacon_int;
3802 * use basic rates from AP, and determine lowest rate
3803 * to use with control frames.
3805 rates = bss_conf->basic_rates;
3806 wlvif->basic_rate_set =
3807 wl1271_tx_enabled_rates_get(wl, rates,
3810 wl1271_tx_min_rate_get(wl,
3811 wlvif->basic_rate_set);
3814 wl1271_tx_enabled_rates_get(wl,
3817 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3822 * with wl1271, we don't need to update the
3823 * beacon_int and dtim_period, because the firmware
3824 * updates it by itself when the first beacon is
3825 * received after a join.
3827 ret = wl1271_cmd_build_ps_poll(wl, wlvif, wlvif->aid);
3832 * Get a template for hardware connection maintenance
3834 dev_kfree_skb(wlvif->probereq);
3835 wlvif->probereq = wl1271_cmd_build_ap_probe_req(wl,
3838 ieoffset = offsetof(struct ieee80211_mgmt,
3839 u.probe_req.variable);
3840 wl1271_ssid_set(vif, wlvif->probereq, ieoffset);
3842 /* enable the connection monitoring feature */
3843 ret = wl1271_acx_conn_monit_params(wl, wlvif, true);
3847 /* use defaults when not associated */
3849 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED,
3852 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT,
3856 /* free probe-request template */
3857 dev_kfree_skb(wlvif->probereq);
3858 wlvif->probereq = NULL;
3860 /* revert back to minimum rates for the current band */
3861 wl1271_set_band_rate(wl, wlvif);
3863 wl1271_tx_min_rate_get(wl,
3864 wlvif->basic_rate_set);
3865 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3869 /* disable connection monitor features */
3870 ret = wl1271_acx_conn_monit_params(wl, wlvif, false);
3872 /* Disable the keep-alive feature */
3873 ret = wl1271_acx_keep_alive_mode(wl, wlvif, false);
3877 /* restore the bssid filter and go to dummy bssid */
3880 * we might have to disable roc, if there was
3881 * no IF_OPER_UP notification.
3884 ret = wl12xx_croc(wl, wlvif->role_id);
3889 * (we also need to disable roc in case of
3890 * roaming on the same channel. until we will
3891 * have a better flow...)
3893 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
3894 ret = wl12xx_croc(wl,
3895 wlvif->dev_role_id);
3900 wl1271_unjoin(wl, wlvif);
3901 if (!bss_conf->idle)
3902 wl12xx_start_dev(wl, wlvif);
3907 if (changed & BSS_CHANGED_IBSS) {
3908 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3909 bss_conf->ibss_joined);
3911 if (bss_conf->ibss_joined) {
3912 u32 rates = bss_conf->basic_rates;
3913 wlvif->basic_rate_set =
3914 wl1271_tx_enabled_rates_get(wl, rates,
3917 wl1271_tx_min_rate_get(wl,
3918 wlvif->basic_rate_set);
3920 /* by default, use 11b + OFDM rates */
3921 wlvif->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3922 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
3928 ret = wl1271_bss_erp_info_changed(wl, vif, bss_conf, changed);
3933 ret = wl1271_join(wl, wlvif, set_assoc);
3935 wl1271_warning("cmd join failed %d", ret);
3939 /* ROC until connected (after EAPOL exchange) */
3941 ret = wl12xx_roc(wl, wlvif, wlvif->role_id);
3945 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags))
3946 wl12xx_set_authorized(wl, wlvif);
3949 * stop device role if started (we might already be in
3952 if (wl12xx_dev_role_started(wlvif)) {
3953 ret = wl12xx_stop_dev(wl, wlvif);
3959 /* Handle new association with HT. Do this after join. */
3961 if ((changed & BSS_CHANGED_HT) &&
3962 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3963 ret = wl1271_acx_set_ht_capabilities(wl,
3968 wl1271_warning("Set ht cap true failed %d",
3973 /* handle new association without HT and disassociation */
3974 else if (changed & BSS_CHANGED_ASSOC) {
3975 ret = wl1271_acx_set_ht_capabilities(wl,
3980 wl1271_warning("Set ht cap false failed %d",
3987 /* Handle HT information change. Done after join. */
3988 if ((changed & BSS_CHANGED_HT) &&
3989 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3990 ret = wl1271_acx_set_ht_information(wl, wlvif,
3991 bss_conf->ht_operation_mode);
3993 wl1271_warning("Set ht information failed %d", ret);
3998 /* Handle arp filtering. Done after join. */
3999 if ((changed & BSS_CHANGED_ARP_FILTER) ||
4000 (!is_ibss && (changed & BSS_CHANGED_QOS))) {
4001 __be32 addr = bss_conf->arp_addr_list[0];
4002 wlvif->sta.qos = bss_conf->qos;
4003 WARN_ON(wlvif->bss_type != BSS_TYPE_STA_BSS);
4005 if (bss_conf->arp_addr_cnt == 1 &&
4006 bss_conf->arp_filter_enabled) {
4007 wlvif->ip_addr = addr;
4009 * The template should have been configured only upon
4010 * association. however, it seems that the correct ip
4011 * isn't being set (when sending), so we have to
4012 * reconfigure the template upon every ip change.
4014 ret = wl1271_cmd_build_arp_rsp(wl, wlvif);
4016 wl1271_warning("build arp rsp failed: %d", ret);
4020 ret = wl1271_acx_arp_ip_filter(wl, wlvif,
4021 (ACX_ARP_FILTER_ARP_FILTERING |
4022 ACX_ARP_FILTER_AUTO_ARP),
4026 ret = wl1271_acx_arp_ip_filter(wl, wlvif, 0, addr);
4037 static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
4038 struct ieee80211_vif *vif,
4039 struct ieee80211_bss_conf *bss_conf,
4042 struct wl1271 *wl = hw->priv;
4043 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4044 bool is_ap = (wlvif->bss_type == BSS_TYPE_AP_BSS);
4047 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
4050 mutex_lock(&wl->mutex);
4052 if (unlikely(wl->state == WL1271_STATE_OFF))
4055 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags)))
4058 ret = wl1271_ps_elp_wakeup(wl);
4063 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
4065 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
4067 wl1271_ps_elp_sleep(wl);
4070 mutex_unlock(&wl->mutex);
4073 static int wl1271_op_conf_tx(struct ieee80211_hw *hw,
4074 struct ieee80211_vif *vif, u16 queue,
4075 const struct ieee80211_tx_queue_params *params)
4077 struct wl1271 *wl = hw->priv;
4078 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4082 mutex_lock(&wl->mutex);
4084 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
4087 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
4089 ps_scheme = CONF_PS_SCHEME_LEGACY;
4091 if (!test_bit(WLVIF_FLAG_INITIALIZED, &wlvif->flags))
4094 ret = wl1271_ps_elp_wakeup(wl);
4099 * the txop is confed in units of 32us by the mac80211,
4102 ret = wl1271_acx_ac_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
4103 params->cw_min, params->cw_max,
4104 params->aifs, params->txop << 5);
4108 ret = wl1271_acx_tid_cfg(wl, wlvif, wl1271_tx_get_queue(queue),
4109 CONF_CHANNEL_TYPE_EDCF,
4110 wl1271_tx_get_queue(queue),
4111 ps_scheme, CONF_ACK_POLICY_LEGACY,
4115 wl1271_ps_elp_sleep(wl);
4118 mutex_unlock(&wl->mutex);
4123 static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw,
4124 struct ieee80211_vif *vif)
4127 struct wl1271 *wl = hw->priv;
4128 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4129 u64 mactime = ULLONG_MAX;
4132 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
4134 mutex_lock(&wl->mutex);
4136 if (unlikely(wl->state == WL1271_STATE_OFF))
4139 ret = wl1271_ps_elp_wakeup(wl);
4143 ret = wl12xx_acx_tsf_info(wl, wlvif, &mactime);
4148 wl1271_ps_elp_sleep(wl);
4151 mutex_unlock(&wl->mutex);
4155 static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
4156 struct survey_info *survey)
4158 struct wl1271 *wl = hw->priv;
4159 struct ieee80211_conf *conf = &hw->conf;
4164 survey->channel = conf->channel;
4165 survey->filled = SURVEY_INFO_NOISE_DBM;
4166 survey->noise = wl->noise;
4171 static int wl1271_allocate_sta(struct wl1271 *wl,
4172 struct wl12xx_vif *wlvif,
4173 struct ieee80211_sta *sta)
4175 struct wl1271_station *wl_sta;
4179 if (wl->active_sta_count >= AP_MAX_STATIONS) {
4180 wl1271_warning("could not allocate HLID - too much stations");
4184 wl_sta = (struct wl1271_station *)sta->drv_priv;
4185 ret = wl12xx_allocate_link(wl, wlvif, &wl_sta->hlid);
4187 wl1271_warning("could not allocate HLID - too many links");
4191 set_bit(wl_sta->hlid, wlvif->ap.sta_hlid_map);
4192 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
4193 wl->active_sta_count++;
4197 void wl1271_free_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 hlid)
4199 if (!test_bit(hlid, wlvif->ap.sta_hlid_map))
4202 clear_bit(hlid, wlvif->ap.sta_hlid_map);
4203 memset(wl->links[hlid].addr, 0, ETH_ALEN);
4204 wl->links[hlid].ba_bitmap = 0;
4205 __clear_bit(hlid, &wl->ap_ps_map);
4206 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
4207 wl12xx_free_link(wl, wlvif, &hlid);
4208 wl->active_sta_count--;
4211 * rearm the tx watchdog when the last STA is freed - give the FW a
4212 * chance to return STA-buffered packets before complaining.
4214 if (wl->active_sta_count == 0)
4215 wl12xx_rearm_tx_watchdog_locked(wl);
4218 static int wl12xx_sta_add(struct wl1271 *wl,
4219 struct wl12xx_vif *wlvif,
4220 struct ieee80211_sta *sta)
4222 struct wl1271_station *wl_sta;
4226 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
4228 ret = wl1271_allocate_sta(wl, wlvif, sta);
4232 wl_sta = (struct wl1271_station *)sta->drv_priv;
4233 hlid = wl_sta->hlid;
4235 ret = wl12xx_cmd_add_peer(wl, wlvif, sta, hlid);
4237 wl1271_free_sta(wl, wlvif, hlid);
4242 static int wl12xx_sta_remove(struct wl1271 *wl,
4243 struct wl12xx_vif *wlvif,
4244 struct ieee80211_sta *sta)
4246 struct wl1271_station *wl_sta;
4249 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
4251 wl_sta = (struct wl1271_station *)sta->drv_priv;
4253 if (WARN_ON(!test_bit(id, wlvif->ap.sta_hlid_map)))
4256 ret = wl12xx_cmd_remove_peer(wl, wl_sta->hlid);
4260 wl1271_free_sta(wl, wlvif, wl_sta->hlid);
4264 static int wl12xx_update_sta_state(struct wl1271 *wl,
4265 struct wl12xx_vif *wlvif,
4266 struct ieee80211_sta *sta,
4267 enum ieee80211_sta_state old_state,
4268 enum ieee80211_sta_state new_state)
4270 struct wl1271_station *wl_sta;
4272 bool is_ap = wlvif->bss_type == BSS_TYPE_AP_BSS;
4273 bool is_sta = wlvif->bss_type == BSS_TYPE_STA_BSS;
4276 wl_sta = (struct wl1271_station *)sta->drv_priv;
4277 hlid = wl_sta->hlid;
4279 /* Add station (AP mode) */
4281 old_state == IEEE80211_STA_NOTEXIST &&
4282 new_state == IEEE80211_STA_NONE)
4283 return wl12xx_sta_add(wl, wlvif, sta);
4285 /* Remove station (AP mode) */
4287 old_state == IEEE80211_STA_NONE &&
4288 new_state == IEEE80211_STA_NOTEXIST) {
4290 wl12xx_sta_remove(wl, wlvif, sta);
4294 /* Authorize station (AP mode) */
4296 new_state == IEEE80211_STA_AUTHORIZED) {
4297 ret = wl12xx_cmd_set_peer_state(wl, hlid);
4301 ret = wl1271_acx_set_ht_capabilities(wl, &sta->ht_cap, true,
4306 /* Authorize station */
4308 new_state == IEEE80211_STA_AUTHORIZED) {
4309 set_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
4310 return wl12xx_set_authorized(wl, wlvif);
4314 old_state == IEEE80211_STA_AUTHORIZED &&
4315 new_state == IEEE80211_STA_ASSOC) {
4316 clear_bit(WLVIF_FLAG_STA_AUTHORIZED, &wlvif->flags);
4323 static int wl12xx_op_sta_state(struct ieee80211_hw *hw,
4324 struct ieee80211_vif *vif,
4325 struct ieee80211_sta *sta,
4326 enum ieee80211_sta_state old_state,
4327 enum ieee80211_sta_state new_state)
4329 struct wl1271 *wl = hw->priv;
4330 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4333 wl1271_debug(DEBUG_MAC80211, "mac80211 sta %d state=%d->%d",
4334 sta->aid, old_state, new_state);
4336 mutex_lock(&wl->mutex);
4338 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4343 ret = wl1271_ps_elp_wakeup(wl);
4347 ret = wl12xx_update_sta_state(wl, wlvif, sta, old_state, new_state);
4349 wl1271_ps_elp_sleep(wl);
4351 mutex_unlock(&wl->mutex);
4352 if (new_state < old_state)
4357 static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
4358 struct ieee80211_vif *vif,
4359 enum ieee80211_ampdu_mlme_action action,
4360 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
4363 struct wl1271 *wl = hw->priv;
4364 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4366 u8 hlid, *ba_bitmap;
4368 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu action %d tid %d", action,
4371 /* sanity check - the fields in FW are only 8bits wide */
4372 if (WARN_ON(tid > 0xFF))
4375 mutex_lock(&wl->mutex);
4377 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4382 if (wlvif->bss_type == BSS_TYPE_STA_BSS) {
4383 hlid = wlvif->sta.hlid;
4384 ba_bitmap = &wlvif->sta.ba_rx_bitmap;
4385 } else if (wlvif->bss_type == BSS_TYPE_AP_BSS) {
4386 struct wl1271_station *wl_sta;
4388 wl_sta = (struct wl1271_station *)sta->drv_priv;
4389 hlid = wl_sta->hlid;
4390 ba_bitmap = &wl->links[hlid].ba_bitmap;
4396 ret = wl1271_ps_elp_wakeup(wl);
4400 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
4404 case IEEE80211_AMPDU_RX_START:
4405 if (!wlvif->ba_support || !wlvif->ba_allowed) {
4410 if (wl->ba_rx_session_count >= RX_BA_MAX_SESSIONS) {
4412 wl1271_error("exceeded max RX BA sessions");
4416 if (*ba_bitmap & BIT(tid)) {
4418 wl1271_error("cannot enable RX BA session on active "
4423 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, *ssn, true,
4426 *ba_bitmap |= BIT(tid);
4427 wl->ba_rx_session_count++;
4431 case IEEE80211_AMPDU_RX_STOP:
4432 if (!(*ba_bitmap & BIT(tid))) {
4434 wl1271_error("no active RX BA session on tid: %d",
4439 ret = wl12xx_acx_set_ba_receiver_session(wl, tid, 0, false,
4442 *ba_bitmap &= ~BIT(tid);
4443 wl->ba_rx_session_count--;
4448 * The BA initiator session management in FW independently.
4449 * Falling break here on purpose for all TX APDU commands.
4451 case IEEE80211_AMPDU_TX_START:
4452 case IEEE80211_AMPDU_TX_STOP:
4453 case IEEE80211_AMPDU_TX_OPERATIONAL:
4458 wl1271_error("Incorrect ampdu action id=%x\n", action);
4462 wl1271_ps_elp_sleep(wl);
4465 mutex_unlock(&wl->mutex);
4470 static int wl12xx_set_bitrate_mask(struct ieee80211_hw *hw,
4471 struct ieee80211_vif *vif,
4472 const struct cfg80211_bitrate_mask *mask)
4474 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
4475 struct wl1271 *wl = hw->priv;
4478 wl1271_debug(DEBUG_MAC80211, "mac80211 set_bitrate_mask 0x%x 0x%x",
4479 mask->control[NL80211_BAND_2GHZ].legacy,
4480 mask->control[NL80211_BAND_5GHZ].legacy);
4482 mutex_lock(&wl->mutex);
4484 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
4485 wlvif->bitrate_masks[i] =
4486 wl1271_tx_enabled_rates_get(wl,
4487 mask->control[i].legacy,
4490 if (unlikely(wl->state == WL1271_STATE_OFF))
4493 if (wlvif->bss_type == BSS_TYPE_STA_BSS &&
4494 !test_bit(WLVIF_FLAG_STA_ASSOCIATED, &wlvif->flags)) {
4496 ret = wl1271_ps_elp_wakeup(wl);
4500 wl1271_set_band_rate(wl, wlvif);
4502 wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
4503 ret = wl1271_acx_sta_rate_policies(wl, wlvif);
4505 wl1271_ps_elp_sleep(wl);
4508 mutex_unlock(&wl->mutex);
4513 static void wl12xx_op_channel_switch(struct ieee80211_hw *hw,
4514 struct ieee80211_channel_switch *ch_switch)
4516 struct wl1271 *wl = hw->priv;
4517 struct wl12xx_vif *wlvif;
4520 wl1271_debug(DEBUG_MAC80211, "mac80211 channel switch");
4522 wl1271_tx_flush(wl);
4524 mutex_lock(&wl->mutex);
4526 if (unlikely(wl->state == WL1271_STATE_OFF)) {
4527 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4528 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
4529 ieee80211_chswitch_done(vif, false);
4534 ret = wl1271_ps_elp_wakeup(wl);
4538 /* TODO: change mac80211 to pass vif as param */
4539 wl12xx_for_each_wlvif_sta(wl, wlvif) {
4540 ret = wl12xx_cmd_channel_switch(wl, wlvif, ch_switch);
4543 set_bit(WLVIF_FLAG_CS_PROGRESS, &wlvif->flags);
4546 wl1271_ps_elp_sleep(wl);
4549 mutex_unlock(&wl->mutex);
4552 static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
4554 struct wl1271 *wl = hw->priv;
4557 mutex_lock(&wl->mutex);
4559 if (unlikely(wl->state == WL1271_STATE_OFF))
4562 /* packets are considered pending if in the TX queue or the FW */
4563 ret = (wl1271_tx_total_queue_count(wl) > 0) || (wl->tx_frames_cnt > 0);
4565 mutex_unlock(&wl->mutex);
4570 /* can't be const, mac80211 writes to this */
4571 static struct ieee80211_rate wl1271_rates[] = {
4573 .hw_value = CONF_HW_BIT_RATE_1MBPS,
4574 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
4576 .hw_value = CONF_HW_BIT_RATE_2MBPS,
4577 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
4578 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4580 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
4581 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
4582 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4584 .hw_value = CONF_HW_BIT_RATE_11MBPS,
4585 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
4586 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
4588 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4589 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4591 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4592 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4594 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4595 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4597 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4598 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4600 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4601 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4603 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4604 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4606 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4607 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4609 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4610 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4613 /* can't be const, mac80211 writes to this */
4614 static struct ieee80211_channel wl1271_channels[] = {
4615 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
4616 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
4617 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
4618 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
4619 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
4620 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
4621 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
4622 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
4623 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
4624 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
4625 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
4626 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
4627 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
4628 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
4631 /* mapping to indexes for wl1271_rates */
4632 static const u8 wl1271_rate_to_idx_2ghz[] = {
4633 /* MCS rates are used only with 11n */
4634 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
4635 7, /* CONF_HW_RXTX_RATE_MCS7 */
4636 6, /* CONF_HW_RXTX_RATE_MCS6 */
4637 5, /* CONF_HW_RXTX_RATE_MCS5 */
4638 4, /* CONF_HW_RXTX_RATE_MCS4 */
4639 3, /* CONF_HW_RXTX_RATE_MCS3 */
4640 2, /* CONF_HW_RXTX_RATE_MCS2 */
4641 1, /* CONF_HW_RXTX_RATE_MCS1 */
4642 0, /* CONF_HW_RXTX_RATE_MCS0 */
4644 11, /* CONF_HW_RXTX_RATE_54 */
4645 10, /* CONF_HW_RXTX_RATE_48 */
4646 9, /* CONF_HW_RXTX_RATE_36 */
4647 8, /* CONF_HW_RXTX_RATE_24 */
4649 /* TI-specific rate */
4650 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4652 7, /* CONF_HW_RXTX_RATE_18 */
4653 6, /* CONF_HW_RXTX_RATE_12 */
4654 3, /* CONF_HW_RXTX_RATE_11 */
4655 5, /* CONF_HW_RXTX_RATE_9 */
4656 4, /* CONF_HW_RXTX_RATE_6 */
4657 2, /* CONF_HW_RXTX_RATE_5_5 */
4658 1, /* CONF_HW_RXTX_RATE_2 */
4659 0 /* CONF_HW_RXTX_RATE_1 */
4662 /* 11n STA capabilities */
4663 #define HW_RX_HIGHEST_RATE 72
4665 #define WL12XX_HT_CAP { \
4666 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4667 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
4668 .ht_supported = true, \
4669 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4670 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4672 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4673 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4674 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4678 /* can't be const, mac80211 writes to this */
4679 static struct ieee80211_supported_band wl1271_band_2ghz = {
4680 .channels = wl1271_channels,
4681 .n_channels = ARRAY_SIZE(wl1271_channels),
4682 .bitrates = wl1271_rates,
4683 .n_bitrates = ARRAY_SIZE(wl1271_rates),
4684 .ht_cap = WL12XX_HT_CAP,
4687 /* 5 GHz data rates for WL1273 */
4688 static struct ieee80211_rate wl1271_rates_5ghz[] = {
4690 .hw_value = CONF_HW_BIT_RATE_6MBPS,
4691 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
4693 .hw_value = CONF_HW_BIT_RATE_9MBPS,
4694 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
4696 .hw_value = CONF_HW_BIT_RATE_12MBPS,
4697 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
4699 .hw_value = CONF_HW_BIT_RATE_18MBPS,
4700 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
4702 .hw_value = CONF_HW_BIT_RATE_24MBPS,
4703 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
4705 .hw_value = CONF_HW_BIT_RATE_36MBPS,
4706 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
4708 .hw_value = CONF_HW_BIT_RATE_48MBPS,
4709 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
4711 .hw_value = CONF_HW_BIT_RATE_54MBPS,
4712 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
4715 /* 5 GHz band channels for WL1273 */
4716 static struct ieee80211_channel wl1271_channels_5ghz[] = {
4717 { .hw_value = 7, .center_freq = 5035, .max_power = 25 },
4718 { .hw_value = 8, .center_freq = 5040, .max_power = 25 },
4719 { .hw_value = 9, .center_freq = 5045, .max_power = 25 },
4720 { .hw_value = 11, .center_freq = 5055, .max_power = 25 },
4721 { .hw_value = 12, .center_freq = 5060, .max_power = 25 },
4722 { .hw_value = 16, .center_freq = 5080, .max_power = 25 },
4723 { .hw_value = 34, .center_freq = 5170, .max_power = 25 },
4724 { .hw_value = 36, .center_freq = 5180, .max_power = 25 },
4725 { .hw_value = 38, .center_freq = 5190, .max_power = 25 },
4726 { .hw_value = 40, .center_freq = 5200, .max_power = 25 },
4727 { .hw_value = 42, .center_freq = 5210, .max_power = 25 },
4728 { .hw_value = 44, .center_freq = 5220, .max_power = 25 },
4729 { .hw_value = 46, .center_freq = 5230, .max_power = 25 },
4730 { .hw_value = 48, .center_freq = 5240, .max_power = 25 },
4731 { .hw_value = 52, .center_freq = 5260, .max_power = 25 },
4732 { .hw_value = 56, .center_freq = 5280, .max_power = 25 },
4733 { .hw_value = 60, .center_freq = 5300, .max_power = 25 },
4734 { .hw_value = 64, .center_freq = 5320, .max_power = 25 },
4735 { .hw_value = 100, .center_freq = 5500, .max_power = 25 },
4736 { .hw_value = 104, .center_freq = 5520, .max_power = 25 },
4737 { .hw_value = 108, .center_freq = 5540, .max_power = 25 },
4738 { .hw_value = 112, .center_freq = 5560, .max_power = 25 },
4739 { .hw_value = 116, .center_freq = 5580, .max_power = 25 },
4740 { .hw_value = 120, .center_freq = 5600, .max_power = 25 },
4741 { .hw_value = 124, .center_freq = 5620, .max_power = 25 },
4742 { .hw_value = 128, .center_freq = 5640, .max_power = 25 },
4743 { .hw_value = 132, .center_freq = 5660, .max_power = 25 },
4744 { .hw_value = 136, .center_freq = 5680, .max_power = 25 },
4745 { .hw_value = 140, .center_freq = 5700, .max_power = 25 },
4746 { .hw_value = 149, .center_freq = 5745, .max_power = 25 },
4747 { .hw_value = 153, .center_freq = 5765, .max_power = 25 },
4748 { .hw_value = 157, .center_freq = 5785, .max_power = 25 },
4749 { .hw_value = 161, .center_freq = 5805, .max_power = 25 },
4750 { .hw_value = 165, .center_freq = 5825, .max_power = 25 },
4753 /* mapping to indexes for wl1271_rates_5ghz */
4754 static const u8 wl1271_rate_to_idx_5ghz[] = {
4755 /* MCS rates are used only with 11n */
4756 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
4757 7, /* CONF_HW_RXTX_RATE_MCS7 */
4758 6, /* CONF_HW_RXTX_RATE_MCS6 */
4759 5, /* CONF_HW_RXTX_RATE_MCS5 */
4760 4, /* CONF_HW_RXTX_RATE_MCS4 */
4761 3, /* CONF_HW_RXTX_RATE_MCS3 */
4762 2, /* CONF_HW_RXTX_RATE_MCS2 */
4763 1, /* CONF_HW_RXTX_RATE_MCS1 */
4764 0, /* CONF_HW_RXTX_RATE_MCS0 */
4766 7, /* CONF_HW_RXTX_RATE_54 */
4767 6, /* CONF_HW_RXTX_RATE_48 */
4768 5, /* CONF_HW_RXTX_RATE_36 */
4769 4, /* CONF_HW_RXTX_RATE_24 */
4771 /* TI-specific rate */
4772 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
4774 3, /* CONF_HW_RXTX_RATE_18 */
4775 2, /* CONF_HW_RXTX_RATE_12 */
4776 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
4777 1, /* CONF_HW_RXTX_RATE_9 */
4778 0, /* CONF_HW_RXTX_RATE_6 */
4779 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
4780 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
4781 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
4784 static struct ieee80211_supported_band wl1271_band_5ghz = {
4785 .channels = wl1271_channels_5ghz,
4786 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
4787 .bitrates = wl1271_rates_5ghz,
4788 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
4789 .ht_cap = WL12XX_HT_CAP,
4792 static const u8 *wl1271_band_rate_to_idx[] = {
4793 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
4794 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
4797 static const struct ieee80211_ops wl1271_ops = {
4798 .start = wl1271_op_start,
4799 .stop = wl1271_op_stop,
4800 .add_interface = wl1271_op_add_interface,
4801 .remove_interface = wl1271_op_remove_interface,
4802 .change_interface = wl12xx_op_change_interface,
4804 .suspend = wl1271_op_suspend,
4805 .resume = wl1271_op_resume,
4807 .config = wl1271_op_config,
4808 .prepare_multicast = wl1271_op_prepare_multicast,
4809 .configure_filter = wl1271_op_configure_filter,
4811 .set_key = wl1271_op_set_key,
4812 .hw_scan = wl1271_op_hw_scan,
4813 .cancel_hw_scan = wl1271_op_cancel_hw_scan,
4814 .sched_scan_start = wl1271_op_sched_scan_start,
4815 .sched_scan_stop = wl1271_op_sched_scan_stop,
4816 .bss_info_changed = wl1271_op_bss_info_changed,
4817 .set_frag_threshold = wl1271_op_set_frag_threshold,
4818 .set_rts_threshold = wl1271_op_set_rts_threshold,
4819 .conf_tx = wl1271_op_conf_tx,
4820 .get_tsf = wl1271_op_get_tsf,
4821 .get_survey = wl1271_op_get_survey,
4822 .sta_state = wl12xx_op_sta_state,
4823 .ampdu_action = wl1271_op_ampdu_action,
4824 .tx_frames_pending = wl1271_tx_frames_pending,
4825 .set_bitrate_mask = wl12xx_set_bitrate_mask,
4826 .channel_switch = wl12xx_op_channel_switch,
4827 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
4831 u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
4835 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
4837 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
4838 wl1271_error("Illegal RX rate from HW: %d", rate);
4842 idx = wl1271_band_rate_to_idx[band][rate];
4843 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
4844 wl1271_error("Unsupported RX rate from HW: %d", rate);
4851 static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
4852 struct device_attribute *attr,
4855 struct wl1271 *wl = dev_get_drvdata(dev);
4860 mutex_lock(&wl->mutex);
4861 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
4863 mutex_unlock(&wl->mutex);
4869 static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
4870 struct device_attribute *attr,
4871 const char *buf, size_t count)
4873 struct wl1271 *wl = dev_get_drvdata(dev);
4877 ret = kstrtoul(buf, 10, &res);
4879 wl1271_warning("incorrect value written to bt_coex_mode");
4883 mutex_lock(&wl->mutex);
4887 if (res == wl->sg_enabled)
4890 wl->sg_enabled = res;
4892 if (wl->state == WL1271_STATE_OFF)
4895 ret = wl1271_ps_elp_wakeup(wl);
4899 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4900 wl1271_ps_elp_sleep(wl);
4903 mutex_unlock(&wl->mutex);
4907 static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4908 wl1271_sysfs_show_bt_coex_state,
4909 wl1271_sysfs_store_bt_coex_state);
4911 static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4912 struct device_attribute *attr,
4915 struct wl1271 *wl = dev_get_drvdata(dev);
4920 mutex_lock(&wl->mutex);
4921 if (wl->hw_pg_ver >= 0)
4922 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4924 len = snprintf(buf, len, "n/a\n");
4925 mutex_unlock(&wl->mutex);
4930 static DEVICE_ATTR(hw_pg_ver, S_IRUGO,
4931 wl1271_sysfs_show_hw_pg_ver, NULL);
4933 static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4934 struct bin_attribute *bin_attr,
4935 char *buffer, loff_t pos, size_t count)
4937 struct device *dev = container_of(kobj, struct device, kobj);
4938 struct wl1271 *wl = dev_get_drvdata(dev);
4942 ret = mutex_lock_interruptible(&wl->mutex);
4944 return -ERESTARTSYS;
4946 /* Let only one thread read the log at a time, blocking others */
4947 while (wl->fwlog_size == 0) {
4950 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4952 TASK_INTERRUPTIBLE);
4954 if (wl->fwlog_size != 0) {
4955 finish_wait(&wl->fwlog_waitq, &wait);
4959 mutex_unlock(&wl->mutex);
4962 finish_wait(&wl->fwlog_waitq, &wait);
4964 if (signal_pending(current))
4965 return -ERESTARTSYS;
4967 ret = mutex_lock_interruptible(&wl->mutex);
4969 return -ERESTARTSYS;
4972 /* Check if the fwlog is still valid */
4973 if (wl->fwlog_size < 0) {
4974 mutex_unlock(&wl->mutex);
4978 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4979 len = min(count, (size_t)wl->fwlog_size);
4980 wl->fwlog_size -= len;
4981 memcpy(buffer, wl->fwlog, len);
4983 /* Make room for new messages */
4984 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4986 mutex_unlock(&wl->mutex);
4991 static struct bin_attribute fwlog_attr = {
4992 .attr = {.name = "fwlog", .mode = S_IRUSR},
4993 .read = wl1271_sysfs_read_fwlog,
4996 static bool wl12xx_mac_in_fuse(struct wl1271 *wl)
4998 bool supported = false;
5001 if (wl->chip.id == CHIP_ID_1283_PG20) {
5002 major = WL128X_PG_GET_MAJOR(wl->hw_pg_ver);
5003 minor = WL128X_PG_GET_MINOR(wl->hw_pg_ver);
5005 /* in wl128x we have the MAC address if the PG is >= (2, 1) */
5006 if (major > 2 || (major == 2 && minor >= 1))
5009 major = WL127X_PG_GET_MAJOR(wl->hw_pg_ver);
5010 minor = WL127X_PG_GET_MINOR(wl->hw_pg_ver);
5012 /* in wl127x we have the MAC address if the PG is >= (3, 1) */
5013 if (major == 3 && minor >= 1)
5017 wl1271_debug(DEBUG_PROBE,
5018 "PG Ver major = %d minor = %d, MAC %s present",
5019 major, minor, supported ? "is" : "is not");
5024 static void wl12xx_derive_mac_addresses(struct wl1271 *wl,
5025 u32 oui, u32 nic, int n)
5029 wl1271_debug(DEBUG_PROBE, "base address: oui %06x nic %06x, n %d",
5032 if (nic + n - 1 > 0xffffff)
5033 wl1271_warning("NIC part of the MAC address wraps around!");
5035 for (i = 0; i < n; i++) {
5036 wl->addresses[i].addr[0] = (u8)(oui >> 16);
5037 wl->addresses[i].addr[1] = (u8)(oui >> 8);
5038 wl->addresses[i].addr[2] = (u8) oui;
5039 wl->addresses[i].addr[3] = (u8)(nic >> 16);
5040 wl->addresses[i].addr[4] = (u8)(nic >> 8);
5041 wl->addresses[i].addr[5] = (u8) nic;
5045 wl->hw->wiphy->n_addresses = n;
5046 wl->hw->wiphy->addresses = wl->addresses;
5049 static void wl12xx_get_fuse_mac(struct wl1271 *wl)
5053 wlcore_set_partition(wl, &wl->ptable[PART_DRPW]);
5055 mac1 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_1);
5056 mac2 = wl1271_read32(wl, WL12XX_REG_FUSE_BD_ADDR_2);
5058 /* these are the two parts of the BD_ADDR */
5059 wl->fuse_oui_addr = ((mac2 & 0xffff) << 8) +
5060 ((mac1 & 0xff000000) >> 24);
5061 wl->fuse_nic_addr = mac1 & 0xffffff;
5063 wlcore_set_partition(wl, &wl->ptable[PART_DOWN]);
5066 static int wl12xx_get_hw_info(struct wl1271 *wl)
5070 ret = wl12xx_set_power_on(wl);
5074 wl->chip.id = wlcore_read_reg(wl, REG_CHIP_ID_B);
5076 wl->fuse_oui_addr = 0;
5077 wl->fuse_nic_addr = 0;
5079 wl->hw_pg_ver = wl->ops->get_pg_ver(wl);
5081 if (wl12xx_mac_in_fuse(wl))
5082 wl12xx_get_fuse_mac(wl);
5084 wl1271_power_off(wl);
5089 static int wl1271_register_hw(struct wl1271 *wl)
5092 u32 oui_addr = 0, nic_addr = 0;
5094 if (wl->mac80211_registered)
5097 ret = wl12xx_get_hw_info(wl);
5099 wl1271_error("couldn't get hw info");
5103 ret = wl1271_fetch_nvs(wl);
5105 /* NOTE: The wl->nvs->nvs element must be first, in
5106 * order to simplify the casting, we assume it is at
5107 * the beginning of the wl->nvs structure.
5109 u8 *nvs_ptr = (u8 *)wl->nvs;
5112 (nvs_ptr[11] << 16) + (nvs_ptr[10] << 8) + nvs_ptr[6];
5114 (nvs_ptr[5] << 16) + (nvs_ptr[4] << 8) + nvs_ptr[3];
5117 /* if the MAC address is zeroed in the NVS derive from fuse */
5118 if (oui_addr == 0 && nic_addr == 0) {
5119 oui_addr = wl->fuse_oui_addr;
5120 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5121 nic_addr = wl->fuse_nic_addr + 1;
5124 wl12xx_derive_mac_addresses(wl, oui_addr, nic_addr, 2);
5126 ret = ieee80211_register_hw(wl->hw);
5128 wl1271_error("unable to register mac80211 hw: %d", ret);
5132 wl->mac80211_registered = true;
5134 wl1271_debugfs_init(wl);
5136 wl1271_notice("loaded");
5142 static void wl1271_unregister_hw(struct wl1271 *wl)
5145 wl1271_plt_stop(wl);
5147 ieee80211_unregister_hw(wl->hw);
5148 wl->mac80211_registered = false;
5152 static int wl1271_init_ieee80211(struct wl1271 *wl)
5154 static const u32 cipher_suites[] = {
5155 WLAN_CIPHER_SUITE_WEP40,
5156 WLAN_CIPHER_SUITE_WEP104,
5157 WLAN_CIPHER_SUITE_TKIP,
5158 WLAN_CIPHER_SUITE_CCMP,
5159 WL1271_CIPHER_SUITE_GEM,
5162 /* The tx descriptor buffer and the TKIP space. */
5163 wl->hw->extra_tx_headroom = WL1271_EXTRA_SPACE_TKIP +
5164 sizeof(struct wl1271_tx_hw_descr);
5167 /* FIXME: find a proper value */
5168 wl->hw->channel_change_time = 10000;
5169 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
5171 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
5172 IEEE80211_HW_SUPPORTS_PS |
5173 IEEE80211_HW_SUPPORTS_DYNAMIC_PS |
5174 IEEE80211_HW_SUPPORTS_UAPSD |
5175 IEEE80211_HW_HAS_RATE_CONTROL |
5176 IEEE80211_HW_CONNECTION_MONITOR |
5177 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
5178 IEEE80211_HW_SPECTRUM_MGMT |
5179 IEEE80211_HW_AP_LINK_PS |
5180 IEEE80211_HW_AMPDU_AGGREGATION |
5181 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW |
5182 IEEE80211_HW_SCAN_WHILE_IDLE;
5184 wl->hw->wiphy->cipher_suites = cipher_suites;
5185 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
5187 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
5188 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP) |
5189 BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
5190 wl->hw->wiphy->max_scan_ssids = 1;
5191 wl->hw->wiphy->max_sched_scan_ssids = 16;
5192 wl->hw->wiphy->max_match_sets = 16;
5194 * Maximum length of elements in scanning probe request templates
5195 * should be the maximum length possible for a template, without
5196 * the IEEE80211 header of the template
5198 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
5199 sizeof(struct ieee80211_header);
5201 wl->hw->wiphy->max_sched_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
5202 sizeof(struct ieee80211_header);
5204 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
5206 /* make sure all our channels fit in the scanned_ch bitmask */
5207 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
5208 ARRAY_SIZE(wl1271_channels_5ghz) >
5209 WL1271_MAX_CHANNELS);
5211 * We keep local copies of the band structs because we need to
5212 * modify them on a per-device basis.
5214 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
5215 sizeof(wl1271_band_2ghz));
5216 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
5217 sizeof(wl1271_band_5ghz));
5219 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5220 &wl->bands[IEEE80211_BAND_2GHZ];
5221 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5222 &wl->bands[IEEE80211_BAND_5GHZ];
5225 wl->hw->max_rates = 1;
5227 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
5229 /* the FW answers probe-requests in AP-mode */
5230 wl->hw->wiphy->flags |= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD;
5231 wl->hw->wiphy->probe_resp_offload =
5232 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS |
5233 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2 |
5234 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P;
5236 SET_IEEE80211_DEV(wl->hw, wl->dev);
5238 wl->hw->sta_data_size = sizeof(struct wl1271_station);
5239 wl->hw->vif_data_size = sizeof(struct wl12xx_vif);
5241 wl->hw->max_rx_aggregation_subframes = 8;
5246 #define WL1271_DEFAULT_CHANNEL 0
5248 struct ieee80211_hw *wlcore_alloc_hw(void)
5250 struct ieee80211_hw *hw;
5255 BUILD_BUG_ON(AP_MAX_STATIONS > WL12XX_MAX_LINKS);
5257 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
5259 wl1271_error("could not alloc ieee80211_hw");
5265 memset(wl, 0, sizeof(*wl));
5267 INIT_LIST_HEAD(&wl->wlvif_list);
5271 for (i = 0; i < NUM_TX_QUEUES; i++)
5272 for (j = 0; j < WL12XX_MAX_LINKS; j++)
5273 skb_queue_head_init(&wl->links[j].tx_queue[i]);
5275 skb_queue_head_init(&wl->deferred_rx_queue);
5276 skb_queue_head_init(&wl->deferred_tx_queue);
5278 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
5279 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
5280 INIT_WORK(&wl->tx_work, wl1271_tx_work);
5281 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
5282 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
5283 INIT_DELAYED_WORK(&wl->tx_watchdog_work, wl12xx_tx_watchdog_work);
5285 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
5286 if (!wl->freezable_wq) {
5291 wl->channel = WL1271_DEFAULT_CHANNEL;
5293 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
5294 wl->band = IEEE80211_BAND_2GHZ;
5296 wl->sg_enabled = true;
5299 wl->ap_fw_ps_map = 0;
5301 wl->platform_quirks = 0;
5302 wl->sched_scanning = false;
5303 wl->tx_spare_blocks = TX_HW_BLOCK_SPARE_DEFAULT;
5304 wl->system_hlid = WL12XX_SYSTEM_HLID;
5305 wl->active_sta_count = 0;
5307 init_waitqueue_head(&wl->fwlog_waitq);
5309 /* The system link is always allocated */
5310 __set_bit(WL12XX_SYSTEM_HLID, wl->links_map);
5312 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
5313 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
5314 wl->tx_frames[i] = NULL;
5316 spin_lock_init(&wl->wl_lock);
5318 wl->state = WL1271_STATE_OFF;
5319 wl->fw_type = WL12XX_FW_TYPE_NONE;
5320 mutex_init(&wl->mutex);
5322 /* Apply default driver configuration. */
5323 wl1271_conf_init(wl);
5325 order = get_order(WL1271_AGGR_BUFFER_SIZE);
5326 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
5327 if (!wl->aggr_buf) {
5332 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
5333 if (!wl->dummy_packet) {
5338 /* Allocate one page for the FW log */
5339 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
5342 goto err_dummy_packet;
5345 wl->mbox = kmalloc(sizeof(*wl->mbox), GFP_DMA);
5354 free_page((unsigned long)wl->fwlog);
5357 dev_kfree_skb(wl->dummy_packet);
5360 free_pages((unsigned long)wl->aggr_buf, order);
5363 destroy_workqueue(wl->freezable_wq);
5366 wl1271_debugfs_exit(wl);
5367 ieee80211_free_hw(hw);
5371 return ERR_PTR(ret);
5373 EXPORT_SYMBOL_GPL(wlcore_alloc_hw);
5375 int wlcore_free_hw(struct wl1271 *wl)
5377 /* Unblock any fwlog readers */
5378 mutex_lock(&wl->mutex);
5379 wl->fwlog_size = -1;
5380 wake_up_interruptible_all(&wl->fwlog_waitq);
5381 mutex_unlock(&wl->mutex);
5383 device_remove_bin_file(wl->dev, &fwlog_attr);
5385 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5387 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5388 free_page((unsigned long)wl->fwlog);
5389 dev_kfree_skb(wl->dummy_packet);
5390 free_pages((unsigned long)wl->aggr_buf,
5391 get_order(WL1271_AGGR_BUFFER_SIZE));
5393 wl1271_debugfs_exit(wl);
5397 wl->fw_type = WL12XX_FW_TYPE_NONE;
5401 kfree(wl->fw_status);
5402 kfree(wl->tx_res_if);
5403 destroy_workqueue(wl->freezable_wq);
5405 ieee80211_free_hw(wl->hw);
5409 EXPORT_SYMBOL_GPL(wlcore_free_hw);
5411 static irqreturn_t wl12xx_hardirq(int irq, void *cookie)
5413 struct wl1271 *wl = cookie;
5414 unsigned long flags;
5416 wl1271_debug(DEBUG_IRQ, "IRQ");
5418 /* complete the ELP completion */
5419 spin_lock_irqsave(&wl->wl_lock, flags);
5420 set_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
5421 if (wl->elp_compl) {
5422 complete(wl->elp_compl);
5423 wl->elp_compl = NULL;
5426 if (test_bit(WL1271_FLAG_SUSPENDED, &wl->flags)) {
5427 /* don't enqueue a work right now. mark it as pending */
5428 set_bit(WL1271_FLAG_PENDING_WORK, &wl->flags);
5429 wl1271_debug(DEBUG_IRQ, "should not enqueue work");
5430 disable_irq_nosync(wl->irq);
5431 pm_wakeup_event(wl->dev, 0);
5432 spin_unlock_irqrestore(&wl->wl_lock, flags);
5435 spin_unlock_irqrestore(&wl->wl_lock, flags);
5437 return IRQ_WAKE_THREAD;
5440 int __devinit wlcore_probe(struct wl1271 *wl, struct platform_device *pdev)
5442 struct wl12xx_platform_data *pdata = pdev->dev.platform_data;
5443 unsigned long irqflags;
5446 if (!wl->ops || !wl->ptable) {
5451 wl->irq = platform_get_irq(pdev, 0);
5452 wl->ref_clock = pdata->board_ref_clock;
5453 wl->tcxo_clock = pdata->board_tcxo_clock;
5454 wl->platform_quirks = pdata->platform_quirks;
5455 wl->set_power = pdata->set_power;
5456 wl->dev = &pdev->dev;
5457 wl->if_ops = pdata->ops;
5459 platform_set_drvdata(pdev, wl);
5461 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
5462 irqflags = IRQF_TRIGGER_RISING;
5464 irqflags = IRQF_TRIGGER_HIGH | IRQF_ONESHOT;
5466 ret = request_threaded_irq(wl->irq, wl12xx_hardirq, wl1271_irq,
5470 wl1271_error("request_irq() failed: %d", ret);
5474 ret = enable_irq_wake(wl->irq);
5476 wl->irq_wake_enabled = true;
5477 device_init_wakeup(wl->dev, 1);
5478 if (pdata->pwr_in_suspend)
5479 wl->hw->wiphy->wowlan.flags = WIPHY_WOWLAN_ANY;
5482 disable_irq(wl->irq);
5484 ret = wl1271_init_ieee80211(wl);
5488 ret = wl1271_register_hw(wl);
5492 /* Create sysfs file to control bt coex state */
5493 ret = device_create_file(wl->dev, &dev_attr_bt_coex_state);
5495 wl1271_error("failed to create sysfs file bt_coex_state");
5499 /* Create sysfs file to get HW PG version */
5500 ret = device_create_file(wl->dev, &dev_attr_hw_pg_ver);
5502 wl1271_error("failed to create sysfs file hw_pg_ver");
5503 goto out_bt_coex_state;
5506 /* Create sysfs file for the FW log */
5507 ret = device_create_bin_file(wl->dev, &fwlog_attr);
5509 wl1271_error("failed to create sysfs file fwlog");
5516 device_remove_file(wl->dev, &dev_attr_hw_pg_ver);
5519 device_remove_file(wl->dev, &dev_attr_bt_coex_state);
5522 free_irq(wl->irq, wl);
5530 EXPORT_SYMBOL_GPL(wlcore_probe);
5532 int __devexit wlcore_remove(struct platform_device *pdev)
5534 struct wl1271 *wl = platform_get_drvdata(pdev);
5536 if (wl->irq_wake_enabled) {
5537 device_init_wakeup(wl->dev, 0);
5538 disable_irq_wake(wl->irq);
5540 wl1271_unregister_hw(wl);
5541 free_irq(wl->irq, wl);
5546 EXPORT_SYMBOL_GPL(wlcore_remove);
5548 u32 wl12xx_debug_level = DEBUG_NONE;
5549 EXPORT_SYMBOL_GPL(wl12xx_debug_level);
5550 module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
5551 MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
5553 module_param_named(fwlog, fwlog_param, charp, 0);
5554 MODULE_PARM_DESC(fwlog,
5555 "FW logger options: continuous, ondemand, dbgpins or disable");
5557 module_param(bug_on_recovery, bool, S_IRUSR | S_IWUSR);
5558 MODULE_PARM_DESC(bug_on_recovery, "BUG() on fw recovery");
5560 MODULE_LICENSE("GPL");
5561 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5562 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");