2 * This file is part of wl1271
4 * Copyright (C) 2008-2010 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/module.h>
25 #include <linux/firmware.h>
26 #include <linux/delay.h>
27 #include <linux/spi/spi.h>
28 #include <linux/crc32.h>
29 #include <linux/etherdevice.h>
30 #include <linux/vmalloc.h>
31 #include <linux/platform_device.h>
32 #include <linux/slab.h>
33 #include <linux/wl12xx.h>
34 #include <linux/sched.h>
37 #include "wl12xx_80211.h"
51 #define WL1271_BOOT_RETRIES 3
53 static struct conf_drv_settings default_conf = {
56 [CONF_SG_BT_PER_THRESHOLD] = 7500,
57 [CONF_SG_HV3_MAX_OVERRIDE] = 0,
58 [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400,
59 [CONF_SG_BT_LOAD_RATIO] = 200,
60 [CONF_SG_AUTO_PS_MODE] = 1,
61 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
62 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
63 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
64 [CONF_SG_BEACON_MISS_PERCENT] = 60,
65 [CONF_SG_RATE_ADAPT_THRESH] = 12,
66 [CONF_SG_RATE_ADAPT_SNR] = 0,
67 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10,
68 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 30,
69 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 8,
70 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20,
71 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 50,
72 /* Note: with UPSD, this should be 4 */
73 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 8,
74 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7,
75 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25,
76 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 20,
77 /* Note: with UPDS, this should be 15 */
78 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8,
79 /* Note: with UPDS, this should be 50 */
80 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 40,
81 /* Note: with UPDS, this should be 10 */
82 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 20,
85 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
86 [CONF_SG_PS_POLL_TIMEOUT] = 10,
87 [CONF_SG_UPSD_TIMEOUT] = 10,
88 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
89 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
90 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
91 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8,
92 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20,
93 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15,
94 [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20,
95 [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50,
96 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10,
97 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
98 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
99 [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75,
100 [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15,
101 [CONF_SG_HV3_MAX_SERVED] = 6,
102 [CONF_SG_DHCP_TIME] = 5000,
103 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
106 [CONF_SG_BT_PER_THRESHOLD] = 7500,
107 [CONF_SG_HV3_MAX_OVERRIDE] = 0,
108 [CONF_SG_BT_NFS_SAMPLE_INTERVAL] = 400,
109 [CONF_SG_BT_LOAD_RATIO] = 50,
110 [CONF_SG_AUTO_PS_MODE] = 1,
111 [CONF_SG_AUTO_SCAN_PROBE_REQ] = 170,
112 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3] = 50,
113 [CONF_SG_ANTENNA_CONFIGURATION] = 0,
114 [CONF_SG_BEACON_MISS_PERCENT] = 60,
115 [CONF_SG_RATE_ADAPT_THRESH] = 64,
116 [CONF_SG_RATE_ADAPT_SNR] = 1,
117 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_BR] = 10,
118 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_BR] = 25,
119 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_BR] = 25,
120 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_BR] = 20,
121 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_BR] = 25,
122 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_BR] = 25,
123 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MIN_EDR] = 7,
124 [CONF_SG_WLAN_PS_BT_ACL_MASTER_MAX_EDR] = 25,
125 [CONF_SG_WLAN_PS_MAX_BT_ACL_MASTER_EDR] = 25,
126 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MIN_EDR] = 8,
127 [CONF_SG_WLAN_PS_BT_ACL_SLAVE_MAX_EDR] = 25,
128 [CONF_SG_WLAN_PS_MAX_BT_ACL_SLAVE_EDR] = 25,
129 [CONF_SG_RXT] = 1200,
130 [CONF_SG_TXT] = 1000,
131 [CONF_SG_ADAPTIVE_RXT_TXT] = 1,
132 [CONF_SG_PS_POLL_TIMEOUT] = 10,
133 [CONF_SG_UPSD_TIMEOUT] = 10,
134 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MIN_EDR] = 7,
135 [CONF_SG_WLAN_ACTIVE_BT_ACL_MASTER_MAX_EDR] = 15,
136 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_MASTER_EDR] = 15,
137 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MIN_EDR] = 8,
138 [CONF_SG_WLAN_ACTIVE_BT_ACL_SLAVE_MAX_EDR] = 20,
139 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_SLAVE_EDR] = 15,
140 [CONF_SG_WLAN_ACTIVE_BT_ACL_MIN_BR] = 20,
141 [CONF_SG_WLAN_ACTIVE_BT_ACL_MAX_BR] = 50,
142 [CONF_SG_WLAN_ACTIVE_MAX_BT_ACL_BR] = 10,
143 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3] = 200,
144 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP] = 800,
145 [CONF_SG_PASSIVE_SCAN_A2DP_BT_TIME] = 75,
146 [CONF_SG_PASSIVE_SCAN_A2DP_WLAN_TIME] = 15,
147 [CONF_SG_HV3_MAX_SERVED] = 6,
148 [CONF_SG_DHCP_TIME] = 5000,
149 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP] = 100,
150 [CONF_SG_TEMP_PARAM_1] = 0,
151 [CONF_SG_TEMP_PARAM_2] = 0,
152 [CONF_SG_TEMP_PARAM_3] = 0,
153 [CONF_SG_TEMP_PARAM_4] = 0,
154 [CONF_SG_TEMP_PARAM_5] = 0,
155 [CONF_SG_AP_BEACON_MISS_TX] = 3,
156 [CONF_SG_RX_WINDOW_LENGTH] = 6,
157 [CONF_SG_AP_CONNECTION_PROTECTION_TIME] = 50,
158 [CONF_SG_TEMP_PARAM_6] = 1,
160 .state = CONF_SG_PROTECTIVE,
163 .rx_msdu_life_time = 512000,
164 .packet_detection_threshold = 0,
165 .ps_poll_timeout = 15,
167 .rts_threshold = IEEE80211_MAX_RTS_THRESHOLD,
168 .rx_cca_threshold = 0,
169 .irq_blk_threshold = 0xFFFF,
170 .irq_pkt_threshold = 0,
172 .queue_type = CONF_RX_QUEUE_TYPE_LOW_PRIORITY,
175 .tx_energy_detection = 0,
178 .short_retry_limit = 10,
179 .long_retry_limit = 10,
202 .aifsn = CONF_TX_AIFS_PIFS,
209 .aifsn = CONF_TX_AIFS_PIFS,
213 .ap_max_tx_retries = 100,
217 .queue_id = CONF_TX_AC_BE,
218 .channel_type = CONF_CHANNEL_TYPE_EDCF,
219 .tsid = CONF_TX_AC_BE,
220 .ps_scheme = CONF_PS_SCHEME_LEGACY,
221 .ack_policy = CONF_ACK_POLICY_LEGACY,
225 .queue_id = CONF_TX_AC_BK,
226 .channel_type = CONF_CHANNEL_TYPE_EDCF,
227 .tsid = CONF_TX_AC_BK,
228 .ps_scheme = CONF_PS_SCHEME_LEGACY,
229 .ack_policy = CONF_ACK_POLICY_LEGACY,
233 .queue_id = CONF_TX_AC_VI,
234 .channel_type = CONF_CHANNEL_TYPE_EDCF,
235 .tsid = CONF_TX_AC_VI,
236 .ps_scheme = CONF_PS_SCHEME_LEGACY,
237 .ack_policy = CONF_ACK_POLICY_LEGACY,
241 .queue_id = CONF_TX_AC_VO,
242 .channel_type = CONF_CHANNEL_TYPE_EDCF,
243 .tsid = CONF_TX_AC_VO,
244 .ps_scheme = CONF_PS_SCHEME_LEGACY,
245 .ack_policy = CONF_ACK_POLICY_LEGACY,
249 .frag_threshold = IEEE80211_MAX_FRAG_THRESHOLD,
250 .tx_compl_timeout = 700,
251 .tx_compl_threshold = 4,
252 .basic_rate = CONF_HW_BIT_RATE_1MBPS,
253 .basic_rate_5 = CONF_HW_BIT_RATE_6MBPS,
254 .tmpl_short_retry_limit = 10,
255 .tmpl_long_retry_limit = 10,
258 .wake_up_event = CONF_WAKE_UP_EVENT_DTIM,
259 .listen_interval = 1,
260 .bcn_filt_mode = CONF_BCN_FILT_MODE_ENABLED,
261 .bcn_filt_ie_count = 2,
264 .ie = WLAN_EID_CHANNEL_SWITCH,
265 .rule = CONF_BCN_RULE_PASS_ON_APPEARANCE,
268 .ie = WLAN_EID_HT_INFORMATION,
269 .rule = CONF_BCN_RULE_PASS_ON_CHANGE,
272 .synch_fail_thold = 10,
273 .bss_lose_timeout = 100,
274 .beacon_rx_timeout = 10000,
275 .broadcast_timeout = 20000,
276 .rx_broadcast_in_ps = 1,
277 .ps_poll_threshold = 10,
278 .ps_poll_recovery_period = 700,
279 .bet_enable = CONF_BET_MODE_ENABLE,
280 .bet_max_consecutive = 50,
281 .psm_entry_retries = 5,
282 .psm_exit_retries = 16,
283 .psm_entry_nullfunc_retries = 3,
284 .psm_entry_hangover_period = 1,
285 .keep_alive_interval = 55000,
286 .max_listen_interval = 20,
293 .host_clk_settling_time = 5000,
294 .host_fast_wakeup_support = false
298 .avg_weight_rssi_beacon = 20,
299 .avg_weight_rssi_data = 10,
300 .avg_weight_snr_beacon = 20,
301 .avg_weight_snr_data = 10,
304 .min_dwell_time_active = 7500,
305 .max_dwell_time_active = 30000,
306 .min_dwell_time_passive = 100000,
307 .max_dwell_time_passive = 100000,
311 /* sched_scan requires dwell times in TU instead of TU/1000 */
312 .min_dwell_time_active = 8,
313 .max_dwell_time_active = 30,
314 .dwell_time_passive = 100,
315 .dwell_time_dfs = 150,
317 .rssi_threshold = -90,
321 .tx_per_channel_power_compensation_2 = {
322 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324 .tx_per_channel_power_compensation_5 = {
325 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
326 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
327 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
331 .tx_ba_win_size = 64,
332 .inactivity_timeout = 10000,
338 .tx_min_block_num = 40,
340 .min_req_tx_blocks = 100,
341 .min_req_rx_blocks = 22,
348 .tx_min_block_num = 40,
350 .min_req_tx_blocks = 45,
351 .min_req_rx_blocks = 22,
357 .n_divider_fref_set_1 = 0xff, /* default */
358 .n_divider_fref_set_2 = 12,
359 .m_divider_fref_set_1 = 148,
360 .m_divider_fref_set_2 = 0xffff, /* default */
361 .coex_pll_stabilization_time = 0xffffffff, /* default */
362 .ldo_stabilization_time = 0xffff, /* default */
363 .fm_disturbed_band_margin = 0xff, /* default */
364 .swallow_clk_diff = 0xff, /* default */
373 .mode = WL12XX_FWLOG_ON_DEMAND,
376 .timestamp = WL12XX_FWLOG_TIMESTAMP_DISABLED,
377 .output = WL12XX_FWLOG_OUTPUT_HOST,
380 .hci_io_ds = HCI_IO_DS_6MA,
383 static char *fwlog_param;
385 static void __wl1271_op_remove_interface(struct wl1271 *wl,
386 bool reset_tx_queues);
387 static void wl1271_free_ap_keys(struct wl1271 *wl);
390 static void wl1271_device_release(struct device *dev)
395 static struct platform_device wl1271_device = {
399 /* device model insists to have a release function */
401 .release = wl1271_device_release,
405 static DEFINE_MUTEX(wl_list_mutex);
406 static LIST_HEAD(wl_list);
408 static int wl1271_check_operstate(struct wl1271 *wl, unsigned char operstate)
411 if (operstate != IF_OPER_UP)
414 if (test_and_set_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags))
417 ret = wl1271_cmd_set_sta_state(wl);
421 wl1271_info("Association completed.");
424 static int wl1271_dev_notify(struct notifier_block *me, unsigned long what,
427 struct net_device *dev = arg;
428 struct wireless_dev *wdev;
430 struct ieee80211_hw *hw;
432 struct wl1271 *wl_temp;
435 /* Check that this notification is for us. */
436 if (what != NETDEV_CHANGE)
439 wdev = dev->ieee80211_ptr;
447 hw = wiphy_priv(wiphy);
452 mutex_lock(&wl_list_mutex);
453 list_for_each_entry(wl, &wl_list, list) {
457 mutex_unlock(&wl_list_mutex);
461 mutex_lock(&wl->mutex);
463 if (wl->state == WL1271_STATE_OFF)
466 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
469 ret = wl1271_ps_elp_wakeup(wl);
473 wl1271_check_operstate(wl, dev->operstate);
475 wl1271_ps_elp_sleep(wl);
478 mutex_unlock(&wl->mutex);
483 static int wl1271_reg_notify(struct wiphy *wiphy,
484 struct regulatory_request *request)
486 struct ieee80211_supported_band *band;
487 struct ieee80211_channel *ch;
490 band = wiphy->bands[IEEE80211_BAND_5GHZ];
491 for (i = 0; i < band->n_channels; i++) {
492 ch = &band->channels[i];
493 if (ch->flags & IEEE80211_CHAN_DISABLED)
496 if (ch->flags & IEEE80211_CHAN_RADAR)
497 ch->flags |= IEEE80211_CHAN_NO_IBSS |
498 IEEE80211_CHAN_PASSIVE_SCAN;
505 static int wl1271_set_rx_streaming(struct wl1271 *wl, bool enable)
509 /* we should hold wl->mutex */
510 ret = wl1271_acx_ps_rx_streaming(wl, enable);
515 set_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags);
517 clear_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags);
523 * this function is being called when the rx_streaming interval
524 * has beed changed or rx_streaming should be disabled
526 int wl1271_recalc_rx_streaming(struct wl1271 *wl)
529 int period = wl->conf.rx_streaming.interval;
531 /* don't reconfigure if rx_streaming is disabled */
532 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
535 /* reconfigure/disable according to new streaming_period */
537 test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) &&
538 (wl->conf.rx_streaming.always ||
539 test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
540 ret = wl1271_set_rx_streaming(wl, true);
542 ret = wl1271_set_rx_streaming(wl, false);
543 /* don't cancel_work_sync since we might deadlock */
544 del_timer_sync(&wl->rx_streaming_timer);
550 static void wl1271_rx_streaming_enable_work(struct work_struct *work)
554 container_of(work, struct wl1271, rx_streaming_enable_work);
556 mutex_lock(&wl->mutex);
558 if (test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags) ||
559 !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags) ||
560 (!wl->conf.rx_streaming.always &&
561 !test_bit(WL1271_FLAG_SOFT_GEMINI, &wl->flags)))
564 if (!wl->conf.rx_streaming.interval)
567 ret = wl1271_ps_elp_wakeup(wl);
571 ret = wl1271_set_rx_streaming(wl, true);
575 /* stop it after some time of inactivity */
576 mod_timer(&wl->rx_streaming_timer,
577 jiffies + msecs_to_jiffies(wl->conf.rx_streaming.duration));
580 wl1271_ps_elp_sleep(wl);
582 mutex_unlock(&wl->mutex);
585 static void wl1271_rx_streaming_disable_work(struct work_struct *work)
589 container_of(work, struct wl1271, rx_streaming_disable_work);
591 mutex_lock(&wl->mutex);
593 if (!test_bit(WL1271_FLAG_RX_STREAMING_STARTED, &wl->flags))
596 ret = wl1271_ps_elp_wakeup(wl);
600 ret = wl1271_set_rx_streaming(wl, false);
605 wl1271_ps_elp_sleep(wl);
607 mutex_unlock(&wl->mutex);
610 static void wl1271_rx_streaming_timer(unsigned long data)
612 struct wl1271 *wl = (struct wl1271 *)data;
613 ieee80211_queue_work(wl->hw, &wl->rx_streaming_disable_work);
616 static void wl1271_conf_init(struct wl1271 *wl)
620 * This function applies the default configuration to the driver. This
621 * function is invoked upon driver load (spi probe.)
623 * The configuration is stored in a run-time structure in order to
624 * facilitate for run-time adjustment of any of the parameters. Making
625 * changes to the configuration structure will apply the new values on
626 * the next interface up (wl1271_op_start.)
629 /* apply driver default configuration */
630 memcpy(&wl->conf, &default_conf, sizeof(default_conf));
632 /* Adjust settings according to optional module parameters */
634 if (!strcmp(fwlog_param, "continuous")) {
635 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
636 } else if (!strcmp(fwlog_param, "ondemand")) {
637 wl->conf.fwlog.mode = WL12XX_FWLOG_ON_DEMAND;
638 } else if (!strcmp(fwlog_param, "dbgpins")) {
639 wl->conf.fwlog.mode = WL12XX_FWLOG_CONTINUOUS;
640 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_DBG_PINS;
641 } else if (!strcmp(fwlog_param, "disable")) {
642 wl->conf.fwlog.mem_blocks = 0;
643 wl->conf.fwlog.output = WL12XX_FWLOG_OUTPUT_NONE;
645 wl1271_error("Unknown fwlog parameter %s", fwlog_param);
650 static int wl1271_plt_init(struct wl1271 *wl)
652 struct conf_tx_ac_category *conf_ac;
653 struct conf_tx_tid *conf_tid;
656 if (wl->chip.id == CHIP_ID_1283_PG20)
657 ret = wl128x_cmd_general_parms(wl);
659 ret = wl1271_cmd_general_parms(wl);
663 if (wl->chip.id == CHIP_ID_1283_PG20)
664 ret = wl128x_cmd_radio_parms(wl);
666 ret = wl1271_cmd_radio_parms(wl);
670 if (wl->chip.id != CHIP_ID_1283_PG20) {
671 ret = wl1271_cmd_ext_radio_parms(wl);
678 /* Chip-specific initializations */
679 ret = wl1271_chip_specific_init(wl);
683 ret = wl1271_sta_init_templates_config(wl);
687 ret = wl1271_acx_init_mem_config(wl);
691 /* PHY layer config */
692 ret = wl1271_init_phy_config(wl);
694 goto out_free_memmap;
696 ret = wl1271_acx_dco_itrim_params(wl);
698 goto out_free_memmap;
700 /* Initialize connection monitoring thresholds */
701 ret = wl1271_acx_conn_monit_params(wl, false);
703 goto out_free_memmap;
705 /* Bluetooth WLAN coexistence */
706 ret = wl1271_init_pta(wl);
708 goto out_free_memmap;
710 /* FM WLAN coexistence */
711 ret = wl1271_acx_fm_coex(wl);
713 goto out_free_memmap;
715 /* Energy detection */
716 ret = wl1271_init_energy_detection(wl);
718 goto out_free_memmap;
720 ret = wl1271_acx_sta_mem_cfg(wl);
722 goto out_free_memmap;
724 /* Default fragmentation threshold */
725 ret = wl1271_acx_frag_threshold(wl, wl->conf.tx.frag_threshold);
727 goto out_free_memmap;
729 /* Default TID/AC configuration */
730 BUG_ON(wl->conf.tx.tid_conf_count != wl->conf.tx.ac_conf_count);
731 for (i = 0; i < wl->conf.tx.tid_conf_count; i++) {
732 conf_ac = &wl->conf.tx.ac_conf[i];
733 ret = wl1271_acx_ac_cfg(wl, conf_ac->ac, conf_ac->cw_min,
734 conf_ac->cw_max, conf_ac->aifsn,
735 conf_ac->tx_op_limit);
737 goto out_free_memmap;
739 conf_tid = &wl->conf.tx.tid_conf[i];
740 ret = wl1271_acx_tid_cfg(wl, conf_tid->queue_id,
741 conf_tid->channel_type,
744 conf_tid->ack_policy,
745 conf_tid->apsd_conf[0],
746 conf_tid->apsd_conf[1]);
748 goto out_free_memmap;
751 /* Enable data path */
752 ret = wl1271_cmd_data_path(wl, 1);
754 goto out_free_memmap;
756 /* Configure for CAM power saving (ie. always active) */
757 ret = wl1271_acx_sleep_auth(wl, WL1271_PSM_CAM);
759 goto out_free_memmap;
762 ret = wl1271_acx_pm_config(wl);
764 goto out_free_memmap;
769 kfree(wl->target_mem_map);
770 wl->target_mem_map = NULL;
775 static void wl1271_irq_ps_regulate_link(struct wl1271 *wl, u8 hlid, u8 tx_blks)
779 /* only regulate station links */
780 if (hlid < WL1271_AP_STA_HLID_START)
783 fw_ps = test_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
786 * Wake up from high level PS if the STA is asleep with too little
787 * blocks in FW or if the STA is awake.
789 if (!fw_ps || tx_blks < WL1271_PS_STA_MAX_BLOCKS)
790 wl1271_ps_link_end(wl, hlid);
792 /* Start high-level PS if the STA is asleep with enough blocks in FW */
793 else if (fw_ps && tx_blks >= WL1271_PS_STA_MAX_BLOCKS)
794 wl1271_ps_link_start(wl, hlid, true);
797 static void wl1271_irq_update_links_status(struct wl1271 *wl,
798 struct wl1271_fw_ap_status *status)
803 cur_fw_ps_map = le32_to_cpu(status->link_ps_bitmap);
804 if (wl->ap_fw_ps_map != cur_fw_ps_map) {
805 wl1271_debug(DEBUG_PSM,
806 "link ps prev 0x%x cur 0x%x changed 0x%x",
807 wl->ap_fw_ps_map, cur_fw_ps_map,
808 wl->ap_fw_ps_map ^ cur_fw_ps_map);
810 wl->ap_fw_ps_map = cur_fw_ps_map;
813 for (hlid = WL1271_AP_STA_HLID_START; hlid < AP_MAX_LINKS; hlid++) {
814 u8 cnt = status->tx_lnk_free_blks[hlid] -
815 wl->links[hlid].prev_freed_blks;
817 wl->links[hlid].prev_freed_blks =
818 status->tx_lnk_free_blks[hlid];
819 wl->links[hlid].allocated_blks -= cnt;
821 wl1271_irq_ps_regulate_link(wl, hlid,
822 wl->links[hlid].allocated_blks);
826 static void wl1271_fw_status(struct wl1271 *wl,
827 struct wl1271_fw_full_status *full_status)
829 struct wl1271_fw_common_status *status = &full_status->common;
831 u32 old_tx_blk_count = wl->tx_blocks_available;
832 u32 freed_blocks = 0;
835 if (wl->bss_type == BSS_TYPE_AP_BSS) {
836 wl1271_raw_read(wl, FW_STATUS_ADDR, status,
837 sizeof(struct wl1271_fw_ap_status), false);
839 wl1271_raw_read(wl, FW_STATUS_ADDR, status,
840 sizeof(struct wl1271_fw_sta_status), false);
843 wl1271_debug(DEBUG_IRQ, "intr: 0x%x (fw_rx_counter = %d, "
844 "drv_rx_counter = %d, tx_results_counter = %d)",
846 status->fw_rx_counter,
847 status->drv_rx_counter,
848 status->tx_results_counter);
850 /* update number of available TX blocks */
851 for (i = 0; i < NUM_TX_QUEUES; i++) {
852 freed_blocks += le32_to_cpu(status->tx_released_blks[i]) -
853 wl->tx_blocks_freed[i];
855 wl->tx_blocks_freed[i] =
856 le32_to_cpu(status->tx_released_blks[i]);
859 wl->tx_allocated_blocks -= freed_blocks;
861 if (wl->bss_type == BSS_TYPE_AP_BSS) {
862 /* Update num of allocated TX blocks per link and ps status */
863 wl1271_irq_update_links_status(wl, &full_status->ap);
864 wl->tx_blocks_available += freed_blocks;
866 int avail = full_status->sta.tx_total - wl->tx_allocated_blocks;
869 * The FW might change the total number of TX memblocks before
870 * we get a notification about blocks being released. Thus, the
871 * available blocks calculation might yield a temporary result
872 * which is lower than the actual available blocks. Keeping in
873 * mind that only blocks that were allocated can be moved from
874 * TX to RX, tx_blocks_available should never decrease here.
876 wl->tx_blocks_available = max((int)wl->tx_blocks_available,
880 /* if more blocks are available now, tx work can be scheduled */
881 if (wl->tx_blocks_available > old_tx_blk_count)
882 clear_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags);
884 /* update the host-chipset time offset */
886 wl->time_offset = (timespec_to_ns(&ts) >> 10) -
887 (s64)le32_to_cpu(status->fw_localtime);
890 static void wl1271_flush_deferred_work(struct wl1271 *wl)
894 /* Pass all received frames to the network stack */
895 while ((skb = skb_dequeue(&wl->deferred_rx_queue)))
896 ieee80211_rx_ni(wl->hw, skb);
898 /* Return sent skbs to the network stack */
899 while ((skb = skb_dequeue(&wl->deferred_tx_queue)))
900 ieee80211_tx_status_ni(wl->hw, skb);
903 static void wl1271_netstack_work(struct work_struct *work)
906 container_of(work, struct wl1271, netstack_work);
909 wl1271_flush_deferred_work(wl);
910 } while (skb_queue_len(&wl->deferred_rx_queue));
913 #define WL1271_IRQ_MAX_LOOPS 256
915 irqreturn_t wl1271_irq(int irq, void *cookie)
919 int loopcount = WL1271_IRQ_MAX_LOOPS;
920 struct wl1271 *wl = (struct wl1271 *)cookie;
922 unsigned int defer_count;
925 /* TX might be handled here, avoid redundant work */
926 set_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
927 cancel_work_sync(&wl->tx_work);
930 * In case edge triggered interrupt must be used, we cannot iterate
931 * more than once without introducing race conditions with the hardirq.
933 if (wl->platform_quirks & WL12XX_PLATFORM_QUIRK_EDGE_IRQ)
936 mutex_lock(&wl->mutex);
938 wl1271_debug(DEBUG_IRQ, "IRQ work");
940 if (unlikely(wl->state == WL1271_STATE_OFF))
943 ret = wl1271_ps_elp_wakeup(wl);
947 while (!done && loopcount--) {
949 * In order to avoid a race with the hardirq, clear the flag
950 * before acknowledging the chip. Since the mutex is held,
951 * wl1271_ps_elp_wakeup cannot be called concurrently.
953 clear_bit(WL1271_FLAG_IRQ_RUNNING, &wl->flags);
954 smp_mb__after_clear_bit();
956 wl1271_fw_status(wl, wl->fw_status);
957 intr = le32_to_cpu(wl->fw_status->common.intr);
958 intr &= WL1271_INTR_MASK;
964 if (unlikely(intr & WL1271_ACX_INTR_WATCHDOG)) {
965 wl1271_error("watchdog interrupt received! "
966 "starting recovery.");
967 wl12xx_queue_recovery_work(wl);
969 /* restarting the chip. ignore any other interrupt. */
973 if (likely(intr & WL1271_ACX_INTR_DATA)) {
974 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_DATA");
976 wl1271_rx(wl, &wl->fw_status->common);
978 /* Check if any tx blocks were freed */
979 spin_lock_irqsave(&wl->wl_lock, flags);
980 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
981 wl->tx_queue_count) {
982 spin_unlock_irqrestore(&wl->wl_lock, flags);
984 * In order to avoid starvation of the TX path,
985 * call the work function directly.
987 wl1271_tx_work_locked(wl);
989 spin_unlock_irqrestore(&wl->wl_lock, flags);
992 /* check for tx results */
993 if (wl->fw_status->common.tx_results_counter !=
994 (wl->tx_results_count & 0xff))
995 wl1271_tx_complete(wl);
997 /* Make sure the deferred queues don't get too long */
998 defer_count = skb_queue_len(&wl->deferred_tx_queue) +
999 skb_queue_len(&wl->deferred_rx_queue);
1000 if (defer_count > WL1271_DEFERRED_QUEUE_LIMIT)
1001 wl1271_flush_deferred_work(wl);
1004 if (intr & WL1271_ACX_INTR_EVENT_A) {
1005 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_A");
1006 wl1271_event_handle(wl, 0);
1009 if (intr & WL1271_ACX_INTR_EVENT_B) {
1010 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_EVENT_B");
1011 wl1271_event_handle(wl, 1);
1014 if (intr & WL1271_ACX_INTR_INIT_COMPLETE)
1015 wl1271_debug(DEBUG_IRQ,
1016 "WL1271_ACX_INTR_INIT_COMPLETE");
1018 if (intr & WL1271_ACX_INTR_HW_AVAILABLE)
1019 wl1271_debug(DEBUG_IRQ, "WL1271_ACX_INTR_HW_AVAILABLE");
1022 wl1271_ps_elp_sleep(wl);
1025 spin_lock_irqsave(&wl->wl_lock, flags);
1026 /* In case TX was not handled here, queue TX work */
1027 clear_bit(WL1271_FLAG_TX_PENDING, &wl->flags);
1028 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1030 ieee80211_queue_work(wl->hw, &wl->tx_work);
1031 spin_unlock_irqrestore(&wl->wl_lock, flags);
1033 mutex_unlock(&wl->mutex);
1037 EXPORT_SYMBOL_GPL(wl1271_irq);
1039 static int wl1271_fetch_firmware(struct wl1271 *wl)
1041 const struct firmware *fw;
1042 const char *fw_name;
1045 switch (wl->bss_type) {
1046 case BSS_TYPE_AP_BSS:
1047 if (wl->chip.id == CHIP_ID_1283_PG20)
1048 fw_name = WL128X_AP_FW_NAME;
1050 fw_name = WL127X_AP_FW_NAME;
1053 case BSS_TYPE_STA_BSS:
1054 if (wl->chip.id == CHIP_ID_1283_PG20)
1055 fw_name = WL128X_FW_NAME;
1057 fw_name = WL1271_FW_NAME;
1060 wl1271_error("no compatible firmware for bss_type %d",
1065 wl1271_debug(DEBUG_BOOT, "booting firmware %s", fw_name);
1067 ret = request_firmware(&fw, fw_name, wl1271_wl_to_dev(wl));
1070 wl1271_error("could not get firmware: %d", ret);
1075 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1082 wl->fw_len = fw->size;
1083 wl->fw = vmalloc(wl->fw_len);
1086 wl1271_error("could not allocate memory for the firmware");
1091 memcpy(wl->fw, fw->data, wl->fw_len);
1092 wl->fw_bss_type = wl->bss_type;
1096 release_firmware(fw);
1101 static int wl1271_fetch_nvs(struct wl1271 *wl)
1103 const struct firmware *fw;
1106 ret = request_firmware(&fw, WL12XX_NVS_NAME, wl1271_wl_to_dev(wl));
1109 wl1271_error("could not get nvs file: %d", ret);
1113 wl->nvs = kmemdup(fw->data, fw->size, GFP_KERNEL);
1116 wl1271_error("could not allocate memory for the nvs file");
1121 wl->nvs_len = fw->size;
1124 release_firmware(fw);
1129 void wl12xx_queue_recovery_work(struct wl1271 *wl)
1131 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
1132 ieee80211_queue_work(wl->hw, &wl->recovery_work);
1135 size_t wl12xx_copy_fwlog(struct wl1271 *wl, u8 *memblock, size_t maxlen)
1139 /* The FW log is a length-value list, find where the log end */
1140 while (len < maxlen) {
1141 if (memblock[len] == 0)
1143 if (len + memblock[len] + 1 > maxlen)
1145 len += memblock[len] + 1;
1148 /* Make sure we have enough room */
1149 len = min(len, (size_t)(PAGE_SIZE - wl->fwlog_size));
1151 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1152 memcpy(wl->fwlog + wl->fwlog_size, memblock, len);
1153 wl->fwlog_size += len;
1158 static void wl12xx_read_fwlog_panic(struct wl1271 *wl)
1164 if ((wl->quirks & WL12XX_QUIRK_FWLOG_NOT_IMPLEMENTED) ||
1165 (wl->conf.fwlog.mode != WL12XX_FWLOG_ON_DEMAND) ||
1166 (wl->conf.fwlog.mem_blocks == 0))
1169 wl1271_info("Reading FW panic log");
1171 block = kmalloc(WL12XX_HW_BLOCK_SIZE, GFP_KERNEL);
1176 * Make sure the chip is awake and the logger isn't active.
1177 * This might fail if the firmware hanged.
1179 if (!wl1271_ps_elp_wakeup(wl))
1180 wl12xx_cmd_stop_fwlog(wl);
1182 /* Read the first memory block address */
1183 wl1271_fw_status(wl, wl->fw_status);
1184 first_addr = __le32_to_cpu(wl->fw_status->sta.log_start_addr);
1188 /* Traverse the memory blocks linked list */
1191 memset(block, 0, WL12XX_HW_BLOCK_SIZE);
1192 wl1271_read_hwaddr(wl, addr, block, WL12XX_HW_BLOCK_SIZE,
1196 * Memory blocks are linked to one another. The first 4 bytes
1197 * of each memory block hold the hardware address of the next
1198 * one. The last memory block points to the first one.
1200 addr = __le32_to_cpup((__le32 *)block);
1201 if (!wl12xx_copy_fwlog(wl, block + sizeof(addr),
1202 WL12XX_HW_BLOCK_SIZE - sizeof(addr)))
1204 } while (addr && (addr != first_addr));
1206 wake_up_interruptible(&wl->fwlog_waitq);
1212 static void wl1271_recovery_work(struct work_struct *work)
1215 container_of(work, struct wl1271, recovery_work);
1217 mutex_lock(&wl->mutex);
1219 if (wl->state != WL1271_STATE_ON)
1222 /* Avoid a recursive recovery */
1223 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1225 wl12xx_read_fwlog_panic(wl);
1227 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1228 wl->chip.fw_ver_str, wl1271_read32(wl, SCR_PAD4));
1230 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
1231 ieee80211_connection_loss(wl->vif);
1233 /* Prevent spurious TX during FW restart */
1234 ieee80211_stop_queues(wl->hw);
1236 if (wl->sched_scanning) {
1237 ieee80211_sched_scan_stopped(wl->hw);
1238 wl->sched_scanning = false;
1241 /* reboot the chipset */
1242 __wl1271_op_remove_interface(wl, false);
1244 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags);
1246 ieee80211_restart_hw(wl->hw);
1249 * Its safe to enable TX now - the queues are stopped after a request
1250 * to restart the HW.
1252 ieee80211_wake_queues(wl->hw);
1255 mutex_unlock(&wl->mutex);
1258 static void wl1271_fw_wakeup(struct wl1271 *wl)
1262 elp_reg = ELPCTRL_WAKE_UP;
1263 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, elp_reg);
1266 static int wl1271_setup(struct wl1271 *wl)
1268 wl->fw_status = kmalloc(sizeof(*wl->fw_status), GFP_KERNEL);
1272 wl->tx_res_if = kmalloc(sizeof(*wl->tx_res_if), GFP_KERNEL);
1273 if (!wl->tx_res_if) {
1274 kfree(wl->fw_status);
1281 static int wl1271_chip_wakeup(struct wl1271 *wl)
1283 struct wl1271_partition_set partition;
1286 msleep(WL1271_PRE_POWER_ON_SLEEP);
1287 ret = wl1271_power_on(wl);
1290 msleep(WL1271_POWER_ON_SLEEP);
1291 wl1271_io_reset(wl);
1294 /* We don't need a real memory partition here, because we only want
1295 * to use the registers at this point. */
1296 memset(&partition, 0, sizeof(partition));
1297 partition.reg.start = REGISTERS_BASE;
1298 partition.reg.size = REGISTERS_DOWN_SIZE;
1299 wl1271_set_partition(wl, &partition);
1301 /* ELP module wake up */
1302 wl1271_fw_wakeup(wl);
1304 /* whal_FwCtrl_BootSm() */
1306 /* 0. read chip id from CHIP_ID */
1307 wl->chip.id = wl1271_read32(wl, CHIP_ID_B);
1309 /* 1. check if chip id is valid */
1311 switch (wl->chip.id) {
1312 case CHIP_ID_1271_PG10:
1313 wl1271_warning("chip id 0x%x (1271 PG10) support is obsolete",
1316 ret = wl1271_setup(wl);
1320 case CHIP_ID_1271_PG20:
1321 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1271 PG20)",
1325 * 'end-of-transaction flag' and 'LPD mode flag'
1326 * should be set in wl127x AP mode only
1328 if (wl->bss_type == BSS_TYPE_AP_BSS)
1329 wl->quirks |= (WL12XX_QUIRK_END_OF_TRANSACTION |
1330 WL12XX_QUIRK_LPD_MODE);
1332 ret = wl1271_setup(wl);
1336 case CHIP_ID_1283_PG20:
1337 wl1271_debug(DEBUG_BOOT, "chip id 0x%x (1283 PG20)",
1340 ret = wl1271_setup(wl);
1344 if (wl1271_set_block_size(wl))
1345 wl->quirks |= WL12XX_QUIRK_BLOCKSIZE_ALIGNMENT;
1347 case CHIP_ID_1283_PG10:
1349 wl1271_warning("unsupported chip id: 0x%x", wl->chip.id);
1354 /* Make sure the firmware type matches the BSS type */
1355 if (wl->fw == NULL || wl->fw_bss_type != wl->bss_type) {
1356 ret = wl1271_fetch_firmware(wl);
1361 /* No NVS from netlink, try to get it from the filesystem */
1362 if (wl->nvs == NULL) {
1363 ret = wl1271_fetch_nvs(wl);
1372 int wl1271_plt_start(struct wl1271 *wl)
1374 int retries = WL1271_BOOT_RETRIES;
1377 mutex_lock(&wl->mutex);
1379 wl1271_notice("power up");
1381 if (wl->state != WL1271_STATE_OFF) {
1382 wl1271_error("cannot go into PLT state because not "
1383 "in off state: %d", wl->state);
1388 wl->bss_type = BSS_TYPE_STA_BSS;
1392 ret = wl1271_chip_wakeup(wl);
1396 ret = wl1271_boot(wl);
1400 ret = wl1271_plt_init(wl);
1404 wl->state = WL1271_STATE_PLT;
1405 wl1271_notice("firmware booted in PLT mode (%s)",
1406 wl->chip.fw_ver_str);
1411 mutex_unlock(&wl->mutex);
1412 /* Unlocking the mutex in the middle of handling is
1413 inherently unsafe. In this case we deem it safe to do,
1414 because we need to let any possibly pending IRQ out of
1415 the system (and while we are WL1271_STATE_OFF the IRQ
1416 work function will not do anything.) Also, any other
1417 possible concurrent operations will fail due to the
1418 current state, hence the wl1271 struct should be safe. */
1419 wl1271_disable_interrupts(wl);
1420 wl1271_flush_deferred_work(wl);
1421 cancel_work_sync(&wl->netstack_work);
1422 mutex_lock(&wl->mutex);
1424 wl1271_power_off(wl);
1427 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1428 WL1271_BOOT_RETRIES);
1430 mutex_unlock(&wl->mutex);
1435 static int __wl1271_plt_stop(struct wl1271 *wl)
1439 wl1271_notice("power down");
1441 if (wl->state != WL1271_STATE_PLT) {
1442 wl1271_error("cannot power down because not in PLT "
1443 "state: %d", wl->state);
1448 wl1271_power_off(wl);
1450 wl->state = WL1271_STATE_OFF;
1453 mutex_unlock(&wl->mutex);
1454 wl1271_disable_interrupts(wl);
1455 wl1271_flush_deferred_work(wl);
1456 cancel_work_sync(&wl->netstack_work);
1457 cancel_work_sync(&wl->recovery_work);
1458 mutex_lock(&wl->mutex);
1463 int wl1271_plt_stop(struct wl1271 *wl)
1467 mutex_lock(&wl->mutex);
1468 ret = __wl1271_plt_stop(wl);
1469 mutex_unlock(&wl->mutex);
1473 static void wl1271_op_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1475 struct wl1271 *wl = hw->priv;
1476 unsigned long flags;
1480 q = wl1271_tx_get_queue(skb_get_queue_mapping(skb));
1482 if (wl->bss_type == BSS_TYPE_AP_BSS)
1483 hlid = wl1271_tx_get_hlid(skb);
1485 spin_lock_irqsave(&wl->wl_lock, flags);
1487 wl->tx_queue_count++;
1490 * The workqueue is slow to process the tx_queue and we need stop
1491 * the queue here, otherwise the queue will get too long.
1493 if (wl->tx_queue_count >= WL1271_TX_QUEUE_HIGH_WATERMARK) {
1494 wl1271_debug(DEBUG_TX, "op_tx: stopping queues");
1495 ieee80211_stop_queues(wl->hw);
1496 set_bit(WL1271_FLAG_TX_QUEUE_STOPPED, &wl->flags);
1499 /* queue the packet */
1500 if (wl->bss_type == BSS_TYPE_AP_BSS) {
1501 wl1271_debug(DEBUG_TX, "queue skb hlid %d q %d", hlid, q);
1502 skb_queue_tail(&wl->links[hlid].tx_queue[q], skb);
1504 skb_queue_tail(&wl->tx_queue[q], skb);
1508 * The chip specific setup must run before the first TX packet -
1509 * before that, the tx_work will not be initialized!
1512 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags) &&
1513 !test_bit(WL1271_FLAG_TX_PENDING, &wl->flags))
1514 ieee80211_queue_work(wl->hw, &wl->tx_work);
1516 spin_unlock_irqrestore(&wl->wl_lock, flags);
1519 int wl1271_tx_dummy_packet(struct wl1271 *wl)
1521 unsigned long flags;
1523 spin_lock_irqsave(&wl->wl_lock, flags);
1524 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING, &wl->flags);
1525 wl->tx_queue_count++;
1526 spin_unlock_irqrestore(&wl->wl_lock, flags);
1528 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1529 if (!test_bit(WL1271_FLAG_FW_TX_BUSY, &wl->flags))
1530 wl1271_tx_work_locked(wl);
1533 * If the FW TX is busy, TX work will be scheduled by the threaded
1534 * interrupt handler function
1540 * The size of the dummy packet should be at least 1400 bytes. However, in
1541 * order to minimize the number of bus transactions, aligning it to 512 bytes
1542 * boundaries could be beneficial, performance wise
1544 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1546 static struct sk_buff *wl12xx_alloc_dummy_packet(struct wl1271 *wl)
1548 struct sk_buff *skb;
1549 struct ieee80211_hdr_3addr *hdr;
1550 unsigned int dummy_packet_size;
1552 dummy_packet_size = TOTAL_TX_DUMMY_PACKET_SIZE -
1553 sizeof(struct wl1271_tx_hw_descr) - sizeof(*hdr);
1555 skb = dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE);
1557 wl1271_warning("Failed to allocate a dummy packet skb");
1561 skb_reserve(skb, sizeof(struct wl1271_tx_hw_descr));
1563 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
1564 memset(hdr, 0, sizeof(*hdr));
1565 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1566 IEEE80211_STYPE_NULLFUNC |
1567 IEEE80211_FCTL_TODS);
1569 memset(skb_put(skb, dummy_packet_size), 0, dummy_packet_size);
1571 /* Dummy packets require the TID to be management */
1572 skb->priority = WL1271_TID_MGMT;
1574 /* Initialize all fields that might be used */
1575 skb_set_queue_mapping(skb, 0);
1576 memset(IEEE80211_SKB_CB(skb), 0, sizeof(struct ieee80211_tx_info));
1582 static struct notifier_block wl1271_dev_notifier = {
1583 .notifier_call = wl1271_dev_notify,
1587 static int wl1271_configure_suspend_sta(struct wl1271 *wl)
1591 mutex_lock(&wl->mutex);
1593 ret = wl1271_ps_elp_wakeup(wl);
1597 /* enter psm if needed*/
1598 if (!test_bit(WL1271_FLAG_PSM, &wl->flags)) {
1599 DECLARE_COMPLETION_ONSTACK(compl);
1601 wl->ps_compl = &compl;
1602 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
1603 wl->basic_rate, true);
1607 /* we must unlock here so we will be able to get events */
1608 wl1271_ps_elp_sleep(wl);
1609 mutex_unlock(&wl->mutex);
1611 ret = wait_for_completion_timeout(
1612 &compl, msecs_to_jiffies(WL1271_PS_COMPLETE_TIMEOUT));
1614 wl1271_warning("couldn't enter ps mode!");
1619 /* take mutex again, and wakeup */
1620 mutex_lock(&wl->mutex);
1622 ret = wl1271_ps_elp_wakeup(wl);
1627 wl1271_ps_elp_sleep(wl);
1629 mutex_unlock(&wl->mutex);
1635 static int wl1271_configure_suspend_ap(struct wl1271 *wl)
1639 mutex_lock(&wl->mutex);
1641 ret = wl1271_ps_elp_wakeup(wl);
1645 ret = wl1271_acx_set_ap_beacon_filter(wl, true);
1647 wl1271_ps_elp_sleep(wl);
1649 mutex_unlock(&wl->mutex);
1654 static int wl1271_configure_suspend(struct wl1271 *wl)
1656 if (wl->bss_type == BSS_TYPE_STA_BSS)
1657 return wl1271_configure_suspend_sta(wl);
1658 if (wl->bss_type == BSS_TYPE_AP_BSS)
1659 return wl1271_configure_suspend_ap(wl);
1663 static void wl1271_configure_resume(struct wl1271 *wl)
1666 bool is_sta = wl->bss_type == BSS_TYPE_STA_BSS;
1667 bool is_ap = wl->bss_type == BSS_TYPE_AP_BSS;
1669 if (!is_sta && !is_ap)
1672 mutex_lock(&wl->mutex);
1673 ret = wl1271_ps_elp_wakeup(wl);
1678 /* exit psm if it wasn't configured */
1679 if (!test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags))
1680 wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
1681 wl->basic_rate, true);
1683 wl1271_acx_set_ap_beacon_filter(wl, false);
1686 wl1271_ps_elp_sleep(wl);
1688 mutex_unlock(&wl->mutex);
1691 static int wl1271_op_suspend(struct ieee80211_hw *hw,
1692 struct cfg80211_wowlan *wow)
1694 struct wl1271 *wl = hw->priv;
1697 wl1271_debug(DEBUG_MAC80211, "mac80211 suspend wow=%d", !!wow);
1698 WARN_ON(!wow || !wow->any);
1700 wl->wow_enabled = true;
1701 ret = wl1271_configure_suspend(wl);
1703 wl1271_warning("couldn't prepare device to suspend");
1706 /* flush any remaining work */
1707 wl1271_debug(DEBUG_MAC80211, "flushing remaining works");
1708 flush_delayed_work(&wl->scan_complete_work);
1711 * disable and re-enable interrupts in order to flush
1714 wl1271_disable_interrupts(wl);
1717 * set suspended flag to avoid triggering a new threaded_irq
1718 * work. no need for spinlock as interrupts are disabled.
1720 set_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1722 wl1271_enable_interrupts(wl);
1723 flush_work(&wl->tx_work);
1724 flush_delayed_work(&wl->pspoll_work);
1725 flush_delayed_work(&wl->elp_work);
1730 static int wl1271_op_resume(struct ieee80211_hw *hw)
1732 struct wl1271 *wl = hw->priv;
1733 unsigned long flags;
1734 bool run_irq_work = false;
1736 wl1271_debug(DEBUG_MAC80211, "mac80211 resume wow=%d",
1738 WARN_ON(!wl->wow_enabled);
1741 * re-enable irq_work enqueuing, and call irq_work directly if
1742 * there is a pending work.
1744 spin_lock_irqsave(&wl->wl_lock, flags);
1745 clear_bit(WL1271_FLAG_SUSPENDED, &wl->flags);
1746 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK, &wl->flags))
1747 run_irq_work = true;
1748 spin_unlock_irqrestore(&wl->wl_lock, flags);
1751 wl1271_debug(DEBUG_MAC80211,
1752 "run postponed irq_work directly");
1754 wl1271_enable_interrupts(wl);
1756 wl1271_configure_resume(wl);
1757 wl->wow_enabled = false;
1763 static int wl1271_op_start(struct ieee80211_hw *hw)
1765 wl1271_debug(DEBUG_MAC80211, "mac80211 start");
1768 * We have to delay the booting of the hardware because
1769 * we need to know the local MAC address before downloading and
1770 * initializing the firmware. The MAC address cannot be changed
1771 * after boot, and without the proper MAC address, the firmware
1772 * will not function properly.
1774 * The MAC address is first known when the corresponding interface
1775 * is added. That is where we will initialize the hardware.
1777 * In addition, we currently have different firmwares for AP and managed
1778 * operation. We will know which to boot according to interface type.
1784 static void wl1271_op_stop(struct ieee80211_hw *hw)
1786 wl1271_debug(DEBUG_MAC80211, "mac80211 stop");
1789 static int wl1271_op_add_interface(struct ieee80211_hw *hw,
1790 struct ieee80211_vif *vif)
1792 struct wl1271 *wl = hw->priv;
1793 struct wiphy *wiphy = hw->wiphy;
1794 int retries = WL1271_BOOT_RETRIES;
1796 bool booted = false;
1798 wl1271_debug(DEBUG_MAC80211, "mac80211 add interface type %d mac %pM",
1799 vif->type, vif->addr);
1801 mutex_lock(&wl->mutex);
1803 wl1271_debug(DEBUG_MAC80211,
1804 "multiple vifs are not supported yet");
1810 * in some very corner case HW recovery scenarios its possible to
1811 * get here before __wl1271_op_remove_interface is complete, so
1812 * opt out if that is the case.
1814 if (test_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags)) {
1819 switch (vif->type) {
1820 case NL80211_IFTYPE_STATION:
1821 wl->bss_type = BSS_TYPE_STA_BSS;
1822 wl->set_bss_type = BSS_TYPE_STA_BSS;
1824 case NL80211_IFTYPE_ADHOC:
1825 wl->bss_type = BSS_TYPE_IBSS;
1826 wl->set_bss_type = BSS_TYPE_STA_BSS;
1828 case NL80211_IFTYPE_AP:
1829 wl->bss_type = BSS_TYPE_AP_BSS;
1836 memcpy(wl->mac_addr, vif->addr, ETH_ALEN);
1838 if (wl->state != WL1271_STATE_OFF) {
1839 wl1271_error("cannot start because not in off state: %d",
1847 ret = wl1271_chip_wakeup(wl);
1851 ret = wl1271_boot(wl);
1855 ret = wl1271_hw_init(wl);
1863 mutex_unlock(&wl->mutex);
1864 /* Unlocking the mutex in the middle of handling is
1865 inherently unsafe. In this case we deem it safe to do,
1866 because we need to let any possibly pending IRQ out of
1867 the system (and while we are WL1271_STATE_OFF the IRQ
1868 work function will not do anything.) Also, any other
1869 possible concurrent operations will fail due to the
1870 current state, hence the wl1271 struct should be safe. */
1871 wl1271_disable_interrupts(wl);
1872 wl1271_flush_deferred_work(wl);
1873 cancel_work_sync(&wl->netstack_work);
1874 mutex_lock(&wl->mutex);
1876 wl1271_power_off(wl);
1880 wl1271_error("firmware boot failed despite %d retries",
1881 WL1271_BOOT_RETRIES);
1886 wl->state = WL1271_STATE_ON;
1887 set_bit(WL1271_FLAG_IF_INITIALIZED, &wl->flags);
1888 wl1271_info("firmware booted (%s)", wl->chip.fw_ver_str);
1890 /* update hw/fw version info in wiphy struct */
1891 wiphy->hw_version = wl->chip.id;
1892 strncpy(wiphy->fw_version, wl->chip.fw_ver_str,
1893 sizeof(wiphy->fw_version));
1896 * Now we know if 11a is supported (info from the NVS), so disable
1897 * 11a channels if not supported
1899 if (!wl->enable_11a)
1900 wiphy->bands[IEEE80211_BAND_5GHZ]->n_channels = 0;
1902 wl1271_debug(DEBUG_MAC80211, "11a is %ssupported",
1903 wl->enable_11a ? "" : "not ");
1906 mutex_unlock(&wl->mutex);
1908 mutex_lock(&wl_list_mutex);
1910 list_add(&wl->list, &wl_list);
1911 mutex_unlock(&wl_list_mutex);
1916 static void __wl1271_op_remove_interface(struct wl1271 *wl,
1917 bool reset_tx_queues)
1921 wl1271_debug(DEBUG_MAC80211, "mac80211 remove interface");
1923 /* because of hardware recovery, we may get here twice */
1924 if (wl->state != WL1271_STATE_ON)
1927 wl1271_info("down");
1929 mutex_lock(&wl_list_mutex);
1930 list_del(&wl->list);
1931 mutex_unlock(&wl_list_mutex);
1933 /* enable dyn ps just in case (if left on due to fw crash etc) */
1934 if (wl->bss_type == BSS_TYPE_STA_BSS)
1935 ieee80211_enable_dyn_ps(wl->vif);
1937 if (wl->scan.state != WL1271_SCAN_STATE_IDLE) {
1938 wl->scan.state = WL1271_SCAN_STATE_IDLE;
1939 memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch));
1940 wl->scan.req = NULL;
1941 ieee80211_scan_completed(wl->hw, true);
1945 * this must be before the cancel_work calls below, so that the work
1946 * functions don't perform further work.
1948 wl->state = WL1271_STATE_OFF;
1950 mutex_unlock(&wl->mutex);
1952 wl1271_disable_interrupts(wl);
1953 wl1271_flush_deferred_work(wl);
1954 cancel_delayed_work_sync(&wl->scan_complete_work);
1955 cancel_work_sync(&wl->netstack_work);
1956 cancel_work_sync(&wl->tx_work);
1957 del_timer_sync(&wl->rx_streaming_timer);
1958 cancel_work_sync(&wl->rx_streaming_enable_work);
1959 cancel_work_sync(&wl->rx_streaming_disable_work);
1960 cancel_delayed_work_sync(&wl->pspoll_work);
1961 cancel_delayed_work_sync(&wl->elp_work);
1963 mutex_lock(&wl->mutex);
1965 /* let's notify MAC80211 about the remaining pending TX frames */
1966 wl1271_tx_reset(wl, reset_tx_queues);
1967 wl1271_power_off(wl);
1969 memset(wl->bssid, 0, ETH_ALEN);
1970 memset(wl->ssid, 0, IW_ESSID_MAX_SIZE + 1);
1972 wl->bss_type = MAX_BSS_TYPE;
1973 wl->set_bss_type = MAX_BSS_TYPE;
1974 wl->band = IEEE80211_BAND_2GHZ;
1977 wl->psm_entry_retry = 0;
1978 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
1979 wl->tx_blocks_available = 0;
1980 wl->tx_allocated_blocks = 0;
1981 wl->tx_results_count = 0;
1982 wl->tx_packets_count = 0;
1983 wl->tx_security_last_seq = 0;
1984 wl->tx_security_seq = 0;
1985 wl->time_offset = 0;
1986 wl->session_counter = 0;
1987 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
1990 wl1271_free_ap_keys(wl);
1991 memset(wl->ap_hlid_map, 0, sizeof(wl->ap_hlid_map));
1992 wl->ap_fw_ps_map = 0;
1994 wl->sched_scanning = false;
1997 * this is performed after the cancel_work calls and the associated
1998 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1999 * get executed before all these vars have been reset.
2003 for (i = 0; i < NUM_TX_QUEUES; i++)
2004 wl->tx_blocks_freed[i] = 0;
2006 wl1271_debugfs_reset(wl);
2008 kfree(wl->fw_status);
2009 wl->fw_status = NULL;
2010 kfree(wl->tx_res_if);
2011 wl->tx_res_if = NULL;
2012 kfree(wl->target_mem_map);
2013 wl->target_mem_map = NULL;
2016 static void wl1271_op_remove_interface(struct ieee80211_hw *hw,
2017 struct ieee80211_vif *vif)
2019 struct wl1271 *wl = hw->priv;
2021 mutex_lock(&wl->mutex);
2023 * wl->vif can be null here if someone shuts down the interface
2024 * just when hardware recovery has been started.
2027 WARN_ON(wl->vif != vif);
2028 __wl1271_op_remove_interface(wl, true);
2031 mutex_unlock(&wl->mutex);
2032 cancel_work_sync(&wl->recovery_work);
2035 void wl1271_configure_filters(struct wl1271 *wl, unsigned int filters)
2037 wl1271_set_default_filters(wl);
2039 /* combine requested filters with current filter config */
2040 filters = wl->filters | filters;
2042 wl1271_debug(DEBUG_FILTERS, "RX filters set: ");
2044 if (filters & FIF_PROMISC_IN_BSS) {
2045 wl1271_debug(DEBUG_FILTERS, " - FIF_PROMISC_IN_BSS");
2046 wl->rx_config &= ~CFG_UNI_FILTER_EN;
2047 wl->rx_config |= CFG_BSSID_FILTER_EN;
2049 if (filters & FIF_BCN_PRBRESP_PROMISC) {
2050 wl1271_debug(DEBUG_FILTERS, " - FIF_BCN_PRBRESP_PROMISC");
2051 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
2052 wl->rx_config &= ~CFG_SSID_FILTER_EN;
2054 if (filters & FIF_OTHER_BSS) {
2055 wl1271_debug(DEBUG_FILTERS, " - FIF_OTHER_BSS");
2056 wl->rx_config &= ~CFG_BSSID_FILTER_EN;
2058 if (filters & FIF_CONTROL) {
2059 wl1271_debug(DEBUG_FILTERS, " - FIF_CONTROL");
2060 wl->rx_filter |= CFG_RX_CTL_EN;
2062 if (filters & FIF_FCSFAIL) {
2063 wl1271_debug(DEBUG_FILTERS, " - FIF_FCSFAIL");
2064 wl->rx_filter |= CFG_RX_FCS_ERROR;
2068 static int wl1271_dummy_join(struct wl1271 *wl)
2071 /* we need to use a dummy BSSID for now */
2072 static const u8 dummy_bssid[ETH_ALEN] = { 0x0b, 0xad, 0xde,
2075 memcpy(wl->bssid, dummy_bssid, ETH_ALEN);
2077 /* pass through frames from all BSS */
2078 wl1271_configure_filters(wl, FIF_OTHER_BSS);
2080 ret = wl1271_cmd_join(wl, wl->set_bss_type);
2084 set_bit(WL1271_FLAG_JOINED, &wl->flags);
2090 static int wl1271_join(struct wl1271 *wl, bool set_assoc)
2095 * One of the side effects of the JOIN command is that is clears
2096 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2097 * to a WPA/WPA2 access point will therefore kill the data-path.
2098 * Currently the only valid scenario for JOIN during association
2099 * is on roaming, in which case we will also be given new keys.
2100 * Keep the below message for now, unless it starts bothering
2101 * users who really like to roam a lot :)
2103 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
2104 wl1271_info("JOIN while associated.");
2107 set_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags);
2109 ret = wl1271_cmd_join(wl, wl->set_bss_type);
2113 set_bit(WL1271_FLAG_JOINED, &wl->flags);
2115 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
2119 * The join command disable the keep-alive mode, shut down its process,
2120 * and also clear the template config, so we need to reset it all after
2121 * the join. The acx_aid starts the keep-alive process, and the order
2122 * of the commands below is relevant.
2124 ret = wl1271_acx_keep_alive_mode(wl, true);
2128 ret = wl1271_acx_aid(wl, wl->aid);
2132 ret = wl1271_cmd_build_klv_null_data(wl);
2136 ret = wl1271_acx_keep_alive_config(wl, CMD_TEMPL_KLV_IDX_NULL_DATA,
2137 ACX_KEEP_ALIVE_TPL_VALID);
2145 static int wl1271_unjoin(struct wl1271 *wl)
2149 /* to stop listening to a channel, we disconnect */
2150 ret = wl1271_cmd_disconnect(wl);
2154 clear_bit(WL1271_FLAG_JOINED, &wl->flags);
2155 memset(wl->bssid, 0, ETH_ALEN);
2157 /* stop filtering packets based on bssid */
2158 wl1271_configure_filters(wl, FIF_OTHER_BSS);
2164 static void wl1271_set_band_rate(struct wl1271 *wl)
2166 if (wl->band == IEEE80211_BAND_2GHZ)
2167 wl->basic_rate_set = wl->conf.tx.basic_rate;
2169 wl->basic_rate_set = wl->conf.tx.basic_rate_5;
2172 static int wl1271_sta_handle_idle(struct wl1271 *wl, bool idle)
2177 if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
2178 ret = wl1271_unjoin(wl);
2182 wl->rate_set = wl1271_tx_min_rate_get(wl);
2183 ret = wl1271_acx_sta_rate_policies(wl);
2186 ret = wl1271_acx_keep_alive_config(
2187 wl, CMD_TEMPL_KLV_IDX_NULL_DATA,
2188 ACX_KEEP_ALIVE_TPL_INVALID);
2191 set_bit(WL1271_FLAG_IDLE, &wl->flags);
2193 /* increment the session counter */
2194 wl->session_counter++;
2195 if (wl->session_counter >= SESSION_COUNTER_MAX)
2196 wl->session_counter = 0;
2198 /* The current firmware only supports sched_scan in idle */
2199 if (wl->sched_scanning) {
2200 wl1271_scan_sched_scan_stop(wl);
2201 ieee80211_sched_scan_stopped(wl->hw);
2204 ret = wl1271_dummy_join(wl);
2207 clear_bit(WL1271_FLAG_IDLE, &wl->flags);
2214 static int wl1271_op_config(struct ieee80211_hw *hw, u32 changed)
2216 struct wl1271 *wl = hw->priv;
2217 struct ieee80211_conf *conf = &hw->conf;
2218 int channel, ret = 0;
2221 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2223 wl1271_debug(DEBUG_MAC80211, "mac80211 config ch %d psm %s power %d %s"
2226 conf->flags & IEEE80211_CONF_PS ? "on" : "off",
2228 conf->flags & IEEE80211_CONF_IDLE ? "idle" : "in use",
2232 * mac80211 will go to idle nearly immediately after transmitting some
2233 * frames, such as the deauth. To make sure those frames reach the air,
2234 * wait here until the TX queue is fully flushed.
2236 if ((changed & IEEE80211_CONF_CHANGE_IDLE) &&
2237 (conf->flags & IEEE80211_CONF_IDLE))
2238 wl1271_tx_flush(wl);
2240 mutex_lock(&wl->mutex);
2242 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2243 /* we support configuring the channel and band while off */
2244 if ((changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2245 wl->band = conf->channel->band;
2246 wl->channel = channel;
2252 is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2254 ret = wl1271_ps_elp_wakeup(wl);
2258 /* if the channel changes while joined, join again */
2259 if (changed & IEEE80211_CONF_CHANGE_CHANNEL &&
2260 ((wl->band != conf->channel->band) ||
2261 (wl->channel != channel))) {
2262 wl->band = conf->channel->band;
2263 wl->channel = channel;
2267 * FIXME: the mac80211 should really provide a fixed
2268 * rate to use here. for now, just use the smallest
2269 * possible rate for the band as a fixed rate for
2270 * association frames and other control messages.
2272 if (!test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags))
2273 wl1271_set_band_rate(wl);
2275 wl->basic_rate = wl1271_tx_min_rate_get(wl);
2276 ret = wl1271_acx_sta_rate_policies(wl);
2278 wl1271_warning("rate policy for channel "
2281 if (test_bit(WL1271_FLAG_JOINED, &wl->flags)) {
2282 ret = wl1271_join(wl, false);
2284 wl1271_warning("cmd join on channel "
2290 if (changed & IEEE80211_CONF_CHANGE_IDLE && !is_ap) {
2291 ret = wl1271_sta_handle_idle(wl,
2292 conf->flags & IEEE80211_CONF_IDLE);
2294 wl1271_warning("idle mode change failed %d", ret);
2298 * if mac80211 changes the PSM mode, make sure the mode is not
2299 * incorrectly changed after the pspoll failure active window.
2301 if (changed & IEEE80211_CONF_CHANGE_PS)
2302 clear_bit(WL1271_FLAG_PSPOLL_FAILURE, &wl->flags);
2304 if (conf->flags & IEEE80211_CONF_PS &&
2305 !test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
2306 set_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
2309 * We enter PSM only if we're already associated.
2310 * If we're not, we'll enter it when joining an SSID,
2311 * through the bss_info_changed() hook.
2313 if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) {
2314 wl1271_debug(DEBUG_PSM, "psm enabled");
2315 ret = wl1271_ps_set_mode(wl, STATION_POWER_SAVE_MODE,
2316 wl->basic_rate, true);
2318 } else if (!(conf->flags & IEEE80211_CONF_PS) &&
2319 test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags)) {
2320 wl1271_debug(DEBUG_PSM, "psm disabled");
2322 clear_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags);
2324 if (test_bit(WL1271_FLAG_PSM, &wl->flags))
2325 ret = wl1271_ps_set_mode(wl, STATION_ACTIVE_MODE,
2326 wl->basic_rate, true);
2329 if (conf->power_level != wl->power_level) {
2330 ret = wl1271_acx_tx_power(wl, conf->power_level);
2334 wl->power_level = conf->power_level;
2338 wl1271_ps_elp_sleep(wl);
2341 mutex_unlock(&wl->mutex);
2346 struct wl1271_filter_params {
2349 u8 mc_list[ACX_MC_ADDRESS_GROUP_MAX][ETH_ALEN];
2352 static u64 wl1271_op_prepare_multicast(struct ieee80211_hw *hw,
2353 struct netdev_hw_addr_list *mc_list)
2355 struct wl1271_filter_params *fp;
2356 struct netdev_hw_addr *ha;
2357 struct wl1271 *wl = hw->priv;
2359 if (unlikely(wl->state == WL1271_STATE_OFF))
2362 fp = kzalloc(sizeof(*fp), GFP_ATOMIC);
2364 wl1271_error("Out of memory setting filters.");
2368 /* update multicast filtering parameters */
2369 fp->mc_list_length = 0;
2370 if (netdev_hw_addr_list_count(mc_list) > ACX_MC_ADDRESS_GROUP_MAX) {
2371 fp->enabled = false;
2374 netdev_hw_addr_list_for_each(ha, mc_list) {
2375 memcpy(fp->mc_list[fp->mc_list_length],
2376 ha->addr, ETH_ALEN);
2377 fp->mc_list_length++;
2381 return (u64)(unsigned long)fp;
2384 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2387 FIF_BCN_PRBRESP_PROMISC | \
2391 static void wl1271_op_configure_filter(struct ieee80211_hw *hw,
2392 unsigned int changed,
2393 unsigned int *total, u64 multicast)
2395 struct wl1271_filter_params *fp = (void *)(unsigned long)multicast;
2396 struct wl1271 *wl = hw->priv;
2399 wl1271_debug(DEBUG_MAC80211, "mac80211 configure filter changed %x"
2400 " total %x", changed, *total);
2402 mutex_lock(&wl->mutex);
2404 *total &= WL1271_SUPPORTED_FILTERS;
2405 changed &= WL1271_SUPPORTED_FILTERS;
2407 if (unlikely(wl->state == WL1271_STATE_OFF))
2410 ret = wl1271_ps_elp_wakeup(wl);
2414 if (wl->bss_type != BSS_TYPE_AP_BSS) {
2415 if (*total & FIF_ALLMULTI)
2416 ret = wl1271_acx_group_address_tbl(wl, false, NULL, 0);
2418 ret = wl1271_acx_group_address_tbl(wl, fp->enabled,
2420 fp->mc_list_length);
2425 /* determine, whether supported filter values have changed */
2429 /* configure filters */
2430 wl->filters = *total;
2431 wl1271_configure_filters(wl, 0);
2433 /* apply configured filters */
2434 ret = wl1271_acx_rx_config(wl, wl->rx_config, wl->rx_filter);
2439 wl1271_ps_elp_sleep(wl);
2442 mutex_unlock(&wl->mutex);
2446 static int wl1271_record_ap_key(struct wl1271 *wl, u8 id, u8 key_type,
2447 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
2450 struct wl1271_ap_key *ap_key;
2453 wl1271_debug(DEBUG_CRYPT, "record ap key id %d", (int)id);
2455 if (key_size > MAX_KEY_SIZE)
2459 * Find next free entry in ap_keys. Also check we are not replacing
2462 for (i = 0; i < MAX_NUM_KEYS; i++) {
2463 if (wl->recorded_ap_keys[i] == NULL)
2466 if (wl->recorded_ap_keys[i]->id == id) {
2467 wl1271_warning("trying to record key replacement");
2472 if (i == MAX_NUM_KEYS)
2475 ap_key = kzalloc(sizeof(*ap_key), GFP_KERNEL);
2480 ap_key->key_type = key_type;
2481 ap_key->key_size = key_size;
2482 memcpy(ap_key->key, key, key_size);
2483 ap_key->hlid = hlid;
2484 ap_key->tx_seq_32 = tx_seq_32;
2485 ap_key->tx_seq_16 = tx_seq_16;
2487 wl->recorded_ap_keys[i] = ap_key;
2491 static void wl1271_free_ap_keys(struct wl1271 *wl)
2495 for (i = 0; i < MAX_NUM_KEYS; i++) {
2496 kfree(wl->recorded_ap_keys[i]);
2497 wl->recorded_ap_keys[i] = NULL;
2501 static int wl1271_ap_init_hwenc(struct wl1271 *wl)
2504 struct wl1271_ap_key *key;
2505 bool wep_key_added = false;
2507 for (i = 0; i < MAX_NUM_KEYS; i++) {
2508 if (wl->recorded_ap_keys[i] == NULL)
2511 key = wl->recorded_ap_keys[i];
2512 ret = wl1271_cmd_set_ap_key(wl, KEY_ADD_OR_REPLACE,
2513 key->id, key->key_type,
2514 key->key_size, key->key,
2515 key->hlid, key->tx_seq_32,
2520 if (key->key_type == KEY_WEP)
2521 wep_key_added = true;
2524 if (wep_key_added) {
2525 ret = wl1271_cmd_set_ap_default_wep_key(wl, wl->default_key);
2531 wl1271_free_ap_keys(wl);
2535 static int wl1271_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
2536 u8 key_size, const u8 *key, u32 tx_seq_32,
2537 u16 tx_seq_16, struct ieee80211_sta *sta)
2540 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2543 struct wl1271_station *wl_sta;
2547 wl_sta = (struct wl1271_station *)sta->drv_priv;
2548 hlid = wl_sta->hlid;
2550 hlid = WL1271_AP_BROADCAST_HLID;
2553 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
2555 * We do not support removing keys after AP shutdown.
2556 * Pretend we do to make mac80211 happy.
2558 if (action != KEY_ADD_OR_REPLACE)
2561 ret = wl1271_record_ap_key(wl, id,
2563 key, hlid, tx_seq_32,
2566 ret = wl1271_cmd_set_ap_key(wl, action,
2567 id, key_type, key_size,
2568 key, hlid, tx_seq_32,
2576 static const u8 bcast_addr[ETH_ALEN] = {
2577 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2580 addr = sta ? sta->addr : bcast_addr;
2582 if (is_zero_ether_addr(addr)) {
2583 /* We dont support TX only encryption */
2587 /* The wl1271 does not allow to remove unicast keys - they
2588 will be cleared automatically on next CMD_JOIN. Ignore the
2589 request silently, as we dont want the mac80211 to emit
2590 an error message. */
2591 if (action == KEY_REMOVE && !is_broadcast_ether_addr(addr))
2594 ret = wl1271_cmd_set_sta_key(wl, action,
2595 id, key_type, key_size,
2596 key, addr, tx_seq_32,
2601 /* the default WEP key needs to be configured at least once */
2602 if (key_type == KEY_WEP) {
2603 ret = wl1271_cmd_set_sta_default_wep_key(wl,
2613 static int wl1271_op_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
2614 struct ieee80211_vif *vif,
2615 struct ieee80211_sta *sta,
2616 struct ieee80211_key_conf *key_conf)
2618 struct wl1271 *wl = hw->priv;
2624 wl1271_debug(DEBUG_MAC80211, "mac80211 set key");
2626 wl1271_debug(DEBUG_CRYPT, "CMD: 0x%x sta: %p", cmd, sta);
2627 wl1271_debug(DEBUG_CRYPT, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
2628 key_conf->cipher, key_conf->keyidx,
2629 key_conf->keylen, key_conf->flags);
2630 wl1271_dump(DEBUG_CRYPT, "KEY: ", key_conf->key, key_conf->keylen);
2632 mutex_lock(&wl->mutex);
2634 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2639 ret = wl1271_ps_elp_wakeup(wl);
2643 switch (key_conf->cipher) {
2644 case WLAN_CIPHER_SUITE_WEP40:
2645 case WLAN_CIPHER_SUITE_WEP104:
2648 key_conf->hw_key_idx = key_conf->keyidx;
2650 case WLAN_CIPHER_SUITE_TKIP:
2651 key_type = KEY_TKIP;
2653 key_conf->hw_key_idx = key_conf->keyidx;
2654 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
2655 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
2657 case WLAN_CIPHER_SUITE_CCMP:
2660 key_conf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
2661 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
2662 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
2664 case WL1271_CIPHER_SUITE_GEM:
2666 tx_seq_32 = WL1271_TX_SECURITY_HI32(wl->tx_security_seq);
2667 tx_seq_16 = WL1271_TX_SECURITY_LO16(wl->tx_security_seq);
2670 wl1271_error("Unknown key algo 0x%x", key_conf->cipher);
2678 ret = wl1271_set_key(wl, KEY_ADD_OR_REPLACE,
2679 key_conf->keyidx, key_type,
2680 key_conf->keylen, key_conf->key,
2681 tx_seq_32, tx_seq_16, sta);
2683 wl1271_error("Could not add or replace key");
2689 ret = wl1271_set_key(wl, KEY_REMOVE,
2690 key_conf->keyidx, key_type,
2691 key_conf->keylen, key_conf->key,
2694 wl1271_error("Could not remove key");
2700 wl1271_error("Unsupported key cmd 0x%x", cmd);
2706 wl1271_ps_elp_sleep(wl);
2709 mutex_unlock(&wl->mutex);
2714 static int wl1271_op_hw_scan(struct ieee80211_hw *hw,
2715 struct ieee80211_vif *vif,
2716 struct cfg80211_scan_request *req)
2718 struct wl1271 *wl = hw->priv;
2723 wl1271_debug(DEBUG_MAC80211, "mac80211 hw scan");
2726 ssid = req->ssids[0].ssid;
2727 len = req->ssids[0].ssid_len;
2730 mutex_lock(&wl->mutex);
2732 if (wl->state == WL1271_STATE_OFF) {
2734 * We cannot return -EBUSY here because cfg80211 will expect
2735 * a call to ieee80211_scan_completed if we do - in this case
2736 * there won't be any call.
2742 ret = wl1271_ps_elp_wakeup(wl);
2746 ret = wl1271_scan(hw->priv, ssid, len, req);
2748 wl1271_ps_elp_sleep(wl);
2751 mutex_unlock(&wl->mutex);
2756 static int wl1271_op_sched_scan_start(struct ieee80211_hw *hw,
2757 struct ieee80211_vif *vif,
2758 struct cfg80211_sched_scan_request *req,
2759 struct ieee80211_sched_scan_ies *ies)
2761 struct wl1271 *wl = hw->priv;
2764 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_start");
2766 mutex_lock(&wl->mutex);
2768 ret = wl1271_ps_elp_wakeup(wl);
2772 ret = wl1271_scan_sched_scan_config(wl, req, ies);
2776 ret = wl1271_scan_sched_scan_start(wl);
2780 wl->sched_scanning = true;
2783 wl1271_ps_elp_sleep(wl);
2785 mutex_unlock(&wl->mutex);
2789 static void wl1271_op_sched_scan_stop(struct ieee80211_hw *hw,
2790 struct ieee80211_vif *vif)
2792 struct wl1271 *wl = hw->priv;
2795 wl1271_debug(DEBUG_MAC80211, "wl1271_op_sched_scan_stop");
2797 mutex_lock(&wl->mutex);
2799 ret = wl1271_ps_elp_wakeup(wl);
2803 wl1271_scan_sched_scan_stop(wl);
2805 wl1271_ps_elp_sleep(wl);
2807 mutex_unlock(&wl->mutex);
2810 static int wl1271_op_set_frag_threshold(struct ieee80211_hw *hw, u32 value)
2812 struct wl1271 *wl = hw->priv;
2815 mutex_lock(&wl->mutex);
2817 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2822 ret = wl1271_ps_elp_wakeup(wl);
2826 ret = wl1271_acx_frag_threshold(wl, value);
2828 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret);
2830 wl1271_ps_elp_sleep(wl);
2833 mutex_unlock(&wl->mutex);
2838 static int wl1271_op_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
2840 struct wl1271 *wl = hw->priv;
2843 mutex_lock(&wl->mutex);
2845 if (unlikely(wl->state == WL1271_STATE_OFF)) {
2850 ret = wl1271_ps_elp_wakeup(wl);
2854 ret = wl1271_acx_rts_threshold(wl, value);
2856 wl1271_warning("wl1271_op_set_rts_threshold failed: %d", ret);
2858 wl1271_ps_elp_sleep(wl);
2861 mutex_unlock(&wl->mutex);
2866 static int wl1271_ssid_set(struct wl1271 *wl, struct sk_buff *skb,
2870 const u8 *ptr = cfg80211_find_ie(WLAN_EID_SSID, skb->data + offset,
2874 wl1271_error("No SSID in IEs!");
2879 if (ssid_len > IEEE80211_MAX_SSID_LEN) {
2880 wl1271_error("SSID is too long!");
2884 wl->ssid_len = ssid_len;
2885 memcpy(wl->ssid, ptr+2, ssid_len);
2889 static int wl1271_bss_erp_info_changed(struct wl1271 *wl,
2890 struct ieee80211_bss_conf *bss_conf,
2895 if (changed & BSS_CHANGED_ERP_SLOT) {
2896 if (bss_conf->use_short_slot)
2897 ret = wl1271_acx_slot(wl, SLOT_TIME_SHORT);
2899 ret = wl1271_acx_slot(wl, SLOT_TIME_LONG);
2901 wl1271_warning("Set slot time failed %d", ret);
2906 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
2907 if (bss_conf->use_short_preamble)
2908 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_SHORT);
2910 wl1271_acx_set_preamble(wl, ACX_PREAMBLE_LONG);
2913 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
2914 if (bss_conf->use_cts_prot)
2915 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_ENABLE);
2917 ret = wl1271_acx_cts_protect(wl, CTSPROTECT_DISABLE);
2919 wl1271_warning("Set ctsprotect failed %d", ret);
2928 static int wl1271_bss_beacon_info_changed(struct wl1271 *wl,
2929 struct ieee80211_vif *vif,
2930 struct ieee80211_bss_conf *bss_conf,
2933 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
2936 if ((changed & BSS_CHANGED_BEACON_INT)) {
2937 wl1271_debug(DEBUG_MASTER, "beacon interval updated: %d",
2938 bss_conf->beacon_int);
2940 wl->beacon_int = bss_conf->beacon_int;
2943 if ((changed & BSS_CHANGED_BEACON)) {
2944 struct ieee80211_hdr *hdr;
2945 int ieoffset = offsetof(struct ieee80211_mgmt,
2947 struct sk_buff *beacon = ieee80211_beacon_get(wl->hw, vif);
2953 wl1271_debug(DEBUG_MASTER, "beacon updated");
2955 ret = wl1271_ssid_set(wl, beacon, ieoffset);
2957 dev_kfree_skb(beacon);
2960 tmpl_id = is_ap ? CMD_TEMPL_AP_BEACON :
2962 ret = wl1271_cmd_template_set(wl, tmpl_id,
2965 wl1271_tx_min_rate_get(wl));
2967 dev_kfree_skb(beacon);
2971 hdr = (struct ieee80211_hdr *) beacon->data;
2972 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2973 IEEE80211_STYPE_PROBE_RESP);
2975 tmpl_id = is_ap ? CMD_TEMPL_AP_PROBE_RESPONSE :
2976 CMD_TEMPL_PROBE_RESPONSE;
2977 ret = wl1271_cmd_template_set(wl,
2981 wl1271_tx_min_rate_get(wl));
2982 dev_kfree_skb(beacon);
2991 /* AP mode changes */
2992 static void wl1271_bss_info_changed_ap(struct wl1271 *wl,
2993 struct ieee80211_vif *vif,
2994 struct ieee80211_bss_conf *bss_conf,
2999 if ((changed & BSS_CHANGED_BASIC_RATES)) {
3000 u32 rates = bss_conf->basic_rates;
3002 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl, rates);
3003 wl->basic_rate = wl1271_tx_min_rate_get(wl);
3005 ret = wl1271_init_ap_rates(wl);
3007 wl1271_error("AP rate policy change failed %d", ret);
3011 ret = wl1271_ap_init_templates(wl);
3016 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf, changed);
3020 if ((changed & BSS_CHANGED_BEACON_ENABLED)) {
3021 if (bss_conf->enable_beacon) {
3022 if (!test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
3023 ret = wl1271_cmd_start_bss(wl);
3027 set_bit(WL1271_FLAG_AP_STARTED, &wl->flags);
3028 wl1271_debug(DEBUG_AP, "started AP");
3030 ret = wl1271_ap_init_hwenc(wl);
3035 if (test_bit(WL1271_FLAG_AP_STARTED, &wl->flags)) {
3036 ret = wl1271_cmd_stop_bss(wl);
3040 clear_bit(WL1271_FLAG_AP_STARTED, &wl->flags);
3041 wl1271_debug(DEBUG_AP, "stopped AP");
3046 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
3053 /* STA/IBSS mode changes */
3054 static void wl1271_bss_info_changed_sta(struct wl1271 *wl,
3055 struct ieee80211_vif *vif,
3056 struct ieee80211_bss_conf *bss_conf,
3059 bool do_join = false, set_assoc = false;
3060 bool is_ibss = (wl->bss_type == BSS_TYPE_IBSS);
3061 u32 sta_rate_set = 0;
3063 struct ieee80211_sta *sta;
3064 bool sta_exists = false;
3065 struct ieee80211_sta_ht_cap sta_ht_cap;
3068 ret = wl1271_bss_beacon_info_changed(wl, vif, bss_conf,
3074 if ((changed & BSS_CHANGED_BEACON_INT) && is_ibss)
3077 /* Need to update the SSID (for filtering etc) */
3078 if ((changed & BSS_CHANGED_BEACON) && is_ibss)
3081 if ((changed & BSS_CHANGED_BEACON_ENABLED) && is_ibss) {
3082 wl1271_debug(DEBUG_ADHOC, "ad-hoc beaconing: %s",
3083 bss_conf->enable_beacon ? "enabled" : "disabled");
3085 if (bss_conf->enable_beacon)
3086 wl->set_bss_type = BSS_TYPE_IBSS;
3088 wl->set_bss_type = BSS_TYPE_STA_BSS;
3092 if ((changed & BSS_CHANGED_CQM)) {
3093 bool enable = false;
3094 if (bss_conf->cqm_rssi_thold)
3096 ret = wl1271_acx_rssi_snr_trigger(wl, enable,
3097 bss_conf->cqm_rssi_thold,
3098 bss_conf->cqm_rssi_hyst);
3101 wl->rssi_thold = bss_conf->cqm_rssi_thold;
3104 if ((changed & BSS_CHANGED_BSSID) &&
3106 * Now we know the correct bssid, so we send a new join command
3107 * and enable the BSSID filter
3109 memcmp(wl->bssid, bss_conf->bssid, ETH_ALEN)) {
3110 memcpy(wl->bssid, bss_conf->bssid, ETH_ALEN);
3112 if (!is_zero_ether_addr(wl->bssid)) {
3113 ret = wl1271_cmd_build_null_data(wl);
3117 ret = wl1271_build_qos_null_data(wl);
3121 /* filter out all packets not from this BSSID */
3122 wl1271_configure_filters(wl, 0);
3124 /* Need to update the BSSID (for filtering etc) */
3130 sta = ieee80211_find_sta(vif, bss_conf->bssid);
3132 /* save the supp_rates of the ap */
3133 sta_rate_set = sta->supp_rates[wl->hw->conf.channel->band];
3134 if (sta->ht_cap.ht_supported)
3136 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET);
3137 sta_ht_cap = sta->ht_cap;
3143 /* handle new association with HT and HT information change */
3144 if ((changed & BSS_CHANGED_HT) &&
3145 (bss_conf->channel_type != NL80211_CHAN_NO_HT)) {
3146 ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
3149 wl1271_warning("Set ht cap true failed %d",
3153 ret = wl1271_acx_set_ht_information(wl,
3154 bss_conf->ht_operation_mode);
3156 wl1271_warning("Set ht information failed %d",
3161 /* handle new association without HT and disassociation */
3162 else if (changed & BSS_CHANGED_ASSOC) {
3163 ret = wl1271_acx_set_ht_capabilities(wl, &sta_ht_cap,
3166 wl1271_warning("Set ht cap false failed %d",
3173 if ((changed & BSS_CHANGED_ASSOC)) {
3174 if (bss_conf->assoc) {
3177 wl->aid = bss_conf->aid;
3180 wl->ps_poll_failures = 0;
3183 * use basic rates from AP, and determine lowest rate
3184 * to use with control frames.
3186 rates = bss_conf->basic_rates;
3187 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
3189 wl->basic_rate = wl1271_tx_min_rate_get(wl);
3191 wl->rate_set = wl1271_tx_enabled_rates_get(wl,
3193 ret = wl1271_acx_sta_rate_policies(wl);
3198 * with wl1271, we don't need to update the
3199 * beacon_int and dtim_period, because the firmware
3200 * updates it by itself when the first beacon is
3201 * received after a join.
3203 ret = wl1271_cmd_build_ps_poll(wl, wl->aid);
3208 * Get a template for hardware connection maintenance
3210 dev_kfree_skb(wl->probereq);
3211 wl->probereq = wl1271_cmd_build_ap_probe_req(wl, NULL);
3212 ieoffset = offsetof(struct ieee80211_mgmt,
3213 u.probe_req.variable);
3214 wl1271_ssid_set(wl, wl->probereq, ieoffset);
3216 /* enable the connection monitoring feature */
3217 ret = wl1271_acx_conn_monit_params(wl, true);
3221 /* If we want to go in PSM but we're not there yet */
3222 if (test_bit(WL1271_FLAG_PSM_REQUESTED, &wl->flags) &&
3223 !test_bit(WL1271_FLAG_PSM, &wl->flags)) {
3224 enum wl1271_cmd_ps_mode mode;
3226 mode = STATION_POWER_SAVE_MODE;
3227 ret = wl1271_ps_set_mode(wl, mode,
3234 /* use defaults when not associated */
3236 !!test_and_clear_bit(WL1271_FLAG_STA_ASSOCIATED,
3238 clear_bit(WL1271_FLAG_STA_STATE_SENT, &wl->flags);
3241 /* free probe-request template */
3242 dev_kfree_skb(wl->probereq);
3243 wl->probereq = NULL;
3245 /* re-enable dynamic ps - just in case */
3246 ieee80211_enable_dyn_ps(wl->vif);
3248 /* revert back to minimum rates for the current band */
3249 wl1271_set_band_rate(wl);
3250 wl->basic_rate = wl1271_tx_min_rate_get(wl);
3251 ret = wl1271_acx_sta_rate_policies(wl);
3255 /* disable connection monitor features */
3256 ret = wl1271_acx_conn_monit_params(wl, false);
3258 /* Disable the keep-alive feature */
3259 ret = wl1271_acx_keep_alive_mode(wl, false);
3263 /* restore the bssid filter and go to dummy bssid */
3266 wl1271_dummy_join(wl);
3271 if (changed & BSS_CHANGED_IBSS) {
3272 wl1271_debug(DEBUG_ADHOC, "ibss_joined: %d",
3273 bss_conf->ibss_joined);
3275 if (bss_conf->ibss_joined) {
3276 u32 rates = bss_conf->basic_rates;
3277 wl->basic_rate_set = wl1271_tx_enabled_rates_get(wl,
3279 wl->basic_rate = wl1271_tx_min_rate_get(wl);
3281 /* by default, use 11b rates */
3282 wl->rate_set = CONF_TX_IBSS_DEFAULT_RATES;
3283 ret = wl1271_acx_sta_rate_policies(wl);
3289 ret = wl1271_bss_erp_info_changed(wl, bss_conf, changed);
3293 if (changed & BSS_CHANGED_ARP_FILTER) {
3294 __be32 addr = bss_conf->arp_addr_list[0];
3295 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
3297 if (bss_conf->arp_addr_cnt == 1 &&
3298 bss_conf->arp_filter_enabled) {
3300 * The template should have been configured only upon
3301 * association. however, it seems that the correct ip
3302 * isn't being set (when sending), so we have to
3303 * reconfigure the template upon every ip change.
3305 ret = wl1271_cmd_build_arp_rsp(wl, addr);
3307 wl1271_warning("build arp rsp failed: %d", ret);
3311 ret = wl1271_acx_arp_ip_filter(wl,
3312 ACX_ARP_FILTER_ARP_FILTERING,
3315 ret = wl1271_acx_arp_ip_filter(wl, 0, addr);
3322 ret = wl1271_join(wl, set_assoc);
3324 wl1271_warning("cmd join failed %d", ret);
3327 wl1271_check_operstate(wl, ieee80211_get_operstate(vif));
3334 static void wl1271_op_bss_info_changed(struct ieee80211_hw *hw,
3335 struct ieee80211_vif *vif,
3336 struct ieee80211_bss_conf *bss_conf,
3339 struct wl1271 *wl = hw->priv;
3340 bool is_ap = (wl->bss_type == BSS_TYPE_AP_BSS);
3343 wl1271_debug(DEBUG_MAC80211, "mac80211 bss info changed 0x%x",
3346 mutex_lock(&wl->mutex);
3348 if (unlikely(wl->state == WL1271_STATE_OFF))
3351 ret = wl1271_ps_elp_wakeup(wl);
3356 wl1271_bss_info_changed_ap(wl, vif, bss_conf, changed);
3358 wl1271_bss_info_changed_sta(wl, vif, bss_conf, changed);
3360 wl1271_ps_elp_sleep(wl);
3363 mutex_unlock(&wl->mutex);
3366 static int wl1271_op_conf_tx(struct ieee80211_hw *hw, u16 queue,
3367 const struct ieee80211_tx_queue_params *params)
3369 struct wl1271 *wl = hw->priv;
3373 mutex_lock(&wl->mutex);
3375 wl1271_debug(DEBUG_MAC80211, "mac80211 conf tx %d", queue);
3378 ps_scheme = CONF_PS_SCHEME_UPSD_TRIGGER;
3380 ps_scheme = CONF_PS_SCHEME_LEGACY;
3382 if (wl->state == WL1271_STATE_OFF) {
3384 * If the state is off, the parameters will be recorded and
3385 * configured on init. This happens in AP-mode.
3387 struct conf_tx_ac_category *conf_ac =
3388 &wl->conf.tx.ac_conf[wl1271_tx_get_queue(queue)];
3389 struct conf_tx_tid *conf_tid =
3390 &wl->conf.tx.tid_conf[wl1271_tx_get_queue(queue)];
3392 conf_ac->ac = wl1271_tx_get_queue(queue);
3393 conf_ac->cw_min = (u8)params->cw_min;
3394 conf_ac->cw_max = params->cw_max;
3395 conf_ac->aifsn = params->aifs;
3396 conf_ac->tx_op_limit = params->txop << 5;
3398 conf_tid->queue_id = wl1271_tx_get_queue(queue);
3399 conf_tid->channel_type = CONF_CHANNEL_TYPE_EDCF;
3400 conf_tid->tsid = wl1271_tx_get_queue(queue);
3401 conf_tid->ps_scheme = ps_scheme;
3402 conf_tid->ack_policy = CONF_ACK_POLICY_LEGACY;
3403 conf_tid->apsd_conf[0] = 0;
3404 conf_tid->apsd_conf[1] = 0;
3408 ret = wl1271_ps_elp_wakeup(wl);
3413 * the txop is confed in units of 32us by the mac80211,
3416 ret = wl1271_acx_ac_cfg(wl, wl1271_tx_get_queue(queue),
3417 params->cw_min, params->cw_max,
3418 params->aifs, params->txop << 5);
3422 ret = wl1271_acx_tid_cfg(wl, wl1271_tx_get_queue(queue),
3423 CONF_CHANNEL_TYPE_EDCF,
3424 wl1271_tx_get_queue(queue),
3425 ps_scheme, CONF_ACK_POLICY_LEGACY,
3429 wl1271_ps_elp_sleep(wl);
3432 mutex_unlock(&wl->mutex);
3437 static u64 wl1271_op_get_tsf(struct ieee80211_hw *hw)
3440 struct wl1271 *wl = hw->priv;
3441 u64 mactime = ULLONG_MAX;
3444 wl1271_debug(DEBUG_MAC80211, "mac80211 get tsf");
3446 mutex_lock(&wl->mutex);
3448 if (unlikely(wl->state == WL1271_STATE_OFF))
3451 ret = wl1271_ps_elp_wakeup(wl);
3455 ret = wl1271_acx_tsf_info(wl, &mactime);
3460 wl1271_ps_elp_sleep(wl);
3463 mutex_unlock(&wl->mutex);
3467 static int wl1271_op_get_survey(struct ieee80211_hw *hw, int idx,
3468 struct survey_info *survey)
3470 struct wl1271 *wl = hw->priv;
3471 struct ieee80211_conf *conf = &hw->conf;
3476 survey->channel = conf->channel;
3477 survey->filled = SURVEY_INFO_NOISE_DBM;
3478 survey->noise = wl->noise;
3483 static int wl1271_allocate_sta(struct wl1271 *wl,
3484 struct ieee80211_sta *sta,
3487 struct wl1271_station *wl_sta;
3490 id = find_first_zero_bit(wl->ap_hlid_map, AP_MAX_STATIONS);
3491 if (id >= AP_MAX_STATIONS) {
3492 wl1271_warning("could not allocate HLID - too much stations");
3496 wl_sta = (struct wl1271_station *)sta->drv_priv;
3497 __set_bit(id, wl->ap_hlid_map);
3498 wl_sta->hlid = WL1271_AP_STA_HLID_START + id;
3499 *hlid = wl_sta->hlid;
3500 memcpy(wl->links[wl_sta->hlid].addr, sta->addr, ETH_ALEN);
3504 static void wl1271_free_sta(struct wl1271 *wl, u8 hlid)
3506 int id = hlid - WL1271_AP_STA_HLID_START;
3508 if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
3511 __clear_bit(id, wl->ap_hlid_map);
3512 memset(wl->links[hlid].addr, 0, ETH_ALEN);
3513 wl1271_tx_reset_link_queues(wl, hlid);
3514 __clear_bit(hlid, &wl->ap_ps_map);
3515 __clear_bit(hlid, (unsigned long *)&wl->ap_fw_ps_map);
3518 static int wl1271_op_sta_add(struct ieee80211_hw *hw,
3519 struct ieee80211_vif *vif,
3520 struct ieee80211_sta *sta)
3522 struct wl1271 *wl = hw->priv;
3526 mutex_lock(&wl->mutex);
3528 if (unlikely(wl->state == WL1271_STATE_OFF))
3531 if (wl->bss_type != BSS_TYPE_AP_BSS)
3534 wl1271_debug(DEBUG_MAC80211, "mac80211 add sta %d", (int)sta->aid);
3536 ret = wl1271_allocate_sta(wl, sta, &hlid);
3540 ret = wl1271_ps_elp_wakeup(wl);
3544 ret = wl1271_cmd_add_sta(wl, sta, hlid);
3549 wl1271_ps_elp_sleep(wl);
3553 wl1271_free_sta(wl, hlid);
3556 mutex_unlock(&wl->mutex);
3560 static int wl1271_op_sta_remove(struct ieee80211_hw *hw,
3561 struct ieee80211_vif *vif,
3562 struct ieee80211_sta *sta)
3564 struct wl1271 *wl = hw->priv;
3565 struct wl1271_station *wl_sta;
3568 mutex_lock(&wl->mutex);
3570 if (unlikely(wl->state == WL1271_STATE_OFF))
3573 if (wl->bss_type != BSS_TYPE_AP_BSS)
3576 wl1271_debug(DEBUG_MAC80211, "mac80211 remove sta %d", (int)sta->aid);
3578 wl_sta = (struct wl1271_station *)sta->drv_priv;
3579 id = wl_sta->hlid - WL1271_AP_STA_HLID_START;
3580 if (WARN_ON(!test_bit(id, wl->ap_hlid_map)))
3583 ret = wl1271_ps_elp_wakeup(wl);
3587 ret = wl1271_cmd_remove_sta(wl, wl_sta->hlid);
3591 wl1271_free_sta(wl, wl_sta->hlid);
3594 wl1271_ps_elp_sleep(wl);
3597 mutex_unlock(&wl->mutex);
3601 static int wl1271_op_ampdu_action(struct ieee80211_hw *hw,
3602 struct ieee80211_vif *vif,
3603 enum ieee80211_ampdu_mlme_action action,
3604 struct ieee80211_sta *sta, u16 tid, u16 *ssn,
3607 struct wl1271 *wl = hw->priv;
3610 mutex_lock(&wl->mutex);
3612 if (unlikely(wl->state == WL1271_STATE_OFF)) {
3617 ret = wl1271_ps_elp_wakeup(wl);
3621 wl1271_debug(DEBUG_MAC80211, "mac80211 ampdu: Rx tid %d action %d",
3625 case IEEE80211_AMPDU_RX_START:
3626 if ((wl->ba_support) && (wl->ba_allowed)) {
3627 ret = wl1271_acx_set_ba_receiver_session(wl, tid, *ssn,
3630 wl->ba_rx_bitmap |= BIT(tid);
3636 case IEEE80211_AMPDU_RX_STOP:
3637 ret = wl1271_acx_set_ba_receiver_session(wl, tid, 0, false);
3639 wl->ba_rx_bitmap &= ~BIT(tid);
3643 * The BA initiator session management in FW independently.
3644 * Falling break here on purpose for all TX APDU commands.
3646 case IEEE80211_AMPDU_TX_START:
3647 case IEEE80211_AMPDU_TX_STOP:
3648 case IEEE80211_AMPDU_TX_OPERATIONAL:
3653 wl1271_error("Incorrect ampdu action id=%x\n", action);
3657 wl1271_ps_elp_sleep(wl);
3660 mutex_unlock(&wl->mutex);
3665 static bool wl1271_tx_frames_pending(struct ieee80211_hw *hw)
3667 struct wl1271 *wl = hw->priv;
3670 mutex_lock(&wl->mutex);
3672 if (unlikely(wl->state == WL1271_STATE_OFF))
3675 /* packets are considered pending if in the TX queue or the FW */
3676 ret = (wl->tx_queue_count > 0) || (wl->tx_frames_cnt > 0);
3678 /* the above is appropriate for STA mode for PS purposes */
3679 WARN_ON(wl->bss_type != BSS_TYPE_STA_BSS);
3682 mutex_unlock(&wl->mutex);
3687 /* can't be const, mac80211 writes to this */
3688 static struct ieee80211_rate wl1271_rates[] = {
3690 .hw_value = CONF_HW_BIT_RATE_1MBPS,
3691 .hw_value_short = CONF_HW_BIT_RATE_1MBPS, },
3693 .hw_value = CONF_HW_BIT_RATE_2MBPS,
3694 .hw_value_short = CONF_HW_BIT_RATE_2MBPS,
3695 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3697 .hw_value = CONF_HW_BIT_RATE_5_5MBPS,
3698 .hw_value_short = CONF_HW_BIT_RATE_5_5MBPS,
3699 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3701 .hw_value = CONF_HW_BIT_RATE_11MBPS,
3702 .hw_value_short = CONF_HW_BIT_RATE_11MBPS,
3703 .flags = IEEE80211_RATE_SHORT_PREAMBLE },
3705 .hw_value = CONF_HW_BIT_RATE_6MBPS,
3706 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
3708 .hw_value = CONF_HW_BIT_RATE_9MBPS,
3709 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
3711 .hw_value = CONF_HW_BIT_RATE_12MBPS,
3712 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
3714 .hw_value = CONF_HW_BIT_RATE_18MBPS,
3715 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
3717 .hw_value = CONF_HW_BIT_RATE_24MBPS,
3718 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
3720 .hw_value = CONF_HW_BIT_RATE_36MBPS,
3721 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
3723 .hw_value = CONF_HW_BIT_RATE_48MBPS,
3724 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
3726 .hw_value = CONF_HW_BIT_RATE_54MBPS,
3727 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
3730 /* can't be const, mac80211 writes to this */
3731 static struct ieee80211_channel wl1271_channels[] = {
3732 { .hw_value = 1, .center_freq = 2412, .max_power = 25 },
3733 { .hw_value = 2, .center_freq = 2417, .max_power = 25 },
3734 { .hw_value = 3, .center_freq = 2422, .max_power = 25 },
3735 { .hw_value = 4, .center_freq = 2427, .max_power = 25 },
3736 { .hw_value = 5, .center_freq = 2432, .max_power = 25 },
3737 { .hw_value = 6, .center_freq = 2437, .max_power = 25 },
3738 { .hw_value = 7, .center_freq = 2442, .max_power = 25 },
3739 { .hw_value = 8, .center_freq = 2447, .max_power = 25 },
3740 { .hw_value = 9, .center_freq = 2452, .max_power = 25 },
3741 { .hw_value = 10, .center_freq = 2457, .max_power = 25 },
3742 { .hw_value = 11, .center_freq = 2462, .max_power = 25 },
3743 { .hw_value = 12, .center_freq = 2467, .max_power = 25 },
3744 { .hw_value = 13, .center_freq = 2472, .max_power = 25 },
3745 { .hw_value = 14, .center_freq = 2484, .max_power = 25 },
3748 /* mapping to indexes for wl1271_rates */
3749 static const u8 wl1271_rate_to_idx_2ghz[] = {
3750 /* MCS rates are used only with 11n */
3751 7, /* CONF_HW_RXTX_RATE_MCS7 */
3752 6, /* CONF_HW_RXTX_RATE_MCS6 */
3753 5, /* CONF_HW_RXTX_RATE_MCS5 */
3754 4, /* CONF_HW_RXTX_RATE_MCS4 */
3755 3, /* CONF_HW_RXTX_RATE_MCS3 */
3756 2, /* CONF_HW_RXTX_RATE_MCS2 */
3757 1, /* CONF_HW_RXTX_RATE_MCS1 */
3758 0, /* CONF_HW_RXTX_RATE_MCS0 */
3760 11, /* CONF_HW_RXTX_RATE_54 */
3761 10, /* CONF_HW_RXTX_RATE_48 */
3762 9, /* CONF_HW_RXTX_RATE_36 */
3763 8, /* CONF_HW_RXTX_RATE_24 */
3765 /* TI-specific rate */
3766 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
3768 7, /* CONF_HW_RXTX_RATE_18 */
3769 6, /* CONF_HW_RXTX_RATE_12 */
3770 3, /* CONF_HW_RXTX_RATE_11 */
3771 5, /* CONF_HW_RXTX_RATE_9 */
3772 4, /* CONF_HW_RXTX_RATE_6 */
3773 2, /* CONF_HW_RXTX_RATE_5_5 */
3774 1, /* CONF_HW_RXTX_RATE_2 */
3775 0 /* CONF_HW_RXTX_RATE_1 */
3778 /* 11n STA capabilities */
3779 #define HW_RX_HIGHEST_RATE 72
3781 #ifdef CONFIG_WL12XX_HT
3782 #define WL12XX_HT_CAP { \
3783 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
3784 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
3785 .ht_supported = true, \
3786 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
3787 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
3789 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
3790 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
3791 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
3795 #define WL12XX_HT_CAP { \
3796 .ht_supported = false, \
3800 /* can't be const, mac80211 writes to this */
3801 static struct ieee80211_supported_band wl1271_band_2ghz = {
3802 .channels = wl1271_channels,
3803 .n_channels = ARRAY_SIZE(wl1271_channels),
3804 .bitrates = wl1271_rates,
3805 .n_bitrates = ARRAY_SIZE(wl1271_rates),
3806 .ht_cap = WL12XX_HT_CAP,
3809 /* 5 GHz data rates for WL1273 */
3810 static struct ieee80211_rate wl1271_rates_5ghz[] = {
3812 .hw_value = CONF_HW_BIT_RATE_6MBPS,
3813 .hw_value_short = CONF_HW_BIT_RATE_6MBPS, },
3815 .hw_value = CONF_HW_BIT_RATE_9MBPS,
3816 .hw_value_short = CONF_HW_BIT_RATE_9MBPS, },
3818 .hw_value = CONF_HW_BIT_RATE_12MBPS,
3819 .hw_value_short = CONF_HW_BIT_RATE_12MBPS, },
3821 .hw_value = CONF_HW_BIT_RATE_18MBPS,
3822 .hw_value_short = CONF_HW_BIT_RATE_18MBPS, },
3824 .hw_value = CONF_HW_BIT_RATE_24MBPS,
3825 .hw_value_short = CONF_HW_BIT_RATE_24MBPS, },
3827 .hw_value = CONF_HW_BIT_RATE_36MBPS,
3828 .hw_value_short = CONF_HW_BIT_RATE_36MBPS, },
3830 .hw_value = CONF_HW_BIT_RATE_48MBPS,
3831 .hw_value_short = CONF_HW_BIT_RATE_48MBPS, },
3833 .hw_value = CONF_HW_BIT_RATE_54MBPS,
3834 .hw_value_short = CONF_HW_BIT_RATE_54MBPS, },
3837 /* 5 GHz band channels for WL1273 */
3838 static struct ieee80211_channel wl1271_channels_5ghz[] = {
3839 { .hw_value = 7, .center_freq = 5035},
3840 { .hw_value = 8, .center_freq = 5040},
3841 { .hw_value = 9, .center_freq = 5045},
3842 { .hw_value = 11, .center_freq = 5055},
3843 { .hw_value = 12, .center_freq = 5060},
3844 { .hw_value = 16, .center_freq = 5080},
3845 { .hw_value = 34, .center_freq = 5170},
3846 { .hw_value = 36, .center_freq = 5180},
3847 { .hw_value = 38, .center_freq = 5190},
3848 { .hw_value = 40, .center_freq = 5200},
3849 { .hw_value = 42, .center_freq = 5210},
3850 { .hw_value = 44, .center_freq = 5220},
3851 { .hw_value = 46, .center_freq = 5230},
3852 { .hw_value = 48, .center_freq = 5240},
3853 { .hw_value = 52, .center_freq = 5260},
3854 { .hw_value = 56, .center_freq = 5280},
3855 { .hw_value = 60, .center_freq = 5300},
3856 { .hw_value = 64, .center_freq = 5320},
3857 { .hw_value = 100, .center_freq = 5500},
3858 { .hw_value = 104, .center_freq = 5520},
3859 { .hw_value = 108, .center_freq = 5540},
3860 { .hw_value = 112, .center_freq = 5560},
3861 { .hw_value = 116, .center_freq = 5580},
3862 { .hw_value = 120, .center_freq = 5600},
3863 { .hw_value = 124, .center_freq = 5620},
3864 { .hw_value = 128, .center_freq = 5640},
3865 { .hw_value = 132, .center_freq = 5660},
3866 { .hw_value = 136, .center_freq = 5680},
3867 { .hw_value = 140, .center_freq = 5700},
3868 { .hw_value = 149, .center_freq = 5745},
3869 { .hw_value = 153, .center_freq = 5765},
3870 { .hw_value = 157, .center_freq = 5785},
3871 { .hw_value = 161, .center_freq = 5805},
3872 { .hw_value = 165, .center_freq = 5825},
3875 /* mapping to indexes for wl1271_rates_5ghz */
3876 static const u8 wl1271_rate_to_idx_5ghz[] = {
3877 /* MCS rates are used only with 11n */
3878 7, /* CONF_HW_RXTX_RATE_MCS7 */
3879 6, /* CONF_HW_RXTX_RATE_MCS6 */
3880 5, /* CONF_HW_RXTX_RATE_MCS5 */
3881 4, /* CONF_HW_RXTX_RATE_MCS4 */
3882 3, /* CONF_HW_RXTX_RATE_MCS3 */
3883 2, /* CONF_HW_RXTX_RATE_MCS2 */
3884 1, /* CONF_HW_RXTX_RATE_MCS1 */
3885 0, /* CONF_HW_RXTX_RATE_MCS0 */
3887 7, /* CONF_HW_RXTX_RATE_54 */
3888 6, /* CONF_HW_RXTX_RATE_48 */
3889 5, /* CONF_HW_RXTX_RATE_36 */
3890 4, /* CONF_HW_RXTX_RATE_24 */
3892 /* TI-specific rate */
3893 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_22 */
3895 3, /* CONF_HW_RXTX_RATE_18 */
3896 2, /* CONF_HW_RXTX_RATE_12 */
3897 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_11 */
3898 1, /* CONF_HW_RXTX_RATE_9 */
3899 0, /* CONF_HW_RXTX_RATE_6 */
3900 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_5_5 */
3901 CONF_HW_RXTX_RATE_UNSUPPORTED, /* CONF_HW_RXTX_RATE_2 */
3902 CONF_HW_RXTX_RATE_UNSUPPORTED /* CONF_HW_RXTX_RATE_1 */
3905 static struct ieee80211_supported_band wl1271_band_5ghz = {
3906 .channels = wl1271_channels_5ghz,
3907 .n_channels = ARRAY_SIZE(wl1271_channels_5ghz),
3908 .bitrates = wl1271_rates_5ghz,
3909 .n_bitrates = ARRAY_SIZE(wl1271_rates_5ghz),
3910 .ht_cap = WL12XX_HT_CAP,
3913 static const u8 *wl1271_band_rate_to_idx[] = {
3914 [IEEE80211_BAND_2GHZ] = wl1271_rate_to_idx_2ghz,
3915 [IEEE80211_BAND_5GHZ] = wl1271_rate_to_idx_5ghz
3918 static const struct ieee80211_ops wl1271_ops = {
3919 .start = wl1271_op_start,
3920 .stop = wl1271_op_stop,
3921 .add_interface = wl1271_op_add_interface,
3922 .remove_interface = wl1271_op_remove_interface,
3924 .suspend = wl1271_op_suspend,
3925 .resume = wl1271_op_resume,
3927 .config = wl1271_op_config,
3928 .prepare_multicast = wl1271_op_prepare_multicast,
3929 .configure_filter = wl1271_op_configure_filter,
3931 .set_key = wl1271_op_set_key,
3932 .hw_scan = wl1271_op_hw_scan,
3933 .sched_scan_start = wl1271_op_sched_scan_start,
3934 .sched_scan_stop = wl1271_op_sched_scan_stop,
3935 .bss_info_changed = wl1271_op_bss_info_changed,
3936 .set_frag_threshold = wl1271_op_set_frag_threshold,
3937 .set_rts_threshold = wl1271_op_set_rts_threshold,
3938 .conf_tx = wl1271_op_conf_tx,
3939 .get_tsf = wl1271_op_get_tsf,
3940 .get_survey = wl1271_op_get_survey,
3941 .sta_add = wl1271_op_sta_add,
3942 .sta_remove = wl1271_op_sta_remove,
3943 .ampdu_action = wl1271_op_ampdu_action,
3944 .tx_frames_pending = wl1271_tx_frames_pending,
3945 CFG80211_TESTMODE_CMD(wl1271_tm_cmd)
3949 u8 wl1271_rate_to_idx(int rate, enum ieee80211_band band)
3953 BUG_ON(band >= sizeof(wl1271_band_rate_to_idx)/sizeof(u8 *));
3955 if (unlikely(rate >= CONF_HW_RXTX_RATE_MAX)) {
3956 wl1271_error("Illegal RX rate from HW: %d", rate);
3960 idx = wl1271_band_rate_to_idx[band][rate];
3961 if (unlikely(idx == CONF_HW_RXTX_RATE_UNSUPPORTED)) {
3962 wl1271_error("Unsupported RX rate from HW: %d", rate);
3969 static ssize_t wl1271_sysfs_show_bt_coex_state(struct device *dev,
3970 struct device_attribute *attr,
3973 struct wl1271 *wl = dev_get_drvdata(dev);
3978 mutex_lock(&wl->mutex);
3979 len = snprintf(buf, len, "%d\n\n0 - off\n1 - on\n",
3981 mutex_unlock(&wl->mutex);
3987 static ssize_t wl1271_sysfs_store_bt_coex_state(struct device *dev,
3988 struct device_attribute *attr,
3989 const char *buf, size_t count)
3991 struct wl1271 *wl = dev_get_drvdata(dev);
3995 ret = kstrtoul(buf, 10, &res);
3997 wl1271_warning("incorrect value written to bt_coex_mode");
4001 mutex_lock(&wl->mutex);
4005 if (res == wl->sg_enabled)
4008 wl->sg_enabled = res;
4010 if (wl->state == WL1271_STATE_OFF)
4013 ret = wl1271_ps_elp_wakeup(wl);
4017 wl1271_acx_sg_enable(wl, wl->sg_enabled);
4018 wl1271_ps_elp_sleep(wl);
4021 mutex_unlock(&wl->mutex);
4025 static DEVICE_ATTR(bt_coex_state, S_IRUGO | S_IWUSR,
4026 wl1271_sysfs_show_bt_coex_state,
4027 wl1271_sysfs_store_bt_coex_state);
4029 static ssize_t wl1271_sysfs_show_hw_pg_ver(struct device *dev,
4030 struct device_attribute *attr,
4033 struct wl1271 *wl = dev_get_drvdata(dev);
4038 mutex_lock(&wl->mutex);
4039 if (wl->hw_pg_ver >= 0)
4040 len = snprintf(buf, len, "%d\n", wl->hw_pg_ver);
4042 len = snprintf(buf, len, "n/a\n");
4043 mutex_unlock(&wl->mutex);
4048 static DEVICE_ATTR(hw_pg_ver, S_IRUGO | S_IWUSR,
4049 wl1271_sysfs_show_hw_pg_ver, NULL);
4051 static ssize_t wl1271_sysfs_read_fwlog(struct file *filp, struct kobject *kobj,
4052 struct bin_attribute *bin_attr,
4053 char *buffer, loff_t pos, size_t count)
4055 struct device *dev = container_of(kobj, struct device, kobj);
4056 struct wl1271 *wl = dev_get_drvdata(dev);
4060 ret = mutex_lock_interruptible(&wl->mutex);
4062 return -ERESTARTSYS;
4064 /* Let only one thread read the log at a time, blocking others */
4065 while (wl->fwlog_size == 0) {
4068 prepare_to_wait_exclusive(&wl->fwlog_waitq,
4070 TASK_INTERRUPTIBLE);
4072 if (wl->fwlog_size != 0) {
4073 finish_wait(&wl->fwlog_waitq, &wait);
4077 mutex_unlock(&wl->mutex);
4080 finish_wait(&wl->fwlog_waitq, &wait);
4082 if (signal_pending(current))
4083 return -ERESTARTSYS;
4085 ret = mutex_lock_interruptible(&wl->mutex);
4087 return -ERESTARTSYS;
4090 /* Check if the fwlog is still valid */
4091 if (wl->fwlog_size < 0) {
4092 mutex_unlock(&wl->mutex);
4096 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4097 len = min(count, (size_t)wl->fwlog_size);
4098 wl->fwlog_size -= len;
4099 memcpy(buffer, wl->fwlog, len);
4101 /* Make room for new messages */
4102 memmove(wl->fwlog, wl->fwlog + len, wl->fwlog_size);
4104 mutex_unlock(&wl->mutex);
4109 static struct bin_attribute fwlog_attr = {
4110 .attr = {.name = "fwlog", .mode = S_IRUSR},
4111 .read = wl1271_sysfs_read_fwlog,
4114 int wl1271_register_hw(struct wl1271 *wl)
4118 if (wl->mac80211_registered)
4121 ret = wl1271_fetch_nvs(wl);
4123 /* NOTE: The wl->nvs->nvs element must be first, in
4124 * order to simplify the casting, we assume it is at
4125 * the beginning of the wl->nvs structure.
4127 u8 *nvs_ptr = (u8 *)wl->nvs;
4129 wl->mac_addr[0] = nvs_ptr[11];
4130 wl->mac_addr[1] = nvs_ptr[10];
4131 wl->mac_addr[2] = nvs_ptr[6];
4132 wl->mac_addr[3] = nvs_ptr[5];
4133 wl->mac_addr[4] = nvs_ptr[4];
4134 wl->mac_addr[5] = nvs_ptr[3];
4137 SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr);
4139 ret = ieee80211_register_hw(wl->hw);
4141 wl1271_error("unable to register mac80211 hw: %d", ret);
4145 wl->mac80211_registered = true;
4147 wl1271_debugfs_init(wl);
4149 register_netdevice_notifier(&wl1271_dev_notifier);
4151 wl1271_notice("loaded");
4155 EXPORT_SYMBOL_GPL(wl1271_register_hw);
4157 void wl1271_unregister_hw(struct wl1271 *wl)
4159 if (wl->state == WL1271_STATE_PLT)
4160 __wl1271_plt_stop(wl);
4162 unregister_netdevice_notifier(&wl1271_dev_notifier);
4163 ieee80211_unregister_hw(wl->hw);
4164 wl->mac80211_registered = false;
4167 EXPORT_SYMBOL_GPL(wl1271_unregister_hw);
4169 int wl1271_init_ieee80211(struct wl1271 *wl)
4171 static const u32 cipher_suites[] = {
4172 WLAN_CIPHER_SUITE_WEP40,
4173 WLAN_CIPHER_SUITE_WEP104,
4174 WLAN_CIPHER_SUITE_TKIP,
4175 WLAN_CIPHER_SUITE_CCMP,
4176 WL1271_CIPHER_SUITE_GEM,
4179 /* The tx descriptor buffer and the TKIP space. */
4180 wl->hw->extra_tx_headroom = WL1271_TKIP_IV_SPACE +
4181 sizeof(struct wl1271_tx_hw_descr);
4184 /* FIXME: find a proper value */
4185 wl->hw->channel_change_time = 10000;
4186 wl->hw->max_listen_interval = wl->conf.conn.max_listen_interval;
4188 wl->hw->flags = IEEE80211_HW_SIGNAL_DBM |
4189 IEEE80211_HW_BEACON_FILTER |
4190 IEEE80211_HW_SUPPORTS_PS |
4191 IEEE80211_HW_SUPPORTS_UAPSD |
4192 IEEE80211_HW_HAS_RATE_CONTROL |
4193 IEEE80211_HW_CONNECTION_MONITOR |
4194 IEEE80211_HW_SUPPORTS_CQM_RSSI |
4195 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
4196 IEEE80211_HW_SPECTRUM_MGMT |
4197 IEEE80211_HW_AP_LINK_PS;
4199 wl->hw->wiphy->cipher_suites = cipher_suites;
4200 wl->hw->wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
4202 wl->hw->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
4203 BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_AP);
4204 wl->hw->wiphy->max_scan_ssids = 1;
4206 * Maximum length of elements in scanning probe request templates
4207 * should be the maximum length possible for a template, without
4208 * the IEEE80211 header of the template
4210 wl->hw->wiphy->max_scan_ie_len = WL1271_CMD_TEMPL_MAX_SIZE -
4211 sizeof(struct ieee80211_header);
4213 /* make sure all our channels fit in the scanned_ch bitmask */
4214 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels) +
4215 ARRAY_SIZE(wl1271_channels_5ghz) >
4216 WL1271_MAX_CHANNELS);
4218 * We keep local copies of the band structs because we need to
4219 * modify them on a per-device basis.
4221 memcpy(&wl->bands[IEEE80211_BAND_2GHZ], &wl1271_band_2ghz,
4222 sizeof(wl1271_band_2ghz));
4223 memcpy(&wl->bands[IEEE80211_BAND_5GHZ], &wl1271_band_5ghz,
4224 sizeof(wl1271_band_5ghz));
4226 wl->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4227 &wl->bands[IEEE80211_BAND_2GHZ];
4228 wl->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4229 &wl->bands[IEEE80211_BAND_5GHZ];
4232 wl->hw->max_rates = 1;
4234 wl->hw->wiphy->reg_notifier = wl1271_reg_notify;
4236 SET_IEEE80211_DEV(wl->hw, wl1271_wl_to_dev(wl));
4238 wl->hw->sta_data_size = sizeof(struct wl1271_station);
4240 wl->hw->max_rx_aggregation_subframes = 8;
4244 EXPORT_SYMBOL_GPL(wl1271_init_ieee80211);
4246 #define WL1271_DEFAULT_CHANNEL 0
4248 struct ieee80211_hw *wl1271_alloc_hw(void)
4250 struct ieee80211_hw *hw;
4251 struct platform_device *plat_dev = NULL;
4256 hw = ieee80211_alloc_hw(sizeof(*wl), &wl1271_ops);
4258 wl1271_error("could not alloc ieee80211_hw");
4263 plat_dev = kmemdup(&wl1271_device, sizeof(wl1271_device), GFP_KERNEL);
4265 wl1271_error("could not allocate platform_device");
4267 goto err_plat_alloc;
4271 memset(wl, 0, sizeof(*wl));
4273 INIT_LIST_HEAD(&wl->list);
4276 wl->plat_dev = plat_dev;
4278 for (i = 0; i < NUM_TX_QUEUES; i++)
4279 skb_queue_head_init(&wl->tx_queue[i]);
4281 for (i = 0; i < NUM_TX_QUEUES; i++)
4282 for (j = 0; j < AP_MAX_LINKS; j++)
4283 skb_queue_head_init(&wl->links[j].tx_queue[i]);
4285 skb_queue_head_init(&wl->deferred_rx_queue);
4286 skb_queue_head_init(&wl->deferred_tx_queue);
4288 INIT_DELAYED_WORK(&wl->elp_work, wl1271_elp_work);
4289 INIT_DELAYED_WORK(&wl->pspoll_work, wl1271_pspoll_work);
4290 INIT_WORK(&wl->netstack_work, wl1271_netstack_work);
4291 INIT_WORK(&wl->tx_work, wl1271_tx_work);
4292 INIT_WORK(&wl->recovery_work, wl1271_recovery_work);
4293 INIT_DELAYED_WORK(&wl->scan_complete_work, wl1271_scan_complete_work);
4294 INIT_WORK(&wl->rx_streaming_enable_work,
4295 wl1271_rx_streaming_enable_work);
4296 INIT_WORK(&wl->rx_streaming_disable_work,
4297 wl1271_rx_streaming_disable_work);
4299 wl->freezable_wq = create_freezable_workqueue("wl12xx_wq");
4300 if (!wl->freezable_wq) {
4305 wl->channel = WL1271_DEFAULT_CHANNEL;
4306 wl->beacon_int = WL1271_DEFAULT_BEACON_INT;
4307 wl->default_key = 0;
4309 wl->rx_config = WL1271_DEFAULT_STA_RX_CONFIG;
4310 wl->rx_filter = WL1271_DEFAULT_STA_RX_FILTER;
4311 wl->psm_entry_retry = 0;
4312 wl->power_level = WL1271_DEFAULT_POWER_LEVEL;
4313 wl->basic_rate_set = CONF_TX_RATE_MASK_BASIC;
4314 wl->basic_rate = CONF_TX_RATE_MASK_BASIC;
4315 wl->rate_set = CONF_TX_RATE_MASK_BASIC;
4316 wl->band = IEEE80211_BAND_2GHZ;
4319 wl->sg_enabled = true;
4321 wl->bss_type = MAX_BSS_TYPE;
4322 wl->set_bss_type = MAX_BSS_TYPE;
4323 wl->fw_bss_type = MAX_BSS_TYPE;
4324 wl->last_tx_hlid = 0;
4326 wl->ap_fw_ps_map = 0;
4328 wl->platform_quirks = 0;
4329 wl->sched_scanning = false;
4330 setup_timer(&wl->rx_streaming_timer, wl1271_rx_streaming_timer,
4331 (unsigned long) wl);
4333 init_waitqueue_head(&wl->fwlog_waitq);
4335 memset(wl->tx_frames_map, 0, sizeof(wl->tx_frames_map));
4336 for (i = 0; i < ACX_TX_DESCRIPTORS; i++)
4337 wl->tx_frames[i] = NULL;
4339 spin_lock_init(&wl->wl_lock);
4341 wl->state = WL1271_STATE_OFF;
4342 mutex_init(&wl->mutex);
4344 /* Apply default driver configuration. */
4345 wl1271_conf_init(wl);
4347 order = get_order(WL1271_AGGR_BUFFER_SIZE);
4348 wl->aggr_buf = (u8 *)__get_free_pages(GFP_KERNEL, order);
4349 if (!wl->aggr_buf) {
4354 wl->dummy_packet = wl12xx_alloc_dummy_packet(wl);
4355 if (!wl->dummy_packet) {
4360 /* Allocate one page for the FW log */
4361 wl->fwlog = (u8 *)get_zeroed_page(GFP_KERNEL);
4364 goto err_dummy_packet;
4367 /* Register platform device */
4368 ret = platform_device_register(wl->plat_dev);
4370 wl1271_error("couldn't register platform device");
4373 dev_set_drvdata(&wl->plat_dev->dev, wl);
4375 /* Create sysfs file to control bt coex state */
4376 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4378 wl1271_error("failed to create sysfs file bt_coex_state");
4382 /* Create sysfs file to get HW PG version */
4383 ret = device_create_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4385 wl1271_error("failed to create sysfs file hw_pg_ver");
4386 goto err_bt_coex_state;
4389 /* Create sysfs file for the FW log */
4390 ret = device_create_bin_file(&wl->plat_dev->dev, &fwlog_attr);
4392 wl1271_error("failed to create sysfs file fwlog");
4399 device_remove_file(&wl->plat_dev->dev, &dev_attr_hw_pg_ver);
4402 device_remove_file(&wl->plat_dev->dev, &dev_attr_bt_coex_state);
4405 platform_device_unregister(wl->plat_dev);
4408 free_page((unsigned long)wl->fwlog);
4411 dev_kfree_skb(wl->dummy_packet);
4414 free_pages((unsigned long)wl->aggr_buf, order);
4417 destroy_workqueue(wl->freezable_wq);
4420 wl1271_debugfs_exit(wl);
4424 ieee80211_free_hw(hw);
4428 return ERR_PTR(ret);
4430 EXPORT_SYMBOL_GPL(wl1271_alloc_hw);
4432 int wl1271_free_hw(struct wl1271 *wl)
4434 /* Unblock any fwlog readers */
4435 mutex_lock(&wl->mutex);
4436 wl->fwlog_size = -1;
4437 wake_up_interruptible_all(&wl->fwlog_waitq);
4438 mutex_unlock(&wl->mutex);
4440 device_remove_bin_file(&wl->plat_dev->dev, &fwlog_attr);
4441 platform_device_unregister(wl->plat_dev);
4442 free_page((unsigned long)wl->fwlog);
4443 dev_kfree_skb(wl->dummy_packet);
4444 free_pages((unsigned long)wl->aggr_buf,
4445 get_order(WL1271_AGGR_BUFFER_SIZE));
4446 kfree(wl->plat_dev);
4448 wl1271_debugfs_exit(wl);
4455 kfree(wl->fw_status);
4456 kfree(wl->tx_res_if);
4457 destroy_workqueue(wl->freezable_wq);
4459 ieee80211_free_hw(wl->hw);
4463 EXPORT_SYMBOL_GPL(wl1271_free_hw);
4465 u32 wl12xx_debug_level = DEBUG_NONE;
4466 EXPORT_SYMBOL_GPL(wl12xx_debug_level);
4467 module_param_named(debug_level, wl12xx_debug_level, uint, S_IRUSR | S_IWUSR);
4468 MODULE_PARM_DESC(debug_level, "wl12xx debugging level");
4470 module_param_named(fwlog, fwlog_param, charp, 0);
4471 MODULE_PARM_DESC(keymap,
4472 "FW logger options: continuous, ondemand, dbgpins or disable");
4474 MODULE_LICENSE("GPL");
4475 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
4476 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");