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"
54 #define WL1271_BOOT_RETRIES 3
56 static struct conf_drv_settings default_conf
= {
59 [CONF_SG_ACL_BT_MASTER_MIN_BR
] = 10,
60 [CONF_SG_ACL_BT_MASTER_MAX_BR
] = 180,
61 [CONF_SG_ACL_BT_SLAVE_MIN_BR
] = 10,
62 [CONF_SG_ACL_BT_SLAVE_MAX_BR
] = 180,
63 [CONF_SG_ACL_BT_MASTER_MIN_EDR
] = 10,
64 [CONF_SG_ACL_BT_MASTER_MAX_EDR
] = 80,
65 [CONF_SG_ACL_BT_SLAVE_MIN_EDR
] = 10,
66 [CONF_SG_ACL_BT_SLAVE_MAX_EDR
] = 80,
67 [CONF_SG_ACL_WLAN_PS_MASTER_BR
] = 8,
68 [CONF_SG_ACL_WLAN_PS_SLAVE_BR
] = 8,
69 [CONF_SG_ACL_WLAN_PS_MASTER_EDR
] = 20,
70 [CONF_SG_ACL_WLAN_PS_SLAVE_EDR
] = 20,
71 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_BR
] = 20,
72 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_BR
] = 35,
73 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_BR
] = 16,
74 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_BR
] = 35,
75 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MIN_EDR
] = 32,
76 [CONF_SG_ACL_WLAN_ACTIVE_MASTER_MAX_EDR
] = 50,
77 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MIN_EDR
] = 28,
78 [CONF_SG_ACL_WLAN_ACTIVE_SLAVE_MAX_EDR
] = 50,
79 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_BR
] = 10,
80 [CONF_SG_ACL_ACTIVE_SCAN_WLAN_EDR
] = 20,
81 [CONF_SG_ACL_PASSIVE_SCAN_BT_BR
] = 75,
82 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_BR
] = 15,
83 [CONF_SG_ACL_PASSIVE_SCAN_BT_EDR
] = 27,
84 [CONF_SG_ACL_PASSIVE_SCAN_WLAN_EDR
] = 17,
85 /* active scan params */
86 [CONF_SG_AUTO_SCAN_PROBE_REQ
] = 170,
87 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_HV3
] = 50,
88 [CONF_SG_ACTIVE_SCAN_DURATION_FACTOR_A2DP
] = 100,
89 /* passive scan params */
90 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_BR
] = 800,
91 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_A2DP_EDR
] = 200,
92 [CONF_SG_PASSIVE_SCAN_DURATION_FACTOR_HV3
] = 200,
93 /* passive scan in dual antenna params */
94 [CONF_SG_CONSECUTIVE_HV3_IN_PASSIVE_SCAN
] = 0,
95 [CONF_SG_BCN_HV3_COLLISION_THRESH_IN_PASSIVE_SCAN
] = 0,
96 [CONF_SG_TX_RX_PROTECTION_BWIDTH_IN_PASSIVE_SCAN
] = 0,
98 [CONF_SG_STA_FORCE_PS_IN_BT_SCO
] = 1,
99 [CONF_SG_ANTENNA_CONFIGURATION
] = 0,
100 [CONF_SG_BEACON_MISS_PERCENT
] = 60,
101 [CONF_SG_DHCP_TIME
] = 5000,
102 [CONF_SG_RXT
] = 1200,
103 [CONF_SG_TXT
] = 1000,
104 [CONF_SG_ADAPTIVE_RXT_TXT
] = 1,
105 [CONF_SG_GENERAL_USAGE_BIT_MAP
] = 3,
106 [CONF_SG_HV3_MAX_SERVED
] = 6,
107 [CONF_SG_PS_POLL_TIMEOUT
] = 10,
108 [CONF_SG_UPSD_TIMEOUT
] = 10,
109 [CONF_SG_CONSECUTIVE_CTS_THRESHOLD
] = 2,
110 [CONF_SG_STA_RX_WINDOW_AFTER_DTIM
] = 5,
111 [CONF_SG_STA_CONNECTION_PROTECTION_TIME
] = 30,
113 [CONF_AP_BEACON_MISS_TX
] = 3,
114 [CONF_AP_RX_WINDOW_AFTER_BEACON
] = 10,
115 [CONF_AP_BEACON_WINDOW_INTERVAL
] = 2,
116 [CONF_AP_CONNECTION_PROTECTION_TIME
] = 0,
117 [CONF_AP_BT_ACL_VAL_BT_SERVE_TIME
] = 25,
118 [CONF_AP_BT_ACL_VAL_WL_SERVE_TIME
] = 25,
119 /* CTS Diluting params */
120 [CONF_SG_CTS_DILUTED_BAD_RX_PACKETS_TH
] = 0,
121 [CONF_SG_CTS_CHOP_IN_DUAL_ANT_SCO_MASTER
] = 0,
123 .state
= CONF_SG_PROTECTIVE
,
126 .rx_msdu_life_time
= 512000,
127 .packet_detection_threshold
= 0,
128 .ps_poll_timeout
= 15,
130 .rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
,
131 .rx_cca_threshold
= 0,
132 .irq_blk_threshold
= 0xFFFF,
133 .irq_pkt_threshold
= 0,
135 .queue_type
= CONF_RX_QUEUE_TYPE_LOW_PRIORITY
,
138 .tx_energy_detection
= 0,
141 .short_retry_limit
= 10,
142 .long_retry_limit
= 10,
165 .aifsn
= CONF_TX_AIFS_PIFS
,
172 .aifsn
= CONF_TX_AIFS_PIFS
,
176 .max_tx_retries
= 100,
177 .ap_aging_period
= 300,
181 .queue_id
= CONF_TX_AC_BE
,
182 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
183 .tsid
= CONF_TX_AC_BE
,
184 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
185 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
189 .queue_id
= CONF_TX_AC_BK
,
190 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
191 .tsid
= CONF_TX_AC_BK
,
192 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
193 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
197 .queue_id
= CONF_TX_AC_VI
,
198 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
199 .tsid
= CONF_TX_AC_VI
,
200 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
201 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
205 .queue_id
= CONF_TX_AC_VO
,
206 .channel_type
= CONF_CHANNEL_TYPE_EDCF
,
207 .tsid
= CONF_TX_AC_VO
,
208 .ps_scheme
= CONF_PS_SCHEME_LEGACY
,
209 .ack_policy
= CONF_ACK_POLICY_LEGACY
,
213 .frag_threshold
= IEEE80211_MAX_FRAG_THRESHOLD
,
214 .tx_compl_timeout
= 700,
215 .tx_compl_threshold
= 4,
216 .basic_rate
= CONF_HW_BIT_RATE_1MBPS
,
217 .basic_rate_5
= CONF_HW_BIT_RATE_6MBPS
,
218 .tmpl_short_retry_limit
= 10,
219 .tmpl_long_retry_limit
= 10,
220 .tx_watchdog_timeout
= 5000,
223 .wake_up_event
= CONF_WAKE_UP_EVENT_DTIM
,
224 .listen_interval
= 1,
225 .suspend_wake_up_event
= CONF_WAKE_UP_EVENT_N_DTIM
,
226 .suspend_listen_interval
= 3,
227 .bcn_filt_mode
= CONF_BCN_FILT_MODE_ENABLED
,
228 .bcn_filt_ie_count
= 2,
231 .ie
= WLAN_EID_CHANNEL_SWITCH
,
232 .rule
= CONF_BCN_RULE_PASS_ON_APPEARANCE
,
235 .ie
= WLAN_EID_HT_OPERATION
,
236 .rule
= CONF_BCN_RULE_PASS_ON_CHANGE
,
239 .synch_fail_thold
= 10,
240 .bss_lose_timeout
= 100,
241 .beacon_rx_timeout
= 10000,
242 .broadcast_timeout
= 20000,
243 .rx_broadcast_in_ps
= 1,
244 .ps_poll_threshold
= 10,
245 .bet_enable
= CONF_BET_MODE_ENABLE
,
246 .bet_max_consecutive
= 50,
247 .psm_entry_retries
= 8,
248 .psm_exit_retries
= 16,
249 .psm_entry_nullfunc_retries
= 3,
250 .dynamic_ps_timeout
= 200,
252 .keep_alive_interval
= 55000,
253 .max_listen_interval
= 20,
260 .host_clk_settling_time
= 5000,
261 .host_fast_wakeup_support
= false
265 .avg_weight_rssi_beacon
= 20,
266 .avg_weight_rssi_data
= 10,
267 .avg_weight_snr_beacon
= 20,
268 .avg_weight_snr_data
= 10,
271 .min_dwell_time_active
= 7500,
272 .max_dwell_time_active
= 30000,
273 .min_dwell_time_passive
= 100000,
274 .max_dwell_time_passive
= 100000,
276 .split_scan_timeout
= 50000,
280 * Values are in TU/1000 but since sched scan FW command
281 * params are in TUs rounding up may occur.
283 .base_dwell_time
= 7500,
284 .max_dwell_time_delta
= 22500,
285 /* based on 250bits per probe @1Mbps */
286 .dwell_time_delta_per_probe
= 2000,
287 /* based on 250bits per probe @6Mbps (plus a bit more) */
288 .dwell_time_delta_per_probe_5
= 350,
289 .dwell_time_passive
= 100000,
290 .dwell_time_dfs
= 150000,
292 .rssi_threshold
= -90,
296 .tx_per_channel_power_compensation_2
= {
297 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
299 .tx_per_channel_power_compensation_5
= {
300 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
301 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
307 .tx_ba_win_size
= 64,
308 .inactivity_timeout
= 10000,
309 .tx_ba_tid_bitmap
= CONF_TX_BA_ENABLED_TID_BITMAP
,
315 .tx_min_block_num
= 40,
317 .min_req_tx_blocks
= 100,
318 .min_req_rx_blocks
= 22,
325 .tx_min_block_num
= 40,
327 .min_req_tx_blocks
= 45,
328 .min_req_rx_blocks
= 22,
334 .n_divider_fref_set_1
= 0xff, /* default */
335 .n_divider_fref_set_2
= 12,
336 .m_divider_fref_set_1
= 148,
337 .m_divider_fref_set_2
= 0xffff, /* default */
338 .coex_pll_stabilization_time
= 0xffffffff, /* default */
339 .ldo_stabilization_time
= 0xffff, /* default */
340 .fm_disturbed_band_margin
= 0xff, /* default */
341 .swallow_clk_diff
= 0xff, /* default */
350 .mode
= WL12XX_FWLOG_ON_DEMAND
,
353 .timestamp
= WL12XX_FWLOG_TIMESTAMP_DISABLED
,
354 .output
= WL12XX_FWLOG_OUTPUT_HOST
,
358 .rate_retry_score
= 32000,
363 .inverse_curiosity_factor
= 5,
365 .tx_fail_high_th
= 10,
366 .per_alpha_shift
= 4,
368 .per_beta1_shift
= 10,
369 .per_beta2_shift
= 8,
371 .rate_check_down
= 12,
372 .rate_retry_policy
= {
373 0x00, 0x00, 0x00, 0x00, 0x00,
374 0x00, 0x00, 0x00, 0x00, 0x00,
380 .hangover_period
= 20,
382 .early_termination_mode
= 1,
393 static char *fwlog_param
;
394 static bool bug_on_recovery
;
396 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
397 struct ieee80211_vif
*vif
,
398 bool reset_tx_queues
);
399 static void wl1271_op_stop(struct ieee80211_hw
*hw
);
400 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
);
402 static int wl12xx_set_authorized(struct wl1271
*wl
,
403 struct wl12xx_vif
*wlvif
)
407 if (WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
))
410 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
413 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT
, &wlvif
->flags
))
416 ret
= wl12xx_cmd_set_peer_state(wl
, wlvif
->sta
.hlid
);
420 wl12xx_croc(wl
, wlvif
->role_id
);
422 wl1271_info("Association completed.");
426 static int wl1271_reg_notify(struct wiphy
*wiphy
,
427 struct regulatory_request
*request
)
429 struct ieee80211_supported_band
*band
;
430 struct ieee80211_channel
*ch
;
433 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
434 for (i
= 0; i
< band
->n_channels
; i
++) {
435 ch
= &band
->channels
[i
];
436 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
439 if (ch
->flags
& IEEE80211_CHAN_RADAR
)
440 ch
->flags
|= IEEE80211_CHAN_NO_IBSS
|
441 IEEE80211_CHAN_PASSIVE_SCAN
;
448 static int wl1271_set_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
453 /* we should hold wl->mutex */
454 ret
= wl1271_acx_ps_rx_streaming(wl
, wlvif
, enable
);
459 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
461 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
467 * this function is being called when the rx_streaming interval
468 * has beed changed or rx_streaming should be disabled
470 int wl1271_recalc_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
473 int period
= wl
->conf
.rx_streaming
.interval
;
475 /* don't reconfigure if rx_streaming is disabled */
476 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
479 /* reconfigure/disable according to new streaming_period */
481 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
482 (wl
->conf
.rx_streaming
.always
||
483 test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
484 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
486 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
487 /* don't cancel_work_sync since we might deadlock */
488 del_timer_sync(&wlvif
->rx_streaming_timer
);
494 static void wl1271_rx_streaming_enable_work(struct work_struct
*work
)
497 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
498 rx_streaming_enable_work
);
499 struct wl1271
*wl
= wlvif
->wl
;
501 mutex_lock(&wl
->mutex
);
503 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
) ||
504 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
505 (!wl
->conf
.rx_streaming
.always
&&
506 !test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
509 if (!wl
->conf
.rx_streaming
.interval
)
512 ret
= wl1271_ps_elp_wakeup(wl
);
516 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
520 /* stop it after some time of inactivity */
521 mod_timer(&wlvif
->rx_streaming_timer
,
522 jiffies
+ msecs_to_jiffies(wl
->conf
.rx_streaming
.duration
));
525 wl1271_ps_elp_sleep(wl
);
527 mutex_unlock(&wl
->mutex
);
530 static void wl1271_rx_streaming_disable_work(struct work_struct
*work
)
533 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
534 rx_streaming_disable_work
);
535 struct wl1271
*wl
= wlvif
->wl
;
537 mutex_lock(&wl
->mutex
);
539 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
542 ret
= wl1271_ps_elp_wakeup(wl
);
546 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
551 wl1271_ps_elp_sleep(wl
);
553 mutex_unlock(&wl
->mutex
);
556 static void wl1271_rx_streaming_timer(unsigned long data
)
558 struct wl12xx_vif
*wlvif
= (struct wl12xx_vif
*)data
;
559 struct wl1271
*wl
= wlvif
->wl
;
560 ieee80211_queue_work(wl
->hw
, &wlvif
->rx_streaming_disable_work
);
563 /* wl->mutex must be taken */
564 void wl12xx_rearm_tx_watchdog_locked(struct wl1271
*wl
)
566 /* if the watchdog is not armed, don't do anything */
567 if (wl
->tx_allocated_blocks
== 0)
570 cancel_delayed_work(&wl
->tx_watchdog_work
);
571 ieee80211_queue_delayed_work(wl
->hw
, &wl
->tx_watchdog_work
,
572 msecs_to_jiffies(wl
->conf
.tx
.tx_watchdog_timeout
));
575 static void wl12xx_tx_watchdog_work(struct work_struct
*work
)
577 struct delayed_work
*dwork
;
580 dwork
= container_of(work
, struct delayed_work
, work
);
581 wl
= container_of(dwork
, struct wl1271
, tx_watchdog_work
);
583 mutex_lock(&wl
->mutex
);
585 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
588 /* Tx went out in the meantime - everything is ok */
589 if (unlikely(wl
->tx_allocated_blocks
== 0))
593 * if a ROC is in progress, we might not have any Tx for a long
594 * time (e.g. pending Tx on the non-ROC channels)
596 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
597 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to ROC",
598 wl
->conf
.tx
.tx_watchdog_timeout
);
599 wl12xx_rearm_tx_watchdog_locked(wl
);
604 * if a scan is in progress, we might not have any Tx for a long
607 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
) {
608 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to scan",
609 wl
->conf
.tx
.tx_watchdog_timeout
);
610 wl12xx_rearm_tx_watchdog_locked(wl
);
615 * AP might cache a frame for a long time for a sleeping station,
616 * so rearm the timer if there's an AP interface with stations. If
617 * Tx is genuinely stuck we will most hopefully discover it when all
618 * stations are removed due to inactivity.
620 if (wl
->active_sta_count
) {
621 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms. AP has "
623 wl
->conf
.tx
.tx_watchdog_timeout
,
624 wl
->active_sta_count
);
625 wl12xx_rearm_tx_watchdog_locked(wl
);
629 wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
630 wl
->conf
.tx
.tx_watchdog_timeout
);
631 wl12xx_queue_recovery_work(wl
);
634 mutex_unlock(&wl
->mutex
);
637 static void wl1271_conf_init(struct wl1271
*wl
)
641 * This function applies the default configuration to the driver. This
642 * function is invoked upon driver load (spi probe.)
644 * The configuration is stored in a run-time structure in order to
645 * facilitate for run-time adjustment of any of the parameters. Making
646 * changes to the configuration structure will apply the new values on
647 * the next interface up (wl1271_op_start.)
650 /* apply driver default configuration */
651 memcpy(&wl
->conf
, &default_conf
, sizeof(default_conf
));
653 /* Adjust settings according to optional module parameters */
655 if (!strcmp(fwlog_param
, "continuous")) {
656 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
657 } else if (!strcmp(fwlog_param
, "ondemand")) {
658 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_ON_DEMAND
;
659 } else if (!strcmp(fwlog_param
, "dbgpins")) {
660 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
661 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_DBG_PINS
;
662 } else if (!strcmp(fwlog_param
, "disable")) {
663 wl
->conf
.fwlog
.mem_blocks
= 0;
664 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_NONE
;
666 wl1271_error("Unknown fwlog parameter %s", fwlog_param
);
671 static int wl1271_plt_init(struct wl1271
*wl
)
675 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
676 ret
= wl128x_cmd_general_parms(wl
);
678 ret
= wl1271_cmd_general_parms(wl
);
682 if (wl
->chip
.id
== CHIP_ID_1283_PG20
)
683 ret
= wl128x_cmd_radio_parms(wl
);
685 ret
= wl1271_cmd_radio_parms(wl
);
689 if (wl
->chip
.id
!= CHIP_ID_1283_PG20
) {
690 ret
= wl1271_cmd_ext_radio_parms(wl
);
695 /* Chip-specific initializations */
696 ret
= wl1271_chip_specific_init(wl
);
700 ret
= wl1271_acx_init_mem_config(wl
);
704 ret
= wl12xx_acx_mem_cfg(wl
);
706 goto out_free_memmap
;
708 /* Enable data path */
709 ret
= wl1271_cmd_data_path(wl
, 1);
711 goto out_free_memmap
;
713 /* Configure for CAM power saving (ie. always active) */
714 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
716 goto out_free_memmap
;
719 ret
= wl1271_acx_pm_config(wl
);
721 goto out_free_memmap
;
726 kfree(wl
->target_mem_map
);
727 wl
->target_mem_map
= NULL
;
732 static void wl12xx_irq_ps_regulate_link(struct wl1271
*wl
,
733 struct wl12xx_vif
*wlvif
,
736 bool fw_ps
, single_sta
;
738 fw_ps
= test_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
739 single_sta
= (wl
->active_sta_count
== 1);
742 * Wake up from high level PS if the STA is asleep with too little
743 * packets in FW or if the STA is awake.
745 if (!fw_ps
|| tx_pkts
< WL1271_PS_STA_MAX_PACKETS
)
746 wl12xx_ps_link_end(wl
, wlvif
, hlid
);
749 * Start high-level PS if the STA is asleep with enough blocks in FW.
750 * Make an exception if this is the only connected station. In this
751 * case FW-memory congestion is not a problem.
753 else if (!single_sta
&& fw_ps
&& tx_pkts
>= WL1271_PS_STA_MAX_PACKETS
)
754 wl12xx_ps_link_start(wl
, wlvif
, hlid
, true);
757 static void wl12xx_irq_update_links_status(struct wl1271
*wl
,
758 struct wl12xx_vif
*wlvif
,
759 struct wl12xx_fw_status
*status
)
761 struct wl1271_link
*lnk
;
765 /* TODO: also use link_fast_bitmap here */
767 cur_fw_ps_map
= le32_to_cpu(status
->link_ps_bitmap
);
768 if (wl
->ap_fw_ps_map
!= cur_fw_ps_map
) {
769 wl1271_debug(DEBUG_PSM
,
770 "link ps prev 0x%x cur 0x%x changed 0x%x",
771 wl
->ap_fw_ps_map
, cur_fw_ps_map
,
772 wl
->ap_fw_ps_map
^ cur_fw_ps_map
);
774 wl
->ap_fw_ps_map
= cur_fw_ps_map
;
777 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
, WL12XX_MAX_LINKS
) {
778 lnk
= &wl
->links
[hlid
];
779 cnt
= status
->tx_lnk_free_pkts
[hlid
] - lnk
->prev_freed_pkts
;
781 lnk
->prev_freed_pkts
= status
->tx_lnk_free_pkts
[hlid
];
782 lnk
->allocated_pkts
-= cnt
;
784 wl12xx_irq_ps_regulate_link(wl
, wlvif
, hlid
,
785 lnk
->allocated_pkts
);
789 static void wl12xx_fw_status(struct wl1271
*wl
,
790 struct wl12xx_fw_status
*status
)
792 struct wl12xx_vif
*wlvif
;
794 u32 old_tx_blk_count
= wl
->tx_blocks_available
;
795 int avail
, freed_blocks
;
798 wlcore_raw_read_data(wl
, REG_RAW_FW_STATUS_ADDR
, status
,
799 sizeof(*status
), false);
801 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
802 "drv_rx_counter = %d, tx_results_counter = %d)",
804 status
->fw_rx_counter
,
805 status
->drv_rx_counter
,
806 status
->tx_results_counter
);
808 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
809 /* prevent wrap-around in freed-packets counter */
810 wl
->tx_allocated_pkts
[i
] -=
811 (status
->tx_released_pkts
[i
] -
812 wl
->tx_pkts_freed
[i
]) & 0xff;
814 wl
->tx_pkts_freed
[i
] = status
->tx_released_pkts
[i
];
817 /* prevent wrap-around in total blocks counter */
818 if (likely(wl
->tx_blocks_freed
<=
819 le32_to_cpu(status
->total_released_blks
)))
820 freed_blocks
= le32_to_cpu(status
->total_released_blks
) -
823 freed_blocks
= 0x100000000LL
- wl
->tx_blocks_freed
+
824 le32_to_cpu(status
->total_released_blks
);
826 wl
->tx_blocks_freed
= le32_to_cpu(status
->total_released_blks
);
828 wl
->tx_allocated_blocks
-= freed_blocks
;
831 * If the FW freed some blocks:
832 * If we still have allocated blocks - re-arm the timer, Tx is
833 * not stuck. Otherwise, cancel the timer (no Tx currently).
836 if (wl
->tx_allocated_blocks
)
837 wl12xx_rearm_tx_watchdog_locked(wl
);
839 cancel_delayed_work(&wl
->tx_watchdog_work
);
842 avail
= le32_to_cpu(status
->tx_total
) - wl
->tx_allocated_blocks
;
845 * The FW might change the total number of TX memblocks before
846 * we get a notification about blocks being released. Thus, the
847 * available blocks calculation might yield a temporary result
848 * which is lower than the actual available blocks. Keeping in
849 * mind that only blocks that were allocated can be moved from
850 * TX to RX, tx_blocks_available should never decrease here.
852 wl
->tx_blocks_available
= max((int)wl
->tx_blocks_available
,
855 /* if more blocks are available now, tx work can be scheduled */
856 if (wl
->tx_blocks_available
> old_tx_blk_count
)
857 clear_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
);
859 /* for AP update num of allocated TX blocks per link and ps status */
860 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
861 wl12xx_irq_update_links_status(wl
, wlvif
, status
);
864 /* update the host-chipset time offset */
866 wl
->time_offset
= (timespec_to_ns(&ts
) >> 10) -
867 (s64
)le32_to_cpu(status
->fw_localtime
);
870 static void wl1271_flush_deferred_work(struct wl1271
*wl
)
874 /* Pass all received frames to the network stack */
875 while ((skb
= skb_dequeue(&wl
->deferred_rx_queue
)))
876 ieee80211_rx_ni(wl
->hw
, skb
);
878 /* Return sent skbs to the network stack */
879 while ((skb
= skb_dequeue(&wl
->deferred_tx_queue
)))
880 ieee80211_tx_status_ni(wl
->hw
, skb
);
883 static void wl1271_netstack_work(struct work_struct
*work
)
886 container_of(work
, struct wl1271
, netstack_work
);
889 wl1271_flush_deferred_work(wl
);
890 } while (skb_queue_len(&wl
->deferred_rx_queue
));
893 #define WL1271_IRQ_MAX_LOOPS 256
895 static irqreturn_t
wl1271_irq(int irq
, void *cookie
)
899 int loopcount
= WL1271_IRQ_MAX_LOOPS
;
900 struct wl1271
*wl
= (struct wl1271
*)cookie
;
902 unsigned int defer_count
;
905 /* TX might be handled here, avoid redundant work */
906 set_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
907 cancel_work_sync(&wl
->tx_work
);
910 * In case edge triggered interrupt must be used, we cannot iterate
911 * more than once without introducing race conditions with the hardirq.
913 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
916 mutex_lock(&wl
->mutex
);
918 wl1271_debug(DEBUG_IRQ
, "IRQ work");
920 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
923 ret
= wl1271_ps_elp_wakeup(wl
);
927 while (!done
&& loopcount
--) {
929 * In order to avoid a race with the hardirq, clear the flag
930 * before acknowledging the chip. Since the mutex is held,
931 * wl1271_ps_elp_wakeup cannot be called concurrently.
933 clear_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
934 smp_mb__after_clear_bit();
936 wl12xx_fw_status(wl
, wl
->fw_status
);
938 wlcore_hw_tx_immediate_compl(wl
);
940 intr
= le32_to_cpu(wl
->fw_status
->intr
);
941 intr
&= WL1271_INTR_MASK
;
947 if (unlikely(intr
& WL1271_ACX_INTR_WATCHDOG
)) {
948 wl1271_error("watchdog interrupt received! "
949 "starting recovery.");
950 wl12xx_queue_recovery_work(wl
);
952 /* restarting the chip. ignore any other interrupt. */
956 if (likely(intr
& WL1271_ACX_INTR_DATA
)) {
957 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
959 wl12xx_rx(wl
, wl
->fw_status
);
961 /* Check if any tx blocks were freed */
962 spin_lock_irqsave(&wl
->wl_lock
, flags
);
963 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
964 wl1271_tx_total_queue_count(wl
) > 0) {
965 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
967 * In order to avoid starvation of the TX path,
968 * call the work function directly.
970 wl1271_tx_work_locked(wl
);
972 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
975 /* check for tx results */
976 wlcore_hw_tx_delayed_compl(wl
);
978 /* Make sure the deferred queues don't get too long */
979 defer_count
= skb_queue_len(&wl
->deferred_tx_queue
) +
980 skb_queue_len(&wl
->deferred_rx_queue
);
981 if (defer_count
> WL1271_DEFERRED_QUEUE_LIMIT
)
982 wl1271_flush_deferred_work(wl
);
985 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
986 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
987 wl1271_event_handle(wl
, 0);
990 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
991 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
992 wl1271_event_handle(wl
, 1);
995 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
996 wl1271_debug(DEBUG_IRQ
,
997 "WL1271_ACX_INTR_INIT_COMPLETE");
999 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
1000 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
1003 wl1271_ps_elp_sleep(wl
);
1006 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1007 /* In case TX was not handled here, queue TX work */
1008 clear_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
1009 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1010 wl1271_tx_total_queue_count(wl
) > 0)
1011 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1012 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1014 mutex_unlock(&wl
->mutex
);
1019 struct vif_counter_data
{
1022 struct ieee80211_vif
*cur_vif
;
1023 bool cur_vif_running
;
1026 static void wl12xx_vif_count_iter(void *data
, u8
*mac
,
1027 struct ieee80211_vif
*vif
)
1029 struct vif_counter_data
*counter
= data
;
1032 if (counter
->cur_vif
== vif
)
1033 counter
->cur_vif_running
= true;
1036 /* caller must not hold wl->mutex, as it might deadlock */
1037 static void wl12xx_get_vif_count(struct ieee80211_hw
*hw
,
1038 struct ieee80211_vif
*cur_vif
,
1039 struct vif_counter_data
*data
)
1041 memset(data
, 0, sizeof(*data
));
1042 data
->cur_vif
= cur_vif
;
1044 ieee80211_iterate_active_interfaces(hw
,
1045 wl12xx_vif_count_iter
, data
);
1048 static int wl12xx_fetch_firmware(struct wl1271
*wl
, bool plt
)
1050 const struct firmware
*fw
;
1051 const char *fw_name
;
1052 enum wl12xx_fw_type fw_type
;
1056 fw_type
= WL12XX_FW_TYPE_PLT
;
1057 fw_name
= wl
->plt_fw_name
;
1060 * we can't call wl12xx_get_vif_count() here because
1061 * wl->mutex is taken, so use the cached last_vif_count value
1063 if (wl
->last_vif_count
> 1) {
1064 fw_type
= WL12XX_FW_TYPE_MULTI
;
1065 fw_name
= wl
->mr_fw_name
;
1067 fw_type
= WL12XX_FW_TYPE_NORMAL
;
1068 fw_name
= wl
->sr_fw_name
;
1072 if (wl
->fw_type
== fw_type
)
1075 wl1271_debug(DEBUG_BOOT
, "booting firmware %s", fw_name
);
1077 ret
= request_firmware(&fw
, fw_name
, wl
->dev
);
1080 wl1271_error("could not get firmware %s: %d", fw_name
, ret
);
1085 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1092 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
1093 wl
->fw_len
= fw
->size
;
1094 wl
->fw
= vmalloc(wl
->fw_len
);
1097 wl1271_error("could not allocate memory for the firmware");
1102 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
1104 wl
->fw_type
= fw_type
;
1106 release_firmware(fw
);
1111 static int wl1271_fetch_nvs(struct wl1271
*wl
)
1113 const struct firmware
*fw
;
1116 ret
= request_firmware(&fw
, WL12XX_NVS_NAME
, wl
->dev
);
1119 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME
,
1124 wl
->nvs
= kmemdup(fw
->data
, fw
->size
, GFP_KERNEL
);
1127 wl1271_error("could not allocate memory for the nvs file");
1132 wl
->nvs_len
= fw
->size
;
1135 release_firmware(fw
);
1140 void wl12xx_queue_recovery_work(struct wl1271
*wl
)
1142 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
1143 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
1146 size_t wl12xx_copy_fwlog(struct wl1271
*wl
, u8
*memblock
, size_t maxlen
)
1150 /* The FW log is a length-value list, find where the log end */
1151 while (len
< maxlen
) {
1152 if (memblock
[len
] == 0)
1154 if (len
+ memblock
[len
] + 1 > maxlen
)
1156 len
+= memblock
[len
] + 1;
1159 /* Make sure we have enough room */
1160 len
= min(len
, (size_t)(PAGE_SIZE
- wl
->fwlog_size
));
1162 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1163 memcpy(wl
->fwlog
+ wl
->fwlog_size
, memblock
, len
);
1164 wl
->fwlog_size
+= len
;
1169 static void wl12xx_read_fwlog_panic(struct wl1271
*wl
)
1175 if ((wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
) ||
1176 (wl
->conf
.fwlog
.mode
!= WL12XX_FWLOG_ON_DEMAND
) ||
1177 (wl
->conf
.fwlog
.mem_blocks
== 0))
1180 wl1271_info("Reading FW panic log");
1182 block
= kmalloc(WL12XX_HW_BLOCK_SIZE
, GFP_KERNEL
);
1187 * Make sure the chip is awake and the logger isn't active.
1188 * This might fail if the firmware hanged.
1190 if (!wl1271_ps_elp_wakeup(wl
))
1191 wl12xx_cmd_stop_fwlog(wl
);
1193 /* Read the first memory block address */
1194 wl12xx_fw_status(wl
, wl
->fw_status
);
1195 first_addr
= le32_to_cpu(wl
->fw_status
->log_start_addr
);
1199 /* Traverse the memory blocks linked list */
1202 memset(block
, 0, WL12XX_HW_BLOCK_SIZE
);
1203 wl1271_read_hwaddr(wl
, addr
, block
, WL12XX_HW_BLOCK_SIZE
,
1207 * Memory blocks are linked to one another. The first 4 bytes
1208 * of each memory block hold the hardware address of the next
1209 * one. The last memory block points to the first one.
1211 addr
= le32_to_cpup((__le32
*)block
);
1212 if (!wl12xx_copy_fwlog(wl
, block
+ sizeof(addr
),
1213 WL12XX_HW_BLOCK_SIZE
- sizeof(addr
)))
1215 } while (addr
&& (addr
!= first_addr
));
1217 wake_up_interruptible(&wl
->fwlog_waitq
);
1223 static void wl1271_recovery_work(struct work_struct
*work
)
1226 container_of(work
, struct wl1271
, recovery_work
);
1227 struct wl12xx_vif
*wlvif
;
1228 struct ieee80211_vif
*vif
;
1230 mutex_lock(&wl
->mutex
);
1232 if (wl
->state
!= WL1271_STATE_ON
|| wl
->plt
)
1235 /* Avoid a recursive recovery */
1236 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
1238 wl12xx_read_fwlog_panic(wl
);
1240 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1241 wl
->chip
.fw_ver_str
,
1242 wlcore_read_reg(wl
, REG_PC_ON_RECOVERY
));
1244 BUG_ON(bug_on_recovery
&&
1245 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
));
1248 * Advance security sequence number to overcome potential progress
1249 * in the firmware during recovery. This doens't hurt if the network is
1252 wl12xx_for_each_wlvif(wl
, wlvif
) {
1253 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
1254 test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1255 wlvif
->tx_security_seq
+=
1256 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
1259 /* Prevent spurious TX during FW restart */
1260 ieee80211_stop_queues(wl
->hw
);
1262 if (wl
->sched_scanning
) {
1263 ieee80211_sched_scan_stopped(wl
->hw
);
1264 wl
->sched_scanning
= false;
1267 /* reboot the chipset */
1268 while (!list_empty(&wl
->wlvif_list
)) {
1269 wlvif
= list_first_entry(&wl
->wlvif_list
,
1270 struct wl12xx_vif
, list
);
1271 vif
= wl12xx_wlvif_to_vif(wlvif
);
1272 __wl1271_op_remove_interface(wl
, vif
, false);
1274 mutex_unlock(&wl
->mutex
);
1275 wl1271_op_stop(wl
->hw
);
1277 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
1279 ieee80211_restart_hw(wl
->hw
);
1282 * Its safe to enable TX now - the queues are stopped after a request
1283 * to restart the HW.
1285 ieee80211_wake_queues(wl
->hw
);
1288 mutex_unlock(&wl
->mutex
);
1291 static void wl1271_fw_wakeup(struct wl1271
*wl
)
1293 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG
, ELPCTRL_WAKE_UP
);
1296 static int wl1271_setup(struct wl1271
*wl
)
1298 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
1302 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
1303 if (!wl
->tx_res_if
) {
1304 kfree(wl
->fw_status
);
1311 static int wl12xx_set_power_on(struct wl1271
*wl
)
1315 msleep(WL1271_PRE_POWER_ON_SLEEP
);
1316 ret
= wl1271_power_on(wl
);
1319 msleep(WL1271_POWER_ON_SLEEP
);
1320 wl1271_io_reset(wl
);
1323 wlcore_set_partition(wl
, &wl
->ptable
[PART_BOOT
]);
1325 /* ELP module wake up */
1326 wl1271_fw_wakeup(wl
);
1332 static int wl12xx_chip_wakeup(struct wl1271
*wl
, bool plt
)
1336 ret
= wl12xx_set_power_on(wl
);
1341 * For wl127x based devices we could use the default block
1342 * size (512 bytes), but due to a bug in the sdio driver, we
1343 * need to set it explicitly after the chip is powered on. To
1344 * simplify the code and since the performance impact is
1345 * negligible, we use the same block size for all different
1348 if (wl1271_set_block_size(wl
))
1349 wl
->quirks
|= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN
;
1351 ret
= wl
->ops
->identify_chip(wl
);
1355 /* TODO: make sure the lower driver has set things up correctly */
1357 ret
= wl1271_setup(wl
);
1361 ret
= wl12xx_fetch_firmware(wl
, plt
);
1365 /* No NVS from netlink, try to get it from the filesystem */
1366 if (wl
->nvs
== NULL
) {
1367 ret
= wl1271_fetch_nvs(wl
);
1376 int wl1271_plt_start(struct wl1271
*wl
)
1378 int retries
= WL1271_BOOT_RETRIES
;
1379 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1382 mutex_lock(&wl
->mutex
);
1384 wl1271_notice("power up");
1386 if (wl
->state
!= WL1271_STATE_OFF
) {
1387 wl1271_error("cannot go into PLT state because not "
1388 "in off state: %d", wl
->state
);
1395 ret
= wl12xx_chip_wakeup(wl
, true);
1399 ret
= wl
->ops
->boot(wl
);
1403 ret
= wl1271_plt_init(wl
);
1408 wl
->state
= WL1271_STATE_ON
;
1409 wl1271_notice("firmware booted in PLT mode (%s)",
1410 wl
->chip
.fw_ver_str
);
1412 /* update hw/fw version info in wiphy struct */
1413 wiphy
->hw_version
= wl
->chip
.id
;
1414 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
1415 sizeof(wiphy
->fw_version
));
1420 mutex_unlock(&wl
->mutex
);
1421 /* Unlocking the mutex in the middle of handling is
1422 inherently unsafe. In this case we deem it safe to do,
1423 because we need to let any possibly pending IRQ out of
1424 the system (and while we are WL1271_STATE_OFF the IRQ
1425 work function will not do anything.) Also, any other
1426 possible concurrent operations will fail due to the
1427 current state, hence the wl1271 struct should be safe. */
1428 wlcore_disable_interrupts(wl
);
1429 wl1271_flush_deferred_work(wl
);
1430 cancel_work_sync(&wl
->netstack_work
);
1431 mutex_lock(&wl
->mutex
);
1433 wl1271_power_off(wl
);
1436 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1437 WL1271_BOOT_RETRIES
);
1439 mutex_unlock(&wl
->mutex
);
1444 int wl1271_plt_stop(struct wl1271
*wl
)
1448 wl1271_notice("power down");
1451 * Interrupts must be disabled before setting the state to OFF.
1452 * Otherwise, the interrupt handler might be called and exit without
1453 * reading the interrupt status.
1455 wlcore_disable_interrupts(wl
);
1456 mutex_lock(&wl
->mutex
);
1458 mutex_unlock(&wl
->mutex
);
1461 * This will not necessarily enable interrupts as interrupts
1462 * may have been disabled when op_stop was called. It will,
1463 * however, balance the above call to disable_interrupts().
1465 wlcore_enable_interrupts(wl
);
1467 wl1271_error("cannot power down because not in PLT "
1468 "state: %d", wl
->state
);
1473 mutex_unlock(&wl
->mutex
);
1475 wl1271_flush_deferred_work(wl
);
1476 cancel_work_sync(&wl
->netstack_work
);
1477 cancel_work_sync(&wl
->recovery_work
);
1478 cancel_delayed_work_sync(&wl
->elp_work
);
1479 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1481 mutex_lock(&wl
->mutex
);
1482 wl1271_power_off(wl
);
1484 wl
->state
= WL1271_STATE_OFF
;
1487 mutex_unlock(&wl
->mutex
);
1493 static void wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1495 struct wl1271
*wl
= hw
->priv
;
1496 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1497 struct ieee80211_vif
*vif
= info
->control
.vif
;
1498 struct wl12xx_vif
*wlvif
= NULL
;
1499 unsigned long flags
;
1504 wlvif
= wl12xx_vif_to_data(vif
);
1506 mapping
= skb_get_queue_mapping(skb
);
1507 q
= wl1271_tx_get_queue(mapping
);
1509 hlid
= wl12xx_tx_get_hlid(wl
, wlvif
, skb
);
1511 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1513 /* queue the packet */
1514 if (hlid
== WL12XX_INVALID_LINK_ID
||
1515 (wlvif
&& !test_bit(hlid
, wlvif
->links_map
))) {
1516 wl1271_debug(DEBUG_TX
, "DROP skb hlid %d q %d", hlid
, q
);
1517 ieee80211_free_txskb(hw
, skb
);
1521 wl1271_debug(DEBUG_TX
, "queue skb hlid %d q %d len %d",
1523 skb_queue_tail(&wl
->links
[hlid
].tx_queue
[q
], skb
);
1525 wl
->tx_queue_count
[q
]++;
1528 * The workqueue is slow to process the tx_queue and we need stop
1529 * the queue here, otherwise the queue will get too long.
1531 if (wl
->tx_queue_count
[q
] >= WL1271_TX_QUEUE_HIGH_WATERMARK
) {
1532 wl1271_debug(DEBUG_TX
, "op_tx: stopping queues for q %d", q
);
1533 ieee80211_stop_queue(wl
->hw
, mapping
);
1534 set_bit(q
, &wl
->stopped_queues_map
);
1538 * The chip specific setup must run before the first TX packet -
1539 * before that, the tx_work will not be initialized!
1542 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1543 !test_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
))
1544 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1547 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1550 int wl1271_tx_dummy_packet(struct wl1271
*wl
)
1552 unsigned long flags
;
1555 /* no need to queue a new dummy packet if one is already pending */
1556 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
))
1559 q
= wl1271_tx_get_queue(skb_get_queue_mapping(wl
->dummy_packet
));
1561 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1562 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
);
1563 wl
->tx_queue_count
[q
]++;
1564 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1566 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1567 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
))
1568 wl1271_tx_work_locked(wl
);
1571 * If the FW TX is busy, TX work will be scheduled by the threaded
1572 * interrupt handler function
1578 * The size of the dummy packet should be at least 1400 bytes. However, in
1579 * order to minimize the number of bus transactions, aligning it to 512 bytes
1580 * boundaries could be beneficial, performance wise
1582 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1584 static struct sk_buff
*wl12xx_alloc_dummy_packet(struct wl1271
*wl
)
1586 struct sk_buff
*skb
;
1587 struct ieee80211_hdr_3addr
*hdr
;
1588 unsigned int dummy_packet_size
;
1590 dummy_packet_size
= TOTAL_TX_DUMMY_PACKET_SIZE
-
1591 sizeof(struct wl1271_tx_hw_descr
) - sizeof(*hdr
);
1593 skb
= dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE
);
1595 wl1271_warning("Failed to allocate a dummy packet skb");
1599 skb_reserve(skb
, sizeof(struct wl1271_tx_hw_descr
));
1601 hdr
= (struct ieee80211_hdr_3addr
*) skb_put(skb
, sizeof(*hdr
));
1602 memset(hdr
, 0, sizeof(*hdr
));
1603 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1604 IEEE80211_STYPE_NULLFUNC
|
1605 IEEE80211_FCTL_TODS
);
1607 memset(skb_put(skb
, dummy_packet_size
), 0, dummy_packet_size
);
1609 /* Dummy packets require the TID to be management */
1610 skb
->priority
= WL1271_TID_MGMT
;
1612 /* Initialize all fields that might be used */
1613 skb_set_queue_mapping(skb
, 0);
1614 memset(IEEE80211_SKB_CB(skb
), 0, sizeof(struct ieee80211_tx_info
));
1621 static int wl1271_configure_suspend_sta(struct wl1271
*wl
,
1622 struct wl12xx_vif
*wlvif
)
1626 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1629 ret
= wl1271_ps_elp_wakeup(wl
);
1633 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1634 wl
->conf
.conn
.suspend_wake_up_event
,
1635 wl
->conf
.conn
.suspend_listen_interval
);
1638 wl1271_error("suspend: set wake up conditions failed: %d", ret
);
1640 wl1271_ps_elp_sleep(wl
);
1647 static int wl1271_configure_suspend_ap(struct wl1271
*wl
,
1648 struct wl12xx_vif
*wlvif
)
1652 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1655 ret
= wl1271_ps_elp_wakeup(wl
);
1659 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
1661 wl1271_ps_elp_sleep(wl
);
1667 static int wl1271_configure_suspend(struct wl1271
*wl
,
1668 struct wl12xx_vif
*wlvif
)
1670 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1671 return wl1271_configure_suspend_sta(wl
, wlvif
);
1672 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
1673 return wl1271_configure_suspend_ap(wl
, wlvif
);
1677 static void wl1271_configure_resume(struct wl1271
*wl
,
1678 struct wl12xx_vif
*wlvif
)
1681 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
1682 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
1684 if ((!is_ap
) && (!is_sta
))
1687 ret
= wl1271_ps_elp_wakeup(wl
);
1692 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1693 wl
->conf
.conn
.wake_up_event
,
1694 wl
->conf
.conn
.listen_interval
);
1697 wl1271_error("resume: wake up conditions failed: %d",
1701 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
1704 wl1271_ps_elp_sleep(wl
);
1707 static int wl1271_op_suspend(struct ieee80211_hw
*hw
,
1708 struct cfg80211_wowlan
*wow
)
1710 struct wl1271
*wl
= hw
->priv
;
1711 struct wl12xx_vif
*wlvif
;
1714 wl1271_debug(DEBUG_MAC80211
, "mac80211 suspend wow=%d", !!wow
);
1715 WARN_ON(!wow
|| !wow
->any
);
1717 wl1271_tx_flush(wl
);
1719 mutex_lock(&wl
->mutex
);
1720 wl
->wow_enabled
= true;
1721 wl12xx_for_each_wlvif(wl
, wlvif
) {
1722 ret
= wl1271_configure_suspend(wl
, wlvif
);
1724 wl1271_warning("couldn't prepare device to suspend");
1728 mutex_unlock(&wl
->mutex
);
1729 /* flush any remaining work */
1730 wl1271_debug(DEBUG_MAC80211
, "flushing remaining works");
1733 * disable and re-enable interrupts in order to flush
1736 wlcore_disable_interrupts(wl
);
1739 * set suspended flag to avoid triggering a new threaded_irq
1740 * work. no need for spinlock as interrupts are disabled.
1742 set_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1744 wlcore_enable_interrupts(wl
);
1745 flush_work(&wl
->tx_work
);
1746 flush_delayed_work(&wl
->elp_work
);
1751 static int wl1271_op_resume(struct ieee80211_hw
*hw
)
1753 struct wl1271
*wl
= hw
->priv
;
1754 struct wl12xx_vif
*wlvif
;
1755 unsigned long flags
;
1756 bool run_irq_work
= false;
1758 wl1271_debug(DEBUG_MAC80211
, "mac80211 resume wow=%d",
1760 WARN_ON(!wl
->wow_enabled
);
1763 * re-enable irq_work enqueuing, and call irq_work directly if
1764 * there is a pending work.
1766 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1767 clear_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1768 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
))
1769 run_irq_work
= true;
1770 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1773 wl1271_debug(DEBUG_MAC80211
,
1774 "run postponed irq_work directly");
1776 wlcore_enable_interrupts(wl
);
1779 mutex_lock(&wl
->mutex
);
1780 wl12xx_for_each_wlvif(wl
, wlvif
) {
1781 wl1271_configure_resume(wl
, wlvif
);
1783 wl
->wow_enabled
= false;
1784 mutex_unlock(&wl
->mutex
);
1790 static int wl1271_op_start(struct ieee80211_hw
*hw
)
1792 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
1795 * We have to delay the booting of the hardware because
1796 * we need to know the local MAC address before downloading and
1797 * initializing the firmware. The MAC address cannot be changed
1798 * after boot, and without the proper MAC address, the firmware
1799 * will not function properly.
1801 * The MAC address is first known when the corresponding interface
1802 * is added. That is where we will initialize the hardware.
1808 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
1810 struct wl1271
*wl
= hw
->priv
;
1813 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
1816 * Interrupts must be disabled before setting the state to OFF.
1817 * Otherwise, the interrupt handler might be called and exit without
1818 * reading the interrupt status.
1820 wlcore_disable_interrupts(wl
);
1821 mutex_lock(&wl
->mutex
);
1822 if (wl
->state
== WL1271_STATE_OFF
) {
1823 mutex_unlock(&wl
->mutex
);
1826 * This will not necessarily enable interrupts as interrupts
1827 * may have been disabled when op_stop was called. It will,
1828 * however, balance the above call to disable_interrupts().
1830 wlcore_enable_interrupts(wl
);
1835 * this must be before the cancel_work calls below, so that the work
1836 * functions don't perform further work.
1838 wl
->state
= WL1271_STATE_OFF
;
1839 mutex_unlock(&wl
->mutex
);
1841 wl1271_flush_deferred_work(wl
);
1842 cancel_delayed_work_sync(&wl
->scan_complete_work
);
1843 cancel_work_sync(&wl
->netstack_work
);
1844 cancel_work_sync(&wl
->tx_work
);
1845 cancel_delayed_work_sync(&wl
->elp_work
);
1846 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1848 /* let's notify MAC80211 about the remaining pending TX frames */
1849 wl12xx_tx_reset(wl
, true);
1850 mutex_lock(&wl
->mutex
);
1852 wl1271_power_off(wl
);
1854 wl
->band
= IEEE80211_BAND_2GHZ
;
1857 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1858 wl
->tx_blocks_available
= 0;
1859 wl
->tx_allocated_blocks
= 0;
1860 wl
->tx_results_count
= 0;
1861 wl
->tx_packets_count
= 0;
1862 wl
->time_offset
= 0;
1863 wl
->ap_fw_ps_map
= 0;
1865 wl
->sched_scanning
= false;
1866 memset(wl
->roles_map
, 0, sizeof(wl
->roles_map
));
1867 memset(wl
->links_map
, 0, sizeof(wl
->links_map
));
1868 memset(wl
->roc_map
, 0, sizeof(wl
->roc_map
));
1869 wl
->active_sta_count
= 0;
1871 /* The system link is always allocated */
1872 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
1875 * this is performed after the cancel_work calls and the associated
1876 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1877 * get executed before all these vars have been reset.
1881 wl
->tx_blocks_freed
= 0;
1883 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1884 wl
->tx_pkts_freed
[i
] = 0;
1885 wl
->tx_allocated_pkts
[i
] = 0;
1888 wl1271_debugfs_reset(wl
);
1890 kfree(wl
->fw_status
);
1891 wl
->fw_status
= NULL
;
1892 kfree(wl
->tx_res_if
);
1893 wl
->tx_res_if
= NULL
;
1894 kfree(wl
->target_mem_map
);
1895 wl
->target_mem_map
= NULL
;
1897 mutex_unlock(&wl
->mutex
);
1900 static int wl12xx_allocate_rate_policy(struct wl1271
*wl
, u8
*idx
)
1902 u8 policy
= find_first_zero_bit(wl
->rate_policies_map
,
1903 WL12XX_MAX_RATE_POLICIES
);
1904 if (policy
>= WL12XX_MAX_RATE_POLICIES
)
1907 __set_bit(policy
, wl
->rate_policies_map
);
1912 static void wl12xx_free_rate_policy(struct wl1271
*wl
, u8
*idx
)
1914 if (WARN_ON(*idx
>= WL12XX_MAX_RATE_POLICIES
))
1917 __clear_bit(*idx
, wl
->rate_policies_map
);
1918 *idx
= WL12XX_MAX_RATE_POLICIES
;
1921 static u8
wl12xx_get_role_type(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1923 switch (wlvif
->bss_type
) {
1924 case BSS_TYPE_AP_BSS
:
1926 return WL1271_ROLE_P2P_GO
;
1928 return WL1271_ROLE_AP
;
1930 case BSS_TYPE_STA_BSS
:
1932 return WL1271_ROLE_P2P_CL
;
1934 return WL1271_ROLE_STA
;
1937 return WL1271_ROLE_IBSS
;
1940 wl1271_error("invalid bss_type: %d", wlvif
->bss_type
);
1942 return WL12XX_INVALID_ROLE_TYPE
;
1945 static int wl12xx_init_vif_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1947 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1950 /* clear everything but the persistent data */
1951 memset(wlvif
, 0, offsetof(struct wl12xx_vif
, persistent
));
1953 switch (ieee80211_vif_type_p2p(vif
)) {
1954 case NL80211_IFTYPE_P2P_CLIENT
:
1957 case NL80211_IFTYPE_STATION
:
1958 wlvif
->bss_type
= BSS_TYPE_STA_BSS
;
1960 case NL80211_IFTYPE_ADHOC
:
1961 wlvif
->bss_type
= BSS_TYPE_IBSS
;
1963 case NL80211_IFTYPE_P2P_GO
:
1966 case NL80211_IFTYPE_AP
:
1967 wlvif
->bss_type
= BSS_TYPE_AP_BSS
;
1970 wlvif
->bss_type
= MAX_BSS_TYPE
;
1974 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
1975 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
1976 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
1978 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1979 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1980 /* init sta/ibss data */
1981 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
1982 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
1983 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
1984 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
1987 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
1988 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
1989 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
1990 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
1991 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
1992 wl12xx_allocate_rate_policy(wl
,
1993 &wlvif
->ap
.ucast_rate_idx
[i
]);
1996 wlvif
->bitrate_masks
[IEEE80211_BAND_2GHZ
] = wl
->conf
.tx
.basic_rate
;
1997 wlvif
->bitrate_masks
[IEEE80211_BAND_5GHZ
] = wl
->conf
.tx
.basic_rate_5
;
1998 wlvif
->basic_rate_set
= CONF_TX_RATE_MASK_BASIC
;
1999 wlvif
->basic_rate
= CONF_TX_RATE_MASK_BASIC
;
2000 wlvif
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
2001 wlvif
->beacon_int
= WL1271_DEFAULT_BEACON_INT
;
2004 * mac80211 configures some values globally, while we treat them
2005 * per-interface. thus, on init, we have to copy them from wl
2007 wlvif
->band
= wl
->band
;
2008 wlvif
->channel
= wl
->channel
;
2009 wlvif
->power_level
= wl
->power_level
;
2011 INIT_WORK(&wlvif
->rx_streaming_enable_work
,
2012 wl1271_rx_streaming_enable_work
);
2013 INIT_WORK(&wlvif
->rx_streaming_disable_work
,
2014 wl1271_rx_streaming_disable_work
);
2015 INIT_LIST_HEAD(&wlvif
->list
);
2017 setup_timer(&wlvif
->rx_streaming_timer
, wl1271_rx_streaming_timer
,
2018 (unsigned long) wlvif
);
2022 static bool wl12xx_init_fw(struct wl1271
*wl
)
2024 int retries
= WL1271_BOOT_RETRIES
;
2025 bool booted
= false;
2026 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
2031 ret
= wl12xx_chip_wakeup(wl
, false);
2035 ret
= wl
->ops
->boot(wl
);
2039 ret
= wl1271_hw_init(wl
);
2047 mutex_unlock(&wl
->mutex
);
2048 /* Unlocking the mutex in the middle of handling is
2049 inherently unsafe. In this case we deem it safe to do,
2050 because we need to let any possibly pending IRQ out of
2051 the system (and while we are WL1271_STATE_OFF the IRQ
2052 work function will not do anything.) Also, any other
2053 possible concurrent operations will fail due to the
2054 current state, hence the wl1271 struct should be safe. */
2055 wlcore_disable_interrupts(wl
);
2056 wl1271_flush_deferred_work(wl
);
2057 cancel_work_sync(&wl
->netstack_work
);
2058 mutex_lock(&wl
->mutex
);
2060 wl1271_power_off(wl
);
2064 wl1271_error("firmware boot failed despite %d retries",
2065 WL1271_BOOT_RETRIES
);
2069 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver_str
);
2071 /* update hw/fw version info in wiphy struct */
2072 wiphy
->hw_version
= wl
->chip
.id
;
2073 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
2074 sizeof(wiphy
->fw_version
));
2077 * Now we know if 11a is supported (info from the NVS), so disable
2078 * 11a channels if not supported
2080 if (!wl
->enable_11a
)
2081 wiphy
->bands
[IEEE80211_BAND_5GHZ
]->n_channels
= 0;
2083 wl1271_debug(DEBUG_MAC80211
, "11a is %ssupported",
2084 wl
->enable_11a
? "" : "not ");
2086 wl
->state
= WL1271_STATE_ON
;
2091 static bool wl12xx_dev_role_started(struct wl12xx_vif
*wlvif
)
2093 return wlvif
->dev_hlid
!= WL12XX_INVALID_LINK_ID
;
2097 * Check whether a fw switch (i.e. moving from one loaded
2098 * fw to another) is needed. This function is also responsible
2099 * for updating wl->last_vif_count, so it must be called before
2100 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2103 static bool wl12xx_need_fw_change(struct wl1271
*wl
,
2104 struct vif_counter_data vif_counter_data
,
2107 enum wl12xx_fw_type current_fw
= wl
->fw_type
;
2108 u8 vif_count
= vif_counter_data
.counter
;
2110 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
))
2113 /* increase the vif count if this is a new vif */
2114 if (add
&& !vif_counter_data
.cur_vif_running
)
2117 wl
->last_vif_count
= vif_count
;
2119 /* no need for fw change if the device is OFF */
2120 if (wl
->state
== WL1271_STATE_OFF
)
2123 if (vif_count
> 1 && current_fw
== WL12XX_FW_TYPE_NORMAL
)
2125 if (vif_count
<= 1 && current_fw
== WL12XX_FW_TYPE_MULTI
)
2132 * Enter "forced psm". Make sure the sta is in psm against the ap,
2133 * to make the fw switch a bit more disconnection-persistent.
2135 static void wl12xx_force_active_psm(struct wl1271
*wl
)
2137 struct wl12xx_vif
*wlvif
;
2139 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
2140 wl1271_ps_set_mode(wl
, wlvif
, STATION_POWER_SAVE_MODE
);
2144 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
2145 struct ieee80211_vif
*vif
)
2147 struct wl1271
*wl
= hw
->priv
;
2148 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2149 struct vif_counter_data vif_count
;
2152 bool booted
= false;
2154 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
2155 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
2157 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
2158 ieee80211_vif_type_p2p(vif
), vif
->addr
);
2160 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2162 mutex_lock(&wl
->mutex
);
2163 ret
= wl1271_ps_elp_wakeup(wl
);
2168 * in some very corner case HW recovery scenarios its possible to
2169 * get here before __wl1271_op_remove_interface is complete, so
2170 * opt out if that is the case.
2172 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
) ||
2173 test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)) {
2179 ret
= wl12xx_init_vif_data(wl
, vif
);
2184 role_type
= wl12xx_get_role_type(wl
, wlvif
);
2185 if (role_type
== WL12XX_INVALID_ROLE_TYPE
) {
2190 if (wl12xx_need_fw_change(wl
, vif_count
, true)) {
2191 wl12xx_force_active_psm(wl
);
2192 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2193 mutex_unlock(&wl
->mutex
);
2194 wl1271_recovery_work(&wl
->recovery_work
);
2199 * TODO: after the nvs issue will be solved, move this block
2200 * to start(), and make sure here the driver is ON.
2202 if (wl
->state
== WL1271_STATE_OFF
) {
2204 * we still need this in order to configure the fw
2205 * while uploading the nvs
2207 memcpy(wl
->addresses
[0].addr
, vif
->addr
, ETH_ALEN
);
2209 booted
= wl12xx_init_fw(wl
);
2216 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2217 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2219 * The device role is a special role used for
2220 * rx and tx frames prior to association (as
2221 * the STA role can get packets only from
2222 * its associated bssid)
2224 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2226 &wlvif
->dev_role_id
);
2231 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2232 role_type
, &wlvif
->role_id
);
2236 ret
= wl1271_init_vif_specific(wl
, vif
);
2240 list_add(&wlvif
->list
, &wl
->wlvif_list
);
2241 set_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
);
2243 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2248 wl1271_ps_elp_sleep(wl
);
2250 mutex_unlock(&wl
->mutex
);
2255 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
2256 struct ieee80211_vif
*vif
,
2257 bool reset_tx_queues
)
2259 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2262 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
2264 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2267 /* because of hardware recovery, we may get here twice */
2268 if (wl
->state
!= WL1271_STATE_ON
)
2271 wl1271_info("down");
2273 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
&&
2274 wl
->scan_vif
== vif
) {
2276 * Rearm the tx watchdog just before idling scan. This
2277 * prevents just-finished scans from triggering the watchdog
2279 wl12xx_rearm_tx_watchdog_locked(wl
);
2281 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
2282 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
2283 wl
->scan_vif
= NULL
;
2284 wl
->scan
.req
= NULL
;
2285 ieee80211_scan_completed(wl
->hw
, true);
2288 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
)) {
2289 /* disable active roles */
2290 ret
= wl1271_ps_elp_wakeup(wl
);
2294 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2295 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2296 if (wl12xx_dev_role_started(wlvif
))
2297 wl12xx_stop_dev(wl
, wlvif
);
2299 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2304 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->role_id
);
2308 wl1271_ps_elp_sleep(wl
);
2311 /* clear all hlids (except system_hlid) */
2312 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
2314 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2315 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2316 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
2317 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
2318 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
2319 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
2321 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
2322 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
2323 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
2324 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
2325 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
2326 wl12xx_free_rate_policy(wl
,
2327 &wlvif
->ap
.ucast_rate_idx
[i
]);
2328 wl1271_free_ap_keys(wl
, wlvif
);
2331 dev_kfree_skb(wlvif
->probereq
);
2332 wlvif
->probereq
= NULL
;
2333 wl12xx_tx_reset_wlvif(wl
, wlvif
);
2334 if (wl
->last_wlvif
== wlvif
)
2335 wl
->last_wlvif
= NULL
;
2336 list_del(&wlvif
->list
);
2337 memset(wlvif
->ap
.sta_hlid_map
, 0, sizeof(wlvif
->ap
.sta_hlid_map
));
2338 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
2339 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
2341 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2346 mutex_unlock(&wl
->mutex
);
2348 del_timer_sync(&wlvif
->rx_streaming_timer
);
2349 cancel_work_sync(&wlvif
->rx_streaming_enable_work
);
2350 cancel_work_sync(&wlvif
->rx_streaming_disable_work
);
2352 mutex_lock(&wl
->mutex
);
2355 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
2356 struct ieee80211_vif
*vif
)
2358 struct wl1271
*wl
= hw
->priv
;
2359 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2360 struct wl12xx_vif
*iter
;
2361 struct vif_counter_data vif_count
;
2362 bool cancel_recovery
= true;
2364 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2365 mutex_lock(&wl
->mutex
);
2367 if (wl
->state
== WL1271_STATE_OFF
||
2368 !test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2372 * wl->vif can be null here if someone shuts down the interface
2373 * just when hardware recovery has been started.
2375 wl12xx_for_each_wlvif(wl
, iter
) {
2379 __wl1271_op_remove_interface(wl
, vif
, true);
2382 WARN_ON(iter
!= wlvif
);
2383 if (wl12xx_need_fw_change(wl
, vif_count
, false)) {
2384 wl12xx_force_active_psm(wl
);
2385 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2386 wl12xx_queue_recovery_work(wl
);
2387 cancel_recovery
= false;
2390 mutex_unlock(&wl
->mutex
);
2391 if (cancel_recovery
)
2392 cancel_work_sync(&wl
->recovery_work
);
2395 static int wl12xx_op_change_interface(struct ieee80211_hw
*hw
,
2396 struct ieee80211_vif
*vif
,
2397 enum nl80211_iftype new_type
, bool p2p
)
2399 struct wl1271
*wl
= hw
->priv
;
2402 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2403 wl1271_op_remove_interface(hw
, vif
);
2405 vif
->type
= new_type
;
2407 ret
= wl1271_op_add_interface(hw
, vif
);
2409 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2413 static int wl1271_join(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2417 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
2420 * One of the side effects of the JOIN command is that is clears
2421 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2422 * to a WPA/WPA2 access point will therefore kill the data-path.
2423 * Currently the only valid scenario for JOIN during association
2424 * is on roaming, in which case we will also be given new keys.
2425 * Keep the below message for now, unless it starts bothering
2426 * users who really like to roam a lot :)
2428 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2429 wl1271_info("JOIN while associated.");
2431 /* clear encryption type */
2432 wlvif
->encryption_type
= KEY_NONE
;
2435 set_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
);
2438 ret
= wl12xx_cmd_role_start_ibss(wl
, wlvif
);
2440 ret
= wl12xx_cmd_role_start_sta(wl
, wlvif
);
2444 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2448 * The join command disable the keep-alive mode, shut down its process,
2449 * and also clear the template config, so we need to reset it all after
2450 * the join. The acx_aid starts the keep-alive process, and the order
2451 * of the commands below is relevant.
2453 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, true);
2457 ret
= wl1271_acx_aid(wl
, wlvif
, wlvif
->aid
);
2461 ret
= wl12xx_cmd_build_klv_null_data(wl
, wlvif
);
2465 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
,
2466 CMD_TEMPL_KLV_IDX_NULL_DATA
,
2467 ACX_KEEP_ALIVE_TPL_VALID
);
2475 static int wl1271_unjoin(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2479 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
)) {
2480 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
2482 wl12xx_cmd_stop_channel_switch(wl
);
2483 ieee80211_chswitch_done(vif
, false);
2486 /* to stop listening to a channel, we disconnect */
2487 ret
= wl12xx_cmd_role_stop_sta(wl
, wlvif
);
2491 /* reset TX security counters on a clean disconnect */
2492 wlvif
->tx_security_last_seq_lsb
= 0;
2493 wlvif
->tx_security_seq
= 0;
2499 static void wl1271_set_band_rate(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2501 wlvif
->basic_rate_set
= wlvif
->bitrate_masks
[wlvif
->band
];
2502 wlvif
->rate_set
= wlvif
->basic_rate_set
;
2505 static int wl1271_sta_handle_idle(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2509 bool cur_idle
= !test_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2511 if (idle
== cur_idle
)
2515 /* no need to croc if we weren't busy (e.g. during boot) */
2516 if (wl12xx_dev_role_started(wlvif
)) {
2517 ret
= wl12xx_stop_dev(wl
, wlvif
);
2522 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
2523 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2526 ret
= wl1271_acx_keep_alive_config(
2527 wl
, wlvif
, CMD_TEMPL_KLV_IDX_NULL_DATA
,
2528 ACX_KEEP_ALIVE_TPL_INVALID
);
2531 clear_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2533 /* The current firmware only supports sched_scan in idle */
2534 if (wl
->sched_scanning
) {
2535 wl1271_scan_sched_scan_stop(wl
);
2536 ieee80211_sched_scan_stopped(wl
->hw
);
2539 ret
= wl12xx_start_dev(wl
, wlvif
);
2542 set_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2549 static int wl12xx_config_vif(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2550 struct ieee80211_conf
*conf
, u32 changed
)
2552 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2555 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2557 /* if the channel changes while joined, join again */
2558 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
2559 ((wlvif
->band
!= conf
->channel
->band
) ||
2560 (wlvif
->channel
!= channel
))) {
2561 /* send all pending packets */
2562 wl1271_tx_work_locked(wl
);
2563 wlvif
->band
= conf
->channel
->band
;
2564 wlvif
->channel
= channel
;
2568 * FIXME: the mac80211 should really provide a fixed
2569 * rate to use here. for now, just use the smallest
2570 * possible rate for the band as a fixed rate for
2571 * association frames and other control messages.
2573 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2574 wl1271_set_band_rate(wl
, wlvif
);
2577 wl1271_tx_min_rate_get(wl
,
2578 wlvif
->basic_rate_set
);
2579 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2581 wl1271_warning("rate policy for channel "
2585 * change the ROC channel. do it only if we are
2586 * not idle. otherwise, CROC will be called
2589 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
,
2591 wl12xx_dev_role_started(wlvif
) &&
2592 !(conf
->flags
& IEEE80211_CONF_IDLE
)) {
2593 ret
= wl12xx_stop_dev(wl
, wlvif
);
2597 ret
= wl12xx_start_dev(wl
, wlvif
);
2604 if ((changed
& IEEE80211_CONF_CHANGE_PS
) && !is_ap
) {
2606 if ((conf
->flags
& IEEE80211_CONF_PS
) &&
2607 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
2608 !test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2613 if (wl
->conf
.conn
.forced_ps
) {
2614 ps_mode
= STATION_POWER_SAVE_MODE
;
2615 ps_mode_str
= "forced";
2617 ps_mode
= STATION_AUTO_PS_MODE
;
2618 ps_mode_str
= "auto";
2621 wl1271_debug(DEBUG_PSM
, "%s ps enabled", ps_mode_str
);
2623 ret
= wl1271_ps_set_mode(wl
, wlvif
, ps_mode
);
2626 wl1271_warning("enter %s ps failed %d",
2629 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
2630 test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2632 wl1271_debug(DEBUG_PSM
, "auto ps disabled");
2634 ret
= wl1271_ps_set_mode(wl
, wlvif
,
2635 STATION_ACTIVE_MODE
);
2637 wl1271_warning("exit auto ps failed %d", ret
);
2641 if (conf
->power_level
!= wlvif
->power_level
) {
2642 ret
= wl1271_acx_tx_power(wl
, wlvif
, conf
->power_level
);
2646 wlvif
->power_level
= conf
->power_level
;
2652 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
2654 struct wl1271
*wl
= hw
->priv
;
2655 struct wl12xx_vif
*wlvif
;
2656 struct ieee80211_conf
*conf
= &hw
->conf
;
2657 int channel
, ret
= 0;
2659 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2661 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d %s"
2664 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
2666 conf
->flags
& IEEE80211_CONF_IDLE
? "idle" : "in use",
2670 * mac80211 will go to idle nearly immediately after transmitting some
2671 * frames, such as the deauth. To make sure those frames reach the air,
2672 * wait here until the TX queue is fully flushed.
2674 if ((changed
& IEEE80211_CONF_CHANGE_IDLE
) &&
2675 (conf
->flags
& IEEE80211_CONF_IDLE
))
2676 wl1271_tx_flush(wl
);
2678 mutex_lock(&wl
->mutex
);
2680 /* we support configuring the channel and band even while off */
2681 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2682 wl
->band
= conf
->channel
->band
;
2683 wl
->channel
= channel
;
2686 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
2687 wl
->power_level
= conf
->power_level
;
2689 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2692 ret
= wl1271_ps_elp_wakeup(wl
);
2696 /* configure each interface */
2697 wl12xx_for_each_wlvif(wl
, wlvif
) {
2698 ret
= wl12xx_config_vif(wl
, wlvif
, conf
, changed
);
2704 wl1271_ps_elp_sleep(wl
);
2707 mutex_unlock(&wl
->mutex
);
2712 struct wl1271_filter_params
{
2715 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
2718 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
,
2719 struct netdev_hw_addr_list
*mc_list
)
2721 struct wl1271_filter_params
*fp
;
2722 struct netdev_hw_addr
*ha
;
2723 struct wl1271
*wl
= hw
->priv
;
2725 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2728 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
2730 wl1271_error("Out of memory setting filters.");
2734 /* update multicast filtering parameters */
2735 fp
->mc_list_length
= 0;
2736 if (netdev_hw_addr_list_count(mc_list
) > ACX_MC_ADDRESS_GROUP_MAX
) {
2737 fp
->enabled
= false;
2740 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2741 memcpy(fp
->mc_list
[fp
->mc_list_length
],
2742 ha
->addr
, ETH_ALEN
);
2743 fp
->mc_list_length
++;
2747 return (u64
)(unsigned long)fp
;
2750 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2753 FIF_BCN_PRBRESP_PROMISC | \
2757 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
2758 unsigned int changed
,
2759 unsigned int *total
, u64 multicast
)
2761 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
2762 struct wl1271
*wl
= hw
->priv
;
2763 struct wl12xx_vif
*wlvif
;
2767 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter changed %x"
2768 " total %x", changed
, *total
);
2770 mutex_lock(&wl
->mutex
);
2772 *total
&= WL1271_SUPPORTED_FILTERS
;
2773 changed
&= WL1271_SUPPORTED_FILTERS
;
2775 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2778 ret
= wl1271_ps_elp_wakeup(wl
);
2782 wl12xx_for_each_wlvif(wl
, wlvif
) {
2783 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
2784 if (*total
& FIF_ALLMULTI
)
2785 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2789 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2792 fp
->mc_list_length
);
2799 * the fw doesn't provide an api to configure the filters. instead,
2800 * the filters configuration is based on the active roles / ROC
2805 wl1271_ps_elp_sleep(wl
);
2808 mutex_unlock(&wl
->mutex
);
2812 static int wl1271_record_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2813 u8 id
, u8 key_type
, u8 key_size
,
2814 const u8
*key
, u8 hlid
, u32 tx_seq_32
,
2817 struct wl1271_ap_key
*ap_key
;
2820 wl1271_debug(DEBUG_CRYPT
, "record ap key id %d", (int)id
);
2822 if (key_size
> MAX_KEY_SIZE
)
2826 * Find next free entry in ap_keys. Also check we are not replacing
2829 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2830 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2833 if (wlvif
->ap
.recorded_keys
[i
]->id
== id
) {
2834 wl1271_warning("trying to record key replacement");
2839 if (i
== MAX_NUM_KEYS
)
2842 ap_key
= kzalloc(sizeof(*ap_key
), GFP_KERNEL
);
2847 ap_key
->key_type
= key_type
;
2848 ap_key
->key_size
= key_size
;
2849 memcpy(ap_key
->key
, key
, key_size
);
2850 ap_key
->hlid
= hlid
;
2851 ap_key
->tx_seq_32
= tx_seq_32
;
2852 ap_key
->tx_seq_16
= tx_seq_16
;
2854 wlvif
->ap
.recorded_keys
[i
] = ap_key
;
2858 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2862 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2863 kfree(wlvif
->ap
.recorded_keys
[i
]);
2864 wlvif
->ap
.recorded_keys
[i
] = NULL
;
2868 static int wl1271_ap_init_hwenc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2871 struct wl1271_ap_key
*key
;
2872 bool wep_key_added
= false;
2874 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2876 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2879 key
= wlvif
->ap
.recorded_keys
[i
];
2881 if (hlid
== WL12XX_INVALID_LINK_ID
)
2882 hlid
= wlvif
->ap
.bcast_hlid
;
2884 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
2885 key
->id
, key
->key_type
,
2886 key
->key_size
, key
->key
,
2887 hlid
, key
->tx_seq_32
,
2892 if (key
->key_type
== KEY_WEP
)
2893 wep_key_added
= true;
2896 if (wep_key_added
) {
2897 ret
= wl12xx_cmd_set_default_wep_key(wl
, wlvif
->default_key
,
2898 wlvif
->ap
.bcast_hlid
);
2904 wl1271_free_ap_keys(wl
, wlvif
);
2908 static int wl1271_set_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2909 u16 action
, u8 id
, u8 key_type
,
2910 u8 key_size
, const u8
*key
, u32 tx_seq_32
,
2911 u16 tx_seq_16
, struct ieee80211_sta
*sta
)
2914 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2917 * A role set to GEM cipher requires different Tx settings (namely
2918 * spare blocks). Note when we are in this mode so the HW can adjust.
2920 if (key_type
== KEY_GEM
) {
2921 if (action
== KEY_ADD_OR_REPLACE
)
2922 wlvif
->is_gem
= true;
2923 else if (action
== KEY_REMOVE
)
2924 wlvif
->is_gem
= false;
2928 struct wl1271_station
*wl_sta
;
2932 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
2933 hlid
= wl_sta
->hlid
;
2935 hlid
= wlvif
->ap
.bcast_hlid
;
2938 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
2940 * We do not support removing keys after AP shutdown.
2941 * Pretend we do to make mac80211 happy.
2943 if (action
!= KEY_ADD_OR_REPLACE
)
2946 ret
= wl1271_record_ap_key(wl
, wlvif
, id
,
2948 key
, hlid
, tx_seq_32
,
2951 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, action
,
2952 id
, key_type
, key_size
,
2953 key
, hlid
, tx_seq_32
,
2961 static const u8 bcast_addr
[ETH_ALEN
] = {
2962 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2965 addr
= sta
? sta
->addr
: bcast_addr
;
2967 if (is_zero_ether_addr(addr
)) {
2968 /* We dont support TX only encryption */
2972 /* The wl1271 does not allow to remove unicast keys - they
2973 will be cleared automatically on next CMD_JOIN. Ignore the
2974 request silently, as we dont want the mac80211 to emit
2975 an error message. */
2976 if (action
== KEY_REMOVE
&& !is_broadcast_ether_addr(addr
))
2979 /* don't remove key if hlid was already deleted */
2980 if (action
== KEY_REMOVE
&&
2981 wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
2984 ret
= wl1271_cmd_set_sta_key(wl
, wlvif
, action
,
2985 id
, key_type
, key_size
,
2986 key
, addr
, tx_seq_32
,
2991 /* the default WEP key needs to be configured at least once */
2992 if (key_type
== KEY_WEP
) {
2993 ret
= wl12xx_cmd_set_default_wep_key(wl
,
3004 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3005 struct ieee80211_vif
*vif
,
3006 struct ieee80211_sta
*sta
,
3007 struct ieee80211_key_conf
*key_conf
)
3009 struct wl1271
*wl
= hw
->priv
;
3010 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3016 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
3018 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x sta: %p", cmd
, sta
);
3019 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
3020 key_conf
->cipher
, key_conf
->keyidx
,
3021 key_conf
->keylen
, key_conf
->flags
);
3022 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
3024 mutex_lock(&wl
->mutex
);
3026 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3031 ret
= wl1271_ps_elp_wakeup(wl
);
3035 switch (key_conf
->cipher
) {
3036 case WLAN_CIPHER_SUITE_WEP40
:
3037 case WLAN_CIPHER_SUITE_WEP104
:
3040 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3042 case WLAN_CIPHER_SUITE_TKIP
:
3043 key_type
= KEY_TKIP
;
3045 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3046 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3047 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3049 case WLAN_CIPHER_SUITE_CCMP
:
3052 key_conf
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3053 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3054 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3056 case WL1271_CIPHER_SUITE_GEM
:
3058 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3059 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3062 wl1271_error("Unknown key algo 0x%x", key_conf
->cipher
);
3070 ret
= wl1271_set_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
3071 key_conf
->keyidx
, key_type
,
3072 key_conf
->keylen
, key_conf
->key
,
3073 tx_seq_32
, tx_seq_16
, sta
);
3075 wl1271_error("Could not add or replace key");
3080 * reconfiguring arp response if the unicast (or common)
3081 * encryption key type was changed
3083 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
3084 (sta
|| key_type
== KEY_WEP
) &&
3085 wlvif
->encryption_type
!= key_type
) {
3086 wlvif
->encryption_type
= key_type
;
3087 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3089 wl1271_warning("build arp rsp failed: %d", ret
);
3096 ret
= wl1271_set_key(wl
, wlvif
, KEY_REMOVE
,
3097 key_conf
->keyidx
, key_type
,
3098 key_conf
->keylen
, key_conf
->key
,
3101 wl1271_error("Could not remove key");
3107 wl1271_error("Unsupported key cmd 0x%x", cmd
);
3113 wl1271_ps_elp_sleep(wl
);
3116 mutex_unlock(&wl
->mutex
);
3121 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
3122 struct ieee80211_vif
*vif
,
3123 struct cfg80211_scan_request
*req
)
3125 struct wl1271
*wl
= hw
->priv
;
3130 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
3133 ssid
= req
->ssids
[0].ssid
;
3134 len
= req
->ssids
[0].ssid_len
;
3137 mutex_lock(&wl
->mutex
);
3139 if (wl
->state
== WL1271_STATE_OFF
) {
3141 * We cannot return -EBUSY here because cfg80211 will expect
3142 * a call to ieee80211_scan_completed if we do - in this case
3143 * there won't be any call.
3149 ret
= wl1271_ps_elp_wakeup(wl
);
3153 /* fail if there is any role in ROC */
3154 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
3155 /* don't allow scanning right now */
3160 ret
= wl1271_scan(hw
->priv
, vif
, ssid
, len
, req
);
3162 wl1271_ps_elp_sleep(wl
);
3164 mutex_unlock(&wl
->mutex
);
3169 static void wl1271_op_cancel_hw_scan(struct ieee80211_hw
*hw
,
3170 struct ieee80211_vif
*vif
)
3172 struct wl1271
*wl
= hw
->priv
;
3175 wl1271_debug(DEBUG_MAC80211
, "mac80211 cancel hw scan");
3177 mutex_lock(&wl
->mutex
);
3179 if (wl
->state
== WL1271_STATE_OFF
)
3182 if (wl
->scan
.state
== WL1271_SCAN_STATE_IDLE
)
3185 ret
= wl1271_ps_elp_wakeup(wl
);
3189 if (wl
->scan
.state
!= WL1271_SCAN_STATE_DONE
) {
3190 ret
= wl1271_scan_stop(wl
);
3196 * Rearm the tx watchdog just before idling scan. This
3197 * prevents just-finished scans from triggering the watchdog
3199 wl12xx_rearm_tx_watchdog_locked(wl
);
3201 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
3202 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
3203 wl
->scan_vif
= NULL
;
3204 wl
->scan
.req
= NULL
;
3205 ieee80211_scan_completed(wl
->hw
, true);
3208 wl1271_ps_elp_sleep(wl
);
3210 mutex_unlock(&wl
->mutex
);
3212 cancel_delayed_work_sync(&wl
->scan_complete_work
);
3215 static int wl1271_op_sched_scan_start(struct ieee80211_hw
*hw
,
3216 struct ieee80211_vif
*vif
,
3217 struct cfg80211_sched_scan_request
*req
,
3218 struct ieee80211_sched_scan_ies
*ies
)
3220 struct wl1271
*wl
= hw
->priv
;
3221 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3224 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_start");
3226 mutex_lock(&wl
->mutex
);
3228 if (wl
->state
== WL1271_STATE_OFF
) {
3233 ret
= wl1271_ps_elp_wakeup(wl
);
3237 ret
= wl1271_scan_sched_scan_config(wl
, wlvif
, req
, ies
);
3241 ret
= wl1271_scan_sched_scan_start(wl
, wlvif
);
3245 wl
->sched_scanning
= true;
3248 wl1271_ps_elp_sleep(wl
);
3250 mutex_unlock(&wl
->mutex
);
3254 static void wl1271_op_sched_scan_stop(struct ieee80211_hw
*hw
,
3255 struct ieee80211_vif
*vif
)
3257 struct wl1271
*wl
= hw
->priv
;
3260 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_stop");
3262 mutex_lock(&wl
->mutex
);
3264 if (wl
->state
== WL1271_STATE_OFF
)
3267 ret
= wl1271_ps_elp_wakeup(wl
);
3271 wl1271_scan_sched_scan_stop(wl
);
3273 wl1271_ps_elp_sleep(wl
);
3275 mutex_unlock(&wl
->mutex
);
3278 static int wl1271_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3280 struct wl1271
*wl
= hw
->priv
;
3283 mutex_lock(&wl
->mutex
);
3285 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3290 ret
= wl1271_ps_elp_wakeup(wl
);
3294 ret
= wl1271_acx_frag_threshold(wl
, value
);
3296 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret
);
3298 wl1271_ps_elp_sleep(wl
);
3301 mutex_unlock(&wl
->mutex
);
3306 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3308 struct wl1271
*wl
= hw
->priv
;
3309 struct wl12xx_vif
*wlvif
;
3312 mutex_lock(&wl
->mutex
);
3314 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3319 ret
= wl1271_ps_elp_wakeup(wl
);
3323 wl12xx_for_each_wlvif(wl
, wlvif
) {
3324 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, value
);
3326 wl1271_warning("set rts threshold failed: %d", ret
);
3328 wl1271_ps_elp_sleep(wl
);
3331 mutex_unlock(&wl
->mutex
);
3336 static int wl1271_ssid_set(struct ieee80211_vif
*vif
, struct sk_buff
*skb
,
3339 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3341 const u8
*ptr
= cfg80211_find_ie(WLAN_EID_SSID
, skb
->data
+ offset
,
3345 wl1271_error("No SSID in IEs!");
3350 if (ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3351 wl1271_error("SSID is too long!");
3355 wlvif
->ssid_len
= ssid_len
;
3356 memcpy(wlvif
->ssid
, ptr
+2, ssid_len
);
3360 static void wl12xx_remove_ie(struct sk_buff
*skb
, u8 eid
, int ieoffset
)
3363 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3364 u8
*ie
= (u8
*)cfg80211_find_ie(eid
, skb
->data
+ ieoffset
,
3365 skb
->len
- ieoffset
);
3370 memmove(ie
, next
, end
- next
);
3371 skb_trim(skb
, skb
->len
- len
);
3374 static void wl12xx_remove_vendor_ie(struct sk_buff
*skb
,
3375 unsigned int oui
, u8 oui_type
,
3379 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3380 u8
*ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
3381 skb
->data
+ ieoffset
,
3382 skb
->len
- ieoffset
);
3387 memmove(ie
, next
, end
- next
);
3388 skb_trim(skb
, skb
->len
- len
);
3391 static int wl1271_ap_set_probe_resp_tmpl(struct wl1271
*wl
, u32 rates
,
3392 struct ieee80211_vif
*vif
)
3394 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3395 struct sk_buff
*skb
;
3398 skb
= ieee80211_proberesp_get(wl
->hw
, vif
);
3402 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3403 CMD_TEMPL_AP_PROBE_RESPONSE
,
3412 static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271
*wl
,
3413 struct ieee80211_vif
*vif
,
3415 size_t probe_rsp_len
,
3418 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3419 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
3420 u8 probe_rsp_templ
[WL1271_CMD_TEMPL_MAX_SIZE
];
3421 int ssid_ie_offset
, ie_offset
, templ_len
;
3424 /* no need to change probe response if the SSID is set correctly */
3425 if (wlvif
->ssid_len
> 0)
3426 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3427 CMD_TEMPL_AP_PROBE_RESPONSE
,
3432 if (probe_rsp_len
+ bss_conf
->ssid_len
> WL1271_CMD_TEMPL_MAX_SIZE
) {
3433 wl1271_error("probe_rsp template too big");
3437 /* start searching from IE offset */
3438 ie_offset
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
3440 ptr
= cfg80211_find_ie(WLAN_EID_SSID
, probe_rsp_data
+ ie_offset
,
3441 probe_rsp_len
- ie_offset
);
3443 wl1271_error("No SSID in beacon!");
3447 ssid_ie_offset
= ptr
- probe_rsp_data
;
3448 ptr
+= (ptr
[1] + 2);
3450 memcpy(probe_rsp_templ
, probe_rsp_data
, ssid_ie_offset
);
3452 /* insert SSID from bss_conf */
3453 probe_rsp_templ
[ssid_ie_offset
] = WLAN_EID_SSID
;
3454 probe_rsp_templ
[ssid_ie_offset
+ 1] = bss_conf
->ssid_len
;
3455 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2,
3456 bss_conf
->ssid
, bss_conf
->ssid_len
);
3457 templ_len
= ssid_ie_offset
+ 2 + bss_conf
->ssid_len
;
3459 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2 + bss_conf
->ssid_len
,
3460 ptr
, probe_rsp_len
- (ptr
- probe_rsp_data
));
3461 templ_len
+= probe_rsp_len
- (ptr
- probe_rsp_data
);
3463 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3464 CMD_TEMPL_AP_PROBE_RESPONSE
,
3470 static int wl1271_bss_erp_info_changed(struct wl1271
*wl
,
3471 struct ieee80211_vif
*vif
,
3472 struct ieee80211_bss_conf
*bss_conf
,
3475 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3478 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3479 if (bss_conf
->use_short_slot
)
3480 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_SHORT
);
3482 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_LONG
);
3484 wl1271_warning("Set slot time failed %d", ret
);
3489 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3490 if (bss_conf
->use_short_preamble
)
3491 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_SHORT
);
3493 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_LONG
);
3496 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3497 if (bss_conf
->use_cts_prot
)
3498 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3501 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3502 CTSPROTECT_DISABLE
);
3504 wl1271_warning("Set ctsprotect failed %d", ret
);
3513 static int wl1271_bss_beacon_info_changed(struct wl1271
*wl
,
3514 struct ieee80211_vif
*vif
,
3515 struct ieee80211_bss_conf
*bss_conf
,
3518 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3519 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3522 if ((changed
& BSS_CHANGED_BEACON_INT
)) {
3523 wl1271_debug(DEBUG_MASTER
, "beacon interval updated: %d",
3524 bss_conf
->beacon_int
);
3526 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3529 if ((changed
& BSS_CHANGED_AP_PROBE_RESP
) && is_ap
) {
3530 u32 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3531 if (!wl1271_ap_set_probe_resp_tmpl(wl
, rate
, vif
)) {
3532 wl1271_debug(DEBUG_AP
, "probe response updated");
3533 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
);
3537 if ((changed
& BSS_CHANGED_BEACON
)) {
3538 struct ieee80211_hdr
*hdr
;
3540 int ieoffset
= offsetof(struct ieee80211_mgmt
,
3542 struct sk_buff
*beacon
= ieee80211_beacon_get(wl
->hw
, vif
);
3550 wl1271_debug(DEBUG_MASTER
, "beacon updated");
3552 ret
= wl1271_ssid_set(vif
, beacon
, ieoffset
);
3554 dev_kfree_skb(beacon
);
3557 min_rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3558 tmpl_id
= is_ap
? CMD_TEMPL_AP_BEACON
:
3560 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, tmpl_id
,
3565 dev_kfree_skb(beacon
);
3570 * In case we already have a probe-resp beacon set explicitly
3571 * by usermode, don't use the beacon data.
3573 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
))
3576 /* remove TIM ie from probe response */
3577 wl12xx_remove_ie(beacon
, WLAN_EID_TIM
, ieoffset
);
3580 * remove p2p ie from probe response.
3581 * the fw reponds to probe requests that don't include
3582 * the p2p ie. probe requests with p2p ie will be passed,
3583 * and will be responded by the supplicant (the spec
3584 * forbids including the p2p ie when responding to probe
3585 * requests that didn't include it).
3587 wl12xx_remove_vendor_ie(beacon
, WLAN_OUI_WFA
,
3588 WLAN_OUI_TYPE_WFA_P2P
, ieoffset
);
3590 hdr
= (struct ieee80211_hdr
*) beacon
->data
;
3591 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3592 IEEE80211_STYPE_PROBE_RESP
);
3594 ret
= wl1271_ap_set_probe_resp_tmpl_legacy(wl
, vif
,
3599 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3600 CMD_TEMPL_PROBE_RESPONSE
,
3605 dev_kfree_skb(beacon
);
3612 wl1271_error("beacon info change failed: %d", ret
);
3616 /* AP mode changes */
3617 static void wl1271_bss_info_changed_ap(struct wl1271
*wl
,
3618 struct ieee80211_vif
*vif
,
3619 struct ieee80211_bss_conf
*bss_conf
,
3622 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3625 if ((changed
& BSS_CHANGED_BASIC_RATES
)) {
3626 u32 rates
= bss_conf
->basic_rates
;
3628 wlvif
->basic_rate_set
= wl1271_tx_enabled_rates_get(wl
, rates
,
3630 wlvif
->basic_rate
= wl1271_tx_min_rate_get(wl
,
3631 wlvif
->basic_rate_set
);
3633 ret
= wl1271_init_ap_rates(wl
, wlvif
);
3635 wl1271_error("AP rate policy change failed %d", ret
);
3639 ret
= wl1271_ap_init_templates(wl
, vif
);
3644 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
, changed
);
3648 if ((changed
& BSS_CHANGED_BEACON_ENABLED
)) {
3649 if (bss_conf
->enable_beacon
) {
3650 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3651 ret
= wl12xx_cmd_role_start_ap(wl
, wlvif
);
3655 ret
= wl1271_ap_init_hwenc(wl
, wlvif
);
3659 set_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3660 wl1271_debug(DEBUG_AP
, "started AP");
3663 if (test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3664 ret
= wl12xx_cmd_role_stop_ap(wl
, wlvif
);
3668 clear_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3669 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
,
3671 wl1271_debug(DEBUG_AP
, "stopped AP");
3676 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3680 /* Handle HT information change */
3681 if ((changed
& BSS_CHANGED_HT
) &&
3682 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3683 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3684 bss_conf
->ht_operation_mode
);
3686 wl1271_warning("Set ht information failed %d", ret
);
3695 /* STA/IBSS mode changes */
3696 static void wl1271_bss_info_changed_sta(struct wl1271
*wl
,
3697 struct ieee80211_vif
*vif
,
3698 struct ieee80211_bss_conf
*bss_conf
,
3701 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3702 bool do_join
= false, set_assoc
= false;
3703 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
3704 bool ibss_joined
= false;
3705 u32 sta_rate_set
= 0;
3707 struct ieee80211_sta
*sta
;
3708 bool sta_exists
= false;
3709 struct ieee80211_sta_ht_cap sta_ht_cap
;
3712 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
,
3718 if (changed
& BSS_CHANGED_IBSS
) {
3719 if (bss_conf
->ibss_joined
) {
3720 set_bit(WLVIF_FLAG_IBSS_JOINED
, &wlvif
->flags
);
3723 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED
,
3725 wl1271_unjoin(wl
, wlvif
);
3729 if ((changed
& BSS_CHANGED_BEACON_INT
) && ibss_joined
)
3732 /* Need to update the SSID (for filtering etc) */
3733 if ((changed
& BSS_CHANGED_BEACON
) && ibss_joined
)
3736 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && ibss_joined
) {
3737 wl1271_debug(DEBUG_ADHOC
, "ad-hoc beaconing: %s",
3738 bss_conf
->enable_beacon
? "enabled" : "disabled");
3743 if (changed
& BSS_CHANGED_IDLE
&& !is_ibss
) {
3744 ret
= wl1271_sta_handle_idle(wl
, wlvif
, bss_conf
->idle
);
3746 wl1271_warning("idle mode change failed %d", ret
);
3749 if ((changed
& BSS_CHANGED_CQM
)) {
3750 bool enable
= false;
3751 if (bss_conf
->cqm_rssi_thold
)
3753 ret
= wl1271_acx_rssi_snr_trigger(wl
, wlvif
, enable
,
3754 bss_conf
->cqm_rssi_thold
,
3755 bss_conf
->cqm_rssi_hyst
);
3758 wlvif
->rssi_thold
= bss_conf
->cqm_rssi_thold
;
3761 if (changed
& BSS_CHANGED_BSSID
)
3762 if (!is_zero_ether_addr(bss_conf
->bssid
)) {
3763 ret
= wl12xx_cmd_build_null_data(wl
, wlvif
);
3767 ret
= wl1271_build_qos_null_data(wl
, vif
);
3772 if (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_HT
)) {
3774 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
3778 /* save the supp_rates of the ap */
3779 sta_rate_set
= sta
->supp_rates
[wl
->hw
->conf
.channel
->band
];
3780 if (sta
->ht_cap
.ht_supported
)
3782 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
);
3783 sta_ht_cap
= sta
->ht_cap
;
3790 if ((changed
& BSS_CHANGED_ASSOC
)) {
3791 if (bss_conf
->assoc
) {
3794 wlvif
->aid
= bss_conf
->aid
;
3795 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3800 * use basic rates from AP, and determine lowest rate
3801 * to use with control frames.
3803 rates
= bss_conf
->basic_rates
;
3804 wlvif
->basic_rate_set
=
3805 wl1271_tx_enabled_rates_get(wl
, rates
,
3808 wl1271_tx_min_rate_get(wl
,
3809 wlvif
->basic_rate_set
);
3812 wl1271_tx_enabled_rates_get(wl
,
3815 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3820 * with wl1271, we don't need to update the
3821 * beacon_int and dtim_period, because the firmware
3822 * updates it by itself when the first beacon is
3823 * received after a join.
3825 ret
= wl1271_cmd_build_ps_poll(wl
, wlvif
, wlvif
->aid
);
3830 * Get a template for hardware connection maintenance
3832 dev_kfree_skb(wlvif
->probereq
);
3833 wlvif
->probereq
= wl1271_cmd_build_ap_probe_req(wl
,
3836 ieoffset
= offsetof(struct ieee80211_mgmt
,
3837 u
.probe_req
.variable
);
3838 wl1271_ssid_set(vif
, wlvif
->probereq
, ieoffset
);
3840 /* enable the connection monitoring feature */
3841 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, true);
3845 /* use defaults when not associated */
3847 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED
,
3850 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT
,
3854 /* free probe-request template */
3855 dev_kfree_skb(wlvif
->probereq
);
3856 wlvif
->probereq
= NULL
;
3858 /* revert back to minimum rates for the current band */
3859 wl1271_set_band_rate(wl
, wlvif
);
3861 wl1271_tx_min_rate_get(wl
,
3862 wlvif
->basic_rate_set
);
3863 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3867 /* disable connection monitor features */
3868 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
3870 /* Disable the keep-alive feature */
3871 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
3875 /* restore the bssid filter and go to dummy bssid */
3878 * we might have to disable roc, if there was
3879 * no IF_OPER_UP notification.
3882 ret
= wl12xx_croc(wl
, wlvif
->role_id
);
3887 * (we also need to disable roc in case of
3888 * roaming on the same channel. until we will
3889 * have a better flow...)
3891 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
3892 ret
= wl12xx_croc(wl
,
3893 wlvif
->dev_role_id
);
3898 wl1271_unjoin(wl
, wlvif
);
3899 if (!bss_conf
->idle
)
3900 wl12xx_start_dev(wl
, wlvif
);
3905 if (changed
& BSS_CHANGED_IBSS
) {
3906 wl1271_debug(DEBUG_ADHOC
, "ibss_joined: %d",
3907 bss_conf
->ibss_joined
);
3909 if (bss_conf
->ibss_joined
) {
3910 u32 rates
= bss_conf
->basic_rates
;
3911 wlvif
->basic_rate_set
=
3912 wl1271_tx_enabled_rates_get(wl
, rates
,
3915 wl1271_tx_min_rate_get(wl
,
3916 wlvif
->basic_rate_set
);
3918 /* by default, use 11b + OFDM rates */
3919 wlvif
->rate_set
= CONF_TX_IBSS_DEFAULT_RATES
;
3920 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3926 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3931 ret
= wl1271_join(wl
, wlvif
, set_assoc
);
3933 wl1271_warning("cmd join failed %d", ret
);
3937 /* ROC until connected (after EAPOL exchange) */
3939 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->role_id
);
3943 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
))
3944 wl12xx_set_authorized(wl
, wlvif
);
3947 * stop device role if started (we might already be in
3950 if (wl12xx_dev_role_started(wlvif
)) {
3951 ret
= wl12xx_stop_dev(wl
, wlvif
);
3957 /* Handle new association with HT. Do this after join. */
3959 if ((changed
& BSS_CHANGED_HT
) &&
3960 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3961 ret
= wl1271_acx_set_ht_capabilities(wl
,
3966 wl1271_warning("Set ht cap true failed %d",
3971 /* handle new association without HT and disassociation */
3972 else if (changed
& BSS_CHANGED_ASSOC
) {
3973 ret
= wl1271_acx_set_ht_capabilities(wl
,
3978 wl1271_warning("Set ht cap false failed %d",
3985 /* Handle HT information change. Done after join. */
3986 if ((changed
& BSS_CHANGED_HT
) &&
3987 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3988 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3989 bss_conf
->ht_operation_mode
);
3991 wl1271_warning("Set ht information failed %d", ret
);
3996 /* Handle arp filtering. Done after join. */
3997 if ((changed
& BSS_CHANGED_ARP_FILTER
) ||
3998 (!is_ibss
&& (changed
& BSS_CHANGED_QOS
))) {
3999 __be32 addr
= bss_conf
->arp_addr_list
[0];
4000 wlvif
->sta
.qos
= bss_conf
->qos
;
4001 WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
);
4003 if (bss_conf
->arp_addr_cnt
== 1 &&
4004 bss_conf
->arp_filter_enabled
) {
4005 wlvif
->ip_addr
= addr
;
4007 * The template should have been configured only upon
4008 * association. however, it seems that the correct ip
4009 * isn't being set (when sending), so we have to
4010 * reconfigure the template upon every ip change.
4012 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
4014 wl1271_warning("build arp rsp failed: %d", ret
);
4018 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
,
4019 (ACX_ARP_FILTER_ARP_FILTERING
|
4020 ACX_ARP_FILTER_AUTO_ARP
),
4024 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
, 0, addr
);
4035 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
4036 struct ieee80211_vif
*vif
,
4037 struct ieee80211_bss_conf
*bss_conf
,
4040 struct wl1271
*wl
= hw
->priv
;
4041 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4042 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
4045 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed 0x%x",
4048 mutex_lock(&wl
->mutex
);
4050 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4053 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)))
4056 ret
= wl1271_ps_elp_wakeup(wl
);
4061 wl1271_bss_info_changed_ap(wl
, vif
, bss_conf
, changed
);
4063 wl1271_bss_info_changed_sta(wl
, vif
, bss_conf
, changed
);
4065 wl1271_ps_elp_sleep(wl
);
4068 mutex_unlock(&wl
->mutex
);
4071 static int wl1271_op_conf_tx(struct ieee80211_hw
*hw
,
4072 struct ieee80211_vif
*vif
, u16 queue
,
4073 const struct ieee80211_tx_queue_params
*params
)
4075 struct wl1271
*wl
= hw
->priv
;
4076 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4080 mutex_lock(&wl
->mutex
);
4082 wl1271_debug(DEBUG_MAC80211
, "mac80211 conf tx %d", queue
);
4085 ps_scheme
= CONF_PS_SCHEME_UPSD_TRIGGER
;
4087 ps_scheme
= CONF_PS_SCHEME_LEGACY
;
4089 if (!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
4092 ret
= wl1271_ps_elp_wakeup(wl
);
4097 * the txop is confed in units of 32us by the mac80211,
4100 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4101 params
->cw_min
, params
->cw_max
,
4102 params
->aifs
, params
->txop
<< 5);
4106 ret
= wl1271_acx_tid_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4107 CONF_CHANNEL_TYPE_EDCF
,
4108 wl1271_tx_get_queue(queue
),
4109 ps_scheme
, CONF_ACK_POLICY_LEGACY
,
4113 wl1271_ps_elp_sleep(wl
);
4116 mutex_unlock(&wl
->mutex
);
4121 static u64
wl1271_op_get_tsf(struct ieee80211_hw
*hw
,
4122 struct ieee80211_vif
*vif
)
4125 struct wl1271
*wl
= hw
->priv
;
4126 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4127 u64 mactime
= ULLONG_MAX
;
4130 wl1271_debug(DEBUG_MAC80211
, "mac80211 get tsf");
4132 mutex_lock(&wl
->mutex
);
4134 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4137 ret
= wl1271_ps_elp_wakeup(wl
);
4141 ret
= wl12xx_acx_tsf_info(wl
, wlvif
, &mactime
);
4146 wl1271_ps_elp_sleep(wl
);
4149 mutex_unlock(&wl
->mutex
);
4153 static int wl1271_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
4154 struct survey_info
*survey
)
4156 struct wl1271
*wl
= hw
->priv
;
4157 struct ieee80211_conf
*conf
= &hw
->conf
;
4162 survey
->channel
= conf
->channel
;
4163 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
4164 survey
->noise
= wl
->noise
;
4169 static int wl1271_allocate_sta(struct wl1271
*wl
,
4170 struct wl12xx_vif
*wlvif
,
4171 struct ieee80211_sta
*sta
)
4173 struct wl1271_station
*wl_sta
;
4177 if (wl
->active_sta_count
>= AP_MAX_STATIONS
) {
4178 wl1271_warning("could not allocate HLID - too much stations");
4182 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4183 ret
= wl12xx_allocate_link(wl
, wlvif
, &wl_sta
->hlid
);
4185 wl1271_warning("could not allocate HLID - too many links");
4189 set_bit(wl_sta
->hlid
, wlvif
->ap
.sta_hlid_map
);
4190 memcpy(wl
->links
[wl_sta
->hlid
].addr
, sta
->addr
, ETH_ALEN
);
4191 wl
->active_sta_count
++;
4195 void wl1271_free_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 hlid
)
4197 if (!test_bit(hlid
, wlvif
->ap
.sta_hlid_map
))
4200 clear_bit(hlid
, wlvif
->ap
.sta_hlid_map
);
4201 memset(wl
->links
[hlid
].addr
, 0, ETH_ALEN
);
4202 wl
->links
[hlid
].ba_bitmap
= 0;
4203 __clear_bit(hlid
, &wl
->ap_ps_map
);
4204 __clear_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
4205 wl12xx_free_link(wl
, wlvif
, &hlid
);
4206 wl
->active_sta_count
--;
4209 * rearm the tx watchdog when the last STA is freed - give the FW a
4210 * chance to return STA-buffered packets before complaining.
4212 if (wl
->active_sta_count
== 0)
4213 wl12xx_rearm_tx_watchdog_locked(wl
);
4216 static int wl12xx_sta_add(struct wl1271
*wl
,
4217 struct wl12xx_vif
*wlvif
,
4218 struct ieee80211_sta
*sta
)
4220 struct wl1271_station
*wl_sta
;
4224 wl1271_debug(DEBUG_MAC80211
, "mac80211 add sta %d", (int)sta
->aid
);
4226 ret
= wl1271_allocate_sta(wl
, wlvif
, sta
);
4230 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4231 hlid
= wl_sta
->hlid
;
4233 ret
= wl12xx_cmd_add_peer(wl
, wlvif
, sta
, hlid
);
4235 wl1271_free_sta(wl
, wlvif
, hlid
);
4240 static int wl12xx_sta_remove(struct wl1271
*wl
,
4241 struct wl12xx_vif
*wlvif
,
4242 struct ieee80211_sta
*sta
)
4244 struct wl1271_station
*wl_sta
;
4247 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove sta %d", (int)sta
->aid
);
4249 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4251 if (WARN_ON(!test_bit(id
, wlvif
->ap
.sta_hlid_map
)))
4254 ret
= wl12xx_cmd_remove_peer(wl
, wl_sta
->hlid
);
4258 wl1271_free_sta(wl
, wlvif
, wl_sta
->hlid
);
4262 static int wl12xx_update_sta_state(struct wl1271
*wl
,
4263 struct wl12xx_vif
*wlvif
,
4264 struct ieee80211_sta
*sta
,
4265 enum ieee80211_sta_state old_state
,
4266 enum ieee80211_sta_state new_state
)
4268 struct wl1271_station
*wl_sta
;
4270 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
4271 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
4274 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4275 hlid
= wl_sta
->hlid
;
4277 /* Add station (AP mode) */
4279 old_state
== IEEE80211_STA_NOTEXIST
&&
4280 new_state
== IEEE80211_STA_NONE
)
4281 return wl12xx_sta_add(wl
, wlvif
, sta
);
4283 /* Remove station (AP mode) */
4285 old_state
== IEEE80211_STA_NONE
&&
4286 new_state
== IEEE80211_STA_NOTEXIST
) {
4288 wl12xx_sta_remove(wl
, wlvif
, sta
);
4292 /* Authorize station (AP mode) */
4294 new_state
== IEEE80211_STA_AUTHORIZED
) {
4295 ret
= wl12xx_cmd_set_peer_state(wl
, hlid
);
4299 ret
= wl1271_acx_set_ht_capabilities(wl
, &sta
->ht_cap
, true,
4304 /* Authorize station */
4306 new_state
== IEEE80211_STA_AUTHORIZED
) {
4307 set_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4308 return wl12xx_set_authorized(wl
, wlvif
);
4312 old_state
== IEEE80211_STA_AUTHORIZED
&&
4313 new_state
== IEEE80211_STA_ASSOC
) {
4314 clear_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4321 static int wl12xx_op_sta_state(struct ieee80211_hw
*hw
,
4322 struct ieee80211_vif
*vif
,
4323 struct ieee80211_sta
*sta
,
4324 enum ieee80211_sta_state old_state
,
4325 enum ieee80211_sta_state new_state
)
4327 struct wl1271
*wl
= hw
->priv
;
4328 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4331 wl1271_debug(DEBUG_MAC80211
, "mac80211 sta %d state=%d->%d",
4332 sta
->aid
, old_state
, new_state
);
4334 mutex_lock(&wl
->mutex
);
4336 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4341 ret
= wl1271_ps_elp_wakeup(wl
);
4345 ret
= wl12xx_update_sta_state(wl
, wlvif
, sta
, old_state
, new_state
);
4347 wl1271_ps_elp_sleep(wl
);
4349 mutex_unlock(&wl
->mutex
);
4350 if (new_state
< old_state
)
4355 static int wl1271_op_ampdu_action(struct ieee80211_hw
*hw
,
4356 struct ieee80211_vif
*vif
,
4357 enum ieee80211_ampdu_mlme_action action
,
4358 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4361 struct wl1271
*wl
= hw
->priv
;
4362 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4364 u8 hlid
, *ba_bitmap
;
4366 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu action %d tid %d", action
,
4369 /* sanity check - the fields in FW are only 8bits wide */
4370 if (WARN_ON(tid
> 0xFF))
4373 mutex_lock(&wl
->mutex
);
4375 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4380 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
) {
4381 hlid
= wlvif
->sta
.hlid
;
4382 ba_bitmap
= &wlvif
->sta
.ba_rx_bitmap
;
4383 } else if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
) {
4384 struct wl1271_station
*wl_sta
;
4386 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4387 hlid
= wl_sta
->hlid
;
4388 ba_bitmap
= &wl
->links
[hlid
].ba_bitmap
;
4394 ret
= wl1271_ps_elp_wakeup(wl
);
4398 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu: Rx tid %d action %d",
4402 case IEEE80211_AMPDU_RX_START
:
4403 if (!wlvif
->ba_support
|| !wlvif
->ba_allowed
) {
4408 if (wl
->ba_rx_session_count
>= RX_BA_MAX_SESSIONS
) {
4410 wl1271_error("exceeded max RX BA sessions");
4414 if (*ba_bitmap
& BIT(tid
)) {
4416 wl1271_error("cannot enable RX BA session on active "
4421 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, *ssn
, true,
4424 *ba_bitmap
|= BIT(tid
);
4425 wl
->ba_rx_session_count
++;
4429 case IEEE80211_AMPDU_RX_STOP
:
4430 if (!(*ba_bitmap
& BIT(tid
))) {
4432 wl1271_error("no active RX BA session on tid: %d",
4437 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, 0, false,
4440 *ba_bitmap
&= ~BIT(tid
);
4441 wl
->ba_rx_session_count
--;
4446 * The BA initiator session management in FW independently.
4447 * Falling break here on purpose for all TX APDU commands.
4449 case IEEE80211_AMPDU_TX_START
:
4450 case IEEE80211_AMPDU_TX_STOP
:
4451 case IEEE80211_AMPDU_TX_OPERATIONAL
:
4456 wl1271_error("Incorrect ampdu action id=%x\n", action
);
4460 wl1271_ps_elp_sleep(wl
);
4463 mutex_unlock(&wl
->mutex
);
4468 static int wl12xx_set_bitrate_mask(struct ieee80211_hw
*hw
,
4469 struct ieee80211_vif
*vif
,
4470 const struct cfg80211_bitrate_mask
*mask
)
4472 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4473 struct wl1271
*wl
= hw
->priv
;
4476 wl1271_debug(DEBUG_MAC80211
, "mac80211 set_bitrate_mask 0x%x 0x%x",
4477 mask
->control
[NL80211_BAND_2GHZ
].legacy
,
4478 mask
->control
[NL80211_BAND_5GHZ
].legacy
);
4480 mutex_lock(&wl
->mutex
);
4482 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4483 wlvif
->bitrate_masks
[i
] =
4484 wl1271_tx_enabled_rates_get(wl
,
4485 mask
->control
[i
].legacy
,
4488 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4491 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
4492 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
)) {
4494 ret
= wl1271_ps_elp_wakeup(wl
);
4498 wl1271_set_band_rate(wl
, wlvif
);
4500 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
4501 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
4503 wl1271_ps_elp_sleep(wl
);
4506 mutex_unlock(&wl
->mutex
);
4511 static void wl12xx_op_channel_switch(struct ieee80211_hw
*hw
,
4512 struct ieee80211_channel_switch
*ch_switch
)
4514 struct wl1271
*wl
= hw
->priv
;
4515 struct wl12xx_vif
*wlvif
;
4518 wl1271_debug(DEBUG_MAC80211
, "mac80211 channel switch");
4520 wl1271_tx_flush(wl
);
4522 mutex_lock(&wl
->mutex
);
4524 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4525 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4526 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
4527 ieee80211_chswitch_done(vif
, false);
4532 ret
= wl1271_ps_elp_wakeup(wl
);
4536 /* TODO: change mac80211 to pass vif as param */
4537 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4538 ret
= wl12xx_cmd_channel_switch(wl
, wlvif
, ch_switch
);
4541 set_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
);
4544 wl1271_ps_elp_sleep(wl
);
4547 mutex_unlock(&wl
->mutex
);
4550 static bool wl1271_tx_frames_pending(struct ieee80211_hw
*hw
)
4552 struct wl1271
*wl
= hw
->priv
;
4555 mutex_lock(&wl
->mutex
);
4557 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4560 /* packets are considered pending if in the TX queue or the FW */
4561 ret
= (wl1271_tx_total_queue_count(wl
) > 0) || (wl
->tx_frames_cnt
> 0);
4563 mutex_unlock(&wl
->mutex
);
4568 /* can't be const, mac80211 writes to this */
4569 static struct ieee80211_rate wl1271_rates
[] = {
4571 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
4572 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
4574 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
4575 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
4576 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4578 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
4579 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
4580 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4582 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
4583 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
4584 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4586 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4587 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4589 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4590 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4592 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4593 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4595 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4596 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4598 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4599 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4601 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4602 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4604 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4605 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4607 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4608 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4611 /* can't be const, mac80211 writes to this */
4612 static struct ieee80211_channel wl1271_channels
[] = {
4613 { .hw_value
= 1, .center_freq
= 2412, .max_power
= 25 },
4614 { .hw_value
= 2, .center_freq
= 2417, .max_power
= 25 },
4615 { .hw_value
= 3, .center_freq
= 2422, .max_power
= 25 },
4616 { .hw_value
= 4, .center_freq
= 2427, .max_power
= 25 },
4617 { .hw_value
= 5, .center_freq
= 2432, .max_power
= 25 },
4618 { .hw_value
= 6, .center_freq
= 2437, .max_power
= 25 },
4619 { .hw_value
= 7, .center_freq
= 2442, .max_power
= 25 },
4620 { .hw_value
= 8, .center_freq
= 2447, .max_power
= 25 },
4621 { .hw_value
= 9, .center_freq
= 2452, .max_power
= 25 },
4622 { .hw_value
= 10, .center_freq
= 2457, .max_power
= 25 },
4623 { .hw_value
= 11, .center_freq
= 2462, .max_power
= 25 },
4624 { .hw_value
= 12, .center_freq
= 2467, .max_power
= 25 },
4625 { .hw_value
= 13, .center_freq
= 2472, .max_power
= 25 },
4626 { .hw_value
= 14, .center_freq
= 2484, .max_power
= 25 },
4629 /* 11n STA capabilities */
4630 #define HW_RX_HIGHEST_RATE 72
4632 #define WL12XX_HT_CAP { \
4633 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4634 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
4635 .ht_supported = true, \
4636 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4637 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4639 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4640 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4641 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4645 /* can't be const, mac80211 writes to this */
4646 static struct ieee80211_supported_band wl1271_band_2ghz
= {
4647 .channels
= wl1271_channels
,
4648 .n_channels
= ARRAY_SIZE(wl1271_channels
),
4649 .bitrates
= wl1271_rates
,
4650 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
4651 .ht_cap
= WL12XX_HT_CAP
,
4654 /* 5 GHz data rates for WL1273 */
4655 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
4657 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4658 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4660 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4661 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4663 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4664 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4666 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4667 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4669 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4670 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4672 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4673 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4675 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4676 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4678 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4679 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4682 /* 5 GHz band channels for WL1273 */
4683 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
4684 { .hw_value
= 7, .center_freq
= 5035, .max_power
= 25 },
4685 { .hw_value
= 8, .center_freq
= 5040, .max_power
= 25 },
4686 { .hw_value
= 9, .center_freq
= 5045, .max_power
= 25 },
4687 { .hw_value
= 11, .center_freq
= 5055, .max_power
= 25 },
4688 { .hw_value
= 12, .center_freq
= 5060, .max_power
= 25 },
4689 { .hw_value
= 16, .center_freq
= 5080, .max_power
= 25 },
4690 { .hw_value
= 34, .center_freq
= 5170, .max_power
= 25 },
4691 { .hw_value
= 36, .center_freq
= 5180, .max_power
= 25 },
4692 { .hw_value
= 38, .center_freq
= 5190, .max_power
= 25 },
4693 { .hw_value
= 40, .center_freq
= 5200, .max_power
= 25 },
4694 { .hw_value
= 42, .center_freq
= 5210, .max_power
= 25 },
4695 { .hw_value
= 44, .center_freq
= 5220, .max_power
= 25 },
4696 { .hw_value
= 46, .center_freq
= 5230, .max_power
= 25 },
4697 { .hw_value
= 48, .center_freq
= 5240, .max_power
= 25 },
4698 { .hw_value
= 52, .center_freq
= 5260, .max_power
= 25 },
4699 { .hw_value
= 56, .center_freq
= 5280, .max_power
= 25 },
4700 { .hw_value
= 60, .center_freq
= 5300, .max_power
= 25 },
4701 { .hw_value
= 64, .center_freq
= 5320, .max_power
= 25 },
4702 { .hw_value
= 100, .center_freq
= 5500, .max_power
= 25 },
4703 { .hw_value
= 104, .center_freq
= 5520, .max_power
= 25 },
4704 { .hw_value
= 108, .center_freq
= 5540, .max_power
= 25 },
4705 { .hw_value
= 112, .center_freq
= 5560, .max_power
= 25 },
4706 { .hw_value
= 116, .center_freq
= 5580, .max_power
= 25 },
4707 { .hw_value
= 120, .center_freq
= 5600, .max_power
= 25 },
4708 { .hw_value
= 124, .center_freq
= 5620, .max_power
= 25 },
4709 { .hw_value
= 128, .center_freq
= 5640, .max_power
= 25 },
4710 { .hw_value
= 132, .center_freq
= 5660, .max_power
= 25 },
4711 { .hw_value
= 136, .center_freq
= 5680, .max_power
= 25 },
4712 { .hw_value
= 140, .center_freq
= 5700, .max_power
= 25 },
4713 { .hw_value
= 149, .center_freq
= 5745, .max_power
= 25 },
4714 { .hw_value
= 153, .center_freq
= 5765, .max_power
= 25 },
4715 { .hw_value
= 157, .center_freq
= 5785, .max_power
= 25 },
4716 { .hw_value
= 161, .center_freq
= 5805, .max_power
= 25 },
4717 { .hw_value
= 165, .center_freq
= 5825, .max_power
= 25 },
4720 static struct ieee80211_supported_band wl1271_band_5ghz
= {
4721 .channels
= wl1271_channels_5ghz
,
4722 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
4723 .bitrates
= wl1271_rates_5ghz
,
4724 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
4725 .ht_cap
= WL12XX_HT_CAP
,
4728 static const struct ieee80211_ops wl1271_ops
= {
4729 .start
= wl1271_op_start
,
4730 .stop
= wl1271_op_stop
,
4731 .add_interface
= wl1271_op_add_interface
,
4732 .remove_interface
= wl1271_op_remove_interface
,
4733 .change_interface
= wl12xx_op_change_interface
,
4735 .suspend
= wl1271_op_suspend
,
4736 .resume
= wl1271_op_resume
,
4738 .config
= wl1271_op_config
,
4739 .prepare_multicast
= wl1271_op_prepare_multicast
,
4740 .configure_filter
= wl1271_op_configure_filter
,
4742 .set_key
= wl1271_op_set_key
,
4743 .hw_scan
= wl1271_op_hw_scan
,
4744 .cancel_hw_scan
= wl1271_op_cancel_hw_scan
,
4745 .sched_scan_start
= wl1271_op_sched_scan_start
,
4746 .sched_scan_stop
= wl1271_op_sched_scan_stop
,
4747 .bss_info_changed
= wl1271_op_bss_info_changed
,
4748 .set_frag_threshold
= wl1271_op_set_frag_threshold
,
4749 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
4750 .conf_tx
= wl1271_op_conf_tx
,
4751 .get_tsf
= wl1271_op_get_tsf
,
4752 .get_survey
= wl1271_op_get_survey
,
4753 .sta_state
= wl12xx_op_sta_state
,
4754 .ampdu_action
= wl1271_op_ampdu_action
,
4755 .tx_frames_pending
= wl1271_tx_frames_pending
,
4756 .set_bitrate_mask
= wl12xx_set_bitrate_mask
,
4757 .channel_switch
= wl12xx_op_channel_switch
,
4758 CFG80211_TESTMODE_CMD(wl1271_tm_cmd
)
4762 u8
wlcore_rate_to_idx(struct wl1271
*wl
, u8 rate
, enum ieee80211_band band
)
4768 if (unlikely(rate
>= wl
->hw_tx_rate_tbl_size
)) {
4769 wl1271_error("Illegal RX rate from HW: %d", rate
);
4773 idx
= wl
->band_rate_to_idx
[band
][rate
];
4774 if (unlikely(idx
== CONF_HW_RXTX_RATE_UNSUPPORTED
)) {
4775 wl1271_error("Unsupported RX rate from HW: %d", rate
);
4782 static ssize_t
wl1271_sysfs_show_bt_coex_state(struct device
*dev
,
4783 struct device_attribute
*attr
,
4786 struct wl1271
*wl
= dev_get_drvdata(dev
);
4791 mutex_lock(&wl
->mutex
);
4792 len
= snprintf(buf
, len
, "%d\n\n0 - off\n1 - on\n",
4794 mutex_unlock(&wl
->mutex
);
4800 static ssize_t
wl1271_sysfs_store_bt_coex_state(struct device
*dev
,
4801 struct device_attribute
*attr
,
4802 const char *buf
, size_t count
)
4804 struct wl1271
*wl
= dev_get_drvdata(dev
);
4808 ret
= kstrtoul(buf
, 10, &res
);
4810 wl1271_warning("incorrect value written to bt_coex_mode");
4814 mutex_lock(&wl
->mutex
);
4818 if (res
== wl
->sg_enabled
)
4821 wl
->sg_enabled
= res
;
4823 if (wl
->state
== WL1271_STATE_OFF
)
4826 ret
= wl1271_ps_elp_wakeup(wl
);
4830 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
4831 wl1271_ps_elp_sleep(wl
);
4834 mutex_unlock(&wl
->mutex
);
4838 static DEVICE_ATTR(bt_coex_state
, S_IRUGO
| S_IWUSR
,
4839 wl1271_sysfs_show_bt_coex_state
,
4840 wl1271_sysfs_store_bt_coex_state
);
4842 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
4843 struct device_attribute
*attr
,
4846 struct wl1271
*wl
= dev_get_drvdata(dev
);
4851 mutex_lock(&wl
->mutex
);
4852 if (wl
->hw_pg_ver
>= 0)
4853 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
4855 len
= snprintf(buf
, len
, "n/a\n");
4856 mutex_unlock(&wl
->mutex
);
4861 static DEVICE_ATTR(hw_pg_ver
, S_IRUGO
,
4862 wl1271_sysfs_show_hw_pg_ver
, NULL
);
4864 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
4865 struct bin_attribute
*bin_attr
,
4866 char *buffer
, loff_t pos
, size_t count
)
4868 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4869 struct wl1271
*wl
= dev_get_drvdata(dev
);
4873 ret
= mutex_lock_interruptible(&wl
->mutex
);
4875 return -ERESTARTSYS
;
4877 /* Let only one thread read the log at a time, blocking others */
4878 while (wl
->fwlog_size
== 0) {
4881 prepare_to_wait_exclusive(&wl
->fwlog_waitq
,
4883 TASK_INTERRUPTIBLE
);
4885 if (wl
->fwlog_size
!= 0) {
4886 finish_wait(&wl
->fwlog_waitq
, &wait
);
4890 mutex_unlock(&wl
->mutex
);
4893 finish_wait(&wl
->fwlog_waitq
, &wait
);
4895 if (signal_pending(current
))
4896 return -ERESTARTSYS
;
4898 ret
= mutex_lock_interruptible(&wl
->mutex
);
4900 return -ERESTARTSYS
;
4903 /* Check if the fwlog is still valid */
4904 if (wl
->fwlog_size
< 0) {
4905 mutex_unlock(&wl
->mutex
);
4909 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4910 len
= min(count
, (size_t)wl
->fwlog_size
);
4911 wl
->fwlog_size
-= len
;
4912 memcpy(buffer
, wl
->fwlog
, len
);
4914 /* Make room for new messages */
4915 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
4917 mutex_unlock(&wl
->mutex
);
4922 static struct bin_attribute fwlog_attr
= {
4923 .attr
= {.name
= "fwlog", .mode
= S_IRUSR
},
4924 .read
= wl1271_sysfs_read_fwlog
,
4927 static void wl12xx_derive_mac_addresses(struct wl1271
*wl
,
4928 u32 oui
, u32 nic
, int n
)
4932 wl1271_debug(DEBUG_PROBE
, "base address: oui %06x nic %06x, n %d",
4935 if (nic
+ n
- 1 > 0xffffff)
4936 wl1271_warning("NIC part of the MAC address wraps around!");
4938 for (i
= 0; i
< n
; i
++) {
4939 wl
->addresses
[i
].addr
[0] = (u8
)(oui
>> 16);
4940 wl
->addresses
[i
].addr
[1] = (u8
)(oui
>> 8);
4941 wl
->addresses
[i
].addr
[2] = (u8
) oui
;
4942 wl
->addresses
[i
].addr
[3] = (u8
)(nic
>> 16);
4943 wl
->addresses
[i
].addr
[4] = (u8
)(nic
>> 8);
4944 wl
->addresses
[i
].addr
[5] = (u8
) nic
;
4948 wl
->hw
->wiphy
->n_addresses
= n
;
4949 wl
->hw
->wiphy
->addresses
= wl
->addresses
;
4952 static int wl12xx_get_hw_info(struct wl1271
*wl
)
4956 ret
= wl12xx_set_power_on(wl
);
4960 wl
->chip
.id
= wlcore_read_reg(wl
, REG_CHIP_ID_B
);
4962 wl
->fuse_oui_addr
= 0;
4963 wl
->fuse_nic_addr
= 0;
4965 wl
->hw_pg_ver
= wl
->ops
->get_pg_ver(wl
);
4967 if (wl
->ops
->get_mac
)
4968 wl
->ops
->get_mac(wl
);
4970 wl1271_power_off(wl
);
4975 static int wl1271_register_hw(struct wl1271
*wl
)
4978 u32 oui_addr
= 0, nic_addr
= 0;
4980 if (wl
->mac80211_registered
)
4983 ret
= wl12xx_get_hw_info(wl
);
4985 wl1271_error("couldn't get hw info");
4989 ret
= wl1271_fetch_nvs(wl
);
4991 /* NOTE: The wl->nvs->nvs element must be first, in
4992 * order to simplify the casting, we assume it is at
4993 * the beginning of the wl->nvs structure.
4995 u8
*nvs_ptr
= (u8
*)wl
->nvs
;
4998 (nvs_ptr
[11] << 16) + (nvs_ptr
[10] << 8) + nvs_ptr
[6];
5000 (nvs_ptr
[5] << 16) + (nvs_ptr
[4] << 8) + nvs_ptr
[3];
5003 /* if the MAC address is zeroed in the NVS derive from fuse */
5004 if (oui_addr
== 0 && nic_addr
== 0) {
5005 oui_addr
= wl
->fuse_oui_addr
;
5006 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5007 nic_addr
= wl
->fuse_nic_addr
+ 1;
5010 wl12xx_derive_mac_addresses(wl
, oui_addr
, nic_addr
, 2);
5012 ret
= ieee80211_register_hw(wl
->hw
);
5014 wl1271_error("unable to register mac80211 hw: %d", ret
);
5018 wl
->mac80211_registered
= true;
5020 wl1271_debugfs_init(wl
);
5022 wl1271_notice("loaded");
5028 static void wl1271_unregister_hw(struct wl1271
*wl
)
5031 wl1271_plt_stop(wl
);
5033 ieee80211_unregister_hw(wl
->hw
);
5034 wl
->mac80211_registered
= false;
5038 static int wl1271_init_ieee80211(struct wl1271
*wl
)
5040 static const u32 cipher_suites
[] = {
5041 WLAN_CIPHER_SUITE_WEP40
,
5042 WLAN_CIPHER_SUITE_WEP104
,
5043 WLAN_CIPHER_SUITE_TKIP
,
5044 WLAN_CIPHER_SUITE_CCMP
,
5045 WL1271_CIPHER_SUITE_GEM
,
5048 /* The tx descriptor buffer and the TKIP space. */
5049 wl
->hw
->extra_tx_headroom
= WL1271_EXTRA_SPACE_TKIP
+
5050 sizeof(struct wl1271_tx_hw_descr
);
5053 /* FIXME: find a proper value */
5054 wl
->hw
->channel_change_time
= 10000;
5055 wl
->hw
->max_listen_interval
= wl
->conf
.conn
.max_listen_interval
;
5057 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
5058 IEEE80211_HW_SUPPORTS_PS
|
5059 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
5060 IEEE80211_HW_SUPPORTS_UAPSD
|
5061 IEEE80211_HW_HAS_RATE_CONTROL
|
5062 IEEE80211_HW_CONNECTION_MONITOR
|
5063 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
5064 IEEE80211_HW_SPECTRUM_MGMT
|
5065 IEEE80211_HW_AP_LINK_PS
|
5066 IEEE80211_HW_AMPDU_AGGREGATION
|
5067 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
|
5068 IEEE80211_HW_SCAN_WHILE_IDLE
;
5070 wl
->hw
->wiphy
->cipher_suites
= cipher_suites
;
5071 wl
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
5073 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5074 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_AP
) |
5075 BIT(NL80211_IFTYPE_P2P_CLIENT
) | BIT(NL80211_IFTYPE_P2P_GO
);
5076 wl
->hw
->wiphy
->max_scan_ssids
= 1;
5077 wl
->hw
->wiphy
->max_sched_scan_ssids
= 16;
5078 wl
->hw
->wiphy
->max_match_sets
= 16;
5080 * Maximum length of elements in scanning probe request templates
5081 * should be the maximum length possible for a template, without
5082 * the IEEE80211 header of the template
5084 wl
->hw
->wiphy
->max_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5085 sizeof(struct ieee80211_header
);
5087 wl
->hw
->wiphy
->max_sched_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5088 sizeof(struct ieee80211_header
);
5090 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
5092 /* make sure all our channels fit in the scanned_ch bitmask */
5093 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels
) +
5094 ARRAY_SIZE(wl1271_channels_5ghz
) >
5095 WL1271_MAX_CHANNELS
);
5097 * We keep local copies of the band structs because we need to
5098 * modify them on a per-device basis.
5100 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
], &wl1271_band_2ghz
,
5101 sizeof(wl1271_band_2ghz
));
5102 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
], &wl1271_band_5ghz
,
5103 sizeof(wl1271_band_5ghz
));
5105 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5106 &wl
->bands
[IEEE80211_BAND_2GHZ
];
5107 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5108 &wl
->bands
[IEEE80211_BAND_5GHZ
];
5111 wl
->hw
->max_rates
= 1;
5113 wl
->hw
->wiphy
->reg_notifier
= wl1271_reg_notify
;
5115 /* the FW answers probe-requests in AP-mode */
5116 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5117 wl
->hw
->wiphy
->probe_resp_offload
=
5118 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5119 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5120 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5122 SET_IEEE80211_DEV(wl
->hw
, wl
->dev
);
5124 wl
->hw
->sta_data_size
= sizeof(struct wl1271_station
);
5125 wl
->hw
->vif_data_size
= sizeof(struct wl12xx_vif
);
5127 wl
->hw
->max_rx_aggregation_subframes
= 8;
5132 #define WL1271_DEFAULT_CHANNEL 0
5134 struct ieee80211_hw
*wlcore_alloc_hw(size_t priv_size
)
5136 struct ieee80211_hw
*hw
;
5141 BUILD_BUG_ON(AP_MAX_STATIONS
> WL12XX_MAX_LINKS
);
5143 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
5145 wl1271_error("could not alloc ieee80211_hw");
5151 memset(wl
, 0, sizeof(*wl
));
5153 wl
->priv
= kzalloc(priv_size
, GFP_KERNEL
);
5155 wl1271_error("could not alloc wl priv");
5157 goto err_priv_alloc
;
5160 INIT_LIST_HEAD(&wl
->wlvif_list
);
5164 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
5165 for (j
= 0; j
< WL12XX_MAX_LINKS
; j
++)
5166 skb_queue_head_init(&wl
->links
[j
].tx_queue
[i
]);
5168 skb_queue_head_init(&wl
->deferred_rx_queue
);
5169 skb_queue_head_init(&wl
->deferred_tx_queue
);
5171 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
5172 INIT_WORK(&wl
->netstack_work
, wl1271_netstack_work
);
5173 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
5174 INIT_WORK(&wl
->recovery_work
, wl1271_recovery_work
);
5175 INIT_DELAYED_WORK(&wl
->scan_complete_work
, wl1271_scan_complete_work
);
5176 INIT_DELAYED_WORK(&wl
->tx_watchdog_work
, wl12xx_tx_watchdog_work
);
5178 wl
->freezable_wq
= create_freezable_workqueue("wl12xx_wq");
5179 if (!wl
->freezable_wq
) {
5184 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
5186 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
5187 wl
->band
= IEEE80211_BAND_2GHZ
;
5189 wl
->sg_enabled
= true;
5192 wl
->ap_fw_ps_map
= 0;
5194 wl
->platform_quirks
= 0;
5195 wl
->sched_scanning
= false;
5196 wl
->system_hlid
= WL12XX_SYSTEM_HLID
;
5197 wl
->active_sta_count
= 0;
5199 init_waitqueue_head(&wl
->fwlog_waitq
);
5201 /* The system link is always allocated */
5202 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
5204 memset(wl
->tx_frames_map
, 0, sizeof(wl
->tx_frames_map
));
5205 for (i
= 0; i
< wl
->num_tx_desc
; i
++)
5206 wl
->tx_frames
[i
] = NULL
;
5208 spin_lock_init(&wl
->wl_lock
);
5210 wl
->state
= WL1271_STATE_OFF
;
5211 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5212 mutex_init(&wl
->mutex
);
5214 /* Apply default driver configuration. */
5215 wl1271_conf_init(wl
);
5217 order
= get_order(WL1271_AGGR_BUFFER_SIZE
);
5218 wl
->aggr_buf
= (u8
*)__get_free_pages(GFP_KERNEL
, order
);
5219 if (!wl
->aggr_buf
) {
5224 wl
->dummy_packet
= wl12xx_alloc_dummy_packet(wl
);
5225 if (!wl
->dummy_packet
) {
5230 /* Allocate one page for the FW log */
5231 wl
->fwlog
= (u8
*)get_zeroed_page(GFP_KERNEL
);
5234 goto err_dummy_packet
;
5237 wl
->mbox
= kmalloc(sizeof(*wl
->mbox
), GFP_DMA
);
5246 free_page((unsigned long)wl
->fwlog
);
5249 dev_kfree_skb(wl
->dummy_packet
);
5252 free_pages((unsigned long)wl
->aggr_buf
, order
);
5255 destroy_workqueue(wl
->freezable_wq
);
5258 wl1271_debugfs_exit(wl
);
5262 ieee80211_free_hw(hw
);
5266 return ERR_PTR(ret
);
5268 EXPORT_SYMBOL_GPL(wlcore_alloc_hw
);
5270 int wlcore_free_hw(struct wl1271
*wl
)
5272 /* Unblock any fwlog readers */
5273 mutex_lock(&wl
->mutex
);
5274 wl
->fwlog_size
= -1;
5275 wake_up_interruptible_all(&wl
->fwlog_waitq
);
5276 mutex_unlock(&wl
->mutex
);
5278 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
5280 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5282 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5283 free_page((unsigned long)wl
->fwlog
);
5284 dev_kfree_skb(wl
->dummy_packet
);
5285 free_pages((unsigned long)wl
->aggr_buf
,
5286 get_order(WL1271_AGGR_BUFFER_SIZE
));
5288 wl1271_debugfs_exit(wl
);
5292 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5296 kfree(wl
->fw_status
);
5297 kfree(wl
->tx_res_if
);
5298 destroy_workqueue(wl
->freezable_wq
);
5301 ieee80211_free_hw(wl
->hw
);
5305 EXPORT_SYMBOL_GPL(wlcore_free_hw
);
5307 static irqreturn_t
wl12xx_hardirq(int irq
, void *cookie
)
5309 struct wl1271
*wl
= cookie
;
5310 unsigned long flags
;
5312 wl1271_debug(DEBUG_IRQ
, "IRQ");
5314 /* complete the ELP completion */
5315 spin_lock_irqsave(&wl
->wl_lock
, flags
);
5316 set_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
5317 if (wl
->elp_compl
) {
5318 complete(wl
->elp_compl
);
5319 wl
->elp_compl
= NULL
;
5322 if (test_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
)) {
5323 /* don't enqueue a work right now. mark it as pending */
5324 set_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
);
5325 wl1271_debug(DEBUG_IRQ
, "should not enqueue work");
5326 disable_irq_nosync(wl
->irq
);
5327 pm_wakeup_event(wl
->dev
, 0);
5328 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5331 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5333 return IRQ_WAKE_THREAD
;
5336 int __devinit
wlcore_probe(struct wl1271
*wl
, struct platform_device
*pdev
)
5338 struct wl12xx_platform_data
*pdata
= pdev
->dev
.platform_data
;
5339 unsigned long irqflags
;
5342 if (!wl
->ops
|| !wl
->ptable
) {
5347 BUG_ON(wl
->num_tx_desc
> WLCORE_MAX_TX_DESCRIPTORS
);
5349 wl
->irq
= platform_get_irq(pdev
, 0);
5350 wl
->ref_clock
= pdata
->board_ref_clock
;
5351 wl
->tcxo_clock
= pdata
->board_tcxo_clock
;
5352 wl
->platform_quirks
= pdata
->platform_quirks
;
5353 wl
->set_power
= pdata
->set_power
;
5354 wl
->dev
= &pdev
->dev
;
5355 wl
->if_ops
= pdata
->ops
;
5357 platform_set_drvdata(pdev
, wl
);
5359 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
5360 irqflags
= IRQF_TRIGGER_RISING
;
5362 irqflags
= IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
;
5364 ret
= request_threaded_irq(wl
->irq
, wl12xx_hardirq
, wl1271_irq
,
5368 wl1271_error("request_irq() failed: %d", ret
);
5372 ret
= enable_irq_wake(wl
->irq
);
5374 wl
->irq_wake_enabled
= true;
5375 device_init_wakeup(wl
->dev
, 1);
5376 if (pdata
->pwr_in_suspend
)
5377 wl
->hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_ANY
;
5380 disable_irq(wl
->irq
);
5382 ret
= wl1271_init_ieee80211(wl
);
5386 ret
= wl1271_register_hw(wl
);
5390 /* Create sysfs file to control bt coex state */
5391 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
5393 wl1271_error("failed to create sysfs file bt_coex_state");
5397 /* Create sysfs file to get HW PG version */
5398 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5400 wl1271_error("failed to create sysfs file hw_pg_ver");
5401 goto out_bt_coex_state
;
5404 /* Create sysfs file for the FW log */
5405 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
5407 wl1271_error("failed to create sysfs file fwlog");
5414 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5417 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5420 free_irq(wl
->irq
, wl
);
5428 EXPORT_SYMBOL_GPL(wlcore_probe
);
5430 int __devexit
wlcore_remove(struct platform_device
*pdev
)
5432 struct wl1271
*wl
= platform_get_drvdata(pdev
);
5434 if (wl
->irq_wake_enabled
) {
5435 device_init_wakeup(wl
->dev
, 0);
5436 disable_irq_wake(wl
->irq
);
5438 wl1271_unregister_hw(wl
);
5439 free_irq(wl
->irq
, wl
);
5444 EXPORT_SYMBOL_GPL(wlcore_remove
);
5446 u32 wl12xx_debug_level
= DEBUG_NONE
;
5447 EXPORT_SYMBOL_GPL(wl12xx_debug_level
);
5448 module_param_named(debug_level
, wl12xx_debug_level
, uint
, S_IRUSR
| S_IWUSR
);
5449 MODULE_PARM_DESC(debug_level
, "wl12xx debugging level");
5451 module_param_named(fwlog
, fwlog_param
, charp
, 0);
5452 MODULE_PARM_DESC(fwlog
,
5453 "FW logger options: continuous, ondemand, dbgpins or disable");
5455 module_param(bug_on_recovery
, bool, S_IRUSR
| S_IWUSR
);
5456 MODULE_PARM_DESC(bug_on_recovery
, "BUG() on fw recovery");
5458 MODULE_LICENSE("GPL");
5459 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5460 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");