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 bool bug_on_recovery
;
60 static bool no_recovery
;
62 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
63 struct ieee80211_vif
*vif
,
64 bool reset_tx_queues
);
65 static void wl1271_op_stop(struct ieee80211_hw
*hw
);
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
->sta
.hlid
);
86 wl12xx_croc(wl
, wlvif
->role_id
);
88 wl1271_info("Association completed.");
92 static int wl1271_reg_notify(struct wiphy
*wiphy
,
93 struct regulatory_request
*request
)
95 struct ieee80211_supported_band
*band
;
96 struct ieee80211_channel
*ch
;
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
;
114 static int wl1271_set_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
119 /* we should hold wl->mutex */
120 ret
= wl1271_acx_ps_rx_streaming(wl
, wlvif
, enable
);
125 set_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
127 clear_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
);
133 * this function is being called when the rx_streaming interval
134 * has beed changed or rx_streaming should be disabled
136 int wl1271_recalc_rx_streaming(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
139 int period
= wl
->conf
.rx_streaming
.interval
;
141 /* don't reconfigure if rx_streaming is disabled */
142 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
145 /* reconfigure/disable according to new streaming_period */
147 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
148 (wl
->conf
.rx_streaming
.always
||
149 test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
150 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
152 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
153 /* don't cancel_work_sync since we might deadlock */
154 del_timer_sync(&wlvif
->rx_streaming_timer
);
160 static void wl1271_rx_streaming_enable_work(struct work_struct
*work
)
163 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
164 rx_streaming_enable_work
);
165 struct wl1271
*wl
= wlvif
->wl
;
167 mutex_lock(&wl
->mutex
);
169 if (test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
) ||
170 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
171 (!wl
->conf
.rx_streaming
.always
&&
172 !test_bit(WL1271_FLAG_SOFT_GEMINI
, &wl
->flags
)))
175 if (!wl
->conf
.rx_streaming
.interval
)
178 ret
= wl1271_ps_elp_wakeup(wl
);
182 ret
= wl1271_set_rx_streaming(wl
, wlvif
, true);
186 /* stop it after some time of inactivity */
187 mod_timer(&wlvif
->rx_streaming_timer
,
188 jiffies
+ msecs_to_jiffies(wl
->conf
.rx_streaming
.duration
));
191 wl1271_ps_elp_sleep(wl
);
193 mutex_unlock(&wl
->mutex
);
196 static void wl1271_rx_streaming_disable_work(struct work_struct
*work
)
199 struct wl12xx_vif
*wlvif
= container_of(work
, struct wl12xx_vif
,
200 rx_streaming_disable_work
);
201 struct wl1271
*wl
= wlvif
->wl
;
203 mutex_lock(&wl
->mutex
);
205 if (!test_bit(WLVIF_FLAG_RX_STREAMING_STARTED
, &wlvif
->flags
))
208 ret
= wl1271_ps_elp_wakeup(wl
);
212 ret
= wl1271_set_rx_streaming(wl
, wlvif
, false);
217 wl1271_ps_elp_sleep(wl
);
219 mutex_unlock(&wl
->mutex
);
222 static void wl1271_rx_streaming_timer(unsigned long data
)
224 struct wl12xx_vif
*wlvif
= (struct wl12xx_vif
*)data
;
225 struct wl1271
*wl
= wlvif
->wl
;
226 ieee80211_queue_work(wl
->hw
, &wlvif
->rx_streaming_disable_work
);
229 /* wl->mutex must be taken */
230 void wl12xx_rearm_tx_watchdog_locked(struct wl1271
*wl
)
232 /* if the watchdog is not armed, don't do anything */
233 if (wl
->tx_allocated_blocks
== 0)
236 cancel_delayed_work(&wl
->tx_watchdog_work
);
237 ieee80211_queue_delayed_work(wl
->hw
, &wl
->tx_watchdog_work
,
238 msecs_to_jiffies(wl
->conf
.tx
.tx_watchdog_timeout
));
241 static void wl12xx_tx_watchdog_work(struct work_struct
*work
)
243 struct delayed_work
*dwork
;
246 dwork
= container_of(work
, struct delayed_work
, work
);
247 wl
= container_of(dwork
, struct wl1271
, tx_watchdog_work
);
249 mutex_lock(&wl
->mutex
);
251 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
254 /* Tx went out in the meantime - everything is ok */
255 if (unlikely(wl
->tx_allocated_blocks
== 0))
259 * if a ROC is in progress, we might not have any Tx for a long
260 * time (e.g. pending Tx on the non-ROC channels)
262 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
263 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to ROC",
264 wl
->conf
.tx
.tx_watchdog_timeout
);
265 wl12xx_rearm_tx_watchdog_locked(wl
);
270 * if a scan is in progress, we might not have any Tx for a long
273 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
) {
274 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms due to scan",
275 wl
->conf
.tx
.tx_watchdog_timeout
);
276 wl12xx_rearm_tx_watchdog_locked(wl
);
281 * AP might cache a frame for a long time for a sleeping station,
282 * so rearm the timer if there's an AP interface with stations. If
283 * Tx is genuinely stuck we will most hopefully discover it when all
284 * stations are removed due to inactivity.
286 if (wl
->active_sta_count
) {
287 wl1271_debug(DEBUG_TX
, "No Tx (in FW) for %d ms. AP has "
289 wl
->conf
.tx
.tx_watchdog_timeout
,
290 wl
->active_sta_count
);
291 wl12xx_rearm_tx_watchdog_locked(wl
);
295 wl1271_error("Tx stuck (in FW) for %d ms. Starting recovery",
296 wl
->conf
.tx
.tx_watchdog_timeout
);
297 wl12xx_queue_recovery_work(wl
);
300 mutex_unlock(&wl
->mutex
);
303 static void wlcore_adjust_conf(struct wl1271
*wl
)
305 /* Adjust settings according to optional module parameters */
307 if (!strcmp(fwlog_param
, "continuous")) {
308 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
309 } else if (!strcmp(fwlog_param
, "ondemand")) {
310 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_ON_DEMAND
;
311 } else if (!strcmp(fwlog_param
, "dbgpins")) {
312 wl
->conf
.fwlog
.mode
= WL12XX_FWLOG_CONTINUOUS
;
313 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_DBG_PINS
;
314 } else if (!strcmp(fwlog_param
, "disable")) {
315 wl
->conf
.fwlog
.mem_blocks
= 0;
316 wl
->conf
.fwlog
.output
= WL12XX_FWLOG_OUTPUT_NONE
;
318 wl1271_error("Unknown fwlog parameter %s", fwlog_param
);
323 static int wl1271_plt_init(struct wl1271
*wl
)
327 ret
= wl
->ops
->hw_init(wl
);
331 ret
= wl1271_acx_init_mem_config(wl
);
335 ret
= wl12xx_acx_mem_cfg(wl
);
337 goto out_free_memmap
;
339 /* Enable data path */
340 ret
= wl1271_cmd_data_path(wl
, 1);
342 goto out_free_memmap
;
344 /* Configure for CAM power saving (ie. always active) */
345 ret
= wl1271_acx_sleep_auth(wl
, WL1271_PSM_CAM
);
347 goto out_free_memmap
;
350 ret
= wl1271_acx_pm_config(wl
);
352 goto out_free_memmap
;
357 kfree(wl
->target_mem_map
);
358 wl
->target_mem_map
= NULL
;
363 static void wl12xx_irq_ps_regulate_link(struct wl1271
*wl
,
364 struct wl12xx_vif
*wlvif
,
367 bool fw_ps
, single_sta
;
369 fw_ps
= test_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
370 single_sta
= (wl
->active_sta_count
== 1);
373 * Wake up from high level PS if the STA is asleep with too little
374 * packets in FW or if the STA is awake.
376 if (!fw_ps
|| tx_pkts
< WL1271_PS_STA_MAX_PACKETS
)
377 wl12xx_ps_link_end(wl
, wlvif
, hlid
);
380 * Start high-level PS if the STA is asleep with enough blocks in FW.
381 * Make an exception if this is the only connected station. In this
382 * case FW-memory congestion is not a problem.
384 else if (!single_sta
&& fw_ps
&& tx_pkts
>= WL1271_PS_STA_MAX_PACKETS
)
385 wl12xx_ps_link_start(wl
, wlvif
, hlid
, true);
388 static void wl12xx_irq_update_links_status(struct wl1271
*wl
,
389 struct wl12xx_vif
*wlvif
,
390 struct wl_fw_status
*status
)
392 struct wl1271_link
*lnk
;
396 /* TODO: also use link_fast_bitmap here */
398 cur_fw_ps_map
= le32_to_cpu(status
->link_ps_bitmap
);
399 if (wl
->ap_fw_ps_map
!= cur_fw_ps_map
) {
400 wl1271_debug(DEBUG_PSM
,
401 "link ps prev 0x%x cur 0x%x changed 0x%x",
402 wl
->ap_fw_ps_map
, cur_fw_ps_map
,
403 wl
->ap_fw_ps_map
^ cur_fw_ps_map
);
405 wl
->ap_fw_ps_map
= cur_fw_ps_map
;
408 for_each_set_bit(hlid
, wlvif
->ap
.sta_hlid_map
, WL12XX_MAX_LINKS
) {
409 lnk
= &wl
->links
[hlid
];
410 cnt
= status
->counters
.tx_lnk_free_pkts
[hlid
] -
411 lnk
->prev_freed_pkts
;
413 lnk
->prev_freed_pkts
= status
->counters
.tx_lnk_free_pkts
[hlid
];
414 lnk
->allocated_pkts
-= cnt
;
416 wl12xx_irq_ps_regulate_link(wl
, wlvif
, hlid
,
417 lnk
->allocated_pkts
);
421 static void wl12xx_fw_status(struct wl1271
*wl
,
422 struct wl_fw_status
*status
)
424 struct wl12xx_vif
*wlvif
;
426 u32 old_tx_blk_count
= wl
->tx_blocks_available
;
427 int avail
, freed_blocks
;
431 status_len
= sizeof(*status
) + wl
->fw_status_priv_len
;
433 wlcore_raw_read_data(wl
, REG_RAW_FW_STATUS_ADDR
, status
,
436 wl1271_debug(DEBUG_IRQ
, "intr: 0x%x (fw_rx_counter = %d, "
437 "drv_rx_counter = %d, tx_results_counter = %d)",
439 status
->fw_rx_counter
,
440 status
->drv_rx_counter
,
441 status
->tx_results_counter
);
443 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
444 /* prevent wrap-around in freed-packets counter */
445 wl
->tx_allocated_pkts
[i
] -=
446 (status
->counters
.tx_released_pkts
[i
] -
447 wl
->tx_pkts_freed
[i
]) & 0xff;
449 wl
->tx_pkts_freed
[i
] = status
->counters
.tx_released_pkts
[i
];
452 /* prevent wrap-around in total blocks counter */
453 if (likely(wl
->tx_blocks_freed
<=
454 le32_to_cpu(status
->total_released_blks
)))
455 freed_blocks
= le32_to_cpu(status
->total_released_blks
) -
458 freed_blocks
= 0x100000000LL
- wl
->tx_blocks_freed
+
459 le32_to_cpu(status
->total_released_blks
);
461 wl
->tx_blocks_freed
= le32_to_cpu(status
->total_released_blks
);
463 wl
->tx_allocated_blocks
-= freed_blocks
;
466 * If the FW freed some blocks:
467 * If we still have allocated blocks - re-arm the timer, Tx is
468 * not stuck. Otherwise, cancel the timer (no Tx currently).
471 if (wl
->tx_allocated_blocks
)
472 wl12xx_rearm_tx_watchdog_locked(wl
);
474 cancel_delayed_work(&wl
->tx_watchdog_work
);
477 avail
= le32_to_cpu(status
->tx_total
) - wl
->tx_allocated_blocks
;
480 * The FW might change the total number of TX memblocks before
481 * we get a notification about blocks being released. Thus, the
482 * available blocks calculation might yield a temporary result
483 * which is lower than the actual available blocks. Keeping in
484 * mind that only blocks that were allocated can be moved from
485 * TX to RX, tx_blocks_available should never decrease here.
487 wl
->tx_blocks_available
= max((int)wl
->tx_blocks_available
,
490 /* if more blocks are available now, tx work can be scheduled */
491 if (wl
->tx_blocks_available
> old_tx_blk_count
)
492 clear_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
);
494 /* for AP update num of allocated TX blocks per link and ps status */
495 wl12xx_for_each_wlvif_ap(wl
, wlvif
) {
496 wl12xx_irq_update_links_status(wl
, wlvif
, status
);
499 /* update the host-chipset time offset */
501 wl
->time_offset
= (timespec_to_ns(&ts
) >> 10) -
502 (s64
)le32_to_cpu(status
->fw_localtime
);
505 static void wl1271_flush_deferred_work(struct wl1271
*wl
)
509 /* Pass all received frames to the network stack */
510 while ((skb
= skb_dequeue(&wl
->deferred_rx_queue
)))
511 ieee80211_rx_ni(wl
->hw
, skb
);
513 /* Return sent skbs to the network stack */
514 while ((skb
= skb_dequeue(&wl
->deferred_tx_queue
)))
515 ieee80211_tx_status_ni(wl
->hw
, skb
);
518 static void wl1271_netstack_work(struct work_struct
*work
)
521 container_of(work
, struct wl1271
, netstack_work
);
524 wl1271_flush_deferred_work(wl
);
525 } while (skb_queue_len(&wl
->deferred_rx_queue
));
528 #define WL1271_IRQ_MAX_LOOPS 256
530 static irqreturn_t
wl1271_irq(int irq
, void *cookie
)
534 int loopcount
= WL1271_IRQ_MAX_LOOPS
;
535 struct wl1271
*wl
= (struct wl1271
*)cookie
;
537 unsigned int defer_count
;
540 /* TX might be handled here, avoid redundant work */
541 set_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
542 cancel_work_sync(&wl
->tx_work
);
545 * In case edge triggered interrupt must be used, we cannot iterate
546 * more than once without introducing race conditions with the hardirq.
548 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
551 mutex_lock(&wl
->mutex
);
553 wl1271_debug(DEBUG_IRQ
, "IRQ work");
555 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
558 ret
= wl1271_ps_elp_wakeup(wl
);
562 while (!done
&& loopcount
--) {
564 * In order to avoid a race with the hardirq, clear the flag
565 * before acknowledging the chip. Since the mutex is held,
566 * wl1271_ps_elp_wakeup cannot be called concurrently.
568 clear_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
569 smp_mb__after_clear_bit();
571 wl12xx_fw_status(wl
, wl
->fw_status
);
573 wlcore_hw_tx_immediate_compl(wl
);
575 intr
= le32_to_cpu(wl
->fw_status
->intr
);
576 intr
&= WL1271_INTR_MASK
;
582 if (unlikely(intr
& WL1271_ACX_INTR_WATCHDOG
)) {
583 wl1271_error("watchdog interrupt received! "
584 "starting recovery.");
585 wl12xx_queue_recovery_work(wl
);
587 /* restarting the chip. ignore any other interrupt. */
591 if (likely(intr
& WL1271_ACX_INTR_DATA
)) {
592 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_DATA");
594 wl12xx_rx(wl
, wl
->fw_status
);
596 /* Check if any tx blocks were freed */
597 spin_lock_irqsave(&wl
->wl_lock
, flags
);
598 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
599 wl1271_tx_total_queue_count(wl
) > 0) {
600 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
602 * In order to avoid starvation of the TX path,
603 * call the work function directly.
605 wl1271_tx_work_locked(wl
);
607 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
610 /* check for tx results */
611 wlcore_hw_tx_delayed_compl(wl
);
613 /* Make sure the deferred queues don't get too long */
614 defer_count
= skb_queue_len(&wl
->deferred_tx_queue
) +
615 skb_queue_len(&wl
->deferred_rx_queue
);
616 if (defer_count
> WL1271_DEFERRED_QUEUE_LIMIT
)
617 wl1271_flush_deferred_work(wl
);
620 if (intr
& WL1271_ACX_INTR_EVENT_A
) {
621 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_A");
622 wl1271_event_handle(wl
, 0);
625 if (intr
& WL1271_ACX_INTR_EVENT_B
) {
626 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_EVENT_B");
627 wl1271_event_handle(wl
, 1);
630 if (intr
& WL1271_ACX_INTR_INIT_COMPLETE
)
631 wl1271_debug(DEBUG_IRQ
,
632 "WL1271_ACX_INTR_INIT_COMPLETE");
634 if (intr
& WL1271_ACX_INTR_HW_AVAILABLE
)
635 wl1271_debug(DEBUG_IRQ
, "WL1271_ACX_INTR_HW_AVAILABLE");
638 wl1271_ps_elp_sleep(wl
);
641 spin_lock_irqsave(&wl
->wl_lock
, flags
);
642 /* In case TX was not handled here, queue TX work */
643 clear_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
);
644 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
645 wl1271_tx_total_queue_count(wl
) > 0)
646 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
647 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
649 mutex_unlock(&wl
->mutex
);
654 struct vif_counter_data
{
657 struct ieee80211_vif
*cur_vif
;
658 bool cur_vif_running
;
661 static void wl12xx_vif_count_iter(void *data
, u8
*mac
,
662 struct ieee80211_vif
*vif
)
664 struct vif_counter_data
*counter
= data
;
667 if (counter
->cur_vif
== vif
)
668 counter
->cur_vif_running
= true;
671 /* caller must not hold wl->mutex, as it might deadlock */
672 static void wl12xx_get_vif_count(struct ieee80211_hw
*hw
,
673 struct ieee80211_vif
*cur_vif
,
674 struct vif_counter_data
*data
)
676 memset(data
, 0, sizeof(*data
));
677 data
->cur_vif
= cur_vif
;
679 ieee80211_iterate_active_interfaces(hw
,
680 wl12xx_vif_count_iter
, data
);
683 static int wl12xx_fetch_firmware(struct wl1271
*wl
, bool plt
)
685 const struct firmware
*fw
;
687 enum wl12xx_fw_type fw_type
;
691 fw_type
= WL12XX_FW_TYPE_PLT
;
692 fw_name
= wl
->plt_fw_name
;
695 * we can't call wl12xx_get_vif_count() here because
696 * wl->mutex is taken, so use the cached last_vif_count value
698 if (wl
->last_vif_count
> 1) {
699 fw_type
= WL12XX_FW_TYPE_MULTI
;
700 fw_name
= wl
->mr_fw_name
;
702 fw_type
= WL12XX_FW_TYPE_NORMAL
;
703 fw_name
= wl
->sr_fw_name
;
707 if (wl
->fw_type
== fw_type
)
710 wl1271_debug(DEBUG_BOOT
, "booting firmware %s", fw_name
);
712 ret
= request_firmware(&fw
, fw_name
, wl
->dev
);
715 wl1271_error("could not get firmware %s: %d", fw_name
, ret
);
720 wl1271_error("firmware size is not multiple of 32 bits: %zu",
727 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
728 wl
->fw_len
= fw
->size
;
729 wl
->fw
= vmalloc(wl
->fw_len
);
732 wl1271_error("could not allocate memory for the firmware");
737 memcpy(wl
->fw
, fw
->data
, wl
->fw_len
);
739 wl
->fw_type
= fw_type
;
741 release_firmware(fw
);
746 static int wl1271_fetch_nvs(struct wl1271
*wl
)
748 const struct firmware
*fw
;
751 ret
= request_firmware(&fw
, WL12XX_NVS_NAME
, wl
->dev
);
754 wl1271_error("could not get nvs file %s: %d", WL12XX_NVS_NAME
,
759 wl
->nvs
= kmemdup(fw
->data
, fw
->size
, GFP_KERNEL
);
762 wl1271_error("could not allocate memory for the nvs file");
767 wl
->nvs_len
= fw
->size
;
770 release_firmware(fw
);
775 void wl12xx_queue_recovery_work(struct wl1271
*wl
)
777 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
))
778 ieee80211_queue_work(wl
->hw
, &wl
->recovery_work
);
781 size_t wl12xx_copy_fwlog(struct wl1271
*wl
, u8
*memblock
, size_t maxlen
)
785 /* The FW log is a length-value list, find where the log end */
786 while (len
< maxlen
) {
787 if (memblock
[len
] == 0)
789 if (len
+ memblock
[len
] + 1 > maxlen
)
791 len
+= memblock
[len
] + 1;
794 /* Make sure we have enough room */
795 len
= min(len
, (size_t)(PAGE_SIZE
- wl
->fwlog_size
));
797 /* Fill the FW log file, consumed by the sysfs fwlog entry */
798 memcpy(wl
->fwlog
+ wl
->fwlog_size
, memblock
, len
);
799 wl
->fwlog_size
+= len
;
804 static void wl12xx_read_fwlog_panic(struct wl1271
*wl
)
810 if ((wl
->quirks
& WLCORE_QUIRK_FWLOG_NOT_IMPLEMENTED
) ||
811 (wl
->conf
.fwlog
.mode
!= WL12XX_FWLOG_ON_DEMAND
) ||
812 (wl
->conf
.fwlog
.mem_blocks
== 0))
815 wl1271_info("Reading FW panic log");
817 block
= kmalloc(WL12XX_HW_BLOCK_SIZE
, GFP_KERNEL
);
822 * Make sure the chip is awake and the logger isn't active.
823 * This might fail if the firmware hanged.
825 if (!wl1271_ps_elp_wakeup(wl
))
826 wl12xx_cmd_stop_fwlog(wl
);
828 /* Read the first memory block address */
829 wl12xx_fw_status(wl
, wl
->fw_status
);
830 first_addr
= le32_to_cpu(wl
->fw_status
->log_start_addr
);
834 /* Traverse the memory blocks linked list */
837 memset(block
, 0, WL12XX_HW_BLOCK_SIZE
);
838 wl1271_read_hwaddr(wl
, addr
, block
, WL12XX_HW_BLOCK_SIZE
,
842 * Memory blocks are linked to one another. The first 4 bytes
843 * of each memory block hold the hardware address of the next
844 * one. The last memory block points to the first one.
846 addr
= le32_to_cpup((__le32
*)block
);
847 if (!wl12xx_copy_fwlog(wl
, block
+ sizeof(addr
),
848 WL12XX_HW_BLOCK_SIZE
- sizeof(addr
)))
850 } while (addr
&& (addr
!= first_addr
));
852 wake_up_interruptible(&wl
->fwlog_waitq
);
858 static void wl1271_recovery_work(struct work_struct
*work
)
861 container_of(work
, struct wl1271
, recovery_work
);
862 struct wl12xx_vif
*wlvif
;
863 struct ieee80211_vif
*vif
;
865 mutex_lock(&wl
->mutex
);
867 if (wl
->state
!= WL1271_STATE_ON
|| wl
->plt
)
870 /* Avoid a recursive recovery */
871 set_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
873 wl12xx_read_fwlog_panic(wl
);
875 wl1271_info("Hardware recovery in progress. FW ver: %s pc: 0x%x",
877 wlcore_read_reg(wl
, REG_PC_ON_RECOVERY
));
879 BUG_ON(bug_on_recovery
&&
880 !test_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
));
883 wl1271_info("No recovery (chosen on module load). Fw will remain stuck.");
884 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
888 BUG_ON(bug_on_recovery
);
891 * Advance security sequence number to overcome potential progress
892 * in the firmware during recovery. This doens't hurt if the network is
895 wl12xx_for_each_wlvif(wl
, wlvif
) {
896 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) ||
897 test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
898 wlvif
->tx_security_seq
+=
899 WL1271_TX_SQN_POST_RECOVERY_PADDING
;
902 /* Prevent spurious TX during FW restart */
903 ieee80211_stop_queues(wl
->hw
);
905 if (wl
->sched_scanning
) {
906 ieee80211_sched_scan_stopped(wl
->hw
);
907 wl
->sched_scanning
= false;
910 /* reboot the chipset */
911 while (!list_empty(&wl
->wlvif_list
)) {
912 wlvif
= list_first_entry(&wl
->wlvif_list
,
913 struct wl12xx_vif
, list
);
914 vif
= wl12xx_wlvif_to_vif(wlvif
);
915 __wl1271_op_remove_interface(wl
, vif
, false);
917 mutex_unlock(&wl
->mutex
);
918 wl1271_op_stop(wl
->hw
);
920 clear_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
);
922 ieee80211_restart_hw(wl
->hw
);
925 * Its safe to enable TX now - the queues are stopped after a request
928 ieee80211_wake_queues(wl
->hw
);
931 mutex_unlock(&wl
->mutex
);
934 static void wl1271_fw_wakeup(struct wl1271
*wl
)
936 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG
, ELPCTRL_WAKE_UP
);
939 static int wl1271_setup(struct wl1271
*wl
)
941 wl
->fw_status
= kmalloc(sizeof(*wl
->fw_status
), GFP_KERNEL
);
945 wl
->tx_res_if
= kmalloc(sizeof(*wl
->tx_res_if
), GFP_KERNEL
);
946 if (!wl
->tx_res_if
) {
947 kfree(wl
->fw_status
);
954 static int wl12xx_set_power_on(struct wl1271
*wl
)
958 msleep(WL1271_PRE_POWER_ON_SLEEP
);
959 ret
= wl1271_power_on(wl
);
962 msleep(WL1271_POWER_ON_SLEEP
);
966 wlcore_set_partition(wl
, &wl
->ptable
[PART_BOOT
]);
968 /* ELP module wake up */
969 wl1271_fw_wakeup(wl
);
975 static int wl12xx_chip_wakeup(struct wl1271
*wl
, bool plt
)
979 ret
= wl12xx_set_power_on(wl
);
984 * For wl127x based devices we could use the default block
985 * size (512 bytes), but due to a bug in the sdio driver, we
986 * need to set it explicitly after the chip is powered on. To
987 * simplify the code and since the performance impact is
988 * negligible, we use the same block size for all different
991 if (wl1271_set_block_size(wl
))
992 wl
->quirks
|= WLCORE_QUIRK_TX_BLOCKSIZE_ALIGN
;
994 ret
= wl
->ops
->identify_chip(wl
);
998 /* TODO: make sure the lower driver has set things up correctly */
1000 ret
= wl1271_setup(wl
);
1004 ret
= wl12xx_fetch_firmware(wl
, plt
);
1008 /* No NVS from netlink, try to get it from the filesystem */
1009 if (wl
->nvs
== NULL
) {
1010 ret
= wl1271_fetch_nvs(wl
);
1019 int wl1271_plt_start(struct wl1271
*wl
)
1021 int retries
= WL1271_BOOT_RETRIES
;
1022 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1025 mutex_lock(&wl
->mutex
);
1027 wl1271_notice("power up");
1029 if (wl
->state
!= WL1271_STATE_OFF
) {
1030 wl1271_error("cannot go into PLT state because not "
1031 "in off state: %d", wl
->state
);
1038 ret
= wl12xx_chip_wakeup(wl
, true);
1042 ret
= wl
->ops
->boot(wl
);
1046 ret
= wl1271_plt_init(wl
);
1051 wl
->state
= WL1271_STATE_ON
;
1052 wl1271_notice("firmware booted in PLT mode (%s)",
1053 wl
->chip
.fw_ver_str
);
1055 /* update hw/fw version info in wiphy struct */
1056 wiphy
->hw_version
= wl
->chip
.id
;
1057 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
1058 sizeof(wiphy
->fw_version
));
1063 mutex_unlock(&wl
->mutex
);
1064 /* Unlocking the mutex in the middle of handling is
1065 inherently unsafe. In this case we deem it safe to do,
1066 because we need to let any possibly pending IRQ out of
1067 the system (and while we are WL1271_STATE_OFF the IRQ
1068 work function will not do anything.) Also, any other
1069 possible concurrent operations will fail due to the
1070 current state, hence the wl1271 struct should be safe. */
1071 wlcore_disable_interrupts(wl
);
1072 wl1271_flush_deferred_work(wl
);
1073 cancel_work_sync(&wl
->netstack_work
);
1074 mutex_lock(&wl
->mutex
);
1076 wl1271_power_off(wl
);
1079 wl1271_error("firmware boot in PLT mode failed despite %d retries",
1080 WL1271_BOOT_RETRIES
);
1082 mutex_unlock(&wl
->mutex
);
1087 int wl1271_plt_stop(struct wl1271
*wl
)
1091 wl1271_notice("power down");
1094 * Interrupts must be disabled before setting the state to OFF.
1095 * Otherwise, the interrupt handler might be called and exit without
1096 * reading the interrupt status.
1098 wlcore_disable_interrupts(wl
);
1099 mutex_lock(&wl
->mutex
);
1101 mutex_unlock(&wl
->mutex
);
1104 * This will not necessarily enable interrupts as interrupts
1105 * may have been disabled when op_stop was called. It will,
1106 * however, balance the above call to disable_interrupts().
1108 wlcore_enable_interrupts(wl
);
1110 wl1271_error("cannot power down because not in PLT "
1111 "state: %d", wl
->state
);
1116 mutex_unlock(&wl
->mutex
);
1118 wl1271_flush_deferred_work(wl
);
1119 cancel_work_sync(&wl
->netstack_work
);
1120 cancel_work_sync(&wl
->recovery_work
);
1121 cancel_delayed_work_sync(&wl
->elp_work
);
1122 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1123 cancel_delayed_work_sync(&wl
->connection_loss_work
);
1125 mutex_lock(&wl
->mutex
);
1126 wl1271_power_off(wl
);
1128 wl
->state
= WL1271_STATE_OFF
;
1131 mutex_unlock(&wl
->mutex
);
1137 static void wl1271_op_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1139 struct wl1271
*wl
= hw
->priv
;
1140 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
1141 struct ieee80211_vif
*vif
= info
->control
.vif
;
1142 struct wl12xx_vif
*wlvif
= NULL
;
1143 unsigned long flags
;
1148 wlvif
= wl12xx_vif_to_data(vif
);
1150 mapping
= skb_get_queue_mapping(skb
);
1151 q
= wl1271_tx_get_queue(mapping
);
1153 hlid
= wl12xx_tx_get_hlid(wl
, wlvif
, skb
);
1155 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1157 /* queue the packet */
1158 if (hlid
== WL12XX_INVALID_LINK_ID
||
1159 (wlvif
&& !test_bit(hlid
, wlvif
->links_map
))) {
1160 wl1271_debug(DEBUG_TX
, "DROP skb hlid %d q %d", hlid
, q
);
1161 ieee80211_free_txskb(hw
, skb
);
1165 wl1271_debug(DEBUG_TX
, "queue skb hlid %d q %d len %d",
1167 skb_queue_tail(&wl
->links
[hlid
].tx_queue
[q
], skb
);
1169 wl
->tx_queue_count
[q
]++;
1172 * The workqueue is slow to process the tx_queue and we need stop
1173 * the queue here, otherwise the queue will get too long.
1175 if (wl
->tx_queue_count
[q
] >= WL1271_TX_QUEUE_HIGH_WATERMARK
) {
1176 wl1271_debug(DEBUG_TX
, "op_tx: stopping queues for q %d", q
);
1177 ieee80211_stop_queue(wl
->hw
, mapping
);
1178 set_bit(q
, &wl
->stopped_queues_map
);
1182 * The chip specific setup must run before the first TX packet -
1183 * before that, the tx_work will not be initialized!
1186 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
) &&
1187 !test_bit(WL1271_FLAG_TX_PENDING
, &wl
->flags
))
1188 ieee80211_queue_work(wl
->hw
, &wl
->tx_work
);
1191 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1194 int wl1271_tx_dummy_packet(struct wl1271
*wl
)
1196 unsigned long flags
;
1199 /* no need to queue a new dummy packet if one is already pending */
1200 if (test_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
))
1203 q
= wl1271_tx_get_queue(skb_get_queue_mapping(wl
->dummy_packet
));
1205 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1206 set_bit(WL1271_FLAG_DUMMY_PACKET_PENDING
, &wl
->flags
);
1207 wl
->tx_queue_count
[q
]++;
1208 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1210 /* The FW is low on RX memory blocks, so send the dummy packet asap */
1211 if (!test_bit(WL1271_FLAG_FW_TX_BUSY
, &wl
->flags
))
1212 wl1271_tx_work_locked(wl
);
1215 * If the FW TX is busy, TX work will be scheduled by the threaded
1216 * interrupt handler function
1222 * The size of the dummy packet should be at least 1400 bytes. However, in
1223 * order to minimize the number of bus transactions, aligning it to 512 bytes
1224 * boundaries could be beneficial, performance wise
1226 #define TOTAL_TX_DUMMY_PACKET_SIZE (ALIGN(1400, 512))
1228 static struct sk_buff
*wl12xx_alloc_dummy_packet(struct wl1271
*wl
)
1230 struct sk_buff
*skb
;
1231 struct ieee80211_hdr_3addr
*hdr
;
1232 unsigned int dummy_packet_size
;
1234 dummy_packet_size
= TOTAL_TX_DUMMY_PACKET_SIZE
-
1235 sizeof(struct wl1271_tx_hw_descr
) - sizeof(*hdr
);
1237 skb
= dev_alloc_skb(TOTAL_TX_DUMMY_PACKET_SIZE
);
1239 wl1271_warning("Failed to allocate a dummy packet skb");
1243 skb_reserve(skb
, sizeof(struct wl1271_tx_hw_descr
));
1245 hdr
= (struct ieee80211_hdr_3addr
*) skb_put(skb
, sizeof(*hdr
));
1246 memset(hdr
, 0, sizeof(*hdr
));
1247 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_DATA
|
1248 IEEE80211_STYPE_NULLFUNC
|
1249 IEEE80211_FCTL_TODS
);
1251 memset(skb_put(skb
, dummy_packet_size
), 0, dummy_packet_size
);
1253 /* Dummy packets require the TID to be management */
1254 skb
->priority
= WL1271_TID_MGMT
;
1256 /* Initialize all fields that might be used */
1257 skb_set_queue_mapping(skb
, 0);
1258 memset(IEEE80211_SKB_CB(skb
), 0, sizeof(struct ieee80211_tx_info
));
1266 wl1271_validate_wowlan_pattern(struct cfg80211_wowlan_trig_pkt_pattern
*p
)
1268 int num_fields
= 0, in_field
= 0, fields_size
= 0;
1269 int i
, pattern_len
= 0;
1272 wl1271_warning("No mask in WoWLAN pattern");
1277 * The pattern is broken up into segments of bytes at different offsets
1278 * that need to be checked by the FW filter. Each segment is called
1279 * a field in the FW API. We verify that the total number of fields
1280 * required for this pattern won't exceed FW limits (8)
1281 * as well as the total fields buffer won't exceed the FW limit.
1282 * Note that if there's a pattern which crosses Ethernet/IP header
1283 * boundary a new field is required.
1285 for (i
= 0; i
< p
->pattern_len
; i
++) {
1286 if (test_bit(i
, (unsigned long *)p
->mask
)) {
1291 if (i
== WL1271_RX_FILTER_ETH_HEADER_SIZE
) {
1293 fields_size
+= pattern_len
+
1294 RX_FILTER_FIELD_OVERHEAD
;
1302 fields_size
+= pattern_len
+
1303 RX_FILTER_FIELD_OVERHEAD
;
1310 fields_size
+= pattern_len
+ RX_FILTER_FIELD_OVERHEAD
;
1314 if (num_fields
> WL1271_RX_FILTER_MAX_FIELDS
) {
1315 wl1271_warning("RX Filter too complex. Too many segments");
1319 if (fields_size
> WL1271_RX_FILTER_MAX_FIELDS_SIZE
) {
1320 wl1271_warning("RX filter pattern is too big");
1327 struct wl12xx_rx_filter
*wl1271_rx_filter_alloc(void)
1329 return kzalloc(sizeof(struct wl12xx_rx_filter
), GFP_KERNEL
);
1332 void wl1271_rx_filter_free(struct wl12xx_rx_filter
*filter
)
1339 for (i
= 0; i
< filter
->num_fields
; i
++)
1340 kfree(filter
->fields
[i
].pattern
);
1345 int wl1271_rx_filter_alloc_field(struct wl12xx_rx_filter
*filter
,
1346 u16 offset
, u8 flags
,
1347 u8
*pattern
, u8 len
)
1349 struct wl12xx_rx_filter_field
*field
;
1351 if (filter
->num_fields
== WL1271_RX_FILTER_MAX_FIELDS
) {
1352 wl1271_warning("Max fields per RX filter. can't alloc another");
1356 field
= &filter
->fields
[filter
->num_fields
];
1358 field
->pattern
= kzalloc(len
, GFP_KERNEL
);
1359 if (!field
->pattern
) {
1360 wl1271_warning("Failed to allocate RX filter pattern");
1364 filter
->num_fields
++;
1366 field
->offset
= cpu_to_le16(offset
);
1367 field
->flags
= flags
;
1369 memcpy(field
->pattern
, pattern
, len
);
1374 int wl1271_rx_filter_get_fields_size(struct wl12xx_rx_filter
*filter
)
1376 int i
, fields_size
= 0;
1378 for (i
= 0; i
< filter
->num_fields
; i
++)
1379 fields_size
+= filter
->fields
[i
].len
+
1380 sizeof(struct wl12xx_rx_filter_field
) -
1386 void wl1271_rx_filter_flatten_fields(struct wl12xx_rx_filter
*filter
,
1390 struct wl12xx_rx_filter_field
*field
;
1392 for (i
= 0; i
< filter
->num_fields
; i
++) {
1393 field
= (struct wl12xx_rx_filter_field
*)buf
;
1395 field
->offset
= filter
->fields
[i
].offset
;
1396 field
->flags
= filter
->fields
[i
].flags
;
1397 field
->len
= filter
->fields
[i
].len
;
1399 memcpy(&field
->pattern
, filter
->fields
[i
].pattern
, field
->len
);
1400 buf
+= sizeof(struct wl12xx_rx_filter_field
) -
1401 sizeof(u8
*) + field
->len
;
1406 * Allocates an RX filter returned through f
1407 * which needs to be freed using rx_filter_free()
1409 static int wl1271_convert_wowlan_pattern_to_rx_filter(
1410 struct cfg80211_wowlan_trig_pkt_pattern
*p
,
1411 struct wl12xx_rx_filter
**f
)
1414 struct wl12xx_rx_filter
*filter
;
1418 filter
= wl1271_rx_filter_alloc();
1420 wl1271_warning("Failed to alloc rx filter");
1426 while (i
< p
->pattern_len
) {
1427 if (!test_bit(i
, (unsigned long *)p
->mask
)) {
1432 for (j
= i
; j
< p
->pattern_len
; j
++) {
1433 if (!test_bit(j
, (unsigned long *)p
->mask
))
1436 if (i
< WL1271_RX_FILTER_ETH_HEADER_SIZE
&&
1437 j
>= WL1271_RX_FILTER_ETH_HEADER_SIZE
)
1441 if (i
< WL1271_RX_FILTER_ETH_HEADER_SIZE
) {
1443 flags
= WL1271_RX_FILTER_FLAG_ETHERNET_HEADER
;
1445 offset
= i
- WL1271_RX_FILTER_ETH_HEADER_SIZE
;
1446 flags
= WL1271_RX_FILTER_FLAG_IP_HEADER
;
1451 ret
= wl1271_rx_filter_alloc_field(filter
,
1454 &p
->pattern
[i
], len
);
1461 filter
->action
= FILTER_SIGNAL
;
1467 wl1271_rx_filter_free(filter
);
1473 static int wl1271_configure_wowlan(struct wl1271
*wl
,
1474 struct cfg80211_wowlan
*wow
)
1478 if (!wow
|| wow
->any
|| !wow
->n_patterns
) {
1479 wl1271_acx_default_rx_filter_enable(wl
, 0, FILTER_SIGNAL
);
1480 wl1271_rx_filter_clear_all(wl
);
1484 if (WARN_ON(wow
->n_patterns
> WL1271_MAX_RX_FILTERS
))
1487 /* Validate all incoming patterns before clearing current FW state */
1488 for (i
= 0; i
< wow
->n_patterns
; i
++) {
1489 ret
= wl1271_validate_wowlan_pattern(&wow
->patterns
[i
]);
1491 wl1271_warning("Bad wowlan pattern %d", i
);
1496 wl1271_acx_default_rx_filter_enable(wl
, 0, FILTER_SIGNAL
);
1497 wl1271_rx_filter_clear_all(wl
);
1499 /* Translate WoWLAN patterns into filters */
1500 for (i
= 0; i
< wow
->n_patterns
; i
++) {
1501 struct cfg80211_wowlan_trig_pkt_pattern
*p
;
1502 struct wl12xx_rx_filter
*filter
= NULL
;
1504 p
= &wow
->patterns
[i
];
1506 ret
= wl1271_convert_wowlan_pattern_to_rx_filter(p
, &filter
);
1508 wl1271_warning("Failed to create an RX filter from "
1509 "wowlan pattern %d", i
);
1513 ret
= wl1271_rx_filter_enable(wl
, i
, 1, filter
);
1515 wl1271_rx_filter_free(filter
);
1520 ret
= wl1271_acx_default_rx_filter_enable(wl
, 1, FILTER_DROP
);
1526 static int wl1271_configure_suspend_sta(struct wl1271
*wl
,
1527 struct wl12xx_vif
*wlvif
,
1528 struct cfg80211_wowlan
*wow
)
1532 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
1535 ret
= wl1271_ps_elp_wakeup(wl
);
1539 wl1271_configure_wowlan(wl
, wow
);
1540 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1541 wl
->conf
.conn
.suspend_wake_up_event
,
1542 wl
->conf
.conn
.suspend_listen_interval
);
1545 wl1271_error("suspend: set wake up conditions failed: %d", ret
);
1547 wl1271_ps_elp_sleep(wl
);
1554 static int wl1271_configure_suspend_ap(struct wl1271
*wl
,
1555 struct wl12xx_vif
*wlvif
)
1559 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
))
1562 ret
= wl1271_ps_elp_wakeup(wl
);
1566 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, true);
1568 wl1271_ps_elp_sleep(wl
);
1574 static int wl1271_configure_suspend(struct wl1271
*wl
,
1575 struct wl12xx_vif
*wlvif
,
1576 struct cfg80211_wowlan
*wow
)
1578 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
)
1579 return wl1271_configure_suspend_sta(wl
, wlvif
, wow
);
1580 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
1581 return wl1271_configure_suspend_ap(wl
, wlvif
);
1585 static void wl1271_configure_resume(struct wl1271
*wl
,
1586 struct wl12xx_vif
*wlvif
)
1589 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
1590 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
1592 if ((!is_ap
) && (!is_sta
))
1595 ret
= wl1271_ps_elp_wakeup(wl
);
1600 wl1271_configure_wowlan(wl
, NULL
);
1602 ret
= wl1271_acx_wake_up_conditions(wl
, wlvif
,
1603 wl
->conf
.conn
.wake_up_event
,
1604 wl
->conf
.conn
.listen_interval
);
1607 wl1271_error("resume: wake up conditions failed: %d",
1611 ret
= wl1271_acx_beacon_filter_opt(wl
, wlvif
, false);
1614 wl1271_ps_elp_sleep(wl
);
1617 static int wl1271_op_suspend(struct ieee80211_hw
*hw
,
1618 struct cfg80211_wowlan
*wow
)
1620 struct wl1271
*wl
= hw
->priv
;
1621 struct wl12xx_vif
*wlvif
;
1624 wl1271_debug(DEBUG_MAC80211
, "mac80211 suspend wow=%d", !!wow
);
1627 wl1271_tx_flush(wl
);
1629 mutex_lock(&wl
->mutex
);
1630 wl
->wow_enabled
= true;
1631 wl12xx_for_each_wlvif(wl
, wlvif
) {
1632 ret
= wl1271_configure_suspend(wl
, wlvif
, wow
);
1634 mutex_unlock(&wl
->mutex
);
1635 wl1271_warning("couldn't prepare device to suspend");
1639 mutex_unlock(&wl
->mutex
);
1640 /* flush any remaining work */
1641 wl1271_debug(DEBUG_MAC80211
, "flushing remaining works");
1644 * disable and re-enable interrupts in order to flush
1647 wlcore_disable_interrupts(wl
);
1650 * set suspended flag to avoid triggering a new threaded_irq
1651 * work. no need for spinlock as interrupts are disabled.
1653 set_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1655 wlcore_enable_interrupts(wl
);
1656 flush_work(&wl
->tx_work
);
1657 flush_delayed_work(&wl
->elp_work
);
1662 static int wl1271_op_resume(struct ieee80211_hw
*hw
)
1664 struct wl1271
*wl
= hw
->priv
;
1665 struct wl12xx_vif
*wlvif
;
1666 unsigned long flags
;
1667 bool run_irq_work
= false;
1669 wl1271_debug(DEBUG_MAC80211
, "mac80211 resume wow=%d",
1671 WARN_ON(!wl
->wow_enabled
);
1674 * re-enable irq_work enqueuing, and call irq_work directly if
1675 * there is a pending work.
1677 spin_lock_irqsave(&wl
->wl_lock
, flags
);
1678 clear_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
);
1679 if (test_and_clear_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
))
1680 run_irq_work
= true;
1681 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
1684 wl1271_debug(DEBUG_MAC80211
,
1685 "run postponed irq_work directly");
1687 wlcore_enable_interrupts(wl
);
1690 mutex_lock(&wl
->mutex
);
1691 wl12xx_for_each_wlvif(wl
, wlvif
) {
1692 wl1271_configure_resume(wl
, wlvif
);
1694 wl
->wow_enabled
= false;
1695 mutex_unlock(&wl
->mutex
);
1701 static int wl1271_op_start(struct ieee80211_hw
*hw
)
1703 wl1271_debug(DEBUG_MAC80211
, "mac80211 start");
1706 * We have to delay the booting of the hardware because
1707 * we need to know the local MAC address before downloading and
1708 * initializing the firmware. The MAC address cannot be changed
1709 * after boot, and without the proper MAC address, the firmware
1710 * will not function properly.
1712 * The MAC address is first known when the corresponding interface
1713 * is added. That is where we will initialize the hardware.
1719 static void wl1271_op_stop(struct ieee80211_hw
*hw
)
1721 struct wl1271
*wl
= hw
->priv
;
1724 wl1271_debug(DEBUG_MAC80211
, "mac80211 stop");
1727 * Interrupts must be disabled before setting the state to OFF.
1728 * Otherwise, the interrupt handler might be called and exit without
1729 * reading the interrupt status.
1731 wlcore_disable_interrupts(wl
);
1732 mutex_lock(&wl
->mutex
);
1733 if (wl
->state
== WL1271_STATE_OFF
) {
1734 mutex_unlock(&wl
->mutex
);
1737 * This will not necessarily enable interrupts as interrupts
1738 * may have been disabled when op_stop was called. It will,
1739 * however, balance the above call to disable_interrupts().
1741 wlcore_enable_interrupts(wl
);
1746 * this must be before the cancel_work calls below, so that the work
1747 * functions don't perform further work.
1749 wl
->state
= WL1271_STATE_OFF
;
1750 mutex_unlock(&wl
->mutex
);
1752 wl1271_flush_deferred_work(wl
);
1753 cancel_delayed_work_sync(&wl
->scan_complete_work
);
1754 cancel_work_sync(&wl
->netstack_work
);
1755 cancel_work_sync(&wl
->tx_work
);
1756 cancel_delayed_work_sync(&wl
->elp_work
);
1757 cancel_delayed_work_sync(&wl
->tx_watchdog_work
);
1758 cancel_delayed_work_sync(&wl
->connection_loss_work
);
1760 /* let's notify MAC80211 about the remaining pending TX frames */
1761 wl12xx_tx_reset(wl
, true);
1762 mutex_lock(&wl
->mutex
);
1764 wl1271_power_off(wl
);
1766 wl
->band
= IEEE80211_BAND_2GHZ
;
1769 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
1770 wl
->channel_type
= NL80211_CHAN_NO_HT
;
1771 wl
->tx_blocks_available
= 0;
1772 wl
->tx_allocated_blocks
= 0;
1773 wl
->tx_results_count
= 0;
1774 wl
->tx_packets_count
= 0;
1775 wl
->time_offset
= 0;
1776 wl
->ap_fw_ps_map
= 0;
1778 wl
->sched_scanning
= false;
1779 memset(wl
->roles_map
, 0, sizeof(wl
->roles_map
));
1780 memset(wl
->links_map
, 0, sizeof(wl
->links_map
));
1781 memset(wl
->roc_map
, 0, sizeof(wl
->roc_map
));
1782 wl
->active_sta_count
= 0;
1784 /* The system link is always allocated */
1785 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
1788 * this is performed after the cancel_work calls and the associated
1789 * mutex_lock, so that wl1271_op_add_interface does not accidentally
1790 * get executed before all these vars have been reset.
1794 wl
->tx_blocks_freed
= 0;
1796 for (i
= 0; i
< NUM_TX_QUEUES
; i
++) {
1797 wl
->tx_pkts_freed
[i
] = 0;
1798 wl
->tx_allocated_pkts
[i
] = 0;
1801 wl1271_debugfs_reset(wl
);
1803 kfree(wl
->fw_status
);
1804 wl
->fw_status
= NULL
;
1805 kfree(wl
->tx_res_if
);
1806 wl
->tx_res_if
= NULL
;
1807 kfree(wl
->target_mem_map
);
1808 wl
->target_mem_map
= NULL
;
1810 mutex_unlock(&wl
->mutex
);
1813 static int wl12xx_allocate_rate_policy(struct wl1271
*wl
, u8
*idx
)
1815 u8 policy
= find_first_zero_bit(wl
->rate_policies_map
,
1816 WL12XX_MAX_RATE_POLICIES
);
1817 if (policy
>= WL12XX_MAX_RATE_POLICIES
)
1820 __set_bit(policy
, wl
->rate_policies_map
);
1825 static void wl12xx_free_rate_policy(struct wl1271
*wl
, u8
*idx
)
1827 if (WARN_ON(*idx
>= WL12XX_MAX_RATE_POLICIES
))
1830 __clear_bit(*idx
, wl
->rate_policies_map
);
1831 *idx
= WL12XX_MAX_RATE_POLICIES
;
1834 static u8
wl12xx_get_role_type(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
1836 switch (wlvif
->bss_type
) {
1837 case BSS_TYPE_AP_BSS
:
1839 return WL1271_ROLE_P2P_GO
;
1841 return WL1271_ROLE_AP
;
1843 case BSS_TYPE_STA_BSS
:
1845 return WL1271_ROLE_P2P_CL
;
1847 return WL1271_ROLE_STA
;
1850 return WL1271_ROLE_IBSS
;
1853 wl1271_error("invalid bss_type: %d", wlvif
->bss_type
);
1855 return WL12XX_INVALID_ROLE_TYPE
;
1858 static int wl12xx_init_vif_data(struct wl1271
*wl
, struct ieee80211_vif
*vif
)
1860 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
1863 /* clear everything but the persistent data */
1864 memset(wlvif
, 0, offsetof(struct wl12xx_vif
, persistent
));
1866 switch (ieee80211_vif_type_p2p(vif
)) {
1867 case NL80211_IFTYPE_P2P_CLIENT
:
1870 case NL80211_IFTYPE_STATION
:
1871 wlvif
->bss_type
= BSS_TYPE_STA_BSS
;
1873 case NL80211_IFTYPE_ADHOC
:
1874 wlvif
->bss_type
= BSS_TYPE_IBSS
;
1876 case NL80211_IFTYPE_P2P_GO
:
1879 case NL80211_IFTYPE_AP
:
1880 wlvif
->bss_type
= BSS_TYPE_AP_BSS
;
1883 wlvif
->bss_type
= MAX_BSS_TYPE
;
1887 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
1888 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
1889 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
1891 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
1892 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
1893 /* init sta/ibss data */
1894 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
1895 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
1896 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
1897 wl12xx_allocate_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
1900 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
1901 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
1902 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
1903 wl12xx_allocate_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
1904 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
1905 wl12xx_allocate_rate_policy(wl
,
1906 &wlvif
->ap
.ucast_rate_idx
[i
]);
1909 wlvif
->bitrate_masks
[IEEE80211_BAND_2GHZ
] = wl
->conf
.tx
.basic_rate
;
1910 wlvif
->bitrate_masks
[IEEE80211_BAND_5GHZ
] = wl
->conf
.tx
.basic_rate_5
;
1911 wlvif
->basic_rate_set
= CONF_TX_RATE_MASK_BASIC
;
1912 wlvif
->basic_rate
= CONF_TX_RATE_MASK_BASIC
;
1913 wlvif
->rate_set
= CONF_TX_RATE_MASK_BASIC
;
1914 wlvif
->beacon_int
= WL1271_DEFAULT_BEACON_INT
;
1917 * mac80211 configures some values globally, while we treat them
1918 * per-interface. thus, on init, we have to copy them from wl
1920 wlvif
->band
= wl
->band
;
1921 wlvif
->channel
= wl
->channel
;
1922 wlvif
->power_level
= wl
->power_level
;
1923 wlvif
->channel_type
= wl
->channel_type
;
1925 INIT_WORK(&wlvif
->rx_streaming_enable_work
,
1926 wl1271_rx_streaming_enable_work
);
1927 INIT_WORK(&wlvif
->rx_streaming_disable_work
,
1928 wl1271_rx_streaming_disable_work
);
1929 INIT_LIST_HEAD(&wlvif
->list
);
1931 setup_timer(&wlvif
->rx_streaming_timer
, wl1271_rx_streaming_timer
,
1932 (unsigned long) wlvif
);
1936 static bool wl12xx_init_fw(struct wl1271
*wl
)
1938 int retries
= WL1271_BOOT_RETRIES
;
1939 bool booted
= false;
1940 struct wiphy
*wiphy
= wl
->hw
->wiphy
;
1945 ret
= wl12xx_chip_wakeup(wl
, false);
1949 ret
= wl
->ops
->boot(wl
);
1953 ret
= wl1271_hw_init(wl
);
1961 mutex_unlock(&wl
->mutex
);
1962 /* Unlocking the mutex in the middle of handling is
1963 inherently unsafe. In this case we deem it safe to do,
1964 because we need to let any possibly pending IRQ out of
1965 the system (and while we are WL1271_STATE_OFF the IRQ
1966 work function will not do anything.) Also, any other
1967 possible concurrent operations will fail due to the
1968 current state, hence the wl1271 struct should be safe. */
1969 wlcore_disable_interrupts(wl
);
1970 wl1271_flush_deferred_work(wl
);
1971 cancel_work_sync(&wl
->netstack_work
);
1972 mutex_lock(&wl
->mutex
);
1974 wl1271_power_off(wl
);
1978 wl1271_error("firmware boot failed despite %d retries",
1979 WL1271_BOOT_RETRIES
);
1983 wl1271_info("firmware booted (%s)", wl
->chip
.fw_ver_str
);
1985 /* update hw/fw version info in wiphy struct */
1986 wiphy
->hw_version
= wl
->chip
.id
;
1987 strncpy(wiphy
->fw_version
, wl
->chip
.fw_ver_str
,
1988 sizeof(wiphy
->fw_version
));
1991 * Now we know if 11a is supported (info from the NVS), so disable
1992 * 11a channels if not supported
1994 if (!wl
->enable_11a
)
1995 wiphy
->bands
[IEEE80211_BAND_5GHZ
]->n_channels
= 0;
1997 wl1271_debug(DEBUG_MAC80211
, "11a is %ssupported",
1998 wl
->enable_11a
? "" : "not ");
2000 wl
->state
= WL1271_STATE_ON
;
2005 static bool wl12xx_dev_role_started(struct wl12xx_vif
*wlvif
)
2007 return wlvif
->dev_hlid
!= WL12XX_INVALID_LINK_ID
;
2011 * Check whether a fw switch (i.e. moving from one loaded
2012 * fw to another) is needed. This function is also responsible
2013 * for updating wl->last_vif_count, so it must be called before
2014 * loading a non-plt fw (so the correct fw (single-role/multi-role)
2017 static bool wl12xx_need_fw_change(struct wl1271
*wl
,
2018 struct vif_counter_data vif_counter_data
,
2021 enum wl12xx_fw_type current_fw
= wl
->fw_type
;
2022 u8 vif_count
= vif_counter_data
.counter
;
2024 if (test_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
))
2027 /* increase the vif count if this is a new vif */
2028 if (add
&& !vif_counter_data
.cur_vif_running
)
2031 wl
->last_vif_count
= vif_count
;
2033 /* no need for fw change if the device is OFF */
2034 if (wl
->state
== WL1271_STATE_OFF
)
2037 if (vif_count
> 1 && current_fw
== WL12XX_FW_TYPE_NORMAL
)
2039 if (vif_count
<= 1 && current_fw
== WL12XX_FW_TYPE_MULTI
)
2046 * Enter "forced psm". Make sure the sta is in psm against the ap,
2047 * to make the fw switch a bit more disconnection-persistent.
2049 static void wl12xx_force_active_psm(struct wl1271
*wl
)
2051 struct wl12xx_vif
*wlvif
;
2053 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
2054 wl1271_ps_set_mode(wl
, wlvif
, STATION_POWER_SAVE_MODE
);
2058 static int wl1271_op_add_interface(struct ieee80211_hw
*hw
,
2059 struct ieee80211_vif
*vif
)
2061 struct wl1271
*wl
= hw
->priv
;
2062 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2063 struct vif_counter_data vif_count
;
2066 bool booted
= false;
2068 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
2069 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
2071 wl1271_debug(DEBUG_MAC80211
, "mac80211 add interface type %d mac %pM",
2072 ieee80211_vif_type_p2p(vif
), vif
->addr
);
2074 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2076 mutex_lock(&wl
->mutex
);
2077 ret
= wl1271_ps_elp_wakeup(wl
);
2082 * in some very corner case HW recovery scenarios its possible to
2083 * get here before __wl1271_op_remove_interface is complete, so
2084 * opt out if that is the case.
2086 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
) ||
2087 test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)) {
2093 ret
= wl12xx_init_vif_data(wl
, vif
);
2098 role_type
= wl12xx_get_role_type(wl
, wlvif
);
2099 if (role_type
== WL12XX_INVALID_ROLE_TYPE
) {
2104 if (wl12xx_need_fw_change(wl
, vif_count
, true)) {
2105 wl12xx_force_active_psm(wl
);
2106 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2107 mutex_unlock(&wl
->mutex
);
2108 wl1271_recovery_work(&wl
->recovery_work
);
2113 * TODO: after the nvs issue will be solved, move this block
2114 * to start(), and make sure here the driver is ON.
2116 if (wl
->state
== WL1271_STATE_OFF
) {
2118 * we still need this in order to configure the fw
2119 * while uploading the nvs
2121 memcpy(wl
->addresses
[0].addr
, vif
->addr
, ETH_ALEN
);
2123 booted
= wl12xx_init_fw(wl
);
2130 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2131 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2133 * The device role is a special role used for
2134 * rx and tx frames prior to association (as
2135 * the STA role can get packets only from
2136 * its associated bssid)
2138 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2140 &wlvif
->dev_role_id
);
2145 ret
= wl12xx_cmd_role_enable(wl
, vif
->addr
,
2146 role_type
, &wlvif
->role_id
);
2150 ret
= wl1271_init_vif_specific(wl
, vif
);
2154 list_add(&wlvif
->list
, &wl
->wlvif_list
);
2155 set_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
);
2157 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2162 wl1271_ps_elp_sleep(wl
);
2164 mutex_unlock(&wl
->mutex
);
2169 static void __wl1271_op_remove_interface(struct wl1271
*wl
,
2170 struct ieee80211_vif
*vif
,
2171 bool reset_tx_queues
)
2173 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2176 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove interface");
2178 if (!test_and_clear_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2181 /* because of hardware recovery, we may get here twice */
2182 if (wl
->state
!= WL1271_STATE_ON
)
2185 wl1271_info("down");
2187 if (wl
->scan
.state
!= WL1271_SCAN_STATE_IDLE
&&
2188 wl
->scan_vif
== vif
) {
2190 * Rearm the tx watchdog just before idling scan. This
2191 * prevents just-finished scans from triggering the watchdog
2193 wl12xx_rearm_tx_watchdog_locked(wl
);
2195 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
2196 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
2197 wl
->scan_vif
= NULL
;
2198 wl
->scan
.req
= NULL
;
2199 ieee80211_scan_completed(wl
->hw
, true);
2202 if (!test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS
, &wl
->flags
)) {
2203 /* disable active roles */
2204 ret
= wl1271_ps_elp_wakeup(wl
);
2208 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2209 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2210 if (wl12xx_dev_role_started(wlvif
))
2211 wl12xx_stop_dev(wl
, wlvif
);
2213 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->dev_role_id
);
2218 ret
= wl12xx_cmd_role_disable(wl
, &wlvif
->role_id
);
2222 wl1271_ps_elp_sleep(wl
);
2225 /* clear all hlids (except system_hlid) */
2226 wlvif
->dev_hlid
= WL12XX_INVALID_LINK_ID
;
2228 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
||
2229 wlvif
->bss_type
== BSS_TYPE_IBSS
) {
2230 wlvif
->sta
.hlid
= WL12XX_INVALID_LINK_ID
;
2231 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.basic_rate_idx
);
2232 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.ap_rate_idx
);
2233 wl12xx_free_rate_policy(wl
, &wlvif
->sta
.p2p_rate_idx
);
2235 wlvif
->ap
.bcast_hlid
= WL12XX_INVALID_LINK_ID
;
2236 wlvif
->ap
.global_hlid
= WL12XX_INVALID_LINK_ID
;
2237 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.mgmt_rate_idx
);
2238 wl12xx_free_rate_policy(wl
, &wlvif
->ap
.bcast_rate_idx
);
2239 for (i
= 0; i
< CONF_TX_MAX_AC_COUNT
; i
++)
2240 wl12xx_free_rate_policy(wl
,
2241 &wlvif
->ap
.ucast_rate_idx
[i
]);
2242 wl1271_free_ap_keys(wl
, wlvif
);
2245 dev_kfree_skb(wlvif
->probereq
);
2246 wlvif
->probereq
= NULL
;
2247 wl12xx_tx_reset_wlvif(wl
, wlvif
);
2248 if (wl
->last_wlvif
== wlvif
)
2249 wl
->last_wlvif
= NULL
;
2250 list_del(&wlvif
->list
);
2251 memset(wlvif
->ap
.sta_hlid_map
, 0, sizeof(wlvif
->ap
.sta_hlid_map
));
2252 wlvif
->role_id
= WL12XX_INVALID_ROLE_ID
;
2253 wlvif
->dev_role_id
= WL12XX_INVALID_ROLE_ID
;
2255 if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
)
2260 mutex_unlock(&wl
->mutex
);
2262 del_timer_sync(&wlvif
->rx_streaming_timer
);
2263 cancel_work_sync(&wlvif
->rx_streaming_enable_work
);
2264 cancel_work_sync(&wlvif
->rx_streaming_disable_work
);
2266 mutex_lock(&wl
->mutex
);
2269 static void wl1271_op_remove_interface(struct ieee80211_hw
*hw
,
2270 struct ieee80211_vif
*vif
)
2272 struct wl1271
*wl
= hw
->priv
;
2273 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2274 struct wl12xx_vif
*iter
;
2275 struct vif_counter_data vif_count
;
2276 bool cancel_recovery
= true;
2278 wl12xx_get_vif_count(hw
, vif
, &vif_count
);
2279 mutex_lock(&wl
->mutex
);
2281 if (wl
->state
== WL1271_STATE_OFF
||
2282 !test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
2286 * wl->vif can be null here if someone shuts down the interface
2287 * just when hardware recovery has been started.
2289 wl12xx_for_each_wlvif(wl
, iter
) {
2293 __wl1271_op_remove_interface(wl
, vif
, true);
2296 WARN_ON(iter
!= wlvif
);
2297 if (wl12xx_need_fw_change(wl
, vif_count
, false)) {
2298 wl12xx_force_active_psm(wl
);
2299 set_bit(WL1271_FLAG_INTENDED_FW_RECOVERY
, &wl
->flags
);
2300 wl12xx_queue_recovery_work(wl
);
2301 cancel_recovery
= false;
2304 mutex_unlock(&wl
->mutex
);
2305 if (cancel_recovery
)
2306 cancel_work_sync(&wl
->recovery_work
);
2309 static int wl12xx_op_change_interface(struct ieee80211_hw
*hw
,
2310 struct ieee80211_vif
*vif
,
2311 enum nl80211_iftype new_type
, bool p2p
)
2313 struct wl1271
*wl
= hw
->priv
;
2316 set_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2317 wl1271_op_remove_interface(hw
, vif
);
2319 vif
->type
= new_type
;
2321 ret
= wl1271_op_add_interface(hw
, vif
);
2323 clear_bit(WL1271_FLAG_VIF_CHANGE_IN_PROGRESS
, &wl
->flags
);
2327 static int wl1271_join(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2331 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
2334 * One of the side effects of the JOIN command is that is clears
2335 * WPA/WPA2 keys from the chipset. Performing a JOIN while associated
2336 * to a WPA/WPA2 access point will therefore kill the data-path.
2337 * Currently the only valid scenario for JOIN during association
2338 * is on roaming, in which case we will also be given new keys.
2339 * Keep the below message for now, unless it starts bothering
2340 * users who really like to roam a lot :)
2342 if (test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2343 wl1271_info("JOIN while associated.");
2345 /* clear encryption type */
2346 wlvif
->encryption_type
= KEY_NONE
;
2349 set_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
);
2352 ret
= wl12xx_cmd_role_start_ibss(wl
, wlvif
);
2354 ret
= wl12xx_cmd_role_start_sta(wl
, wlvif
);
2358 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2362 * The join command disable the keep-alive mode, shut down its process,
2363 * and also clear the template config, so we need to reset it all after
2364 * the join. The acx_aid starts the keep-alive process, and the order
2365 * of the commands below is relevant.
2367 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, true);
2371 ret
= wl1271_acx_aid(wl
, wlvif
, wlvif
->aid
);
2375 ret
= wl12xx_cmd_build_klv_null_data(wl
, wlvif
);
2379 ret
= wl1271_acx_keep_alive_config(wl
, wlvif
,
2380 CMD_TEMPL_KLV_IDX_NULL_DATA
,
2381 ACX_KEEP_ALIVE_TPL_VALID
);
2389 static int wl1271_unjoin(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2393 if (test_and_clear_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
)) {
2394 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
2396 wl12xx_cmd_stop_channel_switch(wl
);
2397 ieee80211_chswitch_done(vif
, false);
2400 /* to stop listening to a channel, we disconnect */
2401 ret
= wl12xx_cmd_role_stop_sta(wl
, wlvif
);
2405 /* reset TX security counters on a clean disconnect */
2406 wlvif
->tx_security_last_seq_lsb
= 0;
2407 wlvif
->tx_security_seq
= 0;
2413 static void wl1271_set_band_rate(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2415 wlvif
->basic_rate_set
= wlvif
->bitrate_masks
[wlvif
->band
];
2416 wlvif
->rate_set
= wlvif
->basic_rate_set
;
2419 static int wl1271_sta_handle_idle(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2423 bool cur_idle
= !test_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2425 if (idle
== cur_idle
)
2429 /* no need to croc if we weren't busy (e.g. during boot) */
2430 if (wl12xx_dev_role_started(wlvif
)) {
2431 ret
= wl12xx_stop_dev(wl
, wlvif
);
2436 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
2437 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2440 ret
= wl1271_acx_keep_alive_config(
2441 wl
, wlvif
, CMD_TEMPL_KLV_IDX_NULL_DATA
,
2442 ACX_KEEP_ALIVE_TPL_INVALID
);
2445 clear_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2447 /* The current firmware only supports sched_scan in idle */
2448 if (wl
->sched_scanning
) {
2449 wl1271_scan_sched_scan_stop(wl
);
2450 ieee80211_sched_scan_stopped(wl
->hw
);
2453 ret
= wl12xx_start_dev(wl
, wlvif
);
2456 set_bit(WLVIF_FLAG_IN_USE
, &wlvif
->flags
);
2463 static int wl12xx_config_vif(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2464 struct ieee80211_conf
*conf
, u32 changed
)
2466 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2469 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2471 /* if the channel changes while joined, join again */
2472 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
&&
2473 ((wlvif
->band
!= conf
->channel
->band
) ||
2474 (wlvif
->channel
!= channel
) ||
2475 (wlvif
->channel_type
!= conf
->channel_type
))) {
2476 /* send all pending packets */
2477 wl1271_tx_work_locked(wl
);
2478 wlvif
->band
= conf
->channel
->band
;
2479 wlvif
->channel
= channel
;
2480 wlvif
->channel_type
= conf
->channel_type
;
2484 * FIXME: the mac80211 should really provide a fixed
2485 * rate to use here. for now, just use the smallest
2486 * possible rate for the band as a fixed rate for
2487 * association frames and other control messages.
2489 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
2490 wl1271_set_band_rate(wl
, wlvif
);
2493 wl1271_tx_min_rate_get(wl
,
2494 wlvif
->basic_rate_set
);
2495 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
2497 wl1271_warning("rate policy for channel "
2501 * change the ROC channel. do it only if we are
2502 * not idle. otherwise, CROC will be called
2505 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
,
2507 wl12xx_dev_role_started(wlvif
) &&
2508 !(conf
->flags
& IEEE80211_CONF_IDLE
)) {
2509 ret
= wl12xx_stop_dev(wl
, wlvif
);
2513 ret
= wl12xx_start_dev(wl
, wlvif
);
2520 if ((changed
& IEEE80211_CONF_CHANGE_PS
) && !is_ap
) {
2522 if ((conf
->flags
& IEEE80211_CONF_PS
) &&
2523 test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
) &&
2524 !test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2529 if (wl
->conf
.conn
.forced_ps
) {
2530 ps_mode
= STATION_POWER_SAVE_MODE
;
2531 ps_mode_str
= "forced";
2533 ps_mode
= STATION_AUTO_PS_MODE
;
2534 ps_mode_str
= "auto";
2537 wl1271_debug(DEBUG_PSM
, "%s ps enabled", ps_mode_str
);
2539 ret
= wl1271_ps_set_mode(wl
, wlvif
, ps_mode
);
2542 wl1271_warning("enter %s ps failed %d",
2545 } else if (!(conf
->flags
& IEEE80211_CONF_PS
) &&
2546 test_bit(WLVIF_FLAG_IN_PS
, &wlvif
->flags
)) {
2548 wl1271_debug(DEBUG_PSM
, "auto ps disabled");
2550 ret
= wl1271_ps_set_mode(wl
, wlvif
,
2551 STATION_ACTIVE_MODE
);
2553 wl1271_warning("exit auto ps failed %d", ret
);
2557 if (conf
->power_level
!= wlvif
->power_level
) {
2558 ret
= wl1271_acx_tx_power(wl
, wlvif
, conf
->power_level
);
2562 wlvif
->power_level
= conf
->power_level
;
2568 static int wl1271_op_config(struct ieee80211_hw
*hw
, u32 changed
)
2570 struct wl1271
*wl
= hw
->priv
;
2571 struct wl12xx_vif
*wlvif
;
2572 struct ieee80211_conf
*conf
= &hw
->conf
;
2573 int channel
, ret
= 0;
2575 channel
= ieee80211_frequency_to_channel(conf
->channel
->center_freq
);
2577 wl1271_debug(DEBUG_MAC80211
, "mac80211 config ch %d psm %s power %d %s"
2580 conf
->flags
& IEEE80211_CONF_PS
? "on" : "off",
2582 conf
->flags
& IEEE80211_CONF_IDLE
? "idle" : "in use",
2586 * mac80211 will go to idle nearly immediately after transmitting some
2587 * frames, such as the deauth. To make sure those frames reach the air,
2588 * wait here until the TX queue is fully flushed.
2590 if ((changed
& IEEE80211_CONF_CHANGE_IDLE
) &&
2591 (conf
->flags
& IEEE80211_CONF_IDLE
))
2592 wl1271_tx_flush(wl
);
2594 mutex_lock(&wl
->mutex
);
2596 /* we support configuring the channel and band even while off */
2597 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
2598 wl
->band
= conf
->channel
->band
;
2599 wl
->channel
= channel
;
2600 wl
->channel_type
= conf
->channel_type
;
2603 if (changed
& IEEE80211_CONF_CHANGE_POWER
)
2604 wl
->power_level
= conf
->power_level
;
2606 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2609 ret
= wl1271_ps_elp_wakeup(wl
);
2613 /* configure each interface */
2614 wl12xx_for_each_wlvif(wl
, wlvif
) {
2615 ret
= wl12xx_config_vif(wl
, wlvif
, conf
, changed
);
2621 wl1271_ps_elp_sleep(wl
);
2624 mutex_unlock(&wl
->mutex
);
2629 struct wl1271_filter_params
{
2632 u8 mc_list
[ACX_MC_ADDRESS_GROUP_MAX
][ETH_ALEN
];
2635 static u64
wl1271_op_prepare_multicast(struct ieee80211_hw
*hw
,
2636 struct netdev_hw_addr_list
*mc_list
)
2638 struct wl1271_filter_params
*fp
;
2639 struct netdev_hw_addr
*ha
;
2640 struct wl1271
*wl
= hw
->priv
;
2642 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2645 fp
= kzalloc(sizeof(*fp
), GFP_ATOMIC
);
2647 wl1271_error("Out of memory setting filters.");
2651 /* update multicast filtering parameters */
2652 fp
->mc_list_length
= 0;
2653 if (netdev_hw_addr_list_count(mc_list
) > ACX_MC_ADDRESS_GROUP_MAX
) {
2654 fp
->enabled
= false;
2657 netdev_hw_addr_list_for_each(ha
, mc_list
) {
2658 memcpy(fp
->mc_list
[fp
->mc_list_length
],
2659 ha
->addr
, ETH_ALEN
);
2660 fp
->mc_list_length
++;
2664 return (u64
)(unsigned long)fp
;
2667 #define WL1271_SUPPORTED_FILTERS (FIF_PROMISC_IN_BSS | \
2670 FIF_BCN_PRBRESP_PROMISC | \
2674 static void wl1271_op_configure_filter(struct ieee80211_hw
*hw
,
2675 unsigned int changed
,
2676 unsigned int *total
, u64 multicast
)
2678 struct wl1271_filter_params
*fp
= (void *)(unsigned long)multicast
;
2679 struct wl1271
*wl
= hw
->priv
;
2680 struct wl12xx_vif
*wlvif
;
2684 wl1271_debug(DEBUG_MAC80211
, "mac80211 configure filter changed %x"
2685 " total %x", changed
, *total
);
2687 mutex_lock(&wl
->mutex
);
2689 *total
&= WL1271_SUPPORTED_FILTERS
;
2690 changed
&= WL1271_SUPPORTED_FILTERS
;
2692 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
2695 ret
= wl1271_ps_elp_wakeup(wl
);
2699 wl12xx_for_each_wlvif(wl
, wlvif
) {
2700 if (wlvif
->bss_type
!= BSS_TYPE_AP_BSS
) {
2701 if (*total
& FIF_ALLMULTI
)
2702 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2706 ret
= wl1271_acx_group_address_tbl(wl
, wlvif
,
2709 fp
->mc_list_length
);
2716 * the fw doesn't provide an api to configure the filters. instead,
2717 * the filters configuration is based on the active roles / ROC
2722 wl1271_ps_elp_sleep(wl
);
2725 mutex_unlock(&wl
->mutex
);
2729 static int wl1271_record_ap_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2730 u8 id
, u8 key_type
, u8 key_size
,
2731 const u8
*key
, u8 hlid
, u32 tx_seq_32
,
2734 struct wl1271_ap_key
*ap_key
;
2737 wl1271_debug(DEBUG_CRYPT
, "record ap key id %d", (int)id
);
2739 if (key_size
> MAX_KEY_SIZE
)
2743 * Find next free entry in ap_keys. Also check we are not replacing
2746 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2747 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2750 if (wlvif
->ap
.recorded_keys
[i
]->id
== id
) {
2751 wl1271_warning("trying to record key replacement");
2756 if (i
== MAX_NUM_KEYS
)
2759 ap_key
= kzalloc(sizeof(*ap_key
), GFP_KERNEL
);
2764 ap_key
->key_type
= key_type
;
2765 ap_key
->key_size
= key_size
;
2766 memcpy(ap_key
->key
, key
, key_size
);
2767 ap_key
->hlid
= hlid
;
2768 ap_key
->tx_seq_32
= tx_seq_32
;
2769 ap_key
->tx_seq_16
= tx_seq_16
;
2771 wlvif
->ap
.recorded_keys
[i
] = ap_key
;
2775 static void wl1271_free_ap_keys(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2779 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2780 kfree(wlvif
->ap
.recorded_keys
[i
]);
2781 wlvif
->ap
.recorded_keys
[i
] = NULL
;
2785 static int wl1271_ap_init_hwenc(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
)
2788 struct wl1271_ap_key
*key
;
2789 bool wep_key_added
= false;
2791 for (i
= 0; i
< MAX_NUM_KEYS
; i
++) {
2793 if (wlvif
->ap
.recorded_keys
[i
] == NULL
)
2796 key
= wlvif
->ap
.recorded_keys
[i
];
2798 if (hlid
== WL12XX_INVALID_LINK_ID
)
2799 hlid
= wlvif
->ap
.bcast_hlid
;
2801 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
2802 key
->id
, key
->key_type
,
2803 key
->key_size
, key
->key
,
2804 hlid
, key
->tx_seq_32
,
2809 if (key
->key_type
== KEY_WEP
)
2810 wep_key_added
= true;
2813 if (wep_key_added
) {
2814 ret
= wl12xx_cmd_set_default_wep_key(wl
, wlvif
->default_key
,
2815 wlvif
->ap
.bcast_hlid
);
2821 wl1271_free_ap_keys(wl
, wlvif
);
2825 static int wl1271_set_key(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
,
2826 u16 action
, u8 id
, u8 key_type
,
2827 u8 key_size
, const u8
*key
, u32 tx_seq_32
,
2828 u16 tx_seq_16
, struct ieee80211_sta
*sta
)
2831 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
2834 * A role set to GEM cipher requires different Tx settings (namely
2835 * spare blocks). Note when we are in this mode so the HW can adjust.
2837 if (key_type
== KEY_GEM
) {
2838 if (action
== KEY_ADD_OR_REPLACE
)
2839 wlvif
->is_gem
= true;
2840 else if (action
== KEY_REMOVE
)
2841 wlvif
->is_gem
= false;
2845 struct wl1271_station
*wl_sta
;
2849 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
2850 hlid
= wl_sta
->hlid
;
2852 hlid
= wlvif
->ap
.bcast_hlid
;
2855 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
2857 * We do not support removing keys after AP shutdown.
2858 * Pretend we do to make mac80211 happy.
2860 if (action
!= KEY_ADD_OR_REPLACE
)
2863 ret
= wl1271_record_ap_key(wl
, wlvif
, id
,
2865 key
, hlid
, tx_seq_32
,
2868 ret
= wl1271_cmd_set_ap_key(wl
, wlvif
, action
,
2869 id
, key_type
, key_size
,
2870 key
, hlid
, tx_seq_32
,
2878 static const u8 bcast_addr
[ETH_ALEN
] = {
2879 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2882 addr
= sta
? sta
->addr
: bcast_addr
;
2884 if (is_zero_ether_addr(addr
)) {
2885 /* We dont support TX only encryption */
2889 /* The wl1271 does not allow to remove unicast keys - they
2890 will be cleared automatically on next CMD_JOIN. Ignore the
2891 request silently, as we dont want the mac80211 to emit
2892 an error message. */
2893 if (action
== KEY_REMOVE
&& !is_broadcast_ether_addr(addr
))
2896 /* don't remove key if hlid was already deleted */
2897 if (action
== KEY_REMOVE
&&
2898 wlvif
->sta
.hlid
== WL12XX_INVALID_LINK_ID
)
2901 ret
= wl1271_cmd_set_sta_key(wl
, wlvif
, action
,
2902 id
, key_type
, key_size
,
2903 key
, addr
, tx_seq_32
,
2908 /* the default WEP key needs to be configured at least once */
2909 if (key_type
== KEY_WEP
) {
2910 ret
= wl12xx_cmd_set_default_wep_key(wl
,
2921 static int wl1271_op_set_key(struct ieee80211_hw
*hw
, enum set_key_cmd cmd
,
2922 struct ieee80211_vif
*vif
,
2923 struct ieee80211_sta
*sta
,
2924 struct ieee80211_key_conf
*key_conf
)
2926 struct wl1271
*wl
= hw
->priv
;
2927 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
2933 wl1271_debug(DEBUG_MAC80211
, "mac80211 set key");
2935 wl1271_debug(DEBUG_CRYPT
, "CMD: 0x%x sta: %p", cmd
, sta
);
2936 wl1271_debug(DEBUG_CRYPT
, "Key: algo:0x%x, id:%d, len:%d flags 0x%x",
2937 key_conf
->cipher
, key_conf
->keyidx
,
2938 key_conf
->keylen
, key_conf
->flags
);
2939 wl1271_dump(DEBUG_CRYPT
, "KEY: ", key_conf
->key
, key_conf
->keylen
);
2941 mutex_lock(&wl
->mutex
);
2943 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
2948 ret
= wl1271_ps_elp_wakeup(wl
);
2952 switch (key_conf
->cipher
) {
2953 case WLAN_CIPHER_SUITE_WEP40
:
2954 case WLAN_CIPHER_SUITE_WEP104
:
2957 key_conf
->hw_key_idx
= key_conf
->keyidx
;
2959 case WLAN_CIPHER_SUITE_TKIP
:
2960 key_type
= KEY_TKIP
;
2962 key_conf
->hw_key_idx
= key_conf
->keyidx
;
2963 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
2964 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
2966 case WLAN_CIPHER_SUITE_CCMP
:
2969 key_conf
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
2970 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
2971 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
2973 case WL1271_CIPHER_SUITE_GEM
:
2975 tx_seq_32
= WL1271_TX_SECURITY_HI32(wlvif
->tx_security_seq
);
2976 tx_seq_16
= WL1271_TX_SECURITY_LO16(wlvif
->tx_security_seq
);
2979 wl1271_error("Unknown key algo 0x%x", key_conf
->cipher
);
2987 ret
= wl1271_set_key(wl
, wlvif
, KEY_ADD_OR_REPLACE
,
2988 key_conf
->keyidx
, key_type
,
2989 key_conf
->keylen
, key_conf
->key
,
2990 tx_seq_32
, tx_seq_16
, sta
);
2992 wl1271_error("Could not add or replace key");
2997 * reconfiguring arp response if the unicast (or common)
2998 * encryption key type was changed
3000 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
3001 (sta
|| key_type
== KEY_WEP
) &&
3002 wlvif
->encryption_type
!= key_type
) {
3003 wlvif
->encryption_type
= key_type
;
3004 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3006 wl1271_warning("build arp rsp failed: %d", ret
);
3013 ret
= wl1271_set_key(wl
, wlvif
, KEY_REMOVE
,
3014 key_conf
->keyidx
, key_type
,
3015 key_conf
->keylen
, key_conf
->key
,
3018 wl1271_error("Could not remove key");
3024 wl1271_error("Unsupported key cmd 0x%x", cmd
);
3030 wl1271_ps_elp_sleep(wl
);
3033 mutex_unlock(&wl
->mutex
);
3038 static int wl1271_op_hw_scan(struct ieee80211_hw
*hw
,
3039 struct ieee80211_vif
*vif
,
3040 struct cfg80211_scan_request
*req
)
3042 struct wl1271
*wl
= hw
->priv
;
3047 wl1271_debug(DEBUG_MAC80211
, "mac80211 hw scan");
3050 ssid
= req
->ssids
[0].ssid
;
3051 len
= req
->ssids
[0].ssid_len
;
3054 mutex_lock(&wl
->mutex
);
3056 if (wl
->state
== WL1271_STATE_OFF
) {
3058 * We cannot return -EBUSY here because cfg80211 will expect
3059 * a call to ieee80211_scan_completed if we do - in this case
3060 * there won't be any call.
3066 ret
= wl1271_ps_elp_wakeup(wl
);
3070 /* fail if there is any role in ROC */
3071 if (find_first_bit(wl
->roc_map
, WL12XX_MAX_ROLES
) < WL12XX_MAX_ROLES
) {
3072 /* don't allow scanning right now */
3077 ret
= wl1271_scan(hw
->priv
, vif
, ssid
, len
, req
);
3079 wl1271_ps_elp_sleep(wl
);
3081 mutex_unlock(&wl
->mutex
);
3086 static void wl1271_op_cancel_hw_scan(struct ieee80211_hw
*hw
,
3087 struct ieee80211_vif
*vif
)
3089 struct wl1271
*wl
= hw
->priv
;
3092 wl1271_debug(DEBUG_MAC80211
, "mac80211 cancel hw scan");
3094 mutex_lock(&wl
->mutex
);
3096 if (wl
->state
== WL1271_STATE_OFF
)
3099 if (wl
->scan
.state
== WL1271_SCAN_STATE_IDLE
)
3102 ret
= wl1271_ps_elp_wakeup(wl
);
3106 if (wl
->scan
.state
!= WL1271_SCAN_STATE_DONE
) {
3107 ret
= wl1271_scan_stop(wl
);
3113 * Rearm the tx watchdog just before idling scan. This
3114 * prevents just-finished scans from triggering the watchdog
3116 wl12xx_rearm_tx_watchdog_locked(wl
);
3118 wl
->scan
.state
= WL1271_SCAN_STATE_IDLE
;
3119 memset(wl
->scan
.scanned_ch
, 0, sizeof(wl
->scan
.scanned_ch
));
3120 wl
->scan_vif
= NULL
;
3121 wl
->scan
.req
= NULL
;
3122 ieee80211_scan_completed(wl
->hw
, true);
3125 wl1271_ps_elp_sleep(wl
);
3127 mutex_unlock(&wl
->mutex
);
3129 cancel_delayed_work_sync(&wl
->scan_complete_work
);
3132 static int wl1271_op_sched_scan_start(struct ieee80211_hw
*hw
,
3133 struct ieee80211_vif
*vif
,
3134 struct cfg80211_sched_scan_request
*req
,
3135 struct ieee80211_sched_scan_ies
*ies
)
3137 struct wl1271
*wl
= hw
->priv
;
3138 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3141 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_start");
3143 mutex_lock(&wl
->mutex
);
3145 if (wl
->state
== WL1271_STATE_OFF
) {
3150 ret
= wl1271_ps_elp_wakeup(wl
);
3154 ret
= wl1271_scan_sched_scan_config(wl
, wlvif
, req
, ies
);
3158 ret
= wl1271_scan_sched_scan_start(wl
, wlvif
);
3162 wl
->sched_scanning
= true;
3165 wl1271_ps_elp_sleep(wl
);
3167 mutex_unlock(&wl
->mutex
);
3171 static void wl1271_op_sched_scan_stop(struct ieee80211_hw
*hw
,
3172 struct ieee80211_vif
*vif
)
3174 struct wl1271
*wl
= hw
->priv
;
3177 wl1271_debug(DEBUG_MAC80211
, "wl1271_op_sched_scan_stop");
3179 mutex_lock(&wl
->mutex
);
3181 if (wl
->state
== WL1271_STATE_OFF
)
3184 ret
= wl1271_ps_elp_wakeup(wl
);
3188 wl1271_scan_sched_scan_stop(wl
);
3190 wl1271_ps_elp_sleep(wl
);
3192 mutex_unlock(&wl
->mutex
);
3195 static int wl1271_op_set_frag_threshold(struct ieee80211_hw
*hw
, u32 value
)
3197 struct wl1271
*wl
= hw
->priv
;
3200 mutex_lock(&wl
->mutex
);
3202 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3207 ret
= wl1271_ps_elp_wakeup(wl
);
3211 ret
= wl1271_acx_frag_threshold(wl
, value
);
3213 wl1271_warning("wl1271_op_set_frag_threshold failed: %d", ret
);
3215 wl1271_ps_elp_sleep(wl
);
3218 mutex_unlock(&wl
->mutex
);
3223 static int wl1271_op_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
3225 struct wl1271
*wl
= hw
->priv
;
3226 struct wl12xx_vif
*wlvif
;
3229 mutex_lock(&wl
->mutex
);
3231 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
3236 ret
= wl1271_ps_elp_wakeup(wl
);
3240 wl12xx_for_each_wlvif(wl
, wlvif
) {
3241 ret
= wl1271_acx_rts_threshold(wl
, wlvif
, value
);
3243 wl1271_warning("set rts threshold failed: %d", ret
);
3245 wl1271_ps_elp_sleep(wl
);
3248 mutex_unlock(&wl
->mutex
);
3253 static int wl1271_ssid_set(struct ieee80211_vif
*vif
, struct sk_buff
*skb
,
3256 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3258 const u8
*ptr
= cfg80211_find_ie(WLAN_EID_SSID
, skb
->data
+ offset
,
3262 wl1271_error("No SSID in IEs!");
3267 if (ssid_len
> IEEE80211_MAX_SSID_LEN
) {
3268 wl1271_error("SSID is too long!");
3272 wlvif
->ssid_len
= ssid_len
;
3273 memcpy(wlvif
->ssid
, ptr
+2, ssid_len
);
3277 static void wl12xx_remove_ie(struct sk_buff
*skb
, u8 eid
, int ieoffset
)
3280 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3281 u8
*ie
= (u8
*)cfg80211_find_ie(eid
, skb
->data
+ ieoffset
,
3282 skb
->len
- ieoffset
);
3287 memmove(ie
, next
, end
- next
);
3288 skb_trim(skb
, skb
->len
- len
);
3291 static void wl12xx_remove_vendor_ie(struct sk_buff
*skb
,
3292 unsigned int oui
, u8 oui_type
,
3296 const u8
*next
, *end
= skb
->data
+ skb
->len
;
3297 u8
*ie
= (u8
*)cfg80211_find_vendor_ie(oui
, oui_type
,
3298 skb
->data
+ ieoffset
,
3299 skb
->len
- ieoffset
);
3304 memmove(ie
, next
, end
- next
);
3305 skb_trim(skb
, skb
->len
- len
);
3308 static int wl1271_ap_set_probe_resp_tmpl(struct wl1271
*wl
, u32 rates
,
3309 struct ieee80211_vif
*vif
)
3311 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3312 struct sk_buff
*skb
;
3315 skb
= ieee80211_proberesp_get(wl
->hw
, vif
);
3319 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3320 CMD_TEMPL_AP_PROBE_RESPONSE
,
3329 static int wl1271_ap_set_probe_resp_tmpl_legacy(struct wl1271
*wl
,
3330 struct ieee80211_vif
*vif
,
3332 size_t probe_rsp_len
,
3335 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3336 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
3337 u8 probe_rsp_templ
[WL1271_CMD_TEMPL_MAX_SIZE
];
3338 int ssid_ie_offset
, ie_offset
, templ_len
;
3341 /* no need to change probe response if the SSID is set correctly */
3342 if (wlvif
->ssid_len
> 0)
3343 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3344 CMD_TEMPL_AP_PROBE_RESPONSE
,
3349 if (probe_rsp_len
+ bss_conf
->ssid_len
> WL1271_CMD_TEMPL_MAX_SIZE
) {
3350 wl1271_error("probe_rsp template too big");
3354 /* start searching from IE offset */
3355 ie_offset
= offsetof(struct ieee80211_mgmt
, u
.probe_resp
.variable
);
3357 ptr
= cfg80211_find_ie(WLAN_EID_SSID
, probe_rsp_data
+ ie_offset
,
3358 probe_rsp_len
- ie_offset
);
3360 wl1271_error("No SSID in beacon!");
3364 ssid_ie_offset
= ptr
- probe_rsp_data
;
3365 ptr
+= (ptr
[1] + 2);
3367 memcpy(probe_rsp_templ
, probe_rsp_data
, ssid_ie_offset
);
3369 /* insert SSID from bss_conf */
3370 probe_rsp_templ
[ssid_ie_offset
] = WLAN_EID_SSID
;
3371 probe_rsp_templ
[ssid_ie_offset
+ 1] = bss_conf
->ssid_len
;
3372 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2,
3373 bss_conf
->ssid
, bss_conf
->ssid_len
);
3374 templ_len
= ssid_ie_offset
+ 2 + bss_conf
->ssid_len
;
3376 memcpy(probe_rsp_templ
+ ssid_ie_offset
+ 2 + bss_conf
->ssid_len
,
3377 ptr
, probe_rsp_len
- (ptr
- probe_rsp_data
));
3378 templ_len
+= probe_rsp_len
- (ptr
- probe_rsp_data
);
3380 return wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3381 CMD_TEMPL_AP_PROBE_RESPONSE
,
3387 static int wl1271_bss_erp_info_changed(struct wl1271
*wl
,
3388 struct ieee80211_vif
*vif
,
3389 struct ieee80211_bss_conf
*bss_conf
,
3392 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3395 if (changed
& BSS_CHANGED_ERP_SLOT
) {
3396 if (bss_conf
->use_short_slot
)
3397 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_SHORT
);
3399 ret
= wl1271_acx_slot(wl
, wlvif
, SLOT_TIME_LONG
);
3401 wl1271_warning("Set slot time failed %d", ret
);
3406 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
3407 if (bss_conf
->use_short_preamble
)
3408 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_SHORT
);
3410 wl1271_acx_set_preamble(wl
, wlvif
, ACX_PREAMBLE_LONG
);
3413 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
3414 if (bss_conf
->use_cts_prot
)
3415 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3418 ret
= wl1271_acx_cts_protect(wl
, wlvif
,
3419 CTSPROTECT_DISABLE
);
3421 wl1271_warning("Set ctsprotect failed %d", ret
);
3430 static int wl1271_bss_beacon_info_changed(struct wl1271
*wl
,
3431 struct ieee80211_vif
*vif
,
3432 struct ieee80211_bss_conf
*bss_conf
,
3435 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3436 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3439 if ((changed
& BSS_CHANGED_BEACON_INT
)) {
3440 wl1271_debug(DEBUG_MASTER
, "beacon interval updated: %d",
3441 bss_conf
->beacon_int
);
3443 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3446 if ((changed
& BSS_CHANGED_AP_PROBE_RESP
) && is_ap
) {
3447 u32 rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3448 if (!wl1271_ap_set_probe_resp_tmpl(wl
, rate
, vif
)) {
3449 wl1271_debug(DEBUG_AP
, "probe response updated");
3450 set_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
);
3454 if ((changed
& BSS_CHANGED_BEACON
)) {
3455 struct ieee80211_hdr
*hdr
;
3457 int ieoffset
= offsetof(struct ieee80211_mgmt
,
3459 struct sk_buff
*beacon
= ieee80211_beacon_get(wl
->hw
, vif
);
3467 wl1271_debug(DEBUG_MASTER
, "beacon updated");
3469 ret
= wl1271_ssid_set(vif
, beacon
, ieoffset
);
3471 dev_kfree_skb(beacon
);
3474 min_rate
= wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
3475 tmpl_id
= is_ap
? CMD_TEMPL_AP_BEACON
:
3477 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
, tmpl_id
,
3482 dev_kfree_skb(beacon
);
3487 * In case we already have a probe-resp beacon set explicitly
3488 * by usermode, don't use the beacon data.
3490 if (test_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
, &wlvif
->flags
))
3493 /* remove TIM ie from probe response */
3494 wl12xx_remove_ie(beacon
, WLAN_EID_TIM
, ieoffset
);
3497 * remove p2p ie from probe response.
3498 * the fw reponds to probe requests that don't include
3499 * the p2p ie. probe requests with p2p ie will be passed,
3500 * and will be responded by the supplicant (the spec
3501 * forbids including the p2p ie when responding to probe
3502 * requests that didn't include it).
3504 wl12xx_remove_vendor_ie(beacon
, WLAN_OUI_WFA
,
3505 WLAN_OUI_TYPE_WFA_P2P
, ieoffset
);
3507 hdr
= (struct ieee80211_hdr
*) beacon
->data
;
3508 hdr
->frame_control
= cpu_to_le16(IEEE80211_FTYPE_MGMT
|
3509 IEEE80211_STYPE_PROBE_RESP
);
3511 ret
= wl1271_ap_set_probe_resp_tmpl_legacy(wl
, vif
,
3516 ret
= wl1271_cmd_template_set(wl
, wlvif
->role_id
,
3517 CMD_TEMPL_PROBE_RESPONSE
,
3522 dev_kfree_skb(beacon
);
3529 wl1271_error("beacon info change failed: %d", ret
);
3533 /* AP mode changes */
3534 static void wl1271_bss_info_changed_ap(struct wl1271
*wl
,
3535 struct ieee80211_vif
*vif
,
3536 struct ieee80211_bss_conf
*bss_conf
,
3539 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3542 if ((changed
& BSS_CHANGED_BASIC_RATES
)) {
3543 u32 rates
= bss_conf
->basic_rates
;
3545 wlvif
->basic_rate_set
= wl1271_tx_enabled_rates_get(wl
, rates
,
3547 wlvif
->basic_rate
= wl1271_tx_min_rate_get(wl
,
3548 wlvif
->basic_rate_set
);
3550 ret
= wl1271_init_ap_rates(wl
, wlvif
);
3552 wl1271_error("AP rate policy change failed %d", ret
);
3556 ret
= wl1271_ap_init_templates(wl
, vif
);
3561 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
, changed
);
3565 if ((changed
& BSS_CHANGED_BEACON_ENABLED
)) {
3566 if (bss_conf
->enable_beacon
) {
3567 if (!test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3568 ret
= wl12xx_cmd_role_start_ap(wl
, wlvif
);
3572 ret
= wl1271_ap_init_hwenc(wl
, wlvif
);
3576 set_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3577 wl1271_debug(DEBUG_AP
, "started AP");
3580 if (test_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
)) {
3581 ret
= wl12xx_cmd_role_stop_ap(wl
, wlvif
);
3585 clear_bit(WLVIF_FLAG_AP_STARTED
, &wlvif
->flags
);
3586 clear_bit(WLVIF_FLAG_AP_PROBE_RESP_SET
,
3588 wl1271_debug(DEBUG_AP
, "stopped AP");
3593 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3597 /* Handle HT information change */
3598 if ((changed
& BSS_CHANGED_HT
) &&
3599 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3600 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3601 bss_conf
->ht_operation_mode
);
3603 wl1271_warning("Set ht information failed %d", ret
);
3612 /* STA/IBSS mode changes */
3613 static void wl1271_bss_info_changed_sta(struct wl1271
*wl
,
3614 struct ieee80211_vif
*vif
,
3615 struct ieee80211_bss_conf
*bss_conf
,
3618 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3619 bool do_join
= false, set_assoc
= false;
3620 bool is_ibss
= (wlvif
->bss_type
== BSS_TYPE_IBSS
);
3621 bool ibss_joined
= false;
3622 u32 sta_rate_set
= 0;
3624 struct ieee80211_sta
*sta
;
3625 bool sta_exists
= false;
3626 struct ieee80211_sta_ht_cap sta_ht_cap
;
3629 ret
= wl1271_bss_beacon_info_changed(wl
, vif
, bss_conf
,
3635 if (changed
& BSS_CHANGED_IBSS
) {
3636 if (bss_conf
->ibss_joined
) {
3637 set_bit(WLVIF_FLAG_IBSS_JOINED
, &wlvif
->flags
);
3640 if (test_and_clear_bit(WLVIF_FLAG_IBSS_JOINED
,
3642 wl1271_unjoin(wl
, wlvif
);
3646 if ((changed
& BSS_CHANGED_BEACON_INT
) && ibss_joined
)
3649 /* Need to update the SSID (for filtering etc) */
3650 if ((changed
& BSS_CHANGED_BEACON
) && ibss_joined
)
3653 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && ibss_joined
) {
3654 wl1271_debug(DEBUG_ADHOC
, "ad-hoc beaconing: %s",
3655 bss_conf
->enable_beacon
? "enabled" : "disabled");
3660 if (changed
& BSS_CHANGED_IDLE
&& !is_ibss
) {
3661 ret
= wl1271_sta_handle_idle(wl
, wlvif
, bss_conf
->idle
);
3663 wl1271_warning("idle mode change failed %d", ret
);
3666 if ((changed
& BSS_CHANGED_CQM
)) {
3667 bool enable
= false;
3668 if (bss_conf
->cqm_rssi_thold
)
3670 ret
= wl1271_acx_rssi_snr_trigger(wl
, wlvif
, enable
,
3671 bss_conf
->cqm_rssi_thold
,
3672 bss_conf
->cqm_rssi_hyst
);
3675 wlvif
->rssi_thold
= bss_conf
->cqm_rssi_thold
;
3678 if (changed
& BSS_CHANGED_BSSID
)
3679 if (!is_zero_ether_addr(bss_conf
->bssid
)) {
3680 ret
= wl12xx_cmd_build_null_data(wl
, wlvif
);
3684 ret
= wl1271_build_qos_null_data(wl
, vif
);
3689 if (changed
& (BSS_CHANGED_ASSOC
| BSS_CHANGED_HT
)) {
3691 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
3695 /* save the supp_rates of the ap */
3696 sta_rate_set
= sta
->supp_rates
[wl
->hw
->conf
.channel
->band
];
3697 if (sta
->ht_cap
.ht_supported
)
3699 (sta
->ht_cap
.mcs
.rx_mask
[0] << HW_HT_RATES_OFFSET
) |
3700 (sta
->ht_cap
.mcs
.rx_mask
[1] << HW_MIMO_RATES_OFFSET
);
3701 sta_ht_cap
= sta
->ht_cap
;
3708 if ((changed
& BSS_CHANGED_ASSOC
)) {
3709 if (bss_conf
->assoc
) {
3712 wlvif
->aid
= bss_conf
->aid
;
3713 wlvif
->channel_type
= bss_conf
->channel_type
;
3714 wlvif
->beacon_int
= bss_conf
->beacon_int
;
3718 /* Cancel connection_loss_work */
3719 cancel_delayed_work_sync(&wl
->connection_loss_work
);
3722 * use basic rates from AP, and determine lowest rate
3723 * to use with control frames.
3725 rates
= bss_conf
->basic_rates
;
3726 wlvif
->basic_rate_set
=
3727 wl1271_tx_enabled_rates_get(wl
, rates
,
3730 wl1271_tx_min_rate_get(wl
,
3731 wlvif
->basic_rate_set
);
3734 wl1271_tx_enabled_rates_get(wl
,
3737 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3742 * with wl1271, we don't need to update the
3743 * beacon_int and dtim_period, because the firmware
3744 * updates it by itself when the first beacon is
3745 * received after a join.
3747 ret
= wl1271_cmd_build_ps_poll(wl
, wlvif
, wlvif
->aid
);
3752 * Get a template for hardware connection maintenance
3754 dev_kfree_skb(wlvif
->probereq
);
3755 wlvif
->probereq
= wl1271_cmd_build_ap_probe_req(wl
,
3758 ieoffset
= offsetof(struct ieee80211_mgmt
,
3759 u
.probe_req
.variable
);
3760 wl1271_ssid_set(vif
, wlvif
->probereq
, ieoffset
);
3762 /* enable the connection monitoring feature */
3763 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, true);
3767 /* use defaults when not associated */
3769 !!test_and_clear_bit(WLVIF_FLAG_STA_ASSOCIATED
,
3772 !!test_and_clear_bit(WLVIF_FLAG_STA_STATE_SENT
,
3776 /* free probe-request template */
3777 dev_kfree_skb(wlvif
->probereq
);
3778 wlvif
->probereq
= NULL
;
3780 /* revert back to minimum rates for the current band */
3781 wl1271_set_band_rate(wl
, wlvif
);
3783 wl1271_tx_min_rate_get(wl
,
3784 wlvif
->basic_rate_set
);
3785 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3789 /* disable connection monitor features */
3790 ret
= wl1271_acx_conn_monit_params(wl
, wlvif
, false);
3792 /* Disable the keep-alive feature */
3793 ret
= wl1271_acx_keep_alive_mode(wl
, wlvif
, false);
3797 /* restore the bssid filter and go to dummy bssid */
3800 * we might have to disable roc, if there was
3801 * no IF_OPER_UP notification.
3804 ret
= wl12xx_croc(wl
, wlvif
->role_id
);
3809 * (we also need to disable roc in case of
3810 * roaming on the same channel. until we will
3811 * have a better flow...)
3813 if (test_bit(wlvif
->dev_role_id
, wl
->roc_map
)) {
3814 ret
= wl12xx_croc(wl
,
3815 wlvif
->dev_role_id
);
3820 wl1271_unjoin(wl
, wlvif
);
3821 if (!bss_conf
->idle
)
3822 wl12xx_start_dev(wl
, wlvif
);
3827 if (changed
& BSS_CHANGED_IBSS
) {
3828 wl1271_debug(DEBUG_ADHOC
, "ibss_joined: %d",
3829 bss_conf
->ibss_joined
);
3831 if (bss_conf
->ibss_joined
) {
3832 u32 rates
= bss_conf
->basic_rates
;
3833 wlvif
->basic_rate_set
=
3834 wl1271_tx_enabled_rates_get(wl
, rates
,
3837 wl1271_tx_min_rate_get(wl
,
3838 wlvif
->basic_rate_set
);
3840 /* by default, use 11b + OFDM rates */
3841 wlvif
->rate_set
= CONF_TX_IBSS_DEFAULT_RATES
;
3842 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
3848 ret
= wl1271_bss_erp_info_changed(wl
, vif
, bss_conf
, changed
);
3853 ret
= wl1271_join(wl
, wlvif
, set_assoc
);
3855 wl1271_warning("cmd join failed %d", ret
);
3859 /* ROC until connected (after EAPOL exchange) */
3861 ret
= wl12xx_roc(wl
, wlvif
, wlvif
->role_id
);
3865 if (test_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
))
3866 wl12xx_set_authorized(wl
, wlvif
);
3869 * stop device role if started (we might already be in
3872 if (wl12xx_dev_role_started(wlvif
)) {
3873 ret
= wl12xx_stop_dev(wl
, wlvif
);
3879 /* Handle new association with HT. Do this after join. */
3881 if ((changed
& BSS_CHANGED_HT
) &&
3882 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3883 ret
= wl1271_acx_set_ht_capabilities(wl
,
3888 wl1271_warning("Set ht cap true failed %d",
3893 /* handle new association without HT and disassociation */
3894 else if (changed
& BSS_CHANGED_ASSOC
) {
3895 ret
= wl1271_acx_set_ht_capabilities(wl
,
3900 wl1271_warning("Set ht cap false failed %d",
3907 /* Handle HT information change. Done after join. */
3908 if ((changed
& BSS_CHANGED_HT
) &&
3909 (bss_conf
->channel_type
!= NL80211_CHAN_NO_HT
)) {
3910 ret
= wl1271_acx_set_ht_information(wl
, wlvif
,
3911 bss_conf
->ht_operation_mode
);
3913 wl1271_warning("Set ht information failed %d", ret
);
3918 /* Handle arp filtering. Done after join. */
3919 if ((changed
& BSS_CHANGED_ARP_FILTER
) ||
3920 (!is_ibss
&& (changed
& BSS_CHANGED_QOS
))) {
3921 __be32 addr
= bss_conf
->arp_addr_list
[0];
3922 wlvif
->sta
.qos
= bss_conf
->qos
;
3923 WARN_ON(wlvif
->bss_type
!= BSS_TYPE_STA_BSS
);
3925 if (bss_conf
->arp_addr_cnt
== 1 &&
3926 bss_conf
->arp_filter_enabled
) {
3927 wlvif
->ip_addr
= addr
;
3929 * The template should have been configured only upon
3930 * association. however, it seems that the correct ip
3931 * isn't being set (when sending), so we have to
3932 * reconfigure the template upon every ip change.
3934 ret
= wl1271_cmd_build_arp_rsp(wl
, wlvif
);
3936 wl1271_warning("build arp rsp failed: %d", ret
);
3940 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
,
3941 (ACX_ARP_FILTER_ARP_FILTERING
|
3942 ACX_ARP_FILTER_AUTO_ARP
),
3946 ret
= wl1271_acx_arp_ip_filter(wl
, wlvif
, 0, addr
);
3957 static void wl1271_op_bss_info_changed(struct ieee80211_hw
*hw
,
3958 struct ieee80211_vif
*vif
,
3959 struct ieee80211_bss_conf
*bss_conf
,
3962 struct wl1271
*wl
= hw
->priv
;
3963 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
3964 bool is_ap
= (wlvif
->bss_type
== BSS_TYPE_AP_BSS
);
3967 wl1271_debug(DEBUG_MAC80211
, "mac80211 bss info changed 0x%x",
3970 mutex_lock(&wl
->mutex
);
3972 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
3975 if (unlikely(!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
)))
3978 ret
= wl1271_ps_elp_wakeup(wl
);
3983 wl1271_bss_info_changed_ap(wl
, vif
, bss_conf
, changed
);
3985 wl1271_bss_info_changed_sta(wl
, vif
, bss_conf
, changed
);
3987 wl1271_ps_elp_sleep(wl
);
3990 mutex_unlock(&wl
->mutex
);
3993 static int wl1271_op_conf_tx(struct ieee80211_hw
*hw
,
3994 struct ieee80211_vif
*vif
, u16 queue
,
3995 const struct ieee80211_tx_queue_params
*params
)
3997 struct wl1271
*wl
= hw
->priv
;
3998 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4002 mutex_lock(&wl
->mutex
);
4004 wl1271_debug(DEBUG_MAC80211
, "mac80211 conf tx %d", queue
);
4007 ps_scheme
= CONF_PS_SCHEME_UPSD_TRIGGER
;
4009 ps_scheme
= CONF_PS_SCHEME_LEGACY
;
4011 if (!test_bit(WLVIF_FLAG_INITIALIZED
, &wlvif
->flags
))
4014 ret
= wl1271_ps_elp_wakeup(wl
);
4019 * the txop is confed in units of 32us by the mac80211,
4022 ret
= wl1271_acx_ac_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4023 params
->cw_min
, params
->cw_max
,
4024 params
->aifs
, params
->txop
<< 5);
4028 ret
= wl1271_acx_tid_cfg(wl
, wlvif
, wl1271_tx_get_queue(queue
),
4029 CONF_CHANNEL_TYPE_EDCF
,
4030 wl1271_tx_get_queue(queue
),
4031 ps_scheme
, CONF_ACK_POLICY_LEGACY
,
4035 wl1271_ps_elp_sleep(wl
);
4038 mutex_unlock(&wl
->mutex
);
4043 static u64
wl1271_op_get_tsf(struct ieee80211_hw
*hw
,
4044 struct ieee80211_vif
*vif
)
4047 struct wl1271
*wl
= hw
->priv
;
4048 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4049 u64 mactime
= ULLONG_MAX
;
4052 wl1271_debug(DEBUG_MAC80211
, "mac80211 get tsf");
4054 mutex_lock(&wl
->mutex
);
4056 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4059 ret
= wl1271_ps_elp_wakeup(wl
);
4063 ret
= wl12xx_acx_tsf_info(wl
, wlvif
, &mactime
);
4068 wl1271_ps_elp_sleep(wl
);
4071 mutex_unlock(&wl
->mutex
);
4075 static int wl1271_op_get_survey(struct ieee80211_hw
*hw
, int idx
,
4076 struct survey_info
*survey
)
4078 struct wl1271
*wl
= hw
->priv
;
4079 struct ieee80211_conf
*conf
= &hw
->conf
;
4084 survey
->channel
= conf
->channel
;
4085 survey
->filled
= SURVEY_INFO_NOISE_DBM
;
4086 survey
->noise
= wl
->noise
;
4091 static int wl1271_allocate_sta(struct wl1271
*wl
,
4092 struct wl12xx_vif
*wlvif
,
4093 struct ieee80211_sta
*sta
)
4095 struct wl1271_station
*wl_sta
;
4099 if (wl
->active_sta_count
>= AP_MAX_STATIONS
) {
4100 wl1271_warning("could not allocate HLID - too much stations");
4104 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4105 ret
= wl12xx_allocate_link(wl
, wlvif
, &wl_sta
->hlid
);
4107 wl1271_warning("could not allocate HLID - too many links");
4111 set_bit(wl_sta
->hlid
, wlvif
->ap
.sta_hlid_map
);
4112 memcpy(wl
->links
[wl_sta
->hlid
].addr
, sta
->addr
, ETH_ALEN
);
4113 wl
->active_sta_count
++;
4117 void wl1271_free_sta(struct wl1271
*wl
, struct wl12xx_vif
*wlvif
, u8 hlid
)
4119 if (!test_bit(hlid
, wlvif
->ap
.sta_hlid_map
))
4122 clear_bit(hlid
, wlvif
->ap
.sta_hlid_map
);
4123 memset(wl
->links
[hlid
].addr
, 0, ETH_ALEN
);
4124 wl
->links
[hlid
].ba_bitmap
= 0;
4125 __clear_bit(hlid
, &wl
->ap_ps_map
);
4126 __clear_bit(hlid
, (unsigned long *)&wl
->ap_fw_ps_map
);
4127 wl12xx_free_link(wl
, wlvif
, &hlid
);
4128 wl
->active_sta_count
--;
4131 * rearm the tx watchdog when the last STA is freed - give the FW a
4132 * chance to return STA-buffered packets before complaining.
4134 if (wl
->active_sta_count
== 0)
4135 wl12xx_rearm_tx_watchdog_locked(wl
);
4138 static int wl12xx_sta_add(struct wl1271
*wl
,
4139 struct wl12xx_vif
*wlvif
,
4140 struct ieee80211_sta
*sta
)
4142 struct wl1271_station
*wl_sta
;
4146 wl1271_debug(DEBUG_MAC80211
, "mac80211 add sta %d", (int)sta
->aid
);
4148 ret
= wl1271_allocate_sta(wl
, wlvif
, sta
);
4152 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4153 hlid
= wl_sta
->hlid
;
4155 ret
= wl12xx_cmd_add_peer(wl
, wlvif
, sta
, hlid
);
4157 wl1271_free_sta(wl
, wlvif
, hlid
);
4162 static int wl12xx_sta_remove(struct wl1271
*wl
,
4163 struct wl12xx_vif
*wlvif
,
4164 struct ieee80211_sta
*sta
)
4166 struct wl1271_station
*wl_sta
;
4169 wl1271_debug(DEBUG_MAC80211
, "mac80211 remove sta %d", (int)sta
->aid
);
4171 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4173 if (WARN_ON(!test_bit(id
, wlvif
->ap
.sta_hlid_map
)))
4176 ret
= wl12xx_cmd_remove_peer(wl
, wl_sta
->hlid
);
4180 wl1271_free_sta(wl
, wlvif
, wl_sta
->hlid
);
4184 static int wl12xx_update_sta_state(struct wl1271
*wl
,
4185 struct wl12xx_vif
*wlvif
,
4186 struct ieee80211_sta
*sta
,
4187 enum ieee80211_sta_state old_state
,
4188 enum ieee80211_sta_state new_state
)
4190 struct wl1271_station
*wl_sta
;
4192 bool is_ap
= wlvif
->bss_type
== BSS_TYPE_AP_BSS
;
4193 bool is_sta
= wlvif
->bss_type
== BSS_TYPE_STA_BSS
;
4196 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4197 hlid
= wl_sta
->hlid
;
4199 /* Add station (AP mode) */
4201 old_state
== IEEE80211_STA_NOTEXIST
&&
4202 new_state
== IEEE80211_STA_NONE
)
4203 return wl12xx_sta_add(wl
, wlvif
, sta
);
4205 /* Remove station (AP mode) */
4207 old_state
== IEEE80211_STA_NONE
&&
4208 new_state
== IEEE80211_STA_NOTEXIST
) {
4210 wl12xx_sta_remove(wl
, wlvif
, sta
);
4214 /* Authorize station (AP mode) */
4216 new_state
== IEEE80211_STA_AUTHORIZED
) {
4217 ret
= wl12xx_cmd_set_peer_state(wl
, hlid
);
4221 ret
= wl1271_acx_set_ht_capabilities(wl
, &sta
->ht_cap
, true,
4226 /* Authorize station */
4228 new_state
== IEEE80211_STA_AUTHORIZED
) {
4229 set_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4230 return wl12xx_set_authorized(wl
, wlvif
);
4234 old_state
== IEEE80211_STA_AUTHORIZED
&&
4235 new_state
== IEEE80211_STA_ASSOC
) {
4236 clear_bit(WLVIF_FLAG_STA_AUTHORIZED
, &wlvif
->flags
);
4243 static int wl12xx_op_sta_state(struct ieee80211_hw
*hw
,
4244 struct ieee80211_vif
*vif
,
4245 struct ieee80211_sta
*sta
,
4246 enum ieee80211_sta_state old_state
,
4247 enum ieee80211_sta_state new_state
)
4249 struct wl1271
*wl
= hw
->priv
;
4250 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4253 wl1271_debug(DEBUG_MAC80211
, "mac80211 sta %d state=%d->%d",
4254 sta
->aid
, old_state
, new_state
);
4256 mutex_lock(&wl
->mutex
);
4258 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4263 ret
= wl1271_ps_elp_wakeup(wl
);
4267 ret
= wl12xx_update_sta_state(wl
, wlvif
, sta
, old_state
, new_state
);
4269 wl1271_ps_elp_sleep(wl
);
4271 mutex_unlock(&wl
->mutex
);
4272 if (new_state
< old_state
)
4277 static int wl1271_op_ampdu_action(struct ieee80211_hw
*hw
,
4278 struct ieee80211_vif
*vif
,
4279 enum ieee80211_ampdu_mlme_action action
,
4280 struct ieee80211_sta
*sta
, u16 tid
, u16
*ssn
,
4283 struct wl1271
*wl
= hw
->priv
;
4284 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4286 u8 hlid
, *ba_bitmap
;
4288 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu action %d tid %d", action
,
4291 /* sanity check - the fields in FW are only 8bits wide */
4292 if (WARN_ON(tid
> 0xFF))
4295 mutex_lock(&wl
->mutex
);
4297 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4302 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
) {
4303 hlid
= wlvif
->sta
.hlid
;
4304 ba_bitmap
= &wlvif
->sta
.ba_rx_bitmap
;
4305 } else if (wlvif
->bss_type
== BSS_TYPE_AP_BSS
) {
4306 struct wl1271_station
*wl_sta
;
4308 wl_sta
= (struct wl1271_station
*)sta
->drv_priv
;
4309 hlid
= wl_sta
->hlid
;
4310 ba_bitmap
= &wl
->links
[hlid
].ba_bitmap
;
4316 ret
= wl1271_ps_elp_wakeup(wl
);
4320 wl1271_debug(DEBUG_MAC80211
, "mac80211 ampdu: Rx tid %d action %d",
4324 case IEEE80211_AMPDU_RX_START
:
4325 if (!wlvif
->ba_support
|| !wlvif
->ba_allowed
) {
4330 if (wl
->ba_rx_session_count
>= RX_BA_MAX_SESSIONS
) {
4332 wl1271_error("exceeded max RX BA sessions");
4336 if (*ba_bitmap
& BIT(tid
)) {
4338 wl1271_error("cannot enable RX BA session on active "
4343 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, *ssn
, true,
4346 *ba_bitmap
|= BIT(tid
);
4347 wl
->ba_rx_session_count
++;
4351 case IEEE80211_AMPDU_RX_STOP
:
4352 if (!(*ba_bitmap
& BIT(tid
))) {
4354 wl1271_error("no active RX BA session on tid: %d",
4359 ret
= wl12xx_acx_set_ba_receiver_session(wl
, tid
, 0, false,
4362 *ba_bitmap
&= ~BIT(tid
);
4363 wl
->ba_rx_session_count
--;
4368 * The BA initiator session management in FW independently.
4369 * Falling break here on purpose for all TX APDU commands.
4371 case IEEE80211_AMPDU_TX_START
:
4372 case IEEE80211_AMPDU_TX_STOP
:
4373 case IEEE80211_AMPDU_TX_OPERATIONAL
:
4378 wl1271_error("Incorrect ampdu action id=%x\n", action
);
4382 wl1271_ps_elp_sleep(wl
);
4385 mutex_unlock(&wl
->mutex
);
4390 static int wl12xx_set_bitrate_mask(struct ieee80211_hw
*hw
,
4391 struct ieee80211_vif
*vif
,
4392 const struct cfg80211_bitrate_mask
*mask
)
4394 struct wl12xx_vif
*wlvif
= wl12xx_vif_to_data(vif
);
4395 struct wl1271
*wl
= hw
->priv
;
4398 wl1271_debug(DEBUG_MAC80211
, "mac80211 set_bitrate_mask 0x%x 0x%x",
4399 mask
->control
[NL80211_BAND_2GHZ
].legacy
,
4400 mask
->control
[NL80211_BAND_5GHZ
].legacy
);
4402 mutex_lock(&wl
->mutex
);
4404 for (i
= 0; i
< IEEE80211_NUM_BANDS
; i
++)
4405 wlvif
->bitrate_masks
[i
] =
4406 wl1271_tx_enabled_rates_get(wl
,
4407 mask
->control
[i
].legacy
,
4410 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4413 if (wlvif
->bss_type
== BSS_TYPE_STA_BSS
&&
4414 !test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
)) {
4416 ret
= wl1271_ps_elp_wakeup(wl
);
4420 wl1271_set_band_rate(wl
, wlvif
);
4422 wl1271_tx_min_rate_get(wl
, wlvif
->basic_rate_set
);
4423 ret
= wl1271_acx_sta_rate_policies(wl
, wlvif
);
4425 wl1271_ps_elp_sleep(wl
);
4428 mutex_unlock(&wl
->mutex
);
4433 static void wl12xx_op_channel_switch(struct ieee80211_hw
*hw
,
4434 struct ieee80211_channel_switch
*ch_switch
)
4436 struct wl1271
*wl
= hw
->priv
;
4437 struct wl12xx_vif
*wlvif
;
4440 wl1271_debug(DEBUG_MAC80211
, "mac80211 channel switch");
4442 wl1271_tx_flush(wl
);
4444 mutex_lock(&wl
->mutex
);
4446 if (unlikely(wl
->state
== WL1271_STATE_OFF
)) {
4447 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4448 struct ieee80211_vif
*vif
= wl12xx_wlvif_to_vif(wlvif
);
4449 ieee80211_chswitch_done(vif
, false);
4454 ret
= wl1271_ps_elp_wakeup(wl
);
4458 /* TODO: change mac80211 to pass vif as param */
4459 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4460 ret
= wl12xx_cmd_channel_switch(wl
, wlvif
, ch_switch
);
4463 set_bit(WLVIF_FLAG_CS_PROGRESS
, &wlvif
->flags
);
4466 wl1271_ps_elp_sleep(wl
);
4469 mutex_unlock(&wl
->mutex
);
4472 static bool wl1271_tx_frames_pending(struct ieee80211_hw
*hw
)
4474 struct wl1271
*wl
= hw
->priv
;
4477 mutex_lock(&wl
->mutex
);
4479 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4482 /* packets are considered pending if in the TX queue or the FW */
4483 ret
= (wl1271_tx_total_queue_count(wl
) > 0) || (wl
->tx_frames_cnt
> 0);
4485 mutex_unlock(&wl
->mutex
);
4490 /* can't be const, mac80211 writes to this */
4491 static struct ieee80211_rate wl1271_rates
[] = {
4493 .hw_value
= CONF_HW_BIT_RATE_1MBPS
,
4494 .hw_value_short
= CONF_HW_BIT_RATE_1MBPS
, },
4496 .hw_value
= CONF_HW_BIT_RATE_2MBPS
,
4497 .hw_value_short
= CONF_HW_BIT_RATE_2MBPS
,
4498 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4500 .hw_value
= CONF_HW_BIT_RATE_5_5MBPS
,
4501 .hw_value_short
= CONF_HW_BIT_RATE_5_5MBPS
,
4502 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4504 .hw_value
= CONF_HW_BIT_RATE_11MBPS
,
4505 .hw_value_short
= CONF_HW_BIT_RATE_11MBPS
,
4506 .flags
= IEEE80211_RATE_SHORT_PREAMBLE
},
4508 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4509 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4511 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4512 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4514 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4515 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4517 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4518 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4520 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4521 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4523 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4524 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4526 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4527 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4529 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4530 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4533 /* can't be const, mac80211 writes to this */
4534 static struct ieee80211_channel wl1271_channels
[] = {
4535 { .hw_value
= 1, .center_freq
= 2412, .max_power
= 25 },
4536 { .hw_value
= 2, .center_freq
= 2417, .max_power
= 25 },
4537 { .hw_value
= 3, .center_freq
= 2422, .max_power
= 25 },
4538 { .hw_value
= 4, .center_freq
= 2427, .max_power
= 25 },
4539 { .hw_value
= 5, .center_freq
= 2432, .max_power
= 25 },
4540 { .hw_value
= 6, .center_freq
= 2437, .max_power
= 25 },
4541 { .hw_value
= 7, .center_freq
= 2442, .max_power
= 25 },
4542 { .hw_value
= 8, .center_freq
= 2447, .max_power
= 25 },
4543 { .hw_value
= 9, .center_freq
= 2452, .max_power
= 25 },
4544 { .hw_value
= 10, .center_freq
= 2457, .max_power
= 25 },
4545 { .hw_value
= 11, .center_freq
= 2462, .max_power
= 25 },
4546 { .hw_value
= 12, .center_freq
= 2467, .max_power
= 25 },
4547 { .hw_value
= 13, .center_freq
= 2472, .max_power
= 25 },
4548 { .hw_value
= 14, .center_freq
= 2484, .max_power
= 25 },
4551 /* can't be const, mac80211 writes to this */
4552 static struct ieee80211_supported_band wl1271_band_2ghz
= {
4553 .channels
= wl1271_channels
,
4554 .n_channels
= ARRAY_SIZE(wl1271_channels
),
4555 .bitrates
= wl1271_rates
,
4556 .n_bitrates
= ARRAY_SIZE(wl1271_rates
),
4559 /* 5 GHz data rates for WL1273 */
4560 static struct ieee80211_rate wl1271_rates_5ghz
[] = {
4562 .hw_value
= CONF_HW_BIT_RATE_6MBPS
,
4563 .hw_value_short
= CONF_HW_BIT_RATE_6MBPS
, },
4565 .hw_value
= CONF_HW_BIT_RATE_9MBPS
,
4566 .hw_value_short
= CONF_HW_BIT_RATE_9MBPS
, },
4568 .hw_value
= CONF_HW_BIT_RATE_12MBPS
,
4569 .hw_value_short
= CONF_HW_BIT_RATE_12MBPS
, },
4571 .hw_value
= CONF_HW_BIT_RATE_18MBPS
,
4572 .hw_value_short
= CONF_HW_BIT_RATE_18MBPS
, },
4574 .hw_value
= CONF_HW_BIT_RATE_24MBPS
,
4575 .hw_value_short
= CONF_HW_BIT_RATE_24MBPS
, },
4577 .hw_value
= CONF_HW_BIT_RATE_36MBPS
,
4578 .hw_value_short
= CONF_HW_BIT_RATE_36MBPS
, },
4580 .hw_value
= CONF_HW_BIT_RATE_48MBPS
,
4581 .hw_value_short
= CONF_HW_BIT_RATE_48MBPS
, },
4583 .hw_value
= CONF_HW_BIT_RATE_54MBPS
,
4584 .hw_value_short
= CONF_HW_BIT_RATE_54MBPS
, },
4587 /* 5 GHz band channels for WL1273 */
4588 static struct ieee80211_channel wl1271_channels_5ghz
[] = {
4589 { .hw_value
= 7, .center_freq
= 5035, .max_power
= 25 },
4590 { .hw_value
= 8, .center_freq
= 5040, .max_power
= 25 },
4591 { .hw_value
= 9, .center_freq
= 5045, .max_power
= 25 },
4592 { .hw_value
= 11, .center_freq
= 5055, .max_power
= 25 },
4593 { .hw_value
= 12, .center_freq
= 5060, .max_power
= 25 },
4594 { .hw_value
= 16, .center_freq
= 5080, .max_power
= 25 },
4595 { .hw_value
= 34, .center_freq
= 5170, .max_power
= 25 },
4596 { .hw_value
= 36, .center_freq
= 5180, .max_power
= 25 },
4597 { .hw_value
= 38, .center_freq
= 5190, .max_power
= 25 },
4598 { .hw_value
= 40, .center_freq
= 5200, .max_power
= 25 },
4599 { .hw_value
= 42, .center_freq
= 5210, .max_power
= 25 },
4600 { .hw_value
= 44, .center_freq
= 5220, .max_power
= 25 },
4601 { .hw_value
= 46, .center_freq
= 5230, .max_power
= 25 },
4602 { .hw_value
= 48, .center_freq
= 5240, .max_power
= 25 },
4603 { .hw_value
= 52, .center_freq
= 5260, .max_power
= 25 },
4604 { .hw_value
= 56, .center_freq
= 5280, .max_power
= 25 },
4605 { .hw_value
= 60, .center_freq
= 5300, .max_power
= 25 },
4606 { .hw_value
= 64, .center_freq
= 5320, .max_power
= 25 },
4607 { .hw_value
= 100, .center_freq
= 5500, .max_power
= 25 },
4608 { .hw_value
= 104, .center_freq
= 5520, .max_power
= 25 },
4609 { .hw_value
= 108, .center_freq
= 5540, .max_power
= 25 },
4610 { .hw_value
= 112, .center_freq
= 5560, .max_power
= 25 },
4611 { .hw_value
= 116, .center_freq
= 5580, .max_power
= 25 },
4612 { .hw_value
= 120, .center_freq
= 5600, .max_power
= 25 },
4613 { .hw_value
= 124, .center_freq
= 5620, .max_power
= 25 },
4614 { .hw_value
= 128, .center_freq
= 5640, .max_power
= 25 },
4615 { .hw_value
= 132, .center_freq
= 5660, .max_power
= 25 },
4616 { .hw_value
= 136, .center_freq
= 5680, .max_power
= 25 },
4617 { .hw_value
= 140, .center_freq
= 5700, .max_power
= 25 },
4618 { .hw_value
= 149, .center_freq
= 5745, .max_power
= 25 },
4619 { .hw_value
= 153, .center_freq
= 5765, .max_power
= 25 },
4620 { .hw_value
= 157, .center_freq
= 5785, .max_power
= 25 },
4621 { .hw_value
= 161, .center_freq
= 5805, .max_power
= 25 },
4622 { .hw_value
= 165, .center_freq
= 5825, .max_power
= 25 },
4625 static struct ieee80211_supported_band wl1271_band_5ghz
= {
4626 .channels
= wl1271_channels_5ghz
,
4627 .n_channels
= ARRAY_SIZE(wl1271_channels_5ghz
),
4628 .bitrates
= wl1271_rates_5ghz
,
4629 .n_bitrates
= ARRAY_SIZE(wl1271_rates_5ghz
),
4632 static const struct ieee80211_ops wl1271_ops
= {
4633 .start
= wl1271_op_start
,
4634 .stop
= wl1271_op_stop
,
4635 .add_interface
= wl1271_op_add_interface
,
4636 .remove_interface
= wl1271_op_remove_interface
,
4637 .change_interface
= wl12xx_op_change_interface
,
4639 .suspend
= wl1271_op_suspend
,
4640 .resume
= wl1271_op_resume
,
4642 .config
= wl1271_op_config
,
4643 .prepare_multicast
= wl1271_op_prepare_multicast
,
4644 .configure_filter
= wl1271_op_configure_filter
,
4646 .set_key
= wl1271_op_set_key
,
4647 .hw_scan
= wl1271_op_hw_scan
,
4648 .cancel_hw_scan
= wl1271_op_cancel_hw_scan
,
4649 .sched_scan_start
= wl1271_op_sched_scan_start
,
4650 .sched_scan_stop
= wl1271_op_sched_scan_stop
,
4651 .bss_info_changed
= wl1271_op_bss_info_changed
,
4652 .set_frag_threshold
= wl1271_op_set_frag_threshold
,
4653 .set_rts_threshold
= wl1271_op_set_rts_threshold
,
4654 .conf_tx
= wl1271_op_conf_tx
,
4655 .get_tsf
= wl1271_op_get_tsf
,
4656 .get_survey
= wl1271_op_get_survey
,
4657 .sta_state
= wl12xx_op_sta_state
,
4658 .ampdu_action
= wl1271_op_ampdu_action
,
4659 .tx_frames_pending
= wl1271_tx_frames_pending
,
4660 .set_bitrate_mask
= wl12xx_set_bitrate_mask
,
4661 .channel_switch
= wl12xx_op_channel_switch
,
4662 CFG80211_TESTMODE_CMD(wl1271_tm_cmd
)
4666 u8
wlcore_rate_to_idx(struct wl1271
*wl
, u8 rate
, enum ieee80211_band band
)
4672 if (unlikely(rate
>= wl
->hw_tx_rate_tbl_size
)) {
4673 wl1271_error("Illegal RX rate from HW: %d", rate
);
4677 idx
= wl
->band_rate_to_idx
[band
][rate
];
4678 if (unlikely(idx
== CONF_HW_RXTX_RATE_UNSUPPORTED
)) {
4679 wl1271_error("Unsupported RX rate from HW: %d", rate
);
4686 static ssize_t
wl1271_sysfs_show_bt_coex_state(struct device
*dev
,
4687 struct device_attribute
*attr
,
4690 struct wl1271
*wl
= dev_get_drvdata(dev
);
4695 mutex_lock(&wl
->mutex
);
4696 len
= snprintf(buf
, len
, "%d\n\n0 - off\n1 - on\n",
4698 mutex_unlock(&wl
->mutex
);
4704 static ssize_t
wl1271_sysfs_store_bt_coex_state(struct device
*dev
,
4705 struct device_attribute
*attr
,
4706 const char *buf
, size_t count
)
4708 struct wl1271
*wl
= dev_get_drvdata(dev
);
4712 ret
= kstrtoul(buf
, 10, &res
);
4714 wl1271_warning("incorrect value written to bt_coex_mode");
4718 mutex_lock(&wl
->mutex
);
4722 if (res
== wl
->sg_enabled
)
4725 wl
->sg_enabled
= res
;
4727 if (wl
->state
== WL1271_STATE_OFF
)
4730 ret
= wl1271_ps_elp_wakeup(wl
);
4734 wl1271_acx_sg_enable(wl
, wl
->sg_enabled
);
4735 wl1271_ps_elp_sleep(wl
);
4738 mutex_unlock(&wl
->mutex
);
4742 static DEVICE_ATTR(bt_coex_state
, S_IRUGO
| S_IWUSR
,
4743 wl1271_sysfs_show_bt_coex_state
,
4744 wl1271_sysfs_store_bt_coex_state
);
4746 static ssize_t
wl1271_sysfs_show_hw_pg_ver(struct device
*dev
,
4747 struct device_attribute
*attr
,
4750 struct wl1271
*wl
= dev_get_drvdata(dev
);
4755 mutex_lock(&wl
->mutex
);
4756 if (wl
->hw_pg_ver
>= 0)
4757 len
= snprintf(buf
, len
, "%d\n", wl
->hw_pg_ver
);
4759 len
= snprintf(buf
, len
, "n/a\n");
4760 mutex_unlock(&wl
->mutex
);
4765 static DEVICE_ATTR(hw_pg_ver
, S_IRUGO
,
4766 wl1271_sysfs_show_hw_pg_ver
, NULL
);
4768 static ssize_t
wl1271_sysfs_read_fwlog(struct file
*filp
, struct kobject
*kobj
,
4769 struct bin_attribute
*bin_attr
,
4770 char *buffer
, loff_t pos
, size_t count
)
4772 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
4773 struct wl1271
*wl
= dev_get_drvdata(dev
);
4777 ret
= mutex_lock_interruptible(&wl
->mutex
);
4779 return -ERESTARTSYS
;
4781 /* Let only one thread read the log at a time, blocking others */
4782 while (wl
->fwlog_size
== 0) {
4785 prepare_to_wait_exclusive(&wl
->fwlog_waitq
,
4787 TASK_INTERRUPTIBLE
);
4789 if (wl
->fwlog_size
!= 0) {
4790 finish_wait(&wl
->fwlog_waitq
, &wait
);
4794 mutex_unlock(&wl
->mutex
);
4797 finish_wait(&wl
->fwlog_waitq
, &wait
);
4799 if (signal_pending(current
))
4800 return -ERESTARTSYS
;
4802 ret
= mutex_lock_interruptible(&wl
->mutex
);
4804 return -ERESTARTSYS
;
4807 /* Check if the fwlog is still valid */
4808 if (wl
->fwlog_size
< 0) {
4809 mutex_unlock(&wl
->mutex
);
4813 /* Seeking is not supported - old logs are not kept. Disregard pos. */
4814 len
= min(count
, (size_t)wl
->fwlog_size
);
4815 wl
->fwlog_size
-= len
;
4816 memcpy(buffer
, wl
->fwlog
, len
);
4818 /* Make room for new messages */
4819 memmove(wl
->fwlog
, wl
->fwlog
+ len
, wl
->fwlog_size
);
4821 mutex_unlock(&wl
->mutex
);
4826 static struct bin_attribute fwlog_attr
= {
4827 .attr
= {.name
= "fwlog", .mode
= S_IRUSR
},
4828 .read
= wl1271_sysfs_read_fwlog
,
4831 static void wl1271_connection_loss_work(struct work_struct
*work
)
4833 struct delayed_work
*dwork
;
4835 struct ieee80211_vif
*vif
;
4836 struct wl12xx_vif
*wlvif
;
4838 dwork
= container_of(work
, struct delayed_work
, work
);
4839 wl
= container_of(dwork
, struct wl1271
, connection_loss_work
);
4841 wl1271_info("Connection loss work.");
4843 mutex_lock(&wl
->mutex
);
4845 if (unlikely(wl
->state
== WL1271_STATE_OFF
))
4848 /* Call mac80211 connection loss */
4849 wl12xx_for_each_wlvif_sta(wl
, wlvif
) {
4850 if (!test_bit(WLVIF_FLAG_STA_ASSOCIATED
, &wlvif
->flags
))
4852 vif
= wl12xx_wlvif_to_vif(wlvif
);
4853 ieee80211_connection_loss(vif
);
4856 mutex_unlock(&wl
->mutex
);
4859 static void wl12xx_derive_mac_addresses(struct wl1271
*wl
,
4860 u32 oui
, u32 nic
, int n
)
4864 wl1271_debug(DEBUG_PROBE
, "base address: oui %06x nic %06x, n %d",
4867 if (nic
+ n
- 1 > 0xffffff)
4868 wl1271_warning("NIC part of the MAC address wraps around!");
4870 for (i
= 0; i
< n
; i
++) {
4871 wl
->addresses
[i
].addr
[0] = (u8
)(oui
>> 16);
4872 wl
->addresses
[i
].addr
[1] = (u8
)(oui
>> 8);
4873 wl
->addresses
[i
].addr
[2] = (u8
) oui
;
4874 wl
->addresses
[i
].addr
[3] = (u8
)(nic
>> 16);
4875 wl
->addresses
[i
].addr
[4] = (u8
)(nic
>> 8);
4876 wl
->addresses
[i
].addr
[5] = (u8
) nic
;
4880 wl
->hw
->wiphy
->n_addresses
= n
;
4881 wl
->hw
->wiphy
->addresses
= wl
->addresses
;
4884 static int wl12xx_get_hw_info(struct wl1271
*wl
)
4888 ret
= wl12xx_set_power_on(wl
);
4892 wl
->chip
.id
= wlcore_read_reg(wl
, REG_CHIP_ID_B
);
4894 wl
->fuse_oui_addr
= 0;
4895 wl
->fuse_nic_addr
= 0;
4897 wl
->hw_pg_ver
= wl
->ops
->get_pg_ver(wl
);
4899 if (wl
->ops
->get_mac
)
4900 wl
->ops
->get_mac(wl
);
4902 wl1271_power_off(wl
);
4907 static int wl1271_register_hw(struct wl1271
*wl
)
4910 u32 oui_addr
= 0, nic_addr
= 0;
4912 if (wl
->mac80211_registered
)
4915 ret
= wl12xx_get_hw_info(wl
);
4917 wl1271_error("couldn't get hw info");
4921 ret
= wl1271_fetch_nvs(wl
);
4923 /* NOTE: The wl->nvs->nvs element must be first, in
4924 * order to simplify the casting, we assume it is at
4925 * the beginning of the wl->nvs structure.
4927 u8
*nvs_ptr
= (u8
*)wl
->nvs
;
4930 (nvs_ptr
[11] << 16) + (nvs_ptr
[10] << 8) + nvs_ptr
[6];
4932 (nvs_ptr
[5] << 16) + (nvs_ptr
[4] << 8) + nvs_ptr
[3];
4935 /* if the MAC address is zeroed in the NVS derive from fuse */
4936 if (oui_addr
== 0 && nic_addr
== 0) {
4937 oui_addr
= wl
->fuse_oui_addr
;
4938 /* fuse has the BD_ADDR, the WLAN addresses are the next two */
4939 nic_addr
= wl
->fuse_nic_addr
+ 1;
4942 wl12xx_derive_mac_addresses(wl
, oui_addr
, nic_addr
, 2);
4944 ret
= ieee80211_register_hw(wl
->hw
);
4946 wl1271_error("unable to register mac80211 hw: %d", ret
);
4950 wl
->mac80211_registered
= true;
4952 wl1271_debugfs_init(wl
);
4954 wl1271_notice("loaded");
4960 static void wl1271_unregister_hw(struct wl1271
*wl
)
4963 wl1271_plt_stop(wl
);
4965 ieee80211_unregister_hw(wl
->hw
);
4966 wl
->mac80211_registered
= false;
4970 static int wl1271_init_ieee80211(struct wl1271
*wl
)
4972 static const u32 cipher_suites
[] = {
4973 WLAN_CIPHER_SUITE_WEP40
,
4974 WLAN_CIPHER_SUITE_WEP104
,
4975 WLAN_CIPHER_SUITE_TKIP
,
4976 WLAN_CIPHER_SUITE_CCMP
,
4977 WL1271_CIPHER_SUITE_GEM
,
4980 /* The tx descriptor buffer and the TKIP space. */
4981 wl
->hw
->extra_tx_headroom
= WL1271_EXTRA_SPACE_TKIP
+
4982 sizeof(struct wl1271_tx_hw_descr
);
4985 /* FIXME: find a proper value */
4986 wl
->hw
->channel_change_time
= 10000;
4987 wl
->hw
->max_listen_interval
= wl
->conf
.conn
.max_listen_interval
;
4989 wl
->hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
4990 IEEE80211_HW_SUPPORTS_PS
|
4991 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
4992 IEEE80211_HW_SUPPORTS_UAPSD
|
4993 IEEE80211_HW_HAS_RATE_CONTROL
|
4994 IEEE80211_HW_CONNECTION_MONITOR
|
4995 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
4996 IEEE80211_HW_SPECTRUM_MGMT
|
4997 IEEE80211_HW_AP_LINK_PS
|
4998 IEEE80211_HW_AMPDU_AGGREGATION
|
4999 IEEE80211_HW_TX_AMPDU_SETUP_IN_HW
|
5000 IEEE80211_HW_SCAN_WHILE_IDLE
;
5002 wl
->hw
->wiphy
->cipher_suites
= cipher_suites
;
5003 wl
->hw
->wiphy
->n_cipher_suites
= ARRAY_SIZE(cipher_suites
);
5005 wl
->hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
5006 BIT(NL80211_IFTYPE_ADHOC
) | BIT(NL80211_IFTYPE_AP
) |
5007 BIT(NL80211_IFTYPE_P2P_CLIENT
) | BIT(NL80211_IFTYPE_P2P_GO
);
5008 wl
->hw
->wiphy
->max_scan_ssids
= 1;
5009 wl
->hw
->wiphy
->max_sched_scan_ssids
= 16;
5010 wl
->hw
->wiphy
->max_match_sets
= 16;
5012 * Maximum length of elements in scanning probe request templates
5013 * should be the maximum length possible for a template, without
5014 * the IEEE80211 header of the template
5016 wl
->hw
->wiphy
->max_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5017 sizeof(struct ieee80211_header
);
5019 wl
->hw
->wiphy
->max_sched_scan_ie_len
= WL1271_CMD_TEMPL_MAX_SIZE
-
5020 sizeof(struct ieee80211_header
);
5022 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
|
5023 WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL
;
5025 /* make sure all our channels fit in the scanned_ch bitmask */
5026 BUILD_BUG_ON(ARRAY_SIZE(wl1271_channels
) +
5027 ARRAY_SIZE(wl1271_channels_5ghz
) >
5028 WL1271_MAX_CHANNELS
);
5030 * We keep local copies of the band structs because we need to
5031 * modify them on a per-device basis.
5033 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
], &wl1271_band_2ghz
,
5034 sizeof(wl1271_band_2ghz
));
5035 memcpy(&wl
->bands
[IEEE80211_BAND_2GHZ
].ht_cap
, &wl
->ht_cap
,
5036 sizeof(wl
->ht_cap
));
5037 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
], &wl1271_band_5ghz
,
5038 sizeof(wl1271_band_5ghz
));
5039 memcpy(&wl
->bands
[IEEE80211_BAND_5GHZ
].ht_cap
, &wl
->ht_cap
,
5040 sizeof(wl
->ht_cap
));
5042 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
5043 &wl
->bands
[IEEE80211_BAND_2GHZ
];
5044 wl
->hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
5045 &wl
->bands
[IEEE80211_BAND_5GHZ
];
5048 wl
->hw
->max_rates
= 1;
5050 wl
->hw
->wiphy
->reg_notifier
= wl1271_reg_notify
;
5052 /* the FW answers probe-requests in AP-mode */
5053 wl
->hw
->wiphy
->flags
|= WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD
;
5054 wl
->hw
->wiphy
->probe_resp_offload
=
5055 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS
|
5056 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_WPS2
|
5057 NL80211_PROBE_RESP_OFFLOAD_SUPPORT_P2P
;
5059 SET_IEEE80211_DEV(wl
->hw
, wl
->dev
);
5061 wl
->hw
->sta_data_size
= sizeof(struct wl1271_station
);
5062 wl
->hw
->vif_data_size
= sizeof(struct wl12xx_vif
);
5064 wl
->hw
->max_rx_aggregation_subframes
= wl
->conf
.ht
.rx_ba_win_size
;
5069 #define WL1271_DEFAULT_CHANNEL 0
5071 struct ieee80211_hw
*wlcore_alloc_hw(size_t priv_size
)
5073 struct ieee80211_hw
*hw
;
5078 BUILD_BUG_ON(AP_MAX_STATIONS
> WL12XX_MAX_LINKS
);
5080 hw
= ieee80211_alloc_hw(sizeof(*wl
), &wl1271_ops
);
5082 wl1271_error("could not alloc ieee80211_hw");
5088 memset(wl
, 0, sizeof(*wl
));
5090 wl
->priv
= kzalloc(priv_size
, GFP_KERNEL
);
5092 wl1271_error("could not alloc wl priv");
5094 goto err_priv_alloc
;
5097 INIT_LIST_HEAD(&wl
->wlvif_list
);
5101 for (i
= 0; i
< NUM_TX_QUEUES
; i
++)
5102 for (j
= 0; j
< WL12XX_MAX_LINKS
; j
++)
5103 skb_queue_head_init(&wl
->links
[j
].tx_queue
[i
]);
5105 skb_queue_head_init(&wl
->deferred_rx_queue
);
5106 skb_queue_head_init(&wl
->deferred_tx_queue
);
5108 INIT_DELAYED_WORK(&wl
->elp_work
, wl1271_elp_work
);
5109 INIT_WORK(&wl
->netstack_work
, wl1271_netstack_work
);
5110 INIT_WORK(&wl
->tx_work
, wl1271_tx_work
);
5111 INIT_WORK(&wl
->recovery_work
, wl1271_recovery_work
);
5112 INIT_DELAYED_WORK(&wl
->scan_complete_work
, wl1271_scan_complete_work
);
5113 INIT_DELAYED_WORK(&wl
->tx_watchdog_work
, wl12xx_tx_watchdog_work
);
5114 INIT_DELAYED_WORK(&wl
->connection_loss_work
,
5115 wl1271_connection_loss_work
);
5117 wl
->freezable_wq
= create_freezable_workqueue("wl12xx_wq");
5118 if (!wl
->freezable_wq
) {
5123 wl
->channel
= WL1271_DEFAULT_CHANNEL
;
5125 wl
->power_level
= WL1271_DEFAULT_POWER_LEVEL
;
5126 wl
->band
= IEEE80211_BAND_2GHZ
;
5127 wl
->channel_type
= NL80211_CHAN_NO_HT
;
5129 wl
->sg_enabled
= true;
5132 wl
->ap_fw_ps_map
= 0;
5134 wl
->platform_quirks
= 0;
5135 wl
->sched_scanning
= false;
5136 wl
->system_hlid
= WL12XX_SYSTEM_HLID
;
5137 wl
->active_sta_count
= 0;
5139 init_waitqueue_head(&wl
->fwlog_waitq
);
5141 /* The system link is always allocated */
5142 __set_bit(WL12XX_SYSTEM_HLID
, wl
->links_map
);
5144 memset(wl
->tx_frames_map
, 0, sizeof(wl
->tx_frames_map
));
5145 for (i
= 0; i
< wl
->num_tx_desc
; i
++)
5146 wl
->tx_frames
[i
] = NULL
;
5148 spin_lock_init(&wl
->wl_lock
);
5150 wl
->state
= WL1271_STATE_OFF
;
5151 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5152 mutex_init(&wl
->mutex
);
5154 order
= get_order(WL1271_AGGR_BUFFER_SIZE
);
5155 wl
->aggr_buf
= (u8
*)__get_free_pages(GFP_KERNEL
, order
);
5156 if (!wl
->aggr_buf
) {
5161 wl
->dummy_packet
= wl12xx_alloc_dummy_packet(wl
);
5162 if (!wl
->dummy_packet
) {
5167 /* Allocate one page for the FW log */
5168 wl
->fwlog
= (u8
*)get_zeroed_page(GFP_KERNEL
);
5171 goto err_dummy_packet
;
5174 wl
->mbox
= kmalloc(sizeof(*wl
->mbox
), GFP_KERNEL
| GFP_DMA
);
5183 free_page((unsigned long)wl
->fwlog
);
5186 dev_kfree_skb(wl
->dummy_packet
);
5189 free_pages((unsigned long)wl
->aggr_buf
, order
);
5192 destroy_workqueue(wl
->freezable_wq
);
5195 wl1271_debugfs_exit(wl
);
5199 ieee80211_free_hw(hw
);
5203 return ERR_PTR(ret
);
5205 EXPORT_SYMBOL_GPL(wlcore_alloc_hw
);
5207 int wlcore_free_hw(struct wl1271
*wl
)
5209 /* Unblock any fwlog readers */
5210 mutex_lock(&wl
->mutex
);
5211 wl
->fwlog_size
= -1;
5212 wake_up_interruptible_all(&wl
->fwlog_waitq
);
5213 mutex_unlock(&wl
->mutex
);
5215 device_remove_bin_file(wl
->dev
, &fwlog_attr
);
5217 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5219 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5220 free_page((unsigned long)wl
->fwlog
);
5221 dev_kfree_skb(wl
->dummy_packet
);
5222 free_pages((unsigned long)wl
->aggr_buf
,
5223 get_order(WL1271_AGGR_BUFFER_SIZE
));
5225 wl1271_debugfs_exit(wl
);
5229 wl
->fw_type
= WL12XX_FW_TYPE_NONE
;
5233 kfree(wl
->fw_status
);
5234 kfree(wl
->tx_res_if
);
5235 destroy_workqueue(wl
->freezable_wq
);
5238 ieee80211_free_hw(wl
->hw
);
5242 EXPORT_SYMBOL_GPL(wlcore_free_hw
);
5244 static irqreturn_t
wl12xx_hardirq(int irq
, void *cookie
)
5246 struct wl1271
*wl
= cookie
;
5247 unsigned long flags
;
5249 wl1271_debug(DEBUG_IRQ
, "IRQ");
5251 /* complete the ELP completion */
5252 spin_lock_irqsave(&wl
->wl_lock
, flags
);
5253 set_bit(WL1271_FLAG_IRQ_RUNNING
, &wl
->flags
);
5254 if (wl
->elp_compl
) {
5255 complete(wl
->elp_compl
);
5256 wl
->elp_compl
= NULL
;
5259 if (test_bit(WL1271_FLAG_SUSPENDED
, &wl
->flags
)) {
5260 /* don't enqueue a work right now. mark it as pending */
5261 set_bit(WL1271_FLAG_PENDING_WORK
, &wl
->flags
);
5262 wl1271_debug(DEBUG_IRQ
, "should not enqueue work");
5263 disable_irq_nosync(wl
->irq
);
5264 pm_wakeup_event(wl
->dev
, 0);
5265 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5268 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
5270 return IRQ_WAKE_THREAD
;
5273 int __devinit
wlcore_probe(struct wl1271
*wl
, struct platform_device
*pdev
)
5275 struct wl12xx_platform_data
*pdata
= pdev
->dev
.platform_data
;
5276 unsigned long irqflags
;
5279 if (!wl
->ops
|| !wl
->ptable
) {
5284 BUG_ON(wl
->num_tx_desc
> WLCORE_MAX_TX_DESCRIPTORS
);
5286 /* adjust some runtime configuration parameters */
5287 wlcore_adjust_conf(wl
);
5289 wl
->irq
= platform_get_irq(pdev
, 0);
5290 wl
->ref_clock
= pdata
->board_ref_clock
;
5291 wl
->tcxo_clock
= pdata
->board_tcxo_clock
;
5292 wl
->platform_quirks
= pdata
->platform_quirks
;
5293 wl
->set_power
= pdata
->set_power
;
5294 wl
->dev
= &pdev
->dev
;
5295 wl
->if_ops
= pdata
->ops
;
5297 platform_set_drvdata(pdev
, wl
);
5299 if (wl
->platform_quirks
& WL12XX_PLATFORM_QUIRK_EDGE_IRQ
)
5300 irqflags
= IRQF_TRIGGER_RISING
;
5302 irqflags
= IRQF_TRIGGER_HIGH
| IRQF_ONESHOT
;
5304 ret
= request_threaded_irq(wl
->irq
, wl12xx_hardirq
, wl1271_irq
,
5308 wl1271_error("request_irq() failed: %d", ret
);
5312 ret
= enable_irq_wake(wl
->irq
);
5314 wl
->irq_wake_enabled
= true;
5315 device_init_wakeup(wl
->dev
, 1);
5316 if (pdata
->pwr_in_suspend
) {
5317 wl
->hw
->wiphy
->wowlan
.flags
= WIPHY_WOWLAN_ANY
;
5318 wl
->hw
->wiphy
->wowlan
.n_patterns
=
5319 WL1271_MAX_RX_FILTERS
;
5320 wl
->hw
->wiphy
->wowlan
.pattern_min_len
= 1;
5321 wl
->hw
->wiphy
->wowlan
.pattern_max_len
=
5322 WL1271_RX_FILTER_MAX_PATTERN_SIZE
;
5325 disable_irq(wl
->irq
);
5327 ret
= wl1271_init_ieee80211(wl
);
5331 ret
= wl1271_register_hw(wl
);
5335 /* Create sysfs file to control bt coex state */
5336 ret
= device_create_file(wl
->dev
, &dev_attr_bt_coex_state
);
5338 wl1271_error("failed to create sysfs file bt_coex_state");
5342 /* Create sysfs file to get HW PG version */
5343 ret
= device_create_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5345 wl1271_error("failed to create sysfs file hw_pg_ver");
5346 goto out_bt_coex_state
;
5349 /* Create sysfs file for the FW log */
5350 ret
= device_create_bin_file(wl
->dev
, &fwlog_attr
);
5352 wl1271_error("failed to create sysfs file fwlog");
5359 device_remove_file(wl
->dev
, &dev_attr_hw_pg_ver
);
5362 device_remove_file(wl
->dev
, &dev_attr_bt_coex_state
);
5365 free_irq(wl
->irq
, wl
);
5373 EXPORT_SYMBOL_GPL(wlcore_probe
);
5375 int __devexit
wlcore_remove(struct platform_device
*pdev
)
5377 struct wl1271
*wl
= platform_get_drvdata(pdev
);
5379 if (wl
->irq_wake_enabled
) {
5380 device_init_wakeup(wl
->dev
, 0);
5381 disable_irq_wake(wl
->irq
);
5383 wl1271_unregister_hw(wl
);
5384 free_irq(wl
->irq
, wl
);
5389 EXPORT_SYMBOL_GPL(wlcore_remove
);
5391 u32 wl12xx_debug_level
= DEBUG_NONE
;
5392 EXPORT_SYMBOL_GPL(wl12xx_debug_level
);
5393 module_param_named(debug_level
, wl12xx_debug_level
, uint
, S_IRUSR
| S_IWUSR
);
5394 MODULE_PARM_DESC(debug_level
, "wl12xx debugging level");
5396 module_param_named(fwlog
, fwlog_param
, charp
, 0);
5397 MODULE_PARM_DESC(fwlog
,
5398 "FW logger options: continuous, ondemand, dbgpins or disable");
5400 module_param(bug_on_recovery
, bool, S_IRUSR
| S_IWUSR
);
5401 MODULE_PARM_DESC(bug_on_recovery
, "BUG() on fw recovery");
5403 module_param(no_recovery
, bool, S_IRUSR
| S_IWUSR
);
5404 MODULE_PARM_DESC(no_recovery
, "Prevent HW recovery. FW will remain stuck.");
5406 MODULE_LICENSE("GPL");
5407 MODULE_AUTHOR("Luciano Coelho <coelho@ti.com>");
5408 MODULE_AUTHOR("Juuso Oikarinen <juuso.oikarinen@nokia.com>");