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 ret
= wl
->ops
->hw_init(wl
);
679 ret
= wl1271_acx_init_mem_config(wl
);
683 ret
= wl12xx_acx_mem_cfg(wl
);
685 goto out_free_memmap
;
687 /* Enable data path */
688 ret
= wl1271_cmd_data_path(wl
, 1);
690 goto out_free_memmap
;
692 /* Configure for CAM power saving (ie. always active) */
693 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
695 goto out_free_memmap
;
698 ret
= wl1271_acx_pm_config(wl
);
700 goto out_free_memmap
;
705 kfree(wl
->target_mem_map
);
706 wl
->target_mem_map
= NULL
;
711 static void wl12xx_irq_ps_regulate_link(struct wl1271
*wl
,
712 struct wl12xx_vif
*wlvif
,
715 bool fw_ps
, single_sta
;
717 fw_ps
= test_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
718 single_sta
= (wl
->active_sta_count
== 1);
721 * Wake up from high level PS if the STA is asleep with too little
722 * packets in FW or if the STA is awake.
724 if (!fw_ps
|| tx_pkts
< WL1271_PS_STA_MAX_PACKETS
)
725 wl12xx_ps_link_end(wl
, wlvif
, hlid
);
728 * Start high-level PS if the STA is asleep with enough blocks in FW.
729 * Make an exception if this is the only connected station. In this
730 * case FW-memory congestion is not a problem.
732 else if (!single_sta
&& fw_ps
&& tx_pkts
>= WL1271_PS_STA_MAX_PACKETS
)
733 wl12xx_ps_link_start(wl
, wlvif
, hlid
, true);
736 static void wl12xx_irq_update_links_status(struct wl1271
*wl
,
737 struct wl12xx_vif
*wlvif
,
738 struct wl12xx_fw_status
*status
)
740 struct wl1271_link
*lnk
;
744 /* TODO: also use link_fast_bitmap here */
746 cur_fw_ps_map
= le32_to_cpu(status
->link_ps_bitmap
);
747 if (wl
->ap_fw_ps_map
!= cur_fw_ps_map
) {
748 wl1271_debug(DEBUG_PSM
,
749 "link ps prev 0x%x cur 0x%x changed 0x%x",
750 wl
->ap_fw_ps_map
, cur_fw_ps_map
,
751 wl
->ap_fw_ps_map
^ cur_fw_ps_map
);
753 wl
->ap_fw_ps_map
= cur_fw_ps_map
;
756 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
, WL12XX_MAX_LINKS
) {
757 lnk
= &wl
->links
[hlid
];
758 cnt
= status
->tx_lnk_free_pkts
[hlid
] - lnk
->prev_freed_pkts
;
760 lnk
->prev_freed_pkts
= status
->tx_lnk_free_pkts
[hlid
];
761 lnk
->allocated_pkts
-= cnt
;
763 wl12xx_irq_ps_regulate_link(wl
, wlvif
, hlid
,
764 lnk
->allocated_pkts
);
768 static void wl12xx_fw_status(struct wl1271
*wl
,
769 struct wl12xx_fw_status
*status
)
771 struct wl12xx_vif
*wlvif
;
773 u32 old_tx_blk_count
= wl
->tx_blocks_available
;
774 int avail
, freed_blocks
;
777 wlcore_raw_read_data(wl
, REG_RAW_FW_STATUS_ADDR
, status
,
778 sizeof(*status
), false);
780 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
781 "drv_rx_counter = %d, tx_results_counter = %d)",
783 status
->fw_rx_counter
,
784 status
->drv_rx_counter
,
785 status
->tx_results_counter
);
787 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
788 /* prevent wrap-around in freed-packets counter */
789 wl
->tx_allocated_pkts
[i
] -=
790 (status
->tx_released_pkts
[i
] -
791 wl
->tx_pkts_freed
[i
]) & 0xff;
793 wl
->tx_pkts_freed
[i
] = status
->tx_released_pkts
[i
];
796 /* prevent wrap-around in total blocks counter */
797 if (likely(wl
->tx_blocks_freed
<=
798 le32_to_cpu(status
->total_released_blks
)))
799 freed_blocks
= le32_to_cpu(status
->total_released_blks
) -
802 freed_blocks
= 0x100000000LL
- wl
->tx_blocks_freed
+
803 le32_to_cpu(status
->total_released_blks
);
805 wl
->tx_blocks_freed
= le32_to_cpu(status
->total_released_blks
);
807 wl
->tx_allocated_blocks
-= freed_blocks
;
810 * If the FW freed some blocks:
811 * If we still have allocated blocks - re-arm the timer, Tx is
812 * not stuck. Otherwise, cancel the timer (no Tx currently).
815 if (wl
->tx_allocated_blocks
)
816 wl12xx_rearm_tx_watchdog_locked(wl
);
818 cancel_delayed_work(&wl
->tx_watchdog_work
);
821 avail
= le32_to_cpu(status
->tx_total
) - wl
->tx_allocated_blocks
;
824 * The FW might change the total number of TX memblocks before
825 * we get a notification about blocks being released. Thus, the
826 * available blocks calculation might yield a temporary result
827 * which is lower than the actual available blocks. Keeping in
828 * mind that only blocks that were allocated can be moved from
829 * TX to RX, tx_blocks_available should never decrease here.
831 wl
->tx_blocks_available
= max((int)wl
->tx_blocks_available
,
834 /* if more blocks are available now, tx work can be scheduled */
835 if (wl
->tx_blocks_available
> old_tx_blk_count
)
836 clear_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
);
838 /* for AP update num of allocated TX blocks per link and ps status */
839 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
840 wl12xx_irq_update_links_status(wl
, wlvif
, status
);
843 /* update the host-chipset time offset */
845 wl
->time_offset
= (timespec_to_ns(&ts
) >> 10) -
846 (s64
)le32_to_cpu(status
->fw_localtime
);
849 static void wl1271_flush_deferred_work(struct wl1271
*wl
)
853 /* Pass all received frames to the network stack */
854 while ((skb
= skb_dequeue(&wl
->deferred_rx_queue
)))
855 ieee80211_rx_ni(wl
->hw
, skb
);
857 /* Return sent skbs to the network stack */
858 while ((skb
= skb_dequeue(&wl
->deferred_tx_queue
)))
859 ieee80211_tx_status_ni(wl
->hw
, skb
);
862 static void wl1271_netstack_work(struct work_struct
*work
)
865 container_of(work
, struct wl1271
, netstack_work
);
868 wl1271_flush_deferred_work(wl
);
869 } while (skb_queue_len(&wl
->deferred_rx_queue
));
872 #define WL1271_IRQ_MAX_LOOPS 256
874 static irqreturn_t
wl1271_irq(int irq
, void *cookie
)
878 int loopcount
= WL1271_IRQ_MAX_LOOPS
;
879 struct wl1271
*wl
= (struct wl1271
*)cookie
;
881 unsigned int defer_count
;
884 /* TX might be handled here, avoid redundant work */
885 set_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
886 cancel_work_sync(&wl
->tx_work
);
889 * In case edge triggered interrupt must be used, we cannot iterate
890 * more than once without introducing race conditions with the hardirq.
892 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
895 mutex_lock(&wl
->mutex
);
897 wl1271_debug(DEBUG_IRQ
, "IRQ work");
899 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
902 ret
= wl1271_ps_elp_wakeup(wl
);
906 while (!done
&& loopcount
--) {
908 * In order to avoid a race with the hardirq, clear the flag
909 * before acknowledging the chip. Since the mutex is held,
910 * wl1271_ps_elp_wakeup cannot be called concurrently.
912 clear_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
913 smp_mb__after_clear_bit();
915 wl12xx_fw_status(wl
, wl
->fw_status
);
917 wlcore_hw_tx_immediate_compl(wl
);
919 intr
= le32_to_cpu(wl
->fw_status
->intr
);
920 intr
&= WL1271_INTR_MASK
;
926 if (unlikely(intr
& WL1271_ACX_INTR_WATCHDOG
)) {
927 wl1271_error("watchdog interrupt received! "
928 "starting recovery.");
929 wl12xx_queue_recovery_work(wl
);
931 /* restarting the chip. ignore any other interrupt. */
935 if (likely(intr
& WL1271_ACX_INTR_DATA
)) {
936 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
938 wl12xx_rx(wl
, wl
->fw_status
);
940 /* Check if any tx blocks were freed */
941 spin_lock_irqsave(&wl
->wl_lock
, flags
);
942 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
943 wl1271_tx_total_queue_count(wl
) > 0) {
944 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
946 * In order to avoid starvation of the TX path,
947 * call the work function directly.
949 wl1271_tx_work_locked(wl
);
951 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
954 /* check for tx results */
955 wlcore_hw_tx_delayed_compl(wl
);
957 /* Make sure the deferred queues don't get too long */
958 defer_count
= skb_queue_len(&wl
->deferred_tx_queue
) +
959 skb_queue_len(&wl
->deferred_rx_queue
);
960 if (defer_count
> WL1271_DEFERRED_QUEUE_LIMIT
)
961 wl1271_flush_deferred_work(wl
);
964 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
965 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
966 wl1271_event_handle(wl
, 0);
969 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
970 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
971 wl1271_event_handle(wl
, 1);
974 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
975 wl1271_debug(DEBUG_IRQ
,
976 "WL1271_ACX_INTR_INIT_COMPLETE");
978 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
979 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
982 wl1271_ps_elp_sleep(wl
);
985 spin_lock_irqsave(&wl
->wl_lock
, flags
);
986 /* In case TX was not handled here, queue TX work */
987 clear_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
988 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
989 wl1271_tx_total_queue_count(wl
) > 0)
990 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
991 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
993 mutex_unlock(&wl
->mutex
);
998 struct vif_counter_data
{
1001 struct ieee80211_vif
*cur_vif
;
1002 bool cur_vif_running
;
1005 static void wl12xx_vif_count_iter(void *data
, u8
*mac
,
1006 struct ieee80211_vif
*vif
)
1008 struct vif_counter_data
*counter
= data
;
1011 if (counter
->cur_vif
== vif
)
1012 counter
->cur_vif_running
= true;
1015 /* caller must not hold wl->mutex, as it might deadlock */
1016 static void wl12xx_get_vif_count(struct ieee80211_hw
*hw
,
1017 struct ieee80211_vif
*cur_vif
,
1018 struct vif_counter_data
*data
)
1020 memset(data
, 0, sizeof(*data
));
1021 data
->cur_vif
= cur_vif
;
1023 ieee80211_iterate_active_interfaces(hw
,
1024 wl12xx_vif_count_iter
, data
);
1027 static int wl12xx_fetch_firmware(struct wl1271
*wl
, bool plt
)
1029 const struct firmware
*fw
;
1030 const char *fw_name
;
1031 enum wl12xx_fw_type fw_type
;
1035 fw_type
= WL12XX_FW_TYPE_PLT
;
1036 fw_name
= wl
->plt_fw_name
;
1039 * we can't call wl12xx_get_vif_count() here because
1040 * wl->mutex is taken, so use the cached last_vif_count value
1042 if (wl
->last_vif_count
> 1) {
1043 fw_type
= WL12XX_FW_TYPE_MULTI
;
1044 fw_name
= wl
->mr_fw_name
;
1046 fw_type
= WL12XX_FW_TYPE_NORMAL
;
1047 fw_name
= wl
->sr_fw_name
;
1051 if (wl
->fw_type
== fw_type
)
1054 wl1271_debug(DEBUG_BOOT
, "booting firmware %s", fw_name
);
1056 ret
= request_firmware(&fw
, fw_name
, wl
->dev
);
1059 wl1271_error("could not get firmware %s: %d", fw_name
, ret
);
1064 wl1271_error("firmware size is not multiple of 32 bits: %zu",
1071 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
1072 wl
->fw_len
= fw
->size
;
1073 wl
->fw
= vmalloc(wl
->fw_len
);
1076 wl1271_error("could not allocate memory for the firmware");
1081 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
1083 wl
->fw_type
= fw_type
;
1085 release_firmware(fw
);
1090 static int wl1271_fetch_nvs(struct wl1271
*wl
)
1092 const struct firmware
*fw
;
1095 ret
= request_firmware(&fw
, WL12XX_NVS_NAME
, wl
->dev
);
1098 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME
,
1103 wl
->nvs
= kmemdup(fw
->data
, fw
->size
, GFP_KERNEL
);
1106 wl1271_error("could not allocate memory for the nvs file");
1111 wl
->nvs_len
= fw
->size
;
1114 release_firmware(fw
);
1119 void wl12xx_queue_recovery_work(struct wl1271
*wl
)
1121 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
1122 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
1125 size_t wl12xx_copy_fwlog(struct wl1271
*wl
, u8
*memblock
, size_t maxlen
)
1129 /* The FW log is a length-value list, find where the log end */
1130 while (len
< maxlen
) {
1131 if (memblock
[len
] == 0)
1133 if (len
+ memblock
[len
] + 1 > maxlen
)
1135 len
+= memblock
[len
] + 1;
1138 /* Make sure we have enough room */
1139 len
= min(len
, (size_t)(PAGE_SIZE
- wl
->fwlog_size
));
1141 /* Fill the FW log file, consumed by the sysfs fwlog entry */
1142 memcpy(wl
->fwlog
+ wl
->fwlog_size
, memblock
, len
);
1143 wl
->fwlog_size
+= len
;
1148 static void wl12xx_read_fwlog_panic(struct wl1271
*wl
)
1154 if ((wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
) ||
1155 (wl
->conf
.fwlog
.mode
!= WL12XX_FWLOG_ON_DEMAND
) ||
1156 (wl
->conf
.fwlog
.mem_blocks
== 0))
1159 wl1271_info("Reading FW panic log");
1161 block
= kmalloc(WL12XX_HW_BLOCK_SIZE
, GFP_KERNEL
);
1166 * Make sure the chip is awake and the logger isn't active.
1167 * This might fail if the firmware hanged.
1169 if (!wl1271_ps_elp_wakeup(wl
))
1170 wl12xx_cmd_stop_fwlog(wl
);
1172 /* Read the first memory block address */
1173 wl12xx_fw_status(wl
, wl
->fw_status
);
1174 first_addr
= le32_to_cpu(wl
->fw_status
->log_start_addr
);
1178 /* Traverse the memory blocks linked list */
1181 memset(block
, 0, WL12XX_HW_BLOCK_SIZE
);
1182 wl1271_read_hwaddr(wl
, addr
, block
, WL12XX_HW_BLOCK_SIZE
,
1186 * Memory blocks are linked to one another. The first 4 bytes
1187 * of each memory block hold the hardware address of the next
1188 * one. The last memory block points to the first one.
1190 addr
= le32_to_cpup((__le32
*)block
);
1191 if (!wl12xx_copy_fwlog(wl
, block
+ sizeof(addr
),
1192 WL12XX_HW_BLOCK_SIZE
- sizeof(addr
)))
1194 } while (addr
&& (addr
!= first_addr
));
1196 wake_up_interruptible(&wl
->fwlog_waitq
);
1202 static void wl1271_recovery_work(struct work_struct
*work
)
1205 container_of(work
, struct wl1271
, recovery_work
);
1206 struct wl12xx_vif
*wlvif
;
1207 struct ieee80211_vif
*vif
;
1209 mutex_lock(&wl
->mutex
);
1211 if (wl
->state
!= WL1271_STATE_ON
|| wl
->plt
)
1214 /* Avoid a recursive recovery */
1215 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
1217 wl12xx_read_fwlog_panic(wl
);
1219 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
1220 wl
->chip
.fw_ver_str
,
1221 wlcore_read_reg(wl
, REG_PC_ON_RECOVERY
));
1223 BUG_ON(bug_on_recovery
&&
1224 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
));
1227 * Advance security sequence number to overcome potential progress
1228 * in the firmware during recovery. This doens't hurt if the network is
1231 wl12xx_for_each_wlvif(wl
, wlvif
) {
1232 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
1233 test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1234 wlvif
->tx_security_seq
+=
1235 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
1238 /* Prevent spurious TX during FW restart */
1239 ieee80211_stop_queues(wl
->hw
);
1241 if (wl
->sched_scanning
) {
1242 ieee80211_sched_scan_stopped(wl
->hw
);
1243 wl
->sched_scanning
= false;
1246 /* reboot the chipset */
1247 while (!list_empty(&wl
->wlvif_list
)) {
1248 wlvif
= list_first_entry(&wl
->wlvif_list
,
1249 struct wl12xx_vif
, list
);
1250 vif
= wl12xx_wlvif_to_vif(wlvif
);
1251 __wl1271_op_remove_interface(wl
, vif
, false);
1253 mutex_unlock(&wl
->mutex
);
1254 wl1271_op_stop(wl
->hw
);
1256 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
1258 ieee80211_restart_hw(wl
->hw
);
1261 * Its safe to enable TX now - the queues are stopped after a request
1262 * to restart the HW.
1264 ieee80211_wake_queues(wl
->hw
);
1267 mutex_unlock(&wl
->mutex
);
1270 static void wl1271_fw_wakeup(struct wl1271
*wl
)
1272 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG
, ELPCTRL_WAKE_UP
);
1275 static int wl1271_setup(struct wl1271
*wl
)
1277 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
1281 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
1282 if (!wl
->tx_res_if
) {
1283 kfree(wl
->fw_status
);
1290 static int wl12xx_set_power_on(struct wl1271
*wl
)
1294 msleep(WL1271_PRE_POWER_ON_SLEEP
);
1295 ret
= wl1271_power_on(wl
);
1298 msleep(WL1271_POWER_ON_SLEEP
);
1299 wl1271_io_reset(wl
);
1302 wlcore_set_partition(wl
, &wl
->ptable
[PART_BOOT
]);
1304 /* ELP module wake up */
1305 wl1271_fw_wakeup(wl
);
1311 static int wl12xx_chip_wakeup(struct wl1271
*wl
, bool plt
)
1315 ret
= wl12xx_set_power_on(wl
);
1320 * For wl127x based devices we could use the default block
1321 * size (512 bytes), but due to a bug in the sdio driver, we
1322 * need to set it explicitly after the chip is powered on. To
1323 * simplify the code and since the performance impact is
1324 * negligible, we use the same block size for all different
1327 if (wl1271_set_block_size(wl
))
1328 wl
->quirks
|= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN
;
1330 ret
= wl
->ops
->identify_chip(wl
);
1334 /* TODO: make sure the lower driver has set things up correctly */
1336 ret
= wl1271_setup(wl
);
1340 ret
= wl12xx_fetch_firmware(wl
, plt
);
1344 /* No NVS from netlink, try to get it from the filesystem */
1345 if (wl
->nvs
== NULL
) {
1346 ret
= wl1271_fetch_nvs(wl
);
1355 int wl1271_plt_start(struct wl1271
*wl
)
1357 int retries
= WL1271_BOOT_RETRIES
;
1358 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1361 mutex_lock(&wl
->mutex
);
1363 wl1271_notice("power up");
1365 if (wl
->state
!= WL1271_STATE_OFF
) {
1366 wl1271_error("cannot go into PLT state because not "
1367 "in off state: %d", wl
->state
);
1374 ret
= wl12xx_chip_wakeup(wl
, true);
1378 ret
= wl
->ops
->boot(wl
);
1382 ret
= wl1271_plt_init(wl
);
1387 wl
->state
= WL1271_STATE_ON
;
1388 wl1271_notice("firmware booted in PLT mode (%s)",
1389 wl
->chip
.fw_ver_str
);
1391 /* update hw/fw version info in wiphy struct */
1392 wiphy
->hw_version
= wl
->chip
.id
;
1393 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
1394 sizeof(wiphy
->fw_version
));
1399 mutex_unlock(&wl
->mutex
);
1400 /* Unlocking the mutex in the middle of handling is
1401 inherently unsafe. In this case we deem it safe to do,
1402 because we need to let any possibly pending IRQ out of
1403 the system (and while we are WL1271_STATE_OFF the IRQ
1404 work function will not do anything.) Also, any other
1405 possible concurrent operations will fail due to the
1406 current state, hence the wl1271 struct should be safe. */
1407 wlcore_disable_interrupts(wl
);
1408 wl1271_flush_deferred_work(wl
);
1409 cancel_work_sync(&wl
->netstack_work
);
1410 mutex_lock(&wl
->mutex
);
1412 wl1271_power_off(wl
);
1415 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1416 WL1271_BOOT_RETRIES
);
1418 mutex_unlock(&wl
->mutex
);
1423 int wl1271_plt_stop(struct wl1271
*wl
)
1427 wl1271_notice("power down");
1430 * Interrupts must be disabled before setting the state to OFF.
1431 * Otherwise, the interrupt handler might be called and exit without
1432 * reading the interrupt status.
1434 wlcore_disable_interrupts(wl
);
1435 mutex_lock(&wl
->mutex
);
1437 mutex_unlock(&wl
->mutex
);
1440 * This will not necessarily enable interrupts as interrupts
1441 * may have been disabled when op_stop was called. It will,
1442 * however, balance the above call to disable_interrupts().
1444 wlcore_enable_interrupts(wl
);
1446 wl1271_error("cannot power down because not in PLT "
1447 "state: %d", wl
->state
);
1452 mutex_unlock(&wl
->mutex
);
1454 wl1271_flush_deferred_work(wl
);
1455 cancel_work_sync(&wl
->netstack_work
);
1456 cancel_work_sync(&wl
->recovery_work
);
1457 cancel_delayed_work_sync(&wl
->elp_work
);
1458 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1460 mutex_lock(&wl
->mutex
);
1461 wl1271_power_off(wl
);
1463 wl
->state
= WL1271_STATE_OFF
;
1466 mutex_unlock(&wl
->mutex
);
1472 static void wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1474 struct wl1271
*wl
= hw
->priv
;
1475 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1476 struct ieee80211_vif
*vif
= info
->control
.vif
;
1477 struct wl12xx_vif
*wlvif
= NULL
;
1478 unsigned long flags
;
1483 wlvif
= wl12xx_vif_to_data(vif
);
1485 mapping
= skb_get_queue_mapping(skb
);
1486 q
= wl1271_tx_get_queue(mapping
);
1488 hlid
= wl12xx_tx_get_hlid(wl
, wlvif
, skb
);
1490 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1492 /* queue the packet */
1493 if (hlid
== WL12XX_INVALID_LINK_ID
||
1494 (wlvif
&& !test_bit(hlid
, wlvif
->links_map
))) {
1495 wl1271_debug(DEBUG_TX
, "DROP skb hlid %d q %d", hlid
, q
);
1496 ieee80211_free_txskb(hw
, skb
);
1500 wl1271_debug(DEBUG_TX
, "queue skb hlid %d q %d len %d",
1502 skb_queue_tail(&wl
->links
[hlid
].tx_queue
[q
], skb
);
1504 wl
->tx_queue_count
[q
]++;
1507 * The workqueue is slow to process the tx_queue and we need stop
1508 * the queue here, otherwise the queue will get too long.
1510 if (wl
->tx_queue_count
[q
] >= WL1271_TX_QUEUE_HIGH_WATERMARK
) {
1511 wl1271_debug(DEBUG_TX
, "op_tx: stopping queues for q %d", q
);
1512 ieee80211_stop_queue(wl
->hw
, mapping
);
1513 set_bit(q
, &wl
->stopped_queues_map
);
1517 * The chip specific setup must run before the first TX packet -
1518 * before that, the tx_work will not be initialized!
1521 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1522 !test_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
))
1523 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1526 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1529 int wl1271_tx_dummy_packet(struct wl1271
*wl
)
1531 unsigned long flags
;
1534 /* no need to queue a new dummy packet if one is already pending */
1535 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
))
1538 q
= wl1271_tx_get_queue(skb_get_queue_mapping(wl
->dummy_packet
));
1540 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1541 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
);
1542 wl
->tx_queue_count
[q
]++;
1543 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1545 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1546 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
))
1547 wl1271_tx_work_locked(wl
);
1550 * If the FW TX is busy, TX work will be scheduled by the threaded
1551 * interrupt handler function
1557 * The size of the dummy packet should be at least 1400 bytes. However, in
1558 * order to minimize the number of bus transactions, aligning it to 512 bytes
1559 * boundaries could be beneficial, performance wise
1561 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1563 static struct sk_buff
*wl12xx_alloc_dummy_packet(struct wl1271
*wl
)
1565 struct sk_buff
*skb
;
1566 struct ieee80211_hdr_3addr
*hdr
;
1567 unsigned int dummy_packet_size
;
1569 dummy_packet_size
= TOTAL_TX_DUMMY_PACKET_SIZE
-
1570 sizeof(struct wl1271_tx_hw_descr
) - sizeof(*hdr
);
1572 skb
= dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE
);
1574 wl1271_warning("Failed to allocate a dummy packet skb");
1578 skb_reserve(skb
, sizeof(struct wl1271_tx_hw_descr
));
1580 hdr
= (struct ieee80211_hdr_3addr
*) skb_put(skb
, sizeof(*hdr
));
1581 memset(hdr
, 0, sizeof(*hdr
));
1582 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1583 IEEE80211_STYPE_NULLFUNC
|
1584 IEEE80211_FCTL_TODS
);
1586 memset(skb_put(skb
, dummy_packet_size
), 0, dummy_packet_size
);
1588 /* Dummy packets require the TID to be management */
1589 skb
->priority
= WL1271_TID_MGMT
;
1591 /* Initialize all fields that might be used */
1592 skb_set_queue_mapping(skb
, 0);
1593 memset(IEEE80211_SKB_CB(skb
), 0, sizeof(struct ieee80211_tx_info
));
1600 static int wl1271_configure_suspend_sta(struct wl1271
*wl
,
1601 struct wl12xx_vif
*wlvif
)
1605 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1608 ret
= wl1271_ps_elp_wakeup(wl
);
1612 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1613 wl
->conf
.conn
.suspend_wake_up_event
,
1614 wl
->conf
.conn
.suspend_listen_interval
);
1617 wl1271_error("suspend: set wake up conditions failed: %d", ret
);
1619 wl1271_ps_elp_sleep(wl
);
1626 static int wl1271_configure_suspend_ap(struct wl1271
*wl
,
1627 struct wl12xx_vif
*wlvif
)
1631 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1634 ret
= wl1271_ps_elp_wakeup(wl
);
1638 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
1640 wl1271_ps_elp_sleep(wl
);
1646 static int wl1271_configure_suspend(struct wl1271
*wl
,
1647 struct wl12xx_vif
*wlvif
)
1649 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1650 return wl1271_configure_suspend_sta(wl
, wlvif
);
1651 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
1652 return wl1271_configure_suspend_ap(wl
, wlvif
);
1656 static void wl1271_configure_resume(struct wl1271
*wl
,
1657 struct wl12xx_vif
*wlvif
)
1660 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
1661 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
1663 if ((!is_ap
) && (!is_sta
))
1666 ret
= wl1271_ps_elp_wakeup(wl
);
1671 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1672 wl
->conf
.conn
.wake_up_event
,
1673 wl
->conf
.conn
.listen_interval
);
1676 wl1271_error("resume: wake up conditions failed: %d",
1680 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
1683 wl1271_ps_elp_sleep(wl
);
1686 static int wl1271_op_suspend(struct ieee80211_hw
*hw
,
1687 struct cfg80211_wowlan
*wow
)
1689 struct wl1271
*wl
= hw
->priv
;
1690 struct wl12xx_vif
*wlvif
;
1693 wl1271_debug(DEBUG_MAC80211
, "mac80211 suspend wow=%d", !!wow
);
1694 WARN_ON(!wow
|| !wow
->any
);
1696 wl1271_tx_flush(wl
);
1698 mutex_lock(&wl
->mutex
);
1699 wl
->wow_enabled
= true;
1700 wl12xx_for_each_wlvif(wl
, wlvif
) {
1701 ret
= wl1271_configure_suspend(wl
, wlvif
);
1703 wl1271_warning("couldn't prepare device to suspend");
1707 mutex_unlock(&wl
->mutex
);
1708 /* flush any remaining work */
1709 wl1271_debug(DEBUG_MAC80211
, "flushing remaining works");
1712 * disable and re-enable interrupts in order to flush
1715 wlcore_disable_interrupts(wl
);
1718 * set suspended flag to avoid triggering a new threaded_irq
1719 * work. no need for spinlock as interrupts are disabled.
1721 set_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1723 wlcore_enable_interrupts(wl
);
1724 flush_work(&wl
->tx_work
);
1725 flush_delayed_work(&wl
->elp_work
);
1730 static int wl1271_op_resume(struct ieee80211_hw
*hw
)
1732 struct wl1271
*wl
= hw
->priv
;
1733 struct wl12xx_vif
*wlvif
;
1734 unsigned long flags
;
1735 bool run_irq_work
= false;
1737 wl1271_debug(DEBUG_MAC80211
, "mac80211 resume wow=%d",
1739 WARN_ON(!wl
->wow_enabled
);
1742 * re-enable irq_work enqueuing, and call irq_work directly if
1743 * there is a pending work.
1745 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1746 clear_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1747 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
))
1748 run_irq_work
= true;
1749 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1752 wl1271_debug(DEBUG_MAC80211
,
1753 "run postponed irq_work directly");
1755 wlcore_enable_interrupts(wl
);
1758 mutex_lock(&wl
->mutex
);
1759 wl12xx_for_each_wlvif(wl
, wlvif
) {
1760 wl1271_configure_resume(wl
, wlvif
);
1762 wl
->wow_enabled
= false;
1763 mutex_unlock(&wl
->mutex
);
1769 static int wl1271_op_start(struct ieee80211_hw
*hw
)
1771 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
1774 * We have to delay the booting of the hardware because
1775 * we need to know the local MAC address before downloading and
1776 * initializing the firmware. The MAC address cannot be changed
1777 * after boot, and without the proper MAC address, the firmware
1778 * will not function properly.
1780 * The MAC address is first known when the corresponding interface
1781 * is added. That is where we will initialize the hardware.
1787 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
1789 struct wl1271
*wl
= hw
->priv
;
1792 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
1795 * Interrupts must be disabled before setting the state to OFF.
1796 * Otherwise, the interrupt handler might be called and exit without
1797 * reading the interrupt status.
1799 wlcore_disable_interrupts(wl
);
1800 mutex_lock(&wl
->mutex
);
1801 if (wl
->state
== WL1271_STATE_OFF
) {
1802 mutex_unlock(&wl
->mutex
);
1805 * This will not necessarily enable interrupts as interrupts
1806 * may have been disabled when op_stop was called. It will,
1807 * however, balance the above call to disable_interrupts().
1809 wlcore_enable_interrupts(wl
);
1814 * this must be before the cancel_work calls below, so that the work
1815 * functions don't perform further work.
1817 wl
->state
= WL1271_STATE_OFF
;
1818 mutex_unlock(&wl
->mutex
);
1820 wl1271_flush_deferred_work(wl
);
1821 cancel_delayed_work_sync(&wl
->scan_complete_work
);
1822 cancel_work_sync(&wl
->netstack_work
);
1823 cancel_work_sync(&wl
->tx_work
);
1824 cancel_delayed_work_sync(&wl
->elp_work
);
1825 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1827 /* let's notify MAC80211 about the remaining pending TX frames */
1828 wl12xx_tx_reset(wl
, true);
1829 mutex_lock(&wl
->mutex
);
1831 wl1271_power_off(wl
);
1833 wl
->band
= IEEE80211_BAND_2GHZ
;
1836 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1837 wl
->tx_blocks_available
= 0;
1838 wl
->tx_allocated_blocks
= 0;
1839 wl
->tx_results_count
= 0;
1840 wl
->tx_packets_count
= 0;
1841 wl
->time_offset
= 0;
1842 wl
->ap_fw_ps_map
= 0;
1844 wl
->sched_scanning
= false;
1845 memset(wl
->roles_map
, 0, sizeof(wl
->roles_map
));
1846 memset(wl
->links_map
, 0, sizeof(wl
->links_map
));
1847 memset(wl
->roc_map
, 0, sizeof(wl
->roc_map
));
1848 wl
->active_sta_count
= 0;
1850 /* The system link is always allocated */
1851 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
1854 * this is performed after the cancel_work calls and the associated
1855 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1856 * get executed before all these vars have been reset.
1860 wl
->tx_blocks_freed
= 0;
1862 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1863 wl
->tx_pkts_freed
[i
] = 0;
1864 wl
->tx_allocated_pkts
[i
] = 0;
1867 wl1271_debugfs_reset(wl
);
1869 kfree(wl
->fw_status
);
1870 wl
->fw_status
= NULL
;
1871 kfree(wl
->tx_res_if
);
1872 wl
->tx_res_if
= NULL
;
1873 kfree(wl
->target_mem_map
);
1874 wl
->target_mem_map
= NULL
;
1876 mutex_unlock(&wl
->mutex
);
1879 static int wl12xx_allocate_rate_policy(struct wl1271
*wl
, u8
*idx
)
1881 u8 policy
= find_first_zero_bit(wl
->rate_policies_map
,
1882 WL12XX_MAX_RATE_POLICIES
);
1883 if (policy
>= WL12XX_MAX_RATE_POLICIES
)
1886 __set_bit(policy
, wl
->rate_policies_map
);
1891 static void wl12xx_free_rate_policy(struct wl1271
*wl
, u8
*idx
)
1893 if (WARN_ON(*idx
>= WL12XX_MAX_RATE_POLICIES
))
1896 __clear_bit(*idx
, wl
->rate_policies_map
);
1897 *idx
= WL12XX_MAX_RATE_POLICIES
;
1900 static u8
wl12xx_get_role_type(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1902 switch (wlvif
->bss_type
) {
1903 case BSS_TYPE_AP_BSS
:
1905 return WL1271_ROLE_P2P_GO
;
1907 return WL1271_ROLE_AP
;
1909 case BSS_TYPE_STA_BSS
:
1911 return WL1271_ROLE_P2P_CL
;
1913 return WL1271_ROLE_STA
;
1916 return WL1271_ROLE_IBSS
;
1919 wl1271_error("invalid bss_type: %d", wlvif
->bss_type
);
1921 return WL12XX_INVALID_ROLE_TYPE
;
1924 static int wl12xx_init_vif_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1926 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1929 /* clear everything but the persistent data */
1930 memset(wlvif
, 0, offsetof(struct wl12xx_vif
, persistent
));
1932 switch (ieee80211_vif_type_p2p(vif
)) {
1933 case NL80211_IFTYPE_P2P_CLIENT
:
1936 case NL80211_IFTYPE_STATION
:
1937 wlvif
->bss_type
= BSS_TYPE_STA_BSS
;
1939 case NL80211_IFTYPE_ADHOC
:
1940 wlvif
->bss_type
= BSS_TYPE_IBSS
;
1942 case NL80211_IFTYPE_P2P_GO
:
1945 case NL80211_IFTYPE_AP
:
1946 wlvif
->bss_type
= BSS_TYPE_AP_BSS
;
1949 wlvif
->bss_type
= MAX_BSS_TYPE
;
1953 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
1954 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
1955 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
1957 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1958 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1959 /* init sta/ibss data */
1960 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
1961 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
1962 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
1963 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
1966 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
1967 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
1968 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
1969 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
1970 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
1971 wl12xx_allocate_rate_policy(wl
,
1972 &wlvif
->ap
.ucast_rate_idx
[i
]);
1975 wlvif
->bitrate_masks
[IEEE80211_BAND_2GHZ
] = wl
->conf
.tx
.basic_rate
;
1976 wlvif
->bitrate_masks
[IEEE80211_BAND_5GHZ
] = wl
->conf
.tx
.basic_rate_5
;
1977 wlvif
->basic_rate_set
= CONF_TX_RATE_MASK_BASIC
;
1978 wlvif
->basic_rate
= CONF_TX_RATE_MASK_BASIC
;
1979 wlvif
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
1980 wlvif
->beacon_int
= WL1271_DEFAULT_BEACON_INT
;
1983 * mac80211 configures some values globally, while we treat them
1984 * per-interface. thus, on init, we have to copy them from wl
1986 wlvif
->band
= wl
->band
;
1987 wlvif
->channel
= wl
->channel
;
1988 wlvif
->power_level
= wl
->power_level
;
1990 INIT_WORK(&wlvif
->rx_streaming_enable_work
,
1991 wl1271_rx_streaming_enable_work
);
1992 INIT_WORK(&wlvif
->rx_streaming_disable_work
,
1993 wl1271_rx_streaming_disable_work
);
1994 INIT_LIST_HEAD(&wlvif
->list
);
1996 setup_timer(&wlvif
->rx_streaming_timer
, wl1271_rx_streaming_timer
,
1997 (unsigned long) wlvif
);
2001 static bool wl12xx_init_fw(struct wl1271
*wl
)
2003 int retries
= WL1271_BOOT_RETRIES
;
2004 bool booted
= false;
2005 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
2010 ret
= wl12xx_chip_wakeup(wl
, false);
2014 ret
= wl
->ops
->boot(wl
);
2018 ret
= wl1271_hw_init(wl
);
2026 mutex_unlock(&wl
->mutex
);
2027 /* Unlocking the mutex in the middle of handling is
2028 inherently unsafe. In this case we deem it safe to do,
2029 because we need to let any possibly pending IRQ out of
2030 the system (and while we are WL1271_STATE_OFF the IRQ
2031 work function will not do anything.) Also, any other
2032 possible concurrent operations will fail due to the
2033 current state, hence the wl1271 struct should be safe. */
2034 wlcore_disable_interrupts(wl
);
2035 wl1271_flush_deferred_work(wl
);
2036 cancel_work_sync(&wl
->netstack_work
);
2037 mutex_lock(&wl
->mutex
);
2039 wl1271_power_off(wl
);
2043 wl1271_error("firmware boot failed despite %d retries",
2044 WL1271_BOOT_RETRIES
);
2048 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver_str
);
2050 /* update hw/fw version info in wiphy struct */
2051 wiphy
->hw_version
= wl
->chip
.id
;
2052 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
2053 sizeof(wiphy
->fw_version
));
2056 * Now we know if 11a is supported (info from the NVS), so disable
2057 * 11a channels if not supported
2059 if (!wl
->enable_11a
)
2060 wiphy
->bands
[IEEE80211_BAND_5GHZ
]->n_channels
= 0;
2062 wl1271_debug(DEBUG_MAC80211
, "11a is %ssupported",
2063 wl
->enable_11a
? "" : "not ");
2065 wl
->state
= WL1271_STATE_ON
;
2070 static bool wl12xx_dev_role_started(struct wl12xx_vif
*wlvif
)
2072 return wlvif
->dev_hlid
!= WL12XX_INVALID_LINK_ID
;
2076 * Check whether a fw switch (i.e. moving from one loaded
2077 * fw to another) is needed. This function is also responsible
2078 * for updating wl->last_vif_count, so it must be called before
2079 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2082 static bool wl12xx_need_fw_change(struct wl1271
*wl
,
2083 struct vif_counter_data vif_counter_data
,
2086 enum wl12xx_fw_type current_fw
= wl
->fw_type
;
2087 u8 vif_count
= vif_counter_data
.counter
;
2089 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
))
2092 /* increase the vif count if this is a new vif */
2093 if (add
&& !vif_counter_data
.cur_vif_running
)
2096 wl
->last_vif_count
= vif_count
;
2098 /* no need for fw change if the device is OFF */
2099 if (wl
->state
== WL1271_STATE_OFF
)
2102 if (vif_count
> 1 && current_fw
== WL12XX_FW_TYPE_NORMAL
)
2104 if (vif_count
<= 1 && current_fw
== WL12XX_FW_TYPE_MULTI
)
2111 * Enter "forced psm". Make sure the sta is in psm against the ap,
2112 * to make the fw switch a bit more disconnection-persistent.
2114 static void wl12xx_force_active_psm(struct wl1271
*wl
)
2116 struct wl12xx_vif
*wlvif
;
2118 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
2119 wl1271_ps_set_mode(wl
, wlvif
, STATION_POWER_SAVE_MODE
);
2123 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
2124 struct ieee80211_vif
*vif
)
2126 struct wl1271
*wl
= hw
->priv
;
2127 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2128 struct vif_counter_data vif_count
;
2131 bool booted
= false;
2133 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
2134 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
2136 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
2137 ieee80211_vif_type_p2p(vif
), vif
->addr
);
2139 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2141 mutex_lock(&wl
->mutex
);
2142 ret
= wl1271_ps_elp_wakeup(wl
);
2147 * in some very corner case HW recovery scenarios its possible to
2148 * get here before __wl1271_op_remove_interface is complete, so
2149 * opt out if that is the case.
2151 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
) ||
2152 test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)) {
2158 ret
= wl12xx_init_vif_data(wl
, vif
);
2163 role_type
= wl12xx_get_role_type(wl
, wlvif
);
2164 if (role_type
== WL12XX_INVALID_ROLE_TYPE
) {
2169 if (wl12xx_need_fw_change(wl
, vif_count
, true)) {
2170 wl12xx_force_active_psm(wl
);
2171 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2172 mutex_unlock(&wl
->mutex
);
2173 wl1271_recovery_work(&wl
->recovery_work
);
2178 * TODO: after the nvs issue will be solved, move this block
2179 * to start(), and make sure here the driver is ON.
2181 if (wl
->state
== WL1271_STATE_OFF
) {
2183 * we still need this in order to configure the fw
2184 * while uploading the nvs
2186 memcpy(wl
->addresses
[0].addr
, vif
->addr
, ETH_ALEN
);
2188 booted
= wl12xx_init_fw(wl
);
2195 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2196 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2198 * The device role is a special role used for
2199 * rx and tx frames prior to association (as
2200 * the STA role can get packets only from
2201 * its associated bssid)
2203 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2205 &wlvif
->dev_role_id
);
2210 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2211 role_type
, &wlvif
->role_id
);
2215 ret
= wl1271_init_vif_specific(wl
, vif
);
2219 list_add(&wlvif
->list
, &wl
->wlvif_list
);
2220 set_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
);
2222 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2227 wl1271_ps_elp_sleep(wl
);
2229 mutex_unlock(&wl
->mutex
);
2234 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
2235 struct ieee80211_vif
*vif
,
2236 bool reset_tx_queues
)
2238 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2241 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
2243 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2246 /* because of hardware recovery, we may get here twice */
2247 if (wl
->state
!= WL1271_STATE_ON
)
2250 wl1271_info("down");
2252 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
&&
2253 wl
->scan_vif
== vif
) {
2255 * Rearm the tx watchdog just before idling scan. This
2256 * prevents just-finished scans from triggering the watchdog
2258 wl12xx_rearm_tx_watchdog_locked(wl
);
2260 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
2261 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
2262 wl
->scan_vif
= NULL
;
2263 wl
->scan
.req
= NULL
;
2264 ieee80211_scan_completed(wl
->hw
, true);
2267 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
)) {
2268 /* disable active roles */
2269 ret
= wl1271_ps_elp_wakeup(wl
);
2273 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2274 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2275 if (wl12xx_dev_role_started(wlvif
))
2276 wl12xx_stop_dev(wl
, wlvif
);
2278 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2283 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->role_id
);
2287 wl1271_ps_elp_sleep(wl
);
2290 /* clear all hlids (except system_hlid) */
2291 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
2293 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2294 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2295 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
2296 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
2297 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
2298 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
2300 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
2301 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
2302 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
2303 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
2304 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
2305 wl12xx_free_rate_policy(wl
,
2306 &wlvif
->ap
.ucast_rate_idx
[i
]);
2307 wl1271_free_ap_keys(wl
, wlvif
);
2310 dev_kfree_skb(wlvif
->probereq
);
2311 wlvif
->probereq
= NULL
;
2312 wl12xx_tx_reset_wlvif(wl
, wlvif
);
2313 if (wl
->last_wlvif
== wlvif
)
2314 wl
->last_wlvif
= NULL
;
2315 list_del(&wlvif
->list
);
2316 memset(wlvif
->ap
.sta_hlid_map
, 0, sizeof(wlvif
->ap
.sta_hlid_map
));
2317 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
2318 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
2320 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2325 mutex_unlock(&wl
->mutex
);
2327 del_timer_sync(&wlvif
->rx_streaming_timer
);
2328 cancel_work_sync(&wlvif
->rx_streaming_enable_work
);
2329 cancel_work_sync(&wlvif
->rx_streaming_disable_work
);
2331 mutex_lock(&wl
->mutex
);
2334 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
2335 struct ieee80211_vif
*vif
)
2337 struct wl1271
*wl
= hw
->priv
;
2338 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2339 struct wl12xx_vif
*iter
;
2340 struct vif_counter_data vif_count
;
2341 bool cancel_recovery
= true;
2343 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2344 mutex_lock(&wl
->mutex
);
2346 if (wl
->state
== WL1271_STATE_OFF
||
2347 !test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2351 * wl->vif can be null here if someone shuts down the interface
2352 * just when hardware recovery has been started.
2354 wl12xx_for_each_wlvif(wl
, iter
) {
2358 __wl1271_op_remove_interface(wl
, vif
, true);
2361 WARN_ON(iter
!= wlvif
);
2362 if (wl12xx_need_fw_change(wl
, vif_count
, false)) {
2363 wl12xx_force_active_psm(wl
);
2364 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2365 wl12xx_queue_recovery_work(wl
);
2366 cancel_recovery
= false;
2369 mutex_unlock(&wl
->mutex
);
2370 if (cancel_recovery
)
2371 cancel_work_sync(&wl
->recovery_work
);
2374 static int wl12xx_op_change_interface(struct ieee80211_hw
*hw
,
2375 struct ieee80211_vif
*vif
,
2376 enum nl80211_iftype new_type
, bool p2p
)
2378 struct wl1271
*wl
= hw
->priv
;
2381 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2382 wl1271_op_remove_interface(hw
, vif
);
2384 vif
->type
= new_type
;
2386 ret
= wl1271_op_add_interface(hw
, vif
);
2388 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2392 static int wl1271_join(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2396 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
2399 * One of the side effects of the JOIN command is that is clears
2400 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2401 * to a WPA/WPA2 access point will therefore kill the data-path.
2402 * Currently the only valid scenario for JOIN during association
2403 * is on roaming, in which case we will also be given new keys.
2404 * Keep the below message for now, unless it starts bothering
2405 * users who really like to roam a lot :)
2407 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2408 wl1271_info("JOIN while associated.");
2410 /* clear encryption type */
2411 wlvif
->encryption_type
= KEY_NONE
;
2414 set_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
);
2417 ret
= wl12xx_cmd_role_start_ibss(wl
, wlvif
);
2419 ret
= wl12xx_cmd_role_start_sta(wl
, wlvif
);
2423 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2427 * The join command disable the keep-alive mode, shut down its process,
2428 * and also clear the template config, so we need to reset it all after
2429 * the join. The acx_aid starts the keep-alive process, and the order
2430 * of the commands below is relevant.
2432 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, true);
2436 ret
= wl1271_acx_aid(wl
, wlvif
, wlvif
->aid
);
2440 ret
= wl12xx_cmd_build_klv_null_data(wl
, wlvif
);
2444 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
,
2445 CMD_TEMPL_KLV_IDX_NULL_DATA
,
2446 ACX_KEEP_ALIVE_TPL_VALID
);
2454 static int wl1271_unjoin(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2458 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
)) {
2459 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
2461 wl12xx_cmd_stop_channel_switch(wl
);
2462 ieee80211_chswitch_done(vif
, false);
2465 /* to stop listening to a channel, we disconnect */
2466 ret
= wl12xx_cmd_role_stop_sta(wl
, wlvif
);
2470 /* reset TX security counters on a clean disconnect */
2471 wlvif
->tx_security_last_seq_lsb
= 0;
2472 wlvif
->tx_security_seq
= 0;
2478 static void wl1271_set_band_rate(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2480 wlvif
->basic_rate_set
= wlvif
->bitrate_masks
[wlvif
->band
];
2481 wlvif
->rate_set
= wlvif
->basic_rate_set
;
2484 static int wl1271_sta_handle_idle(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2488 bool cur_idle
= !test_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2490 if (idle
== cur_idle
)
2494 /* no need to croc if we weren't busy (e.g. during boot) */
2495 if (wl12xx_dev_role_started(wlvif
)) {
2496 ret
= wl12xx_stop_dev(wl
, wlvif
);
2501 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
2502 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2505 ret
= wl1271_acx_keep_alive_config(
2506 wl
, wlvif
, CMD_TEMPL_KLV_IDX_NULL_DATA
,
2507 ACX_KEEP_ALIVE_TPL_INVALID
);
2510 clear_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2512 /* The current firmware only supports sched_scan in idle */
2513 if (wl
->sched_scanning
) {
2514 wl1271_scan_sched_scan_stop(wl
);
2515 ieee80211_sched_scan_stopped(wl
->hw
);
2518 ret
= wl12xx_start_dev(wl
, wlvif
);
2521 set_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2528 static int wl12xx_config_vif(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2529 struct ieee80211_conf
*conf
, u32 changed
)
2531 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2534 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2536 /* if the channel changes while joined, join again */
2537 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
2538 ((wlvif
->band
!= conf
->channel
->band
) ||
2539 (wlvif
->channel
!= channel
))) {
2540 /* send all pending packets */
2541 wl1271_tx_work_locked(wl
);
2542 wlvif
->band
= conf
->channel
->band
;
2543 wlvif
->channel
= channel
;
2547 * FIXME: the mac80211 should really provide a fixed
2548 * rate to use here. for now, just use the smallest
2549 * possible rate for the band as a fixed rate for
2550 * association frames and other control messages.
2552 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2553 wl1271_set_band_rate(wl
, wlvif
);
2556 wl1271_tx_min_rate_get(wl
,
2557 wlvif
->basic_rate_set
);
2558 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2560 wl1271_warning("rate policy for channel "
2564 * change the ROC channel. do it only if we are
2565 * not idle. otherwise, CROC will be called
2568 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
,
2570 wl12xx_dev_role_started(wlvif
) &&
2571 !(conf
->flags
& IEEE80211_CONF_IDLE
)) {
2572 ret
= wl12xx_stop_dev(wl
, wlvif
);
2576 ret
= wl12xx_start_dev(wl
, wlvif
);
2583 if ((changed
& IEEE80211_CONF_CHANGE_PS
) && !is_ap
) {
2585 if ((conf
->flags
& IEEE80211_CONF_PS
) &&
2586 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
2587 !test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2592 if (wl
->conf
.conn
.forced_ps
) {
2593 ps_mode
= STATION_POWER_SAVE_MODE
;
2594 ps_mode_str
= "forced";
2596 ps_mode
= STATION_AUTO_PS_MODE
;
2597 ps_mode_str
= "auto";
2600 wl1271_debug(DEBUG_PSM
, "%s ps enabled", ps_mode_str
);
2602 ret
= wl1271_ps_set_mode(wl
, wlvif
, ps_mode
);
2605 wl1271_warning("enter %s ps failed %d",
2608 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
2609 test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2611 wl1271_debug(DEBUG_PSM
, "auto ps disabled");
2613 ret
= wl1271_ps_set_mode(wl
, wlvif
,
2614 STATION_ACTIVE_MODE
);
2616 wl1271_warning("exit auto ps failed %d", ret
);
2620 if (conf
->power_level
!= wlvif
->power_level
) {
2621 ret
= wl1271_acx_tx_power(wl
, wlvif
, conf
->power_level
);
2625 wlvif
->power_level
= conf
->power_level
;
2631 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
2633 struct wl1271
*wl
= hw
->priv
;
2634 struct wl12xx_vif
*wlvif
;
2635 struct ieee80211_conf
*conf
= &hw
->conf
;
2636 int channel
, ret
= 0;
2638 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2640 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d %s"
2643 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
2645 conf
->flags
& IEEE80211_CONF_IDLE
? "idle" : "in use",
2649 * mac80211 will go to idle nearly immediately after transmitting some
2650 * frames, such as the deauth. To make sure those frames reach the air,
2651 * wait here until the TX queue is fully flushed.
2653 if ((changed
& IEEE80211_CONF_CHANGE_IDLE
) &&
2654 (conf
->flags
& IEEE80211_CONF_IDLE
))
2655 wl1271_tx_flush(wl
);
2657 mutex_lock(&wl
->mutex
);
2659 /* we support configuring the channel and band even while off */
2660 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2661 wl
->band
= conf
->channel
->band
;
2662 wl
->channel
= channel
;
2665 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
2666 wl
->power_level
= conf
->power_level
;
2668 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2671 ret
= wl1271_ps_elp_wakeup(wl
);
2675 /* configure each interface */
2676 wl12xx_for_each_wlvif(wl
, wlvif
) {
2677 ret
= wl12xx_config_vif(wl
, wlvif
, conf
, changed
);
2683 wl1271_ps_elp_sleep(wl
);
2686 mutex_unlock(&wl
->mutex
);
2691 struct wl1271_filter_params
{
2694 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
2697 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
,
2698 struct netdev_hw_addr_list
*mc_list
)
2700 struct wl1271_filter_params
*fp
;
2701 struct netdev_hw_addr
*ha
;
2702 struct wl1271
*wl
= hw
->priv
;
2704 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2707 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
2709 wl1271_error("Out of memory setting filters.");
2713 /* update multicast filtering parameters */
2714 fp
->mc_list_length
= 0;
2715 if (netdev_hw_addr_list_count(mc_list
) > ACX_MC_ADDRESS_GROUP_MAX
) {
2716 fp
->enabled
= false;
2719 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2720 memcpy(fp
->mc_list
[fp
->mc_list_length
],
2721 ha
->addr
, ETH_ALEN
);
2722 fp
->mc_list_length
++;
2726 return (u64
)(unsigned long)fp
;
2729 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2732 FIF_BCN_PRBRESP_PROMISC | \
2736 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
2737 unsigned int changed
,
2738 unsigned int *total
, u64 multicast
)
2740 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
2741 struct wl1271
*wl
= hw
->priv
;
2742 struct wl12xx_vif
*wlvif
;
2746 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter changed %x"
2747 " total %x", changed
, *total
);
2749 mutex_lock(&wl
->mutex
);
2751 *total
&= WL1271_SUPPORTED_FILTERS
;
2752 changed
&= WL1271_SUPPORTED_FILTERS
;
2754 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2757 ret
= wl1271_ps_elp_wakeup(wl
);
2761 wl12xx_for_each_wlvif(wl
, wlvif
) {
2762 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
2763 if (*total
& FIF_ALLMULTI
)
2764 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2768 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2771 fp
->mc_list_length
);
2778 * the fw doesn't provide an api to configure the filters. instead,
2779 * the filters configuration is based on the active roles / ROC
2784 wl1271_ps_elp_sleep(wl
);
2787 mutex_unlock(&wl
->mutex
);
2791 static int wl1271_record_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2792 u8 id
, u8 key_type
, u8 key_size
,
2793 const u8
*key
, u8 hlid
, u32 tx_seq_32
,
2796 struct wl1271_ap_key
*ap_key
;
2799 wl1271_debug(DEBUG_CRYPT
, "record ap key id %d", (int)id
);
2801 if (key_size
> MAX_KEY_SIZE
)
2805 * Find next free entry in ap_keys. Also check we are not replacing
2808 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2809 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2812 if (wlvif
->ap
.recorded_keys
[i
]->id
== id
) {
2813 wl1271_warning("trying to record key replacement");
2818 if (i
== MAX_NUM_KEYS
)
2821 ap_key
= kzalloc(sizeof(*ap_key
), GFP_KERNEL
);
2826 ap_key
->key_type
= key_type
;
2827 ap_key
->key_size
= key_size
;
2828 memcpy(ap_key
->key
, key
, key_size
);
2829 ap_key
->hlid
= hlid
;
2830 ap_key
->tx_seq_32
= tx_seq_32
;
2831 ap_key
->tx_seq_16
= tx_seq_16
;
2833 wlvif
->ap
.recorded_keys
[i
] = ap_key
;
2837 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2841 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2842 kfree(wlvif
->ap
.recorded_keys
[i
]);
2843 wlvif
->ap
.recorded_keys
[i
] = NULL
;
2847 static int wl1271_ap_init_hwenc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2850 struct wl1271_ap_key
*key
;
2851 bool wep_key_added
= false;
2853 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2855 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2858 key
= wlvif
->ap
.recorded_keys
[i
];
2860 if (hlid
== WL12XX_INVALID_LINK_ID
)
2861 hlid
= wlvif
->ap
.bcast_hlid
;
2863 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
2864 key
->id
, key
->key_type
,
2865 key
->key_size
, key
->key
,
2866 hlid
, key
->tx_seq_32
,
2871 if (key
->key_type
== KEY_WEP
)
2872 wep_key_added
= true;
2875 if (wep_key_added
) {
2876 ret
= wl12xx_cmd_set_default_wep_key(wl
, wlvif
->default_key
,
2877 wlvif
->ap
.bcast_hlid
);
2883 wl1271_free_ap_keys(wl
, wlvif
);
2887 static int wl1271_set_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2888 u16 action
, u8 id
, u8 key_type
,
2889 u8 key_size
, const u8
*key
, u32 tx_seq_32
,
2890 u16 tx_seq_16
, struct ieee80211_sta
*sta
)
2893 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2896 * A role set to GEM cipher requires different Tx settings (namely
2897 * spare blocks). Note when we are in this mode so the HW can adjust.
2899 if (key_type
== KEY_GEM
) {
2900 if (action
== KEY_ADD_OR_REPLACE
)
2901 wlvif
->is_gem
= true;
2902 else if (action
== KEY_REMOVE
)
2903 wlvif
->is_gem
= false;
2907 struct wl1271_station
*wl_sta
;
2911 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
2912 hlid
= wl_sta
->hlid
;
2914 hlid
= wlvif
->ap
.bcast_hlid
;
2917 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
2919 * We do not support removing keys after AP shutdown.
2920 * Pretend we do to make mac80211 happy.
2922 if (action
!= KEY_ADD_OR_REPLACE
)
2925 ret
= wl1271_record_ap_key(wl
, wlvif
, id
,
2927 key
, hlid
, tx_seq_32
,
2930 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, action
,
2931 id
, key_type
, key_size
,
2932 key
, hlid
, tx_seq_32
,
2940 static const u8 bcast_addr
[ETH_ALEN
] = {
2941 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2944 addr
= sta
? sta
->addr
: bcast_addr
;
2946 if (is_zero_ether_addr(addr
)) {
2947 /* We dont support TX only encryption */
2951 /* The wl1271 does not allow to remove unicast keys - they
2952 will be cleared automatically on next CMD_JOIN. Ignore the
2953 request silently, as we dont want the mac80211 to emit
2954 an error message. */
2955 if (action
== KEY_REMOVE
&& !is_broadcast_ether_addr(addr
))
2958 /* don't remove key if hlid was already deleted */
2959 if (action
== KEY_REMOVE
&&
2960 wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
2963 ret
= wl1271_cmd_set_sta_key(wl
, wlvif
, action
,
2964 id
, key_type
, key_size
,
2965 key
, addr
, tx_seq_32
,
2970 /* the default WEP key needs to be configured at least once */
2971 if (key_type
== KEY_WEP
) {
2972 ret
= wl12xx_cmd_set_default_wep_key(wl
,
2983 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2984 struct ieee80211_vif
*vif
,
2985 struct ieee80211_sta
*sta
,
2986 struct ieee80211_key_conf
*key_conf
)
2988 struct wl1271
*wl
= hw
->priv
;
2989 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2995 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
2997 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x sta: %p", cmd
, sta
);
2998 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
2999 key_conf
->cipher
, key_conf
->keyidx
,
3000 key_conf
->keylen
, key_conf
->flags
);
3001 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
3003 mutex_lock(&wl
->mutex
);
3005 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3010 ret
= wl1271_ps_elp_wakeup(wl
);
3014 switch (key_conf
->cipher
) {
3015 case WLAN_CIPHER_SUITE_WEP40
:
3016 case WLAN_CIPHER_SUITE_WEP104
:
3019 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3021 case WLAN_CIPHER_SUITE_TKIP
:
3022 key_type
= KEY_TKIP
;
3024 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3025 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3026 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3028 case WLAN_CIPHER_SUITE_CCMP
:
3031 key_conf
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3032 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3033 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3035 case WL1271_CIPHER_SUITE_GEM
:
3037 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3038 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3041 wl1271_error("Unknown key algo 0x%x", key_conf
->cipher
);
3049 ret
= wl1271_set_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
3050 key_conf
->keyidx
, key_type
,
3051 key_conf
->keylen
, key_conf
->key
,
3052 tx_seq_32
, tx_seq_16
, sta
);
3054 wl1271_error("Could not add or replace key");
3059 * reconfiguring arp response if the unicast (or common)
3060 * encryption key type was changed
3062 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
3063 (sta
|| key_type
== KEY_WEP
) &&
3064 wlvif
->encryption_type
!= key_type
) {
3065 wlvif
->encryption_type
= key_type
;
3066 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3068 wl1271_warning("build arp rsp failed: %d", ret
);
3075 ret
= wl1271_set_key(wl
, wlvif
, KEY_REMOVE
,
3076 key_conf
->keyidx
, key_type
,
3077 key_conf
->keylen
, key_conf
->key
,
3080 wl1271_error("Could not remove key");
3086 wl1271_error("Unsupported key cmd 0x%x", cmd
);
3092 wl1271_ps_elp_sleep(wl
);
3095 mutex_unlock(&wl
->mutex
);
3100 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
3101 struct ieee80211_vif
*vif
,
3102 struct cfg80211_scan_request
*req
)
3104 struct wl1271
*wl
= hw
->priv
;
3109 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
3112 ssid
= req
->ssids
[0].ssid
;
3113 len
= req
->ssids
[0].ssid_len
;
3116 mutex_lock(&wl
->mutex
);
3118 if (wl
->state
== WL1271_STATE_OFF
) {
3120 * We cannot return -EBUSY here because cfg80211 will expect
3121 * a call to ieee80211_scan_completed if we do - in this case
3122 * there won't be any call.
3128 ret
= wl1271_ps_elp_wakeup(wl
);
3132 /* fail if there is any role in ROC */
3133 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
3134 /* don't allow scanning right now */
3139 ret
= wl1271_scan(hw
->priv
, vif
, ssid
, len
, req
);
3141 wl1271_ps_elp_sleep(wl
);
3143 mutex_unlock(&wl
->mutex
);
3148 static void wl1271_op_cancel_hw_scan(struct ieee80211_hw
*hw
,
3149 struct ieee80211_vif
*vif
)
3151 struct wl1271
*wl
= hw
->priv
;
3154 wl1271_debug(DEBUG_MAC80211
, "mac80211 cancel hw scan");
3156 mutex_lock(&wl
->mutex
);
3158 if (wl
->state
== WL1271_STATE_OFF
)
3161 if (wl
->scan
.state
== WL1271_SCAN_STATE_IDLE
)
3164 ret
= wl1271_ps_elp_wakeup(wl
);
3168 if (wl
->scan
.state
!= WL1271_SCAN_STATE_DONE
) {
3169 ret
= wl1271_scan_stop(wl
);
3175 * Rearm the tx watchdog just before idling scan. This
3176 * prevents just-finished scans from triggering the watchdog
3178 wl12xx_rearm_tx_watchdog_locked(wl
);
3180 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
3181 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
3182 wl
->scan_vif
= NULL
;
3183 wl
->scan
.req
= NULL
;
3184 ieee80211_scan_completed(wl
->hw
, true);
3187 wl1271_ps_elp_sleep(wl
);
3189 mutex_unlock(&wl
->mutex
);
3191 cancel_delayed_work_sync(&wl
->scan_complete_work
);
3194 static int wl1271_op_sched_scan_start(struct ieee80211_hw
*hw
,
3195 struct ieee80211_vif
*vif
,
3196 struct cfg80211_sched_scan_request
*req
,
3197 struct ieee80211_sched_scan_ies
*ies
)
3199 struct wl1271
*wl
= hw
->priv
;
3200 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3203 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_start");
3205 mutex_lock(&wl
->mutex
);
3207 if (wl
->state
== WL1271_STATE_OFF
) {
3212 ret
= wl1271_ps_elp_wakeup(wl
);
3216 ret
= wl1271_scan_sched_scan_config(wl
, wlvif
, req
, ies
);
3220 ret
= wl1271_scan_sched_scan_start(wl
, wlvif
);
3224 wl
->sched_scanning
= true;
3227 wl1271_ps_elp_sleep(wl
);
3229 mutex_unlock(&wl
->mutex
);
3233 static void wl1271_op_sched_scan_stop(struct ieee80211_hw
*hw
,
3234 struct ieee80211_vif
*vif
)
3236 struct wl1271
*wl
= hw
->priv
;
3239 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_stop");
3241 mutex_lock(&wl
->mutex
);
3243 if (wl
->state
== WL1271_STATE_OFF
)
3246 ret
= wl1271_ps_elp_wakeup(wl
);
3250 wl1271_scan_sched_scan_stop(wl
);
3252 wl1271_ps_elp_sleep(wl
);
3254 mutex_unlock(&wl
->mutex
);
3257 static int wl1271_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3259 struct wl1271
*wl
= hw
->priv
;
3262 mutex_lock(&wl
->mutex
);
3264 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3269 ret
= wl1271_ps_elp_wakeup(wl
);
3273 ret
= wl1271_acx_frag_threshold(wl
, value
);
3275 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret
);
3277 wl1271_ps_elp_sleep(wl
);
3280 mutex_unlock(&wl
->mutex
);
3285 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3287 struct wl1271
*wl
= hw
->priv
;
3288 struct wl12xx_vif
*wlvif
;
3291 mutex_lock(&wl
->mutex
);
3293 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3298 ret
= wl1271_ps_elp_wakeup(wl
);
3302 wl12xx_for_each_wlvif(wl
, wlvif
) {
3303 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, value
);
3305 wl1271_warning("set rts threshold failed: %d", ret
);
3307 wl1271_ps_elp_sleep(wl
);
3310 mutex_unlock(&wl
->mutex
);
3315 static int wl1271_ssid_set(struct ieee80211_vif
*vif
, struct sk_buff
*skb
,
3318 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3320 const u8
*ptr
= cfg80211_find_ie(WLAN_EID_SSID
, skb
->data
+ offset
,
3324 wl1271_error("No SSID in IEs!");
3329 if (ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3330 wl1271_error("SSID is too long!");
3334 wlvif
->ssid_len
= ssid_len
;
3335 memcpy(wlvif
->ssid
, ptr
+2, ssid_len
);
3339 static void wl12xx_remove_ie(struct sk_buff
*skb
, u8 eid
, int ieoffset
)
3342 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3343 u8
*ie
= (u8
*)cfg80211_find_ie(eid
, skb
->data
+ ieoffset
,
3344 skb
->len
- ieoffset
);
3349 memmove(ie
, next
, end
- next
);
3350 skb_trim(skb
, skb
->len
- len
);
3353 static void wl12xx_remove_vendor_ie(struct sk_buff
*skb
,
3354 unsigned int oui
, u8 oui_type
,
3358 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3359 u8
*ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
3360 skb
->data
+ ieoffset
,
3361 skb
->len
- ieoffset
);
3366 memmove(ie
, next
, end
- next
);
3367 skb_trim(skb
, skb
->len
- len
);
3370 static int wl1271_ap_set_probe_resp_tmpl(struct wl1271
*wl
, u32 rates
,
3371 struct ieee80211_vif
*vif
)
3373 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3374 struct sk_buff
*skb
;
3377 skb
= ieee80211_proberesp_get(wl
->hw
, vif
);
3381 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3382 CMD_TEMPL_AP_PROBE_RESPONSE
,
3391 static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271
*wl
,
3392 struct ieee80211_vif
*vif
,
3394 size_t probe_rsp_len
,
3397 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3398 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
3399 u8 probe_rsp_templ
[WL1271_CMD_TEMPL_MAX_SIZE
];
3400 int ssid_ie_offset
, ie_offset
, templ_len
;
3403 /* no need to change probe response if the SSID is set correctly */
3404 if (wlvif
->ssid_len
> 0)
3405 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3406 CMD_TEMPL_AP_PROBE_RESPONSE
,
3411 if (probe_rsp_len
+ bss_conf
->ssid_len
> WL1271_CMD_TEMPL_MAX_SIZE
) {
3412 wl1271_error("probe_rsp template too big");
3416 /* start searching from IE offset */
3417 ie_offset
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
3419 ptr
= cfg80211_find_ie(WLAN_EID_SSID
, probe_rsp_data
+ ie_offset
,
3420 probe_rsp_len
- ie_offset
);
3422 wl1271_error("No SSID in beacon!");
3426 ssid_ie_offset
= ptr
- probe_rsp_data
;
3427 ptr
+= (ptr
[1] + 2);
3429 memcpy(probe_rsp_templ
, probe_rsp_data
, ssid_ie_offset
);
3431 /* insert SSID from bss_conf */
3432 probe_rsp_templ
[ssid_ie_offset
] = WLAN_EID_SSID
;
3433 probe_rsp_templ
[ssid_ie_offset
+ 1] = bss_conf
->ssid_len
;
3434 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2,
3435 bss_conf
->ssid
, bss_conf
->ssid_len
);
3436 templ_len
= ssid_ie_offset
+ 2 + bss_conf
->ssid_len
;
3438 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2 + bss_conf
->ssid_len
,
3439 ptr
, probe_rsp_len
- (ptr
- probe_rsp_data
));
3440 templ_len
+= probe_rsp_len
- (ptr
- probe_rsp_data
);
3442 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3443 CMD_TEMPL_AP_PROBE_RESPONSE
,
3449 static int wl1271_bss_erp_info_changed(struct wl1271
*wl
,
3450 struct ieee80211_vif
*vif
,
3451 struct ieee80211_bss_conf
*bss_conf
,
3454 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3457 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3458 if (bss_conf
->use_short_slot
)
3459 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_SHORT
);
3461 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_LONG
);
3463 wl1271_warning("Set slot time failed %d", ret
);
3468 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3469 if (bss_conf
->use_short_preamble
)
3470 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_SHORT
);
3472 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_LONG
);
3475 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3476 if (bss_conf
->use_cts_prot
)
3477 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3480 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3481 CTSPROTECT_DISABLE
);
3483 wl1271_warning("Set ctsprotect failed %d", ret
);
3492 static int wl1271_bss_beacon_info_changed(struct wl1271
*wl
,
3493 struct ieee80211_vif
*vif
,
3494 struct ieee80211_bss_conf
*bss_conf
,
3497 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3498 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3501 if ((changed
& BSS_CHANGED_BEACON_INT
)) {
3502 wl1271_debug(DEBUG_MASTER
, "beacon interval updated: %d",
3503 bss_conf
->beacon_int
);
3505 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3508 if ((changed
& BSS_CHANGED_AP_PROBE_RESP
) && is_ap
) {
3509 u32 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3510 if (!wl1271_ap_set_probe_resp_tmpl(wl
, rate
, vif
)) {
3511 wl1271_debug(DEBUG_AP
, "probe response updated");
3512 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
);
3516 if ((changed
& BSS_CHANGED_BEACON
)) {
3517 struct ieee80211_hdr
*hdr
;
3519 int ieoffset
= offsetof(struct ieee80211_mgmt
,
3521 struct sk_buff
*beacon
= ieee80211_beacon_get(wl
->hw
, vif
);
3529 wl1271_debug(DEBUG_MASTER
, "beacon updated");
3531 ret
= wl1271_ssid_set(vif
, beacon
, ieoffset
);
3533 dev_kfree_skb(beacon
);
3536 min_rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3537 tmpl_id
= is_ap
? CMD_TEMPL_AP_BEACON
:
3539 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, tmpl_id
,
3544 dev_kfree_skb(beacon
);
3549 * In case we already have a probe-resp beacon set explicitly
3550 * by usermode, don't use the beacon data.
3552 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
))
3555 /* remove TIM ie from probe response */
3556 wl12xx_remove_ie(beacon
, WLAN_EID_TIM
, ieoffset
);
3559 * remove p2p ie from probe response.
3560 * the fw reponds to probe requests that don't include
3561 * the p2p ie. probe requests with p2p ie will be passed,
3562 * and will be responded by the supplicant (the spec
3563 * forbids including the p2p ie when responding to probe
3564 * requests that didn't include it).
3566 wl12xx_remove_vendor_ie(beacon
, WLAN_OUI_WFA
,
3567 WLAN_OUI_TYPE_WFA_P2P
, ieoffset
);
3569 hdr
= (struct ieee80211_hdr
*) beacon
->data
;
3570 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3571 IEEE80211_STYPE_PROBE_RESP
);
3573 ret
= wl1271_ap_set_probe_resp_tmpl_legacy(wl
, vif
,
3578 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3579 CMD_TEMPL_PROBE_RESPONSE
,
3584 dev_kfree_skb(beacon
);
3591 wl1271_error("beacon info change failed: %d", ret
);
3595 /* AP mode changes */
3596 static void wl1271_bss_info_changed_ap(struct wl1271
*wl
,
3597 struct ieee80211_vif
*vif
,
3598 struct ieee80211_bss_conf
*bss_conf
,
3601 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3604 if ((changed
& BSS_CHANGED_BASIC_RATES
)) {
3605 u32 rates
= bss_conf
->basic_rates
;
3607 wlvif
->basic_rate_set
= wl1271_tx_enabled_rates_get(wl
, rates
,
3609 wlvif
->basic_rate
= wl1271_tx_min_rate_get(wl
,
3610 wlvif
->basic_rate_set
);
3612 ret
= wl1271_init_ap_rates(wl
, wlvif
);
3614 wl1271_error("AP rate policy change failed %d", ret
);
3618 ret
= wl1271_ap_init_templates(wl
, vif
);
3623 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
, changed
);
3627 if ((changed
& BSS_CHANGED_BEACON_ENABLED
)) {
3628 if (bss_conf
->enable_beacon
) {
3629 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3630 ret
= wl12xx_cmd_role_start_ap(wl
, wlvif
);
3634 ret
= wl1271_ap_init_hwenc(wl
, wlvif
);
3638 set_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3639 wl1271_debug(DEBUG_AP
, "started AP");
3642 if (test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3643 ret
= wl12xx_cmd_role_stop_ap(wl
, wlvif
);
3647 clear_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3648 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
,
3650 wl1271_debug(DEBUG_AP
, "stopped AP");
3655 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3659 /* Handle HT information change */
3660 if ((changed
& BSS_CHANGED_HT
) &&
3661 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3662 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3663 bss_conf
->ht_operation_mode
);
3665 wl1271_warning("Set ht information failed %d", ret
);
3674 /* STA/IBSS mode changes */
3675 static void wl1271_bss_info_changed_sta(struct wl1271
*wl
,
3676 struct ieee80211_vif
*vif
,
3677 struct ieee80211_bss_conf
*bss_conf
,
3680 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3681 bool do_join
= false, set_assoc
= false;
3682 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
3683 bool ibss_joined
= false;
3684 u32 sta_rate_set
= 0;
3686 struct ieee80211_sta
*sta
;
3687 bool sta_exists
= false;
3688 struct ieee80211_sta_ht_cap sta_ht_cap
;
3691 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
,
3697 if (changed
& BSS_CHANGED_IBSS
) {
3698 if (bss_conf
->ibss_joined
) {
3699 set_bit(WLVIF_FLAG_IBSS_JOINED
, &wlvif
->flags
);
3702 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED
,
3704 wl1271_unjoin(wl
, wlvif
);
3708 if ((changed
& BSS_CHANGED_BEACON_INT
) && ibss_joined
)
3711 /* Need to update the SSID (for filtering etc) */
3712 if ((changed
& BSS_CHANGED_BEACON
) && ibss_joined
)
3715 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && ibss_joined
) {
3716 wl1271_debug(DEBUG_ADHOC
, "ad-hoc beaconing: %s",
3717 bss_conf
->enable_beacon
? "enabled" : "disabled");
3722 if (changed
& BSS_CHANGED_IDLE
&& !is_ibss
) {
3723 ret
= wl1271_sta_handle_idle(wl
, wlvif
, bss_conf
->idle
);
3725 wl1271_warning("idle mode change failed %d", ret
);
3728 if ((changed
& BSS_CHANGED_CQM
)) {
3729 bool enable
= false;
3730 if (bss_conf
->cqm_rssi_thold
)
3732 ret
= wl1271_acx_rssi_snr_trigger(wl
, wlvif
, enable
,
3733 bss_conf
->cqm_rssi_thold
,
3734 bss_conf
->cqm_rssi_hyst
);
3737 wlvif
->rssi_thold
= bss_conf
->cqm_rssi_thold
;
3740 if (changed
& BSS_CHANGED_BSSID
)
3741 if (!is_zero_ether_addr(bss_conf
->bssid
)) {
3742 ret
= wl12xx_cmd_build_null_data(wl
, wlvif
);
3746 ret
= wl1271_build_qos_null_data(wl
, vif
);
3751 if (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_HT
)) {
3753 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
3757 /* save the supp_rates of the ap */
3758 sta_rate_set
= sta
->supp_rates
[wl
->hw
->conf
.channel
->band
];
3759 if (sta
->ht_cap
.ht_supported
)
3761 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
);
3762 sta_ht_cap
= sta
->ht_cap
;
3769 if ((changed
& BSS_CHANGED_ASSOC
)) {
3770 if (bss_conf
->assoc
) {
3773 wlvif
->aid
= bss_conf
->aid
;
3774 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3779 * use basic rates from AP, and determine lowest rate
3780 * to use with control frames.
3782 rates
= bss_conf
->basic_rates
;
3783 wlvif
->basic_rate_set
=
3784 wl1271_tx_enabled_rates_get(wl
, rates
,
3787 wl1271_tx_min_rate_get(wl
,
3788 wlvif
->basic_rate_set
);
3791 wl1271_tx_enabled_rates_get(wl
,
3794 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3799 * with wl1271, we don't need to update the
3800 * beacon_int and dtim_period, because the firmware
3801 * updates it by itself when the first beacon is
3802 * received after a join.
3804 ret
= wl1271_cmd_build_ps_poll(wl
, wlvif
, wlvif
->aid
);
3809 * Get a template for hardware connection maintenance
3811 dev_kfree_skb(wlvif
->probereq
);
3812 wlvif
->probereq
= wl1271_cmd_build_ap_probe_req(wl
,
3815 ieoffset
= offsetof(struct ieee80211_mgmt
,
3816 u
.probe_req
.variable
);
3817 wl1271_ssid_set(vif
, wlvif
->probereq
, ieoffset
);
3819 /* enable the connection monitoring feature */
3820 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, true);
3824 /* use defaults when not associated */
3826 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED
,
3829 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT
,
3833 /* free probe-request template */
3834 dev_kfree_skb(wlvif
->probereq
);
3835 wlvif
->probereq
= NULL
;
3837 /* revert back to minimum rates for the current band */
3838 wl1271_set_band_rate(wl
, wlvif
);
3840 wl1271_tx_min_rate_get(wl
,
3841 wlvif
->basic_rate_set
);
3842 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3846 /* disable connection monitor features */
3847 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
3849 /* Disable the keep-alive feature */
3850 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
3854 /* restore the bssid filter and go to dummy bssid */
3857 * we might have to disable roc, if there was
3858 * no IF_OPER_UP notification.
3861 ret
= wl12xx_croc(wl
, wlvif
->role_id
);
3866 * (we also need to disable roc in case of
3867 * roaming on the same channel. until we will
3868 * have a better flow...)
3870 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
3871 ret
= wl12xx_croc(wl
,
3872 wlvif
->dev_role_id
);
3877 wl1271_unjoin(wl
, wlvif
);
3878 if (!bss_conf
->idle
)
3879 wl12xx_start_dev(wl
, wlvif
);
3884 if (changed
& BSS_CHANGED_IBSS
) {
3885 wl1271_debug(DEBUG_ADHOC
, "ibss_joined: %d",
3886 bss_conf
->ibss_joined
);
3888 if (bss_conf
->ibss_joined
) {
3889 u32 rates
= bss_conf
->basic_rates
;
3890 wlvif
->basic_rate_set
=
3891 wl1271_tx_enabled_rates_get(wl
, rates
,
3894 wl1271_tx_min_rate_get(wl
,
3895 wlvif
->basic_rate_set
);
3897 /* by default, use 11b + OFDM rates */
3898 wlvif
->rate_set
= CONF_TX_IBSS_DEFAULT_RATES
;
3899 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3905 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3910 ret
= wl1271_join(wl
, wlvif
, set_assoc
);
3912 wl1271_warning("cmd join failed %d", ret
);
3916 /* ROC until connected (after EAPOL exchange) */
3918 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->role_id
);
3922 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
))
3923 wl12xx_set_authorized(wl
, wlvif
);
3926 * stop device role if started (we might already be in
3929 if (wl12xx_dev_role_started(wlvif
)) {
3930 ret
= wl12xx_stop_dev(wl
, wlvif
);
3936 /* Handle new association with HT. Do this after join. */
3938 if ((changed
& BSS_CHANGED_HT
) &&
3939 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3940 ret
= wl1271_acx_set_ht_capabilities(wl
,
3945 wl1271_warning("Set ht cap true failed %d",
3950 /* handle new association without HT and disassociation */
3951 else if (changed
& BSS_CHANGED_ASSOC
) {
3952 ret
= wl1271_acx_set_ht_capabilities(wl
,
3957 wl1271_warning("Set ht cap false failed %d",
3964 /* Handle HT information change. Done after join. */
3965 if ((changed
& BSS_CHANGED_HT
) &&
3966 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3967 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3968 bss_conf
->ht_operation_mode
);
3970 wl1271_warning("Set ht information failed %d", ret
);
3975 /* Handle arp filtering. Done after join. */
3976 if ((changed
& BSS_CHANGED_ARP_FILTER
) ||
3977 (!is_ibss
&& (changed
& BSS_CHANGED_QOS
))) {
3978 __be32 addr
= bss_conf
->arp_addr_list
[0];
3979 wlvif
->sta
.qos
= bss_conf
->qos
;
3980 WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
);
3982 if (bss_conf
->arp_addr_cnt
== 1 &&
3983 bss_conf
->arp_filter_enabled
) {
3984 wlvif
->ip_addr
= addr
;
3986 * The template should have been configured only upon
3987 * association. however, it seems that the correct ip
3988 * isn't being set (when sending), so we have to
3989 * reconfigure the template upon every ip change.
3991 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3993 wl1271_warning("build arp rsp failed: %d", ret
);
3997 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
,
3998 (ACX_ARP_FILTER_ARP_FILTERING
|
3999 ACX_ARP_FILTER_AUTO_ARP
),
4003 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
, 0, addr
);
4014 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
4015 struct ieee80211_vif
*vif
,
4016 struct ieee80211_bss_conf
*bss_conf
,
4019 struct wl1271
*wl
= hw
->priv
;
4020 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4021 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
4024 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed 0x%x",
4027 mutex_lock(&wl
->mutex
);
4029 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4032 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)))
4035 ret
= wl1271_ps_elp_wakeup(wl
);
4040 wl1271_bss_info_changed_ap(wl
, vif
, bss_conf
, changed
);
4042 wl1271_bss_info_changed_sta(wl
, vif
, bss_conf
, changed
);
4044 wl1271_ps_elp_sleep(wl
);
4047 mutex_unlock(&wl
->mutex
);
4050 static int wl1271_op_conf_tx(struct ieee80211_hw
*hw
,
4051 struct ieee80211_vif
*vif
, u16 queue
,
4052 const struct ieee80211_tx_queue_params
*params
)
4054 struct wl1271
*wl
= hw
->priv
;
4055 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4059 mutex_lock(&wl
->mutex
);
4061 wl1271_debug(DEBUG_MAC80211
, "mac80211 conf tx %d", queue
);
4064 ps_scheme
= CONF_PS_SCHEME_UPSD_TRIGGER
;
4066 ps_scheme
= CONF_PS_SCHEME_LEGACY
;
4068 if (!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
4071 ret
= wl1271_ps_elp_wakeup(wl
);
4076 * the txop is confed in units of 32us by the mac80211,
4079 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4080 params
->cw_min
, params
->cw_max
,
4081 params
->aifs
, params
->txop
<< 5);
4085 ret
= wl1271_acx_tid_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4086 CONF_CHANNEL_TYPE_EDCF
,
4087 wl1271_tx_get_queue(queue
),
4088 ps_scheme
, CONF_ACK_POLICY_LEGACY
,
4092 wl1271_ps_elp_sleep(wl
);
4095 mutex_unlock(&wl
->mutex
);
4100 static u64
wl1271_op_get_tsf(struct ieee80211_hw
*hw
,
4101 struct ieee80211_vif
*vif
)
4104 struct wl1271
*wl
= hw
->priv
;
4105 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4106 u64 mactime
= ULLONG_MAX
;
4109 wl1271_debug(DEBUG_MAC80211
, "mac80211 get tsf");
4111 mutex_lock(&wl
->mutex
);
4113 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4116 ret
= wl1271_ps_elp_wakeup(wl
);
4120 ret
= wl12xx_acx_tsf_info(wl
, wlvif
, &mactime
);
4125 wl1271_ps_elp_sleep(wl
);
4128 mutex_unlock(&wl
->mutex
);
4132 static int wl1271_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
4133 struct survey_info
*survey
)
4135 struct wl1271
*wl
= hw
->priv
;
4136 struct ieee80211_conf
*conf
= &hw
->conf
;
4141 survey
->channel
= conf
->channel
;
4142 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
4143 survey
->noise
= wl
->noise
;
4148 static int wl1271_allocate_sta(struct wl1271
*wl
,
4149 struct wl12xx_vif
*wlvif
,
4150 struct ieee80211_sta
*sta
)
4152 struct wl1271_station
*wl_sta
;
4156 if (wl
->active_sta_count
>= AP_MAX_STATIONS
) {
4157 wl1271_warning("could not allocate HLID - too much stations");
4161 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4162 ret
= wl12xx_allocate_link(wl
, wlvif
, &wl_sta
->hlid
);
4164 wl1271_warning("could not allocate HLID - too many links");
4168 set_bit(wl_sta
->hlid
, wlvif
->ap
.sta_hlid_map
);
4169 memcpy(wl
->links
[wl_sta
->hlid
].addr
, sta
->addr
, ETH_ALEN
);
4170 wl
->active_sta_count
++;
4174 void wl1271_free_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 hlid
)
4176 if (!test_bit(hlid
, wlvif
->ap
.sta_hlid_map
))
4179 clear_bit(hlid
, wlvif
->ap
.sta_hlid_map
);
4180 memset(wl
->links
[hlid
].addr
, 0, ETH_ALEN
);
4181 wl
->links
[hlid
].ba_bitmap
= 0;
4182 __clear_bit(hlid
, &wl
->ap_ps_map
);
4183 __clear_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
4184 wl12xx_free_link(wl
, wlvif
, &hlid
);
4185 wl
->active_sta_count
--;
4188 * rearm the tx watchdog when the last STA is freed - give the FW a
4189 * chance to return STA-buffered packets before complaining.
4191 if (wl
->active_sta_count
== 0)
4192 wl12xx_rearm_tx_watchdog_locked(wl
);
4195 static int wl12xx_sta_add(struct wl1271
*wl
,
4196 struct wl12xx_vif
*wlvif
,
4197 struct ieee80211_sta
*sta
)
4199 struct wl1271_station
*wl_sta
;
4203 wl1271_debug(DEBUG_MAC80211
, "mac80211 add sta %d", (int)sta
->aid
);
4205 ret
= wl1271_allocate_sta(wl
, wlvif
, sta
);
4209 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4210 hlid
= wl_sta
->hlid
;
4212 ret
= wl12xx_cmd_add_peer(wl
, wlvif
, sta
, hlid
);
4214 wl1271_free_sta(wl
, wlvif
, hlid
);
4219 static int wl12xx_sta_remove(struct wl1271
*wl
,
4220 struct wl12xx_vif
*wlvif
,
4221 struct ieee80211_sta
*sta
)
4223 struct wl1271_station
*wl_sta
;
4226 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove sta %d", (int)sta
->aid
);
4228 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4230 if (WARN_ON(!test_bit(id
, wlvif
->ap
.sta_hlid_map
)))
4233 ret
= wl12xx_cmd_remove_peer(wl
, wl_sta
->hlid
);
4237 wl1271_free_sta(wl
, wlvif
, wl_sta
->hlid
);
4241 static int wl12xx_update_sta_state(struct wl1271
*wl
,
4242 struct wl12xx_vif
*wlvif
,
4243 struct ieee80211_sta
*sta
,
4244 enum ieee80211_sta_state old_state
,
4245 enum ieee80211_sta_state new_state
)
4247 struct wl1271_station
*wl_sta
;
4249 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
4250 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
4253 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4254 hlid
= wl_sta
->hlid
;
4256 /* Add station (AP mode) */
4258 old_state
== IEEE80211_STA_NOTEXIST
&&
4259 new_state
== IEEE80211_STA_NONE
)
4260 return wl12xx_sta_add(wl
, wlvif
, sta
);
4262 /* Remove station (AP mode) */
4264 old_state
== IEEE80211_STA_NONE
&&
4265 new_state
== IEEE80211_STA_NOTEXIST
) {
4267 wl12xx_sta_remove(wl
, wlvif
, sta
);
4271 /* Authorize station (AP mode) */
4273 new_state
== IEEE80211_STA_AUTHORIZED
) {
4274 ret
= wl12xx_cmd_set_peer_state(wl
, hlid
);
4278 ret
= wl1271_acx_set_ht_capabilities(wl
, &sta
->ht_cap
, true,
4283 /* Authorize station */
4285 new_state
== IEEE80211_STA_AUTHORIZED
) {
4286 set_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4287 return wl12xx_set_authorized(wl
, wlvif
);
4291 old_state
== IEEE80211_STA_AUTHORIZED
&&
4292 new_state
== IEEE80211_STA_ASSOC
) {
4293 clear_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4300 static int wl12xx_op_sta_state(struct ieee80211_hw
*hw
,
4301 struct ieee80211_vif
*vif
,
4302 struct ieee80211_sta
*sta
,
4303 enum ieee80211_sta_state old_state
,
4304 enum ieee80211_sta_state new_state
)
4306 struct wl1271
*wl
= hw
->priv
;
4307 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4310 wl1271_debug(DEBUG_MAC80211
, "mac80211 sta %d state=%d->%d",
4311 sta
->aid
, old_state
, new_state
);
4313 mutex_lock(&wl
->mutex
);
4315 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4320 ret
= wl1271_ps_elp_wakeup(wl
);
4324 ret
= wl12xx_update_sta_state(wl
, wlvif
, sta
, old_state
, new_state
);
4326 wl1271_ps_elp_sleep(wl
);
4328 mutex_unlock(&wl
->mutex
);
4329 if (new_state
< old_state
)
4334 static int wl1271_op_ampdu_action(struct ieee80211_hw
*hw
,
4335 struct ieee80211_vif
*vif
,
4336 enum ieee80211_ampdu_mlme_action action
,
4337 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4340 struct wl1271
*wl
= hw
->priv
;
4341 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4343 u8 hlid
, *ba_bitmap
;
4345 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu action %d tid %d", action
,
4348 /* sanity check - the fields in FW are only 8bits wide */
4349 if (WARN_ON(tid
> 0xFF))
4352 mutex_lock(&wl
->mutex
);
4354 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4359 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
) {
4360 hlid
= wlvif
->sta
.hlid
;
4361 ba_bitmap
= &wlvif
->sta
.ba_rx_bitmap
;
4362 } else if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
) {
4363 struct wl1271_station
*wl_sta
;
4365 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4366 hlid
= wl_sta
->hlid
;
4367 ba_bitmap
= &wl
->links
[hlid
].ba_bitmap
;
4373 ret
= wl1271_ps_elp_wakeup(wl
);
4377 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu: Rx tid %d action %d",
4381 case IEEE80211_AMPDU_RX_START
:
4382 if (!wlvif
->ba_support
|| !wlvif
->ba_allowed
) {
4387 if (wl
->ba_rx_session_count
>= RX_BA_MAX_SESSIONS
) {
4389 wl1271_error("exceeded max RX BA sessions");
4393 if (*ba_bitmap
& BIT(tid
)) {
4395 wl1271_error("cannot enable RX BA session on active "
4400 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, *ssn
, true,
4403 *ba_bitmap
|= BIT(tid
);
4404 wl
->ba_rx_session_count
++;
4408 case IEEE80211_AMPDU_RX_STOP
:
4409 if (!(*ba_bitmap
& BIT(tid
))) {
4411 wl1271_error("no active RX BA session on tid: %d",
4416 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, 0, false,
4419 *ba_bitmap
&= ~BIT(tid
);
4420 wl
->ba_rx_session_count
--;
4425 * The BA initiator session management in FW independently.
4426 * Falling break here on purpose for all TX APDU commands.
4428 case IEEE80211_AMPDU_TX_START
:
4429 case IEEE80211_AMPDU_TX_STOP
:
4430 case IEEE80211_AMPDU_TX_OPERATIONAL
:
4435 wl1271_error("Incorrect ampdu action id=%x\n", action
);
4439 wl1271_ps_elp_sleep(wl
);
4442 mutex_unlock(&wl
->mutex
);
4447 static int wl12xx_set_bitrate_mask(struct ieee80211_hw
*hw
,
4448 struct ieee80211_vif
*vif
,
4449 const struct cfg80211_bitrate_mask
*mask
)
4451 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4452 struct wl1271
*wl
= hw
->priv
;
4455 wl1271_debug(DEBUG_MAC80211
, "mac80211 set_bitrate_mask 0x%x 0x%x",
4456 mask
->control
[NL80211_BAND_2GHZ
].legacy
,
4457 mask
->control
[NL80211_BAND_5GHZ
].legacy
);
4459 mutex_lock(&wl
->mutex
);
4461 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4462 wlvif
->bitrate_masks
[i
] =
4463 wl1271_tx_enabled_rates_get(wl
,
4464 mask
->control
[i
].legacy
,
4467 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4470 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
4471 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
)) {
4473 ret
= wl1271_ps_elp_wakeup(wl
);
4477 wl1271_set_band_rate(wl
, wlvif
);
4479 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
4480 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
4482 wl1271_ps_elp_sleep(wl
);
4485 mutex_unlock(&wl
->mutex
);
4490 static void wl12xx_op_channel_switch(struct ieee80211_hw
*hw
,
4491 struct ieee80211_channel_switch
*ch_switch
)
4493 struct wl1271
*wl
= hw
->priv
;
4494 struct wl12xx_vif
*wlvif
;
4497 wl1271_debug(DEBUG_MAC80211
, "mac80211 channel switch");
4499 wl1271_tx_flush(wl
);
4501 mutex_lock(&wl
->mutex
);
4503 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4504 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4505 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
4506 ieee80211_chswitch_done(vif
, false);
4511 ret
= wl1271_ps_elp_wakeup(wl
);
4515 /* TODO: change mac80211 to pass vif as param */
4516 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4517 ret
= wl12xx_cmd_channel_switch(wl
, wlvif
, ch_switch
);
4520 set_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
);
4523 wl1271_ps_elp_sleep(wl
);
4526 mutex_unlock(&wl
->mutex
);
4529 static bool wl1271_tx_frames_pending(struct ieee80211_hw
*hw
)
4531 struct wl1271
*wl
= hw
->priv
;
4534 mutex_lock(&wl
->mutex
);
4536 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4539 /* packets are considered pending if in the TX queue or the FW */
4540 ret
= (wl1271_tx_total_queue_count(wl
) > 0) || (wl
->tx_frames_cnt
> 0);
4542 mutex_unlock(&wl
->mutex
);
4547 /* can't be const, mac80211 writes to this */
4548 static struct ieee80211_rate wl1271_rates
[] = {
4550 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
4551 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
4553 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
4554 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
4555 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4557 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
4558 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
4559 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4561 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
4562 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
4563 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4565 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4566 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4568 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4569 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4571 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4572 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4574 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4575 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4577 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4578 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4580 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4581 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4583 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4584 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4586 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4587 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4590 /* can't be const, mac80211 writes to this */
4591 static struct ieee80211_channel wl1271_channels
[] = {
4592 { .hw_value
= 1, .center_freq
= 2412, .max_power
= 25 },
4593 { .hw_value
= 2, .center_freq
= 2417, .max_power
= 25 },
4594 { .hw_value
= 3, .center_freq
= 2422, .max_power
= 25 },
4595 { .hw_value
= 4, .center_freq
= 2427, .max_power
= 25 },
4596 { .hw_value
= 5, .center_freq
= 2432, .max_power
= 25 },
4597 { .hw_value
= 6, .center_freq
= 2437, .max_power
= 25 },
4598 { .hw_value
= 7, .center_freq
= 2442, .max_power
= 25 },
4599 { .hw_value
= 8, .center_freq
= 2447, .max_power
= 25 },
4600 { .hw_value
= 9, .center_freq
= 2452, .max_power
= 25 },
4601 { .hw_value
= 10, .center_freq
= 2457, .max_power
= 25 },
4602 { .hw_value
= 11, .center_freq
= 2462, .max_power
= 25 },
4603 { .hw_value
= 12, .center_freq
= 2467, .max_power
= 25 },
4604 { .hw_value
= 13, .center_freq
= 2472, .max_power
= 25 },
4605 { .hw_value
= 14, .center_freq
= 2484, .max_power
= 25 },
4608 /* 11n STA capabilities */
4609 #define HW_RX_HIGHEST_RATE 72
4611 #define WL12XX_HT_CAP { \
4612 .cap = IEEE80211_HT_CAP_GRN_FLD | IEEE80211_HT_CAP_SGI_20 | \
4613 (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT), \
4614 .ht_supported = true, \
4615 .ampdu_factor = IEEE80211_HT_MAX_AMPDU_8K, \
4616 .ampdu_density = IEEE80211_HT_MPDU_DENSITY_8, \
4618 .rx_mask = { 0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, }, \
4619 .rx_highest = cpu_to_le16(HW_RX_HIGHEST_RATE), \
4620 .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
4624 /* can't be const, mac80211 writes to this */
4625 static struct ieee80211_supported_band wl1271_band_2ghz
= {
4626 .channels
= wl1271_channels
,
4627 .n_channels
= ARRAY_SIZE(wl1271_channels
),
4628 .bitrates
= wl1271_rates
,
4629 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
4630 .ht_cap
= WL12XX_HT_CAP
,
4633 /* 5 GHz data rates for WL1273 */
4634 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
4636 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4637 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4639 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4640 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4642 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4643 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4645 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4646 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4648 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4649 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4651 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4652 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4654 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4655 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4657 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4658 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4661 /* 5 GHz band channels for WL1273 */
4662 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
4663 { .hw_value
= 7, .center_freq
= 5035, .max_power
= 25 },
4664 { .hw_value
= 8, .center_freq
= 5040, .max_power
= 25 },
4665 { .hw_value
= 9, .center_freq
= 5045, .max_power
= 25 },
4666 { .hw_value
= 11, .center_freq
= 5055, .max_power
= 25 },
4667 { .hw_value
= 12, .center_freq
= 5060, .max_power
= 25 },
4668 { .hw_value
= 16, .center_freq
= 5080, .max_power
= 25 },
4669 { .hw_value
= 34, .center_freq
= 5170, .max_power
= 25 },
4670 { .hw_value
= 36, .center_freq
= 5180, .max_power
= 25 },
4671 { .hw_value
= 38, .center_freq
= 5190, .max_power
= 25 },
4672 { .hw_value
= 40, .center_freq
= 5200, .max_power
= 25 },
4673 { .hw_value
= 42, .center_freq
= 5210, .max_power
= 25 },
4674 { .hw_value
= 44, .center_freq
= 5220, .max_power
= 25 },
4675 { .hw_value
= 46, .center_freq
= 5230, .max_power
= 25 },
4676 { .hw_value
= 48, .center_freq
= 5240, .max_power
= 25 },
4677 { .hw_value
= 52, .center_freq
= 5260, .max_power
= 25 },
4678 { .hw_value
= 56, .center_freq
= 5280, .max_power
= 25 },
4679 { .hw_value
= 60, .center_freq
= 5300, .max_power
= 25 },
4680 { .hw_value
= 64, .center_freq
= 5320, .max_power
= 25 },
4681 { .hw_value
= 100, .center_freq
= 5500, .max_power
= 25 },
4682 { .hw_value
= 104, .center_freq
= 5520, .max_power
= 25 },
4683 { .hw_value
= 108, .center_freq
= 5540, .max_power
= 25 },
4684 { .hw_value
= 112, .center_freq
= 5560, .max_power
= 25 },
4685 { .hw_value
= 116, .center_freq
= 5580, .max_power
= 25 },
4686 { .hw_value
= 120, .center_freq
= 5600, .max_power
= 25 },
4687 { .hw_value
= 124, .center_freq
= 5620, .max_power
= 25 },
4688 { .hw_value
= 128, .center_freq
= 5640, .max_power
= 25 },
4689 { .hw_value
= 132, .center_freq
= 5660, .max_power
= 25 },
4690 { .hw_value
= 136, .center_freq
= 5680, .max_power
= 25 },
4691 { .hw_value
= 140, .center_freq
= 5700, .max_power
= 25 },
4692 { .hw_value
= 149, .center_freq
= 5745, .max_power
= 25 },
4693 { .hw_value
= 153, .center_freq
= 5765, .max_power
= 25 },
4694 { .hw_value
= 157, .center_freq
= 5785, .max_power
= 25 },
4695 { .hw_value
= 161, .center_freq
= 5805, .max_power
= 25 },
4696 { .hw_value
= 165, .center_freq
= 5825, .max_power
= 25 },
4699 static struct ieee80211_supported_band wl1271_band_5ghz
= {
4700 .channels
= wl1271_channels_5ghz
,
4701 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
4702 .bitrates
= wl1271_rates_5ghz
,
4703 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
4704 .ht_cap
= WL12XX_HT_CAP
,
4707 static const struct ieee80211_ops wl1271_ops
= {
4708 .start
= wl1271_op_start
,
4709 .stop
= wl1271_op_stop
,
4710 .add_interface
= wl1271_op_add_interface
,
4711 .remove_interface
= wl1271_op_remove_interface
,
4712 .change_interface
= wl12xx_op_change_interface
,
4714 .suspend
= wl1271_op_suspend
,
4715 .resume
= wl1271_op_resume
,
4717 .config
= wl1271_op_config
,
4718 .prepare_multicast
= wl1271_op_prepare_multicast
,
4719 .configure_filter
= wl1271_op_configure_filter
,
4721 .set_key
= wl1271_op_set_key
,
4722 .hw_scan
= wl1271_op_hw_scan
,
4723 .cancel_hw_scan
= wl1271_op_cancel_hw_scan
,
4724 .sched_scan_start
= wl1271_op_sched_scan_start
,
4725 .sched_scan_stop
= wl1271_op_sched_scan_stop
,
4726 .bss_info_changed
= wl1271_op_bss_info_changed
,
4727 .set_frag_threshold
= wl1271_op_set_frag_threshold
,
4728 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
4729 .conf_tx
= wl1271_op_conf_tx
,
4730 .get_tsf
= wl1271_op_get_tsf
,
4731 .get_survey
= wl1271_op_get_survey
,
4732 .sta_state
= wl12xx_op_sta_state
,
4733 .ampdu_action
= wl1271_op_ampdu_action
,
4734 .tx_frames_pending
= wl1271_tx_frames_pending
,
4735 .set_bitrate_mask
= wl12xx_set_bitrate_mask
,
4736 .channel_switch
= wl12xx_op_channel_switch
,
4737 CFG80211_TESTMODE_CMD(wl1271_tm_cmd
)
4741 u8
wlcore_rate_to_idx(struct wl1271
*wl
, u8 rate
, enum ieee80211_band band
)
4747 if (unlikely(rate
>= wl
->hw_tx_rate_tbl_size
)) {
4748 wl1271_error("Illegal RX rate from HW: %d", rate
);
4752 idx
= wl
->band_rate_to_idx
[band
][rate
];
4753 if (unlikely(idx
== CONF_HW_RXTX_RATE_UNSUPPORTED
)) {
4754 wl1271_error("Unsupported RX rate from HW: %d", rate
);
4761 static ssize_t
wl1271_sysfs_show_bt_coex_state(struct device
*dev
,
4762 struct device_attribute
*attr
,
4765 struct wl1271
*wl
= dev_get_drvdata(dev
);
4770 mutex_lock(&wl
->mutex
);
4771 len
= snprintf(buf
, len
, "%d\n\n0 - off\n1 - on\n",
4773 mutex_unlock(&wl
->mutex
);
4779 static ssize_t
wl1271_sysfs_store_bt_coex_state(struct device
*dev
,
4780 struct device_attribute
*attr
,
4781 const char *buf
, size_t count
)
4783 struct wl1271
*wl
= dev_get_drvdata(dev
);
4787 ret
= kstrtoul(buf
, 10, &res
);
4789 wl1271_warning("incorrect value written to bt_coex_mode");
4793 mutex_lock(&wl
->mutex
);
4797 if (res
== wl
->sg_enabled
)
4800 wl
->sg_enabled
= res
;
4802 if (wl
->state
== WL1271_STATE_OFF
)
4805 ret
= wl1271_ps_elp_wakeup(wl
);
4809 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
4810 wl1271_ps_elp_sleep(wl
);
4813 mutex_unlock(&wl
->mutex
);
4817 static DEVICE_ATTR(bt_coex_state
, S_IRUGO
| S_IWUSR
,
4818 wl1271_sysfs_show_bt_coex_state
,
4819 wl1271_sysfs_store_bt_coex_state
);
4821 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
4822 struct device_attribute
*attr
,
4825 struct wl1271
*wl
= dev_get_drvdata(dev
);
4830 mutex_lock(&wl
->mutex
);
4831 if (wl
->hw_pg_ver
>= 0)
4832 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
4834 len
= snprintf(buf
, len
, "n/a\n");
4835 mutex_unlock(&wl
->mutex
);
4840 static DEVICE_ATTR(hw_pg_ver
, S_IRUGO
,
4841 wl1271_sysfs_show_hw_pg_ver
, NULL
);
4843 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
4844 struct bin_attribute
*bin_attr
,
4845 char *buffer
, loff_t pos
, size_t count
)
4847 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4848 struct wl1271
*wl
= dev_get_drvdata(dev
);
4852 ret
= mutex_lock_interruptible(&wl
->mutex
);
4854 return -ERESTARTSYS
;
4856 /* Let only one thread read the log at a time, blocking others */
4857 while (wl
->fwlog_size
== 0) {
4860 prepare_to_wait_exclusive(&wl
->fwlog_waitq
,
4862 TASK_INTERRUPTIBLE
);
4864 if (wl
->fwlog_size
!= 0) {
4865 finish_wait(&wl
->fwlog_waitq
, &wait
);
4869 mutex_unlock(&wl
->mutex
);
4872 finish_wait(&wl
->fwlog_waitq
, &wait
);
4874 if (signal_pending(current
))
4875 return -ERESTARTSYS
;
4877 ret
= mutex_lock_interruptible(&wl
->mutex
);
4879 return -ERESTARTSYS
;
4882 /* Check if the fwlog is still valid */
4883 if (wl
->fwlog_size
< 0) {
4884 mutex_unlock(&wl
->mutex
);
4888 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4889 len
= min(count
, (size_t)wl
->fwlog_size
);
4890 wl
->fwlog_size
-= len
;
4891 memcpy(buffer
, wl
->fwlog
, len
);
4893 /* Make room for new messages */
4894 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
4896 mutex_unlock(&wl
->mutex
);
4901 static struct bin_attribute fwlog_attr
= {
4902 .attr
= {.name
= "fwlog", .mode
= S_IRUSR
},
4903 .read
= wl1271_sysfs_read_fwlog
,
4906 static void wl12xx_derive_mac_addresses(struct wl1271
*wl
,
4907 u32 oui
, u32 nic
, int n
)
4911 wl1271_debug(DEBUG_PROBE
, "base address: oui %06x nic %06x, n %d",
4914 if (nic
+ n
- 1 > 0xffffff)
4915 wl1271_warning("NIC part of the MAC address wraps around!");
4917 for (i
= 0; i
< n
; i
++) {
4918 wl
->addresses
[i
].addr
[0] = (u8
)(oui
>> 16);
4919 wl
->addresses
[i
].addr
[1] = (u8
)(oui
>> 8);
4920 wl
->addresses
[i
].addr
[2] = (u8
) oui
;
4921 wl
->addresses
[i
].addr
[3] = (u8
)(nic
>> 16);
4922 wl
->addresses
[i
].addr
[4] = (u8
)(nic
>> 8);
4923 wl
->addresses
[i
].addr
[5] = (u8
) nic
;
4927 wl
->hw
->wiphy
->n_addresses
= n
;
4928 wl
->hw
->wiphy
->addresses
= wl
->addresses
;
4931 static int wl12xx_get_hw_info(struct wl1271
*wl
)
4935 ret
= wl12xx_set_power_on(wl
);
4939 wl
->chip
.id
= wlcore_read_reg(wl
, REG_CHIP_ID_B
);
4941 wl
->fuse_oui_addr
= 0;
4942 wl
->fuse_nic_addr
= 0;
4944 wl
->hw_pg_ver
= wl
->ops
->get_pg_ver(wl
);
4946 if (wl
->ops
->get_mac
)
4947 wl
->ops
->get_mac(wl
);
4949 wl1271_power_off(wl
);
4954 static int wl1271_register_hw(struct wl1271
*wl
)
4957 u32 oui_addr
= 0, nic_addr
= 0;
4959 if (wl
->mac80211_registered
)
4962 ret
= wl12xx_get_hw_info(wl
);
4964 wl1271_error("couldn't get hw info");
4968 ret
= wl1271_fetch_nvs(wl
);
4970 /* NOTE: The wl->nvs->nvs element must be first, in
4971 * order to simplify the casting, we assume it is at
4972 * the beginning of the wl->nvs structure.
4974 u8
*nvs_ptr
= (u8
*)wl
->nvs
;
4977 (nvs_ptr
[11] << 16) + (nvs_ptr
[10] << 8) + nvs_ptr
[6];
4979 (nvs_ptr
[5] << 16) + (nvs_ptr
[4] << 8) + nvs_ptr
[3];
4982 /* if the MAC address is zeroed in the NVS derive from fuse */
4983 if (oui_addr
== 0 && nic_addr
== 0) {
4984 oui_addr
= wl
->fuse_oui_addr
;
4985 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
4986 nic_addr
= wl
->fuse_nic_addr
+ 1;
4989 wl12xx_derive_mac_addresses(wl
, oui_addr
, nic_addr
, 2);
4991 ret
= ieee80211_register_hw(wl
->hw
);
4993 wl1271_error("unable to register mac80211 hw: %d", ret
);
4997 wl
->mac80211_registered
= true;
4999 wl1271_debugfs_init(wl
);
5001 wl1271_notice("loaded");
5007 static void wl1271_unregister_hw(struct wl1271
*wl
)
5010 wl1271_plt_stop(wl
);
5012 ieee80211_unregister_hw(wl
->hw
);
5013 wl
->mac80211_registered
= false;
5017 static int wl1271_init_ieee80211(struct wl1271
*wl
)
5019 static const u32 cipher_suites
[] = {
5020 WLAN_CIPHER_SUITE_WEP40
,
5021 WLAN_CIPHER_SUITE_WEP104
,
5022 WLAN_CIPHER_SUITE_TKIP
,
5023 WLAN_CIPHER_SUITE_CCMP
,
5024 WL1271_CIPHER_SUITE_GEM
,
5027 /* The tx descriptor buffer and the TKIP space. */
5028 wl
->hw
->extra_tx_headroom
= WL1271_EXTRA_SPACE_TKIP
+
5029 sizeof(struct wl1271_tx_hw_descr
);
5032 /* FIXME: find a proper value */
5033 wl
->hw
->channel_change_time
= 10000;
5034 wl
->hw
->max_listen_interval
= wl
->conf
.conn
.max_listen_interval
;
5036 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
5037 IEEE80211_HW_SUPPORTS_PS
|
5038 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
5039 IEEE80211_HW_SUPPORTS_UAPSD
|
5040 IEEE80211_HW_HAS_RATE_CONTROL
|
5041 IEEE80211_HW_CONNECTION_MONITOR
|
5042 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
5043 IEEE80211_HW_SPECTRUM_MGMT
|
5044 IEEE80211_HW_AP_LINK_PS
|
5045 IEEE80211_HW_AMPDU_AGGREGATION
|
5046 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
|
5047 IEEE80211_HW_SCAN_WHILE_IDLE
;
5049 wl
->hw
->wiphy
->cipher_suites
= cipher_suites
;
5050 wl
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
5052 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5053 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_AP
) |
5054 BIT(NL80211_IFTYPE_P2P_CLIENT
) | BIT(NL80211_IFTYPE_P2P_GO
);
5055 wl
->hw
->wiphy
->max_scan_ssids
= 1;
5056 wl
->hw
->wiphy
->max_sched_scan_ssids
= 16;
5057 wl
->hw
->wiphy
->max_match_sets
= 16;
5059 * Maximum length of elements in scanning probe request templates
5060 * should be the maximum length possible for a template, without
5061 * the IEEE80211 header of the template
5063 wl
->hw
->wiphy
->max_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5064 sizeof(struct ieee80211_header
);
5066 wl
->hw
->wiphy
->max_sched_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5067 sizeof(struct ieee80211_header
);
5069 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
5071 /* make sure all our channels fit in the scanned_ch bitmask */
5072 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels
) +
5073 ARRAY_SIZE(wl1271_channels_5ghz
) >
5074 WL1271_MAX_CHANNELS
);
5076 * We keep local copies of the band structs because we need to
5077 * modify them on a per-device basis.
5079 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
], &wl1271_band_2ghz
,
5080 sizeof(wl1271_band_2ghz
));
5081 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
], &wl1271_band_5ghz
,
5082 sizeof(wl1271_band_5ghz
));
5084 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5085 &wl
->bands
[IEEE80211_BAND_2GHZ
];
5086 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5087 &wl
->bands
[IEEE80211_BAND_5GHZ
];
5090 wl
->hw
->max_rates
= 1;
5092 wl
->hw
->wiphy
->reg_notifier
= wl1271_reg_notify
;
5094 /* the FW answers probe-requests in AP-mode */
5095 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5096 wl
->hw
->wiphy
->probe_resp_offload
=
5097 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5098 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5099 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5101 SET_IEEE80211_DEV(wl
->hw
, wl
->dev
);
5103 wl
->hw
->sta_data_size
= sizeof(struct wl1271_station
);
5104 wl
->hw
->vif_data_size
= sizeof(struct wl12xx_vif
);
5106 wl
->hw
->max_rx_aggregation_subframes
= 8;
5111 #define WL1271_DEFAULT_CHANNEL 0
5113 struct ieee80211_hw
*wlcore_alloc_hw(size_t priv_size
)
5115 struct ieee80211_hw
*hw
;
5120 BUILD_BUG_ON(AP_MAX_STATIONS
> WL12XX_MAX_LINKS
);
5122 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
5124 wl1271_error("could not alloc ieee80211_hw");
5130 memset(wl
, 0, sizeof(*wl
));
5132 wl
->priv
= kzalloc(priv_size
, GFP_KERNEL
);
5134 wl1271_error("could not alloc wl priv");
5136 goto err_priv_alloc
;
5139 INIT_LIST_HEAD(&wl
->wlvif_list
);
5143 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
5144 for (j
= 0; j
< WL12XX_MAX_LINKS
; j
++)
5145 skb_queue_head_init(&wl
->links
[j
].tx_queue
[i
]);
5147 skb_queue_head_init(&wl
->deferred_rx_queue
);
5148 skb_queue_head_init(&wl
->deferred_tx_queue
);
5150 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
5151 INIT_WORK(&wl
->netstack_work
, wl1271_netstack_work
);
5152 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
5153 INIT_WORK(&wl
->recovery_work
, wl1271_recovery_work
);
5154 INIT_DELAYED_WORK(&wl
->scan_complete_work
, wl1271_scan_complete_work
);
5155 INIT_DELAYED_WORK(&wl
->tx_watchdog_work
, wl12xx_tx_watchdog_work
);
5157 wl
->freezable_wq
= create_freezable_workqueue("wl12xx_wq");
5158 if (!wl
->freezable_wq
) {
5163 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
5165 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
5166 wl
->band
= IEEE80211_BAND_2GHZ
;
5168 wl
->sg_enabled
= true;
5171 wl
->ap_fw_ps_map
= 0;
5173 wl
->platform_quirks
= 0;
5174 wl
->sched_scanning
= false;
5175 wl
->system_hlid
= WL12XX_SYSTEM_HLID
;
5176 wl
->active_sta_count
= 0;
5178 init_waitqueue_head(&wl
->fwlog_waitq
);
5180 /* The system link is always allocated */
5181 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
5183 memset(wl
->tx_frames_map
, 0, sizeof(wl
->tx_frames_map
));
5184 for (i
= 0; i
< wl
->num_tx_desc
; i
++)
5185 wl
->tx_frames
[i
] = NULL
;
5187 spin_lock_init(&wl
->wl_lock
);
5189 wl
->state
= WL1271_STATE_OFF
;
5190 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5191 mutex_init(&wl
->mutex
);
5193 /* Apply default driver configuration. */
5194 wl1271_conf_init(wl
);
5196 order
= get_order(WL1271_AGGR_BUFFER_SIZE
);
5197 wl
->aggr_buf
= (u8
*)__get_free_pages(GFP_KERNEL
, order
);
5198 if (!wl
->aggr_buf
) {
5203 wl
->dummy_packet
= wl12xx_alloc_dummy_packet(wl
);
5204 if (!wl
->dummy_packet
) {
5209 /* Allocate one page for the FW log */
5210 wl
->fwlog
= (u8
*)get_zeroed_page(GFP_KERNEL
);
5213 goto err_dummy_packet
;
5216 wl
->mbox
= kmalloc(sizeof(*wl
->mbox
), GFP_DMA
);
5225 free_page((unsigned long)wl
->fwlog
);
5228 dev_kfree_skb(wl
->dummy_packet
);
5231 free_pages((unsigned long)wl
->aggr_buf
, order
);
5234 destroy_workqueue(wl
->freezable_wq
);
5237 wl1271_debugfs_exit(wl
);
5241 ieee80211_free_hw(hw
);
5245 return ERR_PTR(ret
);
5247 EXPORT_SYMBOL_GPL(wlcore_alloc_hw
);
5249 int wlcore_free_hw(struct wl1271
*wl
)
5251 /* Unblock any fwlog readers */
5252 mutex_lock(&wl
->mutex
);
5253 wl
->fwlog_size
= -1;
5254 wake_up_interruptible_all(&wl
->fwlog_waitq
);
5255 mutex_unlock(&wl
->mutex
);
5257 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
5259 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5261 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5262 free_page((unsigned long)wl
->fwlog
);
5263 dev_kfree_skb(wl
->dummy_packet
);
5264 free_pages((unsigned long)wl
->aggr_buf
,
5265 get_order(WL1271_AGGR_BUFFER_SIZE
));
5267 wl1271_debugfs_exit(wl
);
5271 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5275 kfree(wl
->fw_status
);
5276 kfree(wl
->tx_res_if
);
5277 destroy_workqueue(wl
->freezable_wq
);
5280 ieee80211_free_hw(wl
->hw
);
5284 EXPORT_SYMBOL_GPL(wlcore_free_hw
);
5286 static irqreturn_t
wl12xx_hardirq(int irq
, void *cookie
)
5288 struct wl1271
*wl
= cookie
;
5289 unsigned long flags
;
5291 wl1271_debug(DEBUG_IRQ
, "IRQ");
5293 /* complete the ELP completion */
5294 spin_lock_irqsave(&wl
->wl_lock
, flags
);
5295 set_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
5296 if (wl
->elp_compl
) {
5297 complete(wl
->elp_compl
);
5298 wl
->elp_compl
= NULL
;
5301 if (test_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
)) {
5302 /* don't enqueue a work right now. mark it as pending */
5303 set_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
);
5304 wl1271_debug(DEBUG_IRQ
, "should not enqueue work");
5305 disable_irq_nosync(wl
->irq
);
5306 pm_wakeup_event(wl
->dev
, 0);
5307 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5310 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5312 return IRQ_WAKE_THREAD
;
5315 int __devinit
wlcore_probe(struct wl1271
*wl
, struct platform_device
*pdev
)
5317 struct wl12xx_platform_data
*pdata
= pdev
->dev
.platform_data
;
5318 unsigned long irqflags
;
5321 if (!wl
->ops
|| !wl
->ptable
) {
5326 BUG_ON(wl
->num_tx_desc
> WLCORE_MAX_TX_DESCRIPTORS
);
5328 wl
->irq
= platform_get_irq(pdev
, 0);
5329 wl
->ref_clock
= pdata
->board_ref_clock
;
5330 wl
->tcxo_clock
= pdata
->board_tcxo_clock
;
5331 wl
->platform_quirks
= pdata
->platform_quirks
;
5332 wl
->set_power
= pdata
->set_power
;
5333 wl
->dev
= &pdev
->dev
;
5334 wl
->if_ops
= pdata
->ops
;
5336 platform_set_drvdata(pdev
, wl
);
5338 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
5339 irqflags
= IRQF_TRIGGER_RISING
;
5341 irqflags
= IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
;
5343 ret
= request_threaded_irq(wl
->irq
, wl12xx_hardirq
, wl1271_irq
,
5347 wl1271_error("request_irq() failed: %d", ret
);
5351 ret
= enable_irq_wake(wl
->irq
);
5353 wl
->irq_wake_enabled
= true;
5354 device_init_wakeup(wl
->dev
, 1);
5355 if (pdata
->pwr_in_suspend
)
5356 wl
->hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_ANY
;
5359 disable_irq(wl
->irq
);
5361 ret
= wl1271_init_ieee80211(wl
);
5365 ret
= wl1271_register_hw(wl
);
5369 /* Create sysfs file to control bt coex state */
5370 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
5372 wl1271_error("failed to create sysfs file bt_coex_state");
5376 /* Create sysfs file to get HW PG version */
5377 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5379 wl1271_error("failed to create sysfs file hw_pg_ver");
5380 goto out_bt_coex_state
;
5383 /* Create sysfs file for the FW log */
5384 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
5386 wl1271_error("failed to create sysfs file fwlog");
5393 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5396 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5399 free_irq(wl
->irq
, wl
);
5407 EXPORT_SYMBOL_GPL(wlcore_probe
);
5409 int __devexit
wlcore_remove(struct platform_device
*pdev
)
5411 struct wl1271
*wl
= platform_get_drvdata(pdev
);
5413 if (wl
->irq_wake_enabled
) {
5414 device_init_wakeup(wl
->dev
, 0);
5415 disable_irq_wake(wl
->irq
);
5417 wl1271_unregister_hw(wl
);
5418 free_irq(wl
->irq
, wl
);
5423 EXPORT_SYMBOL_GPL(wlcore_remove
);
5425 u32 wl12xx_debug_level
= DEBUG_NONE
;
5426 EXPORT_SYMBOL_GPL(wl12xx_debug_level
);
5427 module_param_named(debug_level
, wl12xx_debug_level
, uint
, S_IRUSR
| S_IWUSR
);
5428 MODULE_PARM_DESC(debug_level
, "wl12xx debugging level");
5430 module_param_named(fwlog
, fwlog_param
, charp
, 0);
5431 MODULE_PARM_DESC(fwlog
,
5432 "FW logger options: continuous, ondemand, dbgpins or disable");
5434 module_param(bug_on_recovery
, bool, S_IRUSR
| S_IWUSR
);
5435 MODULE_PARM_DESC(bug_on_recovery
, "BUG() on fw recovery");
5437 MODULE_LICENSE("GPL");
5438 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5439 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");