3 * This file is part of wl1271
5 * Copyright (C) 2008-2010 Nokia Corporation
7 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * version 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <linux/module.h>
26 #include <linux/firmware.h>
27 #include <linux/delay.h>
28 #include <linux/spi/spi.h>
29 #include <linux/crc32.h>
30 #include <linux/etherdevice.h>
31 #include <linux/vmalloc.h>
32 #include <linux/platform_device.h>
33 #include <linux/slab.h>
34 #include <linux/wl12xx.h>
35 #include <linux/sched.h>
36 #include <linux/interrupt.h>
40 #include "wl12xx_80211.h"
53 #define WL1271_BOOT_RETRIES 3
55 static struct conf_drv_settings default_conf
= {
58 [CONF_SG_ACL_BT_MASTER_MIN_BR
] = 10,
59 [CONF_SG_ACL_BT_MASTER_MAX_BR
] = 180,
60 [CONF_SG_ACL_BT_SLAVE_MIN_BR
] = 10,
61 [CONF_SG_ACL_BT_SLAVE_MAX_BR
] = 180,
62 [CONF_SG_ACL_BT_MASTER_MIN_EDR
] = 10,
63 [CONF_SG_ACL_BT_MASTER_MAX_EDR
] = 80,
64 [CONF_SG_ACL_BT_SLAVE_MIN_EDR
] = 10,
65 [CONF_SG_ACL_BT_SLAVE_MAX_EDR
] = 80,
66 [CONF_SG_ACL_WLAN_PS_MASTER_BR
] = 8,
67 [CONF_SG_ACL_WLAN_PS_SLAVE_BR
] = 8,
68 [CONF_SG_ACL_WLAN_PS_MASTER_EDR
] = 20,
69 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR
] = 20,
70 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR
] = 20,
71 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR
] = 35,
72 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR
] = 16,
73 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR
] = 35,
74 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR
] = 32,
75 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR
] = 50,
76 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR
] = 28,
77 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR
] = 50,
78 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR
] = 10,
79 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR
] = 20,
80 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR
] = 75,
81 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR
] = 15,
82 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR
] = 27,
83 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR
] = 17,
84 /* active scan params */
85 [CONF_SG_AUTO_SCAN_PROBE_REQ
] = 170,
86 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3
] = 50,
87 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP
] = 100,
88 /* passive scan params */
89 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR
] = 800,
90 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR
] = 200,
91 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3
] = 200,
92 /* passive scan in dual antenna params */
93 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN
] = 0,
94 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN
] = 0,
95 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN
] = 0,
97 [CONF_SG_STA_FORCE_PS_IN_BT_SCO
] = 1,
98 [CONF_SG_ANTENNA_CONFIGURATION
] = 0,
99 [CONF_SG_BEACON_MISS_PERCENT
] = 60,
100 [CONF_SG_DHCP_TIME
] = 5000,
101 [CONF_SG_RXT
] = 1200,
102 [CONF_SG_TXT
] = 1000,
103 [CONF_SG_ADAPTIVE_RXT_TXT
] = 1,
104 [CONF_SG_GENERAL_USAGE_BIT_MAP
] = 3,
105 [CONF_SG_HV3_MAX_SERVED
] = 6,
106 [CONF_SG_PS_POLL_TIMEOUT
] = 10,
107 [CONF_SG_UPSD_TIMEOUT
] = 10,
108 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD
] = 2,
109 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM
] = 5,
110 [CONF_SG_STA_CONNECTION_PROTECTION_TIME
] = 30,
112 [CONF_AP_BEACON_MISS_TX
] = 3,
113 [CONF_AP_RX_WINDOW_AFTER_BEACON
] = 10,
114 [CONF_AP_BEACON_WINDOW_INTERVAL
] = 2,
115 [CONF_AP_CONNECTION_PROTECTION_TIME
] = 0,
116 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME
] = 25,
117 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME
] = 25,
118 /* CTS Diluting params */
119 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH
] = 0,
120 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER
] = 0,
122 .state
= CONF_SG_PROTECTIVE
,
125 .rx_msdu_life_time
= 512000,
126 .packet_detection_threshold
= 0,
127 .ps_poll_timeout
= 15,
129 .rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
,
130 .rx_cca_threshold
= 0,
131 .irq_blk_threshold
= 0xFFFF,
132 .irq_pkt_threshold
= 0,
134 .queue_type
= CONF_RX_QUEUE_TYPE_LOW_PRIORITY
,
137 .tx_energy_detection
= 0,
140 .short_retry_limit
= 10,
141 .long_retry_limit
= 10,
164 .aifsn
= CONF_TX_AIFS_PIFS
,
171 .aifsn
= CONF_TX_AIFS_PIFS
,
175 .max_tx_retries
= 100,
176 .ap_aging_period
= 300,
180 .queue_id
= CONF_TX_AC_BE
,
181 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
182 .tsid
= CONF_TX_AC_BE
,
183 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
184 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
188 .queue_id
= CONF_TX_AC_BK
,
189 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
190 .tsid
= CONF_TX_AC_BK
,
191 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
192 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
196 .queue_id
= CONF_TX_AC_VI
,
197 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
198 .tsid
= CONF_TX_AC_VI
,
199 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
200 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
204 .queue_id
= CONF_TX_AC_VO
,
205 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
206 .tsid
= CONF_TX_AC_VO
,
207 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
208 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
212 .frag_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
,
213 .tx_compl_timeout
= 700,
214 .tx_compl_threshold
= 4,
215 .basic_rate
= CONF_HW_BIT_RATE_1MBPS
,
216 .basic_rate_5
= CONF_HW_BIT_RATE_6MBPS
,
217 .tmpl_short_retry_limit
= 10,
218 .tmpl_long_retry_limit
= 10,
219 .tx_watchdog_timeout
= 5000,
222 .wake_up_event
= CONF_WAKE_UP_EVENT_DTIM
,
223 .listen_interval
= 1,
224 .suspend_wake_up_event
= CONF_WAKE_UP_EVENT_N_DTIM
,
225 .suspend_listen_interval
= 3,
226 .bcn_filt_mode
= CONF_BCN_FILT_MODE_ENABLED
,
227 .bcn_filt_ie_count
= 2,
230 .ie
= WLAN_EID_CHANNEL_SWITCH
,
231 .rule
= CONF_BCN_RULE_PASS_ON_APPEARANCE
,
234 .ie
= WLAN_EID_HT_OPERATION
,
235 .rule
= CONF_BCN_RULE_PASS_ON_CHANGE
,
238 .synch_fail_thold
= 10,
239 .bss_lose_timeout
= 100,
240 .beacon_rx_timeout
= 10000,
241 .broadcast_timeout
= 20000,
242 .rx_broadcast_in_ps
= 1,
243 .ps_poll_threshold
= 10,
244 .bet_enable
= CONF_BET_MODE_ENABLE
,
245 .bet_max_consecutive
= 50,
246 .psm_entry_retries
= 8,
247 .psm_exit_retries
= 16,
248 .psm_entry_nullfunc_retries
= 3,
249 .dynamic_ps_timeout
= 200,
251 .keep_alive_interval
= 55000,
252 .max_listen_interval
= 20,
259 .host_clk_settling_time
= 5000,
260 .host_fast_wakeup_support
= false
264 .avg_weight_rssi_beacon
= 20,
265 .avg_weight_rssi_data
= 10,
266 .avg_weight_snr_beacon
= 20,
267 .avg_weight_snr_data
= 10,
270 .min_dwell_time_active
= 7500,
271 .max_dwell_time_active
= 30000,
272 .min_dwell_time_passive
= 100000,
273 .max_dwell_time_passive
= 100000,
275 .split_scan_timeout
= 50000,
279 * Values are in TU/1000 but since sched scan FW command
280 * params are in TUs rounding up may occur.
282 .base_dwell_time
= 7500,
283 .max_dwell_time_delta
= 22500,
284 /* based on 250bits per probe @1Mbps */
285 .dwell_time_delta_per_probe
= 2000,
286 /* based on 250bits per probe @6Mbps (plus a bit more) */
287 .dwell_time_delta_per_probe_5
= 350,
288 .dwell_time_passive
= 100000,
289 .dwell_time_dfs
= 150000,
291 .rssi_threshold
= -90,
295 .tx_per_channel_power_compensation_2
= {
296 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
298 .tx_per_channel_power_compensation_5
= {
299 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
306 .tx_ba_win_size
= 64,
307 .inactivity_timeout
= 10000,
308 .tx_ba_tid_bitmap
= CONF_TX_BA_ENABLED_TID_BITMAP
,
314 .tx_min_block_num
= 40,
316 .min_req_tx_blocks
= 100,
317 .min_req_rx_blocks
= 22,
324 .tx_min_block_num
= 40,
326 .min_req_tx_blocks
= 45,
327 .min_req_rx_blocks
= 22,
333 .n_divider_fref_set_1
= 0xff, /* default */
334 .n_divider_fref_set_2
= 12,
335 .m_divider_fref_set_1
= 148,
336 .m_divider_fref_set_2
= 0xffff, /* default */
337 .coex_pll_stabilization_time
= 0xffffffff, /* default */
338 .ldo_stabilization_time
= 0xffff, /* default */
339 .fm_disturbed_band_margin
= 0xff, /* default */
340 .swallow_clk_diff
= 0xff, /* default */
349 .mode
= WL12XX_FWLOG_ON_DEMAND
,
352 .timestamp
= WL12XX_FWLOG_TIMESTAMP_DISABLED
,
353 .output
= WL12XX_FWLOG_OUTPUT_HOST
,
357 .rate_retry_score
= 32000,
362 .inverse_curiosity_factor
= 5,
364 .tx_fail_high_th
= 10,
365 .per_alpha_shift
= 4,
367 .per_beta1_shift
= 10,
368 .per_beta2_shift
= 8,
370 .rate_check_down
= 12,
371 .rate_retry_policy
= {
372 0x00, 0x00, 0x00, 0x00, 0x00,
373 0x00, 0x00, 0x00, 0x00, 0x00,
379 .hangover_period
= 20,
381 .early_termination_mode
= 1,
392 static char *fwlog_param
;
393 static bool bug_on_recovery
;
395 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
396 struct ieee80211_vif
*vif
,
397 bool reset_tx_queues
);
398 static void wl1271_op_stop(struct ieee80211_hw
*hw
);
399 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
);
401 static int wl12xx_set_authorized(struct wl1271
*wl
,
402 struct wl12xx_vif
*wlvif
)
406 if (WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
))
409 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
412 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT
, &wlvif
->flags
))
415 ret
= wl12xx_cmd_set_peer_state(wl
, wlvif
->sta
.hlid
);
419 wl12xx_croc(wl
, wlvif
->role_id
);
421 wl1271_info("Association completed.");
425 static int wl1271_reg_notify(struct wiphy
*wiphy
,
426 struct regulatory_request
*request
)
428 struct ieee80211_supported_band
*band
;
429 struct ieee80211_channel
*ch
;
432 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
433 for (i
= 0; i
< band
->n_channels
; i
++) {
434 ch
= &band
->channels
[i
];
435 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
438 if (ch
->flags
& IEEE80211_CHAN_RADAR
)
439 ch
->flags
|= IEEE80211_CHAN_NO_IBSS
|
440 IEEE80211_CHAN_PASSIVE_SCAN
;
447 static int wl1271_set_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
452 /* we should hold wl->mutex */
453 ret
= wl1271_acx_ps_rx_streaming(wl
, wlvif
, enable
);
458 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
460 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
466 * this function is being called when the rx_streaming interval
467 * has beed changed or rx_streaming should be disabled
469 int wl1271_recalc_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
472 int period
= wl
->conf
.rx_streaming
.interval
;
474 /* don't reconfigure if rx_streaming is disabled */
475 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
478 /* reconfigure/disable according to new streaming_period */
480 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
481 (wl
->conf
.rx_streaming
.always
||
482 test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
483 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
485 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
486 /* don't cancel_work_sync since we might deadlock */
487 del_timer_sync(&wlvif
->rx_streaming_timer
);
493 static void wl1271_rx_streaming_enable_work(struct work_struct
*work
)
496 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
497 rx_streaming_enable_work
);
498 struct wl1271
*wl
= wlvif
->wl
;
500 mutex_lock(&wl
->mutex
);
502 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
) ||
503 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
504 (!wl
->conf
.rx_streaming
.always
&&
505 !test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
508 if (!wl
->conf
.rx_streaming
.interval
)
511 ret
= wl1271_ps_elp_wakeup(wl
);
515 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
519 /* stop it after some time of inactivity */
520 mod_timer(&wlvif
->rx_streaming_timer
,
521 jiffies
+ msecs_to_jiffies(wl
->conf
.rx_streaming
.duration
));
524 wl1271_ps_elp_sleep(wl
);
526 mutex_unlock(&wl
->mutex
);
529 static void wl1271_rx_streaming_disable_work(struct work_struct
*work
)
532 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
533 rx_streaming_disable_work
);
534 struct wl1271
*wl
= wlvif
->wl
;
536 mutex_lock(&wl
->mutex
);
538 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
541 ret
= wl1271_ps_elp_wakeup(wl
);
545 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
550 wl1271_ps_elp_sleep(wl
);
552 mutex_unlock(&wl
->mutex
);
555 static void wl1271_rx_streaming_timer(unsigned long data
)
557 struct wl12xx_vif
*wlvif
= (struct wl12xx_vif
*)data
;
558 struct wl1271
*wl
= wlvif
->wl
;
559 ieee80211_queue_work(wl
->hw
, &wlvif
->rx_streaming_disable_work
);
562 /* wl->mutex must be taken */
563 void wl12xx_rearm_tx_watchdog_locked(struct wl1271
*wl
)
565 /* if the watchdog is not armed, don't do anything */
566 if (wl
->tx_allocated_blocks
== 0)
569 cancel_delayed_work(&wl
->tx_watchdog_work
);
570 ieee80211_queue_delayed_work(wl
->hw
, &wl
->tx_watchdog_work
,
571 msecs_to_jiffies(wl
->conf
.tx
.tx_watchdog_timeout
));
574 static void wl12xx_tx_watchdog_work(struct work_struct
*work
)
576 struct delayed_work
*dwork
;
579 dwork
= container_of(work
, struct delayed_work
, work
);
580 wl
= container_of(dwork
, struct wl1271
, tx_watchdog_work
);
582 mutex_lock(&wl
->mutex
);
584 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
587 /* Tx went out in the meantime - everything is ok */
588 if (unlikely(wl
->tx_allocated_blocks
== 0))
592 * if a ROC is in progress, we might not have any Tx for a long
593 * time (e.g. pending Tx on the non-ROC channels)
595 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
596 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to ROC",
597 wl
->conf
.tx
.tx_watchdog_timeout
);
598 wl12xx_rearm_tx_watchdog_locked(wl
);
603 * if a scan is in progress, we might not have any Tx for a long
606 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
) {
607 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to scan",
608 wl
->conf
.tx
.tx_watchdog_timeout
);
609 wl12xx_rearm_tx_watchdog_locked(wl
);
614 * AP might cache a frame for a long time for a sleeping station,
615 * so rearm the timer if there's an AP interface with stations. If
616 * Tx is genuinely stuck we will most hopefully discover it when all
617 * stations are removed due to inactivity.
619 if (wl
->active_sta_count
) {
620 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms. AP has "
622 wl
->conf
.tx
.tx_watchdog_timeout
,
623 wl
->active_sta_count
);
624 wl12xx_rearm_tx_watchdog_locked(wl
);
628 wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
629 wl
->conf
.tx
.tx_watchdog_timeout
);
630 wl12xx_queue_recovery_work(wl
);
633 mutex_unlock(&wl
->mutex
);
636 static void wl1271_conf_init(struct wl1271
*wl
)
640 * This function applies the default configuration to the driver. This
641 * function is invoked upon driver load (spi probe.)
643 * The configuration is stored in a run-time structure in order to
644 * facilitate for run-time adjustment of any of the parameters. Making
645 * changes to the configuration structure will apply the new values on
646 * the next interface up (wl1271_op_start.)
649 /* apply driver default configuration */
650 memcpy(&wl
->conf
, &default_conf
, sizeof(default_conf
));
652 /* Adjust settings according to optional module parameters */
654 if (!strcmp(fwlog_param
, "continuous")) {
655 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
656 } else if (!strcmp(fwlog_param
, "ondemand")) {
657 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_ON_DEMAND
;
658 } else if (!strcmp(fwlog_param
, "dbgpins")) {
659 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
660 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_DBG_PINS
;
661 } else if (!strcmp(fwlog_param
, "disable")) {
662 wl
->conf
.fwlog
.mem_blocks
= 0;
663 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_NONE
;
665 wl1271_error("Unknown fwlog parameter %s", fwlog_param
);
670 static int wl1271_plt_init(struct wl1271
*wl
)
674 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
675 ret
= wl128x_cmd_general_parms(wl
);
677 ret
= wl1271_cmd_general_parms(wl
);
681 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
682 ret
= wl128x_cmd_radio_parms(wl
);
684 ret
= wl1271_cmd_radio_parms(wl
);
688 if (wl
->chip
.id
!= CHIP_ID_1283_PG20
) {
689 ret
= wl1271_cmd_ext_radio_parms(wl
);
694 /* Chip-specific initializations */
695 ret
= wl1271_chip_specific_init(wl
);
699 ret
= wl1271_acx_init_mem_config(wl
);
703 ret
= wl12xx_acx_mem_cfg(wl
);
705 goto out_free_memmap
;
707 /* Enable data path */
708 ret
= wl1271_cmd_data_path(wl
, 1);
710 goto out_free_memmap
;
712 /* Configure for CAM power saving (ie. always active) */
713 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
715 goto out_free_memmap
;
718 ret
= wl1271_acx_pm_config(wl
);
720 goto out_free_memmap
;
725 kfree(wl
->target_mem_map
);
726 wl
->target_mem_map
= NULL
;
731 static void wl12xx_irq_ps_regulate_link(struct wl1271
*wl
,
732 struct wl12xx_vif
*wlvif
,
735 bool fw_ps
, single_sta
;
737 fw_ps
= test_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
738 single_sta
= (wl
->active_sta_count
== 1);
741 * Wake up from high level PS if the STA is asleep with too little
742 * packets in FW or if the STA is awake.
744 if (!fw_ps
|| tx_pkts
< WL1271_PS_STA_MAX_PACKETS
)
745 wl12xx_ps_link_end(wl
, wlvif
, hlid
);
748 * Start high-level PS if the STA is asleep with enough blocks in FW.
749 * Make an exception if this is the only connected station. In this
750 * case FW-memory congestion is not a problem.
752 else if (!single_sta
&& fw_ps
&& tx_pkts
>= WL1271_PS_STA_MAX_PACKETS
)
753 wl12xx_ps_link_start(wl
, wlvif
, hlid
, true);
756 static void wl12xx_irq_update_links_status(struct wl1271
*wl
,
757 struct wl12xx_vif
*wlvif
,
758 struct wl12xx_fw_status
*status
)
760 struct wl1271_link
*lnk
;
764 /* TODO: also use link_fast_bitmap here */
766 cur_fw_ps_map
= le32_to_cpu(status
->link_ps_bitmap
);
767 if (wl
->ap_fw_ps_map
!= cur_fw_ps_map
) {
768 wl1271_debug(DEBUG_PSM
,
769 "link ps prev 0x%x cur 0x%x changed 0x%x",
770 wl
->ap_fw_ps_map
, cur_fw_ps_map
,
771 wl
->ap_fw_ps_map
^ cur_fw_ps_map
);
773 wl
->ap_fw_ps_map
= cur_fw_ps_map
;
776 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
, WL12XX_MAX_LINKS
) {
777 lnk
= &wl
->links
[hlid
];
778 cnt
= status
->tx_lnk_free_pkts
[hlid
] - lnk
->prev_freed_pkts
;
780 lnk
->prev_freed_pkts
= status
->tx_lnk_free_pkts
[hlid
];
781 lnk
->allocated_pkts
-= cnt
;
783 wl12xx_irq_ps_regulate_link(wl
, wlvif
, hlid
,
784 lnk
->allocated_pkts
);
788 static void wl12xx_fw_status(struct wl1271
*wl
,
789 struct wl12xx_fw_status
*status
)
791 struct wl12xx_vif
*wlvif
;
793 u32 old_tx_blk_count
= wl
->tx_blocks_available
;
794 int avail
, freed_blocks
;
797 wlcore_raw_read_data(wl
, REG_RAW_FW_STATUS_ADDR
, status
,
798 sizeof(*status
), false);
800 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
801 "drv_rx_counter = %d, tx_results_counter = %d)",
803 status
->fw_rx_counter
,
804 status
->drv_rx_counter
,
805 status
->tx_results_counter
);
807 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
808 /* prevent wrap-around in freed-packets counter */
809 wl
->tx_allocated_pkts
[i
] -=
810 (status
->tx_released_pkts
[i
] -
811 wl
->tx_pkts_freed
[i
]) & 0xff;
813 wl
->tx_pkts_freed
[i
] = status
->tx_released_pkts
[i
];
816 /* prevent wrap-around in total blocks counter */
817 if (likely(wl
->tx_blocks_freed
<=
818 le32_to_cpu(status
->total_released_blks
)))
819 freed_blocks
= le32_to_cpu(status
->total_released_blks
) -
822 freed_blocks
= 0x100000000LL
- wl
->tx_blocks_freed
+
823 le32_to_cpu(status
->total_released_blks
);
825 wl
->tx_blocks_freed
= le32_to_cpu(status
->total_released_blks
);
827 wl
->tx_allocated_blocks
-= freed_blocks
;
830 * If the FW freed some blocks:
831 * If we still have allocated blocks - re-arm the timer, Tx is
832 * not stuck. Otherwise, cancel the timer (no Tx currently).
835 if (wl
->tx_allocated_blocks
)
836 wl12xx_rearm_tx_watchdog_locked(wl
);
838 cancel_delayed_work(&wl
->tx_watchdog_work
);
841 avail
= le32_to_cpu(status
->tx_total
) - wl
->tx_allocated_blocks
;
844 * The FW might change the total number of TX memblocks before
845 * we get a notification about blocks being released. Thus, the
846 * available blocks calculation might yield a temporary result
847 * which is lower than the actual available blocks. Keeping in
848 * mind that only blocks that were allocated can be moved from
849 * TX to RX, tx_blocks_available should never decrease here.
851 wl
->tx_blocks_available
= max((int)wl
->tx_blocks_available
,
854 /* if more blocks are available now, tx work can be scheduled */
855 if (wl
->tx_blocks_available
> old_tx_blk_count
)
856 clear_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
);
858 /* for AP update num of allocated TX blocks per link and ps status */
859 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
860 wl12xx_irq_update_links_status(wl
, wlvif
, status
);
863 /* update the host-chipset time offset */
865 wl
->time_offset
= (timespec_to_ns(&ts
) >> 10) -
866 (s64
)le32_to_cpu(status
->fw_localtime
);
869 static void wl1271_flush_deferred_work(struct wl1271
*wl
)
873 /* Pass all received frames to the network stack */
874 while ((skb
= skb_dequeue(&wl
->deferred_rx_queue
)))
875 ieee80211_rx_ni(wl
->hw
, skb
);
877 /* Return sent skbs to the network stack */
878 while ((skb
= skb_dequeue(&wl
->deferred_tx_queue
)))
879 ieee80211_tx_status_ni(wl
->hw
, skb
);
882 static void wl1271_netstack_work(struct work_struct
*work
)
885 container_of(work
, struct wl1271
, netstack_work
);
888 wl1271_flush_deferred_work(wl
);
889 } while (skb_queue_len(&wl
->deferred_rx_queue
));
892 #define WL1271_IRQ_MAX_LOOPS 256
894 static irqreturn_t
wl1271_irq(int irq
, void *cookie
)
898 int loopcount
= WL1271_IRQ_MAX_LOOPS
;
899 struct wl1271
*wl
= (struct wl1271
*)cookie
;
901 unsigned int defer_count
;
904 /* TX might be handled here, avoid redundant work */
905 set_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
906 cancel_work_sync(&wl
->tx_work
);
909 * In case edge triggered interrupt must be used, we cannot iterate
910 * more than once without introducing race conditions with the hardirq.
912 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
915 mutex_lock(&wl
->mutex
);
917 wl1271_debug(DEBUG_IRQ
, "IRQ work");
919 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
922 ret
= wl1271_ps_elp_wakeup(wl
);
926 while (!done
&& loopcount
--) {
928 * In order to avoid a race with the hardirq, clear the flag
929 * before acknowledging the chip. Since the mutex is held,
930 * wl1271_ps_elp_wakeup cannot be called concurrently.
932 clear_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
933 smp_mb__after_clear_bit();
935 wl12xx_fw_status(wl
, wl
->fw_status
);
936 intr
= le32_to_cpu(wl
->fw_status
->intr
);
937 intr
&= WL1271_INTR_MASK
;
943 if (unlikely(intr
& WL1271_ACX_INTR_WATCHDOG
)) {
944 wl1271_error("watchdog interrupt received! "
945 "starting recovery.");
946 wl12xx_queue_recovery_work(wl
);
948 /* restarting the chip. ignore any other interrupt. */
952 if (likely(intr
& WL1271_ACX_INTR_DATA
)) {
953 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
955 wl12xx_rx(wl
, wl
->fw_status
);
957 /* Check if any tx blocks were freed */
958 spin_lock_irqsave(&wl
->wl_lock
, flags
);
959 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
960 wl1271_tx_total_queue_count(wl
) > 0) {
961 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
963 * In order to avoid starvation of the TX path,
964 * call the work function directly.
966 wl1271_tx_work_locked(wl
);
968 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
971 /* check for tx results */
972 if (wl
->fw_status
->tx_results_counter
!=
973 (wl
->tx_results_count
& 0xff))
974 wl1271_tx_complete(wl
);
976 /* Make sure the deferred queues don't get too long */
977 defer_count
= skb_queue_len(&wl
->deferred_tx_queue
) +
978 skb_queue_len(&wl
->deferred_rx_queue
);
979 if (defer_count
> WL1271_DEFERRED_QUEUE_LIMIT
)
980 wl1271_flush_deferred_work(wl
);
983 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
984 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
985 wl1271_event_handle(wl
, 0);
988 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
989 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
990 wl1271_event_handle(wl
, 1);
993 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
994 wl1271_debug(DEBUG_IRQ
,
995 "WL1271_ACX_INTR_INIT_COMPLETE");
997 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
998 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
1001 wl1271_ps_elp_sleep(wl
);
1004 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1005 /* In case TX was not handled here, queue TX work */
1006 clear_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
1007 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1008 wl1271_tx_total_queue_count(wl
) > 0)
1009 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1010 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1012 mutex_unlock(&wl
->mutex
);
1017 struct vif_counter_data
{
1020 struct ieee80211_vif
*cur_vif
;
1021 bool cur_vif_running
;
1024 static void wl12xx_vif_count_iter(void *data
, u8
*mac
,
1025 struct ieee80211_vif
*vif
)
1027 struct vif_counter_data
*counter
= data
;
1030 if (counter
->cur_vif
== vif
)
1031 counter
->cur_vif_running
= true;
1034 /* caller must not hold wl->mutex, as it might deadlock */
1035 static void wl12xx_get_vif_count(struct ieee80211_hw
*hw
,
1036 struct ieee80211_vif
*cur_vif
,
1037 struct vif_counter_data
*data
)
1039 memset(data
, 0, sizeof(*data
));
1040 data
->cur_vif
= cur_vif
;
1042 ieee80211_iterate_active_interfaces(hw
,
1043 wl12xx_vif_count_iter
, data
);
1046 static int wl12xx_fetch_firmware(struct wl1271
*wl
, bool plt
)
1048 const struct firmware
*fw
;
1049 const char *fw_name
;
1050 enum wl12xx_fw_type fw_type
;
1054 fw_type
= WL12XX_FW_TYPE_PLT
;
1055 fw_name
= wl
->plt_fw_name
;
1058 * we can't call wl12xx_get_vif_count() here because
1059 * wl->mutex is taken, so use the cached last_vif_count value
1061 if (wl
->last_vif_count
> 1) {
1062 fw_type
= WL12XX_FW_TYPE_MULTI
;
1063 fw_name
= wl
->mr_fw_name
;
1065 fw_type
= WL12XX_FW_TYPE_NORMAL
;
1066 fw_name
= wl
->sr_fw_name
;
1070 if (wl
->fw_type
== fw_type
)
1073 wl1271_debug(DEBUG_BOOT
, "booting firmware %s", fw_name
);
1075 ret
= request_firmware(&fw
, fw_name
, wl
->dev
);
1078 wl1271_error("could not get firmware %s: %d", fw_name
, ret
);
1083 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1090 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
1091 wl
->fw_len
= fw
->size
;
1092 wl
->fw
= vmalloc(wl
->fw_len
);
1095 wl1271_error("could not allocate memory for the firmware");
1100 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
1102 wl
->fw_type
= fw_type
;
1104 release_firmware(fw
);
1109 static int wl1271_fetch_nvs(struct wl1271
*wl
)
1111 const struct firmware
*fw
;
1114 ret
= request_firmware(&fw
, WL12XX_NVS_NAME
, wl
->dev
);
1117 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME
,
1122 wl
->nvs
= kmemdup(fw
->data
, fw
->size
, GFP_KERNEL
);
1125 wl1271_error("could not allocate memory for the nvs file");
1130 wl
->nvs_len
= fw
->size
;
1133 release_firmware(fw
);
1138 void wl12xx_queue_recovery_work(struct wl1271
*wl
)
1140 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
1141 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
1144 size_t wl12xx_copy_fwlog(struct wl1271
*wl
, u8
*memblock
, size_t maxlen
)
1148 /* The FW log is a length-value list, find where the log end */
1149 while (len
< maxlen
) {
1150 if (memblock
[len
] == 0)
1152 if (len
+ memblock
[len
] + 1 > maxlen
)
1154 len
+= memblock
[len
] + 1;
1157 /* Make sure we have enough room */
1158 len
= min(len
, (size_t)(PAGE_SIZE
- wl
->fwlog_size
));
1160 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1161 memcpy(wl
->fwlog
+ wl
->fwlog_size
, memblock
, len
);
1162 wl
->fwlog_size
+= len
;
1167 static void wl12xx_read_fwlog_panic(struct wl1271
*wl
)
1173 if ((wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
) ||
1174 (wl
->conf
.fwlog
.mode
!= WL12XX_FWLOG_ON_DEMAND
) ||
1175 (wl
->conf
.fwlog
.mem_blocks
== 0))
1178 wl1271_info("Reading FW panic log");
1180 block
= kmalloc(WL12XX_HW_BLOCK_SIZE
, GFP_KERNEL
);
1185 * Make sure the chip is awake and the logger isn't active.
1186 * This might fail if the firmware hanged.
1188 if (!wl1271_ps_elp_wakeup(wl
))
1189 wl12xx_cmd_stop_fwlog(wl
);
1191 /* Read the first memory block address */
1192 wl12xx_fw_status(wl
, wl
->fw_status
);
1193 first_addr
= le32_to_cpu(wl
->fw_status
->log_start_addr
);
1197 /* Traverse the memory blocks linked list */
1200 memset(block
, 0, WL12XX_HW_BLOCK_SIZE
);
1201 wl1271_read_hwaddr(wl
, addr
, block
, WL12XX_HW_BLOCK_SIZE
,
1205 * Memory blocks are linked to one another. The first 4 bytes
1206 * of each memory block hold the hardware address of the next
1207 * one. The last memory block points to the first one.
1209 addr
= le32_to_cpup((__le32
*)block
);
1210 if (!wl12xx_copy_fwlog(wl
, block
+ sizeof(addr
),
1211 WL12XX_HW_BLOCK_SIZE
- sizeof(addr
)))
1213 } while (addr
&& (addr
!= first_addr
));
1215 wake_up_interruptible(&wl
->fwlog_waitq
);
1221 static void wl1271_recovery_work(struct work_struct
*work
)
1224 container_of(work
, struct wl1271
, recovery_work
);
1225 struct wl12xx_vif
*wlvif
;
1226 struct ieee80211_vif
*vif
;
1228 mutex_lock(&wl
->mutex
);
1230 if (wl
->state
!= WL1271_STATE_ON
|| wl
->plt
)
1233 /* Avoid a recursive recovery */
1234 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
1236 wl12xx_read_fwlog_panic(wl
);
1238 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1239 wl
->chip
.fw_ver_str
,
1240 wlcore_read_reg(wl
, REG_PC_ON_RECOVERY
));
1242 BUG_ON(bug_on_recovery
&&
1243 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
));
1246 * Advance security sequence number to overcome potential progress
1247 * in the firmware during recovery. This doens't hurt if the network is
1250 wl12xx_for_each_wlvif(wl
, wlvif
) {
1251 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
1252 test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1253 wlvif
->tx_security_seq
+=
1254 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
1257 /* Prevent spurious TX during FW restart */
1258 ieee80211_stop_queues(wl
->hw
);
1260 if (wl
->sched_scanning
) {
1261 ieee80211_sched_scan_stopped(wl
->hw
);
1262 wl
->sched_scanning
= false;
1265 /* reboot the chipset */
1266 while (!list_empty(&wl
->wlvif_list
)) {
1267 wlvif
= list_first_entry(&wl
->wlvif_list
,
1268 struct wl12xx_vif
, list
);
1269 vif
= wl12xx_wlvif_to_vif(wlvif
);
1270 __wl1271_op_remove_interface(wl
, vif
, false);
1272 mutex_unlock(&wl
->mutex
);
1273 wl1271_op_stop(wl
->hw
);
1275 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
1277 ieee80211_restart_hw(wl
->hw
);
1280 * Its safe to enable TX now - the queues are stopped after a request
1281 * to restart the HW.
1283 ieee80211_wake_queues(wl
->hw
);
1286 mutex_unlock(&wl
->mutex
);
1289 static void wl1271_fw_wakeup(struct wl1271
*wl
)
1291 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG
, ELPCTRL_WAKE_UP
);
1294 static int wl1271_setup(struct wl1271
*wl
)
1296 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
1300 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
1301 if (!wl
->tx_res_if
) {
1302 kfree(wl
->fw_status
);
1309 static int wl12xx_set_power_on(struct wl1271
*wl
)
1313 msleep(WL1271_PRE_POWER_ON_SLEEP
);
1314 ret
= wl1271_power_on(wl
);
1317 msleep(WL1271_POWER_ON_SLEEP
);
1318 wl1271_io_reset(wl
);
1321 wlcore_set_partition(wl
, &wl
->ptable
[PART_BOOT
]);
1323 /* ELP module wake up */
1324 wl1271_fw_wakeup(wl
);
1330 static int wl12xx_chip_wakeup(struct wl1271
*wl
, bool plt
)
1334 ret
= wl12xx_set_power_on(wl
);
1339 * For wl127x based devices we could use the default block
1340 * size (512 bytes), but due to a bug in the sdio driver, we
1341 * need to set it explicitly after the chip is powered on. To
1342 * simplify the code and since the performance impact is
1343 * negligible, we use the same block size for all different
1346 if (!wl1271_set_block_size(wl
))
1347 wl
->quirks
|= WLCORE_QUIRK_NO_BLOCKSIZE_ALIGNMENT
;
1349 ret
= wl
->ops
->identify_chip(wl
);
1353 /* TODO: make sure the lower driver has set things up correctly */
1355 ret
= wl1271_setup(wl
);
1359 ret
= wl12xx_fetch_firmware(wl
, plt
);
1363 /* No NVS from netlink, try to get it from the filesystem */
1364 if (wl
->nvs
== NULL
) {
1365 ret
= wl1271_fetch_nvs(wl
);
1374 int wl1271_plt_start(struct wl1271
*wl
)
1376 int retries
= WL1271_BOOT_RETRIES
;
1377 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1380 mutex_lock(&wl
->mutex
);
1382 wl1271_notice("power up");
1384 if (wl
->state
!= WL1271_STATE_OFF
) {
1385 wl1271_error("cannot go into PLT state because not "
1386 "in off state: %d", wl
->state
);
1393 ret
= wl12xx_chip_wakeup(wl
, true);
1397 ret
= wl
->ops
->boot(wl
);
1401 ret
= wl1271_plt_init(wl
);
1406 wl
->state
= WL1271_STATE_ON
;
1407 wl1271_notice("firmware booted in PLT mode (%s)",
1408 wl
->chip
.fw_ver_str
);
1410 /* update hw/fw version info in wiphy struct */
1411 wiphy
->hw_version
= wl
->chip
.id
;
1412 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
1413 sizeof(wiphy
->fw_version
));
1418 mutex_unlock(&wl
->mutex
);
1419 /* Unlocking the mutex in the middle of handling is
1420 inherently unsafe. In this case we deem it safe to do,
1421 because we need to let any possibly pending IRQ out of
1422 the system (and while we are WL1271_STATE_OFF the IRQ
1423 work function will not do anything.) Also, any other
1424 possible concurrent operations will fail due to the
1425 current state, hence the wl1271 struct should be safe. */
1426 wlcore_disable_interrupts(wl
);
1427 wl1271_flush_deferred_work(wl
);
1428 cancel_work_sync(&wl
->netstack_work
);
1429 mutex_lock(&wl
->mutex
);
1431 wl1271_power_off(wl
);
1434 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1435 WL1271_BOOT_RETRIES
);
1437 mutex_unlock(&wl
->mutex
);
1442 int wl1271_plt_stop(struct wl1271
*wl
)
1446 wl1271_notice("power down");
1449 * Interrupts must be disabled before setting the state to OFF.
1450 * Otherwise, the interrupt handler might be called and exit without
1451 * reading the interrupt status.
1453 wlcore_disable_interrupts(wl
);
1454 mutex_lock(&wl
->mutex
);
1456 mutex_unlock(&wl
->mutex
);
1459 * This will not necessarily enable interrupts as interrupts
1460 * may have been disabled when op_stop was called. It will,
1461 * however, balance the above call to disable_interrupts().
1463 wlcore_enable_interrupts(wl
);
1465 wl1271_error("cannot power down because not in PLT "
1466 "state: %d", wl
->state
);
1471 mutex_unlock(&wl
->mutex
);
1473 wl1271_flush_deferred_work(wl
);
1474 cancel_work_sync(&wl
->netstack_work
);
1475 cancel_work_sync(&wl
->recovery_work
);
1476 cancel_delayed_work_sync(&wl
->elp_work
);
1477 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1479 mutex_lock(&wl
->mutex
);
1480 wl1271_power_off(wl
);
1482 wl
->state
= WL1271_STATE_OFF
;
1485 mutex_unlock(&wl
->mutex
);
1491 static void wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1493 struct wl1271
*wl
= hw
->priv
;
1494 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1495 struct ieee80211_vif
*vif
= info
->control
.vif
;
1496 struct wl12xx_vif
*wlvif
= NULL
;
1497 unsigned long flags
;
1502 wlvif
= wl12xx_vif_to_data(vif
);
1504 mapping
= skb_get_queue_mapping(skb
);
1505 q
= wl1271_tx_get_queue(mapping
);
1507 hlid
= wl12xx_tx_get_hlid(wl
, wlvif
, skb
);
1509 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1511 /* queue the packet */
1512 if (hlid
== WL12XX_INVALID_LINK_ID
||
1513 (wlvif
&& !test_bit(hlid
, wlvif
->links_map
))) {
1514 wl1271_debug(DEBUG_TX
, "DROP skb hlid %d q %d", hlid
, q
);
1515 ieee80211_free_txskb(hw
, skb
);
1519 wl1271_debug(DEBUG_TX
, "queue skb hlid %d q %d len %d",
1521 skb_queue_tail(&wl
->links
[hlid
].tx_queue
[q
], skb
);
1523 wl
->tx_queue_count
[q
]++;
1526 * The workqueue is slow to process the tx_queue and we need stop
1527 * the queue here, otherwise the queue will get too long.
1529 if (wl
->tx_queue_count
[q
] >= WL1271_TX_QUEUE_HIGH_WATERMARK
) {
1530 wl1271_debug(DEBUG_TX
, "op_tx: stopping queues for q %d", q
);
1531 ieee80211_stop_queue(wl
->hw
, mapping
);
1532 set_bit(q
, &wl
->stopped_queues_map
);
1536 * The chip specific setup must run before the first TX packet -
1537 * before that, the tx_work will not be initialized!
1540 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1541 !test_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
))
1542 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1545 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1548 int wl1271_tx_dummy_packet(struct wl1271
*wl
)
1550 unsigned long flags
;
1553 /* no need to queue a new dummy packet if one is already pending */
1554 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
))
1557 q
= wl1271_tx_get_queue(skb_get_queue_mapping(wl
->dummy_packet
));
1559 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1560 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
);
1561 wl
->tx_queue_count
[q
]++;
1562 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1564 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1565 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
))
1566 wl1271_tx_work_locked(wl
);
1569 * If the FW TX is busy, TX work will be scheduled by the threaded
1570 * interrupt handler function
1576 * The size of the dummy packet should be at least 1400 bytes. However, in
1577 * order to minimize the number of bus transactions, aligning it to 512 bytes
1578 * boundaries could be beneficial, performance wise
1580 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1582 static struct sk_buff
*wl12xx_alloc_dummy_packet(struct wl1271
*wl
)
1584 struct sk_buff
*skb
;
1585 struct ieee80211_hdr_3addr
*hdr
;
1586 unsigned int dummy_packet_size
;
1588 dummy_packet_size
= TOTAL_TX_DUMMY_PACKET_SIZE
-
1589 sizeof(struct wl1271_tx_hw_descr
) - sizeof(*hdr
);
1591 skb
= dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE
);
1593 wl1271_warning("Failed to allocate a dummy packet skb");
1597 skb_reserve(skb
, sizeof(struct wl1271_tx_hw_descr
));
1599 hdr
= (struct ieee80211_hdr_3addr
*) skb_put(skb
, sizeof(*hdr
));
1600 memset(hdr
, 0, sizeof(*hdr
));
1601 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1602 IEEE80211_STYPE_NULLFUNC
|
1603 IEEE80211_FCTL_TODS
);
1605 memset(skb_put(skb
, dummy_packet_size
), 0, dummy_packet_size
);
1607 /* Dummy packets require the TID to be management */
1608 skb
->priority
= WL1271_TID_MGMT
;
1610 /* Initialize all fields that might be used */
1611 skb_set_queue_mapping(skb
, 0);
1612 memset(IEEE80211_SKB_CB(skb
), 0, sizeof(struct ieee80211_tx_info
));
1619 static int wl1271_configure_suspend_sta(struct wl1271
*wl
,
1620 struct wl12xx_vif
*wlvif
)
1624 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1627 ret
= wl1271_ps_elp_wakeup(wl
);
1631 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1632 wl
->conf
.conn
.suspend_wake_up_event
,
1633 wl
->conf
.conn
.suspend_listen_interval
);
1636 wl1271_error("suspend: set wake up conditions failed: %d", ret
);
1638 wl1271_ps_elp_sleep(wl
);
1645 static int wl1271_configure_suspend_ap(struct wl1271
*wl
,
1646 struct wl12xx_vif
*wlvif
)
1650 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1653 ret
= wl1271_ps_elp_wakeup(wl
);
1657 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
1659 wl1271_ps_elp_sleep(wl
);
1665 static int wl1271_configure_suspend(struct wl1271
*wl
,
1666 struct wl12xx_vif
*wlvif
)
1668 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1669 return wl1271_configure_suspend_sta(wl
, wlvif
);
1670 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
1671 return wl1271_configure_suspend_ap(wl
, wlvif
);
1675 static void wl1271_configure_resume(struct wl1271
*wl
,
1676 struct wl12xx_vif
*wlvif
)
1679 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
1680 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
1682 if ((!is_ap
) && (!is_sta
))
1685 ret
= wl1271_ps_elp_wakeup(wl
);
1690 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1691 wl
->conf
.conn
.wake_up_event
,
1692 wl
->conf
.conn
.listen_interval
);
1695 wl1271_error("resume: wake up conditions failed: %d",
1699 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
1702 wl1271_ps_elp_sleep(wl
);
1705 static int wl1271_op_suspend(struct ieee80211_hw
*hw
,
1706 struct cfg80211_wowlan
*wow
)
1708 struct wl1271
*wl
= hw
->priv
;
1709 struct wl12xx_vif
*wlvif
;
1712 wl1271_debug(DEBUG_MAC80211
, "mac80211 suspend wow=%d", !!wow
);
1713 WARN_ON(!wow
|| !wow
->any
);
1715 wl1271_tx_flush(wl
);
1717 mutex_lock(&wl
->mutex
);
1718 wl
->wow_enabled
= true;
1719 wl12xx_for_each_wlvif(wl
, wlvif
) {
1720 ret
= wl1271_configure_suspend(wl
, wlvif
);
1722 wl1271_warning("couldn't prepare device to suspend");
1726 mutex_unlock(&wl
->mutex
);
1727 /* flush any remaining work */
1728 wl1271_debug(DEBUG_MAC80211
, "flushing remaining works");
1731 * disable and re-enable interrupts in order to flush
1734 wlcore_disable_interrupts(wl
);
1737 * set suspended flag to avoid triggering a new threaded_irq
1738 * work. no need for spinlock as interrupts are disabled.
1740 set_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1742 wlcore_enable_interrupts(wl
);
1743 flush_work(&wl
->tx_work
);
1744 flush_delayed_work(&wl
->elp_work
);
1749 static int wl1271_op_resume(struct ieee80211_hw
*hw
)
1751 struct wl1271
*wl
= hw
->priv
;
1752 struct wl12xx_vif
*wlvif
;
1753 unsigned long flags
;
1754 bool run_irq_work
= false;
1756 wl1271_debug(DEBUG_MAC80211
, "mac80211 resume wow=%d",
1758 WARN_ON(!wl
->wow_enabled
);
1761 * re-enable irq_work enqueuing, and call irq_work directly if
1762 * there is a pending work.
1764 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1765 clear_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1766 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
))
1767 run_irq_work
= true;
1768 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1771 wl1271_debug(DEBUG_MAC80211
,
1772 "run postponed irq_work directly");
1774 wlcore_enable_interrupts(wl
);
1777 mutex_lock(&wl
->mutex
);
1778 wl12xx_for_each_wlvif(wl
, wlvif
) {
1779 wl1271_configure_resume(wl
, wlvif
);
1781 wl
->wow_enabled
= false;
1782 mutex_unlock(&wl
->mutex
);
1788 static int wl1271_op_start(struct ieee80211_hw
*hw
)
1790 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
1793 * We have to delay the booting of the hardware because
1794 * we need to know the local MAC address before downloading and
1795 * initializing the firmware. The MAC address cannot be changed
1796 * after boot, and without the proper MAC address, the firmware
1797 * will not function properly.
1799 * The MAC address is first known when the corresponding interface
1800 * is added. That is where we will initialize the hardware.
1806 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
1808 struct wl1271
*wl
= hw
->priv
;
1811 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
1814 * Interrupts must be disabled before setting the state to OFF.
1815 * Otherwise, the interrupt handler might be called and exit without
1816 * reading the interrupt status.
1818 wlcore_disable_interrupts(wl
);
1819 mutex_lock(&wl
->mutex
);
1820 if (wl
->state
== WL1271_STATE_OFF
) {
1821 mutex_unlock(&wl
->mutex
);
1824 * This will not necessarily enable interrupts as interrupts
1825 * may have been disabled when op_stop was called. It will,
1826 * however, balance the above call to disable_interrupts().
1828 wlcore_enable_interrupts(wl
);
1833 * this must be before the cancel_work calls below, so that the work
1834 * functions don't perform further work.
1836 wl
->state
= WL1271_STATE_OFF
;
1837 mutex_unlock(&wl
->mutex
);
1839 wl1271_flush_deferred_work(wl
);
1840 cancel_delayed_work_sync(&wl
->scan_complete_work
);
1841 cancel_work_sync(&wl
->netstack_work
);
1842 cancel_work_sync(&wl
->tx_work
);
1843 cancel_delayed_work_sync(&wl
->elp_work
);
1844 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1846 /* let's notify MAC80211 about the remaining pending TX frames */
1847 wl12xx_tx_reset(wl
, true);
1848 mutex_lock(&wl
->mutex
);
1850 wl1271_power_off(wl
);
1852 wl
->band
= IEEE80211_BAND_2GHZ
;
1855 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1856 wl
->tx_blocks_available
= 0;
1857 wl
->tx_allocated_blocks
= 0;
1858 wl
->tx_results_count
= 0;
1859 wl
->tx_packets_count
= 0;
1860 wl
->time_offset
= 0;
1861 wl
->ap_fw_ps_map
= 0;
1863 wl
->sched_scanning
= false;
1864 memset(wl
->roles_map
, 0, sizeof(wl
->roles_map
));
1865 memset(wl
->links_map
, 0, sizeof(wl
->links_map
));
1866 memset(wl
->roc_map
, 0, sizeof(wl
->roc_map
));
1867 wl
->active_sta_count
= 0;
1869 /* The system link is always allocated */
1870 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
1873 * this is performed after the cancel_work calls and the associated
1874 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1875 * get executed before all these vars have been reset.
1879 wl
->tx_blocks_freed
= 0;
1881 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1882 wl
->tx_pkts_freed
[i
] = 0;
1883 wl
->tx_allocated_pkts
[i
] = 0;
1886 wl1271_debugfs_reset(wl
);
1888 kfree(wl
->fw_status
);
1889 wl
->fw_status
= NULL
;
1890 kfree(wl
->tx_res_if
);
1891 wl
->tx_res_if
= NULL
;
1892 kfree(wl
->target_mem_map
);
1893 wl
->target_mem_map
= NULL
;
1895 mutex_unlock(&wl
->mutex
);
1898 static int wl12xx_allocate_rate_policy(struct wl1271
*wl
, u8
*idx
)
1900 u8 policy
= find_first_zero_bit(wl
->rate_policies_map
,
1901 WL12XX_MAX_RATE_POLICIES
);
1902 if (policy
>= WL12XX_MAX_RATE_POLICIES
)
1905 __set_bit(policy
, wl
->rate_policies_map
);
1910 static void wl12xx_free_rate_policy(struct wl1271
*wl
, u8
*idx
)
1912 if (WARN_ON(*idx
>= WL12XX_MAX_RATE_POLICIES
))
1915 __clear_bit(*idx
, wl
->rate_policies_map
);
1916 *idx
= WL12XX_MAX_RATE_POLICIES
;
1919 static u8
wl12xx_get_role_type(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1921 switch (wlvif
->bss_type
) {
1922 case BSS_TYPE_AP_BSS
:
1924 return WL1271_ROLE_P2P_GO
;
1926 return WL1271_ROLE_AP
;
1928 case BSS_TYPE_STA_BSS
:
1930 return WL1271_ROLE_P2P_CL
;
1932 return WL1271_ROLE_STA
;
1935 return WL1271_ROLE_IBSS
;
1938 wl1271_error("invalid bss_type: %d", wlvif
->bss_type
);
1940 return WL12XX_INVALID_ROLE_TYPE
;
1943 static int wl12xx_init_vif_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1945 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1948 /* clear everything but the persistent data */
1949 memset(wlvif
, 0, offsetof(struct wl12xx_vif
, persistent
));
1951 switch (ieee80211_vif_type_p2p(vif
)) {
1952 case NL80211_IFTYPE_P2P_CLIENT
:
1955 case NL80211_IFTYPE_STATION
:
1956 wlvif
->bss_type
= BSS_TYPE_STA_BSS
;
1958 case NL80211_IFTYPE_ADHOC
:
1959 wlvif
->bss_type
= BSS_TYPE_IBSS
;
1961 case NL80211_IFTYPE_P2P_GO
:
1964 case NL80211_IFTYPE_AP
:
1965 wlvif
->bss_type
= BSS_TYPE_AP_BSS
;
1968 wlvif
->bss_type
= MAX_BSS_TYPE
;
1972 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
1973 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
1974 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
1976 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1977 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1978 /* init sta/ibss data */
1979 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
1980 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
1981 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
1982 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
1985 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
1986 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
1987 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
1988 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
1989 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
1990 wl12xx_allocate_rate_policy(wl
,
1991 &wlvif
->ap
.ucast_rate_idx
[i
]);
1994 wlvif
->bitrate_masks
[IEEE80211_BAND_2GHZ
] = wl
->conf
.tx
.basic_rate
;
1995 wlvif
->bitrate_masks
[IEEE80211_BAND_5GHZ
] = wl
->conf
.tx
.basic_rate_5
;
1996 wlvif
->basic_rate_set
= CONF_TX_RATE_MASK_BASIC
;
1997 wlvif
->basic_rate
= CONF_TX_RATE_MASK_BASIC
;
1998 wlvif
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
1999 wlvif
->beacon_int
= WL1271_DEFAULT_BEACON_INT
;
2002 * mac80211 configures some values globally, while we treat them
2003 * per-interface. thus, on init, we have to copy them from wl
2005 wlvif
->band
= wl
->band
;
2006 wlvif
->channel
= wl
->channel
;
2007 wlvif
->power_level
= wl
->power_level
;
2009 INIT_WORK(&wlvif
->rx_streaming_enable_work
,
2010 wl1271_rx_streaming_enable_work
);
2011 INIT_WORK(&wlvif
->rx_streaming_disable_work
,
2012 wl1271_rx_streaming_disable_work
);
2013 INIT_LIST_HEAD(&wlvif
->list
);
2015 setup_timer(&wlvif
->rx_streaming_timer
, wl1271_rx_streaming_timer
,
2016 (unsigned long) wlvif
);
2020 static bool wl12xx_init_fw(struct wl1271
*wl
)
2022 int retries
= WL1271_BOOT_RETRIES
;
2023 bool booted
= false;
2024 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
2029 ret
= wl12xx_chip_wakeup(wl
, false);
2033 ret
= wl
->ops
->boot(wl
);
2037 ret
= wl1271_hw_init(wl
);
2045 mutex_unlock(&wl
->mutex
);
2046 /* Unlocking the mutex in the middle of handling is
2047 inherently unsafe. In this case we deem it safe to do,
2048 because we need to let any possibly pending IRQ out of
2049 the system (and while we are WL1271_STATE_OFF the IRQ
2050 work function will not do anything.) Also, any other
2051 possible concurrent operations will fail due to the
2052 current state, hence the wl1271 struct should be safe. */
2053 wlcore_disable_interrupts(wl
);
2054 wl1271_flush_deferred_work(wl
);
2055 cancel_work_sync(&wl
->netstack_work
);
2056 mutex_lock(&wl
->mutex
);
2058 wl1271_power_off(wl
);
2062 wl1271_error("firmware boot failed despite %d retries",
2063 WL1271_BOOT_RETRIES
);
2067 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver_str
);
2069 /* update hw/fw version info in wiphy struct */
2070 wiphy
->hw_version
= wl
->chip
.id
;
2071 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
2072 sizeof(wiphy
->fw_version
));
2075 * Now we know if 11a is supported (info from the NVS), so disable
2076 * 11a channels if not supported
2078 if (!wl
->enable_11a
)
2079 wiphy
->bands
[IEEE80211_BAND_5GHZ
]->n_channels
= 0;
2081 wl1271_debug(DEBUG_MAC80211
, "11a is %ssupported",
2082 wl
->enable_11a
? "" : "not ");
2084 wl
->state
= WL1271_STATE_ON
;
2089 static bool wl12xx_dev_role_started(struct wl12xx_vif
*wlvif
)
2091 return wlvif
->dev_hlid
!= WL12XX_INVALID_LINK_ID
;
2095 * Check whether a fw switch (i.e. moving from one loaded
2096 * fw to another) is needed. This function is also responsible
2097 * for updating wl->last_vif_count, so it must be called before
2098 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2101 static bool wl12xx_need_fw_change(struct wl1271
*wl
,
2102 struct vif_counter_data vif_counter_data
,
2105 enum wl12xx_fw_type current_fw
= wl
->fw_type
;
2106 u8 vif_count
= vif_counter_data
.counter
;
2108 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
))
2111 /* increase the vif count if this is a new vif */
2112 if (add
&& !vif_counter_data
.cur_vif_running
)
2115 wl
->last_vif_count
= vif_count
;
2117 /* no need for fw change if the device is OFF */
2118 if (wl
->state
== WL1271_STATE_OFF
)
2121 if (vif_count
> 1 && current_fw
== WL12XX_FW_TYPE_NORMAL
)
2123 if (vif_count
<= 1 && current_fw
== WL12XX_FW_TYPE_MULTI
)
2130 * Enter "forced psm". Make sure the sta is in psm against the ap,
2131 * to make the fw switch a bit more disconnection-persistent.
2133 static void wl12xx_force_active_psm(struct wl1271
*wl
)
2135 struct wl12xx_vif
*wlvif
;
2137 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
2138 wl1271_ps_set_mode(wl
, wlvif
, STATION_POWER_SAVE_MODE
);
2142 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
2143 struct ieee80211_vif
*vif
)
2145 struct wl1271
*wl
= hw
->priv
;
2146 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2147 struct vif_counter_data vif_count
;
2150 bool booted
= false;
2152 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
2153 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
2155 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
2156 ieee80211_vif_type_p2p(vif
), vif
->addr
);
2158 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2160 mutex_lock(&wl
->mutex
);
2161 ret
= wl1271_ps_elp_wakeup(wl
);
2166 * in some very corner case HW recovery scenarios its possible to
2167 * get here before __wl1271_op_remove_interface is complete, so
2168 * opt out if that is the case.
2170 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
) ||
2171 test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)) {
2177 ret
= wl12xx_init_vif_data(wl
, vif
);
2182 role_type
= wl12xx_get_role_type(wl
, wlvif
);
2183 if (role_type
== WL12XX_INVALID_ROLE_TYPE
) {
2188 if (wl12xx_need_fw_change(wl
, vif_count
, true)) {
2189 wl12xx_force_active_psm(wl
);
2190 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2191 mutex_unlock(&wl
->mutex
);
2192 wl1271_recovery_work(&wl
->recovery_work
);
2197 * TODO: after the nvs issue will be solved, move this block
2198 * to start(), and make sure here the driver is ON.
2200 if (wl
->state
== WL1271_STATE_OFF
) {
2202 * we still need this in order to configure the fw
2203 * while uploading the nvs
2205 memcpy(wl
->addresses
[0].addr
, vif
->addr
, ETH_ALEN
);
2207 booted
= wl12xx_init_fw(wl
);
2214 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2215 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2217 * The device role is a special role used for
2218 * rx and tx frames prior to association (as
2219 * the STA role can get packets only from
2220 * its associated bssid)
2222 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2224 &wlvif
->dev_role_id
);
2229 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2230 role_type
, &wlvif
->role_id
);
2234 ret
= wl1271_init_vif_specific(wl
, vif
);
2238 list_add(&wlvif
->list
, &wl
->wlvif_list
);
2239 set_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
);
2241 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2246 wl1271_ps_elp_sleep(wl
);
2248 mutex_unlock(&wl
->mutex
);
2253 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
2254 struct ieee80211_vif
*vif
,
2255 bool reset_tx_queues
)
2257 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2260 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
2262 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2265 /* because of hardware recovery, we may get here twice */
2266 if (wl
->state
!= WL1271_STATE_ON
)
2269 wl1271_info("down");
2271 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
&&
2272 wl
->scan_vif
== vif
) {
2274 * Rearm the tx watchdog just before idling scan. This
2275 * prevents just-finished scans from triggering the watchdog
2277 wl12xx_rearm_tx_watchdog_locked(wl
);
2279 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
2280 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
2281 wl
->scan_vif
= NULL
;
2282 wl
->scan
.req
= NULL
;
2283 ieee80211_scan_completed(wl
->hw
, true);
2286 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
)) {
2287 /* disable active roles */
2288 ret
= wl1271_ps_elp_wakeup(wl
);
2292 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2293 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2294 if (wl12xx_dev_role_started(wlvif
))
2295 wl12xx_stop_dev(wl
, wlvif
);
2297 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2302 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->role_id
);
2306 wl1271_ps_elp_sleep(wl
);
2309 /* clear all hlids (except system_hlid) */
2310 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
2312 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2313 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2314 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
2315 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
2316 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
2317 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
2319 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
2320 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
2321 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
2322 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
2323 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
2324 wl12xx_free_rate_policy(wl
,
2325 &wlvif
->ap
.ucast_rate_idx
[i
]);
2326 wl1271_free_ap_keys(wl
, wlvif
);
2329 dev_kfree_skb(wlvif
->probereq
);
2330 wlvif
->probereq
= NULL
;
2331 wl12xx_tx_reset_wlvif(wl
, wlvif
);
2332 if (wl
->last_wlvif
== wlvif
)
2333 wl
->last_wlvif
= NULL
;
2334 list_del(&wlvif
->list
);
2335 memset(wlvif
->ap
.sta_hlid_map
, 0, sizeof(wlvif
->ap
.sta_hlid_map
));
2336 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
2337 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
2339 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2344 mutex_unlock(&wl
->mutex
);
2346 del_timer_sync(&wlvif
->rx_streaming_timer
);
2347 cancel_work_sync(&wlvif
->rx_streaming_enable_work
);
2348 cancel_work_sync(&wlvif
->rx_streaming_disable_work
);
2350 mutex_lock(&wl
->mutex
);
2353 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
2354 struct ieee80211_vif
*vif
)
2356 struct wl1271
*wl
= hw
->priv
;
2357 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2358 struct wl12xx_vif
*iter
;
2359 struct vif_counter_data vif_count
;
2360 bool cancel_recovery
= true;
2362 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2363 mutex_lock(&wl
->mutex
);
2365 if (wl
->state
== WL1271_STATE_OFF
||
2366 !test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2370 * wl->vif can be null here if someone shuts down the interface
2371 * just when hardware recovery has been started.
2373 wl12xx_for_each_wlvif(wl
, iter
) {
2377 __wl1271_op_remove_interface(wl
, vif
, true);
2380 WARN_ON(iter
!= wlvif
);
2381 if (wl12xx_need_fw_change(wl
, vif_count
, false)) {
2382 wl12xx_force_active_psm(wl
);
2383 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2384 wl12xx_queue_recovery_work(wl
);
2385 cancel_recovery
= false;
2388 mutex_unlock(&wl
->mutex
);
2389 if (cancel_recovery
)
2390 cancel_work_sync(&wl
->recovery_work
);
2393 static int wl12xx_op_change_interface(struct ieee80211_hw
*hw
,
2394 struct ieee80211_vif
*vif
,
2395 enum nl80211_iftype new_type
, bool p2p
)
2397 struct wl1271
*wl
= hw
->priv
;
2400 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2401 wl1271_op_remove_interface(hw
, vif
);
2403 vif
->type
= new_type
;
2405 ret
= wl1271_op_add_interface(hw
, vif
);
2407 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2411 static int wl1271_join(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2415 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
2418 * One of the side effects of the JOIN command is that is clears
2419 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2420 * to a WPA/WPA2 access point will therefore kill the data-path.
2421 * Currently the only valid scenario for JOIN during association
2422 * is on roaming, in which case we will also be given new keys.
2423 * Keep the below message for now, unless it starts bothering
2424 * users who really like to roam a lot :)
2426 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2427 wl1271_info("JOIN while associated.");
2429 /* clear encryption type */
2430 wlvif
->encryption_type
= KEY_NONE
;
2433 set_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
);
2436 ret
= wl12xx_cmd_role_start_ibss(wl
, wlvif
);
2438 ret
= wl12xx_cmd_role_start_sta(wl
, wlvif
);
2442 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2446 * The join command disable the keep-alive mode, shut down its process,
2447 * and also clear the template config, so we need to reset it all after
2448 * the join. The acx_aid starts the keep-alive process, and the order
2449 * of the commands below is relevant.
2451 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, true);
2455 ret
= wl1271_acx_aid(wl
, wlvif
, wlvif
->aid
);
2459 ret
= wl12xx_cmd_build_klv_null_data(wl
, wlvif
);
2463 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
,
2464 CMD_TEMPL_KLV_IDX_NULL_DATA
,
2465 ACX_KEEP_ALIVE_TPL_VALID
);
2473 static int wl1271_unjoin(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2477 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
)) {
2478 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
2480 wl12xx_cmd_stop_channel_switch(wl
);
2481 ieee80211_chswitch_done(vif
, false);
2484 /* to stop listening to a channel, we disconnect */
2485 ret
= wl12xx_cmd_role_stop_sta(wl
, wlvif
);
2489 /* reset TX security counters on a clean disconnect */
2490 wlvif
->tx_security_last_seq_lsb
= 0;
2491 wlvif
->tx_security_seq
= 0;
2497 static void wl1271_set_band_rate(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2499 wlvif
->basic_rate_set
= wlvif
->bitrate_masks
[wlvif
->band
];
2500 wlvif
->rate_set
= wlvif
->basic_rate_set
;
2503 static int wl1271_sta_handle_idle(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2507 bool cur_idle
= !test_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2509 if (idle
== cur_idle
)
2513 /* no need to croc if we weren't busy (e.g. during boot) */
2514 if (wl12xx_dev_role_started(wlvif
)) {
2515 ret
= wl12xx_stop_dev(wl
, wlvif
);
2520 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
2521 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2524 ret
= wl1271_acx_keep_alive_config(
2525 wl
, wlvif
, CMD_TEMPL_KLV_IDX_NULL_DATA
,
2526 ACX_KEEP_ALIVE_TPL_INVALID
);
2529 clear_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2531 /* The current firmware only supports sched_scan in idle */
2532 if (wl
->sched_scanning
) {
2533 wl1271_scan_sched_scan_stop(wl
);
2534 ieee80211_sched_scan_stopped(wl
->hw
);
2537 ret
= wl12xx_start_dev(wl
, wlvif
);
2540 set_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2547 static int wl12xx_config_vif(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2548 struct ieee80211_conf
*conf
, u32 changed
)
2550 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2553 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2555 /* if the channel changes while joined, join again */
2556 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
2557 ((wlvif
->band
!= conf
->channel
->band
) ||
2558 (wlvif
->channel
!= channel
))) {
2559 /* send all pending packets */
2560 wl1271_tx_work_locked(wl
);
2561 wlvif
->band
= conf
->channel
->band
;
2562 wlvif
->channel
= channel
;
2566 * FIXME: the mac80211 should really provide a fixed
2567 * rate to use here. for now, just use the smallest
2568 * possible rate for the band as a fixed rate for
2569 * association frames and other control messages.
2571 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2572 wl1271_set_band_rate(wl
, wlvif
);
2575 wl1271_tx_min_rate_get(wl
,
2576 wlvif
->basic_rate_set
);
2577 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2579 wl1271_warning("rate policy for channel "
2583 * change the ROC channel. do it only if we are
2584 * not idle. otherwise, CROC will be called
2587 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
,
2589 wl12xx_dev_role_started(wlvif
) &&
2590 !(conf
->flags
& IEEE80211_CONF_IDLE
)) {
2591 ret
= wl12xx_stop_dev(wl
, wlvif
);
2595 ret
= wl12xx_start_dev(wl
, wlvif
);
2602 if ((changed
& IEEE80211_CONF_CHANGE_PS
) && !is_ap
) {
2604 if ((conf
->flags
& IEEE80211_CONF_PS
) &&
2605 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
2606 !test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2611 if (wl
->conf
.conn
.forced_ps
) {
2612 ps_mode
= STATION_POWER_SAVE_MODE
;
2613 ps_mode_str
= "forced";
2615 ps_mode
= STATION_AUTO_PS_MODE
;
2616 ps_mode_str
= "auto";
2619 wl1271_debug(DEBUG_PSM
, "%s ps enabled", ps_mode_str
);
2621 ret
= wl1271_ps_set_mode(wl
, wlvif
, ps_mode
);
2624 wl1271_warning("enter %s ps failed %d",
2627 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
2628 test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2630 wl1271_debug(DEBUG_PSM
, "auto ps disabled");
2632 ret
= wl1271_ps_set_mode(wl
, wlvif
,
2633 STATION_ACTIVE_MODE
);
2635 wl1271_warning("exit auto ps failed %d", ret
);
2639 if (conf
->power_level
!= wlvif
->power_level
) {
2640 ret
= wl1271_acx_tx_power(wl
, wlvif
, conf
->power_level
);
2644 wlvif
->power_level
= conf
->power_level
;
2650 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
2652 struct wl1271
*wl
= hw
->priv
;
2653 struct wl12xx_vif
*wlvif
;
2654 struct ieee80211_conf
*conf
= &hw
->conf
;
2655 int channel
, ret
= 0;
2657 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2659 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d %s"
2662 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
2664 conf
->flags
& IEEE80211_CONF_IDLE
? "idle" : "in use",
2668 * mac80211 will go to idle nearly immediately after transmitting some
2669 * frames, such as the deauth. To make sure those frames reach the air,
2670 * wait here until the TX queue is fully flushed.
2672 if ((changed
& IEEE80211_CONF_CHANGE_IDLE
) &&
2673 (conf
->flags
& IEEE80211_CONF_IDLE
))
2674 wl1271_tx_flush(wl
);
2676 mutex_lock(&wl
->mutex
);
2678 /* we support configuring the channel and band even while off */
2679 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2680 wl
->band
= conf
->channel
->band
;
2681 wl
->channel
= channel
;
2684 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
2685 wl
->power_level
= conf
->power_level
;
2687 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2690 ret
= wl1271_ps_elp_wakeup(wl
);
2694 /* configure each interface */
2695 wl12xx_for_each_wlvif(wl
, wlvif
) {
2696 ret
= wl12xx_config_vif(wl
, wlvif
, conf
, changed
);
2702 wl1271_ps_elp_sleep(wl
);
2705 mutex_unlock(&wl
->mutex
);
2710 struct wl1271_filter_params
{
2713 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
2716 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
,
2717 struct netdev_hw_addr_list
*mc_list
)
2719 struct wl1271_filter_params
*fp
;
2720 struct netdev_hw_addr
*ha
;
2721 struct wl1271
*wl
= hw
->priv
;
2723 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2726 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
2728 wl1271_error("Out of memory setting filters.");
2732 /* update multicast filtering parameters */
2733 fp
->mc_list_length
= 0;
2734 if (netdev_hw_addr_list_count(mc_list
) > ACX_MC_ADDRESS_GROUP_MAX
) {
2735 fp
->enabled
= false;
2738 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2739 memcpy(fp
->mc_list
[fp
->mc_list_length
],
2740 ha
->addr
, ETH_ALEN
);
2741 fp
->mc_list_length
++;
2745 return (u64
)(unsigned long)fp
;
2748 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2751 FIF_BCN_PRBRESP_PROMISC | \
2755 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
2756 unsigned int changed
,
2757 unsigned int *total
, u64 multicast
)
2759 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
2760 struct wl1271
*wl
= hw
->priv
;
2761 struct wl12xx_vif
*wlvif
;
2765 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter changed %x"
2766 " total %x", changed
, *total
);
2768 mutex_lock(&wl
->mutex
);
2770 *total
&= WL1271_SUPPORTED_FILTERS
;
2771 changed
&= WL1271_SUPPORTED_FILTERS
;
2773 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2776 ret
= wl1271_ps_elp_wakeup(wl
);
2780 wl12xx_for_each_wlvif(wl
, wlvif
) {
2781 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
2782 if (*total
& FIF_ALLMULTI
)
2783 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2787 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2790 fp
->mc_list_length
);
2797 * the fw doesn't provide an api to configure the filters. instead,
2798 * the filters configuration is based on the active roles / ROC
2803 wl1271_ps_elp_sleep(wl
);
2806 mutex_unlock(&wl
->mutex
);
2810 static int wl1271_record_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2811 u8 id
, u8 key_type
, u8 key_size
,
2812 const u8
*key
, u8 hlid
, u32 tx_seq_32
,
2815 struct wl1271_ap_key
*ap_key
;
2818 wl1271_debug(DEBUG_CRYPT
, "record ap key id %d", (int)id
);
2820 if (key_size
> MAX_KEY_SIZE
)
2824 * Find next free entry in ap_keys. Also check we are not replacing
2827 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2828 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2831 if (wlvif
->ap
.recorded_keys
[i
]->id
== id
) {
2832 wl1271_warning("trying to record key replacement");
2837 if (i
== MAX_NUM_KEYS
)
2840 ap_key
= kzalloc(sizeof(*ap_key
), GFP_KERNEL
);
2845 ap_key
->key_type
= key_type
;
2846 ap_key
->key_size
= key_size
;
2847 memcpy(ap_key
->key
, key
, key_size
);
2848 ap_key
->hlid
= hlid
;
2849 ap_key
->tx_seq_32
= tx_seq_32
;
2850 ap_key
->tx_seq_16
= tx_seq_16
;
2852 wlvif
->ap
.recorded_keys
[i
] = ap_key
;
2856 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2860 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2861 kfree(wlvif
->ap
.recorded_keys
[i
]);
2862 wlvif
->ap
.recorded_keys
[i
] = NULL
;
2866 static int wl1271_ap_init_hwenc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2869 struct wl1271_ap_key
*key
;
2870 bool wep_key_added
= false;
2872 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2874 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2877 key
= wlvif
->ap
.recorded_keys
[i
];
2879 if (hlid
== WL12XX_INVALID_LINK_ID
)
2880 hlid
= wlvif
->ap
.bcast_hlid
;
2882 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
2883 key
->id
, key
->key_type
,
2884 key
->key_size
, key
->key
,
2885 hlid
, key
->tx_seq_32
,
2890 if (key
->key_type
== KEY_WEP
)
2891 wep_key_added
= true;
2894 if (wep_key_added
) {
2895 ret
= wl12xx_cmd_set_default_wep_key(wl
, wlvif
->default_key
,
2896 wlvif
->ap
.bcast_hlid
);
2902 wl1271_free_ap_keys(wl
, wlvif
);
2906 static int wl1271_set_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2907 u16 action
, u8 id
, u8 key_type
,
2908 u8 key_size
, const u8
*key
, u32 tx_seq_32
,
2909 u16 tx_seq_16
, struct ieee80211_sta
*sta
)
2912 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2915 * A role set to GEM cipher requires different Tx settings (namely
2916 * spare blocks). Note when we are in this mode so the HW can adjust.
2918 if (key_type
== KEY_GEM
) {
2919 if (action
== KEY_ADD_OR_REPLACE
)
2920 wlvif
->is_gem
= true;
2921 else if (action
== KEY_REMOVE
)
2922 wlvif
->is_gem
= false;
2926 struct wl1271_station
*wl_sta
;
2930 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
2931 hlid
= wl_sta
->hlid
;
2933 hlid
= wlvif
->ap
.bcast_hlid
;
2936 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
2938 * We do not support removing keys after AP shutdown.
2939 * Pretend we do to make mac80211 happy.
2941 if (action
!= KEY_ADD_OR_REPLACE
)
2944 ret
= wl1271_record_ap_key(wl
, wlvif
, id
,
2946 key
, hlid
, tx_seq_32
,
2949 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, action
,
2950 id
, key_type
, key_size
,
2951 key
, hlid
, tx_seq_32
,
2959 static const u8 bcast_addr
[ETH_ALEN
] = {
2960 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2963 addr
= sta
? sta
->addr
: bcast_addr
;
2965 if (is_zero_ether_addr(addr
)) {
2966 /* We dont support TX only encryption */
2970 /* The wl1271 does not allow to remove unicast keys - they
2971 will be cleared automatically on next CMD_JOIN. Ignore the
2972 request silently, as we dont want the mac80211 to emit
2973 an error message. */
2974 if (action
== KEY_REMOVE
&& !is_broadcast_ether_addr(addr
))
2977 /* don't remove key if hlid was already deleted */
2978 if (action
== KEY_REMOVE
&&
2979 wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
2982 ret
= wl1271_cmd_set_sta_key(wl
, wlvif
, action
,
2983 id
, key_type
, key_size
,
2984 key
, addr
, tx_seq_32
,
2989 /* the default WEP key needs to be configured at least once */
2990 if (key_type
== KEY_WEP
) {
2991 ret
= wl12xx_cmd_set_default_wep_key(wl
,
3002 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3003 struct ieee80211_vif
*vif
,
3004 struct ieee80211_sta
*sta
,
3005 struct ieee80211_key_conf
*key_conf
)
3007 struct wl1271
*wl
= hw
->priv
;
3008 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3014 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
3016 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x sta: %p", cmd
, sta
);
3017 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
3018 key_conf
->cipher
, key_conf
->keyidx
,
3019 key_conf
->keylen
, key_conf
->flags
);
3020 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
3022 mutex_lock(&wl
->mutex
);
3024 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3029 ret
= wl1271_ps_elp_wakeup(wl
);
3033 switch (key_conf
->cipher
) {
3034 case WLAN_CIPHER_SUITE_WEP40
:
3035 case WLAN_CIPHER_SUITE_WEP104
:
3038 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3040 case WLAN_CIPHER_SUITE_TKIP
:
3041 key_type
= KEY_TKIP
;
3043 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3044 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3045 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3047 case WLAN_CIPHER_SUITE_CCMP
:
3050 key_conf
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3051 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3052 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3054 case WL1271_CIPHER_SUITE_GEM
:
3056 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3057 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3060 wl1271_error("Unknown key algo 0x%x", key_conf
->cipher
);
3068 ret
= wl1271_set_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
3069 key_conf
->keyidx
, key_type
,
3070 key_conf
->keylen
, key_conf
->key
,
3071 tx_seq_32
, tx_seq_16
, sta
);
3073 wl1271_error("Could not add or replace key");
3078 * reconfiguring arp response if the unicast (or common)
3079 * encryption key type was changed
3081 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
3082 (sta
|| key_type
== KEY_WEP
) &&
3083 wlvif
->encryption_type
!= key_type
) {
3084 wlvif
->encryption_type
= key_type
;
3085 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3087 wl1271_warning("build arp rsp failed: %d", ret
);
3094 ret
= wl1271_set_key(wl
, wlvif
, KEY_REMOVE
,
3095 key_conf
->keyidx
, key_type
,
3096 key_conf
->keylen
, key_conf
->key
,
3099 wl1271_error("Could not remove key");
3105 wl1271_error("Unsupported key cmd 0x%x", cmd
);
3111 wl1271_ps_elp_sleep(wl
);
3114 mutex_unlock(&wl
->mutex
);
3119 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
3120 struct ieee80211_vif
*vif
,
3121 struct cfg80211_scan_request
*req
)
3123 struct wl1271
*wl
= hw
->priv
;
3128 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
3131 ssid
= req
->ssids
[0].ssid
;
3132 len
= req
->ssids
[0].ssid_len
;
3135 mutex_lock(&wl
->mutex
);
3137 if (wl
->state
== WL1271_STATE_OFF
) {
3139 * We cannot return -EBUSY here because cfg80211 will expect
3140 * a call to ieee80211_scan_completed if we do - in this case
3141 * there won't be any call.
3147 ret
= wl1271_ps_elp_wakeup(wl
);
3151 /* fail if there is any role in ROC */
3152 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
3153 /* don't allow scanning right now */
3158 ret
= wl1271_scan(hw
->priv
, vif
, ssid
, len
, req
);
3160 wl1271_ps_elp_sleep(wl
);
3162 mutex_unlock(&wl
->mutex
);
3167 static void wl1271_op_cancel_hw_scan(struct ieee80211_hw
*hw
,
3168 struct ieee80211_vif
*vif
)
3170 struct wl1271
*wl
= hw
->priv
;
3173 wl1271_debug(DEBUG_MAC80211
, "mac80211 cancel hw scan");
3175 mutex_lock(&wl
->mutex
);
3177 if (wl
->state
== WL1271_STATE_OFF
)
3180 if (wl
->scan
.state
== WL1271_SCAN_STATE_IDLE
)
3183 ret
= wl1271_ps_elp_wakeup(wl
);
3187 if (wl
->scan
.state
!= WL1271_SCAN_STATE_DONE
) {
3188 ret
= wl1271_scan_stop(wl
);
3194 * Rearm the tx watchdog just before idling scan. This
3195 * prevents just-finished scans from triggering the watchdog
3197 wl12xx_rearm_tx_watchdog_locked(wl
);
3199 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
3200 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
3201 wl
->scan_vif
= NULL
;
3202 wl
->scan
.req
= NULL
;
3203 ieee80211_scan_completed(wl
->hw
, true);
3206 wl1271_ps_elp_sleep(wl
);
3208 mutex_unlock(&wl
->mutex
);
3210 cancel_delayed_work_sync(&wl
->scan_complete_work
);
3213 static int wl1271_op_sched_scan_start(struct ieee80211_hw
*hw
,
3214 struct ieee80211_vif
*vif
,
3215 struct cfg80211_sched_scan_request
*req
,
3216 struct ieee80211_sched_scan_ies
*ies
)
3218 struct wl1271
*wl
= hw
->priv
;
3219 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3222 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_start");
3224 mutex_lock(&wl
->mutex
);
3226 if (wl
->state
== WL1271_STATE_OFF
) {
3231 ret
= wl1271_ps_elp_wakeup(wl
);
3235 ret
= wl1271_scan_sched_scan_config(wl
, wlvif
, req
, ies
);
3239 ret
= wl1271_scan_sched_scan_start(wl
, wlvif
);
3243 wl
->sched_scanning
= true;
3246 wl1271_ps_elp_sleep(wl
);
3248 mutex_unlock(&wl
->mutex
);
3252 static void wl1271_op_sched_scan_stop(struct ieee80211_hw
*hw
,
3253 struct ieee80211_vif
*vif
)
3255 struct wl1271
*wl
= hw
->priv
;
3258 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_stop");
3260 mutex_lock(&wl
->mutex
);
3262 if (wl
->state
== WL1271_STATE_OFF
)
3265 ret
= wl1271_ps_elp_wakeup(wl
);
3269 wl1271_scan_sched_scan_stop(wl
);
3271 wl1271_ps_elp_sleep(wl
);
3273 mutex_unlock(&wl
->mutex
);
3276 static int wl1271_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3278 struct wl1271
*wl
= hw
->priv
;
3281 mutex_lock(&wl
->mutex
);
3283 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3288 ret
= wl1271_ps_elp_wakeup(wl
);
3292 ret
= wl1271_acx_frag_threshold(wl
, value
);
3294 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret
);
3296 wl1271_ps_elp_sleep(wl
);
3299 mutex_unlock(&wl
->mutex
);
3304 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3306 struct wl1271
*wl
= hw
->priv
;
3307 struct wl12xx_vif
*wlvif
;
3310 mutex_lock(&wl
->mutex
);
3312 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3317 ret
= wl1271_ps_elp_wakeup(wl
);
3321 wl12xx_for_each_wlvif(wl
, wlvif
) {
3322 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, value
);
3324 wl1271_warning("set rts threshold failed: %d", ret
);
3326 wl1271_ps_elp_sleep(wl
);
3329 mutex_unlock(&wl
->mutex
);
3334 static int wl1271_ssid_set(struct ieee80211_vif
*vif
, struct sk_buff
*skb
,
3337 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3339 const u8
*ptr
= cfg80211_find_ie(WLAN_EID_SSID
, skb
->data
+ offset
,
3343 wl1271_error("No SSID in IEs!");
3348 if (ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3349 wl1271_error("SSID is too long!");
3353 wlvif
->ssid_len
= ssid_len
;
3354 memcpy(wlvif
->ssid
, ptr
+2, ssid_len
);
3358 static void wl12xx_remove_ie(struct sk_buff
*skb
, u8 eid
, int ieoffset
)
3361 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3362 u8
*ie
= (u8
*)cfg80211_find_ie(eid
, skb
->data
+ ieoffset
,
3363 skb
->len
- ieoffset
);
3368 memmove(ie
, next
, end
- next
);
3369 skb_trim(skb
, skb
->len
- len
);
3372 static void wl12xx_remove_vendor_ie(struct sk_buff
*skb
,
3373 unsigned int oui
, u8 oui_type
,
3377 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3378 u8
*ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
3379 skb
->data
+ ieoffset
,
3380 skb
->len
- ieoffset
);
3385 memmove(ie
, next
, end
- next
);
3386 skb_trim(skb
, skb
->len
- len
);
3389 static int wl1271_ap_set_probe_resp_tmpl(struct wl1271
*wl
, u32 rates
,
3390 struct ieee80211_vif
*vif
)
3392 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3393 struct sk_buff
*skb
;
3396 skb
= ieee80211_proberesp_get(wl
->hw
, vif
);
3400 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3401 CMD_TEMPL_AP_PROBE_RESPONSE
,
3410 static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271
*wl
,
3411 struct ieee80211_vif
*vif
,
3413 size_t probe_rsp_len
,
3416 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3417 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
3418 u8 probe_rsp_templ
[WL1271_CMD_TEMPL_MAX_SIZE
];
3419 int ssid_ie_offset
, ie_offset
, templ_len
;
3422 /* no need to change probe response if the SSID is set correctly */
3423 if (wlvif
->ssid_len
> 0)
3424 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3425 CMD_TEMPL_AP_PROBE_RESPONSE
,
3430 if (probe_rsp_len
+ bss_conf
->ssid_len
> WL1271_CMD_TEMPL_MAX_SIZE
) {
3431 wl1271_error("probe_rsp template too big");
3435 /* start searching from IE offset */
3436 ie_offset
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
3438 ptr
= cfg80211_find_ie(WLAN_EID_SSID
, probe_rsp_data
+ ie_offset
,
3439 probe_rsp_len
- ie_offset
);
3441 wl1271_error("No SSID in beacon!");
3445 ssid_ie_offset
= ptr
- probe_rsp_data
;
3446 ptr
+= (ptr
[1] + 2);
3448 memcpy(probe_rsp_templ
, probe_rsp_data
, ssid_ie_offset
);
3450 /* insert SSID from bss_conf */
3451 probe_rsp_templ
[ssid_ie_offset
] = WLAN_EID_SSID
;
3452 probe_rsp_templ
[ssid_ie_offset
+ 1] = bss_conf
->ssid_len
;
3453 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2,
3454 bss_conf
->ssid
, bss_conf
->ssid_len
);
3455 templ_len
= ssid_ie_offset
+ 2 + bss_conf
->ssid_len
;
3457 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2 + bss_conf
->ssid_len
,
3458 ptr
, probe_rsp_len
- (ptr
- probe_rsp_data
));
3459 templ_len
+= probe_rsp_len
- (ptr
- probe_rsp_data
);
3461 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3462 CMD_TEMPL_AP_PROBE_RESPONSE
,
3468 static int wl1271_bss_erp_info_changed(struct wl1271
*wl
,
3469 struct ieee80211_vif
*vif
,
3470 struct ieee80211_bss_conf
*bss_conf
,
3473 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3476 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3477 if (bss_conf
->use_short_slot
)
3478 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_SHORT
);
3480 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_LONG
);
3482 wl1271_warning("Set slot time failed %d", ret
);
3487 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3488 if (bss_conf
->use_short_preamble
)
3489 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_SHORT
);
3491 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_LONG
);
3494 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3495 if (bss_conf
->use_cts_prot
)
3496 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3499 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3500 CTSPROTECT_DISABLE
);
3502 wl1271_warning("Set ctsprotect failed %d", ret
);
3511 static int wl1271_bss_beacon_info_changed(struct wl1271
*wl
,
3512 struct ieee80211_vif
*vif
,
3513 struct ieee80211_bss_conf
*bss_conf
,
3516 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3517 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3520 if ((changed
& BSS_CHANGED_BEACON_INT
)) {
3521 wl1271_debug(DEBUG_MASTER
, "beacon interval updated: %d",
3522 bss_conf
->beacon_int
);
3524 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3527 if ((changed
& BSS_CHANGED_AP_PROBE_RESP
) && is_ap
) {
3528 u32 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3529 if (!wl1271_ap_set_probe_resp_tmpl(wl
, rate
, vif
)) {
3530 wl1271_debug(DEBUG_AP
, "probe response updated");
3531 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
);
3535 if ((changed
& BSS_CHANGED_BEACON
)) {
3536 struct ieee80211_hdr
*hdr
;
3538 int ieoffset
= offsetof(struct ieee80211_mgmt
,
3540 struct sk_buff
*beacon
= ieee80211_beacon_get(wl
->hw
, vif
);
3548 wl1271_debug(DEBUG_MASTER
, "beacon updated");
3550 ret
= wl1271_ssid_set(vif
, beacon
, ieoffset
);
3552 dev_kfree_skb(beacon
);
3555 min_rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3556 tmpl_id
= is_ap
? CMD_TEMPL_AP_BEACON
:
3558 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, tmpl_id
,
3563 dev_kfree_skb(beacon
);
3568 * In case we already have a probe-resp beacon set explicitly
3569 * by usermode, don't use the beacon data.
3571 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
))
3574 /* remove TIM ie from probe response */
3575 wl12xx_remove_ie(beacon
, WLAN_EID_TIM
, ieoffset
);
3578 * remove p2p ie from probe response.
3579 * the fw reponds to probe requests that don't include
3580 * the p2p ie. probe requests with p2p ie will be passed,
3581 * and will be responded by the supplicant (the spec
3582 * forbids including the p2p ie when responding to probe
3583 * requests that didn't include it).
3585 wl12xx_remove_vendor_ie(beacon
, WLAN_OUI_WFA
,
3586 WLAN_OUI_TYPE_WFA_P2P
, ieoffset
);
3588 hdr
= (struct ieee80211_hdr
*) beacon
->data
;
3589 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3590 IEEE80211_STYPE_PROBE_RESP
);
3592 ret
= wl1271_ap_set_probe_resp_tmpl_legacy(wl
, vif
,
3597 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3598 CMD_TEMPL_PROBE_RESPONSE
,
3603 dev_kfree_skb(beacon
);
3610 wl1271_error("beacon info change failed: %d", ret
);
3614 /* AP mode changes */
3615 static void wl1271_bss_info_changed_ap(struct wl1271
*wl
,
3616 struct ieee80211_vif
*vif
,
3617 struct ieee80211_bss_conf
*bss_conf
,
3620 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3623 if ((changed
& BSS_CHANGED_BASIC_RATES
)) {
3624 u32 rates
= bss_conf
->basic_rates
;
3626 wlvif
->basic_rate_set
= wl1271_tx_enabled_rates_get(wl
, rates
,
3628 wlvif
->basic_rate
= wl1271_tx_min_rate_get(wl
,
3629 wlvif
->basic_rate_set
);
3631 ret
= wl1271_init_ap_rates(wl
, wlvif
);
3633 wl1271_error("AP rate policy change failed %d", ret
);
3637 ret
= wl1271_ap_init_templates(wl
, vif
);
3642 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
, changed
);
3646 if ((changed
& BSS_CHANGED_BEACON_ENABLED
)) {
3647 if (bss_conf
->enable_beacon
) {
3648 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3649 ret
= wl12xx_cmd_role_start_ap(wl
, wlvif
);
3653 ret
= wl1271_ap_init_hwenc(wl
, wlvif
);
3657 set_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3658 wl1271_debug(DEBUG_AP
, "started AP");
3661 if (test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3662 ret
= wl12xx_cmd_role_stop_ap(wl
, wlvif
);
3666 clear_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3667 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
,
3669 wl1271_debug(DEBUG_AP
, "stopped AP");
3674 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3678 /* Handle HT information change */
3679 if ((changed
& BSS_CHANGED_HT
) &&
3680 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3681 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3682 bss_conf
->ht_operation_mode
);
3684 wl1271_warning("Set ht information failed %d", ret
);
3693 /* STA/IBSS mode changes */
3694 static void wl1271_bss_info_changed_sta(struct wl1271
*wl
,
3695 struct ieee80211_vif
*vif
,
3696 struct ieee80211_bss_conf
*bss_conf
,
3699 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3700 bool do_join
= false, set_assoc
= false;
3701 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
3702 bool ibss_joined
= false;
3703 u32 sta_rate_set
= 0;
3705 struct ieee80211_sta
*sta
;
3706 bool sta_exists
= false;
3707 struct ieee80211_sta_ht_cap sta_ht_cap
;
3710 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
,
3716 if (changed
& BSS_CHANGED_IBSS
) {
3717 if (bss_conf
->ibss_joined
) {
3718 set_bit(WLVIF_FLAG_IBSS_JOINED
, &wlvif
->flags
);
3721 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED
,
3723 wl1271_unjoin(wl
, wlvif
);
3727 if ((changed
& BSS_CHANGED_BEACON_INT
) && ibss_joined
)
3730 /* Need to update the SSID (for filtering etc) */
3731 if ((changed
& BSS_CHANGED_BEACON
) && ibss_joined
)
3734 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && ibss_joined
) {
3735 wl1271_debug(DEBUG_ADHOC
, "ad-hoc beaconing: %s",
3736 bss_conf
->enable_beacon
? "enabled" : "disabled");
3741 if (changed
& BSS_CHANGED_IDLE
&& !is_ibss
) {
3742 ret
= wl1271_sta_handle_idle(wl
, wlvif
, bss_conf
->idle
);
3744 wl1271_warning("idle mode change failed %d", ret
);
3747 if ((changed
& BSS_CHANGED_CQM
)) {
3748 bool enable
= false;
3749 if (bss_conf
->cqm_rssi_thold
)
3751 ret
= wl1271_acx_rssi_snr_trigger(wl
, wlvif
, enable
,
3752 bss_conf
->cqm_rssi_thold
,
3753 bss_conf
->cqm_rssi_hyst
);
3756 wlvif
->rssi_thold
= bss_conf
->cqm_rssi_thold
;
3759 if (changed
& BSS_CHANGED_BSSID
)
3760 if (!is_zero_ether_addr(bss_conf
->bssid
)) {
3761 ret
= wl12xx_cmd_build_null_data(wl
, wlvif
);
3765 ret
= wl1271_build_qos_null_data(wl
, vif
);
3770 if (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_HT
)) {
3772 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
3776 /* save the supp_rates of the ap */
3777 sta_rate_set
= sta
->supp_rates
[wl
->hw
->conf
.channel
->band
];
3778 if (sta
->ht_cap
.ht_supported
)
3780 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
);
3781 sta_ht_cap
= sta
->ht_cap
;
3788 if ((changed
& BSS_CHANGED_ASSOC
)) {
3789 if (bss_conf
->assoc
) {
3792 wlvif
->aid
= bss_conf
->aid
;
3793 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3798 * use basic rates from AP, and determine lowest rate
3799 * to use with control frames.
3801 rates
= bss_conf
->basic_rates
;
3802 wlvif
->basic_rate_set
=
3803 wl1271_tx_enabled_rates_get(wl
, rates
,
3806 wl1271_tx_min_rate_get(wl
,
3807 wlvif
->basic_rate_set
);
3810 wl1271_tx_enabled_rates_get(wl
,
3813 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3818 * with wl1271, we don't need to update the
3819 * beacon_int and dtim_period, because the firmware
3820 * updates it by itself when the first beacon is
3821 * received after a join.
3823 ret
= wl1271_cmd_build_ps_poll(wl
, wlvif
, wlvif
->aid
);
3828 * Get a template for hardware connection maintenance
3830 dev_kfree_skb(wlvif
->probereq
);
3831 wlvif
->probereq
= wl1271_cmd_build_ap_probe_req(wl
,
3834 ieoffset
= offsetof(struct ieee80211_mgmt
,
3835 u
.probe_req
.variable
);
3836 wl1271_ssid_set(vif
, wlvif
->probereq
, ieoffset
);
3838 /* enable the connection monitoring feature */
3839 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, true);
3843 /* use defaults when not associated */
3845 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED
,
3848 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT
,
3852 /* free probe-request template */
3853 dev_kfree_skb(wlvif
->probereq
);
3854 wlvif
->probereq
= NULL
;
3856 /* revert back to minimum rates for the current band */
3857 wl1271_set_band_rate(wl
, wlvif
);
3859 wl1271_tx_min_rate_get(wl
,
3860 wlvif
->basic_rate_set
);
3861 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3865 /* disable connection monitor features */
3866 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
3868 /* Disable the keep-alive feature */
3869 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
3873 /* restore the bssid filter and go to dummy bssid */
3876 * we might have to disable roc, if there was
3877 * no IF_OPER_UP notification.
3880 ret
= wl12xx_croc(wl
, wlvif
->role_id
);
3885 * (we also need to disable roc in case of
3886 * roaming on the same channel. until we will
3887 * have a better flow...)
3889 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
3890 ret
= wl12xx_croc(wl
,
3891 wlvif
->dev_role_id
);
3896 wl1271_unjoin(wl
, wlvif
);
3897 if (!bss_conf
->idle
)
3898 wl12xx_start_dev(wl
, wlvif
);
3903 if (changed
& BSS_CHANGED_IBSS
) {
3904 wl1271_debug(DEBUG_ADHOC
, "ibss_joined: %d",
3905 bss_conf
->ibss_joined
);
3907 if (bss_conf
->ibss_joined
) {
3908 u32 rates
= bss_conf
->basic_rates
;
3909 wlvif
->basic_rate_set
=
3910 wl1271_tx_enabled_rates_get(wl
, rates
,
3913 wl1271_tx_min_rate_get(wl
,
3914 wlvif
->basic_rate_set
);
3916 /* by default, use 11b + OFDM rates */
3917 wlvif
->rate_set
= CONF_TX_IBSS_DEFAULT_RATES
;
3918 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3924 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3929 ret
= wl1271_join(wl
, wlvif
, set_assoc
);
3931 wl1271_warning("cmd join failed %d", ret
);
3935 /* ROC until connected (after EAPOL exchange) */
3937 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->role_id
);
3941 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
))
3942 wl12xx_set_authorized(wl
, wlvif
);
3945 * stop device role if started (we might already be in
3948 if (wl12xx_dev_role_started(wlvif
)) {
3949 ret
= wl12xx_stop_dev(wl
, wlvif
);
3955 /* Handle new association with HT. Do this after join. */
3957 if ((changed
& BSS_CHANGED_HT
) &&
3958 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3959 ret
= wl1271_acx_set_ht_capabilities(wl
,
3964 wl1271_warning("Set ht cap true failed %d",
3969 /* handle new association without HT and disassociation */
3970 else if (changed
& BSS_CHANGED_ASSOC
) {
3971 ret
= wl1271_acx_set_ht_capabilities(wl
,
3976 wl1271_warning("Set ht cap false failed %d",
3983 /* Handle HT information change. Done after join. */
3984 if ((changed
& BSS_CHANGED_HT
) &&
3985 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3986 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3987 bss_conf
->ht_operation_mode
);
3989 wl1271_warning("Set ht information failed %d", ret
);
3994 /* Handle arp filtering. Done after join. */
3995 if ((changed
& BSS_CHANGED_ARP_FILTER
) ||
3996 (!is_ibss
&& (changed
& BSS_CHANGED_QOS
))) {
3997 __be32 addr
= bss_conf
->arp_addr_list
[0];
3998 wlvif
->sta
.qos
= bss_conf
->qos
;
3999 WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
);
4001 if (bss_conf
->arp_addr_cnt
== 1 &&
4002 bss_conf
->arp_filter_enabled
) {
4003 wlvif
->ip_addr
= addr
;
4005 * The template should have been configured only upon
4006 * association. however, it seems that the correct ip
4007 * isn't being set (when sending), so we have to
4008 * reconfigure the template upon every ip change.
4010 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
4012 wl1271_warning("build arp rsp failed: %d", ret
);
4016 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
,
4017 (ACX_ARP_FILTER_ARP_FILTERING
|
4018 ACX_ARP_FILTER_AUTO_ARP
),
4022 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
, 0, addr
);
4033 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
4034 struct ieee80211_vif
*vif
,
4035 struct ieee80211_bss_conf
*bss_conf
,
4038 struct wl1271
*wl
= hw
->priv
;
4039 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4040 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
4043 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed 0x%x",
4046 mutex_lock(&wl
->mutex
);
4048 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4051 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)))
4054 ret
= wl1271_ps_elp_wakeup(wl
);
4059 wl1271_bss_info_changed_ap(wl
, vif
, bss_conf
, changed
);
4061 wl1271_bss_info_changed_sta(wl
, vif
, bss_conf
, changed
);
4063 wl1271_ps_elp_sleep(wl
);
4066 mutex_unlock(&wl
->mutex
);
4069 static int wl1271_op_conf_tx(struct ieee80211_hw
*hw
,
4070 struct ieee80211_vif
*vif
, u16 queue
,
4071 const struct ieee80211_tx_queue_params
*params
)
4073 struct wl1271
*wl
= hw
->priv
;
4074 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4078 mutex_lock(&wl
->mutex
);
4080 wl1271_debug(DEBUG_MAC80211
, "mac80211 conf tx %d", queue
);
4083 ps_scheme
= CONF_PS_SCHEME_UPSD_TRIGGER
;
4085 ps_scheme
= CONF_PS_SCHEME_LEGACY
;
4087 if (!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
4090 ret
= wl1271_ps_elp_wakeup(wl
);
4095 * the txop is confed in units of 32us by the mac80211,
4098 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4099 params
->cw_min
, params
->cw_max
,
4100 params
->aifs
, params
->txop
<< 5);
4104 ret
= wl1271_acx_tid_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4105 CONF_CHANNEL_TYPE_EDCF
,
4106 wl1271_tx_get_queue(queue
),
4107 ps_scheme
, CONF_ACK_POLICY_LEGACY
,
4111 wl1271_ps_elp_sleep(wl
);
4114 mutex_unlock(&wl
->mutex
);
4119 static u64
wl1271_op_get_tsf(struct ieee80211_hw
*hw
,
4120 struct ieee80211_vif
*vif
)
4123 struct wl1271
*wl
= hw
->priv
;
4124 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4125 u64 mactime
= ULLONG_MAX
;
4128 wl1271_debug(DEBUG_MAC80211
, "mac80211 get tsf");
4130 mutex_lock(&wl
->mutex
);
4132 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4135 ret
= wl1271_ps_elp_wakeup(wl
);
4139 ret
= wl12xx_acx_tsf_info(wl
, wlvif
, &mactime
);
4144 wl1271_ps_elp_sleep(wl
);
4147 mutex_unlock(&wl
->mutex
);
4151 static int wl1271_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
4152 struct survey_info
*survey
)
4154 struct wl1271
*wl
= hw
->priv
;
4155 struct ieee80211_conf
*conf
= &hw
->conf
;
4160 survey
->channel
= conf
->channel
;
4161 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
4162 survey
->noise
= wl
->noise
;
4167 static int wl1271_allocate_sta(struct wl1271
*wl
,
4168 struct wl12xx_vif
*wlvif
,
4169 struct ieee80211_sta
*sta
)
4171 struct wl1271_station
*wl_sta
;
4175 if (wl
->active_sta_count
>= AP_MAX_STATIONS
) {
4176 wl1271_warning("could not allocate HLID - too much stations");
4180 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4181 ret
= wl12xx_allocate_link(wl
, wlvif
, &wl_sta
->hlid
);
4183 wl1271_warning("could not allocate HLID - too many links");
4187 set_bit(wl_sta
->hlid
, wlvif
->ap
.sta_hlid_map
);
4188 memcpy(wl
->links
[wl_sta
->hlid
].addr
, sta
->addr
, ETH_ALEN
);
4189 wl
->active_sta_count
++;
4193 void wl1271_free_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 hlid
)
4195 if (!test_bit(hlid
, wlvif
->ap
.sta_hlid_map
))
4198 clear_bit(hlid
, wlvif
->ap
.sta_hlid_map
);
4199 memset(wl
->links
[hlid
].addr
, 0, ETH_ALEN
);
4200 wl
->links
[hlid
].ba_bitmap
= 0;
4201 __clear_bit(hlid
, &wl
->ap_ps_map
);
4202 __clear_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
4203 wl12xx_free_link(wl
, wlvif
, &hlid
);
4204 wl
->active_sta_count
--;
4207 * rearm the tx watchdog when the last STA is freed - give the FW a
4208 * chance to return STA-buffered packets before complaining.
4210 if (wl
->active_sta_count
== 0)
4211 wl12xx_rearm_tx_watchdog_locked(wl
);
4214 static int wl12xx_sta_add(struct wl1271
*wl
,
4215 struct wl12xx_vif
*wlvif
,
4216 struct ieee80211_sta
*sta
)
4218 struct wl1271_station
*wl_sta
;
4222 wl1271_debug(DEBUG_MAC80211
, "mac80211 add sta %d", (int)sta
->aid
);
4224 ret
= wl1271_allocate_sta(wl
, wlvif
, sta
);
4228 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4229 hlid
= wl_sta
->hlid
;
4231 ret
= wl12xx_cmd_add_peer(wl
, wlvif
, sta
, hlid
);
4233 wl1271_free_sta(wl
, wlvif
, hlid
);
4238 static int wl12xx_sta_remove(struct wl1271
*wl
,
4239 struct wl12xx_vif
*wlvif
,
4240 struct ieee80211_sta
*sta
)
4242 struct wl1271_station
*wl_sta
;
4245 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove sta %d", (int)sta
->aid
);
4247 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4249 if (WARN_ON(!test_bit(id
, wlvif
->ap
.sta_hlid_map
)))
4252 ret
= wl12xx_cmd_remove_peer(wl
, wl_sta
->hlid
);
4256 wl1271_free_sta(wl
, wlvif
, wl_sta
->hlid
);
4260 static int wl12xx_update_sta_state(struct wl1271
*wl
,
4261 struct wl12xx_vif
*wlvif
,
4262 struct ieee80211_sta
*sta
,
4263 enum ieee80211_sta_state old_state
,
4264 enum ieee80211_sta_state new_state
)
4266 struct wl1271_station
*wl_sta
;
4268 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
4269 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
4272 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4273 hlid
= wl_sta
->hlid
;
4275 /* Add station (AP mode) */
4277 old_state
== IEEE80211_STA_NOTEXIST
&&
4278 new_state
== IEEE80211_STA_NONE
)
4279 return wl12xx_sta_add(wl
, wlvif
, sta
);
4281 /* Remove station (AP mode) */
4283 old_state
== IEEE80211_STA_NONE
&&
4284 new_state
== IEEE80211_STA_NOTEXIST
) {
4286 wl12xx_sta_remove(wl
, wlvif
, sta
);
4290 /* Authorize station (AP mode) */
4292 new_state
== IEEE80211_STA_AUTHORIZED
) {
4293 ret
= wl12xx_cmd_set_peer_state(wl
, hlid
);
4297 ret
= wl1271_acx_set_ht_capabilities(wl
, &sta
->ht_cap
, true,
4302 /* Authorize station */
4304 new_state
== IEEE80211_STA_AUTHORIZED
) {
4305 set_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4306 return wl12xx_set_authorized(wl
, wlvif
);
4310 old_state
== IEEE80211_STA_AUTHORIZED
&&
4311 new_state
== IEEE80211_STA_ASSOC
) {
4312 clear_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4319 static int wl12xx_op_sta_state(struct ieee80211_hw
*hw
,
4320 struct ieee80211_vif
*vif
,
4321 struct ieee80211_sta
*sta
,
4322 enum ieee80211_sta_state old_state
,
4323 enum ieee80211_sta_state new_state
)
4325 struct wl1271
*wl
= hw
->priv
;
4326 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4329 wl1271_debug(DEBUG_MAC80211
, "mac80211 sta %d state=%d->%d",
4330 sta
->aid
, old_state
, new_state
);
4332 mutex_lock(&wl
->mutex
);
4334 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4339 ret
= wl1271_ps_elp_wakeup(wl
);
4343 ret
= wl12xx_update_sta_state(wl
, wlvif
, sta
, old_state
, new_state
);
4345 wl1271_ps_elp_sleep(wl
);
4347 mutex_unlock(&wl
->mutex
);
4348 if (new_state
< old_state
)
4353 static int wl1271_op_ampdu_action(struct ieee80211_hw
*hw
,
4354 struct ieee80211_vif
*vif
,
4355 enum ieee80211_ampdu_mlme_action action
,
4356 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4359 struct wl1271
*wl
= hw
->priv
;
4360 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4362 u8 hlid
, *ba_bitmap
;
4364 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu action %d tid %d", action
,
4367 /* sanity check - the fields in FW are only 8bits wide */
4368 if (WARN_ON(tid
> 0xFF))
4371 mutex_lock(&wl
->mutex
);
4373 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4378 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
) {
4379 hlid
= wlvif
->sta
.hlid
;
4380 ba_bitmap
= &wlvif
->sta
.ba_rx_bitmap
;
4381 } else if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
) {
4382 struct wl1271_station
*wl_sta
;
4384 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4385 hlid
= wl_sta
->hlid
;
4386 ba_bitmap
= &wl
->links
[hlid
].ba_bitmap
;
4392 ret
= wl1271_ps_elp_wakeup(wl
);
4396 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu: Rx tid %d action %d",
4400 case IEEE80211_AMPDU_RX_START
:
4401 if (!wlvif
->ba_support
|| !wlvif
->ba_allowed
) {
4406 if (wl
->ba_rx_session_count
>= RX_BA_MAX_SESSIONS
) {
4408 wl1271_error("exceeded max RX BA sessions");
4412 if (*ba_bitmap
& BIT(tid
)) {
4414 wl1271_error("cannot enable RX BA session on active "
4419 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, *ssn
, true,
4422 *ba_bitmap
|= BIT(tid
);
4423 wl
->ba_rx_session_count
++;
4427 case IEEE80211_AMPDU_RX_STOP
:
4428 if (!(*ba_bitmap
& BIT(tid
))) {
4430 wl1271_error("no active RX BA session on tid: %d",
4435 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, 0, false,
4438 *ba_bitmap
&= ~BIT(tid
);
4439 wl
->ba_rx_session_count
--;
4444 * The BA initiator session management in FW independently.
4445 * Falling break here on purpose for all TX APDU commands.
4447 case IEEE80211_AMPDU_TX_START
:
4448 case IEEE80211_AMPDU_TX_STOP
:
4449 case IEEE80211_AMPDU_TX_OPERATIONAL
:
4454 wl1271_error("Incorrect ampdu action id=%x\n", action
);
4458 wl1271_ps_elp_sleep(wl
);
4461 mutex_unlock(&wl
->mutex
);
4466 static int wl12xx_set_bitrate_mask(struct ieee80211_hw
*hw
,
4467 struct ieee80211_vif
*vif
,
4468 const struct cfg80211_bitrate_mask
*mask
)
4470 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4471 struct wl1271
*wl
= hw
->priv
;
4474 wl1271_debug(DEBUG_MAC80211
, "mac80211 set_bitrate_mask 0x%x 0x%x",
4475 mask
->control
[NL80211_BAND_2GHZ
].legacy
,
4476 mask
->control
[NL80211_BAND_5GHZ
].legacy
);
4478 mutex_lock(&wl
->mutex
);
4480 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4481 wlvif
->bitrate_masks
[i
] =
4482 wl1271_tx_enabled_rates_get(wl
,
4483 mask
->control
[i
].legacy
,
4486 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4489 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
4490 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
)) {
4492 ret
= wl1271_ps_elp_wakeup(wl
);
4496 wl1271_set_band_rate(wl
, wlvif
);
4498 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
4499 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
4501 wl1271_ps_elp_sleep(wl
);
4504 mutex_unlock(&wl
->mutex
);
4509 static void wl12xx_op_channel_switch(struct ieee80211_hw
*hw
,
4510 struct ieee80211_channel_switch
*ch_switch
)
4512 struct wl1271
*wl
= hw
->priv
;
4513 struct wl12xx_vif
*wlvif
;
4516 wl1271_debug(DEBUG_MAC80211
, "mac80211 channel switch");
4518 wl1271_tx_flush(wl
);
4520 mutex_lock(&wl
->mutex
);
4522 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4523 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4524 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
4525 ieee80211_chswitch_done(vif
, false);
4530 ret
= wl1271_ps_elp_wakeup(wl
);
4534 /* TODO: change mac80211 to pass vif as param */
4535 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4536 ret
= wl12xx_cmd_channel_switch(wl
, wlvif
, ch_switch
);
4539 set_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
);
4542 wl1271_ps_elp_sleep(wl
);
4545 mutex_unlock(&wl
->mutex
);
4548 static bool wl1271_tx_frames_pending(struct ieee80211_hw
*hw
)
4550 struct wl1271
*wl
= hw
->priv
;
4553 mutex_lock(&wl
->mutex
);
4555 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4558 /* packets are considered pending if in the TX queue or the FW */
4559 ret
= (wl1271_tx_total_queue_count(wl
) > 0) || (wl
->tx_frames_cnt
> 0);
4561 mutex_unlock(&wl
->mutex
);
4566 /* can't be const, mac80211 writes to this */
4567 static struct ieee80211_rate wl1271_rates
[] = {
4569 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
4570 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
4572 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
4573 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
4574 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4576 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
4577 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
4578 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4580 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
4581 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
4582 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4584 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4585 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4587 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4588 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4590 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4591 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4593 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4594 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4596 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4597 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4599 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4600 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4602 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4603 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4605 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4606 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4609 /* can't be const, mac80211 writes to this */
4610 static struct ieee80211_channel wl1271_channels
[] = {
4611 { .hw_value
= 1, .center_freq
= 2412, .max_power
= 25 },
4612 { .hw_value
= 2, .center_freq
= 2417, .max_power
= 25 },
4613 { .hw_value
= 3, .center_freq
= 2422, .max_power
= 25 },
4614 { .hw_value
= 4, .center_freq
= 2427, .max_power
= 25 },
4615 { .hw_value
= 5, .center_freq
= 2432, .max_power
= 25 },
4616 { .hw_value
= 6, .center_freq
= 2437, .max_power
= 25 },
4617 { .hw_value
= 7, .center_freq
= 2442, .max_power
= 25 },
4618 { .hw_value
= 8, .center_freq
= 2447, .max_power
= 25 },
4619 { .hw_value
= 9, .center_freq
= 2452, .max_power
= 25 },
4620 { .hw_value
= 10, .center_freq
= 2457, .max_power
= 25 },
4621 { .hw_value
= 11, .center_freq
= 2462, .max_power
= 25 },
4622 { .hw_value
= 12, .center_freq
= 2467, .max_power
= 25 },
4623 { .hw_value
= 13, .center_freq
= 2472, .max_power
= 25 },
4624 { .hw_value
= 14, .center_freq
= 2484, .max_power
= 25 },
4627 /* mapping to indexes for wl1271_rates */
4628 static const u8 wl1271_rate_to_idx_2ghz
[] = {
4629 /* MCS rates are used only with 11n */
4630 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
4631 7, /* CONF_HW_RXTX_RATE_MCS7 */
4632 6, /* CONF_HW_RXTX_RATE_MCS6 */
4633 5, /* CONF_HW_RXTX_RATE_MCS5 */
4634 4, /* CONF_HW_RXTX_RATE_MCS4 */
4635 3, /* CONF_HW_RXTX_RATE_MCS3 */
4636 2, /* CONF_HW_RXTX_RATE_MCS2 */
4637 1, /* CONF_HW_RXTX_RATE_MCS1 */
4638 0, /* CONF_HW_RXTX_RATE_MCS0 */
4640 11, /* CONF_HW_RXTX_RATE_54 */
4641 10, /* CONF_HW_RXTX_RATE_48 */
4642 9, /* CONF_HW_RXTX_RATE_36 */
4643 8, /* CONF_HW_RXTX_RATE_24 */
4645 /* TI-specific rate */
4646 CONF_HW_RXTX_RATE_UNSUPPORTED
, /* CONF_HW_RXTX_RATE_22 */
4648 7, /* CONF_HW_RXTX_RATE_18 */
4649 6, /* CONF_HW_RXTX_RATE_12 */
4650 3, /* CONF_HW_RXTX_RATE_11 */
4651 5, /* CONF_HW_RXTX_RATE_9 */
4652 4, /* CONF_HW_RXTX_RATE_6 */
4653 2, /* CONF_HW_RXTX_RATE_5_5 */
4654 1, /* CONF_HW_RXTX_RATE_2 */
4655 0 /* CONF_HW_RXTX_RATE_1 */
4658 /* 11n STA capabilities */
4659 #define HW_RX_HIGHEST_RATE 72
4661 #define WL12XX_HT_CAP { \
4662 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4663 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
4664 .ht_supported = true, \
4665 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4666 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4668 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4669 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4670 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4674 /* can't be const, mac80211 writes to this */
4675 static struct ieee80211_supported_band wl1271_band_2ghz
= {
4676 .channels
= wl1271_channels
,
4677 .n_channels
= ARRAY_SIZE(wl1271_channels
),
4678 .bitrates
= wl1271_rates
,
4679 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
4680 .ht_cap
= WL12XX_HT_CAP
,
4683 /* 5 GHz data rates for WL1273 */
4684 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
4686 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4687 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4689 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4690 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4692 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4693 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4695 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4696 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4698 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4699 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4701 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4702 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4704 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4705 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4707 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4708 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4711 /* 5 GHz band channels for WL1273 */
4712 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
4713 { .hw_value
= 7, .center_freq
= 5035, .max_power
= 25 },
4714 { .hw_value
= 8, .center_freq
= 5040, .max_power
= 25 },
4715 { .hw_value
= 9, .center_freq
= 5045, .max_power
= 25 },
4716 { .hw_value
= 11, .center_freq
= 5055, .max_power
= 25 },
4717 { .hw_value
= 12, .center_freq
= 5060, .max_power
= 25 },
4718 { .hw_value
= 16, .center_freq
= 5080, .max_power
= 25 },
4719 { .hw_value
= 34, .center_freq
= 5170, .max_power
= 25 },
4720 { .hw_value
= 36, .center_freq
= 5180, .max_power
= 25 },
4721 { .hw_value
= 38, .center_freq
= 5190, .max_power
= 25 },
4722 { .hw_value
= 40, .center_freq
= 5200, .max_power
= 25 },
4723 { .hw_value
= 42, .center_freq
= 5210, .max_power
= 25 },
4724 { .hw_value
= 44, .center_freq
= 5220, .max_power
= 25 },
4725 { .hw_value
= 46, .center_freq
= 5230, .max_power
= 25 },
4726 { .hw_value
= 48, .center_freq
= 5240, .max_power
= 25 },
4727 { .hw_value
= 52, .center_freq
= 5260, .max_power
= 25 },
4728 { .hw_value
= 56, .center_freq
= 5280, .max_power
= 25 },
4729 { .hw_value
= 60, .center_freq
= 5300, .max_power
= 25 },
4730 { .hw_value
= 64, .center_freq
= 5320, .max_power
= 25 },
4731 { .hw_value
= 100, .center_freq
= 5500, .max_power
= 25 },
4732 { .hw_value
= 104, .center_freq
= 5520, .max_power
= 25 },
4733 { .hw_value
= 108, .center_freq
= 5540, .max_power
= 25 },
4734 { .hw_value
= 112, .center_freq
= 5560, .max_power
= 25 },
4735 { .hw_value
= 116, .center_freq
= 5580, .max_power
= 25 },
4736 { .hw_value
= 120, .center_freq
= 5600, .max_power
= 25 },
4737 { .hw_value
= 124, .center_freq
= 5620, .max_power
= 25 },
4738 { .hw_value
= 128, .center_freq
= 5640, .max_power
= 25 },
4739 { .hw_value
= 132, .center_freq
= 5660, .max_power
= 25 },
4740 { .hw_value
= 136, .center_freq
= 5680, .max_power
= 25 },
4741 { .hw_value
= 140, .center_freq
= 5700, .max_power
= 25 },
4742 { .hw_value
= 149, .center_freq
= 5745, .max_power
= 25 },
4743 { .hw_value
= 153, .center_freq
= 5765, .max_power
= 25 },
4744 { .hw_value
= 157, .center_freq
= 5785, .max_power
= 25 },
4745 { .hw_value
= 161, .center_freq
= 5805, .max_power
= 25 },
4746 { .hw_value
= 165, .center_freq
= 5825, .max_power
= 25 },
4749 /* mapping to indexes for wl1271_rates_5ghz */
4750 static const u8 wl1271_rate_to_idx_5ghz
[] = {
4751 /* MCS rates are used only with 11n */
4752 7, /* CONF_HW_RXTX_RATE_MCS7_SGI */
4753 7, /* CONF_HW_RXTX_RATE_MCS7 */
4754 6, /* CONF_HW_RXTX_RATE_MCS6 */
4755 5, /* CONF_HW_RXTX_RATE_MCS5 */
4756 4, /* CONF_HW_RXTX_RATE_MCS4 */
4757 3, /* CONF_HW_RXTX_RATE_MCS3 */
4758 2, /* CONF_HW_RXTX_RATE_MCS2 */
4759 1, /* CONF_HW_RXTX_RATE_MCS1 */
4760 0, /* CONF_HW_RXTX_RATE_MCS0 */
4762 7, /* CONF_HW_RXTX_RATE_54 */
4763 6, /* CONF_HW_RXTX_RATE_48 */
4764 5, /* CONF_HW_RXTX_RATE_36 */
4765 4, /* CONF_HW_RXTX_RATE_24 */
4767 /* TI-specific rate */
4768 CONF_HW_RXTX_RATE_UNSUPPORTED
, /* CONF_HW_RXTX_RATE_22 */
4770 3, /* CONF_HW_RXTX_RATE_18 */
4771 2, /* CONF_HW_RXTX_RATE_12 */
4772 CONF_HW_RXTX_RATE_UNSUPPORTED
, /* CONF_HW_RXTX_RATE_11 */
4773 1, /* CONF_HW_RXTX_RATE_9 */
4774 0, /* CONF_HW_RXTX_RATE_6 */
4775 CONF_HW_RXTX_RATE_UNSUPPORTED
, /* CONF_HW_RXTX_RATE_5_5 */
4776 CONF_HW_RXTX_RATE_UNSUPPORTED
, /* CONF_HW_RXTX_RATE_2 */
4777 CONF_HW_RXTX_RATE_UNSUPPORTED
/* CONF_HW_RXTX_RATE_1 */
4780 static struct ieee80211_supported_band wl1271_band_5ghz
= {
4781 .channels
= wl1271_channels_5ghz
,
4782 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
4783 .bitrates
= wl1271_rates_5ghz
,
4784 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
4785 .ht_cap
= WL12XX_HT_CAP
,
4788 static const u8
*wl1271_band_rate_to_idx
[] = {
4789 [IEEE80211_BAND_2GHZ
] = wl1271_rate_to_idx_2ghz
,
4790 [IEEE80211_BAND_5GHZ
] = wl1271_rate_to_idx_5ghz
4793 static const struct ieee80211_ops wl1271_ops
= {
4794 .start
= wl1271_op_start
,
4795 .stop
= wl1271_op_stop
,
4796 .add_interface
= wl1271_op_add_interface
,
4797 .remove_interface
= wl1271_op_remove_interface
,
4798 .change_interface
= wl12xx_op_change_interface
,
4800 .suspend
= wl1271_op_suspend
,
4801 .resume
= wl1271_op_resume
,
4803 .config
= wl1271_op_config
,
4804 .prepare_multicast
= wl1271_op_prepare_multicast
,
4805 .configure_filter
= wl1271_op_configure_filter
,
4807 .set_key
= wl1271_op_set_key
,
4808 .hw_scan
= wl1271_op_hw_scan
,
4809 .cancel_hw_scan
= wl1271_op_cancel_hw_scan
,
4810 .sched_scan_start
= wl1271_op_sched_scan_start
,
4811 .sched_scan_stop
= wl1271_op_sched_scan_stop
,
4812 .bss_info_changed
= wl1271_op_bss_info_changed
,
4813 .set_frag_threshold
= wl1271_op_set_frag_threshold
,
4814 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
4815 .conf_tx
= wl1271_op_conf_tx
,
4816 .get_tsf
= wl1271_op_get_tsf
,
4817 .get_survey
= wl1271_op_get_survey
,
4818 .sta_state
= wl12xx_op_sta_state
,
4819 .ampdu_action
= wl1271_op_ampdu_action
,
4820 .tx_frames_pending
= wl1271_tx_frames_pending
,
4821 .set_bitrate_mask
= wl12xx_set_bitrate_mask
,
4822 .channel_switch
= wl12xx_op_channel_switch
,
4823 CFG80211_TESTMODE_CMD(wl1271_tm_cmd
)
4827 u8
wl1271_rate_to_idx(int rate
, enum ieee80211_band band
)
4831 BUG_ON(band
>= sizeof(wl1271_band_rate_to_idx
)/sizeof(u8
*));
4833 if (unlikely(rate
>= CONF_HW_RXTX_RATE_MAX
)) {
4834 wl1271_error("Illegal RX rate from HW: %d", rate
);
4838 idx
= wl1271_band_rate_to_idx
[band
][rate
];
4839 if (unlikely(idx
== CONF_HW_RXTX_RATE_UNSUPPORTED
)) {
4840 wl1271_error("Unsupported RX rate from HW: %d", rate
);
4847 static ssize_t
wl1271_sysfs_show_bt_coex_state(struct device
*dev
,
4848 struct device_attribute
*attr
,
4851 struct wl1271
*wl
= dev_get_drvdata(dev
);
4856 mutex_lock(&wl
->mutex
);
4857 len
= snprintf(buf
, len
, "%d\n\n0 - off\n1 - on\n",
4859 mutex_unlock(&wl
->mutex
);
4865 static ssize_t
wl1271_sysfs_store_bt_coex_state(struct device
*dev
,
4866 struct device_attribute
*attr
,
4867 const char *buf
, size_t count
)
4869 struct wl1271
*wl
= dev_get_drvdata(dev
);
4873 ret
= kstrtoul(buf
, 10, &res
);
4875 wl1271_warning("incorrect value written to bt_coex_mode");
4879 mutex_lock(&wl
->mutex
);
4883 if (res
== wl
->sg_enabled
)
4886 wl
->sg_enabled
= res
;
4888 if (wl
->state
== WL1271_STATE_OFF
)
4891 ret
= wl1271_ps_elp_wakeup(wl
);
4895 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
4896 wl1271_ps_elp_sleep(wl
);
4899 mutex_unlock(&wl
->mutex
);
4903 static DEVICE_ATTR(bt_coex_state
, S_IRUGO
| S_IWUSR
,
4904 wl1271_sysfs_show_bt_coex_state
,
4905 wl1271_sysfs_store_bt_coex_state
);
4907 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
4908 struct device_attribute
*attr
,
4911 struct wl1271
*wl
= dev_get_drvdata(dev
);
4916 mutex_lock(&wl
->mutex
);
4917 if (wl
->hw_pg_ver
>= 0)
4918 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
4920 len
= snprintf(buf
, len
, "n/a\n");
4921 mutex_unlock(&wl
->mutex
);
4926 static DEVICE_ATTR(hw_pg_ver
, S_IRUGO
,
4927 wl1271_sysfs_show_hw_pg_ver
, NULL
);
4929 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
4930 struct bin_attribute
*bin_attr
,
4931 char *buffer
, loff_t pos
, size_t count
)
4933 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4934 struct wl1271
*wl
= dev_get_drvdata(dev
);
4938 ret
= mutex_lock_interruptible(&wl
->mutex
);
4940 return -ERESTARTSYS
;
4942 /* Let only one thread read the log at a time, blocking others */
4943 while (wl
->fwlog_size
== 0) {
4946 prepare_to_wait_exclusive(&wl
->fwlog_waitq
,
4948 TASK_INTERRUPTIBLE
);
4950 if (wl
->fwlog_size
!= 0) {
4951 finish_wait(&wl
->fwlog_waitq
, &wait
);
4955 mutex_unlock(&wl
->mutex
);
4958 finish_wait(&wl
->fwlog_waitq
, &wait
);
4960 if (signal_pending(current
))
4961 return -ERESTARTSYS
;
4963 ret
= mutex_lock_interruptible(&wl
->mutex
);
4965 return -ERESTARTSYS
;
4968 /* Check if the fwlog is still valid */
4969 if (wl
->fwlog_size
< 0) {
4970 mutex_unlock(&wl
->mutex
);
4974 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4975 len
= min(count
, (size_t)wl
->fwlog_size
);
4976 wl
->fwlog_size
-= len
;
4977 memcpy(buffer
, wl
->fwlog
, len
);
4979 /* Make room for new messages */
4980 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
4982 mutex_unlock(&wl
->mutex
);
4987 static struct bin_attribute fwlog_attr
= {
4988 .attr
= {.name
= "fwlog", .mode
= S_IRUSR
},
4989 .read
= wl1271_sysfs_read_fwlog
,
4992 static void wl12xx_derive_mac_addresses(struct wl1271
*wl
,
4993 u32 oui
, u32 nic
, int n
)
4997 wl1271_debug(DEBUG_PROBE
, "base address: oui %06x nic %06x, n %d",
5000 if (nic
+ n
- 1 > 0xffffff)
5001 wl1271_warning("NIC part of the MAC address wraps around!");
5003 for (i
= 0; i
< n
; i
++) {
5004 wl
->addresses
[i
].addr
[0] = (u8
)(oui
>> 16);
5005 wl
->addresses
[i
].addr
[1] = (u8
)(oui
>> 8);
5006 wl
->addresses
[i
].addr
[2] = (u8
) oui
;
5007 wl
->addresses
[i
].addr
[3] = (u8
)(nic
>> 16);
5008 wl
->addresses
[i
].addr
[4] = (u8
)(nic
>> 8);
5009 wl
->addresses
[i
].addr
[5] = (u8
) nic
;
5013 wl
->hw
->wiphy
->n_addresses
= n
;
5014 wl
->hw
->wiphy
->addresses
= wl
->addresses
;
5017 static int wl12xx_get_hw_info(struct wl1271
*wl
)
5021 ret
= wl12xx_set_power_on(wl
);
5025 wl
->chip
.id
= wlcore_read_reg(wl
, REG_CHIP_ID_B
);
5027 wl
->fuse_oui_addr
= 0;
5028 wl
->fuse_nic_addr
= 0;
5030 wl
->hw_pg_ver
= wl
->ops
->get_pg_ver(wl
);
5032 if (wl
->ops
->get_mac
)
5033 wl
->ops
->get_mac(wl
);
5035 wl1271_power_off(wl
);
5040 static int wl1271_register_hw(struct wl1271
*wl
)
5043 u32 oui_addr
= 0, nic_addr
= 0;
5045 if (wl
->mac80211_registered
)
5048 ret
= wl12xx_get_hw_info(wl
);
5050 wl1271_error("couldn't get hw info");
5054 ret
= wl1271_fetch_nvs(wl
);
5056 /* NOTE: The wl->nvs->nvs element must be first, in
5057 * order to simplify the casting, we assume it is at
5058 * the beginning of the wl->nvs structure.
5060 u8
*nvs_ptr
= (u8
*)wl
->nvs
;
5063 (nvs_ptr
[11] << 16) + (nvs_ptr
[10] << 8) + nvs_ptr
[6];
5065 (nvs_ptr
[5] << 16) + (nvs_ptr
[4] << 8) + nvs_ptr
[3];
5068 /* if the MAC address is zeroed in the NVS derive from fuse */
5069 if (oui_addr
== 0 && nic_addr
== 0) {
5070 oui_addr
= wl
->fuse_oui_addr
;
5071 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5072 nic_addr
= wl
->fuse_nic_addr
+ 1;
5075 wl12xx_derive_mac_addresses(wl
, oui_addr
, nic_addr
, 2);
5077 ret
= ieee80211_register_hw(wl
->hw
);
5079 wl1271_error("unable to register mac80211 hw: %d", ret
);
5083 wl
->mac80211_registered
= true;
5085 wl1271_debugfs_init(wl
);
5087 wl1271_notice("loaded");
5093 static void wl1271_unregister_hw(struct wl1271
*wl
)
5096 wl1271_plt_stop(wl
);
5098 ieee80211_unregister_hw(wl
->hw
);
5099 wl
->mac80211_registered
= false;
5103 static int wl1271_init_ieee80211(struct wl1271
*wl
)
5105 static const u32 cipher_suites
[] = {
5106 WLAN_CIPHER_SUITE_WEP40
,
5107 WLAN_CIPHER_SUITE_WEP104
,
5108 WLAN_CIPHER_SUITE_TKIP
,
5109 WLAN_CIPHER_SUITE_CCMP
,
5110 WL1271_CIPHER_SUITE_GEM
,
5113 /* The tx descriptor buffer and the TKIP space. */
5114 wl
->hw
->extra_tx_headroom
= WL1271_EXTRA_SPACE_TKIP
+
5115 sizeof(struct wl1271_tx_hw_descr
);
5118 /* FIXME: find a proper value */
5119 wl
->hw
->channel_change_time
= 10000;
5120 wl
->hw
->max_listen_interval
= wl
->conf
.conn
.max_listen_interval
;
5122 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
5123 IEEE80211_HW_SUPPORTS_PS
|
5124 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
5125 IEEE80211_HW_SUPPORTS_UAPSD
|
5126 IEEE80211_HW_HAS_RATE_CONTROL
|
5127 IEEE80211_HW_CONNECTION_MONITOR
|
5128 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
5129 IEEE80211_HW_SPECTRUM_MGMT
|
5130 IEEE80211_HW_AP_LINK_PS
|
5131 IEEE80211_HW_AMPDU_AGGREGATION
|
5132 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
|
5133 IEEE80211_HW_SCAN_WHILE_IDLE
;
5135 wl
->hw
->wiphy
->cipher_suites
= cipher_suites
;
5136 wl
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
5138 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5139 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_AP
) |
5140 BIT(NL80211_IFTYPE_P2P_CLIENT
) | BIT(NL80211_IFTYPE_P2P_GO
);
5141 wl
->hw
->wiphy
->max_scan_ssids
= 1;
5142 wl
->hw
->wiphy
->max_sched_scan_ssids
= 16;
5143 wl
->hw
->wiphy
->max_match_sets
= 16;
5145 * Maximum length of elements in scanning probe request templates
5146 * should be the maximum length possible for a template, without
5147 * the IEEE80211 header of the template
5149 wl
->hw
->wiphy
->max_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5150 sizeof(struct ieee80211_header
);
5152 wl
->hw
->wiphy
->max_sched_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5153 sizeof(struct ieee80211_header
);
5155 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
5157 /* make sure all our channels fit in the scanned_ch bitmask */
5158 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels
) +
5159 ARRAY_SIZE(wl1271_channels_5ghz
) >
5160 WL1271_MAX_CHANNELS
);
5162 * We keep local copies of the band structs because we need to
5163 * modify them on a per-device basis.
5165 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
], &wl1271_band_2ghz
,
5166 sizeof(wl1271_band_2ghz
));
5167 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
], &wl1271_band_5ghz
,
5168 sizeof(wl1271_band_5ghz
));
5170 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5171 &wl
->bands
[IEEE80211_BAND_2GHZ
];
5172 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5173 &wl
->bands
[IEEE80211_BAND_5GHZ
];
5176 wl
->hw
->max_rates
= 1;
5178 wl
->hw
->wiphy
->reg_notifier
= wl1271_reg_notify
;
5180 /* the FW answers probe-requests in AP-mode */
5181 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5182 wl
->hw
->wiphy
->probe_resp_offload
=
5183 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5184 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5185 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5187 SET_IEEE80211_DEV(wl
->hw
, wl
->dev
);
5189 wl
->hw
->sta_data_size
= sizeof(struct wl1271_station
);
5190 wl
->hw
->vif_data_size
= sizeof(struct wl12xx_vif
);
5192 wl
->hw
->max_rx_aggregation_subframes
= 8;
5197 #define WL1271_DEFAULT_CHANNEL 0
5199 struct ieee80211_hw
*wlcore_alloc_hw(size_t priv_size
)
5201 struct ieee80211_hw
*hw
;
5206 BUILD_BUG_ON(AP_MAX_STATIONS
> WL12XX_MAX_LINKS
);
5208 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
5210 wl1271_error("could not alloc ieee80211_hw");
5216 memset(wl
, 0, sizeof(*wl
));
5218 wl
->priv
= kzalloc(priv_size
, GFP_KERNEL
);
5220 wl1271_error("could not alloc wl priv");
5222 goto err_priv_alloc
;
5225 INIT_LIST_HEAD(&wl
->wlvif_list
);
5229 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
5230 for (j
= 0; j
< WL12XX_MAX_LINKS
; j
++)
5231 skb_queue_head_init(&wl
->links
[j
].tx_queue
[i
]);
5233 skb_queue_head_init(&wl
->deferred_rx_queue
);
5234 skb_queue_head_init(&wl
->deferred_tx_queue
);
5236 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
5237 INIT_WORK(&wl
->netstack_work
, wl1271_netstack_work
);
5238 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
5239 INIT_WORK(&wl
->recovery_work
, wl1271_recovery_work
);
5240 INIT_DELAYED_WORK(&wl
->scan_complete_work
, wl1271_scan_complete_work
);
5241 INIT_DELAYED_WORK(&wl
->tx_watchdog_work
, wl12xx_tx_watchdog_work
);
5243 wl
->freezable_wq
= create_freezable_workqueue("wl12xx_wq");
5244 if (!wl
->freezable_wq
) {
5249 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
5251 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
5252 wl
->band
= IEEE80211_BAND_2GHZ
;
5254 wl
->sg_enabled
= true;
5257 wl
->ap_fw_ps_map
= 0;
5259 wl
->platform_quirks
= 0;
5260 wl
->sched_scanning
= false;
5261 wl
->system_hlid
= WL12XX_SYSTEM_HLID
;
5262 wl
->active_sta_count
= 0;
5264 init_waitqueue_head(&wl
->fwlog_waitq
);
5266 /* The system link is always allocated */
5267 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
5269 memset(wl
->tx_frames_map
, 0, sizeof(wl
->tx_frames_map
));
5270 for (i
= 0; i
< wl
->num_tx_desc
; i
++)
5271 wl
->tx_frames
[i
] = NULL
;
5273 spin_lock_init(&wl
->wl_lock
);
5275 wl
->state
= WL1271_STATE_OFF
;
5276 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5277 mutex_init(&wl
->mutex
);
5279 /* Apply default driver configuration. */
5280 wl1271_conf_init(wl
);
5282 order
= get_order(WL1271_AGGR_BUFFER_SIZE
);
5283 wl
->aggr_buf
= (u8
*)__get_free_pages(GFP_KERNEL
, order
);
5284 if (!wl
->aggr_buf
) {
5289 wl
->dummy_packet
= wl12xx_alloc_dummy_packet(wl
);
5290 if (!wl
->dummy_packet
) {
5295 /* Allocate one page for the FW log */
5296 wl
->fwlog
= (u8
*)get_zeroed_page(GFP_KERNEL
);
5299 goto err_dummy_packet
;
5302 wl
->mbox
= kmalloc(sizeof(*wl
->mbox
), GFP_DMA
);
5311 free_page((unsigned long)wl
->fwlog
);
5314 dev_kfree_skb(wl
->dummy_packet
);
5317 free_pages((unsigned long)wl
->aggr_buf
, order
);
5320 destroy_workqueue(wl
->freezable_wq
);
5323 wl1271_debugfs_exit(wl
);
5327 ieee80211_free_hw(hw
);
5331 return ERR_PTR(ret
);
5333 EXPORT_SYMBOL_GPL(wlcore_alloc_hw
);
5335 int wlcore_free_hw(struct wl1271
*wl
)
5337 /* Unblock any fwlog readers */
5338 mutex_lock(&wl
->mutex
);
5339 wl
->fwlog_size
= -1;
5340 wake_up_interruptible_all(&wl
->fwlog_waitq
);
5341 mutex_unlock(&wl
->mutex
);
5343 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
5345 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5347 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5348 free_page((unsigned long)wl
->fwlog
);
5349 dev_kfree_skb(wl
->dummy_packet
);
5350 free_pages((unsigned long)wl
->aggr_buf
,
5351 get_order(WL1271_AGGR_BUFFER_SIZE
));
5353 wl1271_debugfs_exit(wl
);
5357 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5361 kfree(wl
->fw_status
);
5362 kfree(wl
->tx_res_if
);
5363 destroy_workqueue(wl
->freezable_wq
);
5366 ieee80211_free_hw(wl
->hw
);
5370 EXPORT_SYMBOL_GPL(wlcore_free_hw
);
5372 static irqreturn_t
wl12xx_hardirq(int irq
, void *cookie
)
5374 struct wl1271
*wl
= cookie
;
5375 unsigned long flags
;
5377 wl1271_debug(DEBUG_IRQ
, "IRQ");
5379 /* complete the ELP completion */
5380 spin_lock_irqsave(&wl
->wl_lock
, flags
);
5381 set_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
5382 if (wl
->elp_compl
) {
5383 complete(wl
->elp_compl
);
5384 wl
->elp_compl
= NULL
;
5387 if (test_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
)) {
5388 /* don't enqueue a work right now. mark it as pending */
5389 set_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
);
5390 wl1271_debug(DEBUG_IRQ
, "should not enqueue work");
5391 disable_irq_nosync(wl
->irq
);
5392 pm_wakeup_event(wl
->dev
, 0);
5393 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5396 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5398 return IRQ_WAKE_THREAD
;
5401 int __devinit
wlcore_probe(struct wl1271
*wl
, struct platform_device
*pdev
)
5403 struct wl12xx_platform_data
*pdata
= pdev
->dev
.platform_data
;
5404 unsigned long irqflags
;
5407 if (!wl
->ops
|| !wl
->ptable
) {
5412 BUG_ON(wl
->num_tx_desc
> WLCORE_MAX_TX_DESCRIPTORS
);
5414 wl
->irq
= platform_get_irq(pdev
, 0);
5415 wl
->ref_clock
= pdata
->board_ref_clock
;
5416 wl
->tcxo_clock
= pdata
->board_tcxo_clock
;
5417 wl
->platform_quirks
= pdata
->platform_quirks
;
5418 wl
->set_power
= pdata
->set_power
;
5419 wl
->dev
= &pdev
->dev
;
5420 wl
->if_ops
= pdata
->ops
;
5422 platform_set_drvdata(pdev
, wl
);
5424 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
5425 irqflags
= IRQF_TRIGGER_RISING
;
5427 irqflags
= IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
;
5429 ret
= request_threaded_irq(wl
->irq
, wl12xx_hardirq
, wl1271_irq
,
5433 wl1271_error("request_irq() failed: %d", ret
);
5437 ret
= enable_irq_wake(wl
->irq
);
5439 wl
->irq_wake_enabled
= true;
5440 device_init_wakeup(wl
->dev
, 1);
5441 if (pdata
->pwr_in_suspend
)
5442 wl
->hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_ANY
;
5445 disable_irq(wl
->irq
);
5447 ret
= wl1271_init_ieee80211(wl
);
5451 ret
= wl1271_register_hw(wl
);
5455 /* Create sysfs file to control bt coex state */
5456 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
5458 wl1271_error("failed to create sysfs file bt_coex_state");
5462 /* Create sysfs file to get HW PG version */
5463 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5465 wl1271_error("failed to create sysfs file hw_pg_ver");
5466 goto out_bt_coex_state
;
5469 /* Create sysfs file for the FW log */
5470 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
5472 wl1271_error("failed to create sysfs file fwlog");
5479 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5482 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5485 free_irq(wl
->irq
, wl
);
5493 EXPORT_SYMBOL_GPL(wlcore_probe
);
5495 int __devexit
wlcore_remove(struct platform_device
*pdev
)
5497 struct wl1271
*wl
= platform_get_drvdata(pdev
);
5499 if (wl
->irq_wake_enabled
) {
5500 device_init_wakeup(wl
->dev
, 0);
5501 disable_irq_wake(wl
->irq
);
5503 wl1271_unregister_hw(wl
);
5504 free_irq(wl
->irq
, wl
);
5509 EXPORT_SYMBOL_GPL(wlcore_remove
);
5511 u32 wl12xx_debug_level
= DEBUG_NONE
;
5512 EXPORT_SYMBOL_GPL(wl12xx_debug_level
);
5513 module_param_named(debug_level
, wl12xx_debug_level
, uint
, S_IRUSR
| S_IWUSR
);
5514 MODULE_PARM_DESC(debug_level
, "wl12xx debugging level");
5516 module_param_named(fwlog
, fwlog_param
, charp
, 0);
5517 MODULE_PARM_DESC(fwlog
,
5518 "FW logger options: continuous, ondemand, dbgpins or disable");
5520 module_param(bug_on_recovery
, bool, S_IRUSR
| S_IWUSR
);
5521 MODULE_PARM_DESC(bug_on_recovery
, "BUG() on fw recovery");
5523 MODULE_LICENSE("GPL");
5524 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5525 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");