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 #define WL1271_BOOT_RETRIES 3
58 static char *fwlog_param
;
59 static int bug_on_recovery
= -1;
60 static int no_recovery
= -1;
62 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
63 struct ieee80211_vif
*vif
,
64 bool reset_tx_queues
);
65 static void wlcore_op_stop_locked(struct wl1271
*wl
);
66 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
);
68 static int wl12xx_set_authorized(struct wl1271
*wl
,
69 struct wl12xx_vif
*wlvif
)
73 if (WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
))
76 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
79 if (test_and_set_bit(WLVIF_FLAG_STA_STATE_SENT
, &wlvif
->flags
))
82 ret
= wl12xx_cmd_set_peer_state(wl
, wlvif
, wlvif
->sta
.hlid
);
86 wl1271_info("Association completed.");
90 static int wl1271_reg_notify(struct wiphy
*wiphy
,
91 struct regulatory_request
*request
)
93 struct ieee80211_supported_band
*band
;
94 struct ieee80211_channel
*ch
;
96 struct ieee80211_hw
*hw
= wiphy_to_ieee80211_hw(wiphy
);
97 struct wl1271
*wl
= hw
->priv
;
99 band
= wiphy
->bands
[IEEE80211_BAND_5GHZ
];
100 for (i
= 0; i
< band
->n_channels
; i
++) {
101 ch
= &band
->channels
[i
];
102 if (ch
->flags
& IEEE80211_CHAN_DISABLED
)
105 if (ch
->flags
& IEEE80211_CHAN_RADAR
)
106 ch
->flags
|= IEEE80211_CHAN_NO_IBSS
|
107 IEEE80211_CHAN_PASSIVE_SCAN
;
111 if (likely(wl
->state
== WLCORE_STATE_ON
))
112 wlcore_regdomain_config(wl
);
117 static int wl1271_set_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
122 /* we should hold wl->mutex */
123 ret
= wl1271_acx_ps_rx_streaming(wl
, wlvif
, enable
);
128 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
130 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
136 * this function is being called when the rx_streaming interval
137 * has beed changed or rx_streaming should be disabled
139 int wl1271_recalc_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
142 int period
= wl
->conf
.rx_streaming
.interval
;
144 /* don't reconfigure if rx_streaming is disabled */
145 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
148 /* reconfigure/disable according to new streaming_period */
150 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
151 (wl
->conf
.rx_streaming
.always
||
152 test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
153 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
155 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
156 /* don't cancel_work_sync since we might deadlock */
157 del_timer_sync(&wlvif
->rx_streaming_timer
);
163 static void wl1271_rx_streaming_enable_work(struct work_struct
*work
)
166 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
167 rx_streaming_enable_work
);
168 struct wl1271
*wl
= wlvif
->wl
;
170 mutex_lock(&wl
->mutex
);
172 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
) ||
173 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
174 (!wl
->conf
.rx_streaming
.always
&&
175 !test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
178 if (!wl
->conf
.rx_streaming
.interval
)
181 ret
= wl1271_ps_elp_wakeup(wl
);
185 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
189 /* stop it after some time of inactivity */
190 mod_timer(&wlvif
->rx_streaming_timer
,
191 jiffies
+ msecs_to_jiffies(wl
->conf
.rx_streaming
.duration
));
194 wl1271_ps_elp_sleep(wl
);
196 mutex_unlock(&wl
->mutex
);
199 static void wl1271_rx_streaming_disable_work(struct work_struct
*work
)
202 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
203 rx_streaming_disable_work
);
204 struct wl1271
*wl
= wlvif
->wl
;
206 mutex_lock(&wl
->mutex
);
208 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
211 ret
= wl1271_ps_elp_wakeup(wl
);
215 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
220 wl1271_ps_elp_sleep(wl
);
222 mutex_unlock(&wl
->mutex
);
225 static void wl1271_rx_streaming_timer(unsigned long data
)
227 struct wl12xx_vif
*wlvif
= (struct wl12xx_vif
*)data
;
228 struct wl1271
*wl
= wlvif
->wl
;
229 ieee80211_queue_work(wl
->hw
, &wlvif
->rx_streaming_disable_work
);
232 /* wl->mutex must be taken */
233 void wl12xx_rearm_tx_watchdog_locked(struct wl1271
*wl
)
235 /* if the watchdog is not armed, don't do anything */
236 if (wl
->tx_allocated_blocks
== 0)
239 cancel_delayed_work(&wl
->tx_watchdog_work
);
240 ieee80211_queue_delayed_work(wl
->hw
, &wl
->tx_watchdog_work
,
241 msecs_to_jiffies(wl
->conf
.tx
.tx_watchdog_timeout
));
244 static void wl12xx_tx_watchdog_work(struct work_struct
*work
)
246 struct delayed_work
*dwork
;
249 dwork
= container_of(work
, struct delayed_work
, work
);
250 wl
= container_of(dwork
, struct wl1271
, tx_watchdog_work
);
252 mutex_lock(&wl
->mutex
);
254 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
257 /* Tx went out in the meantime - everything is ok */
258 if (unlikely(wl
->tx_allocated_blocks
== 0))
262 * if a ROC is in progress, we might not have any Tx for a long
263 * time (e.g. pending Tx on the non-ROC channels)
265 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
266 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to ROC",
267 wl
->conf
.tx
.tx_watchdog_timeout
);
268 wl12xx_rearm_tx_watchdog_locked(wl
);
273 * if a scan is in progress, we might not have any Tx for a long
276 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
) {
277 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to scan",
278 wl
->conf
.tx
.tx_watchdog_timeout
);
279 wl12xx_rearm_tx_watchdog_locked(wl
);
284 * AP might cache a frame for a long time for a sleeping station,
285 * so rearm the timer if there's an AP interface with stations. If
286 * Tx is genuinely stuck we will most hopefully discover it when all
287 * stations are removed due to inactivity.
289 if (wl
->active_sta_count
) {
290 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms. AP has "
292 wl
->conf
.tx
.tx_watchdog_timeout
,
293 wl
->active_sta_count
);
294 wl12xx_rearm_tx_watchdog_locked(wl
);
298 wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
299 wl
->conf
.tx
.tx_watchdog_timeout
);
300 wl12xx_queue_recovery_work(wl
);
303 mutex_unlock(&wl
->mutex
);
306 static void wlcore_adjust_conf(struct wl1271
*wl
)
308 /* Adjust settings according to optional module parameters */
311 if (!strcmp(fwlog_param
, "continuous")) {
312 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
313 } else if (!strcmp(fwlog_param
, "ondemand")) {
314 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_ON_DEMAND
;
315 } else if (!strcmp(fwlog_param
, "dbgpins")) {
316 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
317 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_DBG_PINS
;
318 } else if (!strcmp(fwlog_param
, "disable")) {
319 wl
->conf
.fwlog
.mem_blocks
= 0;
320 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_NONE
;
322 wl1271_error("Unknown fwlog parameter %s", fwlog_param
);
326 if (bug_on_recovery
!= -1)
327 wl
->conf
.recovery
.bug_on_recovery
= (u8
) bug_on_recovery
;
329 if (no_recovery
!= -1)
330 wl
->conf
.recovery
.no_recovery
= (u8
) no_recovery
;
333 static void wl12xx_irq_ps_regulate_link(struct wl1271
*wl
,
334 struct wl12xx_vif
*wlvif
,
337 bool fw_ps
, single_sta
;
339 fw_ps
= test_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
340 single_sta
= (wl
->active_sta_count
== 1);
343 * Wake up from high level PS if the STA is asleep with too little
344 * packets in FW or if the STA is awake.
346 if (!fw_ps
|| tx_pkts
< WL1271_PS_STA_MAX_PACKETS
)
347 wl12xx_ps_link_end(wl
, wlvif
, hlid
);
350 * Start high-level PS if the STA is asleep with enough blocks in FW.
351 * Make an exception if this is the only connected station. In this
352 * case FW-memory congestion is not a problem.
354 else if (!single_sta
&& fw_ps
&& tx_pkts
>= WL1271_PS_STA_MAX_PACKETS
)
355 wl12xx_ps_link_start(wl
, wlvif
, hlid
, true);
358 static void wl12xx_irq_update_links_status(struct wl1271
*wl
,
359 struct wl12xx_vif
*wlvif
,
360 struct wl_fw_status_2
*status
)
362 struct wl1271_link
*lnk
;
366 /* TODO: also use link_fast_bitmap here */
368 cur_fw_ps_map
= le32_to_cpu(status
->link_ps_bitmap
);
369 if (wl
->ap_fw_ps_map
!= cur_fw_ps_map
) {
370 wl1271_debug(DEBUG_PSM
,
371 "link ps prev 0x%x cur 0x%x changed 0x%x",
372 wl
->ap_fw_ps_map
, cur_fw_ps_map
,
373 wl
->ap_fw_ps_map
^ cur_fw_ps_map
);
375 wl
->ap_fw_ps_map
= cur_fw_ps_map
;
378 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
, WL12XX_MAX_LINKS
) {
379 lnk
= &wl
->links
[hlid
];
380 cnt
= status
->counters
.tx_lnk_free_pkts
[hlid
] -
381 lnk
->prev_freed_pkts
;
383 lnk
->prev_freed_pkts
= status
->counters
.tx_lnk_free_pkts
[hlid
];
384 lnk
->allocated_pkts
-= cnt
;
386 wl12xx_irq_ps_regulate_link(wl
, wlvif
, hlid
,
387 lnk
->allocated_pkts
);
391 static int wlcore_fw_status(struct wl1271
*wl
,
392 struct wl_fw_status_1
*status_1
,
393 struct wl_fw_status_2
*status_2
)
395 struct wl12xx_vif
*wlvif
;
397 u32 old_tx_blk_count
= wl
->tx_blocks_available
;
398 int avail
, freed_blocks
;
403 status_len
= WLCORE_FW_STATUS_1_LEN(wl
->num_rx_desc
) +
404 sizeof(*status_2
) + wl
->fw_status_priv_len
;
406 ret
= wlcore_raw_read_data(wl
, REG_RAW_FW_STATUS_ADDR
, status_1
,
411 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
412 "drv_rx_counter = %d, tx_results_counter = %d)",
414 status_1
->fw_rx_counter
,
415 status_1
->drv_rx_counter
,
416 status_1
->tx_results_counter
);
418 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
419 /* prevent wrap-around in freed-packets counter */
420 wl
->tx_allocated_pkts
[i
] -=
421 (status_2
->counters
.tx_released_pkts
[i
] -
422 wl
->tx_pkts_freed
[i
]) & 0xff;
424 wl
->tx_pkts_freed
[i
] = status_2
->counters
.tx_released_pkts
[i
];
427 /* prevent wrap-around in total blocks counter */
428 if (likely(wl
->tx_blocks_freed
<=
429 le32_to_cpu(status_2
->total_released_blks
)))
430 freed_blocks
= le32_to_cpu(status_2
->total_released_blks
) -
433 freed_blocks
= 0x100000000LL
- wl
->tx_blocks_freed
+
434 le32_to_cpu(status_2
->total_released_blks
);
436 wl
->tx_blocks_freed
= le32_to_cpu(status_2
->total_released_blks
);
438 wl
->tx_allocated_blocks
-= freed_blocks
;
441 * If the FW freed some blocks:
442 * If we still have allocated blocks - re-arm the timer, Tx is
443 * not stuck. Otherwise, cancel the timer (no Tx currently).
446 if (wl
->tx_allocated_blocks
)
447 wl12xx_rearm_tx_watchdog_locked(wl
);
449 cancel_delayed_work(&wl
->tx_watchdog_work
);
452 avail
= le32_to_cpu(status_2
->tx_total
) - wl
->tx_allocated_blocks
;
455 * The FW might change the total number of TX memblocks before
456 * we get a notification about blocks being released. Thus, the
457 * available blocks calculation might yield a temporary result
458 * which is lower than the actual available blocks. Keeping in
459 * mind that only blocks that were allocated can be moved from
460 * TX to RX, tx_blocks_available should never decrease here.
462 wl
->tx_blocks_available
= max((int)wl
->tx_blocks_available
,
465 /* if more blocks are available now, tx work can be scheduled */
466 if (wl
->tx_blocks_available
> old_tx_blk_count
)
467 clear_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
);
469 /* for AP update num of allocated TX blocks per link and ps status */
470 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
471 wl12xx_irq_update_links_status(wl
, wlvif
, status_2
);
474 /* update the host-chipset time offset */
476 wl
->time_offset
= (timespec_to_ns(&ts
) >> 10) -
477 (s64
)le32_to_cpu(status_2
->fw_localtime
);
482 static void wl1271_flush_deferred_work(struct wl1271
*wl
)
486 /* Pass all received frames to the network stack */
487 while ((skb
= skb_dequeue(&wl
->deferred_rx_queue
)))
488 ieee80211_rx_ni(wl
->hw
, skb
);
490 /* Return sent skbs to the network stack */
491 while ((skb
= skb_dequeue(&wl
->deferred_tx_queue
)))
492 ieee80211_tx_status_ni(wl
->hw
, skb
);
495 static void wl1271_netstack_work(struct work_struct
*work
)
498 container_of(work
, struct wl1271
, netstack_work
);
501 wl1271_flush_deferred_work(wl
);
502 } while (skb_queue_len(&wl
->deferred_rx_queue
));
505 #define WL1271_IRQ_MAX_LOOPS 256
507 static int wlcore_irq_locked(struct wl1271
*wl
)
511 int loopcount
= WL1271_IRQ_MAX_LOOPS
;
513 unsigned int defer_count
;
517 * In case edge triggered interrupt must be used, we cannot iterate
518 * more than once without introducing race conditions with the hardirq.
520 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
523 wl1271_debug(DEBUG_IRQ
, "IRQ work");
525 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
528 ret
= wl1271_ps_elp_wakeup(wl
);
532 while (!done
&& loopcount
--) {
534 * In order to avoid a race with the hardirq, clear the flag
535 * before acknowledging the chip. Since the mutex is held,
536 * wl1271_ps_elp_wakeup cannot be called concurrently.
538 clear_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
539 smp_mb__after_clear_bit();
541 ret
= wlcore_fw_status(wl
, wl
->fw_status_1
, wl
->fw_status_2
);
545 wlcore_hw_tx_immediate_compl(wl
);
547 intr
= le32_to_cpu(wl
->fw_status_1
->intr
);
548 intr
&= WLCORE_ALL_INTR_MASK
;
554 if (unlikely(intr
& WL1271_ACX_INTR_WATCHDOG
)) {
555 wl1271_error("HW watchdog interrupt received! starting recovery.");
556 wl
->watchdog_recovery
= true;
559 /* restarting the chip. ignore any other interrupt. */
563 if (unlikely(intr
& WL1271_ACX_SW_INTR_WATCHDOG
)) {
564 wl1271_error("SW watchdog interrupt received! "
565 "starting recovery.");
566 wl
->watchdog_recovery
= true;
569 /* restarting the chip. ignore any other interrupt. */
573 if (likely(intr
& WL1271_ACX_INTR_DATA
)) {
574 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
576 ret
= wlcore_rx(wl
, wl
->fw_status_1
);
580 /* Check if any tx blocks were freed */
581 spin_lock_irqsave(&wl
->wl_lock
, flags
);
582 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
583 wl1271_tx_total_queue_count(wl
) > 0) {
584 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
586 * In order to avoid starvation of the TX path,
587 * call the work function directly.
589 ret
= wlcore_tx_work_locked(wl
);
593 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
596 /* check for tx results */
597 ret
= wlcore_hw_tx_delayed_compl(wl
);
601 /* Make sure the deferred queues don't get too long */
602 defer_count
= skb_queue_len(&wl
->deferred_tx_queue
) +
603 skb_queue_len(&wl
->deferred_rx_queue
);
604 if (defer_count
> WL1271_DEFERRED_QUEUE_LIMIT
)
605 wl1271_flush_deferred_work(wl
);
608 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
609 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
610 ret
= wl1271_event_handle(wl
, 0);
615 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
616 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
617 ret
= wl1271_event_handle(wl
, 1);
622 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
623 wl1271_debug(DEBUG_IRQ
,
624 "WL1271_ACX_INTR_INIT_COMPLETE");
626 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
627 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
630 wl1271_ps_elp_sleep(wl
);
636 static irqreturn_t
wlcore_irq(int irq
, void *cookie
)
640 struct wl1271
*wl
= cookie
;
642 /* TX might be handled here, avoid redundant work */
643 set_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
644 cancel_work_sync(&wl
->tx_work
);
646 mutex_lock(&wl
->mutex
);
648 ret
= wlcore_irq_locked(wl
);
650 wl12xx_queue_recovery_work(wl
);
652 spin_lock_irqsave(&wl
->wl_lock
, flags
);
653 /* In case TX was not handled here, queue TX work */
654 clear_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
655 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
656 wl1271_tx_total_queue_count(wl
) > 0)
657 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
658 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
660 mutex_unlock(&wl
->mutex
);
665 struct vif_counter_data
{
668 struct ieee80211_vif
*cur_vif
;
669 bool cur_vif_running
;
672 static void wl12xx_vif_count_iter(void *data
, u8
*mac
,
673 struct ieee80211_vif
*vif
)
675 struct vif_counter_data
*counter
= data
;
678 if (counter
->cur_vif
== vif
)
679 counter
->cur_vif_running
= true;
682 /* caller must not hold wl->mutex, as it might deadlock */
683 static void wl12xx_get_vif_count(struct ieee80211_hw
*hw
,
684 struct ieee80211_vif
*cur_vif
,
685 struct vif_counter_data
*data
)
687 memset(data
, 0, sizeof(*data
));
688 data
->cur_vif
= cur_vif
;
690 ieee80211_iterate_active_interfaces(hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
691 wl12xx_vif_count_iter
, data
);
694 static int wl12xx_fetch_firmware(struct wl1271
*wl
, bool plt
)
696 const struct firmware
*fw
;
698 enum wl12xx_fw_type fw_type
;
702 fw_type
= WL12XX_FW_TYPE_PLT
;
703 fw_name
= wl
->plt_fw_name
;
706 * we can't call wl12xx_get_vif_count() here because
707 * wl->mutex is taken, so use the cached last_vif_count value
709 if (wl
->last_vif_count
> 1 && wl
->mr_fw_name
) {
710 fw_type
= WL12XX_FW_TYPE_MULTI
;
711 fw_name
= wl
->mr_fw_name
;
713 fw_type
= WL12XX_FW_TYPE_NORMAL
;
714 fw_name
= wl
->sr_fw_name
;
718 if (wl
->fw_type
== fw_type
)
721 wl1271_debug(DEBUG_BOOT
, "booting firmware %s", fw_name
);
723 ret
= request_firmware(&fw
, fw_name
, wl
->dev
);
726 wl1271_error("could not get firmware %s: %d", fw_name
, ret
);
731 wl1271_error("firmware size is not multiple of 32 bits: %zu",
738 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
739 wl
->fw_len
= fw
->size
;
740 wl
->fw
= vmalloc(wl
->fw_len
);
743 wl1271_error("could not allocate memory for the firmware");
748 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
750 wl
->fw_type
= fw_type
;
752 release_firmware(fw
);
757 void wl12xx_queue_recovery_work(struct wl1271
*wl
)
759 WARN_ON(!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
));
761 /* Avoid a recursive recovery */
762 if (wl
->state
== WLCORE_STATE_ON
) {
763 wl
->state
= WLCORE_STATE_RESTARTING
;
764 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
765 wlcore_disable_interrupts_nosync(wl
);
766 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
770 size_t wl12xx_copy_fwlog(struct wl1271
*wl
, u8
*memblock
, size_t maxlen
)
774 /* The FW log is a length-value list, find where the log end */
775 while (len
< maxlen
) {
776 if (memblock
[len
] == 0)
778 if (len
+ memblock
[len
] + 1 > maxlen
)
780 len
+= memblock
[len
] + 1;
783 /* Make sure we have enough room */
784 len
= min(len
, (size_t)(PAGE_SIZE
- wl
->fwlog_size
));
786 /* Fill the FW log file, consumed by the sysfs fwlog entry */
787 memcpy(wl
->fwlog
+ wl
->fwlog_size
, memblock
, len
);
788 wl
->fwlog_size
+= len
;
793 #define WLCORE_FW_LOG_END 0x2000000
795 static void wl12xx_read_fwlog_panic(struct wl1271
*wl
)
803 if ((wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
) ||
804 (wl
->conf
.fwlog
.mem_blocks
== 0))
807 wl1271_info("Reading FW panic log");
809 block
= kmalloc(WL12XX_HW_BLOCK_SIZE
, GFP_KERNEL
);
814 * Make sure the chip is awake and the logger isn't active.
815 * Do not send a stop fwlog command if the fw is hanged or if
816 * dbgpins are used (due to some fw bug).
818 if (wl1271_ps_elp_wakeup(wl
))
820 if (!wl
->watchdog_recovery
&&
821 wl
->conf
.fwlog
.output
!= WL12XX_FWLOG_OUTPUT_DBG_PINS
)
822 wl12xx_cmd_stop_fwlog(wl
);
824 /* Read the first memory block address */
825 ret
= wlcore_fw_status(wl
, wl
->fw_status_1
, wl
->fw_status_2
);
829 addr
= le32_to_cpu(wl
->fw_status_2
->log_start_addr
);
833 if (wl
->conf
.fwlog
.mode
== WL12XX_FWLOG_CONTINUOUS
) {
834 offset
= sizeof(addr
) + sizeof(struct wl1271_rx_descriptor
);
835 end_of_log
= WLCORE_FW_LOG_END
;
837 offset
= sizeof(addr
);
841 /* Traverse the memory blocks linked list */
843 memset(block
, 0, WL12XX_HW_BLOCK_SIZE
);
844 ret
= wlcore_read_hwaddr(wl
, addr
, block
, WL12XX_HW_BLOCK_SIZE
,
850 * Memory blocks are linked to one another. The first 4 bytes
851 * of each memory block hold the hardware address of the next
852 * one. The last memory block points to the first one in
853 * on demand mode and is equal to 0x2000000 in continuous mode.
855 addr
= le32_to_cpup((__le32
*)block
);
856 if (!wl12xx_copy_fwlog(wl
, block
+ offset
,
857 WL12XX_HW_BLOCK_SIZE
- offset
))
859 } while (addr
&& (addr
!= end_of_log
));
861 wake_up_interruptible(&wl
->fwlog_waitq
);
867 static void wlcore_print_recovery(struct wl1271
*wl
)
873 wl1271_info("Hardware recovery in progress. FW ver: %s",
874 wl
->chip
.fw_ver_str
);
876 /* change partitions momentarily so we can read the FW pc */
877 ret
= wlcore_set_partition(wl
, &wl
->ptable
[PART_BOOT
]);
881 ret
= wlcore_read_reg(wl
, REG_PC_ON_RECOVERY
, &pc
);
885 ret
= wlcore_read_reg(wl
, REG_INTERRUPT_NO_CLEAR
, &hint_sts
);
889 wl1271_info("pc: 0x%x, hint_sts: 0x%08x count: %d",
890 pc
, hint_sts
, ++wl
->recovery_count
);
892 wlcore_set_partition(wl
, &wl
->ptable
[PART_WORK
]);
896 static void wl1271_recovery_work(struct work_struct
*work
)
899 container_of(work
, struct wl1271
, recovery_work
);
900 struct wl12xx_vif
*wlvif
;
901 struct ieee80211_vif
*vif
;
903 mutex_lock(&wl
->mutex
);
905 if (wl
->state
== WLCORE_STATE_OFF
|| wl
->plt
)
908 if (!test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
)) {
909 wl12xx_read_fwlog_panic(wl
);
910 wlcore_print_recovery(wl
);
913 BUG_ON(wl
->conf
.recovery
.bug_on_recovery
&&
914 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
));
916 if (wl
->conf
.recovery
.no_recovery
) {
917 wl1271_info("No recovery (chosen on module load). Fw will remain stuck.");
922 * Advance security sequence number to overcome potential progress
923 * in the firmware during recovery. This doens't hurt if the network is
926 wl12xx_for_each_wlvif(wl
, wlvif
) {
927 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
928 test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
929 wlvif
->tx_security_seq
+=
930 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
933 /* Prevent spurious TX during FW restart */
934 wlcore_stop_queues(wl
, WLCORE_QUEUE_STOP_REASON_FW_RESTART
);
936 /* reboot the chipset */
937 while (!list_empty(&wl
->wlvif_list
)) {
938 wlvif
= list_first_entry(&wl
->wlvif_list
,
939 struct wl12xx_vif
, list
);
940 vif
= wl12xx_wlvif_to_vif(wlvif
);
941 __wl1271_op_remove_interface(wl
, vif
, false);
944 wlcore_op_stop_locked(wl
);
946 ieee80211_restart_hw(wl
->hw
);
949 * Its safe to enable TX now - the queues are stopped after a request
952 wlcore_wake_queues(wl
, WLCORE_QUEUE_STOP_REASON_FW_RESTART
);
955 wl
->watchdog_recovery
= false;
956 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
957 mutex_unlock(&wl
->mutex
);
960 static int wlcore_fw_wakeup(struct wl1271
*wl
)
962 return wlcore_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG
, ELPCTRL_WAKE_UP
);
965 static int wl1271_setup(struct wl1271
*wl
)
967 wl
->fw_status_1
= kmalloc(WLCORE_FW_STATUS_1_LEN(wl
->num_rx_desc
) +
968 sizeof(*wl
->fw_status_2
) +
969 wl
->fw_status_priv_len
, GFP_KERNEL
);
970 if (!wl
->fw_status_1
)
973 wl
->fw_status_2
= (struct wl_fw_status_2
*)
974 (((u8
*) wl
->fw_status_1
) +
975 WLCORE_FW_STATUS_1_LEN(wl
->num_rx_desc
));
977 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
978 if (!wl
->tx_res_if
) {
979 kfree(wl
->fw_status_1
);
986 static int wl12xx_set_power_on(struct wl1271
*wl
)
990 msleep(WL1271_PRE_POWER_ON_SLEEP
);
991 ret
= wl1271_power_on(wl
);
994 msleep(WL1271_POWER_ON_SLEEP
);
998 ret
= wlcore_set_partition(wl
, &wl
->ptable
[PART_BOOT
]);
1002 /* ELP module wake up */
1003 ret
= wlcore_fw_wakeup(wl
);
1011 wl1271_power_off(wl
);
1015 static int wl12xx_chip_wakeup(struct wl1271
*wl
, bool plt
)
1019 ret
= wl12xx_set_power_on(wl
);
1024 * For wl127x based devices we could use the default block
1025 * size (512 bytes), but due to a bug in the sdio driver, we
1026 * need to set it explicitly after the chip is powered on. To
1027 * simplify the code and since the performance impact is
1028 * negligible, we use the same block size for all different
1031 * Check if the bus supports blocksize alignment and, if it
1032 * doesn't, make sure we don't have the quirk.
1034 if (!wl1271_set_block_size(wl
))
1035 wl
->quirks
&= ~WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN
;
1037 /* TODO: make sure the lower driver has set things up correctly */
1039 ret
= wl1271_setup(wl
);
1043 ret
= wl12xx_fetch_firmware(wl
, plt
);
1051 int wl1271_plt_start(struct wl1271
*wl
, const enum plt_mode plt_mode
)
1053 int retries
= WL1271_BOOT_RETRIES
;
1054 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1056 static const char* const PLT_MODE
[] = {
1064 mutex_lock(&wl
->mutex
);
1066 wl1271_notice("power up");
1068 if (wl
->state
!= WLCORE_STATE_OFF
) {
1069 wl1271_error("cannot go into PLT state because not "
1070 "in off state: %d", wl
->state
);
1075 /* Indicate to lower levels that we are now in PLT mode */
1077 wl
->plt_mode
= plt_mode
;
1081 ret
= wl12xx_chip_wakeup(wl
, true);
1085 ret
= wl
->ops
->plt_init(wl
);
1089 wl
->state
= WLCORE_STATE_ON
;
1090 wl1271_notice("firmware booted in PLT mode %s (%s)",
1092 wl
->chip
.fw_ver_str
);
1094 /* update hw/fw version info in wiphy struct */
1095 wiphy
->hw_version
= wl
->chip
.id
;
1096 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
1097 sizeof(wiphy
->fw_version
));
1102 wl1271_power_off(wl
);
1106 wl
->plt_mode
= PLT_OFF
;
1108 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1109 WL1271_BOOT_RETRIES
);
1111 mutex_unlock(&wl
->mutex
);
1116 int wl1271_plt_stop(struct wl1271
*wl
)
1120 wl1271_notice("power down");
1123 * Interrupts must be disabled before setting the state to OFF.
1124 * Otherwise, the interrupt handler might be called and exit without
1125 * reading the interrupt status.
1127 wlcore_disable_interrupts(wl
);
1128 mutex_lock(&wl
->mutex
);
1130 mutex_unlock(&wl
->mutex
);
1133 * This will not necessarily enable interrupts as interrupts
1134 * may have been disabled when op_stop was called. It will,
1135 * however, balance the above call to disable_interrupts().
1137 wlcore_enable_interrupts(wl
);
1139 wl1271_error("cannot power down because not in PLT "
1140 "state: %d", wl
->state
);
1145 mutex_unlock(&wl
->mutex
);
1147 wl1271_flush_deferred_work(wl
);
1148 cancel_work_sync(&wl
->netstack_work
);
1149 cancel_work_sync(&wl
->recovery_work
);
1150 cancel_delayed_work_sync(&wl
->elp_work
);
1151 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1153 mutex_lock(&wl
->mutex
);
1154 wl1271_power_off(wl
);
1156 wl
->sleep_auth
= WL1271_PSM_ILLEGAL
;
1157 wl
->state
= WLCORE_STATE_OFF
;
1159 wl
->plt_mode
= PLT_OFF
;
1161 mutex_unlock(&wl
->mutex
);
1167 static void wl1271_op_tx(struct ieee80211_hw
*hw
,
1168 struct ieee80211_tx_control
*control
,
1169 struct sk_buff
*skb
)
1171 struct wl1271
*wl
= hw
->priv
;
1172 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1173 struct ieee80211_vif
*vif
= info
->control
.vif
;
1174 struct wl12xx_vif
*wlvif
= NULL
;
1175 unsigned long flags
;
1180 wlvif
= wl12xx_vif_to_data(vif
);
1182 mapping
= skb_get_queue_mapping(skb
);
1183 q
= wl1271_tx_get_queue(mapping
);
1185 hlid
= wl12xx_tx_get_hlid(wl
, wlvif
, skb
, control
->sta
);
1187 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1190 * drop the packet if the link is invalid or the queue is stopped
1191 * for any reason but watermark. Watermark is a "soft"-stop so we
1192 * allow these packets through.
1194 if (hlid
== WL12XX_INVALID_LINK_ID
||
1195 (wlvif
&& !test_bit(hlid
, wlvif
->links_map
)) ||
1196 (wlcore_is_queue_stopped(wl
, q
) &&
1197 !wlcore_is_queue_stopped_by_reason(wl
, q
,
1198 WLCORE_QUEUE_STOP_REASON_WATERMARK
))) {
1199 wl1271_debug(DEBUG_TX
, "DROP skb hlid %d q %d", hlid
, q
);
1200 ieee80211_free_txskb(hw
, skb
);
1204 wl1271_debug(DEBUG_TX
, "queue skb hlid %d q %d len %d",
1206 skb_queue_tail(&wl
->links
[hlid
].tx_queue
[q
], skb
);
1208 wl
->tx_queue_count
[q
]++;
1211 * The workqueue is slow to process the tx_queue and we need stop
1212 * the queue here, otherwise the queue will get too long.
1214 if (wl
->tx_queue_count
[q
] >= WL1271_TX_QUEUE_HIGH_WATERMARK
&&
1215 !wlcore_is_queue_stopped_by_reason(wl
, q
,
1216 WLCORE_QUEUE_STOP_REASON_WATERMARK
)) {
1217 wl1271_debug(DEBUG_TX
, "op_tx: stopping queues for q %d", q
);
1218 wlcore_stop_queue_locked(wl
, q
,
1219 WLCORE_QUEUE_STOP_REASON_WATERMARK
);
1223 * The chip specific setup must run before the first TX packet -
1224 * before that, the tx_work will not be initialized!
1227 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1228 !test_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
))
1229 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1232 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1235 int wl1271_tx_dummy_packet(struct wl1271
*wl
)
1237 unsigned long flags
;
1240 /* no need to queue a new dummy packet if one is already pending */
1241 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
))
1244 q
= wl1271_tx_get_queue(skb_get_queue_mapping(wl
->dummy_packet
));
1246 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1247 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
);
1248 wl
->tx_queue_count
[q
]++;
1249 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1251 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1252 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
))
1253 return wlcore_tx_work_locked(wl
);
1256 * If the FW TX is busy, TX work will be scheduled by the threaded
1257 * interrupt handler function
1263 * The size of the dummy packet should be at least 1400 bytes. However, in
1264 * order to minimize the number of bus transactions, aligning it to 512 bytes
1265 * boundaries could be beneficial, performance wise
1267 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1269 static struct sk_buff
*wl12xx_alloc_dummy_packet(struct wl1271
*wl
)
1271 struct sk_buff
*skb
;
1272 struct ieee80211_hdr_3addr
*hdr
;
1273 unsigned int dummy_packet_size
;
1275 dummy_packet_size
= TOTAL_TX_DUMMY_PACKET_SIZE
-
1276 sizeof(struct wl1271_tx_hw_descr
) - sizeof(*hdr
);
1278 skb
= dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE
);
1280 wl1271_warning("Failed to allocate a dummy packet skb");
1284 skb_reserve(skb
, sizeof(struct wl1271_tx_hw_descr
));
1286 hdr
= (struct ieee80211_hdr_3addr
*) skb_put(skb
, sizeof(*hdr
));
1287 memset(hdr
, 0, sizeof(*hdr
));
1288 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1289 IEEE80211_STYPE_NULLFUNC
|
1290 IEEE80211_FCTL_TODS
);
1292 memset(skb_put(skb
, dummy_packet_size
), 0, dummy_packet_size
);
1294 /* Dummy packets require the TID to be management */
1295 skb
->priority
= WL1271_TID_MGMT
;
1297 /* Initialize all fields that might be used */
1298 skb_set_queue_mapping(skb
, 0);
1299 memset(IEEE80211_SKB_CB(skb
), 0, sizeof(struct ieee80211_tx_info
));
1307 wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern
*p
)
1309 int num_fields
= 0, in_field
= 0, fields_size
= 0;
1310 int i
, pattern_len
= 0;
1313 wl1271_warning("No mask in WoWLAN pattern");
1318 * The pattern is broken up into segments of bytes at different offsets
1319 * that need to be checked by the FW filter. Each segment is called
1320 * a field in the FW API. We verify that the total number of fields
1321 * required for this pattern won't exceed FW limits (8)
1322 * as well as the total fields buffer won't exceed the FW limit.
1323 * Note that if there's a pattern which crosses Ethernet/IP header
1324 * boundary a new field is required.
1326 for (i
= 0; i
< p
->pattern_len
; i
++) {
1327 if (test_bit(i
, (unsigned long *)p
->mask
)) {
1332 if (i
== WL1271_RX_FILTER_ETH_HEADER_SIZE
) {
1334 fields_size
+= pattern_len
+
1335 RX_FILTER_FIELD_OVERHEAD
;
1343 fields_size
+= pattern_len
+
1344 RX_FILTER_FIELD_OVERHEAD
;
1351 fields_size
+= pattern_len
+ RX_FILTER_FIELD_OVERHEAD
;
1355 if (num_fields
> WL1271_RX_FILTER_MAX_FIELDS
) {
1356 wl1271_warning("RX Filter too complex. Too many segments");
1360 if (fields_size
> WL1271_RX_FILTER_MAX_FIELDS_SIZE
) {
1361 wl1271_warning("RX filter pattern is too big");
1368 struct wl12xx_rx_filter
*wl1271_rx_filter_alloc(void)
1370 return kzalloc(sizeof(struct wl12xx_rx_filter
), GFP_KERNEL
);
1373 void wl1271_rx_filter_free(struct wl12xx_rx_filter
*filter
)
1380 for (i
= 0; i
< filter
->num_fields
; i
++)
1381 kfree(filter
->fields
[i
].pattern
);
1386 int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter
*filter
,
1387 u16 offset
, u8 flags
,
1388 u8
*pattern
, u8 len
)
1390 struct wl12xx_rx_filter_field
*field
;
1392 if (filter
->num_fields
== WL1271_RX_FILTER_MAX_FIELDS
) {
1393 wl1271_warning("Max fields per RX filter. can't alloc another");
1397 field
= &filter
->fields
[filter
->num_fields
];
1399 field
->pattern
= kzalloc(len
, GFP_KERNEL
);
1400 if (!field
->pattern
) {
1401 wl1271_warning("Failed to allocate RX filter pattern");
1405 filter
->num_fields
++;
1407 field
->offset
= cpu_to_le16(offset
);
1408 field
->flags
= flags
;
1410 memcpy(field
->pattern
, pattern
, len
);
1415 int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter
*filter
)
1417 int i
, fields_size
= 0;
1419 for (i
= 0; i
< filter
->num_fields
; i
++)
1420 fields_size
+= filter
->fields
[i
].len
+
1421 sizeof(struct wl12xx_rx_filter_field
) -
1427 void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter
*filter
,
1431 struct wl12xx_rx_filter_field
*field
;
1433 for (i
= 0; i
< filter
->num_fields
; i
++) {
1434 field
= (struct wl12xx_rx_filter_field
*)buf
;
1436 field
->offset
= filter
->fields
[i
].offset
;
1437 field
->flags
= filter
->fields
[i
].flags
;
1438 field
->len
= filter
->fields
[i
].len
;
1440 memcpy(&field
->pattern
, filter
->fields
[i
].pattern
, field
->len
);
1441 buf
+= sizeof(struct wl12xx_rx_filter_field
) -
1442 sizeof(u8
*) + field
->len
;
1447 * Allocates an RX filter returned through f
1448 * which needs to be freed using rx_filter_free()
1450 static int wl1271_convert_wowlan_pattern_to_rx_filter(
1451 struct cfg80211_wowlan_trig_pkt_pattern
*p
,
1452 struct wl12xx_rx_filter
**f
)
1455 struct wl12xx_rx_filter
*filter
;
1459 filter
= wl1271_rx_filter_alloc();
1461 wl1271_warning("Failed to alloc rx filter");
1467 while (i
< p
->pattern_len
) {
1468 if (!test_bit(i
, (unsigned long *)p
->mask
)) {
1473 for (j
= i
; j
< p
->pattern_len
; j
++) {
1474 if (!test_bit(j
, (unsigned long *)p
->mask
))
1477 if (i
< WL1271_RX_FILTER_ETH_HEADER_SIZE
&&
1478 j
>= WL1271_RX_FILTER_ETH_HEADER_SIZE
)
1482 if (i
< WL1271_RX_FILTER_ETH_HEADER_SIZE
) {
1484 flags
= WL1271_RX_FILTER_FLAG_ETHERNET_HEADER
;
1486 offset
= i
- WL1271_RX_FILTER_ETH_HEADER_SIZE
;
1487 flags
= WL1271_RX_FILTER_FLAG_IP_HEADER
;
1492 ret
= wl1271_rx_filter_alloc_field(filter
,
1495 &p
->pattern
[i
], len
);
1502 filter
->action
= FILTER_SIGNAL
;
1508 wl1271_rx_filter_free(filter
);
1514 static int wl1271_configure_wowlan(struct wl1271
*wl
,
1515 struct cfg80211_wowlan
*wow
)
1519 if (!wow
|| wow
->any
|| !wow
->n_patterns
) {
1520 ret
= wl1271_acx_default_rx_filter_enable(wl
, 0,
1525 ret
= wl1271_rx_filter_clear_all(wl
);
1532 if (WARN_ON(wow
->n_patterns
> WL1271_MAX_RX_FILTERS
))
1535 /* Validate all incoming patterns before clearing current FW state */
1536 for (i
= 0; i
< wow
->n_patterns
; i
++) {
1537 ret
= wl1271_validate_wowlan_pattern(&wow
->patterns
[i
]);
1539 wl1271_warning("Bad wowlan pattern %d", i
);
1544 ret
= wl1271_acx_default_rx_filter_enable(wl
, 0, FILTER_SIGNAL
);
1548 ret
= wl1271_rx_filter_clear_all(wl
);
1552 /* Translate WoWLAN patterns into filters */
1553 for (i
= 0; i
< wow
->n_patterns
; i
++) {
1554 struct cfg80211_wowlan_trig_pkt_pattern
*p
;
1555 struct wl12xx_rx_filter
*filter
= NULL
;
1557 p
= &wow
->patterns
[i
];
1559 ret
= wl1271_convert_wowlan_pattern_to_rx_filter(p
, &filter
);
1561 wl1271_warning("Failed to create an RX filter from "
1562 "wowlan pattern %d", i
);
1566 ret
= wl1271_rx_filter_enable(wl
, i
, 1, filter
);
1568 wl1271_rx_filter_free(filter
);
1573 ret
= wl1271_acx_default_rx_filter_enable(wl
, 1, FILTER_DROP
);
1579 static int wl1271_configure_suspend_sta(struct wl1271
*wl
,
1580 struct wl12xx_vif
*wlvif
,
1581 struct cfg80211_wowlan
*wow
)
1585 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1588 ret
= wl1271_ps_elp_wakeup(wl
);
1592 ret
= wl1271_configure_wowlan(wl
, wow
);
1596 if ((wl
->conf
.conn
.suspend_wake_up_event
==
1597 wl
->conf
.conn
.wake_up_event
) &&
1598 (wl
->conf
.conn
.suspend_listen_interval
==
1599 wl
->conf
.conn
.listen_interval
))
1602 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1603 wl
->conf
.conn
.suspend_wake_up_event
,
1604 wl
->conf
.conn
.suspend_listen_interval
);
1607 wl1271_error("suspend: set wake up conditions failed: %d", ret
);
1610 wl1271_ps_elp_sleep(wl
);
1616 static int wl1271_configure_suspend_ap(struct wl1271
*wl
,
1617 struct wl12xx_vif
*wlvif
)
1621 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1624 ret
= wl1271_ps_elp_wakeup(wl
);
1628 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
1630 wl1271_ps_elp_sleep(wl
);
1636 static int wl1271_configure_suspend(struct wl1271
*wl
,
1637 struct wl12xx_vif
*wlvif
,
1638 struct cfg80211_wowlan
*wow
)
1640 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1641 return wl1271_configure_suspend_sta(wl
, wlvif
, wow
);
1642 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
1643 return wl1271_configure_suspend_ap(wl
, wlvif
);
1647 static void wl1271_configure_resume(struct wl1271
*wl
,
1648 struct wl12xx_vif
*wlvif
)
1651 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
1652 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
1654 if ((!is_ap
) && (!is_sta
))
1657 if (is_sta
&& !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1660 ret
= wl1271_ps_elp_wakeup(wl
);
1665 wl1271_configure_wowlan(wl
, NULL
);
1667 if ((wl
->conf
.conn
.suspend_wake_up_event
==
1668 wl
->conf
.conn
.wake_up_event
) &&
1669 (wl
->conf
.conn
.suspend_listen_interval
==
1670 wl
->conf
.conn
.listen_interval
))
1673 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1674 wl
->conf
.conn
.wake_up_event
,
1675 wl
->conf
.conn
.listen_interval
);
1678 wl1271_error("resume: wake up conditions failed: %d",
1682 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
1686 wl1271_ps_elp_sleep(wl
);
1689 static int wl1271_op_suspend(struct ieee80211_hw
*hw
,
1690 struct cfg80211_wowlan
*wow
)
1692 struct wl1271
*wl
= hw
->priv
;
1693 struct wl12xx_vif
*wlvif
;
1696 wl1271_debug(DEBUG_MAC80211
, "mac80211 suspend wow=%d", !!wow
);
1699 /* we want to perform the recovery before suspending */
1700 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
)) {
1701 wl1271_warning("postponing suspend to perform recovery");
1705 wl1271_tx_flush(wl
);
1707 mutex_lock(&wl
->mutex
);
1708 wl
->wow_enabled
= true;
1709 wl12xx_for_each_wlvif(wl
, wlvif
) {
1710 ret
= wl1271_configure_suspend(wl
, wlvif
, wow
);
1712 mutex_unlock(&wl
->mutex
);
1713 wl1271_warning("couldn't prepare device to suspend");
1717 mutex_unlock(&wl
->mutex
);
1718 /* flush any remaining work */
1719 wl1271_debug(DEBUG_MAC80211
, "flushing remaining works");
1722 * disable and re-enable interrupts in order to flush
1725 wlcore_disable_interrupts(wl
);
1728 * set suspended flag to avoid triggering a new threaded_irq
1729 * work. no need for spinlock as interrupts are disabled.
1731 set_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1733 wlcore_enable_interrupts(wl
);
1734 flush_work(&wl
->tx_work
);
1735 flush_delayed_work(&wl
->elp_work
);
1740 static int wl1271_op_resume(struct ieee80211_hw
*hw
)
1742 struct wl1271
*wl
= hw
->priv
;
1743 struct wl12xx_vif
*wlvif
;
1744 unsigned long flags
;
1745 bool run_irq_work
= false, pending_recovery
;
1748 wl1271_debug(DEBUG_MAC80211
, "mac80211 resume wow=%d",
1750 WARN_ON(!wl
->wow_enabled
);
1753 * re-enable irq_work enqueuing, and call irq_work directly if
1754 * there is a pending work.
1756 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1757 clear_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1758 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
))
1759 run_irq_work
= true;
1760 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1762 mutex_lock(&wl
->mutex
);
1764 /* test the recovery flag before calling any SDIO functions */
1765 pending_recovery
= test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
,
1769 wl1271_debug(DEBUG_MAC80211
,
1770 "run postponed irq_work directly");
1772 /* don't talk to the HW if recovery is pending */
1773 if (!pending_recovery
) {
1774 ret
= wlcore_irq_locked(wl
);
1776 wl12xx_queue_recovery_work(wl
);
1779 wlcore_enable_interrupts(wl
);
1782 if (pending_recovery
) {
1783 wl1271_warning("queuing forgotten recovery on resume");
1784 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
1788 wl12xx_for_each_wlvif(wl
, wlvif
) {
1789 wl1271_configure_resume(wl
, wlvif
);
1793 wl
->wow_enabled
= false;
1794 mutex_unlock(&wl
->mutex
);
1800 static int wl1271_op_start(struct ieee80211_hw
*hw
)
1802 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
1805 * We have to delay the booting of the hardware because
1806 * we need to know the local MAC address before downloading and
1807 * initializing the firmware. The MAC address cannot be changed
1808 * after boot, and without the proper MAC address, the firmware
1809 * will not function properly.
1811 * The MAC address is first known when the corresponding interface
1812 * is added. That is where we will initialize the hardware.
1818 static void wlcore_op_stop_locked(struct wl1271
*wl
)
1822 if (wl
->state
== WLCORE_STATE_OFF
) {
1823 if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
,
1825 wlcore_enable_interrupts(wl
);
1831 * this must be before the cancel_work calls below, so that the work
1832 * functions don't perform further work.
1834 wl
->state
= WLCORE_STATE_OFF
;
1837 * Use the nosync variant to disable interrupts, so the mutex could be
1838 * held while doing so without deadlocking.
1840 wlcore_disable_interrupts_nosync(wl
);
1842 mutex_unlock(&wl
->mutex
);
1844 wlcore_synchronize_interrupts(wl
);
1845 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
1846 cancel_work_sync(&wl
->recovery_work
);
1847 wl1271_flush_deferred_work(wl
);
1848 cancel_delayed_work_sync(&wl
->scan_complete_work
);
1849 cancel_work_sync(&wl
->netstack_work
);
1850 cancel_work_sync(&wl
->tx_work
);
1851 cancel_delayed_work_sync(&wl
->elp_work
);
1852 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1854 /* let's notify MAC80211 about the remaining pending TX frames */
1855 wl12xx_tx_reset(wl
);
1856 mutex_lock(&wl
->mutex
);
1858 wl1271_power_off(wl
);
1860 * In case a recovery was scheduled, interrupts were disabled to avoid
1861 * an interrupt storm. Now that the power is down, it is safe to
1862 * re-enable interrupts to balance the disable depth
1864 if (test_and_clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
1865 wlcore_enable_interrupts(wl
);
1867 wl
->band
= IEEE80211_BAND_2GHZ
;
1870 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1871 wl
->channel_type
= NL80211_CHAN_NO_HT
;
1872 wl
->tx_blocks_available
= 0;
1873 wl
->tx_allocated_blocks
= 0;
1874 wl
->tx_results_count
= 0;
1875 wl
->tx_packets_count
= 0;
1876 wl
->time_offset
= 0;
1877 wl
->ap_fw_ps_map
= 0;
1879 wl
->sleep_auth
= WL1271_PSM_ILLEGAL
;
1880 memset(wl
->roles_map
, 0, sizeof(wl
->roles_map
));
1881 memset(wl
->links_map
, 0, sizeof(wl
->links_map
));
1882 memset(wl
->roc_map
, 0, sizeof(wl
->roc_map
));
1883 memset(wl
->session_ids
, 0, sizeof(wl
->session_ids
));
1884 wl
->active_sta_count
= 0;
1886 /* The system link is always allocated */
1887 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
1890 * this is performed after the cancel_work calls and the associated
1891 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1892 * get executed before all these vars have been reset.
1896 wl
->tx_blocks_freed
= 0;
1898 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1899 wl
->tx_pkts_freed
[i
] = 0;
1900 wl
->tx_allocated_pkts
[i
] = 0;
1903 wl1271_debugfs_reset(wl
);
1905 kfree(wl
->fw_status_1
);
1906 wl
->fw_status_1
= NULL
;
1907 wl
->fw_status_2
= NULL
;
1908 kfree(wl
->tx_res_if
);
1909 wl
->tx_res_if
= NULL
;
1910 kfree(wl
->target_mem_map
);
1911 wl
->target_mem_map
= NULL
;
1914 * FW channels must be re-calibrated after recovery,
1915 * clear the last Reg-Domain channel configuration.
1917 memset(wl
->reg_ch_conf_last
, 0, sizeof(wl
->reg_ch_conf_last
));
1920 static void wlcore_op_stop(struct ieee80211_hw
*hw
)
1922 struct wl1271
*wl
= hw
->priv
;
1924 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
1926 mutex_lock(&wl
->mutex
);
1928 wlcore_op_stop_locked(wl
);
1930 mutex_unlock(&wl
->mutex
);
1933 static void wlcore_channel_switch_work(struct work_struct
*work
)
1935 struct delayed_work
*dwork
;
1937 struct ieee80211_vif
*vif
;
1938 struct wl12xx_vif
*wlvif
;
1941 dwork
= container_of(work
, struct delayed_work
, work
);
1942 wlvif
= container_of(dwork
, struct wl12xx_vif
, channel_switch_work
);
1945 wl1271_info("channel switch failed (role_id: %d).", wlvif
->role_id
);
1947 mutex_lock(&wl
->mutex
);
1949 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
1952 /* check the channel switch is still ongoing */
1953 if (!test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
))
1956 vif
= wl12xx_wlvif_to_vif(wlvif
);
1957 ieee80211_chswitch_done(vif
, false);
1959 ret
= wl1271_ps_elp_wakeup(wl
);
1963 wl12xx_cmd_stop_channel_switch(wl
, wlvif
);
1965 wl1271_ps_elp_sleep(wl
);
1967 mutex_unlock(&wl
->mutex
);
1970 static void wlcore_connection_loss_work(struct work_struct
*work
)
1972 struct delayed_work
*dwork
;
1974 struct ieee80211_vif
*vif
;
1975 struct wl12xx_vif
*wlvif
;
1977 dwork
= container_of(work
, struct delayed_work
, work
);
1978 wlvif
= container_of(dwork
, struct wl12xx_vif
, connection_loss_work
);
1981 wl1271_info("Connection loss work (role_id: %d).", wlvif
->role_id
);
1983 mutex_lock(&wl
->mutex
);
1985 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
1988 /* Call mac80211 connection loss */
1989 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1992 vif
= wl12xx_wlvif_to_vif(wlvif
);
1993 ieee80211_connection_loss(vif
);
1995 mutex_unlock(&wl
->mutex
);
1998 static int wl12xx_allocate_rate_policy(struct wl1271
*wl
, u8
*idx
)
2000 u8 policy
= find_first_zero_bit(wl
->rate_policies_map
,
2001 WL12XX_MAX_RATE_POLICIES
);
2002 if (policy
>= WL12XX_MAX_RATE_POLICIES
)
2005 __set_bit(policy
, wl
->rate_policies_map
);
2010 static void wl12xx_free_rate_policy(struct wl1271
*wl
, u8
*idx
)
2012 if (WARN_ON(*idx
>= WL12XX_MAX_RATE_POLICIES
))
2015 __clear_bit(*idx
, wl
->rate_policies_map
);
2016 *idx
= WL12XX_MAX_RATE_POLICIES
;
2019 static int wlcore_allocate_klv_template(struct wl1271
*wl
, u8
*idx
)
2021 u8 policy
= find_first_zero_bit(wl
->klv_templates_map
,
2022 WLCORE_MAX_KLV_TEMPLATES
);
2023 if (policy
>= WLCORE_MAX_KLV_TEMPLATES
)
2026 __set_bit(policy
, wl
->klv_templates_map
);
2031 static void wlcore_free_klv_template(struct wl1271
*wl
, u8
*idx
)
2033 if (WARN_ON(*idx
>= WLCORE_MAX_KLV_TEMPLATES
))
2036 __clear_bit(*idx
, wl
->klv_templates_map
);
2037 *idx
= WLCORE_MAX_KLV_TEMPLATES
;
2040 static u8
wl12xx_get_role_type(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2042 switch (wlvif
->bss_type
) {
2043 case BSS_TYPE_AP_BSS
:
2045 return WL1271_ROLE_P2P_GO
;
2047 return WL1271_ROLE_AP
;
2049 case BSS_TYPE_STA_BSS
:
2051 return WL1271_ROLE_P2P_CL
;
2053 return WL1271_ROLE_STA
;
2056 return WL1271_ROLE_IBSS
;
2059 wl1271_error("invalid bss_type: %d", wlvif
->bss_type
);
2061 return WL12XX_INVALID_ROLE_TYPE
;
2064 static int wl12xx_init_vif_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
2066 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2069 /* clear everything but the persistent data */
2070 memset(wlvif
, 0, offsetof(struct wl12xx_vif
, persistent
));
2072 switch (ieee80211_vif_type_p2p(vif
)) {
2073 case NL80211_IFTYPE_P2P_CLIENT
:
2076 case NL80211_IFTYPE_STATION
:
2077 wlvif
->bss_type
= BSS_TYPE_STA_BSS
;
2079 case NL80211_IFTYPE_ADHOC
:
2080 wlvif
->bss_type
= BSS_TYPE_IBSS
;
2082 case NL80211_IFTYPE_P2P_GO
:
2085 case NL80211_IFTYPE_AP
:
2086 wlvif
->bss_type
= BSS_TYPE_AP_BSS
;
2089 wlvif
->bss_type
= MAX_BSS_TYPE
;
2093 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
2094 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
2095 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
2097 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2098 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2099 /* init sta/ibss data */
2100 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
2101 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
2102 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
2103 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
2104 wlcore_allocate_klv_template(wl
, &wlvif
->sta
.klv_template_id
);
2105 wlvif
->basic_rate_set
= CONF_TX_RATE_MASK_BASIC
;
2106 wlvif
->basic_rate
= CONF_TX_RATE_MASK_BASIC
;
2107 wlvif
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
2110 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
2111 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
2112 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
2113 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
2114 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
2115 wl12xx_allocate_rate_policy(wl
,
2116 &wlvif
->ap
.ucast_rate_idx
[i
]);
2117 wlvif
->basic_rate_set
= CONF_TX_ENABLED_RATES
;
2119 * TODO: check if basic_rate shouldn't be
2120 * wl1271_tx_min_rate_get(wl, wlvif->basic_rate_set);
2121 * instead (the same thing for STA above).
2123 wlvif
->basic_rate
= CONF_TX_ENABLED_RATES
;
2124 /* TODO: this seems to be used only for STA, check it */
2125 wlvif
->rate_set
= CONF_TX_ENABLED_RATES
;
2128 wlvif
->bitrate_masks
[IEEE80211_BAND_2GHZ
] = wl
->conf
.tx
.basic_rate
;
2129 wlvif
->bitrate_masks
[IEEE80211_BAND_5GHZ
] = wl
->conf
.tx
.basic_rate_5
;
2130 wlvif
->beacon_int
= WL1271_DEFAULT_BEACON_INT
;
2133 * mac80211 configures some values globally, while we treat them
2134 * per-interface. thus, on init, we have to copy them from wl
2136 wlvif
->band
= wl
->band
;
2137 wlvif
->channel
= wl
->channel
;
2138 wlvif
->power_level
= wl
->power_level
;
2139 wlvif
->channel_type
= wl
->channel_type
;
2141 INIT_WORK(&wlvif
->rx_streaming_enable_work
,
2142 wl1271_rx_streaming_enable_work
);
2143 INIT_WORK(&wlvif
->rx_streaming_disable_work
,
2144 wl1271_rx_streaming_disable_work
);
2145 INIT_DELAYED_WORK(&wlvif
->channel_switch_work
,
2146 wlcore_channel_switch_work
);
2147 INIT_DELAYED_WORK(&wlvif
->connection_loss_work
,
2148 wlcore_connection_loss_work
);
2149 INIT_LIST_HEAD(&wlvif
->list
);
2151 setup_timer(&wlvif
->rx_streaming_timer
, wl1271_rx_streaming_timer
,
2152 (unsigned long) wlvif
);
2156 static bool wl12xx_init_fw(struct wl1271
*wl
)
2158 int retries
= WL1271_BOOT_RETRIES
;
2159 bool booted
= false;
2160 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
2165 ret
= wl12xx_chip_wakeup(wl
, false);
2169 ret
= wl
->ops
->boot(wl
);
2173 ret
= wl1271_hw_init(wl
);
2181 mutex_unlock(&wl
->mutex
);
2182 /* Unlocking the mutex in the middle of handling is
2183 inherently unsafe. In this case we deem it safe to do,
2184 because we need to let any possibly pending IRQ out of
2185 the system (and while we are WLCORE_STATE_OFF the IRQ
2186 work function will not do anything.) Also, any other
2187 possible concurrent operations will fail due to the
2188 current state, hence the wl1271 struct should be safe. */
2189 wlcore_disable_interrupts(wl
);
2190 wl1271_flush_deferred_work(wl
);
2191 cancel_work_sync(&wl
->netstack_work
);
2192 mutex_lock(&wl
->mutex
);
2194 wl1271_power_off(wl
);
2198 wl1271_error("firmware boot failed despite %d retries",
2199 WL1271_BOOT_RETRIES
);
2203 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver_str
);
2205 /* update hw/fw version info in wiphy struct */
2206 wiphy
->hw_version
= wl
->chip
.id
;
2207 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
2208 sizeof(wiphy
->fw_version
));
2211 * Now we know if 11a is supported (info from the NVS), so disable
2212 * 11a channels if not supported
2214 if (!wl
->enable_11a
)
2215 wiphy
->bands
[IEEE80211_BAND_5GHZ
]->n_channels
= 0;
2217 wl1271_debug(DEBUG_MAC80211
, "11a is %ssupported",
2218 wl
->enable_11a
? "" : "not ");
2220 wl
->state
= WLCORE_STATE_ON
;
2225 static bool wl12xx_dev_role_started(struct wl12xx_vif
*wlvif
)
2227 return wlvif
->dev_hlid
!= WL12XX_INVALID_LINK_ID
;
2231 * Check whether a fw switch (i.e. moving from one loaded
2232 * fw to another) is needed. This function is also responsible
2233 * for updating wl->last_vif_count, so it must be called before
2234 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2237 static bool wl12xx_need_fw_change(struct wl1271
*wl
,
2238 struct vif_counter_data vif_counter_data
,
2241 enum wl12xx_fw_type current_fw
= wl
->fw_type
;
2242 u8 vif_count
= vif_counter_data
.counter
;
2244 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
))
2247 /* increase the vif count if this is a new vif */
2248 if (add
&& !vif_counter_data
.cur_vif_running
)
2251 wl
->last_vif_count
= vif_count
;
2253 /* no need for fw change if the device is OFF */
2254 if (wl
->state
== WLCORE_STATE_OFF
)
2257 /* no need for fw change if a single fw is used */
2258 if (!wl
->mr_fw_name
)
2261 if (vif_count
> 1 && current_fw
== WL12XX_FW_TYPE_NORMAL
)
2263 if (vif_count
<= 1 && current_fw
== WL12XX_FW_TYPE_MULTI
)
2270 * Enter "forced psm". Make sure the sta is in psm against the ap,
2271 * to make the fw switch a bit more disconnection-persistent.
2273 static void wl12xx_force_active_psm(struct wl1271
*wl
)
2275 struct wl12xx_vif
*wlvif
;
2277 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
2278 wl1271_ps_set_mode(wl
, wlvif
, STATION_POWER_SAVE_MODE
);
2282 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
2283 struct ieee80211_vif
*vif
)
2285 struct wl1271
*wl
= hw
->priv
;
2286 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2287 struct vif_counter_data vif_count
;
2290 bool booted
= false;
2292 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
2293 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
2295 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
2296 ieee80211_vif_type_p2p(vif
), vif
->addr
);
2298 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2300 mutex_lock(&wl
->mutex
);
2301 ret
= wl1271_ps_elp_wakeup(wl
);
2306 * in some very corner case HW recovery scenarios its possible to
2307 * get here before __wl1271_op_remove_interface is complete, so
2308 * opt out if that is the case.
2310 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
) ||
2311 test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)) {
2317 ret
= wl12xx_init_vif_data(wl
, vif
);
2322 role_type
= wl12xx_get_role_type(wl
, wlvif
);
2323 if (role_type
== WL12XX_INVALID_ROLE_TYPE
) {
2328 if (wl12xx_need_fw_change(wl
, vif_count
, true)) {
2329 wl12xx_force_active_psm(wl
);
2330 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2331 mutex_unlock(&wl
->mutex
);
2332 wl1271_recovery_work(&wl
->recovery_work
);
2337 * TODO: after the nvs issue will be solved, move this block
2338 * to start(), and make sure here the driver is ON.
2340 if (wl
->state
== WLCORE_STATE_OFF
) {
2342 * we still need this in order to configure the fw
2343 * while uploading the nvs
2345 memcpy(wl
->addresses
[0].addr
, vif
->addr
, ETH_ALEN
);
2347 booted
= wl12xx_init_fw(wl
);
2354 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2355 role_type
, &wlvif
->role_id
);
2359 ret
= wl1271_init_vif_specific(wl
, vif
);
2363 list_add(&wlvif
->list
, &wl
->wlvif_list
);
2364 set_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
);
2366 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2371 wl1271_ps_elp_sleep(wl
);
2373 mutex_unlock(&wl
->mutex
);
2378 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
2379 struct ieee80211_vif
*vif
,
2380 bool reset_tx_queues
)
2382 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2384 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2386 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
2388 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2391 /* because of hardware recovery, we may get here twice */
2392 if (wl
->state
== WLCORE_STATE_OFF
)
2395 wl1271_info("down");
2397 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
&&
2398 wl
->scan_wlvif
== wlvif
) {
2400 * Rearm the tx watchdog just before idling scan. This
2401 * prevents just-finished scans from triggering the watchdog
2403 wl12xx_rearm_tx_watchdog_locked(wl
);
2405 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
2406 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
2407 wl
->scan_wlvif
= NULL
;
2408 wl
->scan
.req
= NULL
;
2409 ieee80211_scan_completed(wl
->hw
, true);
2412 if (wl
->sched_vif
== wlvif
) {
2413 ieee80211_sched_scan_stopped(wl
->hw
);
2414 wl
->sched_vif
= NULL
;
2417 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
)) {
2418 /* disable active roles */
2419 ret
= wl1271_ps_elp_wakeup(wl
);
2423 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2424 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2425 if (wl12xx_dev_role_started(wlvif
))
2426 wl12xx_stop_dev(wl
, wlvif
);
2429 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->role_id
);
2433 wl1271_ps_elp_sleep(wl
);
2436 /* clear all hlids (except system_hlid) */
2437 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
2439 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2440 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2441 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
2442 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
2443 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
2444 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
2445 wlcore_free_klv_template(wl
, &wlvif
->sta
.klv_template_id
);
2447 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
2448 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
2449 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
2450 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
2451 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
2452 wl12xx_free_rate_policy(wl
,
2453 &wlvif
->ap
.ucast_rate_idx
[i
]);
2454 wl1271_free_ap_keys(wl
, wlvif
);
2457 dev_kfree_skb(wlvif
->probereq
);
2458 wlvif
->probereq
= NULL
;
2459 wl12xx_tx_reset_wlvif(wl
, wlvif
);
2460 if (wl
->last_wlvif
== wlvif
)
2461 wl
->last_wlvif
= NULL
;
2462 list_del(&wlvif
->list
);
2463 memset(wlvif
->ap
.sta_hlid_map
, 0, sizeof(wlvif
->ap
.sta_hlid_map
));
2464 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
2465 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
2473 * Last AP, have more stations. Configure sleep auth according to STA.
2474 * Don't do thin on unintended recovery.
2476 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
) &&
2477 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
))
2480 if (wl
->ap_count
== 0 && is_ap
&& wl
->sta_count
) {
2481 u8 sta_auth
= wl
->conf
.conn
.sta_sleep_auth
;
2482 /* Configure for power according to debugfs */
2483 if (sta_auth
!= WL1271_PSM_ILLEGAL
)
2484 wl1271_acx_sleep_auth(wl
, sta_auth
);
2485 /* Configure for ELP power saving */
2487 wl1271_acx_sleep_auth(wl
, WL1271_PSM_ELP
);
2491 mutex_unlock(&wl
->mutex
);
2493 del_timer_sync(&wlvif
->rx_streaming_timer
);
2494 cancel_work_sync(&wlvif
->rx_streaming_enable_work
);
2495 cancel_work_sync(&wlvif
->rx_streaming_disable_work
);
2496 cancel_delayed_work_sync(&wlvif
->connection_loss_work
);
2498 mutex_lock(&wl
->mutex
);
2501 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
2502 struct ieee80211_vif
*vif
)
2504 struct wl1271
*wl
= hw
->priv
;
2505 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2506 struct wl12xx_vif
*iter
;
2507 struct vif_counter_data vif_count
;
2509 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2510 mutex_lock(&wl
->mutex
);
2512 if (wl
->state
== WLCORE_STATE_OFF
||
2513 !test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2517 * wl->vif can be null here if someone shuts down the interface
2518 * just when hardware recovery has been started.
2520 wl12xx_for_each_wlvif(wl
, iter
) {
2524 __wl1271_op_remove_interface(wl
, vif
, true);
2527 WARN_ON(iter
!= wlvif
);
2528 if (wl12xx_need_fw_change(wl
, vif_count
, false)) {
2529 wl12xx_force_active_psm(wl
);
2530 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2531 wl12xx_queue_recovery_work(wl
);
2534 mutex_unlock(&wl
->mutex
);
2537 static int wl12xx_op_change_interface(struct ieee80211_hw
*hw
,
2538 struct ieee80211_vif
*vif
,
2539 enum nl80211_iftype new_type
, bool p2p
)
2541 struct wl1271
*wl
= hw
->priv
;
2544 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2545 wl1271_op_remove_interface(hw
, vif
);
2547 vif
->type
= new_type
;
2549 ret
= wl1271_op_add_interface(hw
, vif
);
2551 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2555 static int wlcore_join(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2558 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
2561 * One of the side effects of the JOIN command is that is clears
2562 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2563 * to a WPA/WPA2 access point will therefore kill the data-path.
2564 * Currently the only valid scenario for JOIN during association
2565 * is on roaming, in which case we will also be given new keys.
2566 * Keep the below message for now, unless it starts bothering
2567 * users who really like to roam a lot :)
2569 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2570 wl1271_info("JOIN while associated.");
2572 /* clear encryption type */
2573 wlvif
->encryption_type
= KEY_NONE
;
2576 ret
= wl12xx_cmd_role_start_ibss(wl
, wlvif
);
2578 if (wl
->quirks
& WLCORE_QUIRK_START_STA_FAILS
) {
2580 * TODO: this is an ugly workaround for wl12xx fw
2581 * bug - we are not able to tx/rx after the first
2582 * start_sta, so make dummy start+stop calls,
2583 * and then call start_sta again.
2584 * this should be fixed in the fw.
2586 wl12xx_cmd_role_start_sta(wl
, wlvif
);
2587 wl12xx_cmd_role_stop_sta(wl
, wlvif
);
2590 ret
= wl12xx_cmd_role_start_sta(wl
, wlvif
);
2596 static int wl1271_ssid_set(struct wl12xx_vif
*wlvif
, struct sk_buff
*skb
,
2600 const u8
*ptr
= cfg80211_find_ie(WLAN_EID_SSID
, skb
->data
+ offset
,
2604 wl1271_error("No SSID in IEs!");
2609 if (ssid_len
> IEEE80211_MAX_SSID_LEN
) {
2610 wl1271_error("SSID is too long!");
2614 wlvif
->ssid_len
= ssid_len
;
2615 memcpy(wlvif
->ssid
, ptr
+2, ssid_len
);
2619 static int wlcore_set_ssid(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2621 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
2622 struct sk_buff
*skb
;
2625 /* we currently only support setting the ssid from the ap probe req */
2626 if (wlvif
->bss_type
!= BSS_TYPE_STA_BSS
)
2629 skb
= ieee80211_ap_probereq_get(wl
->hw
, vif
);
2633 ieoffset
= offsetof(struct ieee80211_mgmt
,
2634 u
.probe_req
.variable
);
2635 wl1271_ssid_set(wlvif
, skb
, ieoffset
);
2641 static int wlcore_set_assoc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2642 struct ieee80211_bss_conf
*bss_conf
,
2648 wlvif
->aid
= bss_conf
->aid
;
2649 wlvif
->channel_type
= cfg80211_get_chandef_type(&bss_conf
->chandef
);
2650 wlvif
->beacon_int
= bss_conf
->beacon_int
;
2651 wlvif
->wmm_enabled
= bss_conf
->qos
;
2653 set_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
);
2656 * with wl1271, we don't need to update the
2657 * beacon_int and dtim_period, because the firmware
2658 * updates it by itself when the first beacon is
2659 * received after a join.
2661 ret
= wl1271_cmd_build_ps_poll(wl
, wlvif
, wlvif
->aid
);
2666 * Get a template for hardware connection maintenance
2668 dev_kfree_skb(wlvif
->probereq
);
2669 wlvif
->probereq
= wl1271_cmd_build_ap_probe_req(wl
,
2672 ieoffset
= offsetof(struct ieee80211_mgmt
,
2673 u
.probe_req
.variable
);
2674 wl1271_ssid_set(wlvif
, wlvif
->probereq
, ieoffset
);
2676 /* enable the connection monitoring feature */
2677 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, true);
2682 * The join command disable the keep-alive mode, shut down its process,
2683 * and also clear the template config, so we need to reset it all after
2684 * the join. The acx_aid starts the keep-alive process, and the order
2685 * of the commands below is relevant.
2687 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, true);
2691 ret
= wl1271_acx_aid(wl
, wlvif
, wlvif
->aid
);
2695 ret
= wl12xx_cmd_build_klv_null_data(wl
, wlvif
);
2699 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
,
2700 wlvif
->sta
.klv_template_id
,
2701 ACX_KEEP_ALIVE_TPL_VALID
);
2706 * The default fw psm configuration is AUTO, while mac80211 default
2707 * setting is off (ACTIVE), so sync the fw with the correct value.
2709 ret
= wl1271_ps_set_mode(wl
, wlvif
, STATION_ACTIVE_MODE
);
2715 wl1271_tx_enabled_rates_get(wl
,
2718 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2726 static int wlcore_unset_assoc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2729 bool sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
2731 /* make sure we are connected (sta) joined */
2733 !test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2736 /* make sure we are joined (ibss) */
2738 test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED
, &wlvif
->flags
))
2742 /* use defaults when not associated */
2745 /* free probe-request template */
2746 dev_kfree_skb(wlvif
->probereq
);
2747 wlvif
->probereq
= NULL
;
2749 /* disable connection monitor features */
2750 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
2754 /* Disable the keep-alive feature */
2755 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
2760 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
)) {
2761 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
2763 wl12xx_cmd_stop_channel_switch(wl
, wlvif
);
2764 ieee80211_chswitch_done(vif
, false);
2765 cancel_delayed_work(&wlvif
->channel_switch_work
);
2768 /* invalidate keep-alive template */
2769 wl1271_acx_keep_alive_config(wl
, wlvif
,
2770 wlvif
->sta
.klv_template_id
,
2771 ACX_KEEP_ALIVE_TPL_INVALID
);
2773 /* reset TX security counters on a clean disconnect */
2774 wlvif
->tx_security_last_seq_lsb
= 0;
2775 wlvif
->tx_security_seq
= 0;
2780 static void wl1271_set_band_rate(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2782 wlvif
->basic_rate_set
= wlvif
->bitrate_masks
[wlvif
->band
];
2783 wlvif
->rate_set
= wlvif
->basic_rate_set
;
2786 static int wl12xx_config_vif(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2787 struct ieee80211_conf
*conf
, u32 changed
)
2791 if (conf
->power_level
!= wlvif
->power_level
) {
2792 ret
= wl1271_acx_tx_power(wl
, wlvif
, conf
->power_level
);
2796 wlvif
->power_level
= conf
->power_level
;
2802 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
2804 struct wl1271
*wl
= hw
->priv
;
2805 struct wl12xx_vif
*wlvif
;
2806 struct ieee80211_conf
*conf
= &hw
->conf
;
2809 wl1271_debug(DEBUG_MAC80211
, "mac80211 config psm %s power %d %s"
2811 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
2813 conf
->flags
& IEEE80211_CONF_IDLE
? "idle" : "in use",
2816 mutex_lock(&wl
->mutex
);
2818 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
2819 wl
->power_level
= conf
->power_level
;
2821 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
2824 ret
= wl1271_ps_elp_wakeup(wl
);
2828 /* configure each interface */
2829 wl12xx_for_each_wlvif(wl
, wlvif
) {
2830 ret
= wl12xx_config_vif(wl
, wlvif
, conf
, changed
);
2836 wl1271_ps_elp_sleep(wl
);
2839 mutex_unlock(&wl
->mutex
);
2844 struct wl1271_filter_params
{
2847 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
2850 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
,
2851 struct netdev_hw_addr_list
*mc_list
)
2853 struct wl1271_filter_params
*fp
;
2854 struct netdev_hw_addr
*ha
;
2856 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
2858 wl1271_error("Out of memory setting filters.");
2862 /* update multicast filtering parameters */
2863 fp
->mc_list_length
= 0;
2864 if (netdev_hw_addr_list_count(mc_list
) > ACX_MC_ADDRESS_GROUP_MAX
) {
2865 fp
->enabled
= false;
2868 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2869 memcpy(fp
->mc_list
[fp
->mc_list_length
],
2870 ha
->addr
, ETH_ALEN
);
2871 fp
->mc_list_length
++;
2875 return (u64
)(unsigned long)fp
;
2878 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2881 FIF_BCN_PRBRESP_PROMISC | \
2885 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
2886 unsigned int changed
,
2887 unsigned int *total
, u64 multicast
)
2889 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
2890 struct wl1271
*wl
= hw
->priv
;
2891 struct wl12xx_vif
*wlvif
;
2895 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter changed %x"
2896 " total %x", changed
, *total
);
2898 mutex_lock(&wl
->mutex
);
2900 *total
&= WL1271_SUPPORTED_FILTERS
;
2901 changed
&= WL1271_SUPPORTED_FILTERS
;
2903 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
2906 ret
= wl1271_ps_elp_wakeup(wl
);
2910 wl12xx_for_each_wlvif(wl
, wlvif
) {
2911 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
2912 if (*total
& FIF_ALLMULTI
)
2913 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2917 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2920 fp
->mc_list_length
);
2927 * the fw doesn't provide an api to configure the filters. instead,
2928 * the filters configuration is based on the active roles / ROC
2933 wl1271_ps_elp_sleep(wl
);
2936 mutex_unlock(&wl
->mutex
);
2940 static int wl1271_record_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2941 u8 id
, u8 key_type
, u8 key_size
,
2942 const u8
*key
, u8 hlid
, u32 tx_seq_32
,
2945 struct wl1271_ap_key
*ap_key
;
2948 wl1271_debug(DEBUG_CRYPT
, "record ap key id %d", (int)id
);
2950 if (key_size
> MAX_KEY_SIZE
)
2954 * Find next free entry in ap_keys. Also check we are not replacing
2957 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2958 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2961 if (wlvif
->ap
.recorded_keys
[i
]->id
== id
) {
2962 wl1271_warning("trying to record key replacement");
2967 if (i
== MAX_NUM_KEYS
)
2970 ap_key
= kzalloc(sizeof(*ap_key
), GFP_KERNEL
);
2975 ap_key
->key_type
= key_type
;
2976 ap_key
->key_size
= key_size
;
2977 memcpy(ap_key
->key
, key
, key_size
);
2978 ap_key
->hlid
= hlid
;
2979 ap_key
->tx_seq_32
= tx_seq_32
;
2980 ap_key
->tx_seq_16
= tx_seq_16
;
2982 wlvif
->ap
.recorded_keys
[i
] = ap_key
;
2986 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2990 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2991 kfree(wlvif
->ap
.recorded_keys
[i
]);
2992 wlvif
->ap
.recorded_keys
[i
] = NULL
;
2996 static int wl1271_ap_init_hwenc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2999 struct wl1271_ap_key
*key
;
3000 bool wep_key_added
= false;
3002 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
3004 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
3007 key
= wlvif
->ap
.recorded_keys
[i
];
3009 if (hlid
== WL12XX_INVALID_LINK_ID
)
3010 hlid
= wlvif
->ap
.bcast_hlid
;
3012 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
3013 key
->id
, key
->key_type
,
3014 key
->key_size
, key
->key
,
3015 hlid
, key
->tx_seq_32
,
3020 if (key
->key_type
== KEY_WEP
)
3021 wep_key_added
= true;
3024 if (wep_key_added
) {
3025 ret
= wl12xx_cmd_set_default_wep_key(wl
, wlvif
->default_key
,
3026 wlvif
->ap
.bcast_hlid
);
3032 wl1271_free_ap_keys(wl
, wlvif
);
3036 static int wl1271_set_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
3037 u16 action
, u8 id
, u8 key_type
,
3038 u8 key_size
, const u8
*key
, u32 tx_seq_32
,
3039 u16 tx_seq_16
, struct ieee80211_sta
*sta
)
3042 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3045 struct wl1271_station
*wl_sta
;
3049 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
3050 hlid
= wl_sta
->hlid
;
3052 hlid
= wlvif
->ap
.bcast_hlid
;
3055 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3057 * We do not support removing keys after AP shutdown.
3058 * Pretend we do to make mac80211 happy.
3060 if (action
!= KEY_ADD_OR_REPLACE
)
3063 ret
= wl1271_record_ap_key(wl
, wlvif
, id
,
3065 key
, hlid
, tx_seq_32
,
3068 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, action
,
3069 id
, key_type
, key_size
,
3070 key
, hlid
, tx_seq_32
,
3078 static const u8 bcast_addr
[ETH_ALEN
] = {
3079 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
3082 addr
= sta
? sta
->addr
: bcast_addr
;
3084 if (is_zero_ether_addr(addr
)) {
3085 /* We dont support TX only encryption */
3089 /* The wl1271 does not allow to remove unicast keys - they
3090 will be cleared automatically on next CMD_JOIN. Ignore the
3091 request silently, as we dont want the mac80211 to emit
3092 an error message. */
3093 if (action
== KEY_REMOVE
&& !is_broadcast_ether_addr(addr
))
3096 /* don't remove key if hlid was already deleted */
3097 if (action
== KEY_REMOVE
&&
3098 wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
3101 ret
= wl1271_cmd_set_sta_key(wl
, wlvif
, action
,
3102 id
, key_type
, key_size
,
3103 key
, addr
, tx_seq_32
,
3108 /* the default WEP key needs to be configured at least once */
3109 if (key_type
== KEY_WEP
) {
3110 ret
= wl12xx_cmd_set_default_wep_key(wl
,
3121 static int wlcore_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
3122 struct ieee80211_vif
*vif
,
3123 struct ieee80211_sta
*sta
,
3124 struct ieee80211_key_conf
*key_conf
)
3126 struct wl1271
*wl
= hw
->priv
;
3128 bool might_change_spare
=
3129 key_conf
->cipher
== WL1271_CIPHER_SUITE_GEM
||
3130 key_conf
->cipher
== WLAN_CIPHER_SUITE_TKIP
;
3132 if (might_change_spare
) {
3134 * stop the queues and flush to ensure the next packets are
3135 * in sync with FW spare block accounting
3137 mutex_lock(&wl
->mutex
);
3138 wlcore_stop_queues(wl
, WLCORE_QUEUE_STOP_REASON_SPARE_BLK
);
3139 mutex_unlock(&wl
->mutex
);
3141 wl1271_tx_flush(wl
);
3144 mutex_lock(&wl
->mutex
);
3146 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
3148 goto out_wake_queues
;
3151 ret
= wl1271_ps_elp_wakeup(wl
);
3153 goto out_wake_queues
;
3155 ret
= wlcore_hw_set_key(wl
, cmd
, vif
, sta
, key_conf
);
3157 wl1271_ps_elp_sleep(wl
);
3160 if (might_change_spare
)
3161 wlcore_wake_queues(wl
, WLCORE_QUEUE_STOP_REASON_SPARE_BLK
);
3163 mutex_unlock(&wl
->mutex
);
3168 int wlcore_set_key(struct wl1271
*wl
, enum set_key_cmd cmd
,
3169 struct ieee80211_vif
*vif
,
3170 struct ieee80211_sta
*sta
,
3171 struct ieee80211_key_conf
*key_conf
)
3173 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3179 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
3181 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x sta: %p", cmd
, sta
);
3182 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
3183 key_conf
->cipher
, key_conf
->keyidx
,
3184 key_conf
->keylen
, key_conf
->flags
);
3185 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
3187 switch (key_conf
->cipher
) {
3188 case WLAN_CIPHER_SUITE_WEP40
:
3189 case WLAN_CIPHER_SUITE_WEP104
:
3192 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3194 case WLAN_CIPHER_SUITE_TKIP
:
3195 key_type
= KEY_TKIP
;
3197 key_conf
->hw_key_idx
= key_conf
->keyidx
;
3198 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3199 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3201 case WLAN_CIPHER_SUITE_CCMP
:
3204 key_conf
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
3205 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3206 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3208 case WL1271_CIPHER_SUITE_GEM
:
3210 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
3211 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
3214 wl1271_error("Unknown key algo 0x%x", key_conf
->cipher
);
3221 ret
= wl1271_set_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
3222 key_conf
->keyidx
, key_type
,
3223 key_conf
->keylen
, key_conf
->key
,
3224 tx_seq_32
, tx_seq_16
, sta
);
3226 wl1271_error("Could not add or replace key");
3231 * reconfiguring arp response if the unicast (or common)
3232 * encryption key type was changed
3234 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
3235 (sta
|| key_type
== KEY_WEP
) &&
3236 wlvif
->encryption_type
!= key_type
) {
3237 wlvif
->encryption_type
= key_type
;
3238 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3240 wl1271_warning("build arp rsp failed: %d", ret
);
3247 ret
= wl1271_set_key(wl
, wlvif
, KEY_REMOVE
,
3248 key_conf
->keyidx
, key_type
,
3249 key_conf
->keylen
, key_conf
->key
,
3252 wl1271_error("Could not remove key");
3258 wl1271_error("Unsupported key cmd 0x%x", cmd
);
3264 EXPORT_SYMBOL_GPL(wlcore_set_key
);
3266 void wlcore_regdomain_config(struct wl1271
*wl
)
3270 if (!(wl
->quirks
& WLCORE_QUIRK_REGDOMAIN_CONF
))
3273 mutex_lock(&wl
->mutex
);
3274 ret
= wl1271_ps_elp_wakeup(wl
);
3278 ret
= wlcore_cmd_regdomain_config_locked(wl
);
3280 wl12xx_queue_recovery_work(wl
);
3284 wl1271_ps_elp_sleep(wl
);
3286 mutex_unlock(&wl
->mutex
);
3289 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
3290 struct ieee80211_vif
*vif
,
3291 struct cfg80211_scan_request
*req
)
3293 struct wl1271
*wl
= hw
->priv
;
3298 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
3301 ssid
= req
->ssids
[0].ssid
;
3302 len
= req
->ssids
[0].ssid_len
;
3305 mutex_lock(&wl
->mutex
);
3307 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
3309 * We cannot return -EBUSY here because cfg80211 will expect
3310 * a call to ieee80211_scan_completed if we do - in this case
3311 * there won't be any call.
3317 ret
= wl1271_ps_elp_wakeup(wl
);
3321 /* fail if there is any role in ROC */
3322 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
3323 /* don't allow scanning right now */
3328 ret
= wlcore_scan(hw
->priv
, vif
, ssid
, len
, req
);
3330 wl1271_ps_elp_sleep(wl
);
3332 mutex_unlock(&wl
->mutex
);
3337 static void wl1271_op_cancel_hw_scan(struct ieee80211_hw
*hw
,
3338 struct ieee80211_vif
*vif
)
3340 struct wl1271
*wl
= hw
->priv
;
3341 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3344 wl1271_debug(DEBUG_MAC80211
, "mac80211 cancel hw scan");
3346 mutex_lock(&wl
->mutex
);
3348 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
3351 if (wl
->scan
.state
== WL1271_SCAN_STATE_IDLE
)
3354 ret
= wl1271_ps_elp_wakeup(wl
);
3358 if (wl
->scan
.state
!= WL1271_SCAN_STATE_DONE
) {
3359 ret
= wl
->ops
->scan_stop(wl
, wlvif
);
3365 * Rearm the tx watchdog just before idling scan. This
3366 * prevents just-finished scans from triggering the watchdog
3368 wl12xx_rearm_tx_watchdog_locked(wl
);
3370 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
3371 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
3372 wl
->scan_wlvif
= NULL
;
3373 wl
->scan
.req
= NULL
;
3374 ieee80211_scan_completed(wl
->hw
, true);
3377 wl1271_ps_elp_sleep(wl
);
3379 mutex_unlock(&wl
->mutex
);
3381 cancel_delayed_work_sync(&wl
->scan_complete_work
);
3384 static int wl1271_op_sched_scan_start(struct ieee80211_hw
*hw
,
3385 struct ieee80211_vif
*vif
,
3386 struct cfg80211_sched_scan_request
*req
,
3387 struct ieee80211_sched_scan_ies
*ies
)
3389 struct wl1271
*wl
= hw
->priv
;
3390 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3393 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_start");
3395 mutex_lock(&wl
->mutex
);
3397 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
3402 ret
= wl1271_ps_elp_wakeup(wl
);
3406 ret
= wl
->ops
->sched_scan_start(wl
, wlvif
, req
, ies
);
3410 wl
->sched_vif
= wlvif
;
3413 wl1271_ps_elp_sleep(wl
);
3415 mutex_unlock(&wl
->mutex
);
3419 static void wl1271_op_sched_scan_stop(struct ieee80211_hw
*hw
,
3420 struct ieee80211_vif
*vif
)
3422 struct wl1271
*wl
= hw
->priv
;
3423 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3426 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_stop");
3428 mutex_lock(&wl
->mutex
);
3430 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
3433 ret
= wl1271_ps_elp_wakeup(wl
);
3437 wl
->ops
->sched_scan_stop(wl
, wlvif
);
3439 wl1271_ps_elp_sleep(wl
);
3441 mutex_unlock(&wl
->mutex
);
3444 static int wl1271_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3446 struct wl1271
*wl
= hw
->priv
;
3449 mutex_lock(&wl
->mutex
);
3451 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
3456 ret
= wl1271_ps_elp_wakeup(wl
);
3460 ret
= wl1271_acx_frag_threshold(wl
, value
);
3462 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret
);
3464 wl1271_ps_elp_sleep(wl
);
3467 mutex_unlock(&wl
->mutex
);
3472 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3474 struct wl1271
*wl
= hw
->priv
;
3475 struct wl12xx_vif
*wlvif
;
3478 mutex_lock(&wl
->mutex
);
3480 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
3485 ret
= wl1271_ps_elp_wakeup(wl
);
3489 wl12xx_for_each_wlvif(wl
, wlvif
) {
3490 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, value
);
3492 wl1271_warning("set rts threshold failed: %d", ret
);
3494 wl1271_ps_elp_sleep(wl
);
3497 mutex_unlock(&wl
->mutex
);
3502 static void wl12xx_remove_ie(struct sk_buff
*skb
, u8 eid
, int ieoffset
)
3505 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3506 u8
*ie
= (u8
*)cfg80211_find_ie(eid
, skb
->data
+ ieoffset
,
3507 skb
->len
- ieoffset
);
3512 memmove(ie
, next
, end
- next
);
3513 skb_trim(skb
, skb
->len
- len
);
3516 static void wl12xx_remove_vendor_ie(struct sk_buff
*skb
,
3517 unsigned int oui
, u8 oui_type
,
3521 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3522 u8
*ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
3523 skb
->data
+ ieoffset
,
3524 skb
->len
- ieoffset
);
3529 memmove(ie
, next
, end
- next
);
3530 skb_trim(skb
, skb
->len
- len
);
3533 static int wl1271_ap_set_probe_resp_tmpl(struct wl1271
*wl
, u32 rates
,
3534 struct ieee80211_vif
*vif
)
3536 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3537 struct sk_buff
*skb
;
3540 skb
= ieee80211_proberesp_get(wl
->hw
, vif
);
3544 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3545 CMD_TEMPL_AP_PROBE_RESPONSE
,
3554 wl1271_debug(DEBUG_AP
, "probe response updated");
3555 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
);
3561 static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271
*wl
,
3562 struct ieee80211_vif
*vif
,
3564 size_t probe_rsp_len
,
3567 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3568 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
3569 u8 probe_rsp_templ
[WL1271_CMD_TEMPL_MAX_SIZE
];
3570 int ssid_ie_offset
, ie_offset
, templ_len
;
3573 /* no need to change probe response if the SSID is set correctly */
3574 if (wlvif
->ssid_len
> 0)
3575 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3576 CMD_TEMPL_AP_PROBE_RESPONSE
,
3581 if (probe_rsp_len
+ bss_conf
->ssid_len
> WL1271_CMD_TEMPL_MAX_SIZE
) {
3582 wl1271_error("probe_rsp template too big");
3586 /* start searching from IE offset */
3587 ie_offset
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
3589 ptr
= cfg80211_find_ie(WLAN_EID_SSID
, probe_rsp_data
+ ie_offset
,
3590 probe_rsp_len
- ie_offset
);
3592 wl1271_error("No SSID in beacon!");
3596 ssid_ie_offset
= ptr
- probe_rsp_data
;
3597 ptr
+= (ptr
[1] + 2);
3599 memcpy(probe_rsp_templ
, probe_rsp_data
, ssid_ie_offset
);
3601 /* insert SSID from bss_conf */
3602 probe_rsp_templ
[ssid_ie_offset
] = WLAN_EID_SSID
;
3603 probe_rsp_templ
[ssid_ie_offset
+ 1] = bss_conf
->ssid_len
;
3604 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2,
3605 bss_conf
->ssid
, bss_conf
->ssid_len
);
3606 templ_len
= ssid_ie_offset
+ 2 + bss_conf
->ssid_len
;
3608 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2 + bss_conf
->ssid_len
,
3609 ptr
, probe_rsp_len
- (ptr
- probe_rsp_data
));
3610 templ_len
+= probe_rsp_len
- (ptr
- probe_rsp_data
);
3612 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3613 CMD_TEMPL_AP_PROBE_RESPONSE
,
3619 static int wl1271_bss_erp_info_changed(struct wl1271
*wl
,
3620 struct ieee80211_vif
*vif
,
3621 struct ieee80211_bss_conf
*bss_conf
,
3624 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3627 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3628 if (bss_conf
->use_short_slot
)
3629 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_SHORT
);
3631 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_LONG
);
3633 wl1271_warning("Set slot time failed %d", ret
);
3638 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3639 if (bss_conf
->use_short_preamble
)
3640 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_SHORT
);
3642 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_LONG
);
3645 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3646 if (bss_conf
->use_cts_prot
)
3647 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3650 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3651 CTSPROTECT_DISABLE
);
3653 wl1271_warning("Set ctsprotect failed %d", ret
);
3662 static int wlcore_set_beacon_template(struct wl1271
*wl
,
3663 struct ieee80211_vif
*vif
,
3666 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3667 struct ieee80211_hdr
*hdr
;
3670 int ieoffset
= offsetof(struct ieee80211_mgmt
,
3672 struct sk_buff
*beacon
= ieee80211_beacon_get(wl
->hw
, vif
);
3680 wl1271_debug(DEBUG_MASTER
, "beacon updated");
3682 ret
= wl1271_ssid_set(wlvif
, beacon
, ieoffset
);
3684 dev_kfree_skb(beacon
);
3687 min_rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3688 tmpl_id
= is_ap
? CMD_TEMPL_AP_BEACON
:
3690 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, tmpl_id
,
3695 dev_kfree_skb(beacon
);
3699 wlvif
->wmm_enabled
=
3700 cfg80211_find_vendor_ie(WLAN_OUI_MICROSOFT
,
3701 WLAN_OUI_TYPE_MICROSOFT_WMM
,
3702 beacon
->data
+ ieoffset
,
3703 beacon
->len
- ieoffset
);
3706 * In case we already have a probe-resp beacon set explicitly
3707 * by usermode, don't use the beacon data.
3709 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
))
3712 /* remove TIM ie from probe response */
3713 wl12xx_remove_ie(beacon
, WLAN_EID_TIM
, ieoffset
);
3716 * remove p2p ie from probe response.
3717 * the fw reponds to probe requests that don't include
3718 * the p2p ie. probe requests with p2p ie will be passed,
3719 * and will be responded by the supplicant (the spec
3720 * forbids including the p2p ie when responding to probe
3721 * requests that didn't include it).
3723 wl12xx_remove_vendor_ie(beacon
, WLAN_OUI_WFA
,
3724 WLAN_OUI_TYPE_WFA_P2P
, ieoffset
);
3726 hdr
= (struct ieee80211_hdr
*) beacon
->data
;
3727 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3728 IEEE80211_STYPE_PROBE_RESP
);
3730 ret
= wl1271_ap_set_probe_resp_tmpl_legacy(wl
, vif
,
3735 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3736 CMD_TEMPL_PROBE_RESPONSE
,
3741 dev_kfree_skb(beacon
);
3749 static int wl1271_bss_beacon_info_changed(struct wl1271
*wl
,
3750 struct ieee80211_vif
*vif
,
3751 struct ieee80211_bss_conf
*bss_conf
,
3754 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3755 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3758 if (changed
& BSS_CHANGED_BEACON_INT
) {
3759 wl1271_debug(DEBUG_MASTER
, "beacon interval updated: %d",
3760 bss_conf
->beacon_int
);
3762 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3765 if ((changed
& BSS_CHANGED_AP_PROBE_RESP
) && is_ap
) {
3766 u32 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3768 wl1271_ap_set_probe_resp_tmpl(wl
, rate
, vif
);
3771 if (changed
& BSS_CHANGED_BEACON
) {
3772 ret
= wlcore_set_beacon_template(wl
, vif
, is_ap
);
3779 wl1271_error("beacon info change failed: %d", ret
);
3783 /* AP mode changes */
3784 static void wl1271_bss_info_changed_ap(struct wl1271
*wl
,
3785 struct ieee80211_vif
*vif
,
3786 struct ieee80211_bss_conf
*bss_conf
,
3789 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3792 if (changed
& BSS_CHANGED_BASIC_RATES
) {
3793 u32 rates
= bss_conf
->basic_rates
;
3795 wlvif
->basic_rate_set
= wl1271_tx_enabled_rates_get(wl
, rates
,
3797 wlvif
->basic_rate
= wl1271_tx_min_rate_get(wl
,
3798 wlvif
->basic_rate_set
);
3800 ret
= wl1271_init_ap_rates(wl
, wlvif
);
3802 wl1271_error("AP rate policy change failed %d", ret
);
3806 ret
= wl1271_ap_init_templates(wl
, vif
);
3810 ret
= wl1271_ap_set_probe_resp_tmpl(wl
, wlvif
->basic_rate
, vif
);
3814 ret
= wlcore_set_beacon_template(wl
, vif
, true);
3819 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
, changed
);
3823 if (changed
& BSS_CHANGED_BEACON_ENABLED
) {
3824 if (bss_conf
->enable_beacon
) {
3825 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3826 ret
= wl12xx_cmd_role_start_ap(wl
, wlvif
);
3830 ret
= wl1271_ap_init_hwenc(wl
, wlvif
);
3834 set_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3835 wl1271_debug(DEBUG_AP
, "started AP");
3838 if (test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3839 ret
= wl12xx_cmd_role_stop_ap(wl
, wlvif
);
3843 clear_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3844 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
,
3846 wl1271_debug(DEBUG_AP
, "stopped AP");
3851 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3855 /* Handle HT information change */
3856 if ((changed
& BSS_CHANGED_HT
) &&
3857 (bss_conf
->chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
)) {
3858 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3859 bss_conf
->ht_operation_mode
);
3861 wl1271_warning("Set ht information failed %d", ret
);
3870 static int wlcore_set_bssid(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
3871 struct ieee80211_bss_conf
*bss_conf
,
3877 wl1271_debug(DEBUG_MAC80211
,
3878 "changed_bssid: %pM, aid: %d, bcn_int: %d, brates: 0x%x sta_rate_set: 0x%x",
3879 bss_conf
->bssid
, bss_conf
->aid
,
3880 bss_conf
->beacon_int
,
3881 bss_conf
->basic_rates
, sta_rate_set
);
3883 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3884 rates
= bss_conf
->basic_rates
;
3885 wlvif
->basic_rate_set
=
3886 wl1271_tx_enabled_rates_get(wl
, rates
,
3889 wl1271_tx_min_rate_get(wl
,
3890 wlvif
->basic_rate_set
);
3894 wl1271_tx_enabled_rates_get(wl
,
3898 /* we only support sched_scan while not connected */
3899 if (wl
->sched_vif
== wlvif
)
3900 wl
->ops
->sched_scan_stop(wl
, wlvif
);
3902 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3906 ret
= wl12xx_cmd_build_null_data(wl
, wlvif
);
3910 ret
= wl1271_build_qos_null_data(wl
, wl12xx_wlvif_to_vif(wlvif
));
3914 wlcore_set_ssid(wl
, wlvif
);
3916 set_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
3921 static int wlcore_clear_bssid(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
3925 /* revert back to minimum rates for the current band */
3926 wl1271_set_band_rate(wl
, wlvif
);
3927 wlvif
->basic_rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3929 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3933 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
3934 test_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
)) {
3935 ret
= wl12xx_cmd_role_stop_sta(wl
, wlvif
);
3940 clear_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
3943 /* STA/IBSS mode changes */
3944 static void wl1271_bss_info_changed_sta(struct wl1271
*wl
,
3945 struct ieee80211_vif
*vif
,
3946 struct ieee80211_bss_conf
*bss_conf
,
3949 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3950 bool do_join
= false;
3951 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
3952 bool ibss_joined
= false;
3953 u32 sta_rate_set
= 0;
3955 struct ieee80211_sta
*sta
;
3956 bool sta_exists
= false;
3957 struct ieee80211_sta_ht_cap sta_ht_cap
;
3960 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
,
3966 if (changed
& BSS_CHANGED_IBSS
) {
3967 if (bss_conf
->ibss_joined
) {
3968 set_bit(WLVIF_FLAG_IBSS_JOINED
, &wlvif
->flags
);
3971 wlcore_unset_assoc(wl
, wlvif
);
3972 wl12xx_cmd_role_stop_sta(wl
, wlvif
);
3976 if ((changed
& BSS_CHANGED_BEACON_INT
) && ibss_joined
)
3979 /* Need to update the SSID (for filtering etc) */
3980 if ((changed
& BSS_CHANGED_BEACON
) && ibss_joined
)
3983 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && ibss_joined
) {
3984 wl1271_debug(DEBUG_ADHOC
, "ad-hoc beaconing: %s",
3985 bss_conf
->enable_beacon
? "enabled" : "disabled");
3990 if (changed
& BSS_CHANGED_CQM
) {
3991 bool enable
= false;
3992 if (bss_conf
->cqm_rssi_thold
)
3994 ret
= wl1271_acx_rssi_snr_trigger(wl
, wlvif
, enable
,
3995 bss_conf
->cqm_rssi_thold
,
3996 bss_conf
->cqm_rssi_hyst
);
3999 wlvif
->rssi_thold
= bss_conf
->cqm_rssi_thold
;
4002 if (changed
& (BSS_CHANGED_BSSID
| BSS_CHANGED_HT
|
4003 BSS_CHANGED_ASSOC
)) {
4005 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
4007 u8
*rx_mask
= sta
->ht_cap
.mcs
.rx_mask
;
4009 /* save the supp_rates of the ap */
4010 sta_rate_set
= sta
->supp_rates
[wlvif
->band
];
4011 if (sta
->ht_cap
.ht_supported
)
4013 (rx_mask
[0] << HW_HT_RATES_OFFSET
) |
4014 (rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
4015 sta_ht_cap
= sta
->ht_cap
;
4022 if (changed
& BSS_CHANGED_BSSID
) {
4023 if (!is_zero_ether_addr(bss_conf
->bssid
)) {
4024 ret
= wlcore_set_bssid(wl
, wlvif
, bss_conf
,
4029 /* Need to update the BSSID (for filtering etc) */
4032 ret
= wlcore_clear_bssid(wl
, wlvif
);
4038 if (changed
& BSS_CHANGED_IBSS
) {
4039 wl1271_debug(DEBUG_ADHOC
, "ibss_joined: %d",
4040 bss_conf
->ibss_joined
);
4042 if (bss_conf
->ibss_joined
) {
4043 u32 rates
= bss_conf
->basic_rates
;
4044 wlvif
->basic_rate_set
=
4045 wl1271_tx_enabled_rates_get(wl
, rates
,
4048 wl1271_tx_min_rate_get(wl
,
4049 wlvif
->basic_rate_set
);
4051 /* by default, use 11b + OFDM rates */
4052 wlvif
->rate_set
= CONF_TX_IBSS_DEFAULT_RATES
;
4053 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
4059 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
4064 ret
= wlcore_join(wl
, wlvif
);
4066 wl1271_warning("cmd join failed %d", ret
);
4071 if (changed
& BSS_CHANGED_ASSOC
) {
4072 if (bss_conf
->assoc
) {
4073 ret
= wlcore_set_assoc(wl
, wlvif
, bss_conf
,
4078 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
))
4079 wl12xx_set_authorized(wl
, wlvif
);
4081 wlcore_unset_assoc(wl
, wlvif
);
4085 if (changed
& BSS_CHANGED_PS
) {
4086 if ((bss_conf
->ps
) &&
4087 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
4088 !test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
4092 if (wl
->conf
.conn
.forced_ps
) {
4093 ps_mode
= STATION_POWER_SAVE_MODE
;
4094 ps_mode_str
= "forced";
4096 ps_mode
= STATION_AUTO_PS_MODE
;
4097 ps_mode_str
= "auto";
4100 wl1271_debug(DEBUG_PSM
, "%s ps enabled", ps_mode_str
);
4102 ret
= wl1271_ps_set_mode(wl
, wlvif
, ps_mode
);
4104 wl1271_warning("enter %s ps failed %d",
4106 } else if (!bss_conf
->ps
&&
4107 test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
4108 wl1271_debug(DEBUG_PSM
, "auto ps disabled");
4110 ret
= wl1271_ps_set_mode(wl
, wlvif
,
4111 STATION_ACTIVE_MODE
);
4113 wl1271_warning("exit auto ps failed %d", ret
);
4117 /* Handle new association with HT. Do this after join. */
4119 (changed
& BSS_CHANGED_HT
)) {
4121 bss_conf
->chandef
.width
!= NL80211_CHAN_WIDTH_20_NOHT
;
4123 ret
= wl1271_acx_set_ht_capabilities(wl
,
4128 wl1271_warning("Set ht cap failed %d", ret
);
4134 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
4135 bss_conf
->ht_operation_mode
);
4137 wl1271_warning("Set ht information failed %d",
4144 /* Handle arp filtering. Done after join. */
4145 if ((changed
& BSS_CHANGED_ARP_FILTER
) ||
4146 (!is_ibss
&& (changed
& BSS_CHANGED_QOS
))) {
4147 __be32 addr
= bss_conf
->arp_addr_list
[0];
4148 wlvif
->sta
.qos
= bss_conf
->qos
;
4149 WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
);
4151 if (bss_conf
->arp_addr_cnt
== 1 &&
4152 bss_conf
->arp_filter_enabled
) {
4153 wlvif
->ip_addr
= addr
;
4155 * The template should have been configured only upon
4156 * association. however, it seems that the correct ip
4157 * isn't being set (when sending), so we have to
4158 * reconfigure the template upon every ip change.
4160 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
4162 wl1271_warning("build arp rsp failed: %d", ret
);
4166 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
,
4167 (ACX_ARP_FILTER_ARP_FILTERING
|
4168 ACX_ARP_FILTER_AUTO_ARP
),
4172 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
, 0, addr
);
4183 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
4184 struct ieee80211_vif
*vif
,
4185 struct ieee80211_bss_conf
*bss_conf
,
4188 struct wl1271
*wl
= hw
->priv
;
4189 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4190 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
4193 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info role %d changed 0x%x",
4194 wlvif
->role_id
, (int)changed
);
4197 * make sure to cancel pending disconnections if our association
4200 if (!is_ap
&& (changed
& BSS_CHANGED_ASSOC
))
4201 cancel_delayed_work_sync(&wlvif
->connection_loss_work
);
4203 if (is_ap
&& (changed
& BSS_CHANGED_BEACON_ENABLED
) &&
4204 !bss_conf
->enable_beacon
)
4205 wl1271_tx_flush(wl
);
4207 mutex_lock(&wl
->mutex
);
4209 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
4212 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)))
4215 ret
= wl1271_ps_elp_wakeup(wl
);
4220 wl1271_bss_info_changed_ap(wl
, vif
, bss_conf
, changed
);
4222 wl1271_bss_info_changed_sta(wl
, vif
, bss_conf
, changed
);
4224 wl1271_ps_elp_sleep(wl
);
4227 mutex_unlock(&wl
->mutex
);
4230 static int wlcore_op_add_chanctx(struct ieee80211_hw
*hw
,
4231 struct ieee80211_chanctx_conf
*ctx
)
4233 wl1271_debug(DEBUG_MAC80211
, "mac80211 add chanctx %d (type %d)",
4234 ieee80211_frequency_to_channel(ctx
->def
.chan
->center_freq
),
4235 cfg80211_get_chandef_type(&ctx
->def
));
4239 static void wlcore_op_remove_chanctx(struct ieee80211_hw
*hw
,
4240 struct ieee80211_chanctx_conf
*ctx
)
4242 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove chanctx %d (type %d)",
4243 ieee80211_frequency_to_channel(ctx
->def
.chan
->center_freq
),
4244 cfg80211_get_chandef_type(&ctx
->def
));
4247 static void wlcore_op_change_chanctx(struct ieee80211_hw
*hw
,
4248 struct ieee80211_chanctx_conf
*ctx
,
4251 wl1271_debug(DEBUG_MAC80211
,
4252 "mac80211 change chanctx %d (type %d) changed 0x%x",
4253 ieee80211_frequency_to_channel(ctx
->def
.chan
->center_freq
),
4254 cfg80211_get_chandef_type(&ctx
->def
), changed
);
4257 static int wlcore_op_assign_vif_chanctx(struct ieee80211_hw
*hw
,
4258 struct ieee80211_vif
*vif
,
4259 struct ieee80211_chanctx_conf
*ctx
)
4261 struct wl1271
*wl
= hw
->priv
;
4262 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4263 int channel
= ieee80211_frequency_to_channel(
4264 ctx
->def
.chan
->center_freq
);
4266 wl1271_debug(DEBUG_MAC80211
,
4267 "mac80211 assign chanctx (role %d) %d (type %d)",
4268 wlvif
->role_id
, channel
, cfg80211_get_chandef_type(&ctx
->def
));
4270 mutex_lock(&wl
->mutex
);
4272 wlvif
->band
= ctx
->def
.chan
->band
;
4273 wlvif
->channel
= channel
;
4274 wlvif
->channel_type
= cfg80211_get_chandef_type(&ctx
->def
);
4276 /* update default rates according to the band */
4277 wl1271_set_band_rate(wl
, wlvif
);
4279 mutex_unlock(&wl
->mutex
);
4284 static void wlcore_op_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
4285 struct ieee80211_vif
*vif
,
4286 struct ieee80211_chanctx_conf
*ctx
)
4288 struct wl1271
*wl
= hw
->priv
;
4289 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4291 wl1271_debug(DEBUG_MAC80211
,
4292 "mac80211 unassign chanctx (role %d) %d (type %d)",
4294 ieee80211_frequency_to_channel(ctx
->def
.chan
->center_freq
),
4295 cfg80211_get_chandef_type(&ctx
->def
));
4297 wl1271_tx_flush(wl
);
4300 static int wl1271_op_conf_tx(struct ieee80211_hw
*hw
,
4301 struct ieee80211_vif
*vif
, u16 queue
,
4302 const struct ieee80211_tx_queue_params
*params
)
4304 struct wl1271
*wl
= hw
->priv
;
4305 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4309 mutex_lock(&wl
->mutex
);
4311 wl1271_debug(DEBUG_MAC80211
, "mac80211 conf tx %d", queue
);
4314 ps_scheme
= CONF_PS_SCHEME_UPSD_TRIGGER
;
4316 ps_scheme
= CONF_PS_SCHEME_LEGACY
;
4318 if (!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
4321 ret
= wl1271_ps_elp_wakeup(wl
);
4326 * the txop is confed in units of 32us by the mac80211,
4329 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4330 params
->cw_min
, params
->cw_max
,
4331 params
->aifs
, params
->txop
<< 5);
4335 ret
= wl1271_acx_tid_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4336 CONF_CHANNEL_TYPE_EDCF
,
4337 wl1271_tx_get_queue(queue
),
4338 ps_scheme
, CONF_ACK_POLICY_LEGACY
,
4342 wl1271_ps_elp_sleep(wl
);
4345 mutex_unlock(&wl
->mutex
);
4350 static u64
wl1271_op_get_tsf(struct ieee80211_hw
*hw
,
4351 struct ieee80211_vif
*vif
)
4354 struct wl1271
*wl
= hw
->priv
;
4355 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4356 u64 mactime
= ULLONG_MAX
;
4359 wl1271_debug(DEBUG_MAC80211
, "mac80211 get tsf");
4361 mutex_lock(&wl
->mutex
);
4363 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
4366 ret
= wl1271_ps_elp_wakeup(wl
);
4370 ret
= wl12xx_acx_tsf_info(wl
, wlvif
, &mactime
);
4375 wl1271_ps_elp_sleep(wl
);
4378 mutex_unlock(&wl
->mutex
);
4382 static int wl1271_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
4383 struct survey_info
*survey
)
4385 struct ieee80211_conf
*conf
= &hw
->conf
;
4390 survey
->channel
= conf
->channel
;
4395 static int wl1271_allocate_sta(struct wl1271
*wl
,
4396 struct wl12xx_vif
*wlvif
,
4397 struct ieee80211_sta
*sta
)
4399 struct wl1271_station
*wl_sta
;
4403 if (wl
->active_sta_count
>= AP_MAX_STATIONS
) {
4404 wl1271_warning("could not allocate HLID - too much stations");
4408 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4409 ret
= wl12xx_allocate_link(wl
, wlvif
, &wl_sta
->hlid
);
4411 wl1271_warning("could not allocate HLID - too many links");
4415 set_bit(wl_sta
->hlid
, wlvif
->ap
.sta_hlid_map
);
4416 memcpy(wl
->links
[wl_sta
->hlid
].addr
, sta
->addr
, ETH_ALEN
);
4417 wl
->active_sta_count
++;
4421 void wl1271_free_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 hlid
)
4423 if (!test_bit(hlid
, wlvif
->ap
.sta_hlid_map
))
4426 clear_bit(hlid
, wlvif
->ap
.sta_hlid_map
);
4427 memset(wl
->links
[hlid
].addr
, 0, ETH_ALEN
);
4428 wl
->links
[hlid
].ba_bitmap
= 0;
4429 __clear_bit(hlid
, &wl
->ap_ps_map
);
4430 __clear_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
4431 wl12xx_free_link(wl
, wlvif
, &hlid
);
4432 wl
->active_sta_count
--;
4435 * rearm the tx watchdog when the last STA is freed - give the FW a
4436 * chance to return STA-buffered packets before complaining.
4438 if (wl
->active_sta_count
== 0)
4439 wl12xx_rearm_tx_watchdog_locked(wl
);
4442 static int wl12xx_sta_add(struct wl1271
*wl
,
4443 struct wl12xx_vif
*wlvif
,
4444 struct ieee80211_sta
*sta
)
4446 struct wl1271_station
*wl_sta
;
4450 wl1271_debug(DEBUG_MAC80211
, "mac80211 add sta %d", (int)sta
->aid
);
4452 ret
= wl1271_allocate_sta(wl
, wlvif
, sta
);
4456 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4457 hlid
= wl_sta
->hlid
;
4459 ret
= wl12xx_cmd_add_peer(wl
, wlvif
, sta
, hlid
);
4461 wl1271_free_sta(wl
, wlvif
, hlid
);
4466 static int wl12xx_sta_remove(struct wl1271
*wl
,
4467 struct wl12xx_vif
*wlvif
,
4468 struct ieee80211_sta
*sta
)
4470 struct wl1271_station
*wl_sta
;
4473 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove sta %d", (int)sta
->aid
);
4475 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4477 if (WARN_ON(!test_bit(id
, wlvif
->ap
.sta_hlid_map
)))
4480 ret
= wl12xx_cmd_remove_peer(wl
, wl_sta
->hlid
);
4484 wl1271_free_sta(wl
, wlvif
, wl_sta
->hlid
);
4488 static void wlcore_roc_if_possible(struct wl1271
*wl
,
4489 struct wl12xx_vif
*wlvif
)
4491 if (find_first_bit(wl
->roc_map
,
4492 WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
)
4495 if (WARN_ON(wlvif
->role_id
== WL12XX_INVALID_ROLE_ID
))
4498 wl12xx_roc(wl
, wlvif
, wlvif
->role_id
, wlvif
->band
, wlvif
->channel
);
4501 static void wlcore_update_inconn_sta(struct wl1271
*wl
,
4502 struct wl12xx_vif
*wlvif
,
4503 struct wl1271_station
*wl_sta
,
4506 if (in_connection
) {
4507 if (WARN_ON(wl_sta
->in_connection
))
4509 wl_sta
->in_connection
= true;
4510 if (!wlvif
->inconn_count
++)
4511 wlcore_roc_if_possible(wl
, wlvif
);
4513 if (!wl_sta
->in_connection
)
4516 wl_sta
->in_connection
= false;
4517 wlvif
->inconn_count
--;
4518 if (WARN_ON(wlvif
->inconn_count
< 0))
4521 if (!wlvif
->inconn_count
)
4522 if (test_bit(wlvif
->role_id
, wl
->roc_map
))
4523 wl12xx_croc(wl
, wlvif
->role_id
);
4527 static int wl12xx_update_sta_state(struct wl1271
*wl
,
4528 struct wl12xx_vif
*wlvif
,
4529 struct ieee80211_sta
*sta
,
4530 enum ieee80211_sta_state old_state
,
4531 enum ieee80211_sta_state new_state
)
4533 struct wl1271_station
*wl_sta
;
4535 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
4536 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
4539 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4540 hlid
= wl_sta
->hlid
;
4542 /* Add station (AP mode) */
4544 old_state
== IEEE80211_STA_NOTEXIST
&&
4545 new_state
== IEEE80211_STA_NONE
) {
4546 ret
= wl12xx_sta_add(wl
, wlvif
, sta
);
4550 wlcore_update_inconn_sta(wl
, wlvif
, wl_sta
, true);
4553 /* Remove station (AP mode) */
4555 old_state
== IEEE80211_STA_NONE
&&
4556 new_state
== IEEE80211_STA_NOTEXIST
) {
4558 wl12xx_sta_remove(wl
, wlvif
, sta
);
4560 wlcore_update_inconn_sta(wl
, wlvif
, wl_sta
, false);
4563 /* Authorize station (AP mode) */
4565 new_state
== IEEE80211_STA_AUTHORIZED
) {
4566 ret
= wl12xx_cmd_set_peer_state(wl
, wlvif
, hlid
);
4570 ret
= wl1271_acx_set_ht_capabilities(wl
, &sta
->ht_cap
, true,
4575 wlcore_update_inconn_sta(wl
, wlvif
, wl_sta
, false);
4578 /* Authorize station */
4580 new_state
== IEEE80211_STA_AUTHORIZED
) {
4581 set_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4582 ret
= wl12xx_set_authorized(wl
, wlvif
);
4588 old_state
== IEEE80211_STA_AUTHORIZED
&&
4589 new_state
== IEEE80211_STA_ASSOC
) {
4590 clear_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4591 clear_bit(WLVIF_FLAG_STA_STATE_SENT
, &wlvif
->flags
);
4594 /* clear ROCs on failure or authorization */
4596 (new_state
== IEEE80211_STA_AUTHORIZED
||
4597 new_state
== IEEE80211_STA_NOTEXIST
)) {
4598 if (test_bit(wlvif
->role_id
, wl
->roc_map
))
4599 wl12xx_croc(wl
, wlvif
->role_id
);
4603 old_state
== IEEE80211_STA_NOTEXIST
&&
4604 new_state
== IEEE80211_STA_NONE
) {
4605 if (find_first_bit(wl
->roc_map
,
4606 WL12XX_MAX_ROLES
) >= WL12XX_MAX_ROLES
) {
4607 WARN_ON(wlvif
->role_id
== WL12XX_INVALID_ROLE_ID
);
4608 wl12xx_roc(wl
, wlvif
, wlvif
->role_id
,
4609 wlvif
->band
, wlvif
->channel
);
4615 static int wl12xx_op_sta_state(struct ieee80211_hw
*hw
,
4616 struct ieee80211_vif
*vif
,
4617 struct ieee80211_sta
*sta
,
4618 enum ieee80211_sta_state old_state
,
4619 enum ieee80211_sta_state new_state
)
4621 struct wl1271
*wl
= hw
->priv
;
4622 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4625 wl1271_debug(DEBUG_MAC80211
, "mac80211 sta %d state=%d->%d",
4626 sta
->aid
, old_state
, new_state
);
4628 mutex_lock(&wl
->mutex
);
4630 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
4635 ret
= wl1271_ps_elp_wakeup(wl
);
4639 ret
= wl12xx_update_sta_state(wl
, wlvif
, sta
, old_state
, new_state
);
4641 wl1271_ps_elp_sleep(wl
);
4643 mutex_unlock(&wl
->mutex
);
4644 if (new_state
< old_state
)
4649 static int wl1271_op_ampdu_action(struct ieee80211_hw
*hw
,
4650 struct ieee80211_vif
*vif
,
4651 enum ieee80211_ampdu_mlme_action action
,
4652 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4655 struct wl1271
*wl
= hw
->priv
;
4656 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4658 u8 hlid
, *ba_bitmap
;
4660 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu action %d tid %d", action
,
4663 /* sanity check - the fields in FW are only 8bits wide */
4664 if (WARN_ON(tid
> 0xFF))
4667 mutex_lock(&wl
->mutex
);
4669 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
4674 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
) {
4675 hlid
= wlvif
->sta
.hlid
;
4676 ba_bitmap
= &wlvif
->sta
.ba_rx_bitmap
;
4677 } else if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
) {
4678 struct wl1271_station
*wl_sta
;
4680 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4681 hlid
= wl_sta
->hlid
;
4682 ba_bitmap
= &wl
->links
[hlid
].ba_bitmap
;
4688 ret
= wl1271_ps_elp_wakeup(wl
);
4692 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu: Rx tid %d action %d",
4696 case IEEE80211_AMPDU_RX_START
:
4697 if (!wlvif
->ba_support
|| !wlvif
->ba_allowed
) {
4702 if (wl
->ba_rx_session_count
>= RX_BA_MAX_SESSIONS
) {
4704 wl1271_error("exceeded max RX BA sessions");
4708 if (*ba_bitmap
& BIT(tid
)) {
4710 wl1271_error("cannot enable RX BA session on active "
4715 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, *ssn
, true,
4718 *ba_bitmap
|= BIT(tid
);
4719 wl
->ba_rx_session_count
++;
4723 case IEEE80211_AMPDU_RX_STOP
:
4724 if (!(*ba_bitmap
& BIT(tid
))) {
4726 * this happens on reconfig - so only output a debug
4727 * message for now, and don't fail the function.
4729 wl1271_debug(DEBUG_MAC80211
,
4730 "no active RX BA session on tid: %d",
4736 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, 0, false,
4739 *ba_bitmap
&= ~BIT(tid
);
4740 wl
->ba_rx_session_count
--;
4745 * The BA initiator session management in FW independently.
4746 * Falling break here on purpose for all TX APDU commands.
4748 case IEEE80211_AMPDU_TX_START
:
4749 case IEEE80211_AMPDU_TX_STOP
:
4750 case IEEE80211_AMPDU_TX_OPERATIONAL
:
4755 wl1271_error("Incorrect ampdu action id=%x\n", action
);
4759 wl1271_ps_elp_sleep(wl
);
4762 mutex_unlock(&wl
->mutex
);
4767 static int wl12xx_set_bitrate_mask(struct ieee80211_hw
*hw
,
4768 struct ieee80211_vif
*vif
,
4769 const struct cfg80211_bitrate_mask
*mask
)
4771 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4772 struct wl1271
*wl
= hw
->priv
;
4775 wl1271_debug(DEBUG_MAC80211
, "mac80211 set_bitrate_mask 0x%x 0x%x",
4776 mask
->control
[NL80211_BAND_2GHZ
].legacy
,
4777 mask
->control
[NL80211_BAND_5GHZ
].legacy
);
4779 mutex_lock(&wl
->mutex
);
4781 for (i
= 0; i
< WLCORE_NUM_BANDS
; i
++)
4782 wlvif
->bitrate_masks
[i
] =
4783 wl1271_tx_enabled_rates_get(wl
,
4784 mask
->control
[i
].legacy
,
4787 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
4790 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
4791 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
)) {
4793 ret
= wl1271_ps_elp_wakeup(wl
);
4797 wl1271_set_band_rate(wl
, wlvif
);
4799 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
4800 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
4802 wl1271_ps_elp_sleep(wl
);
4805 mutex_unlock(&wl
->mutex
);
4810 static void wl12xx_op_channel_switch(struct ieee80211_hw
*hw
,
4811 struct ieee80211_channel_switch
*ch_switch
)
4813 struct wl1271
*wl
= hw
->priv
;
4814 struct wl12xx_vif
*wlvif
;
4817 wl1271_debug(DEBUG_MAC80211
, "mac80211 channel switch");
4819 wl1271_tx_flush(wl
);
4821 mutex_lock(&wl
->mutex
);
4823 if (unlikely(wl
->state
== WLCORE_STATE_OFF
)) {
4824 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4825 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
4826 ieee80211_chswitch_done(vif
, false);
4829 } else if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
4833 ret
= wl1271_ps_elp_wakeup(wl
);
4837 /* TODO: change mac80211 to pass vif as param */
4838 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4839 unsigned long delay_usec
;
4841 ret
= wl
->ops
->channel_switch(wl
, wlvif
, ch_switch
);
4845 set_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
);
4847 /* indicate failure 5 seconds after channel switch time */
4848 delay_usec
= ieee80211_tu_to_usec(wlvif
->beacon_int
) *
4850 ieee80211_queue_delayed_work(hw
, &wlvif
->channel_switch_work
,
4851 usecs_to_jiffies(delay_usec
) +
4852 msecs_to_jiffies(5000));
4856 wl1271_ps_elp_sleep(wl
);
4859 mutex_unlock(&wl
->mutex
);
4862 static void wlcore_op_flush(struct ieee80211_hw
*hw
, bool drop
)
4864 struct wl1271
*wl
= hw
->priv
;
4866 wl1271_tx_flush(wl
);
4869 static int wlcore_op_remain_on_channel(struct ieee80211_hw
*hw
,
4870 struct ieee80211_vif
*vif
,
4871 struct ieee80211_channel
*chan
,
4874 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4875 struct wl1271
*wl
= hw
->priv
;
4876 int channel
, ret
= 0;
4878 channel
= ieee80211_frequency_to_channel(chan
->center_freq
);
4880 wl1271_debug(DEBUG_MAC80211
, "mac80211 roc %d (%d)",
4881 channel
, wlvif
->role_id
);
4883 mutex_lock(&wl
->mutex
);
4885 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
4888 /* return EBUSY if we can't ROC right now */
4889 if (WARN_ON(wl
->roc_vif
||
4890 find_first_bit(wl
->roc_map
,
4891 WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
)) {
4896 ret
= wl1271_ps_elp_wakeup(wl
);
4900 ret
= wl12xx_start_dev(wl
, wlvif
, chan
->band
, channel
);
4905 ieee80211_queue_delayed_work(hw
, &wl
->roc_complete_work
,
4906 msecs_to_jiffies(duration
));
4908 wl1271_ps_elp_sleep(wl
);
4910 mutex_unlock(&wl
->mutex
);
4914 static int __wlcore_roc_completed(struct wl1271
*wl
)
4916 struct wl12xx_vif
*wlvif
;
4919 /* already completed */
4920 if (unlikely(!wl
->roc_vif
))
4923 wlvif
= wl12xx_vif_to_data(wl
->roc_vif
);
4925 if (!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
4928 ret
= wl12xx_stop_dev(wl
, wlvif
);
4937 static int wlcore_roc_completed(struct wl1271
*wl
)
4941 wl1271_debug(DEBUG_MAC80211
, "roc complete");
4943 mutex_lock(&wl
->mutex
);
4945 if (unlikely(wl
->state
!= WLCORE_STATE_ON
)) {
4950 ret
= wl1271_ps_elp_wakeup(wl
);
4954 ret
= __wlcore_roc_completed(wl
);
4956 wl1271_ps_elp_sleep(wl
);
4958 mutex_unlock(&wl
->mutex
);
4963 static void wlcore_roc_complete_work(struct work_struct
*work
)
4965 struct delayed_work
*dwork
;
4969 dwork
= container_of(work
, struct delayed_work
, work
);
4970 wl
= container_of(dwork
, struct wl1271
, roc_complete_work
);
4972 ret
= wlcore_roc_completed(wl
);
4974 ieee80211_remain_on_channel_expired(wl
->hw
);
4977 static int wlcore_op_cancel_remain_on_channel(struct ieee80211_hw
*hw
)
4979 struct wl1271
*wl
= hw
->priv
;
4981 wl1271_debug(DEBUG_MAC80211
, "mac80211 croc");
4984 wl1271_tx_flush(wl
);
4987 * we can't just flush_work here, because it might deadlock
4988 * (as we might get called from the same workqueue)
4990 cancel_delayed_work_sync(&wl
->roc_complete_work
);
4991 wlcore_roc_completed(wl
);
4996 static void wlcore_op_sta_rc_update(struct ieee80211_hw
*hw
,
4997 struct ieee80211_vif
*vif
,
4998 struct ieee80211_sta
*sta
,
5001 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
5002 struct wl1271
*wl
= hw
->priv
;
5004 wlcore_hw_sta_rc_update(wl
, wlvif
, sta
, changed
);
5007 static bool wl1271_tx_frames_pending(struct ieee80211_hw
*hw
)
5009 struct wl1271
*wl
= hw
->priv
;
5012 mutex_lock(&wl
->mutex
);
5014 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
5017 /* packets are considered pending if in the TX queue or the FW */
5018 ret
= (wl1271_tx_total_queue_count(wl
) > 0) || (wl
->tx_frames_cnt
> 0);
5020 mutex_unlock(&wl
->mutex
);
5025 /* can't be const, mac80211 writes to this */
5026 static struct ieee80211_rate wl1271_rates
[] = {
5028 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
5029 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
5031 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
5032 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
5033 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
5035 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
5036 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
5037 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
5039 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
5040 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
5041 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
5043 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
5044 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
5046 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
5047 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
5049 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
5050 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
5052 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
5053 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
5055 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
5056 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
5058 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
5059 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
5061 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
5062 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
5064 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
5065 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
5068 /* can't be const, mac80211 writes to this */
5069 static struct ieee80211_channel wl1271_channels
[] = {
5070 { .hw_value
= 1, .center_freq
= 2412, .max_power
= 25 },
5071 { .hw_value
= 2, .center_freq
= 2417, .max_power
= 25 },
5072 { .hw_value
= 3, .center_freq
= 2422, .max_power
= 25 },
5073 { .hw_value
= 4, .center_freq
= 2427, .max_power
= 25 },
5074 { .hw_value
= 5, .center_freq
= 2432, .max_power
= 25 },
5075 { .hw_value
= 6, .center_freq
= 2437, .max_power
= 25 },
5076 { .hw_value
= 7, .center_freq
= 2442, .max_power
= 25 },
5077 { .hw_value
= 8, .center_freq
= 2447, .max_power
= 25 },
5078 { .hw_value
= 9, .center_freq
= 2452, .max_power
= 25 },
5079 { .hw_value
= 10, .center_freq
= 2457, .max_power
= 25 },
5080 { .hw_value
= 11, .center_freq
= 2462, .max_power
= 25 },
5081 { .hw_value
= 12, .center_freq
= 2467, .max_power
= 25 },
5082 { .hw_value
= 13, .center_freq
= 2472, .max_power
= 25 },
5083 { .hw_value
= 14, .center_freq
= 2484, .max_power
= 25 },
5086 /* can't be const, mac80211 writes to this */
5087 static struct ieee80211_supported_band wl1271_band_2ghz
= {
5088 .channels
= wl1271_channels
,
5089 .n_channels
= ARRAY_SIZE(wl1271_channels
),
5090 .bitrates
= wl1271_rates
,
5091 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
5094 /* 5 GHz data rates for WL1273 */
5095 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
5097 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
5098 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
5100 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
5101 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
5103 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
5104 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
5106 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
5107 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
5109 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
5110 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
5112 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
5113 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
5115 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
5116 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
5118 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
5119 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
5122 /* 5 GHz band channels for WL1273 */
5123 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
5124 { .hw_value
= 7, .center_freq
= 5035, .max_power
= 25 },
5125 { .hw_value
= 8, .center_freq
= 5040, .max_power
= 25 },
5126 { .hw_value
= 9, .center_freq
= 5045, .max_power
= 25 },
5127 { .hw_value
= 11, .center_freq
= 5055, .max_power
= 25 },
5128 { .hw_value
= 12, .center_freq
= 5060, .max_power
= 25 },
5129 { .hw_value
= 16, .center_freq
= 5080, .max_power
= 25 },
5130 { .hw_value
= 34, .center_freq
= 5170, .max_power
= 25 },
5131 { .hw_value
= 36, .center_freq
= 5180, .max_power
= 25 },
5132 { .hw_value
= 38, .center_freq
= 5190, .max_power
= 25 },
5133 { .hw_value
= 40, .center_freq
= 5200, .max_power
= 25 },
5134 { .hw_value
= 42, .center_freq
= 5210, .max_power
= 25 },
5135 { .hw_value
= 44, .center_freq
= 5220, .max_power
= 25 },
5136 { .hw_value
= 46, .center_freq
= 5230, .max_power
= 25 },
5137 { .hw_value
= 48, .center_freq
= 5240, .max_power
= 25 },
5138 { .hw_value
= 52, .center_freq
= 5260, .max_power
= 25 },
5139 { .hw_value
= 56, .center_freq
= 5280, .max_power
= 25 },
5140 { .hw_value
= 60, .center_freq
= 5300, .max_power
= 25 },
5141 { .hw_value
= 64, .center_freq
= 5320, .max_power
= 25 },
5142 { .hw_value
= 100, .center_freq
= 5500, .max_power
= 25 },
5143 { .hw_value
= 104, .center_freq
= 5520, .max_power
= 25 },
5144 { .hw_value
= 108, .center_freq
= 5540, .max_power
= 25 },
5145 { .hw_value
= 112, .center_freq
= 5560, .max_power
= 25 },
5146 { .hw_value
= 116, .center_freq
= 5580, .max_power
= 25 },
5147 { .hw_value
= 120, .center_freq
= 5600, .max_power
= 25 },
5148 { .hw_value
= 124, .center_freq
= 5620, .max_power
= 25 },
5149 { .hw_value
= 128, .center_freq
= 5640, .max_power
= 25 },
5150 { .hw_value
= 132, .center_freq
= 5660, .max_power
= 25 },
5151 { .hw_value
= 136, .center_freq
= 5680, .max_power
= 25 },
5152 { .hw_value
= 140, .center_freq
= 5700, .max_power
= 25 },
5153 { .hw_value
= 149, .center_freq
= 5745, .max_power
= 25 },
5154 { .hw_value
= 153, .center_freq
= 5765, .max_power
= 25 },
5155 { .hw_value
= 157, .center_freq
= 5785, .max_power
= 25 },
5156 { .hw_value
= 161, .center_freq
= 5805, .max_power
= 25 },
5157 { .hw_value
= 165, .center_freq
= 5825, .max_power
= 25 },
5160 static struct ieee80211_supported_band wl1271_band_5ghz
= {
5161 .channels
= wl1271_channels_5ghz
,
5162 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
5163 .bitrates
= wl1271_rates_5ghz
,
5164 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
5167 static const struct ieee80211_ops wl1271_ops
= {
5168 .start
= wl1271_op_start
,
5169 .stop
= wlcore_op_stop
,
5170 .add_interface
= wl1271_op_add_interface
,
5171 .remove_interface
= wl1271_op_remove_interface
,
5172 .change_interface
= wl12xx_op_change_interface
,
5174 .suspend
= wl1271_op_suspend
,
5175 .resume
= wl1271_op_resume
,
5177 .config
= wl1271_op_config
,
5178 .prepare_multicast
= wl1271_op_prepare_multicast
,
5179 .configure_filter
= wl1271_op_configure_filter
,
5181 .set_key
= wlcore_op_set_key
,
5182 .hw_scan
= wl1271_op_hw_scan
,
5183 .cancel_hw_scan
= wl1271_op_cancel_hw_scan
,
5184 .sched_scan_start
= wl1271_op_sched_scan_start
,
5185 .sched_scan_stop
= wl1271_op_sched_scan_stop
,
5186 .bss_info_changed
= wl1271_op_bss_info_changed
,
5187 .set_frag_threshold
= wl1271_op_set_frag_threshold
,
5188 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
5189 .conf_tx
= wl1271_op_conf_tx
,
5190 .get_tsf
= wl1271_op_get_tsf
,
5191 .get_survey
= wl1271_op_get_survey
,
5192 .sta_state
= wl12xx_op_sta_state
,
5193 .ampdu_action
= wl1271_op_ampdu_action
,
5194 .tx_frames_pending
= wl1271_tx_frames_pending
,
5195 .set_bitrate_mask
= wl12xx_set_bitrate_mask
,
5196 .channel_switch
= wl12xx_op_channel_switch
,
5197 .flush
= wlcore_op_flush
,
5198 .remain_on_channel
= wlcore_op_remain_on_channel
,
5199 .cancel_remain_on_channel
= wlcore_op_cancel_remain_on_channel
,
5200 .add_chanctx
= wlcore_op_add_chanctx
,
5201 .remove_chanctx
= wlcore_op_remove_chanctx
,
5202 .change_chanctx
= wlcore_op_change_chanctx
,
5203 .assign_vif_chanctx
= wlcore_op_assign_vif_chanctx
,
5204 .unassign_vif_chanctx
= wlcore_op_unassign_vif_chanctx
,
5205 .sta_rc_update
= wlcore_op_sta_rc_update
,
5206 CFG80211_TESTMODE_CMD(wl1271_tm_cmd
)
5210 u8
wlcore_rate_to_idx(struct wl1271
*wl
, u8 rate
, enum ieee80211_band band
)
5216 if (unlikely(rate
>= wl
->hw_tx_rate_tbl_size
)) {
5217 wl1271_error("Illegal RX rate from HW: %d", rate
);
5221 idx
= wl
->band_rate_to_idx
[band
][rate
];
5222 if (unlikely(idx
== CONF_HW_RXTX_RATE_UNSUPPORTED
)) {
5223 wl1271_error("Unsupported RX rate from HW: %d", rate
);
5230 static ssize_t
wl1271_sysfs_show_bt_coex_state(struct device
*dev
,
5231 struct device_attribute
*attr
,
5234 struct wl1271
*wl
= dev_get_drvdata(dev
);
5239 mutex_lock(&wl
->mutex
);
5240 len
= snprintf(buf
, len
, "%d\n\n0 - off\n1 - on\n",
5242 mutex_unlock(&wl
->mutex
);
5248 static ssize_t
wl1271_sysfs_store_bt_coex_state(struct device
*dev
,
5249 struct device_attribute
*attr
,
5250 const char *buf
, size_t count
)
5252 struct wl1271
*wl
= dev_get_drvdata(dev
);
5256 ret
= kstrtoul(buf
, 10, &res
);
5258 wl1271_warning("incorrect value written to bt_coex_mode");
5262 mutex_lock(&wl
->mutex
);
5266 if (res
== wl
->sg_enabled
)
5269 wl
->sg_enabled
= res
;
5271 if (unlikely(wl
->state
!= WLCORE_STATE_ON
))
5274 ret
= wl1271_ps_elp_wakeup(wl
);
5278 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
5279 wl1271_ps_elp_sleep(wl
);
5282 mutex_unlock(&wl
->mutex
);
5286 static DEVICE_ATTR(bt_coex_state
, S_IRUGO
| S_IWUSR
,
5287 wl1271_sysfs_show_bt_coex_state
,
5288 wl1271_sysfs_store_bt_coex_state
);
5290 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
5291 struct device_attribute
*attr
,
5294 struct wl1271
*wl
= dev_get_drvdata(dev
);
5299 mutex_lock(&wl
->mutex
);
5300 if (wl
->hw_pg_ver
>= 0)
5301 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
5303 len
= snprintf(buf
, len
, "n/a\n");
5304 mutex_unlock(&wl
->mutex
);
5309 static DEVICE_ATTR(hw_pg_ver
, S_IRUGO
,
5310 wl1271_sysfs_show_hw_pg_ver
, NULL
);
5312 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
5313 struct bin_attribute
*bin_attr
,
5314 char *buffer
, loff_t pos
, size_t count
)
5316 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
5317 struct wl1271
*wl
= dev_get_drvdata(dev
);
5321 ret
= mutex_lock_interruptible(&wl
->mutex
);
5323 return -ERESTARTSYS
;
5325 /* Let only one thread read the log at a time, blocking others */
5326 while (wl
->fwlog_size
== 0) {
5329 prepare_to_wait_exclusive(&wl
->fwlog_waitq
,
5331 TASK_INTERRUPTIBLE
);
5333 if (wl
->fwlog_size
!= 0) {
5334 finish_wait(&wl
->fwlog_waitq
, &wait
);
5338 mutex_unlock(&wl
->mutex
);
5341 finish_wait(&wl
->fwlog_waitq
, &wait
);
5343 if (signal_pending(current
))
5344 return -ERESTARTSYS
;
5346 ret
= mutex_lock_interruptible(&wl
->mutex
);
5348 return -ERESTARTSYS
;
5351 /* Check if the fwlog is still valid */
5352 if (wl
->fwlog_size
< 0) {
5353 mutex_unlock(&wl
->mutex
);
5357 /* Seeking is not supported - old logs are not kept. Disregard pos. */
5358 len
= min(count
, (size_t)wl
->fwlog_size
);
5359 wl
->fwlog_size
-= len
;
5360 memcpy(buffer
, wl
->fwlog
, len
);
5362 /* Make room for new messages */
5363 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
5365 mutex_unlock(&wl
->mutex
);
5370 static struct bin_attribute fwlog_attr
= {
5371 .attr
= {.name
= "fwlog", .mode
= S_IRUSR
},
5372 .read
= wl1271_sysfs_read_fwlog
,
5375 static void wl12xx_derive_mac_addresses(struct wl1271
*wl
, u32 oui
, u32 nic
)
5379 wl1271_debug(DEBUG_PROBE
, "base address: oui %06x nic %06x",
5382 if (nic
+ WLCORE_NUM_MAC_ADDRESSES
- wl
->num_mac_addr
> 0xffffff)
5383 wl1271_warning("NIC part of the MAC address wraps around!");
5385 for (i
= 0; i
< wl
->num_mac_addr
; i
++) {
5386 wl
->addresses
[i
].addr
[0] = (u8
)(oui
>> 16);
5387 wl
->addresses
[i
].addr
[1] = (u8
)(oui
>> 8);
5388 wl
->addresses
[i
].addr
[2] = (u8
) oui
;
5389 wl
->addresses
[i
].addr
[3] = (u8
)(nic
>> 16);
5390 wl
->addresses
[i
].addr
[4] = (u8
)(nic
>> 8);
5391 wl
->addresses
[i
].addr
[5] = (u8
) nic
;
5395 /* we may be one address short at the most */
5396 WARN_ON(wl
->num_mac_addr
+ 1 < WLCORE_NUM_MAC_ADDRESSES
);
5399 * turn on the LAA bit in the first address and use it as
5402 if (wl
->num_mac_addr
< WLCORE_NUM_MAC_ADDRESSES
) {
5403 int idx
= WLCORE_NUM_MAC_ADDRESSES
- 1;
5404 memcpy(&wl
->addresses
[idx
], &wl
->addresses
[0],
5405 sizeof(wl
->addresses
[0]));
5407 wl
->addresses
[idx
].addr
[2] |= BIT(1);
5410 wl
->hw
->wiphy
->n_addresses
= WLCORE_NUM_MAC_ADDRESSES
;
5411 wl
->hw
->wiphy
->addresses
= wl
->addresses
;
5414 static int wl12xx_get_hw_info(struct wl1271
*wl
)
5418 ret
= wl12xx_set_power_on(wl
);
5422 ret
= wlcore_read_reg(wl
, REG_CHIP_ID_B
, &wl
->chip
.id
);
5426 wl
->fuse_oui_addr
= 0;
5427 wl
->fuse_nic_addr
= 0;
5429 ret
= wl
->ops
->get_pg_ver(wl
, &wl
->hw_pg_ver
);
5433 if (wl
->ops
->get_mac
)
5434 ret
= wl
->ops
->get_mac(wl
);
5437 wl1271_power_off(wl
);
5441 static int wl1271_register_hw(struct wl1271
*wl
)
5444 u32 oui_addr
= 0, nic_addr
= 0;
5446 if (wl
->mac80211_registered
)
5449 if (wl
->nvs_len
>= 12) {
5450 /* NOTE: The wl->nvs->nvs element must be first, in
5451 * order to simplify the casting, we assume it is at
5452 * the beginning of the wl->nvs structure.
5454 u8
*nvs_ptr
= (u8
*)wl
->nvs
;
5457 (nvs_ptr
[11] << 16) + (nvs_ptr
[10] << 8) + nvs_ptr
[6];
5459 (nvs_ptr
[5] << 16) + (nvs_ptr
[4] << 8) + nvs_ptr
[3];
5462 /* if the MAC address is zeroed in the NVS derive from fuse */
5463 if (oui_addr
== 0 && nic_addr
== 0) {
5464 oui_addr
= wl
->fuse_oui_addr
;
5465 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
5466 nic_addr
= wl
->fuse_nic_addr
+ 1;
5469 wl12xx_derive_mac_addresses(wl
, oui_addr
, nic_addr
);
5471 ret
= ieee80211_register_hw(wl
->hw
);
5473 wl1271_error("unable to register mac80211 hw: %d", ret
);
5477 wl
->mac80211_registered
= true;
5479 wl1271_debugfs_init(wl
);
5481 wl1271_notice("loaded");
5487 static void wl1271_unregister_hw(struct wl1271
*wl
)
5490 wl1271_plt_stop(wl
);
5492 ieee80211_unregister_hw(wl
->hw
);
5493 wl
->mac80211_registered
= false;
5497 static const struct ieee80211_iface_limit wlcore_iface_limits
[] = {
5500 .types
= BIT(NL80211_IFTYPE_STATION
),
5504 .types
= BIT(NL80211_IFTYPE_AP
) |
5505 BIT(NL80211_IFTYPE_P2P_GO
) |
5506 BIT(NL80211_IFTYPE_P2P_CLIENT
),
5510 static struct ieee80211_iface_combination
5511 wlcore_iface_combinations
[] = {
5513 .max_interfaces
= 3,
5514 .limits
= wlcore_iface_limits
,
5515 .n_limits
= ARRAY_SIZE(wlcore_iface_limits
),
5519 static int wl1271_init_ieee80211(struct wl1271
*wl
)
5521 static const u32 cipher_suites
[] = {
5522 WLAN_CIPHER_SUITE_WEP40
,
5523 WLAN_CIPHER_SUITE_WEP104
,
5524 WLAN_CIPHER_SUITE_TKIP
,
5525 WLAN_CIPHER_SUITE_CCMP
,
5526 WL1271_CIPHER_SUITE_GEM
,
5529 /* The tx descriptor buffer */
5530 wl
->hw
->extra_tx_headroom
= sizeof(struct wl1271_tx_hw_descr
);
5532 if (wl
->quirks
& WLCORE_QUIRK_TKIP_HEADER_SPACE
)
5533 wl
->hw
->extra_tx_headroom
+= WL1271_EXTRA_SPACE_TKIP
;
5536 /* FIXME: find a proper value */
5537 wl
->hw
->channel_change_time
= 10000;
5538 wl
->hw
->max_listen_interval
= wl
->conf
.conn
.max_listen_interval
;
5540 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
5541 IEEE80211_HW_SUPPORTS_PS
|
5542 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
5543 IEEE80211_HW_SUPPORTS_UAPSD
|
5544 IEEE80211_HW_HAS_RATE_CONTROL
|
5545 IEEE80211_HW_CONNECTION_MONITOR
|
5546 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
5547 IEEE80211_HW_SPECTRUM_MGMT
|
5548 IEEE80211_HW_AP_LINK_PS
|
5549 IEEE80211_HW_AMPDU_AGGREGATION
|
5550 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
|
5551 IEEE80211_HW_SCAN_WHILE_IDLE
;
5553 wl
->hw
->wiphy
->cipher_suites
= cipher_suites
;
5554 wl
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
5556 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5557 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_AP
) |
5558 BIT(NL80211_IFTYPE_P2P_CLIENT
) | BIT(NL80211_IFTYPE_P2P_GO
);
5559 wl
->hw
->wiphy
->max_scan_ssids
= 1;
5560 wl
->hw
->wiphy
->max_sched_scan_ssids
= 16;
5561 wl
->hw
->wiphy
->max_match_sets
= 16;
5563 * Maximum length of elements in scanning probe request templates
5564 * should be the maximum length possible for a template, without
5565 * the IEEE80211 header of the template
5567 wl
->hw
->wiphy
->max_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5568 sizeof(struct ieee80211_header
);
5570 wl
->hw
->wiphy
->max_sched_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5571 sizeof(struct ieee80211_header
);
5573 wl
->hw
->wiphy
->max_remain_on_channel_duration
= 5000;
5575 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
|
5576 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
5578 /* make sure all our channels fit in the scanned_ch bitmask */
5579 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels
) +
5580 ARRAY_SIZE(wl1271_channels_5ghz
) >
5581 WL1271_MAX_CHANNELS
);
5583 * We keep local copies of the band structs because we need to
5584 * modify them on a per-device basis.
5586 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
], &wl1271_band_2ghz
,
5587 sizeof(wl1271_band_2ghz
));
5588 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
].ht_cap
,
5589 &wl
->ht_cap
[IEEE80211_BAND_2GHZ
],
5590 sizeof(*wl
->ht_cap
));
5591 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
], &wl1271_band_5ghz
,
5592 sizeof(wl1271_band_5ghz
));
5593 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
].ht_cap
,
5594 &wl
->ht_cap
[IEEE80211_BAND_5GHZ
],
5595 sizeof(*wl
->ht_cap
));
5597 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5598 &wl
->bands
[IEEE80211_BAND_2GHZ
];
5599 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5600 &wl
->bands
[IEEE80211_BAND_5GHZ
];
5603 wl
->hw
->max_rates
= 1;
5605 wl
->hw
->wiphy
->reg_notifier
= wl1271_reg_notify
;
5607 /* the FW answers probe-requests in AP-mode */
5608 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5609 wl
->hw
->wiphy
->probe_resp_offload
=
5610 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5611 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5612 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5614 /* allowed interface combinations */
5615 wlcore_iface_combinations
[0].num_different_channels
= wl
->num_channels
;
5616 wl
->hw
->wiphy
->iface_combinations
= wlcore_iface_combinations
;
5617 wl
->hw
->wiphy
->n_iface_combinations
=
5618 ARRAY_SIZE(wlcore_iface_combinations
);
5620 SET_IEEE80211_DEV(wl
->hw
, wl
->dev
);
5622 wl
->hw
->sta_data_size
= sizeof(struct wl1271_station
);
5623 wl
->hw
->vif_data_size
= sizeof(struct wl12xx_vif
);
5625 wl
->hw
->max_rx_aggregation_subframes
= wl
->conf
.ht
.rx_ba_win_size
;
5630 #define WL1271_DEFAULT_CHANNEL 0
5632 struct ieee80211_hw
*wlcore_alloc_hw(size_t priv_size
, u32 aggr_buf_size
,
5635 struct ieee80211_hw
*hw
;
5640 BUILD_BUG_ON(AP_MAX_STATIONS
> WL12XX_MAX_LINKS
);
5642 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
5644 wl1271_error("could not alloc ieee80211_hw");
5650 memset(wl
, 0, sizeof(*wl
));
5652 wl
->priv
= kzalloc(priv_size
, GFP_KERNEL
);
5654 wl1271_error("could not alloc wl priv");
5656 goto err_priv_alloc
;
5659 INIT_LIST_HEAD(&wl
->wlvif_list
);
5663 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
5664 for (j
= 0; j
< WL12XX_MAX_LINKS
; j
++)
5665 skb_queue_head_init(&wl
->links
[j
].tx_queue
[i
]);
5667 skb_queue_head_init(&wl
->deferred_rx_queue
);
5668 skb_queue_head_init(&wl
->deferred_tx_queue
);
5670 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
5671 INIT_WORK(&wl
->netstack_work
, wl1271_netstack_work
);
5672 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
5673 INIT_WORK(&wl
->recovery_work
, wl1271_recovery_work
);
5674 INIT_DELAYED_WORK(&wl
->scan_complete_work
, wl1271_scan_complete_work
);
5675 INIT_DELAYED_WORK(&wl
->roc_complete_work
, wlcore_roc_complete_work
);
5676 INIT_DELAYED_WORK(&wl
->tx_watchdog_work
, wl12xx_tx_watchdog_work
);
5678 wl
->freezable_wq
= create_freezable_workqueue("wl12xx_wq");
5679 if (!wl
->freezable_wq
) {
5684 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
5686 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
5687 wl
->band
= IEEE80211_BAND_2GHZ
;
5688 wl
->channel_type
= NL80211_CHAN_NO_HT
;
5690 wl
->sg_enabled
= true;
5691 wl
->sleep_auth
= WL1271_PSM_ILLEGAL
;
5692 wl
->recovery_count
= 0;
5695 wl
->ap_fw_ps_map
= 0;
5697 wl
->platform_quirks
= 0;
5698 wl
->system_hlid
= WL12XX_SYSTEM_HLID
;
5699 wl
->active_sta_count
= 0;
5701 init_waitqueue_head(&wl
->fwlog_waitq
);
5703 /* The system link is always allocated */
5704 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
5706 memset(wl
->tx_frames_map
, 0, sizeof(wl
->tx_frames_map
));
5707 for (i
= 0; i
< wl
->num_tx_desc
; i
++)
5708 wl
->tx_frames
[i
] = NULL
;
5710 spin_lock_init(&wl
->wl_lock
);
5712 wl
->state
= WLCORE_STATE_OFF
;
5713 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5714 mutex_init(&wl
->mutex
);
5715 mutex_init(&wl
->flush_mutex
);
5716 init_completion(&wl
->nvs_loading_complete
);
5718 order
= get_order(aggr_buf_size
);
5719 wl
->aggr_buf
= (u8
*)__get_free_pages(GFP_KERNEL
, order
);
5720 if (!wl
->aggr_buf
) {
5724 wl
->aggr_buf_size
= aggr_buf_size
;
5726 wl
->dummy_packet
= wl12xx_alloc_dummy_packet(wl
);
5727 if (!wl
->dummy_packet
) {
5732 /* Allocate one page for the FW log */
5733 wl
->fwlog
= (u8
*)get_zeroed_page(GFP_KERNEL
);
5736 goto err_dummy_packet
;
5739 wl
->mbox_size
= mbox_size
;
5740 wl
->mbox
= kmalloc(wl
->mbox_size
, GFP_KERNEL
| GFP_DMA
);
5749 free_page((unsigned long)wl
->fwlog
);
5752 dev_kfree_skb(wl
->dummy_packet
);
5755 free_pages((unsigned long)wl
->aggr_buf
, order
);
5758 destroy_workqueue(wl
->freezable_wq
);
5761 wl1271_debugfs_exit(wl
);
5765 ieee80211_free_hw(hw
);
5769 return ERR_PTR(ret
);
5771 EXPORT_SYMBOL_GPL(wlcore_alloc_hw
);
5773 int wlcore_free_hw(struct wl1271
*wl
)
5775 /* Unblock any fwlog readers */
5776 mutex_lock(&wl
->mutex
);
5777 wl
->fwlog_size
= -1;
5778 wake_up_interruptible_all(&wl
->fwlog_waitq
);
5779 mutex_unlock(&wl
->mutex
);
5781 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
5783 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5785 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5787 free_page((unsigned long)wl
->fwlog
);
5788 dev_kfree_skb(wl
->dummy_packet
);
5789 free_pages((unsigned long)wl
->aggr_buf
, get_order(wl
->aggr_buf_size
));
5791 wl1271_debugfs_exit(wl
);
5795 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5799 kfree(wl
->fw_status_1
);
5800 kfree(wl
->tx_res_if
);
5801 destroy_workqueue(wl
->freezable_wq
);
5804 ieee80211_free_hw(wl
->hw
);
5808 EXPORT_SYMBOL_GPL(wlcore_free_hw
);
5810 static irqreturn_t
wl12xx_hardirq(int irq
, void *cookie
)
5812 struct wl1271
*wl
= cookie
;
5813 unsigned long flags
;
5815 wl1271_debug(DEBUG_IRQ
, "IRQ");
5817 /* complete the ELP completion */
5818 spin_lock_irqsave(&wl
->wl_lock
, flags
);
5819 set_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
5820 if (wl
->elp_compl
) {
5821 complete(wl
->elp_compl
);
5822 wl
->elp_compl
= NULL
;
5825 if (test_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
)) {
5826 /* don't enqueue a work right now. mark it as pending */
5827 set_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
);
5828 wl1271_debug(DEBUG_IRQ
, "should not enqueue work");
5829 disable_irq_nosync(wl
->irq
);
5830 pm_wakeup_event(wl
->dev
, 0);
5831 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5834 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5836 return IRQ_WAKE_THREAD
;
5839 static void wlcore_nvs_cb(const struct firmware
*fw
, void *context
)
5841 struct wl1271
*wl
= context
;
5842 struct platform_device
*pdev
= wl
->pdev
;
5843 struct wl12xx_platform_data
*pdata
= pdev
->dev
.platform_data
;
5844 unsigned long irqflags
;
5848 wl
->nvs
= kmemdup(fw
->data
, fw
->size
, GFP_KERNEL
);
5850 wl1271_error("Could not allocate nvs data");
5853 wl
->nvs_len
= fw
->size
;
5855 wl1271_debug(DEBUG_BOOT
, "Could not get nvs file %s",
5861 ret
= wl
->ops
->setup(wl
);
5865 BUG_ON(wl
->num_tx_desc
> WLCORE_MAX_TX_DESCRIPTORS
);
5867 /* adjust some runtime configuration parameters */
5868 wlcore_adjust_conf(wl
);
5870 wl
->irq
= platform_get_irq(pdev
, 0);
5871 wl
->platform_quirks
= pdata
->platform_quirks
;
5872 wl
->set_power
= pdata
->set_power
;
5873 wl
->if_ops
= pdata
->ops
;
5875 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
5876 irqflags
= IRQF_TRIGGER_RISING
;
5878 irqflags
= IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
;
5880 ret
= request_threaded_irq(wl
->irq
, wl12xx_hardirq
, wlcore_irq
,
5884 wl1271_error("request_irq() failed: %d", ret
);
5889 ret
= enable_irq_wake(wl
->irq
);
5891 wl
->irq_wake_enabled
= true;
5892 device_init_wakeup(wl
->dev
, 1);
5893 if (pdata
->pwr_in_suspend
) {
5894 wl
->hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_ANY
;
5895 wl
->hw
->wiphy
->wowlan
.n_patterns
=
5896 WL1271_MAX_RX_FILTERS
;
5897 wl
->hw
->wiphy
->wowlan
.pattern_min_len
= 1;
5898 wl
->hw
->wiphy
->wowlan
.pattern_max_len
=
5899 WL1271_RX_FILTER_MAX_PATTERN_SIZE
;
5903 disable_irq(wl
->irq
);
5905 ret
= wl12xx_get_hw_info(wl
);
5907 wl1271_error("couldn't get hw info");
5911 ret
= wl
->ops
->identify_chip(wl
);
5915 ret
= wl1271_init_ieee80211(wl
);
5919 ret
= wl1271_register_hw(wl
);
5923 /* Create sysfs file to control bt coex state */
5924 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
5926 wl1271_error("failed to create sysfs file bt_coex_state");
5930 /* Create sysfs file to get HW PG version */
5931 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5933 wl1271_error("failed to create sysfs file hw_pg_ver");
5934 goto out_bt_coex_state
;
5937 /* Create sysfs file for the FW log */
5938 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
5940 wl1271_error("failed to create sysfs file fwlog");
5944 wl
->initialized
= true;
5948 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5951 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5954 wl1271_unregister_hw(wl
);
5957 free_irq(wl
->irq
, wl
);
5963 release_firmware(fw
);
5964 complete_all(&wl
->nvs_loading_complete
);
5967 int __devinit
wlcore_probe(struct wl1271
*wl
, struct platform_device
*pdev
)
5971 if (!wl
->ops
|| !wl
->ptable
)
5974 wl
->dev
= &pdev
->dev
;
5976 platform_set_drvdata(pdev
, wl
);
5978 ret
= request_firmware_nowait(THIS_MODULE
, FW_ACTION_HOTPLUG
,
5979 WL12XX_NVS_NAME
, &pdev
->dev
, GFP_KERNEL
,
5982 wl1271_error("request_firmware_nowait failed: %d", ret
);
5983 complete_all(&wl
->nvs_loading_complete
);
5988 EXPORT_SYMBOL_GPL(wlcore_probe
);
5990 int __devexit
wlcore_remove(struct platform_device
*pdev
)
5992 struct wl1271
*wl
= platform_get_drvdata(pdev
);
5994 wait_for_completion(&wl
->nvs_loading_complete
);
5995 if (!wl
->initialized
)
5998 if (wl
->irq_wake_enabled
) {
5999 device_init_wakeup(wl
->dev
, 0);
6000 disable_irq_wake(wl
->irq
);
6002 wl1271_unregister_hw(wl
);
6003 free_irq(wl
->irq
, wl
);
6008 EXPORT_SYMBOL_GPL(wlcore_remove
);
6010 u32 wl12xx_debug_level
= DEBUG_NONE
;
6011 EXPORT_SYMBOL_GPL(wl12xx_debug_level
);
6012 module_param_named(debug_level
, wl12xx_debug_level
, uint
, S_IRUSR
| S_IWUSR
);
6013 MODULE_PARM_DESC(debug_level
, "wl12xx debugging level");
6015 module_param_named(fwlog
, fwlog_param
, charp
, 0);
6016 MODULE_PARM_DESC(fwlog
,
6017 "FW logger options: continuous, ondemand, dbgpins or disable");
6019 module_param(bug_on_recovery
, int, S_IRUSR
| S_IWUSR
);
6020 MODULE_PARM_DESC(bug_on_recovery
, "BUG() on fw recovery");
6022 module_param(no_recovery
, int, S_IRUSR
| S_IWUSR
);
6023 MODULE_PARM_DESC(no_recovery
, "Prevent HW recovery. FW will remain stuck.");
6025 MODULE_LICENSE("GPL");
6026 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
6027 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");
6028 MODULE_FIRMWARE(WL12XX_NVS_NAME
);